1 /*
2  * Copyright (C) 2018 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.features;
18 
19 import android.content.Context;
20 import android.os.Build.VERSION;
21 import android.os.Build.VERSION_CODES;
22 import com.android.tv.common.feature.Feature;
23 import com.google.android.tv.partner.support.PartnerCustomizations;
24 
25 /** Features backed by {@link PartnerCustomizations}. */
26 @SuppressWarnings("AndroidApiChecker") // TODO(b/32513850) remove when error prone is updated
27 public final class PartnerFeatures {
28 
29     public static final Feature TVPROVIDER_ALLOWS_SYSTEM_INSERTS_TO_PROGRAM_TABLE =
30             new PartnerFeature(
31                     PartnerCustomizations.TVPROVIDER_ALLOWS_SYSTEM_INSERTS_TO_PROGRAM_TABLE);
32 
33     public static final Feature TURN_OFF_EMBEDDED_TUNER =
34             new PartnerFeature(PartnerCustomizations.TURN_OFF_EMBEDDED_TUNER);
35 
36     public static final Feature TVPROVIDER_ALLOWS_COLUMN_CREATION =
37             new PartnerFeature(PartnerCustomizations.TVPROVIDER_ALLOWS_COLUMN_CREATION);
38 
39     private static class PartnerFeature implements Feature {
40 
41         private final String property;
42 
PartnerFeature(String property)43         public PartnerFeature(String property) {
44             this.property = property;
45         }
46 
47         @Override
isEnabled(Context context)48         public boolean isEnabled(Context context) {
49             if (VERSION.SDK_INT >= VERSION_CODES.N) {
50                 PartnerCustomizations partnerCustomizations = new PartnerCustomizations(context);
51                 return partnerCustomizations.getBooleanResource(context, property).orElse(false);
52             }
53             return false;
54         }
55     }
56 
PartnerFeatures()57     private PartnerFeatures() {}
58 }
59