summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhao Wei Liew <zhaoweiliew@gmail.com>2016-06-29 20:21:59 +0800
committerZhao Wei Liew <zhaoweiliew@gmail.com>2016-07-02 13:02:54 +0800
commit1da88e6e9f14fa77d912c8fa6540bc8888cfde25 (patch)
treee2bb36db1197c185e73c46345bbfb07a508f7fca
parent9dad4fe88897cd01a64c793a4081576d7396bce7 (diff)
downloadandroid_hardware_samsung-1da88e6e9f14fa77d912c8fa6540bc8888cfde25.tar.gz
android_hardware_samsung-1da88e6e9f14fa77d912c8fa6540bc8888cfde25.tar.bz2
android_hardware_samsung-1da88e6e9f14fa77d912c8fa6540bc8888cfde25.zip
hardware: Clean up CMHW and AdvancedDisplay
- Use CMSDK FileUtils - Simplify, yet harden checks - Use static final Strings - Remove unnecessary imports - Remove unnecessary Strings - Update copyright Change-Id: Id2f0f2fdf5be7e2b29a3910a6aa56a3aad10868f
-rw-r--r--AdvancedDisplay/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java5
-rw-r--r--AdvancedDisplay/src/com/cyanogenmod/settings/device/Utils.java83
-rw-r--r--AdvancedDisplay/src/com/cyanogenmod/settings/device/mDNIeNegative.java8
-rw-r--r--AdvancedDisplay/src/com/cyanogenmod/settings/device/mDNIeScenario.java8
-rw-r--r--cmhw/org/cyanogenmod/hardware/AdaptiveBacklight.java26
-rw-r--r--cmhw/org/cyanogenmod/hardware/HighTouchSensitivity.java67
-rw-r--r--cmhw/org/cyanogenmod/hardware/SunlightEnhancement.java17
-rw-r--r--cmhw/org/cyanogenmod/hardware/TouchscreenHovering.java71
-rw-r--r--cmhw/org/cyanogenmod/hardware/VibratorHW.java80
9 files changed, 134 insertions, 231 deletions
diff --git a/AdvancedDisplay/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java b/AdvancedDisplay/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java
index 7b64a4f..8ecb593 100644
--- a/AdvancedDisplay/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java
+++ b/AdvancedDisplay/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java
@@ -31,6 +31,7 @@ import android.preference.PreferenceScreen;
import android.util.Log;
import com.cyanogenmod.settings.device.R;
+import org.cyanogenmod.internal.util.FileUtils;
public class ScreenFragmentActivity extends PreferenceFragment {
@@ -69,8 +70,8 @@ public class ScreenFragmentActivity extends PreferenceFragment {
return true;
}
- public static boolean isSupported(String FILE) {
- return Utils.fileExists(FILE);
+ public static boolean isSupported(String filePath) {
+ return FileUtils.isFileWritable(filePath);
}
public static void restore(Context context) {
diff --git a/AdvancedDisplay/src/com/cyanogenmod/settings/device/Utils.java b/AdvancedDisplay/src/com/cyanogenmod/settings/device/Utils.java
deleted file mode 100644
index 552ece5..0000000
--- a/AdvancedDisplay/src/com/cyanogenmod/settings/device/Utils.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod 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 com.cyanogenmod.settings.device;
-
-import android.util.Log;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.SyncFailedException;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.content.Context;
-
-public class Utils {
-
- private static final String TAG = "DeviceSettings_Utils";
- private static final String TAG_READ = "DeviceSettings_Utils_Read";
- private static final String TAG_WRITE = "DeviceSettings_Utils_Write";
-
- /**
- * Write a string value to the specified file.
- *
- * @param filename The filename
- * @param value The value
- */
- public static void writeValue(String filename, String value) {
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(new File(filename), false);
- fos.write(value.getBytes());
- fos.flush();
- // fos.getFD().sync();
- } catch (FileNotFoundException ex) {
- Log.w(TAG, "file " + filename + " not found: " + ex);
- } catch (SyncFailedException ex) {
- Log.w(TAG, "file " + filename + " sync failed: " + ex);
- } catch (IOException ex) {
- Log.w(TAG, "IOException trying to sync " + filename + ": " + ex);
- } catch (RuntimeException ex) {
- Log.w(TAG, "exception while syncing file: ", ex);
- } finally {
- if (fos != null) {
- try {
- Log.w(TAG_WRITE, "file " + filename + ": " + value);
- fos.close();
- } catch (IOException ex) {
- Log.w(TAG, "IOException while closing synced file: ", ex);
- } catch (RuntimeException ex) {
- Log.w(TAG, "exception while closing file: ", ex);
- }
- }
- }
-
- }
-
- /**
- * Check if the specified file exists.
- * @param filename The filename
- * @return Whether the file exists or not
- */
- public static boolean fileExists(String filename) {
- return new File(filename).exists();
- }
-
-}
diff --git a/AdvancedDisplay/src/com/cyanogenmod/settings/device/mDNIeNegative.java b/AdvancedDisplay/src/com/cyanogenmod/settings/device/mDNIeNegative.java
index bde9946..a5e20f2 100644
--- a/AdvancedDisplay/src/com/cyanogenmod/settings/device/mDNIeNegative.java
+++ b/AdvancedDisplay/src/com/cyanogenmod/settings/device/mDNIeNegative.java
@@ -25,6 +25,8 @@ import android.preference.ListPreference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceManager;
+import org.cyanogenmod.internal.util.FileUtils;
+
public class mDNIeNegative extends ListPreference implements OnPreferenceChangeListener {
private static String FILE = null;
@@ -36,7 +38,7 @@ public class mDNIeNegative extends ListPreference implements OnPreferenceChangeL
}
public static boolean isSupported(String filePath) {
- return Utils.fileExists(filePath);
+ return FileUtils.isFileWritable(filePath);
}
/**
@@ -50,11 +52,11 @@ public class mDNIeNegative extends ListPreference implements OnPreferenceChangeL
}
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
- Utils.writeValue(FILE, sharedPrefs.getString(DisplaySettings.KEY_MDNIE_NEGATIVE, "0"));
+ FileUtils.writeLine(FILE, sharedPrefs.getString(DisplaySettings.KEY_MDNIE_NEGATIVE, "0"));
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
- Utils.writeValue(FILE, (String) newValue);
+ FileUtils.writeLine(FILE, (String) newValue);
return true;
}
diff --git a/AdvancedDisplay/src/com/cyanogenmod/settings/device/mDNIeScenario.java b/AdvancedDisplay/src/com/cyanogenmod/settings/device/mDNIeScenario.java
index cbab69d..5d33fe9 100644
--- a/AdvancedDisplay/src/com/cyanogenmod/settings/device/mDNIeScenario.java
+++ b/AdvancedDisplay/src/com/cyanogenmod/settings/device/mDNIeScenario.java
@@ -25,6 +25,8 @@ import android.preference.ListPreference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceManager;
+import org.cyanogenmod.internal.util.FileUtils;
+
public class mDNIeScenario extends ListPreference implements OnPreferenceChangeListener {
private static String FILE = null;
@@ -36,7 +38,7 @@ public class mDNIeScenario extends ListPreference implements OnPreferenceChangeL
}
public static boolean isSupported(String filePath) {
- return Utils.fileExists(filePath);
+ return FileUtils.isFileWritable(filePath);
}
/**
@@ -50,11 +52,11 @@ public class mDNIeScenario extends ListPreference implements OnPreferenceChangeL
}
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
- Utils.writeValue(FILE, sharedPrefs.getString(DisplaySettings.KEY_MDNIE_SCENARIO, "0"));
+ FileUtils.writeLine(FILE, sharedPrefs.getString(DisplaySettings.KEY_MDNIE_SCENARIO, "0"));
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
- Utils.writeValue(FILE, (String) newValue);
+ FileUtils.writeLine(FILE, (String) newValue);
return true;
}
diff --git a/cmhw/org/cyanogenmod/hardware/AdaptiveBacklight.java b/cmhw/org/cyanogenmod/hardware/AdaptiveBacklight.java
index 10f7d20..16a3748 100644
--- a/cmhw/org/cyanogenmod/hardware/AdaptiveBacklight.java
+++ b/cmhw/org/cyanogenmod/hardware/AdaptiveBacklight.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 The CyanogenMod Project
+ * Copyright (C) 2013-2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,9 @@
package org.cyanogenmod.hardware;
-import org.cyanogenmod.hardware.util.FileUtils;
-
import android.os.SystemProperties;
-import android.text.TextUtils;
-import java.io.File;
+import org.cyanogenmod.internal.util.FileUtils;
/**
* Adaptive backlight support (this refers to technologies like NVIDIA SmartDimmer,
@@ -29,7 +26,8 @@ import java.io.File;
*/
public class AdaptiveBacklight {
- private static String FILE_CABC = SystemProperties.get("ro.cm.hardware.cabc", "/sys/class/lcd/panel/power_reduce");
+ private static final String FILE_CABC = SystemProperties.get(
+ "ro.cm.hardware.cabc", "/sys/class/lcd/panel/power_reduce");
/**
* Whether device supports an adaptive backlight technology.
@@ -37,8 +35,8 @@ public class AdaptiveBacklight {
* @return boolean Supported devices must return always true
*/
public static boolean isSupported() {
- File f = new File(FILE_CABC);
- return f.exists();
+ return FileUtils.isFileWritable(FILE_CABC) &&
+ FileUtils.isFileReadable(FILE_CABC);
}
/**
@@ -48,11 +46,7 @@ public class AdaptiveBacklight {
* the operation failed while reading the status; true in any other case.
*/
public static boolean isEnabled() {
- if (TextUtils.equals(FileUtils.readOneLine(FILE_CABC), "1")) {
- return true;
- } else {
- return false;
- }
+ return "1".equals(FileUtils.readOneLine(FILE_CABC));
}
/**
@@ -63,10 +57,6 @@ public class AdaptiveBacklight {
* failed; true in any other case.
*/
public static boolean setEnabled(boolean status) {
- if (status == true) {
- return FileUtils.writeLine(FILE_CABC, "1");
- } else {
- return FileUtils.writeLine(FILE_CABC, "0");
- }
+ return FileUtils.writeLine(FILE_CABC, status ? "1" : "0");
}
}
diff --git a/cmhw/org/cyanogenmod/hardware/HighTouchSensitivity.java b/cmhw/org/cyanogenmod/hardware/HighTouchSensitivity.java
index b968be4..4e3c973 100644
--- a/cmhw/org/cyanogenmod/hardware/HighTouchSensitivity.java
+++ b/cmhw/org/cyanogenmod/hardware/HighTouchSensitivity.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 The CyanogenMod Project
+ * Copyright (C) 2014-2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,29 +16,28 @@
package org.cyanogenmod.hardware;
-import org.cyanogenmod.hardware.util.FileUtils;
+import android.util.Log;
+
+import org.cyanogenmod.internal.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
*/
public class HighTouchSensitivity {
- private static String TAG = "HighTouchSensitivity";
+ private static final 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 STATUS_OK = ":OK";
+ private static final String COMMAND_PATH = "/sys/class/sec/tsp/cmd";
+ private static final String COMMAND_LIST_PATH = "/sys/class/sec/tsp/cmd_list";
+ private static final String COMMAND_RESULT_PATH = "/sys/class/sec/tsp/cmd_result";
+ private static final String GLOVE_MODE = "glove_mode";
+ private static final String GLOVE_MODE_ENABLE = "glove_mode,1";
+ private static final String GLOVE_MODE_DISABLE = "glove_mode,0";
+ private static final String STATUS_OK = ":OK";
/**
* Whether device supports high touch sensitivity.
@@ -46,25 +45,29 @@ public class HighTouchSensitivity {
* @return boolean Supported devices must return always true
*/
public static boolean isSupported() {
- File f = new File(COMMAND_PATH);
- if (f.exists()) {
- BufferedReader reader = null;
- try {
- String currentLine;
- reader = new BufferedReader(new FileReader(COMMAND_LIST_PATH));
- while ((currentLine = reader.readLine()) != null) {
- if (GLOVE_MODE.equals(currentLine))
- return true;
+ if (!FileUtils.isFileWritable(COMMAND_PATH) ||
+ !FileUtils.isFileReadable(COMMAND_LIST_PATH) ||
+ !FileUtils.isFileReadable(COMMAND_RESULT_PATH)) {
+ return false;
+ }
+
+ BufferedReader reader = null;
+ try {
+ String currentLine;
+ reader = new BufferedReader(new FileReader(COMMAND_LIST_PATH));
+ while ((currentLine = reader.readLine()) != null) {
+ if (GLOVE_MODE.equals(currentLine)) {
+ return true;
}
- } catch (IOException e) {
- // Ignore exception, will be false anyway
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- // Ignore exception, no recovery possible
- }
+ }
+ } catch (IOException e) {
+ Log.e(TAG, "Could not read from file " + COMMAND_LIST_PATH, e);
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ // Ignore exception, no recovery possible
}
}
}
@@ -77,7 +80,7 @@ public class HighTouchSensitivity {
* or the operation failed while reading the status; true in any other case.
*/
public static boolean isEnabled() {
- return FileUtils.readOneLine(COMMAND_RESULT_PATH).equals(GLOVE_MODE_ENABLE + STATUS_OK);
+ return (GLOVE_MODE_ENABLE + STATUS_OK).equals(FileUtils.readOneLine(COMMAND_RESULT_PATH));
}
/**
diff --git a/cmhw/org/cyanogenmod/hardware/SunlightEnhancement.java b/cmhw/org/cyanogenmod/hardware/SunlightEnhancement.java
index afcf33c..8c55ca8 100644
--- a/cmhw/org/cyanogenmod/hardware/SunlightEnhancement.java
+++ b/cmhw/org/cyanogenmod/hardware/SunlightEnhancement.java
@@ -16,11 +16,9 @@
package org.cyanogenmod.hardware;
-import org.cyanogenmod.hardware.util.FileUtils;
-
import android.os.SystemProperties;
-import java.io.File;
+import org.cyanogenmod.internal.util.FileUtils;
/**
* Sunlight Readability Enhancement support, aka Facemelt Mode.
@@ -30,7 +28,8 @@ import java.io.File;
* support.
*/
public class SunlightEnhancement {
- private static final String sOutdoorModePath = "/sys/class/mdnie/mdnie/outdoor";
+
+ private static final String FILE_SRE = "/sys/class/mdnie/mdnie/outdoor";
/**
* Whether device supports SRE
@@ -38,7 +37,8 @@ public class SunlightEnhancement {
* @return boolean Supported devices must return always true
*/
public static boolean isSupported() {
- return new File(sOutdoorModePath).exists();
+ return FileUtils.isFileWritable(FILE_SRE) &&
+ FileUtils.isFileReadable(FILE_SRE);
}
/**
@@ -48,10 +48,7 @@ public class SunlightEnhancement {
* the operation failed while reading the status; true in any other case.
*/
public static boolean isEnabled() {
- String line = FileUtils.readOneLine(sOutdoorModePath);
- if (line == null)
- return false;
- return line.equals("1");
+ return "1".equals(FileUtils.readOneLine(FILE_SRE));
}
/**
@@ -62,7 +59,7 @@ public class SunlightEnhancement {
* failed; true in any other case.
*/
public static boolean setEnabled(boolean status) {
- return FileUtils.writeLine(sOutdoorModePath, status ? "1" : "0");
+ return FileUtils.writeLine(FILE_SRE, status ? "1" : "0");
}
/**
diff --git a/cmhw/org/cyanogenmod/hardware/TouchscreenHovering.java b/cmhw/org/cyanogenmod/hardware/TouchscreenHovering.java
index f6a7ee8..69e61f8 100644
--- a/cmhw/org/cyanogenmod/hardware/TouchscreenHovering.java
+++ b/cmhw/org/cyanogenmod/hardware/TouchscreenHovering.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 The CyanogenMod Project
+ * Copyright (C) 2015-2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,29 +16,28 @@
package org.cyanogenmod.hardware;
-import org.cyanogenmod.hardware.util.FileUtils;
+import android.util.Log;
+
+import org.cyanogenmod.internal.util.FileUtils;
import java.io.BufferedReader;
-import java.io.File;
import java.io.FileReader;
import java.io.IOException;
-import android.util.Log;
-
/**
* Touchscreen Hovering
*/
public class TouchscreenHovering {
- private static String TAG = "TouchscreenHovering";
+ private static final String TAG = "TouchscreenHovering";
- 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 HOVER_MODE = "hover_enable";
- private static String HOVER_MODE_ENABLE = "hover_enable,1";
- private static String HOVER_MODE_DISABLE = "hover_enable,0";
- private static String STATUS_OK = ":OK";
+ private static final String COMMAND_PATH = "/sys/class/sec/tsp/cmd";
+ private static final String COMMAND_LIST_PATH = "/sys/class/sec/tsp/cmd_list";
+ private static final String COMMAND_RESULT_PATH = "/sys/class/sec/tsp/cmd_result";
+ private static final String HOVER_MODE = "hover_enable";
+ private static final String HOVER_MODE_ENABLE = "hover_enable,1";
+ private static final String HOVER_MODE_DISABLE = "hover_enable,0";
+ private static final String STATUS_OK = ":OK";
/**
* Whether device supports touchscreen hovering.
@@ -46,25 +45,29 @@ public class TouchscreenHovering {
* @return boolean Supported devices must return always true
*/
public static boolean isSupported() {
- File f = new File(COMMAND_PATH);
- if (f.exists()) {
- BufferedReader reader = null;
- try {
- String currentLine;
- reader = new BufferedReader(new FileReader(COMMAND_LIST_PATH));
- while ((currentLine = reader.readLine()) != null) {
- if (HOVER_MODE.equals(currentLine))
- return true;
+ if (!FileUtils.isFileWritable(COMMAND_PATH) ||
+ !FileUtils.isFileReadable(COMMAND_LIST_PATH) ||
+ !FileUtils.isFileReadable(COMMAND_RESULT_PATH)) {
+ return false;
+ }
+
+ BufferedReader reader = null;
+ try {
+ String currentLine;
+ reader = new BufferedReader(new FileReader(COMMAND_LIST_PATH));
+ while ((currentLine = reader.readLine()) != null) {
+ if (HOVER_MODE.equals(currentLine)) {
+ return true;
}
- } catch (IOException e) {
- // Ignore exception, will be false anyway
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- // Ignore exception, no recovery possible
- }
+ }
+ } catch (IOException e) {
+ Log.e(TAG, "Could not read from file " + COMMAND_LIST_PATH, e);
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ // Ignore exception, no recovery possible
}
}
}
@@ -77,7 +80,8 @@ public class TouchscreenHovering {
* or the operation failed while reading the status; true in any other case.
*/
public static boolean isEnabled() {
- return FileUtils.readOneLine(COMMAND_RESULT_PATH).equals(HOVER_MODE_ENABLE + STATUS_OK);
+ return (HOVER_MODE_ENABLE + STATUS_OK).equals(
+ FileUtils.readOneLine(COMMAND_RESULT_PATH));
}
/**
@@ -88,6 +92,7 @@ public class TouchscreenHovering {
* failed; true in any other case.
*/
public static boolean setEnabled(boolean status) {
- return FileUtils.writeLine(COMMAND_PATH, status ? HOVER_MODE_ENABLE : HOVER_MODE_DISABLE);
+ return FileUtils.writeLine(COMMAND_PATH,
+ status ? HOVER_MODE_ENABLE : HOVER_MODE_DISABLE);
}
}
diff --git a/cmhw/org/cyanogenmod/hardware/VibratorHW.java b/cmhw/org/cyanogenmod/hardware/VibratorHW.java
index 3ec6b5d..8c68123 100644
--- a/cmhw/org/cyanogenmod/hardware/VibratorHW.java
+++ b/cmhw/org/cyanogenmod/hardware/VibratorHW.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 The CyanogenMod Project
+ * Copyright (C) 2013-2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,80 +16,66 @@
package org.cyanogenmod.hardware;
-import org.cyanogenmod.hardware.util.FileUtils;
-
-import java.io.File;
+import org.cyanogenmod.internal.util.FileUtils;
public class VibratorHW {
- private static String LEVEL_PATH = "/sys/class/timed_output/vibrator/pwm_value";
- private static String LEVEL_MAX_PATH = "/sys/class/timed_output/vibrator/pwm_max";
- private static String LEVEL_MIN_PATH = "/sys/class/timed_output/vibrator/pwm_min";
- private static String LEVEL_DEFAULT_PATH = "/sys/class/timed_output/vibrator/pwm_default";
- private static String LEVEL_THRESHOLD_PATH = "/sys/class/timed_output/vibrator/pwm_threshold";
+ private static final String DEFAULT_PATH = "/sys/class/timed_output/vibrator/pwm_default";
+ private static final String LEVEL_PATH = "/sys/class/timed_output/vibrator/pwm_value";
+ private static final String MAX_PATH = "/sys/class/timed_output/vibrator/pwm_max";
+ private static final String MIN_PATH = "/sys/class/timed_output/vibrator/pwm_min";
+ private static final String THRESHOLD_PATH = "/sys/class/timed_output/vibrator/pwm_threshold";
public static boolean isSupported() {
- File f = new File(LEVEL_PATH);
- return f.exists();
+ return FileUtils.isFileWritable(LEVEL_PATH) &&
+ FileUtils.isFileReadable(LEVEL_PATH) &&
+ FileUtils.isFileReadable(DEFAULT_PATH) &&
+ FileUtils.isFileReadable(MAX_PATH) &&
+ FileUtils.isFileReadable(MIN_PATH) &&
+ FileUtils.isFileReadable(THRESHOLD_PATH);
}
public static int getMaxIntensity() {
- File f = new File(LEVEL_MAX_PATH);
-
- if(f.exists()) {
- return Integer.parseInt(FileUtils.readOneLine(LEVEL_MAX_PATH));
- } else {
- return 100;
+ try {
+ return Integer.parseInt(FileUtils.readOneLine(MAX_PATH));
+ } catch (NumberFormatException e) {
+ return -1;
}
}
public static int getMinIntensity() {
- File f = new File(LEVEL_MIN_PATH);
-
- if(f.exists()) {
- return Integer.parseInt(FileUtils.readOneLine(LEVEL_MIN_PATH));
- } else {
- return 0;
+ try {
+ return Integer.parseInt(FileUtils.readOneLine(MIN_PATH));
+ } catch (NumberFormatException e) {
+ return -1;
}
}
public static int getWarningThreshold() {
- File f = new File(LEVEL_THRESHOLD_PATH);
-
- if(f.exists()) {
- return Integer.parseInt(FileUtils.readOneLine(LEVEL_THRESHOLD_PATH));
- } else {
- return 75;
+ try {
+ return Integer.parseInt(FileUtils.readOneLine(THRESHOLD_PATH));
+ } catch (NumberFormatException e) {
+ return -1;
}
}
public static int getCurIntensity() {
- File f = new File(LEVEL_PATH);
-
- if(f.exists()) {
+ try {
return Integer.parseInt(FileUtils.readOneLine(LEVEL_PATH));
- } else {
- return 0;
+ } catch (NumberFormatException e) {
+ return -1;
}
}
public static int getDefaultIntensity() {
- File f = new File(LEVEL_DEFAULT_PATH);
-
- if(f.exists()) {
- return Integer.parseInt(FileUtils.readOneLine(LEVEL_DEFAULT_PATH));
- } else {
- return 50;
+ try {
+ return Integer.parseInt(FileUtils.readOneLine(DEFAULT_PATH));
+ } catch (NumberFormatException e) {
+ return -1;
}
}
public static boolean setIntensity(int intensity) {
- File f = new File(LEVEL_PATH);
-
- if(f.exists()) {
- return FileUtils.writeLine(LEVEL_PATH, String.valueOf(intensity));
- } else {
- return false;
- }
+ return FileUtils.writeLine(LEVEL_PATH, String.valueOf(intensity));
}
}