• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.settings.overlay;
18 
19 import android.content.Context;
20 import android.text.TextUtils;
21 import android.util.Log;
22 
23 import androidx.annotation.Nullable;
24 
25 import com.android.tv.settings.R;
26 
27 /** An Util class that manages logic related to build flavor and feature. */
28 public final class FlavorUtils {
29 
30     private static final String TAG = "OverlayUtils";
31 
32     // Build flavors of TvSettings that determines
33     public static final int FLAVOR_UNDEFINED = 0b00000000; // Error/undefined flavor
34     public static final int FLAVOR_CLASSIC = 0b00000001;   // Ordinary classic one panel settings
35     public static final int FLAVOR_TWO_PANEL = 0b00000010; // Two panel settings
36     public static final int FLAVOR_X = 0b00000100;         // Two panel settings with the X overlay
37     public static final int FLAVOR_VENDOR = 0b00001000;    // Two panel settings with Vendor overlay
38 
39     public static final int ALL_FLAVORS_MASK =
40             FLAVOR_CLASSIC | FLAVOR_TWO_PANEL | FLAVOR_X | FLAVOR_VENDOR;
41     public static final int TWO_PANEL_FLAVORS_MASK = FLAVOR_TWO_PANEL | FLAVOR_X | FLAVOR_VENDOR;
42     public static final int X_EXPERIENCE_FLAVORS_MASK = FLAVOR_X | FLAVOR_VENDOR;
43 
44     private static FeatureFactory sFeatureFactory;
45 
46     /** Returns the flavor of current TvSettings. */
getFlavor(@ullable Context context)47     public static int getFlavor(@Nullable Context context) {
48         if (context == null) {
49             Log.w(TAG, "Trying to get flavor from null context. Returning undefined flavor.");
50             return FLAVOR_UNDEFINED;
51         }
52         String flavor = context.getString(R.string.config_tvSettingsFlavor);
53         if (TextUtils.isEmpty(flavor)) {
54             return FLAVOR_CLASSIC;
55         }
56         switch (flavor) {
57             case "Classic":
58                 return FLAVOR_CLASSIC;
59             case "TwoPanel":
60                 return FLAVOR_TWO_PANEL;
61             case "X":
62                 return FLAVOR_X;
63             case "Vendor":
64                 return FLAVOR_VENDOR;
65             default:
66                 Log.w(TAG, "Flavor is unspecified. Default to Classic flavor.");
67                 return FLAVOR_CLASSIC;
68         }
69     }
70 
71     /** Returns whether the UI is two panel style. */
isTwoPanel(@ullable Context context)72     public static boolean isTwoPanel(@Nullable Context context) {
73         return (getFlavor(context) & TWO_PANEL_FLAVORS_MASK) != 0;
74     }
75 
76     /** Returns the correct FeatureFactory. */
getFeatureFactory(@ullable Context context)77     public static FeatureFactory getFeatureFactory(@Nullable Context context) {
78         if (sFeatureFactory != null) {
79             return sFeatureFactory;
80         }
81         switch (getFlavor(context)) {
82             case FLAVOR_TWO_PANEL:
83                 sFeatureFactory = new FeatureFactoryImplTwoPanel();
84                 break;
85             case FLAVOR_X:
86             case FLAVOR_VENDOR:
87                 sFeatureFactory = new FeatureFactoryImplX();
88                 break;
89             case FLAVOR_CLASSIC:
90             case FLAVOR_UNDEFINED:
91             default:
92                 sFeatureFactory = new FeatureFactoryImpl();
93         }
94         return sFeatureFactory;
95     }
96 }
97