Merge "Use synchronization when accessing mPackages state" into oc-mr1-dev

am: 9d656d0305

Change-Id: I78cb61a5bc667fe2d902b49e292968941251cdc6
This commit is contained in:
Fyodor Kupolov
2017-08-25 22:30:20 +00:00
committed by android-build-merger

View File

@@ -21822,32 +21822,36 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
} }
} }
if (callingUid == Process.SHELL_UID synchronized (mPackages) {
&& (pkgSetting.pkgFlags & ApplicationInfo.FLAG_TEST_ONLY) == 0) { if (callingUid == Process.SHELL_UID
// Shell can only change whole packages between ENABLED and DISABLED_USER states && (pkgSetting.pkgFlags & ApplicationInfo.FLAG_TEST_ONLY) == 0) {
// unless it is a test package. // Shell can only change whole packages between ENABLED and DISABLED_USER states
int oldState = pkgSetting.getEnabled(userId); // unless it is a test package.
if (className == null int oldState = pkgSetting.getEnabled(userId);
&& if (className == null
(oldState == COMPONENT_ENABLED_STATE_DISABLED_USER &&
|| oldState == COMPONENT_ENABLED_STATE_DEFAULT (oldState == COMPONENT_ENABLED_STATE_DISABLED_USER
|| oldState == COMPONENT_ENABLED_STATE_ENABLED) || oldState == COMPONENT_ENABLED_STATE_DEFAULT
&& || oldState == COMPONENT_ENABLED_STATE_ENABLED)
(newState == COMPONENT_ENABLED_STATE_DISABLED_USER &&
|| newState == COMPONENT_ENABLED_STATE_DEFAULT (newState == COMPONENT_ENABLED_STATE_DISABLED_USER
|| newState == COMPONENT_ENABLED_STATE_ENABLED)) { || newState == COMPONENT_ENABLED_STATE_DEFAULT
// ok || newState == COMPONENT_ENABLED_STATE_ENABLED)) {
} else { // ok
throw new SecurityException( } else {
"Shell cannot change component state for " + packageName + "/" throw new SecurityException(
+ className + " to " + newState); "Shell cannot change component state for " + packageName + "/"
+ className + " to " + newState);
}
} }
} }
if (className == null) { if (className == null) {
// We're dealing with an application/package level state change // We're dealing with an application/package level state change
if (pkgSetting.getEnabled(userId) == newState) { synchronized (mPackages) {
// Nothing to do if (pkgSetting.getEnabled(userId) == newState) {
return; // Nothing to do
return;
}
} }
// If we're enabling a system stub, there's a little more work to do. // If we're enabling a system stub, there's a little more work to do.
// Prior to enabling the package, we need to decompress the APK(s) to the // Prior to enabling the package, we need to decompress the APK(s) to the
@@ -21961,41 +21965,45 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
// Don't care about who enables an app. // Don't care about who enables an app.
callingPackage = null; callingPackage = null;
} }
pkgSetting.setEnabled(newState, userId, callingPackage); synchronized (mPackages) {
} else { pkgSetting.setEnabled(newState, userId, callingPackage);
// We're dealing with a component level state change
// First, verify that this is a valid class name.
PackageParser.Package pkg = pkgSetting.pkg;
if (pkg == null || !pkg.hasComponentClassName(className)) {
if (pkg != null &&
pkg.applicationInfo.targetSdkVersion >=
Build.VERSION_CODES.JELLY_BEAN) {
throw new IllegalArgumentException("Component class " + className
+ " does not exist in " + packageName);
} else {
Slog.w(TAG, "Failed setComponentEnabledSetting: component class "
+ className + " does not exist in " + packageName);
}
} }
switch (newState) { } else {
case COMPONENT_ENABLED_STATE_ENABLED: synchronized (mPackages) {
if (!pkgSetting.enableComponentLPw(className, userId)) { // We're dealing with a component level state change
return; // First, verify that this is a valid class name.
PackageParser.Package pkg = pkgSetting.pkg;
if (pkg == null || !pkg.hasComponentClassName(className)) {
if (pkg != null &&
pkg.applicationInfo.targetSdkVersion >=
Build.VERSION_CODES.JELLY_BEAN) {
throw new IllegalArgumentException("Component class " + className
+ " does not exist in " + packageName);
} else {
Slog.w(TAG, "Failed setComponentEnabledSetting: component class "
+ className + " does not exist in " + packageName);
}
} }
break; switch (newState) {
case COMPONENT_ENABLED_STATE_DISABLED: case COMPONENT_ENABLED_STATE_ENABLED:
if (!pkgSetting.disableComponentLPw(className, userId)) { if (!pkgSetting.enableComponentLPw(className, userId)) {
return; return;
}
break;
case COMPONENT_ENABLED_STATE_DISABLED:
if (!pkgSetting.disableComponentLPw(className, userId)) {
return;
}
break;
case COMPONENT_ENABLED_STATE_DEFAULT:
if (!pkgSetting.restoreComponentLPw(className, userId)) {
return;
}
break;
default:
Slog.e(TAG, "Invalid new component state: " + newState);
return;
} }
break;
case COMPONENT_ENABLED_STATE_DEFAULT:
if (!pkgSetting.restoreComponentLPw(className, userId)) {
return;
}
break;
default:
Slog.e(TAG, "Invalid new component state: " + newState);
return;
} }
} }
synchronized (mPackages) { synchronized (mPackages) {