mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-16 23:12:47 +00:00
cache device protected prefs instance
This commit is contained in:
parent
98fb94de8d
commit
b8a6443a8f
1 changed files with 8 additions and 4 deletions
|
@ -17,18 +17,22 @@ import androidx.annotation.RequiresApi;
|
|||
public final class DeviceProtectedUtils {
|
||||
|
||||
static final String TAG = DeviceProtectedUtils.class.getSimpleName();
|
||||
private static SharedPreferences prefs;
|
||||
|
||||
public static SharedPreferences getSharedPreferences(final Context context) {
|
||||
if (prefs != null)
|
||||
return prefs;
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return prefs;
|
||||
}
|
||||
Context deviceProtectedContext = getDeviceProtectedContext(context);
|
||||
SharedPreferences deviceProtectedPreferences = PreferenceManager.getDefaultSharedPreferences(deviceProtectedContext);
|
||||
if (deviceProtectedPreferences.getAll().isEmpty()) {
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(deviceProtectedContext);
|
||||
if (prefs.getAll().isEmpty()) {
|
||||
Log.i(TAG, "Device encrypted storage is empty, copying values from credential encrypted storage");
|
||||
deviceProtectedContext.moveSharedPreferencesFrom(context, PreferenceManager.getDefaultSharedPreferencesName(context));
|
||||
}
|
||||
return deviceProtectedPreferences;
|
||||
return prefs;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue