android-testdpc icon indicating copy to clipboard operation
android-testdpc copied to clipboard

Can not revoke admin to uninstall testdpc

Open scruel opened this issue 1 year ago • 2 comments

$ dpm remove-active-admin com.afwsamples.testdpc/.DeviceAdminReceiver
Exception occurred while executing 'remove-active-admin':
java.lang.SecurityException: Attempt to remove non-test admin ComponentInfo{com.afwsamples.testdpc/com.afwsamples.testdpc.DeviceAdminReceiver} 0
        at com.android.server.devicepolicy.DevicePolicyManagerService.lambda$forceRemoveActiveAdmin$10$com-android-server-devicepolicy-DevicePolicyManagerService(DevicePolicyManagerService.java:3593)
        at com.android.server.devicepolicy.DevicePolicyManagerService$$ExternalSyntheticLambda132.runOrThrow(Unknown Source:6)
        at android.os.Binder.withCleanCallingIdentity(Binder.java:427)
        at com.android.server.devicepolicy.DevicePolicyManagerService$Injector.binderWithCleanCallingIdentity(DevicePolicyManagerService.java:1581)
        at com.android.server.devicepolicy.DevicePolicyManagerService.forceRemoveActiveAdmin(DevicePolicyManagerService.java:3589)
        at com.android.server.devicepolicy.DevicePolicyManagerServiceShellCommand.runRemoveActiveAdmin(DevicePolicyManagerServiceShellCommand.java:280)
        at com.android.server.devicepolicy.DevicePolicyManagerServiceShellCommand.onCommand(DevicePolicyManagerServiceShellCommand.java:93)
        at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
        at android.os.ShellCommand.exec(ShellCommand.java:38)
        at com.android.server.devicepolicy.DevicePolicyManagerService.onShellCommand(DevicePolicyManagerService.java:9900)
        at android.os.Binder.shellCommand(Binder.java:1054)
        at android.os.Binder.onTransact(Binder.java:882)
        at android.app.admin.IDevicePolicyManager$Stub.onTransact(IDevicePolicyManager.java:6054)
        at android.os.Binder.execTransactInternal(Binder.java:1290)
        at android.os.Binder.execTransact(Binder.java:1249)

$ dpm set-device-owner com.afwsamples.testdpc/.DeviceAdminReceiver
Exception occurred while executing 'set-device-owner':
java.lang.IllegalStateException: Trying to set the device owner, but the user already has a profile owner.
        at com.android.server.devicepolicy.DevicePolicyManagerService.enforceCanSetDeviceOwnerLocked(DevicePolicyManagerService.java:9560)
        at com.android.server.devicepolicy.DevicePolicyManagerService.setDeviceOwner(DevicePolicyManagerService.java:8393)
        at com.android.server.devicepolicy.DevicePolicyManagerServiceShellCommand.runSetDeviceOwner(DevicePolicyManagerServiceShellCommand.java:259)
        at com.android.server.devicepolicy.DevicePolicyManagerServiceShellCommand.onCommand(DevicePolicyManagerServiceShellCommand.java:89)
        at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
        at android.os.ShellCommand.exec(ShellCommand.java:38)
        at com.android.server.devicepolicy.DevicePolicyManagerService.onShellCommand(DevicePolicyManagerService.java:9900)
        at android.os.Binder.shellCommand(Binder.java:1054)
        at android.os.Binder.onTransact(Binder.java:882)
        at android.app.admin.IDevicePolicyManager$Stub.onTransact(IDevicePolicyManager.java:6054)
        at android.os.Binder.execTransactInternal(Binder.java:1290)
        at android.os.Binder.execTransact(Binder.java:1249)

scruel avatar Apr 19 '24 09:04 scruel

Clone the code, add a line to the AndroidManifest.xml activity: android:testOnly="true" then patch the android system to bypass signature to install this test packages. now u can use that command.

SteveZMTstudios avatar Jun 25 '24 14:06 SteveZMTstudios

Cause Android Security Policy, you cannot remove an active Device Owner on an untest-status packages. the ways above is only be used when Test DPC cannot open. BUT you can remove the device owner in the Test DPC app.

On device owner selection, click Remove this device owner then press OK.

SteveZMTstudios avatar Jun 25 '24 14:06 SteveZMTstudios