diff options
author | 2015-08-01 19:28:29 -0700 | |
---|---|---|
committer | 2015-08-06 09:59:32 -0700 | |
commit | ba7881c89e7dd50aa537e70f0b96273e131dd08e (patch) | |
tree | 7633bf3a37d4d82a05877fab5d45c565b1921979 | |
parent | 950af418c35a1c3be0637c026433f7a8a5d0cb25 (diff) |
Support finishing a task with any finishing activity in the task.
Change-Id: I8c6bb864de6dc135e0fedb16ee424d7816ee3cfa
-rw-r--r-- | core/java/android/app/Activity.java | 19 | ||||
-rw-r--r-- | core/java/android/app/ActivityManagerNative.java | 6 | ||||
-rw-r--r-- | core/java/android/app/ActivityThread.java | 6 | ||||
-rw-r--r-- | core/java/android/app/Dialog.java | 16 | ||||
-rw-r--r-- | core/java/android/app/IActivityManager.java | 2 | ||||
-rw-r--r-- | core/java/android/view/Window.java | 5 | ||||
-rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 8 |
7 files changed, 36 insertions, 26 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 2f40c18b2f9f..5463638ca35a 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -683,6 +683,13 @@ public class Activity extends ContextThemeWrapper /** Start of user-defined activity results. */ public static final int RESULT_FIRST_USER = 1; + /** @hide Task isn't finished when activity is finished */ + public static final int DONT_FINISH_TASK_WITH_ACTIVITY = 0; + /** @hide Task is finished if the finishing activity is the root of the task */ + public static final int FINISH_TASK_WITH_ROOT_ACTIVITY = 1; + /** @hide Task is finished along with the finishing activity*/ + public static final int FINISH_TASK_WITH_ACTIVITY = 2; + static final String FRAGMENTS_TAG = "android:fragments"; private static final String WINDOW_HIERARCHY_TAG = "android:viewHierarchyState"; @@ -2689,8 +2696,8 @@ public class Activity extends ContextThemeWrapper * @hide */ @Override - public void onWindowDismissed() { - finish(); + public void onWindowDismissed(boolean finishTask) { + finish(finishTask ? FINISH_TASK_WITH_ACTIVITY : DONT_FINISH_TASK_WITH_ACTIVITY); } /** @@ -4838,7 +4845,7 @@ public class Activity extends ContextThemeWrapper * Finishes the current activity and specifies whether to remove the task associated with this * activity. */ - private void finish(boolean finishTask) { + private void finish(int finishTask) { if (mParent == null) { int resultCode; Intent resultData; @@ -4869,7 +4876,7 @@ public class Activity extends ContextThemeWrapper * onActivityResult(). */ public void finish() { - finish(false); + finish(DONT_FINISH_TASK_WITH_ACTIVITY); } /** @@ -4969,10 +4976,10 @@ public class Activity extends ContextThemeWrapper /** * Call this when your activity is done and should be closed and the task should be completely - * removed as a part of finishing the Activity. + * removed as a part of finishing the root activity of the task. */ public void finishAndRemoveTask() { - finish(true); + finish(FINISH_TASK_WITH_ROOT_ACTIVITY); } /** diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index e9d4113e8d70..9bf2f6423798 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -346,7 +346,7 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM if (data.readInt() != 0) { resultData = Intent.CREATOR.createFromParcel(data); } - boolean finishTask = (data.readInt() != 0); + int finishTask = data.readInt(); boolean res = finishActivity(token, resultCode, resultData, finishTask); reply.writeNoException(); reply.writeInt(res ? 1 : 0); @@ -2949,7 +2949,7 @@ class ActivityManagerProxy implements IActivityManager data.recycle(); return result; } - public boolean finishActivity(IBinder token, int resultCode, Intent resultData, boolean finishTask) + public boolean finishActivity(IBinder token, int resultCode, Intent resultData, int finishTask) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); @@ -2962,7 +2962,7 @@ class ActivityManagerProxy implements IActivityManager } else { data.writeInt(0); } - data.writeInt(finishTask ? 1 : 0); + data.writeInt(finishTask); mRemote.transact(FINISH_ACTIVITY_TRANSACTION, data, reply, 0); reply.readException(); boolean res = reply.readInt() != 0; diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 4474c7519514..25be22092861 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -2555,7 +2555,8 @@ public final class ActivityThread { // manager to stop us. try { ActivityManagerNative.getDefault() - .finishActivity(r.token, Activity.RESULT_CANCELED, null, false); + .finishActivity(r.token, Activity.RESULT_CANCELED, null, + Activity.DONT_FINISH_TASK_WITH_ACTIVITY); } catch (RemoteException ex) { // Ignore } @@ -3280,7 +3281,8 @@ public final class ActivityThread { // just end this activity. try { ActivityManagerNative.getDefault() - .finishActivity(token, Activity.RESULT_CANCELED, null, false); + .finishActivity(token, Activity.RESULT_CANCELED, null, + Activity.DONT_FINISH_TASK_WITH_ACTIVITY); } catch (RemoteException ex) { } } diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java index f6e0e1e721b9..6e8e2c44ce37 100644 --- a/core/java/android/app/Dialog.java +++ b/core/java/android/app/Dialog.java @@ -721,29 +721,29 @@ public class Dialog implements DialogInterface, Window.Callback, public void onContentChanged() { } - + public void onWindowFocusChanged(boolean hasFocus) { } public void onAttachedToWindow() { } - + public void onDetachedFromWindow() { } /** @hide */ @Override - public void onWindowDismissed() { + public void onWindowDismissed(boolean finishTask) { dismiss(); } - + /** - * Called to process key events. You can override this to intercept all - * key events before they are dispatched to the window. Be sure to call + * Called to process key events. You can override this to intercept all + * key events before they are dispatched to the window. Be sure to call * this implementation for key events that should be handled normally. - * + * * @param event The key event. - * + * * @return boolean Return true if this event was consumed. */ public boolean dispatchKeyEvent(KeyEvent event) { diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index 5352465ff775..3e5ecbbe5ac5 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -93,7 +93,7 @@ public interface IActivityManager extends IInterface { public boolean startNextMatchingActivity(IBinder callingActivity, Intent intent, Bundle options) throws RemoteException; public int startActivityFromRecents(int taskId, Bundle options) throws RemoteException; - public boolean finishActivity(IBinder token, int code, Intent data, boolean finishTask) + public boolean finishActivity(IBinder token, int code, Intent data, int finishTask) throws RemoteException; public void finishSubActivity(IBinder token, String resultWho, int requestCode) throws RemoteException; public boolean finishActivityAffinity(IBinder token) throws RemoteException; diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index 07984e9ddd98..7dd9948ddad0 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -471,8 +471,9 @@ public abstract class Window { /** * Called when a window is dismissed. This informs the callback that the * window is gone, and it should finish itself. + * @param finishTask True if the task should also be finished. */ - public void onWindowDismissed(); + void onWindowDismissed(boolean finishTask); } public Window(Context context) { @@ -659,7 +660,7 @@ public abstract class Window { /** @hide */ public final void dispatchOnWindowDismissed() { if (mOnWindowDismissedCallback != null) { - mOnWindowDismissedCallback.onWindowDismissed(); + mOnWindowDismissedCallback.onWindowDismissed(false); } } diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 7f4746ec2d8b..0afda1dfc281 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -4252,14 +4252,13 @@ public final class ActivityManagerService extends ActivityManagerNative * @param token The Binder token referencing the Activity we want to finish. * @param resultCode Result code, if any, from this Activity. * @param resultData Result data (Intent), if any, from this Activity. - * @param finishTask Whether to finish the task associated with this Activity. Only applies to - * the root Activity in the task. + * @param finishTask Whether to finish the task associated with this Activity. * * @return Returns true if the activity successfully finished, or false if it is still running. */ @Override public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, - boolean finishTask) { + int finishTask) { // Refuse possible leaked file descriptors if (resultData != null && resultData.hasFileDescriptors() == true) { throw new IllegalArgumentException("File descriptors passed in Intent"); @@ -4306,7 +4305,8 @@ public final class ActivityManagerService extends ActivityManagerNative final long origId = Binder.clearCallingIdentity(); try { boolean res; - if (finishTask && r == rootR) { + if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY + || (finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY && r == rootR)) { // If requested, remove the task that is associated to this activity only if it // was the root activity in the task. The result code and data is ignored // because we don't support returning them across task boundaries. |