yegetshalaay
yegetshalaay

Reputation: 21

"java.lang.SecurityException: Attempt to remove non-test admin" while trying to remove device admin

i can't remove device owner from my Android 12.1 device.

When i use dpm list-owners while in adb shell, i get this output: 1 owner:\n User 0: admin=package.name/app.receivers.DeviceAdminReceiver,DeviceOwner,Affiliated and when i use dpm remove-active-admin package.name/app.receivers.DeviceAdminReceiver in adb shell, i get this output:

Exception occurred while executing 'remove-active-admin':
java.lang.SecurityException: Attempt to remove non-test admin ComponentInfo{package.name/app.receivers.DeviceAdminReceiver} 0
        at com.android.server.devicepolicy.DevicePolicyManagerService.lambda$forceRemoveActiveAdmin$9$DevicePolicyManagerService(DevicePolicyManagerService.java:3712)
        at com.android.server.devicepolicy.DevicePolicyManagerService$$ExternalSyntheticLambda20.runOrThrow(Unknown Source:6)
        at android.os.Binder.withCleanCallingIdentity(Binder.java:390)
        at com.android.server.devicepolicy.DevicePolicyManagerService$Injector.binderWithCleanCallingIdentity(DevicePolicyManagerService.java:1554)
        at com.android.server.devicepolicy.DevicePolicyManagerService.forceRemoveActiveAdmin(DevicePolicyManagerService.java:3708)
        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:9818)
        at android.os.Binder.shellCommand(Binder.java:950)
        at android.os.Binder.onTransact(Binder.java:834)
        at android.app.admin.IDevicePolicyManager$Stub.onTransact(IDevicePolicyManager.java:6980)
        at android.os.Binder.execTransactInternal(Binder.java:1184)
        at android.os.Binder.execTransact(Binder.java:1143)

I also tried disabling device management apps from security in settings, but disabling text is also greyed out. What should i do?

Upvotes: 2

Views: 996

Answers (1)

Mohsen Abedini
Mohsen Abedini

Reputation: 184

add this line to android manifest application tag:

android:testOnly="true"

like this:

 <application
        android:name=".presentation.DpcApplication"
        android:icon="@mipmap/ic_launcher"
        android:testOnly="${testOnly}"/>

and in build.gradle:

 buildTypes {
        debug {
            isDebuggable = true
            defaultConfig {
                manifestPlaceholders["testOnly"] = "true"
            }
        }
        release {
            isDebuggable = false
            defaultConfig {
                manifestPlaceholders["testOnly"] = "false"
            }
            isMinifyEnabled = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
            signingConfig = signingConfigs.getByName("debug")
        }
    }

dont use android:testOnly="true" in production, this cause of failure in QrCode provisioning

Upvotes: 1

Related Questions