Skip to content

Commit 458afeb

Browse files
AmolAmritaoleary
authored andcommitted
[Base:1/2] Add back Edge gestures
Revert "base: cleanup nav gestures code" This reverts commit ddb5a2f. Revert "base: add long press home handling to nav gestures" This reverts commit b755ddf. Revert "base: implement OP like navigation gestures [1/2]" This reverts commit 2c23cdd. Revert "Revert Edge Gesture [2/2]" This reverts commit 38390d4. Change-Id: I5dfdd7bee7a2f389bcb275b3d2a135012b170e02
1 parent fa8cb9b commit 458afeb

26 files changed

Lines changed: 2678 additions & 1 deletion

Android.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ LOCAL_SRC_FILES += \
342342
core/java/android/service/voice/IVoiceInteractionSession.aidl \
343343
core/java/android/service/voice/IVoiceInteractionSessionService.aidl \
344344
core/java/android/service/gesture/IGestureService.aidl \
345+
core/java/android/service/gesture/IEdgeGestureService.aidl \
346+
core/java/android/service/gesture/IEdgeGestureActivationListener.aidl \
347+
core/java/android/service/gesture/IEdgeGestureHostCallback.aidl \
345348
core/java/android/service/wallpaper/IWallpaperConnection.aidl \
346349
core/java/android/service/wallpaper/IWallpaperEngine.aidl \
347350
core/java/android/service/wallpaper/IWallpaperService.aidl \

core/java/android/provider/Settings.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4828,6 +4828,12 @@ public boolean validate(String value) {
48284828
*/
48294829
public static final String VOLUME_LINK_NOTIFICATION = "volume_link_notification";
48304830

4831+
/**
4832+
* Use EdgeGesture Service for system gestures in PhoneWindowManager
4833+
* @hide
4834+
*/
4835+
public static final String USE_EDGE_SERVICE_FOR_GESTURES = "edge_service_for_gestures";
4836+
48314837
/**
48324838
* Apps to hide in the ChooserActivity
48334839
* @hide
@@ -8318,6 +8324,54 @@ public static boolean putFloatForUser(ContentResolver cr, String name, float val
83188324
public static final String MANAGED_PROFILE_CONTACT_REMOTE_SEARCH =
83198325
"managed_profile_contact_remote_search";
83208326

8327+
/**
8328+
* Whether to use edge gestures to navigate.
8329+
* @hide
8330+
*/
8331+
public static final String EDGE_GESTURES_ENABLED = "edge_gestures_enabled";
8332+
8333+
/**
8334+
* Haptic feedback duration on edge gesture navigation.
8335+
* @hide
8336+
*/
8337+
public static final String EDGE_GESTURES_FEEDBACK_DURATION = "edge_gestures_feedback_duration";
8338+
8339+
/**
8340+
* Long press duration on edge gesture navigation.
8341+
* @hide
8342+
*/
8343+
public static final String EDGE_GESTURES_LONG_PRESS_DURATION = "edge_gestures_long_press_duration";
8344+
8345+
/**
8346+
* Back gesture active on this edges.
8347+
* @hide
8348+
*/
8349+
public static final String EDGE_GESTURES_BACK_EDGES = "edge_gestures_back_edges";
8350+
8351+
/**
8352+
* Back gesture active on this edges when on landscape.
8353+
* @hide
8354+
*/
8355+
public static final String EDGE_GESTURES_LANDSCAPE_BACK_EDGES = "edge_gestures_landscape_back_edges";
8356+
8357+
/**
8358+
* Activate back gestures only when Y position > than this % of screen.
8359+
* @hide
8360+
*/
8361+
public static final String EDGE_GESTURES_BACK_SCREEN_PERCENT = "edge_gestures_back_screen_percent";
8362+
8363+
/**
8364+
* Show UI feedback when using back gesture.
8365+
* @hide
8366+
*/
8367+
public static final String EDGE_GESTURES_BACK_SHOW_UI_FEEDBACK = "edge_gestures_back_show_ui_feedback";
8368+
8369+
/**
8370+
* Use black arrow theme instead of the white version.
8371+
* @hide
8372+
*/
8373+
public static final String EDGE_GESTURES_BACK_USE_BLACK_ARROW = "edge_gestures_back_use_black_arrow";
8374+
83218375
/**
83228376
* Whether or not the automatic storage manager is enabled and should run on the device.
83238377
*
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/*
2+
* Copyright (C) 2013 The CyanogenMod Project (Jens Doll)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package android.service.gesture;
17+
18+
import android.os.Handler;
19+
import android.os.IBinder;
20+
import android.os.Looper;
21+
import android.os.RemoteException;
22+
import android.os.ServiceManager;
23+
import android.service.gesture.IEdgeGestureActivationListener;
24+
import android.service.gesture.IEdgeGestureHostCallback;
25+
import android.service.gesture.IEdgeGestureService;
26+
import android.util.Slog;
27+
28+
import com.android.internal.util.gesture.EdgeGesturePosition;
29+
30+
/**
31+
* This is a simple Manager class for edge gesture service on the application side. The application need
32+
* {@code INJECT_EVENTS} permission to register {@code EdgeGestureActivationListener}s.<br>
33+
* See {@link android.service.gesture.IEdgeGestureService} for more information.
34+
*
35+
* @see android.service.gesture.IEdgeGestureService
36+
* @hide
37+
*/
38+
public class EdgeGestureManager {
39+
public static final String TAG = "EdgeGestureManager";
40+
public static final boolean DEBUG = false;
41+
42+
private static EdgeGestureManager sInstance;
43+
44+
private final IEdgeGestureService mPs;
45+
46+
public static abstract class EdgeGestureActivationListener {
47+
private Handler mHandler;
48+
private IEdgeGestureHostCallback mCallback;
49+
50+
private class Delegator extends IEdgeGestureActivationListener.Stub {
51+
public void onEdgeGestureActivation(final int touchX, final int touchY, final int positionIndex, final int flags)
52+
throws RemoteException {
53+
mHandler.post(new Runnable() {
54+
public void run() {
55+
EdgeGestureActivationListener.this.onEdgeGestureActivation(touchX, touchY, EdgeGesturePosition.values()[positionIndex], flags);
56+
}
57+
});
58+
}
59+
}
60+
private Delegator mDelegator;
61+
62+
public EdgeGestureActivationListener() {
63+
this(Looper.getMainLooper());
64+
}
65+
66+
public EdgeGestureActivationListener(Looper looper) {
67+
mHandler = new Handler(looper);
68+
mDelegator = new Delegator();
69+
}
70+
71+
/* package */ void setHostCallback(IEdgeGestureHostCallback hostCallback) {
72+
mCallback = hostCallback;
73+
}
74+
75+
/**
76+
* Override this to receive activations from the edge gesture service.
77+
*
78+
* @param touchX the last X position a touch event was registered.
79+
* @param touchY the last Y position a touch event was registered.
80+
* @param position the position of the activation.
81+
* @param flags currently 0.
82+
* @see IEdgeGestureActivationListener#onEdgeGestureActivation(int, int, int, int)
83+
*/
84+
public abstract void onEdgeGestureActivation(int touchX, int touchY, EdgeGesturePosition position, int flags);
85+
86+
/**
87+
* After being activated, this allows the edge gesture control to steal focus from the current
88+
* window.
89+
*
90+
* @see IEdgeGestureHostCallback#gainTouchFocus(IBinder)
91+
*/
92+
public boolean gainTouchFocus(IBinder applicationWindowToken) {
93+
try {
94+
return mCallback.gainTouchFocus(applicationWindowToken);
95+
} catch (RemoteException e) {
96+
Slog.w(TAG, "gainTouchFocus failed: " + e.getMessage());
97+
/* fall through */
98+
}
99+
return false;
100+
}
101+
102+
public boolean dropEventsUntilLift() {
103+
try {
104+
return mCallback.dropEventsUntilLift();
105+
} catch (RemoteException e) {
106+
Slog.w(TAG, "dropNextEvents failed: " + e.getMessage());
107+
/* fall through */
108+
}
109+
return false;
110+
}
111+
112+
/**
113+
* Turns listening for edge gesture activation gestures on again, after it was disabled during
114+
* the call to the listener.
115+
*
116+
* @see IEdgeGestureHostCallback#restoreListenerState()
117+
*/
118+
public void restoreListenerState() {
119+
if (DEBUG) {
120+
Slog.d(TAG, "restore listener state: " + Thread.currentThread().getName());
121+
}
122+
try {
123+
mCallback.restoreListenerState();
124+
} catch (RemoteException e) {
125+
Slog.w(TAG, "restoreListenerState failed: " + e.getMessage());
126+
/* fall through */
127+
}
128+
}
129+
}
130+
131+
private EdgeGestureManager(IEdgeGestureService ps) {
132+
mPs = ps;
133+
}
134+
135+
/**
136+
* Gets an instance of the edge gesture manager.
137+
*
138+
* @return The edge gesture manager instance.
139+
* @hide
140+
*/
141+
public static EdgeGestureManager getInstance() {
142+
synchronized (EdgeGestureManager.class) {
143+
if (sInstance == null) {
144+
IBinder b = ServiceManager.getService("edgegestureservice");
145+
sInstance = new EdgeGestureManager(IEdgeGestureService.Stub.asInterface(b));
146+
}
147+
return sInstance;
148+
}
149+
}
150+
151+
/**
152+
* Checks if the edge gesture service is present.
153+
* <p>
154+
* Since the service is only started at boot time and is bound to the system server, this
155+
* is constant for the devices up time.
156+
*
157+
* @return {@code true} when the edge gesture service is running on this device.
158+
* @hide
159+
*/
160+
public boolean isPresent() {
161+
return mPs != null;
162+
}
163+
164+
/**
165+
* Register a listener for edge gesture activation gestures. Initially the listener
166+
* is set to listen for no position. Use updateedge gestureActivationListener() to
167+
* bind the listener to positions.
168+
*
169+
* @param listener is the activation listener.
170+
* @return {@code true} if the registration was successful.
171+
* @hide
172+
*/
173+
public boolean setEdgeGestureActivationListener(EdgeGestureActivationListener listener) {
174+
if (DEBUG) {
175+
Slog.d(TAG, "Set edge gesture activation listener");
176+
}
177+
if (mPs == null) {
178+
Slog.e(TAG, "Failed to set edge gesture activation listener: Service not present");
179+
return false;
180+
}
181+
try {
182+
IEdgeGestureHostCallback callback = mPs.registerEdgeGestureActivationListener(listener.mDelegator);
183+
listener.setHostCallback(callback);
184+
return true;
185+
} catch (RemoteException e) {
186+
Slog.e(TAG, "Failed to set edge gesture activation listener: " + e.getMessage());
187+
return false;
188+
}
189+
}
190+
191+
/**
192+
* Update the listener to react on gestures in the given positions.
193+
*
194+
* @param listener is a already registered listener.
195+
* @param positions is a bit mask describing the positions to listen to.
196+
* @hide
197+
*/
198+
public void updateEdgeGestureActivationListener(EdgeGestureActivationListener listener, int positions) {
199+
if (DEBUG) {
200+
Slog.d(TAG, "Update edge gesture activation listener: 0x" + Integer.toHexString(positions));
201+
}
202+
if (mPs == null) {
203+
Slog.e(TAG, "Failed to update edge gesture activation listener: Service not present");
204+
return;
205+
}
206+
try {
207+
mPs.updateEdgeGestureActivationListener(listener.mDelegator.asBinder(), positions);
208+
} catch (RemoteException e) {
209+
Slog.e(TAG, "Failed to update edge gesture activation listener: " + e.getMessage());
210+
}
211+
}
212+
213+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
package android.service.gesture;
3+
4+
import android.view.InputEvent;
5+
6+
/** @hide */
7+
interface IEdgeGestureActivationListener {
8+
9+
/** Called when a gesture is detected that fits to the activation gesture. At this point in
10+
* time gesture detection is disabled. Call IEdgeGestureHostCallback.restoreState() to
11+
* recover from this.
12+
*/
13+
oneway void onEdgeGestureActivation(int touchX, int touchY, int positionIndex, int flags);
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package android.service.gesture;
2+
3+
/** @hide */
4+
interface IEdgeGestureHostCallback {
5+
6+
/** After being activated, this allows to steal focus from the current
7+
* window
8+
*/
9+
boolean gainTouchFocus(IBinder windowToken);
10+
11+
/** Turns listening for activation gestures on again, after it was disabled during
12+
* the call to the listener.
13+
*/
14+
oneway void restoreListenerState();
15+
16+
/*
17+
* Tells filter to drop all events till touch up
18+
*/
19+
boolean dropEventsUntilLift();
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package android.service.gesture;
2+
3+
import android.service.gesture.IEdgeGestureActivationListener;
4+
import android.service.gesture.IEdgeGestureHostCallback;
5+
6+
/** @hide */
7+
interface IEdgeGestureService {
8+
9+
/** Register a listener for activation gestures. Initially the listener
10+
* is set to listen for no position. Use updateEdgeGestureActivationListener() to
11+
* bind the listener to positions.
12+
* Use the returned IEdgeGestureHostCallback to manipulate the state after activation.
13+
*/
14+
IEdgeGestureHostCallback registerEdgeGestureActivationListener(in IEdgeGestureActivationListener listener);
15+
16+
/** Update the listener to react on gestures in the given positions.
17+
*/
18+
void updateEdgeGestureActivationListener(in IBinder listener, int positionFlags);
19+
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<body>
2+
3+
{@hide}
4+
5+
</body>

core/java/android/view/InputDevice.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ public final class InputDevice implements Parcelable {
301301
*/
302302
public static final int SOURCE_HDMI = 0x02000000 | SOURCE_CLASS_BUTTON;
303303

304+
/**
305+
* The input source is a custom virtual key event sent programmatically to emulate different events.
306+
*
307+
* The key requested is different from the actual key's event.
308+
*
309+
* @hide
310+
*/
311+
public static final int SOURCE_CUSTOM = 0x08000000 | SOURCE_CLASS_BUTTON;
312+
304313
/**
305314
* The input source is a specific virtual event sent from navigation bar.
306315
*

core/java/android/view/ViewRootImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ static final class SystemUiVisibilityInfo {
474474
}
475475

476476
private String mTag = TAG;
477+
boolean mHaveMoveEvent = false;
478+
boolean mIsPerfLockAcquired = false;
477479

478480
public ViewRootImpl(Context context, Display display) {
479481
mContext = context;
@@ -4793,6 +4795,14 @@ private int processPointerEvent(QueuedInputEvent q) {
47934795
mAttachInfo.mUnbufferedDispatchRequested = false;
47944796
mAttachInfo.mHandlingPointerEvent = true;
47954797
boolean handled = mView.dispatchPointerEvent(event);
4798+
4799+
int action = event.getActionMasked();
4800+
if (action == MotionEvent.ACTION_MOVE) {
4801+
mHaveMoveEvent = true;
4802+
} else if (action == MotionEvent.ACTION_UP) {
4803+
mHaveMoveEvent = false;
4804+
mIsPerfLockAcquired = false;
4805+
}
47964806
maybeUpdatePointerIcon(event);
47974807
maybeUpdateTooltip(event);
47984808
mAttachInfo.mHandlingPointerEvent = false;

0 commit comments

Comments
 (0)