1 /* 2 * Copyright 2024 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 package com.android.ondevicepersonalization.cts.e2e; 17 18 import static org.junit.Assert.assertNotNull; 19 import static org.junit.Assert.assertTrue; 20 21 import android.adservices.ondevicepersonalization.OnDevicePersonalizationConfigManager; 22 import android.content.Context; 23 24 import androidx.test.core.app.ApplicationProvider; 25 import androidx.test.ext.junit.runners.AndroidJUnit4; 26 27 import com.android.compatibility.common.util.ShellUtils; 28 import com.android.ondevicepersonalization.testing.utils.DeviceSupportHelper; 29 import com.android.ondevicepersonalization.testing.utils.ResultReceiver; 30 31 import org.junit.After; 32 import org.junit.Assume; 33 import org.junit.Before; 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 37 import java.util.concurrent.Executors; 38 39 /** CTS Test cases for OnDevicePersonalizationConfigManager APIs. */ 40 @RunWith(AndroidJUnit4.class) 41 public class OdpConfigManagerTests { 42 private final Context mContext = ApplicationProvider.getApplicationContext(); 43 44 @Before setUp()45 public void setUp() throws Exception { 46 // Skip the test if it runs on unsupported platforms. 47 Assume.assumeTrue(DeviceSupportHelper.isDeviceSupported()); 48 49 ShellUtils.runShellCommand( 50 "device_config put on_device_personalization " 51 + "global_kill_switch " 52 + false); 53 } 54 55 @After cleanUp()56 public void cleanUp() throws Exception { 57 ShellUtils.runShellCommand( 58 "device_config delete on_device_personalization global_kill_switch"); 59 } 60 61 @Test testSetPersonalizationStatus()62 public void testSetPersonalizationStatus() throws Exception { 63 OnDevicePersonalizationConfigManager manager = 64 mContext.getSystemService(OnDevicePersonalizationConfigManager.class); 65 assertNotNull(manager); 66 ResultReceiver<Void> receiver = new ResultReceiver<>(); 67 manager.setPersonalizationEnabled(true, Executors.newSingleThreadExecutor(), receiver); 68 assertTrue(receiver.isCalled()); 69 } 70 } 71