This repository has been 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.8k
[device_info] Support v2 android embedder. #2163
Merged
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
952b5d0
draft
ead4e1e
migrate device_info
5c8ebe7
refactor
6c96b7a
rename activities
e587caa
move handler non-publick
5597833
Update MainActivity.java
af6f345
fix gradle
05d9709
review fixes
2dd9444
e2e tests
5fee116
Update CHANGELOG.md
727a3b6
Update MainActivity.java
835793a
remove android x
b7e025a
Update CHANGELOG.md
f3dc369
place test files at the corret place
7d4c91c
Merge branch 'migrate_device_info' of github.com:cyanglaz/plugins int…
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
This file contains 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
116 changes: 116 additions & 0 deletions
116
...evice_info/android/src/main/java/io/flutter/plugins/deviceinfo/MethodCallHandlerImpl.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// 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. | ||
|
||
package io.flutter.plugins.deviceinfo; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.ContentResolver; | ||
import android.os.Build; | ||
import android.provider.Settings; | ||
import androidx.annotation.NonNull; | ||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* The implementation of {@link MethodChannel.MethodCallHandler} for the plugin. Responsible for | ||
* receiving method calls from method channel. | ||
*/ | ||
public class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this class default (package-private) so that we don't need to worry about breaking other clients who may be using it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
private ContentResolver contentResolver; | ||
|
||
/** Substitute for missing values. */ | ||
private static final String[] EMPTY_STRING_LIST = new String[] {}; | ||
|
||
/** Constructs DeviceInfo. The {@code contentResolver} must not be null. */ | ||
public MethodCallHandlerImpl(@NonNull ContentResolver contentResolver) { | ||
this.contentResolver = contentResolver; | ||
} | ||
|
||
@Override | ||
public void onMethodCall(MethodCall call, MethodChannel.Result result) { | ||
if (call.method.equals("getAndroidDeviceInfo")) { | ||
Map<String, Object> build = new HashMap<>(); | ||
build.put("board", Build.BOARD); | ||
build.put("bootloader", Build.BOOTLOADER); | ||
build.put("brand", Build.BRAND); | ||
build.put("device", Build.DEVICE); | ||
build.put("display", Build.DISPLAY); | ||
build.put("fingerprint", Build.FINGERPRINT); | ||
build.put("hardware", Build.HARDWARE); | ||
build.put("host", Build.HOST); | ||
build.put("id", Build.ID); | ||
build.put("manufacturer", Build.MANUFACTURER); | ||
build.put("model", Build.MODEL); | ||
build.put("product", Build.PRODUCT); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
build.put("supported32BitAbis", Arrays.asList(Build.SUPPORTED_32_BIT_ABIS)); | ||
build.put("supported64BitAbis", Arrays.asList(Build.SUPPORTED_64_BIT_ABIS)); | ||
build.put("supportedAbis", Arrays.asList(Build.SUPPORTED_ABIS)); | ||
} else { | ||
build.put("supported32BitAbis", Arrays.asList(EMPTY_STRING_LIST)); | ||
build.put("supported64BitAbis", Arrays.asList(EMPTY_STRING_LIST)); | ||
build.put("supportedAbis", Arrays.asList(EMPTY_STRING_LIST)); | ||
} | ||
build.put("tags", Build.TAGS); | ||
build.put("type", Build.TYPE); | ||
build.put("isPhysicalDevice", !isEmulator()); | ||
build.put("androidId", getAndroidId()); | ||
|
||
Map<String, Object> version = new HashMap<>(); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
version.put("baseOS", Build.VERSION.BASE_OS); | ||
version.put("previewSdkInt", Build.VERSION.PREVIEW_SDK_INT); | ||
version.put("securityPatch", Build.VERSION.SECURITY_PATCH); | ||
} | ||
version.put("codename", Build.VERSION.CODENAME); | ||
version.put("incremental", Build.VERSION.INCREMENTAL); | ||
version.put("release", Build.VERSION.RELEASE); | ||
version.put("sdkInt", Build.VERSION.SDK_INT); | ||
build.put("version", version); | ||
|
||
result.success(build); | ||
} else { | ||
result.notImplemented(); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the Android hardware device ID that is unique between the device + user and app | ||
* signing. This key will change if the app is uninstalled or its data is cleared. Device factory | ||
* reset will also result in a value change. | ||
* | ||
* @return The android ID | ||
*/ | ||
@SuppressLint("HardwareIds") | ||
private String getAndroidId() { | ||
return Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID); | ||
} | ||
|
||
/** | ||
* A simple emulator-detection based on the flutter tools detection logic and a couple of legacy | ||
* detection systems | ||
*/ | ||
private boolean isEmulator() { | ||
return (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")) | ||
|| Build.FINGERPRINT.startsWith("generic") | ||
|| Build.FINGERPRINT.startsWith("unknown") | ||
|| Build.HARDWARE.contains("goldfish") | ||
|| Build.HARDWARE.contains("ranchu") | ||
|| Build.MODEL.contains("google_sdk") | ||
|| Build.MODEL.contains("Emulator") | ||
|| Build.MODEL.contains("Android SDK built for x86") | ||
|| Build.MANUFACTURER.contains("Genymotion") | ||
|| Build.PRODUCT.contains("sdk_google") | ||
|| Build.PRODUCT.contains("google_sdk") | ||
|| Build.PRODUCT.contains("sdk") | ||
|| Build.PRODUCT.contains("sdk_x86") | ||
|| Build.PRODUCT.contains("vbox86p") | ||
|| Build.PRODUCT.contains("emulator") | ||
|| Build.PRODUCT.contains("simulator"); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -4,12 +4,20 @@ | |
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
<application android:name="io.flutter.app.FlutterApplication" android:label="device_info_example" android:icon="@mipmap/ic_launcher"> | ||
<activity android:name="io.flutter.plugins.deviceinfoexample.MainActivity" | ||
<activity android:name=".EmbeddingV1Activity" | ||
android:launchMode="singleTop" | ||
android:theme="@android:style/Theme.Black.NoTitleBar" | ||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection" | ||
android:hardwareAccelerated="true" | ||
android:exported="true" | ||
android:windowSoftInputMode="adjustResize"> | ||
</activity> | ||
<activity android:name=".MainActivity" | ||
android:launchMode="singleTop" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a comment about |
||
android:theme="@android:style/Theme.Black.NoTitleBar" | ||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection" | ||
android:hardwareAccelerated="true" | ||
android:windowSoftInputMode="adjustResize"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
|
17 changes: 17 additions & 0 deletions
17
...e/android/app/src/main/java/io/flutter/plugins/deviceinfoexample/EmbeddingV1Activity.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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. | ||
|
||
package io.flutter.plugins.deviceinfoexample; | ||
|
||
import android.os.Bundle; | ||
import io.flutter.app.FlutterActivity; | ||
import io.flutter.plugins.GeneratedPluginRegistrant; | ||
|
||
public class EmbeddingV1Activity extends FlutterActivity { | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
GeneratedPluginRegistrant.registerWith(this); | ||
} | ||
} |
16 changes: 6 additions & 10 deletions
16
.../example/android/app/src/main/java/io/flutter/plugins/deviceinfoexample/MainActivity.java
This file contains 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 |
---|---|---|
@@ -1,17 +1,13 @@ | ||
// 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. | ||
|
||
package io.flutter.plugins.deviceinfoexample; | ||
|
||
import android.os.Bundle; | ||
import io.flutter.app.FlutterActivity; | ||
import io.flutter.plugins.GeneratedPluginRegistrant; | ||
import io.flutter.embedding.android.FlutterActivity; | ||
import io.flutter.embedding.engine.FlutterEngine; | ||
import io.flutter.plugins.deviceinfo.DeviceInfoPlugin; | ||
|
||
public class MainActivity extends FlutterActivity { | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
GeneratedPluginRegistrant.registerWith(this); | ||
public void configureFlutterEngine(FlutterEngine flutterEngine) { | ||
super.configureFlutterEngine(flutterEngine); | ||
flutterEngine.getPlugins().add(new DeviceInfoPlugin()); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1 +1,4 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
android.enableR8=true | ||
android.useAndroidX=true | ||
android.enableJetifier=true |
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.
Recommendation: consider defining a
teardownMethodChannel()
for symmetry withsetupMethodChannel()
.