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

Commit 4650f7ac authored by Srinu Jella's avatar Srinu Jella Committed by Ricardo Cerqueira
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
Conflicts:
core/java/android/bluetooth/IBluetooth.aidl
parent 197565c3
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;
    }
    /**
@@ -414,6 +415,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
@@ -97,4 +97,7 @@ interface IBluetooth
    boolean isActivityAndEnergyReportingSupported();
    void getActivityEnergyInfoFromController();
    BluetoothActivityEnergyInfo reportActivityInfo();

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