• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.settings.overlay;
18 
19 import android.content.Context;
20 import android.text.TextUtils;
21 import android.util.Log;
22 
23 import com.android.settings.R;
24 import com.android.settings.applications.ApplicationFeatureProvider;
25 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
26 import com.android.settings.dashboard.DashboardFeatureProvider;
27 import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
28 import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
29 import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
30 import com.android.settings.gestures.AssistGestureFeatureProvider;
31 import com.android.settings.localepicker.LocaleFeatureProvider;
32 import com.android.settings.security.SecurityFeatureProvider;
33 import com.android.settings.search2.SearchFeatureProvider;
34 import com.android.settings.users.UserFeatureProvider;
35 
36 /**
37  * Abstract class for creating feature controllers. Allows OEM implementations to define their own
38  * factories with their own controllers containing whatever code is needed to implement
39  * the features. To provide a factory implementation, implementors should override
40  * {@link R.string#config_featureFactory} in their override.
41  */
42 public abstract class FeatureFactory {
43     private static final String LOG_TAG = "FeatureFactory";
44     private static final boolean DEBUG = false;
45 
46     protected static FeatureFactory sFactory;
47 
48     /**
49      * Returns a factory for creating feature controllers. Creates the factory if it does not
50      * already exist. Uses the value of {@link R.string#config_featureFactory} to instantiate
51      * a factory implementation.
52      */
getFactory(Context context)53     public static FeatureFactory getFactory(Context context) {
54         if (sFactory != null) {
55             return sFactory;
56         }
57 
58         if (DEBUG) Log.d(LOG_TAG, "getFactory");
59         final String clsName = context.getString(R.string.config_featureFactory);
60         if (TextUtils.isEmpty(clsName)) {
61             throw new UnsupportedOperationException("No feature factory configured");
62         }
63         try {
64             sFactory = (FeatureFactory) context.getClassLoader().loadClass(clsName).newInstance();
65         } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
66             throw new FactoryNotFoundException(e);
67         }
68 
69         if (DEBUG) Log.d(LOG_TAG, "started " + sFactory.getClass().getSimpleName());
70         return sFactory;
71     }
72 
getAssistGestureFeatureProvider()73     public abstract AssistGestureFeatureProvider getAssistGestureFeatureProvider();
74 
getSuggestionFeatureProvider(Context context)75     public abstract SuggestionFeatureProvider getSuggestionFeatureProvider(Context context);
76 
getSupportFeatureProvider(Context context)77     public abstract SupportFeatureProvider getSupportFeatureProvider(Context context);
78 
getMetricsFeatureProvider()79     public abstract MetricsFeatureProvider getMetricsFeatureProvider();
80 
getPowerUsageFeatureProvider(Context context)81     public abstract PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context);
82 
getDashboardFeatureProvider(Context context)83     public abstract DashboardFeatureProvider getDashboardFeatureProvider(Context context);
84 
getApplicationFeatureProvider(Context context)85     public abstract ApplicationFeatureProvider getApplicationFeatureProvider(Context context);
86 
getLocaleFeatureProvider()87     public abstract LocaleFeatureProvider getLocaleFeatureProvider();
88 
getEnterprisePrivacyFeatureProvider( Context context)89     public abstract EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(
90             Context context);
91 
getSearchFeatureProvider()92     public abstract SearchFeatureProvider getSearchFeatureProvider();
93 
getSurveyFeatureProvider(Context context)94     public abstract SurveyFeatureProvider getSurveyFeatureProvider(Context context);
95 
getSecurityFeatureProvider()96     public abstract SecurityFeatureProvider getSecurityFeatureProvider();
97 
getUserFeatureProvider(Context context)98     public abstract UserFeatureProvider getUserFeatureProvider(Context context);
99 
100     public static final class FactoryNotFoundException extends RuntimeException {
FactoryNotFoundException(Throwable throwable)101         public FactoryNotFoundException(Throwable throwable) {
102             super("Unable to create factory. Did you misconfigure Proguard?", throwable);
103         }
104     }
105 }
106