服务分为2种:Native Service、AndroidService。
Native Service:是在系统init阶段通过init.rc脚本建立的服务,完全在C++空间完成的服务。
| 比如: SensorService,
/system/bin/audioserver进程中:(main_audioserver.cpp) MediaLogService, AudioFlinger, AudioPolicyService, RadioService, SoundTriggerHwService,
/system/bin/cameraserver进程中:(main_cameraserver.cpp) CameraService,
/system/bin/mediacodec 进程中:(main_codecservice.cpp) MediaCodecService,
/system/bin/mediadrmserver进程中:(main_mediadrmserver.cpp) MediaDrmService
/system/bin/drmserver进程中:(main_drmserver.cpp) DrmManagerService
/system/bin/mediaserver (main_mediaserver.cpp) MediaPlayerService, ResourceManagerService, /system/bin/mediaextractor (main_extractorservice.cpp) MediaExtractorService
/system/bin/surfaceflinger (main_surfaceflinger.cpp) SurfaceFlinger等
/system/bin/inputflinger |
备注:
| Android7.0, 把一些service从MediaServer中分离出来了,比如audio, camera,等 frameworks\av\media\audioserver\audioserver.rc frameworks\av\media\audioserver\main_audioserver.cpp |
Androids service:是系统二阶段(init2)初始化时建立的服务,是指在JVM空间完成的服务,虽然也要使用Navite上的框架,但是服务主体存在于Android空间,所有的Androidsservice都运行在一个进程中:systemsever进程。
| ActivityManagerService | PackageManagerService | WindowManagerService |
| PowerManagerService | BatteryService | BatteryStatsService |
| DreamManagerService | DropBoxManagerService | SamplingProfilerService |
| UsageStatsService | DiskStatsService | DeviceStorageMonitorService |
| SchedulingPolicyService | AlarmManagerService | DeviceIdleController |
| ThermalObserver | JobSchedulerService | AccessibilityManagerService |
| DisplayManagerService | LightsService | GraphicsStatsService |
| StatusBarManagerService | NotificationManagerService | WallpaperManagerService |
| UiModeManagerService | AppWidgetService | LauncherAppsService |
| TextServicesManagerService | ContentService | LockSettingsService |
| InputMethodManagerService | InputManagerService | MountService |
| FingerprintService | TvInputManagerService | DockObserver |
| NetworkManagementService | NetworkScoreService | NetworkStatsService |
| NetworkPolicyManagerService | ConnectivityService | BluetoothService |
| WifiP2pService | WifiService | WifiScanningService |
| AudioService | MediaRouterService | VoiceInteractionManagerService |
| MediaProjectionManagerService | MediaSessionService |
|
| DevicePolicyManagerService | PrintManagerService | BackupManagerService |
| UserManagerService | AccountManagerService | TrustManagerService |
| SensorService | LocationManagerService | VibratorService |
| CountryDetectorService | GestureLauncherService | PersistentDataBlockService |
| EthernetService | WebViewUpdateService | ClipboardService |
| TelephonyRegistry | TelecomLoaderService | NsdService |
| UpdateLockService | SerialService | SearchManagerService |
| CommonTimeManagementService | AssetAtlasService | ConsumerIrService |
| MidiServiceCameraService | TwilightService | RestrictionsManagerService |
| MmsServiceBroker | RttService | UsbService |
AudioFlinger为例:
|
对于用户实现:XXX = AudioFlinger IAudioFlinger:是一个接口类,继承IInterface,定义服务的方法,即纯虚函数method_1()等,不能被实例化 BpAudioFlinger:是一个实现类,实现了IAudioFlinger中的纯虚函数,因为不是接口类,这个实现类不需要在接口中体现(即不需要在接口的头文件中体现,如:IMediaPlayer.h),它封装了IAudioFlinger的操作和BpBinder的操作; BnAudioFlinger:仍是一个接口类,未实现IAudioFlinger中的纯虚函数,不能被实例化,需要一个真正工作的类来继承、实现它,这个类才是真正执行具体功能的类。BnAudioFlinger仅实现了虚函数onTransact()(在BBinder::transact()被调用)。 AudioFlinger:实现BnAudioFlinger,会有一个AudioFlinger::instantiate()函数来注册服务。 AudioFlinger::instantiate() 在一个进程(AudioServer)中进行调用,AudioServer由init进程调用
对于C++ Binder框架: IInterface:主要是定义了asBinder()、纯虚函数onAsBinder(),asBinder()直接调用onAsBinder(),onAsBinder()分别在BnInterface、BpInterface中进行了实现,用于获取BnInterface、BpBinder的地址,即IInterface的作用是通过接口获取对应的Binder对象的本地地址/代理BpBinder的地址。 BpInterface< IAudioFlinger >:是一个接口,一个模板类,是一个粘合类,即继承BpInterface< IAudioFlinger >便等同于同时继承IAudioFlinger和BpRefBase。 BnInterface< IAudioFlinger >:是一个接口,一个模板类,是一个粘合类 对于Binder核心库: IBinder:是一个接口,被BpBinder、Bbinder继承 BpBinder:客户端,内部有一个成员mHandle记录了远程服务对象的handle BpRefBase:客户端,内部有一个成员指向BpBinder,采用的是Bridge设计模式,实际是是通过BpBinder来完成通信 Bbinder:服务端 ProcessState、IPCThreadState是进程、线程相关,是对Binder驱动的封装 |
本文探讨了Android系统启动后加载的两类服务——Native Service和Android Service。Native Service在系统初始化的init阶段通过init.rc脚本创建,完全在C++环境中运行。而Android Service则在JVM空间中实现,主要运行于systemserver进程,尽管依赖Native框架,但服务主体属于Android系统。
454

被折叠的 条评论
为什么被折叠?



