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

Commit 03cd78cf authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Convert return type of APIs from Set to List.

Most of the time it will either be empty or have 1 device.
Using list makes it much a better API and since its supported
by the AIDL format, the code becomes much nicer.

Change-Id: I5a2508b33ba754fc8cc738409d658e1235aaf2cf
parent e1627c9d
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -36131,7 +36131,7 @@
<implements name="android.bluetooth.BluetoothProfile">
</implements>
<method name="getConnectedDevices"
 return="java.util.Set&lt;android.bluetooth.BluetoothDevice&gt;"
 return="java.util.List&lt;android.bluetooth.BluetoothDevice&gt;"
 abstract="false"
 native="false"
 synchronized="false"
@@ -36155,7 +36155,7 @@
</parameter>
</method>
<method name="getDevicesMatchingConnectionStates"
 return="java.util.Set&lt;android.bluetooth.BluetoothDevice&gt;"
 return="java.util.List&lt;android.bluetooth.BluetoothDevice&gt;"
 abstract="false"
 native="false"
 synchronized="false"
@@ -37969,7 +37969,7 @@
<implements name="android.bluetooth.BluetoothProfile">
</implements>
<method name="getConnectedDevices"
 return="java.util.Set&lt;android.bluetooth.BluetoothDevice&gt;"
 return="java.util.List&lt;android.bluetooth.BluetoothDevice&gt;"
 abstract="false"
 native="false"
 synchronized="false"
@@ -37993,7 +37993,7 @@
</parameter>
</method>
<method name="getDevicesMatchingConnectionStates"
 return="java.util.Set&lt;android.bluetooth.BluetoothDevice&gt;"
 return="java.util.List&lt;android.bluetooth.BluetoothDevice&gt;"
 abstract="false"
 native="false"
 synchronized="false"
@@ -38097,7 +38097,7 @@
 visibility="public"
>
<method name="getConnectedDevices"
 return="java.util.Set&lt;android.bluetooth.BluetoothDevice&gt;"
 return="java.util.List&lt;android.bluetooth.BluetoothDevice&gt;"
 abstract="true"
 native="false"
 synchronized="false"
@@ -38121,7 +38121,7 @@
</parameter>
</method>
<method name="getDevicesMatchingConnectionStates"
 return="java.util.Set&lt;android.bluetooth.BluetoothDevice&gt;"
 return="java.util.List&lt;android.bluetooth.BluetoothDevice&gt;"
 abstract="true"
 native="false"
 synchronized="false"
+10 −18
Original line number Diff line number Diff line
@@ -26,11 +26,8 @@ import android.os.ServiceManager;
import android.server.BluetoothA2dpService;
import android.util.Log;

import java.util.Collections;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;


/**
@@ -167,35 +164,35 @@ public final class BluetoothA2dp implements BluetoothProfile {
    /**
     * {@inheritDoc}
     */
    public Set<BluetoothDevice> getConnectedDevices() {
    public List<BluetoothDevice> getConnectedDevices() {
        if (DBG) log("getConnectedDevices()");
        if (mService != null && isEnabled()) {
            try {
                return toDeviceSet(mService.getConnectedDevices());
                return mService.getConnectedDevices();
            } catch (RemoteException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return toDeviceSet(new BluetoothDevice[0]);
                return new ArrayList<BluetoothDevice>();
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return toDeviceSet(new BluetoothDevice[0]);
        return new ArrayList<BluetoothDevice>();
    }

    /**
     * {@inheritDoc}
     */
    public Set<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (DBG) log("getDevicesMatchingStates()");
        if (mService != null && isEnabled()) {
            try {
                return toDeviceSet(mService.getDevicesMatchingConnectionStates(states));
                return mService.getDevicesMatchingConnectionStates(states);
            } catch (RemoteException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return toDeviceSet(new BluetoothDevice[0]);
                return new ArrayList<BluetoothDevice>();
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return toDeviceSet(new BluetoothDevice[0]);
        return new ArrayList<BluetoothDevice>();
    }

    /**
@@ -396,11 +393,6 @@ public final class BluetoothA2dp implements BluetoothProfile {
       return false;
    }

    private Set<BluetoothDevice> toDeviceSet(BluetoothDevice[] devices) {
       return Collections.unmodifiableSet(
          new HashSet<BluetoothDevice>(Arrays.asList(devices)));
    }

    private static void log(String msg) {
      Log.d(TAG, msg);
    }
+11 −20
Original line number Diff line number Diff line
@@ -18,20 +18,16 @@ package android.bluetooth;

import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.RemoteException;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;

/**
 * Public API for controlling the Bluetooth Headset Service. This includes both
@@ -218,35 +214,35 @@ public final class BluetoothHeadset implements BluetoothProfile {
    /**
     * {@inheritDoc}
     */
    public Set<BluetoothDevice> getConnectedDevices() {
    public List<BluetoothDevice> getConnectedDevices() {
        if (DBG) log("getConnectedDevices()");
        if (mService != null && isEnabled()) {
            try {
                return toDeviceSet(mService.getConnectedDevices());
                return mService.getConnectedDevices();
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return toDeviceSet(new BluetoothDevice[0]);
                return new ArrayList<BluetoothDevice>();
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return toDeviceSet(new BluetoothDevice[0]);
        return new ArrayList<BluetoothDevice>();
    }

    /**
     * {@inheritDoc}
     */
    public Set<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (DBG) log("getDevicesMatchingStates()");
        if (mService != null && isEnabled()) {
            try {
                return toDeviceSet(mService.getDevicesMatchingConnectionStates(states));
                return mService.getDevicesMatchingConnectionStates(states);
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return toDeviceSet(new BluetoothDevice[0]);
                return new ArrayList<BluetoothDevice>();
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return toDeviceSet(new BluetoothDevice[0]);
        return new ArrayList<BluetoothDevice>();
    }

    /**
@@ -569,11 +565,6 @@ public final class BluetoothHeadset implements BluetoothProfile {
       return false;
    }

    private Set<BluetoothDevice> toDeviceSet(BluetoothDevice[] devices) {
       return Collections.unmodifiableSet(
          new HashSet<BluetoothDevice>(Arrays.asList(devices)));
    }

    private static void log(String msg) {
        Log.d(TAG, msg);
    }
+5 −8
Original line number Diff line number Diff line
@@ -17,10 +17,7 @@

package android.bluetooth;

import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;

import java.util.Set;
import java.util.List;

/**
 * Public APIs for the Bluetooth Profiles.
@@ -150,9 +147,9 @@ public interface BluetoothProfile {
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
     *
     * @return An unmodifiable set of devices. The set will be empty on error.
     * @return List of devices. The list will be empty on error.
     */
    public Set<BluetoothDevice> getConnectedDevices();
    public List<BluetoothDevice> getConnectedDevices();

    /**
     * Get a set of devices that match any of the given connection
@@ -166,9 +163,9 @@ public interface BluetoothProfile {
     * @param states Array of states. States can be one of
     *              {@link #STATE_CONNECTED}, {@link #STATE_CONNECTING},
     *              {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
     * @return An unmodifiable set of devices. The set will be empty on error.
     * @return List of devices. The list will be empty on error.
     */
    public Set<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);

    /**
     * Get the current connection state of the profile
+2 −3
Original line number Diff line number Diff line
@@ -27,9 +27,8 @@ interface IBluetoothA2dp {
    // Public API
    boolean connect(in BluetoothDevice device);
    boolean disconnect(in BluetoothDevice device);
    // change to Set<> once AIDL supports
    BluetoothDevice[] getConnectedDevices();
    BluetoothDevice[] getDevicesMatchingConnectionStates(in int[] states);
    List<BluetoothDevice> getConnectedDevices();
    List<BluetoothDevice> getDevicesMatchingConnectionStates(in int[] states);
    int getConnectionState(in BluetoothDevice device);
    boolean setPriority(in BluetoothDevice device, int priority);
    int getPriority(in BluetoothDevice device);
Loading