diff --git a/packages/device_info/device_info/CHANGELOG.md b/packages/device_info/device_info/CHANGELOG.md index 9af729780914..4f5e1d927c10 100644 --- a/packages/device_info/device_info/CHANGELOG.md +++ b/packages/device_info/device_info/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.2+7 + +* Port device_info plugin to use platform interface. + ## 0.4.2+6 * Moved everything from device_info to device_info/device_info diff --git a/packages/device_info/device_info/lib/device_info.dart b/packages/device_info/device_info/lib/device_info.dart index 25b7d46cdb11..f63730c4323f 100644 --- a/packages/device_info/device_info/lib/device_info.dart +++ b/packages/device_info/device_info/lib/device_info.dart @@ -3,8 +3,10 @@ // found in the LICENSE file. import 'dart:async'; +import 'package:device_info_platform_interface/device_info_platform_interface.dart'; -import 'package:flutter/services.dart'; +export 'package:device_info_platform_interface/device_info_platform_interface.dart' + show AndroidBuildVersion, AndroidDeviceInfo, IosDeviceInfo, IosUtsname; /// Provides device and operating system information. class DeviceInfoPlugin { @@ -12,10 +14,6 @@ class DeviceInfoPlugin { /// repeatedly or in performance-sensitive blocks. DeviceInfoPlugin(); - /// Channel used to communicate to native code. - static const MethodChannel channel = - MethodChannel('plugins.flutter.io/device_info'); - /// This information does not change from call to call. Cache it. AndroidDeviceInfo _cachedAndroidDeviceInfo; @@ -23,8 +21,8 @@ class DeviceInfoPlugin { /// /// See: https://developer.android.com/reference/android/os/Build.html Future get androidInfo async => - _cachedAndroidDeviceInfo ??= AndroidDeviceInfo._fromMap(await channel - .invokeMapMethod('getAndroidDeviceInfo')); + _cachedAndroidDeviceInfo ??= + await DeviceInfoPlatform.instance.androidInfo(); /// This information does not change from call to call. Cache it. IosDeviceInfo _cachedIosDeviceInfo; @@ -33,292 +31,5 @@ class DeviceInfoPlugin { /// /// See: https://developer.apple.com/documentation/uikit/uidevice Future get iosInfo async => - _cachedIosDeviceInfo ??= IosDeviceInfo._fromMap( - await channel.invokeMapMethod('getIosDeviceInfo')); -} - -/// Information derived from `android.os.Build`. -/// -/// See: https://developer.android.com/reference/android/os/Build.html -class AndroidDeviceInfo { - AndroidDeviceInfo._({ - this.version, - this.board, - this.bootloader, - this.brand, - this.device, - this.display, - this.fingerprint, - this.hardware, - this.host, - this.id, - this.manufacturer, - this.model, - this.product, - List supported32BitAbis, - List supported64BitAbis, - List supportedAbis, - this.tags, - this.type, - this.isPhysicalDevice, - this.androidId, - List systemFeatures, - }) : supported32BitAbis = List.unmodifiable(supported32BitAbis), - supported64BitAbis = List.unmodifiable(supported64BitAbis), - supportedAbis = List.unmodifiable(supportedAbis), - systemFeatures = List.unmodifiable(systemFeatures); - - /// Android operating system version values derived from `android.os.Build.VERSION`. - final AndroidBuildVersion version; - - /// The name of the underlying board, like "goldfish". - final String board; - - /// The system bootloader version number. - final String bootloader; - - /// The consumer-visible brand with which the product/hardware will be associated, if any. - final String brand; - - /// The name of the industrial design. - final String device; - - /// A build ID string meant for displaying to the user. - final String display; - - /// A string that uniquely identifies this build. - final String fingerprint; - - /// The name of the hardware (from the kernel command line or /proc). - final String hardware; - - /// Hostname. - final String host; - - /// Either a changelist number, or a label like "M4-rc20". - final String id; - - /// The manufacturer of the product/hardware. - final String manufacturer; - - /// The end-user-visible name for the end product. - final String model; - - /// The name of the overall product. - final String product; - - /// An ordered list of 32 bit ABIs supported by this device. - final List supported32BitAbis; - - /// An ordered list of 64 bit ABIs supported by this device. - final List supported64BitAbis; - - /// An ordered list of ABIs supported by this device. - final List supportedAbis; - - /// Comma-separated tags describing the build, like "unsigned,debug". - final String tags; - - /// The type of build, like "user" or "eng". - final String type; - - /// `false` if the application is running in an emulator, `true` otherwise. - final bool isPhysicalDevice; - - /// The Android hardware device ID that is unique between the device + user and app signing. - final String androidId; - - /// Describes what features are available on the current device. - /// - /// This can be used to check if the device has, for example, a front-facing - /// camera, or a touchscreen. However, in many cases this is not the best - /// API to use. For example, if you are interested in bluetooth, this API - /// can tell you if the device has a bluetooth radio, but it cannot tell you - /// if bluetooth is currently enabled, or if you have been granted the - /// necessary permissions to use it. Please *only* use this if there is no - /// other way to determine if a feature is supported. - /// - /// This data comes from Android's PackageManager.getSystemAvailableFeatures, - /// and many of the common feature strings to look for are available in - /// PackageManager's public documentation: - /// https://developer.android.com/reference/android/content/pm/PackageManager - final List systemFeatures; - - /// Deserializes from the message received from [_kChannel]. - static AndroidDeviceInfo _fromMap(Map map) { - return AndroidDeviceInfo._( - version: - AndroidBuildVersion._fromMap(map['version']?.cast()), - board: map['board'], - bootloader: map['bootloader'], - brand: map['brand'], - device: map['device'], - display: map['display'], - fingerprint: map['fingerprint'], - hardware: map['hardware'], - host: map['host'], - id: map['id'], - manufacturer: map['manufacturer'], - model: map['model'], - product: map['product'], - supported32BitAbis: _fromList(map['supported32BitAbis']), - supported64BitAbis: _fromList(map['supported64BitAbis']), - supportedAbis: _fromList(map['supportedAbis']), - tags: map['tags'], - type: map['type'], - isPhysicalDevice: map['isPhysicalDevice'], - androidId: map['androidId'], - systemFeatures: _fromList(map['systemFeatures']), - ); - } - - /// Deserializes message as List - static List _fromList(dynamic message) { - final List list = message; - return List.from(list); - } -} - -/// Version values of the current Android operating system build derived from -/// `android.os.Build.VERSION`. -/// -/// See: https://developer.android.com/reference/android/os/Build.VERSION.html -class AndroidBuildVersion { - AndroidBuildVersion._({ - this.baseOS, - this.codename, - this.incremental, - this.previewSdkInt, - this.release, - this.sdkInt, - this.securityPatch, - }); - - /// The base OS build the product is based on. - final String baseOS; - - /// The current development codename, or the string "REL" if this is a release build. - final String codename; - - /// The internal value used by the underlying source control to represent this build. - final String incremental; - - /// The developer preview revision of a prerelease SDK. - final int previewSdkInt; - - /// The user-visible version string. - final String release; - - /// The user-visible SDK version of the framework. - /// - /// Possible values are defined in: https://developer.android.com/reference/android/os/Build.VERSION_CODES.html - final int sdkInt; - - /// The user-visible security patch level. - final String securityPatch; - - /// Deserializes from the map message received from [_kChannel]. - static AndroidBuildVersion _fromMap(Map map) { - return AndroidBuildVersion._( - baseOS: map['baseOS'], - codename: map['codename'], - incremental: map['incremental'], - previewSdkInt: map['previewSdkInt'], - release: map['release'], - sdkInt: map['sdkInt'], - securityPatch: map['securityPatch'], - ); - } -} - -/// Information derived from `UIDevice`. -/// -/// See: https://developer.apple.com/documentation/uikit/uidevice -class IosDeviceInfo { - IosDeviceInfo._({ - this.name, - this.systemName, - this.systemVersion, - this.model, - this.localizedModel, - this.identifierForVendor, - this.isPhysicalDevice, - this.utsname, - }); - - /// Device name. - final String name; - - /// The name of the current operating system. - final String systemName; - - /// The current operating system version. - final String systemVersion; - - /// Device model. - final String model; - - /// Localized name of the device model. - final String localizedModel; - - /// Unique UUID value identifying the current device. - final String identifierForVendor; - - /// `false` if the application is running in a simulator, `true` otherwise. - final bool isPhysicalDevice; - - /// Operating system information derived from `sys/utsname.h`. - final IosUtsname utsname; - - /// Deserializes from the map message received from [_kChannel]. - static IosDeviceInfo _fromMap(Map map) { - return IosDeviceInfo._( - name: map['name'], - systemName: map['systemName'], - systemVersion: map['systemVersion'], - model: map['model'], - localizedModel: map['localizedModel'], - identifierForVendor: map['identifierForVendor'], - isPhysicalDevice: map['isPhysicalDevice'] == 'true', - utsname: IosUtsname._fromMap(map['utsname']?.cast()), - ); - } -} - -/// Information derived from `utsname`. -/// See http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysutsname.h.html for details. -class IosUtsname { - IosUtsname._({ - this.sysname, - this.nodename, - this.release, - this.version, - this.machine, - }); - - /// Operating system name. - final String sysname; - - /// Network node name. - final String nodename; - - /// Release level. - final String release; - - /// Version level. - final String version; - - /// Hardware type (e.g. 'iPhone7,1' for iPhone 6 Plus). - final String machine; - - /// Deserializes from the map message received from [_kChannel]. - static IosUtsname _fromMap(Map map) { - return IosUtsname._( - sysname: map['sysname'], - nodename: map['nodename'], - release: map['release'], - version: map['version'], - machine: map['machine'], - ); - } + _cachedIosDeviceInfo ??= await DeviceInfoPlatform.instance.iosInfo(); } diff --git a/packages/device_info/device_info/pubspec.yaml b/packages/device_info/device_info/pubspec.yaml index 8792bdaf5c40..8cb058751fd1 100644 --- a/packages/device_info/device_info/pubspec.yaml +++ b/packages/device_info/device_info/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/device_info # 0.4.y+z is compatible with 1.0.0, if you land a breaking change bump # the version to 2.0.0. # See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0 -version: 0.4.2+6 +version: 0.4.2+7 flutter: plugin: @@ -19,6 +19,7 @@ flutter: dependencies: flutter: sdk: flutter + device_info_platform_interface: ^1.0.0 dev_dependencies: test: ^1.3.0