diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-09 04:05:42 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-09 04:05:42 +0000 |
commit | 38d28e21c9469cba4004be68f69d9acbe1671037 (patch) | |
tree | 08083a871ca4f47f179747b128bacd99cc28a399 | |
parent | 34c9c6cdd72f374cac39a6c15f73faf87d655033 (diff) | |
parent | f223bd540eab28e3b249a26709bf976ebf24c338 (diff) | |
download | base-38d28e21c9469cba4004be68f69d9acbe1671037.tar.gz |
Merge cherrypicks of ['googleplex-android-review.googlesource.com/22246438', 'googleplex-android-review.googlesource.com/22935398', 'googleplex-android-review.googlesource.com/22860951', 'googleplex-android-review.googlesource.com/23053887'] into tm-qpr3-c-release.
Change-Id: I2ee77938260909bb96453c636fff8a8ea0f9bf57
11 files changed, 141 insertions, 18 deletions
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 8f1fc1b9348e..d0e8fbc7ab47 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -112,6 +112,7 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; /** @@ -433,6 +434,7 @@ public abstract class WallpaperService extends Service { Message msg = mCaller.obtainMessageIO(MSG_WINDOW_RESIZED, reportDraw ? 1 : 0, mergedConfiguration); + mIWallpaperEngine.mPendingResizeCount.incrementAndGet(); mCaller.sendMessage(msg); } @@ -1021,6 +1023,10 @@ public abstract class WallpaperService extends Service { out.print(prefix); out.print("mZoom="); out.println(mZoom); out.print(prefix); out.print("mPreviewSurfacePosition="); out.println(mPreviewSurfacePosition); + final int pendingCount = mIWallpaperEngine.mPendingResizeCount.get(); + if (pendingCount != 0) { + out.print(prefix); out.print("mPendingResizeCount="); out.println(pendingCount); + } synchronized (mLock) { out.print(prefix); out.print("mPendingXOffset="); out.print(mPendingXOffset); out.print(" mPendingXOffset="); out.println(mPendingXOffset); @@ -1083,10 +1089,6 @@ public abstract class WallpaperService extends Service { } } - private void updateConfiguration(MergedConfiguration mergedConfiguration) { - mMergedConfiguration.setTo(mergedConfiguration); - } - void updateSurface(boolean forceRelayout, boolean forceReport, boolean redrawNeeded) { if (mDestroyed) { Log.w(TAG, "Ignoring updateSurface due to destroyed"); @@ -1135,7 +1137,7 @@ public abstract class WallpaperService extends Service { | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; final Configuration config = mMergedConfiguration.getMergedConfiguration(); - final Rect maxBounds = config.windowConfiguration.getMaxBounds(); + final Rect maxBounds = new Rect(config.windowConfiguration.getMaxBounds()); if (myWidth == ViewGroup.LayoutParams.MATCH_PARENT && myHeight == ViewGroup.LayoutParams.MATCH_PARENT) { mLayout.width = myWidth; @@ -1195,6 +1197,17 @@ public abstract class WallpaperService extends Service { final int relayoutResult = mSession.relayout(mWindow, mLayout, mWidth, mHeight, View.VISIBLE, 0, 0, 0, mWinFrames, mMergedConfiguration, mSurfaceControl, mInsetsState, mTempControls, mSyncSeqIdBundle); + final Rect outMaxBounds = mMergedConfiguration.getMergedConfiguration() + .windowConfiguration.getMaxBounds(); + if (!outMaxBounds.equals(maxBounds)) { + Log.i(TAG, "Retry updateSurface because bounds changed from relayout: " + + maxBounds + " -> " + outMaxBounds); + mSurfaceHolder.mSurfaceLock.unlock(); + mDrawingAllowed = false; + mCaller.sendMessage(mCaller.obtainMessageI(MSG_WINDOW_RESIZED, + redrawNeeded ? 1 : 0)); + return; + } final int transformHint = SurfaceControl.rotationToBufferTransform( (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); @@ -1461,6 +1474,8 @@ public abstract class WallpaperService extends Service { mPreviousWallpaperDimAmount = mWallpaperDimAmount; mDisplayState = mDisplay.getCommittedState(); mDisplayInstallOrientation = mDisplay.getInstallOrientation(); + mMergedConfiguration.setOverrideConfiguration( + mDisplayContext.getResources().getConfiguration()); if (DEBUG) Log.v(TAG, "onCreate(): " + this); Trace.beginSection("WPMS.Engine.onCreate"); @@ -2262,6 +2277,8 @@ public abstract class WallpaperService extends Service { final IBinder mWindowToken; final int mWindowType; final boolean mIsPreview; + final AtomicInteger mPendingResizeCount = new AtomicInteger(); + boolean mReportDraw; boolean mShownReported; int mReqWidth; int mReqHeight; @@ -2513,11 +2530,7 @@ public abstract class WallpaperService extends Service { mEngine.doCommand(cmd); } break; case MSG_WINDOW_RESIZED: { - final boolean reportDraw = message.arg1 != 0; - mEngine.updateConfiguration(((MergedConfiguration) message.obj)); - mEngine.updateSurface(true, false, reportDraw); - mEngine.doOffsetsChanged(true); - mEngine.scaleAndCropScreenshot(); + handleResized((MergedConfiguration) message.obj, message.arg1 != 0); } break; case MSG_WINDOW_MOVED: { // Do nothing. What does it mean for a Wallpaper to move? @@ -2562,6 +2575,40 @@ public abstract class WallpaperService extends Service { Log.w(TAG, "Unknown message type " + message.what); } } + + /** + * In general this performs relayout for IWindow#resized. If there are several pending + * (in the message queue) MSG_WINDOW_RESIZED from server side, only the last one will be + * handled (ignore intermediate states). Note that this procedure cannot be skipped if the + * configuration is not changed because this is also used to dispatch insets changes. + */ + private void handleResized(MergedConfiguration config, boolean reportDraw) { + // The config can be null when retrying for a changed config from relayout, otherwise + // it is from IWindow#resized which always sends non-null config. + final int pendingCount = config != null ? mPendingResizeCount.decrementAndGet() : -1; + if (reportDraw) { + mReportDraw = true; + } + if (pendingCount > 0) { + if (DEBUG) { + Log.d(TAG, "Skip outdated resize, bounds=" + + config.getMergedConfiguration().windowConfiguration.getMaxBounds() + + " pendingCount=" + pendingCount); + } + return; + } + if (config != null) { + if (DEBUG) { + Log.d(TAG, "Update config from resized, bounds=" + + config.getMergedConfiguration().windowConfiguration.getMaxBounds()); + } + mEngine.mMergedConfiguration.setTo(config); + } + mEngine.updateSurface(true /* forceRelayout */, false /* forceReport */, mReportDraw); + mReportDraw = false; + mEngine.doOffsetsChanged(true); + mEngine.scaleAndCropScreenshot(); + } } /** diff --git a/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java b/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java index 19d83340dc28..69ef15d625a4 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java @@ -83,6 +83,7 @@ import com.android.systemui.statusbar.phone.ScrimController; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.StatusBarTouchableRegionManager; import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent; +import com.android.systemui.statusbar.policy.CastController; import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.LargeScreenUtils; @@ -127,6 +128,7 @@ public class QuickSettingsController { private final FalsingCollector mFalsingCollector; private final LockscreenGestureLogger mLockscreenGestureLogger; private final ShadeLogger mShadeLog; + private final CastController mCastController; private final FeatureFlags mFeatureFlags; private final InteractionJankMonitor mInteractionJankMonitor; private final FalsingManager mFalsingManager; @@ -306,7 +308,8 @@ public class QuickSettingsController { MetricsLogger metricsLogger, FeatureFlags featureFlags, InteractionJankMonitor interactionJankMonitor, - ShadeLogger shadeLog + ShadeLogger shadeLog, + CastController castController ) { mPanelViewControllerLazy = panelViewControllerLazy; mPanelView = panelView; @@ -345,6 +348,7 @@ public class QuickSettingsController { mLockscreenGestureLogger = lockscreenGestureLogger; mMetricsLogger = metricsLogger; mShadeLog = shadeLog; + mCastController = castController; mFeatureFlags = featureFlags; mInteractionJankMonitor = interactionJankMonitor; @@ -1132,7 +1136,9 @@ public class QuickSettingsController { mLastClipBounds.set(left, top, right, bottom); if (mIsFullWidth) { clipStatusView = qsVisible; - float screenCornerRadius = mRecordingController.isRecording() ? 0 : mScreenCornerRadius; + float screenCornerRadius = + mRecordingController.isRecording() || mCastController.hasConnectedCastDevice() + ? 0 : mScreenCornerRadius; radius = (int) MathUtils.lerp(screenCornerRadius, mScrimCornerRadius, Math.min(top / (float) mScrimCornerRadius, 1f)); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastController.java index 98cde2a049da..abedd3220c93 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastController.java @@ -28,6 +28,11 @@ public interface CastController extends CallbackController<Callback>, Dumpable { void startCasting(CastDevice device); void stopCasting(CastDevice device); + /** + * @return whether we have a connected device. + */ + boolean hasConnectedCastDevice(); + public interface Callback { void onCastDevicesChanged(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerImpl.java index 7290a1a82070..f7b601b9d284 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerImpl.java @@ -217,6 +217,12 @@ public class CastControllerImpl implements CastController { } } + @Override + public boolean hasConnectedCastDevice() { + return getCastDevices().stream().anyMatch( + castDevice -> castDevice.state == CastDevice.STATE_CONNECTED); + } + private void setProjection(MediaProjectionInfo projection, boolean started) { boolean changed = false; final MediaProjectionInfo oldProjection = mProjection; diff --git a/packages/SystemUI/src/com/android/systemui/unfold/FoldAodAnimationController.kt b/packages/SystemUI/src/com/android/systemui/unfold/FoldAodAnimationController.kt index 641cc45e01d8..29f67188d59d 100644 --- a/packages/SystemUI/src/com/android/systemui/unfold/FoldAodAnimationController.kt +++ b/packages/SystemUI/src/com/android/systemui/unfold/FoldAodAnimationController.kt @@ -150,10 +150,6 @@ constructor( pendingScrimReadyCallback = onReady } } else if (isFolded && !isFoldHandled && alwaysOnEnabled && isDozing) { - // Screen turning on for the first time after folding and we are already dozing - // We should play the folding to AOD animation - isFoldHandled = true - setAnimationState(playing = true) centralSurfaces.notificationPanelViewController.prepareFoldToAodAnimation() @@ -169,6 +165,13 @@ constructor( // No animation, call ready callback immediately onReady.run() } + + if (isFolded) { + // Any time the screen turns on, this state needs to be reset if the device has been + // folded. Reaching this line implies AOD has been shown in one way or another, + // if enabled + isFoldHandled = true + } } /** Called when keyguard scrim opaque changed */ diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java index 7087c0135998..f297c8f493d8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java @@ -151,6 +151,7 @@ import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.StatusBarTouchableRegionManager; import com.android.systemui.statusbar.phone.TapAgainViewController; import com.android.systemui.statusbar.phone.UnlockedScreenOffAnimationController; +import com.android.systemui.statusbar.policy.CastController; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.KeyguardQsUserSwitchController; import com.android.systemui.statusbar.policy.KeyguardStateController; @@ -293,6 +294,7 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase { @Captor protected ArgumentCaptor<NotificationStackScrollLayout.OnEmptySpaceClickListener> mEmptySpaceClickListenerCaptor; + @Mock private CastController mCastController; protected KeyguardBottomAreaInteractor mKeyguardBottomAreaInteractor; protected KeyguardInteractor mKeyguardInteractor; @@ -639,7 +641,8 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase { mMetricsLogger, mFeatureFlags, mInteractionJankMonitor, - mShadeLog + mShadeLog, + mCastController ); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerTest.java index d8ffe39e427d..d013b0a502db 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerTest.java @@ -85,6 +85,7 @@ import com.android.systemui.statusbar.phone.LockscreenGestureLogger; import com.android.systemui.statusbar.phone.ScrimController; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.StatusBarTouchableRegionManager; +import com.android.systemui.statusbar.policy.CastController; import com.android.systemui.statusbar.policy.KeyguardStateController; import org.junit.After; @@ -153,6 +154,7 @@ public class QuickSettingsControllerTest extends SysuiTestCase { @Mock private ShadeLogger mShadeLogger; @Mock private DumpManager mDumpManager; @Mock private UiEventLogger mUiEventLogger; + @Mock private CastController mCastController; private SysuiStatusBarStateController mStatusBarStateController; @@ -239,7 +241,8 @@ public class QuickSettingsControllerTest extends SysuiTestCase { mMetricsLogger, mFeatureFlags, mInteractionJankMonitor, - mShadeLogger + mShadeLogger, + mCastController ); mFragmentListener = mQsController.getQsFragmentListener(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastControllerImplTest.java index db50163ce6a7..b8e4306a319d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastControllerImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastControllerImplTest.java @@ -1,6 +1,7 @@ package com.android.systemui.statusbar.policy; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -125,4 +126,20 @@ public class CastControllerImplTest extends SysuiTestCase { fail("Concurrent modification exception"); } } + + @Test + public void hasConnectedCastDevice_connected() { + CastController.CastDevice castDevice = new CastController.CastDevice(); + castDevice.state = CastController.CastDevice.STATE_CONNECTED; + mController.startCasting(castDevice); + assertTrue(mController.hasConnectedCastDevice()); + } + + @Test + public void hasConnectedCastDevice_notConnected() { + CastController.CastDevice castDevice = new CastController.CastDevice(); + castDevice.state = CastController.CastDevice.STATE_CONNECTING; + mController.startCasting(castDevice); + assertTrue(mController.hasConnectedCastDevice()); + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt index 7f64867d3868..f788229ddcfd 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt @@ -198,6 +198,31 @@ class FoldAodAnimationControllerTest : SysuiTestCase() { } @Test + fun onFolded_onScreenTurningOnWithoutDozingThenWithDozing_doesNotLogLatency() = + runBlocking(IMMEDIATE) { + val job = underTest.listenForDozing(this) + keyguardRepository.setDozing(false) + setAodEnabled(enabled = true) + + yield() + + fold() + simulateScreenTurningOn() + reset(latencyTracker) + + // Now enable dozing and trigger a second run through the aod animation code. It should + // not rerun the animation + keyguardRepository.setDozing(true) + yield() + simulateScreenTurningOn() + + verify(latencyTracker, never()).onActionStart(any()) + verify(latencyTracker, never()).onActionEnd(any()) + + job.cancel() + } + + @Test fun onFolded_animationCancelled_doesNotLogLatency() = runBlocking(IMMEDIATE) { val job = underTest.listenForDozing(this) diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeCastController.java b/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeCastController.java index f6b24da9b821..84ace7cc9540 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeCastController.java +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeCastController.java @@ -51,4 +51,9 @@ public class FakeCastController extends BaseLeakChecker<Callback> implements Cas public void stopCasting(CastDevice device) { } + + @Override + public boolean hasConnectedCastDevice() { + return false; + } } diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index 02d3af6da326..6ec08dc08c51 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -1396,6 +1396,9 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer< } void onAppTransitionDone() { + if (mSurfaceFreezer.hasLeash()) { + mSurfaceFreezer.unfreeze(getSyncTransaction()); + } for (int i = mChildren.size() - 1; i >= 0; --i) { final WindowContainer wc = mChildren.get(i); wc.onAppTransitionDone(); |