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

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

Add Api to get profile connection state.

This gets the current connection state of the profile with respect
to the local Bluetooth adapter.

Change-Id: I7cff6c9201d29a8b45413cff7384b7483f21bd5c
parent 7a12d6ba
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -773,6 +773,31 @@ public final class BluetoothAdapter {
        return BluetoothAdapter.STATE_DISCONNECTED;
    }

    /**
     * Get the current connection state of a profile.
     * This function can be used to check whether the local Bluetooth adapter
     * is connected to any remote device for a specific profile.
     * Profile can be one of {@link BluetoothProfile.HEADSET},
     * {@link BluetoothProfile.A2DP}.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
     *
     * <p> Return value can be one of
     * {@link * BluetoothProfile.STATE_DISCONNECTED},
     * {@link * BluetoothProfile.STATE_CONNECTING},
     * {@link * BluetoothProfile.STATE_CONNECTED},
     * {@link * BluetoothProfile.STATE_DISCONNECTING}
     * @hide
     */
    public int getProfileConnectionState(int profile) {
        if (getState() != STATE_ON) return BluetoothProfile.STATE_DISCONNECTED;
        try {
            return mService.getProfileConnectionState(profile);
        } catch (RemoteException e) {Log.e(TAG, "getProfileConnectionState:", e);}
        return BluetoothProfile.STATE_DISCONNECTED;
    }

    /**
    /**
     * Picks RFCOMM channels until none are left.
     * Avoids reserved channels.
+6 −0
Original line number Diff line number Diff line
@@ -82,6 +82,12 @@ public interface BluetoothProfile {
     */
    public static final int PAN = 5;

    /**
     * PBAP
     * @hide
     */
    public static final int PBAP = 6;

    /**
     * Default priority for devices that we try to auto-connect to and
     * and allow incoming connections for the profile
+2 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ interface IBluetooth
    byte[] readOutOfBandData();

    int getAdapterConnectionState();
    int getProfileConnectionState(int profile);
    boolean changeApplicationBluetoothState(boolean on,
                                in IBluetoothStateChangeCallback callback, in
                                IBinder b);
@@ -121,5 +122,5 @@ interface IBluetooth
    List<BluetoothDevice> getHealthDevicesMatchingConnectionStates(in int[] states);
    int getHealthDeviceConnectionState(in BluetoothDevice device);

    void sendConnectionStateChange(in BluetoothDevice device, int state, int prevState);
    void sendConnectionStateChange(in BluetoothDevice device, int profile, int state, int prevState);
}
+2 −1
Original line number Diff line number Diff line
@@ -523,7 +523,8 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {

            if (DBG) log("A2DP state : device: " + device + " State:" + prevState + "->" + state);

            mBluetoothService.sendConnectionStateChange(device, state, prevState);
            mBluetoothService.sendConnectionStateChange(device, BluetoothProfile.A2DP, state,
                                                        prevState);
        }
    }

+3 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHealth;
import android.bluetooth.BluetoothHealthAppConfiguration;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothHealthCallback;
import android.content.Context;
import android.os.Handler;
@@ -567,7 +568,8 @@ final class BluetoothHealthProfileHandler {
    private void updateAndSendIntent(BluetoothDevice device, int prevDeviceState,
            int newDeviceState) {
        mHealthDevices.put(device, newDeviceState);
        mBluetoothService.sendConnectionStateChange(device, prevDeviceState, newDeviceState);
        mBluetoothService.sendConnectionStateChange(device, BluetoothProfile.HEALTH,
                                                    prevDeviceState, newDeviceState);
    }

    /**
Loading