• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.wm.shell.activityembedding;
18 
19 import static android.view.WindowManager.TRANSIT_NONE;
20 import static android.window.TransitionInfo.FLAG_FILLS_TASK;
21 import static android.window.TransitionInfo.FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY;
22 
23 import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
24 
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assume.assumeTrue;
27 import static org.mockito.Mockito.mock;
28 
29 import android.animation.Animator;
30 import android.annotation.CallSuper;
31 import android.annotation.NonNull;
32 import android.graphics.Rect;
33 import android.os.IBinder;
34 import android.view.SurfaceControl;
35 import android.view.WindowManager;
36 import android.window.TransitionInfo;
37 import android.window.WindowContainerToken;
38 
39 import com.android.wm.shell.ShellTestCase;
40 import com.android.wm.shell.sysui.ShellInit;
41 import com.android.wm.shell.transition.Transitions;
42 
43 import org.junit.Before;
44 import org.mockito.Mock;
45 import org.mockito.MockitoAnnotations;
46 
47 /** TestBase for ActivityEmbedding animation. */
48 abstract class ActivityEmbeddingAnimationTestBase extends ShellTestCase {
49 
50     @Mock
51     ShellInit mShellInit;
52 
53     @Mock
54     Transitions mTransitions;
55     @Mock
56     IBinder mTransition;
57     @Mock
58     SurfaceControl.Transaction mStartTransaction;
59     @Mock
60     SurfaceControl.Transaction mFinishTransaction;
61     @Mock
62     Animator mAnimator;
63 
64     ActivityEmbeddingController mController;
65     ActivityEmbeddingAnimationRunner mAnimRunner;
66     ActivityEmbeddingAnimationSpec mAnimSpec;
67     Transitions.TransitionFinishCallback mFinishCallback;
68 
69     @CallSuper
70     @Before
setUp()71     public void setUp() {
72         assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS);
73         MockitoAnnotations.initMocks(this);
74         mController = ActivityEmbeddingController.create(mContext, mShellInit, mTransitions);
75         assertNotNull(mController);
76         mAnimRunner = mController.mAnimationRunner;
77         assertNotNull(mAnimRunner);
78         mAnimSpec = mAnimRunner.mAnimationSpec;
79         assertNotNull(mAnimSpec);
80         mFinishCallback = (wct) -> {};
81         spyOn(mController);
82         spyOn(mAnimRunner);
83         spyOn(mAnimSpec);
84         spyOn(mFinishCallback);
85     }
86 
87     /**
88      * Creates a mock {@link TransitionInfo.Change}.
89      *
90      * @param flags the {@link TransitionInfo.ChangeFlags} of the change
91      */
createChange(@ransitionInfo.ChangeFlags int flags)92     static TransitionInfo.Change createChange(@TransitionInfo.ChangeFlags int flags) {
93         return createChange(flags, TRANSIT_NONE);
94     }
95 
96     /**
97      * Creates a mock {@link TransitionInfo.Change}.
98      *
99      * @param flags the {@link TransitionInfo.ChangeFlags} of the change
100      * @param mode the transition mode of the change
101      */
createChange(@ransitionInfo.ChangeFlags int flags, @WindowManager.TransitionType int mode)102     static TransitionInfo.Change createChange(@TransitionInfo.ChangeFlags int flags,
103             @WindowManager.TransitionType int mode) {
104         TransitionInfo.Change c = new TransitionInfo.Change(mock(WindowContainerToken.class),
105                 mock(SurfaceControl.class));
106         c.setFlags(flags);
107         c.setMode(mode);
108         return c;
109     }
110 
111     /**
112      * Creates a mock {@link TransitionInfo.Change} with
113      * {@link TransitionInfo#FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY} flag.
114      */
createEmbeddedChange(@onNull Rect startBounds, @NonNull Rect endBounds, @NonNull Rect taskBounds)115     static TransitionInfo.Change createEmbeddedChange(@NonNull Rect startBounds,
116             @NonNull Rect endBounds, @NonNull Rect taskBounds) {
117         final TransitionInfo.Change change = createChange(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY);
118         change.setStartAbsBounds(startBounds);
119         change.setEndAbsBounds(endBounds);
120         if (taskBounds.width() == startBounds.width()
121                 && taskBounds.height() == startBounds.height()
122                 && taskBounds.width() == endBounds.width()
123                 && taskBounds.height() == endBounds.height()) {
124             change.setFlags(FLAG_FILLS_TASK);
125         }
126         return change;
127     }
128 }
129