In my application, which is the device administrator, I need to erase the entire device when the user tries to disable the application administrator function. When the user goes to the settings / Security / Device admins and deactivates the admin application, the dialog box "You want to deactivate" appears first. If the user says yes, then another small dialog appears with the text provided by the AdminReceiver application in onDisableRequested (). If the user then says yes, I want to erase the entire device. How to do it?
I tried everything, looked for answers, did not find real solutions.
What I tried:
- AdminReceiver has an onDisable () function. I tried to erase the device in this function. However, it looks like onDisable () is called after , the admin is disabled. Thus, the application cannot use the wipeData () function at all (a security exception is thrown). I also confirmed that isAdminActive () returns false at this time.
The official documentation does not say this clearly, but it seems that the administrator is already disconnected when onDisable () is called. Therefore, we must erase the device before this time.
AdminReceiver has an onDisableRequested () function that returns a CharSequence. I tried to put another warning window in this function. This crashes because the warning window cannot be called from the context without activity, which seems to be what we have when we are in onDisableRequested ().
AdminReceiver has an onReceive () function, which is called on any events. In this function, again, we are not in the context of activity and cannot present our own dialogues.
I tried to create another action from onReceive (). It works; during onReceive (), when we get ACTION_DISABLE_ADMIN_REQUESTED, the admin is still active and we can erase it. However, the system still presents its own dialog asking the user to deactivate the administrator. If the user says no to our dialog box, but yes in the system dialog box, the administrator will be disconnected and we will not be able to erase it.
In my subclass of DeviceAdminReceiver, I tried the following:
@Override public void onReceive(Context context, Intent intent) { // detect whether disabling is requested? if (intent.getAction().equals(ACTION_DEVICE_ADMIN_DISABLE_REQUESTED)) { confirmWipeDevice(context); } else { super.onReceive(context, intent); } }
In other words, I do not call super.onReceive (), if the action is to disable the administrator. The confirmWipeDevice () function shows another dialog action. This does not show a system dialog to confirm the disconnection of my admin application. However, this does not prevent the application from being turned off!
Android system seems to do the following:
Submit ACTION_DEVICE_ADMIN_DISABLE_REQUESTED to AdminReceiver
Continue to disable the administrator no matter what the administrator application wants to do
If the user cancels the shutdown, a fine; if not, the application is disabled. Unable to disable the application or disable it when disconnected.
The only solution so far is to immediately delete without confirmation when the user wants to disable the admin application. In other words, I can call getManager (). WipeData () immediately in onDisableRequested (). At that time, the administrator is still active, and it works.
It is right? How to erase a device when a user wants to disable the admin application?
android admin
winitzki Feb 15 '12 at 17:39 2012-02-15 17:39
source share