Skip to content

Commit 15491c6

Browse files
author
Dianne Hackborn
committed
Switch to showing top-most thumbnail of recent apps.
The way it should have been, and with the new recents enter animation the way it must be. Added a new method to retrieve this thumbnail, since it would be less efficient to use the existing API (which always returns the "base" thumbnail). Probably at some point that existing API should be tweaked to always return the top thumbnail instead, but that is for a later time. Also removed code that would clear the thumbnail associated with an activity when it is resumed. I don't think there should ever be a reason to clear a thumbnail -- it's much better to have *something* for the task, even if it is a little out of date. Change-Id: I83e6ca6403eb2df5e4de3009dfe8c210e8cf8d5b
1 parent c535d2f commit 15491c6

File tree

8 files changed

+102
-34
lines changed

8 files changed

+102
-34
lines changed

core/java/android/app/ActivityManager.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,17 @@ public TaskThumbnails getTaskThumbnails(int id) throws SecurityException {
864864
return null;
865865
}
866866
}
867-
867+
868+
/** @hide */
869+
public Bitmap getTaskTopThumbnail(int id) throws SecurityException {
870+
try {
871+
return ActivityManagerNative.getDefault().getTaskTopThumbnail(id);
872+
} catch (RemoteException e) {
873+
// System dead, we will be dead too soon!
874+
return null;
875+
}
876+
}
877+
868878
/**
869879
* Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
870880
* activity along with the task, so it is positioned immediately behind

core/java/android/app/ActivityManagerNative.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
498498
reply.writeTypedList(list);
499499
return true;
500500
}
501-
501+
502502
case GET_TASK_THUMBNAILS_TRANSACTION: {
503503
data.enforceInterface(IActivityManager.descriptor);
504504
int id = data.readInt();
@@ -512,7 +512,21 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
512512
}
513513
return true;
514514
}
515-
515+
516+
case GET_TASK_TOP_THUMBNAIL_TRANSACTION: {
517+
data.enforceInterface(IActivityManager.descriptor);
518+
int id = data.readInt();
519+
Bitmap bm = getTaskTopThumbnail(id);
520+
reply.writeNoException();
521+
if (bm != null) {
522+
reply.writeInt(1);
523+
bm.writeToParcel(reply, 0);
524+
} else {
525+
reply.writeInt(0);
526+
}
527+
return true;
528+
}
529+
516530
case GET_SERVICES_TRANSACTION: {
517531
data.enforceInterface(IActivityManager.descriptor);
518532
int maxNum = data.readInt();
@@ -2307,6 +2321,21 @@ public ActivityManager.TaskThumbnails getTaskThumbnails(int id) throws RemoteExc
23072321
reply.recycle();
23082322
return bm;
23092323
}
2324+
public Bitmap getTaskTopThumbnail(int id) throws RemoteException {
2325+
Parcel data = Parcel.obtain();
2326+
Parcel reply = Parcel.obtain();
2327+
data.writeInterfaceToken(IActivityManager.descriptor);
2328+
data.writeInt(id);
2329+
mRemote.transact(GET_TASK_TOP_THUMBNAIL_TRANSACTION, data, reply, 0);
2330+
reply.readException();
2331+
Bitmap bm = null;
2332+
if (reply.readInt() != 0) {
2333+
bm = Bitmap.CREATOR.createFromParcel(reply);
2334+
}
2335+
data.recycle();
2336+
reply.recycle();
2337+
return bm;
2338+
}
23102339
public List getServices(int maxNum, int flags) throws RemoteException {
23112340
Parcel data = Parcel.obtain();
23122341
Parcel reply = Parcel.obtain();

core/java/android/app/IActivityManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public List getTasks(int maxNum, int flags,
104104
public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum,
105105
int flags, int userId) throws RemoteException;
106106
public ActivityManager.TaskThumbnails getTaskThumbnails(int taskId) throws RemoteException;
107+
public Bitmap getTaskTopThumbnail(int taskId) throws RemoteException;
107108
public List getServices(int maxNum, int flags) throws RemoteException;
108109
public List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState()
109110
throws RemoteException;
@@ -548,7 +549,7 @@ private WaitResult(Parcel source) {
548549
int UNBIND_BACKUP_AGENT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+91;
549550
int GET_UID_FOR_INTENT_SENDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+92;
550551
int HANDLE_INCOMING_USER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+93;
551-
552+
int GET_TASK_TOP_THUMBNAIL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+94;
552553
int KILL_APPLICATION_WITH_APPID_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+95;
553554
int CLOSE_SYSTEM_DIALOGS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+96;
554555
int GET_PROCESS_MEMORY_INFO_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+97;

packages/SystemUI/src/com/android/systemui/recent/RecentTasksLoader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ void loadThumbnailAndIcon(TaskDescription td) {
193193
final ActivityManager am = (ActivityManager)
194194
mContext.getSystemService(Context.ACTIVITY_SERVICE);
195195
final PackageManager pm = mContext.getPackageManager();
196-
ActivityManager.TaskThumbnails thumbs = am.getTaskThumbnails(td.persistentTaskId);
196+
Bitmap thumbnail = am.getTaskTopThumbnail(td.persistentTaskId);
197197
Drawable icon = getFullResIcon(td.resolveInfo, pm);
198198

199199
if (DEBUG) Log.v(TAG, "Loaded bitmap for task "
200-
+ td + ": " + thumbs.mainThumbnail);
200+
+ td + ": " + thumbnail);
201201
synchronized (td) {
202-
if (thumbs != null && thumbs.mainThumbnail != null) {
203-
td.setThumbnail(thumbs.mainThumbnail);
202+
if (thumbnail != null) {
203+
td.setThumbnail(thumbnail);
204204
} else {
205205
td.setThumbnail(mDefaultThumbnailBackground);
206206
}

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public final class ActivityManagerService extends ActivityManagerNative
168168
static final boolean localLOGV = DEBUG;
169169
static final boolean DEBUG_SWITCH = localLOGV || false;
170170
static final boolean DEBUG_TASKS = localLOGV || false;
171+
static final boolean DEBUG_THUMBNAILS = localLOGV || false;
171172
static final boolean DEBUG_PAUSE = localLOGV || false;
172173
static final boolean DEBUG_OOM_ADJ = localLOGV || false;
173174
static final boolean DEBUG_TRANSITION = localLOGV || false;
@@ -5846,6 +5847,18 @@ public ActivityManager.TaskThumbnails getTaskThumbnails(int id) {
58465847
return null;
58475848
}
58485849

5850+
public Bitmap getTaskTopThumbnail(int id) {
5851+
synchronized (this) {
5852+
enforceCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
5853+
"getTaskTopThumbnail()");
5854+
TaskRecord tr = taskForIdLocked(id);
5855+
if (tr != null) {
5856+
return mMainStack.getTaskTopThumbnailLocked(tr);
5857+
}
5858+
}
5859+
return null;
5860+
}
5861+
58495862
public boolean removeSubTask(int taskId, int subTaskIndex) {
58505863
synchronized (this) {
58515864
enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,

services/java/com/android/server/am/ActivityRecord.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ void dump(PrintWriter pw, String prefix) {
219219
pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
220220
pw.print(" thumbnailNeeded="); pw.print(thumbnailNeeded);
221221
pw.print(" forceNewConfig="); pw.println(forceNewConfig);
222-
pw.print(prefix); pw.print("thumbHolder="); pw.println(thumbHolder);
222+
pw.print(prefix); pw.print("thumbHolder: ");
223+
pw.print(Integer.toHexString(System.identityHashCode(thumbHolder)));
224+
if (thumbHolder != null) {
225+
pw.print(" bm="); pw.print(thumbHolder.lastThumbnail);
226+
pw.print(" desc="); pw.print(thumbHolder.lastDescription);
227+
}
228+
pw.println();
223229
if (launchTime != 0 || startTime != 0) {
224230
pw.print(prefix); pw.print("launchTime=");
225231
if (launchTime == 0) pw.print("0");
@@ -674,19 +680,15 @@ void updateThumbnail(Bitmap newThumbnail, CharSequence description) {
674680
}
675681
if (thumbHolder != null) {
676682
if (newThumbnail != null) {
683+
if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
684+
"Setting thumbnail of " + this + " holder " + thumbHolder
685+
+ " to " + newThumbnail);
677686
thumbHolder.lastThumbnail = newThumbnail;
678687
}
679688
thumbHolder.lastDescription = description;
680689
}
681690
}
682691

683-
void clearThumbnail() {
684-
if (thumbHolder != null) {
685-
thumbHolder.lastThumbnail = null;
686-
thumbHolder.lastDescription = null;
687-
}
688-
}
689-
690692
void startLaunchTickingLocked() {
691693
if (ActivityManagerService.IS_USER_BUILD) {
692694
return;

services/java/com/android/server/am/ActivityStack.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,7 @@ private final void completeResumeLocked(ActivityRecord next) {
12031203
if (mMainStack) {
12041204
mService.reportResumedActivityLocked(next);
12051205
}
1206-
1207-
next.clearThumbnail();
1206+
12081207
if (mMainStack) {
12091208
mService.setFocusedActivityLocked(next);
12101209
}
@@ -4328,18 +4327,33 @@ final boolean moveTaskToBackLocked(int task, ActivityRecord reason) {
43284327
finishTaskMoveLocked(task);
43294328
return true;
43304329
}
4331-
4330+
43324331
public ActivityManager.TaskThumbnails getTaskThumbnailsLocked(TaskRecord tr) {
43334332
TaskAccessInfo info = getTaskAccessInfoLocked(tr.taskId, true);
43344333
ActivityRecord resumed = mResumedActivity;
43354334
if (resumed != null && resumed.thumbHolder == tr) {
43364335
info.mainThumbnail = resumed.stack.screenshotActivities(resumed);
4337-
} else {
4338-
info.mainThumbnail = tr.lastThumbnail;
43394336
}
43404337
return info;
43414338
}
43424339

4340+
public Bitmap getTaskTopThumbnailLocked(TaskRecord tr) {
4341+
ActivityRecord resumed = mResumedActivity;
4342+
if (resumed != null && resumed.task == tr) {
4343+
// This task is the current resumed task, we just need to take
4344+
// a screenshot of it and return that.
4345+
return resumed.stack.screenshotActivities(resumed);
4346+
}
4347+
// Return the information about the task, to figure out the top
4348+
// thumbnail to return.
4349+
TaskAccessInfo info = getTaskAccessInfoLocked(tr.taskId, true);
4350+
if (info.numSubThumbbails <= 0) {
4351+
return info.mainThumbnail;
4352+
} else {
4353+
return info.subtasks.get(info.numSubThumbbails-1).holder.lastThumbnail;
4354+
}
4355+
}
4356+
43434357
public ActivityRecord removeTaskActivitiesLocked(int taskId, int subTaskIndex,
43444358
boolean taskRequired) {
43454359
TaskAccessInfo info = getTaskAccessInfoLocked(taskId, false);
@@ -4370,7 +4384,6 @@ public ActivityRecord removeTaskActivitiesLocked(int taskId, int subTaskIndex,
43704384
}
43714385

43724386
public TaskAccessInfo getTaskAccessInfoLocked(int taskId, boolean inclThumbs) {
4373-
ActivityRecord resumed = mResumedActivity;
43744387
final TaskAccessInfo thumbs = new TaskAccessInfo();
43754388
// How many different sub-thumbnails?
43764389
final int NA = mHistory.size();
@@ -4380,6 +4393,10 @@ public TaskAccessInfo getTaskAccessInfoLocked(int taskId, boolean inclThumbs) {
43804393
ActivityRecord ar = mHistory.get(j);
43814394
if (!ar.finishing && ar.task.taskId == taskId) {
43824395
holder = ar.thumbHolder;
4396+
if (holder != null) {
4397+
thumbs.mainThumbnail = holder.lastThumbnail;
4398+
}
4399+
j++;
43834400
break;
43844401
}
43854402
j++;
@@ -4394,7 +4411,6 @@ public TaskAccessInfo getTaskAccessInfoLocked(int taskId, boolean inclThumbs) {
43944411

43954412
ArrayList<TaskAccessInfo.SubTask> subtasks = new ArrayList<TaskAccessInfo.SubTask>();
43964413
thumbs.subtasks = subtasks;
4397-
ActivityRecord lastActivity = null;
43984414
while (j < NA) {
43994415
ActivityRecord ar = mHistory.get(j);
44004416
j++;
@@ -4404,30 +4420,28 @@ public TaskAccessInfo getTaskAccessInfoLocked(int taskId, boolean inclThumbs) {
44044420
if (ar.task.taskId != taskId) {
44054421
break;
44064422
}
4407-
lastActivity = ar;
44084423
if (ar.thumbHolder != holder && holder != null) {
44094424
thumbs.numSubThumbbails++;
44104425
holder = ar.thumbHolder;
44114426
TaskAccessInfo.SubTask sub = new TaskAccessInfo.SubTask();
4412-
sub.thumbnail = holder.lastThumbnail;
4427+
sub.holder = holder;
44134428
sub.activity = ar;
44144429
sub.index = j-1;
44154430
subtasks.add(sub);
44164431
}
44174432
}
4418-
if (lastActivity != null && subtasks.size() > 0) {
4419-
if (resumed == lastActivity) {
4420-
TaskAccessInfo.SubTask sub = subtasks.get(subtasks.size()-1);
4421-
sub.thumbnail = lastActivity.stack.screenshotActivities(lastActivity);
4422-
}
4423-
}
44244433
if (thumbs.numSubThumbbails > 0) {
44254434
thumbs.retriever = new IThumbnailRetriever.Stub() {
44264435
public Bitmap getThumbnail(int index) {
44274436
if (index < 0 || index >= thumbs.subtasks.size()) {
44284437
return null;
44294438
}
4430-
return thumbs.subtasks.get(index).thumbnail;
4439+
TaskAccessInfo.SubTask sub = thumbs.subtasks.get(index);
4440+
ActivityRecord resumed = mResumedActivity;
4441+
if (resumed != null && resumed.thumbHolder == sub.holder) {
4442+
return resumed.stack.screenshotActivities(resumed);
4443+
}
4444+
return sub.holder.lastThumbnail;
44314445
}
44324446
};
44334447
}

services/java/com/android/server/am/TaskAccessInfo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
import java.util.ArrayList;
2020

2121
import android.app.ActivityManager.TaskThumbnails;
22-
import android.graphics.Bitmap;
2322

2423
final class TaskAccessInfo extends TaskThumbnails {
2524
final static class SubTask {
26-
Bitmap thumbnail;
25+
ThumbnailHolder holder;
2726
ActivityRecord activity;
2827
int index;
2928
}

0 commit comments

Comments
 (0)