Skip to content

Commit 3072112

Browse files
yash1200Egor
authored andcommitted
[device_info] Port device_info to use platform interface (flutter#2942)
1 parent 1a56c0b commit 3072112

File tree

3 files changed

+12
-296
lines changed

3 files changed

+12
-296
lines changed

packages/device_info/device_info/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.2+7
2+
3+
* Port device_info plugin to use platform interface.
4+
15
## 0.4.2+6
26

37
* Moved everything from device_info to device_info/device_info

packages/device_info/device_info/lib/device_info.dart

Lines changed: 6 additions & 295 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'package:device_info_platform_interface/device_info_platform_interface.dart';
67

7-
import 'package:flutter/services.dart';
8+
export 'package:device_info_platform_interface/device_info_platform_interface.dart'
9+
show AndroidBuildVersion, AndroidDeviceInfo, IosDeviceInfo, IosUtsname;
810

911
/// Provides device and operating system information.
1012
class DeviceInfoPlugin {
1113
/// No work is done when instantiating the plugin. It's safe to call this
1214
/// repeatedly or in performance-sensitive blocks.
1315
DeviceInfoPlugin();
1416

15-
/// Channel used to communicate to native code.
16-
static const MethodChannel channel =
17-
MethodChannel('plugins.flutter.io/device_info');
18-
1917
/// This information does not change from call to call. Cache it.
2018
AndroidDeviceInfo _cachedAndroidDeviceInfo;
2119

2220
/// Information derived from `android.os.Build`.
2321
///
2422
/// See: https://developer.android.com/reference/android/os/Build.html
2523
Future<AndroidDeviceInfo> get androidInfo async =>
26-
_cachedAndroidDeviceInfo ??= AndroidDeviceInfo._fromMap(await channel
27-
.invokeMapMethod<String, dynamic>('getAndroidDeviceInfo'));
24+
_cachedAndroidDeviceInfo ??=
25+
await DeviceInfoPlatform.instance.androidInfo();
2826

2927
/// This information does not change from call to call. Cache it.
3028
IosDeviceInfo _cachedIosDeviceInfo;
@@ -33,292 +31,5 @@ class DeviceInfoPlugin {
3331
///
3432
/// See: https://developer.apple.com/documentation/uikit/uidevice
3533
Future<IosDeviceInfo> get iosInfo async =>
36-
_cachedIosDeviceInfo ??= IosDeviceInfo._fromMap(
37-
await channel.invokeMapMethod<String, dynamic>('getIosDeviceInfo'));
38-
}
39-
40-
/// Information derived from `android.os.Build`.
41-
///
42-
/// See: https://developer.android.com/reference/android/os/Build.html
43-
class AndroidDeviceInfo {
44-
AndroidDeviceInfo._({
45-
this.version,
46-
this.board,
47-
this.bootloader,
48-
this.brand,
49-
this.device,
50-
this.display,
51-
this.fingerprint,
52-
this.hardware,
53-
this.host,
54-
this.id,
55-
this.manufacturer,
56-
this.model,
57-
this.product,
58-
List<String> supported32BitAbis,
59-
List<String> supported64BitAbis,
60-
List<String> supportedAbis,
61-
this.tags,
62-
this.type,
63-
this.isPhysicalDevice,
64-
this.androidId,
65-
List<String> systemFeatures,
66-
}) : supported32BitAbis = List<String>.unmodifiable(supported32BitAbis),
67-
supported64BitAbis = List<String>.unmodifiable(supported64BitAbis),
68-
supportedAbis = List<String>.unmodifiable(supportedAbis),
69-
systemFeatures = List<String>.unmodifiable(systemFeatures);
70-
71-
/// Android operating system version values derived from `android.os.Build.VERSION`.
72-
final AndroidBuildVersion version;
73-
74-
/// The name of the underlying board, like "goldfish".
75-
final String board;
76-
77-
/// The system bootloader version number.
78-
final String bootloader;
79-
80-
/// The consumer-visible brand with which the product/hardware will be associated, if any.
81-
final String brand;
82-
83-
/// The name of the industrial design.
84-
final String device;
85-
86-
/// A build ID string meant for displaying to the user.
87-
final String display;
88-
89-
/// A string that uniquely identifies this build.
90-
final String fingerprint;
91-
92-
/// The name of the hardware (from the kernel command line or /proc).
93-
final String hardware;
94-
95-
/// Hostname.
96-
final String host;
97-
98-
/// Either a changelist number, or a label like "M4-rc20".
99-
final String id;
100-
101-
/// The manufacturer of the product/hardware.
102-
final String manufacturer;
103-
104-
/// The end-user-visible name for the end product.
105-
final String model;
106-
107-
/// The name of the overall product.
108-
final String product;
109-
110-
/// An ordered list of 32 bit ABIs supported by this device.
111-
final List<String> supported32BitAbis;
112-
113-
/// An ordered list of 64 bit ABIs supported by this device.
114-
final List<String> supported64BitAbis;
115-
116-
/// An ordered list of ABIs supported by this device.
117-
final List<String> supportedAbis;
118-
119-
/// Comma-separated tags describing the build, like "unsigned,debug".
120-
final String tags;
121-
122-
/// The type of build, like "user" or "eng".
123-
final String type;
124-
125-
/// `false` if the application is running in an emulator, `true` otherwise.
126-
final bool isPhysicalDevice;
127-
128-
/// The Android hardware device ID that is unique between the device + user and app signing.
129-
final String androidId;
130-
131-
/// Describes what features are available on the current device.
132-
///
133-
/// This can be used to check if the device has, for example, a front-facing
134-
/// camera, or a touchscreen. However, in many cases this is not the best
135-
/// API to use. For example, if you are interested in bluetooth, this API
136-
/// can tell you if the device has a bluetooth radio, but it cannot tell you
137-
/// if bluetooth is currently enabled, or if you have been granted the
138-
/// necessary permissions to use it. Please *only* use this if there is no
139-
/// other way to determine if a feature is supported.
140-
///
141-
/// This data comes from Android's PackageManager.getSystemAvailableFeatures,
142-
/// and many of the common feature strings to look for are available in
143-
/// PackageManager's public documentation:
144-
/// https://developer.android.com/reference/android/content/pm/PackageManager
145-
final List<String> systemFeatures;
146-
147-
/// Deserializes from the message received from [_kChannel].
148-
static AndroidDeviceInfo _fromMap(Map<String, dynamic> map) {
149-
return AndroidDeviceInfo._(
150-
version:
151-
AndroidBuildVersion._fromMap(map['version']?.cast<String, dynamic>()),
152-
board: map['board'],
153-
bootloader: map['bootloader'],
154-
brand: map['brand'],
155-
device: map['device'],
156-
display: map['display'],
157-
fingerprint: map['fingerprint'],
158-
hardware: map['hardware'],
159-
host: map['host'],
160-
id: map['id'],
161-
manufacturer: map['manufacturer'],
162-
model: map['model'],
163-
product: map['product'],
164-
supported32BitAbis: _fromList(map['supported32BitAbis']),
165-
supported64BitAbis: _fromList(map['supported64BitAbis']),
166-
supportedAbis: _fromList(map['supportedAbis']),
167-
tags: map['tags'],
168-
type: map['type'],
169-
isPhysicalDevice: map['isPhysicalDevice'],
170-
androidId: map['androidId'],
171-
systemFeatures: _fromList(map['systemFeatures']),
172-
);
173-
}
174-
175-
/// Deserializes message as List<String>
176-
static List<String> _fromList(dynamic message) {
177-
final List<dynamic> list = message;
178-
return List<String>.from(list);
179-
}
180-
}
181-
182-
/// Version values of the current Android operating system build derived from
183-
/// `android.os.Build.VERSION`.
184-
///
185-
/// See: https://developer.android.com/reference/android/os/Build.VERSION.html
186-
class AndroidBuildVersion {
187-
AndroidBuildVersion._({
188-
this.baseOS,
189-
this.codename,
190-
this.incremental,
191-
this.previewSdkInt,
192-
this.release,
193-
this.sdkInt,
194-
this.securityPatch,
195-
});
196-
197-
/// The base OS build the product is based on.
198-
final String baseOS;
199-
200-
/// The current development codename, or the string "REL" if this is a release build.
201-
final String codename;
202-
203-
/// The internal value used by the underlying source control to represent this build.
204-
final String incremental;
205-
206-
/// The developer preview revision of a prerelease SDK.
207-
final int previewSdkInt;
208-
209-
/// The user-visible version string.
210-
final String release;
211-
212-
/// The user-visible SDK version of the framework.
213-
///
214-
/// Possible values are defined in: https://developer.android.com/reference/android/os/Build.VERSION_CODES.html
215-
final int sdkInt;
216-
217-
/// The user-visible security patch level.
218-
final String securityPatch;
219-
220-
/// Deserializes from the map message received from [_kChannel].
221-
static AndroidBuildVersion _fromMap(Map<String, dynamic> map) {
222-
return AndroidBuildVersion._(
223-
baseOS: map['baseOS'],
224-
codename: map['codename'],
225-
incremental: map['incremental'],
226-
previewSdkInt: map['previewSdkInt'],
227-
release: map['release'],
228-
sdkInt: map['sdkInt'],
229-
securityPatch: map['securityPatch'],
230-
);
231-
}
232-
}
233-
234-
/// Information derived from `UIDevice`.
235-
///
236-
/// See: https://developer.apple.com/documentation/uikit/uidevice
237-
class IosDeviceInfo {
238-
IosDeviceInfo._({
239-
this.name,
240-
this.systemName,
241-
this.systemVersion,
242-
this.model,
243-
this.localizedModel,
244-
this.identifierForVendor,
245-
this.isPhysicalDevice,
246-
this.utsname,
247-
});
248-
249-
/// Device name.
250-
final String name;
251-
252-
/// The name of the current operating system.
253-
final String systemName;
254-
255-
/// The current operating system version.
256-
final String systemVersion;
257-
258-
/// Device model.
259-
final String model;
260-
261-
/// Localized name of the device model.
262-
final String localizedModel;
263-
264-
/// Unique UUID value identifying the current device.
265-
final String identifierForVendor;
266-
267-
/// `false` if the application is running in a simulator, `true` otherwise.
268-
final bool isPhysicalDevice;
269-
270-
/// Operating system information derived from `sys/utsname.h`.
271-
final IosUtsname utsname;
272-
273-
/// Deserializes from the map message received from [_kChannel].
274-
static IosDeviceInfo _fromMap(Map<String, dynamic> map) {
275-
return IosDeviceInfo._(
276-
name: map['name'],
277-
systemName: map['systemName'],
278-
systemVersion: map['systemVersion'],
279-
model: map['model'],
280-
localizedModel: map['localizedModel'],
281-
identifierForVendor: map['identifierForVendor'],
282-
isPhysicalDevice: map['isPhysicalDevice'] == 'true',
283-
utsname: IosUtsname._fromMap(map['utsname']?.cast<String, dynamic>()),
284-
);
285-
}
286-
}
287-
288-
/// Information derived from `utsname`.
289-
/// See http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysutsname.h.html for details.
290-
class IosUtsname {
291-
IosUtsname._({
292-
this.sysname,
293-
this.nodename,
294-
this.release,
295-
this.version,
296-
this.machine,
297-
});
298-
299-
/// Operating system name.
300-
final String sysname;
301-
302-
/// Network node name.
303-
final String nodename;
304-
305-
/// Release level.
306-
final String release;
307-
308-
/// Version level.
309-
final String version;
310-
311-
/// Hardware type (e.g. 'iPhone7,1' for iPhone 6 Plus).
312-
final String machine;
313-
314-
/// Deserializes from the map message received from [_kChannel].
315-
static IosUtsname _fromMap(Map<String, dynamic> map) {
316-
return IosUtsname._(
317-
sysname: map['sysname'],
318-
nodename: map['nodename'],
319-
release: map['release'],
320-
version: map['version'],
321-
machine: map['machine'],
322-
);
323-
}
34+
_cachedIosDeviceInfo ??= await DeviceInfoPlatform.instance.iosInfo();
32435
}

packages/device_info/device_info/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/device_info
55
# 0.4.y+z is compatible with 1.0.0, if you land a breaking change bump
66
# the version to 2.0.0.
77
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
8-
version: 0.4.2+6
8+
version: 0.4.2+7
99

1010
flutter:
1111
plugin:
@@ -19,6 +19,7 @@ flutter:
1919
dependencies:
2020
flutter:
2121
sdk: flutter
22+
device_info_platform_interface: ^1.0.0
2223

2324
dev_dependencies:
2425
test: ^1.3.0

0 commit comments

Comments
 (0)