|
| 1 | +// Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +/// Information derived from `android.os.Build`. |
| 6 | +/// |
| 7 | +/// See: https://developer.android.com/reference/android/os/Build.html |
| 8 | +class AndroidDeviceInfo { |
| 9 | + /// Android device Info class. |
| 10 | + AndroidDeviceInfo({ |
| 11 | + this.version, |
| 12 | + this.board, |
| 13 | + this.bootloader, |
| 14 | + this.brand, |
| 15 | + this.device, |
| 16 | + this.display, |
| 17 | + this.fingerprint, |
| 18 | + this.hardware, |
| 19 | + this.host, |
| 20 | + this.id, |
| 21 | + this.manufacturer, |
| 22 | + this.model, |
| 23 | + this.product, |
| 24 | + List<String> supported32BitAbis, |
| 25 | + List<String> supported64BitAbis, |
| 26 | + List<String> supportedAbis, |
| 27 | + this.tags, |
| 28 | + this.type, |
| 29 | + this.isPhysicalDevice, |
| 30 | + this.androidId, |
| 31 | + List<String> systemFeatures, |
| 32 | + }) : supported32BitAbis = List<String>.unmodifiable(supported32BitAbis), |
| 33 | + supported64BitAbis = List<String>.unmodifiable(supported64BitAbis), |
| 34 | + supportedAbis = List<String>.unmodifiable(supportedAbis), |
| 35 | + systemFeatures = List<String>.unmodifiable(systemFeatures); |
| 36 | + |
| 37 | + /// Android operating system version values derived from `android.os.Build.VERSION`. |
| 38 | + final AndroidBuildVersion version; |
| 39 | + |
| 40 | + /// The name of the underlying board, like "goldfish". |
| 41 | + final String board; |
| 42 | + |
| 43 | + /// The system bootloader version number. |
| 44 | + final String bootloader; |
| 45 | + |
| 46 | + /// The consumer-visible brand with which the product/hardware will be associated, if any. |
| 47 | + final String brand; |
| 48 | + |
| 49 | + /// The name of the industrial design. |
| 50 | + final String device; |
| 51 | + |
| 52 | + /// A build ID string meant for displaying to the user. |
| 53 | + final String display; |
| 54 | + |
| 55 | + /// A string that uniquely identifies this build. |
| 56 | + final String fingerprint; |
| 57 | + |
| 58 | + /// The name of the hardware (from the kernel command line or /proc). |
| 59 | + final String hardware; |
| 60 | + |
| 61 | + /// Hostname. |
| 62 | + final String host; |
| 63 | + |
| 64 | + /// Either a changelist number, or a label like "M4-rc20". |
| 65 | + final String id; |
| 66 | + |
| 67 | + /// The manufacturer of the product/hardware. |
| 68 | + final String manufacturer; |
| 69 | + |
| 70 | + /// The end-user-visible name for the end product. |
| 71 | + final String model; |
| 72 | + |
| 73 | + /// The name of the overall product. |
| 74 | + final String product; |
| 75 | + |
| 76 | + /// An ordered list of 32 bit ABIs supported by this device. |
| 77 | + final List<String> supported32BitAbis; |
| 78 | + |
| 79 | + /// An ordered list of 64 bit ABIs supported by this device. |
| 80 | + final List<String> supported64BitAbis; |
| 81 | + |
| 82 | + /// An ordered list of ABIs supported by this device. |
| 83 | + final List<String> supportedAbis; |
| 84 | + |
| 85 | + /// Comma-separated tags describing the build, like "unsigned,debug". |
| 86 | + final String tags; |
| 87 | + |
| 88 | + /// The type of build, like "user" or "eng". |
| 89 | + final String type; |
| 90 | + |
| 91 | + /// `false` if the application is running in an emulator, `true` otherwise. |
| 92 | + final bool isPhysicalDevice; |
| 93 | + |
| 94 | + /// The Android hardware device ID that is unique between the device + user and app signing. |
| 95 | + final String androidId; |
| 96 | + |
| 97 | + /// Describes what features are available on the current device. |
| 98 | + /// |
| 99 | + /// This can be used to check if the device has, for example, a front-facing |
| 100 | + /// camera, or a touchscreen. However, in many cases this is not the best |
| 101 | + /// API to use. For example, if you are interested in bluetooth, this API |
| 102 | + /// can tell you if the device has a bluetooth radio, but it cannot tell you |
| 103 | + /// if bluetooth is currently enabled, or if you have been granted the |
| 104 | + /// necessary permissions to use it. Please *only* use this if there is no |
| 105 | + /// other way to determine if a feature is supported. |
| 106 | + /// |
| 107 | + /// This data comes from Android's PackageManager.getSystemAvailableFeatures, |
| 108 | + /// and many of the common feature strings to look for are available in |
| 109 | + /// PackageManager's public documentation: |
| 110 | + /// https://developer.android.com/reference/android/content/pm/PackageManager |
| 111 | + final List<String> systemFeatures; |
| 112 | + |
| 113 | + /// Deserializes from the message received from [_kChannel]. |
| 114 | + static AndroidDeviceInfo fromMap(Map<String, dynamic> map) { |
| 115 | + return AndroidDeviceInfo( |
| 116 | + version: AndroidBuildVersion._fromMap( |
| 117 | + map['version']?.cast<String, dynamic>() ?? {}), |
| 118 | + board: map['board'], |
| 119 | + bootloader: map['bootloader'], |
| 120 | + brand: map['brand'], |
| 121 | + device: map['device'], |
| 122 | + display: map['display'], |
| 123 | + fingerprint: map['fingerprint'], |
| 124 | + hardware: map['hardware'], |
| 125 | + host: map['host'], |
| 126 | + id: map['id'], |
| 127 | + manufacturer: map['manufacturer'], |
| 128 | + model: map['model'], |
| 129 | + product: map['product'], |
| 130 | + supported32BitAbis: _fromList(map['supported32BitAbis'] ?? []), |
| 131 | + supported64BitAbis: _fromList(map['supported64BitAbis'] ?? []), |
| 132 | + supportedAbis: _fromList(map['supportedAbis'] ?? []), |
| 133 | + tags: map['tags'], |
| 134 | + type: map['type'], |
| 135 | + isPhysicalDevice: map['isPhysicalDevice'], |
| 136 | + androidId: map['androidId'], |
| 137 | + systemFeatures: _fromList(map['systemFeatures'] ?? []), |
| 138 | + ); |
| 139 | + } |
| 140 | + |
| 141 | + /// Deserializes message as List<String> |
| 142 | + static List<String> _fromList(dynamic message) { |
| 143 | + final List<dynamic> list = message; |
| 144 | + return List<String>.from(list); |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +/// Version values of the current Android operating system build derived from |
| 149 | +/// `android.os.Build.VERSION`. |
| 150 | +/// |
| 151 | +/// See: https://developer.android.com/reference/android/os/Build.VERSION.html |
| 152 | +class AndroidBuildVersion { |
| 153 | + AndroidBuildVersion._({ |
| 154 | + this.baseOS, |
| 155 | + this.codename, |
| 156 | + this.incremental, |
| 157 | + this.previewSdkInt, |
| 158 | + this.release, |
| 159 | + this.sdkInt, |
| 160 | + this.securityPatch, |
| 161 | + }); |
| 162 | + |
| 163 | + /// The base OS build the product is based on. |
| 164 | + final String baseOS; |
| 165 | + |
| 166 | + /// The current development codename, or the string "REL" if this is a release build. |
| 167 | + final String codename; |
| 168 | + |
| 169 | + /// The internal value used by the underlying source control to represent this build. |
| 170 | + final String incremental; |
| 171 | + |
| 172 | + /// The developer preview revision of a prerelease SDK. |
| 173 | + final int previewSdkInt; |
| 174 | + |
| 175 | + /// The user-visible version string. |
| 176 | + final String release; |
| 177 | + |
| 178 | + /// The user-visible SDK version of the framework. |
| 179 | + /// |
| 180 | + /// Possible values are defined in: https://developer.android.com/reference/android/os/Build.VERSION_CODES.html |
| 181 | + final int sdkInt; |
| 182 | + |
| 183 | + /// The user-visible security patch level. |
| 184 | + final String securityPatch; |
| 185 | + |
| 186 | + /// Deserializes from the map message received from [_kChannel]. |
| 187 | + static AndroidBuildVersion _fromMap(Map<String, dynamic> map) { |
| 188 | + return AndroidBuildVersion._( |
| 189 | + baseOS: map['baseOS'], |
| 190 | + codename: map['codename'], |
| 191 | + incremental: map['incremental'], |
| 192 | + previewSdkInt: map['previewSdkInt'], |
| 193 | + release: map['release'], |
| 194 | + sdkInt: map['sdkInt'], |
| 195 | + securityPatch: map['securityPatch'], |
| 196 | + ); |
| 197 | + } |
| 198 | +} |
0 commit comments