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

Commit 77a57ad9 authored by William Escande's avatar William Escande
Browse files

Revert the getSocketManager Synchronous call

Fix: 216736996
Tag: #stability
Test: atest 'CtsBluetoothTestCases:android.bluetooth.cts.BasicAdapterTest#test_listenUsingRfcommWithServiceRecord'
Test: atest 'CtsBluetoothTestCases:android.bluetooth.cts.LeL2capSocketTest#testOpenInsecureLeL2capServerSocketOnce'
Ignore-AOSP-First: No such change on AOSP yet

Change-Id: I1242fd01105265949a59deca9bf45e99e2a12a38
parent e10aefec
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -2969,14 +2969,7 @@ public class AdapterService extends Service {
        }

        @Override
        public void getSocketManager(SynchronousResultReceiver receiver) {
            try {
                receiver.send(getSocketManager());
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }
        private IBluetoothSocketManager getSocketManager() {
        public IBluetoothSocketManager getSocketManager() {
            AdapterService service = getService();
            if (service == null) {
                return null;
+6 −23
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package android.bluetooth;

import static android.bluetooth.BluetoothUtils.getSyncTimeout;

import android.annotation.RequiresNoPermission;
import android.annotation.RequiresPermission;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
@@ -29,8 +27,6 @@ import android.os.ParcelUuid;
import android.os.RemoteException;
import android.util.Log;

import com.android.modules.utils.SynchronousResultReceiver;

import java.io.Closeable;
import java.io.FileDescriptor;
import java.io.IOException;
@@ -41,7 +37,6 @@ import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.TimeoutException;

/**
 * A connected or connecting Bluetooth socket.
@@ -432,11 +427,7 @@ public final class BluetoothSocket implements Closeable {
            IBluetooth bluetoothProxy =
                    BluetoothAdapter.getDefaultAdapter().getBluetoothService();
            if (bluetoothProxy == null) throw new IOException("Bluetooth is off");
            final SynchronousResultReceiver<IBluetoothSocketManager> recv =
                    new SynchronousResultReceiver();
            bluetoothProxy.getSocketManager(recv);
            IBluetoothSocketManager socketManager =
                    recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            IBluetoothSocketManager socketManager = bluetoothProxy.getSocketManager();
            if (socketManager == null) throw new IOException("bt get socket manager failed");
            mPfd = socketManager.connectSocket(mDevice, mType, mUuid, mPort, getSecurityFlags());
            synchronized (this) {
@@ -460,7 +451,7 @@ public final class BluetoothSocket implements Closeable {
                }
                mSocketState = SocketState.CONNECTED;
            }
        } catch (RemoteException | TimeoutException e) {
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            throw new IOException("unable to send RPC: " + e.getMessage());
        }
@@ -481,18 +472,14 @@ public final class BluetoothSocket implements Closeable {
        }
        try {
            if (DBG) Log.d(TAG, "bindListen(): mPort=" + mPort + ", mType=" + mType);
            final SynchronousResultReceiver<IBluetoothSocketManager> recv =
                    new SynchronousResultReceiver();
            bluetoothProxy.getSocketManager(recv);
            IBluetoothSocketManager socketManager =
                    recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            IBluetoothSocketManager socketManager = bluetoothProxy.getSocketManager();
            if (socketManager == null) {
                Log.e(TAG, "bindListen() bt get socket manager failed");
                return -1;
            }
            mPfd = socketManager
                .createSocketChannel(mType, mServiceName, mUuid, mPort, getSecurityFlags());
        } catch (RemoteException | TimeoutException e) {
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            return -1;
        }
@@ -757,14 +744,10 @@ public final class BluetoothSocket implements Closeable {
            }

            if (DBG) Log.d(TAG, "requestMaximumTxDataLength");
            final SynchronousResultReceiver<IBluetoothSocketManager> recv =
                    new SynchronousResultReceiver();
            bluetoothProxy.getSocketManager(recv);
            IBluetoothSocketManager socketManager =
                    recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            IBluetoothSocketManager socketManager = bluetoothProxy.getSocketManager();
            if (socketManager == null) throw new IOException("bt get socket manager failed");
            socketManager.requestMaximumTxDataLength(mDevice);
        } catch (RemoteException | TimeoutException e) {
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            throw new IOException("unable to send RPC: " + e.getMessage());
        }
+1 −1
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ interface IBluetooth

    // For Socket
    @JavaPassthrough(annotation="@android.annotation.RequiresNoPermission")
    oneway void getSocketManager(in SynchronousResultReceiver receiver);
    IBluetoothSocketManager getSocketManager();

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    oneway void factoryReset(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);