From f49a58c095e3c7e0cd6f1a42befcd34e88b8a7b1 Mon Sep 17 00:00:00 2001 From: Andrii Kulian Date: Wed, 14 Aug 2019 17:34:27 -0700 Subject: Return correct value for Activity#releaseInstance() The documentation of Activity#releaseInstance() API tells that it returns 'true' if it "has started the process of destroying its current instance". However, the actual implementation that calls ActivityRecord#destroyImmediately() would only return 'true' if activity was removed from history immediately. In most cases it would return 'false', since it would first send "destroy" message to the client and wait for it to report back. This CL switches the system-server implementation to return 'true' if the activity is either destroying or destroyed as a result of calling Activity#releaseInstance(). Bug: 137329632 Test: atest CtsWindowManagerDeviceTestCases:ActivityTests Change-Id: I7d7287261d1742cffcf11ffeb32475019b978348 --- services/core/java/com/android/server/wm/ActivityRecord.java | 9 ++++++--- .../java/com/android/server/wm/ActivityTaskManagerService.java | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index fc36e9984c1b..44d6b77c1ab6 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -1935,7 +1935,10 @@ final class ActivityRecord extends ConfigurationContainer { * HistoryRecord. * Normally the server-side record will be removed when the client reports back after * destruction. If, however, at this point there is no client process attached, the record will - * removed immediately. + * be removed immediately. + * + * @return {@code true} if activity was immediately removed from history, {@code false} + * otherwise. */ boolean destroyImmediately(boolean removeFromApp, String reason) { if (DEBUG_SWITCH || DEBUG_CLEANUP) { @@ -3430,8 +3433,8 @@ final class ActivityRecord extends ConfigurationContainer { return false; } final ActivityStack stack = getActivityStack(); - if (stack == null || this == stack.getResumedActivity() || this == stack.mPausingActivity - || !mHaveState || !stopped) { + if (isState(RESUMED) || stack == null || this == stack.mPausingActivity || !mHaveState + || !stopped) { // We're not ready for this kind of thing. return false; } diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index 3c5947a51e11..f2ca2ba82dfb 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -82,6 +82,8 @@ import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PRE import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.SCREEN_COMPAT_PACKAGES; import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.MODE; import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.PACKAGE; +import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; +import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; @@ -3237,11 +3239,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { synchronized (mGlobalLock) { final long origId = Binder.clearCallingIdentity(); try { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null || !r.isDestroyable()) { return false; } - return r.safelyDestroy("app-req"); + r.destroyImmediately(true /* removeFromApp */, "app-req"); + return r.isState(DESTROYING, DESTROYED); } finally { Binder.restoreCallingIdentity(origId); } -- cgit v1.2.3-59-g8ed1b