Added in API level 1
public interface

PersistentStorage

masonamerica.platform.PersistentStorage

Class Overview

Support for storage of key-value pairs which persists across device wipes / factory resets. This is used for various security related features. A reasonable implementation of this needs to store items on a partition which is unaffected by factory reset. The actual format of the storage is left up to the implementation. The implementation in this file is suitable for devices which have a /persist partition (recent QCOM devices fit this criteria).

Summary

Public Methods
abstract byte[] get(String key)
Gets an array of bytes from persistent storage.
abstract boolean isSupported()
Whether device supports persistent properties
abstract int readPersistentInt(String key)
Read an integer from persistent storage
abstract String readPersistentString(String key)
Read a string from persistent storage
abstract boolean reset()
Remove all the data written by this application (and anything in its shared uid).
abstract boolean set(String key, byte[] buffer)
Writes a byte array to persistent storage.
abstract boolean writePersistentInt(String key, int value)
Write an integer to persistent storage, which persists through factory reset
abstract boolean writePersistentString(String key, String value)
Write a string to persistent storage, which persists thru factory reset

Public Methods

public abstract byte[] get (String key)

Added in API level 1

Gets an array of bytes from persistent storage. Use readPersistentString(String) and readPersistentInt(String) for typed helpers.

Returns
byte[] previously stored byte array, null if not found

public abstract boolean isSupported ()

Added in API level 1

Whether device supports persistent properties

Returns
boolean boolean Supported devices must return always true

public abstract int readPersistentInt (String key)

Added in API level 1

Read an integer from persistent storage

Parameters
key String: String identifier for this item. Must not exceed 64 characters.
Returns
int the stored integer, zero if not found

public abstract String readPersistentString (String key)

Added in API level 1

Read a string from persistent storage

Parameters
key String: String identifier for this item. Must not exceed 64 characters.
Returns
String the stored UTF-8 encoded string, null if not found

public abstract boolean reset ()

Remove all the data written by this application (and anything in its shared uid).

Returns
boolean true if the operation succeeded

public abstract boolean set (String key, byte[] buffer)

Added in API level 1

Writes a byte array to persistent storage. Use writePersistentString(String, String) and writePersistentInt(String, int) for typed helpers. The storage of the data is implementation specific. In this implementation, we hash the key with SHA-256 and use the hex string as the stored key. Implementations should delete the key if a null buffer is passed.

Returns
boolean true if the operation succeeded

public abstract boolean writePersistentInt (String key, int value)

Added in API level 1

Write an integer to persistent storage, which persists through factory reset

Parameters
key String: String identifier for this item. Must not exceed 64 characters.
value int: The integer to store
Returns
boolean true on success

public abstract boolean writePersistentString (String key, String value)

Added in API level 1

Write a string to persistent storage, which persists thru factory reset

Parameters
key String: String identifier for this item. Must not exceed 64 characters.
value String: The UTF-8 encoded string to store of at least 1 character. null deletes the key/value pair.
Returns
boolean true on success