From 73e65ba47e613d453e4b69587f5035d21985190c Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Wed, 13 Mar 2019 10:57:09 -0700 Subject: Keep ContentCapturePerUserService alive while the package is being updated. Test: manual verification (cannot be tested using CTS because it would kill the test process) Test: atest CtsContentCaptureServiceTestCases Bug: 126266412 Fixes: 128466656 Change-Id: I73e89f41b58615070c38103fa2f1fa04ac015dca --- .../ContentCaptureManagerService.java | 2 +- .../server/infra/AbstractMasterSystemService.java | 87 +++++++++++++++++++--- 2 files changed, 78 insertions(+), 11 deletions(-) diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java index c75b4c6f113c..9995d8e4d893 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java +++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java @@ -115,7 +115,7 @@ public final class ContentCaptureManagerService extends public ContentCaptureManagerService(@NonNull Context context) { super(context, new FrameworkResourcesServiceNameResolver(context, com.android.internal.R.string.config_defaultContentCaptureService), - UserManager.DISALLOW_CONTENT_CAPTURE); + UserManager.DISALLOW_CONTENT_CAPTURE, /* refreshServiceOnPackageUpdate=*/ false); DeviceConfig.addOnPropertyChangedListener(DeviceConfig.NAMESPACE_CONTENT_CAPTURE, ActivityThread.currentApplication().getMainExecutor(), (namespace, key, value) -> onDeviceConfigChange(key, value)); diff --git a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java index d2ccfcc732a9..4cafd4ba40c1 100644 --- a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java +++ b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java @@ -125,9 +125,27 @@ public abstract class AbstractMasterSystemService mServicesCache = new SparseArray<>(); + /** + * Whether the per-user service should be removed from the cache when its apk is updated. + */ + private final boolean mRefreshServiceOnPackageUpdate; + + /** + * Name of the service's package that was active but then was removed because its package + * update. + * + *

It's a temporary state set / used by the {@link PackageMonitor} implementation, but + * defined here so it can be dumped. + */ + @GuardedBy("mLock") + private String mLastActivePackageName; + /** * Default constructor. * + *

When using this constructor, the {@link AbstractPerUserSystemService} is removed from + * the cache (and re-added) when the service package is updated. + * * @param context system context. * @param serviceNameResolver resolver for * {@link com.android.internal.infra.AbstractRemoteService} instances, or @@ -139,8 +157,32 @@ public abstract class AbstractMasterSystemServiceNOTE: you'll also need to add it to + * {@code UserRestrictionsUtils.USER_RESTRICTIONS}. + * @param refreshServiceOnPackageUpdate when {@code true}, the + * {@link AbstractPerUserSystemService} is removed from the cache (and re-added) when the + * service package is updated; when {@code false}, the service is untouched during the + * update. + */ + protected AbstractMasterSystemService(@NonNull Context context, + @Nullable ServiceNameResolver serviceNameResolver, + @Nullable String disallowProperty, boolean refreshServiceOnPackageUpdate) { super(context); + mRefreshServiceOnPackageUpdate = refreshServiceOnPackageUpdate; + mServiceNameResolver = serviceNameResolver; if (mServiceNameResolver != null) { mServiceNameResolver @@ -553,6 +595,8 @@ public abstract class AbstractMasterSystemService