android-components / mozilla.components.lib.dataprotect / SecureAbove22Preferences

SecureAbove22Preferences

class SecureAbove22Preferences : KeyValuePreferences (source)

A wrapper around SharedPreferences which encrypts contents on supported API versions (23+). Otherwise, this simply delegates to SharedPreferences.

In rare circumstances (such as APK signing key rotation) a master key which protects this storage may be lost, in which case previously stored values will be lost as well. Applications are encouraged to instrument such events.

Parameters

context - A Context, used for accessing SharedPreferences.

name - A name for this storage, used for isolating different instances of SecureAbove22Preferences.

forceInsecure - A flag indicating whether to force plaintext storage. If set to true, InsecurePreferencesImpl21 will be used as a storage layer, otherwise a storage implementation will be decided based on Android API version, with a preference given to secure storage

Constructors

Name Summary
<init> SecureAbove22Preferences(context: <ERROR CLASS>, name: String, forceInsecure: Boolean = false)
A wrapper around SharedPreferences which encrypts contents on supported API versions (23+). Otherwise, this simply delegates to SharedPreferences.

Functions

Name Summary
all fun all(): Map<String, String>
Retrieves all key/value pairs present in the store.
clear fun clear(): Unit
Clears all key/value pairs from the storage.
getString fun getString(key: String): String?
Retrieves a stored key. See putString for storing a key.
putString fun putString(key: String, value: String): Unit
Stores value under key. Retrieve it using getString.
remove fun remove(key: String): Unit
Removes key/value pair from storage for the provided key.

Extension Functions

Name Summary
loadResourceAsString fun Any.loadResourceAsString(path: String): String
Loads a file from the resources folder and returns its content as a string object.