zenfone6: Add swipeup offscreen gesture

Change-Id: I185c905548dfe9c194a7a831934323b25c36b8c2
diff --git a/DeviceParts/res/values/strings.xml b/DeviceParts/res/values/strings.xml
index 490047d..80ea157 100644
--- a/DeviceParts/res/values/strings.xml
+++ b/DeviceParts/res/values/strings.xml
@@ -78,4 +78,6 @@
     <string name="pocket_check_title">Pocket</string>
     <string name="ambient_display_enable">Ambient display must be enabled in display settings</string>
     <string name="wake_entry">Wakeup</string>
+    <string name="swipe_up_to_wake_up_title">Swipe up to wake up</string>
+    <string name="swipe_up_to_wake_up_summary">Swipe up on the screen to wake up your device from idle mode</string>
 </resources>
diff --git a/DeviceParts/res/xml/gesture_settings.xml b/DeviceParts/res/xml/gesture_settings.xml
index ace04c7..910ca57 100644
--- a/DeviceParts/res/xml/gesture_settings.xml
+++ b/DeviceParts/res/xml/gesture_settings.xml
@@ -44,6 +44,12 @@
     <PreferenceCategory
         android:title="@string/offscreen_gesture_title">
 
+        <SwitchPreference
+            android:key="swipeup"
+            android:title="@string/swipe_up_to_wake_up_title"
+            android:summary="@string/swipe_up_to_wake_up_summary"
+            android:persistent="false" />
+
         <org.omnirom.device.AppSelectListPreference
             android:key="c_gesture_app"
             android:title="@string/category_c_gesture"
diff --git a/DeviceParts/src/org/omnirom/device/GestureSettings.java b/DeviceParts/src/org/omnirom/device/GestureSettings.java
index 7977a99..64cd037 100644
--- a/DeviceParts/src/org/omnirom/device/GestureSettings.java
+++ b/DeviceParts/src/org/omnirom/device/GestureSettings.java
@@ -55,6 +55,10 @@
 
     public static final String KEY_PROXI_SWITCH = "proxi";
     public static final String KEY_OFF_SCREEN_GESTURE_FEEDBACK_SWITCH = "off_screen_gesture_feedback";
+    public static final String KEY_SWIPEUP_SWITCH = "swipeup";
+    public static final String KEY_SETTINGS_SWIPEUP_PREFIX = "gesture_setting_";
+
+    public static final String SETTINGS_GESTURE_KEY = KEY_SETTINGS_SWIPEUP_PREFIX + KEY_SWIPEUP_SWITCH;
 
     public static final int KEY_C_ID = 0;
     public static final int KEY_E_ID = 1;
@@ -83,6 +87,7 @@
     public static final String DEVICE_GESTURE_MAPPING_6 = "device_gesture_mapping_6_0";
 
     private TwoStatePreference mProxiSwitch;
+    private TwoStatePreference mSwipeUpSwitch;
     private AppSelectListPreference mFPLongPressApp;
     private AppSelectListPreference mLetterCGesture;
     private AppSelectListPreference mLetterEGesture;
@@ -92,6 +97,7 @@
     private AppSelectListPreference mLetterZGesture;
 
     public static final String GESTURE_CONTROL_PATH = "/sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/fts_gesture_mode";
+    private static final String SWIPEUP_PATH = "/sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/swipeup_mode";
 
     private PreferenceCategory fpGestures;
     private boolean mFpDownSwipe;
@@ -149,6 +155,10 @@
         mLetterZGesture.setValue(value);
         mLetterZGesture.setOnPreferenceChangeListener(this);
 
+        mSwipeUpSwitch = (TwoStatePreference) findPreference(KEY_SWIPEUP_SWITCH);
+        mSwipeUpSwitch.setChecked(Settings.System.getInt(getContext().getContentResolver(),
+        SETTINGS_GESTURE_KEY, 1) != 0);
+
         new FetchPackageInformationTask().execute();
     }
 
@@ -164,6 +174,11 @@
                     Settings.System.OMNI_DEVICE_PROXI_CHECK_ENABLED, mProxiSwitch.isChecked() ? 1 : 0);
             return true;
         }
+        if (preference == mSwipeUpSwitch) {
+            Settings.System.putInt(getContext().getContentResolver(), SETTINGS_GESTURE_KEY, mSwipeUpSwitch.isChecked() ? 1 : 0);
+            Utils.writeValue(getFile(), mSwipeUpSwitch.isChecked() ? "1" : "0");
+            return true;
+        }
         return super.onPreferenceTreeClick(preference);
     }
 
@@ -206,10 +221,19 @@
         return true;
     }
 
+    public static String getFile() {
+        if (Utils.fileWritable(SWIPEUP_PATH)) {
+            return SWIPEUP_PATH;
+        }
+        return null;
+    }
+
     public static String getGestureFile(String key) {
         switch(key) {
             case GESTURE_CONTROL_PATH:
                 return "/sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/fts_gesture_mode";
+            case SWIPEUP_PATH:
+                return "/sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/swipeup_mode";
         }
         return null;
     }
diff --git a/DeviceParts/src/org/omnirom/device/KeyHandler.java b/DeviceParts/src/org/omnirom/device/KeyHandler.java
index b8a623a..ee85805 100644
--- a/DeviceParts/src/org/omnirom/device/KeyHandler.java
+++ b/DeviceParts/src/org/omnirom/device/KeyHandler.java
@@ -87,6 +87,7 @@
     private static final int KEY_GESTURE_V = 47;
     private static final int KEY_GESTURE_W = 17;
     private static final int KEY_GESTURE_Z = 44;
+    private static final int KEY_SWIPEUP_GESTURE = 103;
 
     private static final int MIN_PULSE_INTERVAL_MS = 2500;
     private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
@@ -326,6 +327,9 @@
         if (event.getAction() != KeyEvent.ACTION_UP) {
             return false;
         }
+        if (event.getScanCode() == KEY_SWIPEUP_GESTURE) {
+            return true;
+        }
          String value = getGestureValueForScanCode(event.getScanCode());
         if (!TextUtils.isEmpty(value) && value.equals(AppSelectListPreference.WAKE_ENTRY)) {
             if (DEBUG) Log.i(TAG, "isWakeEvent " + event.getScanCode() + value);
diff --git a/DeviceParts/src/org/omnirom/device/Startup.java b/DeviceParts/src/org/omnirom/device/Startup.java
index fc66c03..a13121d 100644
--- a/DeviceParts/src/org/omnirom/device/Startup.java
+++ b/DeviceParts/src/org/omnirom/device/Startup.java
@@ -94,6 +94,9 @@
         value = Settings.System.getString(context.getContentResolver(), Settings.System.OMNI_BUTTON_EXTRA_KEY_MAPPING);
         restore(getGestureFile(GestureSettings.GESTURE_CONTROL_PATH), value);
 
+        enabled = Settings.System.getInt(context.getContentResolver(), GestureSettings.SETTINGS_GESTURE_KEY, 0) != 0;
+        restore(GestureSettings.getFile(), enabled);
+
         enabled = Settings.System.getInt(context.getContentResolver(), GloveModeSwitch.SETTINGS_KEY, 0) != 0;
         restore(GloveModeSwitch.getFile(), enabled);
     }
diff --git a/keylayout/fts_ts.kl b/keylayout/fts_ts.kl
index c366d5e..2c22921 100644
--- a/keylayout/fts_ts.kl
+++ b/keylayout/fts_ts.kl
@@ -1,5 +1,5 @@
 #key 116    GESTURE_DOUBLE_CLICK          WAKE    VIRTUAL
-#key 103    GESTURE_SWIPE_UP          WAKE    VIRTUAL
+key 103    GESTURE_SWIPE_UP          WAKE    VIRTUAL
 key 158    BACK               VIRTUAL
 #key 139    APP_SWITCH         VIRTUAL
 key 102    HOME               VIRTUAL
diff --git a/prebuilt/system/etc/init/init.qcom.rc b/prebuilt/system/etc/init/init.qcom.rc
index a713d78..547e663 100644
--- a/prebuilt/system/etc/init/init.qcom.rc
+++ b/prebuilt/system/etc/init/init.qcom.rc
@@ -11,6 +11,9 @@
     chmod 0660 /sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/fts_gesture_mode
     chown system system /sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/dclick_mode
     chmod 0660 /sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/dclick_mode
+    chown system system /sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/swipeup_mode
+    chmod 0660 /sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/swipeup_mode
+
     chown system system /sys/devices/platform/soc/soc:goodixfp/proximity_state
     chmod 0660 /sys/devices/platform/soc/soc:goodixfp/proximity_state
 
diff --git a/sepolicy/private/file_contexts b/sepolicy/private/file_contexts
index eed95a4..ef2e277 100644
--- a/sepolicy/private/file_contexts
+++ b/sepolicy/private/file_contexts
@@ -14,6 +14,7 @@
 # Gestures
 /sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/fts_glove_mode        u:object_r:sysfs_gesture:s0
 /sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/fts_gesture_mode      u:object_r:sysfs_gesture:s0
+/sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/swipeup_mode          u:object_r:sysfs_gesture:s0
 
 # Modules
 /system/lib/modules/wlan\.ko                  u:object_r:vendor_file:s0