From cfaf39e73f41a0405283cf2a042187790b3186ff Mon Sep 17 00:00:00 2001 From: Zhao Wei Liew Date: Thu, 17 Nov 2016 23:36:25 +0800 Subject: [PATCH] cmsdk: Add touchscreen gestures support Add the CMHW implementation for touchscreen gestures. Change-Id: Iabeee255748fc92376bc861409a7074de570cb0c --- api/cm_current.txt | 12 +++ .../platform/internal/CMHardwareService.java | 38 +++++++++ .../hardware/CMHardwareManager.java | 34 ++++++++ .../hardware/ICMHardwareService.aidl | 4 + .../hardware/TouchscreenGesture.aidl | 20 +++++ .../hardware/TouchscreenGesture.java | 78 +++++++++++++++++++ 6 files changed, 186 insertions(+) create mode 100644 sdk/src/java/cyanogenmod/hardware/TouchscreenGesture.aidl create mode 100644 sdk/src/java/cyanogenmod/hardware/TouchscreenGesture.java diff --git a/api/cm_current.txt b/api/cm_current.txt index 7816cec8..cebb1cb3 100644 --- a/api/cm_current.txt +++ b/api/cm_current.txt @@ -464,6 +464,7 @@ package cyanogenmod.hardware { method public deprecated int getDisplayGammaCalibrationMax(); method public deprecated int getDisplayGammaCalibrationMin(); method public cyanogenmod.hardware.DisplayMode[] getDisplayModes(); + method public cyanogenmod.hardware.TouchscreenGesture[] getTouchscreenGestures(); method public static cyanogenmod.hardware.CMHardwareManager getInstance(android.content.Context); method public java.lang.String getLtoDestination(); method public long getLtoDownloadInterval(); @@ -493,6 +494,7 @@ package cyanogenmod.hardware { method public deprecated boolean setDisplayGammaCalibration(int, int[]); method public boolean setDisplayMode(cyanogenmod.hardware.DisplayMode, boolean); method public boolean setPictureAdjustment(cyanogenmod.hardware.HSIC); + method public boolean setTouchscreenGestureEnabled(cyanogenmod.hardware.TouchscreenGesture, boolean); method public boolean setVibratorIntensity(int); method public boolean unRegisterThermalListener(cyanogenmod.hardware.ThermalListenerCallback); method public boolean writePersistentBytes(java.lang.String, byte[]); @@ -515,6 +517,7 @@ package cyanogenmod.hardware { field public static final deprecated int FEATURE_TAP_TO_WAKE = 512; // 0x200 field public static final int FEATURE_THERMAL_MONITOR = 32768; // 0x8000 field public static final int FEATURE_TOUCH_HOVERING = 2048; // 0x800 + field public static final int FEATURE_TOUCHSCREEN_GESTURES = 524288; // 0x80000 field public static final int FEATURE_UNIQUE_DEVICE_ID = 65536; // 0x10000 field public static final int FEATURE_VIBRATOR = 1024; // 0x400 } @@ -543,6 +546,15 @@ package cyanogenmod.hardware { method public void writeToParcel(android.os.Parcel, int); } + public class TouchscreenGesture implements android.os.Parcelable { + ctor public TouchscreenGesture(int, java.lang.String, int); + method public int describeContents(); + method public void writeToParcel(android.os.Parcel, int); + field public final int id; + field public final java.lang.String name; + field public final int keycode; + } + public abstract interface IThermalListenerCallback implements android.os.IInterface { method public abstract void onThermalChanged(int) throws android.os.RemoteException; } diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java index 41e7fbb5..567c94d8 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 The CyanogenMod Project + * 2017 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +35,7 @@ import cyanogenmod.hardware.DisplayMode; import cyanogenmod.hardware.IThermalListenerCallback; import cyanogenmod.hardware.ThermalListenerCallback; import cyanogenmod.hardware.HSIC; +import cyanogenmod.hardware.TouchscreenGesture; import java.io.File; import java.util.ArrayList; @@ -56,6 +58,7 @@ import org.cyanogenmod.hardware.SerialNumber; import org.cyanogenmod.hardware.SunlightEnhancement; import org.cyanogenmod.hardware.ThermalMonitor; import org.cyanogenmod.hardware.ThermalUpdateCallback; +import org.cyanogenmod.hardware.TouchscreenGestures; import org.cyanogenmod.hardware.TouchscreenHovering; import org.cyanogenmod.hardware.UniqueDeviceId; import org.cyanogenmod.hardware.VibratorHW; @@ -117,6 +120,9 @@ public class CMHardwareService extends CMSystemService implements ThermalUpdateC public HSIC getDefaultPictureAdjustment(); public boolean setPictureAdjustment(HSIC hsic); public List> getPictureAdjustmentRanges(); + + public TouchscreenGesture[] getTouchscreenGestures(); + public boolean setTouchscreenGestureEnabled(TouchscreenGesture gesture, boolean state); } private class LegacyCMHardware implements CMHardwareInterface { @@ -160,6 +166,8 @@ public class CMHardwareService extends CMSystemService implements ThermalUpdateC mSupportedFeatures |= CMHardwareManager.FEATURE_COLOR_BALANCE; if (PictureAdjustment.isSupported()) mSupportedFeatures |= CMHardwareManager.FEATURE_PICTURE_ADJUSTMENT; + if (TouchscreenGestures.isSupported()) + mSupportedFeatures |= CMHardwareManager.FEATURE_TOUCHSCREEN_GESTURES; } public int getSupportedFeatures() { @@ -384,6 +392,14 @@ public class CMHardwareService extends CMSystemService implements ThermalUpdateC PictureAdjustment.getContrastRange(), PictureAdjustment.getSaturationThresholdRange()); } + + public TouchscreenGesture[] getTouchscreenGestures() { + return TouchscreenGestures.getAvailableGestures(); + } + + public boolean setTouchscreenGestureEnabled(TouchscreenGesture gesture, boolean state) { + return TouchscreenGestures.setGestureEnabled(gesture, state); + } } private CMHardwareInterface getImpl(Context context) { @@ -860,5 +876,27 @@ public class CMHardwareService extends CMSystemService implements ThermalUpdateC } return new float[10]; } + + @Override + public TouchscreenGesture[] getTouchscreenGestures() { + mContext.enforceCallingOrSelfPermission( + cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null); + if (!isSupported(CMHardwareManager.FEATURE_TOUCHSCREEN_GESTURES)) { + Log.e(TAG, "Touchscreen gestures are not supported"); + return null; + } + return mCmHwImpl.getTouchscreenGestures(); + } + + @Override + public boolean setTouchscreenGestureEnabled(TouchscreenGesture gesture, boolean state) { + mContext.enforceCallingOrSelfPermission( + cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null); + if (!isSupported(CMHardwareManager.FEATURE_TOUCHSCREEN_GESTURES)) { + Log.e(TAG, "Touchscreen gestures are not supported"); + return false; + } + return mCmHwImpl.setTouchscreenGestureEnabled(gesture, state); + } }; } diff --git a/sdk/src/java/cyanogenmod/hardware/CMHardwareManager.java b/sdk/src/java/cyanogenmod/hardware/CMHardwareManager.java index 212e4d0c..279d07fe 100644 --- a/sdk/src/java/cyanogenmod/hardware/CMHardwareManager.java +++ b/sdk/src/java/cyanogenmod/hardware/CMHardwareManager.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 The CyanogenMod Project + * 2017 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -172,6 +173,12 @@ public final class CMHardwareManager { @VisibleForTesting public static final int FEATURE_PICTURE_ADJUSTMENT = 0x40000; + /** + * Touchscreen gesture + */ + @VisibleForTesting + public static final int FEATURE_TOUCHSCREEN_GESTURES = 0x80000; + private static final List BOOLEAN_FEATURES = Arrays.asList( FEATURE_ADAPTIVE_BACKLIGHT, FEATURE_COLOR_ENHANCEMENT, @@ -1042,4 +1049,31 @@ public final class CMHardwareManager { } return false; } + + /** + * @return a list of available touchscreen gestures on the devices + */ + public TouchscreenGesture[] getTouchscreenGestures() { + try { + if (checkService()) { + return sService.getTouchscreenGestures(); + } + } catch (RemoteException e) { + } + return null; + } + + /** + * @return true if setting the activation status was successful + */ + public boolean setTouchscreenGestureEnabled( + TouchscreenGesture gesture, boolean state) { + try { + if (checkService()) { + return sService.setTouchscreenGestureEnabled(gesture, state); + } + } catch (RemoteException e) { + } + return false; + } } diff --git a/sdk/src/java/cyanogenmod/hardware/ICMHardwareService.aidl b/sdk/src/java/cyanogenmod/hardware/ICMHardwareService.aidl index 3208ddba..f8ec46d2 100644 --- a/sdk/src/java/cyanogenmod/hardware/ICMHardwareService.aidl +++ b/sdk/src/java/cyanogenmod/hardware/ICMHardwareService.aidl @@ -1,5 +1,6 @@ /** * Copyright (c) 2015, The CyanogenMod Project + * 2017 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +20,7 @@ package cyanogenmod.hardware; import cyanogenmod.hardware.DisplayMode; import cyanogenmod.hardware.HSIC; import cyanogenmod.hardware.IThermalListenerCallback; +import cyanogenmod.hardware.TouchscreenGesture; /** @hide */ interface ICMHardwareService { @@ -70,4 +72,6 @@ interface ICMHardwareService { boolean setPictureAdjustment(in HSIC hsic); float[] getPictureAdjustmentRanges(); + TouchscreenGesture[] getTouchscreenGestures(); + boolean setTouchscreenGestureEnabled(in TouchscreenGesture gesture, boolean state); } diff --git a/sdk/src/java/cyanogenmod/hardware/TouchscreenGesture.aidl b/sdk/src/java/cyanogenmod/hardware/TouchscreenGesture.aidl new file mode 100644 index 00000000..f9a7a7b4 --- /dev/null +++ b/sdk/src/java/cyanogenmod/hardware/TouchscreenGesture.aidl @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * 2017 The LineageOS 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 cyanogenmod.hardware; + +parcelable TouchscreenGesture; diff --git a/sdk/src/java/cyanogenmod/hardware/TouchscreenGesture.java b/sdk/src/java/cyanogenmod/hardware/TouchscreenGesture.java new file mode 100644 index 00000000..d9463a37 --- /dev/null +++ b/sdk/src/java/cyanogenmod/hardware/TouchscreenGesture.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * 2017 The LineageOS 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 cyanogenmod.hardware; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Touchscreen gestures API + * + * A device may implement several touchscreen gestures for use while + * the display is turned off, such as drawing alphabets and shapes. + * These gestures can be interpreted by userspace to activate certain + * actions and launch certain apps, such as to skip music tracks, + * to turn on the flashlight, or to launch the camera app. + * + * This *should always* be supported by the hardware directly. + * A lot of recent touch controllers have a firmware option for this. + * + * This API provides support for enumerating the gestures + * supported by the touchscreen. + * + * A TouchscreenGesture is referenced by it's identifier and carries an + * associated name (up to the user to translate this value). + */ +public class TouchscreenGesture implements Parcelable { + + public final int id; + public final String name; + public final int keycode; + + public TouchscreenGesture(int id, String name, int keycode) { + this.id = id; + this.name = name; + this.keycode = keycode; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + parcel.writeInt(id); + parcel.writeString(name); + parcel.writeInt(keycode); + } + + /** @hide */ + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + + public TouchscreenGesture createFromParcel(Parcel in) { + return new TouchscreenGesture(in.readInt(), in.readString(), in.readInt()); + } + + @Override + public TouchscreenGesture[] newArray(int size) { + return new TouchscreenGesture[size]; + } + }; +}