aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornchalko <nchalko@google.com>2018-10-04 10:49:59 -0700
committerNick Chalko <nchalko@google.com>2018-10-04 13:58:02 -0700
commitf853a1980c2aff838a8efffb373c0cf299d8893d (patch)
tree6128e717cfc9a9e24710266a8be867133912c8df
parent806d636ffc7b86c18bbb402263f05ab4b3878f4d (diff)
downloadTV-f853a1980c2aff838a8efffb373c0cf299d8893d.tar.gz
Migrate live_channels_enable_cloud_epg_region to phenotype
PiperOrigin-RevId: 215765335 Change-Id: I0d87b78929395854a45f8498c9304edcd8226e60
-rw-r--r--common/src/com/android/tv/common/BaseSingletons.java3
-rw-r--r--common/src/com/android/tv/common/config/RemoteConfigFeature.java42
-rw-r--r--common/src/com/android/tv/common/feature/CommonFeatures.java5
-rw-r--r--common/src/com/android/tv/common/feature/FlagFeature.java31
-rwxr-xr-xcommon/src/com/android/tv/common/flags/CloudEpgFlags.java35
-rw-r--r--common/src/com/android/tv/common/flags/has/HasCloudEpgFlags.java29
-rw-r--r--common/src/com/android/tv/common/flags/impl/DefaultCloudEpgFlags.java32
-rw-r--r--src/com/android/tv/app/LiveTvApplication.java7
-rw-r--r--tests/common/src/com/android/tv/testing/TestSingletonApp.java7
-rw-r--r--tests/unit/src/com/android/tv/util/MockTvSingletons.java7
-rw-r--r--tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTuner.java7
11 files changed, 161 insertions, 44 deletions
diff --git a/common/src/com/android/tv/common/BaseSingletons.java b/common/src/com/android/tv/common/BaseSingletons.java
index e735cdb4..d0a92c2b 100644
--- a/common/src/com/android/tv/common/BaseSingletons.java
+++ b/common/src/com/android/tv/common/BaseSingletons.java
@@ -19,11 +19,12 @@ package com.android.tv.common;
import android.content.Context;
import android.content.Intent;
import com.android.tv.common.config.api.RemoteConfig.HasRemoteConfig;
+import com.android.tv.common.flags.has.HasCloudEpgFlags;
import com.android.tv.common.recording.RecordingStorageStatusManager;
import com.android.tv.common.util.Clock;
/** Injection point for the base app */
-public interface BaseSingletons extends HasRemoteConfig {
+public interface BaseSingletons extends HasRemoteConfig, HasCloudEpgFlags {
Clock getClock();
diff --git a/common/src/com/android/tv/common/config/RemoteConfigFeature.java b/common/src/com/android/tv/common/config/RemoteConfigFeature.java
deleted file mode 100644
index bf6d107c..00000000
--- a/common/src/com/android/tv/common/config/RemoteConfigFeature.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2016 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.config;
-
-import android.content.Context;
-import com.android.tv.common.config.api.RemoteConfig.HasRemoteConfig;
-import com.android.tv.common.feature.Feature;
-
-/**
- * A {@link Feature} controlled by a {@link com.android.tv.common.config.api.RemoteConfig} boolean.
- */
-public class RemoteConfigFeature implements Feature {
- private final String mKey;
-
- /** Creates a {@link RemoteConfigFeature for the {@code key}. */
- public static RemoteConfigFeature fromKey(String key) {
- return new RemoteConfigFeature(key);
- }
-
- private RemoteConfigFeature(String key) {
- mKey = key;
- }
-
- @Override
- public boolean isEnabled(Context context) {
- return ((HasRemoteConfig) context).getRemoteConfig().getBoolean(mKey);
- }
-}
diff --git a/common/src/com/android/tv/common/feature/CommonFeatures.java b/common/src/com/android/tv/common/feature/CommonFeatures.java
index dd217b47..56a88e93 100644
--- a/common/src/com/android/tv/common/feature/CommonFeatures.java
+++ b/common/src/com/android/tv/common/feature/CommonFeatures.java
@@ -23,9 +23,10 @@ import static com.android.tv.common.feature.TestableFeature.createTestableFeatur
import android.content.Context;
import android.util.Log;
-import com.android.tv.common.config.RemoteConfigFeature;
import com.android.tv.common.experiments.Experiments;
+import com.android.tv.common.flags.has.HasCloudEpgFlags;
import com.android.tv.common.util.LocationUtils;
+import com.android.tv.common.flags.CloudEpgFlags;
/**
* List of {@link Feature} that affect more than just the Live TV app.
@@ -59,6 +60,8 @@ public class CommonFeatures {
and(
ExperimentFeature.from(Experiments.CLOUD_EPG),
or(
+ FlagFeature.from(
+ HasCloudEpgFlags::fromContext, CloudEpgFlags::supportedRegion),
new Feature() {
private final String[] supportedRegions = {
};
diff --git a/common/src/com/android/tv/common/feature/FlagFeature.java b/common/src/com/android/tv/common/feature/FlagFeature.java
new file mode 100644
index 00000000..a1ec7e61
--- /dev/null
+++ b/common/src/com/android/tv/common/feature/FlagFeature.java
@@ -0,0 +1,31 @@
+package com.android.tv.common.feature;
+
+import android.content.Context;
+import com.google.common.base.Function;
+
+/** Feature from a Flag */
+public class FlagFeature<T> implements Feature {
+
+ private final Function<Context, T> mToFlag;
+ private final Function<T, Boolean> mToBoolean;
+
+ public static <T> FlagFeature<T> from(
+ Function<Context, T> toFlag, Function<T, Boolean> toBoolean) {
+ return new FlagFeature<T>(toFlag, toBoolean);
+ }
+
+ private FlagFeature(Function<Context, T> toFlag, Function<T, Boolean> toBoolean) {
+ mToFlag = toFlag;
+ mToBoolean = toBoolean;
+ }
+
+ @Override
+ public boolean isEnabled(Context context) {
+ return mToBoolean.apply(mToFlag.apply(context));
+ }
+
+ @Override
+ public String toString() {
+ return mToBoolean.toString();
+ }
+}
diff --git a/common/src/com/android/tv/common/flags/CloudEpgFlags.java b/common/src/com/android/tv/common/flags/CloudEpgFlags.java
new file mode 100755
index 00000000..11417966
--- /dev/null
+++ b/common/src/com/android/tv/common/flags/CloudEpgFlags.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2018 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.flags;
+
+/** Flags for Cloud EPG */
+public interface CloudEpgFlags {
+
+ /**
+ * Whether or not this feature is compiled into this build.
+ *
+ * <p>If the macro which generated this code does not have condtional_compilation_enabled as
+ * true, then this always returns true.
+ *
+ * <p>If the macro which generated this code does have conditional_compilation_enabled as true,
+ * this will return true or false depending on the value of the corresponding
+ * config_feature_flag controlling this feature. See go/phenotype-compile-time-features.
+ */
+ boolean compiled();
+
+ /** Is the device in a region supported by Cloud Epg */
+ boolean supportedRegion();
+}
diff --git a/common/src/com/android/tv/common/flags/has/HasCloudEpgFlags.java b/common/src/com/android/tv/common/flags/has/HasCloudEpgFlags.java
new file mode 100644
index 00000000..3061e31d
--- /dev/null
+++ b/common/src/com/android/tv/common/flags/has/HasCloudEpgFlags.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2018 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.flags.has;
+
+import android.content.Context;
+import com.android.tv.common.flags.CloudEpgFlags;
+
+/** Has {@link CloudEpgFlags} */
+public interface HasCloudEpgFlags {
+
+ static CloudEpgFlags fromContext(Context context) {
+ return (CloudEpgFlags) context;
+ }
+
+ CloudEpgFlags getCloudEpgFlags();
+}
diff --git a/common/src/com/android/tv/common/flags/impl/DefaultCloudEpgFlags.java b/common/src/com/android/tv/common/flags/impl/DefaultCloudEpgFlags.java
new file mode 100644
index 00000000..b4348dde
--- /dev/null
+++ b/common/src/com/android/tv/common/flags/impl/DefaultCloudEpgFlags.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2018 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.flags.impl;
+
+import com.android.tv.common.flags.CloudEpgFlags;
+
+/** Default flags for Cloud EPG */
+public final class DefaultCloudEpgFlags implements CloudEpgFlags {
+
+ @Override
+ public boolean compiled() {
+ return true;
+ }
+
+ @Override
+ public boolean supportedRegion() {
+ return false;
+ }
+}
diff --git a/src/com/android/tv/app/LiveTvApplication.java b/src/com/android/tv/app/LiveTvApplication.java
index da9eb85e..8ae7fdec 100644
--- a/src/com/android/tv/app/LiveTvApplication.java
+++ b/src/com/android/tv/app/LiveTvApplication.java
@@ -30,6 +30,7 @@ import com.android.tv.common.config.DefaultConfigManager;
import com.android.tv.common.config.api.RemoteConfig;
import com.android.tv.common.experiments.ExperimentLoader;
import com.android.tv.common.flags.impl.DefaultBackendKnobsFlags;
+import com.android.tv.common.flags.impl.DefaultCloudEpgFlags;
import com.android.tv.common.util.CommonUtils;
import com.android.tv.data.epg.EpgReader;
import com.android.tv.data.epg.StubEpgReader;
@@ -63,6 +64,7 @@ public class LiveTvApplication extends TvApplication {
private final Optional<TunerInputController> mOptionalTunerInputController = Optional.absent();
private final DefaultBackendKnobsFlags mBackendKnobsFlags = new DefaultBackendKnobsFlags();
+ private final DefaultCloudEpgFlags mCloudEpgFlags = new DefaultCloudEpgFlags();
private AccountHelper mAccountHelper;
private Analytics mAnalytics;
private Tracker mTracker;
@@ -152,6 +154,11 @@ public class LiveTvApplication extends TvApplication {
}
@Override
+ public DefaultCloudEpgFlags getCloudEpgFlags() {
+ return mCloudEpgFlags;
+ }
+
+ @Override
public RemoteConfig getRemoteConfig() {
if (mRemoteConfig == null) {
// No need to synchronize this, it does not hurt to create two and throw one away.
diff --git a/tests/common/src/com/android/tv/testing/TestSingletonApp.java b/tests/common/src/com/android/tv/testing/TestSingletonApp.java
index ac3e5141..00dccb45 100644
--- a/tests/common/src/com/android/tv/testing/TestSingletonApp.java
+++ b/tests/common/src/com/android/tv/testing/TestSingletonApp.java
@@ -30,6 +30,7 @@ import com.android.tv.common.BaseApplication;
import com.android.tv.common.config.api.RemoteConfig;
import com.android.tv.common.experiments.ExperimentLoader;
import com.android.tv.common.flags.impl.DefaultBackendKnobsFlags;
+import com.android.tv.common.flags.impl.DefaultCloudEpgFlags;
import com.android.tv.common.recording.RecordingStorageStatusManager;
import com.android.tv.common.util.Clock;
import com.android.tv.data.ChannelDataManager;
@@ -69,6 +70,7 @@ public class TestSingletonApp extends Application implements TvSingletons {
private final Provider<EpgReader> mEpgReaderProvider = SingletonProvider.create(epgReader);
private final Optional<TunerInputController> mOptionalTunerInputController = Optional.absent();
private final DefaultBackendKnobsFlags mBackendKnobs = new DefaultBackendKnobsFlags();
+ private final DefaultCloudEpgFlags mCloudEpgFlags = new DefaultCloudEpgFlags();
private PerformanceMonitor mPerformanceMonitor;
private ChannelDataManager mChannelDataManager;
@@ -247,4 +249,9 @@ public class TestSingletonApp extends Application implements TvSingletons {
public DefaultBackendKnobsFlags getBackendKnobs() {
return mBackendKnobs;
}
+
+ @Override
+ public DefaultCloudEpgFlags getCloudEpgFlags() {
+ return mCloudEpgFlags;
+ }
}
diff --git a/tests/unit/src/com/android/tv/util/MockTvSingletons.java b/tests/unit/src/com/android/tv/util/MockTvSingletons.java
index 78ac87c3..db6a829e 100644
--- a/tests/unit/src/com/android/tv/util/MockTvSingletons.java
+++ b/tests/unit/src/com/android/tv/util/MockTvSingletons.java
@@ -27,6 +27,7 @@ import com.android.tv.analytics.Tracker;
import com.android.tv.common.config.api.RemoteConfig;
import com.android.tv.common.experiments.ExperimentLoader;
import com.android.tv.common.flags.impl.DefaultBackendKnobsFlags;
+import com.android.tv.common.flags.impl.DefaultCloudEpgFlags;
import com.android.tv.common.recording.RecordingStorageStatusManager;
import com.android.tv.common.util.Clock;
import com.android.tv.data.ChannelDataManager;
@@ -52,6 +53,7 @@ public class MockTvSingletons implements TvSingletons {
private final TvApplication mApp;
private final DefaultBackendKnobsFlags mBackendFlags = new DefaultBackendKnobsFlags();
+ private final DefaultCloudEpgFlags mCloudEpgFlags = new DefaultCloudEpgFlags();
private PerformanceMonitor mPerformanceMonitor;
public MockTvSingletons(Context context) {
@@ -206,6 +208,11 @@ public class MockTvSingletons implements TvSingletons {
}
@Override
+ public DefaultCloudEpgFlags getCloudEpgFlags() {
+ return mCloudEpgFlags;
+ }
+
+ @Override
public Executor getDbExecutor() {
return mApp.getDbExecutor();
}
diff --git a/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTuner.java b/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTuner.java
index 15e90437..54fac612 100644
--- a/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTuner.java
+++ b/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTuner.java
@@ -24,6 +24,7 @@ import com.android.tv.common.BaseApplication;
import com.android.tv.common.actions.InputSetupActionUtils;
import com.android.tv.common.config.DefaultConfigManager;
import com.android.tv.common.config.api.RemoteConfig;
+import com.android.tv.common.flags.impl.DefaultCloudEpgFlags;
import com.android.tv.common.util.CommonUtils;
import com.android.tv.tuner.sample.dvb.tvinput.SampleDvbTunerTvInputService;
import com.android.tv.tuner.setup.LiveTvTunerSetupActivity;
@@ -32,6 +33,7 @@ import com.android.tv.tuner.setup.LiveTvTunerSetupActivity;
public class SampleDvbTuner extends BaseApplication {
private String mEmbeddedInputId;
private RemoteConfig mRemoteConfig;
+ private final DefaultCloudEpgFlags mCloudEpgFlags = new DefaultCloudEpgFlags();
@Override
public Intent getTunerSetupIntent(Context context) {
@@ -61,4 +63,9 @@ public class SampleDvbTuner extends BaseApplication {
}
return mRemoteConfig;
}
+
+ @Override
+ public DefaultCloudEpgFlags getCloudEpgFlags() {
+ return mCloudEpgFlags;
+ }
}