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

Commit 090779c8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adding support for passing touchevents through InputDispatcher"

parents ae6b768a aac6c886
Loading
Loading
Loading
Loading
+34 −11
Original line number Diff line number Diff line
@@ -16,19 +16,32 @@

package com.android.systemui.shared.recents;

import android.graphics.Region;
import android.os.Bundle;
import android.view.MotionEvent;
import com.android.systemui.shared.recents.ISystemUiProxy;

oneway interface IOverviewProxy {
    void onBind(in ISystemUiProxy sysUiProxy);

    void onActiveNavBarRegionChanges(in Region activeRegion) = 11;

    void onInitialize(in Bundle params) = 12;


    /**
     * @deprecated
     */
    void onBind(in ISystemUiProxy sysUiProxy) = 0;

    /**
     * Called once immediately prior to the first onMotionEvent() call, providing a hint to the
     * target the initial source of the subsequent motion events.
     *
     * @param downHitTarget is one of the {@link NavigationBarCompat.HitTarget}s
     *
     * @deprecated
     */
    void onPreMotionEvent(int downHitTarget);
    void onPreMotionEvent(int downHitTarget) = 1;

    /**
     * Proxies motion events from the nav bar in SystemUI to the OverviewProxyService. The sender
@@ -38,40 +51,48 @@ oneway interface IOverviewProxy {
     * Quick scrub: DOWN, (MOVE/POINTER_DOWN/POINTER_UP)*, SCRUB_START, SCRUB_PROGRESS*, SCRUB_END
     *
     * Once quick scrub is sent, then no further motion events will be provided.
     *
     * @deprecated
     */
    void onMotionEvent(in MotionEvent event);
    void onMotionEvent(in MotionEvent event) = 2;

    /**
     * Sent when the user starts to actively scrub the nav bar to switch tasks. Once this event is
     * sent the caller will stop sending any motion events and will no longer preemptively cancel
     * any recents animations started as a part of the motion event handling.
     *
     * @deprecated
     */
    void onQuickScrubStart();
    void onQuickScrubStart() = 3;

    /**
     * Sent when the user stops actively scrubbing the nav bar to switch tasks.
     *
     * @deprecated
     */
    void onQuickScrubEnd();
    void onQuickScrubEnd() = 4;

    /**
     * Sent for each movement over the nav bar while the user is scrubbing it to switch tasks.
     *
     * @deprecated
     */
    void onQuickScrubProgress(float progress);
    void onQuickScrubProgress(float progress) = 5;

    /**
     * Sent when overview button is pressed to toggle show/hide of overview.
     */
    void onOverviewToggle();
    void onOverviewToggle() = 6;

    /**
     * Sent when overview is to be shown.
     */
    void onOverviewShown(boolean triggeredFromAltTab);
    void onOverviewShown(boolean triggeredFromAltTab) = 7;

    /**
     * Sent when overview is to be hidden.
     */
    void onOverviewHidden(boolean triggeredFromAltTab, boolean triggeredFromHomeKey);
    void onOverviewHidden(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) = 8;

    /**
     * Sent when a user swipes up over the navigation bar to launch overview. Swipe up is determined
@@ -83,11 +104,13 @@ oneway interface IOverviewProxy {
     * visible, this event will still be sent if user swipes up). When this signal is sent,
     * navigation bar will not handle any gestures such as quick scrub and the home button will
     * cancel (long) press.
     *
     * @deprecated
     */
    void onQuickStep(in MotionEvent event);
    void onQuickStep(in MotionEvent event) = 9;

    /**
     * Sent when there was an action on one of the onboarding tips view.
     */
    void onTip(int actionType, int viewType);
    void onTip(int actionType, int viewType) = 10;
}
+12 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.shared.system;

import android.os.Bundle;
import android.os.Looper;
import android.util.Pair;
import android.view.BatchedInputEventReceiver;
@@ -52,6 +53,16 @@ public class InputChannelCompat {
        return Pair.create(dispatcher, receiver);
    }

    /**
     * Creates a dispatcher from the extras received as part on onInitialize
     */
    public static InputEventReceiver fromBundle(Bundle params, String key,
            Looper looper, Choreographer choreographer, InputEventListener listener) {

        InputChannel channel = params.getParcelable(key);
        return new InputEventReceiver(channel, looper, choreographer, listener);
    }

    /**
     * @see BatchedInputEventReceiver
     */
@@ -90,7 +101,7 @@ public class InputChannelCompat {
        private final InputChannel mInputChannel;
        private final InputEventSender mSender;

        private InputEventDispatcher(InputChannel inputChannel, Looper looper) {
        public InputEventDispatcher(InputChannel inputChannel, Looper looper) {
            mInputChannel = inputChannel;
            mSender = new InputEventSender(inputChannel, looper) { };
        }
+4 −24
Original line number Diff line number Diff line
@@ -17,31 +17,15 @@
package com.android.systemui.shared.system;

import android.annotation.IntDef;
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class NavigationBarCompat {
/**
     * Touch slopes and thresholds for quick step operations. Drag slop is the point where the
     * home button press/long press over are ignored and will start to drag when exceeded and the
     * touch slop is when the respected operation will occur when exceeded. Touch slop must be
     * larger than the drag slop.
 * TODO: Remove this class
 */
    public static int getQuickStepDragSlopPx() {
        return convertDpToPixel(10);
    }

    public static int getQuickStepTouchSlopPx() {
        return convertDpToPixel(24);
    }
public class NavigationBarCompat extends QuickStepContract {

    public static int getQuickScrubTouchSlopPx() {
        return convertDpToPixel(24);
    }

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({HIT_TARGET_NONE, HIT_TARGET_BACK, HIT_TARGET_HOME, HIT_TARGET_OVERVIEW})
@@ -75,8 +59,4 @@ public class NavigationBarCompat {
     * Interaction type: show/hide the overview button while this service is connected to launcher
     */
    public static final int FLAG_SHOW_OVERVIEW_BUTTON = 0x4;

    private static int convertDpToPixel(float dp){
        return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
    }
}
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.systemui.shared.system;

import android.content.res.Resources;

/**
 * Various shared constants between Launcher and SysUI as part of quickstep
 */
public class QuickStepContract {

    public static final String KEY_EXTRA_SYSUI_PROXY = "extra_sysui_proxy";
    public static final String KEY_EXTRA_INPUT_CHANNEL = "extra_input_channel";
    public static final String KEY_EXTRA_WINDOW_CORNER_RADIUS = "extra_window_corner_radius";
    public static final String KEY_EXTRA_SUPPORTS_WINDOW_CORNERS = "extra_supports_window_corners";

    /**
     * Touch slopes and thresholds for quick step operations. Drag slop is the point where the
     * home button press/long press over are ignored and will start to drag when exceeded and the
     * touch slop is when the respected operation will occur when exceeded. Touch slop must be
     * larger than the drag slop.
     */
    public static int getQuickStepDragSlopPx() {
        return convertDpToPixel(10);
    }

    public static int getQuickStepTouchSlopPx() {
        return convertDpToPixel(24);
    }

    public static int getQuickScrubTouchSlopPx() {
        return convertDpToPixel(24);
    }

    private static int convertDpToPixel(float dp) {
        return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
    }
}
+66 −0
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@ import static android.view.MotionEvent.ACTION_UP;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_SWIPE_UP;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON;
import static com.android.systemui.shared.system.NavigationBarCompat.InteractionType;
import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_INPUT_CHANNEL;
import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SUPPORTS_WINDOW_CORNERS;
import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SYSUI_PROXY;
import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_WINDOW_CORNER_RADIUS;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -32,7 +36,9 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -41,6 +47,7 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
import android.view.InputChannel;
import android.view.MotionEvent;

import com.android.internal.policy.ScreenDecorationsUtils;
@@ -51,6 +58,7 @@ import com.android.systemui.recents.OverviewProxyService.OverviewProxyListener;
import com.android.systemui.shared.recents.IOverviewProxy;
import com.android.systemui.shared.recents.ISystemUiProxy;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.InputChannelCompat.InputEventDispatcher;
import com.android.systemui.stackdivider.Divider;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.policy.CallbackController;
@@ -93,6 +101,8 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
    private final List<OverviewProxyListener> mConnectionCallbacks = new ArrayList<>();
    private final Intent mQuickStepIntent;

    private Region mActiveNavBarRegion;

    private IOverviewProxy mOverviewProxy;
    private int mConnectionBackoffAttempts;
    private @InteractionType int mInteractionFlags;
@@ -103,6 +113,8 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
    private float mWindowCornerRadius;
    private boolean mSupportsRoundedCornersOnWindows;

    private InputEventDispatcher mInputEventDispatcher;

    private ISystemUiProxy mSysUiProxy = new ISystemUiProxy.Stub() {

        public void startScreenPinning(int taskId) {
@@ -309,6 +321,20 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
                mCurrentBoundedUserId = -1;
                Log.e(TAG_OPS, "Failed to call onBind()", e);
            }

            Bundle params = new Bundle();
            params.putBinder(KEY_EXTRA_SYSUI_PROXY, mSysUiProxy.asBinder());
            params.putParcelable(KEY_EXTRA_INPUT_CHANNEL, createNewInputDispatcher());
            params.putFloat(KEY_EXTRA_WINDOW_CORNER_RADIUS, mWindowCornerRadius);
            params.putBoolean(KEY_EXTRA_SUPPORTS_WINDOW_CORNERS, mSupportsRoundedCornersOnWindows);
            try {
                mOverviewProxy.onInitialize(params);
            } catch (RemoteException e) {
                // Ignore error until the migration is complete.
                Log.e(TAG_OPS, "Failed to call onBind()", e);
            }
            dispatchNavButtonBounds();

            notifyConnectionChanged();
        }

@@ -317,6 +343,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            Log.w(TAG_OPS, "Null binding of '" + name + "', try reconnecting");
            mCurrentBoundedUserId = -1;
            retryConnectionWithBackoff();
            disposeInputDispatcher();
        }

        @Override
@@ -324,15 +351,32 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            Log.w(TAG_OPS, "Binding died of '" + name + "', try reconnecting");
            mCurrentBoundedUserId = -1;
            retryConnectionWithBackoff();
            disposeInputDispatcher();
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            // Do nothing
            mCurrentBoundedUserId = -1;
            disposeInputDispatcher();
        }
    };

    private void disposeInputDispatcher() {
        if (mInputEventDispatcher != null) {
            mInputEventDispatcher.dispose();
            mInputEventDispatcher = null;
        }
    }

    private InputChannel createNewInputDispatcher() {
        disposeInputDispatcher();

        InputChannel[] channels = InputChannel.openInputChannelPair("overview-proxy-service");
        mInputEventDispatcher = new InputEventDispatcher(channels[0], Looper.getMainLooper());
        return channels[1];
    }

    private final DeviceProvisionedListener mDeviceProvisionedCallback =
                new DeviceProvisionedListener() {
            @Override
@@ -382,6 +426,24 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
        }
    }

    /**
     * Sets the navbar region which can receive touch inputs
     */
    public void onActiveNavBarRegionChanges(Region activeRegion) {
        mActiveNavBarRegion = activeRegion;
        dispatchNavButtonBounds();
    }

    private void dispatchNavButtonBounds() {
        if (mOverviewProxy != null && mActiveNavBarRegion != null) {
            try {
                mOverviewProxy.onActiveNavBarRegionChanges(mActiveNavBarRegion);
            } catch (RemoteException e) {
                Log.e(TAG_OPS, "Failed to call onActiveNavBarRegionChanges()", e);
            }
        }
    }

    public float getBackButtonAlpha() {
        return mBackButtonAlpha;
    }
@@ -477,6 +539,10 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
        return mOverviewProxy;
    }

    public InputEventDispatcher getInputEventDispatcher() {
        return mInputEventDispatcher;
    }

    public int getInteractionFlags() {
        return mInteractionFlags;
    }
Loading