From 16e185e60b449958b138d52a7bdb7dea998ebb79 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 7 Nov 2017 08:30:54 -0800 Subject: [PATCH] Restore legacy recents package check to unblock quickstep development - We added a recents component to allow the development of the recents activity without exposing more privileged permissions, however, SysUI needs to point to the old activity until the new one is ready (it already has the existing priveleged permissions). For the time being, restore the original check for the recents package (to be removed immediately after we switch SysUI to launch the quickstep overview), so that we can both enable the recents component overlay (for development) without the existing recents activity going being given the wrong activity type (for now both the legacy and new recents component will have ACTIVITY_TYPE_RECENTS). - Add a sysui test to ensure that the current recents activity also has the right activity type Bug: 68774229 Test: com.android.server.am.RecentTasksTest#testRecentsComponentActivityType Test: com.android.systemui.recents.RecentsTest#testRecentsActivityType Change-Id: I4bb59efa3507d61ac86c75d3b9c80f2e32d2f7b9 --- packages/SystemUI/tests/AndroidManifest.xml | 3 + .../com/android/systemui/SysuiTestCase.java | 13 ++++ .../android/systemui/recents/RecentsTest.java | 69 +++++++++++++++++++ .../com/android/server/am/ActivityRecord.java | 5 +- 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 packages/SystemUI/tests/src/com/android/systemui/recents/RecentsTest.java diff --git a/packages/SystemUI/tests/AndroidManifest.xml b/packages/SystemUI/tests/AndroidManifest.xml index 67fae5bb0dfb8..e74736ab2fccf 100644 --- a/packages/SystemUI/tests/AndroidManifest.xml +++ b/packages/SystemUI/tests/AndroidManifest.xml @@ -43,6 +43,9 @@ + + + diff --git a/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java b/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java index 65d969932ef51..fbcbd2096db78 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java +++ b/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java @@ -23,6 +23,7 @@ import android.content.Context; import android.os.Handler; import android.os.Looper; import android.os.MessageQueue; +import android.os.ParcelFileDescriptor; import android.support.test.InstrumentationRegistry; import android.support.test.filters.SmallTest; import android.testing.LeakCheck; @@ -34,6 +35,8 @@ import org.junit.Rule; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.io.FileInputStream; +import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -84,6 +87,16 @@ public abstract class SysuiTestCase { return mContext; } + protected void runShellCommand(String command) throws IOException { + ParcelFileDescriptor pfd = mRealInstrumentation.getUiAutomation() + .executeShellCommand(command); + + // Read the input stream fully. + FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(pfd); + while (fis.read() != -1); + fis.close(); + } + protected void waitForIdleSync() { if (mHandler == null) { mHandler = new Handler(Looper.getMainLooper()); diff --git a/packages/SystemUI/tests/src/com/android/systemui/recents/RecentsTest.java b/packages/SystemUI/tests/src/com/android/systemui/recents/RecentsTest.java new file mode 100644 index 0000000000000..bdbd24418d3fd --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/recents/RecentsTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2017 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.systemui.recents; + +import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; + +import static com.android.systemui.recents.RecentsImpl.RECENTS_ACTIVITY; +import static com.android.systemui.recents.RecentsImpl.RECENTS_PACKAGE; + +import static org.junit.Assert.fail; + +import android.app.ActivityManager; +import android.app.ActivityManager.RunningTaskInfo; +import android.app.IActivityManager; +import android.os.SystemClock; +import android.support.test.filters.MediumTest; +import android.support.test.runner.AndroidJUnit4; + +import com.android.systemui.SysuiTestCase; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.List; + +@RunWith(AndroidJUnit4.class) +@MediumTest +public class RecentsTest extends SysuiTestCase { + + @Test + public void testRecentsActivityType() throws Exception { + // Clear the state + final IActivityManager am = ActivityManager.getService(); + am.removeStacksWithActivityTypes(new int[] { ACTIVITY_TYPE_RECENTS }); + + // Toggle recents, use a shell command because it is not exported + runShellCommand("am start -n " + RECENTS_PACKAGE + "/" + RECENTS_ACTIVITY); + + // Verify that an activity was launched with the right activity type + int retryCount = 0; + while (retryCount < 10) { + List tasks = am.getTasks(Integer.MAX_VALUE); + for (RunningTaskInfo info : tasks) { + if (info.configuration.windowConfiguration.getActivityType() + == ACTIVITY_TYPE_RECENTS) { + // Found a recents activity with the right activity type + return; + } + } + SystemClock.sleep(50); + retryCount++; + } + fail("Expected Recents activity with ACTIVITY_TYPE_RECENTS"); + } +} \ No newline at end of file diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index 1db262914cd1c..72120ba0d16a7 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -201,6 +201,8 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo private static final String TAG_STATES = TAG + POSTFIX_STATES; private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; + // TODO(b/67864419): Remove once recents component is overridden + private static final String LEGACY_RECENTS_PACKAGE_NAME = "com.android.systemui.recents"; private static final boolean SHOW_ACTIVITY_START_TIME = true; @@ -1057,7 +1059,8 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo // We only allow home activities to be resizeable if they explicitly requested it. info.resizeMode = RESIZE_MODE_UNRESIZEABLE; } - } else if (service.getRecentTasks().isRecentsComponent(realActivity, appInfo.uid)) { + } else if (realActivity.getClassName().contains(LEGACY_RECENTS_PACKAGE_NAME) || + service.getRecentTasks().isRecentsComponent(realActivity, appInfo.uid)) { activityType = ACTIVITY_TYPE_RECENTS; } else if (options != null && options.getLaunchActivityType() == ACTIVITY_TYPE_ASSISTANT && canLaunchAssistActivity(launchedFromPackage)) {