1 /* 2 * Copyright (C) 2012 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.keyguard; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.HapticFeedbackConstants; 22 import android.view.KeyEvent; 23 import android.view.View; 24 25 import androidx.annotation.CallSuper; 26 27 import com.android.internal.widget.LockscreenCredential; 28 import com.android.systemui.res.R; 29 30 /** 31 * Base class for PIN and password unlock screens. 32 */ 33 public abstract class KeyguardAbsKeyInputView extends KeyguardInputView { 34 protected View mEcaView; 35 36 // To avoid accidental lockout due to events while the device in the pocket, ignore 37 // any passwords with length less than or equal to this length. 38 protected static final int MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT = 3; 39 private KeyDownListener mKeyDownListener; 40 KeyguardAbsKeyInputView(Context context)41 public KeyguardAbsKeyInputView(Context context) { 42 this(context, null); 43 } 44 KeyguardAbsKeyInputView(Context context, AttributeSet attrs)45 public KeyguardAbsKeyInputView(Context context, AttributeSet attrs) { 46 super(context, attrs); 47 } 48 getPasswordTextViewId()49 protected abstract int getPasswordTextViewId(); resetState()50 protected abstract void resetState(); 51 52 @Override 53 @CallSuper onFinishInflate()54 protected void onFinishInflate() { 55 super.onFinishInflate(); 56 mEcaView = findViewById(R.id.keyguard_selector_fade_container); 57 } 58 59 /* 60 * Override this if you have a different string for "wrong password" 61 * 62 * Note that PIN/PUK have their own implementation of verifyPasswordAndUnlock and so don't need this 63 */ getWrongPasswordStringId()64 protected int getWrongPasswordStringId() { 65 return R.string.kg_wrong_password; 66 } 67 resetPasswordText(boolean animate, boolean announce)68 protected abstract void resetPasswordText(boolean animate, boolean announce); getEnteredCredential()69 protected abstract LockscreenCredential getEnteredCredential(); setPasswordEntryEnabled(boolean enabled)70 protected abstract void setPasswordEntryEnabled(boolean enabled); setPasswordEntryInputEnabled(boolean enabled)71 protected abstract void setPasswordEntryInputEnabled(boolean enabled); 72 73 @Override onKeyDown(int keyCode, KeyEvent event)74 public boolean onKeyDown(int keyCode, KeyEvent event) { 75 return mKeyDownListener != null && mKeyDownListener.onKeyDown(keyCode, event); 76 } 77 getPromptReasonStringRes(int reason)78 protected abstract int getPromptReasonStringRes(int reason); 79 80 // Cause a VIRTUAL_KEY vibration doHapticKeyClick()81 public void doHapticKeyClick() { 82 performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, 83 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); 84 } 85 setKeyDownListener(KeyDownListener keyDownListener)86 public void setKeyDownListener(KeyDownListener keyDownListener) { 87 mKeyDownListener = keyDownListener; 88 } 89 90 public interface KeyDownListener { onKeyDown(int keyCode, KeyEvent keyEvent)91 boolean onKeyDown(int keyCode, KeyEvent keyEvent); 92 } 93 } 94 95