| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import android.accounts.AccountManager; |
| 20 |
import android.accounts.IAccountManager; |
| 21 |
import android.adservices.AdServicesFrameworkInitializer; |
| 22 |
import android.annotation.NonNull; |
| 23 |
import android.annotation.Nullable; |
| 24 |
import android.annotation.SystemApi; |
| 25 |
import android.app.ContextImpl.ServiceInitializationState; |
| 26 |
import android.app.admin.DevicePolicyManager; |
| 27 |
import android.app.admin.IDevicePolicyManager; |
| 28 |
import android.app.ambientcontext.AmbientContextManager; |
| 29 |
import android.app.ambientcontext.IAmbientContextManager; |
| 30 |
import android.app.appsearch.AppSearchManagerFrameworkInitializer; |
| 31 |
import android.app.blob.BlobStoreManagerFrameworkInitializer; |
| 32 |
import android.app.contentsuggestions.ContentSuggestionsManager; |
| 33 |
import android.app.contentsuggestions.IContentSuggestionsManager; |
| 34 |
import android.app.job.JobSchedulerFrameworkInitializer; |
| 35 |
import android.app.people.PeopleManager; |
| 36 |
import android.app.prediction.AppPredictionManager; |
| 37 |
import android.app.role.RoleFrameworkInitializer; |
| 38 |
import android.app.sdksandbox.SdkSandboxManagerFrameworkInitializer; |
| 39 |
import android.app.search.SearchUiManager; |
| 40 |
import android.app.slice.SliceManager; |
| 41 |
import android.app.smartspace.SmartspaceManager; |
| 42 |
import android.app.time.TimeManager; |
| 43 |
import android.app.timedetector.TimeDetector; |
| 44 |
import android.app.timedetector.TimeDetectorImpl; |
| 45 |
import android.app.timezonedetector.TimeZoneDetector; |
| 46 |
import android.app.timezonedetector.TimeZoneDetectorImpl; |
| 47 |
import android.app.trust.TrustManager; |
| 48 |
import android.app.usage.IStorageStatsManager; |
| 49 |
import android.app.usage.IUsageStatsManager; |
| 50 |
import android.app.usage.StorageStatsManager; |
| 51 |
import android.app.usage.UsageStatsManager; |
| 52 |
import android.app.wallpapereffectsgeneration.IWallpaperEffectsGenerationManager; |
| 53 |
import android.app.wallpapereffectsgeneration.WallpaperEffectsGenerationManager; |
| 54 |
import android.apphibernation.AppHibernationManager; |
| 55 |
import android.appwidget.AppWidgetManager; |
| 56 |
import android.bluetooth.BluetoothFrameworkInitializer; |
| 57 |
import android.companion.CompanionDeviceManager; |
| 58 |
import android.companion.ICompanionDeviceManager; |
| 59 |
import android.companion.virtual.IVirtualDeviceManager; |
| 60 |
import android.companion.virtual.VirtualDeviceManager; |
| 61 |
import android.content.ClipboardManager; |
| 62 |
import android.content.ContentCaptureOptions; |
| 63 |
import android.content.Context; |
| 64 |
import android.content.IRestrictionsManager; |
| 65 |
import android.content.RestrictionsManager; |
| 66 |
import android.content.integrity.AppIntegrityManager; |
| 67 |
import android.content.integrity.IAppIntegrityManager; |
| 68 |
import android.content.om.IOverlayManager; |
| 69 |
import android.content.om.OverlayManager; |
| 70 |
import android.content.pm.ApplicationInfo; |
| 71 |
import android.content.pm.CrossProfileApps; |
| 72 |
import android.content.pm.DataLoaderManager; |
| 73 |
import android.content.pm.ICrossProfileApps; |
| 74 |
import android.content.pm.IDataLoaderManager; |
| 75 |
import android.content.pm.IShortcutService; |
| 76 |
import android.content.pm.LauncherApps; |
| 77 |
import android.content.pm.PackageManager; |
| 78 |
import android.content.pm.ShortcutManager; |
| 79 |
import android.content.pm.verify.domain.DomainVerificationManager; |
| 80 |
import android.content.pm.verify.domain.IDomainVerificationManager; |
| 81 |
import android.content.res.Resources; |
| 82 |
import android.content.rollback.RollbackManagerFrameworkInitializer; |
| 83 |
import android.debug.AdbManager; |
| 84 |
import android.debug.IAdbManager; |
| 85 |
import android.graphics.fonts.FontManager; |
| 86 |
import android.hardware.ConsumerIrManager; |
| 87 |
import android.hardware.ISerialManager; |
| 88 |
import android.hardware.SensorManager; |
| 89 |
import android.hardware.SensorPrivacyManager; |
| 90 |
import android.hardware.SerialManager; |
| 91 |
import android.hardware.SystemSensorManager; |
| 92 |
import android.hardware.biometrics.BiometricManager; |
| 93 |
import android.hardware.biometrics.IAuthService; |
| 94 |
import android.hardware.camera2.CameraManager; |
| 95 |
import android.hardware.devicestate.DeviceStateManager; |
| 96 |
import android.hardware.display.ColorDisplayManager; |
| 97 |
import android.hardware.display.DisplayManager; |
| 98 |
import android.hardware.face.FaceManager; |
| 99 |
import android.hardware.face.IFaceService; |
| 100 |
import android.hardware.fingerprint.FingerprintManager; |
| 101 |
import android.hardware.fingerprint.IFingerprintService; |
| 102 |
import android.hardware.hdmi.HdmiControlManager; |
| 103 |
import android.hardware.hdmi.IHdmiControlService; |
| 104 |
import android.hardware.input.InputManager; |
| 105 |
import android.hardware.iris.IIrisService; |
| 106 |
import android.hardware.iris.IrisManager; |
| 107 |
import android.hardware.lights.LightsManager; |
| 108 |
import android.hardware.lights.SystemLightsManager; |
| 109 |
import android.hardware.location.ContextHubManager; |
| 110 |
import android.hardware.radio.RadioManager; |
| 111 |
import android.hardware.usb.IUsbManager; |
| 112 |
import android.hardware.usb.UsbManager; |
| 113 |
import android.location.CountryDetector; |
| 114 |
import android.location.ICountryDetector; |
| 115 |
import android.location.ILocationManager; |
| 116 |
import android.location.LocationManager; |
| 117 |
import android.media.AudioDeviceVolumeManager; |
| 118 |
import android.media.AudioManager; |
| 119 |
import android.media.MediaFrameworkInitializer; |
| 120 |
import android.media.MediaFrameworkPlatformInitializer; |
| 121 |
import android.media.MediaRouter; |
| 122 |
import android.media.metrics.IMediaMetricsManager; |
| 123 |
import android.media.metrics.MediaMetricsManager; |
| 124 |
import android.media.midi.IMidiManager; |
| 125 |
import android.media.midi.MidiManager; |
| 126 |
import android.media.musicrecognition.IMusicRecognitionManager; |
| 127 |
import android.media.musicrecognition.MusicRecognitionManager; |
| 128 |
import android.media.projection.MediaProjectionManager; |
| 129 |
import android.media.soundtrigger.SoundTriggerManager; |
| 130 |
import android.media.tv.ITvInputManager; |
| 131 |
import android.media.tv.TvInputManager; |
| 132 |
import android.media.tv.interactive.ITvInteractiveAppManager; |
| 133 |
import android.media.tv.interactive.TvInteractiveAppManager; |
| 134 |
import android.media.tv.tunerresourcemanager.ITunerResourceManager; |
| 135 |
import android.media.tv.tunerresourcemanager.TunerResourceManager; |
| 136 |
import android.nearby.NearbyFrameworkInitializer; |
| 137 |
import android.net.ConnectivityFrameworkInitializer; |
| 138 |
import android.net.ConnectivityFrameworkInitializerTiramisu; |
| 139 |
import android.net.INetworkPolicyManager; |
| 140 |
import android.net.IPacProxyManager; |
| 141 |
import android.net.IVpnManager; |
| 142 |
import android.net.NetworkPolicyManager; |
| 143 |
import android.net.NetworkScoreManager; |
| 144 |
import android.net.NetworkWatchlistManager; |
| 145 |
import android.net.PacProxyManager; |
| 146 |
import android.net.TetheringManager; |
| 147 |
import android.net.VpnManager; |
| 148 |
import android.net.vcn.IVcnManagementService; |
| 149 |
import android.net.vcn.VcnManager; |
| 150 |
import android.net.wifi.WifiFrameworkInitializer; |
| 151 |
import android.net.wifi.nl80211.WifiNl80211Manager; |
| 152 |
import android.nfc.NfcFrameworkInitializer; |
| 153 |
import android.ondevicepersonalization.OnDevicePersonalizationFrameworkInitializer; |
| 154 |
import android.os.BatteryManager; |
| 155 |
import android.os.BatteryStats; |
| 156 |
import android.os.BatteryStatsManager; |
| 157 |
import android.os.BugreportManager; |
| 158 |
import android.os.Build; |
| 159 |
import android.os.DropBoxManager; |
| 160 |
import android.os.HardwarePropertiesManager; |
| 161 |
import android.os.IBatteryPropertiesRegistrar; |
| 162 |
import android.os.IBinder; |
| 163 |
import android.os.IDumpstate; |
| 164 |
import android.os.IHardwarePropertiesManager; |
| 165 |
import android.os.IPowerManager; |
| 166 |
import android.os.IRecoverySystem; |
| 167 |
import android.os.ISystemUpdateManager; |
| 168 |
import android.os.IThermalService; |
| 169 |
import android.os.IUserManager; |
| 170 |
import android.os.IncidentManager; |
| 171 |
import android.os.PerformanceHintManager; |
| 172 |
import android.os.PermissionEnforcer; |
| 173 |
import android.os.PowerManager; |
| 174 |
import android.os.RecoverySystem; |
| 175 |
import android.os.ServiceManager; |
| 176 |
import android.os.ServiceManager.ServiceNotFoundException; |
| 177 |
import android.os.StatsFrameworkInitializer; |
| 178 |
import android.os.SystemConfigManager; |
| 179 |
import android.os.SystemUpdateManager; |
| 180 |
import android.os.SystemVibrator; |
| 181 |
import android.os.SystemVibratorManager; |
| 182 |
import android.os.UserHandle; |
| 183 |
import android.os.UserManager; |
| 184 |
import android.os.Vibrator; |
| 185 |
import android.os.VibratorManager; |
| 186 |
import android.os.health.SystemHealthManager; |
| 187 |
import android.os.image.DynamicSystemManager; |
| 188 |
import android.os.image.IDynamicSystemService; |
| 189 |
import android.os.incremental.IIncrementalService; |
| 190 |
import android.os.incremental.IncrementalManager; |
| 191 |
import android.os.storage.StorageManager; |
| 192 |
import android.permission.LegacyPermissionManager; |
| 193 |
import android.permission.PermissionCheckerManager; |
| 194 |
import android.permission.PermissionControllerManager; |
| 195 |
import android.permission.PermissionManager; |
| 196 |
import android.print.IPrintManager; |
| 197 |
import android.print.PrintManager; |
| 198 |
import android.safetycenter.SafetyCenterFrameworkInitializer; |
| 199 |
import android.scheduling.SchedulingFrameworkInitializer; |
| 200 |
import android.security.FileIntegrityManager; |
| 201 |
import android.security.IFileIntegrityService; |
| 202 |
import android.security.attestationverification.AttestationVerificationManager; |
| 203 |
import android.security.attestationverification.IAttestationVerificationManagerService; |
| 204 |
import android.service.oemlock.IOemLockService; |
| 205 |
import android.service.oemlock.OemLockManager; |
| 206 |
import android.service.persistentdata.IPersistentDataBlockService; |
| 207 |
import android.service.persistentdata.PersistentDataBlockManager; |
| 208 |
import android.service.vr.IVrManager; |
| 209 |
import android.system.virtualmachine.VirtualizationFrameworkInitializer; |
| 210 |
import android.telecom.TelecomManager; |
| 211 |
import android.telephony.MmsManager; |
| 212 |
import android.telephony.TelephonyFrameworkInitializer; |
| 213 |
import android.telephony.TelephonyRegistryManager; |
| 214 |
import android.transparency.BinaryTransparencyManager; |
| 215 |
import android.util.ArrayMap; |
| 216 |
import android.util.Log; |
| 217 |
import android.util.Slog; |
| 218 |
import android.uwb.UwbFrameworkInitializer; |
| 219 |
import android.view.ContextThemeWrapper; |
| 220 |
import android.view.LayoutInflater; |
| 221 |
import android.view.WindowManager; |
| 222 |
import android.view.WindowManagerImpl; |
| 223 |
import android.view.accessibility.AccessibilityManager; |
| 224 |
import android.view.accessibility.CaptioningManager; |
| 225 |
import android.view.autofill.AutofillManager; |
| 226 |
import android.view.autofill.IAutoFillManager; |
| 227 |
import android.view.contentcapture.ContentCaptureManager; |
| 228 |
import android.view.contentcapture.IContentCaptureManager; |
| 229 |
import android.view.displayhash.DisplayHashManager; |
| 230 |
import android.view.inputmethod.InputMethodManager; |
| 231 |
import android.view.textclassifier.TextClassificationManager; |
| 232 |
import android.view.textservice.TextServicesManager; |
| 233 |
import android.view.translation.ITranslationManager; |
| 234 |
import android.view.translation.TranslationManager; |
| 235 |
import android.view.translation.UiTranslationManager; |
| 236 |
|
| 237 |
import com.android.internal.app.IAppOpsService; |
| 238 |
import com.android.internal.app.IBatteryStats; |
| 239 |
import com.android.internal.app.ISoundTriggerService; |
| 240 |
import com.android.internal.appwidget.IAppWidgetService; |
| 241 |
import com.android.internal.graphics.fonts.IFontManager; |
| 242 |
import com.android.internal.net.INetworkWatchlistManager; |
| 243 |
import com.android.internal.os.IBinaryTransparencyService; |
| 244 |
import com.android.internal.os.IDropBoxManagerService; |
| 245 |
import com.android.internal.policy.PhoneLayoutInflater; |
| 246 |
import com.android.internal.util.Preconditions; |
| 247 |
|
| 248 |
import java.util.Map; |
| 249 |
import java.util.Objects; |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
@SystemApi |
| 258 |
public final class SystemServiceRegistry { |
| 259 |
private static final String TAG = "SystemServiceRegistry"; |
| 260 |
|
| 261 |
|
| 262 |
public static boolean sEnableServiceNotFoundWtf = false; |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES = |
| 267 |
new ArrayMap<Class<?>, String>(); |
| 268 |
private static final Map<String, ServiceFetcher<?>> SYSTEM_SERVICE_FETCHERS = |
| 269 |
new ArrayMap<String, ServiceFetcher<?>>(); |
| 270 |
private static final Map<String, String> SYSTEM_SERVICE_CLASS_NAMES = new ArrayMap<>(); |
| 271 |
|
| 272 |
private static int sServiceCacheSize; |
| 273 |
|
| 274 |
private static volatile boolean sInitializing; |
| 275 |
|
| 276 |
|
| 277 |
private SystemServiceRegistry() { } |
| 278 |
|
| 279 |
static { |
| 280 |
|
| 281 |
registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class, |
| 282 |
new CachedServiceFetcher<AccessibilityManager>() { |
| 283 |
@Override |
| 284 |
public AccessibilityManager createService(ContextImpl ctx) { |
| 285 |
return AccessibilityManager.getInstance(ctx); |
| 286 |
}}); |
| 287 |
|
| 288 |
registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class, |
| 289 |
new CachedServiceFetcher<CaptioningManager>() { |
| 290 |
@Override |
| 291 |
public CaptioningManager createService(ContextImpl ctx) { |
| 292 |
return new CaptioningManager(ctx); |
| 293 |
}}); |
| 294 |
|
| 295 |
registerService(Context.ACCOUNT_SERVICE, AccountManager.class, |
| 296 |
new CachedServiceFetcher<AccountManager>() { |
| 297 |
@Override |
| 298 |
public AccountManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 299 |
IBinder b = ServiceManager.getServiceOrThrow(Context.ACCOUNT_SERVICE); |
| 300 |
IAccountManager service = IAccountManager.Stub.asInterface(b); |
| 301 |
return new AccountManager(ctx, service); |
| 302 |
}}); |
| 303 |
|
| 304 |
registerService(Context.ACTIVITY_SERVICE, ActivityManager.class, |
| 305 |
new CachedServiceFetcher<ActivityManager>() { |
| 306 |
@Override |
| 307 |
public ActivityManager createService(ContextImpl ctx) { |
| 308 |
return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); |
| 309 |
}}); |
| 310 |
|
| 311 |
registerService(Context.ACTIVITY_TASK_SERVICE, ActivityTaskManager.class, |
| 312 |
new CachedServiceFetcher<ActivityTaskManager>() { |
| 313 |
@Override |
| 314 |
public ActivityTaskManager createService(ContextImpl ctx) { |
| 315 |
return ActivityTaskManager.getInstance(); |
| 316 |
}}); |
| 317 |
|
| 318 |
registerService(Context.URI_GRANTS_SERVICE, UriGrantsManager.class, |
| 319 |
new CachedServiceFetcher<UriGrantsManager>() { |
| 320 |
@Override |
| 321 |
public UriGrantsManager createService(ContextImpl ctx) { |
| 322 |
return new UriGrantsManager( |
| 323 |
ctx.getOuterContext(), ctx.mMainThread.getHandler()); |
| 324 |
}}); |
| 325 |
|
| 326 |
registerService(Context.ALARM_SERVICE, AlarmManager.class, |
| 327 |
new CachedServiceFetcher<AlarmManager>() { |
| 328 |
@Override |
| 329 |
public AlarmManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 330 |
IBinder b = ServiceManager.getServiceOrThrow(Context.ALARM_SERVICE); |
| 331 |
IAlarmManager service = IAlarmManager.Stub.asInterface(b); |
| 332 |
return new AlarmManager(service, ctx); |
| 333 |
}}); |
| 334 |
|
| 335 |
registerService(Context.AUDIO_SERVICE, AudioManager.class, |
| 336 |
new CachedServiceFetcher<AudioManager>() { |
| 337 |
@Override |
| 338 |
public AudioManager createService(ContextImpl ctx) { |
| 339 |
return new AudioManager(ctx); |
| 340 |
}}); |
| 341 |
|
| 342 |
registerService(Context.AUDIO_DEVICE_VOLUME_SERVICE, AudioDeviceVolumeManager.class, |
| 343 |
new CachedServiceFetcher<AudioDeviceVolumeManager>() { |
| 344 |
@Override |
| 345 |
public AudioDeviceVolumeManager createService(ContextImpl ctx) { |
| 346 |
return new AudioDeviceVolumeManager(ctx); |
| 347 |
}}); |
| 348 |
|
| 349 |
registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class, |
| 350 |
new CachedServiceFetcher<MediaRouter>() { |
| 351 |
@Override |
| 352 |
public MediaRouter createService(ContextImpl ctx) { |
| 353 |
return new MediaRouter(ctx); |
| 354 |
}}); |
| 355 |
|
| 356 |
registerService(Context.HDMI_CONTROL_SERVICE, HdmiControlManager.class, |
| 357 |
new StaticServiceFetcher<HdmiControlManager>() { |
| 358 |
@Override |
| 359 |
public HdmiControlManager createService() throws ServiceNotFoundException { |
| 360 |
IBinder b = ServiceManager.getServiceOrThrow(Context.HDMI_CONTROL_SERVICE); |
| 361 |
return new HdmiControlManager(IHdmiControlService.Stub.asInterface(b)); |
| 362 |
}}); |
| 363 |
|
| 364 |
registerService(Context.TEXT_CLASSIFICATION_SERVICE, TextClassificationManager.class, |
| 365 |
new CachedServiceFetcher<TextClassificationManager>() { |
| 366 |
@Override |
| 367 |
public TextClassificationManager createService(ContextImpl ctx) { |
| 368 |
return new TextClassificationManager(ctx); |
| 369 |
}}); |
| 370 |
|
| 371 |
registerService(Context.FONT_SERVICE, FontManager.class, |
| 372 |
new CachedServiceFetcher<FontManager>() { |
| 373 |
@Override |
| 374 |
public FontManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 375 |
IBinder b = ServiceManager.getServiceOrThrow(Context.FONT_SERVICE); |
| 376 |
return FontManager.create(IFontManager.Stub.asInterface(b)); |
| 377 |
}}); |
| 378 |
|
| 379 |
registerService(Context.CLIPBOARD_SERVICE, ClipboardManager.class, |
| 380 |
new CachedServiceFetcher<ClipboardManager>() { |
| 381 |
@Override |
| 382 |
public ClipboardManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 383 |
return new ClipboardManager(ctx.getOuterContext(), |
| 384 |
ctx.mMainThread.getHandler()); |
| 385 |
}}); |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE); |
| 391 |
|
| 392 |
registerService(Context.PAC_PROXY_SERVICE, PacProxyManager.class, |
| 393 |
new CachedServiceFetcher<PacProxyManager>() { |
| 394 |
@Override |
| 395 |
public PacProxyManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 396 |
IBinder b = ServiceManager.getServiceOrThrow(Context.PAC_PROXY_SERVICE); |
| 397 |
IPacProxyManager service = IPacProxyManager.Stub.asInterface(b); |
| 398 |
return new PacProxyManager(ctx.getOuterContext(), service); |
| 399 |
}}); |
| 400 |
|
| 401 |
registerService(Context.NETD_SERVICE, IBinder.class, new StaticServiceFetcher<IBinder>() { |
| 402 |
@Override |
| 403 |
public IBinder createService() throws ServiceNotFoundException { |
| 404 |
return ServiceManager.getServiceOrThrow(Context.NETD_SERVICE); |
| 405 |
} |
| 406 |
}); |
| 407 |
|
| 408 |
registerService(Context.TETHERING_SERVICE, TetheringManager.class, |
| 409 |
new CachedServiceFetcher<TetheringManager>() { |
| 410 |
@Override |
| 411 |
public TetheringManager createService(ContextImpl ctx) { |
| 412 |
return new TetheringManager( |
| 413 |
ctx, () -> ServiceManager.getService(Context.TETHERING_SERVICE)); |
| 414 |
}}); |
| 415 |
|
| 416 |
registerService(Context.VPN_MANAGEMENT_SERVICE, VpnManager.class, |
| 417 |
new CachedServiceFetcher<VpnManager>() { |
| 418 |
@Override |
| 419 |
public VpnManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 420 |
IBinder b = ServiceManager.getService(Context.VPN_MANAGEMENT_SERVICE); |
| 421 |
IVpnManager service = IVpnManager.Stub.asInterface(b); |
| 422 |
return new VpnManager(ctx, service); |
| 423 |
}}); |
| 424 |
|
| 425 |
registerService(Context.VCN_MANAGEMENT_SERVICE, VcnManager.class, |
| 426 |
new CachedServiceFetcher<VcnManager>() { |
| 427 |
@Override |
| 428 |
public VcnManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 429 |
IBinder b = ServiceManager.getService(Context.VCN_MANAGEMENT_SERVICE); |
| 430 |
IVcnManagementService service = IVcnManagementService.Stub.asInterface(b); |
| 431 |
return new VcnManager(ctx, service); |
| 432 |
}}); |
| 433 |
|
| 434 |
registerService(Context.COUNTRY_DETECTOR, CountryDetector.class, |
| 435 |
new StaticServiceFetcher<CountryDetector>() { |
| 436 |
@Override |
| 437 |
public CountryDetector createService() throws ServiceNotFoundException { |
| 438 |
IBinder b = ServiceManager.getServiceOrThrow(Context.COUNTRY_DETECTOR); |
| 439 |
return new CountryDetector(ICountryDetector.Stub.asInterface(b)); |
| 440 |
}}); |
| 441 |
|
| 442 |
registerService(Context.DEVICE_POLICY_SERVICE, DevicePolicyManager.class, |
| 443 |
new CachedServiceFetcher<DevicePolicyManager>() { |
| 444 |
@Override |
| 445 |
public DevicePolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 446 |
IBinder b = ServiceManager.getServiceOrThrow(Context.DEVICE_POLICY_SERVICE); |
| 447 |
return new DevicePolicyManager(ctx, IDevicePolicyManager.Stub.asInterface(b)); |
| 448 |
}}); |
| 449 |
|
| 450 |
registerService(Context.DOWNLOAD_SERVICE, DownloadManager.class, |
| 451 |
new CachedServiceFetcher<DownloadManager>() { |
| 452 |
@Override |
| 453 |
public DownloadManager createService(ContextImpl ctx) { |
| 454 |
return new DownloadManager(ctx); |
| 455 |
}}); |
| 456 |
|
| 457 |
registerService(Context.BATTERY_SERVICE, BatteryManager.class, |
| 458 |
new CachedServiceFetcher<BatteryManager>() { |
| 459 |
@Override |
| 460 |
public BatteryManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 461 |
IBatteryStats stats = IBatteryStats.Stub.asInterface( |
| 462 |
ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME)); |
| 463 |
IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub |
| 464 |
.asInterface(ServiceManager.getServiceOrThrow("batteryproperties")); |
| 465 |
return new BatteryManager(ctx, stats, registrar); |
| 466 |
}}); |
| 467 |
|
| 468 |
registerService(Context.DROPBOX_SERVICE, DropBoxManager.class, |
| 469 |
new CachedServiceFetcher<DropBoxManager>() { |
| 470 |
@Override |
| 471 |
public DropBoxManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 472 |
IBinder b = ServiceManager.getServiceOrThrow(Context.DROPBOX_SERVICE); |
| 473 |
IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b); |
| 474 |
return new DropBoxManager(ctx, service); |
| 475 |
}}); |
| 476 |
|
| 477 |
registerService(Context.BINARY_TRANSPARENCY_SERVICE, BinaryTransparencyManager.class, |
| 478 |
new CachedServiceFetcher<BinaryTransparencyManager>() { |
| 479 |
@Override |
| 480 |
public BinaryTransparencyManager createService(ContextImpl ctx) |
| 481 |
throws ServiceNotFoundException { |
| 482 |
IBinder b = ServiceManager.getServiceOrThrow( |
| 483 |
Context.BINARY_TRANSPARENCY_SERVICE); |
| 484 |
IBinaryTransparencyService service = IBinaryTransparencyService.Stub.asInterface(b); |
| 485 |
return new BinaryTransparencyManager(ctx, service); |
| 486 |
}}); |
| 487 |
|
| 488 |
registerService(Context.INPUT_SERVICE, InputManager.class, |
| 489 |
new StaticServiceFetcher<InputManager>() { |
| 490 |
@Override |
| 491 |
public InputManager createService() { |
| 492 |
return InputManager.getInstance(); |
| 493 |
}}); |
| 494 |
|
| 495 |
registerService(Context.DISPLAY_SERVICE, DisplayManager.class, |
| 496 |
new CachedServiceFetcher<DisplayManager>() { |
| 497 |
@Override |
| 498 |
public DisplayManager createService(ContextImpl ctx) { |
| 499 |
return new DisplayManager(ctx.getOuterContext()); |
| 500 |
}}); |
| 501 |
|
| 502 |
registerService(Context.COLOR_DISPLAY_SERVICE, ColorDisplayManager.class, |
| 503 |
new CachedServiceFetcher<ColorDisplayManager>() { |
| 504 |
@Override |
| 505 |
public ColorDisplayManager createService(ContextImpl ctx) { |
| 506 |
return new ColorDisplayManager(); |
| 507 |
} |
| 508 |
}); |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
registerService(Context.INPUT_METHOD_SERVICE, InputMethodManager.class, |
| 515 |
new ServiceFetcher<InputMethodManager>() { |
| 516 |
@Override |
| 517 |
public InputMethodManager getService(ContextImpl ctx) { |
| 518 |
return InputMethodManager.forContext(ctx.getOuterContext()); |
| 519 |
}}); |
| 520 |
|
| 521 |
registerService(Context.TEXT_SERVICES_MANAGER_SERVICE, TextServicesManager.class, |
| 522 |
new CachedServiceFetcher<TextServicesManager>() { |
| 523 |
@Override |
| 524 |
public TextServicesManager createService(ContextImpl ctx) |
| 525 |
throws ServiceNotFoundException { |
| 526 |
return TextServicesManager.createInstance(ctx); |
| 527 |
}}); |
| 528 |
|
| 529 |
registerService(Context.KEYGUARD_SERVICE, KeyguardManager.class, |
| 530 |
new CachedServiceFetcher<KeyguardManager>() { |
| 531 |
@Override |
| 532 |
public KeyguardManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 533 |
return new KeyguardManager(ctx); |
| 534 |
}}); |
| 535 |
|
| 536 |
registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class, |
| 537 |
new CachedServiceFetcher<LayoutInflater>() { |
| 538 |
@Override |
| 539 |
public LayoutInflater createService(ContextImpl ctx) { |
| 540 |
return new PhoneLayoutInflater(ctx.getOuterContext()); |
| 541 |
}}); |
| 542 |
|
| 543 |
registerService(Context.LOCATION_SERVICE, LocationManager.class, |
| 544 |
new CachedServiceFetcher<LocationManager>() { |
| 545 |
@Override |
| 546 |
public LocationManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 547 |
IBinder b = ServiceManager.getServiceOrThrow(Context.LOCATION_SERVICE); |
| 548 |
return new LocationManager(ctx, ILocationManager.Stub.asInterface(b)); |
| 549 |
}}); |
| 550 |
|
| 551 |
registerService(Context.NETWORK_POLICY_SERVICE, NetworkPolicyManager.class, |
| 552 |
new CachedServiceFetcher<NetworkPolicyManager>() { |
| 553 |
@Override |
| 554 |
public NetworkPolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 555 |
return new NetworkPolicyManager(ctx, INetworkPolicyManager.Stub.asInterface( |
| 556 |
ServiceManager.getServiceOrThrow(Context.NETWORK_POLICY_SERVICE))); |
| 557 |
}}); |
| 558 |
|
| 559 |
registerService(Context.NOTIFICATION_SERVICE, NotificationManager.class, |
| 560 |
new CachedServiceFetcher<NotificationManager>() { |
| 561 |
@Override |
| 562 |
public NotificationManager createService(ContextImpl ctx) { |
| 563 |
final Context outerContext = ctx.getOuterContext(); |
| 564 |
return new NotificationManager( |
| 565 |
new ContextThemeWrapper(outerContext, |
| 566 |
Resources.selectSystemTheme(0, |
| 567 |
outerContext.getApplicationInfo().targetSdkVersion, |
| 568 |
com.android.internal.R.style.Theme_Dialog, |
| 569 |
com.android.internal.R.style.Theme_Holo_Dialog, |
| 570 |
com.android.internal.R.style.Theme_DeviceDefault_Dialog, |
| 571 |
com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)), |
| 572 |
ctx.mMainThread.getHandler()); |
| 573 |
}}); |
| 574 |
|
| 575 |
registerService(Context.PEOPLE_SERVICE, PeopleManager.class, |
| 576 |
new CachedServiceFetcher<PeopleManager>() { |
| 577 |
@Override |
| 578 |
public PeopleManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 579 |
return new PeopleManager(ctx); |
| 580 |
}}); |
| 581 |
|
| 582 |
registerService(Context.POWER_SERVICE, PowerManager.class, |
| 583 |
new CachedServiceFetcher<PowerManager>() { |
| 584 |
@Override |
| 585 |
public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 586 |
IBinder powerBinder = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE); |
| 587 |
IPowerManager powerService = IPowerManager.Stub.asInterface(powerBinder); |
| 588 |
IBinder thermalBinder = ServiceManager.getServiceOrThrow(Context.THERMAL_SERVICE); |
| 589 |
IThermalService thermalService = IThermalService.Stub.asInterface(thermalBinder); |
| 590 |
return new PowerManager(ctx.getOuterContext(), powerService, thermalService, |
| 591 |
ctx.mMainThread.getHandler()); |
| 592 |
}}); |
| 593 |
|
| 594 |
registerService(Context.PERFORMANCE_HINT_SERVICE, PerformanceHintManager.class, |
| 595 |
new CachedServiceFetcher<PerformanceHintManager>() { |
| 596 |
@Override |
| 597 |
public PerformanceHintManager createService(ContextImpl ctx) |
| 598 |
throws ServiceNotFoundException { |
| 599 |
return PerformanceHintManager.create(); |
| 600 |
}}); |
| 601 |
|
| 602 |
registerService(Context.RECOVERY_SERVICE, RecoverySystem.class, |
| 603 |
new CachedServiceFetcher<RecoverySystem>() { |
| 604 |
@Override |
| 605 |
public RecoverySystem createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 606 |
IBinder b = ServiceManager.getServiceOrThrow(Context.RECOVERY_SERVICE); |
| 607 |
IRecoverySystem service = IRecoverySystem.Stub.asInterface(b); |
| 608 |
return new RecoverySystem(service); |
| 609 |
}}); |
| 610 |
|
| 611 |
registerService(Context.SEARCH_SERVICE, SearchManager.class, |
| 612 |
new CachedServiceFetcher<SearchManager>() { |
| 613 |
@Override |
| 614 |
public SearchManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 615 |
return new SearchManager(ctx.getOuterContext(), |
| 616 |
ctx.mMainThread.getHandler()); |
| 617 |
}}); |
| 618 |
|
| 619 |
registerService(Context.SENSOR_SERVICE, SensorManager.class, |
| 620 |
new CachedServiceFetcher<SensorManager>() { |
| 621 |
@Override |
| 622 |
public SensorManager createService(ContextImpl ctx) { |
| 623 |
return new SystemSensorManager(ctx.getOuterContext(), |
| 624 |
ctx.mMainThread.getHandler().getLooper()); |
| 625 |
}}); |
| 626 |
|
| 627 |
registerService(Context.SENSOR_PRIVACY_SERVICE, SensorPrivacyManager.class, |
| 628 |
new CachedServiceFetcher<SensorPrivacyManager>() { |
| 629 |
@Override |
| 630 |
public SensorPrivacyManager createService(ContextImpl ctx) { |
| 631 |
return SensorPrivacyManager.getInstance(ctx); |
| 632 |
}}); |
| 633 |
|
| 634 |
registerService(Context.STATUS_BAR_SERVICE, StatusBarManager.class, |
| 635 |
new CachedServiceFetcher<StatusBarManager>() { |
| 636 |
@Override |
| 637 |
public StatusBarManager createService(ContextImpl ctx) { |
| 638 |
return new StatusBarManager(ctx.getOuterContext()); |
| 639 |
}}); |
| 640 |
|
| 641 |
registerService(Context.STORAGE_SERVICE, StorageManager.class, |
| 642 |
new CachedServiceFetcher<StorageManager>() { |
| 643 |
@Override |
| 644 |
public StorageManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 645 |
return new StorageManager(ctx, ctx.mMainThread.getHandler().getLooper()); |
| 646 |
}}); |
| 647 |
|
| 648 |
registerService(Context.STORAGE_STATS_SERVICE, StorageStatsManager.class, |
| 649 |
new CachedServiceFetcher<StorageStatsManager>() { |
| 650 |
@Override |
| 651 |
public StorageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 652 |
IStorageStatsManager service = IStorageStatsManager.Stub.asInterface( |
| 653 |
ServiceManager.getServiceOrThrow(Context.STORAGE_STATS_SERVICE)); |
| 654 |
return new StorageStatsManager(ctx, service); |
| 655 |
}}); |
| 656 |
|
| 657 |
registerService(Context.SYSTEM_UPDATE_SERVICE, SystemUpdateManager.class, |
| 658 |
new CachedServiceFetcher<SystemUpdateManager>() { |
| 659 |
@Override |
| 660 |
public SystemUpdateManager createService(ContextImpl ctx) |
| 661 |
throws ServiceNotFoundException { |
| 662 |
IBinder b = ServiceManager.getServiceOrThrow( |
| 663 |
Context.SYSTEM_UPDATE_SERVICE); |
| 664 |
ISystemUpdateManager service = ISystemUpdateManager.Stub.asInterface(b); |
| 665 |
return new SystemUpdateManager(service); |
| 666 |
}}); |
| 667 |
|
| 668 |
registerService(Context.SYSTEM_CONFIG_SERVICE, SystemConfigManager.class, |
| 669 |
new CachedServiceFetcher<SystemConfigManager>() { |
| 670 |
@Override |
| 671 |
public SystemConfigManager createService(ContextImpl ctx) { |
| 672 |
return new SystemConfigManager(); |
| 673 |
}}); |
| 674 |
|
| 675 |
registerService(Context.TELEPHONY_REGISTRY_SERVICE, TelephonyRegistryManager.class, |
| 676 |
new CachedServiceFetcher<TelephonyRegistryManager>() { |
| 677 |
@Override |
| 678 |
public TelephonyRegistryManager createService(ContextImpl ctx) { |
| 679 |
return new TelephonyRegistryManager(ctx); |
| 680 |
}}); |
| 681 |
|
| 682 |
registerService(Context.TELECOM_SERVICE, TelecomManager.class, |
| 683 |
new CachedServiceFetcher<TelecomManager>() { |
| 684 |
@Override |
| 685 |
public TelecomManager createService(ContextImpl ctx) { |
| 686 |
return new TelecomManager(ctx.getOuterContext()); |
| 687 |
}}); |
| 688 |
|
| 689 |
registerService(Context.MMS_SERVICE, MmsManager.class, |
| 690 |
new CachedServiceFetcher<MmsManager>() { |
| 691 |
@Override |
| 692 |
public MmsManager createService(ContextImpl ctx) { |
| 693 |
return new MmsManager(ctx.getOuterContext()); |
| 694 |
}}); |
| 695 |
|
| 696 |
registerService(Context.UI_MODE_SERVICE, UiModeManager.class, |
| 697 |
new CachedServiceFetcher<UiModeManager>() { |
| 698 |
@Override |
| 699 |
public UiModeManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 700 |
return new UiModeManager(ctx.getOuterContext()); |
| 701 |
}}); |
| 702 |
|
| 703 |
registerService(Context.USB_SERVICE, UsbManager.class, |
| 704 |
new CachedServiceFetcher<UsbManager>() { |
| 705 |
@Override |
| 706 |
public UsbManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 707 |
IBinder b = ServiceManager.getServiceOrThrow(Context.USB_SERVICE); |
| 708 |
return new UsbManager(ctx, IUsbManager.Stub.asInterface(b)); |
| 709 |
}}); |
| 710 |
|
| 711 |
registerService(Context.ADB_SERVICE, AdbManager.class, |
| 712 |
new CachedServiceFetcher<AdbManager>() { |
| 713 |
@Override |
| 714 |
public AdbManager createService(ContextImpl ctx) |
| 715 |
throws ServiceNotFoundException { |
| 716 |
IBinder b = ServiceManager.getServiceOrThrow(Context.ADB_SERVICE); |
| 717 |
return new AdbManager(ctx, IAdbManager.Stub.asInterface(b)); |
| 718 |
}}); |
| 719 |
|
| 720 |
registerService(Context.SERIAL_SERVICE, SerialManager.class, |
| 721 |
new CachedServiceFetcher<SerialManager>() { |
| 722 |
@Override |
| 723 |
public SerialManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 724 |
IBinder b = ServiceManager.getServiceOrThrow(Context.SERIAL_SERVICE); |
| 725 |
return new SerialManager(ctx, ISerialManager.Stub.asInterface(b)); |
| 726 |
}}); |
| 727 |
|
| 728 |
registerService(Context.VIBRATOR_MANAGER_SERVICE, VibratorManager.class, |
| 729 |
new CachedServiceFetcher<VibratorManager>() { |
| 730 |
@Override |
| 731 |
public VibratorManager createService(ContextImpl ctx) { |
| 732 |
return new SystemVibratorManager(ctx); |
| 733 |
}}); |
| 734 |
|
| 735 |
registerService(Context.VIBRATOR_SERVICE, Vibrator.class, |
| 736 |
new CachedServiceFetcher<Vibrator>() { |
| 737 |
@Override |
| 738 |
public Vibrator createService(ContextImpl ctx) { |
| 739 |
return new SystemVibrator(ctx); |
| 740 |
}}); |
| 741 |
|
| 742 |
registerService(Context.WALLPAPER_SERVICE, WallpaperManager.class, |
| 743 |
new CachedServiceFetcher<WallpaperManager>() { |
| 744 |
@Override |
| 745 |
public WallpaperManager createService(ContextImpl ctx) |
| 746 |
throws ServiceNotFoundException { |
| 747 |
final IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE); |
| 748 |
if (b == null) { |
| 749 |
ApplicationInfo appInfo = ctx.getApplicationInfo(); |
| 750 |
if (appInfo.targetSdkVersion >= Build.VERSION_CODES.P |
| 751 |
&& appInfo.isInstantApp()) { |
| 752 |
|
| 753 |
throw new ServiceNotFoundException(Context.WALLPAPER_SERVICE); |
| 754 |
} |
| 755 |
final boolean enabled = Resources.getSystem() |
| 756 |
.getBoolean(com.android.internal.R.bool.config_enableWallpaperService); |
| 757 |
if (!enabled) { |
| 758 |
|
| 759 |
return DisabledWallpaperManager.getInstance(); |
| 760 |
} |
| 761 |
|
| 762 |
Log.e(TAG, "No wallpaper service"); |
| 763 |
} |
| 764 |
IWallpaperManager service = IWallpaperManager.Stub.asInterface(b); |
| 765 |
return new WallpaperManager(service, ctx.getOuterContext(), |
| 766 |
ctx.mMainThread.getHandler()); |
| 767 |
}}); |
| 768 |
|
| 769 |
registerService(Context.WIFI_NL80211_SERVICE, WifiNl80211Manager.class, |
| 770 |
new CachedServiceFetcher<WifiNl80211Manager>() { |
| 771 |
@Override |
| 772 |
public WifiNl80211Manager createService(ContextImpl ctx) { |
| 773 |
return new WifiNl80211Manager(ctx.getOuterContext()); |
| 774 |
} |
| 775 |
}); |
| 776 |
|
| 777 |
registerService(Context.WINDOW_SERVICE, WindowManager.class, |
| 778 |
new CachedServiceFetcher<WindowManager>() { |
| 779 |
@Override |
| 780 |
public WindowManager createService(ContextImpl ctx) { |
| 781 |
return new WindowManagerImpl(ctx); |
| 782 |
}}); |
| 783 |
|
| 784 |
registerService(Context.USER_SERVICE, UserManager.class, |
| 785 |
new CachedServiceFetcher<UserManager>() { |
| 786 |
@Override |
| 787 |
public UserManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 788 |
IBinder b = ServiceManager.getServiceOrThrow(Context.USER_SERVICE); |
| 789 |
IUserManager service = IUserManager.Stub.asInterface(b); |
| 790 |
return new UserManager(ctx, service); |
| 791 |
}}); |
| 792 |
|
| 793 |
registerService(Context.APP_OPS_SERVICE, AppOpsManager.class, |
| 794 |
new CachedServiceFetcher<AppOpsManager>() { |
| 795 |
@Override |
| 796 |
public AppOpsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 797 |
IBinder b = ServiceManager.getServiceOrThrow(Context.APP_OPS_SERVICE); |
| 798 |
IAppOpsService service = IAppOpsService.Stub.asInterface(b); |
| 799 |
return new AppOpsManager(ctx, service); |
| 800 |
}}); |
| 801 |
|
| 802 |
registerService(Context.CAMERA_SERVICE, CameraManager.class, |
| 803 |
new CachedServiceFetcher<CameraManager>() { |
| 804 |
@Override |
| 805 |
public CameraManager createService(ContextImpl ctx) { |
| 806 |
return new CameraManager(ctx); |
| 807 |
}}); |
| 808 |
|
| 809 |
registerService(Context.LAUNCHER_APPS_SERVICE, LauncherApps.class, |
| 810 |
new CachedServiceFetcher<LauncherApps>() { |
| 811 |
@Override |
| 812 |
public LauncherApps createService(ContextImpl ctx) { |
| 813 |
return new LauncherApps(ctx); |
| 814 |
}}); |
| 815 |
|
| 816 |
registerService(Context.RESTRICTIONS_SERVICE, RestrictionsManager.class, |
| 817 |
new CachedServiceFetcher<RestrictionsManager>() { |
| 818 |
@Override |
| 819 |
public RestrictionsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 820 |
IBinder b = ServiceManager.getServiceOrThrow(Context.RESTRICTIONS_SERVICE); |
| 821 |
IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b); |
| 822 |
return new RestrictionsManager(ctx, service); |
| 823 |
}}); |
| 824 |
|
| 825 |
registerService(Context.PRINT_SERVICE, PrintManager.class, |
| 826 |
new CachedServiceFetcher<PrintManager>() { |
| 827 |
@Override |
| 828 |
public PrintManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 829 |
IPrintManager service = null; |
| 830 |
|
| 831 |
if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING)) { |
| 832 |
service = IPrintManager.Stub.asInterface(ServiceManager |
| 833 |
.getServiceOrThrow(Context.PRINT_SERVICE)); |
| 834 |
} |
| 835 |
final int userId = ctx.getUserId(); |
| 836 |
final int appId = UserHandle.getAppId(ctx.getApplicationInfo().uid); |
| 837 |
return new PrintManager(ctx.getOuterContext(), service, userId, appId); |
| 838 |
}}); |
| 839 |
|
| 840 |
registerService(Context.COMPANION_DEVICE_SERVICE, CompanionDeviceManager.class, |
| 841 |
new CachedServiceFetcher<CompanionDeviceManager>() { |
| 842 |
@Override |
| 843 |
public CompanionDeviceManager createService(ContextImpl ctx) |
| 844 |
throws ServiceNotFoundException { |
| 845 |
ICompanionDeviceManager service = null; |
| 846 |
|
| 847 |
if (ctx.getPackageManager().hasSystemFeature( |
| 848 |
PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) { |
| 849 |
service = ICompanionDeviceManager.Stub.asInterface( |
| 850 |
ServiceManager.getServiceOrThrow(Context.COMPANION_DEVICE_SERVICE)); |
| 851 |
} |
| 852 |
return new CompanionDeviceManager(service, ctx.getOuterContext()); |
| 853 |
}}); |
| 854 |
|
| 855 |
registerService(Context.VIRTUAL_DEVICE_SERVICE, VirtualDeviceManager.class, |
| 856 |
new CachedServiceFetcher<VirtualDeviceManager>() { |
| 857 |
@Override |
| 858 |
public VirtualDeviceManager createService(ContextImpl ctx) |
| 859 |
throws ServiceNotFoundException { |
| 860 |
IVirtualDeviceManager service = IVirtualDeviceManager.Stub.asInterface( |
| 861 |
ServiceManager.getServiceOrThrow(Context.VIRTUAL_DEVICE_SERVICE)); |
| 862 |
return new VirtualDeviceManager(service, ctx.getOuterContext()); |
| 863 |
}}); |
| 864 |
|
| 865 |
registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class, |
| 866 |
new CachedServiceFetcher<ConsumerIrManager>() { |
| 867 |
@Override |
| 868 |
public ConsumerIrManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 869 |
return new ConsumerIrManager(ctx); |
| 870 |
}}); |
| 871 |
|
| 872 |
registerService(Context.TRUST_SERVICE, TrustManager.class, |
| 873 |
new StaticServiceFetcher<TrustManager>() { |
| 874 |
@Override |
| 875 |
public TrustManager createService() throws ServiceNotFoundException { |
| 876 |
IBinder b = ServiceManager.getServiceOrThrow(Context.TRUST_SERVICE); |
| 877 |
return new TrustManager(b); |
| 878 |
}}); |
| 879 |
|
| 880 |
registerService(Context.FINGERPRINT_SERVICE, FingerprintManager.class, |
| 881 |
new CachedServiceFetcher<FingerprintManager>() { |
| 882 |
@Override |
| 883 |
public FingerprintManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 884 |
final IBinder binder; |
| 885 |
if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { |
| 886 |
binder = ServiceManager.getServiceOrThrow(Context.FINGERPRINT_SERVICE); |
| 887 |
} else { |
| 888 |
binder = ServiceManager.getService(Context.FINGERPRINT_SERVICE); |
| 889 |
} |
| 890 |
IFingerprintService service = IFingerprintService.Stub.asInterface(binder); |
| 891 |
return new FingerprintManager(ctx.getOuterContext(), service); |
| 892 |
}}); |
| 893 |
|
| 894 |
registerService(Context.FACE_SERVICE, FaceManager.class, |
| 895 |
new CachedServiceFetcher<FaceManager>() { |
| 896 |
@Override |
| 897 |
public FaceManager createService(ContextImpl ctx) |
| 898 |
throws ServiceNotFoundException { |
| 899 |
final IBinder binder; |
| 900 |
if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { |
| 901 |
binder = ServiceManager.getServiceOrThrow(Context.FACE_SERVICE); |
| 902 |
} else { |
| 903 |
binder = ServiceManager.getService(Context.FACE_SERVICE); |
| 904 |
} |
| 905 |
IFaceService service = IFaceService.Stub.asInterface(binder); |
| 906 |
return new FaceManager(ctx.getOuterContext(), service); |
| 907 |
} |
| 908 |
}); |
| 909 |
|
| 910 |
registerService(Context.IRIS_SERVICE, IrisManager.class, |
| 911 |
new CachedServiceFetcher<IrisManager>() { |
| 912 |
@Override |
| 913 |
public IrisManager createService(ContextImpl ctx) |
| 914 |
throws ServiceNotFoundException { |
| 915 |
final IBinder binder = |
| 916 |
ServiceManager.getServiceOrThrow(Context.IRIS_SERVICE); |
| 917 |
IIrisService service = IIrisService.Stub.asInterface(binder); |
| 918 |
return new IrisManager(ctx.getOuterContext(), service); |
| 919 |
} |
| 920 |
}); |
| 921 |
|
| 922 |
registerService(Context.BIOMETRIC_SERVICE, BiometricManager.class, |
| 923 |
new CachedServiceFetcher<BiometricManager>() { |
| 924 |
@Override |
| 925 |
public BiometricManager createService(ContextImpl ctx) |
| 926 |
throws ServiceNotFoundException { |
| 927 |
final IBinder binder = |
| 928 |
ServiceManager.getServiceOrThrow(Context.AUTH_SERVICE); |
| 929 |
final IAuthService service = |
| 930 |
IAuthService.Stub.asInterface(binder); |
| 931 |
return new BiometricManager(ctx.getOuterContext(), service); |
| 932 |
} |
| 933 |
}); |
| 934 |
|
| 935 |
registerService(Context.TV_INTERACTIVE_APP_SERVICE, TvInteractiveAppManager.class, |
| 936 |
new CachedServiceFetcher<TvInteractiveAppManager>() { |
| 937 |
@Override |
| 938 |
public TvInteractiveAppManager createService(ContextImpl ctx) |
| 939 |
throws ServiceNotFoundException { |
| 940 |
IBinder iBinder = |
| 941 |
ServiceManager.getServiceOrThrow(Context.TV_INTERACTIVE_APP_SERVICE); |
| 942 |
ITvInteractiveAppManager service = |
| 943 |
ITvInteractiveAppManager.Stub.asInterface(iBinder); |
| 944 |
return new TvInteractiveAppManager(service, ctx.getUserId()); |
| 945 |
}}); |
| 946 |
|
| 947 |
registerService(Context.TV_INPUT_SERVICE, TvInputManager.class, |
| 948 |
new CachedServiceFetcher<TvInputManager>() { |
| 949 |
@Override |
| 950 |
public TvInputManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 951 |
IBinder iBinder = ServiceManager.getServiceOrThrow(Context.TV_INPUT_SERVICE); |
| 952 |
ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder); |
| 953 |
return new TvInputManager(service, ctx.getUserId()); |
| 954 |
}}); |
| 955 |
|
| 956 |
registerService(Context.TV_TUNER_RESOURCE_MGR_SERVICE, TunerResourceManager.class, |
| 957 |
new CachedServiceFetcher<TunerResourceManager>() { |
| 958 |
@Override |
| 959 |
public TunerResourceManager createService(ContextImpl ctx) |
| 960 |
throws ServiceNotFoundException { |
| 961 |
IBinder iBinder = |
| 962 |
ServiceManager.getServiceOrThrow(Context.TV_TUNER_RESOURCE_MGR_SERVICE); |
| 963 |
ITunerResourceManager service = ITunerResourceManager.Stub.asInterface(iBinder); |
| 964 |
return new TunerResourceManager(service, ctx.getUserId()); |
| 965 |
}}); |
| 966 |
|
| 967 |
registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class, |
| 968 |
new CachedServiceFetcher<NetworkScoreManager>() { |
| 969 |
@Override |
| 970 |
public NetworkScoreManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 971 |
return new NetworkScoreManager(ctx); |
| 972 |
}}); |
| 973 |
|
| 974 |
registerService(Context.USAGE_STATS_SERVICE, UsageStatsManager.class, |
| 975 |
new CachedServiceFetcher<UsageStatsManager>() { |
| 976 |
@Override |
| 977 |
public UsageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 978 |
IBinder iBinder = ServiceManager.getServiceOrThrow(Context.USAGE_STATS_SERVICE); |
| 979 |
IUsageStatsManager service = IUsageStatsManager.Stub.asInterface(iBinder); |
| 980 |
return new UsageStatsManager(ctx.getOuterContext(), service); |
| 981 |
}}); |
| 982 |
|
| 983 |
registerService(Context.PERSISTENT_DATA_BLOCK_SERVICE, PersistentDataBlockManager.class, |
| 984 |
new StaticServiceFetcher<PersistentDataBlockManager>() { |
| 985 |
@Override |
| 986 |
public PersistentDataBlockManager createService() throws ServiceNotFoundException { |
| 987 |
IBinder b = ServiceManager.getServiceOrThrow(Context.PERSISTENT_DATA_BLOCK_SERVICE); |
| 988 |
IPersistentDataBlockService persistentDataBlockService = |
| 989 |
IPersistentDataBlockService.Stub.asInterface(b); |
| 990 |
if (persistentDataBlockService != null) { |
| 991 |
return new PersistentDataBlockManager(persistentDataBlockService); |
| 992 |
} else { |
| 993 |
|
| 994 |
return null; |
| 995 |
} |
| 996 |
} |
| 997 |
}); |
| 998 |
|
| 999 |
registerService(Context.OEM_LOCK_SERVICE, OemLockManager.class, |
| 1000 |
new StaticServiceFetcher<OemLockManager>() { |
| 1001 |
@Override |
| 1002 |
public OemLockManager createService() throws ServiceNotFoundException { |
| 1003 |
IBinder b = ServiceManager.getServiceOrThrow(Context.OEM_LOCK_SERVICE); |
| 1004 |
IOemLockService oemLockService = IOemLockService.Stub.asInterface(b); |
| 1005 |
if (oemLockService != null) { |
| 1006 |
return new OemLockManager(oemLockService); |
| 1007 |
} else { |
| 1008 |
|
| 1009 |
return null; |
| 1010 |
} |
| 1011 |
}}); |
| 1012 |
|
| 1013 |
registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class, |
| 1014 |
new CachedServiceFetcher<MediaProjectionManager>() { |
| 1015 |
@Override |
| 1016 |
public MediaProjectionManager createService(ContextImpl ctx) { |
| 1017 |
return new MediaProjectionManager(ctx); |
| 1018 |
}}); |
| 1019 |
|
| 1020 |
registerService(Context.APPWIDGET_SERVICE, AppWidgetManager.class, |
| 1021 |
new CachedServiceFetcher<AppWidgetManager>() { |
| 1022 |
@Override |
| 1023 |
public AppWidgetManager createService(ContextImpl ctx) { |
| 1024 |
IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE); |
| 1025 |
return b == null ? null : new AppWidgetManager(ctx, |
| 1026 |
IAppWidgetService.Stub.asInterface(b)); |
| 1027 |
}}); |
| 1028 |
|
| 1029 |
registerService(Context.MIDI_SERVICE, MidiManager.class, |
| 1030 |
new CachedServiceFetcher<MidiManager>() { |
| 1031 |
@Override |
| 1032 |
public MidiManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1033 |
IBinder b = ServiceManager.getServiceOrThrow(Context.MIDI_SERVICE); |
| 1034 |
return new MidiManager(IMidiManager.Stub.asInterface(b)); |
| 1035 |
}}); |
| 1036 |
|
| 1037 |
registerService(Context.RADIO_SERVICE, RadioManager.class, |
| 1038 |
new CachedServiceFetcher<RadioManager>() { |
| 1039 |
@Override |
| 1040 |
public RadioManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1041 |
return new RadioManager(ctx); |
| 1042 |
}}); |
| 1043 |
|
| 1044 |
registerService(Context.HARDWARE_PROPERTIES_SERVICE, HardwarePropertiesManager.class, |
| 1045 |
new CachedServiceFetcher<HardwarePropertiesManager>() { |
| 1046 |
@Override |
| 1047 |
public HardwarePropertiesManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1048 |
IBinder b = ServiceManager.getServiceOrThrow(Context.HARDWARE_PROPERTIES_SERVICE); |
| 1049 |
IHardwarePropertiesManager service = |
| 1050 |
IHardwarePropertiesManager.Stub.asInterface(b); |
| 1051 |
return new HardwarePropertiesManager(ctx, service); |
| 1052 |
}}); |
| 1053 |
|
| 1054 |
registerService(Context.SOUND_TRIGGER_SERVICE, SoundTriggerManager.class, |
| 1055 |
new CachedServiceFetcher<SoundTriggerManager>() { |
| 1056 |
@Override |
| 1057 |
public SoundTriggerManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1058 |
IBinder b = ServiceManager.getServiceOrThrow(Context.SOUND_TRIGGER_SERVICE); |
| 1059 |
return new SoundTriggerManager(ctx, ISoundTriggerService.Stub.asInterface(b)); |
| 1060 |
}}); |
| 1061 |
|
| 1062 |
registerService(Context.SHORTCUT_SERVICE, ShortcutManager.class, |
| 1063 |
new CachedServiceFetcher<ShortcutManager>() { |
| 1064 |
@Override |
| 1065 |
public ShortcutManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1066 |
IBinder b = ServiceManager.getServiceOrThrow(Context.SHORTCUT_SERVICE); |
| 1067 |
return new ShortcutManager(ctx, IShortcutService.Stub.asInterface(b)); |
| 1068 |
}}); |
| 1069 |
|
| 1070 |
registerService(Context.OVERLAY_SERVICE, OverlayManager.class, |
| 1071 |
new CachedServiceFetcher<OverlayManager>() { |
| 1072 |
@Override |
| 1073 |
public OverlayManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1074 |
IBinder b = ServiceManager.getServiceOrThrow(Context.OVERLAY_SERVICE); |
| 1075 |
return new OverlayManager(ctx, IOverlayManager.Stub.asInterface(b)); |
| 1076 |
}}); |
| 1077 |
|
| 1078 |
registerService(Context.NETWORK_WATCHLIST_SERVICE, NetworkWatchlistManager.class, |
| 1079 |
new CachedServiceFetcher<NetworkWatchlistManager>() { |
| 1080 |
@Override |
| 1081 |
public NetworkWatchlistManager createService(ContextImpl ctx) |
| 1082 |
throws ServiceNotFoundException { |
| 1083 |
IBinder b = |
| 1084 |
ServiceManager.getServiceOrThrow(Context.NETWORK_WATCHLIST_SERVICE); |
| 1085 |
return new NetworkWatchlistManager(ctx, |
| 1086 |
INetworkWatchlistManager.Stub.asInterface(b)); |
| 1087 |
}}); |
| 1088 |
|
| 1089 |
registerService(Context.SYSTEM_HEALTH_SERVICE, SystemHealthManager.class, |
| 1090 |
new CachedServiceFetcher<SystemHealthManager>() { |
| 1091 |
@Override |
| 1092 |
public SystemHealthManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1093 |
IBinder b = ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME); |
| 1094 |
return new SystemHealthManager(IBatteryStats.Stub.asInterface(b)); |
| 1095 |
}}); |
| 1096 |
|
| 1097 |
registerService(Context.CONTEXTHUB_SERVICE, ContextHubManager.class, |
| 1098 |
new CachedServiceFetcher<ContextHubManager>() { |
| 1099 |
@Override |
| 1100 |
public ContextHubManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1101 |
return new ContextHubManager(ctx.getOuterContext(), |
| 1102 |
ctx.mMainThread.getHandler().getLooper()); |
| 1103 |
}}); |
| 1104 |
|
| 1105 |
registerService(Context.INCIDENT_SERVICE, IncidentManager.class, |
| 1106 |
new CachedServiceFetcher<IncidentManager>() { |
| 1107 |
@Override |
| 1108 |
public IncidentManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1109 |
return new IncidentManager(ctx); |
| 1110 |
}}); |
| 1111 |
|
| 1112 |
registerService(Context.BUGREPORT_SERVICE, BugreportManager.class, |
| 1113 |
new CachedServiceFetcher<BugreportManager>() { |
| 1114 |
@Override |
| 1115 |
public BugreportManager createService(ContextImpl ctx) |
| 1116 |
throws ServiceNotFoundException { |
| 1117 |
IBinder b = ServiceManager.getServiceOrThrow(Context.BUGREPORT_SERVICE); |
| 1118 |
return new BugreportManager(ctx.getOuterContext(), |
| 1119 |
IDumpstate.Stub.asInterface(b)); |
| 1120 |
}}); |
| 1121 |
|
| 1122 |
registerService(Context.AUTOFILL_MANAGER_SERVICE, AutofillManager.class, |
| 1123 |
new CachedServiceFetcher<AutofillManager>() { |
| 1124 |
@Override |
| 1125 |
public AutofillManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1126 |
|
| 1127 |
IBinder b = ServiceManager.getService(Context.AUTOFILL_MANAGER_SERVICE); |
| 1128 |
IAutoFillManager service = IAutoFillManager.Stub.asInterface(b); |
| 1129 |
return new AutofillManager(ctx.getOuterContext(), service); |
| 1130 |
}}); |
| 1131 |
|
| 1132 |
registerService(Context.MUSIC_RECOGNITION_SERVICE, MusicRecognitionManager.class, |
| 1133 |
new CachedServiceFetcher<MusicRecognitionManager>() { |
| 1134 |
@Override |
| 1135 |
public MusicRecognitionManager createService(ContextImpl ctx) { |
| 1136 |
IBinder b = ServiceManager.getService( |
| 1137 |
Context.MUSIC_RECOGNITION_SERVICE); |
| 1138 |
return new MusicRecognitionManager( |
| 1139 |
IMusicRecognitionManager.Stub.asInterface(b)); |
| 1140 |
} |
| 1141 |
}); |
| 1142 |
|
| 1143 |
registerService(Context.CONTENT_CAPTURE_MANAGER_SERVICE, ContentCaptureManager.class, |
| 1144 |
new CachedServiceFetcher<ContentCaptureManager>() { |
| 1145 |
@Override |
| 1146 |
public ContentCaptureManager createService(ContextImpl ctx) |
| 1147 |
throws ServiceNotFoundException { |
| 1148 |
|
| 1149 |
Context outerContext = ctx.getOuterContext(); |
| 1150 |
ContentCaptureOptions options = outerContext.getContentCaptureOptions(); |
| 1151 |
|
| 1152 |
if (options != null && (options.lite || options.isWhitelisted(outerContext))) { |
| 1153 |
IBinder b = ServiceManager |
| 1154 |
.getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE); |
| 1155 |
IContentCaptureManager service = IContentCaptureManager.Stub.asInterface(b); |
| 1156 |
|
| 1157 |
if (service != null) { |
| 1158 |
return new ContentCaptureManager(outerContext, service, options); |
| 1159 |
} |
| 1160 |
} |
| 1161 |
|
| 1162 |
|
| 1163 |
return null; |
| 1164 |
}}); |
| 1165 |
|
| 1166 |
registerService(Context.TRANSLATION_MANAGER_SERVICE, TranslationManager.class, |
| 1167 |
new CachedServiceFetcher<TranslationManager>() { |
| 1168 |
@Override |
| 1169 |
public TranslationManager createService(ContextImpl ctx) |
| 1170 |
throws ServiceNotFoundException { |
| 1171 |
IBinder b = ServiceManager.getService(Context.TRANSLATION_MANAGER_SERVICE); |
| 1172 |
ITranslationManager service = ITranslationManager.Stub.asInterface(b); |
| 1173 |
|
| 1174 |
if (service != null) { |
| 1175 |
return new TranslationManager(ctx.getOuterContext(), service); |
| 1176 |
} |
| 1177 |
return null; |
| 1178 |
}}); |
| 1179 |
|
| 1180 |
registerService(Context.UI_TRANSLATION_SERVICE, UiTranslationManager.class, |
| 1181 |
new CachedServiceFetcher<UiTranslationManager>() { |
| 1182 |
@Override |
| 1183 |
public UiTranslationManager createService(ContextImpl ctx) |
| 1184 |
throws ServiceNotFoundException { |
| 1185 |
IBinder b = ServiceManager.getService(Context.TRANSLATION_MANAGER_SERVICE); |
| 1186 |
ITranslationManager service = ITranslationManager.Stub.asInterface(b); |
| 1187 |
if (service != null) { |
| 1188 |
return new UiTranslationManager(ctx.getOuterContext(), service); |
| 1189 |
} |
| 1190 |
return null; |
| 1191 |
}}); |
| 1192 |
|
| 1193 |
registerService(Context.SEARCH_UI_SERVICE, SearchUiManager.class, |
| 1194 |
new CachedServiceFetcher<SearchUiManager>() { |
| 1195 |
@Override |
| 1196 |
public SearchUiManager createService(ContextImpl ctx) |
| 1197 |
throws ServiceNotFoundException { |
| 1198 |
IBinder b = ServiceManager.getService(Context.SEARCH_UI_SERVICE); |
| 1199 |
return b == null ? null : new SearchUiManager(ctx); |
| 1200 |
} |
| 1201 |
}); |
| 1202 |
|
| 1203 |
registerService(Context.SMARTSPACE_SERVICE, SmartspaceManager.class, |
| 1204 |
new CachedServiceFetcher<SmartspaceManager>() { |
| 1205 |
@Override |
| 1206 |
public SmartspaceManager createService(ContextImpl ctx) |
| 1207 |
throws ServiceNotFoundException { |
| 1208 |
IBinder b = ServiceManager.getService(Context.SMARTSPACE_SERVICE); |
| 1209 |
return b == null ? null : new SmartspaceManager(ctx); |
| 1210 |
} |
| 1211 |
}); |
| 1212 |
|
| 1213 |
registerService(Context.APP_PREDICTION_SERVICE, AppPredictionManager.class, |
| 1214 |
new CachedServiceFetcher<AppPredictionManager>() { |
| 1215 |
@Override |
| 1216 |
public AppPredictionManager createService(ContextImpl ctx) |
| 1217 |
throws ServiceNotFoundException { |
| 1218 |
IBinder b = ServiceManager.getService(Context.APP_PREDICTION_SERVICE); |
| 1219 |
return b == null ? null : new AppPredictionManager(ctx); |
| 1220 |
} |
| 1221 |
}); |
| 1222 |
|
| 1223 |
registerService(Context.CONTENT_SUGGESTIONS_SERVICE, |
| 1224 |
ContentSuggestionsManager.class, |
| 1225 |
new CachedServiceFetcher<ContentSuggestionsManager>() { |
| 1226 |
@Override |
| 1227 |
public ContentSuggestionsManager createService(ContextImpl ctx) { |
| 1228 |
|
| 1229 |
IBinder b = ServiceManager.getService( |
| 1230 |
Context.CONTENT_SUGGESTIONS_SERVICE); |
| 1231 |
IContentSuggestionsManager service = |
| 1232 |
IContentSuggestionsManager.Stub.asInterface(b); |
| 1233 |
return new ContentSuggestionsManager(ctx.getUserId(), service); |
| 1234 |
} |
| 1235 |
}); |
| 1236 |
|
| 1237 |
registerService(Context.WALLPAPER_EFFECTS_GENERATION_SERVICE, |
| 1238 |
WallpaperEffectsGenerationManager.class, |
| 1239 |
new CachedServiceFetcher<WallpaperEffectsGenerationManager>() { |
| 1240 |
@Override |
| 1241 |
public WallpaperEffectsGenerationManager createService(ContextImpl ctx) |
| 1242 |
throws ServiceNotFoundException { |
| 1243 |
IBinder b = ServiceManager.getService( |
| 1244 |
Context.WALLPAPER_EFFECTS_GENERATION_SERVICE); |
| 1245 |
return b == null ? null : |
| 1246 |
new WallpaperEffectsGenerationManager( |
| 1247 |
IWallpaperEffectsGenerationManager.Stub.asInterface(b)); |
| 1248 |
} |
| 1249 |
}); |
| 1250 |
|
| 1251 |
registerService(Context.VR_SERVICE, VrManager.class, new CachedServiceFetcher<VrManager>() { |
| 1252 |
@Override |
| 1253 |
public VrManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1254 |
IBinder b = ServiceManager.getServiceOrThrow(Context.VR_SERVICE); |
| 1255 |
return new VrManager(IVrManager.Stub.asInterface(b)); |
| 1256 |
} |
| 1257 |
}); |
| 1258 |
|
| 1259 |
registerService(Context.CROSS_PROFILE_APPS_SERVICE, CrossProfileApps.class, |
| 1260 |
new CachedServiceFetcher<CrossProfileApps>() { |
| 1261 |
@Override |
| 1262 |
public CrossProfileApps createService(ContextImpl ctx) |
| 1263 |
throws ServiceNotFoundException { |
| 1264 |
IBinder b = ServiceManager.getServiceOrThrow( |
| 1265 |
Context.CROSS_PROFILE_APPS_SERVICE); |
| 1266 |
return new CrossProfileApps(ctx.getOuterContext(), |
| 1267 |
ICrossProfileApps.Stub.asInterface(b)); |
| 1268 |
} |
| 1269 |
}); |
| 1270 |
|
| 1271 |
registerService(Context.SLICE_SERVICE, SliceManager.class, |
| 1272 |
new CachedServiceFetcher<SliceManager>() { |
| 1273 |
@Override |
| 1274 |
public SliceManager createService(ContextImpl ctx) |
| 1275 |
throws ServiceNotFoundException { |
| 1276 |
return new SliceManager(ctx.getOuterContext(), |
| 1277 |
ctx.mMainThread.getHandler()); |
| 1278 |
} |
| 1279 |
}); |
| 1280 |
|
| 1281 |
registerService(Context.TIME_DETECTOR_SERVICE, TimeDetector.class, |
| 1282 |
new CachedServiceFetcher<TimeDetector>() { |
| 1283 |
@Override |
| 1284 |
public TimeDetector createService(ContextImpl ctx) |
| 1285 |
throws ServiceNotFoundException { |
| 1286 |
return new TimeDetectorImpl(); |
| 1287 |
}}); |
| 1288 |
|
| 1289 |
registerService(Context.TIME_ZONE_DETECTOR_SERVICE, TimeZoneDetector.class, |
| 1290 |
new CachedServiceFetcher<TimeZoneDetector>() { |
| 1291 |
@Override |
| 1292 |
public TimeZoneDetector createService(ContextImpl ctx) |
| 1293 |
throws ServiceNotFoundException { |
| 1294 |
return new TimeZoneDetectorImpl(); |
| 1295 |
}}); |
| 1296 |
|
| 1297 |
registerService(Context.TIME_MANAGER, TimeManager.class, |
| 1298 |
new CachedServiceFetcher<TimeManager>() { |
| 1299 |
@Override |
| 1300 |
public TimeManager createService(ContextImpl ctx) |
| 1301 |
throws ServiceNotFoundException { |
| 1302 |
return new TimeManager(); |
| 1303 |
}}); |
| 1304 |
|
| 1305 |
registerService(Context.PERMISSION_SERVICE, PermissionManager.class, |
| 1306 |
new CachedServiceFetcher<PermissionManager>() { |
| 1307 |
@Override |
| 1308 |
public PermissionManager createService(ContextImpl ctx) |
| 1309 |
throws ServiceNotFoundException { |
| 1310 |
return new PermissionManager(ctx.getOuterContext()); |
| 1311 |
}}); |
| 1312 |
|
| 1313 |
registerService(Context.LEGACY_PERMISSION_SERVICE, LegacyPermissionManager.class, |
| 1314 |
new CachedServiceFetcher<LegacyPermissionManager>() { |
| 1315 |
@Override |
| 1316 |
public LegacyPermissionManager createService(ContextImpl ctx) |
| 1317 |
throws ServiceNotFoundException { |
| 1318 |
return new LegacyPermissionManager(); |
| 1319 |
}}); |
| 1320 |
|
| 1321 |
registerService(Context.PERMISSION_CONTROLLER_SERVICE, PermissionControllerManager.class, |
| 1322 |
new CachedServiceFetcher<PermissionControllerManager>() { |
| 1323 |
@Override |
| 1324 |
public PermissionControllerManager createService(ContextImpl ctx) { |
| 1325 |
return new PermissionControllerManager(ctx.getOuterContext(), |
| 1326 |
ctx.getMainThreadHandler()); |
| 1327 |
}}); |
| 1328 |
|
| 1329 |
registerService(Context.PERMISSION_CHECKER_SERVICE, PermissionCheckerManager.class, |
| 1330 |
new CachedServiceFetcher<PermissionCheckerManager>() { |
| 1331 |
@Override |
| 1332 |
public PermissionCheckerManager createService(ContextImpl ctx) |
| 1333 |
throws ServiceNotFoundException { |
| 1334 |
return new PermissionCheckerManager(ctx.getOuterContext()); |
| 1335 |
}}); |
| 1336 |
|
| 1337 |
registerService(Context.PERMISSION_ENFORCER_SERVICE, PermissionEnforcer.class, |
| 1338 |
new CachedServiceFetcher<PermissionEnforcer>() { |
| 1339 |
@Override |
| 1340 |
public PermissionEnforcer createService(ContextImpl ctx) |
| 1341 |
throws ServiceNotFoundException { |
| 1342 |
return new PermissionEnforcer(ctx.getOuterContext()); |
| 1343 |
}}); |
| 1344 |
|
| 1345 |
registerService(Context.DYNAMIC_SYSTEM_SERVICE, DynamicSystemManager.class, |
| 1346 |
new CachedServiceFetcher<DynamicSystemManager>() { |
| 1347 |
@Override |
| 1348 |
public DynamicSystemManager createService(ContextImpl ctx) |
| 1349 |
throws ServiceNotFoundException { |
| 1350 |
IBinder b = ServiceManager.getServiceOrThrow( |
| 1351 |
Context.DYNAMIC_SYSTEM_SERVICE); |
| 1352 |
return new DynamicSystemManager( |
| 1353 |
IDynamicSystemService.Stub.asInterface(b)); |
| 1354 |
}}); |
| 1355 |
|
| 1356 |
registerService(Context.BATTERY_STATS_SERVICE, BatteryStatsManager.class, |
| 1357 |
new CachedServiceFetcher<BatteryStatsManager>() { |
| 1358 |
@Override |
| 1359 |
public BatteryStatsManager createService(ContextImpl ctx) |
| 1360 |
throws ServiceNotFoundException { |
| 1361 |
IBinder b = ServiceManager.getServiceOrThrow( |
| 1362 |
Context.BATTERY_STATS_SERVICE); |
| 1363 |
return new BatteryStatsManager( |
| 1364 |
IBatteryStats.Stub.asInterface(b)); |
| 1365 |
}}); |
| 1366 |
registerService(Context.DATA_LOADER_MANAGER_SERVICE, DataLoaderManager.class, |
| 1367 |
new CachedServiceFetcher<DataLoaderManager>() { |
| 1368 |
@Override |
| 1369 |
public DataLoaderManager createService(ContextImpl ctx) |
| 1370 |
throws ServiceNotFoundException { |
| 1371 |
IBinder b = ServiceManager.getServiceOrThrow( |
| 1372 |
Context.DATA_LOADER_MANAGER_SERVICE); |
| 1373 |
return new DataLoaderManager(IDataLoaderManager.Stub.asInterface(b)); |
| 1374 |
}}); |
| 1375 |
registerService(Context.LIGHTS_SERVICE, LightsManager.class, |
| 1376 |
new CachedServiceFetcher<LightsManager>() { |
| 1377 |
@Override |
| 1378 |
public LightsManager createService(ContextImpl ctx) |
| 1379 |
throws ServiceNotFoundException { |
| 1380 |
return new SystemLightsManager(ctx); |
| 1381 |
}}); |
| 1382 |
registerService(Context.LOCALE_SERVICE, LocaleManager.class, |
| 1383 |
new CachedServiceFetcher<LocaleManager>() { |
| 1384 |
@Override |
| 1385 |
public LocaleManager createService(ContextImpl ctx) |
| 1386 |
throws ServiceNotFoundException { |
| 1387 |
return new LocaleManager(ctx, ILocaleManager.Stub.asInterface( |
| 1388 |
ServiceManager.getServiceOrThrow(Context.LOCALE_SERVICE))); |
| 1389 |
}}); |
| 1390 |
registerService(Context.INCREMENTAL_SERVICE, IncrementalManager.class, |
| 1391 |
new CachedServiceFetcher<IncrementalManager>() { |
| 1392 |
@Override |
| 1393 |
public IncrementalManager createService(ContextImpl ctx) { |
| 1394 |
IBinder b = ServiceManager.getService(Context.INCREMENTAL_SERVICE); |
| 1395 |
if (b == null) { |
| 1396 |
return null; |
| 1397 |
} |
| 1398 |
return new IncrementalManager( |
| 1399 |
IIncrementalService.Stub.asInterface(b)); |
| 1400 |
}}); |
| 1401 |
|
| 1402 |
registerService(Context.FILE_INTEGRITY_SERVICE, FileIntegrityManager.class, |
| 1403 |
new CachedServiceFetcher<FileIntegrityManager>() { |
| 1404 |
@Override |
| 1405 |
public FileIntegrityManager createService(ContextImpl ctx) |
| 1406 |
throws ServiceNotFoundException { |
| 1407 |
IBinder b = ServiceManager.getServiceOrThrow( |
| 1408 |
Context.FILE_INTEGRITY_SERVICE); |
| 1409 |
return new FileIntegrityManager(ctx.getOuterContext(), |
| 1410 |
IFileIntegrityService.Stub.asInterface(b)); |
| 1411 |
}}); |
| 1412 |
|
| 1413 |
registerService(Context.ATTESTATION_VERIFICATION_SERVICE, |
| 1414 |
AttestationVerificationManager.class, |
| 1415 |
new CachedServiceFetcher<AttestationVerificationManager>() { |
| 1416 |
@Override |
| 1417 |
public AttestationVerificationManager createService(ContextImpl ctx) |
| 1418 |
throws ServiceNotFoundException { |
| 1419 |
IBinder b = ServiceManager.getServiceOrThrow( |
| 1420 |
Context.ATTESTATION_VERIFICATION_SERVICE); |
| 1421 |
return new AttestationVerificationManager(ctx.getOuterContext(), |
| 1422 |
IAttestationVerificationManagerService.Stub.asInterface(b)); |
| 1423 |
}}); |
| 1424 |
|
| 1425 |
|
| 1426 |
registerService(Context.APP_INTEGRITY_SERVICE, AppIntegrityManager.class, |
| 1427 |
new CachedServiceFetcher<AppIntegrityManager>() { |
| 1428 |
@Override |
| 1429 |
public AppIntegrityManager createService(ContextImpl ctx) |
| 1430 |
throws ServiceNotFoundException { |
| 1431 |
IBinder b = ServiceManager.getServiceOrThrow(Context.APP_INTEGRITY_SERVICE); |
| 1432 |
return new AppIntegrityManager(IAppIntegrityManager.Stub.asInterface(b)); |
| 1433 |
}}); |
| 1434 |
registerService(Context.APP_HIBERNATION_SERVICE, AppHibernationManager.class, |
| 1435 |
new CachedServiceFetcher<AppHibernationManager>() { |
| 1436 |
@Override |
| 1437 |
public AppHibernationManager createService(ContextImpl ctx) { |
| 1438 |
IBinder b = ServiceManager.getService(Context.APP_HIBERNATION_SERVICE); |
| 1439 |
return b == null ? null : new AppHibernationManager(ctx); |
| 1440 |
}}); |
| 1441 |
registerService(Context.DREAM_SERVICE, DreamManager.class, |
| 1442 |
new CachedServiceFetcher<DreamManager>() { |
| 1443 |
@Override |
| 1444 |
public DreamManager createService(ContextImpl ctx) |
| 1445 |
throws ServiceNotFoundException { |
| 1446 |
return new DreamManager(ctx); |
| 1447 |
}}); |
| 1448 |
registerService(Context.DEVICE_STATE_SERVICE, DeviceStateManager.class, |
| 1449 |
new CachedServiceFetcher<DeviceStateManager>() { |
| 1450 |
@Override |
| 1451 |
public DeviceStateManager createService(ContextImpl ctx) { |
| 1452 |
return new DeviceStateManager(); |
| 1453 |
}}); |
| 1454 |
|
| 1455 |
registerService(Context.MEDIA_METRICS_SERVICE, MediaMetricsManager.class, |
| 1456 |
new CachedServiceFetcher<MediaMetricsManager>() { |
| 1457 |
@Override |
| 1458 |
public MediaMetricsManager createService(ContextImpl ctx) |
| 1459 |
throws ServiceNotFoundException { |
| 1460 |
IBinder iBinder = |
| 1461 |
ServiceManager.getServiceOrThrow(Context.MEDIA_METRICS_SERVICE); |
| 1462 |
IMediaMetricsManager service = |
| 1463 |
IMediaMetricsManager.Stub.asInterface(iBinder); |
| 1464 |
return new MediaMetricsManager(service, ctx.getUserId()); |
| 1465 |
}}); |
| 1466 |
|
| 1467 |
registerService(Context.GAME_SERVICE, GameManager.class, |
| 1468 |
new CachedServiceFetcher<GameManager>() { |
| 1469 |
@Override |
| 1470 |
public GameManager createService(ContextImpl ctx) |
| 1471 |
throws ServiceNotFoundException { |
| 1472 |
return new GameManager(ctx.getOuterContext(), |
| 1473 |
ctx.mMainThread.getHandler()); |
| 1474 |
} |
| 1475 |
}); |
| 1476 |
|
| 1477 |
registerService(Context.DOMAIN_VERIFICATION_SERVICE, DomainVerificationManager.class, |
| 1478 |
new CachedServiceFetcher<DomainVerificationManager>() { |
| 1479 |
@Override |
| 1480 |
public DomainVerificationManager createService(ContextImpl context) |
| 1481 |
throws ServiceNotFoundException { |
| 1482 |
IBinder binder = ServiceManager.getServiceOrThrow( |
| 1483 |
Context.DOMAIN_VERIFICATION_SERVICE); |
| 1484 |
IDomainVerificationManager service = |
| 1485 |
IDomainVerificationManager.Stub.asInterface(binder); |
| 1486 |
return new DomainVerificationManager(context, service); |
| 1487 |
} |
| 1488 |
}); |
| 1489 |
|
| 1490 |
registerService(Context.DISPLAY_HASH_SERVICE, DisplayHashManager.class, |
| 1491 |
new CachedServiceFetcher<DisplayHashManager>() { |
| 1492 |
@Override |
| 1493 |
public DisplayHashManager createService(ContextImpl ctx) { |
| 1494 |
return new DisplayHashManager(); |
| 1495 |
} |
| 1496 |
}); |
| 1497 |
|
| 1498 |
registerService(Context.AMBIENT_CONTEXT_SERVICE, AmbientContextManager.class, |
| 1499 |
new CachedServiceFetcher<AmbientContextManager>() { |
| 1500 |
@Override |
| 1501 |
public AmbientContextManager createService(ContextImpl ctx) |
| 1502 |
throws ServiceNotFoundException { |
| 1503 |
IBinder iBinder = ServiceManager.getServiceOrThrow( |
| 1504 |
Context.AMBIENT_CONTEXT_SERVICE); |
| 1505 |
IAmbientContextManager manager = |
| 1506 |
IAmbientContextManager.Stub.asInterface(iBinder); |
| 1507 |
return new AmbientContextManager(ctx.getOuterContext(), manager); |
| 1508 |
}}); |
| 1509 |
|
| 1510 |
sInitializing = true; |
| 1511 |
try { |
| 1512 |
|
| 1513 |
|
| 1514 |
ConnectivityFrameworkInitializer.registerServiceWrappers(); |
| 1515 |
JobSchedulerFrameworkInitializer.registerServiceWrappers(); |
| 1516 |
BlobStoreManagerFrameworkInitializer.initialize(); |
| 1517 |
BluetoothFrameworkInitializer.registerServiceWrappers(); |
| 1518 |
NfcFrameworkInitializer.registerServiceWrappers(); |
| 1519 |
TelephonyFrameworkInitializer.registerServiceWrappers(); |
| 1520 |
AppSearchManagerFrameworkInitializer.initialize(); |
| 1521 |
WifiFrameworkInitializer.registerServiceWrappers(); |
| 1522 |
StatsFrameworkInitializer.registerServiceWrappers(); |
| 1523 |
RollbackManagerFrameworkInitializer.initialize(); |
| 1524 |
MediaFrameworkPlatformInitializer.registerServiceWrappers(); |
| 1525 |
MediaFrameworkInitializer.registerServiceWrappers(); |
| 1526 |
RoleFrameworkInitializer.registerServiceWrappers(); |
| 1527 |
SchedulingFrameworkInitializer.registerServiceWrappers(); |
| 1528 |
SdkSandboxManagerFrameworkInitializer.registerServiceWrappers(); |
| 1529 |
AdServicesFrameworkInitializer.registerServiceWrappers(); |
| 1530 |
UwbFrameworkInitializer.registerServiceWrappers(); |
| 1531 |
SafetyCenterFrameworkInitializer.registerServiceWrappers(); |
| 1532 |
ConnectivityFrameworkInitializerTiramisu.registerServiceWrappers(); |
| 1533 |
NearbyFrameworkInitializer.registerServiceWrappers(); |
| 1534 |
OnDevicePersonalizationFrameworkInitializer.registerServiceWrappers(); |
| 1535 |
VirtualizationFrameworkInitializer.registerServiceWrappers(); |
| 1536 |
} finally { |
| 1537 |
|
| 1538 |
|
| 1539 |
sInitializing = false; |
| 1540 |
} |
| 1541 |
} |
| 1542 |
|
| 1543 |
|
| 1544 |
private static void ensureInitializing(String methodName) { |
| 1545 |
Preconditions.checkState(sInitializing, "Internal error: %s" |
| 1546 |
+ " can only be called during class initialization.", methodName); |
| 1547 |
} |
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
public static Object[] createServiceCache() { |
| 1553 |
return new Object[sServiceCacheSize]; |
| 1554 |
} |
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
public static Object getSystemService(ContextImpl ctx, String name) { |
| 1561 |
if (name == null) { |
| 1562 |
return null; |
| 1563 |
} |
| 1564 |
final ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name); |
| 1565 |
if (fetcher == null) { |
| 1566 |
if (sEnableServiceNotFoundWtf) { |
| 1567 |
Slog.wtf(TAG, "Unknown manager requested: " + name); |
| 1568 |
} |
| 1569 |
return null; |
| 1570 |
} |
| 1571 |
|
| 1572 |
final Object ret = fetcher.getService(ctx); |
| 1573 |
if (sEnableServiceNotFoundWtf && ret == null) { |
| 1574 |
|
| 1575 |
switch (name) { |
| 1576 |
case Context.CONTENT_CAPTURE_MANAGER_SERVICE: |
| 1577 |
case Context.APP_PREDICTION_SERVICE: |
| 1578 |
case Context.INCREMENTAL_SERVICE: |
| 1579 |
case Context.ETHERNET_SERVICE: |
| 1580 |
case Context.VIRTUALIZATION_SERVICE: |
| 1581 |
return null; |
| 1582 |
} |
| 1583 |
Slog.wtf(TAG, "Manager wrapper not available: " + name); |
| 1584 |
return null; |
| 1585 |
} |
| 1586 |
return ret; |
| 1587 |
} |
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
public static String getSystemServiceName(Class<?> serviceClass) { |
| 1594 |
if (serviceClass == null) { |
| 1595 |
return null; |
| 1596 |
} |
| 1597 |
final String serviceName = SYSTEM_SERVICE_NAMES.get(serviceClass); |
| 1598 |
if (sEnableServiceNotFoundWtf && serviceName == null) { |
| 1599 |
|
| 1600 |
Slog.wtf(TAG, "Unknown manager requested: " + serviceClass.getCanonicalName()); |
| 1601 |
} |
| 1602 |
return serviceName; |
| 1603 |
} |
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
private static <T> void registerService(@NonNull String serviceName, |
| 1610 |
@NonNull Class<T> serviceClass, @NonNull ServiceFetcher<T> serviceFetcher) { |
| 1611 |
SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName); |
| 1612 |
SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher); |
| 1613 |
SYSTEM_SERVICE_CLASS_NAMES.put(serviceName, serviceClass.getSimpleName()); |
| 1614 |
} |
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
@Nullable |
| 1624 |
public static String getSystemServiceClassName(@NonNull String name) { |
| 1625 |
return SYSTEM_SERVICE_CLASS_NAMES.get(name); |
| 1626 |
} |
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
@SystemApi |
| 1639 |
public interface StaticServiceProducerWithoutBinder<TServiceClass> { |
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
@NonNull |
| 1644 |
TServiceClass createService(); |
| 1645 |
} |
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
@SystemApi |
| 1657 |
public interface StaticServiceProducerWithBinder<TServiceClass> { |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
@NonNull |
| 1663 |
TServiceClass createService(@NonNull IBinder serviceBinder); |
| 1664 |
} |
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
@SystemApi |
| 1678 |
public interface ContextAwareServiceProducerWithoutBinder<TServiceClass> { |
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
@NonNull |
| 1684 |
|
| 1685 |
TServiceClass createService(@NonNull Context context); |
| 1686 |
} |
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
@SystemApi |
| 1699 |
public interface ContextAwareServiceProducerWithBinder<TServiceClass> { |
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
@NonNull |
| 1705 |
|
| 1706 |
TServiceClass createService(@NonNull Context context, @NonNull IBinder serviceBinder); |
| 1707 |
} |
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
@SystemApi |
| 1725 |
public static <TServiceClass> void registerStaticService( |
| 1726 |
@NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, |
| 1727 |
@NonNull StaticServiceProducerWithBinder<TServiceClass> serviceProducer) { |
| 1728 |
ensureInitializing("registerStaticService"); |
| 1729 |
Preconditions.checkStringNotEmpty(serviceName); |
| 1730 |
Objects.requireNonNull(serviceWrapperClass); |
| 1731 |
Objects.requireNonNull(serviceProducer); |
| 1732 |
|
| 1733 |
registerService(serviceName, serviceWrapperClass, |
| 1734 |
new StaticServiceFetcher<TServiceClass>() { |
| 1735 |
@Override |
| 1736 |
public TServiceClass createService() throws ServiceNotFoundException { |
| 1737 |
return serviceProducer.createService( |
| 1738 |
ServiceManager.getServiceOrThrow(serviceName)); |
| 1739 |
}}); |
| 1740 |
} |
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
@SystemApi |
| 1749 |
public static <TServiceClass> void registerStaticService( |
| 1750 |
@NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, |
| 1751 |
@NonNull StaticServiceProducerWithoutBinder<TServiceClass> serviceProducer) { |
| 1752 |
ensureInitializing("registerStaticService"); |
| 1753 |
Preconditions.checkStringNotEmpty(serviceName); |
| 1754 |
Objects.requireNonNull(serviceWrapperClass); |
| 1755 |
Objects.requireNonNull(serviceProducer); |
| 1756 |
|
| 1757 |
registerService(serviceName, serviceWrapperClass, |
| 1758 |
new StaticServiceFetcher<TServiceClass>() { |
| 1759 |
@Override |
| 1760 |
public TServiceClass createService() { |
| 1761 |
return serviceProducer.createService(); |
| 1762 |
}}); |
| 1763 |
} |
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
@SystemApi |
| 1782 |
public static <TServiceClass> void registerContextAwareService( |
| 1783 |
@NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, |
| 1784 |
@NonNull ContextAwareServiceProducerWithBinder<TServiceClass> serviceProducer) { |
| 1785 |
ensureInitializing("registerContextAwareService"); |
| 1786 |
Preconditions.checkStringNotEmpty(serviceName); |
| 1787 |
Objects.requireNonNull(serviceWrapperClass); |
| 1788 |
Objects.requireNonNull(serviceProducer); |
| 1789 |
|
| 1790 |
registerService(serviceName, serviceWrapperClass, |
| 1791 |
new CachedServiceFetcher<TServiceClass>() { |
| 1792 |
@Override |
| 1793 |
public TServiceClass createService(ContextImpl ctx) |
| 1794 |
throws ServiceNotFoundException { |
| 1795 |
return serviceProducer.createService( |
| 1796 |
ctx.getOuterContext(), |
| 1797 |
ServiceManager.getServiceOrThrow(serviceName)); |
| 1798 |
}}); |
| 1799 |
} |
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
@SystemApi |
| 1810 |
public static <TServiceClass> void registerContextAwareService( |
| 1811 |
@NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, |
| 1812 |
@NonNull ContextAwareServiceProducerWithoutBinder<TServiceClass> serviceProducer) { |
| 1813 |
ensureInitializing("registerContextAwareService"); |
| 1814 |
Preconditions.checkStringNotEmpty(serviceName); |
| 1815 |
Objects.requireNonNull(serviceWrapperClass); |
| 1816 |
Objects.requireNonNull(serviceProducer); |
| 1817 |
|
| 1818 |
registerService(serviceName, serviceWrapperClass, |
| 1819 |
new CachedServiceFetcher<TServiceClass>() { |
| 1820 |
@Override |
| 1821 |
public TServiceClass createService(ContextImpl ctx) { |
| 1822 |
return serviceProducer.createService(ctx.getOuterContext()); |
| 1823 |
}}); |
| 1824 |
} |
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
static abstract interface ServiceFetcher<T> { |
| 1831 |
T getService(ContextImpl ctx); |
| 1832 |
} |
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
static abstract class CachedServiceFetcher<T> implements ServiceFetcher<T> { |
| 1839 |
private final int mCacheIndex; |
| 1840 |
|
| 1841 |
CachedServiceFetcher() { |
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
mCacheIndex = sServiceCacheSize++; |
| 1846 |
} |
| 1847 |
|
| 1848 |
@Override |
| 1849 |
@SuppressWarnings("unchecked") |
| 1850 |
public final T getService(ContextImpl ctx) { |
| 1851 |
final Object[] cache = ctx.mServiceCache; |
| 1852 |
final int[] gates = ctx.mServiceInitializationStateArray; |
| 1853 |
boolean interrupted = false; |
| 1854 |
|
| 1855 |
T ret = null; |
| 1856 |
|
| 1857 |
for (;;) { |
| 1858 |
boolean doInitialize = false; |
| 1859 |
synchronized (cache) { |
| 1860 |
|
| 1861 |
T service = (T) cache[mCacheIndex]; |
| 1862 |
if (service != null) { |
| 1863 |
ret = service; |
| 1864 |
break; |
| 1865 |
} |
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
if (gates[mCacheIndex] == ContextImpl.STATE_READY |
| 1874 |
|| gates[mCacheIndex] == ContextImpl.STATE_NOT_FOUND) { |
| 1875 |
gates[mCacheIndex] = ContextImpl.STATE_UNINITIALIZED; |
| 1876 |
} |
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
if (gates[mCacheIndex] == ContextImpl.STATE_UNINITIALIZED) { |
| 1883 |
doInitialize = true; |
| 1884 |
gates[mCacheIndex] = ContextImpl.STATE_INITIALIZING; |
| 1885 |
} |
| 1886 |
} |
| 1887 |
|
| 1888 |
if (doInitialize) { |
| 1889 |
|
| 1890 |
|
| 1891 |
T service = null; |
| 1892 |
@ServiceInitializationState int newState = ContextImpl.STATE_NOT_FOUND; |
| 1893 |
try { |
| 1894 |
|
| 1895 |
|
| 1896 |
service = createService(ctx); |
| 1897 |
newState = ContextImpl.STATE_READY; |
| 1898 |
|
| 1899 |
} catch (ServiceNotFoundException e) { |
| 1900 |
onServiceNotFound(e); |
| 1901 |
|
| 1902 |
} finally { |
| 1903 |
synchronized (cache) { |
| 1904 |
cache[mCacheIndex] = service; |
| 1905 |
gates[mCacheIndex] = newState; |
| 1906 |
cache.notifyAll(); |
| 1907 |
} |
| 1908 |
} |
| 1909 |
ret = service; |
| 1910 |
break; |
| 1911 |
} |
| 1912 |
|
| 1913 |
|
| 1914 |
synchronized (cache) { |
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
while (gates[mCacheIndex] < ContextImpl.STATE_READY) { |
| 1919 |
try { |
| 1920 |
|
| 1921 |
interrupted |= Thread.interrupted(); |
| 1922 |
cache.wait(); |
| 1923 |
} catch (InterruptedException e) { |
| 1924 |
|
| 1925 |
|
| 1926 |
Slog.w(TAG, "getService() interrupted"); |
| 1927 |
interrupted = true; |
| 1928 |
} |
| 1929 |
} |
| 1930 |
} |
| 1931 |
} |
| 1932 |
if (interrupted) { |
| 1933 |
Thread.currentThread().interrupt(); |
| 1934 |
} |
| 1935 |
return ret; |
| 1936 |
} |
| 1937 |
|
| 1938 |
public abstract T createService(ContextImpl ctx) throws ServiceNotFoundException; |
| 1939 |
} |
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
static abstract class StaticServiceFetcher<T> implements ServiceFetcher<T> { |
| 1946 |
private T mCachedInstance; |
| 1947 |
|
| 1948 |
@Override |
| 1949 |
public final T getService(ContextImpl ctx) { |
| 1950 |
synchronized (StaticServiceFetcher.this) { |
| 1951 |
if (mCachedInstance == null) { |
| 1952 |
try { |
| 1953 |
mCachedInstance = createService(); |
| 1954 |
} catch (ServiceNotFoundException e) { |
| 1955 |
onServiceNotFound(e); |
| 1956 |
} |
| 1957 |
} |
| 1958 |
return mCachedInstance; |
| 1959 |
} |
| 1960 |
} |
| 1961 |
|
| 1962 |
public abstract T createService() throws ServiceNotFoundException; |
| 1963 |
} |
| 1964 |
|
| 1965 |
|
| 1966 |
public static void onServiceNotFound(ServiceNotFoundException e) { |
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
if (android.os.Process.myUid() < android.os.Process.FIRST_APPLICATION_UID) { |
| 1971 |
Log.wtf(TAG, e.getMessage(), e); |
| 1972 |
} else { |
| 1973 |
Log.w(TAG, e.getMessage()); |
| 1974 |
} |
| 1975 |
} |
| 1976 |
} |