diff options
| author | 2014-03-21 09:34:07 -0700 | |
|---|---|---|
| committer | 2014-03-22 16:39:33 -0700 | |
| commit | 2fbd7541804f816171849413b095fcfc70e06c1e (patch) | |
| tree | 0cdbfb95e4d697ca24a5588290b5f03b45be7438 | |
| parent | cde7086b900fd192a8e389f62ab5007d351d86b8 (diff) | |
Add Activity methods for icons and labels.
New Activity methods setRecentsLabel(CharSequence) and
setRecentsIcon(Bitmap) have been added. The topmost
activity with either of these set will be returned in
RecentTaskInfo members activityLabel and activityIcon.
Fixes bug 13562992.
Change-Id: Ic15d1d27b733b892a2a940063b105ac48f1ffee5
| -rw-r--r-- | api/current.txt | 4 | ||||
| -rw-r--r-- | core/java/android/app/Activity.java | 41 | ||||
| -rw-r--r-- | core/java/android/app/ActivityManager.java | 30 | ||||
| -rw-r--r-- | core/java/android/app/ActivityManagerNative.java | 50 | ||||
| -rw-r--r-- | core/java/android/app/IActivityManager.java | 8 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 37 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityRecord.java | 3 |
7 files changed, 170 insertions, 3 deletions
diff --git a/api/current.txt b/api/current.txt index a1628cab01f1..4efe1daf9e1b 100644 --- a/api/current.txt +++ b/api/current.txt @@ -3156,6 +3156,8 @@ package android.app { method public final void setProgressBarIndeterminate(boolean); method public final void setProgressBarIndeterminateVisibility(boolean); method public final void setProgressBarVisibility(boolean); + method public void setRecentsIcon(android.graphics.Bitmap); + method public void setRecentsLabel(java.lang.CharSequence); method public void setRequestedOrientation(int); method public final void setResult(int); method public final void setResult(int, android.content.Intent); @@ -3276,6 +3278,8 @@ package android.app { method public void readFromParcel(android.os.Parcel); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; + field public android.graphics.Bitmap activityIcon; + field public java.lang.CharSequence activityLabel; field public android.content.Intent baseIntent; field public java.lang.CharSequence description; field public int id; diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 606d80374be7..e38bbb3e7770 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -4701,6 +4701,47 @@ public class Activity extends ContextThemeWrapper } /** + * Set a label to be used in the Recents task display. The activities of a task are traversed + * in order from the topmost activity to the bottommost. As soon as one activity returns a + * non-null Recents label the traversal is ended and that value will be used in + * {@link ActivityManager.RecentTaskInfo#activityLabel} + * + * @see ActivityManager#getRecentTasks + * + * @param recentsLabel The label to use in the RecentTaskInfo. + */ + public void setRecentsLabel(CharSequence recentsLabel) { + try { + ActivityManagerNative.getDefault().setRecentsLabel(mToken, recentsLabel); + } catch (RemoteException e) { + } + } + + /** + * Set an icon to be used in the Recents task display. The activities of a task are traversed + * in order from the topmost activity to the bottommost. As soon as one activity returns a + * non-null Recents icon the traversal is ended and that value will be used in + * {@link ActivityManager.RecentTaskInfo#activityIcon}. + * + * @see ActivityManager#getRecentTasks + * + * @param recentsIcon The Bitmap to use in the RecentTaskInfo. + */ + public void setRecentsIcon(Bitmap recentsIcon) { + final Bitmap scaledIcon; + if (recentsIcon != null) { + final int size = ActivityManager.getLauncherLargeIconSizeInner(this); + scaledIcon = Bitmap.createScaledBitmap(recentsIcon, size, size, true); + } else { + scaledIcon = null; + } + try { + ActivityManagerNative.getDefault().setRecentsIcon(mToken, scaledIcon); + } catch (RemoteException e) { + } + } + + /** * Sets the visibility of the progress bar in the title. * <p> * In order for the progress bar to be shown, the feature must be requested diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 0787ef12de32..d386eff3df86 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -510,11 +510,23 @@ public class ActivityManager { public int stackId; /** - * The id the of the user the task was running as. + * The id of the user the task was running as. * @hide */ public int userId; + /** + * The label of the highest activity in the task stack to have set a label + * {@link Activity#setRecentsLabel}. + */ + public CharSequence activityLabel; + + /** + * The Bitmap icon of the highest activity in the task stack to set a Bitmap using + * {@link Activity#setRecentsIcon}. + */ + public Bitmap activityIcon; + public RecentTaskInfo() { } @@ -536,6 +548,14 @@ public class ActivityManager { ComponentName.writeToParcel(origActivity, dest); TextUtils.writeToParcel(description, dest, Parcelable.PARCELABLE_WRITE_RETURN_VALUE); + TextUtils.writeToParcel(activityLabel, dest, + Parcelable.PARCELABLE_WRITE_RETURN_VALUE); + if (activityIcon == null) { + dest.writeInt(0); + } else { + dest.writeInt(1); + activityIcon.writeToParcel(dest, 0); + } dest.writeInt(stackId); dest.writeInt(userId); } @@ -550,6 +570,8 @@ public class ActivityManager { } origActivity = ComponentName.readFromParcel(source); description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); + activityLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); + activityIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null; stackId = source.readInt(); userId = source.readInt(); } @@ -1970,7 +1992,11 @@ public class ActivityManager { * @return dimensions of square icons in terms of pixels */ public int getLauncherLargeIconSize() { - final Resources res = mContext.getResources(); + return getLauncherLargeIconSizeInner(mContext); + } + + static int getLauncherLargeIconSizeInner(Context context) { + final Resources res = context.getResources(); final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size); final int sw = res.getConfiguration().smallestScreenWidthDp; diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index 373a8a3f86c3..707a038f4f09 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -2128,6 +2128,25 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM reply.writeInt(isInLockTaskMode ? 1 : 0); return true; } + + case SET_RECENTS_LABEL_TRANSACTION: { + data.enforceInterface(IActivityManager.descriptor); + IBinder token = data.readStrongBinder(); + CharSequence recentsLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(data); + setRecentsLabel(token, recentsLabel); + reply.writeNoException(); + return true; + } + + case SET_RECENTS_ICON_TRANSACTION: { + data.enforceInterface(IActivityManager.descriptor); + IBinder token = data.readStrongBinder(); + Bitmap recentsIcon = data.readInt() != 0 + ? Bitmap.CREATOR.createFromParcel(data) : null; + setRecentsIcon(token, recentsIcon); + reply.writeNoException(); + return true; + } } return super.onTransact(code, data, reply, flags); @@ -4899,5 +4918,36 @@ class ActivityManagerProxy implements IActivityManager return isInLockTaskMode; } + public void setRecentsLabel(IBinder token, CharSequence recentsLabel) throws RemoteException + { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + data.writeInterfaceToken(IActivityManager.descriptor); + data.writeStrongBinder(token); + TextUtils.writeToParcel(recentsLabel, data, 0); + mRemote.transact(SET_RECENTS_LABEL_TRANSACTION, data, reply, IBinder.FLAG_ONEWAY); + reply.readException(); + data.recycle(); + reply.recycle(); + } + + public void setRecentsIcon(IBinder token, Bitmap recentsBitmap) throws RemoteException + { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + data.writeInterfaceToken(IActivityManager.descriptor); + data.writeStrongBinder(token); + if (recentsBitmap != null) { + data.writeInt(1); + recentsBitmap.writeToParcel(data, 0); + } else { + data.writeInt(0); + } + mRemote.transact(SET_RECENTS_ICON_TRANSACTION, data, reply, IBinder.FLAG_ONEWAY); + reply.readException(); + data.recycle(); + reply.recycle(); + } + private IBinder mRemote; } diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index cb06a42e9b67..3b568395dc50 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -436,6 +436,12 @@ public interface IActivityManager extends IInterface { /** @hide */ public boolean isInLockTaskMode() throws RemoteException; + /** @hide */ + public void setRecentsLabel(IBinder token, CharSequence recentsLabel) throws RemoteException; + + /** @hide */ + public void setRecentsIcon(IBinder token, Bitmap recentsBitmap) throws RemoteException; + /* * Private non-Binder interfaces */ @@ -735,4 +741,6 @@ public interface IActivityManager extends IInterface { int START_LOCK_TASK_BY_TOKEN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+214; int STOP_LOCK_TASK_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+215; int IS_IN_LOCK_TASK_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+216; + int SET_RECENTS_LABEL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+217; + int SET_RECENTS_ICON_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+218; } diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 5500b9ddc1a0..239e423b469e 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -6820,7 +6820,7 @@ public final class ActivityManagerService extends ActivityManagerNative } } - if (pending == null && receiver != null) { + if (pending.pendingRecords.isEmpty() && receiver != null) { // In this case all thumbnails were available and the client // is being asked to be told when the remaining ones come in... // which is unusually, since the top-most currently running @@ -6895,6 +6895,21 @@ public final class ActivityManagerService extends ActivityManagerNative rti.stackId = tr.stack.mStackId; rti.userId = tr.userId; + final ArrayList<ActivityRecord> activities = tr.mActivities; + int numSet = 0; + for (int activityNdx = activities.size() - 1; activityNdx >= 0 && numSet < 2; + --activityNdx) { + final ActivityRecord r = activities.get(activityNdx); + if (rti.activityLabel == null && r.recentsLabel != null) { + rti.activityLabel = r.recentsLabel; + ++numSet; + } + if (rti.activityIcon == null && r.recentsIcon != null) { + rti.activityIcon = r.recentsIcon; + ++numSet; + } + } + if ((flags&ActivityManager.RECENT_IGNORE_UNAVAILABLE) != 0) { // Check whether this activity is currently available. try { @@ -6960,6 +6975,26 @@ public final class ActivityManagerService extends ActivityManagerNative } @Override + public void setRecentsLabel(IBinder token, CharSequence recentsLabel) { + synchronized (this) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r != null) { + r.recentsLabel = recentsLabel.toString(); + } + } + } + + @Override + public void setRecentsIcon(IBinder token, Bitmap recentsIcon) { + synchronized (this) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r != null) { + r.recentsIcon = recentsIcon; + } + } + } + + @Override public boolean removeSubTask(int taskId, int subTaskIndex) { synchronized (this) { enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS, diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index 5d23fc34651b..645a5e892375 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -148,6 +148,9 @@ final class ActivityRecord { boolean mStartingWindowShown = false; ActivityContainer mInitialActivityContainer; + String recentsLabel; + Bitmap recentsIcon; + void dump(PrintWriter pw, String prefix) { final long now = SystemClock.uptimeMillis(); pw.print(prefix); pw.print("packageName="); pw.print(packageName); |