Sever
Sever

Reputation: 2636

Device Administrator password

Is it possible to require a pass-code when the user tries to uncheck the app as an administrator under Settings->Security->Device Administrators?

This would add a roadblock to not easily allow the user to uninstall the app as they would first need to remove the admin privileges from the app (for which they would need to authenticate with a password) and then they could uninstall.

Upvotes: 0

Views: 4009

Answers (3)

RakibulHasan
RakibulHasan

Reputation: 9

@Override
public void onDisabled(Context context, Intent intent) {
    super.onDisabled(context, intent);

    // Lock the device as soon as admin is being disabled
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    devicePolicyManager.lockNow(); // This will lock the device when disabling the admin
}

and in main activity::

// Initialize DevicePolicyManager and ComponentName mDPM = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE); mDeviceAdmin = new ComponentName(this, MyDeviceAdminReceiver.class);

    // Check if the app is a device administrator
    if (mDPM.isAdminActive(mDeviceAdmin)) {
        // If the app is a device admin, display a message and provide a way to disable it
        Toast.makeText(this, "App is a device admin", Toast.LENGTH_SHORT).show();
        // Provide option to disable
        // This would ideally be a button that calls removeDeviceAdmin()
    } else {
        // If the app is not a device admin, display a message and provide a way to enable it
        Toast.makeText(this, "App is not a device admin", Toast.LENGTH_SHORT).show();
        // Provide option to enable
        // This would ideally be a button that calls enableDeviceAdmin()
    }
}



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE_ENABLE_ADMIN) {
        if (resultCode == RESULT_OK) {
            // Successfully added as device admin
            Toast.makeText(this, "Device admin enabled", Toast.LENGTH_SHORT).show();
        } else {
            // Failed to add as device admin
            Toast.makeText(this, "Failed to enable device admin", Toast.LENGTH_SHORT).show();
        }
    } else if (requestCode == REQUEST_CODE_REMOVE_ADMIN) {
        if (resultCode == RESULT_OK) {
            // Successfully removed as device admin
            Toast.makeText(this, "Device admin removed", Toast.LENGTH_SHORT).show();
        } else {
            // Failed to remove device admin
            Toast.makeText(this, "Failed to remove device admin", Toast.LENGTH_SHORT).show();
        }
    }
}

}

i did lock the screen while deactivate is there any system set manual our passowrd

Upvotes: -1

Ray Volkov
Ray Volkov

Reputation: 1


It is possible, but you'd have to employ some pretty sketchy techniques to achieve that. For example, Cerberus has an option called "Protect device admin" which immediately locks your screen and asks for login and password as soon as you tap "Deactivate this device administrator".

I cannot recommend you do this though since it's considered to be malicious behavior. You should use corporate policies instead. AFAIK they've been implemented to newer versions of Android and are not tied to a specific manufacturer.

Upvotes: 0

Pankaj Kumar
Pankaj Kumar

Reputation: 83028

This is not possible AFIK. This is right of user.

You can show a dialog for confirmation about DE-activation of Device Admin, but neither default device admin API gives you a way to show password dialog while DE-activating device admin, nor EDM APIs gives you the permission.

Although EDM APIs gives a way where you can block the DE-activation of Device administrator. So user can not uncheck a particular Device admin.

Upvotes: 2

Related Questions