1 /* 2 * Copyright (C) 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 17 package android.os.flagging.test; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertNotEquals; 21 import static org.junit.Assert.assertThrows; 22 23 import org.junit.Test; 24 import org.junit.runner.RunWith; 25 import org.junit.runners.JUnit4; 26 import org.junit.Rule; 27 28 import android.os.flagging.AconfigStorageWriteException; 29 import android.os.flagging.FlagManager; 30 import android.platform.test.annotations.RequiresFlagsEnabled; 31 import android.platform.test.flag.junit.CheckFlagsRule; 32 import android.platform.test.flag.junit.DeviceFlagsValueProvider; 33 import android.provider.flags.Flags; 34 import androidx.test.InstrumentationRegistry; 35 36 import java.io.IOException; 37 import java.util.HashMap; 38 import java.util.HashSet; 39 import java.util.List; 40 import java.util.Map; 41 42 @RunWith(JUnit4.class) 43 public class AconfigPublicApiCtsTests { 44 @Rule 45 public final CheckFlagsRule mCheckFlagsRule = 46 DeviceFlagsValueProvider.createCheckFlagsRule(); 47 48 @Test 49 @RequiresFlagsEnabled(Flags.FLAG_NEW_STORAGE_PUBLIC_API) testTestProcessCannotCallWriteApis()50 public void testTestProcessCannotCallWriteApis() throws IOException { 51 FlagManager flagManager = 52 InstrumentationRegistry.getInstrumentation() 53 .getContext() 54 .getSystemService(FlagManager.class); 55 assertNotEquals(flagManager, null); 56 57 assertThrows( 58 AconfigStorageWriteException.class, 59 () -> 60 flagManager.setBooleanOverridesOnSystemBuildFingerprint( 61 "test_fingerprint", new HashMap())); 62 63 assertThrows( 64 AconfigStorageWriteException.class, 65 () -> flagManager.setBooleanOverridesOnReboot(new HashMap())); 66 67 assertThrows( 68 AconfigStorageWriteException.class, 69 () -> flagManager.setBooleanLocalOverridesOnReboot(new HashMap())); 70 71 assertThrows( 72 AconfigStorageWriteException.class, 73 () -> flagManager.setBooleanLocalOverridesImmediately(new HashMap())); 74 75 assertThrows( 76 AconfigStorageWriteException.class, 77 () -> flagManager.clearBooleanLocalOverridesImmediately(new HashSet())); 78 79 assertThrows( 80 AconfigStorageWriteException.class, 81 () -> flagManager.clearBooleanLocalOverridesOnReboot(new HashSet())); 82 } 83 84 @Test 85 @RequiresFlagsEnabled(Flags.FLAG_NEW_STORAGE_PUBLIC_API) testAconfigStorageWriteException()86 public void testAconfigStorageWriteException(){ 87 // create new instance of AconfigStorageWriteException 88 AconfigStorageWriteException exception = 89 new AconfigStorageWriteException("test message"); 90 assertEquals(exception.getMessage(), "test message"); 91 92 Exception cause = new Exception("test cause"); 93 exception = new AconfigStorageWriteException("test message", cause); 94 assertEquals(exception.getMessage(), "test message"); 95 assertEquals(exception.getCause(), cause); 96 } 97 } 98