blob: d9af345d6522277083749a11745a865fc28d7b15 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.overlay;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.Nullable;
import com.android.settings.R;
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.aware.AwareFeatureProvider;
import com.android.settings.bluetooth.BluetoothFeatureProvider;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.gestures.AssistGestureFeatureProvider;
import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProvider;
import com.android.settings.panel.PanelFeatureProvider;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.security.SecurityFeatureProvider;
import com.android.settings.slices.SlicesFeatureProvider;
import com.android.settings.users.UserFeatureProvider;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
/**
* Abstract class for creating feature controllers. Allows OEM implementations to define their own
* factories with their own controllers containing whatever code is needed to implement
* the features. To provide a factory implementation, implementors should override
* {@link R.string#config_featureFactory} in their override.
*/
public abstract class FeatureFactory {
private static final String LOG_TAG = "FeatureFactory";
private static final boolean DEBUG = false;
protected static FeatureFactory sFactory;
protected static Context sAppContext;
/**
* Returns a factory for creating feature controllers. Creates the factory if it does not
* already exist. Uses the value of {@link R.string#config_featureFactory} to instantiate
* a factory implementation.
*/
public static FeatureFactory getFactory(Context context) {
if (sFactory != null) {
return sFactory;
}
if (sAppContext == null) {
sAppContext = context.getApplicationContext();
}
if (DEBUG) Log.d(LOG_TAG, "getFactory");
final String clsName = context.getString(R.string.config_featureFactory);
if (TextUtils.isEmpty(clsName)) {
throw new UnsupportedOperationException("No feature factory configured");
}
try {
sFactory = (FeatureFactory) context.getClassLoader().loadClass(clsName).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new FactoryNotFoundException(e);
}
if (DEBUG) Log.d(LOG_TAG, "started " + sFactory.getClass().getSimpleName());
return sFactory;
}
/**
* Returns an application {@link Context} used to create this {@link FeatureFactory}. If the
* factory has not been properly created yet (aka {@link #getFactory} has not been called), this
* will return null.
*/
@Nullable
public static Context getAppContext() {
return sAppContext;
}
public abstract AssistGestureFeatureProvider getAssistGestureFeatureProvider();
public abstract SuggestionFeatureProvider getSuggestionFeatureProvider(Context context);
public abstract SupportFeatureProvider getSupportFeatureProvider(Context context);
public abstract MetricsFeatureProvider getMetricsFeatureProvider();
public abstract PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context);
public abstract DashboardFeatureProvider getDashboardFeatureProvider(Context context);
public abstract DockUpdaterFeatureProvider getDockUpdaterFeatureProvider();
public abstract ApplicationFeatureProvider getApplicationFeatureProvider(Context context);
public abstract LocaleFeatureProvider getLocaleFeatureProvider();
public abstract EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(
Context context);
public abstract SearchFeatureProvider getSearchFeatureProvider();
public abstract SurveyFeatureProvider getSurveyFeatureProvider(Context context);
public abstract SecurityFeatureProvider getSecurityFeatureProvider();
public abstract UserFeatureProvider getUserFeatureProvider(Context context);
public abstract SlicesFeatureProvider getSlicesFeatureProvider();
public abstract AccountFeatureProvider getAccountFeatureProvider();
public abstract PanelFeatureProvider getPanelFeatureProvider();
public abstract ContextualCardFeatureProvider getContextualCardFeatureProvider(Context context);
public abstract BluetoothFeatureProvider getBluetoothFeatureProvider(Context context);
public abstract AwareFeatureProvider getAwareFeatureProvider();
public static final class FactoryNotFoundException extends RuntimeException {
public FactoryNotFoundException(Throwable throwable) {
super("Unable to create factory. Did you misconfigure Proguard?", throwable);
}
}
}
|