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

Commit 6c9df505 authored by Jim Miller's avatar Jim Miller
Browse files

Fix permissions on WindowManagerService.showAssistant()

Since binder call permissions are not transitive by design,
the proper way to fix this is to have the call talk directly
to keyguard from the navigation bar.

Fixes bug 9409008

Change-Id: Ibd90a79bb638c969b514455a2ad93c6ff668222d
parent 1962e264
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -248,12 +248,6 @@ interface IWindowManager
     */
    boolean isSafeModeEnabled();

    /**
     * Tell keyguard to show the assistant (Intent.ACTION_ASSIST) after asking for the user's
     * credentials.
     */
    void showAssistant();

    /**
     * Sets the display magnification callbacks. These callbacks notify
     * the client for contextual changes related to display magnification.
+0 −6
Original line number Diff line number Diff line
@@ -1175,12 +1175,6 @@ public interface WindowManagerPolicy {
     */
    public void dump(String prefix, PrintWriter writer, String[] args);

    /**
     * Ask keyguard to invoke the assist intent after dismissing keyguard
     * {@link android.content.Intent#ACTION_ASSIST}
     */
    public void showAssistant();

    /**
     * Returns whether a given window type can be magnified.
     *
+2 −5
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.internal.widget.multiwaveview.GlowPadView.OnTriggerListener;
import com.android.systemui.statusbar.BaseStatusBar;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.StatusBarPanel;
import com.android.systemui.statusbar.phone.KeyguardTouchDelegate;
import com.android.systemui.statusbar.phone.PhoneStatusBar;

public class SearchPanelView extends FrameLayout implements
@@ -88,11 +89,7 @@ public class SearchPanelView extends FrameLayout implements

        if (isKeyguardShowing) {
            // Have keyguard show the bouncer and launch the activity if the user succeeds.
            try {
                mWm.showAssistant();
            } catch (RemoteException e) {
                // too bad, so sad...
            }
            KeyguardTouchDelegate.getInstance(getContext()).showAssistant();
            onAnimationStarted();
        } else {
            // Otherwise, keyguard isn't showing so launch it from here.
+67 −27
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import android.util.Slog;
import android.view.MotionEvent;

import com.android.internal.policy.IKeyguardExitCallback;
@@ -41,7 +41,9 @@ public class KeyguardTouchDelegate {
    static final String KEYGUARD_PACKAGE = "com.android.keyguard";
    static final String KEYGUARD_CLASS = "com.android.keyguard.KeyguardService";

    IKeyguardService mService;
    private static KeyguardTouchDelegate sInstance;

    private volatile IKeyguardService mService;

    protected static final boolean DEBUG = false;
    protected static final String TAG = "KeyguardTouchDelegate";
@@ -49,83 +51,121 @@ public class KeyguardTouchDelegate {
    private final ServiceConnection mKeyguardConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            Log.v(TAG, "Connected to keyguard");
            Slog.v(TAG, "Connected to keyguard");
            mService = IKeyguardService.Stub.asInterface(service);

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            Log.v(TAG, "Disconnected from keyguard");
            Slog.v(TAG, "Disconnected from keyguard");
            mService = null;
            sInstance = null; // force reconnection if this goes away
        }

    };

    public KeyguardTouchDelegate(Context context) {
    private KeyguardTouchDelegate(Context context) {
        Intent intent = new Intent();
        intent.setClassName(KEYGUARD_PACKAGE, KEYGUARD_CLASS);
        if (!context.bindServiceAsUser(intent, mKeyguardConnection,
                Context.BIND_AUTO_CREATE, UserHandle.OWNER)) {
            if (DEBUG) Log.v(TAG, "*** Keyguard: can't bind to " + KEYGUARD_CLASS);
            if (DEBUG) Slog.v(TAG, "*** Keyguard: can't bind to " + KEYGUARD_CLASS);
        } else {
            if (DEBUG) Log.v(TAG, "*** Keyguard started");
            if (DEBUG) Slog.v(TAG, "*** Keyguard started");
        }
    }

    public static KeyguardTouchDelegate getInstance(Context context) {
        if (sInstance == null) {
            sInstance = new KeyguardTouchDelegate(context);
        }
        return sInstance;
    }

    public boolean isSecure() {
        boolean secure = false;
        if (mService != null) {
        final IKeyguardService service = mService;
        if (service != null) {
            try {
                secure = mService.isSecure();
                return service.isSecure();
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException calling keyguard.isSecure()!", e);
                Slog.e(TAG, "RemoteException calling keyguard.isSecure()!", e);
            }
        } else {
            Log.w(TAG, "isSecure(): NO SERVICE!");
            Slog.w(TAG, "isSecure(): NO SERVICE!");
        }
        return secure;
        return false;
    }

    public boolean dispatch(MotionEvent event) {
        if (mService != null) {
        final IKeyguardService service = mService;
        if (service != null) {
            try {
                mService.dispatch(event);
                service.dispatch(event);
                return true;
            } catch (RemoteException e) {
                // What to do?
                Log.e(TAG, "RemoteException sending event to keyguard!", e);
                Slog.e(TAG, "RemoteException sending event to keyguard!", e);
            }
        } else {
            Slog.w(TAG, "dispatch(event): NO SERVICE!");
        }
        return false;
    }
            return true;

    public boolean isInputRestricted() {
        final IKeyguardService service = mService;
        if (service != null) {
            try {
                return service.isInputRestricted();
            } catch (RemoteException e) {
                Slog.w(TAG , "Remote Exception", e);
            }
        } else {
            Slog.w(TAG, "isInputRestricted(): NO SERVICE!");
        }
        return false;
    }

    public boolean isShowingAndNotHidden() {
        final IKeyguardService service = mService;
        if (service != null) {
            try {
                return service.isShowingAndNotHidden();
            } catch (RemoteException e) {
                Slog.w(TAG , "Remote Exception", e);
            }
        } else {
            Log.w(TAG, "dispatch(event): NO SERVICE!");
            Slog.w(TAG, "isShowingAndNotHidden(): NO SERVICE!");
        }
        return false;
    }

    public void showAssistant() {
        if (mService != null) {
        final IKeyguardService service = mService;
        if (service != null) {
            try {
                mService.showAssistant();
                service.showAssistant();
            } catch (RemoteException e) {
                // What to do?
                Log.e(TAG, "RemoteException launching assistant!", e);
                Slog.e(TAG, "RemoteException launching assistant!", e);
            }
        } else {
            Log.w(TAG, "dispatch(event): NO SERVICE!");
            Slog.w(TAG, "showAssistant(event): NO SERVICE!");
        }
    }

    public void launchCamera() {
        if (mService != null) {
        final IKeyguardService service = mService;
        if (service != null) {
            try {
                mService.launchCamera();
                service.launchCamera();
            } catch (RemoteException e) {
                // What to do?
                Log.e(TAG, "RemoteException launching camera!", e);
                Slog.e(TAG, "RemoteException launching camera!", e);
            }
        } else {
            Log.w(TAG, "dispatch(event): NO SERVICE!");
            Slog.w(TAG, "dispatch(event): NO SERVICE!");
        }
    }

+4 −7
Original line number Diff line number Diff line
@@ -88,7 +88,6 @@ public class NavigationBarView extends LinearLayout {

    // used to disable the camera icon in navbar when disabled by DPM
    private boolean mCameraDisabledByDpm;
    KeyguardTouchDelegate mKeyguardTouchDelegate;

    private final OnTouchListener mCameraTouchListener = new OnTouchListener() {
        @Override
@@ -112,7 +111,7 @@ public class NavigationBarView extends LinearLayout {
                    }
                    break;
            }
            return mKeyguardTouchDelegate.dispatch(event);
            return KeyguardTouchDelegate.getInstance(getContext()).dispatch(event);
        }
    };

@@ -155,8 +154,6 @@ public class NavigationBarView extends LinearLayout {

        mBarTransitions = new NavigationBarTransitions(this);

        mKeyguardTouchDelegate = new KeyguardTouchDelegate(mContext);

        mCameraDisabledByDpm = isCameraDisabledByDpm();
        watchForDevicePolicyChanges();
    }
@@ -341,7 +338,7 @@ public class NavigationBarView extends LinearLayout {
                final int disabledFlags = dpm.getKeyguardDisabledFeatures(null, userId);
                final  boolean disabledBecauseKeyguardSecure =
                        (disabledFlags & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0
                        && mKeyguardTouchDelegate.isSecure();
                        && KeyguardTouchDelegate.getInstance(getContext()).isSecure();
                return dpm.getCameraDisabled(null) || disabledBecauseKeyguardSecure;
            } catch (RemoteException e) {
                Log.e(TAG, "Can't get userId", e);
@@ -426,9 +423,9 @@ public class NavigationBarView extends LinearLayout {

    protected void launchForAccessibilityClick(View v) {
        if (v == getCameraButton()) {
            mKeyguardTouchDelegate.launchCamera();
            KeyguardTouchDelegate.getInstance(getContext()).launchCamera();
        } else if (v == getSearchLight()) {
            mKeyguardTouchDelegate.showAssistant();
            KeyguardTouchDelegate.getInstance(getContext()).showAssistant();
        }
    }

Loading