Rework thumbnail API to not suffer from IPC failures.
Thumbnails are now requested separately, so we don't exceed the
IPC buffer size limit.
Also implement issue #3349553: Please provide a hook to intercept
fragment-breadcrumb clicks
And maybe fix issue #3439199: Music Notification does not turn on
when app switching out of Music app
Change-Id: Ie939e78cc8ded07b18112760e053185947549f61
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index d76b67d..a660076 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -112,6 +112,11 @@
public int id;
/**
+ * The true identifier of this task, valid even if it is not running.
+ */
+ public int persistentId;
+
+ /**
* The original Intent used to launch the task. You can use this
* Intent to re-launch the task (if it is no longer running) or bring
* the current task to the front.
@@ -127,14 +132,6 @@
public ComponentName origActivity;
/**
- * Thumbnail representation of the task's last state. Must
- * use {@link ActivityManager#TASKS_GET_THUMBNAILS} to have this set.
- * @hide -- this is not scalable, need to have a separate API to get
- * the bitmap.
- */
- public Bitmap thumbnail;
-
- /**
* Description of the task's last state.
*/
public CharSequence description;
@@ -148,6 +145,7 @@
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
+ dest.writeInt(persistentId);
if (baseIntent != null) {
dest.writeInt(1);
baseIntent.writeToParcel(dest, 0);
@@ -155,29 +153,19 @@
dest.writeInt(0);
}
ComponentName.writeToParcel(origActivity, dest);
- if (thumbnail != null) {
- dest.writeInt(1);
- thumbnail.writeToParcel(dest, 0);
- } else {
- dest.writeInt(0);
- }
TextUtils.writeToParcel(description, dest,
Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
}
public void readFromParcel(Parcel source) {
id = source.readInt();
+ persistentId = source.readInt();
if (source.readInt() != 0) {
baseIntent = Intent.CREATOR.createFromParcel(source);
} else {
baseIntent = null;
}
origActivity = ComponentName.readFromParcel(source);
- if (source.readInt() != 0) {
- thumbnail = Bitmap.CREATOR.createFromParcel(source);
- } else {
- thumbnail = null;
- }
description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
}
@@ -401,6 +389,16 @@
return getRunningTasks(maxNum, 0, null);
}
+ /** @hide */
+ public Bitmap getTaskThumbnail(int id) throws SecurityException {
+ try {
+ return ActivityManagerNative.getDefault().getTaskThumbnail(id);
+ } catch (RemoteException e) {
+ // System dead, we will be dead too soon!
+ return null;
+ }
+ }
+
/**
* Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
* activity along with the task, so it is positioned immediately behind
@@ -409,6 +407,13 @@
public static final int MOVE_TASK_WITH_HOME = 0x00000001;
/**
+ * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
+ * user-instigated action, so the current activity will not receive a
+ * hint that the user is leaving.
+ */
+ public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
+
+ /**
* Ask that the task associated with a given task ID be moved to the
* front of the stack, so it is now visible to the user. Requires that
* the caller hold permission {@link android.Manifest.permission#REORDER_TASKS}
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index c095c06..d3d3792 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -442,6 +442,20 @@
return true;
}
+ case GET_TASK_THUMBNAIL_TRANSACTION: {
+ data.enforceInterface(IActivityManager.descriptor);
+ int id = data.readInt();
+ Bitmap bm = getTaskThumbnail(id);
+ reply.writeNoException();
+ if (bm != null) {
+ reply.writeInt(1);
+ bm.writeToParcel(reply, 0);
+ } else {
+ reply.writeInt(0);
+ }
+ return true;
+ }
+
case GET_SERVICES_TRANSACTION: {
data.enforceInterface(IActivityManager.descriptor);
int maxNum = data.readInt();
@@ -1816,6 +1830,21 @@
reply.recycle();
return list;
}
+ public Bitmap getTaskThumbnail(int id) throws RemoteException {
+ Parcel data = Parcel.obtain();
+ Parcel reply = Parcel.obtain();
+ data.writeInterfaceToken(IActivityManager.descriptor);
+ data.writeInt(id);
+ mRemote.transact(GET_TASK_THUMBNAIL_TRANSACTION, data, reply, 0);
+ reply.readException();
+ Bitmap bm = null;
+ if (reply.readInt() != 0) {
+ bm = Bitmap.CREATOR.createFromParcel(reply);
+ }
+ data.recycle();
+ reply.recycle();
+ return bm;
+ }
public List getServices(int maxNum, int flags) throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
diff --git a/core/java/android/app/FragmentBreadCrumbs.java b/core/java/android/app/FragmentBreadCrumbs.java
index 3f045ac..df64035 100644
--- a/core/java/android/app/FragmentBreadCrumbs.java
+++ b/core/java/android/app/FragmentBreadCrumbs.java
@@ -50,6 +50,26 @@
/** Listener to inform when a parent entry is clicked */
private OnClickListener mParentClickListener;
+ private OnBreadCrumbClickListener mOnBreadCrumbClickListener;
+
+ /**
+ * Interface to intercept clicks on the bread crumbs.
+ */
+ public interface OnBreadCrumbClickListener {
+ /**
+ * Called when a bread crumb is clicked.
+ *
+ * @param backStack The BackStackEntry whose bread crumb was clicked.
+ * May be null, if this bread crumb is for the root of the back stack.
+ * @param flags Additional information about the entry. Currently
+ * always 0.
+ *
+ * @return Return true to consume this click. Return to false to allow
+ * the default action (popping back stack to this entry) to occur.
+ */
+ public boolean onBreadCrumbClick(BackStackEntry backStack, int flags);
+ }
+
public FragmentBreadCrumbs(Context context) {
this(context, null);
}
@@ -107,6 +127,16 @@
updateCrumbs();
}
+ /**
+ * Sets a listener for clicks on the bread crumbs. This will be called before
+ * the default click action is performed.
+ *
+ * @param listener The new listener to set. Replaces any existing listener.
+ */
+ public void setOnBreadCrumbClickListener(OnBreadCrumbClickListener listener) {
+ mOnBreadCrumbClickListener = listener;
+ }
+
private BackStackRecord createBackStackEntry(CharSequence title, CharSequence shortTitle) {
if (title == null) return null;
@@ -266,8 +296,18 @@
mParentClickListener.onClick(v);
}
} else {
- mActivity.getFragmentManager().popBackStack(bse.getId(),
- bse == mTopEntry? FragmentManager.POP_BACK_STACK_INCLUSIVE : 0);
+ if (mOnBreadCrumbClickListener != null) {
+ if (mOnBreadCrumbClickListener.onBreadCrumbClick(
+ bse == mTopEntry ? null : bse, 0)) {
+ return;
+ }
+ }
+ if (bse == mTopEntry) {
+ // Pop everything off the back stack.
+ mActivity.getFragmentManager().popBackStack();
+ } else {
+ mActivity.getFragmentManager().popBackStack(bse.getId(), 0);
+ }
}
}
}
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 5d4380b..f42e8fb 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -133,6 +133,7 @@
IThumbnailReceiver receiver) throws RemoteException;
public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum,
int flags) throws RemoteException;
+ public Bitmap getTaskThumbnail(int taskId) throws RemoteException;
public List getServices(int maxNum, int flags) throws RemoteException;
public List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState()
throws RemoteException;
@@ -514,7 +515,7 @@
int FORCE_STOP_PACKAGE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+78;
int KILL_PIDS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+79;
int GET_SERVICES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+80;
-
+ int GET_TASK_THUMBNAIL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+81;
int GET_RUNNING_APP_PROCESSES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+82;
int GET_DEVICE_CONFIGURATION_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+83;
int PEEK_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+84;