diff options
author | Shraddha Basantwani <shraddha.basantwani@ittiam.com> | 2019-06-26 18:04:44 -0700 |
---|---|---|
committer | Nick Chalko <nchalko@google.com> | 2019-06-26 19:43:47 -0700 |
commit | 6bf36a5ac83aba3f12e964028ef8cbb8b0f62166 (patch) | |
tree | 9c7251ee5905690d229be6d736ec82405ec1a890 /common | |
parent | 27499616833b42c54b9169b6660aae23536868ff (diff) | |
download | TV-6bf36a5ac83aba3f12e964028ef8cbb8b0f62166.tar.gz |
Fix: Handle null context for DeveloperPreference
Test: adb shell monkey -p com.android.tv -v 10000
Live Channels: Import of 1388194
Bug: 135078192
Change-Id: Ie7c931bc5fe9d82e5876a767609a95e548b1e54d
PiperOrigin-RevId: 255303793
Diffstat (limited to 'common')
-rw-r--r-- | common/src/com/android/tv/common/dev/DeveloperPreference.java | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/common/src/com/android/tv/common/dev/DeveloperPreference.java b/common/src/com/android/tv/common/dev/DeveloperPreference.java index 8985500f..b1c401b0 100644 --- a/common/src/com/android/tv/common/dev/DeveloperPreference.java +++ b/common/src/com/android/tv/common/dev/DeveloperPreference.java @@ -17,6 +17,7 @@ package com.android.tv.common.dev; import android.content.Context; import android.content.SharedPreferences; +import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; /** Preferences available to developers */ @@ -74,6 +75,11 @@ public abstract class DeveloperPreference<T> { return mValue; } + /** Get the current value, or the default if the value is not set or context is null. */ + public final T getDefaultIfContextNull(@Nullable Context context) { + return context == null ? mDefaultValue : getStoredValue(context); + } + protected abstract T getStoredValue(Context context); /** |