简体   繁体   English

在Android上更新设备所有者应用的政策

[英]Update policy on a device owner app on Android

I have a device owner app on Android, and would like to add an additional policy to device-admin.xml file. 我在Android上有设备所有者应用,并且想要为device-admin.xml文件添加其他策略。 This is required because I want to disable camera on keyguard, which requires <disable-keyguard-features /> to be available inside the device-admin.xml. 这是必需的,因为我想在keyguard上禁用摄像头,这需要在device-admin.xml中提供<disable-keyguard-features /> The app was initially installed using NFC and a new version of the app can be installed through a locally saved apk file, which can be downloaded from our private server, however, when the new version of app is installed it seems to have no impact on the addition of <disable-keyguard-features /> to device-admin.xml because we get a SecurityException on calling 该应用程序最初使用NFC安装,可以通过本地保存的apk文件安装该应用程序的新版本,该文件可以从我们的私人服务器下载,但是,当安装新版本的应用程序时,它似乎没有影响将<disable-keyguard-features />到device-admin.xml,因为我们在调用时遇到SecurityException

aDevicePolicyManager.setKeyguardDisabledFeatures(aDeviceAdmin,
    DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA);

Now, if we re-provision a device with new version of the owner app, using NFC then everything goes well, but I am looking for a way to apply this change to existing app, how can this be achieved? 现在,如果我们使用NFC重新配置具有新版本所有者应用程序的设备,那么一切顺利,但我正在寻找一种方法将此更改应用于现有应用程序,如何实现?

In other words, how can we update policy requirements of a device owner app on an Android device without re-provisioning? 换句话说,我们如何更新Android设备上的设备所有者应用的政策要求而无需重新配置?

You can not add a new policy to device-admin.xml and update the application to get the required policy activated. 您无法将新策略添加到device-admin.xml并更新应用程序以激活所需的策略。

You have to re-request the permission for the permission to get activated. 您必须重新请求获得激活权限的权限。

So either go for a update handling mechanism with version codes or just check if the permission exists as explained on this link . 因此,要么使用版本代码来更新处理机制,要么只检查是否存在此链接中所述的权限。

And also do not forget to add a check for any line of code or function which depends on the new admin policy. 此外,不要忘记添加任何代码或函数行的检查,这取决于新的管理策略。

If you feel its expensive to check if you have got the permission every time when you try to run a code have a flag and reset it on onEnabled call back of your DeviceAdminReceiver 如果您觉得每次尝试运行代码时都检查是否获得了权限,并且有一个标志并将其重置为您的DeviceAdminReceiver onEnabled回调

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM