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

Commit ab954546 authored by Jim Miller's avatar Jim Miller Committed by Jorim Jaggi
Browse files

Make IKeyguardService interface asynchronous

Add a state callback so lockscreen reports back whenever its state
relevant for PhoneWindowManager changed, instead of synchronously
calling into SysUI which can lead to deadlocks. Directly use
LockPatternUtils for isSecure, and optimize the number of calls to
this method to optimize layout performance.

Bug: 17677097
Change-Id: I5d491fc8884d4f84d9562626b9ea0d5eaa5166fc
parent fb6121e0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -273,6 +273,7 @@ LOCAL_SRC_FILES += \
	core/java/com/android/internal/policy/IKeyguardShowCallback.aidl \
	core/java/com/android/internal/policy/IKeyguardExitCallback.aidl \
	core/java/com/android/internal/policy/IKeyguardService.aidl \
	core/java/com/android/internal/policy/IKeyguardStateCallback.aidl \
	core/java/com/android/internal/os/IDropBoxManagerService.aidl \
	core/java/com/android/internal/os/IParcelFileDescriptorFactory.aidl \
	core/java/com/android/internal/os/IResultReceiver.aidl \
+19 −32
Original line number Diff line number Diff line
@@ -15,47 +15,34 @@
 */
package com.android.internal.policy;

import android.view.MotionEvent;

import com.android.internal.policy.IKeyguardShowCallback;
import com.android.internal.policy.IKeyguardStateCallback;
import com.android.internal.policy.IKeyguardExitCallback;

import android.os.Bundle;

interface IKeyguardService {
    boolean isShowing();
    boolean isSecure();
    boolean isShowingAndNotOccluded();
    boolean isInputRestricted();
    boolean isDismissable();
    oneway void verifyUnlock(IKeyguardExitCallback callback);
    oneway void keyguardDone(boolean authenticated, boolean wakeup);

oneway interface IKeyguardService {
    /**
     * Sets the Keyguard as occluded when a window dismisses the Keyguard with flag
     * FLAG_SHOW_ON_LOCK_SCREEN.
     *
     * @param isOccluded Whether the Keyguard is occluded by another window.
     * @return See IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_*. This is needed because
     *         PhoneWindowManager needs to set these flags immediately and can't wait for the
     *         Keyguard thread to pick it up. In the hidden case, PhoneWindowManager is solely
     *         responsible to make sure that the flags are unset.
     */
    int setOccluded(boolean isOccluded);

    oneway void dismiss();
    oneway void onDreamingStarted();
    oneway void onDreamingStopped();
    oneway void onScreenTurnedOff(int reason);
    oneway void onScreenTurnedOn(IKeyguardShowCallback callback);
    oneway void setKeyguardEnabled(boolean enabled);
    oneway void onSystemReady();
    oneway void doKeyguardTimeout(in Bundle options);
    oneway void setCurrentUser(int userId);
    oneway void showAssistant();
    oneway void dispatch(in MotionEvent event);
    oneway void launchCamera();
    oneway void onBootCompleted();
    void setOccluded(boolean isOccluded);

    void addStateMonitorCallback(IKeyguardStateCallback callback);
    void verifyUnlock(IKeyguardExitCallback callback);
    void keyguardDone(boolean authenticated, boolean wakeup);
    void dismiss();
    void onDreamingStarted();
    void onDreamingStopped();
    void onScreenTurnedOff(int reason);
    void onScreenTurnedOn(IKeyguardShowCallback callback);
    void setKeyguardEnabled(boolean enabled);
    void onSystemReady();
    void doKeyguardTimeout(in Bundle options);
    void setCurrentUser(int userId);
    void onBootCompleted();

    /**
     * Notifies that the activity behind has now been drawn and it's safe to remove the wallpaper
@@ -64,11 +51,11 @@ interface IKeyguardService {
     * @param startTime the start time of the animation in uptime milliseconds
     * @param fadeoutDuration the duration of the exit animation, in milliseconds
     */
    oneway void startKeyguardExitAnimation(long startTime, long fadeoutDuration);
    void startKeyguardExitAnimation(long startTime, long fadeoutDuration);

    /**
     * Notifies the Keyguard that the activity that was starting has now been drawn and it's safe
     * to start the keyguard dismiss sequence.
     */
    oneway void onActivityDrawn();
    void onActivityDrawn();
}
+22 −0
Original line number Diff line number Diff line
@@ -11,31 +11,12 @@
 * 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
 * limitations under the License.
 */

package com.android.internal.policy;

/**
 * @hide
 */
public class IKeyguardServiceConstants {

    /**
     * Constant for {@link com.android.internal.policy.IKeyguardService#setHidden(boolean)}:
     * Don't change the keyguard window flags.
     */
    public static final int KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_NONE = 0;

    /**
     * Constant for {@link com.android.internal.policy.IKeyguardService#setHidden(boolean)}:
     * Set the keyguard window flags to FLAG_SHOW_WALLPAPER and PRIVATE_FLAG_KEYGUARD.
     */
    public static final int KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS = 1;

    /**
     * Constant for {@link com.android.internal.policy.IKeyguardService#setHidden(boolean)}:
     * Unset the keyguard window flags to FLAG_SHOW_WALLPAPER and PRIVATE_FLAG_KEYGUARD.
     */
    public static final int KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS = 2;
interface IKeyguardStateCallback {
    void onShowingStateChanged(boolean showing);
    void onSimSecureStateChanged(boolean simSecure);
    void onInputRestrictedStateChanged(boolean inputRestricted);
}
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
@@ -71,4 +71,10 @@ public interface ViewMediatorCallback {
     * Play the "device trusted" sound.
     */
    void playTrustedSound();

    /**
     * @return true if and only if Keyguard is showing or if Keyguard is disabled by an external app
     *         (legacy API)
     */
    boolean isInputRestricted();
}
+20 −79
Original line number Diff line number Diff line
@@ -24,12 +24,11 @@ import android.os.Debug;
import android.os.IBinder;
import android.os.Process;
import android.util.Log;
import android.view.MotionEvent;

import com.android.internal.policy.IKeyguardExitCallback;
import com.android.internal.policy.IKeyguardService;
import com.android.internal.policy.IKeyguardServiceConstants;
import com.android.internal.policy.IKeyguardShowCallback;
import com.android.internal.policy.IKeyguardStateCallback;
import com.android.systemui.SystemUIApplication;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;
@@ -66,142 +65,84 @@ public class KeyguardService extends Service {

    private final IKeyguardService.Stub mBinder = new IKeyguardService.Stub() {

        private boolean mIsOccluded;

        @Override
        public boolean isShowing() {
            return mKeyguardViewMediator.isShowing();
        }

        @Override
        public boolean isSecure() {
            return mKeyguardViewMediator.isSecure();
        }

        @Override
        public boolean isShowingAndNotOccluded() {
            return mKeyguardViewMediator.isShowingAndNotOccluded();
        }

        @Override
        public boolean isInputRestricted() {
            return mKeyguardViewMediator.isInputRestricted();
        @Override // Binder interface
        public void addStateMonitorCallback(IKeyguardStateCallback callback) {
            checkPermission();
            mKeyguardViewMediator.addStateMonitorCallback(callback);
        }

        @Override
        @Override // Binder interface
        public void verifyUnlock(IKeyguardExitCallback callback) {
            checkPermission();
            mKeyguardViewMediator.verifyUnlock(callback);
        }

        @Override
        @Override // Binder interface
        public void keyguardDone(boolean authenticated, boolean wakeup) {
            checkPermission();
            mKeyguardViewMediator.keyguardDone(authenticated, wakeup);
        }

        @Override
        public int setOccluded(boolean isOccluded) {
            checkPermission();
            synchronized (this) {
                int result;
                if (isOccluded && mKeyguardViewMediator.isShowing()
                        && !mIsOccluded) {
                    result = IKeyguardServiceConstants
                            .KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS;
                } else if (!isOccluded && mKeyguardViewMediator.isShowing()
                        && mIsOccluded) {
                    result = IKeyguardServiceConstants
                            .KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS;
                } else {
                    result = IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_NONE;
                }
                if (mIsOccluded != isOccluded) {
        @Override // Binder interface
        public void setOccluded(boolean isOccluded) {
            checkPermission();
            mKeyguardViewMediator.setOccluded(isOccluded);

                    // Cache the value so we always have a fresh view in whether Keyguard is occluded.
                    // If we would just call mKeyguardViewMediator.isOccluded(), this might be stale
                    // because that value gets updated in another thread.
                    mIsOccluded = isOccluded;
                }
                return result;
            }
        }

        @Override
        @Override // Binder interface
        public void dismiss() {
            checkPermission();
            mKeyguardViewMediator.dismiss();
        }

        @Override
        @Override // Binder interface
        public void onDreamingStarted() {
            checkPermission();
            mKeyguardViewMediator.onDreamingStarted();
        }

        @Override
        @Override // Binder interface
        public void onDreamingStopped() {
            checkPermission();
            mKeyguardViewMediator.onDreamingStopped();
        }

        @Override
        @Override // Binder interface
        public void onScreenTurnedOff(int reason) {
            checkPermission();
            mKeyguardViewMediator.onScreenTurnedOff(reason);
        }

        @Override
        @Override // Binder interface
        public void onScreenTurnedOn(IKeyguardShowCallback callback) {
            checkPermission();
            mKeyguardViewMediator.onScreenTurnedOn(callback);
        }

        @Override
        @Override // Binder interface
        public void setKeyguardEnabled(boolean enabled) {
            checkPermission();
            mKeyguardViewMediator.setKeyguardEnabled(enabled);
        }

        @Override
        public boolean isDismissable() {
            return mKeyguardViewMediator.isDismissable();
        }

        @Override
        @Override // Binder interface
        public void onSystemReady() {
            checkPermission();
            mKeyguardViewMediator.onSystemReady();
        }

        @Override
        @Override // Binder interface
        public void doKeyguardTimeout(Bundle options) {
            checkPermission();
            mKeyguardViewMediator.doKeyguardTimeout(options);
        }

        @Override
        @Override // Binder interface
        public void setCurrentUser(int userId) {
            checkPermission();
            mKeyguardViewMediator.setCurrentUser(userId);
        }

        @Override
        public void showAssistant() {
            checkPermission();
        }

        @Override
        public void dispatch(MotionEvent event) {
            checkPermission();
        }

        @Override
        public void launchCamera() {
            checkPermission();
        }

        @Override
        public void onBootCompleted() {
            checkPermission();
Loading