1 /* 2 * Copyright (C) 2019 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.car.developeroptions.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 25 import androidx.annotation.Keep; 26 27 import com.android.car.developeroptions.accounts.AccountFeatureProvider; 28 import com.android.car.developeroptions.accounts.AccountFeatureProviderImpl; 29 import com.android.car.developeroptions.applications.ApplicationFeatureProvider; 30 import com.android.car.developeroptions.applications.ApplicationFeatureProviderImpl; 31 import com.android.car.developeroptions.aware.AwareFeatureProvider; 32 import com.android.car.developeroptions.aware.AwareFeatureProviderImpl; 33 import com.android.car.developeroptions.bluetooth.BluetoothFeatureProvider; 34 import com.android.car.developeroptions.bluetooth.BluetoothFeatureProviderImpl; 35 import com.android.car.developeroptions.connecteddevice.dock.DockUpdaterFeatureProviderImpl; 36 import com.android.car.developeroptions.core.instrumentation.SettingsMetricsFeatureProvider; 37 import com.android.car.developeroptions.dashboard.DashboardFeatureProvider; 38 import com.android.car.developeroptions.dashboard.DashboardFeatureProviderImpl; 39 import com.android.car.developeroptions.dashboard.suggestions.SuggestionFeatureProvider; 40 import com.android.car.developeroptions.dashboard.suggestions.SuggestionFeatureProviderImpl; 41 import com.android.car.developeroptions.enterprise.EnterprisePrivacyFeatureProvider; 42 import com.android.car.developeroptions.enterprise.EnterprisePrivacyFeatureProviderImpl; 43 import com.android.car.developeroptions.fuelgauge.PowerUsageFeatureProvider; 44 import com.android.car.developeroptions.fuelgauge.PowerUsageFeatureProviderImpl; 45 import com.android.car.developeroptions.gestures.AssistGestureFeatureProvider; 46 import com.android.car.developeroptions.gestures.AssistGestureFeatureProviderImpl; 47 import com.android.car.developeroptions.homepage.contextualcards.ContextualCardFeatureProvider; 48 import com.android.car.developeroptions.homepage.contextualcards.ContextualCardFeatureProviderImpl; 49 import com.android.car.developeroptions.localepicker.LocaleFeatureProvider; 50 import com.android.car.developeroptions.localepicker.LocaleFeatureProviderImpl; 51 import com.android.car.developeroptions.panel.PanelFeatureProvider; 52 import com.android.car.developeroptions.panel.PanelFeatureProviderImpl; 53 import com.android.car.developeroptions.search.SearchFeatureProvider; 54 import com.android.car.developeroptions.search.SearchFeatureProviderImpl; 55 import com.android.car.developeroptions.security.SecurityFeatureProvider; 56 import com.android.car.developeroptions.security.SecurityFeatureProviderImpl; 57 import com.android.car.developeroptions.slices.SlicesFeatureProvider; 58 import com.android.car.developeroptions.slices.SlicesFeatureProviderImpl; 59 import com.android.car.developeroptions.users.UserFeatureProvider; 60 import com.android.car.developeroptions.users.UserFeatureProviderImpl; 61 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; 62 63 /** 64 * {@link FeatureFactory} implementation for AOSP Settings. 65 */ 66 @Keep 67 public class FeatureFactoryImpl extends FeatureFactory { 68 69 private ApplicationFeatureProvider mApplicationFeatureProvider; 70 private MetricsFeatureProvider mMetricsFeatureProvider; 71 private DashboardFeatureProviderImpl mDashboardFeatureProvider; 72 private DockUpdaterFeatureProvider mDockUpdaterFeatureProvider; 73 private LocaleFeatureProvider mLocaleFeatureProvider; 74 private EnterprisePrivacyFeatureProvider mEnterprisePrivacyFeatureProvider; 75 private SearchFeatureProvider mSearchFeatureProvider; 76 private SecurityFeatureProvider mSecurityFeatureProvider; 77 private SuggestionFeatureProvider mSuggestionFeatureProvider; 78 private PowerUsageFeatureProvider mPowerUsageFeatureProvider; 79 private AssistGestureFeatureProvider mAssistGestureFeatureProvider; 80 private UserFeatureProvider mUserFeatureProvider; 81 private SlicesFeatureProvider mSlicesFeatureProvider; 82 private AccountFeatureProvider mAccountFeatureProvider; 83 private PanelFeatureProvider mPanelFeatureProvider; 84 private ContextualCardFeatureProvider mContextualCardFeatureProvider; 85 private BluetoothFeatureProvider mBluetoothFeatureProvider; 86 private AwareFeatureProvider mAwareFeatureProvider; 87 88 @Override getSupportFeatureProvider(Context context)89 public SupportFeatureProvider getSupportFeatureProvider(Context context) { 90 return null; 91 } 92 93 @Override getMetricsFeatureProvider()94 public MetricsFeatureProvider getMetricsFeatureProvider() { 95 if (mMetricsFeatureProvider == null) { 96 mMetricsFeatureProvider = new SettingsMetricsFeatureProvider(); 97 } 98 return mMetricsFeatureProvider; 99 } 100 101 @Override getPowerUsageFeatureProvider(Context context)102 public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) { 103 if (mPowerUsageFeatureProvider == null) { 104 mPowerUsageFeatureProvider = new PowerUsageFeatureProviderImpl( 105 context.getApplicationContext()); 106 } 107 return mPowerUsageFeatureProvider; 108 } 109 110 @Override getDashboardFeatureProvider(Context context)111 public DashboardFeatureProvider getDashboardFeatureProvider(Context context) { 112 if (mDashboardFeatureProvider == null) { 113 mDashboardFeatureProvider = new DashboardFeatureProviderImpl( 114 context.getApplicationContext()); 115 } 116 return mDashboardFeatureProvider; 117 } 118 119 @Override getDockUpdaterFeatureProvider()120 public DockUpdaterFeatureProvider getDockUpdaterFeatureProvider() { 121 if (mDockUpdaterFeatureProvider == null) { 122 mDockUpdaterFeatureProvider = new DockUpdaterFeatureProviderImpl(); 123 } 124 return mDockUpdaterFeatureProvider; 125 } 126 127 @Override getApplicationFeatureProvider(Context context)128 public ApplicationFeatureProvider getApplicationFeatureProvider(Context context) { 129 if (mApplicationFeatureProvider == null) { 130 final Context appContext = context.getApplicationContext(); 131 mApplicationFeatureProvider = new ApplicationFeatureProviderImpl(appContext, 132 appContext.getPackageManager(), 133 AppGlobals.getPackageManager(), 134 (DevicePolicyManager) appContext 135 .getSystemService(Context.DEVICE_POLICY_SERVICE)); 136 } 137 return mApplicationFeatureProvider; 138 } 139 140 @Override getLocaleFeatureProvider()141 public LocaleFeatureProvider getLocaleFeatureProvider() { 142 if (mLocaleFeatureProvider == null) { 143 mLocaleFeatureProvider = new LocaleFeatureProviderImpl(); 144 } 145 return mLocaleFeatureProvider; 146 } 147 148 @Override getEnterprisePrivacyFeatureProvider(Context context)149 public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) { 150 if (mEnterprisePrivacyFeatureProvider == null) { 151 final Context appContext = context.getApplicationContext(); 152 mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(appContext, 153 (DevicePolicyManager) appContext.getSystemService( 154 Context.DEVICE_POLICY_SERVICE), 155 appContext.getPackageManager(), 156 UserManager.get(appContext), 157 (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE), 158 appContext.getResources()); 159 } 160 return mEnterprisePrivacyFeatureProvider; 161 } 162 163 @Override getSearchFeatureProvider()164 public SearchFeatureProvider getSearchFeatureProvider() { 165 if (mSearchFeatureProvider == null) { 166 mSearchFeatureProvider = new SearchFeatureProviderImpl(); 167 } 168 return mSearchFeatureProvider; 169 } 170 171 @Override getSurveyFeatureProvider(Context context)172 public SurveyFeatureProvider getSurveyFeatureProvider(Context context) { 173 return null; 174 } 175 176 @Override getSecurityFeatureProvider()177 public SecurityFeatureProvider getSecurityFeatureProvider() { 178 if (mSecurityFeatureProvider == null) { 179 mSecurityFeatureProvider = new SecurityFeatureProviderImpl(); 180 } 181 return mSecurityFeatureProvider; 182 } 183 184 @Override getSuggestionFeatureProvider(Context context)185 public SuggestionFeatureProvider getSuggestionFeatureProvider(Context context) { 186 if (mSuggestionFeatureProvider == null) { 187 mSuggestionFeatureProvider = new SuggestionFeatureProviderImpl( 188 context.getApplicationContext()); 189 } 190 return mSuggestionFeatureProvider; 191 } 192 193 @Override getUserFeatureProvider(Context context)194 public UserFeatureProvider getUserFeatureProvider(Context context) { 195 if (mUserFeatureProvider == null) { 196 mUserFeatureProvider = new UserFeatureProviderImpl(context.getApplicationContext()); 197 } 198 return mUserFeatureProvider; 199 } 200 201 @Override getAssistGestureFeatureProvider()202 public AssistGestureFeatureProvider getAssistGestureFeatureProvider() { 203 if (mAssistGestureFeatureProvider == null) { 204 mAssistGestureFeatureProvider = new AssistGestureFeatureProviderImpl(); 205 } 206 return mAssistGestureFeatureProvider; 207 } 208 209 @Override getSlicesFeatureProvider()210 public SlicesFeatureProvider getSlicesFeatureProvider() { 211 if (mSlicesFeatureProvider == null) { 212 mSlicesFeatureProvider = new SlicesFeatureProviderImpl(); 213 } 214 return mSlicesFeatureProvider; 215 } 216 217 @Override getAccountFeatureProvider()218 public AccountFeatureProvider getAccountFeatureProvider() { 219 if (mAccountFeatureProvider == null) { 220 mAccountFeatureProvider = new AccountFeatureProviderImpl(); 221 } 222 return mAccountFeatureProvider; 223 } 224 225 @Override getPanelFeatureProvider()226 public PanelFeatureProvider getPanelFeatureProvider() { 227 if (mPanelFeatureProvider == null) { 228 mPanelFeatureProvider = new PanelFeatureProviderImpl(); 229 } 230 return mPanelFeatureProvider; 231 } 232 233 @Override getContextualCardFeatureProvider(Context context)234 public ContextualCardFeatureProvider getContextualCardFeatureProvider(Context context) { 235 if (mContextualCardFeatureProvider == null) { 236 mContextualCardFeatureProvider = new ContextualCardFeatureProviderImpl( 237 context.getApplicationContext()); 238 } 239 return mContextualCardFeatureProvider; 240 } 241 242 @Override getBluetoothFeatureProvider(Context context)243 public BluetoothFeatureProvider getBluetoothFeatureProvider(Context context) { 244 if (mBluetoothFeatureProvider == null) { 245 mBluetoothFeatureProvider = new BluetoothFeatureProviderImpl( 246 context.getApplicationContext()); 247 } 248 return mBluetoothFeatureProvider; 249 } 250 251 @Override getAwareFeatureProvider()252 public AwareFeatureProvider getAwareFeatureProvider() { 253 if (mAwareFeatureProvider == null) { 254 mAwareFeatureProvider = new AwareFeatureProviderImpl(); 255 } 256 return mAwareFeatureProvider; 257 } 258 } 259