• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.androidbvt;
18 
19 import android.content.ContentResolver;
20 import android.content.Context;
21 import android.os.Environment;
22 import android.provider.Settings;
23 import android.support.test.InstrumentationRegistry;
24 import android.test.suitebuilder.annotation.MediumTest;
25 
26 import junit.framework.TestCase;
27 
28 import java.io.IOException;
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.Map.Entry;
32 
33 /*
34  * Basic test for checking setting are set to default values
35  */
36 public class SysSettingTests extends TestCase {
37     private Context mContext = null;
38     private AndroidBvtHelper mABvtHelper = null;
39     private ContentResolver mResolver = null;
40 
41     private static enum mSettingType {
42         SYSTEM, SECURE, GLOBAL
43     }
44 
45     private static HashMap<String, String> mGlobalSettings = new HashMap<String, String>();
46     {
47         //Bluetooth is by default OFF.
48         mGlobalSettings.put("bluetooth_on", "0");
49         //Airplane mode is by default OFF
50         mGlobalSettings.put("airplane_mode_on", "0");
51         //Wifi is by default on for testing
52         mGlobalSettings.put("wifi_on", "1");
53         //Data roaming is by default OFF
54         mGlobalSettings.put("data_roaming", "0");
55         //Do not Disturb mode is by default OFF
56         mGlobalSettings.put("zen_mode", "0");
57     }
58 
59     private static HashMap<String, String> mSystemSettings = new HashMap<String, String>();
60     {
61         //Automatic Brightness mode is by default on
62         mSystemSettings.put("screen_brightness_mode", "1");
63         //By default 30sec before the device goes to sleep after inactivity
64         mSystemSettings.put("screen_off_timeout", "30000");
65         //By default Font is 1.0
66         mSystemSettings.put("font_scale", "1.0");
67     }
68 
69     private static HashMap<String, String> mSecureSettings = new HashMap<String, String>();
70     {
71         //By default screensaver is enabled
72         mSecureSettings.put("screensaver_enabled", "1");
73     }
74 
75     private static Map<mSettingType, HashMap<String, String>> mSettings =
76             new HashMap<mSettingType, HashMap<String, String>>();
77     {
mSettings.put(mSettingType.GLOBAL, mGlobalSettings)78         mSettings.put(mSettingType.GLOBAL, mGlobalSettings);
mSettings.put(mSettingType.SYSTEM, mSystemSettings)79         mSettings.put(mSettingType.SYSTEM, mSystemSettings);
mSettings.put(mSettingType.SECURE, mSecureSettings)80         mSettings.put(mSettingType.SECURE, mSecureSettings);
81     }
82 
83     @Override
setUp()84     public void setUp() throws Exception {
85         super.setUp();
86         mContext = InstrumentationRegistry.getTargetContext();
87         mResolver = mContext.getContentResolver();
88     }
89 
90     @Override
tearDown()91     public void tearDown() throws Exception {
92         super.tearDown();
93     }
94 
95     @MediumTest
testSettingDefaultValues()96     public void testSettingDefaultValues(){
97         for(Entry<mSettingType, HashMap<String, String>> settingsByType : mSettings.entrySet()){
98             mSettingType settingType = settingsByType.getKey();
99             HashMap<String, String> settings = settingsByType.getValue();
100             for (Entry<String, String> settingPair : settings.entrySet()) {
101                 assertTrue(
102                         String.format("%s does not have default value: %s", settingPair.getKey(),
103                                 settingPair.getValue()),
104                         getStringSetting(settingType, settingPair.getKey())
105                                 .equals(settingPair.getValue()));
106             }
107         }
108     }
109 
getStringSetting(mSettingType type, String sName)110     private String getStringSetting(mSettingType type, String sName) {
111         switch (type) {
112             case SYSTEM:
113                 return Settings.System.getString(mResolver, sName);
114             case GLOBAL:
115                 return Settings.Global.getString(mResolver, sName);
116             case SECURE:
117                 return Settings.Secure.getString(mResolver, sName);
118         }
119         return null;
120     }
121 }
122