summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/java/android/hardware/CmHardwareManager.java16
-rw-r--r--services/core/java/com/android/server/CmHardwareService.java14
2 files changed, 22 insertions, 8 deletions
diff --git a/core/java/android/hardware/CmHardwareManager.java b/core/java/android/hardware/CmHardwareManager.java
index ad840b2aa18..0d47ea41acd 100644
--- a/core/java/android/hardware/CmHardwareManager.java
+++ b/core/java/android/hardware/CmHardwareManager.java
@@ -619,8 +619,8 @@ 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
+ * @param key String identifier for this item. Must not exceed 64 characters.
+ * @param value The UTF-8 encoded string to store of at least 1 character. null deletes the key/value pair.
* @return true on success
*
* @hide
@@ -641,7 +641,7 @@ public final class CmHardwareManager {
/**
* Write an integer to persistent storage, which persists thru factory reset
*
- * @param key String identifier for this item
+ * @param key String identifier for this item. Must not exceed 64 characters.
* @param value The integer to store
* @return true on success
*
@@ -661,8 +661,8 @@ public final class CmHardwareManager {
/**
* 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
+ * @param key String identifier for this item. Must not exceed 64 characters.
+ * @param value The byte array to store, must be 1-4096 bytes. null deletes the key/value pair.
* @return true on success
*
* @hide
@@ -680,7 +680,7 @@ public final class CmHardwareManager {
/**
* Read a string from persistent storage
*
- * @param key String identifier for this item
+ * @param key String identifier for this item. Must not exceed 64 characters.
* @return the stored UTF-8 encoded string, null if not found
*
* @hide
@@ -703,7 +703,7 @@ public final class CmHardwareManager {
/**
* Read an integer from persistent storage
*
- * @param key String identifier for this item
+ * @param key String identifier for this item. Must not exceed 64 characters.
* @return the stored integer, zero if not found
*
* @hide
@@ -724,7 +724,7 @@ public final class CmHardwareManager {
/**
* Read a byte array from persistent storage
*
- * @param key String identifier for this item
+ * @param key String identifier for this item. Must not exceed 64 characters.
* @return the stored byte array, null if not found
*
* @hide
diff --git a/services/core/java/com/android/server/CmHardwareService.java b/services/core/java/com/android/server/CmHardwareService.java
index cfd088e36a7..2b4f11267a8 100644
--- a/services/core/java/com/android/server/CmHardwareService.java
+++ b/services/core/java/com/android/server/CmHardwareService.java
@@ -25,6 +25,7 @@ import android.os.RemoteException;
import android.util.Log;
import java.io.File;
+import java.util.Arrays;
import org.cyanogenmod.hardware.AdaptiveBacklight;
import org.cyanogenmod.hardware.ColorEnhancement;
@@ -522,6 +523,15 @@ public class CmHardwareService extends ICmHardwareService.Stub implements Therma
public boolean writePersistentBytes(String key, byte[] value) {
mContext.enforceCallingOrSelfPermission(
Manifest.permission.MANAGE_PERSISTENT_STORAGE, null);
+ if (key == null || key.length() == 0 || key.length() > 64) {
+ Log.e(TAG, "Invalid key: " + key);
+ return false;
+ }
+ // A null value is delete
+ if (value != null && (value.length > 4096 || value.length == 0)) {
+ Log.e(TAG, "Invalid value: " + (value != null ? Arrays.toString(value) : null));
+ return false;
+ }
if (!isSupported(CmHardwareManager.FEATURE_PERSISTENT_STORAGE)) {
Log.e(TAG, "Persistent storage is not supported");
return false;
@@ -533,6 +543,10 @@ public class CmHardwareService extends ICmHardwareService.Stub implements Therma
public byte[] readPersistentBytes(String key) {
mContext.enforceCallingOrSelfPermission(
Manifest.permission.MANAGE_PERSISTENT_STORAGE, null);
+ if (key == null || key.length() == 0 || key.length() > 64) {
+ Log.e(TAG, "Invalid key: " + key);
+ return null;
+ }
if (!isSupported(CmHardwareManager.FEATURE_PERSISTENT_STORAGE)) {
Log.e(TAG, "Persistent storage is not supported");
return null;