From 07c7b34fe75797638777c2cd113973e975d892ae Mon Sep 17 00:00:00 2001 From: lbill Date: Wed, 14 Oct 2020 12:38:29 +0000 Subject: [PATCH] Move ACTION_MENU/ACTION_CLOSE intent registraction to PipController - Fix the logic error when start PipMenuActivity - Move ACTION_MENU/ACTION_CLOSE eventReceiver to tv/PipController Bug: 168113354 Test: atest CtsSystemUiTestCases Test: atest android.systemui.cts.tv.BasicPipTests Test: adb shell am start -n \ com.android.systemui/com.android.wm.shell.pip.tv.PipMenuActivity Test: adb shell am start -n \ android.systemui.cts.tv.pip/.PipTestActivity -a \ android.systemui.cts.tv.pip.PipTestActivity.enter_pip Test: adb shell am broadcast -a PipNotification.close Test: adb shell am broadcast -a PipNotification.menu Change-Id: Idd4eaa0a7f8a8305caa004f45c549ec808d044a2 --- .../wm/shell/pip/tv/PipController.java | 47 +++++++++++++------ .../wm/shell/pip/tv/PipMenuActivity.java | 4 +- .../wm/shell/pip/tv/PipNotification.java | 30 +----------- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipController.java index 8eac005425bcc..4f2d4e50f76df 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipController.java @@ -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,17 +144,26 @@ 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)) { - String[] packageNames = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES); - int resourceType = intent.getIntExtra(Intent.EXTRA_MEDIA_RESOURCE_TYPE, - INVALID_RESOURCE_TYPE); - if (packageNames != null && packageNames.length > 0 - && resourceType == Intent.EXTRA_MEDIA_RESOURCE_TYPE_VIDEO_CODEC) { - handleMediaResourceGranted(packageNames); - } + 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); + if (packageNames != null && packageNames.length > 0 + && 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,10 +265,10 @@ 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); + // TODO(b/169395392) Refactor PipMenuActivity to PipMenuView + PipMenuActivity.setPipController(this); + } } private void loadConfigurationsAndApply(Configuration newConfig) { @@ -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; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipMenuActivity.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipMenuActivity.java index 06d2408c95f40..e185a96044496 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipMenuActivity.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipMenuActivity.java @@ -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); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipNotification.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipNotification.java index 7433085e6fcbe..f5bbd23fa1d6f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipNotification.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipNotification.java @@ -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); }