FileDocCategorySizeDatePackage
KeyguardViewBase.javaAPI DocAndroid 5.1 API18500Thu Mar 12 22:22:42 GMT 2015com.android.keyguard

KeyguardViewBase

public abstract class KeyguardViewBase extends android.widget.FrameLayout implements com.android.keyguard.KeyguardSecurityContainer.SecurityCallback
Base class for keyguard view. {@link #reset} is where you should reset the state of your view. Use the {@link KeyguardViewCallback} via {@link #getCallback()} to send information back (such as poking the wake lock, or finishing the keyguard). Handles intercepting of media keys that still work when the keyguard is showing.

Fields Summary
private android.media.AudioManager
mAudioManager
private android.telephony.TelephonyManager
mTelephonyManager
protected ViewMediatorCallback
mViewMediatorCallback
protected com.android.internal.widget.LockPatternUtils
mLockPatternUtils
private com.android.keyguard.KeyguardHostView.OnDismissAction
mDismissAction
private static final boolean
KEYGUARD_MANAGES_VOLUME
public static final boolean
DEBUG
private static final String
TAG
private KeyguardSecurityContainer
mSecurityContainer
private static final String
ENABLE_MENU_KEY_FILE
In general, we enable unlocking the insecure keyguard with the menu key. However, there are some cases where we wish to disable it, notably when the menu button placement or technology is prone to false positives.
private final KeyguardActivityLauncher
mActivityLauncher
Constructors Summary
public KeyguardViewBase(android.content.Context context)


       
        this(context, null);
    
public KeyguardViewBase(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
    
Methods Summary
protected voidannounceCurrentSecurityMethod()

        mSecurityContainer.announceCurrentSecurityMethod();
    
public abstract voidcleanUp()
Called before this view is being removed.

public booleandismiss(boolean authenticated)

        return mSecurityContainer.showNextSecurityScreenOrFinish(authenticated);
    
public booleandismiss()
Dismisses the keyguard by going to the next screen or making it gone.

return
True if the keyguard is done.

        return dismiss(false);
    
protected voiddispatchDraw(android.graphics.Canvas canvas)

        super.dispatchDraw(canvas);
        if (mViewMediatorCallback != null) {
            mViewMediatorCallback.keyguardDoneDrawing();
        }
    
public booleandispatchKeyEvent(android.view.KeyEvent event)

        if (interceptMediaKey(event)) {
            return true;
        }
        return super.dispatchKeyEvent(event);
    
public booleandispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)

        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            event.getText().add(mSecurityContainer.getCurrentSecurityModeContentDescription());
            return true;
        } else {
            return super.dispatchPopulateAccessibilityEvent(event);
        }
    
public voiddispatchSystemUiVisibilityChanged(int visibility)

        super.dispatchSystemUiVisibilityChanged(visibility);

        if (!(mContext instanceof Activity)) {
            setSystemUiVisibility(STATUS_BAR_DISABLE_BACK);
        }
    
public voidfinish()
Authentication has happened and it's time to dismiss keyguard. This function should clean up and inform KeyguardViewMediator.

        // If the alternate unlock was suppressed, it can now be safely
        // enabled because the user has left keyguard.
        KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(true);

        // If there's a pending runnable because the user interacted with a widget
        // and we're leaving keyguard, then run it.
        boolean deferKeyguardDone = false;
        if (mDismissAction != null) {
            deferKeyguardDone = mDismissAction.onDismiss();
            mDismissAction = null;
        }
        if (mViewMediatorCallback != null) {
            if (deferKeyguardDone) {
                mViewMediatorCallback.keyguardDonePending();
            } else {
                mViewMediatorCallback.keyguardDone(true);
            }
        }
    
protected KeyguardActivityLaunchergetActivityLauncher()

        return mActivityLauncher;
    
public com.android.keyguard.KeyguardSecurityModel.SecurityModegetCurrentSecurityMode()

        return mSecurityContainer.getCurrentSecurityMode();
    
protected KeyguardSecurityContainergetSecurityContainer()

        return mSecurityContainer;
    
public com.android.keyguard.KeyguardSecurityModel.SecurityModegetSecurityMode()

        return mSecurityContainer.getSecurityMode();
    
public abstract longgetUserActivityTimeout()
Gets the desired user activity timeout in milliseconds, or -1 if the default should be used.

public booleanhandleBackKey()

        if (mSecurityContainer.getCurrentSecuritySelection() == SecurityMode.Account) {
            // go back to primary screen
            mSecurityContainer.showPrimarySecurityScreen(false /*turningOff*/);
            return true;
        }
        if (mSecurityContainer.getCurrentSecuritySelection() != SecurityMode.None) {
            mSecurityContainer.dismiss(false);
            return true;
        }
        return false;
    
private voidhandleMediaKeyEvent(android.view.KeyEvent keyEvent)

        synchronized (this) {
            if (mAudioManager == null) {
                mAudioManager = (AudioManager) getContext().getSystemService(
                        Context.AUDIO_SERVICE);
            }
        }
        mAudioManager.dispatchMediaKeyEvent(keyEvent);
    
public booleanhandleMenuKey()

        // The following enables the MENU key to work for testing automation
        if (shouldEnableMenuKey()) {
            dismiss();
            return true;
        }
        return false;
    
public booleaninterceptMediaKey(android.view.KeyEvent event)
Allows the media keys to work when the keyguard is showing. The media keys should be of no interest to the actual keyguard view(s), so intercepting them here should not be of any harm.

param
event The key event
return
whether the event was consumed as a media key.

        final int keyCode = event.getKeyCode();
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_MEDIA_PLAY:
                case KeyEvent.KEYCODE_MEDIA_PAUSE:
                case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                    /* Suppress PLAY/PAUSE toggle when phone is ringing or
                     * in-call to avoid music playback */
                    if (mTelephonyManager == null) {
                        mTelephonyManager = (TelephonyManager) getContext().getSystemService(
                                Context.TELEPHONY_SERVICE);
                    }
                    if (mTelephonyManager != null &&
                            mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
                        return true;  // suppress key event
                    }
                case KeyEvent.KEYCODE_MUTE:
                case KeyEvent.KEYCODE_HEADSETHOOK:
                case KeyEvent.KEYCODE_MEDIA_STOP:
                case KeyEvent.KEYCODE_MEDIA_NEXT:
                case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                case KeyEvent.KEYCODE_MEDIA_REWIND:
                case KeyEvent.KEYCODE_MEDIA_RECORD:
                case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
                case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
                    handleMediaKeyEvent(event);
                    return true;
                }

                case KeyEvent.KEYCODE_VOLUME_UP:
                case KeyEvent.KEYCODE_VOLUME_DOWN:
                case KeyEvent.KEYCODE_VOLUME_MUTE: {
                    if (KEYGUARD_MANAGES_VOLUME) {
                        synchronized (this) {
                            if (mAudioManager == null) {
                                mAudioManager = (AudioManager) getContext().getSystemService(
                                        Context.AUDIO_SERVICE);
                            }
                        }
                        // Volume buttons should only function for music (local or remote).
                        // TODO: Actually handle MUTE.
                        mAudioManager.adjustSuggestedStreamVolume(
                                keyCode == KeyEvent.KEYCODE_VOLUME_UP
                                        ? AudioManager.ADJUST_RAISE
                                        : AudioManager.ADJUST_LOWER /* direction */,
                                AudioManager.STREAM_MUSIC /* stream */, 0 /* flags */);
                        // Don't execute default volume behavior
                        return true;
                    } else {
                        return false;
                    }
                }
            }
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_MUTE:
                case KeyEvent.KEYCODE_HEADSETHOOK:
                case KeyEvent.KEYCODE_MEDIA_PLAY:
                case KeyEvent.KEYCODE_MEDIA_PAUSE:
                case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                case KeyEvent.KEYCODE_MEDIA_STOP:
                case KeyEvent.KEYCODE_MEDIA_NEXT:
                case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                case KeyEvent.KEYCODE_MEDIA_REWIND:
                case KeyEvent.KEYCODE_MEDIA_RECORD:
                case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
                case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
                    handleMediaKeyEvent(event);
                    return true;
                }
            }
        }
        return false;
    
public voidlaunchCamera()

        mActivityLauncher.launchCamera(getHandler(), null);
    
protected abstract voidonCreateOptions(android.os.Bundle options)

protected abstract voidonExternalMotionEvent(android.view.MotionEvent event)

protected voidonFinishInflate()

        mSecurityContainer =
                (KeyguardSecurityContainer) findViewById(R.id.keyguard_security_container);
        mLockPatternUtils = new LockPatternUtils(mContext);
        mSecurityContainer.setLockPatternUtils(mLockPatternUtils);
        mSecurityContainer.setSecurityCallback(this);
        mSecurityContainer.showPrimarySecurityScreen(false);
        // mSecurityContainer.updateSecurityViews(false /* not bouncing */);
    
public voidonPause()
Called when the Keyguard is not actively shown anymore on the screen.

        if (DEBUG) Log.d(TAG, String.format("screen off, instance %s at %s",
                Integer.toHexString(hashCode()), SystemClock.uptimeMillis()));
        // Once the screen turns off, we no longer consider this to be first boot and we want the
        // biometric unlock to start next time keyguard is shown.
        KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(true);
        mSecurityContainer.showPrimarySecurityScreen(true);
        mSecurityContainer.onPause();
        clearFocus();
    
public voidonResume()
Called when the Keyguard is actively shown on the screen.

        if (DEBUG) Log.d(TAG, "screen on, instance " + Integer.toHexString(hashCode()));
        mSecurityContainer.onResume(KeyguardSecurityView.SCREEN_ON);
        requestFocus();
    
public voidonSecurityModeChanged(com.android.keyguard.KeyguardSecurityModel.SecurityMode securityMode, boolean needsInput)

        if (mViewMediatorCallback != null) {
            mViewMediatorCallback.setNeedsInput(needsInput);
        }
    
protected voidonUserActivityTimeoutChanged()

        if (mViewMediatorCallback != null) {
            mViewMediatorCallback.onUserActivityTimeoutChanged();
        }
    
protected abstract voidonUserSwitching(boolean switching)

public voidsetLockPatternUtils(com.android.internal.widget.LockPatternUtils utils)

        mLockPatternUtils = utils;
        mSecurityContainer.setLockPatternUtils(utils);
    
public voidsetOnDismissAction(com.android.keyguard.KeyguardHostView.OnDismissAction action)
Sets an action to run when keyguard finishes.

param
action

        mDismissAction = action;
    
public voidsetViewMediatorCallback(ViewMediatorCallback viewMediatorCallback)

        mViewMediatorCallback = viewMediatorCallback;
        // Update ViewMediator with the current input method requirements
        mViewMediatorCallback.setNeedsInput(mSecurityContainer.needsInput());
    
private booleanshouldEnableMenuKey()

       
        final Resources res = getResources();
        final boolean configDisabled = res.getBoolean(R.bool.config_disableMenuKeyInLockScreen);
        final boolean isTestHarness = ActivityManager.isRunningInTestHarness();
        final boolean fileOverride = (new File(ENABLE_MENU_KEY_FILE)).exists();
        return !configDisabled || isTestHarness || fileOverride;
    
public voidshowAssistant()


       
        final Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
          .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);

        if (intent == null) return;

        final ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext,
                R.anim.keyguard_action_assist_enter, R.anim.keyguard_action_assist_exit,
                getHandler(), null);

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mActivityLauncher.launchActivityWithAnimation(intent, false, opts.toBundle(), null, null);
    
protected voidshowBouncer(boolean show)

        CharSequence what = getContext().getResources().getText(
                show ? R.string.keyguard_accessibility_show_bouncer
                        : R.string.keyguard_accessibility_hide_bouncer);
        announceForAccessibility(what);
        announceCurrentSecurityMethod();
    
public voidshowPrimarySecurityScreen()
Called when the view needs to be shown.

        if (DEBUG) Log.d(TAG, "show()");
        mSecurityContainer.showPrimarySecurityScreen(false);
    
public voidstartAppearAnimation()
Starts the animation when the Keyguard gets shown.

        mSecurityContainer.startAppearAnimation();
    
public voidstartDisappearAnimation(java.lang.Runnable finishRunnable)

        if (!mSecurityContainer.startDisappearAnimation(finishRunnable) && finishRunnable != null) {
            finishRunnable.run();
        }
    
public voiduserActivity()

        if (mViewMediatorCallback != null) {
            mViewMediatorCallback.userActivity();
        }
    
public voidverifyUnlock()
Verify that the user can get past the keyguard securely. This is called, for example, when the phone disables the keyguard but then wants to launch something else that requires secure access. The result will be propogated back via {@link KeyguardViewCallback#keyguardDone(boolean)}

        SecurityMode securityMode = mSecurityContainer.getSecurityMode();
        if (securityMode == KeyguardSecurityModel.SecurityMode.None) {
            if (mViewMediatorCallback != null) {
                mViewMediatorCallback.keyguardDone(true);
            }
        } else if (securityMode != KeyguardSecurityModel.SecurityMode.Pattern
                && securityMode != KeyguardSecurityModel.SecurityMode.PIN
                && securityMode != KeyguardSecurityModel.SecurityMode.Password) {
            // can only verify unlock when in pattern/password mode
            if (mViewMediatorCallback != null) {
                mViewMediatorCallback.keyguardDone(false);
            }
        } else {
            // otherwise, go to the unlock screen, see if they can verify it
            mSecurityContainer.verifyUnlock();
        }