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

Commit 9c8b03e4 authored by William Escande's avatar William Escande
Browse files

GetUuids refactor to call in correct order

getUuidsList was calling getUuids (return an Array[])
but the getUuids is already calling a method that return a List
By inversing their call we are no longer creating a temporary array

Bug: 222434921
Tag: #refactor
Test: pre-submit
Change-Id: I202d1923d21b795f191e1570cd489e01e78654bd
parent fb35baa9
Loading
Loading
Loading
Loading
+18 −20
Original line number Diff line number Diff line
@@ -1445,26 +1445,9 @@ public final class BluetoothAdapter {
    @RequiresBluetoothConnectPermission
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public @NonNull ParcelUuid[] getUuids() {
        if (getState() != STATE_ON) {
            return new ParcelUuid[0];
        }
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                final SynchronousResultReceiver<List<ParcelUuid>> recv =
                        new SynchronousResultReceiver();
                mService.getUuids(mAttributionSource, recv);
                List<ParcelUuid> parcels = recv.awaitResultNoInterrupt(getSyncTimeout())
                        .getValue(new ArrayList<>());
        List<ParcelUuid> parcels = getUuidsList();
        return parcels.toArray(new ParcelUuid[parcels.size()]);
    }
        } catch (RemoteException | TimeoutException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
        } finally {
            mServiceLock.readLock().unlock();
        }
        return new ParcelUuid[0];
    }

    /**
     * Get the UUIDs supported by the local Bluetooth adapter.
@@ -1475,7 +1458,22 @@ public final class BluetoothAdapter {
    @SystemApi
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public @NonNull List<ParcelUuid> getUuidsList() {
        return Arrays.asList(getUuids());
        List<ParcelUuid> defaultValue = new ArrayList<>();
        if (getState() != STATE_ON || mService == null) {
            return defaultValue;
        }
        mServiceLock.readLock().lock();
        try {
            final SynchronousResultReceiver<List<ParcelUuid>> recv =
                    new SynchronousResultReceiver();
            mService.getUuids(mAttributionSource, recv);
            return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
        } catch (RemoteException | TimeoutException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
        } finally {
            mServiceLock.readLock().unlock();
        }
        return defaultValue;
    }

    /**