Public int grantPermissions (String packageName, ArrayList<String> permissions) method doesn't work for display over other app and ACTION_USAGE_ACCESS_SETTINGS permission (+ AppOps permissions)

Hello,

Permission like SYSTEM_ALERT_WINDOW, PACKAGE_USAGE_STATS, MANAGE_EXTERNAL_STORAGE and many others, are part of a set of special signature-level permissions shown under:
Settings → Apps & Notifications → Advanced → Special App Access .
Those permission are not directly managed by the Package Manager (pm), but by Application Operation (appops), a secondary framework for controlling permissions. To either deny or allow an “AppOps” permission for an app, you can do it - for testing - through adb:

adb shell appops set [--uid] <PackageName> <PermissionName> ignore
adb shell appops set [--uid] <PackageName> <PermissionName> deny
adb shell appops set [--uid] <PackageName> <PermissionName> allow

These SHELL commands are strictly controlled by the Android, and by default neither Third Party app or even System app can invoke a shell command interacting with the Appops framework (only ADB is allowed).

In deploying apps in enterprise environments this could be a limitation.
Starting with firmware versions that include SDK v1.34.4 (see “Supported Devices” compatibility table in SDK documentation), Datalogic whitelisted Scan2Deploy Agent so that it can execute the command through script.

This is an example on how to allow the “MANAGE_EXTERNAL_STORAGE appops” to a package using a script of Datalogic Scan2Deploy Studio:
Select “SHELL” then add:

 appops set --uid <PackageName> MANAGE_EXTERNAL_STORAGE  allow

This is the list of devices and firmware that already (September 22nd, 2023) include SDK 1.34.4:

  • Skorpio X5 Android 11: fw3.21.001 released on 2023-08-28 | SDK 1.34.4
  • Memor 20 Android 11: fw3.22.001 released on 2023-08-28 | SDK 1.34.4
  • Memor 11 Android 11: fw1.03. 07 released on 2023-09-31 | SDK 1.34.6

JoyaTouch 22** Android 11 will include SDK 1.34.4 on the first available FW release.

@Richard_Venderbosch, @Bharat_Kumawat, we were listening to you! :wink:

Simone Callegari
Mobile Products L3 Specialist - SW Engineer | Datalogic

See also:
https://developer.android.com/reference/android/app/AppOpsManager

2 Likes