// TODO: Use dependencies or a boot phase
 public void windowManagerAndInputReady() {
   synchronized (mSyncRoot) {
     mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
     mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
     scheduleTraversalLocked(false);
   }
 }
  private void handleDisplayDeviceAdded(DisplayDevice device) {
    synchronized (mSyncRoot) {
      if (mDisplayDevices.contains(device)) {
        Slog.w(
            TAG,
            "Attempted to add already added display device: "
                + device.getDisplayDeviceInfoLocked());
        return;
      }

      Slog.i(TAG, "Display device added: " + device.getDisplayDeviceInfoLocked());

      mDisplayDevices.add(device);
      addLogicalDisplayLocked(device);
      scheduleTraversalLocked(false);

      // Blank or unblank the display immediately to match the state requested
      // by the power manager (if known).
      switch (mAllDisplayBlankStateFromPowerManager) {
        case DISPLAY_BLANK_STATE_BLANKED:
          device.blankLocked();
          break;
        case DISPLAY_BLANK_STATE_UNBLANKED:
          device.unblankLocked();
          break;
      }
    }
  }
 /**
  * Tells the display manager whether there is interesting unique content on the specified logical
  * display. This is used to control automatic mirroring.
  *
  * <p>If the display has unique content, then the display manager arranges for it to be presented
  * on a physical display if appropriate. Otherwise, the display manager may choose to make the
  * physical display mirror some other logical display.
  *
  * @param displayId The logical display id to update.
  * @param hasContent True if the logical display has content.
  * @param inTraversal True if called from WindowManagerService during a window traversal prior to
  *     call to performTraversalInTransactionFromWindowManager.
  */
 public void setDisplayHasContent(int displayId, boolean hasContent, boolean inTraversal) {
   synchronized (mSyncRoot) {
     LogicalDisplay display = mLogicalDisplays.get(displayId);
     if (display != null && display.hasContentLocked() != hasContent) {
       display.setHasContentLocked(hasContent);
       scheduleTraversalLocked(inTraversal);
     }
   }
 }
 private void requestGlobalDisplayStateInternal(int state) {
   synchronized (mSyncRoot) {
     if (mGlobalDisplayState != state) {
       mGlobalDisplayState = state;
       updateGlobalDisplayStateLocked();
       scheduleTraversalLocked(false);
     }
   }
 }
 private void setDisplayInfoOverrideFromWindowManagerInternal(int displayId, DisplayInfo info) {
   synchronized (mSyncRoot) {
     LogicalDisplay display = mLogicalDisplays.get(displayId);
     if (display != null) {
       if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) {
         sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
         scheduleTraversalLocked(false);
       }
     }
   }
 }
 /**
  * Overrides the display information of a particular logical display. This is used by the window
  * manager to control the size and characteristics of the default display. It is expected to apply
  * the requested change to the display information synchronously so that applications will
  * immediately observe the new state.
  *
  * @param displayId The logical display id.
  * @param info The new data to be stored.
  */
 public void setDisplayInfoOverrideFromWindowManager(int displayId, DisplayInfo info) {
   synchronized (mSyncRoot) {
     LogicalDisplay display = mLogicalDisplays.get(displayId);
     if (display != null) {
       mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked());
       display.setDisplayInfoOverrideFromWindowManagerLocked(info);
       if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) {
         sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
         scheduleTraversalLocked(false);
       }
     }
   }
 }
  private void handleDisplayDeviceRemovedLocked(DisplayDevice device) {
    if (!mDisplayDevices.remove(device)) {
      Slog.w(
          TAG,
          "Attempted to remove non-existent display device: "
              + device.getDisplayDeviceInfoLocked());
      return;
    }

    Slog.i(TAG, "Display device removed: " + device.getDisplayDeviceInfoLocked());

    updateLogicalDisplaysLocked();
    scheduleTraversalLocked(false);
  }
  /** Called by the power manager to unblank all displays. */
  public void unblankAllDisplaysFromPowerManager() {
    synchronized (mSyncRoot) {
      if (mAllDisplayBlankStateFromPowerManager != DISPLAY_BLANK_STATE_UNBLANKED) {
        mAllDisplayBlankStateFromPowerManager = DISPLAY_BLANK_STATE_UNBLANKED;

        final int count = mDisplayDevices.size();
        for (int i = 0; i < count; i++) {
          DisplayDevice device = mDisplayDevices.get(i);
          device.unblankLocked();
        }

        scheduleTraversalLocked(false);
      }
    }
  }
  private void handleDisplayDeviceAddedLocked(DisplayDevice device) {
    if (mDisplayDevices.contains(device)) {
      Slog.w(
          TAG,
          "Attempted to add already added display device: " + device.getDisplayDeviceInfoLocked());
      return;
    }

    Slog.i(TAG, "Display device added: " + device.getDisplayDeviceInfoLocked());

    mDisplayDevices.add(device);
    addLogicalDisplayLocked(device);
    updateDisplayStateLocked(device);
    scheduleTraversalLocked(false);
  }
  private void handleDisplayDeviceChanged(DisplayDevice device) {
    synchronized (mSyncRoot) {
      if (!mDisplayDevices.contains(device)) {
        Slog.w(
            TAG,
            "Attempted to change non-existent display device: "
                + device.getDisplayDeviceInfoLocked());
        return;
      }

      Slog.i(TAG, "Display device changed: " + device.getDisplayDeviceInfoLocked());

      device.applyPendingDisplayDeviceInfoChangesLocked();
      if (updateLogicalDisplaysLocked()) {
        scheduleTraversalLocked(false);
      }
    }
  }
  private void setDisplayHasContentInternal(
      int displayId, boolean hasContent, boolean inTraversal) {
    synchronized (mSyncRoot) {
      LogicalDisplay display = mLogicalDisplays.get(displayId);
      if (display != null && display.hasContentLocked() != hasContent) {
        if (DEBUG) {
          Slog.d(
              TAG,
              "Display "
                  + displayId
                  + " hasContent flag changed: "
                  + "hasContent="
                  + hasContent
                  + ", inTraversal="
                  + inTraversal);
        }

        display.setHasContentLocked(hasContent);
        scheduleTraversalLocked(inTraversal);
      }
    }
  }
 /** Called during initialization to associate the display manager with the input manager. */
 public void setInputManager(InputManagerFuncs inputManagerFuncs) {
   synchronized (mSyncRoot) {
     mInputManagerFuncs = inputManagerFuncs;
     scheduleTraversalLocked(false);
   }
 }
 /** Called during initialization to associate the display manager with the window manager. */
 public void setWindowManager(WindowManagerFuncs windowManagerFuncs) {
   synchronized (mSyncRoot) {
     mWindowManagerFuncs = windowManagerFuncs;
     scheduleTraversalLocked(false);
   }
 }