summaryrefslogtreecommitdiffstats
path: root/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java
diff options
context:
space:
mode:
Diffstat (limited to 'DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java')
-rw-r--r--DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java82
1 files changed, 73 insertions, 9 deletions
diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java b/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java
index 9d4176c..237ea0f 100644
--- a/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java
+++ b/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java
@@ -16,32 +16,96 @@
package com.cyanogenmod.settings.device;
+import android.util.Log;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
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 = "GalaxyNoteSettings_Utils";
+ private static final String TAG_READ = "GalaxyNoteSettings_Utils_Read";
+ private static final String TAG_WRITE = "GalaxyNoteSettings_Utils_Write";
+
/**
* Write a string value to the specified file.
- * @param filename The filename
- * @param value The value
+ *
+ * @param filename The filename
+ * @param value The value
*/
public static void writeValue(String filename, String value) {
+ FileOutputStream fos = null;
try {
- FileOutputStream fos = new FileOutputStream(new File(filename));
+ fos = new FileOutputStream(new File(filename), false);
fos.write(value.getBytes());
fos.flush();
- fos.getFD().sync();
- fos.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
+ // 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);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Write a string value to the specified file.
+ *
+ * @param filename The filename
+ * @param value The value
+ */
+ public static void writeValue(String filename, Boolean value) {
+ FileOutputStream fos = null;
+ String sEnvia;
+ try {
+ fos = new FileOutputStream(new File(filename), false);
+ if (value)
+ sEnvia = "1";
+ else
+ sEnvia = "0";
+ fos.write(sEnvia.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);
+ }
+ }
}
}