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

Commit 7a6f3587 authored by Srinu Jella's avatar Srinu Jella Committed by Steve Kondik
Browse files

Bluetooth: Add Get/Set socket option to the Bluetooth Socket

Introduced Get/Set socket option to the Bluetooth Socket.
For these APIs it will directly call the APIs of Adapter
Service.The corresponding APIs have been implemented in
the Adapter service of native Bluetooth APK.

Change-Id: Ic49b66599fb3c4c500e52295895d708dbc172cc7
parent 1ad4a6d1
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
@@ -200,6 +200,7 @@ public final class BluetoothSocket implements Closeable {
        as.mSocketOS = as.mSocket.getOutputStream();
        as.mAddress = RemoteAddr;
        as.mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(RemoteAddr);
        as.mPort = mPort;
        return as;
    }
    /**
@@ -404,6 +405,61 @@ public final class BluetoothSocket implements Closeable {
        return acceptedSocket;
    }

    /**
     * setSocketOpt for the Buetooth Socket.
     *
     * @param optionName socket option name
     * @param optionVal  socket option value
     * @param optionLen  socket option length
     * @return -1 on immediate error,
     *               0 otherwise
     * @hide
     */
    public int setSocketOpt(int optionName, byte [] optionVal, int optionLen) throws IOException {
        int ret = 0;
        if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
        IBluetooth bluetoothProxy = BluetoothAdapter.getDefaultAdapter().getBluetoothService(null);
        if (bluetoothProxy == null) {
            Log.e(TAG, "setSocketOpt fail, reason: bluetooth is off");
            return -1;
        }
        try {
            if(VDBG) Log.d(TAG, "setSocketOpt(), mType: " + mType + " mPort: " + mPort);
            ret = bluetoothProxy.setSocketOpt(mType, mPort, optionName, optionVal, optionLen);
        } catch (RemoteException e) {
            Log.e(TAG, Log.getStackTraceString(new Throwable()));
            return -1;
        }
        return ret;
    }

    /**
     * getSocketOpt for the Buetooth Socket.
     *
     * @param optionName socket option name
     * @param optionVal  socket option value
     * @return -1 on immediate error,
     *               length of returned socket option otherwise
     * @hide
     */
    public int getSocketOpt(int optionName, byte [] optionVal) throws IOException {
        int ret = 0;
        if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
        IBluetooth bluetoothProxy = BluetoothAdapter.getDefaultAdapter().getBluetoothService(null);
        if (bluetoothProxy == null) {
            Log.e(TAG, "getSocketOpt fail, reason: bluetooth is off");
            return -1;
        }
        try {
            if(VDBG) Log.d(TAG, "getSocketOpt(), mType: " + mType + " mPort: " + mPort);
            ret = bluetoothProxy.getSocketOpt(mType, mPort, optionName, optionVal);
        } catch (RemoteException e) {
            Log.e(TAG, Log.getStackTraceString(new Throwable()));
            return -1;
        }
        return ret;
    }

    /*package*/ int available() throws IOException {
        if (VDBG) Log.d(TAG, "available: " + mSocketIS);
        return mSocketIS.available();
+2 −0
Original line number Diff line number Diff line
@@ -85,4 +85,6 @@ interface IBluetooth
    // For Socket
    ParcelFileDescriptor connectSocket(in BluetoothDevice device, int type, in ParcelUuid uuid, int port, int flag);
    ParcelFileDescriptor createSocketChannel(int type, in String serviceName, in ParcelUuid uuid, int port, int flag);
    int setSocketOpt(int type, int port, int optionName, in byte [] optionVal, int optionLen);
    int getSocketOpt(int type, int port, int optionName, out byte [] optionVal);
}