如何消灭Android设备时,设备管理员停用? [英] How to wipe Android device when device admin is deactivated?

查看:567
本文介绍了如何消灭Android设备时,设备管理员停用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,这是一个设备管理员,我需要当用户试图关闭应用程序的管理功能来擦拭整个设备。当用户进入设置/安全/设备管理员和停用管理应用程序,首先一个对话框是presented是否要取消。如果用户说是,那么另外一个小对话框是presented,以()的onDisableRequested提供的应用程序的AdminReceiver文本。如果用户接着说是,我要消灭整个设备。如何做到这一点?

In my application, which is a device admin, I need to wipe the entire device when the user tries to deactivate the admin function of the application. When the user goes to Settings / Security / Device admins and deactivates the admin app, first a dialog is presented "Do you want to deactivate". If the user says "yes", then another small dialog is presented, with the text provided by the application's AdminReceiver in onDisableRequested(). If the user then says "yes", I want to wipe the entire device. How to accomplish this?

我什么都试过,寻找长期的答案,发现没有真正的解决方案。

I tried everything, searched long for answers, found no real solutions.

我的尝试:

  • AdminReceiver有一个函数禁止接通()。我试图擦除设备中的功能。然而,似乎禁止接通()被调用的管理员已被禁用。因此,应用程序不能在所有使用wipeData()函数(安全异常)。我也验证了isAdminActive()返回false在那个时候。

正式文件并没有说这分明,但似乎管理员已被禁用时,禁止接通()被调用。因此,我们必须在该时间之前擦除设备。

Official documentation does not say this clearly, but it seems that the admin is already disabled when onDisable() is called. Thus we have to wipe the device before that time.

  • AdminReceiver有onDisableRequested一个()的函数,它返回的CharSequence。我试图把另一个警告框,在该功能。这种崩溃是因为一个警告框不能从一个非活动的背景下,这似乎是我们所拥有的,当我们在onDisableRequested()调用。

  • AdminReceiver has a function onDisableRequested(), which returns CharSequence. I tried to put another alert box in that function. This crashes because an alert box cannot be called from a non-activity context, which seems to be what we have when we are in onDisableRequested().

AdminReceiver有一个函数的onReceive(),它被调用的任何事件。在此功能中,再次,我们是不是在一个活动环境中,无法present我们自己的对话框。

AdminReceiver has a function onReceive(), which gets called on any events. In this function, again, we are not in an activity context and cannot present our own dialogs.

我试图创建从的onReceive另一个活动()。这工作;的onReceive()期间,当我们得到ACTION_DISABLE_ADMIN_REQUESTED,管理员仍处于活动状态,我们可以擦除设备。但是,系统仍然presents自己的对话框,询问是否要禁用管理员用户。如果用户说,没有我们的对话,但肯定的系统对话框,管理员将失效,我们将无法擦除设备。

I tried creating another activity from onReceive(). This works; during onReceive() when we get ACTION_DISABLE_ADMIN_REQUESTED, the admin is still active and we can wipe the device. However, the system still presents its own dialog asking the user whether to deactivate the admin. If the user says no to our dialog but yes to the system dialog, the admin will be deactivated and we will have failed to wipe the device.

我试了下,在我的DeviceAdminReceiver的子类:

I tried the following, in my subclass of DeviceAdminReceiver:

@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);
 }      
}

换句话说,我不叫super.onReceive()如果动作是禁用的管理员。函数confirmWipeDevice()示出了具有对话不同的活性。这个不显示系统对话框用于确认我的管理应用的禁用。但是,这并不prevent应用程序被禁用的实际!

In other words, I do not call super.onReceive() if the action is to disable the admin. The function confirmWipeDevice() shows a different activity with a dialog. This does not show the system dialog for confirming the disabling of my admin app. However, this does not prevent the app from being actually disabled!

看来,Android系统将执行以下操作:

It seems that the Android system does the following:

  • 发送ACTION_DEVICE_ADMIN_DISABLE_REQUESTED到AdminReceiver

  • Send ACTION_DEVICE_ADMIN_DISABLE_REQUESTED to the AdminReceiver

继续进行禁用管理员无论管理员应用想做什么

Proceed with disabling the admin regardless of what the admin app wants to do

如果用户取消禁止,罚款;如果不是,应用程序将被禁用。有没有办法让应用程序拒绝被禁用,或擦拭时禁止执行设备。

If the user cancels the disabling, fine; if not, the app is disabled. There is no way for the app to refuse being disabled, or to perform the device wipe upon disabling.

目前为止唯一的办法是用户想要禁用管理应用程序时,立即擦拭而无需确认。换句话说,我可以onDisableRequested立即调用getManager()。wipeData()()。当时,管理员仍然活跃,这工作。

The only solution so far is to wipe immediately without confirmation when the user wants to disable the admin app. In other words, I can call getManager().wipeData() immediately in onDisableRequested(). At that time, the admin is still active and this works.

这是正确的?如何用户选择禁用管理应用程序时擦拭设备?

Is this correct? How to wipe the device when the user chooses to disable the admin app?

推荐答案

我的建议:不要做,除非它就像一个企业式的东西

My recommendation: Don't do that unless it's like a corporate-type thing.

不过。在 onDisableRequested(),你可以 startActivity 的主屏幕,然后 startActivity 活动创建,确认他们是否要继续。如果他们选择的话,那么你做你的愿望(擦除设备),如果他们说没有,然后就 startActivity 再次在主屏幕(或完成())。

But. In onDisableRequested(), you could startActivity for the home screen, and then startActivity for an Activity you created that confirms whether they want to continue or not. If they choose yes, then you do as you desire (wipe the device), if they say no, then just startActivity for the home screen again (or finish()).

这确实还运行的风险,他们可以推出相同的设置页面从近期的任务,在这情况下,他们将有可能能够preSS是(或确定)的对话框上弹出你自定义文本,然后继续禁用设备管理员。为了尽量避免这种情况发生,你可以做在希望它会启动初始设置页面并清除顶部 - 大部分禁用设备管理界面。

This does still run the risk that they can launch the same settings page from the recent tasks, under which circumstance they will likely be able to press "yes" (or ok) on the dialog that popped up with your custom text and then continue with disabling device admin. To try and avoid that from happening, you could do this in the hopes it will start the initial settings page and clear the top-most disable device admin screen.

相反擦,你总是可以做 resetPassword(新密码)键,然后 lockNow()。如果它是一个与安全相关的应用程序,则该人的设备不必被擦拭,密码本来$ P $对 - 定义由谁安装该应用的人

Instead of wiping, you could always do resetPassword("new password") and then lockNow(). If it's a security-related app, then the person's device doesn't have to be wiped, and the password would have been pre-defined by the person who installed the app.

让我知道如果您有任何其他问题。我希望这有助于。

Let me know if you have any other questions. I hope this helps.

编辑:我得到了这个答案的存在让我想起了一个upvote,所以我想我会添加一些信息。

I got an upvote that reminded me this answer exists, so I figured I'd add some info.

您可以使用 lockNow()结合的活动,将在锁定屏幕上方显示,如果要锁定之后,还提供擦拭或任何其他。
并启动擦拭将是一个不错的主意,以prevent问题,如果擦拭,因某些原因出现错误或延误之前锁定。

You could use lockNow() in conjunction with an Activity that will show on top of the lock screen if you want to lock then still offer the wipe or whatever else.
And locking before starting the wipe would be a good idea to prevent problems if the wipe has an error or delay for any reason.

如果做一个分布式应用程序这样的事情(通过应用程序商店),注意不要侵犯他们的政策,因为违反政策的行为可能会导致从App Store永久禁止(它发生在我的谷歌播放,由于无非就是一种误解。)

And if doing anything like this on a distributed app (via app stores), take care not to violate their polices because a policy violation CAN cause a permanent ban from the app store (it happened to me on Google Play, due to nothing more than a misunderstanding.)

这篇关于如何消灭Android设备时,设备管理员停用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆