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.systemui.biometrics; 18 19 import android.annotation.NonNull; 20 import android.content.Context; 21 import android.util.AttributeSet; 22 23 import com.android.internal.annotations.VisibleForTesting; 24 import com.android.internal.widget.LockPatternChecker; 25 import com.android.internal.widget.LockPatternUtils; 26 import com.android.internal.widget.LockPatternView; 27 import com.android.internal.widget.LockscreenCredential; 28 import com.android.internal.widget.VerifyCredentialResponse; 29 import com.android.systemui.R; 30 31 import java.util.List; 32 33 /** 34 * Pattern UI 35 */ 36 public class AuthCredentialPatternView extends AuthCredentialView { 37 38 @VisibleForTesting LockPatternView mLockPatternView; 39 40 private class UnlockPatternListener implements LockPatternView.OnPatternListener { 41 42 @Override onPatternStart()43 public void onPatternStart() { 44 45 } 46 47 @Override onPatternCleared()48 public void onPatternCleared() { 49 50 } 51 52 @Override onPatternCellAdded(List<LockPatternView.Cell> pattern)53 public void onPatternCellAdded(List<LockPatternView.Cell> pattern) { 54 55 } 56 57 @Override onPatternDetected(List<LockPatternView.Cell> pattern)58 public void onPatternDetected(List<LockPatternView.Cell> pattern) { 59 if (mPendingLockCheck != null) { 60 mPendingLockCheck.cancel(false); 61 } 62 63 mLockPatternView.setEnabled(false); 64 65 if (pattern.size() < LockPatternUtils.MIN_PATTERN_REGISTER_FAIL) { 66 // Pattern size is less than the minimum, do not count it as a failed attempt. 67 onPatternVerified(VerifyCredentialResponse.ERROR, 0 /* timeoutMs */); 68 return; 69 } 70 71 try (LockscreenCredential credential = LockscreenCredential.createPattern(pattern)) { 72 // Request LockSettingsService to return the Gatekeeper Password in the 73 // VerifyCredentialResponse so that we can request a Gatekeeper HAT with the 74 // Gatekeeper Password and operationId. 75 mPendingLockCheck = LockPatternChecker.verifyCredential( 76 mLockPatternUtils, 77 credential, 78 mEffectiveUserId, 79 LockPatternUtils.VERIFY_FLAG_REQUEST_GK_PW_HANDLE, 80 this::onPatternVerified); 81 } 82 } 83 onPatternVerified(@onNull VerifyCredentialResponse response, int timeoutMs)84 private void onPatternVerified(@NonNull VerifyCredentialResponse response, int timeoutMs) { 85 AuthCredentialPatternView.this.onCredentialVerified(response, timeoutMs); 86 if (timeoutMs > 0) { 87 mLockPatternView.setEnabled(false); 88 } else { 89 mLockPatternView.setEnabled(true); 90 } 91 } 92 } 93 94 @Override onErrorTimeoutFinish()95 protected void onErrorTimeoutFinish() { 96 super.onErrorTimeoutFinish(); 97 mLockPatternView.setEnabled(true); 98 } 99 AuthCredentialPatternView(Context context, AttributeSet attrs)100 public AuthCredentialPatternView(Context context, AttributeSet attrs) { 101 super(context, attrs); 102 } 103 104 @Override onAttachedToWindow()105 protected void onAttachedToWindow() { 106 super.onAttachedToWindow(); 107 mLockPatternView = findViewById(R.id.lockPattern); 108 mLockPatternView.setOnPatternListener(new UnlockPatternListener()); 109 mLockPatternView.setInStealthMode( 110 !mLockPatternUtils.isVisiblePatternEnabled(mUserId)); 111 } 112 } 113