Loading services/core/java/com/android/server/om/OverlayManagerService.java +64 −55 Original line number Diff line number Diff line Loading @@ -251,14 +251,17 @@ public final class OverlayManagerService extends SystemService { private final Object mLock = new Object(); @GuardedBy("mLock") private final AtomicFile mSettingsFile; private final PackageManagerHelperImpl mPackageManager; private final UserManagerService mUserManager; @GuardedBy("mLock") private final OverlayManagerSettings mSettings; @GuardedBy("mLock") private final OverlayManagerServiceImpl mImpl; private final OverlayActorEnforcer mActorEnforcer; Loading Loading @@ -296,7 +299,9 @@ public final class OverlayManagerService extends SystemService { UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class); umi.addUserLifecycleListener(new UserLifecycleListener()); restoreSettings(); // No async stuff happening in the constructor yet, so it's OK to call a ...Locked() // method without a lock here. restoreSettingsLocked(); // Wipe all shell overlays on boot, to recover from a potentially broken device String shellPkgName = TextUtils.emptyIfNull( Loading Loading @@ -916,12 +921,13 @@ public final class OverlayManagerService extends SystemService { throws RemoteException { try { traceBegin(TRACE_TAG_RRO, "OMS#commit " + transaction); synchronized (mLock) { try { executeAllRequests(transaction); executeAllRequestsLocked(transaction); } catch (Exception e) { final long ident = Binder.clearCallingIdentity(); try { restoreSettings(); restoreSettingsLocked(); } finally { Binder.restoreCallingIdentity(ident); } Loading @@ -929,12 +935,14 @@ public final class OverlayManagerService extends SystemService { throw new SecurityException("commit failed" + (DEBUG || Build.IS_DEBUGGABLE ? ": " + e.getMessage() : "")); } } } finally { traceEnd(TRACE_TAG_RRO); } } private Set<UserPackage> executeRequest( @GuardedBy("mLock") private Set<UserPackage> executeRequestLocked( @NonNull final OverlayManagerTransaction.Request request) throws OperationFailedException { Objects.requireNonNull(request, "Transaction contains a null request"); Loading Loading @@ -1009,22 +1017,19 @@ public final class OverlayManagerService extends SystemService { } } private void executeAllRequests(@NonNull final OverlayManagerTransaction transaction) @GuardedBy("mLock") private void executeAllRequestsLocked(@NonNull final OverlayManagerTransaction transaction) throws OperationFailedException { if (DEBUG) { Slog.d(TAG, "commit " + transaction); } if (transaction == null) { throw new IllegalArgumentException("null transaction"); } synchronized (mLock) { // execute the requests (as calling user) Set<UserPackage> affectedPackagesToUpdate = null; for (Iterator<Request> it = transaction.getRequests(); it.hasNext(); ) { Request request = it.next(); affectedPackagesToUpdate = CollectionUtils.addAll(affectedPackagesToUpdate, executeRequest(request)); executeRequestLocked(request)); } // past the point of no return: the entire transaction has been Loading @@ -1037,7 +1042,6 @@ public final class OverlayManagerService extends SystemService { Binder.restoreCallingIdentity(ident); } } } @Override public void onShellCommand(@NonNull final FileDescriptor in, Loading Loading @@ -1448,12 +1452,14 @@ public final class OverlayManagerService extends SystemService { } } @GuardedBy("mLock") private void updateTargetPackagesLocked(@Nullable UserPackage updatedTarget) { if (updatedTarget != null) { updateTargetPackagesLocked(Set.of(updatedTarget)); } } @GuardedBy("mLock") private void updateTargetPackagesLocked(@Nullable Set<UserPackage> updatedTargets) { if (CollectionUtils.isEmpty(updatedTargets)) { return; Loading Loading @@ -1549,6 +1555,7 @@ public final class OverlayManagerService extends SystemService { } @NonNull @GuardedBy("mLock") private SparseArray<List<String>> updatePackageManagerLocked( @Nullable Set<UserPackage> targets) { if (CollectionUtils.isEmpty(targets)) { Loading @@ -1569,6 +1576,7 @@ public final class OverlayManagerService extends SystemService { * targetPackageNames: the target themselves and shared libraries) */ @NonNull @GuardedBy("mLock") private List<String> updatePackageManagerLocked(@NonNull Collection<String> targetPackageNames, final int userId) { try { Loading Loading @@ -1624,6 +1632,7 @@ public final class OverlayManagerService extends SystemService { } } @GuardedBy("mLock") private void persistSettingsLocked() { if (DEBUG) { Slog.d(TAG, "Writing overlay settings"); Loading @@ -1639,10 +1648,11 @@ public final class OverlayManagerService extends SystemService { } } private void restoreSettings() { @GuardedBy("mLock") private void restoreSettingsLocked() { try { traceBegin(TRACE_TAG_RRO, "OMS#restoreSettings"); synchronized (mLock) { if (!mSettingsFile.getBaseFile().exists()) { return; } Loading @@ -1668,7 +1678,6 @@ public final class OverlayManagerService extends SystemService { } catch (IOException | XmlPullParserException e) { Slog.e(TAG, "failed to restore overlay state", e); } } } finally { traceEnd(TRACE_TAG_RRO); } Loading Loading
services/core/java/com/android/server/om/OverlayManagerService.java +64 −55 Original line number Diff line number Diff line Loading @@ -251,14 +251,17 @@ public final class OverlayManagerService extends SystemService { private final Object mLock = new Object(); @GuardedBy("mLock") private final AtomicFile mSettingsFile; private final PackageManagerHelperImpl mPackageManager; private final UserManagerService mUserManager; @GuardedBy("mLock") private final OverlayManagerSettings mSettings; @GuardedBy("mLock") private final OverlayManagerServiceImpl mImpl; private final OverlayActorEnforcer mActorEnforcer; Loading Loading @@ -296,7 +299,9 @@ public final class OverlayManagerService extends SystemService { UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class); umi.addUserLifecycleListener(new UserLifecycleListener()); restoreSettings(); // No async stuff happening in the constructor yet, so it's OK to call a ...Locked() // method without a lock here. restoreSettingsLocked(); // Wipe all shell overlays on boot, to recover from a potentially broken device String shellPkgName = TextUtils.emptyIfNull( Loading Loading @@ -916,12 +921,13 @@ public final class OverlayManagerService extends SystemService { throws RemoteException { try { traceBegin(TRACE_TAG_RRO, "OMS#commit " + transaction); synchronized (mLock) { try { executeAllRequests(transaction); executeAllRequestsLocked(transaction); } catch (Exception e) { final long ident = Binder.clearCallingIdentity(); try { restoreSettings(); restoreSettingsLocked(); } finally { Binder.restoreCallingIdentity(ident); } Loading @@ -929,12 +935,14 @@ public final class OverlayManagerService extends SystemService { throw new SecurityException("commit failed" + (DEBUG || Build.IS_DEBUGGABLE ? ": " + e.getMessage() : "")); } } } finally { traceEnd(TRACE_TAG_RRO); } } private Set<UserPackage> executeRequest( @GuardedBy("mLock") private Set<UserPackage> executeRequestLocked( @NonNull final OverlayManagerTransaction.Request request) throws OperationFailedException { Objects.requireNonNull(request, "Transaction contains a null request"); Loading Loading @@ -1009,22 +1017,19 @@ public final class OverlayManagerService extends SystemService { } } private void executeAllRequests(@NonNull final OverlayManagerTransaction transaction) @GuardedBy("mLock") private void executeAllRequestsLocked(@NonNull final OverlayManagerTransaction transaction) throws OperationFailedException { if (DEBUG) { Slog.d(TAG, "commit " + transaction); } if (transaction == null) { throw new IllegalArgumentException("null transaction"); } synchronized (mLock) { // execute the requests (as calling user) Set<UserPackage> affectedPackagesToUpdate = null; for (Iterator<Request> it = transaction.getRequests(); it.hasNext(); ) { Request request = it.next(); affectedPackagesToUpdate = CollectionUtils.addAll(affectedPackagesToUpdate, executeRequest(request)); executeRequestLocked(request)); } // past the point of no return: the entire transaction has been Loading @@ -1037,7 +1042,6 @@ public final class OverlayManagerService extends SystemService { Binder.restoreCallingIdentity(ident); } } } @Override public void onShellCommand(@NonNull final FileDescriptor in, Loading Loading @@ -1448,12 +1452,14 @@ public final class OverlayManagerService extends SystemService { } } @GuardedBy("mLock") private void updateTargetPackagesLocked(@Nullable UserPackage updatedTarget) { if (updatedTarget != null) { updateTargetPackagesLocked(Set.of(updatedTarget)); } } @GuardedBy("mLock") private void updateTargetPackagesLocked(@Nullable Set<UserPackage> updatedTargets) { if (CollectionUtils.isEmpty(updatedTargets)) { return; Loading Loading @@ -1549,6 +1555,7 @@ public final class OverlayManagerService extends SystemService { } @NonNull @GuardedBy("mLock") private SparseArray<List<String>> updatePackageManagerLocked( @Nullable Set<UserPackage> targets) { if (CollectionUtils.isEmpty(targets)) { Loading @@ -1569,6 +1576,7 @@ public final class OverlayManagerService extends SystemService { * targetPackageNames: the target themselves and shared libraries) */ @NonNull @GuardedBy("mLock") private List<String> updatePackageManagerLocked(@NonNull Collection<String> targetPackageNames, final int userId) { try { Loading Loading @@ -1624,6 +1632,7 @@ public final class OverlayManagerService extends SystemService { } } @GuardedBy("mLock") private void persistSettingsLocked() { if (DEBUG) { Slog.d(TAG, "Writing overlay settings"); Loading @@ -1639,10 +1648,11 @@ public final class OverlayManagerService extends SystemService { } } private void restoreSettings() { @GuardedBy("mLock") private void restoreSettingsLocked() { try { traceBegin(TRACE_TAG_RRO, "OMS#restoreSettings"); synchronized (mLock) { if (!mSettingsFile.getBaseFile().exists()) { return; } Loading @@ -1668,7 +1678,6 @@ public final class OverlayManagerService extends SystemService { } catch (IOException | XmlPullParserException e) { Slog.e(TAG, "failed to restore overlay state", e); } } } finally { traceEnd(TRACE_TAG_RRO); } Loading