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.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 package verification is enabled or not. 56 */ setPackageVerifierEnabled(Context context, boolean packageVerifierEnabled)57 public void setPackageVerifierEnabled(Context context, boolean packageVerifierEnabled) { 58 Global.putInt(context.getContentResolver(), PACKAGE_VERIFIER_ENABLE, 59 packageVerifierEnabled ? 1 : 0); 60 } 61 62 /** 63 * Returns whether package verification is enabled or not. 64 */ isPackageVerifierEnabled(Context context)65 public boolean isPackageVerifierEnabled(Context context) { 66 return Global.getInt(context.getContentResolver(), PACKAGE_VERIFIER_ENABLE, 0) != 0; 67 } 68 69 /** 70 * Sets whether profile contact remote search is enabled. 71 */ setProfileContactRemoteSearch(Context context, boolean allowed, int userId)72 public void setProfileContactRemoteSearch(Context context, boolean allowed, int userId) { 73 Secure.putIntForUser(context.getContentResolver(), 74 MANAGED_PROFILE_CONTACT_REMOTE_SEARCH, allowed ? 1 : 0, userId); 75 } 76 } 77