Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba7d94b8 authored by Jim Miller's avatar Jim Miller
Browse files

Fix problem where input wasn't being requested

This fixes a bug where input wasn't being enabled when the security
method changed.  The solution is to propagate changes back to the parent

Add missing copyright header to simplified keyguard view.

Bugs 12135931, 12879769

Change-Id: I0fc6cf8ef3b628c96a045797a5b9cdecd3a1007a
parent 5e612cf0
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -400,8 +400,7 @@ public class KeyguardHostView extends KeyguardViewBase {
    }

    @Override
    protected boolean dismiss(boolean authenticated) {
        // TODO Auto-generated method stub
    public boolean dismiss(boolean authenticated) {
        boolean finished = super.dismiss(authenticated);
        if (!finished) {
            mViewStateManager.showBouncer(true);
+9 −13
Original line number Diff line number Diff line
@@ -44,8 +44,9 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe

    // Used to notify the container when something interesting happens.
    public interface SecurityCallback {
        public void dismiss(boolean authenticated);
        public boolean dismiss(boolean authenticated);
        public void userActivity(long timeout);
        public void onSecurityModeChanged(SecurityMode securityMode, boolean needsInput);
        public void finish();
    }

@@ -293,18 +294,12 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
        showSecurityScreen(backup);
    }

    private boolean showNextSecurityScreenIfPresent() {
        SecurityMode securityMode = mSecurityModel.getSecurityMode();
        // Allow an alternate, such as biometric unlock
        securityMode = mSecurityModel.getAlternateFor(securityMode);
        if (SecurityMode.None == securityMode) {
            return false;
        } else {
            showSecurityScreen(securityMode); // switch to the alternate security view
            return true;
        }
    }

    /**
     * Shows the next security screen if there is one.
     * @param authenticated true if the user entered the correct authentication
     * @param authenticated
     * @return true if keyguard is done
     */
    boolean showNextSecurityScreenOrFinish(boolean authenticated) {
        if (DEBUG) Log.d(TAG, "showNextSecurityScreenOrFinish(" + authenticated + ")");
        boolean finish = false;
@@ -386,6 +381,7 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
        }

        mCurrentSecuritySelection = securityMode;
        mSecurityCallback.onSecurityModeChanged(securityMode, newView.needsInput());
    }

    private KeyguardSecurityViewFlipper getFlipper() {
+16 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.keyguard;

import android.content.Context;
+29 −43
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ import java.io.File;
 * Handles intercepting of media keys that still work when the keyguard is
 * showing.
 */
public abstract class KeyguardViewBase extends FrameLayout {
public abstract class KeyguardViewBase extends FrameLayout implements SecurityCallback {

    private AudioManager mAudioManager;
    private TelephonyManager mTelephonyManager = null;
@@ -104,22 +104,7 @@ public abstract class KeyguardViewBase extends FrameLayout {
                (KeyguardSecurityContainer) findViewById(R.id.keyguard_security_container);
        mLockPatternUtils = new LockPatternUtils(mContext);
        mSecurityContainer.setLockPatternUtils(mLockPatternUtils);
        mSecurityContainer.setSecurityCallback(new SecurityCallback() {
            @Override
            public void userActivity(long timeout) {
                KeyguardViewBase.this.userActivity(timeout);
            }

            @Override
            public void dismiss(boolean authenticated) {
                KeyguardViewBase.this.dismiss(authenticated);
            }

            @Override
            public void finish() {
                KeyguardViewBase.this.finish();
            }
        });
        mSecurityContainer.setSecurityCallback(this);
        mSecurityContainer.showPrimarySecurityScreen(false);
        // mSecurityContainer.updateSecurityViews(false /* not bouncing */);
        setBackButtonEnabled(false);
@@ -140,14 +125,6 @@ public abstract class KeyguardViewBase extends FrameLayout {
        dismiss(false);
    }

    protected boolean dismiss(boolean authenticated) {
        boolean finished = getSecurityContainer().showNextSecurityScreenOrFinish(authenticated);
        if (!finished) {
            updateAfterSecuritySelection();
        }
        return finished;
    }

    private void setBackButtonEnabled(boolean enabled) {
        setSystemUiVisibility(enabled ?
                getSystemUiVisibility() & ~View.STATUS_BAR_DISABLE_BACK :
@@ -180,27 +157,31 @@ public abstract class KeyguardViewBase extends FrameLayout {
        mSecurityContainer.announceCurrentSecurityMethod();
    }

    private void updateAfterSecuritySelection() {
        // Enable or disable the back button based on security mode
        if (getSecurityContainer().getSecurityMode() == SecurityMode.Account
                && !mLockPatternUtils.isPermanentlyLocked()) {
            // we're showing account as a backup, provide a way to get back to primary
            setBackButtonEnabled(true);
    protected KeyguardSecurityContainer getSecurityContainer() {
        return mSecurityContainer;
    }

    /**
     * Extend display timeout
     * @param timeout duration to delay timeout, in ms.
     */
    @Override
    public void userActivity(long timeout) {
        if (mViewMediatorCallback != null) {
            mViewMediatorCallback.setNeedsInput(getSecurityContainer().needsInput());
            mViewMediatorCallback.userActivity(timeout);
        }
    }

    protected KeyguardSecurityContainer getSecurityContainer() {
        return mSecurityContainer;
    @Override
    public boolean dismiss(boolean authenticated) {
        return mSecurityContainer.showNextSecurityScreenOrFinish(authenticated);
    }

    /**
     * Authentication has happened and it's time to dismiss keyguard. This function
     * should clean up and inform KeyguardViewMediator.
     */
    @Override
    public void finish() {
        // If the alternate unlock was suppressed, it can now be safely
        // enabled because the user has left keyguard.
@@ -222,17 +203,20 @@ public abstract class KeyguardViewBase extends FrameLayout {
        }
    }

    /**
     * Extend display timeout
     * @param timeout duration to delay timeout, in ms.
     */
    protected void userActivity(long timeout) {
    @Override
    public void onSecurityModeChanged(SecurityMode securityMode, boolean needsInput) {
        // Enable or disable the back button based on security mode
        if (securityMode == SecurityMode.Account && !mLockPatternUtils.isPermanentlyLocked()) {
            // we're showing account as a backup, provide a way to get back to primary
            setBackButtonEnabled(true);
        }

        if (mViewMediatorCallback != null) {
            mViewMediatorCallback.userActivity(timeout);
            mViewMediatorCallback.setNeedsInput(needsInput);
        }
    }

    protected void userActivity() {
    public void userActivity() {
        if (mViewMediatorCallback != null) {
            mViewMediatorCallback.userActivity();
        }
@@ -281,7 +265,7 @@ public abstract class KeyguardViewBase extends FrameLayout {
     * The result will be propogated back via {@link KeyguardViewCallback#keyguardDone(boolean)}
     */
    public void verifyUnlock() {
        SecurityMode securityMode = getSecurityContainer().getSecurityMode();
        SecurityMode securityMode = mSecurityContainer.getSecurityMode();
        if (securityMode == KeyguardSecurityModel.SecurityMode.None) {
            if (mViewMediatorCallback != null) {
                mViewMediatorCallback.keyguardDone(true);
@@ -452,6 +436,8 @@ public abstract class KeyguardViewBase extends FrameLayout {
    public void setViewMediatorCallback(
            KeyguardViewMediator.ViewMediatorCallback viewMediatorCallback) {
        mViewMediatorCallback = viewMediatorCallback;
        // Update ViewMediator with the current input method requirements
        mViewMediatorCallback.setNeedsInput(mSecurityContainer.needsInput());
    }

    protected KeyguardActivityLauncher getActivityLauncher() {
+24 −22
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import org.xmlpull.v1.XmlPullParser;

import android.app.ActivityManager;
import android.appwidget.AppWidgetManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
@@ -41,6 +42,7 @@ import android.os.IBinder;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
@@ -69,7 +71,6 @@ public class KeyguardViewManager {

    // Timeout used for keypresses
    static final int DIGIT_PRESS_WAKE_MILLIS = 5000;
    private static final int HOST_LAYOUT = R.layout.keyguard_simple_host_view;

    private final Context mContext;
    private final ViewManager mViewManager;
@@ -263,6 +264,7 @@ public class KeyguardViewManager {
    }

    SparseArray<Parcelable> mStateContainer = new SparseArray<Parcelable>();
    private int mCurrentLayout;

    private void maybeCreateKeyguardLocked(boolean enableScreenRotation, boolean force,
            Bundle options) {
@@ -310,7 +312,14 @@ public class KeyguardViewManager {
        if (force || mKeyguardView == null) {
            mKeyguardHost.setCustomBackground(null);
            mKeyguardHost.removeAllViews();
            inflateKeyguardView(options);
            int layout = allowNotificationsOnSecureKeyguard()
                    ? R.layout.keyguard_simple_host_view
                    : R.layout.keyguard_host_view;
            if (mCurrentLayout != layout) {
                mStateContainer.clear(); // don't restore to the wrong view hierarchy
                mCurrentLayout = layout;
            }
            mKeyguardView = inflateKeyguardView(options, layout);
            mKeyguardView.requestFocus();
        }
        updateUserActivityTimeoutInWindowLayoutParams();
@@ -319,31 +328,24 @@ public class KeyguardViewManager {
        mKeyguardHost.restoreHierarchyState(mStateContainer);
    }

    private void inflateKeyguardView(Bundle options) {
    private boolean allowNotificationsOnSecureKeyguard() {
        ContentResolver cr = mContext.getContentResolver();
        return Settings.Secure.getInt(cr, Settings.Secure.LOCK_SCREEN_ALLOW_NOTIFICATIONS, 0) == 1;
    }

    private KeyguardViewBase inflateKeyguardView(Bundle options, int layoutId) {
        View v = mKeyguardHost.findViewById(R.id.keyguard_host_view);
        if (v != null) {
            mKeyguardHost.removeView(v);
        }
        final LayoutInflater inflater = LayoutInflater.from(mContext);
        View view = inflater.inflate(HOST_LAYOUT, mKeyguardHost, true);
        mKeyguardView = (KeyguardViewBase) view.findViewById(R.id.keyguard_host_view);
        mKeyguardView.setLockPatternUtils(mLockPatternUtils);
        mKeyguardView.setViewMediatorCallback(mViewMediatorCallback);
        mKeyguardView.onUserSwitching(options != null && options.getBoolean(IS_SWITCHING_USER));

        // HACK
        // The keyguard view will have set up window flags in onFinishInflate before we set
        // the view mediator callback. Make sure it knows the correct IME state.
        if (mViewMediatorCallback != null) {
            KeyguardPasswordView kpv = (KeyguardPasswordView) mKeyguardView.findViewById(
                    R.id.keyguard_password_view);

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

        mKeyguardView.onCreateOptions(options);
        View view = inflater.inflate(layoutId, mKeyguardHost, true);
        KeyguardViewBase keyguard = (KeyguardViewBase) view.findViewById(R.id.keyguard_host_view);
        keyguard.setLockPatternUtils(mLockPatternUtils);
        keyguard.setViewMediatorCallback(mViewMediatorCallback);
        keyguard.onUserSwitching(options != null && options.getBoolean(IS_SWITCHING_USER));
        keyguard.onCreateOptions(options);
        return keyguard;
    }

    public void updateUserActivityTimeout() {