This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class EncryptedDatabase : RoomDatabase() { | |
companion object { | |
fun getInstance(passcode: CharArray, context: Context): | |
EncryptedDatabase = buildDatabase(passcode, context) | |
private fun buildDatabase( | |
passcode: CharArray, | |
context: Context | |
): EncryptedDatabase { | |
// DatabaseKeyMgr is a singleton that all of the above code is wrapped into. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A storage implementation that enforces whole class serialization/deserialization. | |
* | |
* This enforces organization of data that needs to be persisted rather than having generic classes | |
* with lots of unrelated data. | |
* | |
* @param context the caller's context | |
*/ | |
@Singleton | |
class DataStore(context: Context) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A factory that can serialize/deserialize json. | |
*/ | |
object GsonUtils { | |
/** | |
* Handles deserializing the json string into a [T] instance. | |
* | |
* @param json the json to deserialize into an instance of [T] | |
* @throws JsonSyntaxException if there is a failure deserializing then this exception is thrown | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Keeps track of current and prior application state. | |
* | |
* @param dataStore storage | |
*/ | |
@Singleton | |
class StateMachine(private val dataStore: DataStore) { | |
/** | |
* Storage implementation for our state machine. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
class Preferences(context: Context) { | |
private val prefs: SharedPreferences = context.getSharedPreferences("Prefs", Context.MODE_PRIVATE) | |
companion object { | |
const val PREF_CURRENT_STATE = "CurrentState" | |
const val PREF_LAST_KNOWN_ERROR = "LastKnownError" | |
const val PREF_LAST_ACTION_PERFORMED = "LastActionPerformed" | |
} |
OlderNewer