Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae8d3d62 authored by Charlie Wang's avatar Charlie Wang
Browse files

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
parent 15c52c54
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -219,11 +219,10 @@ public class AmbientContextManagerService extends

        List<AmbientContextManagerPerUserService> 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: "