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
This commit is contained in:
Chilun
2019-06-12 12:06:37 +08:00
committed by Chilun Huang
parent e252d155b1
commit 05ff5d1487
2 changed files with 100 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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;
}
}