1 /* 2 * Copyright (C) 2018 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.settings.security; 18 19 import android.content.Context; 20 import android.os.UserHandle; 21 import android.provider.Settings; 22 import android.support.v7.preference.Preference; 23 import android.support.v7.preference.TwoStatePreference; 24 25 import com.android.internal.widget.LockPatternUtils; 26 import com.android.settings.core.BasePreferenceController; 27 import com.android.settings.core.TogglePreferenceController; 28 29 public class LockdownButtonPreferenceController extends TogglePreferenceController { 30 31 private static final String KEY_LOCKDOWN_ENALBED = "security_setting_lockdown_enabled"; 32 33 private final LockPatternUtils mLockPatternUtils; 34 35 public LockdownButtonPreferenceController(Context context) { 36 super(context, KEY_LOCKDOWN_ENALBED); 37 mLockPatternUtils = new LockPatternUtils(context); 38 } 39 40 @Override 41 public int getAvailabilityStatus() { 42 if (mLockPatternUtils.isSecure(UserHandle.myUserId())) { 43 return BasePreferenceController.AVAILABLE; 44 } else { 45 return BasePreferenceController.DISABLED_FOR_USER; 46 } 47 } 48 49 @Override 50 public boolean isChecked() { 51 return Settings.Secure.getInt(mContext.getContentResolver(), 52 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0) != 0; 53 } 54 55 @Override 56 public boolean setChecked(boolean isChecked) { 57 Settings.Secure.putInt(mContext.getContentResolver(), 58 Settings.Secure.LOCKDOWN_IN_POWER_MENU, isChecked ? 1 : 0); 59 return true; 60 } 61 } 62