非系统应用怎样设置不能卸载/删除

From wizarPOS
Revision as of 08:46, 5 August 2024 by Mahong (talk | contribs) (Created page with "{{#ifeq:{{currentloggeduser}}|| <div style="background-color: #ffcccc;border: 1px dashed red; padding: 10px;"> This content is restricted to authorized users only. Please log in to access additional information. </div> | 目前有些客户希望在我们系统中增加他们自己的应用作为系统应用,主要目的就是利用谷歌的原声机制:系统应用不能被删除,只能被更新。但是从安全角度和固件版本管...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

{{#ifeq:||

This content is restricted to authorized users only. Please log in to access additional information.

|

目前有些客户希望在我们系统中增加他们自己的应用作为系统应用,主要目的就是利用谷歌的原声机制:系统应用不能被删除,只能被更新。但是从安全角度和固件版本管理角度,我们不希望客户在我们system中增加客户的apk。因此增加了这个功能:应用删除禁止列表。 所有在应用删除禁止列表中的package包名对应的应用,不会被系统删除,包括通过设置界面手工操作、adb uninstall或者程序使用系统API删除应用。

调用管理接口需要申明权限:android.permission.CLOUDPOS_UNINSTALL_PROHIBITED_APPLICATION。

在PackageManager中增加了addUninstallProhibitedApp, removeUninstallProhibitedApp和clearUninstallProhibitedApps三个方法用来管理列表。 但是由于这个不是谷歌原生暴露的API,建议反射调用:

新增:

PackageManager pm = getPackageManager();

Method add = PackageManager.class.getMethod("addUninstallProhibitedApp", String.class);

boolean result = (Boolean)add.invoke(pm, "com.example.realfullscreensample");

删除:

PackageManager pm = getPackageManager();

Method remove = PackageManager.class.getMethod("removeUninstallProhibitedApp", String.class);

boolean result = (Boolean)remove.invoke(pm, "com.example.realfullscreensample");

清除:

PackageManager pm = getPackageManager();

Method clear = PackageManager.class.getMethod("clearUninstallProhibitedApps");

boolean result = (Boolean)remove.invoke(pm);

Demo

}