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 23 import com.android.internal.widget.LockPatternUtils; 24 import com.android.settings.core.TogglePreferenceController; 25 26 public class LockdownButtonPreferenceController extends TogglePreferenceController { 27 28 private final LockPatternUtils mLockPatternUtils; 29 LockdownButtonPreferenceController(Context context, String key)30 public LockdownButtonPreferenceController(Context context, String key) { 31 super(context, key); 32 mLockPatternUtils = new LockPatternUtils(context); 33 } 34 35 @Override getAvailabilityStatus()36 public int getAvailabilityStatus() { 37 if (mLockPatternUtils.isSecure(UserHandle.myUserId())) { 38 return AVAILABLE; 39 } else { 40 return DISABLED_FOR_USER; 41 } 42 } 43 44 @Override isChecked()45 public boolean isChecked() { 46 return Settings.Secure.getInt(mContext.getContentResolver(), 47 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0) != 0; 48 } 49 50 @Override setChecked(boolean isChecked)51 public boolean setChecked(boolean isChecked) { 52 Settings.Secure.putInt(mContext.getContentResolver(), 53 Settings.Secure.LOCKDOWN_IN_POWER_MENU, isChecked ? 1 : 0); 54 return true; 55 } 56 } 57