diff options
| author | Dan Pasanen <dan.pasanen@gmail.com> | 2014-09-10 09:00:43 -0500 |
|---|---|---|
| committer | invisiblek <dan.pasanen@gmail.com> | 2014-09-10 09:14:49 -0500 |
| commit | fb94531b3f5f029f3325eb79f6e48fd6bff79d80 (patch) | |
| tree | f46bfc3b1f968a62aabec28727530e801a2fc700 | |
| parent | 00c5c41c57c8fd83976e2043bcb6c5153e71626f (diff) | |
HighTouchSensitiviy: update for new api
Change-Id: I936b0cc6e7be40bfa4f9db29bd1056b46c4bb268
| -rw-r--r-- | cmhw/org/cyanogenmod/hardware/HighTouchSensitivity.java | 82 |
1 files changed, 12 insertions, 70 deletions
diff --git a/cmhw/org/cyanogenmod/hardware/HighTouchSensitivity.java b/cmhw/org/cyanogenmod/hardware/HighTouchSensitivity.java index 9dd2530..ba25129 100644 --- a/cmhw/org/cyanogenmod/hardware/HighTouchSensitivity.java +++ b/cmhw/org/cyanogenmod/hardware/HighTouchSensitivity.java @@ -17,29 +17,17 @@ package org.cyanogenmod.hardware; import org.cyanogenmod.hardware.util.FileUtils; - -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; -import java.io.IOException; - -import android.util.Log; /** * Glove mode / high touch sensitivity (on Samsung Galaxy S4) */ public class HighTouchSensitivity { - - private static String TAG = "HighTouchSensitivity"; - private static String COMMAND_PATH = "/sys/class/sec/tsp/cmd"; - private static String COMMAND_LIST_PATH = "/sys/class/sec/tsp/cmd_list"; - private static String COMMAND_RESULT_PATH = "/sys/class/sec/tsp/cmd_result"; - private static String GLOVE_MODE = "glove_mode"; - private static String GLOVE_MODE_ENABLE = GLOVE_MODE + ",1"; - private static String GLOVE_MODE_DISABLE = GLOVE_MODE + ",0"; + private static String RESULT_PATH = "/sys/class/sec/tsp/cmd_result"; + private static String GLOVE_MODE_ENABLE = "glove_mode,1"; + private static String GLOVE_MODE_DISABLE = "glove_mode,0"; private static String STATUS_OK = ":OK"; - private static Object lock; /** * Whether device supports high touch sensitivity. @@ -47,59 +35,17 @@ public class HighTouchSensitivity { * @return boolean Supported devices must return always true */ public static boolean isSupported() { - boolean supported = false; File f = new File(COMMAND_PATH); - - // Check to make sure that the kernel supports glove mode - if(f.exists()) { - BufferedReader reader = null; - try { - reader = new BufferedReader(new FileReader(COMMAND_LIST_PATH)); - String currentLine; - while ((currentLine = reader.readLine()) != null) { - if (currentLine.equals(GLOVE_MODE)) { - supported = true; - break; - } - } - } catch (IOException e) { - } finally { - try { - if (reader != null) { - reader.close(); - } - } catch (IOException e) { - } - } - } - - if (supported) { - Log.v(TAG, "Glove mode / high touch sensitivity is supported"); - } else { - Log.e(TAG, "Glove mode / high touch sensitivity is NOT supported"); - } - - return supported; + return f.exists(); } - /* The kernel does not expose anything that determines whether or not glove - mode is enabled, so we'll let Settings.apk keep track of the state - (kernel boots with glove mode disabled) */ - - /* Synchronized because the result needs to be checked (not sure if anything - * else writes to that sysfs command path though...) */ - private static synchronized boolean setAndCheckResult(String command) { - boolean status = false; - status = FileUtils.writeLine(COMMAND_PATH, command); - String result = FileUtils.readOneLine(COMMAND_RESULT_PATH); - if (result.equals(command + STATUS_OK)) { - status = true; - Log.v(TAG, "Successfully sent \"" + command + "\" to kernel"); - } else { - Log.e(TAG, "Sent \"" + command + "\" to kernel, but got back \"" - + result + "\""); - } - return status; + /** This method returns the current activation status of high touch sensitivity + * + * @return boolean Must be false if high touch sensitivity is not supported or not activated, + * or the operation failed while reading the status; true in any other case. + */ + public static boolean isEnabled() { + return FileUtils.readOneLine(RESULT_PATH).equals(GLOVE_MODE_ENABLE + STATUS_OK); } /** @@ -110,10 +56,6 @@ public class HighTouchSensitivity { * failed; true in any other case. */ public static boolean setEnabled(boolean status) { - if (status == true) { - return setAndCheckResult(GLOVE_MODE_ENABLE); - } else { - return setAndCheckResult(GLOVE_MODE_DISABLE); - } + return FileUtils.writeLine(COMMAND_PATH, (status ? GLOVE_MODE_ENABLE : GLOVE_MODE_DISABLE)); } } |
