@@ -3663,17 +3663,6 @@ void removePackageLI(PackageParser.Package pkg, boolean chatty) {
36633663 mAppDirs .remove (pkg .mPath );
36643664 }
36653665
3666- PackageSetting ps = (PackageSetting )pkg .mExtras ;
3667- if (ps != null && ps .sharedUser != null ) {
3668- // XXX don't do this until the data is removed.
3669- if (false ) {
3670- ps .sharedUser .packages .remove (ps );
3671- if (ps .sharedUser .packages .size () == 0 ) {
3672- // Remove.
3673- }
3674- }
3675- }
3676-
36773666 int N = pkg .providers .size ();
36783667 StringBuilder r = null ;
36793668 int i ;
@@ -5695,12 +5684,26 @@ private void replaceSystemPackageLI(PackageParser.Package deletedPackage,
56955684 return ;
56965685 }
56975686 }
5687+
5688+ killApplication (packageName , oldPkg .applicationInfo .uid );
5689+
56985690 res .removedInfo .uid = oldPkg .applicationInfo .uid ;
56995691 res .removedInfo .removedPackage = packageName ;
57005692 // Remove existing system package
57015693 removePackageLI (oldPkg , true );
57025694 synchronized (mPackages ) {
5703- mSettings .disableSystemPackageLP (packageName );
5695+ if (!mSettings .disableSystemPackageLP (packageName ) && deletedPackage != null ) {
5696+ // We didn't need to disable the .apk as a current system package,
5697+ // which means we are replacing another update that is already
5698+ // installed. We need to make sure to delete the older one's .apk.
5699+ res .removedInfo .args = createInstallArgs (isExternal (pkg )
5700+ ? PackageManager .INSTALL_EXTERNAL : PackageManager .INSTALL_INTERNAL ,
5701+ deletedPackage .applicationInfo .sourceDir ,
5702+ deletedPackage .applicationInfo .publicSourceDir ,
5703+ deletedPackage .applicationInfo .nativeLibraryDir );
5704+ } else {
5705+ res .removedInfo .args = null ;
5706+ }
57045707 }
57055708
57065709 // Successfully disabled the old package. Now proceed with re-installation
@@ -5739,17 +5742,6 @@ private void replaceSystemPackageLI(PackageParser.Package deletedPackage,
57395742 }
57405743 mSettings .writeLP ();
57415744 }
5742- } else {
5743- // If this is an update to an existing update, setup
5744- // to remove the existing update.
5745- synchronized (mPackages ) {
5746- PackageSetting ps = mSettings .getDisabledSystemPkg (packageName );
5747- if (ps != null && ps .codePathString != null &&
5748- !ps .codePathString .equals (oldPkgSetting .codePathString )) {
5749- res .removedInfo .args = createInstallArgs (0 , oldPkgSetting .codePathString ,
5750- oldPkgSetting .resourcePathString , oldPkgSetting .nativeLibraryPathString );
5751- }
5752- }
57535745 }
57545746 }
57555747
@@ -6252,24 +6244,21 @@ private boolean deleteSystemPackageLI(PackageParser.Package p,
62526244 ps = mSettings .getDisabledSystemPkg (p .packageName );
62536245 }
62546246 if (ps == null ) {
6255- Slog .w (TAG , "Attempt to delete system package " + p .packageName );
6247+ Slog .w (TAG , "Attempt to delete unknown system package " + p .packageName );
62566248 return false ;
62576249 } else {
62586250 Log .i (TAG , "Deleting system pkg from data partition" );
62596251 }
62606252 // Delete the updated package
62616253 outInfo .isRemovedPackageSystemUpdate = true ;
6262- final boolean deleteCodeAndResources ;
62636254 if (ps .versionCode < p .mVersionCode ) {
6264- // Delete code and resources for downgrades
6265- deleteCodeAndResources = true ;
6255+ // Delete data for downgrades
62666256 flags &= ~PackageManager .DONT_DELETE_DATA ;
62676257 } else {
62686258 // Preserve data by setting flag
6269- deleteCodeAndResources = false ;
62706259 flags |= PackageManager .DONT_DELETE_DATA ;
62716260 }
6272- boolean ret = deleteInstalledPackageLI (p , deleteCodeAndResources , flags , outInfo ,
6261+ boolean ret = deleteInstalledPackageLI (p , true , flags , outInfo ,
62736262 writeSettings );
62746263 if (!ret ) {
62756264 return false ;
@@ -7850,6 +7839,12 @@ static final class PackageSetting extends PackageSettingBase {
78507839 pkgFlags );
78517840 }
78527841
7842+ PackageSetting (PackageSetting orig ) {
7843+ super (orig .name , orig .realName , orig .codePath , orig .resourcePath ,
7844+ orig .nativeLibraryPathString , orig .versionCode , orig .pkgFlags );
7845+ copyFrom (orig );
7846+ }
7847+
78537848 @ Override
78547849 public String toString () {
78557850 return "PackageSetting{"
@@ -8062,21 +8057,29 @@ SharedUserSetting getSharedUserLP(String name,
80628057 return s ;
80638058 }
80648059
8065- int disableSystemPackageLP (String name ) {
8060+ boolean disableSystemPackageLP (String name ) {
80668061 PackageSetting p = mPackages .get (name );
80678062 if (p == null ) {
80688063 Log .w (TAG , "Package:" +name +" is not an installed package" );
8069- return - 1 ;
8064+ return false ;
80708065 }
80718066 PackageSetting dp = mDisabledSysPackages .get (name );
80728067 // always make sure the system package code and resource paths dont change
8073- if (dp == null ) {
8068+ if (dp == null ) {
80748069 if ((p .pkg != null ) && (p .pkg .applicationInfo != null )) {
80758070 p .pkg .applicationInfo .flags |= ApplicationInfo .FLAG_UPDATED_SYSTEM_APP ;
80768071 }
80778072 mDisabledSysPackages .put (name , p );
8073+
8074+ // a little trick... when we install the new package, we don't
8075+ // want to modify the existing PackageSetting for the built-in
8076+ // version. so at this point we need a new PackageSetting that
8077+ // is okay to much with.
8078+ PackageSetting newp = new PackageSetting (p );
8079+ replacePackageLP (name , newp );
8080+ return true ;
80788081 }
8079- return removePackageLP ( name ) ;
8082+ return false ;
80808083 }
80818084
80828085 PackageSetting enableSystemPackageLP (String name ) {
@@ -8410,6 +8413,19 @@ private int removePackageLP(String name) {
84108413 return -1 ;
84118414 }
84128415
8416+ private void replacePackageLP (String name , PackageSetting newp ) {
8417+ PackageSetting p = mPackages .get (name );
8418+ if (p != null ) {
8419+ if (p .sharedUser != null ) {
8420+ p .sharedUser .packages .remove (p );
8421+ p .sharedUser .packages .add (newp );
8422+ } else {
8423+ replaceUserIdLP (p .userId , newp );
8424+ }
8425+ }
8426+ mPackages .put (name , newp );
8427+ }
8428+
84138429 private boolean addUserIdLP (int uid , Object obj , Object name ) {
84148430 if (uid >= FIRST_APPLICATION_UID + MAX_APPLICATION_UIDS ) {
84158431 return false ;
@@ -8472,6 +8488,16 @@ private void removeUserIdLP(int uid) {
84728488 }
84738489 }
84748490
8491+ private void replaceUserIdLP (int uid , Object obj ) {
8492+ if (uid >= FIRST_APPLICATION_UID ) {
8493+ int N = mUserIds .size ();
8494+ final int index = uid - FIRST_APPLICATION_UID ;
8495+ if (index < N ) mUserIds .set (index , obj );
8496+ } else {
8497+ mOtherUserIds .put (uid , obj );
8498+ }
8499+ }
8500+
84758501 void writeLP () {
84768502 //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024);
84778503
0 commit comments