1 /*
2  * Copyright 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.managedprovisioning.common;
18 
19 import static android.provider.Settings.Global.DEVICE_PROVISIONED;
20 import static android.provider.Settings.Secure.MANAGED_PROFILE_CONTACT_REMOTE_SEARCH;
21 import static android.provider.Settings.Secure.CROSS_PROFILE_CALENDAR_ENABLED;
22 import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
23 
24 import android.content.Context;
25 import android.provider.Settings.Global;
26 import android.provider.Settings.Secure;
27 
28 /**
29  * Wrapper class around the static Settings provider calls.
30  */
31 public class SettingsFacade {
32     /**
33      * Sets USER_SETUP_COMPLETE for a given user.
34      */
setUserSetupCompleted(Context context, int userId)35     public void setUserSetupCompleted(Context context, int userId) {
36         ProvisionLogger.logd("Setting USER_SETUP_COMPLETE to 1 for user " + userId);
37         Secure.putIntForUser(context.getContentResolver(), USER_SETUP_COMPLETE, 1, userId);
38     }
39 
40     /**
41      * Returns whether USER_SETUP_COMPLETE is set on the calling user.
42      */
isUserSetupCompleted(Context context)43     public boolean isUserSetupCompleted(Context context) {
44         return Secure.getInt(context.getContentResolver(), USER_SETUP_COMPLETE, 0) != 0;
45     }
46 
47     /**
48      * Returns whether DEVICE_PROVISIONED is set.
49      */
isDeviceProvisioned(Context context)50     public boolean isDeviceProvisioned(Context context) {
51         return Global.getInt(context.getContentResolver(), DEVICE_PROVISIONED, 0) != 0;
52     }
53 
54     /**
55      * Sets whether profile contact remote search is enabled.
56      */
setProfileContactRemoteSearch(Context context, boolean allowed, int userId)57     public void setProfileContactRemoteSearch(Context context, boolean allowed, int userId) {
58         Secure.putIntForUser(context.getContentResolver(),
59                 MANAGED_PROFILE_CONTACT_REMOTE_SEARCH, allowed ? 1 : 0, userId);
60     }
61 
62     /**
63      * Sets whether cross-profile calendar is enabled.
64      */
setCrossProfileCalendarEnabled(Context context, boolean allowed, int userId)65     public void setCrossProfileCalendarEnabled(Context context, boolean allowed, int userId) {
66         Secure.putIntForUser(context.getContentResolver(),
67                 CROSS_PROFILE_CALENDAR_ENABLED, allowed ? 1 : 0, userId);
68     }
69 
70     /**
71      * Returns whether we are running during the setup wizard flow.
72      */
isDuringSetupWizard(Context context)73     public boolean isDuringSetupWizard(Context context) {
74         // If the flow is running in SUW, the primary user is not set up at this point
75         return !isUserSetupCompleted(context);
76     }
77 
78     /**
79      * Returns whether ADB is enabled (developer mode)
80      */
isDeveloperMode(Context context)81     public boolean isDeveloperMode(Context context) {
82         return Global.getInt(context.getContentResolver(), Global.ADB_ENABLED, 0) > 0;
83     }
84 }
85