aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorShraddha Basantwani <shraddha.basantwani@ittiam.com>2019-06-03 12:03:31 -0700
committerNick Chalko <nchalko@google.com>2019-06-03 14:45:33 -0700
commitfd00ae2153903dfc5ec1ce4c2a04123c02643e89 (patch)
tree52ffe6134b039a54f4fddddb4d4b6c3674d57ace /common
parent64814d0026e1a5e065817fe65ce34a1440e690fa (diff)
downloadTV-fd00ae2153903dfc5ec1ce4c2a04123c02643e89.tar.gz
Replace SystemProperties with DeveloperPreference
Reduce usage of BooleanSystemProperty. END_PUBLIC Bug=80084809 Live Channels: Import of http://pa/1354302 Change-Id: Iec9d6793f22103f0ec2bfda7f0c96eb687c03669 PiperOrigin-RevId: 251280651
Diffstat (limited to 'common')
-rw-r--r--common/src/com/android/tv/common/BaseApplication.java6
-rw-r--r--common/src/com/android/tv/common/dev/DeveloperPreference.java126
-rw-r--r--common/src/com/android/tv/common/dev/DeveloperPreferences.java71
-rw-r--r--common/src/com/android/tv/common/feature/CommonFeatures.java4
-rw-r--r--common/src/com/android/tv/common/feature/DeveloperPreferenceFeature.java59
-rw-r--r--common/src/com/android/tv/common/util/SystemProperties.java19
6 files changed, 263 insertions, 22 deletions
diff --git a/common/src/com/android/tv/common/BaseApplication.java b/common/src/com/android/tv/common/BaseApplication.java
index 27e95b7b..84fcc310 100644
--- a/common/src/com/android/tv/common/BaseApplication.java
+++ b/common/src/com/android/tv/common/BaseApplication.java
@@ -21,12 +21,14 @@ import android.content.Context;
import android.os.Build;
import android.os.StrictMode;
import android.support.annotation.VisibleForTesting;
+
+import com.android.tv.common.dev.DeveloperPreferences;
import com.android.tv.common.feature.CommonFeatures;
import com.android.tv.common.recording.RecordingStorageStatusManager;
import com.android.tv.common.util.Clock;
import com.android.tv.common.util.CommonUtils;
import com.android.tv.common.util.Debug;
-import com.android.tv.common.util.SystemProperties;
+
import dagger.android.DaggerApplication;
/** The base application class for TV applications. */
@@ -65,7 +67,7 @@ public abstract class BaseApplication extends DaggerApplication implements BaseS
// Only set StrictMode for ENG builds because the build server only produces userdebug
// builds.
- if (BuildConfig.ENG && SystemProperties.ALLOW_STRICT_MODE.getValue()) {
+ if (BuildConfig.ENG && DeveloperPreferences.ALLOW_STRICT_MODE.get(this)) {
StrictMode.ThreadPolicy.Builder threadPolicyBuilder =
new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog();
// TODO(b/69565157): Turn penaltyDeath on for VMPolicy when tests are fixed.
diff --git a/common/src/com/android/tv/common/dev/DeveloperPreference.java b/common/src/com/android/tv/common/dev/DeveloperPreference.java
new file mode 100644
index 00000000..8985500f
--- /dev/null
+++ b/common/src/com/android/tv/common/dev/DeveloperPreference.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.tv.common.dev;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.support.annotation.VisibleForTesting;
+
+/** Preferences available to developers */
+public abstract class DeveloperPreference<T> {
+
+ private static final String PREFERENCE_FILE_NAME =
+ "com.android.tv.common.dev.DeveloperPreference";
+
+ /**
+ * Create a boolean developer preference.
+ *
+ * @param key the developer setting key.
+ * @param defaultValue the value to return if the setting is undefined or empty.
+ */
+ public static DeveloperPreference<Boolean> create(String key, boolean defaultValue) {
+ return new DeveloperBooleanPreference(key, defaultValue);
+ }
+
+ @VisibleForTesting
+ static final SharedPreferences getPreferences(Context context) {
+ return context.getSharedPreferences(PREFERENCE_FILE_NAME, Context.MODE_PRIVATE);
+ }
+
+ /**
+ * Create a int developer preference.
+ *
+ * @param key the developer setting key.
+ * @param defaultValue the value to return if the setting is undefined or empty.
+ */
+ public static DeveloperPreference<Integer> create(String key, int defaultValue) {
+ return new DeveloperIntegerPreference(key, defaultValue);
+ }
+
+ final String mKey;
+ final T mDefaultValue;
+ private T mValue;
+
+ private DeveloperPreference(String key, T defaultValue) {
+ mKey = key;
+ mValue = null;
+ mDefaultValue = defaultValue;
+ }
+
+ /** Set the value. */
+ public final void set(Context context, T value) {
+ mValue = value;
+ storeValue(context, value);
+ }
+
+ protected abstract void storeValue(Context context, T value);
+
+ /** Get the current value, or the default if the value is not set. */
+ public final T get(Context context) {
+ mValue = getStoredValue(context);
+ return mValue;
+ }
+
+ protected abstract T getStoredValue(Context context);
+
+ /**
+ * Clears the current value.
+ *
+ * <p>Future calls to {@link #get(Context)} will return the default value.
+ */
+ public final void clear(Context context) {
+ getPreferences(context).edit().remove(mKey);
+ }
+
+ @Override
+ public final String toString() {
+ return "[" + mKey + "]=" + mValue + " Default value : " + mDefaultValue;
+ }
+
+ private static final class DeveloperBooleanPreference extends DeveloperPreference<Boolean> {
+
+ private DeveloperBooleanPreference(String key, Boolean defaultValue) {
+ super(key, defaultValue);
+ }
+
+ @Override
+ public void storeValue(Context context, Boolean value) {
+ getPreferences(context).edit().putBoolean(mKey, value).apply();
+ }
+
+ @Override
+ public Boolean getStoredValue(Context context) {
+ return getPreferences(context).getBoolean(mKey, mDefaultValue);
+ }
+ }
+
+ private static final class DeveloperIntegerPreference extends DeveloperPreference<Integer> {
+
+ private DeveloperIntegerPreference(String key, Integer defaultValue) {
+ super(key, defaultValue);
+ }
+
+ @Override
+ protected void storeValue(Context context, Integer value) {
+ getPreferences(context).edit().putInt(mKey, value).apply();
+ }
+
+ @Override
+ protected Integer getStoredValue(Context context) {
+ return getPreferences(context).getInt(mKey, mDefaultValue);
+ }
+ }
+}
diff --git a/common/src/com/android/tv/common/dev/DeveloperPreferences.java b/common/src/com/android/tv/common/dev/DeveloperPreferences.java
new file mode 100644
index 00000000..9c83b649
--- /dev/null
+++ b/common/src/com/android/tv/common/dev/DeveloperPreferences.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.tv.common.dev;
+
+/** A class about the constants for TV Developer preferences. */
+public final class DeveloperPreferences {
+
+ /**
+ * Allow Google Analytics for eng builds.
+ *
+ * <p>Defaults to {@code false}.
+ */
+ public static final DeveloperPreference<Boolean> ALLOW_ANALYTICS_IN_ENG =
+ DeveloperPreference.create("tv_allow_analytics_in_eng", false);
+
+ /**
+ * Allow Strict mode for debug builds.
+ *
+ * <p>Defaults to {@code true}.
+ */
+ public static final DeveloperPreference<Boolean> ALLOW_STRICT_MODE =
+ DeveloperPreference.create("tv_allow_strict_mode", true);
+
+ /**
+ * When true {@link android.view.KeyEvent}s are logged.
+ *
+ * <p>Defaults to {@code false}.
+ */
+ public static final DeveloperPreference<Boolean> LOG_KEYEVENT =
+ DeveloperPreference.create("tv_log_keyevent", false);
+
+ /**
+ * When true debug keys are used.
+ *
+ * <p>Defaults to {@code false}.
+ */
+ public static final DeveloperPreference<Boolean> USE_DEBUG_KEYS =
+ DeveloperPreference.create("tv_use_debug_keys", false);
+
+ /**
+ * Send {@link com.android.tv.analytics.Tracker} information.
+ *
+ * <p>Defaults to {@code true}.
+ */
+ public static final DeveloperPreference<Boolean> USE_TRACKER =
+ DeveloperPreference.create("tv_use_tracker", true);
+
+ /**
+ * Maximum buffer size in MegaBytes.
+ *
+ * <p>Defaults to 2MB.
+ */
+ public static final DeveloperPreference<Integer> MAX_BUFFER_SIZE_MBYTES =
+ DeveloperPreference.create("tv.tuner.buffersize_mbytes", 2 * 1024);
+
+ private DeveloperPreferences() {}
+}
diff --git a/common/src/com/android/tv/common/feature/CommonFeatures.java b/common/src/com/android/tv/common/feature/CommonFeatures.java
index f79965bb..abe4c1df 100644
--- a/common/src/com/android/tv/common/feature/CommonFeatures.java
+++ b/common/src/com/android/tv/common/feature/CommonFeatures.java
@@ -23,8 +23,10 @@ import static com.android.tv.common.feature.TestableFeature.createTestableFeatur
import android.content.Context;
import android.util.Log;
+
import com.android.tv.common.flags.has.HasCloudEpgFlags;
import com.android.tv.common.util.LocationUtils;
+
import com.android.tv.common.flags.CloudEpgFlags;
/**
@@ -52,7 +54,7 @@ public class CommonFeatures {
* <p>Enables dvr recording regardless of storage status.
*/
public static final Feature FORCE_RECORDING_UNTIL_NO_SPACE =
- PropertyFeature.create("force_recording_until_no_space", false);
+ DeveloperPreferenceFeature.create("force_recording_until_no_space", false);
/** Show postal code fragment before channel scan. */
public static final Feature ENABLE_CLOUD_EPG_REGION =
diff --git a/common/src/com/android/tv/common/feature/DeveloperPreferenceFeature.java b/common/src/com/android/tv/common/feature/DeveloperPreferenceFeature.java
new file mode 100644
index 00000000..1f98547a
--- /dev/null
+++ b/common/src/com/android/tv/common/feature/DeveloperPreferenceFeature.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.tv.common.feature;
+
+import android.content.Context;
+
+import com.android.tv.common.dev.DeveloperPreference;
+
+/** A {@link Feature} based on {@link DeveloperPreference<Boolean>}. */
+public class DeveloperPreferenceFeature implements Feature {
+
+ private final DeveloperPreference<Boolean> mPreference;
+
+ /**
+ * Create a developer preference feature.
+ *
+ * @param key the developer setting key.
+ * @param defaultValue the value to return if the setting is undefined or empty.
+ */
+ public static DeveloperPreferenceFeature create(String key, boolean defaultValue) {
+ return from(DeveloperPreference.create(key, defaultValue));
+ }
+
+ /**
+ * Create a developer preference feature from an exiting {@link DeveloperPreference<Boolean>}.
+ */
+ public static DeveloperPreferenceFeature from(
+ DeveloperPreference<Boolean> developerPreference) {
+ return new DeveloperPreferenceFeature(developerPreference);
+ }
+
+ private DeveloperPreferenceFeature(DeveloperPreference<Boolean> mPreference) {
+ this.mPreference = mPreference;
+ }
+
+ @Override
+ public boolean isEnabled(Context context) {
+ return mPreference.get(context);
+ }
+
+ @Override
+ public String toString() {
+ return mPreference.toString();
+ }
+}
diff --git a/common/src/com/android/tv/common/util/SystemProperties.java b/common/src/com/android/tv/common/util/SystemProperties.java
index 6ac2907b..72920b6b 100644
--- a/common/src/com/android/tv/common/util/SystemProperties.java
+++ b/common/src/com/android/tv/common/util/SystemProperties.java
@@ -21,25 +21,6 @@ import com.android.tv.common.BooleanSystemProperty;
/** A convenience class for getting TV related system properties. */
public final class SystemProperties {
- /** Allow Google Analytics for eng builds. */
- public static final BooleanSystemProperty ALLOW_ANALYTICS_IN_ENG =
- new BooleanSystemProperty("tv_allow_analytics_in_eng", false);
-
- /** Allow Strict mode for debug builds. */
- public static final BooleanSystemProperty ALLOW_STRICT_MODE =
- new BooleanSystemProperty("tv_allow_strict_mode", true);
-
- /** When true {@link android.view.KeyEvent}s are logged. Defaults to false. */
- public static final BooleanSystemProperty LOG_KEYEVENT =
- new BooleanSystemProperty("tv_log_keyevent", false);
- /** When true debug keys are used. Defaults to false. */
- public static final BooleanSystemProperty USE_DEBUG_KEYS =
- new BooleanSystemProperty("tv_use_debug_keys", false);
-
- /** Send {@link com.android.tv.analytics.Tracker} information. Defaults to {@code true}. */
- public static final BooleanSystemProperty USE_TRACKER =
- new BooleanSystemProperty("tv_use_tracker", true);
-
/** Allow third party inputs. */
public static final BooleanSystemProperty ALLOW_THIRD_PARTY_INPUTS =
new BooleanSystemProperty("ro.tv_allow_third_party_inputs", true);