How to grant `android.permission.WRITE_SETTINGS` to `com.termux.api` on One UI? I tried:

```bash
adb shell pm grant com.termux.api android.permission.WRITE_SETTINGS
```
```

Exception occurred while executing 'grant':
java.lang.SecurityException: Permission android.permission.WRITE_SETTINGS is managed by role
at com.android.server.permission.access.permission.PermissionService.access$setRuntimePermissionGranted(qb/112078060 0c34881cc0eb1448ef84494ffd84e7895f8ca1a512a6d95529948e34e73d349b:107)
at com.android.server.permission.access.permission.PermissionService.setRuntimePermissionGranted$default(qb/112078060 0c34881cc0eb1448ef84494ffd84e7895f8ca1a512a6d95529948e34e73d349b:287)
at com.android.server.permission.access.permission.PermissionService.grantRuntimePermission(qb/112078060 0c34881cc0eb1448ef84494ffd84e7895f8ca1a512a6d95529948e34e73d349b:10)
at com.android.server.pm.permission.PermissionManagerService.grantRuntimePermission(qb/112078060 0c34881cc0eb1448ef84494ffd84e7895f8ca1a512a6d95529948e34e73d349b:3)
at android.permission.PermissionManager.grantRuntimePermissionInternal(PermissionManager.java:682)
at android.permission.PermissionManager.grantRuntimePermission(PermissionManager.java:645)
at com.android.server.pm.PackageManagerShellCommand.runGrantRevokePermission(qb/112078060 0c34881cc0eb1448ef84494ffd84e7895f8ca1a512a6d95529948e34e73d349b:266)
at com.android.server.pm.PackageManagerShellCommand.onCommand(qb/112078060 0c34881cc0eb1448ef84494ffd84e7895f8ca1a512a6d95529948e34e73d349b:1742)
at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
at android.os.ShellCommand.exec(ShellCommand.java:38)
at com.android.server.pm.PackageManagerService$IPackageManagerImpl.onShellCommand(qb/112078060 0c34881cc0eb1448ef84494ffd84e7895f8ca1a512a6d95529948e34e73d349b:23)
at android.os.Binder.shellCommand(Binder.java:1187)
at android.os.Binder.onTransact(Binder.java:979)
at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:5306)
at com.android.server.pm.PackageManagerService$IPackageManagerImpl.onTransact(qb/112078060 0c34881cc0eb1448ef84494ffd84e7895f8ca1a512a6d95529948e34e73d349b:1)
at android.os.Binder.execTransactInternal(Binder.java:1462)
at android.os.Binder.execTransact(Binder.java:1401)
```
Aug 1, 10:44pm

The error you're encountering indicates that the android.permission.WRITE_SETTINGS permission is managed by a role on One UI (Samsung's Android skin). This means you cannot grant it directly via ADB for com.termux.api or any other app. Instead, you must assign the app to a role that includes this permission.


How to Grant WRITE_SETTINGS on One UI

Method 1: Use ADB to Assign a Role

One UI restricts WRITE_SETTINGS to apps assigned to the "Settings Manager" role. You can assign this role to com.termux.api using ADB:

  1. Check available roles (optional):

    bash
    adb shell dpm list-roles

    Look for android.app.role.SETTINGS_MANAGER or similar.

  2. Assign the role to Termux:API:

    bash
    adb shell dpm set-role-holder com.termux.api android.app.role.SETTINGS_MANAGER

    If this fails, try:

    bash
    adb shell dpm set-role-holder com.termux.api android.app.role.WRITE_SETTINGS
  3. Verify the role assignment:

    bash
    adb shell dpm get-role-holders android.app.role.SETTINGS_MANAGER

Method 2: Manually Enable in Settings (No Root)

If ADB fails, try enabling it manually:

  1. Open Settings > Apps.

  2. Tap the three-dot menu > Special Access > Write system settings.

  3. Enable com.termux.api (Termux:API) in the list.

    (Note: This path may vary slightly depending on your One UI version.)

Method 3: Use Shizuku (Alternative)

If the above fails, use Shizuku to grant the permission via ADB:

  1. Install Shizuku and start it via ADB.
  2. Use an app like App Ops to enable WRITE_SETTINGS for Termux:API.

Why This Happens

  • One UI (and some other OEMs) restrict sensitive permissions like WRITE_SETTINGS to roles for security.
  • The pm grant command fails because the permission is not a runtime permission but a role-managed permission.

Next Steps

Try Method 1 first. If it doesn’t work, check if com.termux.api appears in the Special Access menu (Method 2).

Aug 1, 10:44pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more