8

Is there any way to detect that device is running Android Go edition? Need to determine if device is capable of providing SYSTEM_ALERT_WINDOW since API 29.

According the reference, Settings.canDrawOverlays(Context context) will always return false on API 29 Go. Without knowing if the system is possible to give access to SYSTEM_ALERT_WINDOW it's hard to work around the case.

Orange
  • 553
  • 3
  • 20

3 Answers3

9
ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
am.isLowRamDevice();

The following code is available in ActivityManager.java

    /**
     * Returns true if this is a low-RAM device.  Exactly whether a device is low-RAM
     * is ultimately up to the device configuration, but currently it generally means
     * something with 1GB or less of RAM.  This is mostly intended to be used by apps
     * to determine whether they should turn off certain features that require more RAM.
     */
    public boolean isLowRamDevice() {
        return isLowRamDeviceStatic();
    }
Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167
greywolf82
  • 21,813
  • 18
  • 54
  • 108
  • Thank you, will try! Possibly, do you know any way to emulate an Android Go device, also? – Orange Oct 12 '19 at 10:29
  • I tried setting an emulator to 1GB of ram, and `am.isLowRamDevice()` returned `false`, which is interesting. – Ben Butterworth Sep 23 '20 at 14:17
  • And Orange, there are no Android Go emulators available yet, unfortunately – Ben Butterworth Sep 23 '20 at 14:19
  • 1
    It doesn't seem the documentation is explicit that all Android Go devices are also isLowRamDevice() == true. Although I know of at least one that is. Anyone find any evidence of this? – Nick Oct 22 '20 at 22:21
4

You can refer to the implementation of the Android 11 source code. It only uses ActivityManager.isLowRamDevice() to check if the SYSTEM_ALERT_WINDOW permission is available.

packages\apps\Settings\src\com\android\settings\Utils.java

/**
 * Returns true if SYSTEM_ALERT_WINDOW permission is available.
 * Starting from Q, SYSTEM_ALERT_WINDOW is disabled on low ram phones.
 */
public static boolean isSystemAlertWindowEnabled(Context context) {
    // SYSTEM_ALERT_WINDOW is disabled on on low ram devices starting from Q
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    return !(am.isLowRamDevice() && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q));
}
Sam Lu
  • 3,448
  • 1
  • 27
  • 39
2

You can simply query PackageManager to check if one of the Android GO preloaded apps is installed, as they have different package names. For example:

Gmail Go package name: "com.google.android.gm.lite"

Regular Gmail package name: "com.google.android.gm"

fun isGoDevice(): Boolean {
    val GMAIL_GO_PACKAGE_NAME = "com.google.android.gm.lite"
    val packageManager = context.getPackageManager()
    return try {
        packageManager.getPackageInfo(GMAIL_GO_PACKAGE_NAME, 0)
        true
    } catch (e: PackageManager.NameNotFoundException) {
        false
    }
}
Rotem Matityahu
  • 325
  • 5
  • 16
  • 1
    This isn't a foolproof method though, not all Android Go devices necessarily have the "Go version" of the system apps. The user may also have uninstalled the Gmail app, triggering a false negative. – Naftoli Ost Dec 22 '21 at 21:35