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

Commit 71fa2c0d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move ACTION_MENU/ACTION_CLOSE intent registraction to PipController"

parents 1992cdb4 07c7b34f
Loading
Loading
Loading
Loading
+32 −15
Original line number Diff line number Diff line
@@ -19,6 +19,10 @@ package com.android.wm.shell.pip.tv;
import static android.app.ActivityTaskManager.INVALID_STACK_ID;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.content.Intent.ACTION_MEDIA_RESOURCE_GRANTED;

import static com.android.wm.shell.pip.tv.PipNotification.ACTION_CLOSE;
import static com.android.wm.shell.pip.tv.PipNotification.ACTION_MENU;

import android.app.ActivityManager;
import android.app.ActivityTaskManager;
@@ -140,8 +144,17 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_MEDIA_RESOURCE_GRANTED.equals(action)) {
            if (DEBUG) {
                Log.d(TAG, "mBroadcastReceiver, action: " + intent.getAction());
            }
            switch (intent.getAction()) {
                case ACTION_MENU:
                    showPictureInPictureMenu();
                    break;
                case ACTION_CLOSE:
                    closePip();
                    break;
                case ACTION_MEDIA_RESOURCE_GRANTED:
                    String[] packageNames = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
                    int resourceType = intent.getIntExtra(Intent.EXTRA_MEDIA_RESOURCE_TYPE,
                            INVALID_RESOURCE_TYPE);
@@ -149,8 +162,8 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
                            && resourceType == Intent.EXTRA_MEDIA_RESOURCE_TYPE_VIDEO_CODEC) {
                        handleMediaResourceGranted(packageNames);
                    }
                    break;
            }

        }
    };
    private final MediaSessionManager.OnActiveSessionsChangedListener mActiveMediaSessionListener =
@@ -233,8 +246,11 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
            mPipTaskOrganizer = pipTaskOrganizer;
            mPipTaskOrganizer.registerPipTransitionCallback(this);
            mActivityTaskManager = ActivityTaskManager.getService();
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction(Intent.ACTION_MEDIA_RESOURCE_GRANTED);

            final IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction(ACTION_CLOSE);
            intentFilter.addAction(ACTION_MENU);
            intentFilter.addAction(ACTION_MEDIA_RESOURCE_GRANTED);
            mContext.registerReceiver(mBroadcastReceiver, intentFilter, UserHandle.USER_ALL);

            // Initialize the last orientation and apply the current configuration
@@ -249,11 +265,11 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to register pinned stack listener", e);
            }
        }

            // TODO(b/169395392) Refactor PipMenuActivity to PipMenuView
            PipMenuActivity.setPipController(this);
        }
    }

    private void loadConfigurationsAndApply(Configuration newConfig) {
        if (mLastOrientation != newConfig.orientation) {
@@ -564,6 +580,7 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
        } catch (RemoteException e) {
            Log.e(TAG, "getRootTaskInfo failed", e);
        }
        if (DEBUG) Log.d(TAG, "getPinnedTaskInfo(), taskInfo=" + taskInfo);
        return taskInfo;
    }

+2 −2
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import java.util.Collections;
 */
public class PipMenuActivity extends Activity implements PipController.Listener {
    private static final String TAG = "PipMenuActivity";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
    private static final boolean DEBUG = PipController.DEBUG;

    static final String EXTRA_CUSTOM_ACTIONS = "custom_actions";

@@ -51,7 +51,7 @@ public class PipMenuActivity extends Activity implements PipController.Listener
        if (DEBUG) Log.d(TAG, "onCreate()");

        super.onCreate(bundle);
        if (sPipController == null || sPipController.isPipShown()) {
        if (sPipController == null) {
            finish();
        }
        setContentView(R.layout.tv_pip_menu);
+2 −28
Original line number Diff line number Diff line
@@ -20,10 +20,8 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.RemoteAction;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
@@ -32,9 +30,7 @@ import android.graphics.Bitmap;
import android.media.MediaMetadata;
import android.media.session.MediaController;
import android.media.session.PlaybackState;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;

import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.wm.shell.R;
@@ -49,8 +45,8 @@ public class PipNotification {
    private static final String NOTIFICATION_TAG = PipNotification.class.getSimpleName();
    private static final boolean DEBUG = PipController.DEBUG;

    private static final String ACTION_MENU = "PipNotification.menu";
    private static final String ACTION_CLOSE = "PipNotification.close";
    static final String ACTION_MENU = "PipNotification.menu";
    static final String ACTION_CLOSE = "PipNotification.close";

    public static final String NOTIFICATION_CHANNEL_TVPIP = "TPP";

@@ -147,23 +143,6 @@ public class PipNotification {
                }
            };

    private final BroadcastReceiver mEventReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (DEBUG) {
                Log.d(TAG, "Received " + intent.getAction() + " from the notification UI");
            }
            switch (intent.getAction()) {
                case ACTION_MENU:
                    mPipController.showPictureInPictureMenu();
                    break;
                case ACTION_CLOSE:
                    mPipController.closePip();
                    break;
            }
        }
    };

    public PipNotification(Context context, PipController pipController) {
        mPackageManager = context.getPackageManager();

@@ -182,11 +161,6 @@ public class PipNotification {
        pipController.addListener(mPipListener);
        pipController.addMediaListener(mPipMediaListener);

        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ACTION_MENU);
        intentFilter.addAction(ACTION_CLOSE);
        context.registerReceiver(mEventReceiver, intentFilter, UserHandle.USER_ALL);

        onConfigurationChanged(context);
    }