Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44aed9fe authored by Tom Giordano's avatar Tom Giordano Committed by Abhisek Devkota
Browse files

framework: fix screenshot and rotation animation for devices with abnormal hw rotation

parent 8348851b
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -391,6 +391,8 @@ class GlobalScreenshot {

    private MediaActionSound mCameraSound;

    private final int mSfHwRotation;


    /**
     * @param context everything needs a context :(
@@ -457,6 +459,9 @@ class GlobalScreenshot {
        // Setup the Camera shutter sound
        mCameraSound = new MediaActionSound();
        mCameraSound.load(MediaActionSound.SHUTTER_CLICK);

        // Load hardware rotation from prop
        mSfHwRotation = android.os.SystemProperties.getInt("ro.sf.hwrotation",0) / 90;
    }

    /**
@@ -500,7 +505,10 @@ class GlobalScreenshot {
        // only in the natural orientation of the device :!)
        mDisplay.getRealMetrics(mDisplayMetrics);
        float[] dims = {mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels};
        float degrees = getDegreesForRotation(mDisplay.getRotation());
        int rot = mDisplay.getRotation();
        // Allow for abnormal hardware orientation
        rot = (rot + mSfHwRotation) % 4;
        float degrees = getDegreesForRotation(rot);
        boolean requiresRotation = (degrees > 0);
        if (requiresRotation) {
            // Get the dimensions of the device in its native orientation
+21 −7
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ class ScreenRotationAnimation {
    BlackFrame mExitingBlackFrame;
    BlackFrame mEnteringBlackFrame;
    int mWidth, mHeight;
    int mSnapshotRotation;

    int mOriginalRotation;
    int mOriginalWidth, mOriginalHeight;
@@ -226,6 +227,9 @@ class ScreenRotationAnimation {
            originalWidth = displayInfo.logicalWidth;
            originalHeight = displayInfo.logicalHeight;
        }
        // Allow for abnormal hardware orientation
        mSnapshotRotation = (4 - android.os.SystemProperties.getInt("ro.sf.hwrotation",0) / 90) % 4;
        if (mSnapshotRotation == Surface.ROTATION_0 || mSnapshotRotation == Surface.ROTATION_180) {
            if (originalRotation == Surface.ROTATION_90
                 || originalRotation == Surface.ROTATION_270) {
                mWidth = originalHeight;
@@ -234,6 +238,16 @@ class ScreenRotationAnimation {
                mWidth = originalWidth;
                mHeight = originalHeight;
            }
        } else {
            if (originalRotation == Surface.ROTATION_90
                || originalRotation == Surface.ROTATION_270) {
                mWidth = originalWidth;
                mHeight = originalHeight;
            } else {
                mWidth = originalHeight;
                mHeight = originalWidth;
            }
        }

        mOriginalRotation = originalRotation;
        mOriginalWidth = originalWidth;
@@ -363,7 +377,7 @@ class ScreenRotationAnimation {
        // Compute the transformation matrix that must be applied
        // to the snapshot to make it stay in the same original position
        // with the current screen rotation.
        int delta = deltaRotation(rotation, Surface.ROTATION_0);
        int delta = deltaRotation(rotation, mSnapshotRotation);
        createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);

        if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
+8 −0
Original line number Diff line number Diff line
@@ -308,6 +308,8 @@ public class WindowManagerService extends IWindowManager.Stub

    final private KeyguardDisableHandler mKeyguardDisableHandler;

    private final int mSfHwRotation;

    final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -897,6 +899,9 @@ public class WindowManagerService extends IWindowManager.Stub
            SurfaceControl.closeTransaction();
        }

        // Load hardware rotation from prop
        mSfHwRotation = android.os.SystemProperties.getInt("ro.sf.hwrotation",0) / 90;

        showCircularDisplayMaskIfNeeded();
        showEmulatorDisplayOverlayIfNeeded();
    }
@@ -6148,6 +6153,9 @@ public class WindowManagerService extends IWindowManager.Stub

                // The screenshot API does not apply the current screen rotation.
                rot = getDefaultDisplayContentLocked().getDisplay().getRotation();
                // Allow for abnormal hardware orientation
                rot = (rot + mSfHwRotation) % 4;


                if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
                    rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;