summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chilun <chilunhuang@google.com> 2019-06-12 12:06:37 +0800
committer Chilun Huang <chilunhuang@google.com> 2019-06-14 03:07:11 +0000
commit05ff5d14872c434c6f82bdbcd6ec2aedbaad221d (patch)
tree2ba7db5cfa8e5edef9206c021f80b131635c31ac
parente252d155b13e0f63ea4d2ff148bbb74aaf7db1da (diff)
We should prevent starting home activity before setup
In original call flow, we were using startActivityAsUser, which has the check, to start home activity. In previous CL, we replaced it by mActivityTaskManagerInternal.startHomeOnDisplay but missed the check. So we need to add it back now. Also add unit tests. Bug: 134689126 Test: atest PhoneWindowManagerTests Change-Id: Icc455d5596f8d9691d61c7b8dda82016720443b7
-rw-r--r--services/core/java/com/android/server/policy/PhoneWindowManager.java5
-rw-r--r--services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java95
2 files changed, 100 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index d624a85acb6e..c31b8094602a 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -5198,6 +5198,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
awakenDreams();
}
+ if (!isUserSetupComplete()) {
+ Slog.i(TAG, "Not going home because user setup is in progress.");
+ return;
+ }
+
// Start dock.
Intent dock = createHomeDockIntent();
if (dock != null) {
diff --git a/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java b/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java
new file mode 100644
index 000000000000..fc24f5e207a8
--- /dev/null
+++ b/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.policy;
+
+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.mock;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
+
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+
+import android.app.ActivityManager;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.server.wm.ActivityTaskManagerInternal;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test class for {@link PhoneWindowManager}.
+ *
+ * Build/Install/Run:
+ * atest WmTests:PhoneWindowManagerTests
+ */
+@SmallTest
+public class PhoneWindowManagerTests {
+
+ PhoneWindowManager mPhoneWindowManager;
+
+ @Before
+ public void setUp() {
+ mPhoneWindowManager = spy(new PhoneWindowManager());
+ spyOn(ActivityManager.getService());
+ }
+
+ @After
+ public void tearDown() {
+ reset(ActivityManager.getService());
+ }
+
+ @Test
+ public void testShouldNotStartDockOrHomeWhenSetup() throws Exception {
+ mockStartDockOrHome();
+ doReturn(false).when(mPhoneWindowManager).isUserSetupComplete();
+
+ mPhoneWindowManager.startDockOrHome(
+ 0 /* displayId */, false /* fromHomeKey */, false /* awakenFromDreams */);
+
+ verify(mPhoneWindowManager, never()).createHomeDockIntent();
+ }
+
+ @Test
+ public void testShouldStartDockOrHomeAfterSetup() throws Exception {
+ mockStartDockOrHome();
+ doReturn(true).when(mPhoneWindowManager).isUserSetupComplete();
+
+ mPhoneWindowManager.startDockOrHome(
+ 0 /* displayId */, false /* fromHomeKey */, false /* awakenFromDreams */);
+
+ verify(mPhoneWindowManager).createHomeDockIntent();
+ }
+
+ private void mockStartDockOrHome() throws Exception {
+ doNothing().when(ActivityManager.getService()).stopAppSwitches();
+ ActivityTaskManagerInternal mMockActivityTaskManagerInternal =
+ mock(ActivityTaskManagerInternal.class);
+ when(mMockActivityTaskManagerInternal.startHomeOnDisplay(
+ anyInt(), anyString(), anyInt(), anyBoolean(), anyBoolean())).thenReturn(false);
+ mPhoneWindowManager.mActivityTaskManagerInternal = mMockActivityTaskManagerInternal;
+ }
+}