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

Commit d691d3cf authored by Srinu Jella's avatar Srinu Jella Committed by Linux Build Service Account
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.

CRs-Fixed: 557180
Change-Id: Ic49b66599fb3c4c500e52295895d708dbc172cc7
(cherry picked from commit 80a5a8d9f465458c5417e532cc98970951f2c675)
(cherry picked from commit 5b4c228467074d2b71e02cd36c220584dba818fe)
parent c5aa6250
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
@@ -201,6 +201,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;
    }
    /**
@@ -405,6 +406,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();
+3 −0
Original line number Diff line number Diff line
@@ -87,4 +87,7 @@ interface IBluetooth
    ParcelFileDescriptor createSocketChannel(int type, in String serviceName, in ParcelUuid uuid, int port, int flag);

    boolean configHciSnoopLog(boolean enable);

    int setSocketOpt(int type, int port, int optionName, in byte [] optionVal, int optionLen);
    int getSocketOpt(int type, int port, int optionName, out byte [] optionVal);
}