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

Commit 86eb709f authored by Bandari Ramesh's avatar Bandari Ramesh Committed by Bruno Martins
Browse files

Bluetooth: Add SDK API support for TWS feature (2)



- Add new SDK APIs to know the device is a TWS
  device and to get the peer TWS device address

 Conflicts:
	core/java/android/bluetooth/BluetoothDevice.java

CRs-Fixed: 2225904
Change-Id: Ia7e3103d603659d524fcb3f42e0b026e316914c5
Signed-off-by: default avatarVolodymyr Zhdanov <wight554@gmail.com>
parent 948cad4a
Loading
Loading
Loading
Loading
+98 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted (subject to the limitations in the
 * disclaimer below) provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *
 * * Neither the name of The Linux Foundation nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Copyright (C) 2009 The Android Open Source Project
 *
@@ -235,6 +270,17 @@ public final class BluetoothDevice implements Parcelable {
     */
    public static final int BATTERY_LEVEL_BLUETOOTH_OFF = -100;

    /**
     * Broadcast Action: Indicates the remote devices are TWS plus earbuds pair.
     * <p>Always contains the extra fields {@link #EXTRA_TWS_PLUS_DEVICE1},
     * {@link #EXTRA_TWS_PLUS_DEVICE2}.
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
     * @hide
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_TWS_PLUS_DEVICE_PAIR =
            "android.bluetooth.device.action.TWS_PLUS_DEVICE_PAIR";

    /**
     * Used as a Parcelable {@link BluetoothDevice} extra field in every intent
     * broadcast by this class. It contains the {@link BluetoothDevice} that
@@ -287,6 +333,23 @@ public final class BluetoothDevice implements Parcelable {
     */
    public static final String EXTRA_PREVIOUS_BOND_STATE =
            "android.bluetooth.device.extra.PREVIOUS_BOND_STATE";

    /**
     * Used as a String extra field in {@link #ACTION_TWS+_DEVICE_PAIR}
     * intents. It contains the first TWS+ earbud address of pair.
     * @hide
     */
    public static final String EXTRA_TWS_PLUS_DEVICE1 =
            "android.bluetooth.device.extra.EXTRA_TWS_PLUS_DEVICE1";

    /**
     * Used as a String extra field in {@link #ACTION_TWS+_DEVICE_PAIR}
     * intents. It contains the second TWS+ earbud address of pair.
     * @hide
     */
    public static final String EXTRA_TWS_PLUS_DEVICE2 =
            "android.bluetooth.device.extra.EXTRA_TWS_PLUS_DEVICE2";

    /**
     * Indicates the remote device is not bonded (paired).
     * <p>There is no shared link key with the remote device, so communication
@@ -1522,6 +1585,41 @@ public final class BluetoothDevice implements Parcelable {
        return false;
    }

    /**
     * Returns whether if the device is TWS+ device.
     *
     * @return True if the devcie is TWS+ device.
     * @hide
     */
    public boolean isTwsPlusDevice() {
         if (sService == null) {
             Log.e(TAG, "BT not enabled. Cannot query remote device sdp records");
             return false;
         }
         try {
             return sService.isTwsPlusDevice(this);
         } catch (RemoteException e) {Log.e(TAG, "", e);}
         return false;
    }

    /**
     * Get the TWS+ peer address of the remote device.
     *
     * @return the TWS+ peer address of the remote device if available, otherwise
     * null.
     * @hide
     */
    public String getTwsPlusPeerAddress() {
        if (sService == null) {
            Log.e(TAG, "BT not enabled. Cannot get Remote Device name");
            return null;
        }
        try {
            return sService.getTwsPlusPeerAddress(this);
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return null;
    }

    /**
     * Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN}
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.