Home > Enterprise >  Why does Intent.ACTION_MAIN require android.permission.MANAGE_USERS on some devices?
Why does Intent.ACTION_MAIN require android.permission.MANAGE_USERS on some devices?

Time:11-21

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

The above code occasionally throws the following exception:

Class: java.lang.SecurityException
 Stack trace: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.amazon.kindle.otter.oobe/.OobeHomeActivity } from ProcessRecord{bbef452 4630:net.my.app/u0a5} (pid=4630, uid=10005) requires android.permission.MANAGE_USERS
    at android.os.Parcel.createException(Parcel.java:1950)
    at android.os.Parcel.readException(Parcel.java:1918)
    at android.os.Parcel.readException(Parcel.java:1868)
    at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:3755)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1669)
    at android.app.Activity.startActivityForResult(Activity.java:4599)
    at androidx.activity.ComponentActivity.startActivityForResult(SourceFile:2)
    at android.app.Activity.startActivityForResult(Activity.java:4557)
    at androidx.activity.ComponentActivity.startActivityForResult(SourceFile:1)
    at android.app.Activity.startActivity(Activity.java:4918)
    at android.app.Activity.startActivity(Activity.java:4886)

This is the case only on a small number of devices. Could anyone shed some light on this?

CodePudding user response:

The activity that you are trying to start is com.amazon.kindle.otter.oobe/.OobeHomeActivity.

A quick search engine lookup suggests that "otter" was the first-generation Kindle Fire. That may not be accurate, in that you believe this device runs Android 9, and that Fire is a ten-year-old device. So, already, this scenario is weird.

If this truly is an Amazon Fire device of some form, they are not governed by the Compatibility Definition Document (CDD) that controls manufacturers that wish to ship the Play Store and Play Services. So, there is no requirement that they have a launcher that is available through an ACTION_MAIN/CATEGORY_HOME Intent, or one that can be started by arbitrary apps.

In this specific case, com.amazon.kindle.otter.oobe/.OobeHomeActivity feels like a one-time "out of box experience" activity, not a real launcher. Why this device has that tied to ACTION_MAIN/CATEGORY_HOME is unclear.

If you are not doing so already, wrap your startActivity() call in a try/catch, so the SecurityException does not crash your app. If you are distributing your app through the Amazon AppStore for Android, you might see if they have documentation for a Fire-specific Intent for getting to the launcher. Otherwise, you will have to settle for "gracefully degrading" when this situation occurs.

  • Related