From 6b3321e48eb3f0032a9baa21774d2c4909fd42e9 Mon Sep 17 00:00:00 2001 From: Reema Bajwa Date: Wed, 21 Dec 2022 19:28:24 +0000 Subject: [PATCH] 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 --- .../infra/AbstractMasterSystemService.java | 23 +++++++++++++++++++ .../infra/AbstractPerUserSystemService.java | 9 +++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java index b813995f1c087..3ae699b1dbba6 100644 --- a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java +++ b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java @@ -684,6 +684,16 @@ public abstract class AbstractMasterSystemService 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 services = getServiceListForUserLocked(userId); if (services == null) { return null; @@ -704,6 +714,19 @@ public abstract class AbstractMasterSystemService updateCachedServiceListMultiModeLocked(int userId, boolean disabled) { + final int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), + Binder.getCallingUid(), userId, false, false, null, + null); + List 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 diff --git a/services/core/java/com/android/server/infra/AbstractPerUserSystemService.java b/services/core/java/com/android/server/infra/AbstractPerUserSystemService.java index ddb19f0ebfb85..af025c0ef4dac 100644 --- a/services/core/java/com/android/server/infra/AbstractPerUserSystemService.java +++ b/services/core/java/com/android/server/infra/AbstractPerUserSystemService.java @@ -154,7 +154,14 @@ public abstract class AbstractPerUserSystemService