103c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi/* 203c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * Copyright (C) 2014 The Android Open Source Project 303c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * 403c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * Licensed under the Apache License, Version 2.0 (the "License"); 503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * you may not use this file except in compliance with the License. 603c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * You may obtain a copy of the License at 703c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * 803c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * http://www.apache.org/licenses/LICENSE-2.0 903c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * 1003c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * Unless required by applicable law or agreed to in writing, software 1103c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * distributed under the License is distributed on an "AS IS" BASIS, 1203c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1303c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * See the License for the specific language governing permissions and 1403c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * limitations under the License 1503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi */ 1603c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 1703c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggipackage com.android.systemui.statusbar.phone; 1803c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 19657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzicimport android.app.ActivityManager; 2003c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggiimport android.content.Context; 21657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzicimport android.os.UserHandle; 22b799d3f127f7410e8d0afe16343032e6115750fcToni Barzicimport android.os.UserManager; 23657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzicimport android.util.Slog; 24df993513fbfe0e952175c1c5384458deaa1ff01aJorim Jaggiimport android.view.KeyEvent; 2503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggiimport android.view.LayoutInflater; 2603c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggiimport android.view.View; 2703c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggiimport android.view.ViewGroup; 28edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roosimport android.view.ViewTreeObserver; 29c1dff8cee8cf334906c1572cc3c50fbff96d1839Jorim Jaggiimport android.view.accessibility.AccessibilityEvent; 3003c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 3103c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggiimport com.android.internal.widget.LockPatternUtils; 326b88cdfba770efc5722338c240ccaada13d7b0d4Jorim Jaggiimport com.android.keyguard.KeyguardHostView; 333122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinekimport com.android.keyguard.KeyguardSecurityView; 3425b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggiimport com.android.keyguard.KeyguardUpdateMonitor; 3525b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggiimport com.android.keyguard.KeyguardUpdateMonitorCallback; 3603c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggiimport com.android.keyguard.R; 3703c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggiimport com.android.keyguard.ViewMediatorCallback; 3886b273f1cc59185a14d5bab8a3f4db30c1a4c8a9Jorim Jaggiimport com.android.systemui.DejankUtils; 390e2ffbd48bbedf47deb7f6aed96bd07e2fc96f53Blazej Magnowskiimport com.android.systemui.classifier.FalsingManager; 4003c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 416b88cdfba770efc5722338c240ccaada13d7b0d4Jorim Jaggiimport static com.android.keyguard.KeyguardHostView.OnDismissAction; 42f18271cb300ed7263b39bd17d36a460c4883db88Jorim Jaggiimport static com.android.keyguard.KeyguardSecurityModel.SecurityMode; 43a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi 4403c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi/** 4503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * A class which manages the bouncer on the lockscreen. 4603c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi */ 4703c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggipublic class KeyguardBouncer { 4803c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 49657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic final static private String TAG = "KeyguardBouncer"; 50657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic 511b30f79cffbe9e0c2b974fa3ee48001edcdd6c05Xiyuan Xia protected Context mContext; 521b30f79cffbe9e0c2b974fa3ee48001edcdd6c05Xiyuan Xia protected ViewMediatorCallback mCallback; 531b30f79cffbe9e0c2b974fa3ee48001edcdd6c05Xiyuan Xia protected LockPatternUtils mLockPatternUtils; 541b30f79cffbe9e0c2b974fa3ee48001edcdd6c05Xiyuan Xia protected ViewGroup mContainer; 5503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi private StatusBarWindowManager mWindowManager; 561b30f79cffbe9e0c2b974fa3ee48001edcdd6c05Xiyuan Xia protected KeyguardHostView mKeyguardView; 571b30f79cffbe9e0c2b974fa3ee48001edcdd6c05Xiyuan Xia protected ViewGroup mRoot; 58416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi private boolean mShowingSoon; 593122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek private int mBouncerPromptReason; 600e2ffbd48bbedf47deb7f6aed96bd07e2fc96f53Blazej Magnowski private FalsingManager mFalsingManager; 6125b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi private KeyguardUpdateMonitorCallback mUpdateMonitorCallback = 6225b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi new KeyguardUpdateMonitorCallback() { 6325b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi @Override 641de8bcb1e51917a301cab2ef7d276b4f9423d95fAdrian Roos public void onStrongAuthStateChanged(int userId) { 6525b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi mBouncerPromptReason = mCallback.getBouncerPromptReason(); 6625b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi } 6725b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi }; 6803c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 6903c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi public KeyguardBouncer(Context context, ViewMediatorCallback callback, 7003c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi LockPatternUtils lockPatternUtils, StatusBarWindowManager windowManager, 7103c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi ViewGroup container) { 7203c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mContext = context; 7303c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mCallback = callback; 7403c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mLockPatternUtils = lockPatternUtils; 7503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mContainer = container; 7603c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mWindowManager = windowManager; 7725b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback); 780e2ffbd48bbedf47deb7f6aed96bd07e2fc96f53Blazej Magnowski mFalsingManager = FalsingManager.getInstance(mContext); 7903c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 8003c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 8195e89caeb252a54807c76d60c7440766829e418cJorim Jaggi public void show(boolean resetSecuritySelection) { 82ec018434d48586c3d2c72ed44ee9164cc4115bc3Vadim Tryshev final int keyguardUserId = KeyguardUpdateMonitor.getCurrentUser(); 83ec018434d48586c3d2c72ed44ee9164cc4115bc3Vadim Tryshev if (keyguardUserId == UserHandle.USER_SYSTEM && UserManager.isSplitSystemUser()) { 84ec018434d48586c3d2c72ed44ee9164cc4115bc3Vadim Tryshev // In split system user mode, we never unlock system user. 85ec018434d48586c3d2c72ed44ee9164cc4115bc3Vadim Tryshev return; 86ec018434d48586c3d2c72ed44ee9164cc4115bc3Vadim Tryshev } 870e2ffbd48bbedf47deb7f6aed96bd07e2fc96f53Blazej Magnowski mFalsingManager.onBouncerShown(); 8803c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi ensureView(); 8995e89caeb252a54807c76d60c7440766829e418cJorim Jaggi if (resetSecuritySelection) { 9095e89caeb252a54807c76d60c7440766829e418cJorim Jaggi // showPrimarySecurityScreen() updates the current security method. This is needed in 9195e89caeb252a54807c76d60c7440766829e418cJorim Jaggi // case we are already showing and the current security method changed. 9295e89caeb252a54807c76d60c7440766829e418cJorim Jaggi mKeyguardView.showPrimarySecurityScreen(); 9395e89caeb252a54807c76d60c7440766829e418cJorim Jaggi } 94416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi if (mRoot.getVisibility() == View.VISIBLE || mShowingSoon) { 952fbad7b6a724cf0a5b98b66fe639d58f5ab10af3Jorim Jaggi return; 962fbad7b6a724cf0a5b98b66fe639d58f5ab10af3Jorim Jaggi } 970bed7f258ba1fffc10f986ee043b769f1fd40ad3Jorim Jaggi 98657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic final int activeUserId = ActivityManager.getCurrentUser(); 99b799d3f127f7410e8d0afe16343032e6115750fcToni Barzic final boolean allowDismissKeyguard = 100b799d3f127f7410e8d0afe16343032e6115750fcToni Barzic !(UserManager.isSplitSystemUser() && activeUserId == UserHandle.USER_SYSTEM) 101657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic && activeUserId == keyguardUserId; 102657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic // If allowed, try to dismiss the Keyguard. If no security auth (password/pin/pattern) is 103657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic // set, this will dismiss the whole Keyguard. Otherwise, show the bouncer. 104657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic if (allowDismissKeyguard && mKeyguardView.dismiss()) { 105657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic return; 106657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic } 107416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi 108657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic // This condition may indicate an error on Android, so log it. 109657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic if (!allowDismissKeyguard) { 110657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic Slog.w(TAG, "User can't dismiss keyguard: " + activeUserId + " != " + keyguardUserId); 111416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi } 112657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic 113657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic mShowingSoon = true; 114657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic 115657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic // Split up the work over multiple frames. 116657f88516ab3c8e5f0f56534c1ab43819ece37faToni Barzic DejankUtils.postAfterTraversal(mShowRunnable); 117416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi } 118416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi 119416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi private final Runnable mShowRunnable = new Runnable() { 120416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi @Override 121416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi public void run() { 1220bed7f258ba1fffc10f986ee043b769f1fd40ad3Jorim Jaggi mRoot.setVisibility(View.VISIBLE); 123a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi mKeyguardView.onResume(); 1243122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek showPromptReason(mBouncerPromptReason); 125edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos if (mKeyguardView.getHeight() != 0) { 126edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos mKeyguardView.startAppearAnimation(); 127edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos } else { 128edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos mKeyguardView.getViewTreeObserver().addOnPreDrawListener( 129edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos new ViewTreeObserver.OnPreDrawListener() { 130edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos @Override 131edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos public boolean onPreDraw() { 132edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos mKeyguardView.getViewTreeObserver().removeOnPreDrawListener(this); 133edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos mKeyguardView.startAppearAnimation(); 134edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos return true; 135edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos } 136edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos }); 137edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos mKeyguardView.requestLayout(); 138edfa96fb14524c0a1273c031512e8df2268c2a53Adrian Roos } 139416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi mShowingSoon = false; 140c1dff8cee8cf334906c1572cc3c50fbff96d1839Jorim Jaggi mKeyguardView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); 1410bed7f258ba1fffc10f986ee043b769f1fd40ad3Jorim Jaggi } 142416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi }; 143416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi 1443122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek /** 1453122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek * Show a string explaining why the security view needs to be solved. 1463122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek * 1473122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek * @param reason a flag indicating which string should be shown, see 1483122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek * {@link KeyguardSecurityView#PROMPT_REASON_NONE} 1493122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek * and {@link KeyguardSecurityView#PROMPT_REASON_RESTART} 1503122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek */ 1513122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek public void showPromptReason(int reason) { 1523122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek mKeyguardView.showPromptReason(reason); 1533122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek } 1543122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek 155cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek public void showMessage(String message, int color) { 156cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek mKeyguardView.showMessage(message, color); 157cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek } 158cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek 159416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi private void cancelShowRunnable() { 16086b273f1cc59185a14d5bab8a3f4db30c1a4c8a9Jorim Jaggi DejankUtils.removeCallbacks(mShowRunnable); 161416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi mShowingSoon = false; 16203c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 16303c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 164d944986fbdb3d45fab9ae4120af76ca4f6b0909cJorim Jaggi public void showWithDismissAction(OnDismissAction r, Runnable cancelAction) { 1657d7090d66692170b0584a5b9f4fe3e47285ee615Adrian Roos ensureView(); 166d944986fbdb3d45fab9ae4120af76ca4f6b0909cJorim Jaggi mKeyguardView.setOnDismissAction(r, cancelAction); 16795e89caeb252a54807c76d60c7440766829e418cJorim Jaggi show(false /* resetSecuritySelection */); 1687d7090d66692170b0584a5b9f4fe3e47285ee615Adrian Roos } 1697d7090d66692170b0584a5b9f4fe3e47285ee615Adrian Roos 170a0be6d53a823f8115d3863773398d640ec2a8c44Jorim Jaggi public void hide(boolean destroyView) { 1710e2ffbd48bbedf47deb7f6aed96bd07e2fc96f53Blazej Magnowski mFalsingManager.onBouncerHidden(); 172416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi cancelShowRunnable(); 1731b30f79cffbe9e0c2b974fa3ee48001edcdd6c05Xiyuan Xia if (mKeyguardView != null) { 174d944986fbdb3d45fab9ae4120af76ca4f6b0909cJorim Jaggi mKeyguardView.cancelDismissAction(); 17503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mKeyguardView.cleanUp(); 17603c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 177a0be6d53a823f8115d3863773398d640ec2a8c44Jorim Jaggi if (destroyView) { 178a0be6d53a823f8115d3863773398d640ec2a8c44Jorim Jaggi removeView(); 179a0be6d53a823f8115d3863773398d640ec2a8c44Jorim Jaggi } else if (mRoot != null) { 180a0be6d53a823f8115d3863773398d640ec2a8c44Jorim Jaggi mRoot.setVisibility(View.INVISIBLE); 181a0be6d53a823f8115d3863773398d640ec2a8c44Jorim Jaggi } 18203c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 18303c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 18476a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi /** 18576a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi * See {@link StatusBarKeyguardViewManager#startPreHideAnimation}. 18676a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi */ 18776a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi public void startPreHideAnimation(Runnable runnable) { 18876a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi if (mKeyguardView != null) { 18976a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi mKeyguardView.startDisappearAnimation(runnable); 1908de4311c51229efbe2f2d0afbf298982c5cadd96Jorim Jaggi } else if (runnable != null) { 19176a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi runnable.run(); 192e29b2dbc762bfa66093d76f5a65f55328d8753c9Jorim Jaggi } 193e29b2dbc762bfa66093d76f5a65f55328d8753c9Jorim Jaggi } 194e29b2dbc762bfa66093d76f5a65f55328d8753c9Jorim Jaggi 19503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi /** 19603c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi * Reset the state of the view. 19703c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi */ 19803c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi public void reset() { 199416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi cancelShowRunnable(); 20003c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi inflateView(); 2010e2ffbd48bbedf47deb7f6aed96bd07e2fc96f53Blazej Magnowski mFalsingManager.onBouncerHidden(); 20203c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 20303c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 20403c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi public void onScreenTurnedOff() { 2059ee256d2522f5ab779dfab65c6d1f389b5ddb59aDan Sandler if (mKeyguardView != null && mRoot != null && mRoot.getVisibility() == View.VISIBLE) { 206a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi mKeyguardView.onPause(); 20703c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 20803c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 20903c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 210e5c7a894635d72514d6f1e952d0f18ba6035e86dJorim Jaggi public boolean isShowing() { 211416493bf66dff0aa7fcd9ea505ed10dbff1f2906Jorim Jaggi return mShowingSoon || (mRoot != null && mRoot.getVisibility() == View.VISIBLE); 212e5c7a894635d72514d6f1e952d0f18ba6035e86dJorim Jaggi } 213e5c7a894635d72514d6f1e952d0f18ba6035e86dJorim Jaggi 2142fbad7b6a724cf0a5b98b66fe639d58f5ab10af3Jorim Jaggi public void prepare() { 21595e89caeb252a54807c76d60c7440766829e418cJorim Jaggi boolean wasInitialized = mRoot != null; 2162fbad7b6a724cf0a5b98b66fe639d58f5ab10af3Jorim Jaggi ensureView(); 21795e89caeb252a54807c76d60c7440766829e418cJorim Jaggi if (wasInitialized) { 21895e89caeb252a54807c76d60c7440766829e418cJorim Jaggi mKeyguardView.showPrimarySecurityScreen(); 21995e89caeb252a54807c76d60c7440766829e418cJorim Jaggi } 22086b273f1cc59185a14d5bab8a3f4db30c1a4c8a9Jorim Jaggi mBouncerPromptReason = mCallback.getBouncerPromptReason(); 2212fbad7b6a724cf0a5b98b66fe639d58f5ab10af3Jorim Jaggi } 2222fbad7b6a724cf0a5b98b66fe639d58f5ab10af3Jorim Jaggi 2231b30f79cffbe9e0c2b974fa3ee48001edcdd6c05Xiyuan Xia protected void ensureView() { 22403c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi if (mRoot == null) { 22503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi inflateView(); 22603c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 22703c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 22803c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 2291b30f79cffbe9e0c2b974fa3ee48001edcdd6c05Xiyuan Xia protected void inflateView() { 23003c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi removeView(); 23103c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mRoot = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.keyguard_bouncer, null); 2326b88cdfba770efc5722338c240ccaada13d7b0d4Jorim Jaggi mKeyguardView = (KeyguardHostView) mRoot.findViewById(R.id.keyguard_host_view); 23303c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mKeyguardView.setLockPatternUtils(mLockPatternUtils); 23403c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mKeyguardView.setViewMediatorCallback(mCallback); 23503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mContainer.addView(mRoot, mContainer.getChildCount()); 23603c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mRoot.setVisibility(View.INVISIBLE); 23703c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 23803c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi 2391b30f79cffbe9e0c2b974fa3ee48001edcdd6c05Xiyuan Xia protected void removeView() { 24003c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi if (mRoot != null && mRoot.getParent() == mContainer) { 24103c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mContainer.removeView(mRoot); 24203c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi mRoot = null; 24303c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 24403c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi } 245e5c7a894635d72514d6f1e952d0f18ba6035e86dJorim Jaggi 246e5c7a894635d72514d6f1e952d0f18ba6035e86dJorim Jaggi public boolean onBackPressed() { 247e5c7a894635d72514d6f1e952d0f18ba6035e86dJorim Jaggi return mKeyguardView != null && mKeyguardView.handleBackKey(); 248e5c7a894635d72514d6f1e952d0f18ba6035e86dJorim Jaggi } 249a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi 250a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi /** 25195e89caeb252a54807c76d60c7440766829e418cJorim Jaggi * @return True if and only if the security method should be shown before showing the 25295e89caeb252a54807c76d60c7440766829e418cJorim Jaggi * notifications on Keyguard, like SIM PIN/PUK. 253a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi */ 254a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi public boolean needsFullscreenBouncer() { 255edd32b881780e52b4ecc43f8df3b6b091e70a863Selim Cinek ensureView(); 256a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi if (mKeyguardView != null) { 257a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi SecurityMode mode = mKeyguardView.getSecurityMode(); 25895e89caeb252a54807c76d60c7440766829e418cJorim Jaggi return mode == SecurityMode.SimPin || mode == SecurityMode.SimPuk; 25995e89caeb252a54807c76d60c7440766829e418cJorim Jaggi } 26095e89caeb252a54807c76d60c7440766829e418cJorim Jaggi return false; 26195e89caeb252a54807c76d60c7440766829e418cJorim Jaggi } 26295e89caeb252a54807c76d60c7440766829e418cJorim Jaggi 26395e89caeb252a54807c76d60c7440766829e418cJorim Jaggi /** 26495e89caeb252a54807c76d60c7440766829e418cJorim Jaggi * Like {@link #needsFullscreenBouncer}, but uses the currently visible security method, which 26595e89caeb252a54807c76d60c7440766829e418cJorim Jaggi * makes this method much faster. 26695e89caeb252a54807c76d60c7440766829e418cJorim Jaggi */ 26795e89caeb252a54807c76d60c7440766829e418cJorim Jaggi public boolean isFullscreenBouncer() { 26895e89caeb252a54807c76d60c7440766829e418cJorim Jaggi if (mKeyguardView != null) { 26995e89caeb252a54807c76d60c7440766829e418cJorim Jaggi SecurityMode mode = mKeyguardView.getCurrentSecurityMode(); 27095e89caeb252a54807c76d60c7440766829e418cJorim Jaggi return mode == SecurityMode.SimPin || mode == SecurityMode.SimPuk; 271a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi } 272a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi return false; 273a005f1b6853e8852c328f4fdc02fb8f9c9ae1cd6Jorim Jaggi } 2748c8bcc160aba9a5e93c8df2a99a39a856fafffabJorim Jaggi 2752231c6e1adefdb7636d9fe38a388f1b0660d30eaChristoph Studer /** 2762231c6e1adefdb7636d9fe38a388f1b0660d30eaChristoph Studer * WARNING: This method might cause Binder calls. 2772231c6e1adefdb7636d9fe38a388f1b0660d30eaChristoph Studer */ 2781568250853d81befcdaef63cc8588435353c3d12Jorim Jaggi public boolean isSecure() { 2791568250853d81befcdaef63cc8588435353c3d12Jorim Jaggi return mKeyguardView == null || mKeyguardView.getSecurityMode() != SecurityMode.None; 2801568250853d81befcdaef63cc8588435353c3d12Jorim Jaggi } 2811568250853d81befcdaef63cc8588435353c3d12Jorim Jaggi 28228540199793c3e0e0cc692a00ce27e7fa2f790b8Selim Cinek public boolean shouldDismissOnMenuPressed() { 28328540199793c3e0e0cc692a00ce27e7fa2f790b8Selim Cinek return mKeyguardView.shouldEnableMenuKey(); 2848c8bcc160aba9a5e93c8df2a99a39a856fafffabJorim Jaggi } 285df993513fbfe0e952175c1c5384458deaa1ff01aJorim Jaggi 286df993513fbfe0e952175c1c5384458deaa1ff01aJorim Jaggi public boolean interceptMediaKey(KeyEvent event) { 287df993513fbfe0e952175c1c5384458deaa1ff01aJorim Jaggi ensureView(); 288df993513fbfe0e952175c1c5384458deaa1ff01aJorim Jaggi return mKeyguardView.interceptMediaKey(event); 289df993513fbfe0e952175c1c5384458deaa1ff01aJorim Jaggi } 2905cc86599ce0e5596655859d09c52934030da240bJorim Jaggi 29125b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi public void notifyKeyguardAuthenticated(boolean strongAuth) { 2925cc86599ce0e5596655859d09c52934030da240bJorim Jaggi ensureView(); 29325b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi mKeyguardView.finish(strongAuth); 2945cc86599ce0e5596655859d09c52934030da240bJorim Jaggi } 29503c701ec58ff6de3cc3c53b05342a475a63a11cfJorim Jaggi} 296