SDMPersistence

The Persistence component is responsible for storing application specific objects and raw data in the device’s physical storage.

List of Features

SDMPersistence Public APIs

ISDMPersistence

	void clear();
	void storeObject(String key, ISDMPersistable object)
	<T extends ISDMPersistable> boolean loadObject(String key, T object)
	void storeRawData(String key, byte[] data)
	byte[] loadRawData(String key)
	void storeDataStream(String key, InputStream stream)
	InputStream loadDataStream(String key)
	boolean loadSDMCache(ISDMCache cache)
	void storeSDMCache(ISDMCache cache)
	boolean removeData(String key)
	boolean removeCache()
	boolean isDataPersisted(String key)
	void setEncryptionKey(byte[] secretKey, String secretKeyAlgorithm) throws SDMPersistenceException

Technical Details

SDMPersistence preferences:

SDMPersistence can persist data in secure and non-secure mode, based on the value of preference PERSISTENCE_SECUREMODE_BOOLEAN. In secure mode, all data stored by SDMPersistence will be encrypted. Encryption is done using the secret key that is passed to SDMPersistence during initialization or by using the setEncryptionKey API. If the Secret Key object is null and the secure mode is turned on for SDMPersistence, SDMPersistenceException will be thrown during runtime. PERSISTENCE_SECUREMODE_BOOLEAN is by default true.

A secret key can be generated with the help of the static API of the SDMPersistence class. Use the SDMPersistence.generateSecretKey (String secretKeyAlgorithm) API. The API returns a generated secret key with the given algorithm in a byte array format.

Important: if PERSISTENCE_SECUREMODE_BOOLEAN preference is changed during runtime, all previously stored data will be deleted without any notification. It depends on the application whether it asks for confirmation from the user before changing the value of this preference.

SDMPersistence by default stores data in the application’s cache folder in the file system on the physical storage of the device. Stored data is not accessible for any other applications, but can be wiped out by the user outside of the application using the device’s application settings. The default folder to store persisted data can be changed by changing the value of PERSISTENCE_DEFAULTFOLDER_PATH_STRING preference. If the PERSISTENCE_DEFAULTFOLDER_PATH_STRING preference is changed during runtime, all previously stored data will be automatically moved to the new folder.

SDMPersistence implementation guarantees the proper concurrent file handling as long as there are no other non SDMPersistence objects trying to access the persisted data.

ISDMPersistable:

All the objects that are to be persisted with SDMPersistence need to implement the ISDMPersistable interface. All valid implementations of ISDMPersistable must implement the declared read and write methods of the interface and must have a public no-arg constructor. SDMOData objects provided by the Android OData SDK are valid implementations of ISDMPersistable.