1 /* 2 * Copyright (C) 2021 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.content.Intent; 20 import android.os.UserHandle; 21 22 import androidx.annotation.Nullable; 23 import androidx.fragment.app.Fragment; 24 25 import com.android.car.settings.common.BaseCarSettingsActivity; 26 import com.android.internal.widget.LockPatternUtils; 27 import com.android.internal.widget.LockscreenCredential; 28 29 /** 30 * Activity for verifying current screen lock before allowing it to be changed. 31 * 32 * This activity differs from {@link CheckLockActivity}, as it provides screen lock data to the 33 * caller. Because of this sensitive data passing, this activity should not be externally 34 * accessible - external applications should use either {@link CheckLockActivity} or 35 * {@link SettingsScreenLockActivity} (depending on their use case). 36 */ 37 public class VerifyLockChangeActivity extends BaseCarSettingsActivity implements CheckLockListener { 38 private int mPasswordQuality; 39 40 @Override 41 @Nullable getInitialFragment()42 protected Fragment getInitialFragment() { 43 Fragment currentFragment = getCurrentFragment(); 44 if (currentFragment != null) { 45 return currentFragment; 46 } 47 48 mPasswordQuality = new LockPatternUtils(this).getKeyguardStoredPasswordQuality( 49 UserHandle.myUserId()); 50 51 Fragment lockFragment = ConfirmPasswordFragmentFactory.getFragment(/* context= */ this); 52 if (lockFragment == null) { 53 // User has not set a password 54 setResult(RESULT_OK); 55 finish(); 56 } 57 return lockFragment; 58 } 59 60 @Override onLockVerified(LockscreenCredential lock)61 public void onLockVerified(LockscreenCredential lock) { 62 Intent data = new Intent(); 63 data.putExtra(PasswordHelper.EXTRA_CURRENT_SCREEN_LOCK, lock); 64 data.putExtra(PasswordHelper.EXTRA_CURRENT_PASSWORD_QUALITY, mPasswordQuality); 65 setResult(RESULT_OK, data); 66 finish(); 67 } 68 69 @Override onDestroy()70 public void onDestroy() { 71 PasswordHelper.zeroizeCredentials(); 72 super.onDestroy(); 73 } 74 } 75