android 自定义分区,android 自定义预制APP分区
1.先要能被PMS掃描到,在構造函數里添加一條掃描記錄,還要設置加載一些庫的路徑,比如:
public PackageManagerService(Context context, Installer installer,
boolean factoryTest, boolean onlyCore) {
......
File oem3rdAppDir = new File(Environment.getOemDirectory(), "preloadapp");
scanDirLI(oem3rdAppDir, 0, scanFlags, 0);
// Remove disable package settings for updated system apps that were
// removed via an OTA. If the update is no longer present, remove the
// app completely. Otherwise, revoke their system privileges.
for (String deletedAppName : possiblyDeletedUpdatedSystemApps) {
PackageParser.Package deletedPkg = mPackages.get(deletedAppName);
mSettings.removeDisabledSystemPackageLPw(deletedAppName);
......
}
private static void setNativeLibraryPaths(PackageParser.Package pkg, File appLib32InstallDir) {
......
boolean isOem3rdApp = codePath.startsWith("/oem/preloadapp") ? true : false;
if (isApkFile(codeFile) || isOem3rdApp) {。。。。。。}
2.直接掃描進去可能會遇到一下問題,比如APP啟動報錯,卸載后重啟會又加載到APP等。
2.1 APP啟動報錯,這可能涉及到證書的問題,預制APP可以不用檢查證書,
可以在 PackageParser.java 里添加如下:
private static void collectCertificates(Package pkg, File apkFile, int parseFlags)
throws PackageParserException {
......
StrictJarFile jarFile = null;
try {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "strictJarFileCtor");
// Ignore signature stripping protections when verifying APKs from system partition.
// For those APKs we only care about extracting signer certificates, and don't care
// about verifying integrity.
boolean signatureSchemeRollbackProtectionsEnforced =
(parseFlags & PARSE_IS_SYSTEM_DIR) == 0;
boolean IsPrebuiltApp = apkPath != null
&& apkPath.startsWith("/oem/preloadapp");
jarFile = new StrictJarFile(
apkPath,
!verified, // whether to verify JAR signature
IsPrebuiltApp ? false : signatureSchemeRollbackProtectionsEnforced);
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
......
2.2 卸載后重啟會又加載到APP,因為系統每次啟動都會去掃描,所以出現此問題的解決思路是在卸載之后把改APP記錄到某個文件,開機后每次掃描的時候做個判斷,如果是被卸載的預制APP,則直接返回,比如:
private boolean deletePackageLIF(String packageName, UserHandle user,
boolean deleteCodeAndResources, int[] allUserHandles, int flags,
PackageRemovedInfo outInfo, boolean writeSettings,
PackageParser.Package replacingPackage) {
......
if (isSystemApp(ps)) {
if (DEBUG_REMOVE) Slog.d(TAG, "Removing system package: " + ps.name);
// When an updated system application is deleted we delete the existing resources
// as well and fall back to existing code in system partition
ret = deleteSystemPackageLIF(ps.pkg, ps, allUserHandles, flags, outInfo, writeSettings);
} else {
if (DEBUG_REMOVE) Slog.d(TAG, "Removing non-system package: " + ps.name);
if(ps.pkg != null && ps.pkg.baseCodePath != null){
String path = ps.pkg.baseCodePath.substring(0, ps.pkg.baseCodePath.lastIndexOf("/"));
這里根據卸載APP的path判斷是否是需要預留的APP,如果是則記錄到文件
}
ret = deleteInstalledPackageLIF(ps, deleteCodeAndResources, flags, allUserHandles,
outInfo, writeSettings, replacingPackage);
}
......
}
private PackageParser.Package scanPackageLI(PackageParser.Package pkg, File scanFile,
final int policyFlags, int scanFlags, long currentTime, @Nullable UserHandle user)
throws PackageManagerException {
這里可以判斷是否是已經卸載的預制APP,如果是則直接返回,不用繼續加載
if(。。。。。。)return pkg;
。。。。。。
}
總結
以上是生活随笔為你收集整理的android 自定义分区,android 自定义预制APP分区的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue 监视数据
- 下一篇: android分辨率 x y,Andro