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