SystemServiceRegistry 解释

SystemServiceRegistry类在静态初始化块中注册系统服务,并将它们存储在Map中以便快速访问。registerService实际上实现了服务的缓存,而不是每次通过ServiceManager获取,提高了效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个类在静态代码块中注册了很多服务

static {
......
registerService(Context.ACTIVITY_SERVICE, ActivityManager.class,
                new CachedServiceFetcher<ActivityManager>() {// 注册AMS
            @Override
            public ActivityManager createService(ContextImpl ctx) {
                return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler());
            }});
......
}
private static <T> void registerService(String serviceName, Class<T> serviceClass,
            ServiceFetcher<T> serviceFetcher) {
        SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName);
        SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher);
    }

这里是把服务放在map里面。

registerService 字面名字是注册服务,其实他是把系统所有注册的服务的代理一次性全部取出来,用代理的时候直接从 map里面取,不用每次都在ServiceManager里面拿。SystemServiceRegistry其实作用就是缓存了所有服务的代理。
registerService 这个名字起得太烂了,cacheService应该叫这个名字合适。

E SystemServiceRegistry: Manager wrapper not available: persistent_data_block 03-25 10:15:02.751 1000 829 870 I am_wtf : [0,21183,system_server,-1,SystemServiceRegistry,No service published for: persistent_data_block] 03-25 10:15:02.752 1000 829 870 I am_wtf : [0,21183,system_server,-1,SystemServiceRegistry,Manager wrapper not available: persistent_data_block] 03-25 10:15:02.753 1000 829 860 I commit_sys_config_file: [package-session,2] 03-25 10:15:02.753 1000 829 962 E AtomicFile: Failed to rename /data/system/install_sessions.xml.new to /data/system/install_sessions.xml 03-25 10:15:02.753 1000 829 962 I commit_sys_config_file: [package-session,2] 03-25 10:15:02.809 1000 829 1017 W RuleEvaluation: Integrity rule files are not available. 03-25 10:15:02.810 1000 829 897 I PackageManager: Integrity check passed for file:///data/app/vmdl46588232.tmp 03-25 10:15:02.813 1000 829 860 I commit_sys_config_file: [package-session,3] 03-25 10:15:02.814 1000 829 897 V PackageManager: pkgLite for install: PackageInfoLite{6c934c5 android.inputmethodservice.cts.devicetest} 03-25 10:15:02.824 1000 829 897 W PackageManager: Can't replace full app with instant app: android.inputmethodservice.cts.devicetest for user: 0 03-25 10:15:02.824 1000 829 870 I ActivityManager: Force stopping android.inputmethodservice.cts.devicetest appid=10183 user=-1: installPackageLI 03-25 10:15:02.824 1000 829 897 W PackageManager: Failed to prepare for install. 03-25 10:15:02.828 1000 829 897 D PackageInstallerSession: Marking session 46588232 as failed: INSTALL_FAILED_SESSION_INVALID: Failed to prepare for install. 03-25 10:15:02.828 1000 829 897 I PackageInstallerSession: Session [46588232] was destroyed because of [Session marked as failed: INSTALL_FAILED_SESSION_INVALID: Failed to prepare for install.] 03-25 10:15:02.830 1000 829 962 I commit_sys_config_file: [package-session,1] 03-25 10:15:02.832 1000 829 860 I commit_sys_config_file: [package-session,2] 03-25 10:15:03.026 shell 520 520 E adbd : longfei transport UsbFfs opening service: shell,v2,TERM=xterm-256color,raw:appops write-settings 03-25 10:15:03.057 1000 829 4479 I commit_sys_config_file: [appops_accesses,5]
03-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值