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
This commit is contained in:
Neil Fuller
2020-06-11 13:45:57 +01:00
parent 472e277ce6
commit a5357c9520

View File

@@ -83,34 +83,36 @@ public class ServiceWatcher implements ServiceConnection {
public static final class ServiceInfo implements Comparable<ServiceInfo> {
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() {