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