Starting with Android Nougat, I used the following code to move the sharedprefs location from the "credential encrypted storage" to "device encrypted storage" so that I can access it before the user unlocks the device (otherwise known as DirectBoot):
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// All N devices have split storage areas, but we may need to
// move the existing preferences to the new device protected
// storage area, which is where the data lives from now on.
final Context deviceContext = context.createDeviceProtectedStorageContext();
if (!deviceContext.moveSharedPreferencesFrom(context, PREFERENCES_NAME)) {
Utils.logWarn(TAG, "Failed to migrate shared preferences.");
}
storageContext = deviceContext;
} else {
storageContext = context;
}
sharedPreferences = storageContext.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
The old location for the file was in /data/data/app_name/shared_prefs/shared_prefs_file_name.xml
Where is the new location for the shared prefs file?
I'd like to know this so that I can copy the file to external storage for a backup/restore function.
As stated in this blog you can find the Device Encrypted Storage under path 'data/user_de/...'