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)

I use this method to grant permission which is declared in manifest it work fine with standard permissions but using ACTION_MANAGE_OVERLAY_PERMISSION and ACTION_USAGE_ACCESS_SETTINGS for both it’s not working please suggest me what i can do?

This are action names, not permission names.
You can use these names for launch intents to open the appropriate system settings dialogs.

Use permission “SYSTEM_ALERT_WINDOW” for drawing over other apps and “PACKAGE_USAGE_STATS” for accessing usage statistics.

1 Like

Yes, I have declared SYSTEM_ALERT_WINDOW and PACKAGE_USAGE_STATS in the manifest, but this method Public int grantPermissions (String packageName, ArrayList permissions) doesn’t work for these permissions.
It only works for standard app permissions, like android.permission.CAMERA,android.permission.READ_CONTACTS etc.

Can you tell me how to enable special access permission without asking the user manually?

1 Like

There is no general way to get these permissions without user interaction - at least for standard applications.

Maybe Datalogic is able to extend the “grantPermissions()” API method for these runtime permissions in a future SDK release :wink:

2 Likes

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