zenfone6: DeviceParts: add Glove Mode
diff --git a/DeviceParts/AndroidManifest.xml b/DeviceParts/AndroidManifest.xml
index c54d9d4..9200e21 100644
--- a/DeviceParts/AndroidManifest.xml
+++ b/DeviceParts/AndroidManifest.xml
@@ -74,5 +74,15 @@
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
             </intent-filter>
         </receiver>
+        <service
+            android:name="org.omnirom.device.GloveModeTileService"
+            android:icon="@drawable/ic_hbm_tile"
+            android:label="@string/tile_glove_mode"
+            android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
+            <intent-filter>
+                <action
+                    android:name="android.service.quicksettings.action.QS_TILE"/>
+            </intent-filter>
+        </service>
     </application>
 </manifest>
diff --git a/DeviceParts/res/values/strings.xml b/DeviceParts/res/values/strings.xml
index f64967c..5322ecb 100644
--- a/DeviceParts/res/values/strings.xml
+++ b/DeviceParts/res/values/strings.xml
@@ -28,8 +28,11 @@
     <string name="swap_back_recents_summary"></string>
     <string name="swap_back_recents_title">Swap back and recents button</string>
     <string name="graphics_title">Graphics</string>
+    <string name="screen_title">Screen Sensitivity</string>
     <string name="srgb_mode_summary"></string>
     <string name="srgb_mode_title">sRGB mode</string>
+    <string name="glove_mode_summary"></string>
+    <string name="glove_mode_title">High Touch Sensitivity</string>
     <string name="hbm_mode_summary"></string>
     <string name="hbm_mode_title">High brightness mode</string>
     <string name="adaptive_mode_title">Adaptive mode</string>
@@ -110,6 +113,7 @@
     <string name="panel_category_title">Panel modes</string>
     <string name="panel_category_summary">Modes for panel color correction</string>
     <string name="off_mode_title">Off</string>
+    <string name="tile_glove_mode">High Touch Sensitivity</string>
     <string name="tile_panel_mode">Panel modes</string>
     <string name="tile_hbm_mode">High brightness modes</string>
     <string name="wake_entry">Wakeup</string>
diff --git a/DeviceParts/res/xml/main.xml b/DeviceParts/res/xml/main.xml
index 58377c4..8d41c3f 100644
--- a/DeviceParts/res/xml/main.xml
+++ b/DeviceParts/res/xml/main.xml
@@ -34,4 +34,14 @@
                 android:targetClass="org.omnirom.device.DozeSettingsActivity" />
     </Preference>
 
+    <PreferenceCategory
+        android:key="screen"
+        android:title="@string/screen_title">
+        <SwitchPreference
+            android:key="glove"
+            android:summary="@string/glove_mode_summary"
+            android:title="@string/glove_mode_title"
+            android:persistent="false" />
+    </PreferenceCategory>
+
 </PreferenceScreen>
diff --git a/DeviceParts/src/org/omnirom/device/DeviceSettings.java b/DeviceParts/src/org/omnirom/device/DeviceSettings.java
index e14b291..5b6ea93 100644
--- a/DeviceParts/src/org/omnirom/device/DeviceSettings.java
+++ b/DeviceParts/src/org/omnirom/device/DeviceSettings.java
@@ -43,11 +43,20 @@
     public static final String SLIDER_DEFAULT_VALUE = "2,1,0";
 
     public static final String KEY_SETTINGS_PREFIX = "device_setting_";
+    public static final String KEY_GLOVE_SWITCH = "glove";
+
+    private static final String KEY_CATEGORY_SCREEN = "screen";
+    private static TwoStatePreference mGloveModeSwitch;
 
     @Override
     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
         setPreferencesFromResource(R.xml.main, rootKey);
 
+        mGloveModeSwitch = (TwoStatePreference) findPreference(KEY_GLOVE_SWITCH);
+        mGloveModeSwitch.setEnabled(GloveModeSwitch.isSupported());
+        mGloveModeSwitch.setChecked(GloveModeSwitch.isCurrentlyEnabled(this.getContext()));
+        mGloveModeSwitch.setOnPreferenceChangeListener(new GloveModeSwitch(getContext()));
+
     }
 
     @Override
diff --git a/DeviceParts/src/org/omnirom/device/GloveModeSwitch.java b/DeviceParts/src/org/omnirom/device/GloveModeSwitch.java
new file mode 100644
index 0000000..30b4dcc
--- /dev/null
+++ b/DeviceParts/src/org/omnirom/device/GloveModeSwitch.java
@@ -0,0 +1,63 @@
+/*
+* Copyright (C) 2016 The OmniROM Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+package org.omnirom.device;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.Preference.OnPreferenceChangeListener;
+import android.support.v7.preference.PreferenceManager;
+
+import org.omnirom.device.DeviceSettings;
+
+public class GloveModeSwitch implements OnPreferenceChangeListener {
+
+    private static final String FILE = "/sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/fts_glove_mode";
+
+    public static final String SETTINGS_KEY = DeviceSettings.KEY_SETTINGS_PREFIX + DeviceSettings.KEY_GLOVE_SWITCH;
+
+    private Context mContext;
+
+    public GloveModeSwitch(Context context) {
+        mContext = context;
+    }
+
+    public static String getFile() {
+        if (Utils.fileWritable(FILE)) {
+            return FILE;
+        }
+        return null;
+    }
+
+    public static boolean isSupported() {
+        return Utils.fileWritable(getFile());
+    }
+
+    public static boolean isCurrentlyEnabled(Context context) {
+        return Utils.getFileValueAsBoolean(getFile(), false);
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        Boolean enabled = (Boolean) newValue;
+        Settings.System.putInt(mContext.getContentResolver(), SETTINGS_KEY, enabled ? 1 : 0);
+        Utils.writeValue(getFile(), enabled ? "1" : "0");
+        return true;
+    }
+}
\ No newline at end of file
diff --git a/DeviceParts/src/org/omnirom/device/GloveModeTileService.java b/DeviceParts/src/org/omnirom/device/GloveModeTileService.java
new file mode 100644
index 0000000..85e79f7
--- /dev/null
+++ b/DeviceParts/src/org/omnirom/device/GloveModeTileService.java
@@ -0,0 +1,62 @@
+/*
+* Copyright (C) 2018 The OmniROM Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+package org.omnirom.device;
+
+import android.annotation.TargetApi;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.service.quicksettings.TileService;
+import android.support.v7.preference.PreferenceManager;
+
+
+@TargetApi(24)
+public class GloveModeTileService extends TileService {
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+    }
+
+    @Override
+    public void onTileAdded() {
+        super.onTileAdded();
+    }
+
+    @Override
+    public void onTileRemoved() {
+        super.onTileRemoved();
+    }
+
+    @Override
+    public void onStartListening() {
+        super.onStartListening();
+    }
+
+    @Override
+    public void onStopListening() {
+        super.onStopListening();
+    }
+
+    @Override
+    public void onClick() {
+        super.onClick();
+        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
+        final boolean enabled = GloveModeSwitch.isCurrentlyEnabled(this);
+        Utils.writeValue(GloveModeSwitch.getFile(), enabled ? "0" : "1");
+        sharedPrefs.edit().putBoolean(DeviceSettings.KEY_GLOVE_SWITCH, enabled ? false : true).commit();
+    }
+}
diff --git a/DeviceParts/src/org/omnirom/device/Startup.java b/DeviceParts/src/org/omnirom/device/Startup.java
index b853564..c43c772 100644
--- a/DeviceParts/src/org/omnirom/device/Startup.java
+++ b/DeviceParts/src/org/omnirom/device/Startup.java
@@ -47,6 +47,10 @@
     private void maybeImportOldSettings(Context context) {
         boolean imported = Settings.System.getInt(context.getContentResolver(), "omni_device_setting_imported", 0) != 0;
         if (!imported) {
+            SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+            boolean enabled = sharedPrefs.getBoolean(DeviceSettings.KEY_GLOVE_SWITCH, false);
+            Settings.System.putInt(context.getContentResolver(), GloveModeSwitch.SETTINGS_KEY, enabled ? 1 : 0);
+
             Settings.System.putInt(context.getContentResolver(), "omni_device_setting_imported", 1);
         }
     }
@@ -142,5 +146,8 @@
         value = Settings.System.getString(context.getContentResolver(), GestureSettings.DEVICE_GESTURE_MAPPING_10);
         enabled = !TextUtils.isEmpty(value) && !value.equals(AppSelectListPreference.DISABLED_ENTRY);
         restore(getGestureFile(GestureSettings.FP_GESTURE_LONG_PRESS_APP), enabled);
+
+        enabled = Settings.System.getInt(context.getContentResolver(), GloveModeSwitch.SETTINGS_KEY, 0) != 0;
+        restore(GloveModeSwitch.getFile(), enabled);
     }
 }
diff --git a/prebuilt/system/etc/init/init.qcom.rc b/prebuilt/system/etc/init/init.qcom.rc
index dfc506a..fc72b28 100644
--- a/prebuilt/system/etc/init/init.qcom.rc
+++ b/prebuilt/system/etc/init/init.qcom.rc
@@ -44,3 +44,7 @@
 
     chown system system /sys/devices/platform/soc/soc:goodixfp/proximity_state
     chmod 0660 /sys/devices/platform/soc/soc:goodixfp/proximity_state
+
+    # Screen Touch
+    chown system system /sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/fts_glove_mode
+    chmod 0660 /sys/devices/platform/soc/c80000.i2c/i2c-4/4-0038/fts_glove_mode