This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[device_info_platform_interface] handle null value from method channel #3609
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6e9e671
migrate platform interface
9ba17a7
fix nullable types
c389a6a
format
a9f0a0a
revert test code in device info
c6a15a8
revert test code
7b5658b
Merge branch 'master' into nnbd_device_info
fefc6db
some cleanup
f69f03e
Merge branch 'nnbd_device_info' of github.com:cyanglaz/plugins into n…
dedd740
review
3d351f1
add docs to explain empty value
d7a8a6f
Update packages/device_info/device_info_platform_interface/test/metho…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 1 addition & 8 deletions
9
packages/device_info/device_info_platform_interface/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,34 +113,40 @@ class AndroidDeviceInfo { | |
| /// Deserializes from the message received from [_kChannel]. | ||
| static AndroidDeviceInfo fromMap(Map<String, dynamic> map) { | ||
| return AndroidDeviceInfo( | ||
| version: | ||
| AndroidBuildVersion._fromMap(map['version']!.cast<String, dynamic>()), | ||
| 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']!), | ||
| version: AndroidBuildVersion._fromMap(map['version'] != null | ||
| ? map['version'].cast<String, dynamic>() | ||
| : <String, dynamic>{}), | ||
| 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'] ?? false, | ||
| androidId: map['androidId'] ?? '', | ||
| systemFeatures: _fromList(map['systemFeatures']), | ||
| ); | ||
| } | ||
|
|
||
| /// Deserializes message as List<String> | ||
| static List<String> _fromList(dynamic message) { | ||
| final List<dynamic> list = message; | ||
| if (message == null) { | ||
| return <String>[]; | ||
| } | ||
| assert(message is List<dynamic>); | ||
| final List<dynamic> list = List<dynamic>.from(message) | ||
| ..removeWhere((value) => value == null); | ||
| return List<String>.from(list); | ||
|
||
| } | ||
| } | ||
|
|
@@ -192,10 +198,10 @@ class AndroidBuildVersion { | |
| baseOS: map['baseOS'], | ||
| previewSdkInt: map['previewSdkInt'], | ||
| securityPatch: map['securityPatch'], | ||
| codename: map['codename']!, | ||
| incremental: map['incremental']!, | ||
| release: map['release']!, | ||
| sdkInt: map['sdkInt']!, | ||
| codename: map['codename'] ?? '', | ||
| incremental: map['incremental'] ?? '', | ||
| release: map['release'] ?? '', | ||
| sdkInt: map['sdkInt'] ?? -1, | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty string means that there's a bug on the platform side right? I think we should have a tracking bug to address this with Pigeon, and add TODOs. We should really try to fix this with Pigeon because I can see this being a source of bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it have anything to do with Pigeon? This plugin doesn't use pigeon.
Anyways, from dart perspective, we should always assume the method channel could return null. Even the native API doesn't return null now, it could in the future as we don't use null safe language on native side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I was referring to the Dart API. If the empty string is documented on the Android official website, then it's correct to provide empty string values. The point about Pigeon is about making this enforcement more explicit upstream, so you don't have to manually deal with it in Dart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean when we eventually migrate this plugin to pigeon?
It's not documented. I also don't want to make everything nullable either. I think in a null safe language, it is usually the case that we don't want to make a string nullable if empty string doesn't have a specific meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, eventual migration. The suggestion is to look at the official documentation for explicit mentions of "null". For example, the bug that Jason was fixing in Java. https://developer.android.com/reference/android/content/pm/FeatureInfo#name The docs explicitly say that it can be
null.I think that is the type of work that will match the intended behavior of the platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the properties in the documentation doesn't say it is nullable or non-null. See https://developer.android.com/reference/kotlin/android/os/Build
So since they are strings, I'd prefer making them non-null and empty string for "no value" on dart side.