Merge "Add flag to allow fetching related users recent tasks."

This commit is contained in:
Kenny Guy
2014-03-18 11:43:45 +00:00
committed by Android (Google) Code Review
5 changed files with 49 additions and 10 deletions

View File

@@ -509,6 +509,12 @@ public class ActivityManager {
*/
public int stackId;
/**
* The id the of the user the task was running as.
* @hide
*/
public int userId;
public RecentTaskInfo() {
}
@@ -531,6 +537,7 @@ public class ActivityManager {
TextUtils.writeToParcel(description, dest,
Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
dest.writeInt(stackId);
dest.writeInt(userId);
}
public void readFromParcel(Parcel source) {
@@ -544,6 +551,7 @@ public class ActivityManager {
origActivity = ComponentName.readFromParcel(source);
description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
stackId = source.readInt();
userId = source.readInt();
}
public static final Creator<RecentTaskInfo> CREATOR
@@ -567,13 +575,20 @@ public class ActivityManager {
* {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
*/
public static final int RECENT_WITH_EXCLUDED = 0x0001;
/**
* Provides a list that does not contain any
* recent tasks that currently are not available to the user.
*/
public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
/**
* Provides a list that also contains recent tasks for user
* and related users.
* @hide
*/
public static final int RECENT_INCLUDE_RELATED = 0x0004;
/**
* Return a list of the tasks that the user has recently launched, with
* the most recent being first and older ones after in order.

View File

@@ -367,8 +367,9 @@ public class RecentTasksLoader implements View.OnTouchListener {
public TaskDescription loadFirstTask() {
final ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RecentTaskInfo> recentTasks = am.getRecentTasksForUser(
1, ActivityManager.RECENT_IGNORE_UNAVAILABLE, UserHandle.CURRENT.getIdentifier());
final List<ActivityManager.RecentTaskInfo> recentTasks = am.getRecentTasksForUser(1,
ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_RELATED,
UserHandle.CURRENT.getIdentifier());
TaskDescription item = null;
if (recentTasks.size() > 0) {
ActivityManager.RecentTaskInfo recentInfo = recentTasks.get(0);
@@ -439,7 +440,8 @@ public class RecentTasksLoader implements View.OnTouchListener {
mContext.getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RecentTaskInfo> recentTasks =
am.getRecentTasks(MAX_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
am.getRecentTasks(MAX_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE
| ActivityManager.RECENT_INCLUDE_RELATED);
int numTasks = recentTasks.size();
ActivityInfo homeInfo = new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME).resolveActivityInfo(pm, 0);

View File

@@ -359,7 +359,8 @@ public class Recents extends SystemUI implements RecentsComponent {
Bitmap loadFirstTaskThumbnail() {
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RecentTaskInfo> tasks = am.getRecentTasksForUser(1,
ActivityManager.RECENT_IGNORE_UNAVAILABLE, UserHandle.CURRENT.getIdentifier());
ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_RELATED,
UserHandle.CURRENT.getIdentifier());
for (ActivityManager.RecentTaskInfo t : tasks) {
// Skip tasks in the home stack
if (am.isInHomeStack(t.persistentId)) {
@@ -376,7 +377,8 @@ public class Recents extends SystemUI implements RecentsComponent {
boolean hasFirstTask() {
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RecentTaskInfo> tasks = am.getRecentTasksForUser(1,
ActivityManager.RECENT_IGNORE_UNAVAILABLE, UserHandle.CURRENT.getIdentifier());
ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_RELATED,
UserHandle.CURRENT.getIdentifier());
for (ActivityManager.RecentTaskInfo t : tasks) {
// Skip tasks in the home stack
if (am.isInHomeStack(t.persistentId)) {

View File

@@ -164,7 +164,8 @@ public class RecentsActivity extends Activity {
final List<ActivityManager.RecentTaskInfo> recentTasks =
am.getRecentTasks(2,
ActivityManager.RECENT_WITH_EXCLUDED |
ActivityManager.RECENT_IGNORE_UNAVAILABLE);
ActivityManager.RECENT_IGNORE_UNAVAILABLE |
ActivityManager.RECENT_INCLUDE_RELATED);
if (recentTasks.size() > 1 &&
mRecentsPanel.simulateClick(recentTasks.get(1).persistentId)) {
// recents panel will take care of calling show(false) through simulateClick

View File

@@ -6856,10 +6856,19 @@ public final class ActivityManagerService extends ActivityManagerNative
ArrayList<ActivityManager.RecentTaskInfo> res
= new ArrayList<ActivityManager.RecentTaskInfo>(
maxNum < N ? maxNum : N);
final Set<Integer> includedUsers;
if ((flags & ActivityManager.RECENT_INCLUDE_RELATED) != 0) {
includedUsers = getRelatedUsersLocked(userId);
} else {
includedUsers = new HashSet<Integer>();
}
includedUsers.add(Integer.valueOf(userId));
for (int i=0; i<N && maxNum > 0; i++) {
TaskRecord tr = mRecentTasks.get(i);
// Only add calling user's recent tasks
if (tr.userId != userId) continue;
// Only add calling user or related users recent tasks
if (!includedUsers.contains(Integer.valueOf(tr.userId))) continue;
// Return the entry if desired by the caller. We always return
// the first entry, because callers always expect this to be the
// foreground app. We may filter others if the caller has
@@ -6883,6 +6892,7 @@ public final class ActivityManagerService extends ActivityManagerNative
rti.origActivity = tr.origActivity;
rti.description = tr.lastDescription;
rti.stackId = tr.stack.mStackId;
rti.userId = tr.userId;
if ((flags&ActivityManager.RECENT_IGNORE_UNAVAILABLE) != 0) {
// Check whether this activity is currently available.
@@ -6902,7 +6912,7 @@ public final class ActivityManagerService extends ActivityManagerNative
// Will never happen.
}
}
res.add(rti);
maxNum--;
}
@@ -16262,6 +16272,15 @@ public final class ActivityManagerService extends ActivityManagerNative
mRelatedUserIds = relatedUserIds;
}
private Set getRelatedUsersLocked(int userId) {
Set userIds = new HashSet<Integer>();
final List<UserInfo> relatedUsers = getUserManagerLocked().getRelatedUsers(userId);
for (UserInfo user : relatedUsers) {
userIds.add(Integer.valueOf(user.id));
}
return userIds;
}
@Override
public boolean switchUser(final int userId) {
return startUser(userId, /* foregound */ true);