Added MasterSystemService.onServiceRemoved() and some other nit fixes...
Test: CtsAutoFillServiceTestCases
Bug: 117779333
Change-Id: If5579b7aef991f34148fde48c35122e194d621d9
diff --git a/services/core/java/com/android/server/AbstractMasterSystemService.java b/services/core/java/com/android/server/AbstractMasterSystemService.java
index c955daf..6cae887 100644
--- a/services/core/java/com/android/server/AbstractMasterSystemService.java
+++ b/services/core/java/com/android/server/AbstractMasterSystemService.java
@@ -244,7 +244,7 @@
*/
@GuardedBy("mLock")
@Nullable
- protected S peekServiceForUserLocked(int userId) {
+ protected S peekServiceForUserLocked(@UserIdInt int userId) {
final int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), userId, false, false, null, null);
return mServicesCache.get(resolvedUserId);
@@ -254,7 +254,7 @@
* Updates a cached service for a given user.
*/
@GuardedBy("mLock")
- protected void updateCachedServiceLocked(int userId) {
+ protected void updateCachedServiceLocked(@UserIdInt int userId) {
updateCachedServiceLocked(userId, isDisabledLocked(userId));
}
@@ -262,7 +262,7 @@
* Checks whether the service is disabled (through {@link UserManager} restrictions) for the
* given user.
*/
- protected boolean isDisabledLocked(int userId) {
+ protected boolean isDisabledLocked(@UserIdInt int userId) {
return mDisabledUsers == null ? false : mDisabledUsers.get(userId);
}
@@ -274,7 +274,7 @@
* @return service for the user.
*/
@GuardedBy("mLock")
- protected S updateCachedServiceLocked(int userId, boolean disabled) {
+ protected S updateCachedServiceLocked(@UserIdInt int userId, boolean disabled) {
final S service = getServiceForUserLocked(userId);
if (service != null) {
service.updateLocked(disabled);
@@ -304,7 +304,7 @@
* <p>By default doesn't do anything, but can be overridden by subclasses.
*/
@SuppressWarnings("unused")
- protected void onServiceEnabledLocked(S service, @UserIdInt int userId) {
+ protected void onServiceEnabledLocked(@NonNull S service, @UserIdInt int userId) {
}
/**
@@ -314,15 +314,23 @@
*/
@GuardedBy("mLock")
@NonNull
- protected S removeCachedServiceLocked(@UserIdInt int userId) {
+ private S removeCachedServiceLocked(@UserIdInt int userId) {
final S service = peekServiceForUserLocked(userId);
if (service != null) {
mServicesCache.delete(userId);
+ onServiceRemoved(service, userId);
}
return service;
}
/**
+ * Called after the service is removed from the cache.
+ */
+ @SuppressWarnings("unused")
+ protected void onServiceRemoved(@NonNull S service, @UserIdInt int userId) {
+ }
+
+ /**
* Visits all services in the cache.
*/
@GuardedBy("mLock")