mirror of
https://github.com/fr3ts0n/AndrOBD.git
synced 2026-07-30 14:36:01 -04:00
fix: null-guard BluetoothAdapter and socket in BtCommService
- Constructor: getDefaultAdapter() can return null on devices without Bluetooth hardware, or if the OS revokes the adapter reference mid-flow (more aggressive on Android 16 permission handling). Guard before calling cancelDiscovery() to avoid a startup NPE. - logSocketUuids(): the socket argument can be null if createRfcommSocketToServiceRecord() threw before assignment. Guard before dereferencing getRemoteDevice(). Not build-verified locally (no Android SDK configured in this environment) — both changes are one-line null guards following the existing pattern used elsewhere in this file (mBtWorkerThread checks). Addresses #299.
This commit is contained in:
@@ -64,7 +64,8 @@ public class BtCommService extends CommService
|
||||
// Always cancel discovery because it will slow down a connection
|
||||
// Member fields
|
||||
BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mAdapter.cancelDiscovery();
|
||||
if (mAdapter != null)
|
||||
mAdapter.cancelDiscovery();
|
||||
|
||||
// set up protocol handlers
|
||||
elm.addTelegramWriter(ser);
|
||||
@@ -264,17 +265,24 @@ public class BtCommService extends CommService
|
||||
StringBuilder message = new StringBuilder(msg);
|
||||
// dump supported UUID's
|
||||
message.append(" - UUIDs:");
|
||||
ParcelUuid[] uuids = socket.getRemoteDevice().getUuids();
|
||||
if(uuids != null)
|
||||
if (socket != null)
|
||||
{
|
||||
for (ParcelUuid uuid: uuids)
|
||||
ParcelUuid[] uuids = socket.getRemoteDevice().getUuids();
|
||||
if(uuids != null)
|
||||
{
|
||||
message.append(uuid.getUuid().toString()).append(",");
|
||||
for (ParcelUuid uuid: uuids)
|
||||
{
|
||||
message.append(uuid.getUuid().toString()).append(",");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
message.append("NONE (Invalid BT implementation)");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
message.append("NONE (Invalid BT implementation)");
|
||||
message.append("NONE (null socket)");
|
||||
}
|
||||
log.log(Level.INFO, message.toString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user