Cleans up sharedUser regardless of creation logic

Prior to this change, we were not updating the shared user a package
setting belongs to if the package setting was not deep copied. In the
case that shared users didn't match, we were not deep copying and so
were not updating later. There is a more fundamental change to be made
here, but we're limiting risk by keeping this change as small as
possible.

Bug: 138919405
Test: atest AppSecurityTests
Test: manual; flash P then flash this build: observe consistent PackageSettings
Change-Id: Ib22f9e6a1fb3104bec4eb3e5b1de983e19d49dce
This commit is contained in:
Patrick Baumann
2019-08-07 17:56:58 -07:00
parent 6aa3f38983
commit cf9a4835c1

View File

@@ -320,7 +320,6 @@ import com.android.server.pm.permission.PermissionManagerServiceInternal;
import com.android.server.pm.permission.PermissionManagerServiceInternal.PermissionCallback;
import com.android.server.pm.permission.PermissionsState;
import com.android.server.policy.PermissionPolicyInternal;
import com.android.server.policy.PermissionPolicyInternal.OnInitializedCallback;
import com.android.server.security.VerityUtils;
import com.android.server.storage.DeviceStorageMonitorInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
@@ -11033,14 +11032,15 @@ public class PackageManagerService extends IPackageManager.Stub
final String realPkgName = request.realPkgName;
final List<String> changedAbiCodePath = result.changedAbiCodePath;
final PackageSetting pkgSetting;
if (request.pkgSetting != null && request.pkgSetting.sharedUser != null
&& request.pkgSetting.sharedUser != result.pkgSetting.sharedUser) {
// shared user changed, remove from old shared user
request.pkgSetting.sharedUser.removePackage(request.pkgSetting);
}
if (result.existingSettingCopied) {
pkgSetting = request.pkgSetting;
pkgSetting.updateFrom(result.pkgSetting);
pkg.mExtras = pkgSetting;
if (pkgSetting.sharedUser != null
&& pkgSetting.sharedUser.removePackage(result.pkgSetting)) {
pkgSetting.sharedUser.addPackage(pkgSetting);
}
} else {
pkgSetting = result.pkgSetting;
if (originalPkgSetting != null) {
@@ -11050,6 +11050,9 @@ public class PackageManagerService extends IPackageManager.Stub
mTransferedPackages.add(originalPkgSetting.name);
}
}
if (pkgSetting.sharedUser != null) {
pkgSetting.sharedUser.addPackage(pkgSetting);
}
// TODO(toddke): Consider a method specifically for modifying the Package object
// post scan; or, moving this stuff out of the Package object since it has nothing
// to do with the package on disk.