SystemService

2021-04-20  本文已影响0人  tzlf

com.android.server.SystemService

com.android.server.SystemServiceManager

android 5.1开始,系统服务如PowerManagerService继承自SystemService

继承SystemService的好处有如下:

1. 实现onBootPhase(int phase),配合SystemServiceManager可以在启动各个阶段处理对应事件

public static final int PHASE_WAIT_FOR_DEFAULT_DISPLAY = 100;

public static final int PHASE_LOCK_SETTINGS_READY = 480;

public static final int PHASE_SYSTEM_SERVICES_READY = 500;

public static final int PHASE_ACTIVITY_MANAGER_READY = 550;

 public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600;

 public static final int PHASE_BOOT_COMPLETED = 1000;

2. 增加了LocalServices

这样SystemServer进程里各个服务调用就不用通过Binder,可以通过getLocalService获取

比如PowerManagerService中添加LocalService:

publishLocalService(PowerManagerInternal.class, new LocalService());

接下来就可以在 ActivityManagerService 调用PowerManagerService里的接口:

mLocalPowerManager = LocalServices.getService(PowerManagerInternal.class);

上一篇 下一篇

猜你喜欢

热点阅读