Fix update logic for multi backend

This change fixes the logic to update services in
AbstractMasterSystemService when a derviced class is configured to
support multiple backends. Before this change, after an update
all PerUserService instances would point to the same backend.

Test: Built & deployed locally

Change-Id: Icfb5860bd0baa588b914375ddfae88741b8fcb9c
This commit is contained in:
Reema Bajwa
2022-12-21 19:28:24 +00:00
parent 1697a83bf6
commit 6b3321e48e
2 changed files with 31 additions and 1 deletions

View File

@@ -684,6 +684,16 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
*/
@GuardedBy("mLock")
protected List<S> updateCachedServiceListLocked(@UserIdInt int userId, boolean disabled) {
if (mServiceNameResolver != null
&& mServiceNameResolver.isConfiguredInMultipleMode()) {
// In multiple mode, we have multiple instances of AbstractPerUserSystemService, per
// user where each instance holds information needed to connect to a backend. An
// update operation in this mode needs to account for addition, deletion, change
// of backends and cannot be executed in the scope of a given
// AbstractPerUserSystemService.
return updateCachedServiceListMultiModeLocked(userId, disabled);
}
// isConfiguredInMultipleMode is false
final List<S> services = getServiceListForUserLocked(userId);
if (services == null) {
return null;
@@ -704,6 +714,19 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
return services;
}
@GuardedBy("mLock")
private List<S> updateCachedServiceListMultiModeLocked(int userId, boolean disabled) {
final int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), userId, false, false, null,
null);
List<S> services = new ArrayList<>();
synchronized (mLock) {
removeCachedServiceListLocked(resolvedUserId);
services = getServiceListForUserLocked(userId);
}
return services;
}
/**
* Gets the Settings property that defines the name of the component name used to bind this
* service to an external service, or {@code null} when the service is not defined by such

View File

@@ -154,7 +154,14 @@ public abstract class AbstractPerUserSystemService<S extends AbstractPerUserSyst
if (mMaster.mServiceNameResolver != null
&& mMaster.mServiceNameResolver.isConfiguredInMultipleMode()) {
updateServiceInfoListLocked();
// Update of multi configured mode should always happen in AbstractMasterSystemService
// as this class is not aware of the complete list of multiple backends. Since we
// should never end up in this state, it is safe to not do anything if we end up here
// through a different code path.
if (mMaster.debug) {
Slog.d(mTag, "Should not end up in updateLocked when "
+ "isConfiguredInMultipleMode is true");
}
} else {
updateServiceInfoLocked();
}