Skip to content

Commit cfaf39e

Browse files
committed
cmsdk: Add touchscreen gestures support
Add the CMHW implementation for touchscreen gestures. Change-Id: Iabeee255748fc92376bc861409a7074de570cb0c
1 parent f142715 commit cfaf39e

File tree

6 files changed

+186
-0
lines changed

6 files changed

+186
-0
lines changed

api/cm_current.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ package cyanogenmod.hardware {
464464
method public deprecated int getDisplayGammaCalibrationMax();
465465
method public deprecated int getDisplayGammaCalibrationMin();
466466
method public cyanogenmod.hardware.DisplayMode[] getDisplayModes();
467+
method public cyanogenmod.hardware.TouchscreenGesture[] getTouchscreenGestures();
467468
method public static cyanogenmod.hardware.CMHardwareManager getInstance(android.content.Context);
468469
method public java.lang.String getLtoDestination();
469470
method public long getLtoDownloadInterval();
@@ -493,6 +494,7 @@ package cyanogenmod.hardware {
493494
method public deprecated boolean setDisplayGammaCalibration(int, int[]);
494495
method public boolean setDisplayMode(cyanogenmod.hardware.DisplayMode, boolean);
495496
method public boolean setPictureAdjustment(cyanogenmod.hardware.HSIC);
497+
method public boolean setTouchscreenGestureEnabled(cyanogenmod.hardware.TouchscreenGesture, boolean);
496498
method public boolean setVibratorIntensity(int);
497499
method public boolean unRegisterThermalListener(cyanogenmod.hardware.ThermalListenerCallback);
498500
method public boolean writePersistentBytes(java.lang.String, byte[]);
@@ -515,6 +517,7 @@ package cyanogenmod.hardware {
515517
field public static final deprecated int FEATURE_TAP_TO_WAKE = 512; // 0x200
516518
field public static final int FEATURE_THERMAL_MONITOR = 32768; // 0x8000
517519
field public static final int FEATURE_TOUCH_HOVERING = 2048; // 0x800
520+
field public static final int FEATURE_TOUCHSCREEN_GESTURES = 524288; // 0x80000
518521
field public static final int FEATURE_UNIQUE_DEVICE_ID = 65536; // 0x10000
519522
field public static final int FEATURE_VIBRATOR = 1024; // 0x400
520523
}
@@ -543,6 +546,15 @@ package cyanogenmod.hardware {
543546
method public void writeToParcel(android.os.Parcel, int);
544547
}
545548

549+
public class TouchscreenGesture implements android.os.Parcelable {
550+
ctor public TouchscreenGesture(int, java.lang.String, int);
551+
method public int describeContents();
552+
method public void writeToParcel(android.os.Parcel, int);
553+
field public final int id;
554+
field public final java.lang.String name;
555+
field public final int keycode;
556+
}
557+
546558
public abstract interface IThermalListenerCallback implements android.os.IInterface {
547559
method public abstract void onThermalChanged(int) throws android.os.RemoteException;
548560
}

cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (C) 2015-2016 The CyanogenMod Project
3+
* 2017 The LineageOS Project
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
56
* you may not use this file except in compliance with the License.
@@ -34,6 +35,7 @@
3435
import cyanogenmod.hardware.IThermalListenerCallback;
3536
import cyanogenmod.hardware.ThermalListenerCallback;
3637
import cyanogenmod.hardware.HSIC;
38+
import cyanogenmod.hardware.TouchscreenGesture;
3739

3840
import java.io.File;
3941
import java.util.ArrayList;
@@ -56,6 +58,7 @@
5658
import org.cyanogenmod.hardware.SunlightEnhancement;
5759
import org.cyanogenmod.hardware.ThermalMonitor;
5860
import org.cyanogenmod.hardware.ThermalUpdateCallback;
61+
import org.cyanogenmod.hardware.TouchscreenGestures;
5962
import org.cyanogenmod.hardware.TouchscreenHovering;
6063
import org.cyanogenmod.hardware.UniqueDeviceId;
6164
import org.cyanogenmod.hardware.VibratorHW;
@@ -117,6 +120,9 @@ private interface CMHardwareInterface {
117120
public HSIC getDefaultPictureAdjustment();
118121
public boolean setPictureAdjustment(HSIC hsic);
119122
public List<Range<Float>> getPictureAdjustmentRanges();
123+
124+
public TouchscreenGesture[] getTouchscreenGestures();
125+
public boolean setTouchscreenGestureEnabled(TouchscreenGesture gesture, boolean state);
120126
}
121127

122128
private class LegacyCMHardware implements CMHardwareInterface {
@@ -160,6 +166,8 @@ public LegacyCMHardware() {
160166
mSupportedFeatures |= CMHardwareManager.FEATURE_COLOR_BALANCE;
161167
if (PictureAdjustment.isSupported())
162168
mSupportedFeatures |= CMHardwareManager.FEATURE_PICTURE_ADJUSTMENT;
169+
if (TouchscreenGestures.isSupported())
170+
mSupportedFeatures |= CMHardwareManager.FEATURE_TOUCHSCREEN_GESTURES;
163171
}
164172

165173
public int getSupportedFeatures() {
@@ -384,6 +392,14 @@ public List<Range<Float>> getPictureAdjustmentRanges() {
384392
PictureAdjustment.getContrastRange(),
385393
PictureAdjustment.getSaturationThresholdRange());
386394
}
395+
396+
public TouchscreenGesture[] getTouchscreenGestures() {
397+
return TouchscreenGestures.getAvailableGestures();
398+
}
399+
400+
public boolean setTouchscreenGestureEnabled(TouchscreenGesture gesture, boolean state) {
401+
return TouchscreenGestures.setGestureEnabled(gesture, state);
402+
}
387403
}
388404

389405
private CMHardwareInterface getImpl(Context context) {
@@ -860,5 +876,27 @@ public float[] getPictureAdjustmentRanges() {
860876
}
861877
return new float[10];
862878
}
879+
880+
@Override
881+
public TouchscreenGesture[] getTouchscreenGestures() {
882+
mContext.enforceCallingOrSelfPermission(
883+
cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null);
884+
if (!isSupported(CMHardwareManager.FEATURE_TOUCHSCREEN_GESTURES)) {
885+
Log.e(TAG, "Touchscreen gestures are not supported");
886+
return null;
887+
}
888+
return mCmHwImpl.getTouchscreenGestures();
889+
}
890+
891+
@Override
892+
public boolean setTouchscreenGestureEnabled(TouchscreenGesture gesture, boolean state) {
893+
mContext.enforceCallingOrSelfPermission(
894+
cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null);
895+
if (!isSupported(CMHardwareManager.FEATURE_TOUCHSCREEN_GESTURES)) {
896+
Log.e(TAG, "Touchscreen gestures are not supported");
897+
return false;
898+
}
899+
return mCmHwImpl.setTouchscreenGestureEnabled(gesture, state);
900+
}
863901
};
864902
}

sdk/src/java/cyanogenmod/hardware/CMHardwareManager.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (C) 2015-2016 The CyanogenMod Project
3+
* 2017 The LineageOS Project
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
56
* you may not use this file except in compliance with the License.
@@ -172,6 +173,12 @@ public final class CMHardwareManager {
172173
@VisibleForTesting
173174
public static final int FEATURE_PICTURE_ADJUSTMENT = 0x40000;
174175

176+
/**
177+
* Touchscreen gesture
178+
*/
179+
@VisibleForTesting
180+
public static final int FEATURE_TOUCHSCREEN_GESTURES = 0x80000;
181+
175182
private static final List<Integer> BOOLEAN_FEATURES = Arrays.asList(
176183
FEATURE_ADAPTIVE_BACKLIGHT,
177184
FEATURE_COLOR_ENHANCEMENT,
@@ -1042,4 +1049,31 @@ public boolean unRegisterThermalListener(ThermalListenerCallback thermalCallback
10421049
}
10431050
return false;
10441051
}
1052+
1053+
/**
1054+
* @return a list of available touchscreen gestures on the devices
1055+
*/
1056+
public TouchscreenGesture[] getTouchscreenGestures() {
1057+
try {
1058+
if (checkService()) {
1059+
return sService.getTouchscreenGestures();
1060+
}
1061+
} catch (RemoteException e) {
1062+
}
1063+
return null;
1064+
}
1065+
1066+
/**
1067+
* @return true if setting the activation status was successful
1068+
*/
1069+
public boolean setTouchscreenGestureEnabled(
1070+
TouchscreenGesture gesture, boolean state) {
1071+
try {
1072+
if (checkService()) {
1073+
return sService.setTouchscreenGestureEnabled(gesture, state);
1074+
}
1075+
} catch (RemoteException e) {
1076+
}
1077+
return false;
1078+
}
10451079
}

sdk/src/java/cyanogenmod/hardware/ICMHardwareService.aidl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright (c) 2015, The CyanogenMod Project
3+
* 2017 The LineageOS Project
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
56
* you may not use this file except in compliance with the License.
@@ -19,6 +20,7 @@ package cyanogenmod.hardware;
1920
import cyanogenmod.hardware.DisplayMode;
2021
import cyanogenmod.hardware.HSIC;
2122
import cyanogenmod.hardware.IThermalListenerCallback;
23+
import cyanogenmod.hardware.TouchscreenGesture;
2224

2325
/** @hide */
2426
interface ICMHardwareService {
@@ -70,4 +72,6 @@ interface ICMHardwareService {
7072
boolean setPictureAdjustment(in HSIC hsic);
7173
float[] getPictureAdjustmentRanges();
7274

75+
TouchscreenGesture[] getTouchscreenGestures();
76+
boolean setTouchscreenGestureEnabled(in TouchscreenGesture gesture, boolean state);
7377
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (C) 2016 The CyanogenMod Project
3+
* 2017 The LineageOS Project
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package cyanogenmod.hardware;
19+
20+
parcelable TouchscreenGesture;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (C) 2016 The CyanogenMod Project
3+
* 2017 The LineageOS Project
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package cyanogenmod.hardware;
19+
20+
import android.os.Parcel;
21+
import android.os.Parcelable;
22+
23+
/**
24+
* Touchscreen gestures API
25+
*
26+
* A device may implement several touchscreen gestures for use while
27+
* the display is turned off, such as drawing alphabets and shapes.
28+
* These gestures can be interpreted by userspace to activate certain
29+
* actions and launch certain apps, such as to skip music tracks,
30+
* to turn on the flashlight, or to launch the camera app.
31+
*
32+
* This *should always* be supported by the hardware directly.
33+
* A lot of recent touch controllers have a firmware option for this.
34+
*
35+
* This API provides support for enumerating the gestures
36+
* supported by the touchscreen.
37+
*
38+
* A TouchscreenGesture is referenced by it's identifier and carries an
39+
* associated name (up to the user to translate this value).
40+
*/
41+
public class TouchscreenGesture implements Parcelable {
42+
43+
public final int id;
44+
public final String name;
45+
public final int keycode;
46+
47+
public TouchscreenGesture(int id, String name, int keycode) {
48+
this.id = id;
49+
this.name = name;
50+
this.keycode = keycode;
51+
}
52+
53+
@Override
54+
public int describeContents() {
55+
return 0;
56+
}
57+
58+
@Override
59+
public void writeToParcel(Parcel parcel, int flags) {
60+
parcel.writeInt(id);
61+
parcel.writeString(name);
62+
parcel.writeInt(keycode);
63+
}
64+
65+
/** @hide */
66+
public static final Parcelable.Creator<TouchscreenGesture> CREATOR =
67+
new Parcelable.Creator<TouchscreenGesture>() {
68+
69+
public TouchscreenGesture createFromParcel(Parcel in) {
70+
return new TouchscreenGesture(in.readInt(), in.readString(), in.readInt());
71+
}
72+
73+
@Override
74+
public TouchscreenGesture[] newArray(int size) {
75+
return new TouchscreenGesture[size];
76+
}
77+
};
78+
}

0 commit comments

Comments
 (0)