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

Commit 3daba432 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Finish DreamActivity on creation if it is obsolete" into tm-dev am:...

Merge "Finish DreamActivity on creation if it is obsolete" into tm-dev am: abfe2878 am: 1f9957c7

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18090283



Change-Id: I28008d17a763141f1c8e08c6ea7bb82c1e3212b7
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d7ffdd77 1f9957c7
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -56,8 +56,9 @@ public class DreamActivity extends Activity {
            setTitle(title);
        }

        DreamService.DreamServiceWrapper callback =
                (DreamService.DreamServiceWrapper) getIntent().getIBinderExtra(EXTRA_CALLBACK);
        final Bundle extras = getIntent().getExtras();
        final DreamService.DreamActivityCallback callback =
                (DreamService.DreamActivityCallback) extras.getBinder(EXTRA_CALLBACK);

        if (callback != null) {
            callback.onActivityCreated(this);
+31 −5
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.content.pm.ServiceInfo;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
@@ -1272,7 +1273,7 @@ public class DreamService extends Service implements Window.Callback {
            Intent i = new Intent(this, DreamActivity.class);
            i.setPackage(getApplicationContext().getPackageName());
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.putExtra(DreamActivity.EXTRA_CALLBACK, mDreamServiceWrapper);
            i.putExtra(DreamActivity.EXTRA_CALLBACK, new DreamActivityCallback(mDreamToken));
            final ServiceInfo serviceInfo = fetchServiceInfo(this,
                    new ComponentName(this, getClass()));
            i.putExtra(DreamActivity.EXTRA_DREAM_TITLE, fetchDreamLabel(this, serviceInfo));
@@ -1452,11 +1453,36 @@ public class DreamService extends Service implements Window.Callback {
        public void wakeUp() {
            mHandler.post(() -> DreamService.this.wakeUp(true /*fromSystem*/));
        }
    }

    /** @hide */
        void onActivityCreated(DreamActivity a) {
            mActivity = a;
            onWindowCreated(a.getWindow());
    final class DreamActivityCallback extends Binder {
        private final IBinder mActivityDreamToken;

        DreamActivityCallback(IBinder token) {
            mActivityDreamToken = token;
        }

        void onActivityCreated(DreamActivity activity) {
            if (mActivityDreamToken != mDreamToken || mFinished) {
                Slog.d(TAG, "DreamActivity was created after the dream was finished or "
                        + "a new dream started, finishing DreamActivity");
                if (!activity.isFinishing()) {
                    activity.finishAndRemoveTask();
                }
                return;
            }
            if (mActivity != null) {
                Slog.w(TAG, "A DreamActivity has already been started, "
                        + "finishing latest DreamActivity");
                if (!activity.isFinishing()) {
                    activity.finishAndRemoveTask();
                }
                return;
            }

            mActivity = activity;
            onWindowCreated(activity.getWindow());
        }
    }