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

Commit 0b495ea0 authored by Sergey Nikolaienkov's avatar Sergey Nikolaienkov
Browse files

Fix Pip dependenices on TV

Fix crash in .tv.PipController: .tv.PipController creates a
PipNotification object before assigning mPipMediaController, but
PipNotification calls PipController#getPipMediaController() from its
constructor, receives null, and causes NPE when tries to subscribe to
it.
This CL fixes the crash by providing PipNotification with a
PipMediaController reference directly (as a constructor param).

Bug: 169575409
Bug: 165795012
Test: make && flash adt3-userdebug
Test: atest android.systemui.cts.tv.MicIndicatorTest
Change-Id: I0010863921607cc315acfcbe0cb9d181b79d26b2
parent 63a37a3a
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -224,10 +224,11 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
            PipBoundsHandler pipBoundsHandler,
            PipTaskOrganizer pipTaskOrganizer,
            PipMediaController pipMediaController,
            PipNotification pipNotification,
            WindowManagerShellWrapper windowManagerShellWrapper) {
        mContext = context;
        mPipBoundsState = pipBoundsState;
        mPipNotification = new PipNotification(context, this);
        mPipNotification = pipNotification;
        mPipBoundsHandler = pipBoundsHandler;
        mPipMediaController = pipMediaController;
        // Ensure that we have the display info in case we get calls to update the bounds
@@ -242,6 +243,8 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
        mPipTaskOrganizer.registerPipTransitionCallback(this);
        mActivityTaskManager = ActivityTaskManager.getService();

        addListener(mPipNotification);

        final IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ACTION_CLOSE);
        intentFilter.addAction(ACTION_MENU);
+37 −39
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.text.TextUtils;

import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.wm.shell.R;
import com.android.wm.shell.pip.PipMediaController;

import java.util.Objects;

@@ -40,7 +41,7 @@ import java.util.Objects;
 * <p>Once it's created, it will manage the PIP notification UI by itself except for handling
 * configuration changes.
 */
public class PipNotification {
public class PipNotification implements PipController.Listener {
    private static final boolean DEBUG = PipController.DEBUG;
    private static final String TAG = "PipNotification";

@@ -63,7 +64,23 @@ public class PipNotification {
    private String mMediaTitle;
    private Bitmap mArt;

    private PipController.Listener mPipListener = new PipController.Listener() {
    public PipNotification(Context context, PipMediaController pipMediaController) {
        mPackageManager = context.getPackageManager();
        mNotificationManager = context.getSystemService(NotificationManager.class);

        mNotificationBuilder = new Notification.Builder(context, NOTIFICATION_CHANNEL_TVPIP)
                .setLocalOnly(true)
                .setOngoing(false)
                .setCategory(Notification.CATEGORY_SYSTEM)
                .extend(new Notification.TvExtender()
                        .setContentIntent(createPendingIntent(context, ACTION_MENU))
                        .setDeleteIntent(createPendingIntent(context, ACTION_CLOSE)));

        pipMediaController.addMetadataListener(this::onMediaMetadataChanged);

        onConfigurationChanged(context);
    }

    @Override
    public void onPipEntered(String packageName) {
        mPackageName = packageName;
@@ -96,25 +113,6 @@ public class PipNotification {
    public void onPipResizeAboutToStart() {
        // no-op.
    }
    };

    public PipNotification(Context context, PipController pipController) {
        mPackageManager = context.getPackageManager();
        mNotificationManager = context.getSystemService(NotificationManager.class);

        mNotificationBuilder = new Notification.Builder(context, NOTIFICATION_CHANNEL_TVPIP)
                .setLocalOnly(true)
                .setOngoing(false)
                .setCategory(Notification.CATEGORY_SYSTEM)
                .extend(new Notification.TvExtender()
                        .setContentIntent(createPendingIntent(context, ACTION_MENU))
                        .setDeleteIntent(createPendingIntent(context, ACTION_CLOSE)));

        pipController.addListener(mPipListener);
        pipController.getPipMediaController().addMetadataListener(this::onMediaMetadataChanged);

        onConfigurationChanged(context);
    }

    private void onMediaMetadataChanged(MediaMetadata metadata) {
        if (updateMediaControllerMetadata(metadata) && mNotified) {
+4 −2
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ public abstract class TvPipModule {
            PipBoundsHandler pipBoundsHandler,
            PipTaskOrganizer pipTaskOrganizer,
            PipMediaController pipMediaController,
            PipNotification pipNotification,
            WindowManagerShellWrapper windowManagerShellWrapper) {
        return Optional.of(
                new PipController(
@@ -61,6 +62,7 @@ public abstract class TvPipModule {
                        pipBoundsHandler,
                        pipTaskOrganizer,
                        pipMediaController,
                        pipNotification,
                        windowManagerShellWrapper));
    }

@@ -80,8 +82,8 @@ public abstract class TvPipModule {
    @WMSingleton
    @Provides
    static PipNotification providePipNotification(Context context,
            PipController pipController) {
        return new PipNotification(context, pipController);
            PipMediaController pipMediaController) {
        return new PipNotification(context, pipMediaController);
    }

    @WMSingleton