Merge "Delegate splash screen starting window to SystemUI(1/N)"

This commit is contained in:
Wei Sheng Shih
2020-11-11 02:30:02 +00:00
committed by Android (Google) Code Review
21 changed files with 768 additions and 55 deletions

View File

@@ -36,6 +36,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.graphics.Rect;
import android.os.Binder;
@@ -71,6 +72,8 @@ public class ShellTaskOrganizerTests {
@Mock
private ITaskOrganizerController mTaskOrganizerController;
@Mock
private Context mContext;
ShellTaskOrganizer mOrganizer;
private final SyncTransactionQueue mSyncTransactionQueue = mock(SyncTransactionQueue.class);
@@ -106,7 +109,7 @@ public class ShellTaskOrganizerTests {
.when(mTaskOrganizerController).registerTaskOrganizer(any());
} catch (RemoteException e) {}
mOrganizer = spy(new ShellTaskOrganizer(mTaskOrganizerController, mSyncTransactionQueue,
mTransactionPool, mTestExecutor, mTestExecutor));
mTransactionPool, mTestExecutor, mTestExecutor, mContext));
}
@Test

View File

@@ -0,0 +1,147 @@
/*
* Copyright (C) 2020 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 unittest.src.com.android.wm.shell.startingsurface;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.testing.TestableContext;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowMetrics;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;
import com.android.wm.shell.startingsurface.StartingSurfaceDrawer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Tests for the starting surface drawer.
*/
@SmallTest
@RunWith(AndroidJUnit4.class)
public class StartingSurfaceDrawerTests {
@Mock
private IBinder mBinder;
@Mock
private WindowManager mMockWindowManager;
TestStartingSurfaceDrawer mStartingSurfaceDrawer;
static final class TestStartingSurfaceDrawer extends StartingSurfaceDrawer{
int mAddWindowForTask = 0;
TestStartingSurfaceDrawer(Context context) {
super(context);
}
@Override
protected void postAddWindow(int taskId, IBinder appToken,
View view, WindowManager wm, WindowManager.LayoutParams params) {
// listen for addView
mAddWindowForTask = taskId;
}
@Override
protected void removeWindowSynced(int taskId) {
// listen for removeView
if (mAddWindowForTask == taskId) {
mAddWindowForTask = 0;
}
}
}
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final TestableContext context = new TestableContext(
InstrumentationRegistry.getInstrumentation().getTargetContext(), null);
final WindowManager realWindowManager = context.getSystemService(WindowManager.class);
final WindowMetrics metrics = realWindowManager.getMaximumWindowMetrics();
context.addMockSystemService(WindowManager.class, mMockWindowManager);
spyOn(context);
spyOn(realWindowManager);
try {
doReturn(context).when(context).createPackageContext(anyString(), anyInt());
} catch (PackageManager.NameNotFoundException e) {
//
}
doReturn(metrics).when(mMockWindowManager).getMaximumWindowMetrics();
doNothing().when(mMockWindowManager).addView(any(), any());
mStartingSurfaceDrawer = spy(new TestStartingSurfaceDrawer(context));
}
@Test
public void testAddSplashScreenSurface() {
final int taskId = 1;
final Handler mainLoop = new Handler(Looper.getMainLooper());
final ActivityManager.RunningTaskInfo taskInfo =
createTaskInfo(taskId, WINDOWING_MODE_FULLSCREEN);
mStartingSurfaceDrawer.addStartingWindow(taskInfo, mBinder);
waitHandlerIdle(mainLoop);
verify(mStartingSurfaceDrawer).postAddWindow(eq(taskId), eq(mBinder), any(), any(), any());
assertEquals(mStartingSurfaceDrawer.mAddWindowForTask, taskId);
mStartingSurfaceDrawer.removeStartingWindow(taskInfo);
waitHandlerIdle(mainLoop);
verify(mStartingSurfaceDrawer).removeWindowSynced(eq(taskId));
assertEquals(mStartingSurfaceDrawer.mAddWindowForTask, 0);
}
private ActivityManager.RunningTaskInfo createTaskInfo(int taskId, int windowingMode) {
ActivityManager.RunningTaskInfo taskInfo = new ActivityManager.RunningTaskInfo();
final ActivityInfo info = new ActivityInfo();
info.applicationInfo = new ApplicationInfo();
info.packageName = "test";
info.theme = android.R.style.Theme;
taskInfo.topActivityInfo = info;
taskInfo.taskId = taskId;
taskInfo.configuration.windowConfiguration.setWindowingMode(windowingMode);
return taskInfo;
}
private static void waitHandlerIdle(Handler handler) {
handler.runWithScissors(() -> { }, 0 /* timeout */);
}
}