Android SystemService类注释

参考文章http://www.robinheztto.com/2016/12/20/android-systemservice/

文件位置:frameworks/base/services/core/java/com/android/server/SystemService.java

此类中所有生命周期的方法都是在SystemServer主线程中被调用

public abstract class SystemService {
  /**
   * 创建ActivityManagerService,PowerManagerService,LightsService,
   * DisplayManagerService之后,PackageManagerService之前.
   */  
  public static final int PHASE_WAIT_FOR_DEFAULT_DISPLAY = 100;

  /**
   * 创建PackageManagerService,WindowManagerService等等诸多服务.
   */
  public static final int PHASE_LOCK_SETTINGS_READY = 480;

  /**
   * PHASE_LOCK_SETTINGS_READY到PHASE_SYSTEM_SERVICES_READY之间无任何操作,PHASE_SYSTEM_SERVICES_READY之后,
   * 系统服务(例如PowerManager,PackageManager等等)能够被调用.
   */
  public static final int PHASE_SYSTEM_SERVICES_READY = 500;

  /**
   * ActivityManagerService ready.
   */
  public static final int PHASE_ACTIVITY_MANAGER_READY = 550;

  /**
   * 启动SystemUI,Watchdog,services能够start/bind三方应用,App能够通过Binder调用系统服务.
   */
  public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600;

  /**
   * 启动完成,系统服务执行PHASE_BOOT_COMPLETED回调比注册ACTION_BOOT_COMPLETED广播能减低延迟.
   */
  public static final int PHASE_BOOT_COMPLETED = 1000;

}

//部分方法注释
/**
 * 构造方法,初始化system server context.
 *
 * @param context The system server context.
 */
public SystemService(Context context) {
    mContext = context;
}

/**
 * 获取system context.
 */
public final Context getContext() {
    return mContext;
}

/**
 * 是否是安全模式.
 */
public final boolean isSafeMode() {
    return getManager().isSafeMode();
}

/**
 * 在构造方法后调用.
 */
public abstract void onStart();

/**
 * 不同BootPhase阶段的回调.
 */
public void onBootPhase(int phase) {}

......

/**
 * Publish the service到ServiceManager,对其他进程提供binder服务.
 */
protected final void publishBinderService(String name, IBinder service) {
    publishBinderService(name, service, false);
}

/**
 * Publish the service到ServiceManager,对其他进程提供binder服务.
 */
protected final void publishBinderService(String name, IBinder service,
        boolean allowIsolated) {
    ServiceManager.addService(name, service, allowIsolated);
}

/**
 * 通过服务名获取binder服务.
 */
protected final IBinder getBinderService(String name) {
    return ServiceManager.getService(name);
}

/**
 * Publish service到LocalServices,以供SystemServer进程中的其他服务调用.
 */
protected final  void publishLocalService(Class type, T service) {
    LocalServices.addService(type, service);
}

/**
 * 通过Class Type从LocalServices中获取服务.
 */
protected final  T getLocalService(Class type) {
    return LocalServices.getService(type);
}

/**
 * 从LocalServices中获取SystemServiceManager(SystemServiceManager也被注册到了从LocalServices).
 */
private SystemServiceManager getManager() {
    return LocalServices.getService(SystemServiceManager.class);
}

你可能感兴趣的:(Android系统)