From ae8d3d628b2877a5e1f69f13ea8f20bb74a1b227 Mon Sep 17 00:00:00 2001 From: Charlie Wang Date: Wed, 21 Dec 2022 16:37:56 -0800 Subject: [PATCH] Address failing tests for CtsMultiUserHostTest. isDefaultServiceEnabled requires a permission check which looks like CTS tests do not have. Instead, manually check if the services passed in are default services, if not then use the ones provided for testing. Bug: 263418986 Test: atest CtsMultiUserHostTestCases:android.host.multiuser.EphemeralTest#testSwitchAndRemoveEphemeralUser atest CtsAmbientContextServiceTestCases atest CtsWearableSensingServiceTestCases. Ignore-AOSP-First: to prevent new feature leak. Change-Id: I2b2871d70d45401fe789c6abf948c42e2e12c871 --- .../AmbientContextManagerService.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/ambientcontext/AmbientContextManagerService.java b/services/core/java/com/android/server/ambientcontext/AmbientContextManagerService.java index a0c7ee65e4147..5c18827ebd61d 100644 --- a/services/core/java/com/android/server/ambientcontext/AmbientContextManagerService.java +++ b/services/core/java/com/android/server/ambientcontext/AmbientContextManagerService.java @@ -219,11 +219,10 @@ public class AmbientContextManagerService extends List serviceList = new ArrayList<>(serviceNames.length); - if (!isDefaultServiceEnabled(resolvedUserId)) { + if (serviceNames.length == 2) { Slog.i(TAG, "Not using default services, " + "services provided for testing should be exactly two services."); - if (serviceNames.length == 2) { - // Expecting two services for testing, first being the default and second wearable. + if (!isDefaultService(serviceNames[0]) && !isDefaultWearableService(serviceNames[1])) { serviceList.add(new DefaultAmbientContextManagerPerUserService( this, mLock, resolvedUserId, AmbientContextManagerPerUserService.ServiceType.DEFAULT, serviceNames[0])); @@ -231,10 +230,10 @@ public class AmbientContextManagerService extends this, mLock, resolvedUserId, AmbientContextManagerPerUserService.ServiceType.WEARABLE, serviceNames[1])); - } else { - Slog.i(TAG, "Incorrect number of services provided for testing."); } return serviceList; + } else { + Slog.i(TAG, "Incorrect number of services provided for testing."); } for (String serviceName : serviceNames) { @@ -428,6 +427,24 @@ public class AmbientContextManagerService extends return AmbientContextManagerPerUserService.ServiceType.DEFAULT; } + private boolean isDefaultService(String serviceName) { + final String defaultService = mContext.getResources() + .getString(R.string.config_defaultAmbientContextDetectionService); + if (defaultService != null && defaultService.equals(serviceName)) { + return true; + } + return false; + } + + private boolean isDefaultWearableService(String serviceName) { + final String wearableService = mContext.getResources() + .getString(R.string.config_defaultWearableSensingService); + if (wearableService != null && wearableService.equals(serviceName)) { + return true; + } + return false; + } + private AmbientContextManagerPerUserService getServiceForType(int userId, AmbientContextManagerPerUserService.ServiceType serviceType) { Slog.d(TAG, "getServiceForType with userid: "