Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fec694ec authored by Chong Zhang's avatar Chong Zhang
Browse files

Put activity into stopped state if recreated while stopped

Move handling of recreate from client side to AMS, so that relaunch
happens at the right condition and activity goes to right state
after it's relaunched.

bug: 30060825
Change-Id: Ia475c26927b305eb25ae12be8640aab1fb7677a0
parent 3025e6be
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -5183,8 +5183,10 @@ public class Activity extends ContextThemeWrapper
        if (Looper.myLooper() != mMainThread.getLooper()) {
            throw new IllegalStateException("Must be called from main thread");
        }
        mMainThread.requestRelaunchActivity(mToken, null, null, 0, false, null, null, false,
                false /* preserveWindow */);
        try {
            ActivityManagerNative.getDefault().requestActivityRelaunch(mToken);
        } catch (RemoteException e) {
        }
    }

    /**
+18 −0
Original line number Diff line number Diff line
@@ -413,6 +413,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case REQUEST_ACTIVITY_RELAUNCH: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder token = data.readStrongBinder();
            requestActivityRelaunch(token);
            reply.writeNoException();
            return true;
        }

        case RELEASE_ACTIVITY_INSTANCE_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder token = data.readStrongBinder();
@@ -3434,6 +3442,16 @@ class ActivityManagerProxy implements IActivityManager
        data.recycle();
        reply.recycle();
    }
    public void requestActivityRelaunch(IBinder token) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(token);
        mRemote.transact(REQUEST_ACTIVITY_RELAUNCH, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
    }
    public boolean releaseActivityInstance(IBinder token) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
+4 −1
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ public interface IActivityManager extends IInterface {
    public void finishSubActivity(IBinder token, String resultWho, int requestCode) throws RemoteException;
    public boolean finishActivityAffinity(IBinder token) throws RemoteException;
    public void finishVoiceTask(IVoiceInteractionSession session) throws RemoteException;
    public void requestActivityRelaunch(IBinder token) throws RemoteException;
    public boolean releaseActivityInstance(IBinder token) throws RemoteException;
    public void releaseSomeActivities(IApplicationThread app) throws RemoteException;
    public boolean willActivityBeVisible(IBinder token) throws RemoteException;
@@ -958,7 +959,6 @@ public interface IActivityManager extends IInterface {
    int DELETE_ACTIVITY_CONTAINER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+185;
    int SET_PROCESS_MEMORY_TRIM_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+186;


    // Start of L transactions
    int GET_TAG_FOR_INTENT_SENDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+210;
    int START_USER_IN_BACKGROUND_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+211;
@@ -1062,4 +1062,7 @@ public interface IActivityManager extends IInterface {
    int SET_VR_THREAD_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 377;
    int SET_RENDER_THREAD_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 378;
    int SET_HAS_TOP_UI = IBinder.FIRST_CALL_TRANSACTION + 379;

    // Start of O transactions
    int REQUEST_ACTIVITY_RELAUNCH = IBinder.FIRST_CALL_TRANSACTION+400;
}
+17 −0
Original line number Diff line number Diff line
@@ -4789,6 +4789,23 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
    }
    @Override
    public final void requestActivityRelaunch(IBinder token) {
        synchronized(this) {
            ActivityRecord r = ActivityRecord.isInStackLocked(token);
            if (r == null) {
                return;
            }
            final long origId = Binder.clearCallingIdentity();
            try {
                r.forceNewConfig = true;
                r.task.stack.ensureActivityConfigurationLocked(r, 0, false);
            } finally {
                Binder.restoreCallingIdentity(origId);
            }
        }
    }
    /**
     * This is the internal entry point for handling Activity.finish().
     *
+5 −0
Original line number Diff line number Diff line
@@ -4779,6 +4779,11 @@ final class ActivityStack {
        } else {
            mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
            r.state = ActivityState.PAUSED;
            // if the app is relaunched when it's stopped, and we're not resuming,
            // put it back into stopped state.
            if (r.stopped) {
                addToStopping(r, true /* immediate */);
            }
        }

        r.configChangeFlags = 0;