• 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.car.hiddenapitest;
18 
19 import static android.provider.DeviceConfig.NAMESPACE_GAME_OVERLAY;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import static org.junit.Assert.assertThrows;
24 
25 import android.car.extendedapitest.testbase.CarApiTestBase;
26 import android.provider.DeviceConfig;
27 import android.provider.Settings;
28 import android.util.Log;
29 
30 import com.android.bedstead.harrier.DeviceState;
31 import com.android.bedstead.multiuser.annotations.RequireRunNotOnVisibleBackgroundNonProfileUser;
32 import com.android.bedstead.multiuser.annotations.RequireRunOnVisibleBackgroundNonProfileUser;
33 import com.android.bedstead.multiuser.annotations.RequireVisibleBackgroundUsers;
34 import com.android.compatibility.common.util.ApiTest;
35 
36 import org.junit.After;
37 import org.junit.Before;
38 import org.junit.ClassRule;
39 import org.junit.Rule;
40 import org.junit.Test;
41 
42 
43 public final class DeviceConfigTest extends CarApiTestBase {
44 
45     private static final String TAG = DeviceConfigTest.class.getSimpleName();
46 
47     @Rule
48     @ClassRule
49     public static final DeviceState sDeviceState = new DeviceState();
50 
51     public static final String KEY = "car_api_test_prop";
52     public static final String VALUE = "Set_Value_42";
53 
54     @Before
55     @After
cleanUp()56     public void cleanUp() {
57         try {
58             DeviceConfig.deleteProperty(NAMESPACE_GAME_OVERLAY, KEY);
59         } catch (Exception e) {
60             Log.e(TAG, "Failed to clean up", e);
61         }
62     }
63 
64     @Test
65     @ApiTest(apis = {"DeviceConfig.setProperty", "DeviceConfig.getProperty"})
66     @RequireVisibleBackgroundUsers(reason = "Device Config for only MUMD devices")
67     @RequireRunNotOnVisibleBackgroundNonProfileUser
testUpdateConfigForCurrentUser()68     public void testUpdateConfigForCurrentUser() throws Exception {
69         assertThat(DeviceConfig.setProperty(NAMESPACE_GAME_OVERLAY, KEY, VALUE,
70                 /* makeDefault= */ false)).isTrue();
71         assertThat(DeviceConfig.getProperty(NAMESPACE_GAME_OVERLAY, KEY)).isEqualTo(VALUE);
72     }
73 
74     @Test
75     @ApiTest(apis = {"Settings.Config.putString"})
76     @RequireVisibleBackgroundUsers(reason = "Device Config for only MUMD devices")
77     @RequireRunOnVisibleBackgroundNonProfileUser
testUpdateConfigForBackgroundUser()78     public void testUpdateConfigForBackgroundUser() throws Exception {
79         assertThrows(SecurityException.class,
80                 () -> Settings.Config.putString(NAMESPACE_GAME_OVERLAY, KEY, VALUE,
81                         /* makeDefault= */ false));
82     }
83 }
84