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.os.Bundle; 21 import android.os.UserHandle; 22 23 import androidx.annotation.Nullable; 24 import androidx.fragment.app.Fragment; 25 26 import com.android.car.settings.R; 27 import com.android.car.settings.common.BaseCarSettingsActivity; 28 import com.android.car.settings.common.Logger; 29 import com.android.internal.widget.LockPatternUtils; 30 import com.android.internal.widget.LockscreenCredential; 31 32 /** 33 * Activity for setting screen locks 34 */ 35 public class SettingsScreenLockActivity extends BaseCarSettingsActivity implements 36 CheckLockListener { 37 38 private static final Logger LOG = new Logger(SettingsScreenLockActivity.class); 39 40 private int mPasswordQuality; 41 42 @Override 43 @Nullable getInitialFragment()44 protected Fragment getInitialFragment() { 45 Fragment currentFragment = getCurrentFragment(); 46 if (currentFragment != null) { 47 return currentFragment; 48 } 49 50 mPasswordQuality = new LockPatternUtils(this).getKeyguardStoredPasswordQuality( 51 UserHandle.myUserId()); 52 53 Fragment fragment; 54 switch (mPasswordQuality) { 55 case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: 56 fragment = new ChooseLockTypeFragment(); 57 break; 58 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: 59 fragment = new ConfirmLockPatternFragment(); 60 break; 61 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: 62 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: 63 fragment = ConfirmLockPinPasswordFragment.newPinInstance(); 64 break; 65 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: 66 case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: 67 fragment = ConfirmLockPinPasswordFragment.newPasswordInstance(); 68 break; 69 default: 70 LOG.e("Unexpected password quality: " + String.valueOf(mPasswordQuality)); 71 fragment = ConfirmLockPinPasswordFragment.newPasswordInstance(); 72 } 73 74 Bundle bundle = fragment.getArguments(); 75 if (bundle == null) { 76 bundle = new Bundle(); 77 } 78 bundle.putInt(PasswordHelper.EXTRA_CURRENT_PASSWORD_QUALITY, mPasswordQuality); 79 fragment.setArguments(bundle); 80 return fragment; 81 } 82 83 @Override onLockVerified(LockscreenCredential lock)84 public void onLockVerified(LockscreenCredential lock) { 85 Fragment fragment = new ChooseLockTypeFragment(); 86 Bundle bundle = fragment.getArguments(); 87 if (bundle == null) { 88 bundle = new Bundle(); 89 } 90 bundle.putParcelable(PasswordHelper.EXTRA_CURRENT_SCREEN_LOCK, lock); 91 bundle.putInt(PasswordHelper.EXTRA_CURRENT_PASSWORD_QUALITY, mPasswordQuality); 92 fragment.setArguments(bundle); 93 94 // Intentionally not using launchFragment(), since we do not want to add to the back stack. 95 getSupportFragmentManager() 96 .beginTransaction() 97 .replace(R.id.fragment_container, fragment) 98 .commit(); 99 } 100 101 @Override onDestroy()102 public void onDestroy() { 103 super.onDestroy(); 104 105 PasswordHelper.zeroizeCredentials(); 106 } 107 } 108