From 92d1652fa6b5b23901084e8ee63d8afe1a53b3da Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Wed, 27 Feb 2019 12:56:18 +0800 Subject: [PATCH] Remove custom lifecycle transitions for onNewIntent callback Rebased from ag/3785659. This CL switches to using post-execution state resolution for new intent delivery. Also removes some unnecessary code needed for old logic. Bug: 65236456 Bug: 77974794 Test: atest ActivityLifecycleTests Change-Id: I734ad50de498cd2a6b9514c8ef6cb1eeb08e4ec5 --- core/java/android/app/Activity.java | 2 -- core/java/android/app/ActivityThread.java | 27 ++----------------- .../android/app/ClientTransactionHandler.java | 3 +-- .../android/app/LocalActivityManager.java | 2 +- .../app/servertransaction/NewIntentItem.java | 21 ++++++--------- .../servertransaction/ObjectPoolTests.java | 6 ++--- .../TransactionParcelTests.java | 2 +- .../com/android/server/wm/ActivityRecord.java | 4 +-- .../com/android/server/wm/ActivityStack.java | 3 +-- 9 files changed, 19 insertions(+), 51 deletions(-) diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 883bcb8968419..54fe65db499ca 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -820,8 +820,6 @@ public class Activity extends ContextThemeWrapper /** {@code true} if the activity lifecycle is in a state which supports picture-in-picture. * This only affects the client-side exception, the actual state check still happens in AMS. */ private boolean mCanEnterPictureInPicture = false; - /** true if the activity is going through a transient pause */ - /*package*/ boolean mTemporaryPause = false; /** true if the activity is being destroyed in order to recreate it with a new configuration */ /*package*/ boolean mChangingConfigurations = false; @UnsupportedAppUsage diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 38006dc5b943b..b37d117238afb 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -615,7 +615,6 @@ public final class ActivityThread extends ClientTransactionHandler { sb.append(", finished=").append(activity.isFinishing()); sb.append(", destroyed=").append(activity.isDestroyed()); sb.append(", startedActivity=").append(activity.mStartedActivity); - sb.append(", temporaryPause=").append(activity.mTemporaryPause); sb.append(", changingConfigurations=").append(activity.mChangingConfigurations); sb.append("}"); } @@ -3319,35 +3318,15 @@ public final class ActivityThread extends ClientTransactionHandler { } } - @UnsupportedAppUsage - void performNewIntents(IBinder token, List intents, boolean andPause) { + @Override + public void handleNewIntent(IBinder token, List intents) { final ActivityClientRecord r = mActivities.get(token); if (r == null) { return; } - final boolean resumed = !r.paused; - if (resumed) { - r.activity.mTemporaryPause = true; - performPauseActivityIfNeeded(r, "performNewIntents"); - } checkAndBlockForNetworkAccess(); deliverNewIntents(r, intents); - if (resumed) { - performResumeActivity(token, false, "performNewIntents"); - r.activity.mTemporaryPause = false; - } else if (andPause) { - // In this case the activity was in the paused state when we delivered the intent, - // to guarantee onResume gets called after onNewIntent we temporarily resume the - // activity and pause again as the caller wanted. - performResumeActivity(token, false, "performNewIntents"); - performPauseActivityIfNeeded(r, "performNewIntents"); - } - } - - @Override - public void handleNewIntent(IBinder token, List intents, boolean andPause) { - performNewIntents(token, intents, andPause); } public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { @@ -4662,7 +4641,6 @@ public final class ActivityThread extends ClientTransactionHandler { try { // Now we are idle. r.activity.mCalled = false; - r.activity.mTemporaryPause = true; mInstrumentation.callActivityOnPause(r.activity); if (!r.activity.mCalled) { throw new SuperNotCalledException( @@ -4684,7 +4662,6 @@ public final class ActivityThread extends ClientTransactionHandler { deliverResults(r, results, reason); if (resumed) { r.activity.performResume(false, reason); - r.activity.mTemporaryPause = false; } } } diff --git a/core/java/android/app/ClientTransactionHandler.java b/core/java/android/app/ClientTransactionHandler.java index 70badfae4a20d..9dc8b45a71dcc 100644 --- a/core/java/android/app/ClientTransactionHandler.java +++ b/core/java/android/app/ClientTransactionHandler.java @@ -150,8 +150,7 @@ public abstract class ClientTransactionHandler { Configuration overrideConfig); /** Deliver new intent. */ - public abstract void handleNewIntent(IBinder token, List intents, - boolean andPause); + public abstract void handleNewIntent(IBinder token, List intents); /** Deliver picture-in-picture mode change notification. */ public abstract void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode, diff --git a/core/java/android/app/LocalActivityManager.java b/core/java/android/app/LocalActivityManager.java index a52fb1a07b84d..94b1d7770307d 100644 --- a/core/java/android/app/LocalActivityManager.java +++ b/core/java/android/app/LocalActivityManager.java @@ -339,7 +339,7 @@ public class LocalActivityManager { ArrayList intents = new ArrayList<>(1); intents.add(new ReferrerIntent(intent, mParent.getPackageName())); if (localLOGV) Log.v(TAG, r.id + ": new intent"); - mActivityThread.performNewIntents(r, intents, false /* andPause */); + mActivityThread.handleNewIntent(r, intents); r.intent = intent; moveToState(r, mCurState); if (mSingleMode) { diff --git a/core/java/android/app/servertransaction/NewIntentItem.java b/core/java/android/app/servertransaction/NewIntentItem.java index 4c7f56d4b076c..2d1883836d02a 100644 --- a/core/java/android/app/servertransaction/NewIntentItem.java +++ b/core/java/android/app/servertransaction/NewIntentItem.java @@ -16,6 +16,8 @@ package android.app.servertransaction; +import static android.app.servertransaction.ActivityLifecycleItem.ON_RESUME; + import android.annotation.UnsupportedAppUsage; import android.app.ClientTransactionHandler; import android.os.IBinder; @@ -36,19 +38,17 @@ public class NewIntentItem extends ClientTransactionItem { @UnsupportedAppUsage private List mIntents; - private boolean mPause; - // TODO(lifecycler): Switch new intent handling to this scheme. - /*@Override + @Override public int getPostExecutionState() { return ON_RESUME; - }*/ + } @Override public void execute(ClientTransactionHandler client, IBinder token, PendingTransactionActions pendingActions) { Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); - client.handleNewIntent(token, mIntents, mPause); + client.handleNewIntent(token, mIntents); Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); } @@ -58,13 +58,12 @@ public class NewIntentItem extends ClientTransactionItem { private NewIntentItem() {} /** Obtain an instance initialized with provided params. */ - public static NewIntentItem obtain(List intents, boolean pause) { + public static NewIntentItem obtain(List intents) { NewIntentItem instance = ObjectPool.obtain(NewIntentItem.class); if (instance == null) { instance = new NewIntentItem(); } instance.mIntents = intents; - instance.mPause = pause; return instance; } @@ -72,7 +71,6 @@ public class NewIntentItem extends ClientTransactionItem { @Override public void recycle() { mIntents = null; - mPause = false; ObjectPool.recycle(this); } @@ -82,13 +80,11 @@ public class NewIntentItem extends ClientTransactionItem { /** Write to Parcel. */ @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeBoolean(mPause); dest.writeTypedList(mIntents, flags); } /** Read from Parcel. */ private NewIntentItem(Parcel in) { - mPause = in.readBoolean(); mIntents = in.createTypedArrayList(ReferrerIntent.CREATOR); } @@ -112,19 +108,18 @@ public class NewIntentItem extends ClientTransactionItem { return false; } final NewIntentItem other = (NewIntentItem) o; - return mPause == other.mPause && Objects.equals(mIntents, other.mIntents); + return Objects.equals(mIntents, other.mIntents); } @Override public int hashCode() { int result = 17; - result = 31 * result + (mPause ? 1 : 0); result = 31 * result + mIntents.hashCode(); return result; } @Override public String toString() { - return "NewIntentItem{pause=" + mPause + ",intents=" + mIntents + "}"; + return "NewIntentItem{intents=" + mIntents + "}"; } } diff --git a/core/tests/coretests/src/android/app/servertransaction/ObjectPoolTests.java b/core/tests/coretests/src/android/app/servertransaction/ObjectPoolTests.java index 447f28e06d7ef..5c8bced251081 100644 --- a/core/tests/coretests/src/android/app/servertransaction/ObjectPoolTests.java +++ b/core/tests/coretests/src/android/app/servertransaction/ObjectPoolTests.java @@ -212,15 +212,15 @@ public class ObjectPoolTests { @Test public void testRecycleNewIntentItem() { - NewIntentItem emptyItem = NewIntentItem.obtain(null, false); - NewIntentItem item = NewIntentItem.obtain(referrerIntentList(), true); + NewIntentItem emptyItem = NewIntentItem.obtain(null); + NewIntentItem item = NewIntentItem.obtain(referrerIntentList()); assertNotSame(item, emptyItem); assertFalse(item.equals(emptyItem)); item.recycle(); assertEquals(item, emptyItem); - NewIntentItem item2 = NewIntentItem.obtain(referrerIntentList(), true); + NewIntentItem item2 = NewIntentItem.obtain(referrerIntentList()); assertSame(item, item2); assertFalse(item2.equals(emptyItem)); } diff --git a/core/tests/coretests/src/android/app/servertransaction/TransactionParcelTests.java b/core/tests/coretests/src/android/app/servertransaction/TransactionParcelTests.java index d117b4096ca09..bffeb2a6c90ee 100644 --- a/core/tests/coretests/src/android/app/servertransaction/TransactionParcelTests.java +++ b/core/tests/coretests/src/android/app/servertransaction/TransactionParcelTests.java @@ -128,7 +128,7 @@ public class TransactionParcelTests { @Test public void testNewIntent() { // Write to parcel - NewIntentItem item = NewIntentItem.obtain(referrerIntentList(), true /* pause */); + NewIntentItem item = NewIntentItem.obtain(referrerIntentList()); writeAndPrepareForReading(item); // Read from parcel and assert diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 91ec4a083ed96..6ac41baefa4a8 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -1595,8 +1595,8 @@ final class ActivityRecord extends ConfigurationContainer { try { ArrayList ar = new ArrayList<>(1); ar.add(rintent); - mAtmService.getLifecycleManager().scheduleTransaction( - app.getThread(), appToken, NewIntentItem.obtain(ar, mState == PAUSED)); + mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, + NewIntentItem.obtain(ar)); unsent = false; } catch (RemoteException e) { Slog.w(TAG, "Exception thrown sending new intent to " + this, e); diff --git a/services/core/java/com/android/server/wm/ActivityStack.java b/services/core/java/com/android/server/wm/ActivityStack.java index 6bc9fc8a9f7ca..e0890a6fe17f3 100644 --- a/services/core/java/com/android/server/wm/ActivityStack.java +++ b/services/core/java/com/android/server/wm/ActivityStack.java @@ -2962,8 +2962,7 @@ class ActivityStack extends ConfigurationContainer { } if (next.newIntents != null) { - transaction.addCallback(NewIntentItem.obtain(next.newIntents, - false /* andPause */)); + transaction.addCallback(NewIntentItem.obtain(next.newIntents)); } // Well the app will no longer be stopped.