diff options
author | 2023-07-14 16:35:06 +0100 | |
---|---|---|
committer | 2023-09-21 12:05:00 +0100 | |
commit | 670fb7f5c0d23cf51ead25538bcb017e03ed73ac (patch) | |
tree | 0d145ee02cf01e42cca30d7555382e3e31aa6746 | |
parent | 3faf4e64c386957aba9926cf61c5f3f0f251c645 (diff) |
Start logging rotation lock history + include caller information
There have been a few reports on foldables where rotation lock suddenly
changed, without user interaction.
Adding these logs will make it easier to debug the issue.
Bug: 289023967
Bug: 289534937
Bug: 279685215
Test: Manually - Change rotation lock and check logs in dumpsys
Change-Id: If8de11265355f640a6ec54950bb3250c231b34cf
21 files changed, 154 insertions, 76 deletions
diff --git a/core/java/android/app/UiAutomationConnection.java b/core/java/android/app/UiAutomationConnection.java index 6f4abfdc05c1..6a03c17159d3 100644 --- a/core/java/android/app/UiAutomationConnection.java +++ b/core/java/android/app/UiAutomationConnection.java @@ -207,9 +207,10 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub { final long identity = Binder.clearCallingIdentity(); try { if (rotation == UiAutomation.ROTATION_UNFREEZE) { - mWindowManager.thawRotation(); + mWindowManager.thawRotation(/* caller= */ "UiAutomationConnection#setRotation"); } else { - mWindowManager.freezeRotation(rotation); + mWindowManager.freezeRotation(rotation, + /* caller= */ "UiAutomationConnection#setRotation"); } return true; } catch (RemoteException re) { @@ -615,11 +616,13 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub { if (mInitialFrozenRotation != INITIAL_FROZEN_ROTATION_UNSPECIFIED) { // Calling out with a lock held is fine since if the system // process is gone the client calling in will be killed. - mWindowManager.freezeRotation(mInitialFrozenRotation); + mWindowManager.freezeRotation(mInitialFrozenRotation, + /* caller= */ "UiAutomationConnection#restoreRotationStateLocked"); } else { // Calling out with a lock held is fine since if the system // process is gone the client calling in will be killed. - mWindowManager.thawRotation(); + mWindowManager.thawRotation( + /* caller= */ "UiAutomationConnection#restoreRotationStateLocked"); } } catch (RemoteException re) { /* ignore */ diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index d3b7a5be47ba..cccac95b9caa 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -316,14 +316,14 @@ interface IWindowManager * android.view.Display#DEFAULT_DISPLAY} and given rotation. */ @UnsupportedAppUsage - void freezeRotation(int rotation); + void freezeRotation(int rotation, String caller); /** * Equivalent to calling {@link #thawDisplayRotation(int)} with {@link * android.view.Display#DEFAULT_DISPLAY}. */ @UnsupportedAppUsage - void thawRotation(); + void thawRotation(String caller); /** * Equivelant to call {@link #isDisplayRotationFrozen(int)} with {@link @@ -341,7 +341,7 @@ interface IWindowManager * {@link android.view.Surface#ROTATION_270} or -1 to freeze it to current rotation. * @hide */ - void freezeDisplayRotation(int displayId, int rotation); + void freezeDisplayRotation(int displayId, int rotation, String caller); /** * Release the orientation lock imposed by freezeRotation() on the display. @@ -349,7 +349,7 @@ interface IWindowManager * @param displayId the ID of display which rotation should be thawed. * @hide */ - void thawDisplayRotation(int displayId); + void thawDisplayRotation(int displayId, String caller); /** * Gets whether the rotation is frozen on the display. diff --git a/core/java/com/android/internal/view/RotationPolicy.java b/core/java/com/android/internal/view/RotationPolicy.java index 058c6ec4d13c..6e45796df053 100644 --- a/core/java/com/android/internal/view/RotationPolicy.java +++ b/core/java/com/android/internal/view/RotationPolicy.java @@ -105,23 +105,23 @@ public final class RotationPolicy { /** * Enables or disables rotation lock from the system UI toggle. */ - public static void setRotationLock(Context context, final boolean enabled) { + public static void setRotationLock(Context context, final boolean enabled, String caller) { final int rotation = areAllRotationsAllowed(context) || useCurrentRotationOnRotationLockChange(context) ? CURRENT_ROTATION : NATURAL_ROTATION; - setRotationLockAtAngle(context, enabled, rotation); + setRotationLockAtAngle(context, enabled, rotation, caller); } /** * Enables or disables rotation lock at a specific rotation from system UI. */ public static void setRotationLockAtAngle(Context context, final boolean enabled, - final int rotation) { + final int rotation, String caller) { Settings.System.putIntForUser(context.getContentResolver(), Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0, UserHandle.USER_CURRENT); - setRotationLock(enabled, rotation); + setRotationLock(enabled, rotation, caller); } /** @@ -129,12 +129,13 @@ public final class RotationPolicy { * * If rotation is locked for accessibility, the system UI toggle is hidden to avoid confusion. */ - public static void setRotationLockForAccessibility(Context context, final boolean enabled) { + public static void setRotationLockForAccessibility(Context context, final boolean enabled, + String caller) { Settings.System.putIntForUser(context.getContentResolver(), Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, enabled ? 1 : 0, UserHandle.USER_CURRENT); - setRotationLock(enabled, NATURAL_ROTATION); + setRotationLock(enabled, NATURAL_ROTATION, caller); } private static boolean areAllRotationsAllowed(Context context) { @@ -146,16 +147,17 @@ public final class RotationPolicy { R.bool.config_useCurrentRotationOnRotationLockChange); } - private static void setRotationLock(final boolean enabled, final int rotation) { + private static void setRotationLock(final boolean enabled, final int rotation, + final String caller) { AsyncTask.execute(new Runnable() { @Override public void run() { try { IWindowManager wm = WindowManagerGlobal.getWindowManagerService(); if (enabled) { - wm.freezeRotation(rotation); + wm.freezeRotation(rotation, caller); } else { - wm.thawRotation(); + wm.thawRotation(caller); } } catch (RemoteException exc) { Log.w(TAG, "Unable to save auto-rotate setting"); diff --git a/data/etc/services.core.protolog.json b/data/etc/services.core.protolog.json index 28a4b49e9d00..417d374150ca 100644 --- a/data/etc/services.core.protolog.json +++ b/data/etc/services.core.protolog.json @@ -1123,12 +1123,6 @@ "group": "WM_SHOW_TRANSACTIONS", "at": "com\/android\/server\/wm\/WindowSurfaceController.java" }, - "-1076978367": { - "message": "thawRotation: mRotation=%d", - "level": "VERBOSE", - "group": "WM_DEBUG_ORIENTATION", - "at": "com\/android\/server\/wm\/WindowManagerService.java" - }, "-1075136930": { "message": "startLockTaskMode: Can't lock due to auth", "level": "WARN", @@ -1231,6 +1225,12 @@ "group": "WM_DEBUG_STARTING_WINDOW", "at": "com\/android\/server\/wm\/WindowState.java" }, + "-962760979": { + "message": "thawRotation: mRotation=%d, caller=%s", + "level": "VERBOSE", + "group": "WM_DEBUG_ORIENTATION", + "at": "com\/android\/server\/wm\/WindowManagerService.java" + }, "-961053385": { "message": "attachWindowContextToDisplayArea: calling from non-existing process pid=%d uid=%d", "level": "WARN", @@ -2785,6 +2785,12 @@ "group": "WM_DEBUG_ORIENTATION", "at": "com\/android\/server\/wm\/WindowManagerService.java" }, + "364992694": { + "message": "freezeDisplayRotation: current rotation=%d, new rotation=%d, caller=%s", + "level": "VERBOSE", + "group": "WM_DEBUG_ORIENTATION", + "at": "com\/android\/server\/wm\/WindowManagerService.java" + }, "371173718": { "message": "finishSync cancel=%b for %s", "level": "VERBOSE", diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/RotationButtonController.java b/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/RotationButtonController.java index 905923039f8b..c0749885846f 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/RotationButtonController.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/RotationButtonController.java @@ -282,9 +282,9 @@ public class RotationButtonController { TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mTaskStackListener); } - public void setRotationLockedAtAngle(int rotationSuggestion) { + public void setRotationLockedAtAngle(int rotationSuggestion, String caller) { RotationPolicy.setRotationLockAtAngle(mContext, /* enabled= */ isRotationLocked(), - /* rotation= */ rotationSuggestion); + /* rotation= */ rotationSuggestion, caller); } public boolean isRotationLocked() { @@ -468,7 +468,8 @@ public class RotationButtonController { if (rotationLocked || mRotationButton.isVisible()) { // Do not allow a change in rotation to set user rotation when docked. if (shouldOverrideUserLockPrefs(rotation) && rotationLocked && !mDocked) { - setRotationLockedAtAngle(rotation); + setRotationLockedAtAngle(rotation, /* caller= */ + "RotationButtonController#onRotationWatcherChanged"); } setRotateSuggestionButtonState(false /* visible */, true /* forced */); } @@ -572,7 +573,8 @@ public class RotationButtonController { private void onRotateSuggestionClick(View v) { mUiEventLogger.log(RotationButtonEvent.ROTATION_SUGGESTION_ACCEPTED); incrementNumAcceptedRotationSuggestionsIfNeeded(); - setRotationLockedAtAngle(mLastRotationSuggestion); + setRotationLockedAtAngle(mLastRotationSuggestion, + /* caller= */ "RotationButtonController#onRotateSuggestionClick"); Log.i(TAG, "onRotateSuggestionClick() mLastRotationSuggestion=" + mLastRotationSuggestion); v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); } diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java index 62b22c50c1dc..f95200b0568d 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java @@ -795,7 +795,8 @@ public class NavigationBar extends ViewController<NavigationBarView> implements // Reset user rotation pref to match that of the WindowManager if starting in locked // mode. This will automatically happen when switching from auto-rotate to locked mode. if (display != null && rotationButtonController.isRotationLocked()) { - rotationButtonController.setRotationLockedAtAngle(display.getRotation()); + rotationButtonController.setRotationLockedAtAngle( + display.getRotation(), /* caller= */ "NavigationBar#onViewAttached"); } } else { mDisabledFlags2 |= StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java index 2d9f7dd038bc..a2fa165f4bc5 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java @@ -133,7 +133,7 @@ public class RotationLockTile extends QSTileImpl<BooleanState> implements @Override protected void handleClick(@Nullable View view) { final boolean newState = !mState.value; - mController.setRotationLocked(!newState); + mController.setRotationLocked(!newState, /* caller= */ "RotationLockTile#handleClick"); refreshState(newState); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingController.java index 01fabcc8bc1e..3008c866d207 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingController.java @@ -159,7 +159,8 @@ public final class DeviceStateRotationLockSettingController // Update the rotation policy, if needed, for this new device state if (shouldBeLocked != isLocked) { - mRotationPolicyWrapper.setRotationLock(shouldBeLocked); + mRotationPolicyWrapper.setRotationLock(shouldBeLocked, + /* caller= */"DeviceStateRotationLockSettingController#readPersistedSetting"); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockController.java index 1158324567ff..607f1e562468 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockController.java @@ -24,8 +24,8 @@ public interface RotationLockController extends Listenable, boolean isRotationLockAffordanceVisible(); boolean isRotationLocked(); boolean isCameraRotationEnabled(); - void setRotationLocked(boolean locked); - void setRotationLockedAtAngle(boolean locked, int rotation); + void setRotationLocked(boolean locked, String caller); + void setRotationLockedAtAngle(boolean locked, int rotation, String caller); public interface RotationLockControllerCallback { void onRotationLockStateChanged(boolean rotationLocked, boolean affordanceVisible); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java index 1eeb0ac8b3bb..797aa1f3a3dd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java @@ -93,12 +93,12 @@ public final class RotationLockControllerImpl implements RotationLockController return mRotationPolicy.isCameraRotationEnabled(); } - public void setRotationLocked(boolean locked) { - mRotationPolicy.setRotationLock(locked); + public void setRotationLocked(boolean locked, String caller) { + mRotationPolicy.setRotationLock(locked, caller); } - public void setRotationLockedAtAngle(boolean locked, int rotation) { - mRotationPolicy.setRotationLockAtAngle(locked, rotation); + public void setRotationLockedAtAngle(boolean locked, int rotation, String caller) { + mRotationPolicy.setRotationLockAtAngle(locked, rotation, caller); } public boolean isRotationLockAffordanceVisible() { diff --git a/packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt b/packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt index d8de07d185c6..374ebe0f28fb 100644 --- a/packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt +++ b/packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt @@ -28,8 +28,8 @@ import javax.inject.Inject * Testable wrapper interface around RotationPolicy {link com.android.internal.view.RotationPolicy} */ interface RotationPolicyWrapper { - fun setRotationLock(enabled: Boolean) - fun setRotationLockAtAngle(enabled: Boolean, rotation: Int) + fun setRotationLock(enabled: Boolean, caller: String) + fun setRotationLockAtAngle(enabled: Boolean, rotation: Int, caller: String) fun getRotationLockOrientation(): Int fun isRotationLockToggleVisible(): Boolean fun isRotationLocked(): Boolean @@ -44,14 +44,14 @@ class RotationPolicyWrapperImpl @Inject constructor( ) : RotationPolicyWrapper { - override fun setRotationLock(enabled: Boolean) { + override fun setRotationLock(enabled: Boolean, caller: String) { traceSection("RotationPolicyWrapperImpl#setRotationLock") { - RotationPolicy.setRotationLock(context, enabled) + RotationPolicy.setRotationLock(context, enabled, caller) } } - override fun setRotationLockAtAngle(enabled: Boolean, rotation: Int) { - RotationPolicy.setRotationLockAtAngle(context, enabled, rotation) + override fun setRotationLockAtAngle(enabled: Boolean, rotation: Int, caller: String) { + RotationPolicy.setRotationLockAtAngle(context, enabled, rotation, caller) } override fun getRotationLockOrientation(): Int = diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingControllerTest.java index c8f28bc17926..4ccbd1b739f3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingControllerTest.java @@ -65,7 +65,7 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase private final FakeSystemClock mFakeSystemClock = new FakeSystemClock(); private final FakeExecutor mFakeExecutor = new FakeExecutor(mFakeSystemClock); - private final RotationPolicyWrapper mFakeRotationPolicy = new FakeRotationPolicy(); + private final FakeRotationPolicy mFakeRotationPolicy = new FakeRotationPolicy(); private DeviceStateRotationLockSettingController mDeviceStateRotationLockSettingController; private DeviceStateManager.DeviceStateCallback mDeviceStateCallback; private DeviceStateRotationLockSettingsManager mSettingsManager; @@ -324,13 +324,21 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase private boolean mRotationLock; - @Override public void setRotationLock(boolean enabled) { - mRotationLock = enabled; + setRotationLock(enabled, /* caller= */ "FakeRotationPolicy"); } @Override + public void setRotationLock(boolean enabled, String caller) { + mRotationLock = enabled; + } + public void setRotationLockAtAngle(boolean enabled, int rotation) { + setRotationLockAtAngle(enabled, rotation, /* caller= */ "FakeRotationPolicy"); + } + + @Override + public void setRotationLockAtAngle(boolean enabled, int rotation, String caller) { mRotationLock = enabled; } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeRotationLockController.java b/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeRotationLockController.java index 4f9cb35db1a3..be57658a4266 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeRotationLockController.java +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeRotationLockController.java @@ -46,7 +46,7 @@ public class FakeRotationLockController extends BaseLeakChecker<RotationLockCont } @Override - public void setRotationLocked(boolean locked) { + public void setRotationLocked(boolean locked, String caller) { } @@ -56,7 +56,7 @@ public class FakeRotationLockController extends BaseLeakChecker<RotationLockCont } @Override - public void setRotationLockedAtAngle(boolean locked, int rotation) { + public void setRotationLockedAtAngle(boolean locked, int rotation, String caller) { } } diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java index d461d1ec02f0..a1b8949c2582 100644 --- a/services/core/java/com/android/server/wm/DisplayRotation.java +++ b/services/core/java/com/android/server/wm/DisplayRotation.java @@ -130,6 +130,7 @@ public class DisplayRotation { private final int mUndockedHdmiRotation; private final RotationAnimationPair mTmpRotationAnim = new RotationAnimationPair(); private final RotationHistory mRotationHistory = new RotationHistory(); + private final RotationLockHistory mRotationLockHistory = new RotationLockHistory(); private OrientationListener mOrientationListener; private StatusBarManagerInternal mStatusBarManagerInternal; @@ -922,7 +923,8 @@ public class DisplayRotation { } @VisibleForTesting - void setUserRotation(int userRotationMode, int userRotation) { + void setUserRotation(int userRotationMode, int userRotation, String caller) { + mRotationLockHistory.addRecord(userRotationMode, userRotation, caller); mRotationChoiceShownToUserForConfirmation = ROTATION_UNDEFINED; if (useDefaultSettingsProvider()) { // We'll be notified via settings listener, so we don't need to update internal values. @@ -953,17 +955,17 @@ public class DisplayRotation { } } - void freezeRotation(int rotation) { + void freezeRotation(int rotation, String caller) { if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis(mDisplayContent)) { rotation = RotationUtils.reverseRotationDirectionAroundZAxis(rotation); } rotation = (rotation == -1) ? mRotation : rotation; - setUserRotation(WindowManagerPolicy.USER_ROTATION_LOCKED, rotation); + setUserRotation(WindowManagerPolicy.USER_ROTATION_LOCKED, rotation, caller); } - void thawRotation() { - setUserRotation(WindowManagerPolicy.USER_ROTATION_FREE, mUserRotation); + void thawRotation(String caller) { + setUserRotation(WindowManagerPolicy.USER_ROTATION_FREE, mUserRotation, caller); } boolean isRotationFrozen() { @@ -1712,6 +1714,15 @@ public class DisplayRotation { r.dump(prefix, pw); } } + + if (!mRotationLockHistory.mRecords.isEmpty()) { + pw.println(); + pw.println(prefix + " RotationLockHistory"); + prefix = " " + prefix; + for (RotationLockHistory.Record r : mRotationLockHistory.mRecords) { + r.dump(prefix, pw); + } + } } void dumpDebug(ProtoOutputStream proto, long fieldId) { @@ -2133,6 +2144,40 @@ public class DisplayRotation { } } + private static class RotationLockHistory { + private static final int MAX_SIZE = 8; + + private static class Record { + @WindowManagerPolicy.UserRotationMode final int mUserRotationMode; + @Surface.Rotation final int mUserRotation; + final String mCaller; + final long mTimestamp = System.currentTimeMillis(); + + private Record(int userRotationMode, int userRotation, String caller) { + mUserRotationMode = userRotationMode; + mUserRotation = userRotation; + mCaller = caller; + } + + void dump(String prefix, PrintWriter pw) { + pw.println(prefix + TimeUtils.logTimeOfDay(mTimestamp) + ": " + + "mode=" + WindowManagerPolicy.userRotationModeToString(mUserRotationMode) + + ", rotation=" + Surface.rotationToString(mUserRotation) + + ", caller=" + mCaller); + } + } + + private final ArrayDeque<RotationLockHistory.Record> mRecords = new ArrayDeque<>(MAX_SIZE); + + void addRecord(@WindowManagerPolicy.UserRotationMode int userRotationMode, + @Surface.Rotation int userRotation, String caller) { + if (mRecords.size() >= MAX_SIZE) { + mRecords.removeFirst(); + } + mRecords.addLast(new Record(userRotationMode, userRotation, caller)); + } + } + private static class RotationHistory { private static final int MAX_SIZE = 8; private static final int NO_FOLD_CONTROLLER = -2; diff --git a/services/core/java/com/android/server/wm/DisplayRotationReversionController.java b/services/core/java/com/android/server/wm/DisplayRotationReversionController.java index d3a8a82f8f87..4eb2d88cb4eb 100644 --- a/services/core/java/com/android/server/wm/DisplayRotationReversionController.java +++ b/services/core/java/com/android/server/wm/DisplayRotationReversionController.java @@ -118,7 +118,8 @@ final class DisplayRotationReversionController { if (mDisplayContent.getDisplayRotation().isRotationFrozen()) { mDisplayContent.getDisplayRotation().setUserRotation( mUserRotationModeOverridden, - mUserRotationOverridden); + mUserRotationOverridden, + /* caller= */ "DisplayRotationReversionController#revertOverride"); return true; } else { return false; diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 8fe104c23312..a084992b850c 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -4281,8 +4281,8 @@ public class WindowManagerService extends IWindowManager.Stub } @Override - public void freezeRotation(int rotation) { - freezeDisplayRotation(Display.DEFAULT_DISPLAY, rotation); + public void freezeRotation(int rotation, String caller) { + freezeDisplayRotation(Display.DEFAULT_DISPLAY, rotation, caller); } /** @@ -4292,7 +4292,7 @@ public class WindowManagerService extends IWindowManager.Stub * @param rotation The desired rotation to freeze to, or -1 to use the current rotation. */ @Override - public void freezeDisplayRotation(int displayId, int rotation) { + public void freezeDisplayRotation(int displayId, int rotation, String caller) { // TODO(multi-display): Track which display is rotated. if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, "freezeRotation()")) { @@ -4302,6 +4302,9 @@ public class WindowManagerService extends IWindowManager.Stub throw new IllegalArgumentException("Rotation argument must be -1 or a valid " + "rotation constant."); } + ProtoLog.v(WM_DEBUG_ORIENTATION, + "freezeDisplayRotation: current rotation=%d, new rotation=%d, caller=%s", + getDefaultDisplayRotation(), rotation, caller); final long origId = Binder.clearCallingIdentity(); try { @@ -4311,7 +4314,7 @@ public class WindowManagerService extends IWindowManager.Stub Slog.w(TAG, "Trying to freeze rotation for a missing display."); return; } - display.getDisplayRotation().freezeRotation(rotation); + display.getDisplayRotation().freezeRotation(rotation, caller); } } finally { Binder.restoreCallingIdentity(origId); @@ -4321,8 +4324,8 @@ public class WindowManagerService extends IWindowManager.Stub } @Override - public void thawRotation() { - thawDisplayRotation(Display.DEFAULT_DISPLAY); + public void thawRotation(String caller) { + thawDisplayRotation(Display.DEFAULT_DISPLAY, caller); } /** @@ -4330,13 +4333,14 @@ public class WindowManagerService extends IWindowManager.Stub * Persists across reboots. */ @Override - public void thawDisplayRotation(int displayId) { + public void thawDisplayRotation(int displayId, String caller) { if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, "thawRotation()")) { throw new SecurityException("Requires SET_ORIENTATION permission"); } - ProtoLog.v(WM_DEBUG_ORIENTATION, "thawRotation: mRotation=%d", getDefaultDisplayRotation()); + ProtoLog.v(WM_DEBUG_ORIENTATION, "thawRotation: mRotation=%d, caller=%s", + getDefaultDisplayRotation(), caller); final long origId = Binder.clearCallingIdentity(); try { @@ -4346,7 +4350,7 @@ public class WindowManagerService extends IWindowManager.Stub Slog.w(TAG, "Trying to thaw rotation for a missing display."); return; } - display.getDisplayRotation().thawRotation(); + display.getDisplayRotation().thawRotation(caller); } } finally { Binder.restoreCallingIdentity(origId); diff --git a/services/core/java/com/android/server/wm/WindowManagerShellCommand.java b/services/core/java/com/android/server/wm/WindowManagerShellCommand.java index 74a0bafd3a4c..8fad9509af44 100644 --- a/services/core/java/com/android/server/wm/WindowManagerShellCommand.java +++ b/services/core/java/com/android/server/wm/WindowManagerShellCommand.java @@ -438,7 +438,8 @@ public class WindowManagerShellCommand extends ShellCommand { } if ("free".equals(lockMode)) { - mInternal.thawDisplayRotation(displayId); + mInternal.thawDisplayRotation(displayId, + /* caller= */ "WindowManagerShellCommand#free"); return 0; } @@ -451,7 +452,8 @@ public class WindowManagerShellCommand extends ShellCommand { try { final int rotation = arg != null ? Integer.parseInt(arg) : -1 /* lock to current rotation */; - mInternal.freezeDisplayRotation(displayId, rotation); + mInternal.freezeDisplayRotation(displayId, rotation, + /* caller= */ "WindowManagerShellCommand#lock"); return 0; } catch (IllegalArgumentException e) { getErrPrintWriter().println("Error: " + e.getMessage()); @@ -1433,7 +1435,8 @@ public class WindowManagerShellCommand extends ShellCommand { mInterface.setForcedDisplayScalingMode(displayId, DisplayContent.FORCE_SCALING_MODE_AUTO); // user-rotation - mInternal.thawDisplayRotation(displayId); + mInternal.thawDisplayRotation(displayId, + /* caller= */ "WindowManagerShellCommand#runReset"); // fixed-to-user-rotation mInterface.setFixedToUserRotation(displayId, IWindowManager.FIXED_TO_USER_ROTATION_DEFAULT); diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java index ae4ebc1223b2..c21c7be757ec 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -1088,7 +1088,7 @@ public class DisplayContentTests extends WindowTestsBase { assertFalse(dc.getRotationReversionController().isAnyOverrideActive()); dc.getDisplayRotation().setUserRotation(WindowManagerPolicy.USER_ROTATION_LOCKED, - ROTATION_90); + ROTATION_90, /* caller= */ "DisplayContentTests"); updateAllDisplayContentAndRotation(dc); assertEquals(ROTATION_90, dc.getDisplayRotation() .rotationForOrientation(SCREEN_ORIENTATION_UNSPECIFIED, ROTATION_90)); @@ -1107,7 +1107,7 @@ public class DisplayContentTests extends WindowTestsBase { assertEquals(ROTATION_90, dc.getDisplayRotation() .rotationForOrientation(SCREEN_ORIENTATION_UNSPECIFIED, ROTATION_0)); dc.getDisplayRotation().setUserRotation(WindowManagerPolicy.USER_ROTATION_FREE, - ROTATION_0); + ROTATION_0, /* caller= */ "DisplayContentTests"); } @Test @@ -1134,7 +1134,8 @@ public class DisplayContentTests extends WindowTestsBase { dc.getDisplayRotation().setFixedToUserRotation( IWindowManager.FIXED_TO_USER_ROTATION_ENABLED); dc.getDisplayRotation().setUserRotation( - WindowManagerPolicy.USER_ROTATION_LOCKED, ROTATION_180); + WindowManagerPolicy.USER_ROTATION_LOCKED, ROTATION_180, + /* caller= */ "DisplayContentTests"); final int newOrientation = getRotatedOrientation(dc); final Task task = new TaskBuilder(mSupervisor) @@ -1174,7 +1175,8 @@ public class DisplayContentTests extends WindowTestsBase { dc.getDisplayRotation().setFixedToUserRotation( IWindowManager.FIXED_TO_USER_ROTATION_ENABLED); dc.getDisplayRotation().setUserRotation( - WindowManagerPolicy.USER_ROTATION_LOCKED, ROTATION_0); + WindowManagerPolicy.USER_ROTATION_LOCKED, ROTATION_0, + /* caller= */ "DisplayContentTests"); dc.getDefaultTaskDisplayArea().setWindowingMode(WINDOWING_MODE_FULLSCREEN); final int newOrientation = getRotatedOrientation(dc); diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java index 915b387ddb75..e14568d281c0 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java @@ -1265,7 +1265,7 @@ public class DisplayRotationTests { } private void freezeRotation(int rotation) { - mTarget.freezeRotation(rotation); + mTarget.freezeRotation(rotation, /* caller= */ "DisplayRotationTests"); if (mTarget.isDefaultDisplay) { mAccelerometerRotationObserver.onChange(false); @@ -1274,7 +1274,7 @@ public class DisplayRotationTests { } private void thawRotation() { - mTarget.thawRotation(); + mTarget.thawRotation(/* caller= */ "DisplayRotationTests"); if (mTarget.isDefaultDisplay) { mAccelerometerRotationObserver.onChange(false); diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java index fb27d6368a7e..0c580697bc4a 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java @@ -610,7 +610,7 @@ public class TaskTests extends WindowTestsBase { // display. final DisplayRotation dr = display.mDisplayContent.getDisplayRotation(); dr.setFixedToUserRotation(FIXED_TO_USER_ROTATION_ENABLED); - dr.setUserRotation(USER_ROTATION_FREE, ROTATION_0); + dr.setUserRotation(USER_ROTATION_FREE, ROTATION_0, /* caller= */ "TaskTests"); final Task rootTask = new TaskBuilder(mSupervisor).setCreateActivity(true) .setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build(); @@ -642,7 +642,7 @@ public class TaskTests extends WindowTestsBase { // Setting app to fixed landscape and changing display top.setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE); // Fix the display orientation to portrait which is 90 degrees for the test display. - dr.setUserRotation(USER_ROTATION_FREE, ROTATION_90); + dr.setUserRotation(USER_ROTATION_FREE, ROTATION_90, /* caller= */ "TaskTests"); // Fixed orientation request should be resolved on activity level. Task fills display // bounds. @@ -681,7 +681,7 @@ public class TaskTests extends WindowTestsBase { // display. final DisplayRotation dr = display.mDisplayContent.getDisplayRotation(); dr.setFixedToUserRotation(FIXED_TO_USER_ROTATION_ENABLED); - dr.setUserRotation(USER_ROTATION_FREE, ROTATION_0); + dr.setUserRotation(USER_ROTATION_FREE, ROTATION_0, /* caller= */ "TaskTests"); final Task rootTask = new TaskBuilder(mSupervisor).setCreateActivity(true) .setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build(); diff --git a/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java b/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java index 06cbeb5368a5..330bc84d7a76 100644 --- a/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java +++ b/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java @@ -124,7 +124,7 @@ public class WindowManagerPermissionTests extends TestCase { @SmallTest public void testSET_ORIENTATION() { try { - mWm.freezeRotation(-1); + mWm.freezeRotation(/* rotation= */ -1, /* caller= */ "WindowManagerPermissionTests"); fail("IWindowManager.freezeRotation did not throw SecurityException as" + " expected"); } catch (SecurityException e) { @@ -134,7 +134,7 @@ public class WindowManagerPermissionTests extends TestCase { } try { - mWm.thawRotation(); + mWm.thawRotation(/* called= */ "WindowManagerPermissionTests"); fail("IWindowManager.thawRotation did not throw SecurityException as" + " expected"); } catch (SecurityException e) { |