Skip to content

Commit

Permalink
feat(device_info_plus): Add isLowRamDevice property to AndroidDeviceI…
Browse files Browse the repository at this point in the history
…nfo (#2765)

Co-authored-by: K. P. Krasiński-Sroka <kpsroka@users.noreply.github.com>
  • Loading branch information
muhib349 and kpsroka committed Mar 29, 2024
1 parent d21f285 commit 1376b03
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
@@ -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)
}
}
@@ -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
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
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
Expand Up @@ -37,4 +37,5 @@ const _fakeAndroidDeviceInfo = <String, dynamic>{
'supported64BitAbis': _fakeSupported64BitAbis,
'supported32BitAbis': _fakeSupported32BitAbis,
'serialNumber': 'SERIAL',
'isLowRamDevice': false,
};
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

0 comments on commit 1376b03

Please sign in to comment.