This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
/
device_info.dart
303 lines (246 loc) · 8.68 KB
/
device_info.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/services.dart';
/// Provides device and operating system information.
class DeviceInfoPlugin {
/// Channel used to communicate to native code.
static const MethodChannel channel =
MethodChannel('plugins.flutter.io/device_info');
DeviceInfoPlugin();
/// This information does not change from call to call. Cache it.
AndroidDeviceInfo _cachedAndroidDeviceInfo;
/// Information derived from `android.os.Build`.
///
/// See: https://developer.android.com/reference/android/os/Build.html
Future<AndroidDeviceInfo> get androidInfo async =>
_cachedAndroidDeviceInfo ??= AndroidDeviceInfo._fromMap(
await channel.invokeMethod('getAndroidDeviceInfo'));
/// This information does not change from call to call. Cache it.
IosDeviceInfo _cachedIosDeviceInfo;
/// Information derived from `UIDevice`.
///
/// See: https://developer.apple.com/documentation/uikit/uidevice
Future<IosDeviceInfo> get iosInfo async => _cachedIosDeviceInfo ??=
IosDeviceInfo._fromMap(await channel.invokeMethod('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<String> supported32BitAbis,
List<String> supported64BitAbis,
List<String> supportedAbis,
this.tags,
this.type,
this.isPhysicalDevice,
this.androidId,
}) : supported32BitAbis = List<String>.unmodifiable(supported32BitAbis),
supported64BitAbis = List<String>.unmodifiable(supported64BitAbis),
supportedAbis = List<String>.unmodifiable(supportedAbis);
/// 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<String> supported32BitAbis;
/// An ordered list of 64 bit ABIs supported by this device.
final List<String> supported64BitAbis;
/// An ordered list of ABIs supported by this device.
final List<String> 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;
/// Deserializes from the message received from [_kChannel].
static AndroidDeviceInfo _fromMap(dynamic message) {
final Map<dynamic, dynamic> map = message;
return AndroidDeviceInfo._(
version: AndroidBuildVersion._fromMap(map['version']),
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'],
);
}
/// Deserializes message as List<String>
static List<String> _fromList(dynamic message) {
final List<dynamic> list = message;
return List<String>.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; its possible values are defined in [AndroidBuildVersionCodes].
final int sdkInt;
/// The user-visible security patch level.
final String securityPatch;
/// Deserializes from the map message received from [_kChannel].
static AndroidBuildVersion _fromMap(dynamic message) {
final Map<dynamic, dynamic> map = message;
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(dynamic message) {
final Map<dynamic, dynamic> map = message;
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']),
);
}
}
/// 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(dynamic message) {
final Map<dynamic, dynamic> map = message;
return IosUtsname._(
sysname: map['sysname'],
nodename: map['nodename'],
release: map['release'],
version: map['version'],
machine: map['machine'],
);
}
}