mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-16 23:12:47 +00:00
Update migration to use moveSharedPreferencesFrom
This commit is contained in:
parent
ddbed48ce9
commit
8c79b31f6a
1 changed files with 3 additions and 29 deletions
|
@ -21,42 +21,16 @@ import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.dslul.openboard.inputmethod.latin.LatinIME;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public final class DeviceProtectedUtils {
|
public final class DeviceProtectedUtils {
|
||||||
|
|
||||||
static final String TAG = DeviceProtectedUtils.class.getSimpleName();
|
static final String TAG = DeviceProtectedUtils.class.getSimpleName();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static SharedPreferences getSharedPreferences(final Context context) {
|
public static SharedPreferences getSharedPreferences(final Context context) {
|
||||||
SharedPreferences deviceProtectedPreferences = PreferenceManager.getDefaultSharedPreferences(getDeviceProtectedContext(context));
|
Context deviceProtectedContext = getDeviceProtectedContext(context);
|
||||||
|
SharedPreferences deviceProtectedPreferences = PreferenceManager.getDefaultSharedPreferences(deviceProtectedContext);
|
||||||
if (deviceProtectedPreferences.getAll().isEmpty()) {
|
if (deviceProtectedPreferences.getAll().isEmpty()) {
|
||||||
Log.i(TAG, "Device encrypted storage is empty, copying values from credential encrypted storage");
|
Log.i(TAG, "Device encrypted storage is empty, copying values from credential encrypted storage");
|
||||||
for (Map.Entry<String, ?> entry : PreferenceManager.getDefaultSharedPreferences(context).getAll().entrySet()) {
|
deviceProtectedContext.moveSharedPreferencesFrom(context, PreferenceManager.getDefaultSharedPreferencesName(context));
|
||||||
SharedPreferences.Editor deviceProtectedPreferencesEditor = deviceProtectedPreferences.edit();
|
|
||||||
try {
|
|
||||||
if (entry.getKey() != null && entry.getValue() != null) {
|
|
||||||
if (entry.getValue() instanceof Boolean)
|
|
||||||
deviceProtectedPreferencesEditor.putBoolean(entry.getKey(), (Boolean) entry.getValue());
|
|
||||||
if (entry.getValue() instanceof Float)
|
|
||||||
deviceProtectedPreferencesEditor.putFloat(entry.getKey(), (Float) entry.getValue());
|
|
||||||
if (entry.getValue() instanceof Integer)
|
|
||||||
deviceProtectedPreferencesEditor.putInt(entry.getKey(), (Integer) entry.getValue());
|
|
||||||
if (entry.getValue() instanceof Long)
|
|
||||||
deviceProtectedPreferencesEditor.putLong(entry.getKey(), (Long) entry.getValue());
|
|
||||||
if (entry.getValue() instanceof String)
|
|
||||||
deviceProtectedPreferencesEditor.putString(entry.getKey(), (String) entry.getValue());
|
|
||||||
if (entry.getValue() instanceof Set)
|
|
||||||
deviceProtectedPreferencesEditor.putStringSet(entry.getKey(), (Set<String>) entry.getValue());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w(TAG, "Unable to copy preference from credential to device encrypted storage", e);
|
|
||||||
}
|
|
||||||
deviceProtectedPreferencesEditor.apply();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return deviceProtectedPreferences;
|
return deviceProtectedPreferences;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue