zenfone6: Enable Smart Key for Google Assistant
Change-Id: I485eb8db3e1a148afea2f939c88d81c22eb11f42
diff --git a/DeviceParts/res/values/strings.xml b/DeviceParts/res/values/strings.xml
index 80ea157..88c0bf7 100644
--- a/DeviceParts/res/values/strings.xml
+++ b/DeviceParts/res/values/strings.xml
@@ -28,6 +28,9 @@
<string name="glove_mode_title">Glove mode</string>
<string name="proxi_summary_head">Check proximity sensor for handling fingerprint sensor</string>
<string name="proxi_title_head">Proximity check</string>
+ <string name="smart_google">Smart key</string>
+ <string name="smart_key_title">Google Assistant</string>
+ <string name="smart_key_summary">Call Google Assistant</string>
<string name="choose_app">Choose app</string>
<string name="offscreen_gesture_title">Offscreen gestures</string>
diff --git a/DeviceParts/res/xml/main.xml b/DeviceParts/res/xml/main.xml
index 8d41c3f..ace376a 100644
--- a/DeviceParts/res/xml/main.xml
+++ b/DeviceParts/res/xml/main.xml
@@ -44,4 +44,14 @@
android:persistent="false" />
</PreferenceCategory>
+ <PreferenceCategory
+ android:key="smartkey"
+ android:title="@string/smart_google">
+ <SwitchPreference
+ android:key="smart_switch"
+ android:summary="@string/smart_key_summary"
+ android:title="@string/smart_key_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 5b6ea93..771904b 100644
--- a/DeviceParts/src/org/omnirom/device/DeviceSettings.java
+++ b/DeviceParts/src/org/omnirom/device/DeviceSettings.java
@@ -44,9 +44,13 @@
public static final String KEY_SETTINGS_PREFIX = "device_setting_";
public static final String KEY_GLOVE_SWITCH = "glove";
+ public static final String KEY_SMART_SWITCH = "smart_switch";
+ public static final String KEY_SMART_PATH = "/sys/devices/platform/soc/soc:asustek_googlekey/googlekey_enable";
+ public static final String SETTINGS_SMART_KEY = KEY_SETTINGS_PREFIX + KEY_SMART_SWITCH;
private static final String KEY_CATEGORY_SCREEN = "screen";
private static TwoStatePreference mGloveModeSwitch;
+ private static TwoStatePreference mSmartKeySwitch;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@@ -57,10 +61,19 @@
mGloveModeSwitch.setChecked(GloveModeSwitch.isCurrentlyEnabled(this.getContext()));
mGloveModeSwitch.setOnPreferenceChangeListener(new GloveModeSwitch(getContext()));
+ mSmartKeySwitch = (TwoStatePreference) findPreference(KEY_SMART_SWITCH);
+ mSmartKeySwitch.setChecked(Settings.System.getInt(getContext().getContentResolver(),
+ SETTINGS_SMART_KEY, 1) != 0);
+
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
+ if (preference == mSmartKeySwitch) {
+ Settings.System.putInt(getContext().getContentResolver(), SETTINGS_SMART_KEY, mSmartKeySwitch.isChecked() ? 1 : 0);
+ Utils.writeValue(getFile(), mSmartKeySwitch.isChecked() ? "1" : "0");
+ return true;
+ }
return super.onPreferenceTreeClick(preference);
}
@@ -68,4 +81,19 @@
public boolean onPreferenceChange(Preference preference, Object newValue) {
return true;
}
+
+ public static String getFile() {
+ if (Utils.fileWritable(KEY_SMART_PATH)) {
+ return KEY_SMART_PATH;
+ }
+ return null;
+ }
+
+ public static String getGestureFile(String key) {
+ switch(key) {
+ case KEY_SMART_PATH:
+ return "/sys/devices/platform/soc/soc:asustek_googlekey/googlekey_enable";
+ }
+ return null;
+ }
}
diff --git a/DeviceParts/src/org/omnirom/device/Startup.java b/DeviceParts/src/org/omnirom/device/Startup.java
index a13121d..11a5ade 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(), DeviceSettings.SETTINGS_SMART_KEY, 0) != 0;
+ restore(DeviceSettings.getFile(), enabled);
+
enabled = Settings.System.getInt(context.getContentResolver(), GestureSettings.SETTINGS_GESTURE_KEY, 0) != 0;
restore(GestureSettings.getFile(), enabled);
diff --git a/prebuilt/system/etc/init/init.qcom.rc b/prebuilt/system/etc/init/init.qcom.rc
index 547e663..a99b823 100644
--- a/prebuilt/system/etc/init/init.qcom.rc
+++ b/prebuilt/system/etc/init/init.qcom.rc
@@ -20,3 +20,7 @@
# 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
+
+ # Smart Key
+ chown system system /sys/devices/platform/soc/soc:asustek_googlekey/googlekey_enable
+ chmod 0660 /sys/devices/platform/soc/soc:asustek_googlekey/googlekey_enable
diff --git a/sepolicy/private/file_contexts b/sepolicy/private/file_contexts
index 808c82e..dd3fd11 100644
--- a/sepolicy/private/file_contexts
+++ b/sepolicy/private/file_contexts
@@ -15,6 +15,7 @@
/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
+/sys/devices/platform/soc/soc:asustek_googlekey/googlekey_enable u:object_r:sysfs_gesture:s0
# Modules
/system/lib/modules/wlan\.ko u:object_r:vendor_file:s0