• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.assertFalse;
20 import static org.junit.Assert.assertNotEquals;
21 import static org.junit.Assert.assertTrue;
22 
23 import android.os.flagging.AconfigPackage;
24 import android.os.flagging.FlagManager;
25 import android.platform.test.annotations.RequiresFlagsEnabled;
26 import android.platform.test.flag.junit.CheckFlagsRule;
27 import android.platform.test.flag.junit.DeviceFlagsValueProvider;
28 import android.provider.flags.Flags;
29 
30 import androidx.test.InstrumentationRegistry;
31 
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.junit.runners.JUnit4;
36 
37 import java.io.IOException;
38 import java.util.HashMap;
39 import java.util.HashSet;
40 
41 @RunWith(JUnit4.class)
42 public class FlagManagerUnitTests {
43     @Rule
44     public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
45 
46     @Test
47     @RequiresFlagsEnabled(Flags.FLAG_NEW_STORAGE_PUBLIC_API)
testSetBooleanLocalOverrideImmediately()48     public void testSetBooleanLocalOverrideImmediately() throws IOException {
49         FlagManager flagManager =
50                 InstrumentationRegistry.getInstrumentation()
51                         .getContext()
52                         .getSystemService(FlagManager.class);
53         assertNotEquals(flagManager, null);
54 
55         HashMap<String, Boolean> flagsToValues = new HashMap();
56         flagsToValues.put("android.provider.flags.flag_manager_unit_test_flag", true);
57         flagManager.setBooleanLocalOverridesImmediately(flagsToValues);
58 
59         AconfigPackage aconfigPackage = AconfigPackage.load("android.provider.flags");
60         boolean value = aconfigPackage.getBooleanFlagValue("flag_manager_unit_test_flag", false);
61 
62         assertTrue(value);
63 
64         HashSet<String> flagNames = new HashSet();
65         flagNames.add("android.provider.flags.flag_manager_unit_test_flag");
66         flagManager.clearBooleanLocalOverridesImmediately(flagNames);
67 
68         AconfigPackage aconfigPackageAfterClearing = AconfigPackage.load("android.provider.flags");
69         boolean valueAfterClearing =
70                 aconfigPackageAfterClearing.getBooleanFlagValue(
71                         "flag_manager_unit_test_flag", false);
72 
73         assertFalse(valueAfterClearing);
74     }
75 }
76