Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 android.app; |
| 18 | |
| 19 | import com.android.internal.app.IAppOpsService; |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 20 | import com.android.internal.app.ISoundTriggerService; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 21 | import com.android.internal.appwidget.IAppWidgetService; |
| 22 | import com.android.internal.os.IDropBoxManagerService; |
| 23 | |
| 24 | import android.accounts.AccountManager; |
| 25 | import android.accounts.IAccountManager; |
| 26 | import android.app.admin.DevicePolicyManager; |
| 27 | import android.app.job.IJobScheduler; |
| 28 | import android.app.job.JobScheduler; |
| 29 | import android.app.trust.TrustManager; |
| 30 | import android.app.usage.IUsageStatsManager; |
Zoltan Szatmary-Ban | 9c5dfa5 | 2015-02-23 17:20:20 +0000 | [diff] [blame] | 31 | import android.app.usage.NetworkStatsManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 32 | import android.app.usage.UsageStatsManager; |
| 33 | import android.appwidget.AppWidgetManager; |
| 34 | import android.bluetooth.BluetoothManager; |
| 35 | import android.content.ClipboardManager; |
| 36 | import android.content.Context; |
| 37 | import android.content.IRestrictionsManager; |
| 38 | import android.content.RestrictionsManager; |
| 39 | import android.content.pm.ILauncherApps; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 40 | import android.content.pm.IShortcutService; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 41 | import android.content.pm.LauncherApps; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 42 | import android.content.pm.ShortcutManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 43 | import android.content.res.Resources; |
| 44 | import android.hardware.ConsumerIrManager; |
| 45 | import android.hardware.ISerialManager; |
| 46 | import android.hardware.SensorManager; |
| 47 | import android.hardware.SerialManager; |
| 48 | import android.hardware.SystemSensorManager; |
| 49 | import android.hardware.camera2.CameraManager; |
| 50 | import android.hardware.display.DisplayManager; |
| 51 | import android.hardware.hdmi.HdmiControlManager; |
| 52 | import android.hardware.hdmi.IHdmiControlService; |
| 53 | import android.hardware.input.InputManager; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 54 | import android.hardware.location.ContextHubManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 55 | import android.hardware.usb.IUsbManager; |
| 56 | import android.hardware.usb.UsbManager; |
Eric Laurent | 2035ac8 | 2015-03-05 15:18:44 -0800 | [diff] [blame] | 57 | import android.hardware.radio.RadioManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 58 | import android.location.CountryDetector; |
| 59 | import android.location.ICountryDetector; |
| 60 | import android.location.ILocationManager; |
| 61 | import android.location.LocationManager; |
| 62 | import android.media.AudioManager; |
| 63 | import android.media.MediaRouter; |
| 64 | import android.media.midi.IMidiManager; |
| 65 | import android.media.midi.MidiManager; |
| 66 | import android.media.projection.MediaProjectionManager; |
| 67 | import android.media.session.MediaSessionManager; |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 68 | import android.media.soundtrigger.SoundTriggerManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 69 | import android.media.tv.ITvInputManager; |
| 70 | import android.media.tv.TvInputManager; |
| 71 | import android.net.ConnectivityManager; |
Paul Stewart | bf8cbb05 | 2016-03-17 10:11:54 -0700 | [diff] [blame] | 72 | import android.net.ConnectivityThread; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 73 | import android.net.EthernetManager; |
| 74 | import android.net.IConnectivityManager; |
| 75 | import android.net.IEthernetManager; |
| 76 | import android.net.INetworkPolicyManager; |
| 77 | import android.net.NetworkPolicyManager; |
| 78 | import android.net.NetworkScoreManager; |
| 79 | import android.net.nsd.INsdManager; |
| 80 | import android.net.nsd.NsdManager; |
| 81 | import android.net.wifi.IRttManager; |
| 82 | import android.net.wifi.IWifiManager; |
| 83 | import android.net.wifi.IWifiScanner; |
| 84 | import android.net.wifi.RttManager; |
| 85 | import android.net.wifi.WifiManager; |
| 86 | import android.net.wifi.WifiScanner; |
Etan Cohen | 20d329b | 2015-09-29 13:49:02 -0700 | [diff] [blame] | 87 | import android.net.wifi.nan.IWifiNanManager; |
| 88 | import android.net.wifi.nan.WifiNanManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 89 | import android.net.wifi.p2p.IWifiP2pManager; |
| 90 | import android.net.wifi.p2p.WifiP2pManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 91 | import android.nfc.NfcManager; |
| 92 | import android.os.BatteryManager; |
| 93 | import android.os.DropBoxManager; |
Polina Bondarenko | 965ecbb | 2015-11-13 15:34:28 +0100 | [diff] [blame] | 94 | import android.os.HardwarePropertiesManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 95 | import android.os.IBinder; |
Polina Bondarenko | f8754ac | 2016-02-12 20:38:23 +0100 | [diff] [blame] | 96 | import android.os.IHardwarePropertiesManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 97 | import android.os.IPowerManager; |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 98 | import android.os.IRecoverySystem; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 99 | import android.os.IUserManager; |
| 100 | import android.os.PowerManager; |
| 101 | import android.os.Process; |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 102 | import android.os.RecoverySystem; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 103 | import android.os.ServiceManager; |
| 104 | import android.os.SystemVibrator; |
| 105 | import android.os.UserHandle; |
| 106 | import android.os.UserManager; |
| 107 | import android.os.Vibrator; |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 108 | import android.os.health.SystemHealthManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 109 | import android.os.storage.StorageManager; |
| 110 | import android.print.IPrintManager; |
| 111 | import android.print.PrintManager; |
Jim Miller | ebbf205 | 2015-03-31 17:24:34 -0700 | [diff] [blame] | 112 | import android.hardware.fingerprint.FingerprintManager; |
| 113 | import android.hardware.fingerprint.IFingerprintService; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 114 | import android.service.persistentdata.IPersistentDataBlockService; |
| 115 | import android.service.persistentdata.PersistentDataBlockManager; |
| 116 | import android.telecom.TelecomManager; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 117 | import android.telephony.CarrierConfigManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 118 | import android.telephony.SubscriptionManager; |
| 119 | import android.telephony.TelephonyManager; |
| 120 | import android.util.Log; |
| 121 | import android.view.ContextThemeWrapper; |
| 122 | import android.view.LayoutInflater; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 123 | import com.android.internal.policy.PhoneLayoutInflater; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 124 | import android.view.WindowManager; |
| 125 | import android.view.WindowManagerImpl; |
| 126 | import android.view.accessibility.AccessibilityManager; |
| 127 | import android.view.accessibility.CaptioningManager; |
| 128 | import android.view.inputmethod.InputMethodManager; |
| 129 | import android.view.textservice.TextServicesManager; |
| 130 | |
| 131 | import java.util.HashMap; |
| 132 | |
| 133 | /** |
| 134 | * Manages all of the system services that can be returned by {@link Context#getSystemService}. |
| 135 | * Used by {@link ContextImpl}. |
| 136 | */ |
| 137 | final class SystemServiceRegistry { |
| 138 | private final static String TAG = "SystemServiceRegistry"; |
| 139 | |
| 140 | // Service registry information. |
| 141 | // This information is never changed once static initialization has completed. |
| 142 | private static final HashMap<Class<?>, String> SYSTEM_SERVICE_NAMES = |
| 143 | new HashMap<Class<?>, String>(); |
| 144 | private static final HashMap<String, ServiceFetcher<?>> SYSTEM_SERVICE_FETCHERS = |
| 145 | new HashMap<String, ServiceFetcher<?>>(); |
| 146 | private static int sServiceCacheSize; |
| 147 | |
| 148 | // Not instantiable. |
| 149 | private SystemServiceRegistry() { } |
| 150 | |
| 151 | static { |
| 152 | registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class, |
| 153 | new CachedServiceFetcher<AccessibilityManager>() { |
| 154 | @Override |
| 155 | public AccessibilityManager createService(ContextImpl ctx) { |
| 156 | return AccessibilityManager.getInstance(ctx); |
| 157 | }}); |
| 158 | |
| 159 | registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class, |
| 160 | new CachedServiceFetcher<CaptioningManager>() { |
| 161 | @Override |
| 162 | public CaptioningManager createService(ContextImpl ctx) { |
| 163 | return new CaptioningManager(ctx); |
| 164 | }}); |
| 165 | |
| 166 | registerService(Context.ACCOUNT_SERVICE, AccountManager.class, |
| 167 | new CachedServiceFetcher<AccountManager>() { |
| 168 | @Override |
| 169 | public AccountManager createService(ContextImpl ctx) { |
| 170 | IBinder b = ServiceManager.getService(Context.ACCOUNT_SERVICE); |
| 171 | IAccountManager service = IAccountManager.Stub.asInterface(b); |
| 172 | return new AccountManager(ctx, service); |
| 173 | }}); |
| 174 | |
| 175 | registerService(Context.ACTIVITY_SERVICE, ActivityManager.class, |
| 176 | new CachedServiceFetcher<ActivityManager>() { |
| 177 | @Override |
| 178 | public ActivityManager createService(ContextImpl ctx) { |
| 179 | return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); |
| 180 | }}); |
| 181 | |
| 182 | registerService(Context.ALARM_SERVICE, AlarmManager.class, |
| 183 | new CachedServiceFetcher<AlarmManager>() { |
| 184 | @Override |
| 185 | public AlarmManager createService(ContextImpl ctx) { |
| 186 | IBinder b = ServiceManager.getService(Context.ALARM_SERVICE); |
| 187 | IAlarmManager service = IAlarmManager.Stub.asInterface(b); |
| 188 | return new AlarmManager(service, ctx); |
| 189 | }}); |
| 190 | |
| 191 | registerService(Context.AUDIO_SERVICE, AudioManager.class, |
| 192 | new CachedServiceFetcher<AudioManager>() { |
| 193 | @Override |
| 194 | public AudioManager createService(ContextImpl ctx) { |
| 195 | return new AudioManager(ctx); |
| 196 | }}); |
| 197 | |
| 198 | registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class, |
| 199 | new CachedServiceFetcher<MediaRouter>() { |
| 200 | @Override |
| 201 | public MediaRouter createService(ContextImpl ctx) { |
| 202 | return new MediaRouter(ctx); |
| 203 | }}); |
| 204 | |
| 205 | registerService(Context.BLUETOOTH_SERVICE, BluetoothManager.class, |
| 206 | new CachedServiceFetcher<BluetoothManager>() { |
| 207 | @Override |
| 208 | public BluetoothManager createService(ContextImpl ctx) { |
| 209 | return new BluetoothManager(ctx); |
| 210 | }}); |
| 211 | |
| 212 | registerService(Context.HDMI_CONTROL_SERVICE, HdmiControlManager.class, |
| 213 | new StaticServiceFetcher<HdmiControlManager>() { |
| 214 | @Override |
| 215 | public HdmiControlManager createService() { |
| 216 | IBinder b = ServiceManager.getService(Context.HDMI_CONTROL_SERVICE); |
| 217 | return new HdmiControlManager(IHdmiControlService.Stub.asInterface(b)); |
| 218 | }}); |
| 219 | |
| 220 | registerService(Context.CLIPBOARD_SERVICE, ClipboardManager.class, |
| 221 | new CachedServiceFetcher<ClipboardManager>() { |
| 222 | @Override |
| 223 | public ClipboardManager createService(ContextImpl ctx) { |
| 224 | return new ClipboardManager(ctx.getOuterContext(), |
| 225 | ctx.mMainThread.getHandler()); |
| 226 | }}); |
| 227 | |
| 228 | // The clipboard service moved to a new package. If someone asks for the old |
| 229 | // interface by class then we want to redirect over to the new interface instead |
| 230 | // (which extends it). |
| 231 | SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE); |
| 232 | |
| 233 | registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class, |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 234 | new StaticApplicationContextServiceFetcher<ConnectivityManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 235 | @Override |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 236 | public ConnectivityManager createService(Context context) { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 237 | IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 238 | IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
| 239 | return new ConnectivityManager(context, service); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 240 | }}); |
| 241 | |
| 242 | registerService(Context.COUNTRY_DETECTOR, CountryDetector.class, |
| 243 | new StaticServiceFetcher<CountryDetector>() { |
| 244 | @Override |
| 245 | public CountryDetector createService() { |
| 246 | IBinder b = ServiceManager.getService(Context.COUNTRY_DETECTOR); |
| 247 | return new CountryDetector(ICountryDetector.Stub.asInterface(b)); |
| 248 | }}); |
| 249 | |
| 250 | registerService(Context.DEVICE_POLICY_SERVICE, DevicePolicyManager.class, |
| 251 | new CachedServiceFetcher<DevicePolicyManager>() { |
| 252 | @Override |
| 253 | public DevicePolicyManager createService(ContextImpl ctx) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 254 | return DevicePolicyManager.create(ctx); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 255 | }}); |
| 256 | |
| 257 | registerService(Context.DOWNLOAD_SERVICE, DownloadManager.class, |
| 258 | new CachedServiceFetcher<DownloadManager>() { |
| 259 | @Override |
| 260 | public DownloadManager createService(ContextImpl ctx) { |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 261 | return new DownloadManager(ctx); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 262 | }}); |
| 263 | |
| 264 | registerService(Context.BATTERY_SERVICE, BatteryManager.class, |
| 265 | new StaticServiceFetcher<BatteryManager>() { |
| 266 | @Override |
| 267 | public BatteryManager createService() { |
| 268 | return new BatteryManager(); |
| 269 | }}); |
| 270 | |
| 271 | registerService(Context.NFC_SERVICE, NfcManager.class, |
| 272 | new CachedServiceFetcher<NfcManager>() { |
| 273 | @Override |
| 274 | public NfcManager createService(ContextImpl ctx) { |
| 275 | return new NfcManager(ctx); |
| 276 | }}); |
| 277 | |
| 278 | registerService(Context.DROPBOX_SERVICE, DropBoxManager.class, |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 279 | new CachedServiceFetcher<DropBoxManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 280 | @Override |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 281 | public DropBoxManager createService(ContextImpl ctx) { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 282 | IBinder b = ServiceManager.getService(Context.DROPBOX_SERVICE); |
| 283 | IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b); |
| 284 | if (service == null) { |
| 285 | // Don't return a DropBoxManager that will NPE upon use. |
| 286 | // This also avoids caching a broken DropBoxManager in |
| 287 | // getDropBoxManager during early boot, before the |
| 288 | // DROPBOX_SERVICE is registered. |
| 289 | return null; |
| 290 | } |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 291 | return new DropBoxManager(ctx, service); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 292 | }}); |
| 293 | |
| 294 | registerService(Context.INPUT_SERVICE, InputManager.class, |
| 295 | new StaticServiceFetcher<InputManager>() { |
| 296 | @Override |
| 297 | public InputManager createService() { |
| 298 | return InputManager.getInstance(); |
| 299 | }}); |
| 300 | |
| 301 | registerService(Context.DISPLAY_SERVICE, DisplayManager.class, |
| 302 | new CachedServiceFetcher<DisplayManager>() { |
| 303 | @Override |
| 304 | public DisplayManager createService(ContextImpl ctx) { |
| 305 | return new DisplayManager(ctx.getOuterContext()); |
| 306 | }}); |
| 307 | |
| 308 | registerService(Context.INPUT_METHOD_SERVICE, InputMethodManager.class, |
| 309 | new StaticServiceFetcher<InputMethodManager>() { |
| 310 | @Override |
| 311 | public InputMethodManager createService() { |
| 312 | return InputMethodManager.getInstance(); |
| 313 | }}); |
| 314 | |
| 315 | registerService(Context.TEXT_SERVICES_MANAGER_SERVICE, TextServicesManager.class, |
| 316 | new StaticServiceFetcher<TextServicesManager>() { |
| 317 | @Override |
| 318 | public TextServicesManager createService() { |
| 319 | return TextServicesManager.getInstance(); |
| 320 | }}); |
| 321 | |
| 322 | registerService(Context.KEYGUARD_SERVICE, KeyguardManager.class, |
| 323 | new StaticServiceFetcher<KeyguardManager>() { |
| 324 | @Override |
| 325 | public KeyguardManager createService() { |
| 326 | return new KeyguardManager(); |
| 327 | }}); |
| 328 | |
| 329 | registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class, |
| 330 | new CachedServiceFetcher<LayoutInflater>() { |
| 331 | @Override |
| 332 | public LayoutInflater createService(ContextImpl ctx) { |
| 333 | return new PhoneLayoutInflater(ctx.getOuterContext()); |
| 334 | }}); |
| 335 | |
| 336 | registerService(Context.LOCATION_SERVICE, LocationManager.class, |
| 337 | new CachedServiceFetcher<LocationManager>() { |
| 338 | @Override |
| 339 | public LocationManager createService(ContextImpl ctx) { |
| 340 | IBinder b = ServiceManager.getService(Context.LOCATION_SERVICE); |
| 341 | return new LocationManager(ctx, ILocationManager.Stub.asInterface(b)); |
| 342 | }}); |
| 343 | |
| 344 | registerService(Context.NETWORK_POLICY_SERVICE, NetworkPolicyManager.class, |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 345 | new CachedServiceFetcher<NetworkPolicyManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 346 | @Override |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 347 | public NetworkPolicyManager createService(ContextImpl ctx) { |
| 348 | return new NetworkPolicyManager(ctx, INetworkPolicyManager.Stub.asInterface( |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 349 | ServiceManager.getService(Context.NETWORK_POLICY_SERVICE))); |
| 350 | }}); |
| 351 | |
| 352 | registerService(Context.NOTIFICATION_SERVICE, NotificationManager.class, |
| 353 | new CachedServiceFetcher<NotificationManager>() { |
| 354 | @Override |
| 355 | public NotificationManager createService(ContextImpl ctx) { |
| 356 | final Context outerContext = ctx.getOuterContext(); |
| 357 | return new NotificationManager( |
| 358 | new ContextThemeWrapper(outerContext, |
| 359 | Resources.selectSystemTheme(0, |
| 360 | outerContext.getApplicationInfo().targetSdkVersion, |
| 361 | com.android.internal.R.style.Theme_Dialog, |
| 362 | com.android.internal.R.style.Theme_Holo_Dialog, |
| 363 | com.android.internal.R.style.Theme_DeviceDefault_Dialog, |
| 364 | com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)), |
| 365 | ctx.mMainThread.getHandler()); |
| 366 | }}); |
| 367 | |
| 368 | registerService(Context.NSD_SERVICE, NsdManager.class, |
| 369 | new CachedServiceFetcher<NsdManager>() { |
| 370 | @Override |
| 371 | public NsdManager createService(ContextImpl ctx) { |
| 372 | IBinder b = ServiceManager.getService(Context.NSD_SERVICE); |
| 373 | INsdManager service = INsdManager.Stub.asInterface(b); |
| 374 | return new NsdManager(ctx.getOuterContext(), service); |
| 375 | }}); |
| 376 | |
| 377 | registerService(Context.POWER_SERVICE, PowerManager.class, |
| 378 | new CachedServiceFetcher<PowerManager>() { |
| 379 | @Override |
| 380 | public PowerManager createService(ContextImpl ctx) { |
| 381 | IBinder b = ServiceManager.getService(Context.POWER_SERVICE); |
| 382 | IPowerManager service = IPowerManager.Stub.asInterface(b); |
| 383 | if (service == null) { |
| 384 | Log.wtf(TAG, "Failed to get power manager service."); |
| 385 | } |
| 386 | return new PowerManager(ctx.getOuterContext(), |
| 387 | service, ctx.mMainThread.getHandler()); |
| 388 | }}); |
| 389 | |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 390 | registerService(Context.RECOVERY_SERVICE, RecoverySystem.class, |
| 391 | new CachedServiceFetcher<RecoverySystem>() { |
| 392 | @Override |
| 393 | public RecoverySystem createService(ContextImpl ctx) { |
| 394 | IBinder b = ServiceManager.getService(Context.RECOVERY_SERVICE); |
| 395 | IRecoverySystem service = IRecoverySystem.Stub.asInterface(b); |
| 396 | if (service == null) { |
| 397 | Log.wtf(TAG, "Failed to get recovery service."); |
| 398 | } |
| 399 | return new RecoverySystem(service); |
| 400 | }}); |
| 401 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 402 | registerService(Context.SEARCH_SERVICE, SearchManager.class, |
| 403 | new CachedServiceFetcher<SearchManager>() { |
| 404 | @Override |
| 405 | public SearchManager createService(ContextImpl ctx) { |
| 406 | return new SearchManager(ctx.getOuterContext(), |
| 407 | ctx.mMainThread.getHandler()); |
| 408 | }}); |
| 409 | |
| 410 | registerService(Context.SENSOR_SERVICE, SensorManager.class, |
| 411 | new CachedServiceFetcher<SensorManager>() { |
| 412 | @Override |
| 413 | public SensorManager createService(ContextImpl ctx) { |
| 414 | return new SystemSensorManager(ctx.getOuterContext(), |
| 415 | ctx.mMainThread.getHandler().getLooper()); |
| 416 | }}); |
| 417 | |
| 418 | registerService(Context.STATUS_BAR_SERVICE, StatusBarManager.class, |
| 419 | new CachedServiceFetcher<StatusBarManager>() { |
| 420 | @Override |
| 421 | public StatusBarManager createService(ContextImpl ctx) { |
| 422 | return new StatusBarManager(ctx.getOuterContext()); |
| 423 | }}); |
| 424 | |
| 425 | registerService(Context.STORAGE_SERVICE, StorageManager.class, |
| 426 | new CachedServiceFetcher<StorageManager>() { |
| 427 | @Override |
| 428 | public StorageManager createService(ContextImpl ctx) { |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 429 | return new StorageManager(ctx, ctx.mMainThread.getHandler().getLooper()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 430 | }}); |
| 431 | |
| 432 | registerService(Context.TELEPHONY_SERVICE, TelephonyManager.class, |
| 433 | new CachedServiceFetcher<TelephonyManager>() { |
| 434 | @Override |
| 435 | public TelephonyManager createService(ContextImpl ctx) { |
| 436 | return new TelephonyManager(ctx.getOuterContext()); |
| 437 | }}); |
| 438 | |
| 439 | registerService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class, |
| 440 | new CachedServiceFetcher<SubscriptionManager>() { |
| 441 | @Override |
| 442 | public SubscriptionManager createService(ContextImpl ctx) { |
| 443 | return new SubscriptionManager(ctx.getOuterContext()); |
| 444 | }}); |
| 445 | |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 446 | registerService(Context.CARRIER_CONFIG_SERVICE, CarrierConfigManager.class, |
| 447 | new CachedServiceFetcher<CarrierConfigManager>() { |
| 448 | @Override |
| 449 | public CarrierConfigManager createService(ContextImpl ctx) { |
| 450 | return new CarrierConfigManager(); |
| 451 | }}); |
| 452 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 453 | registerService(Context.TELECOM_SERVICE, TelecomManager.class, |
| 454 | new CachedServiceFetcher<TelecomManager>() { |
| 455 | @Override |
| 456 | public TelecomManager createService(ContextImpl ctx) { |
| 457 | return new TelecomManager(ctx.getOuterContext()); |
| 458 | }}); |
| 459 | |
| 460 | registerService(Context.UI_MODE_SERVICE, UiModeManager.class, |
| 461 | new CachedServiceFetcher<UiModeManager>() { |
| 462 | @Override |
| 463 | public UiModeManager createService(ContextImpl ctx) { |
| 464 | return new UiModeManager(); |
| 465 | }}); |
| 466 | |
| 467 | registerService(Context.USB_SERVICE, UsbManager.class, |
| 468 | new CachedServiceFetcher<UsbManager>() { |
| 469 | @Override |
| 470 | public UsbManager createService(ContextImpl ctx) { |
| 471 | IBinder b = ServiceManager.getService(Context.USB_SERVICE); |
| 472 | return new UsbManager(ctx, IUsbManager.Stub.asInterface(b)); |
| 473 | }}); |
| 474 | |
| 475 | registerService(Context.SERIAL_SERVICE, SerialManager.class, |
| 476 | new CachedServiceFetcher<SerialManager>() { |
| 477 | @Override |
| 478 | public SerialManager createService(ContextImpl ctx) { |
| 479 | IBinder b = ServiceManager.getService(Context.SERIAL_SERVICE); |
| 480 | return new SerialManager(ctx, ISerialManager.Stub.asInterface(b)); |
| 481 | }}); |
| 482 | |
| 483 | registerService(Context.VIBRATOR_SERVICE, Vibrator.class, |
| 484 | new CachedServiceFetcher<Vibrator>() { |
| 485 | @Override |
| 486 | public Vibrator createService(ContextImpl ctx) { |
| 487 | return new SystemVibrator(ctx); |
| 488 | }}); |
| 489 | |
| 490 | registerService(Context.WALLPAPER_SERVICE, WallpaperManager.class, |
| 491 | new CachedServiceFetcher<WallpaperManager>() { |
| 492 | @Override |
| 493 | public WallpaperManager createService(ContextImpl ctx) { |
| 494 | return new WallpaperManager(ctx.getOuterContext(), |
| 495 | ctx.mMainThread.getHandler()); |
| 496 | }}); |
| 497 | |
| 498 | registerService(Context.WIFI_SERVICE, WifiManager.class, |
| 499 | new CachedServiceFetcher<WifiManager>() { |
| 500 | @Override |
| 501 | public WifiManager createService(ContextImpl ctx) { |
| 502 | IBinder b = ServiceManager.getService(Context.WIFI_SERVICE); |
| 503 | IWifiManager service = IWifiManager.Stub.asInterface(b); |
Paul Stewart | bf8cbb05 | 2016-03-17 10:11:54 -0700 | [diff] [blame] | 504 | return new WifiManager(ctx.getOuterContext(), service, |
| 505 | ConnectivityThread.getInstanceLooper()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 506 | }}); |
| 507 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 508 | registerService(Context.WIFI_P2P_SERVICE, WifiP2pManager.class, |
| 509 | new StaticServiceFetcher<WifiP2pManager>() { |
| 510 | @Override |
| 511 | public WifiP2pManager createService() { |
| 512 | IBinder b = ServiceManager.getService(Context.WIFI_P2P_SERVICE); |
| 513 | IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b); |
| 514 | return new WifiP2pManager(service); |
| 515 | }}); |
| 516 | |
Etan Cohen | 20d329b | 2015-09-29 13:49:02 -0700 | [diff] [blame] | 517 | registerService(Context.WIFI_NAN_SERVICE, WifiNanManager.class, |
| 518 | new StaticServiceFetcher<WifiNanManager>() { |
| 519 | @Override |
| 520 | public WifiNanManager createService() { |
| 521 | IBinder b = ServiceManager.getService(Context.WIFI_NAN_SERVICE); |
| 522 | IWifiNanManager service = IWifiNanManager.Stub.asInterface(b); |
| 523 | if (service == null) { |
| 524 | return null; |
| 525 | } |
| 526 | return new WifiNanManager(service); |
| 527 | }}); |
| 528 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 529 | registerService(Context.WIFI_SCANNING_SERVICE, WifiScanner.class, |
| 530 | new CachedServiceFetcher<WifiScanner>() { |
| 531 | @Override |
| 532 | public WifiScanner createService(ContextImpl ctx) { |
| 533 | IBinder b = ServiceManager.getService(Context.WIFI_SCANNING_SERVICE); |
| 534 | IWifiScanner service = IWifiScanner.Stub.asInterface(b); |
| 535 | return new WifiScanner(ctx.getOuterContext(), service); |
| 536 | }}); |
| 537 | |
| 538 | registerService(Context.WIFI_RTT_SERVICE, RttManager.class, |
| 539 | new CachedServiceFetcher<RttManager>() { |
| 540 | @Override |
| 541 | public RttManager createService(ContextImpl ctx) { |
| 542 | IBinder b = ServiceManager.getService(Context.WIFI_RTT_SERVICE); |
| 543 | IRttManager service = IRttManager.Stub.asInterface(b); |
| 544 | return new RttManager(ctx.getOuterContext(), service); |
| 545 | }}); |
| 546 | |
| 547 | registerService(Context.ETHERNET_SERVICE, EthernetManager.class, |
| 548 | new CachedServiceFetcher<EthernetManager>() { |
| 549 | @Override |
| 550 | public EthernetManager createService(ContextImpl ctx) { |
| 551 | IBinder b = ServiceManager.getService(Context.ETHERNET_SERVICE); |
| 552 | IEthernetManager service = IEthernetManager.Stub.asInterface(b); |
| 553 | return new EthernetManager(ctx.getOuterContext(), service); |
| 554 | }}); |
| 555 | |
| 556 | registerService(Context.WINDOW_SERVICE, WindowManager.class, |
| 557 | new CachedServiceFetcher<WindowManager>() { |
| 558 | @Override |
| 559 | public WindowManager createService(ContextImpl ctx) { |
| 560 | return new WindowManagerImpl(ctx.getDisplay()); |
| 561 | }}); |
| 562 | |
| 563 | registerService(Context.USER_SERVICE, UserManager.class, |
| 564 | new CachedServiceFetcher<UserManager>() { |
| 565 | @Override |
| 566 | public UserManager createService(ContextImpl ctx) { |
| 567 | IBinder b = ServiceManager.getService(Context.USER_SERVICE); |
| 568 | IUserManager service = IUserManager.Stub.asInterface(b); |
| 569 | return new UserManager(ctx, service); |
| 570 | }}); |
| 571 | |
| 572 | registerService(Context.APP_OPS_SERVICE, AppOpsManager.class, |
| 573 | new CachedServiceFetcher<AppOpsManager>() { |
| 574 | @Override |
| 575 | public AppOpsManager createService(ContextImpl ctx) { |
| 576 | IBinder b = ServiceManager.getService(Context.APP_OPS_SERVICE); |
| 577 | IAppOpsService service = IAppOpsService.Stub.asInterface(b); |
| 578 | return new AppOpsManager(ctx, service); |
| 579 | }}); |
| 580 | |
| 581 | registerService(Context.CAMERA_SERVICE, CameraManager.class, |
| 582 | new CachedServiceFetcher<CameraManager>() { |
| 583 | @Override |
| 584 | public CameraManager createService(ContextImpl ctx) { |
| 585 | return new CameraManager(ctx); |
| 586 | }}); |
| 587 | |
| 588 | registerService(Context.LAUNCHER_APPS_SERVICE, LauncherApps.class, |
| 589 | new CachedServiceFetcher<LauncherApps>() { |
| 590 | @Override |
| 591 | public LauncherApps createService(ContextImpl ctx) { |
| 592 | IBinder b = ServiceManager.getService(Context.LAUNCHER_APPS_SERVICE); |
| 593 | ILauncherApps service = ILauncherApps.Stub.asInterface(b); |
| 594 | return new LauncherApps(ctx, service); |
| 595 | }}); |
| 596 | |
| 597 | registerService(Context.RESTRICTIONS_SERVICE, RestrictionsManager.class, |
| 598 | new CachedServiceFetcher<RestrictionsManager>() { |
| 599 | @Override |
| 600 | public RestrictionsManager createService(ContextImpl ctx) { |
| 601 | IBinder b = ServiceManager.getService(Context.RESTRICTIONS_SERVICE); |
| 602 | IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b); |
| 603 | return new RestrictionsManager(ctx, service); |
| 604 | }}); |
| 605 | |
| 606 | registerService(Context.PRINT_SERVICE, PrintManager.class, |
| 607 | new CachedServiceFetcher<PrintManager>() { |
| 608 | @Override |
| 609 | public PrintManager createService(ContextImpl ctx) { |
| 610 | IBinder iBinder = ServiceManager.getService(Context.PRINT_SERVICE); |
| 611 | IPrintManager service = IPrintManager.Stub.asInterface(iBinder); |
| 612 | return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(), |
| 613 | UserHandle.getAppId(Process.myUid())); |
| 614 | }}); |
| 615 | |
| 616 | registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class, |
| 617 | new CachedServiceFetcher<ConsumerIrManager>() { |
| 618 | @Override |
| 619 | public ConsumerIrManager createService(ContextImpl ctx) { |
| 620 | return new ConsumerIrManager(ctx); |
| 621 | }}); |
| 622 | |
| 623 | registerService(Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class, |
| 624 | new CachedServiceFetcher<MediaSessionManager>() { |
| 625 | @Override |
| 626 | public MediaSessionManager createService(ContextImpl ctx) { |
| 627 | return new MediaSessionManager(ctx); |
| 628 | }}); |
| 629 | |
| 630 | registerService(Context.TRUST_SERVICE, TrustManager.class, |
| 631 | new StaticServiceFetcher<TrustManager>() { |
| 632 | @Override |
| 633 | public TrustManager createService() { |
| 634 | IBinder b = ServiceManager.getService(Context.TRUST_SERVICE); |
| 635 | return new TrustManager(b); |
| 636 | }}); |
| 637 | |
| 638 | registerService(Context.FINGERPRINT_SERVICE, FingerprintManager.class, |
| 639 | new CachedServiceFetcher<FingerprintManager>() { |
| 640 | @Override |
| 641 | public FingerprintManager createService(ContextImpl ctx) { |
| 642 | IBinder binder = ServiceManager.getService(Context.FINGERPRINT_SERVICE); |
| 643 | IFingerprintService service = IFingerprintService.Stub.asInterface(binder); |
| 644 | return new FingerprintManager(ctx.getOuterContext(), service); |
| 645 | }}); |
| 646 | |
| 647 | registerService(Context.TV_INPUT_SERVICE, TvInputManager.class, |
| 648 | new StaticServiceFetcher<TvInputManager>() { |
| 649 | @Override |
| 650 | public TvInputManager createService() { |
| 651 | IBinder iBinder = ServiceManager.getService(Context.TV_INPUT_SERVICE); |
| 652 | ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder); |
| 653 | return new TvInputManager(service, UserHandle.myUserId()); |
| 654 | }}); |
| 655 | |
| 656 | registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class, |
| 657 | new CachedServiceFetcher<NetworkScoreManager>() { |
| 658 | @Override |
| 659 | public NetworkScoreManager createService(ContextImpl ctx) { |
| 660 | return new NetworkScoreManager(ctx); |
| 661 | }}); |
| 662 | |
| 663 | registerService(Context.USAGE_STATS_SERVICE, UsageStatsManager.class, |
| 664 | new CachedServiceFetcher<UsageStatsManager>() { |
| 665 | @Override |
| 666 | public UsageStatsManager createService(ContextImpl ctx) { |
| 667 | IBinder iBinder = ServiceManager.getService(Context.USAGE_STATS_SERVICE); |
| 668 | IUsageStatsManager service = IUsageStatsManager.Stub.asInterface(iBinder); |
| 669 | return new UsageStatsManager(ctx.getOuterContext(), service); |
| 670 | }}); |
| 671 | |
Zoltan Szatmary-Ban | 9c5dfa5 | 2015-02-23 17:20:20 +0000 | [diff] [blame] | 672 | registerService(Context.NETWORK_STATS_SERVICE, NetworkStatsManager.class, |
| 673 | new CachedServiceFetcher<NetworkStatsManager>() { |
| 674 | @Override |
| 675 | public NetworkStatsManager createService(ContextImpl ctx) { |
| 676 | return new NetworkStatsManager(ctx.getOuterContext()); |
| 677 | }}); |
| 678 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 679 | registerService(Context.JOB_SCHEDULER_SERVICE, JobScheduler.class, |
| 680 | new StaticServiceFetcher<JobScheduler>() { |
| 681 | @Override |
| 682 | public JobScheduler createService() { |
| 683 | IBinder b = ServiceManager.getService(Context.JOB_SCHEDULER_SERVICE); |
| 684 | return new JobSchedulerImpl(IJobScheduler.Stub.asInterface(b)); |
| 685 | }}); |
| 686 | |
| 687 | registerService(Context.PERSISTENT_DATA_BLOCK_SERVICE, PersistentDataBlockManager.class, |
| 688 | new StaticServiceFetcher<PersistentDataBlockManager>() { |
| 689 | @Override |
| 690 | public PersistentDataBlockManager createService() { |
| 691 | IBinder b = ServiceManager.getService(Context.PERSISTENT_DATA_BLOCK_SERVICE); |
| 692 | IPersistentDataBlockService persistentDataBlockService = |
| 693 | IPersistentDataBlockService.Stub.asInterface(b); |
| 694 | if (persistentDataBlockService != null) { |
| 695 | return new PersistentDataBlockManager(persistentDataBlockService); |
| 696 | } else { |
| 697 | // not supported |
| 698 | return null; |
| 699 | } |
| 700 | }}); |
| 701 | |
| 702 | registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class, |
| 703 | new CachedServiceFetcher<MediaProjectionManager>() { |
| 704 | @Override |
| 705 | public MediaProjectionManager createService(ContextImpl ctx) { |
| 706 | return new MediaProjectionManager(ctx); |
| 707 | }}); |
| 708 | |
| 709 | registerService(Context.APPWIDGET_SERVICE, AppWidgetManager.class, |
| 710 | new CachedServiceFetcher<AppWidgetManager>() { |
| 711 | @Override |
| 712 | public AppWidgetManager createService(ContextImpl ctx) { |
| 713 | IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE); |
| 714 | return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b)); |
| 715 | }}); |
| 716 | |
| 717 | registerService(Context.MIDI_SERVICE, MidiManager.class, |
| 718 | new CachedServiceFetcher<MidiManager>() { |
| 719 | @Override |
| 720 | public MidiManager createService(ContextImpl ctx) { |
| 721 | IBinder b = ServiceManager.getService(Context.MIDI_SERVICE); |
Ricardo Garcia | 47abda5 | 2015-07-16 18:20:46 -0700 | [diff] [blame] | 722 | if (b == null) { |
| 723 | return null; |
| 724 | } |
Mike Lockwood | e0a6ca6 | 2015-06-04 13:43:56 -0700 | [diff] [blame] | 725 | return new MidiManager(IMidiManager.Stub.asInterface(b)); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 726 | }}); |
Eric Laurent | 2035ac8 | 2015-03-05 15:18:44 -0800 | [diff] [blame] | 727 | |
| 728 | registerService(Context.RADIO_SERVICE, RadioManager.class, |
| 729 | new CachedServiceFetcher<RadioManager>() { |
| 730 | @Override |
| 731 | public RadioManager createService(ContextImpl ctx) { |
| 732 | return new RadioManager(ctx); |
| 733 | }}); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 734 | |
Polina Bondarenko | 965ecbb | 2015-11-13 15:34:28 +0100 | [diff] [blame] | 735 | registerService(Context.HARDWARE_PROPERTIES_SERVICE, HardwarePropertiesManager.class, |
| 736 | new CachedServiceFetcher<HardwarePropertiesManager>() { |
| 737 | @Override |
| 738 | public HardwarePropertiesManager createService(ContextImpl ctx) { |
Polina Bondarenko | f8754ac | 2016-02-12 20:38:23 +0100 | [diff] [blame] | 739 | IBinder b = ServiceManager.getService(Context.HARDWARE_PROPERTIES_SERVICE); |
| 740 | IHardwarePropertiesManager service = |
| 741 | IHardwarePropertiesManager.Stub.asInterface(b); |
| 742 | if (service == null) { |
| 743 | Log.wtf(TAG, "Failed to get hardwareproperties service."); |
| 744 | return null; |
| 745 | } |
| 746 | return new HardwarePropertiesManager(ctx, service); |
Polina Bondarenko | 965ecbb | 2015-11-13 15:34:28 +0100 | [diff] [blame] | 747 | }}); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 748 | |
| 749 | registerService(Context.SOUND_TRIGGER_SERVICE, SoundTriggerManager.class, |
| 750 | new CachedServiceFetcher<SoundTriggerManager>() { |
| 751 | @Override |
| 752 | public SoundTriggerManager createService(ContextImpl ctx) { |
| 753 | IBinder b = ServiceManager.getService(Context.SOUND_TRIGGER_SERVICE); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 754 | return new SoundTriggerManager(ctx, ISoundTriggerService.Stub.asInterface(b)); |
| 755 | }}); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 756 | |
| 757 | registerService(Context.SHORTCUT_SERVICE, ShortcutManager.class, |
| 758 | new CachedServiceFetcher<ShortcutManager>() { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 759 | @Override |
| 760 | public ShortcutManager createService(ContextImpl ctx) { |
| 761 | IBinder b = ServiceManager.getService(Context.SHORTCUT_SERVICE); |
| 762 | return new ShortcutManager(ctx, IShortcutService.Stub.asInterface(b)); |
| 763 | }}); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 764 | |
| 765 | registerService(Context.SYSTEM_HEALTH_SERVICE, SystemHealthManager.class, |
| 766 | new CachedServiceFetcher<SystemHealthManager>() { |
| 767 | @Override |
| 768 | public SystemHealthManager createService(ContextImpl ctx) { |
| 769 | return new SystemHealthManager(); |
| 770 | }}); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 771 | |
| 772 | registerService(Context.CONTEXTHUB_SERVICE, ContextHubManager.class, |
| 773 | new CachedServiceFetcher<ContextHubManager>() { |
| 774 | @Override |
| 775 | public ContextHubManager createService(ContextImpl ctx) { |
| 776 | return new ContextHubManager(ctx.getOuterContext(), |
| 777 | ctx.mMainThread.getHandler().getLooper()); |
| 778 | }}); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /** |
| 782 | * Creates an array which is used to cache per-Context service instances. |
| 783 | */ |
| 784 | public static Object[] createServiceCache() { |
| 785 | return new Object[sServiceCacheSize]; |
| 786 | } |
| 787 | |
| 788 | /** |
| 789 | * Gets a system service from a given context. |
| 790 | */ |
| 791 | public static Object getSystemService(ContextImpl ctx, String name) { |
| 792 | ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name); |
| 793 | return fetcher != null ? fetcher.getService(ctx) : null; |
| 794 | } |
| 795 | |
| 796 | /** |
Paul McLean | e3383cc | 2015-05-08 11:41:20 -0700 | [diff] [blame] | 797 | * Gets the name of the system-level service that is represented by the specified class. |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 798 | */ |
| 799 | public static String getSystemServiceName(Class<?> serviceClass) { |
| 800 | return SYSTEM_SERVICE_NAMES.get(serviceClass); |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * Statically registers a system service with the context. |
| 805 | * This method must be called during static initialization only. |
| 806 | */ |
| 807 | private static <T> void registerService(String serviceName, Class<T> serviceClass, |
| 808 | ServiceFetcher<T> serviceFetcher) { |
| 809 | SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName); |
| 810 | SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher); |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * Base interface for classes that fetch services. |
| 815 | * These objects must only be created during static initialization. |
| 816 | */ |
| 817 | static abstract interface ServiceFetcher<T> { |
| 818 | T getService(ContextImpl ctx); |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * Override this class when the system service constructor needs a |
| 823 | * ContextImpl and should be cached and retained by that context. |
| 824 | */ |
| 825 | static abstract class CachedServiceFetcher<T> implements ServiceFetcher<T> { |
| 826 | private final int mCacheIndex; |
| 827 | |
| 828 | public CachedServiceFetcher() { |
| 829 | mCacheIndex = sServiceCacheSize++; |
| 830 | } |
| 831 | |
| 832 | @Override |
| 833 | @SuppressWarnings("unchecked") |
| 834 | public final T getService(ContextImpl ctx) { |
| 835 | final Object[] cache = ctx.mServiceCache; |
| 836 | synchronized (cache) { |
| 837 | // Fetch or create the service. |
| 838 | Object service = cache[mCacheIndex]; |
| 839 | if (service == null) { |
| 840 | service = createService(ctx); |
| 841 | cache[mCacheIndex] = service; |
| 842 | } |
| 843 | return (T)service; |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | public abstract T createService(ContextImpl ctx); |
| 848 | } |
| 849 | |
| 850 | /** |
| 851 | * Override this class when the system service does not need a ContextImpl |
| 852 | * and should be cached and retained process-wide. |
| 853 | */ |
| 854 | static abstract class StaticServiceFetcher<T> implements ServiceFetcher<T> { |
| 855 | private T mCachedInstance; |
| 856 | |
| 857 | @Override |
| 858 | public final T getService(ContextImpl unused) { |
| 859 | synchronized (StaticServiceFetcher.this) { |
| 860 | if (mCachedInstance == null) { |
| 861 | mCachedInstance = createService(); |
| 862 | } |
| 863 | return mCachedInstance; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | public abstract T createService(); |
| 868 | } |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 869 | |
| 870 | /** |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 871 | * Like StaticServiceFetcher, creates only one instance of the service per application, but when |
| 872 | * creating the service for the first time, passes it the application context of the creating |
| 873 | * application. |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 874 | * |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 875 | * TODO: Delete this once its only user (ConnectivityManager) is known to work well in the |
| 876 | * case where multiple application components each have their own ConnectivityManager object. |
| 877 | */ |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 878 | static abstract class StaticApplicationContextServiceFetcher<T> implements ServiceFetcher<T> { |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 879 | private T mCachedInstance; |
| 880 | |
| 881 | @Override |
| 882 | public final T getService(ContextImpl ctx) { |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 883 | synchronized (StaticApplicationContextServiceFetcher.this) { |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 884 | if (mCachedInstance == null) { |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 885 | mCachedInstance = createService(ctx.getApplicationContext()); |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 886 | } |
| 887 | return mCachedInstance; |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | public abstract T createService(Context applicationContext); |
| 892 | } |
| 893 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 894 | } |