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

Commit 21e04212 authored by Jaewan Kim's avatar Jaewan Kim
Browse files

PIP: Prevent PipOverlayActivity from restarting

PipManager moves the PIPed activity to fullscreen if the activity is
restarted. It's because the activity may be started by the Launcher or
an intent again, but we don't want do so for the PipOverlayActivity.

Bug: 27689029
Change-Id: Icebc09e22e5f5f4650fcdbfdd8c452b7cf23844b
parent c1d317f7
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -152,6 +152,7 @@ public class PipManager {
    private final Runnable mOnPinnedActivityRestartAttempt = new Runnable() {
        @Override
        public void run() {
            // If PIPed activity is launched again by Launcher or intent, make it fullscreen.
            movePipToFullscreen();
        }
    };
@@ -315,11 +316,7 @@ public class PipManager {
    private void showPipOverlay() {
        if (DEBUG) Log.d(TAG, "showPipOverlay()");
        mState = STATE_PIP_OVERLAY;
        Intent intent = new Intent(mContext, PipOverlayActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        final ActivityOptions options = ActivityOptions.makeBasic();
        options.setLaunchStackId(PINNED_STACK_ID);
        mContext.startActivity(intent, options.toBundle());
        PipOverlayActivity.showPipOverlay(mContext);
    }

    /**
+35 −3
Original line number Diff line number Diff line
@@ -17,21 +17,31 @@
package com.android.systemui.tv.pip;

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import com.android.systemui.R;

import static android.app.ActivityManager.StackId.PINNED_STACK_ID;

/**
 * Activity to show an overlay on top of PIP activity to show how to pop up PIP menu.
 */
public class PipOverlayActivity extends Activity implements PipManager.Listener {
    private static final String TAG = "PipOverlayActivity";
    private static final boolean DEBUG = false;

    private static final long SHOW_GUIDE_OVERLAY_VIEW_DURATION_MS = 4000;

    /**
     * The single instance of PipOverlayActivity to prevent it from restarting.
     * Note that {@link PipManager} moves the PIPed activity to fullscreen if the activity is
     * restarted. It's because the activity may be started by the Launcher or an intent again,
     * but we don't want do so for the PipOverlayActivity.
     */
    private static PipOverlayActivity sPipOverlayActivity;

    private final PipManager mPipManager = PipManager.getInstance();
    private final Handler mHandler = new Handler();
    private View mGuideOverlayView;
@@ -42,6 +52,19 @@ public class PipOverlayActivity extends Activity implements PipManager.Listener
        }
    };

    /**
     * Launches the PIP overlay. This should be only called on the main thread.
     */
    public static void showPipOverlay(Context context) {
        if (sPipOverlayActivity == null) {
            Intent intent = new Intent(context, PipOverlayActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            final ActivityOptions options = ActivityOptions.makeBasic();
            options.setLaunchStackId(PINNED_STACK_ID);
            context.startActivity(intent, options.toBundle());
        }
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
@@ -49,6 +72,8 @@ public class PipOverlayActivity extends Activity implements PipManager.Listener
        mGuideOverlayView = findViewById(R.id.guide_overlay);
        mGuideButtonsView = findViewById(R.id.guide_buttons);
        mPipManager.addListener(this);

        sPipOverlayActivity = this;
    }

    @Override
@@ -76,6 +101,7 @@ public class PipOverlayActivity extends Activity implements PipManager.Listener
    @Override
    protected void onDestroy() {
        super.onDestroy();
        sPipOverlayActivity = null;
        mHandler.removeCallbacksAndMessages(null);
        mPipManager.removeListener(this);
        mPipManager.resumePipResizing(
@@ -107,4 +133,10 @@ public class PipOverlayActivity extends Activity implements PipManager.Listener
    @Override
    public void onMediaControllerChanged() {
    }

    @Override
    public void finish() {
        sPipOverlayActivity = null;
        super.finish();
    }
}