private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) {
   synchronized (mSyncRoot) {
     LogicalDisplay display = mLogicalDisplays.get(displayId);
     if (display != null) {
       DisplayInfo info = display.getDisplayInfoLocked();
       if (info.hasAccess(callingUid)) {
         return info;
       }
     }
     return null;
   }
 }
 /**
  * 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);
       }
     }
   }
 }
 /**
  * Gets the size of the display as a rectangle, in pixels.
  *
  * @param outSize A {@link Rect} object to receive the size information.
  * @see #getSize(Point)
  */
 public void getRectSize(Rect outSize) {
   synchronized (this) {
     updateDisplayInfoLocked();
     mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments);
     outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels);
   }
 }
 /**
  * Gets a full copy of the display information.
  *
  * @param outDisplayInfo The object to receive the copy of the display information.
  * @return True if the display is still valid.
  * @hide
  */
 public boolean getDisplayInfo(DisplayInfo outDisplayInfo) {
   synchronized (this) {
     updateDisplayInfoLocked();
     outDisplayInfo.copyFrom(mDisplayInfo);
     return mIsValid;
   }
 }
 /**
  * Gets the size of the display, in pixels.
  *
  * <p>Note that this value should <em>not</em> be used for computing layouts, since a device will
  * typically have screen decoration (such as a status bar) along the edges of the display that
  * reduce the amount of application space available from the size returned here. Layouts should
  * instead use the window size.
  *
  * <p>The size is adjusted based on the current rotation of the display.
  *
  * <p>The size returned by this method does not necessarily represent the actual raw size (native
  * resolution) of the display. The returned size may be adjusted to exclude certain system
  * decoration elements that are always visible. It may also be scaled to provide compatibility
  * with older applications that were originally designed for smaller displays.
  *
  * @param outSize A {@link Point} object to receive the size information.
  */
 public void getSize(Point outSize) {
   synchronized (this) {
     updateDisplayInfoLocked();
     mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments);
     outSize.x = mTempMetrics.widthPixels;
     outSize.y = mTempMetrics.heightPixels;
   }
 }
 /**
  * Gets display metrics based on the real size of this display.
  *
  * <p>The size is adjusted based on the current rotation of the display.
  *
  * <p>The real size may be smaller than the physical size of the screen when the window manager is
  * emulating a smaller display (using adb shell am display-size).
  *
  * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
  */
 public void getRealMetrics(DisplayMetrics outMetrics) {
   synchronized (this) {
     updateDisplayInfoLocked();
     mDisplayInfo.getLogicalMetrics(
         outMetrics,
         CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO,
         mDisplayAdjustments.getActivityToken());
   }
 }
 private int[] getDisplayIdsInternal(int callingUid) {
   synchronized (mSyncRoot) {
     final int count = mLogicalDisplays.size();
     int[] displayIds = new int[count];
     int n = 0;
     for (int i = 0; i < count; i++) {
       LogicalDisplay display = mLogicalDisplays.valueAt(i);
       DisplayInfo info = display.getDisplayInfoLocked();
       if (info.hasAccess(callingUid)) {
         displayIds[n++] = mLogicalDisplays.keyAt(i);
       }
     }
     if (n != count) {
       displayIds = Arrays.copyOfRange(displayIds, 0, n);
     }
     return displayIds;
   }
 }
 private void updateCachedAppSizeIfNeededLocked() {
   long now = SystemClock.uptimeMillis();
   if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) {
     updateDisplayInfoLocked();
     mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments);
     mCachedAppWidthCompat = mTempMetrics.widthPixels;
     mCachedAppHeightCompat = mTempMetrics.heightPixels;
     mLastCachedAppSizeUpdate = now;
   }
 }
  /**
   * Warms up the electron beam in preparation for turning on or off. This method prepares a GL
   * context, and captures a screen shot.
   *
   * @param mode The desired mode for the upcoming animation.
   * @return True if the electron beam is ready, false if it is uncontrollable.
   */
  public boolean prepare(int mode) {
    if (DEBUG) {
      Slog.d(TAG, "prepare: mode=" + mode);
    }

    mMode = mode;

    // Get the display size and layer stack.
    // This is not expected to change while the electron beam surface is showing.
    DisplayInfo displayInfo = mDisplayManager.getDisplayInfo(Display.DEFAULT_DISPLAY);
    mDisplayLayerStack = displayInfo.layerStack;

    if (mSwapNeeded) {
      mDisplayWidth = displayInfo.getNaturalHeight();
      mDisplayHeight = displayInfo.getNaturalWidth();
    } else {
      mDisplayWidth = displayInfo.getNaturalWidth();
      mDisplayHeight = displayInfo.getNaturalHeight();
    }

    // Prepare the surface for drawing.
    if (!tryPrepare()) {
      dismiss();
      return false;
    }

    // Done.
    mPrepared = true;

    // Dejanking optimization.
    // Some GL drivers can introduce a lot of lag in the first few frames as they
    // initialize their state and allocate graphics buffers for rendering.
    // Work around this problem by rendering the first frame of the animation a few
    // times.  The rest of the animation should run smoothly thereafter.
    // The frames we draw here aren't visible because we are essentially just
    // painting the screenshot as-is.
    if (mode == MODE_COOL_DOWN) {
      for (int i = 0; i < DEJANK_FRAMES; i++) {
        draw(1.0f);
      }
    }
    return true;
  }
  // Updates all existing logical displays given the current set of display devices.
  // Removes invalid logical displays.
  // Sends notifications if needed.
  private boolean updateLogicalDisplaysLocked() {
    boolean changed = false;
    for (int i = mLogicalDisplays.size(); i-- > 0; ) {
      final int displayId = mLogicalDisplays.keyAt(i);
      LogicalDisplay display = mLogicalDisplays.valueAt(i);

      mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked());
      display.updateLocked(mDisplayDevices);
      if (!display.isValidLocked()) {
        mLogicalDisplays.removeAt(i);
        sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED);
        changed = true;
      } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) {
        sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
        changed = true;
      }
    }
    return changed;
  }
 // For debugging purposes
 @Override
 public String toString() {
   synchronized (this) {
     updateDisplayInfoLocked();
     mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments);
     return "Display id "
         + mDisplayId
         + ": "
         + mDisplayInfo
         + ", "
         + mTempMetrics
         + ", isValid="
         + mIsValid;
   }
 }
 /**
  * Gets display metrics that describe the size and density of this display.
  *
  * <p>The size is adjusted based on the current rotation of the display.
  *
  * <p>The size returned by this method does not necessarily represent the actual raw size (native
  * resolution) of the display. The returned size may be adjusted to exclude certain system decor
  * elements that are always visible. It may also be scaled to provide compatibility with older
  * applications that were originally designed for smaller displays.
  *
  * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
  */
 public void getMetrics(DisplayMetrics outMetrics) {
   synchronized (this) {
     updateDisplayInfoLocked();
     mDisplayInfo.getAppMetrics(outMetrics, mDisplayAdjustments);
   }
 }