diff --git a/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.kt b/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.kt index 72775a9eaa..787086a256 100644 --- a/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.kt +++ b/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.kt @@ -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 @@ -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) } } diff --git a/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/MethodCallHandlerImpl.kt b/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/MethodCallHandlerImpl.kt index ff803775fb..bf2a15e44d 100644 --- a/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/MethodCallHandlerImpl.kt +++ b/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/MethodCallHandlerImpl.kt @@ -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 @@ -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) { @@ -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() diff --git a/packages/device_info_plus/device_info_plus/example/lib/main.dart b/packages/device_info_plus/device_info_plus/example/lib/main.dart index e6c177c452..58f4888b3f 100644 --- a/packages/device_info_plus/device_info_plus/example/lib/main.dart +++ b/packages/device_info_plus/device_info_plus/example/lib/main.dart @@ -102,6 +102,7 @@ class _MyAppState extends State { 'isPhysicalDevice': build.isPhysicalDevice, 'systemFeatures': build.systemFeatures, 'serialNumber': build.serialNumber, + 'isLowRamDevice': build.isLowRamDevice, }; } diff --git a/packages/device_info_plus/device_info_plus/lib/src/model/android_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/android_device_info.dart index 56df796a2e..da4e78d56f 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/model/android_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/android_device_info.dart @@ -31,6 +31,7 @@ class AndroidDeviceInfo extends BaseDeviceInfo { required this.isPhysicalDevice, required List systemFeatures, required this.serialNumber, + required this.isLowRamDevice, }) : supported32BitAbis = List.unmodifiable(supported32BitAbis), supported64BitAbis = List.unmodifiable(supported64BitAbis), supportedAbis = List.unmodifiable(supportedAbis), @@ -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 map) { return AndroidDeviceInfo._( @@ -162,6 +166,7 @@ class AndroidDeviceInfo extends BaseDeviceInfo { isPhysicalDevice: map['isPhysicalDevice'], systemFeatures: _fromList(map['systemFeatures'] ?? []), serialNumber: map['serialNumber'], + isLowRamDevice: map['isLowRamDevice'], ); } diff --git a/packages/device_info_plus/device_info_plus/test/model/android_device_info_fake.dart b/packages/device_info_plus/device_info_plus/test/model/android_device_info_fake.dart index 6baae385eb..9286bd5d7d 100644 --- a/packages/device_info_plus/device_info_plus/test/model/android_device_info_fake.dart +++ b/packages/device_info_plus/device_info_plus/test/model/android_device_info_fake.dart @@ -37,4 +37,5 @@ const _fakeAndroidDeviceInfo = { 'supported64BitAbis': _fakeSupported64BitAbis, 'supported32BitAbis': _fakeSupported32BitAbis, 'serialNumber': 'SERIAL', + 'isLowRamDevice': false, }; diff --git a/packages/device_info_plus/device_info_plus/test/model/android_device_info_test.dart b/packages/device_info_plus/device_info_plus/test/model/android_device_info_test.dart index 7c1d272630..bd88344cd2 100644 --- a/packages/device_info_plus/device_info_plus/test/model/android_device_info_test.dart +++ b/packages/device_info_plus/device_info_plus/test/model/android_device_info_test.dart @@ -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', () {