mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Fixes for NullPointerException spotted on Play Store
These are probably edge cases but they do appear to happen occasionally Fixes Exception java.lang.NullPointerException: Attempt to invoke virtual method 'int android.bluetooth.BluetoothClass.getDeviceClass()' on a null object reference at nodomain.freeyourgadget.gadgetbridge.devices.generic_headphones.GenericHeadphonesCoordinator.supports (GenericHeadphonesCoordinator.java:45) at nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper.resolveDeviceType (DeviceHelper.java:140) at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor.processCandidate (GBScanEventProcessor.java:175) at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor.processAllScanEvents (GBScanEventProcessor.java:237) at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor.run (GBScanEventProcessor.java:81) at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor$1.run (GBScanEventProcessor.java:103) Fixes Exception java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[], int, int)' on a null object reference at android.bluetooth.BluetoothSocket.read (BluetoothSocket.java:692) at android.bluetooth.BluetoothInputStream.read (BluetoothInputStream.java:88) at java.io.InputStream.read (InputStream.java:218) at nodomain.freeyourgadget.gadgetbridge.service.btbr.BtBRQueue$1.run (BtBRQueue.java:73)
This commit is contained in:
+1
@@ -42,6 +42,7 @@ public class GenericHeadphonesCoordinator extends AbstractDeviceCoordinator {
|
||||
try {
|
||||
final BluetoothDevice device = candidate.getDevice();
|
||||
final BluetoothClass deviceClass = device.getBluetoothClass();
|
||||
if (deviceClass == null) return false;
|
||||
int deviceType = deviceClass.getDeviceClass();
|
||||
return deviceType == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET ||
|
||||
deviceType == BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES ||
|
||||
|
||||
@@ -64,12 +64,15 @@ public final class BtBRQueue {
|
||||
@Override
|
||||
public void run() {
|
||||
final byte[] buffer = new byte[mBufferSize];
|
||||
int nRead;
|
||||
int nRead = 0;
|
||||
|
||||
LOG.debug("Read thread started, entering loop");
|
||||
|
||||
while (!mDisposed) {
|
||||
try {
|
||||
if (mBtSocket == null)
|
||||
throw new IOException("mBtSocket was null");
|
||||
|
||||
nRead = mBtSocket.getInputStream().read(buffer);
|
||||
|
||||
// safety measure
|
||||
|
||||
Reference in New Issue
Block a user