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

Commit 8b485adf authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Add support for setMiracastMode

Usage is setMiracastMode(WifiP2pManager.MIRACAST_SOURCE) or
setMiracastMode(WifiP2pManager.MIRACAST_SINK) as an example.
Only available for internal use and can be called as long as
driver is active. P2p connection is not needed for it to be
called

Bug: 8493089
Change-Id: I1f87eaf3311212aae980077de26c05651a8cc811
parent f2b0fdb2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -793,4 +793,14 @@ public class WifiNative {
    public boolean p2pServDiscCancelReq(String id) {
        return doBooleanCommand("P2P_SERV_DISC_CANCEL_REQ " + id);
    }

    /* Set the current mode of miracast operation.
     *  0 = disabled
     *  1 = operating as source
     *  2 = operating as sink
     */
    public void setMiracastMode(int mode) {
        // Note: optional feature on the driver. It is ok for this to fail.
        doBooleanCommand("DRIVER MIRACAST " + mode);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -26,5 +26,6 @@ import android.os.Messenger;
interface IWifiP2pManager
{
    Messenger getMessenger();
    void setMiracastMode(int mode);
}
+15 −0
Original line number Diff line number Diff line
@@ -1258,6 +1258,21 @@ public class WifiP2pManager {
        c.mAsyncChannel.sendMessage(REQUEST_PERSISTENT_GROUP_INFO, 0, c.putListener(listener));
    }

    /** @hide */
    public static final int MIRACAST_DISABLED = 0;
    /** @hide */
    public static final int MIRACAST_SOURCE   = 1;
    /** @hide */
    public static final int MIRACAST_SINK     = 2;
    /** Internal use only @hide */
    public void setMiracastMode(int mode) {
        try {
            mService.setMiracastMode(mode);
        } catch(RemoteException e) {
           // ignore
        }
    }

    /**
     * Get a reference to WifiP2pService handler. This is used to establish
     * an AsyncChannel communication with WifiService
+30 −4
Original line number Diff line number Diff line
@@ -164,6 +164,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
    public static final int DISCONNECT_WIFI_REQUEST         =   BASE + 12;
    public static final int DISCONNECT_WIFI_RESPONSE        =   BASE + 13;

    public static final int SET_MIRACAST_MODE               =   BASE + 14;

    private final boolean mP2pSupported;

    private WifiP2pDevice mThisDevice = new WifiP2pDevice();
@@ -310,6 +312,12 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
                "WifiP2pService");
    }

    private void enforceConnectivityInternalPermission() {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CONNECTIVITY_INTERNAL,
                "WifiP2pService");
    }

    /**
     * Get a reference to handler. This is used by a client to establish
     * an AsyncChannel communication with WifiP2pService
@@ -320,6 +328,20 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
        return new Messenger(mP2pStateMachine.getHandler());
    }

    /** This is used to provide information to drivers to optimize performance depending
     * on the current mode of operation.
     * 0 - disabled
     * 1 - source operation
     * 2 - sink operation
     *
     * As an example, the driver could reduce the channel dwell time during scanning
     * when acting as a source or sink to minimize impact on miracast.
     */
    public void setMiracastMode(int mode) {
        enforceConnectivityInternalPermission();
        mP2pStateMachine.sendMessage(SET_MIRACAST_MODE, mode);
    }

    @Override
    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
@@ -572,6 +594,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
                case DhcpStateMachine.CMD_POST_DHCP_ACTION:
                case DhcpStateMachine.CMD_ON_QUIT:
                case WifiMonitor.P2P_PROV_DISC_FAILURE_EVENT:
                case SET_MIRACAST_MODE:
                    break;
                case WifiStateMachine.CMD_ENABLE_P2P:
                    // Enable is lazy and has no response
@@ -932,6 +955,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
                   mGroups.remove(message.arg1);
                   replyToMessage(message, WifiP2pManager.DELETE_PERSISTENT_GROUP_SUCCEEDED);
                   break;
                case SET_MIRACAST_MODE:
                    mWifiNative.setMiracastMode(message.arg1);
                    break;
                default:
                   return NOT_HANDLED;
            }