android.hardware.display.DisplayManagerGlobal Java Examples

The following examples show how to use android.hardware.display.DisplayManagerGlobal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisplayManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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())) {
            handleLogicalDisplayChanged(displayId, display);
            changed = true;
        }
    }
    return changed;
}
 
Example #2
Source File: Display.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private Display(DisplayManagerGlobal global, int displayId,
        /*@NotNull*/ DisplayInfo displayInfo, DisplayAdjustments daj, Resources res) {
    mGlobal = global;
    mDisplayId = displayId;
    mDisplayInfo = displayInfo;
    mResources = res;
    mDisplayAdjustments = mResources != null
        ? new DisplayAdjustments(mResources.getConfiguration())
        : daj != null ? new DisplayAdjustments(daj) : null;
    mIsValid = true;

    // Cache properties that cannot change as long as the display is valid.
    mLayerStack = displayInfo.layerStack;
    mFlags = displayInfo.flags;
    mType = displayInfo.type;
    mAddress = displayInfo.address;
    mOwnerUid = displayInfo.ownerUid;
    mOwnerPackageName = displayInfo.ownerPackageName;
}
 
Example #3
Source File: SuJavaPlugin.java    From rebootmenu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the level of color saturation to apply to the display.
 *
 * @param level The amount of saturation to apply, between 0 and 1 inclusive.
 *              0 produces a grayscale image, 1 is normal.
 *              //@hide
 */
@TargetApi(Build.VERSION_CODES.P)
private static boolean setDisplaySaturationLevel(@FloatRange(from = 0, to = 1) float level) {
    boolean ret = false;
    try {
        //Landroid/hardware/display/DisplayManagerGlobal;->setSaturationLevel(F)V,greylist-max-o
        //noinspection ConstantConditions
        DisplayManagerGlobal.getInstance().setSaturationLevel(level);
        ret = true;
    } catch (Throwable t) {
        Log.e(TAG, "setDisplaySaturationLevel: ", t);
    } finally {
        Log.d(TAG, "main: setDisplaySaturationLevel(" + level + "): " + ret);
    }
    return ret;
}
 
Example #4
Source File: ResourcesManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an adjusted {@link Display} object based on the inputs or null if display isn't
 * available.
 *
 * @param displayId display Id.
 * @param resources The {@link Resources} backing the display adjustments.
 */
public Display getAdjustedDisplay(final int displayId, Resources resources) {
    synchronized (this) {
        final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
        if (dm == null) {
            // may be null early in system startup
            return null;
        }
        return dm.getCompatibleDisplay(displayId, resources);
    }
}
 
Example #5
Source File: UiAutomation.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Takes a screenshot.
 *
 * @return The screenshot bitmap on success, null otherwise.
 */
public Bitmap takeScreenshot() {
    synchronized (mLock) {
        throwIfNotConnectedLocked();
    }
    Display display = DisplayManagerGlobal.getInstance()
            .getRealDisplay(Display.DEFAULT_DISPLAY);
    Point displaySize = new Point();
    display.getRealSize(displaySize);

    int rotation = display.getRotation();

    // Take the screenshot
    Bitmap screenShot = null;
    try {
        // Calling out without a lock held.
        screenShot = mUiAutomationConnection.takeScreenshot(
                new Rect(0, 0, displaySize.x, displaySize.y), rotation);
        if (screenShot == null) {
            return null;
        }
    } catch (RemoteException re) {
        Log.e(LOG_TAG, "Error while taking screnshot!", re);
        return null;
    }

    // Optimization
    screenShot.setHasAlpha(false);

    return screenShot;
}
 
Example #6
Source File: DisplayManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void handleLogicalDisplayChanged(int displayId, @NonNull LogicalDisplay display) {
    if (displayId == Display.DEFAULT_DISPLAY) {
        recordTopInsetLocked(display);
    }
    sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
}
 
Example #7
Source File: DisplayManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private LogicalDisplay addLogicalDisplayLocked(DisplayDevice device) {
    DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked();
    boolean isDefault = (deviceInfo.flags
            & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0;
    if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) {
        Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo);
        isDefault = false;
    }

    if (!isDefault && mSingleDisplayDemoMode) {
        Slog.i(TAG, "Not creating a logical display for a secondary display "
                + " because single display demo mode is enabled: " + deviceInfo);
        return null;
    }

    final int displayId = assignDisplayIdLocked(isDefault);
    final int layerStack = assignLayerStackLocked(displayId);

    LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device);
    display.updateLocked(mDisplayDevices);
    if (!display.isValidLocked()) {
        // This should never happen currently.
        Slog.w(TAG, "Ignoring display device because the logical display "
                + "created from it was not considered valid: " + deviceInfo);
        return null;
    }

    configureColorModeLocked(display, device);
    if (isDefault) {
        recordStableDisplayStatsIfNeededLocked(display);
        recordTopInsetLocked(display);
    }

    mLogicalDisplays.put(displayId, display);

    // Wake up waitForDefaultDisplay.
    if (isDefault) {
        mSyncRoot.notifyAll();
    }

    sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED);
    return display;
}
 
Example #8
Source File: Choreographer.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static float getRefreshRate() {
    DisplayInfo di = DisplayManagerGlobal.getInstance().getDisplayInfo(
            Display.DEFAULT_DISPLAY);
    return di.getMode().getRefreshRate();
}
 
Example #9
Source File: ShellUiAutomatorBridge.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
public Display getDefaultDisplay() {
	return DisplayManagerGlobal.getInstance().getRealDisplay(
			Display.DEFAULT_DISPLAY);
}
 
Example #10
Source File: BitmapUtil.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
public static Bitmap takeScreenshot(int rotation, int screenWidth,
		int screenHeight) {
	Display display = DisplayManagerGlobal.getInstance().getRealDisplay(
			Display.DEFAULT_DISPLAY);
	Point displaySize = new Point();
	display.getRealSize(displaySize);
	final int displayWidth = screenWidth;
	final int displayHeight = screenHeight;
	final float screenshotWidth;
	final float screenshotHeight;
	switch (rotation) {
	case UiAutomation.ROTATION_FREEZE_0: {
		screenshotWidth = displayWidth;
		screenshotHeight = displayHeight;
	}
		break;
	case UiAutomation.ROTATION_FREEZE_90: {
		screenshotWidth = displayHeight;
		screenshotHeight = displayWidth;
	}
		break;
	case UiAutomation.ROTATION_FREEZE_180: {
		screenshotWidth = displayWidth;
		screenshotHeight = displayHeight;
	}
		break;
	case UiAutomation.ROTATION_FREEZE_270: {
		screenshotWidth = displayHeight;
		screenshotHeight = displayWidth;
	}
		break;
	default: {
		return null;
	}
	}

	Bitmap screenShot = null;
	try {
		screenShot = SurfaceControl.screenshot((int) screenshotWidth,
				(int) screenshotHeight);
		if (screenShot == null) {
			return null;
		}
	} catch (Exception re) {
		return null;
	}
	if (rotation != UiAutomation.ROTATION_FREEZE_0) {
		Bitmap unrotatedScreenShot = Bitmap.createBitmap(displayWidth,
				displayHeight, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(unrotatedScreenShot);
		canvas.translate(unrotatedScreenShot.getWidth() / 2,
				unrotatedScreenShot.getHeight() / 2);
		canvas.rotate(getDegreesForRotation(rotation));
		canvas.translate(-screenshotWidth / 2, -screenshotHeight / 2);
		canvas.drawBitmap(screenShot, 0, 0, null);
		canvas.setBitmap(null);
		screenShot.recycle();
		screenShot = unrotatedScreenShot;
	}
	// Optimization
	screenShot.setHasAlpha(false);
	return screenShot;
}
 
Example #11
Source File: Display.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Internal method to create a display.
 * The display created with this method will have a static {@link DisplayAdjustments} applied.
 * Applications should use {@link android.view.WindowManager#getDefaultDisplay()}
 * or {@link android.hardware.display.DisplayManager#getDisplay}
 * to get a display object.
 *
 * @hide
 */
public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
        DisplayAdjustments daj) {
    this(global, displayId, displayInfo, daj, null /*res*/);
}
 
Example #12
Source File: Display.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Internal method to create a display.
 * The display created with this method will be adjusted based on the adjustments in the
 * supplied {@link Resources}.
 *
 * @hide
 */
public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
        Resources res) {
    this(global, displayId, displayInfo, null /*daj*/, res);
}