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.app.AppGlobals;
20 import android.app.admin.DevicePolicyManager;
21 import android.content.Context;
22 import android.net.ConnectivityManager;
23 import android.os.UserManager;
24 import android.support.annotation.Keep;
25 
26 import com.android.settings.applications.ApplicationFeatureProvider;
27 import com.android.settings.applications.ApplicationFeatureProviderImpl;
28 import com.android.settings.applications.IPackageManagerWrapperImpl;
29 import com.android.settings.applications.PackageManagerWrapperImpl;
30 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
31 import com.android.settings.dashboard.DashboardFeatureProvider;
32 import com.android.settings.dashboard.DashboardFeatureProviderImpl;
33 import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
34 import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
35 import com.android.settings.enterprise.DevicePolicyManagerWrapperImpl;
36 import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
37 import com.android.settings.enterprise.EnterprisePrivacyFeatureProviderImpl;
38 import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
39 import com.android.settings.fuelgauge.PowerUsageFeatureProviderImpl;
40 import com.android.settings.gestures.AssistGestureFeatureProvider;
41 import com.android.settings.gestures.AssistGestureFeatureProviderImpl;
42 import com.android.settings.localepicker.LocaleFeatureProvider;
43 import com.android.settings.localepicker.LocaleFeatureProviderImpl;
44 import com.android.settings.search2.SearchFeatureProvider;
45 import com.android.settings.search2.SearchFeatureProviderImpl;
46 import com.android.settings.security.SecurityFeatureProvider;
47 import com.android.settings.security.SecurityFeatureProviderImpl;
48 import com.android.settings.users.UserFeatureProvider;
49 import com.android.settings.users.UserFeatureProviderImpl;
50 import com.android.settings.vpn2.ConnectivityManagerWrapperImpl;
51 
52 /**
53  * {@link FeatureFactory} implementation for AOSP Settings.
54  */
55 @Keep
56 public class FeatureFactoryImpl extends FeatureFactory {
57 
58     private ApplicationFeatureProvider mApplicationFeatureProvider;
59     private MetricsFeatureProvider mMetricsFeatureProvider;
60     private DashboardFeatureProviderImpl mDashboardFeatureProvider;
61     private LocaleFeatureProvider mLocaleFeatureProvider;
62     private EnterprisePrivacyFeatureProvider mEnterprisePrivacyFeatureProvider;
63     private SearchFeatureProvider mSearchFeatureProvider;
64     private SecurityFeatureProvider mSecurityFeatureProvider;
65     private SuggestionFeatureProvider mSuggestionFeatureProvider;
66     private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
67     private AssistGestureFeatureProvider mAssistGestureFeatureProvider;
68     private UserFeatureProvider mUserFeatureProvider;
69 
70     @Override
getSupportFeatureProvider(Context context)71     public SupportFeatureProvider getSupportFeatureProvider(Context context) {
72         return null;
73     }
74 
75     @Override
getMetricsFeatureProvider()76     public MetricsFeatureProvider getMetricsFeatureProvider() {
77         if (mMetricsFeatureProvider == null) {
78             mMetricsFeatureProvider = new MetricsFeatureProvider();
79         }
80         return mMetricsFeatureProvider;
81     }
82 
83     @Override
getPowerUsageFeatureProvider(Context context)84     public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) {
85         if (mPowerUsageFeatureProvider == null) {
86             mPowerUsageFeatureProvider = new PowerUsageFeatureProviderImpl(context);
87         }
88         return mPowerUsageFeatureProvider;
89     }
90 
91     @Override
getDashboardFeatureProvider(Context context)92     public DashboardFeatureProvider getDashboardFeatureProvider(Context context) {
93         if (mDashboardFeatureProvider == null) {
94             mDashboardFeatureProvider = new DashboardFeatureProviderImpl(context);
95         }
96         return mDashboardFeatureProvider;
97     }
98 
99     @Override
getApplicationFeatureProvider(Context context)100     public ApplicationFeatureProvider getApplicationFeatureProvider(Context context) {
101         if (mApplicationFeatureProvider == null) {
102             mApplicationFeatureProvider = new ApplicationFeatureProviderImpl(context,
103                     new PackageManagerWrapperImpl(context.getPackageManager()),
104                     new IPackageManagerWrapperImpl(AppGlobals.getPackageManager()),
105                     new DevicePolicyManagerWrapperImpl((DevicePolicyManager) context
106                             .getSystemService(Context.DEVICE_POLICY_SERVICE)));
107         }
108         return mApplicationFeatureProvider;
109     }
110 
111     @Override
getLocaleFeatureProvider()112     public LocaleFeatureProvider getLocaleFeatureProvider() {
113         if (mLocaleFeatureProvider == null) {
114             mLocaleFeatureProvider = new LocaleFeatureProviderImpl();
115         }
116         return mLocaleFeatureProvider;
117     }
118 
119     @Override
getEnterprisePrivacyFeatureProvider(Context context)120     public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) {
121         if (mEnterprisePrivacyFeatureProvider == null) {
122             mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(context,
123                     new DevicePolicyManagerWrapperImpl((DevicePolicyManager) context
124                             .getSystemService(Context.DEVICE_POLICY_SERVICE)),
125                     new PackageManagerWrapperImpl(context.getPackageManager()),
126                     UserManager.get(context),
127                     new ConnectivityManagerWrapperImpl((ConnectivityManager) context
128                             .getSystemService(Context.CONNECTIVITY_SERVICE)),
129                     context.getResources());
130         }
131         return mEnterprisePrivacyFeatureProvider;
132     }
133 
134     @Override
getSearchFeatureProvider()135     public SearchFeatureProvider getSearchFeatureProvider() {
136         if (mSearchFeatureProvider == null) {
137             mSearchFeatureProvider = new SearchFeatureProviderImpl();
138         }
139         return mSearchFeatureProvider;
140     }
141 
142     @Override
getSurveyFeatureProvider(Context context)143     public SurveyFeatureProvider getSurveyFeatureProvider(Context context) {
144         return null;
145     }
146 
147     @Override
getSecurityFeatureProvider()148     public SecurityFeatureProvider getSecurityFeatureProvider() {
149         if (mSecurityFeatureProvider == null) {
150             mSecurityFeatureProvider = new SecurityFeatureProviderImpl();
151         }
152         return mSecurityFeatureProvider;
153     }
154 
155     @Override
getSuggestionFeatureProvider(Context context)156     public SuggestionFeatureProvider getSuggestionFeatureProvider(Context context) {
157         if (mSuggestionFeatureProvider == null) {
158             mSuggestionFeatureProvider = new SuggestionFeatureProviderImpl(context);
159         }
160         return mSuggestionFeatureProvider;
161     }
162 
163     @Override
getUserFeatureProvider(Context context)164     public UserFeatureProvider getUserFeatureProvider(Context context) {
165         if (mUserFeatureProvider == null) {
166             mUserFeatureProvider = new UserFeatureProviderImpl(context);
167         }
168         return mUserFeatureProvider;
169     }
170 
171     @Override
getAssistGestureFeatureProvider()172     public AssistGestureFeatureProvider getAssistGestureFeatureProvider() {
173         if (mAssistGestureFeatureProvider == null) {
174             mAssistGestureFeatureProvider = new AssistGestureFeatureProviderImpl();
175         }
176         return mAssistGestureFeatureProvider;
177     }
178 }
179