use of android.bluetooth.BluetoothAdapter in project android by JetBrains.
the class UnitTest method mockFinalClass.
@Test
public void mockFinalClass() {
BluetoothAdapter adapter = mock(BluetoothAdapter.class);
when(adapter.isEnabled()).thenReturn(true);
assertTrue(adapter.isEnabled());
verify(adapter).isEnabled();
verifyNoMoreInteractions(adapter);
}
use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by DirtyUnicorns.
the class Tethering method setBluetoothTethering.
private void setBluetoothTethering(final boolean enable, final ResultReceiver receiver) {
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null || !adapter.isEnabled()) {
Log.w(TAG, "Tried to enable bluetooth tethering with null or disabled adapter. null: " + (adapter == null));
sendTetherResult(receiver, ConnectivityManager.TETHER_ERROR_SERVICE_UNAVAIL);
return;
}
adapter.getProfileProxy(mContext, new ServiceListener() {
@Override
public void onServiceDisconnected(int profile) {
}
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
((BluetoothPan) proxy).setBluetoothTethering(enable);
// TODO: Enabling bluetooth tethering can fail asynchronously here.
// We should figure out a way to bubble up that failure instead of sending success.
int result = ((BluetoothPan) proxy).isTetheringOn() == enable ? ConnectivityManager.TETHER_ERROR_NO_ERROR : ConnectivityManager.TETHER_ERROR_MASTER_ERROR;
sendTetherResult(receiver, result);
if (enable && isTetherProvisioningRequired()) {
scheduleProvisioningRechecks(ConnectivityManager.TETHERING_BLUETOOTH);
}
adapter.closeProfileProxy(BluetoothProfile.PAN, proxy);
}
}, BluetoothProfile.PAN);
}
use of android.bluetooth.BluetoothAdapter in project XobotOS by xamarin.
the class BluetoothHealthProfileHandler method onHealthDevicePropertyChanged.
/*package*/
void onHealthDevicePropertyChanged(String devicePath, String channelPath) {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
String address = mBluetoothService.getAddressFromObjectPath(devicePath);
if (address == null)
return;
//TODO: Fix this in Bluez
if (channelPath.equals("/")) {
// This means that the main channel is being destroyed.
return;
}
BluetoothDevice device = adapter.getRemoteDevice(address);
BluetoothHealthAppConfiguration config = findHealthApplication(device, channelPath);
if (config != null) {
HealthChannel chan = findChannelByPath(device, channelPath);
if (chan == null) {
errorLog("Health Channel is not present:" + channelPath);
} else {
chan.mMainChannel = true;
}
}
}
use of android.bluetooth.BluetoothAdapter in project XobotOS by xamarin.
the class AudioService method getBluetoothHeadset.
private boolean getBluetoothHeadset() {
boolean result = false;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
result = adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
}
// If we could not get a bluetooth headset proxy, send a failure message
// without delay to reset the SCO audio state and clear SCO clients.
// If we could get a proxy, send a delayed failure message that will reset our state
// in case we don't receive onServiceConnected().
sendMsg(mAudioHandler, MSG_BT_HEADSET_CNCT_FAILED, 0, SENDMSG_REPLACE, 0, 0, null, result ? BT_HEADSET_CNCT_TIMEOUT_MS : 0);
return result;
}
use of android.bluetooth.BluetoothAdapter in project android-beacon-library by AltBeacon.
the class CycledLeScannerForLollipop method isBluetoothOn.
private boolean isBluetoothOn() {
try {
BluetoothAdapter bluetoothAdapter = getBluetoothAdapter();
if (bluetoothAdapter != null) {
return (bluetoothAdapter.getState() == BluetoothAdapter.STATE_ON);
}
LogManager.w(TAG, "Cannot get bluetooth adapter");
} catch (SecurityException e) {
LogManager.w(TAG, "SecurityException checking if bluetooth is on");
}
return false;
}
Aggregations