diff options
Diffstat (limited to 'common/src')
58 files changed, 376 insertions, 1187 deletions
diff --git a/common/src/com/android/tv/common/BaseApplication.java b/common/src/com/android/tv/common/BaseApplication.java index 1a421209..45c32567 100644 --- a/common/src/com/android/tv/common/BaseApplication.java +++ b/common/src/com/android/tv/common/BaseApplication.java @@ -21,22 +21,17 @@ 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 dagger.Lazy; +import com.android.tv.common.util.SystemProperties; import dagger.android.DaggerApplication; -import javax.inject.Inject; - -/** The base application class for TV applications. */ +/** The base application class for Live TV applications. */ public abstract class BaseApplication extends DaggerApplication implements BaseSingletons { - @Inject Lazy<RecordingStorageStatusManager> mRecordingStorageStatusManager; + private RecordingStorageStatusManager mRecordingStorageStatusManager; /** * An instance of {@link BaseSingletons}. Note that this can be set directly only for the test @@ -70,7 +65,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 && DeveloperPreferences.ALLOW_STRICT_MODE.get(this)) { + if (BuildConfig.ENG && SystemProperties.ALLOW_STRICT_MODE.getValue()) { StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog(); // TODO(b/69565157): Turn penaltyDeath on for VMPolicy when tests are fixed. @@ -104,6 +99,9 @@ public abstract class BaseApplication extends DaggerApplication implements BaseS @Override @TargetApi(Build.VERSION_CODES.N) public RecordingStorageStatusManager getRecordingStorageStatusManager() { - return mRecordingStorageStatusManager.get(); + if (mRecordingStorageStatusManager == null) { + mRecordingStorageStatusManager = new RecordingStorageStatusManager(this); + } + return mRecordingStorageStatusManager; } } diff --git a/common/src/com/android/tv/common/BaseSingletons.java b/common/src/com/android/tv/common/BaseSingletons.java index 8a3820d1..10530617 100644 --- a/common/src/com/android/tv/common/BaseSingletons.java +++ b/common/src/com/android/tv/common/BaseSingletons.java @@ -18,28 +18,15 @@ package com.android.tv.common; import com.android.tv.common.buildtype.HasBuildType; import com.android.tv.common.flags.has.HasCloudEpgFlags; +import com.android.tv.common.flags.has.HasConcurrentDvrPlaybackFlags; import com.android.tv.common.recording.RecordingStorageStatusManager; import com.android.tv.common.util.Clock; /** Injection point for the base app */ -public interface BaseSingletons extends HasCloudEpgFlags, HasBuildType { +public interface BaseSingletons + extends HasCloudEpgFlags, HasBuildType, HasConcurrentDvrPlaybackFlags { - /* - * Do not add any new methods here. - * - * To move a getter to Injection. - * 1. Make a type injectable @Singleton. - * 2. Mark the getter here as deprecated. - * 3. Lazily inject the object in TvApplication. - * 4. Move easy usages of getters to injection instead. - * 5. Delete the method when all usages are migrated. - */ - - /* @deprecated use injection instead. */ - @Deprecated Clock getClock(); - /* @deprecated use injection instead. */ - @Deprecated RecordingStorageStatusManager getRecordingStorageStatusManager(); } diff --git a/common/src/com/android/tv/common/buildtype/BuildTypeFactory.java b/common/src/com/android/tv/common/buildtype/BuildTypeFactory.java deleted file mode 100644 index 706a6034..00000000 --- a/common/src/com/android/tv/common/buildtype/BuildTypeFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.buildtype; - -import com.google.common.base.Supplier; - -import javax.inject.Inject; - - -/** Factory for {@link HasBuildType.BuildType}. - * - * <p>Hardcoded to {@link HasBuildType.BuildType#AOSP}. - */ -public class BuildTypeFactory implements Supplier<HasBuildType> { - private static final HasBuildType INSTANCE = new AospBuildTypeProvider(); - - @Inject - public BuildTypeFactory() {} - - public static HasBuildType create() { - return INSTANCE; - } - - @Override - public HasBuildType get() { - return INSTANCE; - } -}
\ No newline at end of file diff --git a/common/src/com/android/tv/common/buildtype/BuildTypeModule.java b/common/src/com/android/tv/common/buildtype/BuildTypeModule.java deleted file mode 100644 index 43f398d5..00000000 --- a/common/src/com/android/tv/common/buildtype/BuildTypeModule.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.buildtype; - -import dagger.Module; -import dagger.Provides; -import dagger.Reusable; - -/** Provides BuildType */ -@Module -public class BuildTypeModule { - private static final HasBuildType.BuildType BUILD_TYPE = - BuildTypeFactory.create().getBuildType(); - - @Provides - @Reusable - HasBuildType.BuildType providesBuildType() { - return BUILD_TYPE; - } -} diff --git a/common/src/com/android/tv/common/buildtype/HasBuildType.java b/common/src/com/android/tv/common/buildtype/HasBuildType.java index addac07e..7d5677c9 100644 --- a/common/src/com/android/tv/common/buildtype/HasBuildType.java +++ b/common/src/com/android/tv/common/buildtype/HasBuildType.java @@ -30,7 +30,5 @@ public interface HasBuildType { PROD } - /** @deprecated use injection instead. */ - @Deprecated BuildType getBuildType(); } diff --git a/common/src/com/android/tv/common/compat/TvInputInfoCompat.java b/common/src/com/android/tv/common/compat/TvInputInfoCompat.java index 2f06d943..685a3ed9 100644 --- a/common/src/com/android/tv/common/compat/TvInputInfoCompat.java +++ b/common/src/com/android/tv/common/compat/TvInputInfoCompat.java @@ -45,12 +45,13 @@ public class TvInputInfoCompat { private final Context mContext; private final TvInputInfo mTvInputInfo; - private boolean mAudioOnly; - private boolean mAudioAttributeInit = false; + private final boolean mAudioOnly; public TvInputInfoCompat(Context context, TvInputInfo tvInputInfo) { mContext = context; mTvInputInfo = tvInputInfo; + // TODO(b/112938832): use tvInputInfo.isAudioOnly() when SDK is updated + mAudioOnly = Boolean.parseBoolean(getExtras().get(ATTRIBUTE_NAME_AUDIO_ONLY)); } public TvInputInfo getTvInputInfo() { @@ -58,11 +59,6 @@ public class TvInputInfoCompat { } public boolean isAudioOnly() { - // TODO(b/112938832): use tvInputInfo.isAudioOnly() when SDK is updated - if (!mAudioAttributeInit) { - mAudioOnly = Boolean.parseBoolean(getExtras().get(ATTRIBUTE_NAME_AUDIO_ONLY)); - mAudioAttributeInit = true; - } return mAudioOnly; } diff --git a/common/src/com/android/tv/common/compat/internal/recording_commands.proto b/common/src/com/android/tv/common/compat/internal/recording_commands.proto index c247e781..ce59bfa0 100644 --- a/common/src/com/android/tv/common/compat/internal/recording_commands.proto +++ b/common/src/com/android/tv/common/compat/internal/recording_commands.proto @@ -19,7 +19,6 @@ // package and should not be used outside it. syntax = "proto3"; - package android.tv.common.compat.internal; option java_outer_classname = "RecordingCommands"; diff --git a/common/src/com/android/tv/common/compat/internal/recording_events.proto b/common/src/com/android/tv/common/compat/internal/recording_events.proto index fffa62ab..68db5ddf 100644 --- a/common/src/com/android/tv/common/compat/internal/recording_events.proto +++ b/common/src/com/android/tv/common/compat/internal/recording_events.proto @@ -18,7 +18,6 @@ // support new features on older devices. NOTE: this proto is internal to this // package and should not be used outside it. syntax = "proto3"; - package android.tv.common.compat.internal; option java_outer_classname = "RecordingEvents"; @@ -47,3 +46,4 @@ message RecordingStarted { // Recording URI. string uri = 1; } + diff --git a/common/src/com/android/tv/common/compat/internal/tif_commands.proto b/common/src/com/android/tv/common/compat/internal/tif_commands.proto index b69d4870..d5867703 100644 --- a/common/src/com/android/tv/common/compat/internal/tif_commands.proto +++ b/common/src/com/android/tv/common/compat/internal/tif_commands.proto @@ -19,7 +19,6 @@ // package and should not be used outside it. syntax = "proto3"; - package android.tv.common.compat.internal; option java_outer_classname = "Commands"; diff --git a/common/src/com/android/tv/common/compat/internal/tif_events.proto b/common/src/com/android/tv/common/compat/internal/tif_events.proto index b15a884a..6e71ae11 100644 --- a/common/src/com/android/tv/common/compat/internal/tif_events.proto +++ b/common/src/com/android/tv/common/compat/internal/tif_events.proto @@ -18,7 +18,6 @@ // support new features on older devices. NOTE: this proto is internal to this // package and should not be used outside it. syntax = "proto3"; - package android.tv.common.compat.internal; option java_outer_classname = "Events"; diff --git a/common/src/com/android/tv/common/customization/CustomizationManager.java b/common/src/com/android/tv/common/customization/CustomizationManager.java index 5a29d7c0..09ecaef8 100644 --- a/common/src/com/android/tv/common/customization/CustomizationManager.java +++ b/common/src/com/android/tv/common/customization/CustomizationManager.java @@ -97,8 +97,8 @@ public class CustomizationManager { /** * Returns {@code true} if there's a customization package installed and it specifies built-in - * tuner devices are available. The built-in tuner should support DVB API to be recognized by TV - * app. + * tuner devices are available. The built-in tuner should support DVB API to be recognized by + * Live TV. */ public static boolean hasLinuxDvbBuiltInTuner(Context context) { if (sHasLinuxDvbBuiltInTuner == null) { @@ -156,26 +156,11 @@ public class CustomizationManager { private static String getCustomizationPackageName(Context context) { if (sCustomizationPackage == null) { - sCustomizationPackage = ""; List<PackageInfo> packageInfos = context.getPackageManager() .getPackagesHoldingPermissions(CUSTOMIZE_PERMISSIONS, 0); - if (packageInfos.size() != 0) { - /** Iterate through all packages returning the first vendor customizer */ - for (PackageInfo packageInfo : packageInfos) { - if (packageInfo.packageName.startsWith("com.android") == false) { - sCustomizationPackage = packageInfo.packageName; - break; - } - } - - /** If no vendor package found, return first in the list */ - if (sCustomizationPackage == "") { - sCustomizationPackage = packageInfos.get(0).packageName; - } - } + sCustomizationPackage = packageInfos.size() == 0 ? "" : packageInfos.get(0).packageName; } - return sCustomizationPackage; } diff --git a/common/src/com/android/tv/common/dagger/ApplicationModule.java b/common/src/com/android/tv/common/dagger/ApplicationModule.java index be9cf885..4655f777 100644 --- a/common/src/com/android/tv/common/dagger/ApplicationModule.java +++ b/common/src/com/android/tv/common/dagger/ApplicationModule.java @@ -21,10 +21,8 @@ import android.content.Context; import android.os.Looper; import com.android.tv.common.dagger.annotations.ApplicationContext; import com.android.tv.common.dagger.annotations.MainLooper; -import com.android.tv.common.util.Clock; import dagger.Module; import dagger.Provides; -import dagger.Reusable; /** * Provides application-scope qualifiers for the {@link Application}, the application context, and @@ -59,10 +57,4 @@ public final class ApplicationModule { ContentResolver provideContentResolver() { return mApplication.getContentResolver(); } - - @Provides - @Reusable - static Clock providesClock() { - return Clock.SYSTEM; - } } diff --git a/common/src/com/android/tv/common/dagger/init/SafePreDaggerInitializer.java b/common/src/com/android/tv/common/dagger/init/SafePreDaggerInitializer.java deleted file mode 100644 index 9465d929..00000000 --- a/common/src/com/android/tv/common/dagger/init/SafePreDaggerInitializer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.dagger.init; - -import android.content.Context; -import android.util.Log; - -/** - * Initializes objects one time only. - * - * <p>This is needed because ContentProviders can be created before Application.onCreate - */ -public final class SafePreDaggerInitializer { - private interface Initialize { - void init(Context context); - } - - private static final String TAG = "SafePreDaggerInitializer"; - - private static boolean initialized = false; - private static Context oldContext; - - private static final Initialize[] sList = - new Initialize[] { - /* Begin_AOSP_Comment_Out - com.google.android.libraries.phenotype.client.PhenotypeContext::setContext - End_AOSP_Comment_Out */ - }; - - public static synchronized void init(Context context) { - if (!initialized) { - for (Initialize i : sList) { - i.init(context); - } - oldContext = context; - initialized = true; - } else if (oldContext != context) { - Log.w( - TAG, - "init called more than once, skipping. Old context was " - + oldContext - + " new context is " - + context); - } - } - - private SafePreDaggerInitializer() {} -} diff --git a/common/src/com/android/tv/common/dev/DeveloperPreference.java b/common/src/com/android/tv/common/dev/DeveloperPreference.java deleted file mode 100644 index b1c401b0..00000000 --- a/common/src/com/android/tv/common/dev/DeveloperPreference.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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.Nullable; -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; - } - - /** 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); - - /** - * 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 deleted file mode 100644 index 9c83b649..00000000 --- a/common/src/com/android/tv/common/dev/DeveloperPreferences.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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/experiments/ExperimentFlag.java b/common/src/com/android/tv/common/experiments/ExperimentFlag.java new file mode 100644 index 00000000..b8370ad6 --- /dev/null +++ b/common/src/com/android/tv/common/experiments/ExperimentFlag.java @@ -0,0 +1,96 @@ +/* + * 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.experiments; + +import android.support.annotation.VisibleForTesting; +import com.android.tv.common.BuildConfig; + +import com.google.common.base.Supplier; + +/** Experiments return values based on user, device and other criteria. */ +public final class ExperimentFlag<T> { + + // NOTE: sAllowOverrides IS NEVER USED in the non AOSP version. + private static boolean sAllowOverrides = false; + + @VisibleForTesting + public static void initForTest() { + /* Begin_AOSP_Comment_Out + if (!BuildConfig.AOSP) { + PhenotypeFlag.initForTest(); + return; + } + End_AOSP_Comment_Out */ + sAllowOverrides = true; + } + + /** Returns a boolean experiment */ + public static ExperimentFlag<Boolean> createFlag( +// AOSP_Comment_Out Supplier<Boolean> phenotypeFlag, + boolean defaultValue) { + return new ExperimentFlag<>( +// AOSP_Comment_Out phenotypeFlag, + defaultValue); + } + + private final T mDefaultValue; +// AOSP_Comment_Out private final Supplier<T> mPhenotypeFlag; + +// AOSP_Comment_Out // NOTE: mOverrideValue IS NEVER USED in the non AOSP version. + private T mOverrideValue = null; + // mOverridden IS NEVER USED in the non AOSP version. + private boolean mOverridden = false; + + private ExperimentFlag( +// AOSP_Comment_Out Supplier<T> phenotypeFlag, + // NOTE: defaultValue IS NEVER USED in the non AOSP version. + T defaultValue) { + mDefaultValue = defaultValue; +// AOSP_Comment_Out mPhenotypeFlag = phenotypeFlag; + } + + /** Returns value for this experiment */ + public T get() { + /* Begin_AOSP_Comment_Out + if (!BuildConfig.AOSP) { + return mPhenotypeFlag.get(); + } + End_AOSP_Comment_Out */ + return sAllowOverrides && mOverridden ? mOverrideValue : mDefaultValue; + } + + @VisibleForTesting + public void override(T t) { + + if (sAllowOverrides) { + mOverridden = true; + mOverrideValue = t; + } + } + + @VisibleForTesting + public void resetOverride() { + mOverridden = false; + } + + /* Begin_AOSP_Comment_Out + @VisibleForTesting + T getAospDefaultValueForTesting() { + return mDefaultValue; + } + End_AOSP_Comment_Out */ +} diff --git a/common/src/com/android/tv/common/flags/impl/DefaultMessagesFlags.java b/common/src/com/android/tv/common/experiments/ExperimentLoader.java index f2130a33..5f012e11 100644 --- a/common/src/com/android/tv/common/flags/impl/DefaultMessagesFlags.java +++ b/common/src/com/android/tv/common/experiments/ExperimentLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * 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. @@ -13,18 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.tv.common.flags.impl; -/** - * Default flag values for {@link - * com.android.tv.common.flags.MessagesFlags}. - */ -public final class DefaultMessagesFlags - implements com.android.tv.common.flags.MessagesFlags { +package com.android.tv.common.experiments; - @Override - public boolean compiled() { - return true; - } +import android.content.Context; +/** Used to sync {@link ExperimentFlag}s. */ +public class ExperimentLoader { + + /** Starts a background task to update {@link ExperimentFlag}s */ + public void asyncRefreshExperiments(Context context) { + // Override for your experiment system + } } diff --git a/common/src/com/android/tv/common/experiments/Experiments.java b/common/src/com/android/tv/common/experiments/Experiments.java new file mode 100644 index 00000000..9bfdb547 --- /dev/null +++ b/common/src/com/android/tv/common/experiments/Experiments.java @@ -0,0 +1,64 @@ +/* + * 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.experiments; + +import static com.android.tv.common.experiments.ExperimentFlag.createFlag; + +import com.android.tv.common.BuildConfig; +// AOSP_Comment_Out import com.android.tv.common.flags.LiveChannels; + +/** + * Set of experiments visible in AOSP. + * + * <p>This file is maintained by hand. + */ +public final class Experiments { + public static final ExperimentFlag<Boolean> ENABLE_UNRATED_CONTENT_SETTINGS = + ExperimentFlag.createFlag( +// AOSP_Comment_Out LiveChannels::enableUnratedContentSettings, + false); + + /** Turn analytics on or off based on the System Checkbox for logging. */ + public static final ExperimentFlag<Boolean> ENABLE_ANALYTICS_VIA_CHECKBOX = + createFlag( +// AOSP_Comment_Out LiveChannels::enableAnalyticsViaCheckbox, + false); + + /** + * Allow developer features such as the dev menu and other aids. + * + * <p>These features are available to select users(aka fishfooders) on production builds. + */ + public static final ExperimentFlag<Boolean> ENABLE_DEVELOPER_FEATURES = + ExperimentFlag.createFlag( +// AOSP_Comment_Out LiveChannels::enableDeveloperFeatures, + BuildConfig.ENG); + + /** + * Allow QA features. + * + * <p>These features must be carefully limited, keeping QA differences to a minimum. + * + * <p>These features are available to select users(aka QA) on production builds. + */ + public static final ExperimentFlag<Boolean> ENABLE_QA_FEATURES = + ExperimentFlag.createFlag( +// AOSP_Comment_Out LiveChannels::enableQaFeatures, + false); + + private Experiments() {} +} diff --git a/common/src/com/android/tv/common/feature/CommonFeatures.java b/common/src/com/android/tv/common/feature/CommonFeatures.java index abe4c1df..04052a7c 100644 --- a/common/src/com/android/tv/common/feature/CommonFeatures.java +++ b/common/src/com/android/tv/common/feature/CommonFeatures.java @@ -23,14 +23,12 @@ 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; /** - * List of {@link Feature} that affect more than just the TV app. + * List of {@link Feature} that affect more than just the Live TV app. * * <p>Remove the {@code Feature} once it is launched. */ @@ -54,7 +52,7 @@ public class CommonFeatures { * <p>Enables dvr recording regardless of storage status. */ public static final Feature FORCE_RECORDING_UNTIL_NO_SPACE = - DeveloperPreferenceFeature.create("force_recording_until_no_space", false); + PropertyFeature.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 deleted file mode 100644 index 1f98547a..00000000 --- a/common/src/com/android/tv/common/feature/DeveloperPreferenceFeature.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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/feature/PermissionFeature.java b/common/src/com/android/tv/common/feature/ExperimentFeature.java index 02611785..820eda49 100644 --- a/common/src/com/android/tv/common/feature/PermissionFeature.java +++ b/common/src/com/android/tv/common/feature/ExperimentFeature.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2017 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. @@ -17,22 +17,28 @@ package com.android.tv.common.feature; import android.content.Context; -import android.content.pm.PackageManager; +import com.android.tv.common.experiments.ExperimentFlag; -/** A feature that is only available when {@code permissionName} is granted. */ -public class PermissionFeature implements Feature { +/** A {@link Feature} base on an {@link ExperimentFlag}. */ +public final class ExperimentFeature implements Feature { - public static final PermissionFeature DVB_DEVICE_PERMISSION = - new PermissionFeature("android.permission.DVB_DEVICE"); + public static Feature from(ExperimentFlag<Boolean> flag) { + return new ExperimentFeature(flag); + } - private final String permissionName; + private final ExperimentFlag<Boolean> mFlag; - private PermissionFeature(String permissionName) { - this.permissionName = permissionName; + private ExperimentFeature(ExperimentFlag<Boolean> flag) { + mFlag = flag; } @Override public boolean isEnabled(Context context) { - return context.checkSelfPermission(permissionName) == PackageManager.PERMISSION_GRANTED; + return mFlag.get(); + } + + @Override + public String toString() { + return "ExperimentFeature for " + mFlag; } } diff --git a/common/src/com/android/tv/common/feature/FeatureUtils.java b/common/src/com/android/tv/common/feature/FeatureUtils.java index e6192cd4..aaed6c82 100644 --- a/common/src/com/android/tv/common/feature/FeatureUtils.java +++ b/common/src/com/android/tv/common/feature/FeatureUtils.java @@ -17,6 +17,7 @@ package com.android.tv.common.feature; import android.content.Context; +import com.android.tv.common.BuildConfig; import com.android.tv.common.util.CommonUtils; import java.util.Arrays; @@ -70,6 +71,23 @@ public class FeatureUtils { } }; } + /** + * A feature available in AOSP. + * + * @param googleFeature the feature used in non AOSP builds + * @param aospFeature the feature used in AOSP builds + */ + public static Feature aospFeature( +// AOSP_Comment_Out final Feature googleFeature, + final Feature aospFeature) { + /* Begin_AOSP_Comment_Out + if (!BuildConfig.AOSP) { + return googleFeature; + } else { + End_AOSP_Comment_Out */ + return aospFeature; +// AOSP_Comment_Out } + } /** * Returns a feature that is opposite of the given {@code feature}. diff --git a/common/src/com/android/tv/common/feature/Model.java b/common/src/com/android/tv/common/feature/Model.java index 450cd216..7aa5148e 100644 --- a/common/src/com/android/tv/common/feature/Model.java +++ b/common/src/com/android/tv/common/feature/Model.java @@ -21,11 +21,10 @@ import android.content.Context; /** Holder for {@link android.os.Build#MODEL} features. */ public interface Model { - ModelFeature ARCHER = new ModelFeature("Archer"); ModelFeature NEXUS_PLAYER = new ModelFeature("Nexus Player"); /** True when the {@link android.os.Build#MODEL} equals the {@code model} given. */ - final class ModelFeature implements Feature { + public static final class ModelFeature implements Feature { private final String mModel; private ModelFeature(String model) { diff --git a/common/src/com/android/tv/common/feature/Sdk.java b/common/src/com/android/tv/common/feature/Sdk.java index 54bc1bbd..4b0a925f 100644 --- a/common/src/com/android/tv/common/feature/Sdk.java +++ b/common/src/com/android/tv/common/feature/Sdk.java @@ -29,6 +29,8 @@ public final class Sdk { public static final Feature AT_LEAST_O = new AtLeast(VERSION_CODES.O); + public static final Feature AT_LEAST_P = new AtLeast(VERSION_CODES.P); // AOSP_OC:strip_line + private static final class AtLeast implements Feature { private final int versionCode; diff --git a/common/src/com/android/tv/common/flags/BackendKnobsFlags.java b/common/src/com/android/tv/common/flags/BackendKnobsFlags.java index 3b65df56..69bac7a0 100644 --- a/common/src/com/android/tv/common/flags/BackendKnobsFlags.java +++ b/common/src/com/android/tv/common/flags/BackendKnobsFlags.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License */ - package com.android.tv.common.flags; /** Flags for tuning non ui behavior */ @@ -27,8 +26,8 @@ public interface BackendKnobsFlags { */ boolean compiled(); - /** Number of channels to batch together when fetching programs */ - long epgFetcherChannelsPerProgramFetch(); + /** Enable fetching only part of the program data. */ + boolean enablePartialProgramFetch(); /** EPG fetcher interval in hours */ long epgFetcherIntervalHour(); @@ -36,6 +35,9 @@ public interface BackendKnobsFlags { /** Target channel count for EPG. It is used to adjust the EPG length */ long epgTargetChannelCount(); + /** Enables fetching a few hours of programs only when the epg is scrolled to that time. */ + boolean fetchProgramsAsNeeded(); + /** How many hours of programs are loaded in the program guide for during the initial fetch */ long programGuideInitialFetchHours(); diff --git a/common/src/com/android/tv/common/flags/CloudEpgFlags.java b/common/src/com/android/tv/common/flags/CloudEpgFlags.java index db2789c3..ab4c6a17 100755 --- a/common/src/com/android/tv/common/flags/CloudEpgFlags.java +++ b/common/src/com/android/tv/common/flags/CloudEpgFlags.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License */ - package com.android.tv.common.flags; /** Flags for Cloud EPG */ @@ -30,6 +29,6 @@ public interface CloudEpgFlags { /** Is the device in a region supported by Cloud Epg */ boolean supportedRegion(); - /** List of input ids that the TV app will update their EPG. */ + /** List of input ids that Live TV will update their EPG. */ String thirdPartyEpgInputsCsv(); } diff --git a/common/src/com/android/tv/common/flags/MessagesFlags.java b/common/src/com/android/tv/common/flags/ConcurrentDvrPlaybackFlags.java index 596442fe..1afff793 100755 --- a/common/src/com/android/tv/common/flags/MessagesFlags.java +++ b/common/src/com/android/tv/common/flags/ConcurrentDvrPlaybackFlags.java @@ -13,17 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License */ - package com.android.tv.common.flags; -/** - * Message flags. - * - * <p>Used to hide new messages until all translations are ready. - * - * <p>Production releases never include the messages protected by these flags. - */ -public interface MessagesFlags { +/** Flags allowing concurrent DVR playback */ +public interface ConcurrentDvrPlaybackFlags { /** * Whether or not this feature is compiled into this build. @@ -32,4 +25,10 @@ public interface MessagesFlags { * code generation. */ boolean compiled(); + + /** Enable playback of DVR playback during recording */ + boolean enabled(); + + /** Enable tuner using recording data for playback in onTune */ + boolean onTuneUsesRecording(); } diff --git a/common/src/com/android/tv/common/flags/DvrFlags.java b/common/src/com/android/tv/common/flags/DvrFlags.java deleted file mode 100755 index 9deae1f7..00000000 --- a/common/src/com/android/tv/common/flags/DvrFlags.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.flags; - -/** DVR flags */ -public interface DvrFlags { - - /** - * Whether or not this feature is compiled into this build. - * - * <p>This returns true by default, unless the is_compiled_selector parameter was set during - * code generation. - */ - boolean compiled(); - - /** Allow user to customize timings of program recordings. */ - boolean startEarlyEndLateEnabled(); - - /** Store and use the video aspect ratio in recordings. */ - boolean storeVideoAspectRatio(); -} diff --git a/common/src/com/android/tv/common/flags/LegacyFlags.java b/common/src/com/android/tv/common/flags/LegacyFlags.java deleted file mode 100755 index d0cb1e44..00000000 --- a/common/src/com/android/tv/common/flags/LegacyFlags.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.flags; - -/** Legacy flags */ -public interface LegacyFlags { - - /** - * Whether or not this feature is compiled into this build. - * - * <p>This returns true by default, unless the is_compiled_selector parameter was set during - * code generation. - */ - boolean compiled(); - - /** Enable Developer Features */ - boolean enableDeveloperFeatures(); - - /** Enable QA Features */ - boolean enableQaFeatures(); - - /** Enable Unrated Content Settings */ - boolean enableUnratedContentSettings(); -} diff --git a/common/src/com/android/tv/common/flags/SetupFlags.java b/common/src/com/android/tv/common/flags/SetupFlags.java deleted file mode 100755 index 0a7f2002..00000000 --- a/common/src/com/android/tv/common/flags/SetupFlags.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.flags; - -/** Flags for changing setup behavior */ -public interface SetupFlags { - - /** - * Whether or not this feature is compiled into this build. - * - * <p>This returns true by default, unless the is_compiled_selector parameter was set during - * code generation. - */ - boolean compiled(); - - /** Packages allowed to send intents to SetupPassthroughActivity. */ - com.android.tv.common.flags.proto.TypedFeatures.StringListParam - setupPassThroughPackageWhitelist(); - - /** Use a whitelist for packages allowed to start SetupPassthroughActivity */ - boolean useWhitelistForSetupPassThrough(); -} diff --git a/common/src/com/android/tv/common/flags/TunerFlags.java b/common/src/com/android/tv/common/flags/TunerFlags.java index 5ecfb5bf..5f899b90 100755 --- a/common/src/com/android/tv/common/flags/TunerFlags.java +++ b/common/src/com/android/tv/common/flags/TunerFlags.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License */ - package com.android.tv.common.flags; /** Flags for tuner */ @@ -27,6 +26,9 @@ public interface TunerFlags { */ boolean compiled(); + /** Tune using current recording if available. */ + boolean tuneUsingRecording(); + /** Enable using exoplayer V2 */ boolean useExoplayerV2(); } diff --git a/common/src/com/android/tv/common/flags/UiFlags.java b/common/src/com/android/tv/common/flags/UiFlags.java index 2bd8a59d..4c88d08a 100755 --- a/common/src/com/android/tv/common/flags/UiFlags.java +++ b/common/src/com/android/tv/common/flags/UiFlags.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License */ - package com.android.tv.common.flags; -/** Flags for TV app UI */ +/** Flags for Live TV UI */ public interface UiFlags { /** @@ -27,9 +26,6 @@ public interface UiFlags { */ boolean compiled(); - /** Critic Ratings */ - boolean enableCriticRatings(); - /** * Number of days to be shown by Recording History. * @@ -38,5 +34,8 @@ public interface UiFlags { long maxHistoryDays(); /** Unhide the launcher all the time */ - boolean unhideLauncher(); + boolean uhideLauncher(); + + /** Use the Leanback Pin Picker */ + boolean useLeanbackPinPicker(); } diff --git a/common/src/com/android/tv/common/flags/StartupFlags.java b/common/src/com/android/tv/common/flags/has/HasConcurrentDvrPlaybackFlags.java index 2f64c9fe..b4710875 100755..100644 --- a/common/src/com/android/tv/common/flags/StartupFlags.java +++ b/common/src/com/android/tv/common/flags/has/HasConcurrentDvrPlaybackFlags.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * 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. @@ -13,20 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License */ +package com.android.tv.common.flags.has; -package com.android.tv.common.flags; +import android.content.Context; +import com.android.tv.common.flags.ConcurrentDvrPlaybackFlags; -/** Flags for TV App startup */ -public interface StartupFlags { +/** Has {@link ConcurrentDvrPlaybackFlags} */ +public interface HasConcurrentDvrPlaybackFlags { - /** - * Whether or not this feature is compiled into this build. - * - * <p>This returns true by default, unless the is_compiled_selector parameter was set during - * code generation. - */ - boolean compiled(); + static ConcurrentDvrPlaybackFlags fromContext(Context context) { + return ((HasConcurrentDvrPlaybackFlags) HasUtils.getApplicationContext(context)) + .getConcurrentDvrPlaybackFlags(); + } - /** InputId's that will not be warmed up on MainActivity creation. */ - com.android.tv.common.flags.proto.TypedFeatures.StringListParam warmupInputidBlacklist(); + ConcurrentDvrPlaybackFlags getConcurrentDvrPlaybackFlags(); } diff --git a/common/src/com/android/tv/common/flags/impl/DefaultBackendKnobsFlags.java b/common/src/com/android/tv/common/flags/impl/DefaultBackendKnobsFlags.java index 5302842b..a189e473 100644 --- a/common/src/com/android/tv/common/flags/impl/DefaultBackendKnobsFlags.java +++ b/common/src/com/android/tv/common/flags/impl/DefaultBackendKnobsFlags.java @@ -25,8 +25,8 @@ public final class DefaultBackendKnobsFlags } @Override - public long epgFetcherChannelsPerProgramFetch() { - return 50; + public boolean enablePartialProgramFetch() { + return false; } @Override @@ -35,8 +35,13 @@ public final class DefaultBackendKnobsFlags } @Override + public boolean fetchProgramsAsNeeded() { + return false; + } + + @Override public long programGuideInitialFetchHours() { - return 4; + return 8; } @Override diff --git a/common/src/com/android/tv/common/flags/impl/DefaultDvrFlags.java b/common/src/com/android/tv/common/flags/impl/DefaultConcurrentDvrPlaybackFlags.java index 09f7b4f3..8d8c584a 100644 --- a/common/src/com/android/tv/common/flags/impl/DefaultDvrFlags.java +++ b/common/src/com/android/tv/common/flags/impl/DefaultConcurrentDvrPlaybackFlags.java @@ -15,9 +15,10 @@ */ package com.android.tv.common.flags.impl; -/** Flags for tuning non ui behavior. */ -public final class DefaultDvrFlags - implements com.android.tv.common.flags.DvrFlags { +import com.android.tv.common.flags.ConcurrentDvrPlaybackFlags; + +/** Default flags for Concurrent DVR Playback */ +public final class DefaultConcurrentDvrPlaybackFlags implements ConcurrentDvrPlaybackFlags { @Override public boolean compiled() { @@ -25,12 +26,12 @@ public final class DefaultDvrFlags } @Override - public boolean startEarlyEndLateEnabled() { + public boolean enabled() { return false; } @Override - public boolean storeVideoAspectRatio() { + public boolean onTuneUsesRecording() { return false; } } diff --git a/common/src/com/android/tv/common/flags/impl/DefaultFlagsModule.java b/common/src/com/android/tv/common/flags/impl/DefaultFlagsModule.java index 10be34b5..49352364 100644 --- a/common/src/com/android/tv/common/flags/impl/DefaultFlagsModule.java +++ b/common/src/com/android/tv/common/flags/impl/DefaultFlagsModule.java @@ -18,12 +18,9 @@ package com.android.tv.common.flags.impl; import dagger.Module; import dagger.Provides; import dagger.Reusable; - import com.android.tv.common.flags.BackendKnobsFlags; import com.android.tv.common.flags.CloudEpgFlags; -import com.android.tv.common.flags.DvrFlags; -import com.android.tv.common.flags.LegacyFlags; -import com.android.tv.common.flags.StartupFlags; +import com.android.tv.common.flags.ConcurrentDvrPlaybackFlags; import com.android.tv.common.flags.TunerFlags; import com.android.tv.common.flags.UiFlags; @@ -45,20 +42,8 @@ public class DefaultFlagsModule { @Provides @Reusable - DvrFlags provideDvrFlags() { - return new DefaultDvrFlags(); - } - - @Provides - @Reusable - LegacyFlags provideLegacyFlags() { - return DefaultLegacyFlags.DEFAULT; - } - - @Provides - @Reusable - StartupFlags provideStartupFlags() { - return new DefaultStartupFlags(); + ConcurrentDvrPlaybackFlags provideConcurrentDvrPlaybackFlags() { + return new DefaultConcurrentDvrPlaybackFlags(); } @Provides diff --git a/common/src/com/android/tv/common/flags/impl/DefaultLegacyFlags.java b/common/src/com/android/tv/common/flags/impl/DefaultLegacyFlags.java deleted file mode 100644 index 52142416..00000000 --- a/common/src/com/android/tv/common/flags/impl/DefaultLegacyFlags.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.flags.impl; - -import com.google.auto.value.AutoValue; -import com.android.tv.common.flags.LegacyFlags; - -/** Default {@link LegacyFlags}. */ -@AutoValue -public abstract class DefaultLegacyFlags implements LegacyFlags { - public static final DefaultLegacyFlags DEFAULT = DefaultLegacyFlags.builder().build(); - - public static Builder builder() { - return new AutoValue_DefaultLegacyFlags.Builder() - .compiled(true) - .enableDeveloperFeatures(false) - .enableQaFeatures(false) - .enableUnratedContentSettings(false); - } - - /** Builder for {@link LegacyFlags} */ - @AutoValue.Builder - public abstract static class Builder { - public abstract Builder compiled(boolean value); - - public abstract Builder enableDeveloperFeatures(boolean value); - - public abstract Builder enableQaFeatures(boolean value); - - public abstract Builder enableUnratedContentSettings(boolean value); - - public abstract DefaultLegacyFlags build(); - } -} diff --git a/common/src/com/android/tv/common/flags/impl/DefaultSetupFlags.java b/common/src/com/android/tv/common/flags/impl/DefaultSetupFlags.java deleted file mode 100644 index 3abe6627..00000000 --- a/common/src/com/android/tv/common/flags/impl/DefaultSetupFlags.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.flags.impl; - -import com.android.tv.common.flags.proto.TypedFeatures.StringListParam; - -import com.android.tv.common.flags.SetupFlags; - -/** Default {@link SetupFlags} */ -public class DefaultSetupFlags implements SetupFlags { - @Override - public boolean compiled() { - return true; - } - - @Override - public StringListParam setupPassThroughPackageWhitelist() { - return StringListParam.getDefaultInstance(); - } - - @Override - public boolean useWhitelistForSetupPassThrough() { - return false; - } -} diff --git a/common/src/com/android/tv/common/flags/impl/DefaultStartupFlags.java b/common/src/com/android/tv/common/flags/impl/DefaultStartupFlags.java deleted file mode 100644 index 3eb6edc6..00000000 --- a/common/src/com/android/tv/common/flags/impl/DefaultStartupFlags.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.flags.impl; - -import com.android.tv.common.flags.proto.TypedFeatures.StringListParam; -import com.android.tv.common.flags.StartupFlags; - -/** Default {@link StartupFlags} */ -public class DefaultStartupFlags implements StartupFlags { - @Override - public boolean compiled() { - return true; - } - - @Override - public StringListParam warmupInputidBlacklist() { - return StringListParam.getDefaultInstance(); - } -} diff --git a/common/src/com/android/tv/common/flags/impl/DefaultTunerFlags.java b/common/src/com/android/tv/common/flags/impl/DefaultTunerFlags.java index 2d12e368..195953bc 100644 --- a/common/src/com/android/tv/common/flags/impl/DefaultTunerFlags.java +++ b/common/src/com/android/tv/common/flags/impl/DefaultTunerFlags.java @@ -26,6 +26,11 @@ public class DefaultTunerFlags implements TunerFlags { } @Override + public boolean tuneUsingRecording() { + return false; + } + + @Override public boolean useExoplayerV2() { return false; } diff --git a/common/src/com/android/tv/common/flags/impl/DefaultUiFlags.java b/common/src/com/android/tv/common/flags/impl/DefaultUiFlags.java index 43f0dea0..fce45853 100644 --- a/common/src/com/android/tv/common/flags/impl/DefaultUiFlags.java +++ b/common/src/com/android/tv/common/flags/impl/DefaultUiFlags.java @@ -17,7 +17,7 @@ package com.android.tv.common.flags.impl; import com.android.tv.common.flags.UiFlags; -/** Default Flags for TV app UI */ +/** Default Flags for Live TV UI */ public class DefaultUiFlags implements UiFlags { @Override @@ -26,17 +26,17 @@ public class DefaultUiFlags implements UiFlags { } @Override - public boolean enableCriticRatings() { + public boolean uhideLauncher() { return false; } @Override - public boolean unhideLauncher() { + public boolean useLeanbackPinPicker() { return false; } @Override public long maxHistoryDays() { - return 0; + return 7; } } diff --git a/common/src/com/android/tv/common/flags/impl/SettableFlagsModule.java b/common/src/com/android/tv/common/flags/impl/SettableFlagsModule.java deleted file mode 100644 index ab4ebd34..00000000 --- a/common/src/com/android/tv/common/flags/impl/SettableFlagsModule.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.flags.impl; - -import dagger.Module; -import dagger.Provides; -import dagger.Reusable; - -import com.android.tv.common.flags.BackendKnobsFlags; -import com.android.tv.common.flags.CloudEpgFlags; -import com.android.tv.common.flags.DvrFlags; -import com.android.tv.common.flags.LegacyFlags; -import com.android.tv.common.flags.SetupFlags; -import com.android.tv.common.flags.StartupFlags; -import com.android.tv.common.flags.TunerFlags; -import com.android.tv.common.flags.UiFlags; - -/** Provides public fields for each flag so they can be changed before injection. */ -@Module -public class SettableFlagsModule { - - public DefaultBackendKnobsFlags backendKnobsFlags = new DefaultBackendKnobsFlags(); - public DefaultCloudEpgFlags cloudEpgFlags = new DefaultCloudEpgFlags(); - public DefaultDvrFlags dvrFlags = new DefaultDvrFlags(); - public DefaultLegacyFlags legacyFlags = DefaultLegacyFlags.DEFAULT; - public DefaultSetupFlags setupFlags = new DefaultSetupFlags(); - public DefaultStartupFlags startupFlags = new DefaultStartupFlags(); - public DefaultTunerFlags tunerFlags = new DefaultTunerFlags(); - public DefaultUiFlags uiFlags = new DefaultUiFlags(); - - @Provides - @Reusable - BackendKnobsFlags provideBackendKnobsFlags() { - return backendKnobsFlags; - } - - @Provides - @Reusable - CloudEpgFlags provideCloudEpgFlags() { - return cloudEpgFlags; - } - - @Provides - @Reusable - DvrFlags provideDvrFlags() { - return dvrFlags; - } - - @Provides - @Reusable - LegacyFlags provideLegacyFlags() { - return legacyFlags; - } - - @Provides - @Reusable - SetupFlags provideSetupFlags() { - return setupFlags; - } - - @Provides - @Reusable - StartupFlags provideStartupFlags() { - return startupFlags; - } - - @Provides - @Reusable - TunerFlags provideTunerFlags() { - return tunerFlags; - } - - @Provides - @Reusable - UiFlags provideUiFlags() { - return uiFlags; - } -} diff --git a/common/src/com/android/tv/common/flags/proto/typed-features.proto b/common/src/com/android/tv/common/flags/proto/typed-features.proto deleted file mode 100644 index 855d7311..00000000 --- a/common/src/com/android/tv/common/flags/proto/typed-features.proto +++ /dev/null @@ -1,20 +0,0 @@ -syntax = "proto2"; - -package android.tv.common.flags; - -option java_outer_classname = "TypedFeatures"; -option java_package = "com.android.tv.common.flags.proto"; - -// These messages are to specify feature params that are a list of integers. -message Int32ListParam { - repeated int32 element = 1; -} - -message Int64ListParam { - repeated int64 element = 1; -} - -// This message is to specify feature params that are a list of strings. -message StringListParam { - repeated string element = 1; -} diff --git a/common/src/com/android/tv/common/recording/RecordingStorageStatusManager.java b/common/src/com/android/tv/common/recording/RecordingStorageStatusManager.java index 3552a66f..0fb864bd 100644 --- a/common/src/com/android/tv/common/recording/RecordingStorageStatusManager.java +++ b/common/src/com/android/tv/common/recording/RecordingStorageStatusManager.java @@ -28,11 +28,8 @@ import android.support.annotation.AnyThread; import android.support.annotation.IntDef; import android.support.annotation.WorkerThread; import android.util.Log; - import com.android.tv.common.SoftPreconditions; -import com.android.tv.common.dagger.annotations.ApplicationContext; import com.android.tv.common.feature.CommonFeatures; - import java.io.File; import java.io.IOException; import java.lang.annotation.Retention; @@ -41,13 +38,10 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; -import javax.inject.Inject; -import javax.inject.Singleton; - /** Signals DVR storage status change such as plugging/unplugging. */ -@Singleton public class RecordingStorageStatusManager { private static final String TAG = "RecordingStorageStatusManager"; + private static final boolean DEBUG = false; /** Minimum storage size to support DVR */ public static final long MIN_STORAGE_SIZE_FOR_DVR_IN_BYTES = 50 * 1024 * 1024 * 1024L; // 50GB @@ -149,8 +143,7 @@ public class RecordingStorageStatusManager { * * @param context {@link Context} */ - @Inject - public RecordingStorageStatusManager(@ApplicationContext Context context) { + public RecordingStorageStatusManager(final Context context) { mContext = context; mMountedStorageStatus = getStorageStatusInternal(); mStorageValid = mMountedStorageStatus.isValidForDvr(); diff --git a/common/src/com/android/tv/common/singletons/HasTvInputId.java b/common/src/com/android/tv/common/singletons/HasTvInputId.java index 49cf3d2e..4bc0a21c 100644 --- a/common/src/com/android/tv/common/singletons/HasTvInputId.java +++ b/common/src/com/android/tv/common/singletons/HasTvInputId.java @@ -18,8 +18,8 @@ package com.android.tv.common.singletons; /** * Has TunerInputId. * - * <p>This is used buy both the tuner to get its input id and by the TV app to get the embedded - * tuner input id. + * <p>This is used buy both the tuner to get its input id and by the Live TV to get the + * embedded tuner input id. */ public interface HasTvInputId { diff --git a/common/src/com/android/tv/common/support/tvprovider/README.md b/common/src/com/android/tv/common/support/tvprovider/README.md deleted file mode 100644 index a24dc288..00000000 --- a/common/src/com/android/tv/common/support/tvprovider/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## support provider - -This is preview code destined to be put in androidx.tvprovider.media.tv - - -All classes here must have an associated bug to move to androidx diff --git a/common/src/com/android/tv/common/support/tvprovider/TvContractCompatX.java b/common/src/com/android/tv/common/support/tvprovider/TvContractCompatX.java deleted file mode 100644 index 353e3421..00000000 --- a/common/src/com/android/tv/common/support/tvprovider/TvContractCompatX.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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.support.tvprovider; - -import android.net.Uri; -import android.support.annotation.Nullable; -import androidx.tvprovider.media.tv.TvContractCompat; - -/** - * Extensions to the contract between the TV provider and applications. Contains definitions for the - * supported URIs and columns. - * - * <p>TODO(b/126921088): move this to androidx. - */ -public final class TvContractCompatX { - - /** - * Builds a URI that points to a specific channel. - * - * @param inputPackage the package of the input. - * @param internalProviderId the internal provider id - */ - public static Uri buildChannelUri( - @Nullable String inputPackage, @Nullable String internalProviderId) { - Uri.Builder uri = TvContractCompat.Channels.CONTENT_URI.buildUpon(); - if (inputPackage != null) { - uri.appendQueryParameter("package", inputPackage); - } - if (internalProviderId != null) { - uri.appendQueryParameter( - TvContractCompat.Channels.COLUMN_INTERNAL_PROVIDER_ID, internalProviderId); - } - return uri.build(); - } - - /** - * Builds a URI that points to all programs on a given channel. - * - * @param inputPackage the package of the input. - * @param internalProviderId the internal provider id - */ - public static Uri buildProgramsUriForChannel( - @Nullable String inputPackage, @Nullable String internalProviderId) { - Uri.Builder uri = TvContractCompat.Programs.CONTENT_URI.buildUpon(); - if (inputPackage != null) { - uri.appendQueryParameter("package", inputPackage); - } - if (internalProviderId != null) { - uri.appendQueryParameter( - TvContractCompat.Channels.COLUMN_INTERNAL_PROVIDER_ID, internalProviderId); - } - return uri.build(); - } - - /** - * Builds a URI that points to programs on a specific channel whose schedules overlap with the - * given time frame. - * - * @param inputPackage the package of the input. - * @param internalProviderId the internal provider id - * @param startTime The start time used to filter programs. The returned programs should have - * {@link TvContractCompat.Programs#COLUMN_END_TIME_UTC_MILLIS} that is greater than this - * time. - * @param endTime The end time used to filter programs. The returned programs should have {@link - * TvContractCompat.Programs#COLUMN_START_TIME_UTC_MILLIS} that is less than this time. - */ - public static Uri buildProgramsUriForChannel( - @Nullable String inputPackage, - @Nullable String internalProviderId, - long startTime, - long endTime) { - return buildProgramsUriForChannel(inputPackage, internalProviderId) - .buildUpon() - .appendQueryParameter(TvContractCompat.PARAM_START_TIME, String.valueOf(startTime)) - .appendQueryParameter(TvContractCompat.PARAM_END_TIME, String.valueOf(endTime)) - .build(); - } - - /** - * Builds a URI that points to programs whose schedules overlap with the given time frame. - * - * @param startTime The start time used to filter programs. The returned programs should have - * {@link TvContractCompat.Programs#COLUMN_END_TIME_UTC_MILLIS} that is greater than this - * time. - * @param endTime The end time used to filter programs. The returned programs should have {@link - * TvContractCompat.Programs#COLUMN_START_TIME_UTC_MILLIS} that is less than this time. - */ - public static Uri buildProgramsUri(long startTime, long endTime) { - return TvContractCompat.Programs.CONTENT_URI - .buildUpon() - .appendQueryParameter(TvContractCompat.PARAM_START_TIME, String.valueOf(startTime)) - .appendQueryParameter(TvContractCompat.PARAM_END_TIME, String.valueOf(endTime)) - .build(); - } -} diff --git a/common/src/com/android/tv/common/ui/setup/SetupGuidedStepFragment.java b/common/src/com/android/tv/common/ui/setup/SetupGuidedStepFragment.java index 2a6ceec5..3c76c269 100644 --- a/common/src/com/android/tv/common/ui/setup/SetupGuidedStepFragment.java +++ b/common/src/com/android/tv/common/ui/setup/SetupGuidedStepFragment.java @@ -19,11 +19,11 @@ package com.android.tv.common.ui.setup; import static android.content.Context.ACCESSIBILITY_SERVICE; import android.os.Bundle; -import androidx.leanback.app.GuidedStepFragment; -import androidx.leanback.widget.GuidanceStylist; -import androidx.leanback.widget.GuidedAction; -import androidx.leanback.widget.GuidedActionsStylist; -import androidx.leanback.widget.VerticalGridView; +import android.support.v17.leanback.app.GuidedStepFragment; +import android.support.v17.leanback.widget.GuidanceStylist; +import android.support.v17.leanback.widget.GuidedAction; +import android.support.v17.leanback.widget.GuidedActionsStylist; +import android.support.v17.leanback.widget.VerticalGridView; import android.view.LayoutInflater; import android.view.View; import android.view.View.AccessibilityDelegate; @@ -53,9 +53,9 @@ public abstract class SetupGuidedStepFragment extends GuidedStepFragment { LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); Bundle arguments = getArguments(); - view.findViewById(androidx.leanback.R.id.action_fragment_root) + view.findViewById(android.support.v17.leanback.R.id.action_fragment_root) .setPadding(0, 0, 0, 0); - mContentFragment = view.findViewById(androidx.leanback.R.id.content_fragment); + mContentFragment = view.findViewById(android.support.v17.leanback.R.id.content_fragment); LinearLayout.LayoutParams guidanceLayoutParams = (LinearLayout.LayoutParams) mContentFragment.getLayoutParams(); guidanceLayoutParams.weight = 0; @@ -69,7 +69,7 @@ public abstract class SetupGuidedStepFragment extends GuidedStepFragment { getResources() .getDimensionPixelOffset(R.dimen.setup_done_button_container_width); // Guided actions list - View list = view.findViewById(androidx.leanback.R.id.guidedactions_list); + View list = view.findViewById(android.support.v17.leanback.R.id.guidedactions_list); MarginLayoutParams marginLayoutParams = (MarginLayoutParams) list.getLayoutParams(); // Use content view to check layout direction while view is being created. if (getResources().getConfiguration().getLayoutDirection() @@ -93,12 +93,12 @@ public abstract class SetupGuidedStepFragment extends GuidedStepFragment { gridView.setWindowAlignmentOffset(offset); gridView.setWindowAlignmentOffsetPercent(0); gridView.setItemAlignmentOffsetPercent(0); - ((ViewGroup) view.findViewById(androidx.leanback.R.id.guidedactions_list)) + ((ViewGroup) view.findViewById(android.support.v17.leanback.R.id.guidedactions_list)) .setTransitionGroup(false); // Needed for the shared element transition. // content_frame is defined in leanback. ViewGroup group = - (ViewGroup) view.findViewById(androidx.leanback.R.id.content_frame); + (ViewGroup) view.findViewById(android.support.v17.leanback.R.id.content_frame); group.setClipChildren(false); group.setClipToPadding(false); return view; diff --git a/common/src/com/android/tv/common/ui/setup/SetupMultiPaneFragment.java b/common/src/com/android/tv/common/ui/setup/SetupMultiPaneFragment.java index ee00e9fb..c02d3f56 100644 --- a/common/src/com/android/tv/common/ui/setup/SetupMultiPaneFragment.java +++ b/common/src/com/android/tv/common/ui/setup/SetupMultiPaneFragment.java @@ -112,15 +112,15 @@ public abstract class SetupMultiPaneFragment extends SetupFragment { @Override protected int[] getParentIdsForDelay() { return new int[] { - androidx.leanback.R.id.content_fragment, - androidx.leanback.R.id.guidedactions_list + android.support.v17.leanback.R.id.content_fragment, + android.support.v17.leanback.R.id.guidedactions_list }; } @Override public int[] getSharedElementIds() { return new int[] { - androidx.leanback.R.id.action_fragment_background, R.id.done_button_container + android.support.v17.leanback.R.id.action_fragment_background, R.id.done_button_container }; } } diff --git a/common/src/com/android/tv/common/ui/setup/animation/TranslationAnimationCreator.java b/common/src/com/android/tv/common/ui/setup/animation/TranslationAnimationCreator.java index 59706936..13b89ea1 100644 --- a/common/src/com/android/tv/common/ui/setup/animation/TranslationAnimationCreator.java +++ b/common/src/com/android/tv/common/ui/setup/animation/TranslationAnimationCreator.java @@ -20,7 +20,7 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.animation.TimeInterpolator; import android.graphics.Path; -import androidx.leanback.R; +import android.support.v17.leanback.R; import android.transition.Transition; import android.transition.TransitionValues; import android.view.View; @@ -29,9 +29,9 @@ import android.view.View; * This class is used by Slide and Explode to create an animator that goes from the start position * to the end position. It takes into account the canceled position so that it will not blink out or * shift suddenly when the transition is interrupted. The original class is - * androidx.leanback.transition.TranslationAnimationCreator which is hidden. + * android.support.v17.leanback.transition.TranslationAnimationCreator which is hidden. */ -// Copied from androidx.leanback.transition.TransltaionAnimationCreator +// Copied from android.support.v17.leanback.transition.TransltaionAnimationCreator class TranslationAnimationCreator { /** * Creates an animator that can be used for x and/or y translations. When interrupted, it sets a diff --git a/common/src/com/android/tv/common/util/CommonUtils.java b/common/src/com/android/tv/common/util/CommonUtils.java index 662f819c..4513a879 100644 --- a/common/src/com/android/tv/common/util/CommonUtils.java +++ b/common/src/com/android/tv/common/util/CommonUtils.java @@ -22,8 +22,10 @@ import android.media.tv.TvInputInfo; import android.os.Build; import android.util.ArraySet; import android.util.Log; +import com.android.tv.common.BuildConfig; import com.android.tv.common.CommonConstants; import com.android.tv.common.actions.InputSetupActionUtils; +import com.android.tv.common.experiments.Experiments; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; @@ -51,7 +53,6 @@ public final class CommonUtils { static { BUNDLED_PACKAGE_SET.add("com.android.tv"); -// AOSP_Comment_Out BUNDLED_PACKAGE_SET.add(CommonConstants.BASE_PACKAGE); } private static Boolean sRunningInTest; @@ -122,11 +123,16 @@ public final class CommonUtils { return false; } - /** Returns true if the application is packaged with TV app. */ + /** Returns true if the application is packaged with Live TV. */ public static boolean isPackagedWithLiveChannels(Context context) { return (CommonConstants.BASE_PACKAGE.equals(context.getPackageName())); } + /** Returns true if the current user is a developer. */ + public static boolean isDeveloper() { + return BuildConfig.ENG || Experiments.ENABLE_DEVELOPER_FEATURES.get(); + } + /** Converts time in milliseconds to a ISO 8061 string. */ public static String toIsoDateTimeString(long timeMillis) { return ISO_8601.get().format(new Date(timeMillis)); diff --git a/common/src/com/android/tv/common/util/Debug.java b/common/src/com/android/tv/common/util/Debug.java index 8e826aef..ab908741 100644 --- a/common/src/com/android/tv/common/util/Debug.java +++ b/common/src/com/android/tv/common/util/Debug.java @@ -23,11 +23,11 @@ import java.util.concurrent.TimeUnit; /** A class only for help developers. */ public class Debug { /** - * A threshold of start up time, when the start up time of TV app is more than it, a warning - * will show to the developer. + * A threshold of start up time, when the start up time of Live TV is more than it, a + * warning will show to the developer. */ public static final long TIME_START_UP_DURATION_THRESHOLD = TimeUnit.SECONDS.toMillis(6); - /** Tag for measuring start up time of TV app. */ + /** Tag for measuring start up time of Live TV. */ public static final String TAG_START_UP_TIMER = "start_up_timer"; /** A global map for duration timers. */ diff --git a/common/src/com/android/tv/common/util/LocationUtils.java b/common/src/com/android/tv/common/util/LocationUtils.java index 9d44cf21..ee5119eb 100644 --- a/common/src/com/android/tv/common/util/LocationUtils.java +++ b/common/src/com/android/tv/common/util/LocationUtils.java @@ -16,7 +16,9 @@ package com.android.tv.common.util; +import android.Manifest; import android.content.Context; +import android.content.pm.PackageManager; import android.location.Address; import android.location.Geocoder; import android.location.Location; @@ -24,12 +26,13 @@ import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.Log; - import com.android.tv.common.BuildConfig; + + + import java.io.IOException; import java.util.Collections; import java.util.HashSet; @@ -62,41 +65,19 @@ public class LocationUtils { if (sApplicationContext == null) { sApplicationContext = context.getApplicationContext(); } - /* Begin_AOSP_Comment_Out - if (!BuildConfig.AOSP) { - com.google.android.tv.livechannels.util.GoogleLocationUtilsHelper.startLocationUpdates( - context, LocationUtils::updateAddress); - return null; - } - End_AOSP_Comment_Out */ LocationUtilsHelper.startLocationUpdates(); return null; } - @Nullable - static String getCurrentPostalCode(Context context) throws IOException { - Address address = getCurrentAddress(context); - if (address != null) { - Log.i( - TAG, - "Current country and postal code is " - + address.getCountryName() - + ", " - + address.getPostalCode()); - return address.getPostalCode(); - } - return null; - } - /** The listener used when address is updated. */ public interface OnUpdateAddressListener { /** * Called when address is updated. * - * <p>This listener is removed when this method returns true. + * This listener is removed when this method returns true. * * @return {@code true} if the job has been finished and the listener needs to be removed; - * {@code false} otherwise. + * {@code false} otherwise. */ boolean onUpdateAddress(Address address); } @@ -104,8 +85,8 @@ public class LocationUtils { /** * Add an {@link OnUpdateAddressListener} instance. * - * <p>Note that the listener is removed automatically when {@link - * OnUpdateAddressListener#onUpdateAddress(Address)} is called and returns {@code true}. + * Note that the listener is removed automatically when + * {@link OnUpdateAddressListener#onUpdateAddress(Address)} is called and returns {@code true}. */ public static void addOnUpdateAddressListener(OnUpdateAddressListener listener) { sOnUpdateAddressListeners.add(listener); @@ -114,8 +95,8 @@ public class LocationUtils { /** * Remove an {@link OnUpdateAddressListener} instance if it exists. * - * <p>Note that the listener will be removed automatically when {@link - * OnUpdateAddressListener#onUpdateAddress(Address)} is called and returns {@code true}. + * Note that the listener will be removed automatically when + * {@link OnUpdateAddressListener#onUpdateAddress(Address)} is called and returns {@code true}. */ public static void removeOnUpdateAddressListener(OnUpdateAddressListener listener) { sOnUpdateAddressListeners.remove(listener); @@ -127,13 +108,6 @@ public class LocationUtils { if (sCountry != null) { return sCountry; } - /* Begin_AOSP_Comment_Out - if (!BuildConfig.AOSP) { - sCountry = - com.google.android.tv.livechannels.util.GoogleLocationUtilsHelper - .getDeviceCountry(context); - } - End_AOSP_Comment_Out */ if (TextUtils.isEmpty(sCountry)) { sCountry = context.getResources().getConfiguration().locale.getCountry(); } diff --git a/common/src/com/android/tv/common/util/NetworkTrafficTags.java b/common/src/com/android/tv/common/util/NetworkTrafficTags.java index 51b6c4dc..3c94aed6 100644 --- a/common/src/com/android/tv/common/util/NetworkTrafficTags.java +++ b/common/src/com/android/tv/common/util/NetworkTrafficTags.java @@ -20,7 +20,7 @@ import android.net.TrafficStats; import android.support.annotation.NonNull; import java.util.concurrent.Executor; -/** Constants for tagging network traffic in the TV app. */ +/** Constants for tagging network traffic in the Live channels app. */ public final class NetworkTrafficTags { public static final int DEFAULT_LIVE_CHANNELS = 1; @@ -43,16 +43,16 @@ public final class NetworkTrafficTags { @Override public void execute(final @NonNull Runnable command) { - // TODO(b/62038127): robolectric does not support lamdas in unbundled apps - delegateExecutor.execute( - () -> { - TrafficStats.setThreadStatsTag(tag); - try { - command.run(); - } finally { - TrafficStats.clearThreadStatsTag(); - } - }); + // TODO(b/62038127): robolectric does not support lamdas in unbundled apps + delegateExecutor.execute( + () -> { + TrafficStats.setThreadStatsTag(tag); + try { + command.run(); + } finally { + TrafficStats.clearThreadStatsTag(); + } + }); } } diff --git a/common/src/com/android/tv/common/util/PermissionUtils.java b/common/src/com/android/tv/common/util/PermissionUtils.java index e241b91a..ca1abdc4 100644 --- a/common/src/com/android/tv/common/util/PermissionUtils.java +++ b/common/src/com/android/tv/common/util/PermissionUtils.java @@ -26,9 +26,6 @@ public class PermissionUtils { private static Boolean sHasAccessAllEpgPermission; private static Boolean sHasAccessWatchedHistoryPermission; private static Boolean sHasModifyParentalControlsPermission; - private static Boolean sHasChangeHdmiCecActiveSource; - private static Boolean sHasReadContentRatingSystem; - public static boolean hasAccessAllEpg(Context context) { if (sHasAccessAllEpgPermission == null) { @@ -73,24 +70,4 @@ public class PermissionUtils { return context.checkSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") == PackageManager.PERMISSION_GRANTED; } - - public static boolean hasChangeHdmiCecActiveSource(Context context) { - if (sHasChangeHdmiCecActiveSource == null) { - sHasChangeHdmiCecActiveSource = - context.checkSelfPermission( - "android.permission.CHANGE_HDMI_CEC_ACTIVE_SOURCE") - == PackageManager.PERMISSION_GRANTED; - } - return sHasChangeHdmiCecActiveSource; - } - - public static boolean hasReadContetnRatingSystem(Context context) { - if (sHasReadContentRatingSystem == null) { - sHasReadContentRatingSystem = - context.checkSelfPermission( - "android.permission.READ_CONTENT_RATING_SYSTEMS") - == PackageManager.PERMISSION_GRANTED; - } - return sHasReadContentRatingSystem; - } } diff --git a/common/src/com/android/tv/common/util/PostalCodeUtils.java b/common/src/com/android/tv/common/util/PostalCodeUtils.java index 6ca3d48c..c0917af2 100644 --- a/common/src/com/android/tv/common/util/PostalCodeUtils.java +++ b/common/src/com/android/tv/common/util/PostalCodeUtils.java @@ -17,12 +17,12 @@ package com.android.tv.common.util; import android.content.Context; +import android.location.Address; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.Log; - import com.android.tv.common.CommonPreferences; - import java.io.IOException; import java.util.HashMap; import java.util.Locale; @@ -62,7 +62,7 @@ public class PostalCodeUtils { /** Returns {@code true} if postal code has been changed */ public static boolean updatePostalCode(Context context) throws IOException, SecurityException, NoPostalCodeException { - String postalCode = LocationUtils.getCurrentPostalCode(context); + String postalCode = getPostalCode(context); String lastPostalCode = getLastPostalCode(context); if (TextUtils.isEmpty(postalCode)) { if (TextUtils.isEmpty(lastPostalCode)) { @@ -92,6 +92,21 @@ public class PostalCodeUtils { CommonPreferences.setLastPostalCode(context, postalCode); } + @Nullable + private static String getPostalCode(Context context) throws IOException, SecurityException { + Address address = LocationUtils.getCurrentAddress(context); + if (address != null) { + Log.i( + TAG, + "Current country and postal code is " + + address.getCountryName() + + ", " + + address.getPostalCode()); + return address.getPostalCode(); + } + return null; + } + /** An {@link java.lang.Exception} class to notify no valid postal or zip code is available. */ public static class NoPostalCodeException extends Exception { public NoPostalCodeException() {} diff --git a/common/src/com/android/tv/common/util/SystemProperties.java b/common/src/com/android/tv/common/util/SystemProperties.java index 72920b6b..6ac2907b 100644 --- a/common/src/com/android/tv/common/util/SystemProperties.java +++ b/common/src/com/android/tv/common/util/SystemProperties.java @@ -21,6 +21,25 @@ 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); diff --git a/common/src/com/android/tv/common/util/sql/SqlParams.java b/common/src/com/android/tv/common/util/sql/SqlParams.java deleted file mode 100644 index 87fcabdb..00000000 --- a/common/src/com/android/tv/common/util/sql/SqlParams.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2017 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.util.sql; - -import android.database.DatabaseUtils; -import android.support.annotation.Nullable; -import java.util.Arrays; - -/** Convenience class for SQL operations. */ -public class SqlParams { - private String mTables; - private @Nullable String mSelection; - private @Nullable String[] mSelectionArgs; - - public SqlParams(String tables, @Nullable String selection, @Nullable String... selectionArgs) { - setTables(tables); - setWhere(selection, selectionArgs); - } - - public String getTables() { - return mTables; - } - - public @Nullable String getSelection() { - return mSelection; - } - - public @Nullable String[] getSelectionArgs() { - return mSelectionArgs; - } - - public void setTables(String tables) { - mTables = tables; - } - - public void setWhere(String selection, String... selectionArgs) { - mSelection = selection; - mSelectionArgs = selectionArgs; - } - - public void appendWhere(String selection, String... selectionArgs) { - mSelection = DatabaseUtils.concatenateWhere(mSelection, selection); - if (selectionArgs != null) { - mSelectionArgs = DatabaseUtils.appendSelectionArgs(mSelectionArgs, selectionArgs); - } - } - - public void appendWhereEquals(String name, String value) { - appendWhere(name + "=?", value); - } - - @Override - public String toString() { - return "tables " - + getTables() - + " where " - + getSelection() - + " with " - + Arrays.toString(getSelectionArgs()); - } -} |