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

Commit 011c8572 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Adding PIP input consumer."

parents 156254da 41275481
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -454,12 +454,13 @@ interface IWindowManager
    void registerShortcutKey(in long shortcutCode, IShortcutService keySubscriber);

    /**
     * Create the input consumer for wallpaper events.
     * Create an input consumer by name.
     */
    void createWallpaperInputConsumer(out InputChannel inputChannel);
    void createInputConsumer(String name, out InputChannel inputChannel);

    /**
     * Remove the input consumer for wallpaper events.
     * Destroy an input consumer by name.  This method will also dispose the input channels
     * associated with that InputConsumer.
     */
    void removeWallpaperInputConsumer();
    boolean destroyInputConsumer(String name);
}
+7 −0
Original line number Diff line number Diff line
@@ -64,6 +64,13 @@ public interface WindowManager extends ViewManager {
    /** @hide */
    int DOCKED_BOTTOM = 4;

    /** @hide */
    final static String INPUT_CONSUMER_PIP = "pip_input_consumer";
    /** @hide */
    final static String INPUT_CONSUMER_NAVIGATION = "nav_input_consumer";
    /** @hide */
    final static String INPUT_CONSUMER_WALLPAPER = "wallpaper_input_consumer";

    /**
     * Exception that is thrown when trying to add view whose
     * {@link LayoutParams} {@link LayoutParams#token}
+1 −1
Original line number Diff line number Diff line
@@ -458,7 +458,7 @@ public interface WindowManagerPolicy {
        /**
         * Add a input consumer which will consume all input events going to any window below it.
         */
        public InputConsumer addInputConsumer(Looper looper,
        public InputConsumer createInputConsumer(Looper looper, String name,
                InputEventReceiver.Factory inputEventReceiverFactory);

        /**
+50 −7
Original line number Diff line number Diff line
@@ -19,13 +19,13 @@ package com.android.systemui.tv.pip;
import android.app.ActivityManager.RunningTaskInfo;
import android.app.ActivityManager.StackInfo;
import android.app.ActivityManagerNative;
import android.app.ActivityOptions;
import android.app.IActivityManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Rect;
import android.media.session.MediaController;
@@ -33,24 +33,27 @@ import android.media.session.MediaSessionManager;
import android.media.session.PlaybackState;
import android.os.Debug;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

import android.view.IWindowManager;
import android.view.InputChannel;
import android.view.InputEvent;
import android.view.InputEventReceiver;
import android.view.WindowManagerGlobal;
import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.statusbar.tv.TvStatusBar;
import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;

import java.util.ArrayList;
import java.util.List;

import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.view.WindowManager.INPUT_CONSUMER_PIP;
import static com.android.systemui.Prefs.Key.TV_PICTURE_IN_PICTURE_ONBOARDING_SHOWN;

/**
@@ -160,6 +163,9 @@ public class PipManager {
    private boolean mOnboardingShown;
    private String[] mLastPackagesResourceGranted;

    private InputChannel mInputChannel;
    private PipInputEventReceiver mInputEventReceiver;

    private final Runnable mResizePinnedStackRunnable = new Runnable() {
        @Override
        public void run() {
@@ -197,6 +203,25 @@ public class PipManager {
                }
            };

    /**
     * Input handler used for Pip windows.  Currently eats all the input events.
     */
    private final class PipInputEventReceiver extends InputEventReceiver {
        public PipInputEventReceiver(InputChannel inputChannel, Looper looper) {
            super(inputChannel, looper);
        }

        @Override
        public void onInputEvent(InputEvent event) {
            boolean handled = true;
            try {
                // To be implemented for input handling over Pip windows
            } finally {
                finishInputEvent(event, handled);
            }
        }
    }

    private PipManager() { }

    /**
@@ -221,6 +246,20 @@ public class PipManager {
        mPipRecentsOverlayManager = new PipRecentsOverlayManager(context);
        mMediaSessionManager =
                (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE);

        PackageManager pm = mContext.getPackageManager();
        if (!pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY)) {
            // Initialize the Pip input consumer
            mInputChannel = new InputChannel();
            try {
                IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
                wm.destroyInputConsumer(INPUT_CONSUMER_PIP);
                wm.createInputConsumer(INPUT_CONSUMER_PIP, mInputChannel);
                mInputEventReceiver = new PipInputEventReceiver(mInputChannel, Looper.myLooper());
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to create Pip input consumer", e);
            }
        }
    }

    private void loadConfigurationsAndApply() {
@@ -308,8 +347,12 @@ public class PipManager {
     */
    private void showPipOverlay() {
        if (DEBUG) Log.d(TAG, "showPipOverlay()");
        // Temporary workaround to prevent the overlay on phones
        PackageManager pm = mContext.getPackageManager();
        if (pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY)) {
            PipOverlayActivity.showPipOverlay(mContext);
        }
    }

    /**
     * Suspends resizing operation on the Pip until {@link #resumePipResizing} is called
+2 −4
Original line number Diff line number Diff line
@@ -21,11 +21,10 @@ import android.content.res.Configuration;

import com.android.systemui.SystemUI;

import static android.content.pm.PackageManager.FEATURE_LEANBACK;
import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;

/**
 * Controls the picture-in-picture window for TV devices.
 * Controls the picture-in-picture window.
 */
public class PipUI extends SystemUI {
    private boolean mSupportPip;
@@ -33,8 +32,7 @@ public class PipUI extends SystemUI {
    @Override
    public void start() {
        PackageManager pm = mContext.getPackageManager();
        mSupportPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)
                && pm.hasSystemFeature(FEATURE_LEANBACK);
        mSupportPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE);
        if (!mSupportPip) {
            return;
        }
Loading