summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/IWallpaperManager.aidl14
-rw-r--r--core/java/android/service/wallpaper/IWallpaperEngine.aidl2
-rw-r--r--core/java/android/service/wallpaper/WallpaperService.java47
-rw-r--r--data/etc/services.core.protolog.json30
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java4
-rw-r--r--packages/SystemUI/src/com/android/systemui/flags/Flags.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java15
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java12
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinator.kt62
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt33
-rw-r--r--services/core/java/com/android/server/am/ProcessStateRecord.java2
-rw-r--r--services/core/java/com/android/server/policy/PhoneWindowManager.java29
-rw-r--r--services/core/java/com/android/server/wallpaper/WallpaperManagerInternal.java6
-rw-r--r--services/core/java/com/android/server/wallpaper/WallpaperManagerService.java57
-rw-r--r--services/core/java/com/android/server/wm/ActivityRecord.java2
-rw-r--r--services/core/java/com/android/server/wm/DisplayContent.java12
-rw-r--r--services/core/java/com/android/server/wm/DisplayRotation.java62
-rw-r--r--services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java34
-rw-r--r--services/core/java/com/android/server/wm/DisplayRotationReversionController.java148
-rw-r--r--services/core/java/com/android/server/wm/WindowManagerService.java5
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java6
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java46
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java17
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java44
24 files changed, 663 insertions, 28 deletions
diff --git a/core/java/android/app/IWallpaperManager.aidl b/core/java/android/app/IWallpaperManager.aidl
index 28c273ec50a6..f6056bd39005 100644
--- a/core/java/android/app/IWallpaperManager.aidl
+++ b/core/java/android/app/IWallpaperManager.aidl
@@ -206,6 +206,20 @@ interface IWallpaperManager {
void notifyGoingToSleep(int x, int y, in Bundle extras);
/**
+ * Called when the screen has been fully turned on and is visible.
+ *
+ * @hide
+ */
+ void notifyScreenTurnedOn(int displayId);
+
+ /**
+ * Called when the screen starts turning on.
+ *
+ * @hide
+ */
+ void notifyScreenTurningOn(int displayId);
+
+ /**
* Sets the wallpaper dim amount between [0f, 1f] which would be blended with the system default
* dimming. 0f doesn't add any additional dimming and 1f makes the wallpaper fully black.
*
diff --git a/core/java/android/service/wallpaper/IWallpaperEngine.aidl b/core/java/android/service/wallpaper/IWallpaperEngine.aidl
index 1a00acf475e3..15a8502a2e7f 100644
--- a/core/java/android/service/wallpaper/IWallpaperEngine.aidl
+++ b/core/java/android/service/wallpaper/IWallpaperEngine.aidl
@@ -32,6 +32,8 @@ interface IWallpaperEngine {
oneway void setDisplayPadding(in Rect padding);
@UnsupportedAppUsage
oneway void setVisibility(boolean visible);
+ oneway void onScreenTurningOn();
+ oneway void onScreenTurnedOn();
oneway void setInAmbientMode(boolean inAmbientDisplay, long animationDuration);
@UnsupportedAppUsage
oneway void dispatchPointer(in MotionEvent event);
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java
index 2887d1f85d21..8f1fc1b9348e 100644
--- a/core/java/android/service/wallpaper/WallpaperService.java
+++ b/core/java/android/service/wallpaper/WallpaperService.java
@@ -168,6 +168,7 @@ public abstract class WallpaperService extends Service {
private static final int MSG_ZOOM = 10100;
private static final int MSG_RESIZE_PREVIEW = 10110;
private static final int MSG_REPORT_SHOWN = 10150;
+ private static final int MSG_UPDATE_SCREEN_TURNING_ON = 10170;
private static final int MSG_UPDATE_DIMMING = 10200;
/** limit calls to {@link Engine#onComputeColors} to at most once per second */
@@ -213,6 +214,16 @@ public abstract class WallpaperService extends Service {
boolean mInitializing = true;
boolean mVisible;
+ /**
+ * Whether the screen is turning on.
+ * After the display is powered on, brightness is initially off. It is turned on only after
+ * all windows have been drawn, and sysui notifies that it's ready (See
+ * {@link com.android.internal.policy.IKeyguardDrawnCallback}).
+ * As some wallpapers use visibility as a signal to start animations, this makes sure
+ * {@link Engine#onVisibilityChanged} is invoked only when the display is both on and
+ * visible (with brightness on).
+ */
+ private boolean mIsScreenTurningOn;
boolean mReportedVisible;
boolean mDestroyed;
// Set to true after receiving WallpaperManager#COMMAND_FREEZE. It's reset back to false
@@ -988,6 +999,7 @@ public abstract class WallpaperService extends Service {
out.print(" mDestroyed="); out.println(mDestroyed);
out.print(prefix); out.print("mVisible="); out.print(mVisible);
out.print(" mReportedVisible="); out.println(mReportedVisible);
+ out.print(" mIsScreenTurningOn="); out.println(mIsScreenTurningOn);
out.print(prefix); out.print("mDisplay="); out.println(mDisplay);
out.print(prefix); out.print("mCreated="); out.print(mCreated);
out.print(" mSurfaceCreated="); out.print(mSurfaceCreated);
@@ -1522,6 +1534,13 @@ public abstract class WallpaperService extends Service {
}
}
+ void onScreenTurningOnChanged(boolean isScreenTurningOn) {
+ if (!mDestroyed) {
+ mIsScreenTurningOn = isScreenTurningOn;
+ reportVisibility();
+ }
+ }
+
void doVisibilityChanged(boolean visible) {
if (!mDestroyed) {
mVisible = visible;
@@ -1538,9 +1557,10 @@ public abstract class WallpaperService extends Service {
return;
}
if (!mDestroyed) {
- mDisplayState = mDisplay == null ? Display.STATE_UNKNOWN :
- mDisplay.getCommittedState();
- boolean visible = mVisible && mDisplayState != Display.STATE_OFF;
+ mDisplayState =
+ mDisplay == null ? Display.STATE_UNKNOWN : mDisplay.getCommittedState();
+ boolean displayVisible = Display.isOnState(mDisplayState) && !mIsScreenTurningOn;
+ boolean visible = mVisible && displayVisible;
if (mReportedVisible != visible) {
mReportedVisible = visible;
if (DEBUG) Log.v(TAG, "onVisibilityChanged(" + visible
@@ -2414,6 +2434,20 @@ public abstract class WallpaperService extends Service {
}
}
+ public void updateScreenTurningOn(boolean isScreenTurningOn) {
+ Message msg = mCaller.obtainMessageBO(MSG_UPDATE_SCREEN_TURNING_ON, isScreenTurningOn,
+ null);
+ mCaller.sendMessage(msg);
+ }
+
+ public void onScreenTurningOn() throws RemoteException {
+ updateScreenTurningOn(true);
+ }
+
+ public void onScreenTurnedOn() throws RemoteException {
+ updateScreenTurningOn(false);
+ }
+
@Override
public void executeMessage(Message message) {
if (mDetached.get()) {
@@ -2464,6 +2498,13 @@ public abstract class WallpaperService extends Service {
+ ": " + message.arg1);
mEngine.doVisibilityChanged(message.arg1 != 0);
break;
+ case MSG_UPDATE_SCREEN_TURNING_ON:
+ if (DEBUG) {
+ Log.v(TAG,
+ message.arg1 != 0 ? "Screen turning on" : "Screen turned on");
+ }
+ mEngine.onScreenTurningOnChanged(/* isScreenTurningOn= */ message.arg1 != 0);
+ break;
case MSG_WALLPAPER_OFFSETS: {
mEngine.doOffsetsChanged(true);
} break;
diff --git a/data/etc/services.core.protolog.json b/data/etc/services.core.protolog.json
index 3d7fb16bb846..334a7275ebe2 100644
--- a/data/etc/services.core.protolog.json
+++ b/data/etc/services.core.protolog.json
@@ -469,6 +469,18 @@
"group": "WM_DEBUG_TASKS",
"at": "com\/android\/server\/wm\/RecentTasks.java"
},
+ "-1643780158": {
+ "message": "Saving original orientation before camera compat, last orientation is %d",
+ "level": "VERBOSE",
+ "group": "WM_DEBUG_ORIENTATION",
+ "at": "com\/android\/server\/wm\/DisplayRotationCompatPolicy.java"
+ },
+ "-1639406696": {
+ "message": "NOSENSOR override detected",
+ "level": "VERBOSE",
+ "group": "WM_DEBUG_ORIENTATION",
+ "at": "com\/android\/server\/wm\/DisplayRotationReversionController.java"
+ },
"-1638958146": {
"message": "Removing activity %s from task=%s adding to task=%s Callers=%s",
"level": "INFO",
@@ -751,6 +763,12 @@
"group": "WM_DEBUG_IME",
"at": "com\/android\/server\/wm\/ImeInsetsSourceProvider.java"
},
+ "-1397175017": {
+ "message": "Other orientation overrides are in place: not reverting",
+ "level": "VERBOSE",
+ "group": "WM_DEBUG_ORIENTATION",
+ "at": "com\/android\/server\/wm\/DisplayRotationReversionController.java"
+ },
"-1394745488": {
"message": "ControlAdapter onAnimationCancelled mSource: %s mControlTarget: %s",
"level": "INFO",
@@ -1669,6 +1687,12 @@
"group": "WM_DEBUG_WINDOW_TRANSITIONS",
"at": "com\/android\/server\/wm\/Transition.java"
},
+ "-529187878": {
+ "message": "Reverting orientation after camera compat force rotation",
+ "level": "VERBOSE",
+ "group": "WM_DEBUG_ORIENTATION",
+ "at": "com\/android\/server\/wm\/DisplayRotationCompatPolicy.java"
+ },
"-521613870": {
"message": "App died during pause, not stopping: %s",
"level": "VERBOSE",
@@ -2365,6 +2389,12 @@
"group": "WM_DEBUG_FOCUS_LIGHT",
"at": "com\/android\/server\/wm\/WindowManagerService.java"
},
+ "138097009": {
+ "message": "NOSENSOR override is absent: reverting",
+ "level": "VERBOSE",
+ "group": "WM_DEBUG_ORIENTATION",
+ "at": "com\/android\/server\/wm\/DisplayRotationReversionController.java"
+ },
"140319294": {
"message": "IME target changed within ActivityRecord",
"level": "DEBUG",
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java
index f159f54aa825..77939c7c6964 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java
@@ -716,6 +716,10 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
if (options1 == null) options1 = new Bundle();
if (taskId2 == INVALID_TASK_ID) {
// Launching a solo task.
+ // Exit split first if this task under split roots.
+ if (mMainStage.containsTask(taskId1) || mSideStage.containsTask(taskId1)) {
+ exitSplitScreen(null /* childrenToTop */, EXIT_REASON_RECREATE_SPLIT);
+ }
ActivityOptions activityOptions = ActivityOptions.fromBundle(options1);
activityOptions.update(ActivityOptions.makeRemoteAnimation(adapter));
options1 = activityOptions.toBundle();
diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
index 46d6e84d8ef3..b4a30583f492 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
@@ -68,7 +68,7 @@ object Flags {
@JvmField val DISABLE_FSI = unreleasedFlag(265804648, "disable_fsi")
// TODO(b/254512538): Tracking Bug
- val INSTANT_VOICE_REPLY = releasedFlag(111, "instant_voice_reply")
+ val INSTANT_VOICE_REPLY = unreleasedFlag(111, "instant_voice_reply")
// TODO(b/254512425): Tracking Bug
val NOTIFICATION_MEMORY_MONITOR_ENABLED =
diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
index 4ba0e5e16c72..db0ff4bd5c8a 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
@@ -16,6 +16,7 @@
package com.android.systemui.recents;
+import static android.content.Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST;
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
@@ -389,6 +390,16 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
private final BroadcastReceiver mLauncherStateChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
+ StringBuilder extraComponentList = new StringBuilder(" components: ");
+ if (intent.hasExtra(EXTRA_CHANGED_COMPONENT_NAME_LIST)) {
+ String[] comps = intent.getStringArrayExtra(EXTRA_CHANGED_COMPONENT_NAME_LIST);
+ if (comps != null) {
+ for (String c : comps) {
+ extraComponentList.append(c).append(", ");
+ }
+ }
+ }
+ Log.d(TAG_OPS, "launcherStateChanged intent: " + intent + extraComponentList);
updateEnabledState();
// Reconnect immediately, instead of waiting for resume to arrive.
@@ -399,9 +410,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
private final ServiceConnection mOverviewServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
- if (SysUiState.DEBUG) {
- Log.d(TAG_OPS, "Overview proxy service connected");
- }
+ Log.d(TAG_OPS, "Overview proxy service connected");
mConnectionBackoffAttempts = 0;
mHandler.removeCallbacks(mDeferredConnectionCallback);
try {
diff --git a/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java b/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java
index 2efc23b87da4..19d83340dc28 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java
+++ b/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java
@@ -17,6 +17,8 @@
package com.android.systemui.shade;
+import static android.view.WindowInsets.Type.ime;
+
import static com.android.internal.jank.InteractionJankMonitor.CUJ_NOTIFICATION_SHADE_QS_EXPAND_COLLAPSE;
import static com.android.systemui.classifier.Classifier.QS_COLLAPSE;
import static com.android.systemui.shade.NotificationPanelViewController.COUNTER_PANEL_OPEN_QS;
@@ -450,9 +452,17 @@ public class QuickSettingsController {
return (mQs != null ? mQs.getHeader().getHeight() : 0) + mPeekHeight;
}
+ private boolean isRemoteInputActiveWithKeyboardUp() {
+ //TODO(b/227115380) remove the isVisible(ime()) check once isRemoteInputActive is fixed.
+ // The check for keyboard visibility is a temporary workaround that allows QS to expand
+ // even when isRemoteInputActive is mistakenly returning true.
+ return mRemoteInputManager.isRemoteInputActive()
+ && mPanelView.getRootWindowInsets().isVisible(ime());
+ }
+
public boolean isExpansionEnabled() {
return mExpansionEnabledPolicy && mExpansionEnabledAmbient
- && !mRemoteInputManager.isRemoteInputActive();
+ && !isRemoteInputActiveWithKeyboardUp();
}
public float getTransitioningToFullShadeProgress() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinator.kt
index 82bd45ce2279..6322edf5a1b4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinator.kt
@@ -24,6 +24,10 @@ import androidx.annotation.VisibleForTesting
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyguard.data.repository.KeyguardRepository
+import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
+import com.android.systemui.keyguard.shared.model.KeyguardState
+import com.android.systemui.keyguard.shared.model.TransitionState
+import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.expansionChanges
@@ -40,22 +44,26 @@ import com.android.systemui.statusbar.policy.HeadsUpManager
import com.android.systemui.statusbar.policy.headsUpEvents
import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
-import javax.inject.Inject
-import kotlin.time.Duration
-import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.conflate
+import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.transformLatest
import kotlinx.coroutines.launch
+import kotlinx.coroutines.yield
+import javax.inject.Inject
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.seconds
/**
* Filters low priority and privacy-sensitive notifications from the lockscreen, and hides section
@@ -69,6 +77,7 @@ constructor(
private val headsUpManager: HeadsUpManager,
private val keyguardNotificationVisibilityProvider: KeyguardNotificationVisibilityProvider,
private val keyguardRepository: KeyguardRepository,
+ private val keyguardTransitionRepository: KeyguardTransitionRepository,
private val notifPipelineFlags: NotifPipelineFlags,
@Application private val scope: CoroutineScope,
private val sectionHeaderVisibilityProvider: SectionHeaderVisibilityProvider,
@@ -99,21 +108,46 @@ constructor(
}
private suspend fun trackUnseenNotificationsWhileUnlocked() {
+ // Whether or not we're actively tracking unseen notifications to mark them as seen when
+ // appropriate.
+ val isTrackingUnseen: Flow<Boolean> =
+ keyguardRepository.isKeyguardShowing
+ // transformLatest so that we can cancel listening to keyguard transitions once
+ // isKeyguardShowing changes (after a successful transition to the keyguard).
+ .transformLatest { isShowing ->
+ if (isShowing) {
+ // If the keyguard is showing, we're not tracking unseen.
+ emit(false)
+ } else {
+ // If the keyguard stops showing, then start tracking unseen notifications.
+ emit(true)
+ // If the screen is turning off, stop tracking, but if that transition is
+ // cancelled, then start again.
+ emitAll(
+ keyguardTransitionRepository.transitions
+ .map { step -> !step.isScreenTurningOff }
+ )
+ }
+ }
+ // Prevent double emit of `false` caused by transition to AOD, followed by keyguard
+ // showing
+ .distinctUntilChanged()
+
// Use collectLatest so that trackUnseenNotifications() is cancelled when the keyguard is
// showing again
- var clearUnseenOnUnlock = false
- keyguardRepository.isKeyguardShowing.collectLatest { isKeyguardShowing ->
- if (isKeyguardShowing) {
+ var clearUnseenOnBeginTracking = false
+ isTrackingUnseen.collectLatest { trackingUnseen ->
+ if (!trackingUnseen) {
// Wait for the user to spend enough time on the lock screen before clearing unseen
// set when unlocked
awaitTimeSpentNotDozing(SEEN_TIMEOUT)
- clearUnseenOnUnlock = true
+ clearUnseenOnBeginTracking = true
} else {
- unseenNotifFilter.invalidateList("keyguard no longer showing")
- if (clearUnseenOnUnlock) {
- clearUnseenOnUnlock = false
+ if (clearUnseenOnBeginTracking) {
+ clearUnseenOnBeginTracking = false
unseenNotifications.clear()
}
+ unseenNotifFilter.invalidateList("keyguard no longer showing")
trackUnseenNotifications()
}
}
@@ -142,7 +176,10 @@ constructor(
}
private suspend fun clearUnseenNotificationsWhenShadeIsExpanded() {
- statusBarStateController.expansionChanges.collect { isExpanded ->
+ statusBarStateController.expansionChanges.collectLatest { isExpanded ->
+ // Give keyguard events time to propagate, in case this expansion is part of the
+ // keyguard transition and not the user expanding the shade
+ yield()
if (isExpanded) {
unseenNotifications.clear()
}
@@ -276,3 +313,6 @@ constructor(
private val SEEN_TIMEOUT = 5.seconds
}
}
+
+private val TransitionStep.isScreenTurningOff: Boolean get() =
+ transitionState == TransitionState.STARTED && to != KeyguardState.GONE \ No newline at end of file
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt
index 8109e24a1e52..c2a2a40b7e5d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt
@@ -25,6 +25,10 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.advanceTimeBy
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
+import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
+import com.android.systemui.keyguard.shared.model.KeyguardState
+import com.android.systemui.keyguard.shared.model.TransitionState
+import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.notification.NotifPipelineFlags
@@ -69,6 +73,7 @@ class KeyguardCoordinatorTest : SysuiTestCase() {
private val headsUpManager: HeadsUpManager = mock()
private val keyguardNotifVisibilityProvider: KeyguardNotificationVisibilityProvider = mock()
private val keyguardRepository = FakeKeyguardRepository()
+ private val keyguardTransitionRepository = FakeKeyguardTransitionRepository()
private val notifPipelineFlags: NotifPipelineFlags = mock()
private val notifPipeline: NotifPipeline = mock()
private val sectionHeaderVisibilityProvider: SectionHeaderVisibilityProvider = mock()
@@ -118,6 +123,33 @@ class KeyguardCoordinatorTest : SysuiTestCase() {
}
@Test
+ fun unseenFilterStopsMarkingSeenNotifWhenTransitionToAod() {
+ whenever(notifPipelineFlags.shouldFilterUnseenNotifsOnKeyguard).thenReturn(true)
+
+ // GIVEN: Keyguard is not showing, shade is not expanded, and a notification is present
+ keyguardRepository.setKeyguardShowing(false)
+ whenever(statusBarStateController.isExpanded).thenReturn(false)
+ runKeyguardCoordinatorTest {
+ val fakeEntry = NotificationEntryBuilder().build()
+ collectionListener.onEntryAdded(fakeEntry)
+
+ // WHEN: The device transitions to AOD
+ keyguardTransitionRepository.sendTransitionStep(
+ TransitionStep(to = KeyguardState.AOD, transitionState = TransitionState.STARTED),
+ )
+ testScheduler.runCurrent()
+
+ // WHEN: The shade is expanded
+ whenever(statusBarStateController.isExpanded).thenReturn(true)
+ statusBarStateListener.onExpandedChanged(true)
+ testScheduler.runCurrent()
+
+ // THEN: The notification is still treated as "unseen" and is not filtered out.
+ assertThat(unseenFilter.shouldFilterOut(fakeEntry, 0L)).isFalse()
+ }
+ }
+
+ @Test
fun unseenFilter_headsUpMarkedAsSeen() {
whenever(notifPipelineFlags.shouldFilterUnseenNotifsOnKeyguard).thenReturn(true)
@@ -373,6 +405,7 @@ class KeyguardCoordinatorTest : SysuiTestCase() {
headsUpManager,
keyguardNotifVisibilityProvider,
keyguardRepository,
+ keyguardTransitionRepository,
notifPipelineFlags,
testScope.backgroundScope,
sectionHeaderVisibilityProvider,
diff --git a/services/core/java/com/android/server/am/ProcessStateRecord.java b/services/core/java/com/android/server/am/ProcessStateRecord.java
index eb1fd3aa49be..5a0e8e3e6549 100644
--- a/services/core/java/com/android/server/am/ProcessStateRecord.java
+++ b/services/core/java/com/android/server/am/ProcessStateRecord.java
@@ -618,7 +618,7 @@ final class ProcessStateRecord {
void forceProcessStateUpTo(int newState) {
if (mRepProcState > newState) {
synchronized (mProcLock) {
- mRepProcState = newState;
+ setReportedProcState(newState);
setCurProcState(newState);
setCurRawProcState(newState);
mApp.getPkgList().forEachPackage((pkgName, holder) ->
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index be4fe09d593c..f064f83393c0 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -212,6 +212,7 @@ import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.vr.VrManagerInternal;
+import com.android.server.wallpaper.WallpaperManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.DisplayPolicy;
import com.android.server.wm.DisplayRotation;
@@ -398,6 +399,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
AudioManagerInternal mAudioManagerInternal;
DisplayManager mDisplayManager;
DisplayManagerInternal mDisplayManagerInternal;
+
+ private WallpaperManagerInternal mWallpaperManagerInternal;
+
boolean mPreloadedRecentApps;
final Object mServiceAcquireLock = new Object();
Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
@@ -4776,11 +4780,34 @@ public class PhoneWindowManager implements WindowManagerPolicy {
return bootCompleted ? mKeyguardDrawnTimeout : 5000;
}
+ @Nullable
+ private WallpaperManagerInternal getWallpaperManagerInternal() {
+ if (mWallpaperManagerInternal == null) {
+ mWallpaperManagerInternal = LocalServices.getService(WallpaperManagerInternal.class);
+ }
+ return mWallpaperManagerInternal;
+ }
+
+ private void reportScreenTurningOnToWallpaper(int displayId) {
+ WallpaperManagerInternal wallpaperManagerInternal = getWallpaperManagerInternal();
+ if (wallpaperManagerInternal != null) {
+ wallpaperManagerInternal.onScreenTurningOn(displayId);
+ }
+ }
+
+ private void reportScreenTurnedOnToWallpaper(int displayId) {
+ WallpaperManagerInternal wallpaperManagerInternal = getWallpaperManagerInternal();
+ if (wallpaperManagerInternal != null) {
+ wallpaperManagerInternal.onScreenTurnedOn(displayId);
+ }
+ }
+
// Called on the DisplayManager's DisplayPowerController thread.
@Override
public void screenTurningOn(int displayId, final ScreenOnListener screenOnListener) {
if (DEBUG_WAKEUP) Slog.i(TAG, "Display " + displayId + " turning on...");
+ reportScreenTurningOnToWallpaper(displayId);
if (displayId == DEFAULT_DISPLAY) {
Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenTurningOn",
0 /* cookie */);
@@ -4821,6 +4848,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
public void screenTurnedOn(int displayId) {
if (DEBUG_WAKEUP) Slog.i(TAG, "Display " + displayId + " turned on...");
+ reportScreenTurnedOnToWallpaper(displayId);
+
if (displayId != DEFAULT_DISPLAY) {
return;
}
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerInternal.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerInternal.java
index 584fbddee478..3699557706fd 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerInternal.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerInternal.java
@@ -27,4 +27,10 @@ public abstract class WallpaperManagerInternal {
* Notifies the display is ready for adding wallpaper on it.
*/
public abstract void onDisplayReady(int displayId);
+
+ /** Notifies when the screen finished turning on and is visible to the user. */
+ public abstract void onScreenTurnedOn(int displayId);
+
+ /** Notifies when the screen starts turning on and is not yet visible to the user. */
+ public abstract void onScreenTurningOn(int displayId);
}
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index 79a4acf55fef..1574ff554fb1 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -1762,6 +1762,15 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
public void onDisplayReady(int displayId) {
onDisplayReadyInternal(displayId);
}
+
+ @Override
+ public void onScreenTurnedOn(int displayId) {
+ notifyScreenTurnedOn(displayId);
+ }
+ @Override
+ public void onScreenTurningOn(int displayId) {
+ notifyScreenTurningOn(displayId);
+ }
}
void initialize() {
@@ -2575,6 +2584,54 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}
}
+ /**
+ * Propagates screen turned on event to wallpaper engine.
+ */
+ @Override
+ public void notifyScreenTurnedOn(int displayId) {
+ synchronized (mLock) {
+ final WallpaperData data = mWallpaperMap.get(mCurrentUserId);
+ if (data != null
+ && data.connection != null
+ && data.connection.containsDisplay(displayId)) {
+ final IWallpaperEngine engine = data.connection
+ .getDisplayConnectorOrCreate(displayId).mEngine;
+ if (engine != null) {
+ try {
+ engine.onScreenTurnedOn();
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+
+
+ /**
+ * Propagate screen turning on event to wallpaper engine.
+ */
+ @Override
+ public void notifyScreenTurningOn(int displayId) {
+ synchronized (mLock) {
+ final WallpaperData data = mWallpaperMap.get(mCurrentUserId);
+ if (data != null
+ && data.connection != null
+ && data.connection.containsDisplay(displayId)) {
+ final IWallpaperEngine engine = data.connection
+ .getDisplayConnectorOrCreate(displayId).mEngine;
+ if (engine != null) {
+ try {
+ engine.onScreenTurningOn();
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
@Override
public boolean setLockWallpaperCallback(IWallpaperManagerCallback cb) {
checkPermission(android.Manifest.permission.INTERNAL_SYSTEM_WINDOW);
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 2f7673a309a2..d872ada1fd0c 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -7867,6 +7867,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
mAtmService.getTaskChangeNotificationController().notifyActivityRequestedOrientationChanged(
task.mTaskId, requestedOrientation);
+
+ mDisplayContent.getDisplayRotation().onSetRequestedOrientation();
}
/*
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index 99b0645df6ac..8934ff9a3100 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -746,6 +746,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
*/
DisplayWindowPolicyControllerHelper mDwpcHelper;
+ private final DisplayRotationReversionController mRotationReversionController;
+
private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
WindowStateAnimator winAnimator = w.mWinAnimator;
final ActivityRecord activity = w.mActivityRecord;
@@ -1170,6 +1172,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
mWmService.mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
/* checkDeviceConfig */ false)
? new DisplayRotationCompatPolicy(this) : null;
+ mRotationReversionController = new DisplayRotationReversionController(this);
mInputMonitor = new InputMonitor(mWmService, this);
mInsetsPolicy = new InsetsPolicy(mInsetsStateController, this);
@@ -1283,6 +1286,10 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
.show(mOverlayLayer);
}
+ DisplayRotationReversionController getRotationReversionController() {
+ return mRotationReversionController;
+ }
+
boolean isReady() {
// The display is ready when the system and the individual display are both ready.
return mWmService.mDisplayReady && mDisplayReady;
@@ -1665,9 +1672,14 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
}
private boolean updateOrientation(boolean forceUpdate) {
+ final WindowContainer prevOrientationSource = mLastOrientationSource;
final int orientation = getOrientation();
// The last orientation source is valid only after getOrientation.
final WindowContainer orientationSource = getLastOrientationSource();
+ if (orientationSource != prevOrientationSource
+ && mRotationReversionController.isRotationReversionEnabled()) {
+ mRotationReversionController.updateForNoSensorOverride();
+ }
final ActivityRecord r =
orientationSource != null ? orientationSource.asActivityRecord() : null;
if (r != null) {
diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java
index 30791d3a3cd5..0a1e29ace045 100644
--- a/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -34,6 +34,9 @@ import static com.android.server.wm.DisplayRotationProto.IS_FIXED_TO_USER_ROTATI
import static com.android.server.wm.DisplayRotationProto.LAST_ORIENTATION;
import static com.android.server.wm.DisplayRotationProto.ROTATION;
import static com.android.server.wm.DisplayRotationProto.USER_ROTATION;
+import static com.android.server.wm.DisplayRotationReversionController.REVERSION_TYPE_CAMERA_COMPAT;
+import static com.android.server.wm.DisplayRotationReversionController.REVERSION_TYPE_HALF_FOLD;
+import static com.android.server.wm.DisplayRotationReversionController.REVERSION_TYPE_NOSENSOR;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
@@ -97,6 +100,8 @@ public class DisplayRotation {
// config changes and unexpected jumps while folding the device to closed state.
private static final int FOLDING_RECOMPUTE_CONFIG_DELAY_MS = 800;
+ private static final int ROTATION_UNDEFINED = -1;
+
private static class RotationAnimationPair {
@AnimRes
int mEnter;
@@ -104,6 +109,9 @@ public class DisplayRotation {
int mExit;
}
+ @Nullable
+ final FoldController mFoldController;
+
private final WindowManagerService mService;
private final DisplayContent mDisplayContent;
private final DisplayPolicy mDisplayPolicy;
@@ -125,8 +133,6 @@ public class DisplayRotation {
private OrientationListener mOrientationListener;
private StatusBarManagerInternal mStatusBarManagerInternal;
private SettingsObserver mSettingsObserver;
- @Nullable
- private FoldController mFoldController;
@NonNull
private final DeviceStateController mDeviceStateController;
@@ -184,6 +190,12 @@ public class DisplayRotation {
*/
private int mShowRotationSuggestions;
+ /**
+ * The most recent {@link Surface.Rotation} choice shown to the user for confirmation, or
+ * {@link #ROTATION_UNDEFINED}
+ */
+ private int mRotationChoiceShownToUserForConfirmation = ROTATION_UNDEFINED;
+
private static final int ALLOW_ALL_ROTATIONS_UNDEFINED = -1;
private static final int ALLOW_ALL_ROTATIONS_DISABLED = 0;
private static final int ALLOW_ALL_ROTATIONS_ENABLED = 1;
@@ -271,7 +283,11 @@ public class DisplayRotation {
if (mSupportAutoRotation && mContext.getResources().getBoolean(
R.bool.config_windowManagerHalfFoldAutoRotateOverride)) {
mFoldController = new FoldController();
+ } else {
+ mFoldController = null;
}
+ } else {
+ mFoldController = null;
}
}
@@ -329,6 +345,11 @@ public class DisplayRotation {
return -1;
}
+ @VisibleForTesting
+ boolean useDefaultSettingsProvider() {
+ return isDefaultDisplay;
+ }
+
/**
* Updates the configuration which may have different values depending on current user, e.g.
* runtime resource overlay.
@@ -861,7 +882,8 @@ public class DisplayRotation {
@VisibleForTesting
void setUserRotation(int userRotationMode, int userRotation) {
- if (isDefaultDisplay) {
+ mRotationChoiceShownToUserForConfirmation = ROTATION_UNDEFINED;
+ if (useDefaultSettingsProvider()) {
// We'll be notified via settings listener, so we don't need to update internal values.
final ContentResolver res = mContext.getContentResolver();
final int accelerometerRotation =
@@ -1568,6 +1590,17 @@ public class DisplayRotation {
return shouldUpdateRotation;
}
+ /**
+ * Called from {@link ActivityRecord#setRequestedOrientation(int)}
+ */
+ void onSetRequestedOrientation() {
+ if (mCompatPolicyForImmersiveApps == null
+ || mRotationChoiceShownToUserForConfirmation == ROTATION_UNDEFINED) {
+ return;
+ }
+ mOrientationListener.onProposedRotationChanged(mRotationChoiceShownToUserForConfirmation);
+ }
+
void dump(String prefix, PrintWriter pw) {
pw.println(prefix + "DisplayRotation");
pw.println(prefix + " mCurrentAppOrientation="
@@ -1794,7 +1827,7 @@ public class DisplayRotation {
return false;
}
if (mDeviceState == DeviceStateController.DeviceState.HALF_FOLDED) {
- return !(isTabletop ^ mTabletopRotations.contains(mRotation));
+ return isTabletop == mTabletopRotations.contains(mRotation);
}
return true;
}
@@ -1818,14 +1851,17 @@ public class DisplayRotation {
return mDeviceState == DeviceStateController.DeviceState.OPEN
&& !mShouldIgnoreSensorRotation // Ignore if the hinge angle still moving
&& mInHalfFoldTransition
- && mHalfFoldSavedRotation != -1 // Ignore if we've already reverted.
+ && mDisplayContent.getRotationReversionController().isOverrideActive(
+ REVERSION_TYPE_HALF_FOLD)
&& mUserRotationMode
- == WindowManagerPolicy.USER_ROTATION_LOCKED; // Ignore if we're unlocked.
+ == WindowManagerPolicy.USER_ROTATION_LOCKED; // Ignore if we're unlocked.
}
int revertOverriddenRotation() {
int savedRotation = mHalfFoldSavedRotation;
mHalfFoldSavedRotation = -1;
+ mDisplayContent.getRotationReversionController()
+ .revertOverride(REVERSION_TYPE_HALF_FOLD);
mInHalfFoldTransition = false;
return savedRotation;
}
@@ -1845,6 +1881,8 @@ public class DisplayRotation {
&& mDeviceState != DeviceStateController.DeviceState.HALF_FOLDED) {
// The device has transitioned to HALF_FOLDED state: save the current rotation and
// update the device rotation.
+ mDisplayContent.getRotationReversionController().beforeOverrideApplied(
+ REVERSION_TYPE_HALF_FOLD);
mHalfFoldSavedRotation = mRotation;
mDeviceState = newState;
// Now mFoldState is set to HALF_FOLDED, the overrideFrozenRotation function will
@@ -1966,9 +2004,11 @@ public class DisplayRotation {
// Send interaction power boost to improve redraw performance.
mService.mPowerManagerInternal.setPowerBoost(Boost.INTERACTION, 0);
if (isRotationChoiceAllowed(rotation)) {
+ mRotationChoiceShownToUserForConfirmation = rotation;
final boolean isValid = isValidRotationChoice(rotation);
sendProposedRotationChangeToStatusBarInternal(rotation, isValid);
} else {
+ mRotationChoiceShownToUserForConfirmation = ROTATION_UNDEFINED;
mService.updateRotation(false /* alwaysSendConfiguration */,
false /* forceRelayout */);
}
@@ -2047,6 +2087,8 @@ public class DisplayRotation {
final int mHalfFoldSavedRotation;
final boolean mInHalfFoldTransition;
final DeviceStateController.DeviceState mDeviceState;
+ @Nullable final boolean[] mRotationReversionSlots;
+
@Nullable final String mDisplayRotationCompatPolicySummary;
Record(DisplayRotation dr, int fromRotation, int toRotation) {
@@ -2087,6 +2129,8 @@ public class DisplayRotation {
? null
: dc.mDisplayRotationCompatPolicy
.getSummaryForDisplayRotationHistoryRecord();
+ mRotationReversionSlots =
+ dr.mDisplayContent.getRotationReversionController().getSlotsCopy();
}
void dump(String prefix, PrintWriter pw) {
@@ -2112,6 +2156,12 @@ public class DisplayRotation {
if (mDisplayRotationCompatPolicySummary != null) {
pw.println(prefix + mDisplayRotationCompatPolicySummary);
}
+ if (mRotationReversionSlots != null) {
+ pw.println(prefix + " reversionSlots= NOSENSOR "
+ + mRotationReversionSlots[REVERSION_TYPE_NOSENSOR] + ", CAMERA "
+ + mRotationReversionSlots[REVERSION_TYPE_CAMERA_COMPAT] + " HALF_FOLD "
+ + mRotationReversionSlots[REVERSION_TYPE_HALF_FOLD]);
+ }
}
}
diff --git a/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java b/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java
index fb72d6c6b56d..ae93a9496f7c 100644
--- a/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java
@@ -33,6 +33,7 @@ import static android.view.Display.TYPE_INTERNAL;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ORIENTATION;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_STATES;
+import static com.android.server.wm.DisplayRotationReversionController.REVERSION_TYPE_CAMERA_COMPAT;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -156,6 +157,11 @@ final class DisplayRotationCompatPolicy {
@ScreenOrientation
int getOrientation() {
mLastReportedOrientation = getOrientationInternal();
+ if (mLastReportedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
+ rememberOverriddenOrientationIfNeeded();
+ } else {
+ restoreOverriddenOrientationIfNeeded();
+ }
return mLastReportedOrientation;
}
@@ -277,6 +283,34 @@ final class DisplayRotationCompatPolicy {
+ " }";
}
+ private void restoreOverriddenOrientationIfNeeded() {
+ if (!isOrientationOverridden()) {
+ return;
+ }
+ if (mDisplayContent.getRotationReversionController().revertOverride(
+ REVERSION_TYPE_CAMERA_COMPAT)) {
+ ProtoLog.v(WM_DEBUG_ORIENTATION,
+ "Reverting orientation after camera compat force rotation");
+ // Reset last orientation source since we have reverted the orientation.
+ mDisplayContent.mLastOrientationSource = null;
+ }
+ }
+
+ private boolean isOrientationOverridden() {
+ return mDisplayContent.getRotationReversionController().isOverrideActive(
+ REVERSION_TYPE_CAMERA_COMPAT);
+ }
+
+ private void rememberOverriddenOrientationIfNeeded() {
+ if (!isOrientationOverridden()) {
+ mDisplayContent.getRotationReversionController().beforeOverrideApplied(
+ REVERSION_TYPE_CAMERA_COMPAT);
+ ProtoLog.v(WM_DEBUG_ORIENTATION,
+ "Saving original orientation before camera compat, last orientation is %d",
+ mDisplayContent.getLastOrientation());
+ }
+ }
+
// Refreshing only when configuration changes after rotation.
private boolean shouldRefreshActivity(ActivityRecord activity, Configuration newConfig,
Configuration lastReportedConfig) {
diff --git a/services/core/java/com/android/server/wm/DisplayRotationReversionController.java b/services/core/java/com/android/server/wm/DisplayRotationReversionController.java
new file mode 100644
index 000000000000..d3a8a82f8f87
--- /dev/null
+++ b/services/core/java/com/android/server/wm/DisplayRotationReversionController.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wm;
+
+import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
+
+import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ORIENTATION;
+
+import android.annotation.Nullable;
+import android.app.WindowConfiguration;
+import android.content.ActivityInfoProto;
+import android.view.Surface;
+
+import com.android.internal.protolog.common.ProtoLog;
+import com.android.server.policy.WindowManagerPolicy;
+
+/**
+ * Defines the behavior of reversion from device rotation overrides.
+ *
+ * <p>There are 3 override types:
+ * <ol>
+ * <li>The top application has {@link SCREEN_ORIENTATION_NOSENSOR} set and is rotated to
+ * {@link ROTATION_0}.
+ * <li>Camera compat treatment has rotated the app {@link DisplayRotationCompatPolicy}.
+ * <li>The device is half-folded and has auto-rotate is temporarily enabled.
+ * </ol>
+ *
+ * <p>Before an override is enabled, a component should call {@code beforeOverrideApplied}. When
+ * it wishes to revert, it should call {@code revertOverride}. The user rotation will be restored
+ * if there are no other overrides present.
+ */
+final class DisplayRotationReversionController {
+
+ static final int REVERSION_TYPE_NOSENSOR = 0;
+ static final int REVERSION_TYPE_CAMERA_COMPAT = 1;
+ static final int REVERSION_TYPE_HALF_FOLD = 2;
+ private static final int NUM_SLOTS = 3;
+
+ @Surface.Rotation
+ private int mUserRotationOverridden = WindowConfiguration.ROTATION_UNDEFINED;
+ @WindowManagerPolicy.UserRotationMode
+ private int mUserRotationModeOverridden;
+
+ private final boolean[] mSlots = new boolean[NUM_SLOTS];
+ private final DisplayContent mDisplayContent;
+
+ DisplayRotationReversionController(DisplayContent content) {
+ mDisplayContent = content;
+ }
+
+ boolean isRotationReversionEnabled() {
+ return mDisplayContent.mDisplayRotationCompatPolicy != null
+ || mDisplayContent.getDisplayRotation().mFoldController != null
+ || mDisplayContent.getIgnoreOrientationRequest();
+ }
+
+ void beforeOverrideApplied(int slotIndex) {
+ if (mSlots[slotIndex]) return;
+ maybeSaveUserRotation();
+ mSlots[slotIndex] = true;
+ }
+
+ boolean isOverrideActive(int slotIndex) {
+ return mSlots[slotIndex];
+ }
+
+ @Nullable
+ boolean[] getSlotsCopy() {
+ return isRotationReversionEnabled() ? mSlots.clone() : null;
+ }
+
+ void updateForNoSensorOverride() {
+ if (!mSlots[REVERSION_TYPE_NOSENSOR]) {
+ if (isTopFullscreenActivityNoSensor()) {
+ ProtoLog.v(WM_DEBUG_ORIENTATION, "NOSENSOR override detected");
+ beforeOverrideApplied(REVERSION_TYPE_NOSENSOR);
+ }
+ } else {
+ if (!isTopFullscreenActivityNoSensor()) {
+ ProtoLog.v(WM_DEBUG_ORIENTATION, "NOSENSOR override is absent: reverting");
+ revertOverride(REVERSION_TYPE_NOSENSOR);
+ }
+ }
+ }
+
+ boolean isAnyOverrideActive() {
+ for (int i = 0; i < NUM_SLOTS; ++i) {
+ if (mSlots[i]) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ boolean revertOverride(int slotIndex) {
+ if (!mSlots[slotIndex]) return false;
+ mSlots[slotIndex] = false;
+ if (isAnyOverrideActive()) {
+ ProtoLog.v(WM_DEBUG_ORIENTATION,
+ "Other orientation overrides are in place: not reverting");
+ return false;
+ }
+ // Only override if the rotation is frozen and there are no other active slots.
+ if (mDisplayContent.getDisplayRotation().isRotationFrozen()) {
+ mDisplayContent.getDisplayRotation().setUserRotation(
+ mUserRotationModeOverridden,
+ mUserRotationOverridden);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private void maybeSaveUserRotation() {
+ if (!isAnyOverrideActive()) {
+ mUserRotationModeOverridden =
+ mDisplayContent.getDisplayRotation().getUserRotationMode();
+ mUserRotationOverridden = mDisplayContent.getDisplayRotation().getUserRotation();
+ }
+ }
+
+ private boolean isTopFullscreenActivityNoSensor() {
+ final Task topFullscreenTask =
+ mDisplayContent.getTask(
+ t -> t.getWindowingMode() == WINDOWING_MODE_FULLSCREEN);
+ if (topFullscreenTask != null) {
+ final ActivityRecord topActivity =
+ topFullscreenTask.topRunningActivity();
+ return topActivity != null && topActivity.getOrientation()
+ == ActivityInfoProto.SCREEN_ORIENTATION_NOSENSOR;
+ }
+ 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 8f1702c1b0fa..78ed43658dd5 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -913,6 +913,11 @@ public class WindowManagerService extends IWindowManager.Stub
mMaximumObscuringOpacityForTouch = Settings.Global.getFloat(resolver,
Settings.Global.MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH,
InputManager.DEFAULT_MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH);
+ if (mMaximumObscuringOpacityForTouch < 0.0f
+ || mMaximumObscuringOpacityForTouch > 1.0f) {
+ mMaximumObscuringOpacityForTouch =
+ InputManager.DEFAULT_MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH;
+ }
}
void updateSystemUiSettings(boolean handleChange) {
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
index 2cc752cd1b1a..c91822279e7c 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
@@ -588,12 +588,18 @@ public class ActivityRecordTests extends WindowTestsBase {
throw new IllegalStateException("Orientation in new config should be either"
+ "landscape or portrait.");
}
+
+ final DisplayRotation displayRotation = activity.mDisplayContent.getDisplayRotation();
+ spyOn(displayRotation);
+
activity.setRequestedOrientation(requestedOrientation);
final ActivityConfigurationChangeItem expected =
ActivityConfigurationChangeItem.obtain(newConfig);
verify(mAtm.getLifecycleManager()).scheduleTransaction(eq(activity.app.getThread()),
eq(activity.token), eq(expected));
+
+ verify(displayRotation).onSetRequestedOrientation();
}
@Test
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 dc12469960ff..4d7f37c97a4a 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
@@ -24,6 +24,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.content.pm.ActivityInfo.FLAG_SHOW_WHEN_LOCKED;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
@@ -1061,6 +1062,51 @@ public class DisplayContentTests extends WindowTestsBase {
assertEquals(SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation());
}
+ private void updateAllDisplayContentAndRotation(DisplayContent dc) {
+ // NB updateOrientation will not revert the user orientation until a settings change
+ // takes effect.
+ dc.updateOrientation();
+ dc.onDisplayChanged(dc);
+ dc.mWmService.updateRotation(true /* alwaysSendConfiguration */,
+ false /* forceRelayout */);
+ waitUntilHandlersIdle();
+ }
+
+ @Test
+ public void testNoSensorRevert() {
+ final DisplayContent dc = mDisplayContent;
+ spyOn(dc);
+ doReturn(true).when(dc).getIgnoreOrientationRequest();
+ final DisplayRotation dr = dc.getDisplayRotation();
+ spyOn(dr);
+ doReturn(false).when(dr).useDefaultSettingsProvider();
+ final ActivityRecord app = new ActivityBuilder(mAtm).setCreateTask(true).build();
+ app.setOrientation(SCREEN_ORIENTATION_LANDSCAPE, app);
+
+ assertFalse(dc.getRotationReversionController().isAnyOverrideActive());
+ dc.getDisplayRotation().setUserRotation(WindowManagerPolicy.USER_ROTATION_LOCKED,
+ ROTATION_90);
+ updateAllDisplayContentAndRotation(dc);
+ assertEquals(ROTATION_90, dc.getDisplayRotation()
+ .rotationForOrientation(SCREEN_ORIENTATION_UNSPECIFIED, ROTATION_90));
+
+ app.setOrientation(SCREEN_ORIENTATION_NOSENSOR);
+ updateAllDisplayContentAndRotation(dc);
+ assertTrue(dc.getRotationReversionController().isAnyOverrideActive());
+ assertEquals(ROTATION_0, dc.getRotation());
+
+ app.setOrientation(SCREEN_ORIENTATION_UNSPECIFIED);
+ updateAllDisplayContentAndRotation(dc);
+ assertFalse(dc.getRotationReversionController().isAnyOverrideActive());
+ assertEquals(WindowManagerPolicy.USER_ROTATION_LOCKED,
+ dc.getDisplayRotation().getUserRotationMode());
+ assertEquals(ROTATION_90, dc.getDisplayRotation().getUserRotation());
+ assertEquals(ROTATION_90, dc.getDisplayRotation()
+ .rotationForOrientation(SCREEN_ORIENTATION_UNSPECIFIED, ROTATION_0));
+ dc.getDisplayRotation().setUserRotation(WindowManagerPolicy.USER_ROTATION_FREE,
+ ROTATION_0);
+ }
+
@Test
public void testOnDescendantOrientationRequestChanged() {
final DisplayContent dc = createNewDisplay();
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java
index c2b3783b7311..a3117269eb01 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java
@@ -365,6 +365,23 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase {
}
@Test
+ public void testCameraDisconnected_revertRotationAndRefresh() throws Exception {
+ configureActivityAndDisplay(SCREEN_ORIENTATION_PORTRAIT, ORIENTATION_LANDSCAPE);
+ // Open camera and test for compat treatment
+ mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1);
+ callOnActivityConfigurationChanging(mActivity, /* isDisplayRotationChanging */ true);
+ assertEquals(mDisplayRotationCompatPolicy.getOrientation(),
+ SCREEN_ORIENTATION_LANDSCAPE);
+ assertActivityRefreshRequested(/* refreshRequested */ true);
+ // Close camera and test for revert
+ mCameraAvailabilityCallback.onCameraClosed(CAMERA_ID_1);
+ callOnActivityConfigurationChanging(mActivity, /* isDisplayRotationChanging */ true);
+ assertEquals(mDisplayRotationCompatPolicy.getOrientation(),
+ SCREEN_ORIENTATION_UNSPECIFIED);
+ assertActivityRefreshRequested(/* refreshRequested */ true);
+ }
+
+ @Test
public void testGetOrientation_cameraConnectionClosed_returnUnspecified() {
configureActivity(SCREEN_ORIENTATION_PORTRAIT);
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 890e55b36194..950e9e4848b0 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java
@@ -68,6 +68,7 @@ import android.view.DisplayAddress;
import android.view.Surface;
import android.view.WindowManager;
+import androidx.annotation.Nullable;
import androidx.test.filters.SmallTest;
import com.android.internal.util.test.FakeSettingsProvider;
@@ -111,6 +112,7 @@ public class DisplayRotationTests {
private static WindowManagerService sMockWm;
private DisplayContent mMockDisplayContent;
+ private DisplayRotationReversionController mMockDisplayRotationReversionController;
private DisplayPolicy mMockDisplayPolicy;
private DisplayAddress mMockDisplayAddress;
private Context mMockContext;
@@ -137,6 +139,8 @@ public class DisplayRotationTests {
private DeviceStateController mDeviceStateController;
private DisplayRotation mTarget;
+ @Nullable
+ private DisplayRotationImmersiveAppCompatPolicy mDisplayRotationImmersiveAppCompatPolicyMock;
@BeforeClass
public static void setUpOnce() {
@@ -161,7 +165,7 @@ public class DisplayRotationTests {
LocalServices.removeServiceForTest(StatusBarManagerInternal.class);
mMockStatusBarManagerInternal = mock(StatusBarManagerInternal.class);
LocalServices.addService(StatusBarManagerInternal.class, mMockStatusBarManagerInternal);
-
+ mDisplayRotationImmersiveAppCompatPolicyMock = null;
mBuilder = new DisplayRotationBuilder();
}
@@ -574,6 +578,38 @@ public class DisplayRotationTests {
}
@Test
+ public void testNotifiesChoiceWhenSensorUpdates_immersiveApp() throws Exception {
+ mDisplayRotationImmersiveAppCompatPolicyMock = mock(
+ DisplayRotationImmersiveAppCompatPolicy.class);
+ when(mDisplayRotationImmersiveAppCompatPolicyMock.isRotationLockEnforced(
+ Surface.ROTATION_90)).thenReturn(true);
+
+ mBuilder.build();
+ configureDisplayRotation(SCREEN_ORIENTATION_PORTRAIT, false, false);
+
+ thawRotation();
+
+ enableOrientationSensor();
+
+ mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_90));
+ assertTrue(waitForUiHandler());
+
+ verify(mMockStatusBarManagerInternal).onProposedRotationChanged(Surface.ROTATION_90, true);
+
+ // An imaginary ActivityRecord.setRequestedOrientation call disables immersive mode:
+ when(mDisplayRotationImmersiveAppCompatPolicyMock.isRotationLockEnforced(
+ Surface.ROTATION_90)).thenReturn(false);
+
+ // And then ActivityRecord.setRequestedOrientation calls onSetRequestedOrientation.
+ mTarget.onSetRequestedOrientation();
+
+ // onSetRequestedOrientation should lead to a second call to
+ // mOrientationListener.onProposedRotationChanged
+ // but now, instead of notifying mMockStatusBarManagerInternal, it calls updateRotation:
+ verify(sMockWm).updateRotation(false, false);
+ }
+
+ @Test
public void testAllowAllRotations_allowsUpsideDownSuggestion()
throws Exception {
mBuilder.build();
@@ -1332,6 +1368,10 @@ public class DisplayRotationTests {
when(mMockContext.getResources().getBoolean(
com.android.internal.R.bool.config_windowManagerHalfFoldAutoRotateOverride))
.thenReturn(mSupportHalfFoldAutoRotateOverride);
+ mMockDisplayRotationReversionController =
+ mock(DisplayRotationReversionController.class);
+ when(mMockDisplayContent.getRotationReversionController())
+ .thenReturn(mMockDisplayRotationReversionController);
mMockResolver = mock(ContentResolver.class);
when(mMockContext.getContentResolver()).thenReturn(mMockResolver);
@@ -1354,7 +1394,7 @@ public class DisplayRotationTests {
@Override
DisplayRotationImmersiveAppCompatPolicy initImmersiveAppCompatPolicy(
WindowManagerService service, DisplayContent displayContent) {
- return null;
+ return mDisplayRotationImmersiveAppCompatPolicyMock;
}
@Override