Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(device_info_plus): Add isLowRamDevice property to AndroidDeviceInfo #2765

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.fluttercommunity.plus.device_info

import android.app.ActivityManager
import android.content.Context
import android.content.pm.PackageManager
import android.view.WindowManager
Expand All @@ -23,7 +24,8 @@ class DeviceInfoPlusPlugin : FlutterPlugin {
private fun setupMethodChannel(messenger: BinaryMessenger, context: Context) {
methodChannel = MethodChannel(messenger, "dev.fluttercommunity.plus/device_info")
val packageManager: PackageManager = context.packageManager
val handler = MethodCallHandlerImpl(packageManager)
val activityManager: ActivityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val handler = MethodCallHandlerImpl(packageManager, activityManager)
methodChannel.setMethodCallHandler(handler)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.fluttercommunity.plus.device_info

import android.app.ActivityManager
import android.content.pm.FeatureInfo
import android.content.pm.PackageManager
import android.os.Build
Expand All @@ -17,6 +18,7 @@ import kotlin.collections.HashMap
*/
internal class MethodCallHandlerImpl(
private val packageManager: PackageManager,
private val activityManager: ActivityManager,
) : MethodCallHandler {

override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
Expand Down Expand Up @@ -62,7 +64,7 @@ internal class MethodCallHandlerImpl(
version["release"] = Build.VERSION.RELEASE
version["sdkInt"] = Build.VERSION.SDK_INT
build["version"] = version

build["isLowRamDevice"] = activityManager.isLowRamDevice
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
build["serialNumber"] = try {
Build.getSerial()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class _MyAppState extends State<MyApp> {
'isPhysicalDevice': build.isPhysicalDevice,
'systemFeatures': build.systemFeatures,
'serialNumber': build.serialNumber,
'isLowRamDevice': build.isLowRamDevice,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AndroidDeviceInfo extends BaseDeviceInfo {
required this.isPhysicalDevice,
required List<String> systemFeatures,
required this.serialNumber,
required this.isLowRamDevice,
}) : supported32BitAbis = List<String>.unmodifiable(supported32BitAbis),
supported64BitAbis = List<String>.unmodifiable(supported64BitAbis),
supportedAbis = List<String>.unmodifiable(supportedAbis),
Expand Down Expand Up @@ -136,6 +137,9 @@ class AndroidDeviceInfo extends BaseDeviceInfo {
/// https://developer.android.com/reference/android/os/Build#getSerial()
final String serialNumber;

/// `true` if the application is running on a low-RAM device, `false` otherwise.
final bool isLowRamDevice;

/// Deserializes from the message received from [_kChannel].
static AndroidDeviceInfo fromMap(Map<String, dynamic> map) {
return AndroidDeviceInfo._(
Expand All @@ -162,6 +166,7 @@ class AndroidDeviceInfo extends BaseDeviceInfo {
isPhysicalDevice: map['isPhysicalDevice'],
systemFeatures: _fromList(map['systemFeatures'] ?? []),
serialNumber: map['serialNumber'],
isLowRamDevice: map['isLowRamDevice'],
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ const _fakeAndroidDeviceInfo = <String, dynamic>{
'supported64BitAbis': _fakeSupported64BitAbis,
'supported32BitAbis': _fakeSupported32BitAbis,
'serialNumber': 'SERIAL',
'isLowRamDevice': false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void main() {
expect(androidDeviceInfo.version.incremental, 'incremental');
expect(androidDeviceInfo.version.securityPatch, 'securityPatch');
expect(androidDeviceInfo.serialNumber, 'SERIAL');
expect(androidDeviceInfo.isLowRamDevice, false);
});

test('toMap should return map with correct key and map', () {
Expand Down
Loading