@Test public void testGetAll() { final CryptoSharedPreferences cryptoPreferences = new CryptoSharedPreferences.Builder(preferences).valueCrypto(CRYPTO).build(); final CryptoSharedPreferences.Editor editor = cryptoPreferences.edit(); editor.putString(PREF_KEY + ".Null", null); editor.putString(PREF_KEY + ".String", "Value"); editor.putInt(PREF_KEY + ".Integer", 10); editor.putFloat(PREF_KEY + ".Float", 0.5f); editor.putLong(PREF_KEY + ".Long", 1000L); editor.putBoolean(PREF_KEY + ".Boolean", true); editor.commit(); final Map<String, ?> values = cryptoPreferences.getAll(); assertThat(values, is(notNullValue())); assertThat(values.size(), is(5)); assertThat(values.get(PREF_KEY + ".Null"), is(nullValue())); assertThat((String) values.get(PREF_KEY + ".String"), is("Value")); assertThat((String) values.get(PREF_KEY + ".Integer"), is(Integer.toString(10))); assertThat((String) values.get(PREF_KEY + ".Float"), is(Float.toString(0.5f))); assertThat((String) values.get(PREF_KEY + ".Long"), is(Long.toString(1000L))); assertThat((String) values.get(PREF_KEY + ".Boolean"), is(Boolean.toString(true))); }
@Override public Map<String, ?> getAll() { final Map<String, ?> encryptedValues = delegate.getAll(); final Map<String, Object> decryptedValues = new HashMap<>(encryptedValues.size()); for (final String key : encryptedValues.keySet()) { final Object value = encryptedValues.get(key); final String decryptedKey = helper.decryptKey(key); if (value == null) { decryptedValues.put(decryptedKey, null); } else if (value instanceof String) { decryptedValues.put(decryptedKey, helper.decryptValue(value.toString())); } else if (value instanceof Set) { decryptedValues.put(decryptedKey, helper.decryptValuesSet((Set<String>) value)); } else { throw new IllegalStateException("Found encrypted value of unsupported type!"); } } return decryptedValues; }
CryptoSharedPreferences implements SharedPreferences { @Override public Map<String, ?> getAll() { final Map<String, ?> encryptedValues = delegate.getAll(); final Map<String, Object> decryptedValues = new HashMap<>(encryptedValues.size()); for (final String key : encryptedValues.keySet()) { final Object value = encryptedValues.get(key); final String decryptedKey = helper.decryptKey(key); if (value == null) { decryptedValues.put(decryptedKey, null); } else if (value instanceof String) { decryptedValues.put(decryptedKey, helper.decryptValue(value.toString())); } else if (value instanceof Set) { decryptedValues.put(decryptedKey, helper.decryptValuesSet((Set<String>) value)); } else { throw new IllegalStateException("Found encrypted value of unsupported type!"); } } return decryptedValues; } }
CryptoSharedPreferences implements SharedPreferences { @Override public Map<String, ?> getAll() { final Map<String, ?> encryptedValues = delegate.getAll(); final Map<String, Object> decryptedValues = new HashMap<>(encryptedValues.size()); for (final String key : encryptedValues.keySet()) { final Object value = encryptedValues.get(key); final String decryptedKey = helper.decryptKey(key); if (value == null) { decryptedValues.put(decryptedKey, null); } else if (value instanceof String) { decryptedValues.put(decryptedKey, helper.decryptValue(value.toString())); } else if (value instanceof Set) { decryptedValues.put(decryptedKey, helper.decryptValuesSet((Set<String>) value)); } else { throw new IllegalStateException("Found encrypted value of unsupported type!"); } } return decryptedValues; } @SuppressWarnings("WeakerAccess")  CryptoSharedPreferences(final Builder builder); }
CryptoSharedPreferences implements SharedPreferences { @Override public Map<String, ?> getAll() { final Map<String, ?> encryptedValues = delegate.getAll(); final Map<String, Object> decryptedValues = new HashMap<>(encryptedValues.size()); for (final String key : encryptedValues.keySet()) { final Object value = encryptedValues.get(key); final String decryptedKey = helper.decryptKey(key); if (value == null) { decryptedValues.put(decryptedKey, null); } else if (value instanceof String) { decryptedValues.put(decryptedKey, helper.decryptValue(value.toString())); } else if (value instanceof Set) { decryptedValues.put(decryptedKey, helper.decryptValuesSet((Set<String>) value)); } else { throw new IllegalStateException("Found encrypted value of unsupported type!"); } } return decryptedValues; } @SuppressWarnings("WeakerAccess")  CryptoSharedPreferences(final Builder builder); @Override void registerOnSharedPreferenceChangeListener(@NonNull final OnSharedPreferenceChangeListener listener); @Override void unregisterOnSharedPreferenceChangeListener(@NonNull final OnSharedPreferenceChangeListener listener); @Override Map<String, ?> getAll(); @Override boolean contains(@NonNull final String key); @Override @Nullable String getString(@NonNull final String key, @Nullable final String defValue); @Override @Nullable Set<String> getStringSet(@NonNull final String key, @Nullable final Set<String> defValues); @Override int getInt(@NonNull final String key, final int defValue); @Override long getLong(@NonNull final String key, final long defValue); @Override float getFloat(@NonNull final String key, final float defValue); @Override boolean getBoolean(@NonNull final String key, final boolean defValue); @SuppressLint("CommitPrefEdits") @Override SharedPreferences.Editor edit(); }
CryptoSharedPreferences implements SharedPreferences { @Override public Map<String, ?> getAll() { final Map<String, ?> encryptedValues = delegate.getAll(); final Map<String, Object> decryptedValues = new HashMap<>(encryptedValues.size()); for (final String key : encryptedValues.keySet()) { final Object value = encryptedValues.get(key); final String decryptedKey = helper.decryptKey(key); if (value == null) { decryptedValues.put(decryptedKey, null); } else if (value instanceof String) { decryptedValues.put(decryptedKey, helper.decryptValue(value.toString())); } else if (value instanceof Set) { decryptedValues.put(decryptedKey, helper.decryptValuesSet((Set<String>) value)); } else { throw new IllegalStateException("Found encrypted value of unsupported type!"); } } return decryptedValues; } @SuppressWarnings("WeakerAccess")  CryptoSharedPreferences(final Builder builder); @Override void registerOnSharedPreferenceChangeListener(@NonNull final OnSharedPreferenceChangeListener listener); @Override void unregisterOnSharedPreferenceChangeListener(@NonNull final OnSharedPreferenceChangeListener listener); @Override Map<String, ?> getAll(); @Override boolean contains(@NonNull final String key); @Override @Nullable String getString(@NonNull final String key, @Nullable final String defValue); @Override @Nullable Set<String> getStringSet(@NonNull final String key, @Nullable final Set<String> defValues); @Override int getInt(@NonNull final String key, final int defValue); @Override long getLong(@NonNull final String key, final long defValue); @Override float getFloat(@NonNull final String key, final float defValue); @Override boolean getBoolean(@NonNull final String key, final boolean defValue); @SuppressLint("CommitPrefEdits") @Override SharedPreferences.Editor edit();  }