mirror of
https://github.com/team-infusion-developers/android_hardware_samsung.git
synced 2024-11-06 21:55:41 +00:00
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
This commit is contained in:
parent
9dad4fe888
commit
1da88e6e9f
9 changed files with 134 additions and 231 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue