aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2015-08-31 18:43:51 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2015-09-09 15:43:32 -0700
commit7cef6f69453a8edcb23272e63cea14b2dcad5d77 (patch)
treeaf032c583c024a67fce854d70030744c798b5f64 /src
parent087f2b536d16ae452a955a8ae39dcab214c99c98 (diff)
downloadvendor_cmsdk-7cef6f69453a8edcb23272e63cea14b2dcad5d77.zip
vendor_cmsdk-7cef6f69453a8edcb23272e63cea14b2dcad5d77.tar.gz
vendor_cmsdk-7cef6f69453a8edcb23272e63cea14b2dcad5d77.tar.bz2
cmsdk: Add persistent properties API
* Add support for reading and writing values from/to persistent storage. Requires the MANAGE_PERSISTENT_STORAGE permission, which should not be available for general use by applications. Change-Id: I8a793396d207f23fcda851c172372f2073778eec
Diffstat (limited to 'src')
-rw-r--r--src/java/cyanogenmod/hardware/CMHardwareManager.java133
-rw-r--r--src/java/cyanogenmod/hardware/ICMHardwareService.aidl3
2 files changed, 136 insertions, 0 deletions
diff --git a/src/java/cyanogenmod/hardware/CMHardwareManager.java b/src/java/cyanogenmod/hardware/CMHardwareManager.java
index 96d7dfc..12f3854 100644
--- a/src/java/cyanogenmod/hardware/CMHardwareManager.java
+++ b/src/java/cyanogenmod/hardware/CMHardwareManager.java
@@ -23,7 +23,9 @@ import android.util.Log;
import cyanogenmod.app.CMContextConstants;
+import java.io.UnsupportedEncodingException;
import java.lang.IllegalArgumentException;
+import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
@@ -112,6 +114,11 @@ public final class CMHardwareManager {
*/
public static final int FEATURE_DISPLAY_MODES = 0x2000;
+ /**
+ * Persistent storage
+ */
+ public static final int FEATURE_PERSISTENT_STORAGE = 0x4000;
+
private static final List<Integer> BOOLEAN_FEATURES = Arrays.asList(
FEATURE_ADAPTIVE_BACKLIGHT,
FEATURE_COLOR_ENHANCEMENT,
@@ -413,6 +420,132 @@ public final class CMHardwareManager {
}
/**
+ * Write a string to persistent storage, which persists thru factory reset
+ *
+ * @param key String identifier for this item
+ * @param value The UTF-8 encoded string to store
+ * @return true on success
+ */
+ public boolean writePersistentString(String key, String value) {
+ try {
+ if (checkService()) {
+ return getService().writePersistentBytes(key,
+ value == null ? null : value.getBytes("UTF-8"));
+ }
+ } catch (RemoteException e) {
+ } catch (UnsupportedEncodingException e) {
+ Log.e(TAG, e.getMessage(), e);
+ }
+ return false;
+ }
+
+ /**
+ * Write an integer to persistent storage, which persists thru factory reset
+ *
+ * @param key String identifier for this item
+ * @param value The integer to store
+ * @return true on success
+ */
+ public boolean writePersistentInt(String key, int value) {
+ try {
+ if (checkService()) {
+ return getService().writePersistentBytes(key,
+ ByteBuffer.allocate(4).putInt(value).array());
+ }
+ } catch (RemoteException e) {
+ }
+ return false;
+ }
+
+ /**
+ * Write a byte array to persistent storage, which persists thru factory reset
+ *
+ * @param key String identifier for this item
+ * @param value The byte array to store, up to 4096 bytes
+ * @return true on success
+ */
+ public boolean writePersistentBytes(String key, byte[] value) {
+ try {
+ if (checkService()) {
+ return getService().writePersistentBytes(key, value);
+ }
+ } catch (RemoteException e) {
+ }
+ return false;
+ }
+
+ /**
+ * Read a string from persistent storage
+ *
+ * @param key String identifier for this item
+ * @return the stored UTF-8 encoded string, null if not found
+ */
+ public String readPersistentString(String key) {
+ try {
+ if (checkService()) {
+ byte[] bytes = getService().readPersistentBytes(key);
+ if (bytes != null) {
+ return new String(bytes, "UTF-8");
+ }
+ }
+ } catch (RemoteException e) {
+ } catch (UnsupportedEncodingException e) {
+ Log.e(TAG, e.getMessage(), e);
+ }
+ return null;
+ }
+
+ /**
+ * Read an integer from persistent storage
+ *
+ * @param key String identifier for this item
+ * @return the stored integer, zero if not found
+ */
+ public int readPersistentInt(String key) {
+ try {
+ if (checkService()) {
+ byte[] bytes = getService().readPersistentBytes(key);
+ if (bytes != null) {
+ return ByteBuffer.wrap(bytes).getInt();
+ }
+ }
+ } catch (RemoteException e) {
+ }
+ return 0;
+ }
+
+ /**
+ * Read a byte array from persistent storage
+ *
+ * @param key String identifier for this item
+ * @return the stored byte array, null if not found
+ */
+ public byte[] readPersistentBytes(String key) {
+ try {
+ if (checkService()) {
+ return getService().readPersistentBytes(key);
+ }
+ } catch (RemoteException e) {
+ }
+ return null;
+ }
+
+ /** Delete an object from persistent storage
+ *
+ * @param key String identifier for this item
+ * @return true if an item was deleted
+ */
+ public boolean deletePersistentObject(String key) {
+ try {
+ if (checkService()) {
+ return getService().writePersistentBytes(key, null);
+ }
+ } catch (RemoteException e) {
+ }
+ return false;
+ }
+
+ /**
* {@hide}
*/
public static final int GAMMA_CALIBRATION_RED_INDEX = 0;
diff --git a/src/java/cyanogenmod/hardware/ICMHardwareService.aidl b/src/java/cyanogenmod/hardware/ICMHardwareService.aidl
index 44738e3..edb1b1d 100644
--- a/src/java/cyanogenmod/hardware/ICMHardwareService.aidl
+++ b/src/java/cyanogenmod/hardware/ICMHardwareService.aidl
@@ -47,4 +47,7 @@ interface ICMHardwareService {
DisplayMode getCurrentDisplayMode();
DisplayMode getDefaultDisplayMode();
boolean setDisplayMode(in DisplayMode mode, boolean makeDefault);
+
+ boolean writePersistentBytes(String key, in byte[] bytes);
+ byte[] readPersistentBytes(String key);
}