• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.phone;
18 
19 import static org.junit.Assert.assertEquals;
20 
21 import android.content.Context;
22 import android.content.res.Configuration;
23 import android.content.res.Resources;
24 
25 import androidx.test.InstrumentationRegistry;
26 import androidx.test.runner.AndroidJUnit4;
27 
28 import com.android.TelephonyTestBase;
29 
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 
35 import java.util.Locale;
36 
37 
38 @RunWith(AndroidJUnit4.class)
39 public class PhoneGlobalsTest extends TelephonyTestBase {
40 
41     @Before
setUp()42     public void setUp() throws Exception {
43         super.setUp();
44     }
45 
46     @After
tearDown()47     public void tearDown() throws Exception {
48         super.tearDown();
49     }
50 
51     @Test
testGetImsResources()52     public void testGetImsResources() throws Exception {
53         // Do not use test context here, we are testing that overlaying for different locales works
54         // correctly
55         Context realContext = InstrumentationRegistry.getTargetContext();
56         String defaultImsMmtelPackage = getResourcesForLocale(realContext, Locale.US).getString(
57                 R.string.config_ims_mmtel_package);
58         String defaultImsMmtelPackageUk = getResourcesForLocale(realContext, Locale.UK).getString(
59                 R.string.config_ims_mmtel_package);
60         assertEquals("locales changed IMS package configuration!", defaultImsMmtelPackage,
61                 defaultImsMmtelPackageUk);
62     }
63 
getResourcesForLocale(Context context, Locale locale)64     private Resources getResourcesForLocale(Context context, Locale locale) {
65         Configuration config = new Configuration();
66         config.setToDefaults();
67         config.setLocale(locale);
68         Context localeContext = context.createConfigurationContext(config);
69         return localeContext.getResources();
70     }
71 }
72