Loading core/java/android/bluetooth/BluetoothAdapter.java +22 −0 Original line number Diff line number Diff line Loading @@ -737,6 +737,27 @@ public final class BluetoothAdapter { return null; } /** * Get the current connection state of the local Bluetooth adapter. * This can be used to check whether the local Bluetooth adapter is connected * to any profile of any other remote Bluetooth Device. * * <p> Use this function along with {@link #ACTION_CONNECTION_STATE_CHANGED} * intent to get the connection state of the adapter. * * @return One of {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTED}, * {@link #STATE_CONNECTING} or {@link #STATE_DISCONNECTED} * * @hide */ public int getConnectionState() { if (getState() != STATE_ON) return BluetoothAdapter.STATE_DISCONNECTED; try { return mService.getAdapterConnectionState(); } catch (RemoteException e) {Log.e(TAG, "getConnectionState:", e);} return BluetoothAdapter.STATE_DISCONNECTED; } /** * Picks RFCOMM channels until none are left. * Avoids reserved channels. Loading Loading @@ -879,6 +900,7 @@ public final class BluetoothAdapter { return socket; } /** * Construct an unencrypted, unauthenticated, RFCOMM server socket. * Call #accept to retrieve connections to this socket. Loading core/java/android/bluetooth/IBluetooth.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,8 @@ interface IBluetooth boolean isDiscovering(); byte[] readOutOfBandData(); int getAdapterConnectionState(); boolean createBond(in String address); boolean createBondOutOfBand(in String address, in byte[] hash, in byte[] randomizer); boolean cancelBondProcess(in String address); Loading core/java/android/server/BluetoothService.java +13 −3 Original line number Diff line number Diff line Loading @@ -167,6 +167,8 @@ public class BluetoothService extends IBluetooth.Stub { private static String mDockAddress; private String mDockPin; private int mAdapterConnectionState = BluetoothAdapter.STATE_DISCONNECTED; private static class RemoteService { public String address; public ParcelUuid uuid; Loading Loading @@ -415,6 +417,7 @@ public class BluetoothService extends IBluetooth.Stub { mProfilesConnected = 0; mProfilesConnecting = 0; mProfilesDisconnecting = 0; mAdapterConnectionState = BluetoothAdapter.STATE_DISCONNECTED; if (saveSetting) { persistBluetoothOnSetting(false); Loading Loading @@ -2737,11 +2740,18 @@ public class BluetoothService extends IBluetooth.Stub { } } public int getAdapterConnectionState() { return mAdapterConnectionState; } public synchronized void sendConnectionStateChange(BluetoothDevice device, int state, int prevState) { if (updateCountersAndCheckForConnectionStateChange(device, state, prevState)) { state = getAdapterConnectionState(state); prevState = getAdapterConnectionState(prevState); state = translateToAdapterConnectionState(state); prevState = translateToAdapterConnectionState(prevState); mAdapterConnectionState = state; Intent intent = new Intent(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, state); Loading @@ -2751,7 +2761,7 @@ public class BluetoothService extends IBluetooth.Stub { } } private int getAdapterConnectionState(int state) { private int translateToAdapterConnectionState(int state) { switch (state) { case BluetoothProfile.STATE_CONNECTING: return BluetoothAdapter.STATE_CONNECTING; Loading Loading
core/java/android/bluetooth/BluetoothAdapter.java +22 −0 Original line number Diff line number Diff line Loading @@ -737,6 +737,27 @@ public final class BluetoothAdapter { return null; } /** * Get the current connection state of the local Bluetooth adapter. * This can be used to check whether the local Bluetooth adapter is connected * to any profile of any other remote Bluetooth Device. * * <p> Use this function along with {@link #ACTION_CONNECTION_STATE_CHANGED} * intent to get the connection state of the adapter. * * @return One of {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTED}, * {@link #STATE_CONNECTING} or {@link #STATE_DISCONNECTED} * * @hide */ public int getConnectionState() { if (getState() != STATE_ON) return BluetoothAdapter.STATE_DISCONNECTED; try { return mService.getAdapterConnectionState(); } catch (RemoteException e) {Log.e(TAG, "getConnectionState:", e);} return BluetoothAdapter.STATE_DISCONNECTED; } /** * Picks RFCOMM channels until none are left. * Avoids reserved channels. Loading Loading @@ -879,6 +900,7 @@ public final class BluetoothAdapter { return socket; } /** * Construct an unencrypted, unauthenticated, RFCOMM server socket. * Call #accept to retrieve connections to this socket. Loading
core/java/android/bluetooth/IBluetooth.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,8 @@ interface IBluetooth boolean isDiscovering(); byte[] readOutOfBandData(); int getAdapterConnectionState(); boolean createBond(in String address); boolean createBondOutOfBand(in String address, in byte[] hash, in byte[] randomizer); boolean cancelBondProcess(in String address); Loading
core/java/android/server/BluetoothService.java +13 −3 Original line number Diff line number Diff line Loading @@ -167,6 +167,8 @@ public class BluetoothService extends IBluetooth.Stub { private static String mDockAddress; private String mDockPin; private int mAdapterConnectionState = BluetoothAdapter.STATE_DISCONNECTED; private static class RemoteService { public String address; public ParcelUuid uuid; Loading Loading @@ -415,6 +417,7 @@ public class BluetoothService extends IBluetooth.Stub { mProfilesConnected = 0; mProfilesConnecting = 0; mProfilesDisconnecting = 0; mAdapterConnectionState = BluetoothAdapter.STATE_DISCONNECTED; if (saveSetting) { persistBluetoothOnSetting(false); Loading Loading @@ -2737,11 +2740,18 @@ public class BluetoothService extends IBluetooth.Stub { } } public int getAdapterConnectionState() { return mAdapterConnectionState; } public synchronized void sendConnectionStateChange(BluetoothDevice device, int state, int prevState) { if (updateCountersAndCheckForConnectionStateChange(device, state, prevState)) { state = getAdapterConnectionState(state); prevState = getAdapterConnectionState(prevState); state = translateToAdapterConnectionState(state); prevState = translateToAdapterConnectionState(prevState); mAdapterConnectionState = state; Intent intent = new Intent(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, state); Loading @@ -2751,7 +2761,7 @@ public class BluetoothService extends IBluetooth.Stub { } } private int getAdapterConnectionState(int state) { private int translateToAdapterConnectionState(int state) { switch (state) { case BluetoothProfile.STATE_CONNECTING: return BluetoothAdapter.STATE_CONNECTING; Loading