1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.tv;
18 
19 import static com.android.tv.common.feature.EngOnlyFeature.ENG_ONLY_FEATURE;
20 import static com.android.tv.common.feature.FeatureUtils.AND;
21 import static com.android.tv.common.feature.FeatureUtils.OFF;
22 import static com.android.tv.common.feature.FeatureUtils.ON;
23 import static com.android.tv.common.feature.FeatureUtils.OR;
24 
25 import android.content.Context;
26 import android.content.pm.PackageManager;
27 import android.os.Build;
28 import android.support.annotation.VisibleForTesting;
29 import android.support.v4.os.BuildCompat;
30 
31 import com.android.tv.common.feature.Feature;
32 import com.android.tv.common.feature.GServiceFeature;
33 import com.android.tv.common.feature.PropertyFeature;
34 import com.android.tv.util.PermissionUtils;
35 
36 /**
37  * List of {@link Feature} for the Live TV App.
38  *
39  * <p>Remove the {@code Feature} once it is launched.
40  */
41 public final class Features {
42     /**
43      * UI for opting in to analytics.
44      *
45      * <p>Do not turn this on until the splash screen asking existing users to opt-in is launched.
46      * See <a href="http://b/20228119">b/20228119</a>
47      */
48     public static final Feature ANALYTICS_OPT_IN = ENG_ONLY_FEATURE;
49 
50     /**
51      * Analytics that include sensitive information such as channel or program identifiers.
52      *
53      * <p>See <a href="http://b/22062676">b/22062676</a>
54      */
55     public static final Feature ANALYTICS_V2 = AND(ON, ANALYTICS_OPT_IN);
56 
57     public static final Feature EPG_SEARCH =
58             new PropertyFeature("feature_tv_use_epg_search", false);
59 
60     public static final Feature TUNER = new Feature() {
61         @Override
62         public boolean isEnabled(Context context) {
63 
64             // This is special handling just for USB Tuner.
65             // It does not require any N API's but relies on a improvements in N for AC3 support
66             // After release, change class to this to just be {@link BuildCompat#isAtLeastN()}.
67             return Build.VERSION.SDK_INT > Build.VERSION_CODES.M || BuildCompat.isAtLeastN();
68         }
69 
70     };
71 
72     private static final String GSERVICE_KEY_UNHIDE = "live_channels_unhide";
73     /**
74      * A flag which indicates that LC app is unhidden even when there is no input.
75      */
76     public static final Feature UNHIDE =
77             OR(new GServiceFeature(GSERVICE_KEY_UNHIDE, false), new Feature() {
78                 @Override
79                 public boolean isEnabled(Context context) {
80                     // If LC app runs as non-system app, we unhide the app.
81                     return !PermissionUtils.hasAccessAllEpg(context);
82                 }
83             });
84 
85     public static final Feature PICTURE_IN_PICTURE = new Feature() {
86         private Boolean mEnabled;
87 
88         @Override
89         public boolean isEnabled(Context context) {
90             if (mEnabled == null) {
91                 mEnabled = context.getPackageManager().hasSystemFeature(
92                         PackageManager.FEATURE_PICTURE_IN_PICTURE);
93             }
94             return mEnabled;
95         }
96     };
97 
98     /**
99      * Enable a conflict dialog between currently watched channel and upcoming recording.
100      */
101     public static final Feature SHOW_UPCOMING_CONFLICT_DIALOG = OFF;
102 
103     /**
104      * Use input blacklist to disable partner's tuner input.
105      */
106     public static final Feature USE_PARTNER_INPUT_BLACKLIST = ON;
107 
108     @VisibleForTesting
109     public static final Feature TEST_FEATURE = new PropertyFeature("test_feature", false);
110 
Features()111     private Features() {
112     }
113 }
114