在单设备上共享设备管理员权限
Android root App App
DevicePolicyManager.DELEGATION
......
dsm-delegation-install-uninstall-app
App API >= 23)
dsm-delegation-set-app-ops
AppOps API >= 28)
implementation 'com.github.heruoxin.Delegated-Scopes-Manager:manager:master-SNAPSHOT'
DeviceAdminReceiver#onEnabled
CenterApp.getInstance(context).refreshState();
App
startActivity(new Intent(CenterApp.ACTION_APP_LIST).setPackage(context.getPackageName()));
implementation 'com.github.heruoxin.Delegated-Scopes-Manager:client:master-SNAPSHOT'
<receiver
android:name="yourAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<!-- -->
<action android:name="android.app.develop.action.DEVICE_DELEGATION" />
</intent-filter>
<meta-data
android:name="android.app.develop.delegation"
android:resource="@xml/app_delegation" />
</receiver>
app_delegation.xml
<?xml version="1.0" encoding="utf-8"?>
<device-delegation>
<uses-policies>
<!-- DevicePolicyManager.DELEGATION_APP_RESTRICTIONS -->
<delegation-app-restrictions />
<!-- SDK dsm- -->
<dsm-delegation-set-app-ops />
</uses-policies>
</device-delegation>
DSMClient.getOwnerSDKVersion(context) >= DSMClient.SDK_VERSION // SDK
String packageName = DSMClient.getOwnerPackageName(context); //
List<String> scopes = DSMClient.getDelegatedScopes(context); //
//
DSMClient.requestScopes(activity, DevicePolicyManager.DELEGATION_ENABLE_SYSTEM_APP, "dsm-delegation-install-uninstall-app", ...);
// `Activity#onActivityResult` `RESULT_OK` `RESULT_CANCEL`
DSMClient#installApp``DSMClient#setAppOpsMode
WTFPL