From a5357c95207ed6c19e89d03a5ad03cf9b81addd5 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Thu, 11 Jun 2020 13:45:57 +0100 Subject: [PATCH] Expose isServiceMultiuser Expose ServiceInfo.isServiceMultiuser so the server can take different actions on bind / unbind. For example: when a client runs as the current user there are races between processes when the user switches. i.e. the system server is aware that the current user is switching from user A to user B "immediately", but the client running as user A won't be shut down for a while and can end up being rebound and sending events for user A. Any binder flapping associated with the user A -> user B switch should generally be ignored for a period of time. In the case of a client service that always runs as the system user, the same binder behavior is unexepected would be a more serious error and should be acted on immediately or reported as a configuration error. Test: build only Change-Id: I18f6629aac18076af82b4f6fbf08c4fe5d1c1fd8 --- .../java/com/android/server/ServiceWatcher.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/ServiceWatcher.java b/services/core/java/com/android/server/ServiceWatcher.java index 2ef5895d52d5c..f19ed39f0592a 100644 --- a/services/core/java/com/android/server/ServiceWatcher.java +++ b/services/core/java/com/android/server/ServiceWatcher.java @@ -83,34 +83,36 @@ public class ServiceWatcher implements ServiceConnection { public static final class ServiceInfo implements Comparable { public static final ServiceInfo NONE = new ServiceInfo(Integer.MIN_VALUE, null, - UserHandle.USER_NULL); + UserHandle.USER_NULL, false); public final int version; @Nullable public final ComponentName component; @UserIdInt public final int userId; + public final boolean serviceIsMultiuser; ServiceInfo(ResolveInfo resolveInfo, int currentUserId) { Preconditions.checkArgument(resolveInfo.serviceInfo.getComponentName() != null); Bundle metadata = resolveInfo.serviceInfo.metaData; - boolean isMultiuser; if (metadata != null) { version = metadata.getInt(EXTRA_SERVICE_VERSION, Integer.MIN_VALUE); - isMultiuser = metadata.getBoolean(EXTRA_SERVICE_IS_MULTIUSER, false); + serviceIsMultiuser = metadata.getBoolean(EXTRA_SERVICE_IS_MULTIUSER, false); } else { version = Integer.MIN_VALUE; - isMultiuser = false; + serviceIsMultiuser = false; } component = resolveInfo.serviceInfo.getComponentName(); - userId = isMultiuser ? UserHandle.USER_SYSTEM : currentUserId; + userId = serviceIsMultiuser ? UserHandle.USER_SYSTEM : currentUserId; } - private ServiceInfo(int version, @Nullable ComponentName component, int userId) { + private ServiceInfo(int version, @Nullable ComponentName component, int userId, + boolean serviceIsMultiuser) { Preconditions.checkArgument(component != null || version == Integer.MIN_VALUE); this.version = version; this.component = component; this.userId = userId; + this.serviceIsMultiuser = serviceIsMultiuser; } public @Nullable String getPackageName() {