1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.adservices.common; 18 19 import com.android.compatibility.common.util.ShellUtils; 20 21 /** Class to place back-compat Adservices related helper methods */ 22 public class CompatAdServicesTestUtils { 23 private static final int PPAPI_AND_SYSTEM_SERVER_SOURCE_OF_TRUTH = 2; 24 private static final int APPSEARCH_ONLY = 3; 25 CompatAdServicesTestUtils()26 private CompatAdServicesTestUtils() { 27 /* cannot be instantiated */ 28 } 29 30 /** 31 * Common flags that need to be set to enable back-compat and avoid invoking system server 32 * related code on S- before running various PPAPI related tests. 33 */ setFlags()34 public static void setFlags() { 35 setEnableBackCompatFlag(true); 36 setBlockedTopicsSourceOfTruth(APPSEARCH_ONLY); 37 setConsentSourceOfTruth(APPSEARCH_ONLY); 38 setEnableAppSearchConsentData(true); 39 setEnableMeasurementRollbackAppSearchKillSwitch(false); 40 } 41 42 /** Reset back-compat related flags to their default values after test execution. */ resetFlagsToDefault()43 public static void resetFlagsToDefault() { 44 setEnableBackCompatFlag(false); 45 setBlockedTopicsSourceOfTruth(PPAPI_AND_SYSTEM_SERVER_SOURCE_OF_TRUTH); 46 setConsentSourceOfTruth(PPAPI_AND_SYSTEM_SERVER_SOURCE_OF_TRUTH); 47 setEnableAppSearchConsentData(false); 48 setEnableMeasurementRollbackAppSearchKillSwitch(true); 49 } 50 setPpapiAppAllowList(String allowList)51 public static void setPpapiAppAllowList(String allowList) { 52 ShellUtils.runShellCommand( 53 "device_config put adservices ppapi_app_allow_list " + allowList); 54 } 55 getAndOverridePpapiAppAllowList(String packageName)56 public static String getAndOverridePpapiAppAllowList(String packageName) { 57 String mPreviousAppAllowList = 58 ShellUtils.runShellCommand("device_config get adservices ppapi_app_allow_list"); 59 setPpapiAppAllowList(mPreviousAppAllowList + "," + packageName); 60 return mPreviousAppAllowList; 61 } 62 setEnableBackCompatFlag(boolean isEnabled)63 private static void setEnableBackCompatFlag(boolean isEnabled) { 64 ShellUtils.runShellCommand("device_config put adservices enable_back_compat " + isEnabled); 65 } 66 setConsentSourceOfTruth(int source)67 private static void setConsentSourceOfTruth(int source) { 68 ShellUtils.runShellCommand( 69 "device_config put adservices consent_source_of_truth " + source); 70 } 71 setBlockedTopicsSourceOfTruth(int source)72 private static void setBlockedTopicsSourceOfTruth(int source) { 73 ShellUtils.runShellCommand( 74 "device_config put adservices blocked_topics_source_of_truth " + source); 75 } 76 setEnableAppSearchConsentData(boolean isEnabled)77 private static void setEnableAppSearchConsentData(boolean isEnabled) { 78 ShellUtils.runShellCommand( 79 "device_config put adservices enable_appsearch_consent_data " + isEnabled); 80 } 81 setEnableMeasurementRollbackAppSearchKillSwitch(boolean isEnabled)82 private static void setEnableMeasurementRollbackAppSearchKillSwitch(boolean isEnabled) { 83 ShellUtils.runShellCommand( 84 "device_config put adservices measurement_rollback_deletion_app_search_kill_switch " 85 + isEnabled); 86 } 87 } 88