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

Commit 7fd239cf authored by Craig Mautner's avatar Craig Mautner Committed by Android (Google) Code Review
Browse files

Merge "Pass ActivityOptions back from finishing activity."

parents 7126c3c7 233ceeeb
Loading
Loading
Loading
Loading
+37 −30
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import com.android.internal.policy.PolicyManager;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentCallbacks2;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -1150,6 +1149,12 @@ public class Activity extends ContextThemeWrapper
        }

        getApplication().dispatchActivityStarted(this);

        final ActivityOptions activityOptions = getActivityOptions();
        if (activityOptions != null &&
                activityOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) {
            mEnterTransitionCoordinator = activityOptions.createEnterActivityTransition(this);
        }
    }

    /**
@@ -5272,19 +5277,29 @@ public class Activity extends ContextThemeWrapper
     *
     * @param callback the method to call when all visible Activities behind this one have been
     * drawn and it is safe to make this Activity translucent again.
     * @param options activity options delivered to the activity below this one. The options
     * are retrieved using {@link #getActivityOptions}.
     *
     * @see #convertFromTranslucent()
     * @see TranslucentConversionListener
     *
     * @hide
     */
    public void convertToTranslucent(TranslucentConversionListener callback) {
    void convertToTranslucent(TranslucentConversionListener callback, ActivityOptions options) {
        boolean drawComplete;
        try {
            mTranslucentCallback = callback;
            mChangeCanvasToTranslucent =
                    ActivityManagerNative.getDefault().convertToTranslucent(mToken);
                    ActivityManagerNative.getDefault().convertToTranslucent(mToken, options);
            drawComplete = true;
        } catch (RemoteException e) {
            // pass
            // Make callback return as though it timed out.
            mChangeCanvasToTranslucent = false;
            drawComplete = false;
        }
        if (!mChangeCanvasToTranslucent && mTranslucentCallback != null) {
            // Window is already translucent.
            mTranslucentCallback.onTranslucentConversionComplete(drawComplete);
        }
    }

@@ -5299,6 +5314,22 @@ public class Activity extends ContextThemeWrapper
        }
    }

    /**
     * Retrieve the ActivityOptions passed in from the launching activity or passed back
     * from an activity launched by this activity in its call to {@link
     * #convertToTranslucent(TranslucentConversionListener, ActivityOptions)}
     *
     * @return The ActivityOptions passed to {@link #convertToTranslucent}.
     * @hide
     */
    ActivityOptions getActivityOptions() {
        try {
            return ActivityManagerNative.getDefault().getActivityOptions(mToken);
        } catch (RemoteException e) {
        }
        return null;
    }

    /**
     * Adjust the current immersive mode setting.
     *
@@ -5533,30 +5564,12 @@ public class Activity extends ContextThemeWrapper
        mParent = parent;
    }

    final void attach(Context context, ActivityThread aThread, Instrumentation instr, IBinder token,
            Application application, Intent intent, ActivityInfo info, CharSequence title, 
            Activity parent, String id, NonConfigurationInstances lastNonConfigurationInstances,
            Configuration config) {
        attach(context, aThread, instr, token, 0, application, intent, info, title, parent, id,
            lastNonConfigurationInstances, config);
    }
    
    final void attach(Context context, ActivityThread aThread,
            Instrumentation instr, IBinder token, int ident,
            Application application, Intent intent, ActivityInfo info,
            CharSequence title, Activity parent, String id,
            NonConfigurationInstances lastNonConfigurationInstances,
            Configuration config) {
        attach(context, aThread, instr, token, ident, application, intent, info, title, parent, id,
                lastNonConfigurationInstances, config, null, null);
    }

    final void attach(Context context, ActivityThread aThread,
            Instrumentation instr, IBinder token, int ident,
            Application application, Intent intent, ActivityInfo info,
            CharSequence title, Activity parent, String id,
            NonConfigurationInstances lastNonConfigurationInstances,
            Configuration config, Bundle options, IVoiceInteractor voiceInteractor) {
            Configuration config, IVoiceInteractor voiceInteractor) {
        attachBaseContext(context);

        mFragments.attachActivity(this, mContainer, null);
@@ -5597,12 +5610,6 @@ public class Activity extends ContextThemeWrapper
        }
        mWindowManager = mWindow.getWindowManager();
        mCurrentConfig = config;
        if (options != null) {
            ActivityOptions activityOptions = new ActivityOptions(options);
            if (activityOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) {
                mEnterTransitionCoordinator = activityOptions.createEnterActivityTransition(this);
            }
        }
    }

    /** @hide */
@@ -5873,7 +5880,7 @@ public class Activity extends ContextThemeWrapper
         * occurred waiting for the Activity to complete drawing.
         *
         * @see Activity#convertFromTranslucent()
         * @see Activity#convertToTranslucent(TranslucentConversionListener)
         * @see Activity#convertToTranslucent(TranslucentConversionListener, ActivityOptions)
         */
        public void onTranslucentConversionComplete(boolean drawComplete);
    }
+38 −2
Original line number Diff line number Diff line
@@ -1547,12 +1547,28 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
        case CONVERT_TO_TRANSLUCENT_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder token = data.readStrongBinder();
            boolean converted = convertToTranslucent(token);
            final Bundle bundle;
            if (data.readInt() == 0) {
                bundle = null;
            } else {
                bundle = data.readBundle();
            }
            final ActivityOptions options = bundle == null ? null : new ActivityOptions(bundle);
            boolean converted = convertToTranslucent(token, options);
            reply.writeNoException();
            reply.writeInt(converted ? 1 : 0);
            return true;
        }

        case GET_ACTIVITY_OPTIONS_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder token = data.readStrongBinder();
            final ActivityOptions options = getActivityOptions(token);
            reply.writeNoException();
            reply.writeBundle(options == null ? null : options.toBundle());
            return true;
        }

        case SET_IMMERSIVE_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder token = data.readStrongBinder();
@@ -4074,12 +4090,18 @@ class ActivityManagerProxy implements IActivityManager
        return res;
    }

    public boolean convertToTranslucent(IBinder token)
    public boolean convertToTranslucent(IBinder token, ActivityOptions options)
            throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(token);
        if (options == null) {
            data.writeInt(0);
        } else {
            data.writeInt(1);
            data.writeBundle(options.toBundle());
        }
        mRemote.transact(CONVERT_TO_TRANSLUCENT_TRANSACTION, data, reply, 0);
        reply.readException();
        boolean res = reply.readInt() != 0;
@@ -4088,6 +4110,20 @@ class ActivityManagerProxy implements IActivityManager
        return res;
    }

    public ActivityOptions getActivityOptions(IBinder token) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(token);
        mRemote.transact(GET_ACTIVITY_OPTIONS_TRANSACTION, data, reply, 0);
        reply.readException();
        Bundle bundle = reply.readBundle();
        ActivityOptions options = bundle == null ? null : new ActivityOptions(bundle);
        data.recycle();
        reply.recycle();
        return options;
    }

    public void setImmersive(IBinder token, boolean immersive)
            throws RemoteException {
        Parcel data = Parcel.obtain();
+9 −18
Original line number Diff line number Diff line
@@ -77,7 +77,6 @@ import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.Log;
import android.util.LogPrinter;
import android.util.Pair;
import android.util.PrintWriterPrinter;
import android.util.Slog;
import android.util.SuperNotCalledException;
@@ -295,7 +294,6 @@ public final class ActivityThread {
        boolean isForward;
        int pendingConfigChanges;
        boolean onlyLocalRequest;
        Bundle activityOptions;

        View mPendingRemoveWindow;
        WindowManager mPendingRemoveWindowManager;
@@ -594,8 +592,7 @@ public final class ActivityThread {
        public final void scheduleResumeActivity(IBinder token, int processState,
                boolean isForward, Bundle resumeArgs) {
            updateProcessState(processState, false);
            sendMessage(H.RESUME_ACTIVITY, new Pair<IBinder, Bundle>(token, resumeArgs),
                    isForward ? 1 : 0);
            sendMessage(H.RESUME_ACTIVITY, token, isForward ? 1 : 0);
        }

        public final void scheduleSendResult(IBinder token, List<ResultInfo> results) {
@@ -612,8 +609,7 @@ public final class ActivityThread {
                IVoiceInteractor voiceInteractor, int procState, Bundle state,
                PersistableBundle persistentState, List<ResultInfo> pendingResults,
                List<Intent> pendingNewIntents, boolean notResumed, boolean isForward,
                String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler,
                Bundle resumeArgs) {
                String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler) {

            updateProcessState(procState, false);

@@ -637,7 +633,6 @@ public final class ActivityThread {
            r.profileFile = profileName;
            r.profileFd = profileFd;
            r.autoStopProfiler = autoStopProfiler;
            r.activityOptions = resumeArgs;

            updatePendingConfiguration(curConfig);

@@ -1302,9 +1297,7 @@ public final class ActivityThread {
                    break;
                case RESUME_ACTIVITY:
                    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityResume");
                    final Pair<IBinder, Bundle> resumeArgs = (Pair<IBinder, Bundle>) msg.obj;
                    handleResumeActivity(resumeArgs.first, resumeArgs.second, true,
                            msg.arg1 != 0, true);
                    handleResumeActivity((IBinder) msg.obj, true, msg.arg1 != 0, true);
                    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                    break;
                case SEND_RESULT:
@@ -2084,7 +2077,7 @@ public final class ActivityThread {
                    + ", comp=" + name
                    + ", token=" + token);
        }
        return performLaunchActivity(r, null, null);
        return performLaunchActivity(r, null);
    }

    public final Activity getActivity(IBinder token) {
@@ -2137,8 +2130,7 @@ public final class ActivityThread {
        sendMessage(H.CLEAN_UP_CONTEXT, cci);
    }

    private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent,
            Bundle options) {
    private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {
        // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")");

        ActivityInfo aInfo = r.activityInfo;
@@ -2196,7 +2188,7 @@ public final class ActivityThread {
                        + r.activityInfo.name + " with config " + config);
                activity.attach(appContext, this, getInstrumentation(), r.token,
                        r.ident, app, r.intent, r.activityInfo, title, r.parent,
                        r.embeddedID, r.lastNonConfigurationInstances, config, options,
                        r.embeddedID, r.lastNonConfigurationInstances, config,
                        r.voiceInteractor);

                if (customIntent != null) {
@@ -2322,12 +2314,12 @@ public final class ActivityThread {
        if (localLOGV) Slog.v(
            TAG, "Handling launch of " + r);

        Activity a = performLaunchActivity(r, customIntent, r.activityOptions);
        Activity a = performLaunchActivity(r, customIntent);

        if (a != null) {
            r.createdConfig = new Configuration(mConfiguration);
            Bundle oldState = r.state;
            handleResumeActivity(r.token, r.activityOptions, false, r.isForward,
            handleResumeActivity(r.token, false, r.isForward,
                    !r.activity.mFinished && !r.startsNotResumed);

            if (!r.activity.mFinished && r.startsNotResumed) {
@@ -2887,7 +2879,7 @@ public final class ActivityThread {
        r.mPendingRemoveWindowManager = null;
    }

    final void handleResumeActivity(IBinder token, Bundle resumeArgs,
    final void handleResumeActivity(IBinder token,
            boolean clearHide, boolean isForward, boolean reallyResume) {
        // If we are getting ready to gc after going to the background, well
        // we are back active so skip it.
@@ -3810,7 +3802,6 @@ public final class ActivityThread {
            }
        }
        r.startsNotResumed = tmp.startsNotResumed;
        r.activityOptions = null;

        handleLaunchActivity(r, currentIntent);
    }
+2 −5
Original line number Diff line number Diff line
@@ -152,11 +152,10 @@ public abstract class ApplicationThreadNative extends Binder
            ParcelFileDescriptor profileFd = data.readInt() != 0
                    ? ParcelFileDescriptor.CREATOR.createFromParcel(data) : null;
            boolean autoStopProfiler = data.readInt() != 0;
            Bundle resumeArgs = data.readBundle();
            scheduleLaunchActivity(intent, b, ident, info, curConfig, compatInfo,
                    voiceInteractor, procState, state, persistentState,
                    ri, pi, notResumed, isForward, profileName, profileFd,
                    autoStopProfiler, resumeArgs);
                    autoStopProfiler);
            return true;
        }
        
@@ -737,8 +736,7 @@ class ApplicationThreadProxy implements IApplicationThread {
            IVoiceInteractor voiceInteractor, int procState, Bundle state,
            PersistableBundle persistentState, List<ResultInfo> pendingResults,
            List<Intent> pendingNewIntents, boolean notResumed, boolean isForward,
            String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler,
            Bundle resumeArgs)
            String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler)
            throws RemoteException {
        Parcel data = Parcel.obtain();
        data.writeInterfaceToken(IApplicationThread.descriptor);
@@ -764,7 +762,6 @@ class ApplicationThreadProxy implements IApplicationThread {
            data.writeInt(0);
        }
        data.writeInt(autoStopProfiler ? 1 : 0);
        data.writeBundle(resumeArgs);
        mRemote.transact(SCHEDULE_LAUNCH_ACTIVITY_TRANSACTION, data, null,
                IBinder.FLAG_ONEWAY);
        data.recycle();
+2 −2
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator
                            mActivity.convertFromTranslucent();
                        }
                    }
                });
                }, null);
                Drawable background = getDecor().getBackground();
                if (background != null) {
                    window.setBackgroundDrawable(null);
@@ -230,7 +230,7 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator
                public void onTranslucentConversionComplete(boolean drawComplete) {
                    fadeOutBackground();
                }
            });
            }, null);
        } else {
            fadeOutBackground();
        }
Loading