Skip to content

Commit

Permalink
Warnings fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 committed Dec 8, 2021
1 parent fe0ed15 commit 6c975f3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void onCharacteristicWrite(final BluetoothGatt gatt, final BluetoothGattC
return;

// In Secure DFU we (usually, depends on the page size and PRN value) do not get any notification after the object is completed,
// therefor the lock must be notified here to resume the main process.
// therefore the lock must be notified here to resume the main process.
if (lastPacketTransferred || lastObjectPacketTransferred) {
mFirmwareUploadInProgress = false;
notifyLock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class DfuServiceController implements DfuController {
private LocalBroadcastManager mBroadcastManager;
private final LocalBroadcastManager mBroadcastManager;
private boolean mPaused;
private boolean mAborted;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class DfuServiceListenerHelper {
private static ProgressBroadcastsReceiver mProgressBroadcastReceiver;

private static class LogBroadcastReceiver extends BroadcastReceiver {
private final Map<String, DfuLogListener> mListeners = new HashMap<>();
private DfuLogListener mGlobalLogListener;
private Map<String, DfuLogListener> mListeners = new HashMap<>();

private void setLogListener(final DfuLogListener globalLogListener) {
this.mGlobalLogListener = globalLogListener;
Expand Down Expand Up @@ -113,8 +113,8 @@ public void onReceive(final Context context, final Intent intent) {
}

private static class ProgressBroadcastsReceiver extends BroadcastReceiver {
private final Map<String, DfuProgressListener> mListeners = new HashMap<>();
private DfuProgressListener mGlobalProgressListener;
private Map<String, DfuProgressListener> mListeners = new HashMap<>();

private void setProgressListener(final DfuProgressListener globalProgressListener) {
this.mGlobalProgressListener = globalProgressListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public class ArchiveInputStream extends InputStream {
* Contains bytes arrays with BIN files. HEX files are converted to BIN before being
* added to this map.
*/
private Map<String, byte[]> entries;
private final Map<String, byte[]> entries;
private final CRC32 crc32;
private Manifest manifest;
private CRC32 crc32;

private byte[] applicationBytes;
private byte[] softDeviceBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ public class HexInputStream extends FilterInputStream {
private final int LINE_LENGTH = 128;

private final byte[] localBuf;
private final int available;
private int localPos;
private int pos;
private int size;
private int lastAddress;
private int available, bytesRead;
private int bytesRead;
private final int MBRSize;

/**
Expand Down Expand Up @@ -99,8 +100,8 @@ public HexInputStream(@NonNull final byte[] data, final int mbrSize)
this.available = calculateBinSize(mbrSize);
}

@SuppressWarnings("ResultOfMethodCallIgnored")
private int calculateBinSize(final int mbrSize) throws IOException {
@SuppressWarnings("DuplicateThrows")
private int calculateBinSize(final int mbrSize) throws HexFileValidationException, IOException {
int binSize = 0;
final InputStream in = this.in;
in.mark(in.available());
Expand Down Expand Up @@ -155,7 +156,7 @@ private int calculateBinSize(final int mbrSize) throws IOException {
binSize += lineSize;
// no break!
default:
final long toBeSkipped = lineSize * 2 /* 2 hex per one byte */ + 2 /* check sum */;
final long toBeSkipped = lineSize * 2L /* 2 hex per one byte */ + 2 /* check sum */;
skip(in, toBeSkipped);
break;
}
Expand Down Expand Up @@ -281,7 +282,7 @@ private int readLine() throws IOException {
// data type
if (lastAddress + offset < MBRSize) { // skip MBR
type = -1; // some other than 0
pos += skip(in, lineSize * 2 /* 2 hex per one byte */ + 2 /* check sum */);
pos += skip(in, lineSize * 2L /* 2 hex per one byte */ + 2 /* check sum */);
}
break;
case 0x01:
Expand Down Expand Up @@ -309,7 +310,7 @@ private int readLine() throws IOException {
break;
}
default:
final long toBeSkipped = lineSize * 2 /* 2 hex per one byte */ + 2 /* check sum */;
final long toBeSkipped = lineSize * 2L /* 2 hex per one byte */ + 2 /* check sum */;
pos += skip(in, toBeSkipped);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class BootloaderScannerJB implements BootloaderScanner, BluetoothAdapter.
private String mBootloaderAddress;
private boolean mFound;

@SuppressWarnings("deprecation")
@Override
public String searchFor(final String deviceAddress) {
final String firstBytes = deviceAddress.substring(0, 15);
Expand All @@ -50,25 +49,22 @@ public String searchFor(final String deviceAddress) {
mFound = false;

// Add timeout
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(BootloaderScanner.TIMEOUT);
} catch (final InterruptedException e) {
// do nothing
}

if (mFound)
return;

mBootloaderAddress = null;
mFound = true;

// Notify the waiting thread
synchronized (mLock) {
mLock.notifyAll();
}
new Thread(() -> {
try {
Thread.sleep(BootloaderScanner.TIMEOUT);
} catch (final InterruptedException e) {
// do nothing
}

if (mFound)
return;

mBootloaderAddress = null;
mFound = true;

// Notify the waiting thread
synchronized (mLock) {
mLock.notifyAll();
}
}, "Scanner timer").start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,22 @@ public String searchFor(final String deviceAddress) {
mFound = false;

// Add timeout
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(BootloaderScanner.TIMEOUT);
} catch (final InterruptedException e) {
// do nothing
}

if (mFound)
return;

mBootloaderAddress = null;
mFound = true;

// Notify the waiting thread
synchronized (mLock) {
mLock.notifyAll();
}
new Thread(() -> {
try {
Thread.sleep(BootloaderScanner.TIMEOUT);
} catch (final InterruptedException e) {
// do nothing
}

if (mFound)
return;

mBootloaderAddress = null;
mFound = true;

// Notify the waiting thread
synchronized (mLock) {
mLock.notifyAll();
}
}, "Scanner timer").start();

Expand All @@ -89,7 +86,7 @@ public void run() {
/*
* Android 8.1 onwards, stops unfiltered BLE scanning on screen off. Therefore we must add a filter to
* get scan results in case the device screen is turned off as this may affect users wanting scan/connect to the device in background.
* See {@linktourl https://android.googlesource.com/platform/packages/apps/Bluetooth/+/319aeae6f4ebd13678b4f77375d1804978c4a1e1}
* See https://android.googlesource.com/platform/packages/apps/Bluetooth/+/319aeae6f4ebd13678b4f77375d1804978c4a1e1
*/
final ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
if (adapter.isOffloadedFilteringSupported() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
Expand Down

0 comments on commit 6c975f3

Please sign in to comment.