diff options
63 files changed, 1051 insertions, 242 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/LegacySizeSpecSource.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/LegacySizeSpecSource.kt index fd000ee1d24f..a8743fbed5e0 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/LegacySizeSpecSource.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/LegacySizeSpecSource.kt @@ -21,7 +21,6 @@ import android.content.res.Resources import android.graphics.PointF import android.util.Size import com.android.wm.shell.R -import com.android.wm.shell.pip.PipDisplayLayoutState class LegacySizeSpecSource( private val context: Context, diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipKeepClearAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PhonePipKeepClearAlgorithm.java index 2d3403599484..133242d15822 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipKeepClearAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PhonePipKeepClearAlgorithm.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 The Android Open Source Project + * 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.wm.shell.pip.phone; +package com.android.wm.shell.common.pip; import android.content.Context; import android.content.res.Resources; @@ -24,9 +24,6 @@ import android.util.ArraySet; import android.view.Gravity; import com.android.wm.shell.R; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; -import com.android.wm.shell.pip.PipKeepClearAlgorithmInterface; import java.util.Set; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PhoneSizeSpecSource.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PhoneSizeSpecSource.kt index c5630686f528..18c7bdd6d5ba 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PhoneSizeSpecSource.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PhoneSizeSpecSource.kt @@ -21,7 +21,6 @@ import android.content.res.Resources import android.os.SystemProperties import android.util.Size import com.android.wm.shell.R -import com.android.wm.shell.pip.PipDisplayLayoutState import java.io.PrintWriter class PhoneSizeSpecSource( diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsAlgorithm.java index 4fef672b2cd8..a9f687fc9b2d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsAlgorithm.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.wm.shell.pip; +package com.android.wm.shell.common.pip; import android.annotation.NonNull; import android.annotation.Nullable; @@ -28,8 +28,6 @@ import android.util.Size; import android.view.Gravity; import com.android.wm.shell.R; -import com.android.wm.shell.common.pip.PipUtils; -import com.android.wm.shell.common.pip.SizeSpecSource; import java.io.PrintWriter; @@ -202,7 +200,8 @@ public class PipBoundsAlgorithm { * * @return {@code false} if the given source is too small to use for the entering animation. */ - static boolean isSourceRectHintValidForEnterPip(Rect sourceRectHint, Rect destinationBounds) { + public static boolean isSourceRectHintValidForEnterPip(Rect sourceRectHint, + Rect destinationBounds) { return sourceRectHint != null && sourceRectHint.width() > destinationBounds.width() && sourceRectHint.height() > destinationBounds.height(); @@ -224,7 +223,7 @@ public class PipBoundsAlgorithm { } /** - * @return whether the given {@param aspectRatio} is valid. + * @return whether the given aspectRatio is valid. */ public boolean isValidPictureInPictureAspectRatio(float aspectRatio) { return Float.compare(mMinAspectRatio, aspectRatio) <= 0 diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsState.java index 279ffc50e07e..3b32b6c7b083 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsState.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.wm.shell.pip; +package com.android.wm.shell.common.pip; import android.annotation.IntDef; import android.annotation.NonNull; @@ -36,7 +36,6 @@ import com.android.internal.protolog.common.ProtoLog; import com.android.internal.util.function.TriConsumer; import com.android.wm.shell.R; import com.android.wm.shell.common.DisplayLayout; -import com.android.wm.shell.common.pip.SizeSpecSource; import com.android.wm.shell.protolog.ShellProtoLogGroup; import java.io.PrintWriter; @@ -314,8 +313,11 @@ public class PipBoundsState { return mPipDisplayLayoutState.getDisplayLayout(); } + /** + * Clears the PiP re-entry state. + */ @VisibleForTesting - void clearReentryState() { + public void clearReentryState() { mPipReentryState = null; } @@ -400,11 +402,18 @@ public class PipBoundsState { mNamedUnrestrictedKeepClearAreas.remove(name); } + + /** + * @return restricted keep clear areas. + */ @NonNull public Set<Rect> getRestrictedKeepClearAreas() { return mRestrictedKeepClearAreas; } + /** + * @return unrestricted keep clear areas. + */ @NonNull public Set<Rect> getUnrestrictedKeepClearAreas() { if (mNamedUnrestrictedKeepClearAreas.isEmpty()) return mUnrestrictedKeepClearAreas; @@ -561,7 +570,11 @@ public class PipBoundsState { } } - static final class PipReentryState { + /** + * Represents the state of pip to potentially restore upon reentry. + */ + @VisibleForTesting + public static final class PipReentryState { private static final String TAG = PipReentryState.class.getSimpleName(); private final @Nullable Size mSize; @@ -573,11 +586,11 @@ public class PipBoundsState { } @Nullable - Size getSize() { + public Size getSize() { return mSize; } - float getSnapFraction() { + public float getSnapFraction() { return mSnapFraction; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipDisplayLayoutState.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipDisplayLayoutState.java index 4aa260b44646..ed42117a55af 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipDisplayLayoutState.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipDisplayLayoutState.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.wm.shell.pip; +package com.android.wm.shell.common.pip; import static com.android.wm.shell.common.pip.PipUtils.dpToPx; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipKeepClearAlgorithmInterface.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipKeepClearAlgorithmInterface.java index 5045cf905ee6..954233c04ed4 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipKeepClearAlgorithmInterface.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipKeepClearAlgorithmInterface.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 The Android Open Source Project + * 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.wm.shell.pip; +package com.android.wm.shell.common.pip; import android.graphics.Rect; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipPinchResizingAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipPinchResizingAlgorithm.java index 23153be72890..02b3a8862085 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipPinchResizingAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipPinchResizingAlgorithm.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.wm.shell.pip.phone; +package com.android.wm.shell.common.pip; import android.graphics.Point; import android.graphics.PointF; @@ -35,7 +35,7 @@ public class PipPinchResizingAlgorithm { private final PointF mTmpLastCentroid = new PointF(); /** - * Updates {@param resizeBoundsOut} with the new bounds of the PIP, and returns the angle in + * Updates resizeBoundsOut with the new bounds of the PIP, and returns the angle in * degrees that the PIP should be rotated. */ public float calculateBoundsAndAngle(PointF downPoint, PointF downSecondPoint, diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSnapAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipSnapAlgorithm.java index dd30137813e5..007052ee012a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSnapAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipSnapAlgorithm.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * 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. @@ -14,11 +14,11 @@ * limitations under the License. */ -package com.android.wm.shell.pip; +package com.android.wm.shell.common.pip; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_LEFT; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_LEFT; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_NONE; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_RIGHT; import android.graphics.Rect; @@ -39,14 +39,14 @@ public class PipSnapAlgorithm { } /** - * @return returns a fraction that describes where along the {@param movementBounds} the - * {@param stackBounds} are. If the {@param stackBounds} are not currently on the - * {@param movementBounds} exactly, then they will be snapped to the movement bounds. + * @return returns a fraction that describes where along the movementBounds the + * stackBounds are. If the stackBounds are not currently on the + * movementBounds exactly, then they will be snapped to the movement bounds. * stashType dictates whether the PiP is stashed (off-screen) or not. If * that's the case, we will have to do some math to calculate the snap fraction * correctly. * - * The fraction is defined in a clockwise fashion against the {@param movementBounds}: + * The fraction is defined in a clockwise fashion against the movementBounds: * * 0 1 * 4 +---+ 1 @@ -58,10 +58,10 @@ public class PipSnapAlgorithm { @PipBoundsState.StashType int stashType) { final Rect tmpBounds = new Rect(); snapRectToClosestEdge(stackBounds, movementBounds, tmpBounds, stashType); - final float widthFraction = (float) (tmpBounds.left - movementBounds.left) / - movementBounds.width(); - final float heightFraction = (float) (tmpBounds.top - movementBounds.top) / - movementBounds.height(); + final float widthFraction = (float) (tmpBounds.left - movementBounds.left) + / movementBounds.width(); + final float heightFraction = (float) (tmpBounds.top - movementBounds.top) + / movementBounds.height(); if (tmpBounds.top == movementBounds.top) { return widthFraction; } else if (tmpBounds.left == movementBounds.right) { @@ -74,10 +74,10 @@ public class PipSnapAlgorithm { } /** - * Moves the {@param stackBounds} along the {@param movementBounds} to the given snap fraction. + * Moves the stackBounds along the movementBounds to the given snap fraction. * See {@link #getSnapFraction(Rect, Rect)}. * - * The fraction is define in a clockwise fashion against the {@param movementBounds}: + * The fraction is define in a clockwise fashion against the movementBounds: * * 0 1 * 4 +---+ 1 @@ -122,11 +122,11 @@ public class PipSnapAlgorithm { } /** - * Snaps the {@param stackBounds} to the closest edge of the {@param movementBounds} and writes - * the new bounds out to {@param boundsOut}. + * Snaps the stackBounds to the closest edge of the movementBounds and writes + * the new bounds out to boundsOut. */ @VisibleForTesting - void snapRectToClosestEdge(Rect stackBounds, Rect movementBounds, Rect boundsOut, + public void snapRectToClosestEdge(Rect stackBounds, Rect movementBounds, Rect boundsOut, @PipBoundsState.StashType int stashType) { int leftEdge = stackBounds.left; if (stashType == STASH_TYPE_LEFT) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java index b454807192d4..45869e177c6d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java @@ -58,8 +58,15 @@ import com.android.wm.shell.common.annotations.ShellAnimationThread; import com.android.wm.shell.common.annotations.ShellBackgroundThread; import com.android.wm.shell.common.annotations.ShellMainThread; import com.android.wm.shell.common.annotations.ShellSplashscreenThread; +import com.android.wm.shell.common.pip.PhonePipKeepClearAlgorithm; +import com.android.wm.shell.common.pip.PhoneSizeSpecSource; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.PipMediaController; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.common.pip.PipUiEventLogger; +import com.android.wm.shell.common.pip.SizeSpecSource; import com.android.wm.shell.compatui.CompatUIConfiguration; import com.android.wm.shell.compatui.CompatUIController; import com.android.wm.shell.compatui.CompatUIShellCommandHandler; @@ -343,6 +350,42 @@ public abstract class WMShellBaseModule { return new PipMediaController(context, mainHandler); } + @WMSingleton + @Provides + static SizeSpecSource provideSizeSpecSource(Context context, + PipDisplayLayoutState pipDisplayLayoutState) { + return new PhoneSizeSpecSource(context, pipDisplayLayoutState); + } + + @WMSingleton + @Provides + static PipBoundsState providePipBoundsState(Context context, + SizeSpecSource sizeSpecSource, PipDisplayLayoutState pipDisplayLayoutState) { + return new PipBoundsState(context, sizeSpecSource, pipDisplayLayoutState); + } + + + @WMSingleton + @Provides + static PipSnapAlgorithm providePipSnapAlgorithm() { + return new PipSnapAlgorithm(); + } + + @WMSingleton + @Provides + static PhonePipKeepClearAlgorithm providePhonePipKeepClearAlgorithm(Context context) { + return new PhonePipKeepClearAlgorithm(context); + } + + @WMSingleton + @Provides + static PipBoundsAlgorithm providesPipBoundsAlgorithm(Context context, + PipBoundsState pipBoundsState, PipSnapAlgorithm pipSnapAlgorithm, + PhonePipKeepClearAlgorithm pipKeepClearAlgorithm, + PipDisplayLayoutState pipDisplayLayoutState, SizeSpecSource sizeSpecSource) { + return new PipBoundsAlgorithm(context, pipBoundsState, pipSnapAlgorithm, + pipKeepClearAlgorithm, pipDisplayLayoutState, sizeSpecSource); + } // // Bubbles (optional feature) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1Module.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1Module.java index 4e92ca113114..ba882c403aed 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1Module.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1Module.java @@ -30,9 +30,13 @@ import com.android.wm.shell.common.SystemWindows; import com.android.wm.shell.common.TabletopModeController; import com.android.wm.shell.common.TaskStackListenerImpl; import com.android.wm.shell.common.annotations.ShellMainThread; -import com.android.wm.shell.common.pip.PhoneSizeSpecSource; +import com.android.wm.shell.common.pip.PhonePipKeepClearAlgorithm; import com.android.wm.shell.common.pip.PipAppOpsListener; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.PipMediaController; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.common.pip.PipUiEventLogger; import com.android.wm.shell.common.pip.PipUtils; import com.android.wm.shell.common.pip.SizeSpecSource; @@ -41,17 +45,12 @@ import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.onehanded.OneHandedController; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.pip.PipAnimationController; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; -import com.android.wm.shell.pip.PipDisplayLayoutState; import com.android.wm.shell.pip.PipParamsChangedForwarder; -import com.android.wm.shell.pip.PipSnapAlgorithm; import com.android.wm.shell.pip.PipSurfaceTransactionHelper; import com.android.wm.shell.pip.PipTaskOrganizer; import com.android.wm.shell.pip.PipTransition; import com.android.wm.shell.pip.PipTransitionController; import com.android.wm.shell.pip.PipTransitionState; -import com.android.wm.shell.pip.phone.PhonePipKeepClearAlgorithm; import com.android.wm.shell.pip.phone.PhonePipMenuController; import com.android.wm.shell.pip.phone.PipController; import com.android.wm.shell.pip.phone.PipMotionHelper; @@ -119,35 +118,6 @@ public abstract class Pip1Module { } } - @WMSingleton - @Provides - static PipBoundsState providePipBoundsState(Context context, - SizeSpecSource sizeSpecSource, PipDisplayLayoutState pipDisplayLayoutState) { - return new PipBoundsState(context, sizeSpecSource, pipDisplayLayoutState); - } - - @WMSingleton - @Provides - static PipSnapAlgorithm providePipSnapAlgorithm() { - return new PipSnapAlgorithm(); - } - - @WMSingleton - @Provides - static PhonePipKeepClearAlgorithm providePhonePipKeepClearAlgorithm(Context context) { - return new PhonePipKeepClearAlgorithm(context); - } - - @WMSingleton - @Provides - static PipBoundsAlgorithm providesPipBoundsAlgorithm(Context context, - PipBoundsState pipBoundsState, PipSnapAlgorithm pipSnapAlgorithm, - PhonePipKeepClearAlgorithm pipKeepClearAlgorithm, - PipDisplayLayoutState pipDisplayLayoutState, SizeSpecSource sizeSpecSource) { - return new PipBoundsAlgorithm(context, pipBoundsState, pipSnapAlgorithm, - pipKeepClearAlgorithm, pipDisplayLayoutState, sizeSpecSource); - } - // Handler is used by Icon.loadDrawableAsync @WMSingleton @Provides @@ -213,13 +183,6 @@ public abstract class Pip1Module { @WMSingleton @Provides - static PipAnimationController providePipAnimationController(PipSurfaceTransactionHelper - pipSurfaceTransactionHelper) { - return new PipAnimationController(pipSurfaceTransactionHelper); - } - - @WMSingleton - @Provides static PipTransition providePipTransition(Context context, ShellInit shellInit, ShellTaskOrganizer shellTaskOrganizer, Transitions transitions, PipAnimationController pipAnimationController, PipBoundsAlgorithm pipBoundsAlgorithm, @@ -235,13 +198,6 @@ public abstract class Pip1Module { @WMSingleton @Provides - static SizeSpecSource provideSizeSpecSource(Context context, - PipDisplayLayoutState pipDisplayLayoutState) { - return new PhoneSizeSpecSource(context, pipDisplayLayoutState); - } - - @WMSingleton - @Provides static PipAppOpsListener providePipAppOpsListener(Context context, PipTouchHandler pipTouchHandler, @ShellMainThread ShellExecutor mainExecutor) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1SharedModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1SharedModule.java index c4ca5013afb6..b42372b869dd 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1SharedModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1SharedModule.java @@ -19,6 +19,7 @@ package com.android.wm.shell.dagger.pip; import android.content.Context; import com.android.wm.shell.dagger.WMSingleton; +import com.android.wm.shell.pip.PipAnimationController; import com.android.wm.shell.pip.PipSurfaceTransactionHelper; import dagger.Module; @@ -35,4 +36,11 @@ public abstract class Pip1SharedModule { static PipSurfaceTransactionHelper providePipSurfaceTransactionHelper(Context context) { return new PipSurfaceTransactionHelper(context); } + + @WMSingleton + @Provides + static PipAnimationController providePipAnimationController(PipSurfaceTransactionHelper + pipSurfaceTransactionHelper) { + return new PipAnimationController(pipSurfaceTransactionHelper); + } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip2Module.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip2Module.java index 8dec4ea542a0..af97cf68915f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip2Module.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip2Module.java @@ -16,11 +16,16 @@ package com.android.wm.shell.dagger.pip; -import android.annotation.Nullable; +import android.annotation.NonNull; +import com.android.wm.shell.ShellTaskOrganizer; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; import com.android.wm.shell.dagger.WMShellBaseModule; import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.pip2.PipTransition; +import com.android.wm.shell.sysui.ShellInit; +import com.android.wm.shell.transition.Transitions; import dagger.Module; import dagger.Provides; @@ -33,8 +38,12 @@ import dagger.Provides; public abstract class Pip2Module { @WMSingleton @Provides - @Nullable - static PipTransition providePipTransition() { - return null; + static PipTransition providePipTransition(@NonNull ShellInit shellInit, + @NonNull ShellTaskOrganizer shellTaskOrganizer, + @NonNull Transitions transitions, + PipBoundsState pipBoundsState, + PipBoundsAlgorithm pipBoundsAlgorithm) { + return new PipTransition(shellInit, shellTaskOrganizer, transitions, pipBoundsState, null, + pipBoundsAlgorithm); } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/PipModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/PipModule.java index 9c9364e17e0e..570f0a3db35a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/PipModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/PipModule.java @@ -16,8 +16,6 @@ package com.android.wm.shell.dagger.pip; -import android.annotation.Nullable; - import com.android.wm.shell.common.pip.PipUtils; import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.pip.PipTransitionController; @@ -38,8 +36,8 @@ public abstract class PipModule { @Provides static PipTransitionController providePipTransitionController( com.android.wm.shell.pip.PipTransition legacyPipTransition, - @Nullable com.android.wm.shell.pip2.PipTransition newPipTransition) { - if (PipUtils.isPip2ExperimentEnabled() && newPipTransition != null) { + com.android.wm.shell.pip2.PipTransition newPipTransition) { + if (PipUtils.isPip2ExperimentEnabled()) { return newPipTransition; } else { return legacyPipTransition; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/TvPipModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/TvPipModule.java index a6ff9ecf7f4f..a9675f976fa9 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/TvPipModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/TvPipModule.java @@ -30,16 +30,15 @@ import com.android.wm.shell.common.TaskStackListenerImpl; import com.android.wm.shell.common.annotations.ShellMainThread; import com.android.wm.shell.common.pip.LegacySizeSpecSource; import com.android.wm.shell.common.pip.PipAppOpsListener; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.PipMediaController; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.common.pip.PipUiEventLogger; -import com.android.wm.shell.common.pip.SizeSpecSource; import com.android.wm.shell.dagger.WMShellBaseModule; import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.pip.PipAnimationController; -import com.android.wm.shell.pip.PipDisplayLayoutState; import com.android.wm.shell.pip.PipParamsChangedForwarder; -import com.android.wm.shell.pip.PipSnapAlgorithm; import com.android.wm.shell.pip.PipSurfaceTransactionHelper; import com.android.wm.shell.pip.PipTaskOrganizer; import com.android.wm.shell.pip.PipTransitionController; @@ -131,15 +130,9 @@ public abstract class TvPipModule { @WMSingleton @Provides - static PipSnapAlgorithm providePipSnapAlgorithm() { - return new PipSnapAlgorithm(); - } - - @WMSingleton - @Provides static TvPipBoundsAlgorithm provideTvPipBoundsAlgorithm(Context context, TvPipBoundsState tvPipBoundsState, PipSnapAlgorithm pipSnapAlgorithm, - PipDisplayLayoutState pipDisplayLayoutState, SizeSpecSource sizeSpecSource) { + PipDisplayLayoutState pipDisplayLayoutState, LegacySizeSpecSource sizeSpecSource) { return new TvPipBoundsAlgorithm(context, tvPipBoundsState, pipSnapAlgorithm, pipDisplayLayoutState, sizeSpecSource); } @@ -147,13 +140,13 @@ public abstract class TvPipModule { @WMSingleton @Provides static TvPipBoundsState provideTvPipBoundsState(Context context, - SizeSpecSource sizeSpecSource, PipDisplayLayoutState pipDisplayLayoutState) { + LegacySizeSpecSource sizeSpecSource, PipDisplayLayoutState pipDisplayLayoutState) { return new TvPipBoundsState(context, sizeSpecSource, pipDisplayLayoutState); } @WMSingleton @Provides - static SizeSpecSource provideSizeSpecSource(Context context, + static LegacySizeSpecSource provideSizeSpecSource(Context context, PipDisplayLayoutState pipDisplayLayoutState) { return new LegacySizeSpecSource(context, pipDisplayLayoutState); } @@ -200,13 +193,6 @@ public abstract class TvPipModule { @WMSingleton @Provides - static PipAnimationController providePipAnimationController(PipSurfaceTransactionHelper - pipSurfaceTransactionHelper) { - return new PipAnimationController(pipSurfaceTransactionHelper); - } - - @WMSingleton - @Provides static PipTransitionState providePipTransitionState() { return new PipTransitionState(); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java index ed9ff1c169c6..9e8f9c68d43d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java @@ -82,6 +82,9 @@ import com.android.wm.shell.common.ScreenshotUtils; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.common.annotations.ShellMainThread; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.PipUiEventLogger; import com.android.wm.shell.common.pip.PipUtils; import com.android.wm.shell.pip.phone.PipMotionHelper; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java index 83e03dc850a1..e3922d65215c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java @@ -64,6 +64,9 @@ import androidx.annotation.Nullable; import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.R; import com.android.wm.shell.ShellTaskOrganizer; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.PipUtils; import com.android.wm.shell.protolog.ShellProtoLogGroup; import com.android.wm.shell.splitscreen.SplitScreenController; @@ -89,6 +92,7 @@ public class PipTransition extends PipTransitionController { private final int mEnterExitAnimationDuration; private final PipSurfaceTransactionHelper mSurfaceTransactionHelper; private final Optional<SplitScreenController> mSplitScreenOptional; + private final PipAnimationController mPipAnimationController; private @PipAnimationController.AnimationType int mEnterAnimationType = ANIM_TYPE_BOUNDS; private Transitions.TransitionFinishCallback mFinishCallback; private SurfaceControl.Transaction mFinishTransaction; @@ -137,10 +141,11 @@ public class PipTransition extends PipTransitionController { PipSurfaceTransactionHelper pipSurfaceTransactionHelper, Optional<SplitScreenController> splitScreenOptional) { super(shellInit, shellTaskOrganizer, transitions, pipBoundsState, pipMenuController, - pipBoundsAlgorithm, pipAnimationController); + pipBoundsAlgorithm); mContext = context; mPipTransitionState = pipTransitionState; mPipDisplayLayoutState = pipDisplayLayoutState; + mPipAnimationController = pipAnimationController; mEnterExitAnimationDuration = context.getResources() .getInteger(R.integer.config_pipResizeAnimationDuration); mSurfaceTransactionHelper = pipSurfaceTransactionHelper; @@ -148,6 +153,13 @@ public class PipTransition extends PipTransitionController { } @Override + protected void onInit() { + if (!PipUtils.isPip2ExperimentEnabled()) { + mTransitions.addHandler(this); + } + } + + @Override public void startExitTransition(int type, WindowContainerTransaction out, @Nullable Rect destinationBounds) { if (destinationBounds != null) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransitionController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransitionController.java index 64bba672a5b5..20c57fa5e566 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransitionController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransitionController.java @@ -38,7 +38,8 @@ import android.window.WindowContainerTransaction; import androidx.annotation.NonNull; import com.android.wm.shell.ShellTaskOrganizer; -import com.android.wm.shell.common.pip.PipUtils; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; import com.android.wm.shell.common.split.SplitScreenUtils; import com.android.wm.shell.sysui.ShellInit; import com.android.wm.shell.transition.Transitions; @@ -52,7 +53,6 @@ import java.util.List; */ public abstract class PipTransitionController implements Transitions.TransitionHandler { - protected final PipAnimationController mPipAnimationController; protected final PipBoundsAlgorithm mPipBoundsAlgorithm; protected final PipBoundsState mPipBoundsState; protected final ShellTaskOrganizer mShellTaskOrganizer; @@ -135,22 +135,18 @@ public abstract class PipTransitionController implements Transitions.TransitionH @NonNull ShellTaskOrganizer shellTaskOrganizer, @NonNull Transitions transitions, PipBoundsState pipBoundsState, - PipMenuController pipMenuController, PipBoundsAlgorithm pipBoundsAlgorithm, - PipAnimationController pipAnimationController) { + PipMenuController pipMenuController, PipBoundsAlgorithm pipBoundsAlgorithm) { mPipBoundsState = pipBoundsState; mPipMenuController = pipMenuController; mShellTaskOrganizer = shellTaskOrganizer; mPipBoundsAlgorithm = pipBoundsAlgorithm; - mPipAnimationController = pipAnimationController; mTransitions = transitions; - if (!PipUtils.isPip2ExperimentEnabled()) { - if (Transitions.ENABLE_SHELL_TRANSITIONS) { - shellInit.addInitCallback(this::onInit, this); - } + if (Transitions.ENABLE_SHELL_TRANSITIONS) { + shellInit.addInitCallback(this::onInit, this); } } - private void onInit() { + protected void onInit() { mTransitions.addHandler(this); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java index cc182ba89985..760652625f9e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java @@ -38,10 +38,10 @@ import android.view.WindowManagerGlobal; import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SystemWindows; +import com.android.wm.shell.common.pip.PipBoundsState; import com.android.wm.shell.common.pip.PipMediaController; import com.android.wm.shell.common.pip.PipMediaController.ActionListener; import com.android.wm.shell.common.pip.PipUiEventLogger; -import com.android.wm.shell.pip.PipBoundsState; import com.android.wm.shell.pip.PipMenuController; import com.android.wm.shell.pip.PipSurfaceTransactionHelper; import com.android.wm.shell.protolog.ShellProtoLogGroup; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java index 4a06d84ce90d..bc17ce97dbff 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java @@ -15,7 +15,7 @@ */ package com.android.wm.shell.pip.phone; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_NONE; import android.annotation.NonNull; import android.content.Context; @@ -36,8 +36,8 @@ import androidx.annotation.BinderThread; import com.android.wm.shell.R; import com.android.wm.shell.common.ShellExecutor; -import com.android.wm.shell.pip.PipBoundsState; -import com.android.wm.shell.pip.PipSnapAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.pip.PipTaskOrganizer; import java.util.ArrayList; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java index ddea574c3c89..106486714a5c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java @@ -76,7 +76,12 @@ import com.android.wm.shell.common.TabletopModeController; import com.android.wm.shell.common.TaskStackListenerCallback; import com.android.wm.shell.common.TaskStackListenerImpl; import com.android.wm.shell.common.pip.PipAppOpsListener; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; +import com.android.wm.shell.common.pip.PipKeepClearAlgorithmInterface; import com.android.wm.shell.common.pip.PipMediaController; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.common.pip.PipUtils; import com.android.wm.shell.onehanded.OneHandedController; import com.android.wm.shell.onehanded.OneHandedTransitionCallback; @@ -85,12 +90,7 @@ import com.android.wm.shell.pip.IPipAnimationListener; import com.android.wm.shell.pip.PinnedStackListenerForwarder; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.pip.PipAnimationController; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; -import com.android.wm.shell.pip.PipDisplayLayoutState; -import com.android.wm.shell.pip.PipKeepClearAlgorithmInterface; import com.android.wm.shell.pip.PipParamsChangedForwarder; -import com.android.wm.shell.pip.PipSnapAlgorithm; import com.android.wm.shell.pip.PipTaskOrganizer; import com.android.wm.shell.pip.PipTransitionController; import com.android.wm.shell.pip.PipTransitionState; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipDoubleTapHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipDoubleTapHelper.java index d7d335b856be..1b1ebc39b558 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipDoubleTapHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipDoubleTapHelper.java @@ -20,7 +20,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.graphics.Rect; -import com.android.wm.shell.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipBoundsState; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java index 8f0a8e11103c..c708b86e88c5 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java @@ -20,10 +20,10 @@ import static androidx.dynamicanimation.animation.SpringForce.DAMPING_RATIO_NO_B import static androidx.dynamicanimation.animation.SpringForce.STIFFNESS_LOW; import static androidx.dynamicanimation.animation.SpringForce.STIFFNESS_MEDIUM; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_LEFT; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_NONE; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_RIGHT; import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTION_EXPAND_OR_UNEXPAND; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_LEFT; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT; import static com.android.wm.shell.pip.phone.PipMenuView.ANIM_TYPE_DISMISS; import static com.android.wm.shell.pip.phone.PipMenuView.ANIM_TYPE_NONE; @@ -41,8 +41,8 @@ import com.android.wm.shell.animation.PhysicsAnimator; import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.magnetictarget.MagnetizedObject; import com.android.wm.shell.common.pip.PipAppOpsListener; -import com.android.wm.shell.pip.PipBoundsState; -import com.android.wm.shell.pip.PipSnapAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.pip.PipTaskOrganizer; import com.android.wm.shell.pip.PipTransitionController; import com.android.wm.shell.protolog.ShellProtoLogGroup; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java index 4e687dda4e77..e5f9fdc7a740 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java @@ -46,10 +46,11 @@ import androidx.annotation.VisibleForTesting; import com.android.internal.policy.TaskResizingAlgorithm; import com.android.wm.shell.R; import com.android.wm.shell.common.ShellExecutor; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipPinchResizingAlgorithm; import com.android.wm.shell.common.pip.PipUiEventLogger; import com.android.wm.shell.pip.PipAnimationController; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; import com.android.wm.shell.pip.PipTaskOrganizer; import java.io.PrintWriter; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java index cb4e6c8b6631..700a31926d6c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java @@ -18,10 +18,10 @@ package com.android.wm.shell.pip.phone; import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.PIP_STASHING; import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.PIP_STASH_MINIMUM_VELOCITY_THRESHOLD; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_LEFT; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_NONE; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_RIGHT; import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTION_TO_PIP; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_LEFT; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT; import static com.android.wm.shell.pip.phone.PhonePipMenuController.MENU_STATE_FULL; import static com.android.wm.shell.pip.phone.PhonePipMenuController.MENU_STATE_NONE; import static com.android.wm.shell.pip.phone.PipMenuView.ANIM_TYPE_NONE; @@ -50,12 +50,12 @@ import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.R; import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.ShellExecutor; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; import com.android.wm.shell.common.pip.PipUiEventLogger; import com.android.wm.shell.common.pip.PipUtils; import com.android.wm.shell.common.pip.SizeSpecSource; import com.android.wm.shell.pip.PipAnimationController; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; import com.android.wm.shell.pip.PipTaskOrganizer; import com.android.wm.shell.pip.PipTransitionController; import com.android.wm.shell.protolog.ShellProtoLogGroup; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsAlgorithm.java index cd58ff4f5154..a48e969fde35 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsAlgorithm.java @@ -36,11 +36,11 @@ import androidx.annotation.NonNull; import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.R; import com.android.wm.shell.common.DisplayLayout; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; +import com.android.wm.shell.common.pip.PipKeepClearAlgorithmInterface; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.common.pip.SizeSpecSource; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipDisplayLayoutState; -import com.android.wm.shell.pip.PipKeepClearAlgorithmInterface; -import com.android.wm.shell.pip.PipSnapAlgorithm; import com.android.wm.shell.pip.tv.TvPipKeepClearAlgorithm.Placement; import com.android.wm.shell.protolog.ShellProtoLogGroup; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsController.java index 8d4a38442ce5..8a215b4b2e25 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsController.java @@ -16,7 +16,7 @@ package com.android.wm.shell.pip.tv; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE; +import static com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_NONE; import android.annotation.NonNull; import android.annotation.Nullable; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsState.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsState.java index 4757efc846f9..47a8cc89559e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsState.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsState.java @@ -29,10 +29,10 @@ import android.util.Size; import android.view.Gravity; import android.view.View; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.SizeSpecSource; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; -import com.android.wm.shell.pip.PipDisplayLayoutState; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java index 0816dc74dfa9..46336ce0655a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java @@ -48,11 +48,11 @@ import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.TaskStackListenerCallback; import com.android.wm.shell.common.TaskStackListenerImpl; import com.android.wm.shell.common.pip.PipAppOpsListener; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.PipMediaController; import com.android.wm.shell.pip.PinnedStackListenerForwarder; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.pip.PipAnimationController; -import com.android.wm.shell.pip.PipDisplayLayoutState; import com.android.wm.shell.pip.PipParamsChangedForwarder; import com.android.wm.shell.pip.PipTaskOrganizer; import com.android.wm.shell.pip.PipTransitionController; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithm.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithm.kt index a94bd6ec1040..93f6826ac96b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithm.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithm.kt @@ -21,12 +21,12 @@ import android.graphics.Point import android.graphics.Rect import android.util.Size import android.view.Gravity -import com.android.wm.shell.pip.PipBoundsState -import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_BOTTOM -import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_LEFT -import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE -import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT -import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_TOP +import com.android.wm.shell.common.pip.PipBoundsState +import com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_BOTTOM +import com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_LEFT +import com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_NONE +import com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_RIGHT +import com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_TOP import kotlin.math.abs import kotlin.math.max import kotlin.math.min @@ -54,11 +54,11 @@ class TvPipKeepClearAlgorithm() { * the unstash timeout if already stashed. */ data class Placement( - val bounds: Rect, - val anchorBounds: Rect, - @PipBoundsState.StashType val stashType: Int = STASH_TYPE_NONE, - val unstashDestinationBounds: Rect? = null, - val triggerStash: Boolean = false + val bounds: Rect, + val anchorBounds: Rect, + @PipBoundsState.StashType val stashType: Int = STASH_TYPE_NONE, + val unstashDestinationBounds: Rect? = null, + val triggerStash: Boolean = false ) { /** Bounds to use if the PiP should not be stashed. */ fun getUnstashedBounds() = unstashDestinationBounds ?: bounds diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTaskOrganizer.java index 672080407658..f315afba9a03 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTaskOrganizer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTaskOrganizer.java @@ -25,12 +25,12 @@ import com.android.wm.shell.ShellTaskOrganizer; import com.android.wm.shell.common.DisplayController; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SyncTransactionQueue; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.PipUiEventLogger; import com.android.wm.shell.common.pip.PipUtils; import com.android.wm.shell.pip.PipAnimationController; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; -import com.android.wm.shell.pip.PipDisplayLayoutState; import com.android.wm.shell.pip.PipMenuController; import com.android.wm.shell.pip.PipParamsChangedForwarder; import com.android.wm.shell.pip.PipSurfaceTransactionHelper; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTransition.java index d3253a5e4d94..f24b2b385cad 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTransition.java @@ -21,8 +21,8 @@ import android.content.Context; import androidx.annotation.NonNull; import com.android.wm.shell.ShellTaskOrganizer; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.pip.PipAnimationController; -import com.android.wm.shell.pip.PipDisplayLayoutState; import com.android.wm.shell.pip.PipSurfaceTransactionHelper; import com.android.wm.shell.pip.PipTransition; import com.android.wm.shell.pip.PipTransitionState; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/PipTransition.java index 8ab85d0829df..b8e4c04ac262 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/PipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/PipTransition.java @@ -17,27 +17,65 @@ package com.android.wm.shell.pip2; import android.annotation.NonNull; +import android.os.IBinder; +import android.view.SurfaceControl; +import android.window.TransitionInfo; +import android.window.TransitionRequestInfo; +import android.window.WindowContainerTransaction; + +import androidx.annotation.Nullable; import com.android.wm.shell.ShellTaskOrganizer; -import com.android.wm.shell.pip.PipAnimationController; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipUtils; import com.android.wm.shell.pip.PipMenuController; import com.android.wm.shell.pip.PipTransitionController; import com.android.wm.shell.sysui.ShellInit; import com.android.wm.shell.transition.Transitions; /** Placeholder, for demonstrate purpose only. */ -public abstract class PipTransition extends PipTransitionController { +public class PipTransition extends PipTransitionController { public PipTransition( @NonNull ShellInit shellInit, @NonNull ShellTaskOrganizer shellTaskOrganizer, @NonNull Transitions transitions, PipBoundsState pipBoundsState, PipMenuController pipMenuController, - PipBoundsAlgorithm pipBoundsAlgorithm, - PipAnimationController pipAnimationController) { + PipBoundsAlgorithm pipBoundsAlgorithm) { super(shellInit, shellTaskOrganizer, transitions, pipBoundsState, pipMenuController, - pipBoundsAlgorithm, pipAnimationController); + pipBoundsAlgorithm); + } + + @Override + protected void onInit() { + if (PipUtils.isPip2ExperimentEnabled()) { + mTransitions.addHandler(this); + } + } + + @Nullable + @Override + public WindowContainerTransaction handleRequest(@NonNull IBinder transition, + @NonNull TransitionRequestInfo request) { + return null; } + + @Override + public boolean startAnimation(@NonNull IBinder transition, + @NonNull TransitionInfo info, + @NonNull SurfaceControl.Transaction startTransaction, + @NonNull SurfaceControl.Transaction finishTransaction, + @NonNull Transitions.TransitionFinishCallback finishCallback) { + return false; + } + + @Override + public void mergeAnimation(@NonNull IBinder transition, @NonNull TransitionInfo info, + @NonNull SurfaceControl.Transaction t, @NonNull IBinder mergeTarget, + @NonNull Transitions.TransitionFinishCallback finishCallback) {} + + @Override + public void onTransitionConsumed(@NonNull IBinder transition, boolean aborted, + @Nullable SurfaceControl.Transaction finishT) {} } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsAlgorithmTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsAlgorithmTest.java index bf1b7f9f86ed..46259a8b177f 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsAlgorithmTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsAlgorithmTest.java @@ -33,6 +33,11 @@ import com.android.wm.shell.R; import com.android.wm.shell.ShellTestCase; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.pip.PhoneSizeSpecSource; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; +import com.android.wm.shell.common.pip.PipKeepClearAlgorithmInterface; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.common.pip.SizeSpecSource; import org.junit.Before; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsStateTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsStateTest.java index 4341c4c8c8aa..d34e27b57071 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsStateTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsStateTest.java @@ -36,6 +36,8 @@ import com.android.internal.util.function.TriConsumer; import com.android.wm.shell.R; import com.android.wm.shell.ShellTestCase; import com.android.wm.shell.common.pip.PhoneSizeSpecSource; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.SizeSpecSource; import org.junit.Before; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipSnapAlgorithmTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipSnapAlgorithmTest.java index b9226d2b9b91..ac13d7ffcd61 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipSnapAlgorithmTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipSnapAlgorithmTest.java @@ -25,6 +25,8 @@ import android.testing.TestableLooper; import androidx.test.filters.SmallTest; import com.android.wm.shell.ShellTestCase; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import org.junit.Before; import org.junit.Test; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipTaskOrganizerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipTaskOrganizerTest.java index 248d66590542..4e2b7f6d16b2 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipTaskOrganizerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipTaskOrganizerTest.java @@ -53,6 +53,11 @@ import com.android.wm.shell.common.DisplayController; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.common.pip.PhoneSizeSpecSource; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; +import com.android.wm.shell.common.pip.PipKeepClearAlgorithmInterface; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.common.pip.PipUiEventLogger; import com.android.wm.shell.common.pip.SizeSpecSource; import com.android.wm.shell.pip.phone.PhonePipMenuController; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PhonePipKeepClearAlgorithmTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PhonePipKeepClearAlgorithmTest.java index cc9e26b2c4f1..8c7b47ea7d84 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PhonePipKeepClearAlgorithmTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PhonePipKeepClearAlgorithmTest.java @@ -29,8 +29,9 @@ import android.testing.TestableLooper; import androidx.test.filters.SmallTest; import com.android.wm.shell.ShellTestCase; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PhonePipKeepClearAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; import org.junit.Before; import org.junit.Test; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PhoneSizeSpecSourceTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PhoneSizeSpecSourceTest.java index 024cba319ffc..3d5cd6939d1b 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PhoneSizeSpecSourceTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PhoneSizeSpecSourceTest.java @@ -33,8 +33,8 @@ import com.android.dx.mockito.inline.extended.StaticMockitoSession; import com.android.wm.shell.ShellTestCase; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.pip.PhoneSizeSpecSource; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.SizeSpecSource; -import com.android.wm.shell.pip.PipDisplayLayoutState; import org.junit.After; import org.junit.Assert; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipControllerTest.java index 911f5e165ef1..4eb519334e12 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipControllerTest.java @@ -55,15 +55,16 @@ import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.TabletopModeController; import com.android.wm.shell.common.TaskStackListenerImpl; +import com.android.wm.shell.common.pip.PhonePipKeepClearAlgorithm; import com.android.wm.shell.common.pip.PipAppOpsListener; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.PipMediaController; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.onehanded.OneHandedController; import com.android.wm.shell.pip.PipAnimationController; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; -import com.android.wm.shell.pip.PipDisplayLayoutState; import com.android.wm.shell.pip.PipParamsChangedForwarder; -import com.android.wm.shell.pip.PipSnapAlgorithm; import com.android.wm.shell.pip.PipTaskOrganizer; import com.android.wm.shell.pip.PipTransitionController; import com.android.wm.shell.pip.PipTransitionState; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipDoubleTapHelperTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipDoubleTapHelperTest.java index 8ce3ca4bdc00..0f8db85dcef4 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipDoubleTapHelperTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipDoubleTapHelperTest.java @@ -29,7 +29,7 @@ import android.graphics.Rect; import android.testing.AndroidTestingRunner; import com.android.wm.shell.ShellTestCase; -import com.android.wm.shell.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipBoundsState; import org.junit.Assert; import org.junit.Before; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipResizeGestureHandlerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipResizeGestureHandlerTest.java index 12b4f3e50f32..6777a5bd8ceb 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipResizeGestureHandlerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipResizeGestureHandlerTest.java @@ -37,13 +37,13 @@ import com.android.wm.shell.ShellTestCase; import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.pip.PhoneSizeSpecSource; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; +import com.android.wm.shell.common.pip.PipKeepClearAlgorithmInterface; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.common.pip.PipUiEventLogger; import com.android.wm.shell.common.pip.SizeSpecSource; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; -import com.android.wm.shell.pip.PipDisplayLayoutState; -import com.android.wm.shell.pip.PipKeepClearAlgorithmInterface; -import com.android.wm.shell.pip.PipSnapAlgorithm; import com.android.wm.shell.pip.PipTaskOrganizer; import com.android.wm.shell.pip.PipTransitionController; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java index 314f195d87ac..9aaabd130527 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java @@ -33,13 +33,13 @@ import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.pip.PhoneSizeSpecSource; +import com.android.wm.shell.common.pip.PipBoundsAlgorithm; +import com.android.wm.shell.common.pip.PipBoundsState; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; +import com.android.wm.shell.common.pip.PipKeepClearAlgorithmInterface; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.common.pip.PipUiEventLogger; import com.android.wm.shell.common.pip.SizeSpecSource; -import com.android.wm.shell.pip.PipBoundsAlgorithm; -import com.android.wm.shell.pip.PipBoundsState; -import com.android.wm.shell.pip.PipDisplayLayoutState; -import com.android.wm.shell.pip.PipKeepClearAlgorithmInterface; -import com.android.wm.shell.pip.PipSnapAlgorithm; import com.android.wm.shell.pip.PipTaskOrganizer; import com.android.wm.shell.pip.PipTransitionController; import com.android.wm.shell.sysui.ShellInit; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipBoundsControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipBoundsControllerTest.kt index 7370ed71bbdd..94f2b9131ebd 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipBoundsControllerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipBoundsControllerTest.kt @@ -25,7 +25,7 @@ import android.testing.AndroidTestingRunner import com.android.wm.shell.R import com.android.wm.shell.ShellTestCase -import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT +import com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_RIGHT import com.android.wm.shell.pip.tv.TvPipBoundsController.POSITION_DEBOUNCE_TIMEOUT_MILLIS import com.android.wm.shell.pip.tv.TvPipKeepClearAlgorithm.Placement diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipGravityTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipGravityTest.java index da6951bc588e..82fe5f2f6afc 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipGravityTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipGravityTest.java @@ -27,9 +27,9 @@ import android.view.Gravity; import com.android.wm.shell.ShellTestCase; import com.android.wm.shell.common.pip.LegacySizeSpecSource; +import com.android.wm.shell.common.pip.PipDisplayLayoutState; +import com.android.wm.shell.common.pip.PipSnapAlgorithm; import com.android.wm.shell.common.pip.SizeSpecSource; -import com.android.wm.shell.pip.PipDisplayLayoutState; -import com.android.wm.shell.pip.PipSnapAlgorithm; import org.junit.Before; import org.junit.Test; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithmTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithmTest.kt index aedf65ddc269..998060fdcac2 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithmTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithmTest.kt @@ -22,10 +22,10 @@ import android.testing.AndroidTestingRunner import android.util.Size import android.view.Gravity import com.android.wm.shell.ShellTestCase -import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_BOTTOM -import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE -import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT -import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_TOP +import com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_BOTTOM +import com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_NONE +import com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_RIGHT +import com.android.wm.shell.common.pip.PipBoundsState.STASH_TYPE_TOP import com.android.wm.shell.pip.tv.TvPipKeepClearAlgorithm.Placement import junit.framework.Assert.assertEquals import junit.framework.Assert.assertFalse diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModel.kt b/packages/SystemUI/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModel.kt index e8b8f54220aa..be08932cfa64 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModel.kt @@ -78,17 +78,6 @@ constructor( private val _isOverlayTouched: MutableStateFlow<Boolean> = MutableStateFlow(false) - /** - * If the API caller or the user's personal preferences require explicit confirmation after - * successful authentication. - */ - val isConfirmationRequired: Flow<Boolean> = - combine(_isOverlayTouched, promptSelectorInteractor.isConfirmationRequired) { - isOverlayTouched, - isConfirmationRequired -> - !isOverlayTouched && isConfirmationRequired - } - /** The kind of credential the user has. */ val credentialKind: Flow<PromptKind> = promptSelectorInteractor.credentialKind @@ -137,6 +126,15 @@ constructor( } .distinctUntilChanged() + /** + * If the API caller or the user's personal preferences require explicit confirmation after + * successful authentication. Confirmation always required when in explicit flow. + */ + val isConfirmationRequired: Flow<Boolean> = + combine(_isOverlayTouched, size) { isOverlayTouched, size -> + !isOverlayTouched && size.isNotSmall + } + /** Title for the prompt. */ val title: Flow<String> = promptSelectorInteractor.prompt.map { it?.title ?: "" }.distinctUntilChanged() @@ -170,12 +168,7 @@ constructor( .distinctUntilChanged() /** If the icon can be used as a confirmation button. */ - val isIconConfirmButton: Flow<Boolean> = - combine(size, promptSelectorInteractor.isConfirmationRequired) { - size, - isConfirmationRequired -> - size.isNotSmall && isConfirmationRequired - } + val isIconConfirmButton: Flow<Boolean> = size.map { it.isNotSmall }.distinctUntilChanged() /** If the negative button should be shown. */ val isNegativeButtonVisible: Flow<Boolean> = diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowControllerImpl.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowControllerImpl.java index d2b62eb3779d..e41fb18e023f 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowControllerImpl.java @@ -21,7 +21,6 @@ import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_M import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_BEHAVIOR_CONTROLLED; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_OPTIMIZE_MEASURE; -import static com.android.systemui.DejankUtils.whitelistIpcs; import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENABLE_REMOTE_INPUT; import android.app.IActivityManager; @@ -52,6 +51,7 @@ import com.android.systemui.R; import com.android.systemui.biometrics.AuthController; import com.android.systemui.colorextraction.SysuiColorExtractor; import com.android.systemui.dagger.SysUISingleton; +import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dump.DumpManager; import com.android.systemui.dump.DumpsysTableLogger; import com.android.systemui.keyguard.KeyguardViewMediator; @@ -75,6 +75,7 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.concurrent.Executor; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -102,6 +103,7 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW private final float mKeyguardMaxRefreshRate; private final KeyguardViewMediator mKeyguardViewMediator; private final KeyguardBypassController mKeyguardBypassController; + private final Executor mBackgroundExecutor; private final AuthController mAuthController; private ViewGroup mWindowRootView; private LayoutParams mLp; @@ -135,6 +137,7 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW ConfigurationController configurationController, KeyguardViewMediator keyguardViewMediator, KeyguardBypassController keyguardBypassController, + @Background Executor backgroundExecutor, SysuiColorExtractor colorExtractor, DumpManager dumpManager, KeyguardStateController keyguardStateController, @@ -152,6 +155,7 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW mLpChanged = new LayoutParams(); mKeyguardViewMediator = keyguardViewMediator; mKeyguardBypassController = keyguardBypassController; + mBackgroundExecutor = backgroundExecutor; mColorExtractor = colorExtractor; mScreenOffAnimationController = screenOffAnimationController; dumpManager.registerDumpable(getClass().getName(), this); @@ -512,13 +516,14 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW applyWindowLayoutParams(); if (mHasTopUi != mHasTopUiChanged) { - whitelistIpcs(() -> { + mHasTopUi = mHasTopUiChanged; + mBackgroundExecutor.execute(() -> { try { mActivityManager.setHasTopUi(mHasTopUiChanged); } catch (RemoteException e) { Log.e(TAG, "Failed to call setHasTopUi", e); } - mHasTopUi = mHasTopUiChanged; + }); } notifyStateChangedCallbacks(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModelTest.kt index 47084c087952..0ed46da27b55 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModelTest.kt @@ -20,6 +20,7 @@ import android.hardware.biometrics.PromptInfo import android.hardware.face.FaceSensorPropertiesInternal import android.hardware.fingerprint.FingerprintSensorPropertiesInternal import android.view.HapticFeedbackConstants +import android.view.MotionEvent import androidx.test.filters.SmallTest import com.android.internal.widget.LockPatternUtils import com.android.systemui.SysuiTestCase @@ -500,6 +501,81 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa } @Test + fun auto_confirm_authentication_when_finger_down() = runGenericTest { + val expectConfirmation = testCase.expectConfirmation(atLeastOneFailure = false) + + // No icon button when face only, can't confirm before auth + if (!testCase.isFaceOnly) { + viewModel.onOverlayTouch(obtainMotionEvent(MotionEvent.ACTION_DOWN)) + } + viewModel.showAuthenticated(testCase.authenticatedModality, 0) + + val authenticating by collectLastValue(viewModel.isAuthenticating) + val authenticated by collectLastValue(viewModel.isAuthenticated) + val message by collectLastValue(viewModel.message) + val size by collectLastValue(viewModel.size) + val legacyState by collectLastValue(viewModel.legacyState) + val canTryAgain by collectLastValue(viewModel.canTryAgainNow) + + assertThat(authenticating).isFalse() + assertThat(canTryAgain).isFalse() + assertThat(authenticated?.isAuthenticated).isTrue() + + if (testCase.isFaceOnly && expectConfirmation) { + assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_PENDING_CONFIRMATION) + + assertThat(size).isEqualTo(PromptSize.MEDIUM) + assertButtonsVisible( + cancel = true, + confirm = true, + ) + + viewModel.confirmAuthenticated() + assertThat(message).isEqualTo(PromptMessage.Empty) + assertButtonsVisible() + } else { + assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_AUTHENTICATED) + } + } + + @Test + fun cannot_auto_confirm_authentication_when_finger_up() = runGenericTest { + val expectConfirmation = testCase.expectConfirmation(atLeastOneFailure = false) + + // No icon button when face only, can't confirm before auth + if (!testCase.isFaceOnly) { + viewModel.onOverlayTouch(obtainMotionEvent(MotionEvent.ACTION_DOWN)) + viewModel.onOverlayTouch(obtainMotionEvent(MotionEvent.ACTION_UP)) + } + viewModel.showAuthenticated(testCase.authenticatedModality, 0) + + val authenticating by collectLastValue(viewModel.isAuthenticating) + val authenticated by collectLastValue(viewModel.isAuthenticated) + val message by collectLastValue(viewModel.message) + val size by collectLastValue(viewModel.size) + val legacyState by collectLastValue(viewModel.legacyState) + val canTryAgain by collectLastValue(viewModel.canTryAgainNow) + + assertThat(authenticated?.needsUserConfirmation).isEqualTo(expectConfirmation) + if (expectConfirmation) { + assertThat(size).isEqualTo(PromptSize.MEDIUM) + assertButtonsVisible( + cancel = true, + confirm = true, + ) + + viewModel.confirmAuthenticated() + assertThat(message).isEqualTo(PromptMessage.Empty) + assertButtonsVisible() + } + + assertThat(authenticating).isFalse() + assertThat(authenticated?.isAuthenticated).isTrue() + assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_AUTHENTICATED) + assertThat(canTryAgain).isFalse() + } + + @Test fun cannot_confirm_unless_authenticated() = runGenericTest { val authenticating by collectLastValue(viewModel.isAuthenticating) val authenticated by collectLastValue(viewModel.isAuthenticated) @@ -679,6 +755,10 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa testScope.runTest { block() } } + /** Obtain a MotionEvent with the specified MotionEvent action constant */ + private fun obtainMotionEvent(action: Int): MotionEvent = + MotionEvent.obtain(0, 0, action, 0f, 0f, 0) + companion object { @JvmStatic @Parameterized.Parameters(name = "{0}") diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java index a89214fdd1c0..f73804dbc349 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java @@ -221,7 +221,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { mNotificationShadeWindowController = new NotificationShadeWindowControllerImpl(mContext, mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController, mConfigurationController, mViewMediator, mKeyguardBypassController, - mColorExtractor, mDumpManager, mKeyguardStateController, + mUiBgExecutor, mColorExtractor, mDumpManager, mKeyguardStateController, mScreenOffAnimationController, mAuthController, mShadeExpansionStateManager, mShadeWindowLogger); mFeatureFlags = new FakeFeatureFlags(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowControllerImplTest.java index cde6ac08d5fd..c10333d7e604 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowControllerImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowControllerImplTest.java @@ -62,6 +62,8 @@ import com.android.systemui.statusbar.phone.ScrimController; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.KeyguardStateController; +import com.google.common.util.concurrent.MoreExecutors; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -72,6 +74,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; import java.util.List; +import java.util.concurrent.Executor; @RunWith(AndroidTestingRunner.class) @RunWithLooper @@ -97,6 +100,7 @@ public class NotificationShadeWindowControllerImplTest extends SysuiTestCase { @Mock private ShadeWindowLogger mShadeWindowLogger; @Captor private ArgumentCaptor<WindowManager.LayoutParams> mLayoutParameters; @Captor private ArgumentCaptor<StatusBarStateController.StateListener> mStateListener; + private final Executor mBackgroundExecutor = MoreExecutors.directExecutor(); private NotificationShadeWindowControllerImpl mNotificationShadeWindowController; private float mPreferredRefreshRate = -1; @@ -117,7 +121,7 @@ public class NotificationShadeWindowControllerImplTest extends SysuiTestCase { mNotificationShadeWindowController = new NotificationShadeWindowControllerImpl(mContext, mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController, mConfigurationController, mKeyguardViewMediator, mKeyguardBypassController, - mColorExtractor, mDumpManager, mKeyguardStateController, + mBackgroundExecutor, mColorExtractor, mDumpManager, mKeyguardStateController, mScreenOffAnimationController, mAuthController, mShadeExpansionStateManager, mShadeWindowLogger) { @Override diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java index e10a80cce793..0c69e3b76126 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java @@ -333,7 +333,7 @@ public class BubblesTest extends SysuiTestCase { mNotificationShadeWindowController = new NotificationShadeWindowControllerImpl(mContext, mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController, mConfigurationController, mKeyguardViewMediator, mKeyguardBypassController, - mColorExtractor, mDumpManager, mKeyguardStateController, + syncExecutor, mColorExtractor, mDumpManager, mKeyguardStateController, mScreenOffAnimationController, mAuthController, mShadeExpansionStateManager, mShadeWindowLogger); mNotificationShadeWindowController.setWindowRootView(mNotificationShadeWindowView); diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java index dd434fbeecb4..3e4dd1637387 100644 --- a/services/core/java/com/android/server/pm/ShortcutService.java +++ b/services/core/java/com/android/server/pm/ShortcutService.java @@ -3611,8 +3611,8 @@ public class ShortcutService extends IShortcutService.Stub { // Otherwise check persisted shortcuts getShortcutInfoAsync(launcherUserId, packageName, shortcutId, userId, si -> { - cb.complete(getShortcutIconUriInternal(launcherUserId, launcherPackage, - packageName, si, userId)); + cb.complete(si == null ? null : getShortcutIconUriInternal(launcherUserId, + launcherPackage, packageName, si, userId)); }); } diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 412bc8134c91..4c58e23d6678 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -225,7 +225,6 @@ import static com.android.server.wm.IdentifierProto.USER_ID; import static com.android.server.wm.LetterboxConfiguration.DEFAULT_LETTERBOX_ASPECT_RATIO_FOR_MULTI_WINDOW; import static com.android.server.wm.LetterboxConfiguration.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO; import static com.android.server.wm.StartingData.AFTER_TRANSACTION_COPY_TO_CLIENT; -import static com.android.server.wm.StartingData.AFTER_TRANSACTION_IDLE; import static com.android.server.wm.StartingData.AFTER_TRANSACTION_REMOVE_DIRECTLY; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_PREDICT_BACK; @@ -2860,7 +2859,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } else if (lastData.mRemoveAfterTransaction == AFTER_TRANSACTION_COPY_TO_CLIENT) { removeStartingWindow(); } - lastData.mRemoveAfterTransaction = AFTER_TRANSACTION_IDLE; } void removeStartingWindowAnimation(boolean prepareAnimation) { diff --git a/services/core/java/com/android/server/wm/StartingData.java b/services/core/java/com/android/server/wm/StartingData.java index a23547ef1d5b..2d281c476ec2 100644 --- a/services/core/java/com/android/server/wm/StartingData.java +++ b/services/core/java/com/android/server/wm/StartingData.java @@ -76,7 +76,7 @@ public abstract class StartingData { * This starting window should be removed after applying the start transaction of transition, * which ensures the app window has shown. */ - @AfterTransaction int mRemoveAfterTransaction; + @AfterTransaction int mRemoveAfterTransaction = AFTER_TRANSACTION_IDLE; /** Whether to prepare the removal animation. */ boolean mPrepareRemoveAnimation; diff --git a/services/core/java/com/android/server/wm/Transition.java b/services/core/java/com/android/server/wm/Transition.java index 44632c910a6e..c49a1d0bf19d 100644 --- a/services/core/java/com/android/server/wm/Transition.java +++ b/services/core/java/com/android/server/wm/Transition.java @@ -1127,6 +1127,9 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener { // though, notify the controller to prevent degenerate cases. if (!r.isVisibleRequested()) { mController.mValidateCommitVis.add(r); + } else { + // Make sure onAppTransitionFinished can be notified. + mParticipants.add(r); } return; } diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java index 31afcbf26220..4d7335873074 100644 --- a/services/core/java/com/android/server/wm/WindowToken.java +++ b/services/core/java/com/android/server/wm/WindowToken.java @@ -519,7 +519,8 @@ class WindowToken extends WindowContainer<WindowState> { for (int i = mFixedRotationTransformState.mAssociatedTokens.size() - 1; i >= 0; i--) { final ActivityRecord r = mFixedRotationTransformState.mAssociatedTokens.get(i).asActivityRecord(); - if (r != null && r.isInTransition()) { + // Only care about the transition at Activity/Task level. + if (r != null && r.inTransitionSelfOrParent() && !r.mDisplayContent.inTransition()) { return true; } } 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 9cc4117db0bb..9b22efdae7da 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -1703,14 +1703,17 @@ public class DisplayContentTests extends WindowTestsBase { final Task task = app.getTask(); final ActivityRecord app2 = new ActivityBuilder(mWm.mAtmService).setTask(task).build(); mDisplayContent.setFixedRotationLaunchingApp(app2, (mDisplayContent.getRotation() + 1) % 4); - doReturn(true).when(app).isInTransition(); + doReturn(true).when(app).inTransitionSelfOrParent(); // If the task contains a transition, this should be no-op. mDisplayContent.mFixedRotationTransitionListener.onAppTransitionFinishedLocked(app.token); assertTrue(app2.hasFixedRotationTransform()); assertTrue(mDisplayContent.hasTopFixedRotationLaunchingApp()); - doReturn(false).when(app).isInTransition(); + // The display should be unlikely to be in transition, but if it happens, the fixed + // rotation should proceed to finish because the activity/task level transition is finished. + doReturn(true).when(mDisplayContent).inTransition(); + doReturn(false).when(app).inTransitionSelfOrParent(); // Although this notifies app instead of app2 that uses the fixed rotation, app2 should // still finish the transform because there is no more transition event. mDisplayContent.mFixedRotationTransitionListener.onAppTransitionFinishedLocked(app.token); diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java index 3703349b8d7e..60d640c71d3a 100644 --- a/telephony/java/android/telephony/CarrierConfigManager.java +++ b/telephony/java/android/telephony/CarrierConfigManager.java @@ -1992,7 +1992,7 @@ public class CarrierConfigManager { "lte_plus_threshold_bandwidth_khz_int"; /** - * The combined channel bandwidth threshold (non-inclusive) in KHz required to display the + * The combined channel bandwidth threshold (inclusive) in KHz required to display the * NR advanced (i.e. 5G+) data icon. It is 0 by default, meaning minimum bandwidth check is * not enabled. Other factors like bands or frequency can also determine whether the NR * advanced data icon is shown or not. diff --git a/wifi/java/src/android/net/wifi/nl80211/InstantWifi.java b/wifi/java/src/android/net/wifi/nl80211/InstantWifi.java new file mode 100644 index 000000000000..433e88c58851 --- /dev/null +++ b/wifi/java/src/android/net/wifi/nl80211/InstantWifi.java @@ -0,0 +1,318 @@ +/* + * 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 android.net.wifi.nl80211; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.app.AlarmManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.ConnectivityManager; +import android.net.ConnectivityManager.NetworkCallback; +import android.net.Network; +import android.net.NetworkCapabilities; +import android.net.NetworkRequest; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Handler; +import android.os.PowerManager; +import android.os.SystemClock; +import android.util.Log; + +import com.android.internal.annotations.VisibleForTesting; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; + +/** + * @hide + */ +public class InstantWifi { + private static final String INSTANT_WIFI_TAG = "InstantWifi"; + private static final int OVERRIDED_SCAN_CONNECTION_TIMEOUT_MS = 1000; + private static final int WIFI_NETWORK_EXPIRED_MS = 7 * 24 * 60 * 60 * 1000; // a week + private static final String NO_CONNECTION_TIMEOUT_ALARM_TAG = + INSTANT_WIFI_TAG + " No Connection Timeout"; + + private Context mContext; + private AlarmManager mAlarmManager; + private Handler mEventHandler; + private ConnectivityManager mConnectivityManager; + private WifiManager mWifiManager; + private PowerManager mPowerManager; + private long mLastWifiOnSinceBootMs; + private long mLastScreenOnSinceBootMs; + private boolean mIsWifiConnected = false; + private boolean mScreenOn = false; + private boolean mWifiEnabled = false; + private boolean mIsNoConnectionAlarmSet = false; + private ArrayList<WifiNetwork> mConnectedWifiNetworkList = new ArrayList<>(); + private AlarmManager.OnAlarmListener mNoConnectionTimeoutCallback = + new AlarmManager.OnAlarmListener() { + public void onAlarm() { + Log.i(INSTANT_WIFI_TAG, "Timed out waiting for wifi connection"); + mIsNoConnectionAlarmSet = false; + mWifiManager.startScan(); + } + }; + + public InstantWifi(Context context, AlarmManager alarmManager, Handler eventHandler) { + mContext = context; + mAlarmManager = alarmManager; + mEventHandler = eventHandler; + mWifiManager = mContext.getSystemService(WifiManager.class); + mConnectivityManager = mContext.getSystemService(ConnectivityManager.class); + mConnectivityManager.registerNetworkCallback( + new NetworkRequest.Builder() + .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) + .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) + .build(), new WifiNetworkCallback()); + // System power service was initialized before wifi nl80211 service. + mPowerManager = mContext.getSystemService(PowerManager.class); + IntentFilter screenEventfilter = new IntentFilter(); + screenEventfilter.addAction(Intent.ACTION_SCREEN_ON); + screenEventfilter.addAction(Intent.ACTION_SCREEN_OFF); + mContext.registerReceiver( + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action.equals(Intent.ACTION_SCREEN_ON)) { + if (!mScreenOn) { + mLastScreenOnSinceBootMs = getMockableElapsedRealtime(); + } + mScreenOn = true; + } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { + mScreenOn = false; + } + Log.d(INSTANT_WIFI_TAG, "mScreenOn is changed to " + mScreenOn); + } + }, screenEventfilter, null, mEventHandler); + mScreenOn = mPowerManager.isInteractive(); + mContext.registerReceiver( + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, + WifiManager.WIFI_STATE_UNKNOWN); + mWifiEnabled = state == WifiManager.WIFI_STATE_ENABLED; + if (mWifiEnabled) { + mLastWifiOnSinceBootMs = getMockableElapsedRealtime(); + } + Log.d(INSTANT_WIFI_TAG, "mWifiEnabled is changed to " + mWifiEnabled); + } + }, + new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION), + null, mEventHandler); + } + + @VisibleForTesting + protected long getMockableElapsedRealtime() { + return SystemClock.elapsedRealtime(); + } + + private class WifiNetwork { + private final int mNetId; + private Set<Integer> mConnectedFrequencies = new HashSet<Integer>(); + private int[] mLastTwoConnectedFrequencies = new int[2]; + private long mLastConnectedTimeMillis; + WifiNetwork(int netId) { + mNetId = netId; + } + + public int getNetId() { + return mNetId; + } + + public boolean addConnectedFrequency(int channelFrequency) { + mLastConnectedTimeMillis = getMockableElapsedRealtime(); + if (mLastTwoConnectedFrequencies[0] != channelFrequency + && mLastTwoConnectedFrequencies[1] != channelFrequency) { + mLastTwoConnectedFrequencies[0] = mLastTwoConnectedFrequencies[1]; + mLastTwoConnectedFrequencies[1] = channelFrequency; + } + return mConnectedFrequencies.add(channelFrequency); + } + + public Set<Integer> getConnectedFrequencies() { + return mConnectedFrequencies; + } + + public int[] getLastTwoConnectedFrequencies() { + if ((getMockableElapsedRealtime() - mLastConnectedTimeMillis) + > WIFI_NETWORK_EXPIRED_MS) { + return new int[0]; + } + return mLastTwoConnectedFrequencies; + } + + public long getLastConnectedTimeMillis() { + return mLastConnectedTimeMillis; + } + } + + private class WifiNetworkCallback extends NetworkCallback { + @Override + public void onAvailable(@NonNull Network network) { + } + + @Override + public void onCapabilitiesChanged(Network network, + NetworkCapabilities networkCapabilities) { + if (networkCapabilities != null && network != null) { + WifiInfo wifiInfo = (WifiInfo) networkCapabilities.getTransportInfo(); + if (wifiInfo == null || mWifiManager == null) { + return; + } + WifiConfiguration config = mWifiManager.getPrivilegedConnectedNetwork(); + if (config == null) { + return; + } + final int currentNetworkId = config.networkId; + final int connectecFrequency = wifiInfo.getFrequency(); + if (connectecFrequency < 0 || currentNetworkId < 0) { + return; + } + mIsWifiConnected = true; + if (mIsNoConnectionAlarmSet) { + mAlarmManager.cancel(mNoConnectionTimeoutCallback); + } + Log.d(INSTANT_WIFI_TAG, "Receive Wifi is connected, freq = " + connectecFrequency + + " and currentNetworkId : " + currentNetworkId + + ", wifiinfo = " + wifiInfo); + boolean isExist = false; + for (WifiNetwork wifiNetwork : mConnectedWifiNetworkList) { + if (wifiNetwork.getNetId() == currentNetworkId) { + if (wifiNetwork.addConnectedFrequency(connectecFrequency)) { + Log.d(INSTANT_WIFI_TAG, "Update connected frequency: " + + connectecFrequency + " to Network currentNetworkId : " + + currentNetworkId); + } + isExist = true; + } + } + if (!isExist) { + WifiNetwork currentNetwork = new WifiNetwork(currentNetworkId); + currentNetwork.addConnectedFrequency(connectecFrequency); + if (mConnectedWifiNetworkList.size() < 5) { + mConnectedWifiNetworkList.add(currentNetwork); + } else { + ArrayList<WifiNetwork> lastConnectedWifiNetworkList = new ArrayList<>(); + WifiNetwork legacyNetwork = mConnectedWifiNetworkList.get(0); + for (WifiNetwork connectedNetwork : mConnectedWifiNetworkList) { + if (connectedNetwork.getNetId() == legacyNetwork.getNetId()) { + continue; + } + // Keep the used recently network in the last connected list + if (connectedNetwork.getLastConnectedTimeMillis() + > legacyNetwork.getLastConnectedTimeMillis()) { + lastConnectedWifiNetworkList.add(connectedNetwork); + } else { + lastConnectedWifiNetworkList.add(legacyNetwork); + legacyNetwork = connectedNetwork; + } + } + mConnectedWifiNetworkList = lastConnectedWifiNetworkList; + } + } + } + } + + @Override + public void onLost(@NonNull Network network) { + mIsWifiConnected = false; + } + } + + /** + * Returns whether or not the scan freqs should be overrided by using predicted channels. + */ + public boolean isUsePredictedScanningChannels() { + if (mIsWifiConnected || mConnectedWifiNetworkList.size() == 0 + || !mWifiManager.isWifiEnabled() || !mPowerManager.isInteractive()) { + return false; + } + if (!mWifiEnabled || !mScreenOn) { + Log.d(INSTANT_WIFI_TAG, "WiFi/Screen State mis-match, run instant Wifi anyway!"); + return true; + } + return (((getMockableElapsedRealtime() - mLastWifiOnSinceBootMs) + < OVERRIDED_SCAN_CONNECTION_TIMEOUT_MS) + || ((getMockableElapsedRealtime() - mLastScreenOnSinceBootMs) + < OVERRIDED_SCAN_CONNECTION_TIMEOUT_MS)); + } + + /** + * Overrides the frequenies in SingleScanSetting + * + * @param settings the SingleScanSettings will be overrided. + * @param freqs new frequencies of SingleScanSettings + */ + @Nullable + public void overrideFreqsForSingleScanSettingsIfNecessary( + @Nullable SingleScanSettings settings, @Nullable Set<Integer> freqs) { + if (!isUsePredictedScanningChannels() || settings == null || freqs == null + || freqs.size() == 0) { + return; + } + if (settings.channelSettings == null) { + settings.channelSettings = new ArrayList<>(); + } else { + settings.channelSettings.clear(); + } + for (int freq : freqs) { + if (freq > 0) { + ChannelSettings channel = new ChannelSettings(); + channel.frequency = freq; + settings.channelSettings.add(channel); + } + } + // Monitor connection after last override scan request. + if (mIsNoConnectionAlarmSet) { + mAlarmManager.cancel(mNoConnectionTimeoutCallback); + } + mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, + getMockableElapsedRealtime() + OVERRIDED_SCAN_CONNECTION_TIMEOUT_MS, + NO_CONNECTION_TIMEOUT_ALARM_TAG, mNoConnectionTimeoutCallback, mEventHandler); + mIsNoConnectionAlarmSet = true; + } + + /** + * Returns the predicted scanning chcnnels set. + */ + @NonNull + public Set<Integer> getPredictedScanningChannels() { + Set<Integer> predictedScanChannels = new HashSet<>(); + if (!isUsePredictedScanningChannels()) { + Log.d(INSTANT_WIFI_TAG, "Drop, size: " + mConnectedWifiNetworkList.size()); + return predictedScanChannels; + } + for (WifiNetwork network : mConnectedWifiNetworkList) { + for (int connectedFrequency : network.getLastTwoConnectedFrequencies()) { + if (connectedFrequency > 0) { + predictedScanChannels.add(connectedFrequency); + Log.d(INSTANT_WIFI_TAG, "Add channel: " + connectedFrequency + + " to predicted channel"); + } + } + } + return predictedScanChannels; + } +} diff --git a/wifi/java/src/android/net/wifi/nl80211/WifiNl80211Manager.java b/wifi/java/src/android/net/wifi/nl80211/WifiNl80211Manager.java index 2a199d27a60e..ca12c4cb2020 100644 --- a/wifi/java/src/android/net/wifi/nl80211/WifiNl80211Manager.java +++ b/wifi/java/src/android/net/wifi/nl80211/WifiNl80211Manager.java @@ -105,6 +105,8 @@ public class WifiNl80211Manager { // Cached wificond binder handlers. private IWificond mWificond; + private Context mContext; + private InstantWifi mInstantWifi; private WificondEventHandler mWificondEventHandler = new WificondEventHandler(); private HashMap<String, IClientInterface> mClientInterfaces = new HashMap<>(); private HashMap<String, IApInterface> mApInterfaces = new HashMap<>(); @@ -174,6 +176,12 @@ public class WifiNl80211Manager { /** @hide */ @VisibleForTesting + protected InstantWifi getInstantWifiMockable() { + return mInstantWifi; + } + + /** @hide */ + @VisibleForTesting public class WificondEventHandler extends IWificondEventCallback.Stub { private Map<CountryCodeChangedListener, Executor> mCountryCodeChangedListenerHolder = new HashMap<>(); @@ -419,6 +427,7 @@ public class WifiNl80211Manager { public WifiNl80211Manager(Context context) { mAlarmManager = context.getSystemService(AlarmManager.class); mEventHandler = new Handler(context.getMainLooper()); + mContext = context; } /** @@ -434,6 +443,7 @@ public class WifiNl80211Manager { if (mWificond == null) { Log.e(TAG, "Failed to get reference to wificond"); } + mContext = context; } /** @hide */ @@ -441,6 +451,7 @@ public class WifiNl80211Manager { public WifiNl80211Manager(Context context, IWificond wificond) { this(context); mWificond = wificond; + mContext = context; } /** @hide */ @@ -744,6 +755,9 @@ public class WifiNl80211Manager { Log.e(TAG, "Failed to refresh wificond scanner due to remote exception"); } + if (getInstantWifiMockable() == null) { + mInstantWifi = new InstantWifi(mContext, mAlarmManager, mEventHandler); + } return true; } @@ -1071,6 +1085,10 @@ public class WifiNl80211Manager { if (settings == null) { return false; } + if (getInstantWifiMockable() != null) { + getInstantWifiMockable().overrideFreqsForSingleScanSettingsIfNecessary(settings, + getInstantWifiMockable().getPredictedScanningChannels()); + } try { return scannerImpl.scan(settings); } catch (RemoteException e1) { @@ -1115,6 +1133,10 @@ public class WifiNl80211Manager { if (settings == null) { return WifiScanner.REASON_INVALID_ARGS; } + if (getInstantWifiMockable() != null) { + getInstantWifiMockable().overrideFreqsForSingleScanSettingsIfNecessary(settings, + getInstantWifiMockable().getPredictedScanningChannels()); + } try { int status = scannerImpl.scanRequest(settings); return toFrameworkScanStatusCode(status); diff --git a/wifi/tests/src/android/net/wifi/nl80211/InstantWifiTest.java b/wifi/tests/src/android/net/wifi/nl80211/InstantWifiTest.java new file mode 100644 index 000000000000..ebff0e28082e --- /dev/null +++ b/wifi/tests/src/android/net/wifi/nl80211/InstantWifiTest.java @@ -0,0 +1,256 @@ +/* + * 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 android.net.wifi.nl80211; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.anyLong; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.app.AlarmManager; +import android.app.test.TestAlarmManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.ConnectivityManager; +import android.net.ConnectivityManager.NetworkCallback; +import android.net.Network; +import android.net.NetworkCapabilities; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Handler; +import android.os.IPowerManager; +import android.os.IThermalService; +import android.os.PowerManager; +import android.os.test.TestLooper; + +import androidx.test.filters.SmallTest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.HashSet; +import java.util.Set; + +/** + * Unit tests for {@link android.net.wifi.nl80211.InstantWifi}. + */ +@SmallTest +public class InstantWifiTest { + @Mock private Context mContext; + @Mock private ConnectivityManager mMockConnectivityManager; + @Mock private WifiManager mMockWifiManager; + @Mock private Network mMockWifiNetwork; + @Mock private WifiInfo mMockWifiInfo; + @Mock private WifiConfiguration mMockWifiConfiguration; + @Mock private IPowerManager mPowerManagerService; + private InstantWifi mInstantWifi; + private TestLooper mLooper; + private Handler mHandler; + private TestAlarmManager mTestAlarmManager; + private AlarmManager mAlarmManager; + private PowerManager mMockPowerManager; + + private final ArgumentCaptor<NetworkCallback> mWifiNetworkCallbackCaptor = + ArgumentCaptor.forClass(NetworkCallback.class); + private final ArgumentCaptor<BroadcastReceiver> mScreenBroadcastReceiverCaptor = + ArgumentCaptor.forClass(BroadcastReceiver.class); + private final ArgumentCaptor<BroadcastReceiver> mWifiStateBroadcastReceiverCaptor = + ArgumentCaptor.forClass(BroadcastReceiver.class); + + private static final int TEST_NETWORK_ID = 1; + private static final int TEST_24G_FREQUENCY = 2412; + private static final int TEST_5G_FREQUENCY = 5745; + private long mTimeOffsetMs = 0; + + private class InstantWifiSpy extends InstantWifi { + InstantWifiSpy(Context context, AlarmManager alarmManager, Handler handler) { + super(context, alarmManager, handler); + } + + @Override + protected long getMockableElapsedRealtime() { + return mTimeOffsetMs; + } + } + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + + mLooper = new TestLooper(); + mHandler = new Handler(mLooper.getLooper()); + + mTestAlarmManager = new TestAlarmManager(); + mAlarmManager = mTestAlarmManager.getAlarmManager(); + when(mContext.getSystemServiceName(AlarmManager.class)).thenReturn(Context.ALARM_SERVICE); + when(mContext.getSystemService(AlarmManager.class)).thenReturn(mAlarmManager); + when(mContext.getSystemServiceName(WifiManager.class)).thenReturn(Context.WIFI_SERVICE); + when(mContext.getSystemService(WifiManager.class)).thenReturn(mMockWifiManager); + when(mContext.getSystemServiceName(ConnectivityManager.class)) + .thenReturn(Context.CONNECTIVITY_SERVICE); + when(mContext.getSystemService(ConnectivityManager.class)) + .thenReturn(mMockConnectivityManager); + mMockPowerManager = new PowerManager(mContext, mPowerManagerService, + mock(IThermalService.class), mHandler); + when(mContext.getSystemServiceName(PowerManager.class)).thenReturn(Context.POWER_SERVICE); + when(mContext.getSystemService(PowerManager.class)).thenReturn(mMockPowerManager); + when(mPowerManagerService.isInteractive()).thenReturn(true); + + doReturn(mMockWifiInfo).when(mMockWifiInfo).makeCopy(anyLong()); + mTimeOffsetMs = 0; + mInstantWifi = new InstantWifiSpy(mContext, mAlarmManager, mHandler); + verifyInstantWifiInitialization(); + } + + private void verifyInstantWifiInitialization() { + verify(mMockConnectivityManager).registerNetworkCallback(any(), + mWifiNetworkCallbackCaptor.capture()); + verify(mContext).registerReceiver(mScreenBroadcastReceiverCaptor.capture(), + argThat((IntentFilter filter) -> + filter.hasAction(Intent.ACTION_SCREEN_ON) + && filter.hasAction(Intent.ACTION_SCREEN_OFF)), eq(null), any()); + + verify(mContext).registerReceiver(mWifiStateBroadcastReceiverCaptor.capture(), + argThat((IntentFilter filter) -> + filter.hasAction(WifiManager.WIFI_STATE_CHANGED_ACTION)), eq(null), any()); + } + + private void mockWifiConnectedEvent(int networkId, int connectedFrequency) { + // Send wifi connected event + NetworkCapabilities mockWifiNetworkCapabilities = + new NetworkCapabilities.Builder().setTransportInfo(mMockWifiInfo).build(); + mMockWifiConfiguration.networkId = networkId; + when(mMockWifiManager.getPrivilegedConnectedNetwork()).thenReturn(mMockWifiConfiguration); + when(mMockWifiInfo.getFrequency()).thenReturn(connectedFrequency); + mWifiNetworkCallbackCaptor.getValue().onCapabilitiesChanged(mMockWifiNetwork, + mockWifiNetworkCapabilities); + mLooper.dispatchAll(); + } + + private void mockWifiOnScreenOnBroadcast(boolean isWifiOn, boolean isScreenOn) + throws Exception { + // Send Wifi On broadcast + Intent wifiOnIntent = new Intent(WifiManager.WIFI_STATE_CHANGED_ACTION); + wifiOnIntent.putExtra(WifiManager.EXTRA_WIFI_STATE, + isWifiOn ? WifiManager.WIFI_STATE_ENABLED : WifiManager.WIFI_STATE_DISABLED); + mWifiStateBroadcastReceiverCaptor.getValue().onReceive(mContext, wifiOnIntent); + mLooper.dispatchAll(); + // Send Screen On broadcast + Intent screenOnIntent = + new Intent(isScreenOn ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF); + mScreenBroadcastReceiverCaptor.getValue().onReceive(mContext, screenOnIntent); + mLooper.dispatchAll(); + when(mMockWifiManager.isWifiEnabled()).thenReturn(isWifiOn); + when(mPowerManagerService.isInteractive()).thenReturn(isScreenOn); + } + + @Test + public void testisUsePredictedScanningChannels() throws Exception { + assertFalse(mInstantWifi.isUsePredictedScanningChannels()); + mockWifiOnScreenOnBroadcast(true /* isWifiOn */, false /* isScreenOn */); + assertFalse(mInstantWifi.isUsePredictedScanningChannels()); + mockWifiOnScreenOnBroadcast(false /* isWifiOn */, true /* isScreenOn */); + assertFalse(mInstantWifi.isUsePredictedScanningChannels()); + mockWifiOnScreenOnBroadcast(true /* isWifiOn */, true /* isScreenOn */); + assertFalse(mInstantWifi.isUsePredictedScanningChannels()); + // Send wifi connected event + mockWifiConnectedEvent(TEST_NETWORK_ID, TEST_24G_FREQUENCY); + assertFalse(mInstantWifi.isUsePredictedScanningChannels()); + // Send wifi disconnect + mWifiNetworkCallbackCaptor.getValue().onLost(mMockWifiNetwork); + assertTrue(mInstantWifi.isUsePredictedScanningChannels()); + // Shift time to make it expired + mTimeOffsetMs = 1100; + assertFalse(mInstantWifi.isUsePredictedScanningChannels()); + } + + @Test + public void testGetPredictedScanningChannels() throws Exception { + mockWifiOnScreenOnBroadcast(true /* isWifiOn */, true /* isScreenOn */); + // Send wifi connected event on T0 + mockWifiConnectedEvent(TEST_NETWORK_ID, TEST_24G_FREQUENCY); + // Send wifi disconnect + mWifiNetworkCallbackCaptor.getValue().onLost(mMockWifiNetwork); + assertTrue(mInstantWifi.isUsePredictedScanningChannels()); + assertTrue(mInstantWifi.getPredictedScanningChannels().contains(TEST_24G_FREQUENCY)); + mTimeOffsetMs += 1000; // T1 = 1000 ms + // Send wifi connected event + mockWifiConnectedEvent(TEST_NETWORK_ID + 1, TEST_5G_FREQUENCY); + // Send wifi disconnect + mWifiNetworkCallbackCaptor.getValue().onLost(mMockWifiNetwork); + // isUsePredictedScanningChannels is false since wifi on & screen on is expired + assertFalse(mInstantWifi.isUsePredictedScanningChannels()); + // Override the Wifi On & Screen on time + mockWifiOnScreenOnBroadcast(true /* isWifiOn */, true /* isScreenOn */); + assertTrue(mInstantWifi.getPredictedScanningChannels().contains(TEST_5G_FREQUENCY)); + mTimeOffsetMs += 7 * 24 * 60 * 60 * 1000; // Make T0 expired + // Override the Wifi On & Screen on time + mockWifiOnScreenOnBroadcast(true /* isWifiOn */, true /* isScreenOn */); + assertFalse(mInstantWifi.getPredictedScanningChannels().contains(TEST_24G_FREQUENCY)); + assertTrue(mInstantWifi.getPredictedScanningChannels().contains(TEST_5G_FREQUENCY)); + } + + @Test + public void testOverrideFreqsForSingleScanSettings() throws Exception { + mockWifiOnScreenOnBroadcast(true /* isWifiOn */, true /* isScreenOn */); + // Send wifi connected event + mockWifiConnectedEvent(TEST_NETWORK_ID, TEST_24G_FREQUENCY); + assertFalse(mInstantWifi.isUsePredictedScanningChannels()); + // Send wifi disconnect + mWifiNetworkCallbackCaptor.getValue().onLost(mMockWifiNetwork); + assertTrue(mInstantWifi.isUsePredictedScanningChannels()); + + final ArgumentCaptor<AlarmManager.OnAlarmListener> alarmListenerCaptor = + ArgumentCaptor.forClass(AlarmManager.OnAlarmListener.class); + doNothing().when(mAlarmManager).set(anyInt(), anyLong(), any(), + alarmListenerCaptor.capture(), any()); + Set<Integer> testFreqs = Set.of( + TEST_24G_FREQUENCY, TEST_5G_FREQUENCY); + SingleScanSettings testSingleScanSettings = new SingleScanSettings(); + mInstantWifi.overrideFreqsForSingleScanSettingsIfNecessary( + testSingleScanSettings, new HashSet<Integer>()); + mInstantWifi.overrideFreqsForSingleScanSettingsIfNecessary( + testSingleScanSettings, null); + mInstantWifi.overrideFreqsForSingleScanSettingsIfNecessary(null, null); + verify(mAlarmManager, never()).set(anyInt(), anyLong(), any(), any(), any()); + mInstantWifi.overrideFreqsForSingleScanSettingsIfNecessary(testSingleScanSettings, + testFreqs); + verify(mAlarmManager).set(anyInt(), anyLong(), any(), any(), any()); + Set<Integer> overridedFreqs = new HashSet<Integer>(); + for (ChannelSettings channel : testSingleScanSettings.channelSettings) { + overridedFreqs.add(channel.frequency); + } + assertEquals(testFreqs, overridedFreqs); + alarmListenerCaptor.getValue().onAlarm(); + verify(mMockWifiManager).startScan(); + } +} diff --git a/wifi/tests/src/android/net/wifi/nl80211/WifiNl80211ManagerTest.java b/wifi/tests/src/android/net/wifi/nl80211/WifiNl80211ManagerTest.java index 362eb1425a30..f12818fa64f9 100644 --- a/wifi/tests/src/android/net/wifi/nl80211/WifiNl80211ManagerTest.java +++ b/wifi/tests/src/android/net/wifi/nl80211/WifiNl80211ManagerTest.java @@ -18,6 +18,7 @@ package android.net.wifi.nl80211; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -26,6 +27,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Matchers.argThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyLong; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -37,6 +39,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import android.app.AlarmManager; +import android.app.test.MockAnswerUtil.AnswerWithArguments; import android.app.test.TestAlarmManager; import android.content.Context; import android.net.MacAddress; @@ -104,6 +107,9 @@ public class WifiNl80211ManagerTest { private WifiNl80211Manager.CountryCodeChangedListener mCountryCodeChangedListener2; @Mock private Context mContext; + @Mock + private InstantWifi mMockInstantWifi; + private TestLooper mLooper; private TestAlarmManager mTestAlarmManager; private AlarmManager mAlarmManager; @@ -167,6 +173,17 @@ public class WifiNl80211ManagerTest { 0x00, 0x00 }; + private class WifiNl80211ManagerSpy extends WifiNl80211Manager { + WifiNl80211ManagerSpy(Context context, IWificond wificond) { + super(context, wificond); + } + + @Override + protected InstantWifi getInstantWifiMockable() { + return mMockInstantWifi; + } + } + @Before public void setUp() throws Exception { // Setup mocks for successful WificondControl operation. Failure case mocks should be @@ -181,6 +198,8 @@ public class WifiNl80211ManagerTest { mLooper = new TestLooper(); when(mContext.getMainLooper()).thenReturn(mLooper.getLooper()); + doNothing().when(mMockInstantWifi).overrideFreqsForSingleScanSettingsIfNecessary( + any(), any()); when(mWificond.asBinder()).thenReturn(mWifiCondBinder); when(mClientInterface.getWifiScannerImpl()).thenReturn(mWifiScannerImpl); when(mWificond.createClientInterface(any())).thenReturn(mClientInterface); @@ -189,7 +208,7 @@ public class WifiNl80211ManagerTest { when(mWificond.tearDownApInterface(any())).thenReturn(true); when(mClientInterface.getWifiScannerImpl()).thenReturn(mWifiScannerImpl); when(mClientInterface.getInterfaceName()).thenReturn(TEST_INTERFACE_NAME); - mWificondControl = new WifiNl80211Manager(mContext, mWificond); + mWificondControl = new WifiNl80211ManagerSpy(mContext, mWificond); mWificondEventHandler = mWificondControl.getWificondEventHandler(); assertEquals(true, mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME, Runnable::run, @@ -1159,6 +1178,40 @@ public class WifiNl80211ManagerTest { verify(mWificond).notifyCountryCodeChanged(); } + @Test + public void testInstantWifi() throws Exception { + doAnswer(new AnswerWithArguments() { + public void answer(SingleScanSettings settings, Set<Integer> freqs) { + if (settings.channelSettings == null) { + settings.channelSettings = new ArrayList<>(); + } else { + settings.channelSettings.clear(); + } + for (int freq : freqs) { + if (freq > 0) { + ChannelSettings channel = new ChannelSettings(); + channel.frequency = freq; + settings.channelSettings.add(channel); + } + } + } + }).when(mMockInstantWifi).overrideFreqsForSingleScanSettingsIfNecessary( + any(), any()); + Set<Integer> testPredictedChannelsSet = Set.of(2412, 5745); + assertNotEquals(testPredictedChannelsSet, SCAN_FREQ_SET); + when(mWifiScannerImpl.scan(any(SingleScanSettings.class))).thenReturn(true); + when(mMockInstantWifi.getPredictedScanningChannels()).thenReturn(testPredictedChannelsSet); + + // Trigger scan to check scan settings are changed + assertTrue(mWificondControl.startScan( + TEST_INTERFACE_NAME, WifiScanner.SCAN_TYPE_LOW_POWER, + SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST)); + verify(mMockInstantWifi).getPredictedScanningChannels(); + verify(mWifiScannerImpl).scan(argThat(new ScanMatcher( + IWifiScannerImpl.SCAN_TYPE_LOW_POWER, + testPredictedChannelsSet, SCAN_HIDDEN_NETWORK_SSID_LIST, false, null))); + } + // Create a ArgumentMatcher which captures a SingleScanSettings parameter and checks if it // matches the provided frequency set and ssid set. private class ScanMatcher implements ArgumentMatcher<SingleScanSettings> { |