diff --git a/core/java/android/preference/Preference.java b/core/java/android/preference/Preference.java index 443a3e968b9c2..a8b98ac518185 100644 --- a/core/java/android/preference/Preference.java +++ b/core/java/android/preference/Preference.java @@ -458,8 +458,8 @@ public class Preference implements Comparable { } /** - * Return the extras Bundle object associated with this preference, - * returning null if there is not currently one. + * Return the extras Bundle object associated with this preference, returning {@code null} if + * there is not currently one. */ public Bundle peekExtras() { return mExtras; @@ -974,7 +974,7 @@ public class Preference implements Comparable { * the persistent {@link SharedPreferences} storage by default or into * {@link PreferenceDataStore} if assigned. * - * @param persistent Set true if it should store its value(s) into the {@link SharedPreferences}. + * @param persistent set {@code true} if it should store its value(s) into the storage. */ public void setPersistent(boolean persistent) { mPersistent = persistent; @@ -1035,7 +1035,7 @@ public class Preference implements Comparable { * * @param preferenceScreen A {@link PreferenceScreen} whose hierarchy click * listener should be called in the proper order (between other - * processing). May be null. + * processing). May be {@code null}. * @hide */ public void performClick(PreferenceScreen preferenceScreen) { @@ -1102,9 +1102,9 @@ public class Preference implements Comparable { * {@link SharedPreferences}, this is intended behavior to improve * performance. * - * @return The {@link SharedPreferences} where this Preference reads its value(s), or null if it - * isn't attached to a Preference hierarchy or if {@link PreferenceDataStore} is used - * instead. + * @return the {@link SharedPreferences} where this Preference reads its value(s). If + * this preference isn't attached to a Preference hierarchy or if + * a {@link PreferenceDataStore} has been set, this method returns {@code null}. * @see #getEditor() * @see #setPreferenceDataStore(PreferenceDataStore) */ @@ -1129,9 +1129,9 @@ public class Preference implements Comparable { * not show up in the SharedPreferences, this is intended behavior to * improve performance. * - * @return A {@link SharedPreferences.Editor} where this preference saves its value(s), or null - * if it isn't attached to a Preference hierarchy or if {@link PreferenceDataStore} is - * used instead. + * @return a {@link SharedPreferences.Editor} where this preference saves its value(s). If + * this preference isn't attached to a Preference hierarchy or if + * a {@link PreferenceDataStore} has been set, this method returns {@code null}. * @see #shouldCommit() * @see #getSharedPreferences() * @see #setPreferenceDataStore(PreferenceDataStore) @@ -1149,7 +1149,7 @@ public class Preference implements Comparable { * {@link #getEditor()}. This may return false in situations where batch * committing is being done (by the manager) to improve performance. * - *

If this preference is using {@link PreferenceDataStore} this value should be irrelevant. + *

If this preference is using {@link PreferenceDataStore} this value is irrelevant. * * @return Whether the Preference should commit its saved value(s). * @see #getEditor() @@ -1253,10 +1253,10 @@ public class Preference implements Comparable { } /** - * Assigns a {@link PreferenceGroup} as the parent of this Preference. Set null to remove - * the current parent. + * Assigns a {@link PreferenceGroup} as the parent of this Preference. Set {@code null} to + * remove the current parent. * - * @param parentGroup Parent preference group of this Preference or null if none. + * @param parentGroup Parent preference group of this Preference or {@code null} if none. */ void assignParent(@Nullable PreferenceGroup parentGroup) { mParentGroup = parentGroup; @@ -1425,10 +1425,10 @@ public class Preference implements Comparable { } /** - * Returns the {@link PreferenceGroup} which is this Preference assigned to or null if this - * preference is not assigned to any group or is a root Preference. + * Returns the {@link PreferenceGroup} which is this Preference assigned to or {@code null} if + * this preference is not assigned to any group or is a root Preference. * - * @return The parent PreferenceGroup or null if not attached to any. + * @return the parent PreferenceGroup or {@code null} if not attached to any */ @Nullable public PreferenceGroup getParent() { @@ -1483,7 +1483,7 @@ public class Preference implements Comparable { * if {@link #shouldPersist()} is true). * *

In case of using {@link PreferenceDataStore}, the restorePersistedValue is - * always false. But the default value (if provided) is set. + * always {@code true}. But the default value (if provided) is set. * *

This may not always be called. One example is if it should not persist * but there is no default value given. @@ -1910,9 +1910,9 @@ public class Preference implements Comparable { * state. This state should only contain information that is not persistent * or can be reconstructed later. * - * @return A Parcelable object containing the current dynamic state of - * this Preference, or null if there is nothing interesting to save. - * The default implementation returns null. + * @return A Parcelable object containing the current dynamic state of this Preference, or + * {@code null} if there is nothing interesting to save. The default implementation + * returns {@code null}. * @see #onRestoreInstanceState * @see #saveHierarchyState */ @@ -1958,9 +1958,9 @@ public class Preference implements Comparable { } /** - * Hook allowing a Preference to re-apply a representation of its internal - * state that had previously been generated by {@link #onSaveInstanceState}. - * This function will never be called with a null state. + * Hook allowing a Preference to re-apply a representation of its internal state that had + * previously been generated by {@link #onSaveInstanceState}. This function will never be called + * with a {@code null} state. * * @param state The saved state that had previously been returned by * {@link #onSaveInstanceState}. diff --git a/core/java/android/preference/PreferenceManager.java b/core/java/android/preference/PreferenceManager.java index 14b748a9c6df0..ea32dfd7f919f 100644 --- a/core/java/android/preference/PreferenceManager.java +++ b/core/java/android/preference/PreferenceManager.java @@ -93,8 +93,8 @@ public class PreferenceManager { private SharedPreferences mSharedPreferences; /** - * Data store to be used by the Preferences or null if {@link android.content.SharedPreferences} - * should be used. + * Data store to be used by the Preferences or {@code null} if + * {@link android.content.SharedPreferences} should be used. */ @Nullable private PreferenceDataStore mPreferenceDataStore; @@ -484,11 +484,16 @@ public class PreferenceManager { /** * Gets a {@link SharedPreferences} instance that preferences managed by this will use. * - * @return A {@link SharedPreferences} instance pointing to the file that contains the values of - * preferences that are managed by this or null if {@link PreferenceDataStore} is used instead. + * @return a {@link SharedPreferences} instance pointing to the file that contains the values of + * preferences that are managed by this PreferenceManager. If a + * {@link PreferenceDataStore} has been set, this method returns {@code null}. */ public SharedPreferences getSharedPreferences() { - if (mSharedPreferences == null && getPreferenceDataStore() == null) { + if (mPreferenceDataStore != null) { + return null; + } + + if (mSharedPreferences == null) { final Context storageContext; switch (mStorage) { case STORAGE_DEVICE_PROTECTED: @@ -564,8 +569,8 @@ public class PreferenceManager { /** * Finds a {@link Preference} based on its key. * - * @param key The key of the preference to retrieve. - * @return The {@link Preference} with the key, or null. + * @param key the key of the preference to retrieve + * @return the {@link Preference} with the key, or {@code null} * @see PreferenceGroup#findPreference(CharSequence) */ @Nullable @@ -659,11 +664,11 @@ public class PreferenceManager { /** * Returns an editor to use when modifying the shared preferences. - *

- * Do NOT commit unless {@link #shouldCommit()} returns true. * - * @return An editor to use to write to shared preferences or null if - * {@link PreferenceDataStore} is used instead. + *

Do NOT commit unless {@link #shouldCommit()} returns true. + * + * @return an editor to use to write to shared preferences. If a {@link PreferenceDataStore} + * has been set, this method returns {@code null}. * @see #shouldCommit() */ SharedPreferences.Editor getEditor() { @@ -687,6 +692,8 @@ public class PreferenceManager { * {@link #getEditor()}. This will return false in cases where the writes * should be batched, for example when inflating preferences from XML. * + *

If preferences are using {@link PreferenceDataStore} this value is irrelevant. + * * @return Whether the client should commit. */ boolean shouldCommit() { @@ -711,8 +718,8 @@ public class PreferenceManager { * Returns the activity that shows the preferences. This is useful for doing * managed queries, but in most cases the use of {@link #getContext()} is * preferred. - *

- * This will return null if this class was instantiated with a Context + * + *

This will return {@code null} if this class was instantiated with a Context * instead of Activity. For example, when setting the default values. * * @return The activity that shows the preferences.