设备策略管理器 - 重置密码 - Android 3.0 问题
我在 Android 应用程序中使用设备策略管理器,但 Honeycomb 设备出现问题。当尝试调用 ResetPassword 时,我抛出异常。 Froyo 或 Gingerbread 的情况并非如此,因为它们都工作得很好。
错误是:
java.lang.RuntimeException:无法启动接收器 Package.Name.Test:java.lang.SecurityException:权限拒绝:从 pid=x 写入 com.android.providers.settings.SettingsProvider uri content://settings/secure , uid=y 需要 android.permission.WRITE_SETTINGS
我的 Android 代码如下:
DevicePolicyManager mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if ((mDPM.getActiveAdmins() != null) && (mDPM.isAdminActive(new ComponentName(context, DeviceAdmin.class)))) {
mDPM.resetPassword(extra, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
mDPM.lockNow();
} else {
Log.d(TAG, "Could not lock because device admin not enabled");
}
问题发生在:
mDPM.resetPassword(extra, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
我的 Device_Admin.xml 是:
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<force-lock />
<wipe-data />
<reset-password />
</uses-policies>
</device-admin>
就像我说的,设备管理器在 Froyo 和 Gingerbread 上工作得很好设备,尽管我确实对使用不同键盘保护的用户存在一些问题,例如 Droid X 和 HTC Sense。这个问题与时间有关。当我调用 lockNow 时,设备将关闭屏幕,但 HTC Sense 或 MotoBlur 不会真正锁定键盘保护,直到设置、安全、锁定手机中设置的时间为止。
任何帮助都会很棒!我最近刚刚在 I/O 上拿到了一台蜂窝平板电脑,尚未在该设备上测试该应用程序,但我在市场网站上看到运行 3.0 的 Xoom 的用户出现错误。还没见过任何 3.1 设备。
I am using Device Policy Manager in my Android App and I have a problem with Honeycomb devices. When attempting to call resetPassword I get an exception thrown. This is not the case in Froyo or Gingerbread, as both of those work fine.
The error is:
java.lang.RuntimeException: Unable to start receiver Package.Name.Test: java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider uri content://settings/secure from pid=x, uid=y requires android.permission.WRITE_SETTINGS
My Android Code is as follows:
DevicePolicyManager mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if ((mDPM.getActiveAdmins() != null) && (mDPM.isAdminActive(new ComponentName(context, DeviceAdmin.class)))) {
mDPM.resetPassword(extra, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
mDPM.lockNow();
} else {
Log.d(TAG, "Could not lock because device admin not enabled");
}
The problem occurs at:
mDPM.resetPassword(extra, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
My Device_Admin.xml is:
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<force-lock />
<wipe-data />
<reset-password />
</uses-policies>
</device-admin>
Like I said the device admin works great on Froyo and Gingerbread devices, although I do have some problems with users using different keyguards, an example is the Droid X and HTC Sense. This problem is with timing. When I call lockNow the device will turn off the screen but HTC Sense or MotoBlur will not actually lock the keyguard until the time that was set in Settings, Security, Lock Phone After.
Any help would be awesome! I just recently got a honeycomb tablet at I/O and haven't tested the app out on this device yet, but I see the errors on the market website with users with the Xoom running 3.0. Have not seen any 3.1 devices yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我也为此苦苦挣扎。该解决方案也列在您的链接之一上,但我也会在这里提到它,以防它对其他人有帮助。
如果设备是全新的(或恢复出厂设置),则代码会按照您的描述失败。
如果用户仅使用设置菜单输入密码一次,相同的代码就会以某种方式开始工作并继续工作。
确实是一个非常奇怪的错误!
I struggled with this also. The solution is also listed on one of your links, but I'll mention it here also in case it helps someone else.
If the device is brand new (or factory reset) the code fails as you describe.
If the user enters a password using the settings menu just once, somehow the same code starts working and keeps on working.
A very weird bug indeed!!
在Android Honeycomb 3.0平台上,
DevicePolicyServiceManager
与Gingerbread非常不同,resetPassword()
的整个流程是:这里你应该知道为什么< code>WRITE_SETTINGS 是必需的,似乎这是 Google 的错误,他们没有把Binder.clearCallingIndentity() 块中的 LockPatternUtils.checkPasswordInHistory() 方法。
还有一件事,即使您在
AndroidManifest.xml
文件中添加WRITE_SETTINGS
权限,它也会告诉您还需要WRTITE_SECURE_SETTINGS
权限。希望谷歌能够尽快解决这个问题。
PS 看来这个问题已经在 ICS 平台上得到解决,Google 已经从 resetPassword() 块中删除了 checkPasswordInHistory() 。我不认为这是一个好的解决方案,我不知道为什么?也许他们想尽快发布 ICS?
On Android Honeycomb 3.0 platform, the
DevicePolicyServiceManager
is very different from Gingerbread, the whole flow ofresetPassword()
is:Here you should know why
WRITE_SETTINGS
is required, it seems that this is Google's mistake, they did not put the LockPatternUtils.checkPasswordInHistory() method inBinder.clearCallingIndentity()
block.One more thing, even if you add
WRITE_SETTINGS
permission in yourAndroidManifest.xml
file, it will tell you thatWRTITE_SECURE_SETTINGS
permission is also required.Hope Google can fix this issue ASAP.
P.S. It seems that this issue has been fixed on ICS platform, Google has removed the checkPasswordInHistory() from resetPassword() block. I do not think this is a good solutoin and i don't know why? Maybe they wanna release ICS as soon as possible?
我也遇到了这个问题,我可以告诉你的是,如果你没有手动设置密码,即使是一次,它也会强制关闭请求 write_settings 权限,但如果你尝试一次从那里手动设置密码,它会工作就像魅力。
I also faced this problem, what i can tell is if you didn't set the password manually even single time, the it will give force close asking for write_settings permission but if you try once by setting password manually from there on-wards it will work like charm.
我正在研究这个问题(顺便说一句,这在 3.1 上也很容易重现),但看起来你已经根据 您提交的问题。我只是想在这里指出,以防其他人尝试研究答案。
I was looking at this problem (which is readily reproducible on 3.1 as well, btw), but it appears that you already figured it out, based upon the issue you filed. I just wanted to note that here in case anyone else tried to research the answer.