1 /* 2 * Copyright (C) 2019 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.content.Context; 21 import android.os.Bundle; 22 import android.os.UserHandle; 23 24 import androidx.annotation.Nullable; 25 import androidx.fragment.app.Fragment; 26 27 import com.android.car.settings.common.Logger; 28 import com.android.internal.widget.LockPatternUtils; 29 30 /** 31 * Factory class which generate password fragment for current user. 32 */ 33 public class ConfirmPasswordFragmentFactory { 34 35 private static final Logger LOG = new Logger(ConfirmPasswordFragmentFactory.class); 36 37 /** 38 * Gets the correct password fragment of current user, returns the corresponding password 39 * fragment of current user 40 * 41 * @return {@code null} if no password is set for the current user. 42 */ 43 @Nullable getFragment(Context context)44 public static Fragment getFragment(Context context) { 45 Fragment fragment; 46 int passwordQuality = new LockPatternUtils(context).getKeyguardStoredPasswordQuality( 47 UserHandle.myUserId()); 48 switch (passwordQuality) { 49 case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: 50 // User has not set a password. 51 return null; 52 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: 53 fragment = new ConfirmLockPatternFragment(); 54 break; 55 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: 56 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: 57 fragment = ConfirmLockPinPasswordFragment.newPinInstance(); 58 break; 59 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: 60 case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: 61 fragment = ConfirmLockPinPasswordFragment.newPasswordInstance(); 62 break; 63 default: 64 LOG.e("Unexpected password quality: " + passwordQuality); 65 fragment = ConfirmLockPinPasswordFragment.newPasswordInstance(); 66 } 67 68 Bundle bundle = fragment.getArguments(); 69 if (bundle == null) { 70 bundle = new Bundle(); 71 } 72 bundle.putInt(PasswordHelper.EXTRA_CURRENT_PASSWORD_QUALITY, passwordQuality); 73 fragment.setArguments(bundle); 74 return fragment; 75 } 76 } 77