过滤Home属性的应用,然后禁止此类应用的安装,目前定制项目中十有八九都是客户提供launcher,然后禁止别的launcher安装,如何屏蔽呢?修改文件frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java,修改里面的私有方法installNewPackageLIF,
private static boolean hasLauncherCatagory(ActivityIntentInfo filter) {
return filter.hasCategory(Intent.CATEGORY_HOME);
}
/*
* Install a non-existing package.
*/
private void installNewPackageLIF(PackageParser.Package pkg, final int policyFlags,
int scanFlags, UserHandle user, String installerPackageName, String volumeUuid,
PackageInstalledInfo res) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "installNewPackage");
// Remember this for later, in case we need to rollback this install
String pkgName = pkg.packageName;
.......//省略若干行
try {
PackageParser.Package newPackage = scanPackageTracedLI(pkg, policyFlags, scanFlags,System.currentTimeMillis(), user);
//add for prevent 3rd app to be installed start
for (PackageParser.Activity a : newPackage.activities) {
for (ActivityIntentInfo filter : a.intents) {
if (hasLauncherCatagory(filter) && !pkgName.equals("com.vc")) { //判断是否是launcher
deletePackageLIF(pkgName, UserHandle.ALL, false, null, 0,res.removedInfo, false,null); //如果是launcher就删除文件,并且提示无法安装
res.setError(INSTALL_FAILED_INVALID_INSTALL_LOCATION,
"Cannot install updates to system or vendor apps on sdcard");
return;
}
}
}
//add for prevent 3rd app to be installed end
updateSettingsLI(newPackage, installerPackageName, null, res, user);
......//省略若干行