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.server.deviceconfig; 18 19 import static org.junit.Assert.assertFalse; 20 import static org.junit.Assert.assertTrue; 21 import static org.junit.Assert.assertEquals; 22 import static org.junit.Assume.assumeTrue; 23 24 import android.provider.DeviceConfig; 25 26 import com.android.modules.utils.build.SdkLevel; 27 28 import com.android.server.deviceconfig.DeviceConfigBootstrapValues; 29 30 import androidx.test.platform.app.InstrumentationRegistry; 31 import androidx.test.runner.AndroidJUnit4; 32 33 import java.io.IOException; 34 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 38 @RunWith(AndroidJUnit4.class) 39 public class DeviceConfigBootstrapValuesTest { 40 private static final String WRITE_DEVICE_CONFIG_PERMISSION = 41 "android.permission.WRITE_DEVICE_CONFIG"; 42 43 private static final String READ_DEVICE_CONFIG_PERMISSION = 44 "android.permission.READ_DEVICE_CONFIG"; 45 46 private static final String PATH_1 = "file:///data/local/tmp/deviceconfig/bootstrap1.txt"; 47 48 @Test assertParsesFiles()49 public void assertParsesFiles() throws IOException { 50 assumeTrue(SdkLevel.isAtLeastV()); 51 InstrumentationRegistry.getInstrumentation().getUiAutomation().adoptShellPermissionIdentity( 52 WRITE_DEVICE_CONFIG_PERMISSION, READ_DEVICE_CONFIG_PERMISSION); 53 54 DeviceConfigBootstrapValues values = new DeviceConfigBootstrapValues(PATH_1); 55 values.applyValuesIfNeeded(); 56 57 assertTrue(DeviceConfig.getBoolean("a.a.a", "b.b.b", false)); 58 assertFalse(DeviceConfig.getBoolean("a.a.a", "b.b", true)); 59 assertTrue(DeviceConfig.getBoolean("b.b.b", "c.c", false)); 60 assertEquals(2, DeviceConfig.getProperties("a.a.a").getKeyset().size()); 61 assertEquals(1, DeviceConfig.getProperties("b.b.b").getKeyset().size()); 62 } 63 } 64