最近在看 uiautomator 的源码,UiDevice 的初始化操作:

private UiDevice() {
      /* hide constructor */
  }

  /**
   * @hide
   */
  public void initialize(UiAutomatorBridge uiAutomatorBridge) {
      mUiAutomationBridge = uiAutomatorBridge;
  }


/**
   * Retrieves a singleton instance of UiDevice
   *
   * @return UiDevice instance
   * @since API Level 16
   */
  public static UiDevice getInstance() {
      if (sDevice == null) {
          sDevice = new UiDevice();
      }
      return sDevice;
  }

UiDevice 初始化这块应该是拿到 UiAutomatorBridge 对象,但是这一部分被隐藏了,有个疑问是 UiAutomatorBridge 是怎么实例化的?


↙↙↙阅读原文可查看相关链接,并与作者交流