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

Commit dd0463ae authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Change handling of remoteUuids.

Use the ParcelUuid instead of UUID

Change-Id:Ie05d65a62e8a4df8182a4c737d46c14142bfec43
parent 82c3ef7a
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -503,7 +503,7 @@ public final class BluetoothDevice implements Parcelable {
    }
    }


    /** @hide */
    /** @hide */
     public String[] getUuids() {
     public ParcelUuid[] getUuids() {
        try {
        try {
            return sService.getRemoteUuids(mAddress);
            return sService.getRemoteUuids(mAddress);
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        } catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -511,7 +511,7 @@ public final class BluetoothDevice implements Parcelable {
    }
    }


    /** @hide */
    /** @hide */
    public int getServiceChannel(String uuid) {
    public int getServiceChannel(ParcelUuid uuid) {
         try {
         try {
             return sService.getRemoteServiceChannel(mAddress, uuid);
             return sService.getRemoteServiceChannel(mAddress, uuid);
         } catch (RemoteException e) {Log.e(TAG, "", e);}
         } catch (RemoteException e) {Log.e(TAG, "", e);}
+78 −18
Original line number Original line Diff line number Diff line
@@ -16,10 +16,11 @@


package android.bluetooth;
package android.bluetooth;


import java.util.UUID;
import java.util.Arrays;
import java.util.HashSet;


/**
/**
* Static helper methods and constants to decode the UUID of remote devices.
* Static helper methods and constants to decode the ParcelUuid of remote devices.
*  @hide
*  @hide
*/
*/
public final class BluetoothUuid {
public final class BluetoothUuid {
@@ -30,40 +31,99 @@ public final class BluetoothUuid {
     * The following 128 bit values are calculated as:
     * The following 128 bit values are calculated as:
     *  uuid * 2^96 + BASE_UUID
     *  uuid * 2^96 + BASE_UUID
     */
     */
    public static final UUID AudioSink = UUID.fromString("0000110B-0000-1000-8000-00805F9B34FB");
    public static final ParcelUuid AudioSink =
    public static final UUID AudioSource = UUID.fromString("0000110A-0000-1000-8000-00805F9B34FB");
            ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
    public static final UUID AdvAudioDist = UUID.fromString("0000110D-0000-1000-8000-00805F9B34FB");
    public static final ParcelUuid AudioSource =
    public static final UUID HSP       = UUID.fromString("00001108-0000-1000-8000-00805F9B34FB");
            ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
    public static final UUID Handsfree  = UUID.fromString("0000111E-0000-1000-8000-00805F9B34FB");
    public static final ParcelUuid AdvAudioDist =
    public static final UUID AvrcpController =
            ParcelUuid.fromString("0000110D-0000-1000-8000-00805F9B34FB");
                                          UUID.fromString("0000110E-0000-1000-8000-00805F9B34FB");
    public static final ParcelUuid HSP =
    public static final UUID AvrcpTarget = UUID.fromString("0000110C-0000-1000-8000-00805F9B34FB");
            ParcelUuid.fromString("00001108-0000-1000-8000-00805F9B34FB");

    public static final ParcelUuid Handsfree =
    public static boolean isAudioSource(UUID uuid) {
            ParcelUuid.fromString("0000111E-0000-1000-8000-00805F9B34FB");
    public static final ParcelUuid AvrcpController =
            ParcelUuid.fromString("0000110E-0000-1000-8000-00805F9B34FB");
    public static final ParcelUuid AvrcpTarget =
            ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB");
    public static final ParcelUuid ObexObjectPush =
            ParcelUuid.fromString("00001105-0000-1000-8000-00805f9b34fb");

    public static boolean isAudioSource(ParcelUuid uuid) {
        return uuid.equals(AudioSource);
        return uuid.equals(AudioSource);
    }
    }


    public static boolean isAudioSink(UUID uuid) {
    public static boolean isAudioSink(ParcelUuid uuid) {
        return uuid.equals(AudioSink);
        return uuid.equals(AudioSink);
    }
    }


    public static boolean isAdvAudioDist(UUID uuid) {
    public static boolean isAdvAudioDist(ParcelUuid uuid) {
        return uuid.equals(AdvAudioDist);
        return uuid.equals(AdvAudioDist);
    }
    }


    public static boolean isHandsfree(UUID uuid) {
    public static boolean isHandsfree(ParcelUuid uuid) {
        return uuid.equals(Handsfree);
        return uuid.equals(Handsfree);
    }
    }


    public static boolean isHeadset(UUID uuid) {
    public static boolean isHeadset(ParcelUuid uuid) {
        return uuid.equals(HSP);
        return uuid.equals(HSP);
    }
    }


    public static boolean isAvrcpController(UUID uuid) {
    public static boolean isAvrcpController(ParcelUuid uuid) {
        return uuid.equals(AvrcpController);
        return uuid.equals(AvrcpController);
    }
    }


    public static boolean isAvrcpTarget(UUID uuid) {
    public static boolean isAvrcpTarget(ParcelUuid uuid) {
        return uuid.equals(AvrcpTarget);
        return uuid.equals(AvrcpTarget);
    }
    }

    /**
     * Returns true if ParcelUuid is present in uuidArray
     *
     * @param uuidArray - Array of ParcelUuids
     * @param uuid
     */
    public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
        for (ParcelUuid element: uuidArray) {
            if (element.equals(uuid)) return true;
        }
        return false;
    }

    /**
     * Returns true if there any common ParcelUuids in uuidA and uuidB.
     *
     * @param uuidA - List of ParcelUuids
     * @param uuidB - List of ParcelUuids
     *
     */
    public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
        if (uuidA == null && uuidB == null) return true;
        if (uuidA == null || uuidB == null) return false;

        HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
        for (ParcelUuid uuid: uuidB) {
            if (uuidSet.contains(uuid)) return true;
        }
        return false;
    }

    /**
     * Returns true if all the ParcelUuids in ParcelUuidB are present in
     * ParcelUuidA
     *
     * @param uuidA - Array of ParcelUuidsA
     * @param uuidB - Array of ParcelUuidsB
     *
     */
    public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
        if (uuidA == null && uuidB == null) return true;
        if (uuidA == null || uuidB == null) return false;

        HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
        for (ParcelUuid uuid: uuidB) {
            if (!uuidSet.contains(uuid)) return false;
        }
        return true;
    }

}
}
+4 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package android.bluetooth;
package android.bluetooth;


import android.bluetooth.ParcelUuid;

/**
/**
 * System private API for talking with the Bluetooth service.
 * System private API for talking with the Bluetooth service.
 *
 *
@@ -50,8 +52,8 @@ interface IBluetooth


    String getRemoteName(in String address);
    String getRemoteName(in String address);
    int getRemoteClass(in String address);
    int getRemoteClass(in String address);
    String[] getRemoteUuids(in String address);
    ParcelUuid[] getRemoteUuids(in String address);
    int getRemoteServiceChannel(in String address, String uuid);
    int getRemoteServiceChannel(in String address,in ParcelUuid uuid);


    boolean setPin(in String address, in byte[] pin);
    boolean setPin(in String address, in byte[] pin);
    boolean setPasskey(in String address, int passkey);
    boolean setPasskey(in String address, int passkey);
+11 −21
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.IBluetoothA2dp;
import android.bluetooth.IBluetoothA2dp;
import android.bluetooth.ParcelUuid;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -42,7 +43,6 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.HashSet;
import java.util.Set;
import java.util.Set;
import java.util.UUID;


public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
    private static final String TAG = "BluetoothA2dpService";
    private static final String TAG = "BluetoothA2dpService";
@@ -188,16 +188,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
    }
    }


    private boolean isSinkDevice(BluetoothDevice device) {
    private boolean isSinkDevice(BluetoothDevice device) {
        String uuids[] = mBluetoothService.getRemoteUuids(device.getAddress());
        ParcelUuid[] uuids = mBluetoothService.getRemoteUuids(device.getAddress());
        UUID uuid;
        if (uuids != null && BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.AudioSink)) {
        if (uuids != null) {
            for (String deviceUuid: uuids) {
                uuid = UUID.fromString(deviceUuid);
                if (BluetoothUuid.isAudioSink(uuid)) {
            return true;
            return true;
        }
        }
            }
        }
        return false;
        return false;
    }
    }


@@ -229,16 +223,12 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
            for (String path: paths) {
            for (String path: paths) {
                String address = mBluetoothService.getAddressFromObjectPath(path);
                String address = mBluetoothService.getAddressFromObjectPath(path);
                BluetoothDevice device = mAdapter.getRemoteDevice(address);
                BluetoothDevice device = mAdapter.getRemoteDevice(address);
                String []uuids = mBluetoothService.getRemoteUuids(address);
                ParcelUuid[] remoteUuids = mBluetoothService.getRemoteUuids(address);
                if (uuids != null)
                if (remoteUuids != null)
                    for (String uuid: uuids) {
                    if (BluetoothUuid.containsAnyUuid(remoteUuids,
                        UUID remoteUuid = UUID.fromString(uuid);
                            new ParcelUuid[] {BluetoothUuid.AudioSink,
                        if (BluetoothUuid.isAudioSink(remoteUuid) ||
                                                BluetoothUuid.AdvAudioDist})) {
                            BluetoothUuid.isAudioSource(remoteUuid) ||
                            BluetoothUuid.isAdvAudioDist(remoteUuid)) {
                        addAudioSink(device);
                        addAudioSink(device);
                            break;
                        }
                    }
                    }
                }
                }
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.ParcelUuid;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.Handler;
import android.os.Handler;
@@ -28,7 +29,6 @@ import android.os.Message;
import android.util.Log;
import android.util.Log;


import java.util.HashMap;
import java.util.HashMap;
import java.util.UUID;


/**
/**
 * TODO: Move this to
 * TODO: Move this to
@@ -501,7 +501,7 @@ class BluetoothEventLoop {
        }
        }


        boolean authorized = false;
        boolean authorized = false;
        UUID uuid = UUID.fromString(deviceUuid);
        ParcelUuid uuid = ParcelUuid.fromString(deviceUuid);
        // Bluez sends the UUID of the local service being accessed, _not_ the
        // Bluez sends the UUID of the local service being accessed, _not_ the
        // remote service
        // remote service
        if (mBluetoothService.isEnabled() &&
        if (mBluetoothService.isEnabled() &&
Loading