summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tom Chan <tomchan@google.com> 2024-01-24 18:37:36 +0000
committer Tom Chan <tomchan@google.com> 2024-01-24 19:01:42 +0000
commit38a2eef04d5fe6d8895d2e696911c98a21c11dd7 (patch)
tree20188160b8debb2b43a8be5c703799dd200a6a16
parent9812a64b24502edc8913eea4dbac830e03007ec8 (diff)
Get WSM per user service dynamically.
This change makes WearableSensingManagerService gets the current user's per-user service instead of the default one. It also fixes an issue with overriding the wearable sensing service implementation by shell command. Previously, the WSS service name is cached in WearableSensingManagerPerUserService and cannot be changed without a phone restart, which means after the shell command overrides the service value, it stays the same even if the command is run again with a different service name. After this change, running the shell command will destroy the cached per-user service and hence allows the service name to be overwritten to a different value. Bug: 301427767 Test: atest CtsWearableSensingServiceTestCases and then tried on-device with a different WSS service name to verify the shell command can overwrite the service name for a second time Change-Id: Ie13b496f827e2f2e83da9d8a96ef9f85e6c93c8c
-rw-r--r--services/core/java/com/android/server/wearable/WearableSensingManagerService.java27
1 files changed, 23 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/wearable/WearableSensingManagerService.java b/services/core/java/com/android/server/wearable/WearableSensingManagerService.java
index 106be5f124a0..4cc2c025575e 100644
--- a/services/core/java/com/android/server/wearable/WearableSensingManagerService.java
+++ b/services/core/java/com/android/server/wearable/WearableSensingManagerService.java
@@ -48,6 +48,7 @@ import com.android.server.pm.KnownPackages;
import java.io.FileDescriptor;
import java.util.Objects;
import java.util.Set;
+import java.util.function.Consumer;
/**
* System service for managing sensing {@link AmbientContextEvent}s on Wearables.
@@ -191,9 +192,23 @@ public class WearableSensingManagerService extends
}
}
+ private void callPerUserServiceIfExist(
+ Consumer<WearableSensingManagerPerUserService> serviceConsumer,
+ RemoteCallback statusCallback) {
+ int userId = UserHandle.getCallingUserId();
+ synchronized (mLock) {
+ WearableSensingManagerPerUserService service = getServiceForUserLocked(userId);
+ if (service == null) {
+ Slog.w(TAG, "Service not available for userId " + userId);
+ WearableSensingManagerPerUserService.notifyStatusCallback(statusCallback,
+ WearableSensingManager.STATUS_SERVICE_UNAVAILABLE);
+ return;
+ }
+ serviceConsumer.accept(service);
+ }
+ }
+
private final class WearableSensingManagerInternal extends IWearableSensingManager.Stub {
- final WearableSensingManagerPerUserService mService = getServiceForUserLocked(
- UserHandle.getCallingUserId());
@Override
public void provideDataStream(
@@ -210,7 +225,9 @@ public class WearableSensingManagerService extends
WearableSensingManager.STATUS_SERVICE_UNAVAILABLE);
return;
}
- mService.onProvideDataStream(parcelFileDescriptor, callback);
+ callPerUserServiceIfExist(
+ service -> service.onProvideDataStream(parcelFileDescriptor, callback),
+ callback);
}
@Override
@@ -229,7 +246,9 @@ public class WearableSensingManagerService extends
WearableSensingManager.STATUS_SERVICE_UNAVAILABLE);
return;
}
- mService.onProvidedData(data, sharedMemory, callback);
+ callPerUserServiceIfExist(
+ service -> service.onProvidedData(data, sharedMemory, callback),
+ callback);
}
@Override