diff options
author | Zhao Wei Liew <zhaoweiliew@gmail.com> | 2016-06-29 20:21:59 +0800 |
---|---|---|
committer | Zhao Wei Liew <zhaoweiliew@gmail.com> | 2016-07-02 13:02:54 +0800 |
commit | 1da88e6e9f14fa77d912c8fa6540bc8888cfde25 (patch) | |
tree | e2bb36db1197c185e73c46345bbfb07a508f7fca /AdvancedDisplay/src/com/cyanogenmod/settings | |
parent | 9dad4fe88897cd01a64c793a4081576d7396bce7 (diff) | |
download | android_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
Diffstat (limited to 'AdvancedDisplay/src/com/cyanogenmod/settings')
4 files changed, 13 insertions, 91 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; } |