繁体   English   中英

应用已设置为个人资料所有者,但无法再将其删除

[英]App already set as profile owner, but can't remove it anymore

我有一个类 AdminReceiver 在我的应用程序中扩展 DeviceAdminReceiver。 以前我通过 ADB shell 使它成为配置文件所有者

adb shell dpm set-active-admin com.example.myApp/com.example.myApp.AdminReceiver 
adb shell dpm set-profile-owner com.example.myApp/com.example.myApp.AdminReceiver

一切都很顺利。 随后,我想以编程方式从我的应用程序中执行以下指令将其删除:

DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
    try {
        dpm.clearProfileOwnerApp(packageName);
    } catch (Exception e) {
        Log.e(TAG, "removingProfile: ", e);
    }

我得到以下异常:

java.lang.SecurityException: Admin ComponentInfo{com.example.myApp/com.example.myApp.AdminReceiver} does not own the profile

.

当我尝试通过 ADB 再次设置配置文件所有者时,出现以下异常

java.lang.IllegalStateException: Trying to set the profile owner, but profile owner is already set

.

这很疯狂,因为当我尝试删除个人资料所有者时,它就像没有它一样,如果我尝试使它成为个人资料所有者,它就像它已经拥有一样!

有没有没有任何设备恢复出厂设置的解决方案?

正面临同样的问题,终于找到了解决方案。

安装脚本

adb install app.apk
adb shell dpm set-device-owner [your.package]/.DeviceAdminReceiver

卸载脚本

adb install -r -t app-testOnly.apk
adb shell dpm remove-active-admin [your.package]/.DeviceAdminReceiver
adb shell pm uninstall [your.package]

注意:您需要先创建一个testOnly版本的应用程序。 此外,如果实际应用程序已签名,则 testOnly 必须使用相同的证书进行签名。

暂无
暂无

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

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