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.app.admin.DevicePolicyManager; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.os.UserHandle; 24 import android.support.v7.preference.Preference; 25 import android.text.TextUtils; 26 27 import com.android.settings.R; 28 import com.android.settings.Utils; 29 import com.android.settings.core.SubSettingLauncher; 30 import com.android.settings.password.ChooseLockGeneric; 31 32 public class ChangeProfileScreenLockPreferenceController extends 33 ChangeScreenLockPreferenceController { 34 35 private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile"; 36 37 public ChangeProfileScreenLockPreferenceController(Context context, 38 SecuritySettings host) { 39 super(context, host); 40 } 41 42 public boolean isAvailable() { 43 if (mProfileChallengeUserId == UserHandle.USER_NULL || 44 !mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) { 45 return false; 46 } 47 if (!mLockPatternUtils.isSecure(mProfileChallengeUserId)) { 48 return true; 49 } 50 switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId)) { 51 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: 52 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: 53 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: 54 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: 55 case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: 56 case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: 57 case DevicePolicyManager.PASSWORD_QUALITY_MANAGED: 58 return true; 59 } 60 return false; 61 } 62 63 @Override 64 public String getPreferenceKey() { 65 return KEY_UNLOCK_SET_OR_CHANGE_PROFILE; 66 } 67 68 @Override 69 public boolean handlePreferenceTreeClick(Preference preference) { 70 if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) { 71 return false; 72 } 73 if (Utils.startQuietModeDialogIfNecessary(mContext, mUm, mProfileChallengeUserId)) { 74 return false; 75 } 76 final Bundle extras = new Bundle(); 77 extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId); 78 new SubSettingLauncher(mContext) 79 .setDestination(ChooseLockGeneric.ChooseLockGenericFragment.class.getName()) 80 .setTitle(R.string.lock_settings_picker_title_profile) 81 .setSourceMetricsCategory(mHost.getMetricsCategory()) 82 .setArguments(extras) 83 .launch(); 84 85 return true; 86 } 87 88 @Override 89 public void updateState(Preference preference) { 90 updateSummary(preference, mProfileChallengeUserId); 91 92 if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) { 93 final String summary = mContext.getString( 94 R.string.lock_settings_profile_unified_summary); 95 mPreference.setSummary(summary); 96 mPreference.setEnabled(false); 97 } else { 98 // PO may disallow to change profile password, and the profile's password is 99 // separated from screen lock password. Disable profile specific "Screen lock" menu. 100 disableIfPasswordQualityManaged(mProfileChallengeUserId); 101 } 102 } 103 } 104