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
This commit is contained in:
Winson Chung
2017-11-07 08:30:54 -08:00
parent 0f6fae9efa
commit 16e185e60b
4 changed files with 89 additions and 1 deletions

View File

@@ -43,6 +43,9 @@
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.STATUS_BAR" />
<uses-permission android:name="android.permission.MANAGE_ACTIVITY_STACKS" />
<uses-permission android:name="android.permission.REAL_GET_TASKS" />
<application>
<uses-library android:name="android.test.runner" />

View File

@@ -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());

View File

@@ -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<RunningTaskInfo> 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");
}
}

View File

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