use of android.bluetooth.BluetoothAdapter in project android_packages_apps_Settings by LineageOS.
the class DevelopmentSettings method writeBtHciSnoopLogOptions.
private void writeBtHciSnoopLogOptions() {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
SystemProperties.set(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, Boolean.toString(mBtHciSnoopLog.isChecked()));
}
use of android.bluetooth.BluetoothAdapter in project fdroidclient by f-droid.
the class SwapWorkflowActivity method startBluetoothSwap.
/**
* The process for setting up bluetooth is as follows:
* * Assume we have bluetooth available (otherwise the button which allowed us to start
* the bluetooth process should not have been available).
* * Ask user to enable (if not enabled yet).
* * Start bluetooth server socket.
* * Enable bluetooth discoverability, so that people can connect to our server socket.
*
* Note that this is a little different than the usual process for bluetooth _clients_, which
* involves pairing and connecting with other devices.
*/
public void startBluetoothSwap() {
Utils.debugLog(TAG, "Initiating Bluetooth swap, will ensure the Bluetooth devices is enabled and discoverable before starting server.");
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
if (adapter.isEnabled()) {
Utils.debugLog(TAG, "Bluetooth enabled, will check if device is discoverable with device.");
ensureBluetoothDiscoverableThenStart();
} else {
Utils.debugLog(TAG, "Bluetooth disabled, asking user to enable it.");
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_BLUETOOTH_ENABLE_FOR_SWAP);
}
}
}
use of android.bluetooth.BluetoothAdapter in project fdroidclient by f-droid.
the class BluetoothServer method run.
@Override
public void run() {
isRunning = true;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
try {
serverSocket = adapter.listenUsingInsecureRfcommWithServiceRecord("FDroid App Swap", BluetoothConstants.fdroidUuid());
} catch (IOException e) {
Log.e(TAG, "Error starting Bluetooth server socket, will stop the server now", e);
swap.stop();
isRunning = false;
return;
}
while (true) {
if (isInterrupted()) {
Utils.debugLog(TAG, "Server stopped so will terminate loop looking for client connections.");
break;
}
try {
BluetoothSocket clientSocket = serverSocket.accept();
if (clientSocket != null) {
if (isInterrupted()) {
Utils.debugLog(TAG, "Server stopped after socket accepted from client, but before initiating connection.");
break;
}
ClientConnection client = new ClientConnection(clientSocket, webRoot);
client.start();
clients.add(client);
}
} catch (IOException e) {
Log.e(TAG, "Error receiving client connection over Bluetooth server socket, will continue listening for other clients", e);
}
}
isRunning = false;
}
use of android.bluetooth.BluetoothAdapter in project xDrip by NightscoutFoundation.
the class SystemStatus method forgetDeviceListener.
private void forgetDeviceListener() {
forget_device.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mBluetoothManager != null && ActiveBluetoothDevice.first() != null) {
final BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
if (bluetoothAdapter != null) {
for (BluetoothDevice bluetoothDevice : bluetoothAdapter.getBondedDevices()) {
if (bluetoothDevice.getAddress().compareTo(ActiveBluetoothDevice.first().address) == 0) {
try {
Method m = bluetoothDevice.getClass().getMethod("removeBond", (Class[]) null);
m.invoke(bluetoothDevice, (Object[]) null);
notes.append("\n- Bluetooth unbonded, if using share tell it to forget your device.");
notes.append("\n- Scan for devices again to set connection back up!");
} catch (Exception e) {
Log.e("SystemStatus", e.getMessage(), e);
}
}
}
ActiveBluetoothDevice.forget();
bluetoothAdapter.disable();
mHandler.postDelayed(new Runnable() {
public void run() {
bluetoothAdapter.enable();
set_current_values();
mHandler2.postDelayed(new Runnable() {
public void run() {
CollectionServiceStarter.restartCollectionService(getApplicationContext());
set_current_values();
}
}, 5000);
}
}, 1000);
}
}
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
if (collection_method.compareTo("DexcomG5") == 0) {
Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
mBluetoothAdapter = mBluetoothManager.getAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if ((pairedDevices != null) && (pairedDevices.size() > 0)) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
try {
Method m = device.getClass().getMethod("removeBond", (Class[]) null);
m.invoke(device, (Object[]) null);
notes.append("\nG5 Transmitter unbonded, switch device mode to prevent re-pairing to G5.");
} catch (Exception e) {
Log.e("SystemStatus", e.getMessage(), e);
}
}
}
}
}
}
}
});
}
use of android.bluetooth.BluetoothAdapter in project xDrip by NightscoutFoundation.
the class Ob1G5CollectionService method unBond.
public synchronized void unBond() {
UserError.Log.d(TAG, "unBond() start");
if (transmitterMAC == null)
return;
final BluetoothAdapter mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();
final Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
if (device.getAddress() != null) {
if (device.getAddress().equals(transmitterMAC)) {
try {
UserError.Log.e(TAG, "removingBond: " + transmitterMAC);
Method m = device.getClass().getMethod("removeBond", (Class[]) null);
m.invoke(device, (Object[]) null);
} catch (Exception e) {
UserError.Log.e(TAG, e.getMessage(), e);
}
}
}
}
}
UserError.Log.d(TAG, "unBond() finished");
}
Aggregations