diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-02-13 10:30:22 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-02-13 10:30:22 +0000 |
commit | 090779c8a7549d37eec1625ae847054eb5a31210 (patch) | |
tree | aa632ee9a72e14224980322077be7b8eef7a1070 | |
parent | ae6b768aa9370265b704220b88fb608aaf9806fe (diff) | |
parent | aac6c8864b737761690eab8a9e29a6ee5f77d27b (diff) |
Merge "Adding support for passing touchevents through InputDispatcher"
7 files changed, 196 insertions, 43 deletions
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/IOverviewProxy.aidl b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/IOverviewProxy.aidl index 2ff98ba8ab30..37abab9f1ddb 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/IOverviewProxy.aidl +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/IOverviewProxy.aidl @@ -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; } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/InputChannelCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/InputChannelCompat.java index f7ccb816b675..804f4f112c14 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/InputChannelCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/InputChannelCompat.java @@ -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; @@ -53,6 +54,16 @@ public class InputChannelCompat { } /** + * 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 */ public static class InputEventReceiver { @@ -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) { }; } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/NavigationBarCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/NavigationBarCompat.java index 69aea2c59029..b363b4a242e1 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/NavigationBarCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/NavigationBarCompat.java @@ -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. - */ - public static int getQuickStepDragSlopPx() { - return convertDpToPixel(10); - } - - public static int getQuickStepTouchSlopPx() { - return convertDpToPixel(24); - } +/** + * TODO: Remove this class + */ +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); - } } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java new file mode 100644 index 000000000000..6d7abd089861 --- /dev/null +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java @@ -0,0 +1,52 @@ +/* + * 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); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java index c474faf6b1e0..83c4cfc6c126 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java +++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java @@ -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; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java index 651670cbf2c0..ebd420478c0f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -45,6 +45,8 @@ import android.content.res.Configuration; import android.graphics.Canvas; import android.graphics.Point; import android.graphics.Rect; +import android.graphics.Region; +import android.graphics.Region.Op; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -128,8 +130,8 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav private Rect mBackButtonBounds = new Rect(); private Rect mRecentsButtonBounds = new Rect(); private Rect mRotationButtonBounds = new Rect(); + private final Region mActiveRegion = new Region(); private int[] mTmpPosition = new int[2]; - private Rect mTmpRect = new Rect(); private KeyButtonDrawable mBackIcon; private KeyButtonDrawable mHomeDefaultIcon; @@ -954,17 +956,22 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); - updateButtonLocationOnScreen(getBackButton(), mBackButtonBounds); - updateButtonLocationOnScreen(getHomeButton(), mHomeButtonBounds); - updateButtonLocationOnScreen(getRecentsButton(), mRecentsButtonBounds); - updateButtonLocationOnScreen(getRotateSuggestionButton(), mRotationButtonBounds); + + mActiveRegion.setEmpty(); + updateButtonLocation(getBackButton(), mBackButtonBounds, true); + updateButtonLocation(getHomeButton(), mHomeButtonBounds, false); + updateButtonLocation(getRecentsButton(), mRecentsButtonBounds, false); + updateButtonLocation(getRotateSuggestionButton(), mRotationButtonBounds, true); + // TODO: Handle button visibility changes + mOverviewProxyService.onActiveNavBarRegionChanges(mActiveRegion); if (mGestureHelper != null) { mGestureHelper.onLayout(changed, left, top, right, bottom); } mRecentsOnboarding.setNavBarHeight(getMeasuredHeight()); } - private void updateButtonLocationOnScreen(ButtonDispatcher button, Rect buttonBounds) { + private void updateButtonLocation(ButtonDispatcher button, Rect buttonBounds, + boolean isActive) { View view = button.getCurrentView(); if (view == null) { buttonBounds.setEmpty(); @@ -975,6 +982,14 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav final float posY = view.getTranslationY(); view.setTranslationX(0); view.setTranslationY(0); + + if (isActive) { + view.getLocationOnScreen(mTmpPosition); + buttonBounds.set(mTmpPosition[0], mTmpPosition[1], + mTmpPosition[0] + view.getMeasuredWidth(), + mTmpPosition[1] + view.getMeasuredHeight()); + mActiveRegion.op(buttonBounds, Op.UNION); + } view.getLocationInWindow(mTmpPosition); buttonBounds.set(mTmpPosition[0], mTmpPosition[1], mTmpPosition[0] + view.getMeasuredWidth(), diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java index 84f1cef19b77..73ab5274a0ab 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java @@ -56,6 +56,7 @@ import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper; import com.android.systemui.recents.OverviewProxyService; import com.android.systemui.shared.recents.IOverviewProxy; import com.android.systemui.shared.recents.utilities.Utilities; +import com.android.systemui.shared.system.InputChannelCompat.InputEventDispatcher; import com.android.systemui.shared.system.NavigationBarCompat; import java.io.PrintWriter; @@ -676,8 +677,13 @@ public class QuickStepController implements GestureHelper { } private boolean proxyMotionEvents(MotionEvent event) { - final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy(); event.transform(mTransformGlobalMatrix); + InputEventDispatcher dispatcher = mOverviewEventSender.getInputEventDispatcher(); + if (dispatcher != null) { + dispatcher.dispatch(event); + } + + final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy(); try { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { overviewProxy.onPreMotionEvent(mNavigationBarView.getDownHitTarget()); |