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

Commit 7cf83124 authored by Jeykumar Sankaran's avatar Jeykumar Sankaran Committed by Linux Build Service Account
Browse files

frameworks/base: Use ExtendedRemoteDisplay to launch Wifi Display

- RemoteDisplay class is used to launch WiFi Display
  implementation in the Android framework with a discovered peer.
  There is a need to support proprietary implementation of wifi
  display instead of the framework implementation.

- To enable this support, ExtendedRemoteDisplay is added,
  which launches the proprietary solution. ExtendedRemoteDisplay object
  is created if the class is available in the package. If the class is
  not available the default implementation will be used by creating
  RemoteDisplay.

Change-Id: I2e2a5e552bc86888848c0402bafd873620b05c21
(cherry picked from commit 912d47682c5ec65ff0aaa0a59cc5d28110482392)
(cherry picked from commit a9c91658d40a38f4f6e204a33d9bc70bcf97ede3)
parent 16dad200
Loading
Loading
Loading
Loading
+163 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *     * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials provided
 *      with the distribution.
 *     * Neither the name of The Linux Foundation nor the names of its
 *      contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.android.server.display;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.media.RemoteDisplay;
import android.os.Handler;
import android.util.Slog;
import android.content.Context;

class ExtendedRemoteDisplayHelper {
    private static final String TAG = "ExtendedRemoteDisplayHelper";

    // ExtendedRemoteDisplay class
    // ExtendedRemoteDisplay is an enhanced RemoteDisplay. It has
    // similar interface as RemoteDisplay class
    private static Class sExtRemoteDisplayClass;

    // Method object for the API ExtendedRemoteDisplay.Listen
    // ExtendedRemoteDisplay.Listen has the same API signature as
    // RemoteDisplay.Listen except for an additional argument to pass the
    // Context
    private static Method sExtRemoteDisplayListen;

    // Method Object for the API ExtendedRemoteDisplay.Dispose
    // ExtendedRemoteDisplay.Dispose follows the same API signature as
    // RemoteDisplay.Dispose
    private static Method sExtRemoteDisplayDispose;

    static {
        //Check availability of ExtendedRemoteDisplay runtime
        try {
            sExtRemoteDisplayClass = Class.forName("com.qualcomm.wfd.ExtendedRemoteDisplay");
        } catch (Throwable t) {
            Slog.i(TAG, "ExtendedRemoteDisplay Not available.");
        }

        if(sExtRemoteDisplayClass != null) {
            // If ExtendedRemoteDisplay is available find the methods
            Slog.i(TAG, "ExtendedRemoteDisplay Is available. Find Methods");
            try {
                Class args[] = {
                                   String.class,
                                   RemoteDisplay.Listener.class,
                                   Handler.class, Context.class
                               };
                sExtRemoteDisplayListen = sExtRemoteDisplayClass.getDeclaredMethod("listen", args);
            } catch (Throwable t) {
                Slog.i(TAG, "ExtendedRemoteDisplay.listen Not available.");
            }

            try {
                Class args[] = {};
                sExtRemoteDisplayDispose = sExtRemoteDisplayClass.getDeclaredMethod("dispose", args);
            } catch (Throwable t) {
                Slog.i(TAG, "ExtendedRemoteDisplay.dispose Not available.");
            }
        }
    }

    /**
     * Starts listening for displays to be connected on the specified interface.
     *
     * @param iface The interface address and port in the form "x.x.x.x:y".
     * @param listener The listener to invoke
     *         when displays are connected or disconnected.
     * @param handler The handler on which to invoke the listener.
     * @param context The current service context
     *  */
    public static Object listen(String iface, RemoteDisplay.Listener listener,
                                         Handler handler, Context context)
    {
        Object extRemoteDisplay = null;
        Slog.i(TAG, "ExtendedRemoteDisplay.listen");

        if(sExtRemoteDisplayListen != null && sExtRemoteDisplayDispose != null){
            try {
                extRemoteDisplay = sExtRemoteDisplayListen.invoke(null,
                                  iface, listener, handler, context);
            } catch (InvocationTargetException e) {
                Slog.i(TAG, "ExtendedRemoteDisplay.listen - InvocationTargetException");
                Throwable cause = e.getCause();
                if (cause instanceof RuntimeException) {
                    throw (RuntimeException) cause;
                } else if (cause instanceof Error) {
                    throw (Error) cause;
                } else {
                    throw new RuntimeException(e);
                }
            } catch (IllegalAccessException e) {
                Slog.i(TAG, "ExtendedRemoteDisplay.listen -IllegalAccessException");
                e.printStackTrace();
            }
        }
        return extRemoteDisplay;
    }

    /**
     * Disconnects the remote display and stops listening for new connections.
     */
    public static void dispose(Object extRemoteDisplay) {
        Slog.i(TAG, "ExtendedRemoteDisplay.dispose");
        try{
            sExtRemoteDisplayDispose.invoke(extRemoteDisplay);
        } catch (InvocationTargetException e) {
            Slog.i(TAG, "ExtendedRemoteDisplay.dispose - InvocationTargetException");
            Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            } else if (cause instanceof Error) {
                throw (Error) cause;
            } else {
                throw new RuntimeException(e);
            }
        } catch (IllegalAccessException e) {
            Slog.i(TAG, "ExtendedRemoteDisplay.dispose-IllegalAccessException");
            e.printStackTrace();
        }
    }

    /**
     * Checks if ExtendedRemoteDisplay is available
     */
    public static boolean isAvailable()
    {
        if(sExtRemoteDisplayClass != null &&
           sExtRemoteDisplayDispose != null &&
           sExtRemoteDisplayListen != null) {
            Slog.i(TAG, "ExtendedRemoteDisplay isAvailable() : Available.");
            return true;
        }
        Slog.i(TAG, "ExtendedRemoteDisplay isAvailable() : Not Available.");
        return false;
    }
}
+26 −6
Original line number Original line Diff line number Diff line
@@ -131,6 +131,10 @@ final class WifiDisplayController implements DumpUtils.Dump {
    // Number of connection retries remaining.
    // Number of connection retries remaining.
    private int mConnectionRetriesLeft;
    private int mConnectionRetriesLeft;


    // The Extended remote display that is listening on the connection.
    // Created after the Wifi P2P network is connected.
    private Object mExtRemoteDisplay;

    // The remote display that is listening on the connection.
    // The remote display that is listening on the connection.
    // Created after the Wifi P2P network is connected.
    // Created after the Wifi P2P network is connected.
    private RemoteDisplay mRemoteDisplay;
    private RemoteDisplay mRemoteDisplay;
@@ -510,11 +514,19 @@ final class WifiDisplayController implements DumpUtils.Dump {
    private void updateConnection() {
    private void updateConnection() {
        // Step 1. Before we try to connect to a new device, tell the system we
        // Step 1. Before we try to connect to a new device, tell the system we
        // have disconnected from the old one.
        // have disconnected from the old one.
        if (mRemoteDisplay != null && mConnectedDevice != mDesiredDevice) {
        if ((mRemoteDisplay != null || mExtRemoteDisplay != null) &&
            Slog.i(TAG, "Stopped listening for RTSP connection on " + mRemoteDisplayInterface
                mConnectedDevice != mDesiredDevice) {
            Slog.i(TAG, "Stopped listening for RTSP connection on "
                    + mRemoteDisplayInterface
                    + " from Wifi display: " + mConnectedDevice.deviceName);
                    + " from Wifi display: " + mConnectedDevice.deviceName);


            if(mRemoteDisplay != null) {
                mRemoteDisplay.dispose();
                mRemoteDisplay.dispose();
            } else if(mExtRemoteDisplay != null) {
                ExtendedRemoteDisplayHelper.dispose(mExtRemoteDisplay);
            }

            mExtRemoteDisplay = null;
            mRemoteDisplay = null;
            mRemoteDisplay = null;
            mRemoteDisplayInterface = null;
            mRemoteDisplayInterface = null;
            mRemoteDisplayConnected = false;
            mRemoteDisplayConnected = false;
@@ -662,7 +674,8 @@ final class WifiDisplayController implements DumpUtils.Dump {
        }
        }


        // Step 6. Listen for incoming connections.
        // Step 6. Listen for incoming connections.
        if (mConnectedDevice != null && mRemoteDisplay == null) {
        if (mConnectedDevice != null && (mRemoteDisplay == null &&
                    mExtRemoteDisplay == null)) {
            Inet4Address addr = getInterfaceAddress(mConnectedDeviceGroupInfo);
            Inet4Address addr = getInterfaceAddress(mConnectedDeviceGroupInfo);
            if (addr == null) {
            if (addr == null) {
                Slog.i(TAG, "Failed to get local interface address for communicating "
                Slog.i(TAG, "Failed to get local interface address for communicating "
@@ -681,7 +694,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
            Slog.i(TAG, "Listening for RTSP connection on " + iface
            Slog.i(TAG, "Listening for RTSP connection on " + iface
                    + " from Wifi display: " + mConnectedDevice.deviceName);
                    + " from Wifi display: " + mConnectedDevice.deviceName);


            mRemoteDisplay = RemoteDisplay.listen(iface, new RemoteDisplay.Listener() {
            RemoteDisplay.Listener listener = new RemoteDisplay.Listener() {
                @Override
                @Override
                public void onDisplayConnected(Surface surface,
                public void onDisplayConnected(Surface surface,
                        int width, int height, int flags, int session) {
                        int width, int height, int flags, int session) {
@@ -720,7 +733,14 @@ final class WifiDisplayController implements DumpUtils.Dump {
                        handleConnectionFailure(false);
                        handleConnectionFailure(false);
                    }
                    }
                }
                }
            }, mHandler);
            };
            if(ExtendedRemoteDisplayHelper.isAvailable()){
                mExtRemoteDisplay = ExtendedRemoteDisplayHelper.listen(iface,
                        listener, mHandler, mContext);
            } else {
                mRemoteDisplay = RemoteDisplay.listen(iface, listener,
                        mHandler);
            }


            // Use extended timeout value for certification, as some tests require user inputs
            // Use extended timeout value for certification, as some tests require user inputs
            int rtspTimeout = mWifiDisplayCertMode ?
            int rtspTimeout = mWifiDisplayCertMode ?