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.car.settings.security; 18 19 import android.app.admin.DevicePolicyManager; 20 import android.app.admin.PasswordMetrics; 21 import android.car.drivingstate.CarUxRestrictions; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.os.UserHandle; 25 26 import androidx.preference.Preference; 27 28 import com.android.car.settings.common.FragmentController; 29 import com.android.internal.widget.LockPatternUtils; 30 31 /** Business logic for the lock pattern picker preference. */ 32 public class PatternLockPreferenceController extends LockTypeBasePreferenceController { 33 34 private static final int[] ALLOWED_PASSWORD_QUALITIES = 35 new int[]{DevicePolicyManager.PASSWORD_QUALITY_SOMETHING}; 36 37 private final LockPatternUtils mLockPatternUtils; 38 PatternLockPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)39 public PatternLockPreferenceController(Context context, String preferenceKey, 40 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 41 super(context, preferenceKey, fragmentController, uxRestrictions); 42 mLockPatternUtils = new LockPatternUtils(context); 43 } 44 45 @Override activityToOpen()46 protected Intent activityToOpen() { 47 return new Intent(getContext(), ChooseLockPatternActivity.class); 48 } 49 50 @Override allowedPasswordQualities()51 protected int[] allowedPasswordQualities() { 52 return ALLOWED_PASSWORD_QUALITIES; 53 } 54 55 @Override updateState(Preference preference)56 protected void updateState(Preference preference) { 57 super.updateState(preference); 58 59 PasswordMetrics metrics = mLockPatternUtils.getRequestedPasswordMetrics( 60 UserHandle.myUserId(), /* deviceWideOnly= */ false); 61 preference.setEnabled(metrics.credType <= LockPatternUtils.CREDENTIAL_TYPE_PATTERN); 62 } 63 } 64