DEV Community

Discussion on: Beyond preferences

Collapse
 
tkuenneth profile image
Thomas Künneth

I was asked if I knew if Preferences DataStore could use encrypted files. I didn't. As this is a very interesting question, I decided to take a look at the source code. Here's what I found.

To prepare the data store, I used val Context.dataStore by preferencesDataStore("user_preferences").

source code of preferencesDataStore()

As you can see, an instance of PreferenceDataStoreSingletonDelegate is returned. Here's the interesting part:

code snippet from PreferenceDataStoreSingletonDelegate

So, next stop: PreferenceDataStoreFactory.create():

source code of PreferenceDataStoreFactory.create()

So, the final destination is PreferencesSerializer. It overrides two suspending functions, readFrom() and writeTo(). I guess that the changes would need to be made there. In theory the api might be expanded to pass in alternative implementations.

So, I hope you enjoyed this short dig. 😎