How to detect Android Go?

Viewed 2075

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.

3 Answers
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();
    }

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));
}

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
    }
}
Related