Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@EricEnslen
Copy link
Contributor

@EricEnslen EricEnslen commented Feb 28, 2020

Description

There's a variety of scenarios where checking at runtime which system
features are available is useful. System features are device
capabilities that do not change at runtime (for example, FEATURE_BLUETOOTH
is always present if the device has a bluetooth radio, even if Bluetooth
is presently disabled), so DeviceInfo seems like the right place to put
this.

Related Issues

N/A

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

/// The Android hardware device ID that is unique between the device + user and app signing.
final String androidId;

/// A list of available features, from PackageManager.getSystemAvailableFeatures.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require Flutter apps to know Android specific system feature strings. Would it be possible to expose this as an enum? It would be OK for it to be less generic in the name of making API easier to grok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would create a maintenance headache, and it would restrict the flexibility of the API (unless we also surfaced the strings that don't match to an enum, which would be a bit redundant).

The Android API that this maps to is inherently based on strings. Some of the more common feature strings are surfaced as public constants in PackageManager (see https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS and below) but that list is both regularly updated, and always incomplete. For example, there's manufacturer features like "com.google.android.feature.GOOGLE_EXPERIENCE" that would never be added to the list of string constants in PackageManager, but some app developers may care to check for. For any developer wanting to use this API, it should be a simple effort to figure out which strings they care about, and hardcode them in a simple wrapper around AndroidDeviceInfo.

Copy link
Contributor

@mehmetf mehmetf Mar 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Android API that this maps to is inherently based on strings.

Good to know. In that case, I am OK with this API.

common feature strings are surfaced as public constants

Can we do the same and expose a bunch of const values for common cases that the apps can use?

Flutter developers are not typically familiar with Android and how it works. They might not even know what to google. Ideally, everything they need to know is in the Dart API. If that's not the case, we should improve the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked a bit offline. It would be a lot of constants to add (PackageManager has ~140 public FEATURE_ constants), and they're already available through PackageManager's documentation, so we agreed there's not much value in adding the consts in Dart. Updated the documentation on the dart side to reference PackageManager's documentation where the common strings are available, as well as to caution people against using this API except for in specific circumstances where they have no other option.

There's a variety of scenarios where checking at runtime which system
features are available is useful.  System features are device
capabilities that do not change at runtime (for example, FEATURE_BLUETOOTH
is always present if the device has a bluetooth radio, even if Bluetooth
is presently disabled), so DeviceInfo seems like the right place to put
this.
@mehmetf mehmetf merged commit 958826f into flutter:master Mar 3, 2020
@lidongze91
Copy link
Contributor

lidongze91 commented Mar 5, 2020

We have a breaking change for this PR. It happens when the receiver of the function fromList is null. Could you provide proper checks please?

EdwinRomelta pushed a commit to EdwinRomelta/plugins that referenced this pull request Jun 11, 2020
flutter#2567)

There's a variety of scenarios where checking at runtime which system
features are available is useful.  System features are device
capabilities that do not change at runtime (for example, FEATURE_BLUETOOTH
is always present if the device has a bluetooth radio, even if Bluetooth
is presently disabled), so DeviceInfo seems like the right place to put
this.
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
flutter#2567)

There's a variety of scenarios where checking at runtime which system
features are available is useful.  System features are device
capabilities that do not change at runtime (for example, FEATURE_BLUETOOTH
is always present if the device has a bluetooth radio, even if Bluetooth
is presently disabled), so DeviceInfo seems like the right place to put
this.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants