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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<ReferrerIntent> intents, boolean andPause) {
|
||||
@Override
|
||||
public void handleNewIntent(IBinder token, List<ReferrerIntent> 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<ReferrerIntent> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,8 +150,7 @@ public abstract class ClientTransactionHandler {
|
||||
Configuration overrideConfig);
|
||||
|
||||
/** Deliver new intent. */
|
||||
public abstract void handleNewIntent(IBinder token, List<ReferrerIntent> intents,
|
||||
boolean andPause);
|
||||
public abstract void handleNewIntent(IBinder token, List<ReferrerIntent> intents);
|
||||
|
||||
/** Deliver picture-in-picture mode change notification. */
|
||||
public abstract void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode,
|
||||
|
||||
@@ -339,7 +339,7 @@ public class LocalActivityManager {
|
||||
ArrayList<ReferrerIntent> 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) {
|
||||
|
||||
@@ -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<ReferrerIntent> 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<ReferrerIntent> intents, boolean pause) {
|
||||
public static NewIntentItem obtain(List<ReferrerIntent> 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 + "}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1595,8 +1595,8 @@ final class ActivityRecord extends ConfigurationContainer {
|
||||
try {
|
||||
ArrayList<ReferrerIntent> 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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user