• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Global.PACKAGE_VERIFIER_ENABLE;
21 import static android.provider.Settings.Secure.MANAGED_PROFILE_CONTACT_REMOTE_SEARCH;
22 import static android.provider.Settings.Secure.CROSS_PROFILE_CALENDAR_ENABLED;
23 import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
24 
25 import android.content.Context;
26 import android.provider.Settings.Global;
27 import android.provider.Settings.Secure;
28 
29 /**
30  * Wrapper class around the static Settings provider calls.
31  */
32 public class SettingsFacade {
33     /**
34      * Sets USER_SETUP_COMPLETE for a given user.
35      */
setUserSetupCompleted(Context context, int userId)36     public void setUserSetupCompleted(Context context, int userId) {
37         ProvisionLogger.logd("Setting USER_SETUP_COMPLETE to 1 for user " + userId);
38         Secure.putIntForUser(context.getContentResolver(), USER_SETUP_COMPLETE, 1, userId);
39     }
40 
41     /**
42      * Returns whether USER_SETUP_COMPLETE is set on the calling user.
43      */
isUserSetupCompleted(Context context)44     public boolean isUserSetupCompleted(Context context) {
45         return Secure.getInt(context.getContentResolver(), USER_SETUP_COMPLETE, 0) != 0;
46     }
47 
48     /**
49      * Returns whether DEVICE_PROVISIONED is set.
50      */
isDeviceProvisioned(Context context)51     public boolean isDeviceProvisioned(Context context) {
52         return Global.getInt(context.getContentResolver(), DEVICE_PROVISIONED, 0) != 0;
53     }
54 
55     /**
56      * Sets DEVICE_PROVISIONED.
57      */
setDeviceProvisioned(Context context)58     public void setDeviceProvisioned(Context context) {
59         Global.putInt(context.getContentResolver(), DEVICE_PROVISIONED, 1);
60     }
61 
62     /**
63      * Sets whether package verification is enabled or not.
64      */
setPackageVerifierEnabled(Context context, boolean packageVerifierEnabled)65     public void setPackageVerifierEnabled(Context context, boolean packageVerifierEnabled) {
66         Global.putInt(context.getContentResolver(), PACKAGE_VERIFIER_ENABLE,
67                 packageVerifierEnabled ? 1 : 0);
68     }
69 
70     /**
71      * Returns whether package verification is enabled or not.
72      */
isPackageVerifierEnabled(Context context)73     public boolean isPackageVerifierEnabled(Context context) {
74         return Global.getInt(context.getContentResolver(), PACKAGE_VERIFIER_ENABLE, 0) != 0;
75     }
76 
77     /**
78      * Sets whether profile contact remote search is enabled.
79      */
setProfileContactRemoteSearch(Context context, boolean allowed, int userId)80     public void setProfileContactRemoteSearch(Context context, boolean allowed, int userId) {
81         Secure.putIntForUser(context.getContentResolver(),
82                 MANAGED_PROFILE_CONTACT_REMOTE_SEARCH, allowed ? 1 : 0, userId);
83     }
84 
85     /**
86      * Sets whether cross-profile calendar is enabled.
87      */
setCrossProfileCalendarEnabled(Context context, boolean allowed, int userId)88     public void setCrossProfileCalendarEnabled(Context context, boolean allowed, int userId) {
89         Secure.putIntForUser(context.getContentResolver(),
90                 CROSS_PROFILE_CALENDAR_ENABLED, allowed ? 1 : 0, userId);
91     }
92 
93     /**
94      * Returns whether we are running during the setup wizard flow.
95      */
isDuringSetupWizard(Context context)96     public boolean isDuringSetupWizard(Context context) {
97         // If the flow is running in SUW, the primary user is not set up at this point
98         return !isUserSetupCompleted(context);
99     }
100 }
101