通過應(yīng)用商店更新高版本的系統(tǒng)app,在升級(jí)完成后重啟會(huì)刪除掉新安裝的app歉秫?
解決方法:
修改frameworks/base/services/java/com/android/server/pm/PackageManagerService.java注釋掉紅色的部分
if?(pkg.mVersionCode?<=?ps.versionCode)?{
//?The?system?package?has?been?updated?and?the?code?path?does?not?match????????????????????//?Ignore?entry.?Skip?it.
Log.i(TAG,?"Package?"?+?ps.name?+?"?at?"?+?scanFile
+?"?ignored:?updated?version?"?+?ps.versionCode
+?"?better?than?this?"?+?pkg.mVersionCode);
if?(!updatedPkg.codePath.equals(scanFile))?{
Slog.w(PackageManagerService.TAG,?"Code?path?for?hidden?system?pkg?:?"
+?ps.name?+?"?changing?from?"?+?updatedPkg.codePathString
+?"?to?"?+?scanFile);
updatedPkg.codePath?=?scanFile;
updatedPkg.codePathString?=?scanFile.toString();
//?This?is?the?point?at?which?we?know?that?the?system-disk?APK
//?for?this?package?has?moved?during?a?reboot?(e.g.?due?to?an?OTA),
//?so?we?need?to?reevaluate?it?for?privilege?policy.
if?(locationIsPrivileged(scanFile))?{
updatedPkg.pkgFlags?|=?ApplicationInfo.FLAG_PRIVILEGED;
}
}
updatedPkg.pkg?=?pkg;
mLastScanError?=?PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE;
return?null;
}/*else?{
//?The?current?app?on?the?system?partion?is?better?than
//?what?we?have?updated?to?on?the?data?partition;?switch
//?back?to?the?system?partition?version.
//?At?this?point,?its?safely?assumed?that?package?installation?for
//?apps?in?system?partition?will?go?through.?If?not?there?won't?be?a?working
//?version?of?the?app
//?writer
synchronized?(mPackages)?{
//?Just?remove?the?loaded?entries?from?package?lists.
mPackages.remove(ps.name);
}
Slog.w(TAG,?"Package?"?+?ps.name?+?"?at?"?+?scanFile
+?"reverting?from?"?+?ps.codePathString
+?":?new?version?"?+?pkg.mVersionCode
+?"?better?than?installed?"?+?ps.versionCode);
InstallArgs?args?=?createInstallArgs(packageFlagsToInstallFlags(ps),
ps.codePathString,?ps.resourcePathString,?ps.nativeLibraryPathString);
synchronized?(mInstallLock)?{
args.cleanUpResourcesLI();
}
synchronized?(mPackages)?{
mSettings.enableSystemPackageLPw(ps.name);
}
}???*/
根本原因:
Google為APK定義了兩個(gè)關(guān)于版本屬性:VersionCode和VersionName蛾洛,他們有不同的用途。
VersionCode:對(duì)消費(fèi)者不可見雁芙,僅用于應(yīng)用市場轧膘、程序內(nèi)部識(shí)別版本,判斷新舊等用途兔甘』寻—整數(shù)值,代表應(yīng)用程序代碼的相對(duì)版本洞焙,也就是版本更新過多少次蟆淀。整數(shù)值有利于其它程序比較,檢查是升級(jí)還是降級(jí)澡匪。你可以把這個(gè)值設(shè)定為任何想設(shè)的值熔任,但是,你必須保證后續(xù)更新版的值要比這個(gè)大唁情。系統(tǒng)不會(huì)強(qiáng)制要求這一行為疑苔,但是隨著版本更新值也增加是正常的行為。一般來說甸鸟,你發(fā)布的第一版程序的versionCode設(shè)定為1惦费,然后每次發(fā)布都會(huì)相應(yīng)增加兵迅,不管發(fā)布的內(nèi)容是較大還是較小的
VersionName:展示給消費(fèi)者,消費(fèi)者會(huì)通過它認(rèn)知自己安裝的版本薪贫,下文提到的版本號(hào)都是說