diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2014-12-05 13:11:55 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2014-12-05 15:37:39 +0100 |
commit | 9856b182bb43ff36266e63027f18f67a0ce244ea (patch) | |
tree | 2b8948d732658bb7780db9d0ec7c5e364d0c1754 /src/android | |
parent | 228b54c723a2f05e493eab6b67dece29ab7de687 (diff) |
Cleanup Bluetooth Java code
These points were raised by Android-studio's Code analyzer
Change-Id: I5481b7ca74ec902b289a71096879e32301ee6494
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/android')
4 files changed, 21 insertions, 13 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java index f12e68fa..c8453a0b 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java @@ -40,7 +40,7 @@ import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; + import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.HashSet; @@ -49,7 +49,9 @@ import java.util.List; public class QtBluetoothBroadcastReceiver extends BroadcastReceiver { /* Pointer to the Qt object that "owns" the Java object */ + @SuppressWarnings("WeakerAccess") long qtObject = 0; + @SuppressWarnings("WeakerAccess") static Activity qtactivity = null; private static final int TURN_BT_ON = 3330; @@ -158,11 +160,11 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver //process found remote connections but avoid duplications HashSet<String> set = new HashSet<String>(); - for (int i = 0; i < gattConnections.size(); i++) - set.add(gattConnections.get(i).toString()); + for (Object gattConnection : gattConnections) + set.add(gattConnection.toString()); - for (int i = 0; i < gattServerConnections.size(); i++) - set.add(gattServerConnections.get(i).toString()); + for (Object gattServerConnection : gattServerConnections) + set.add(gattServerConnection.toString()); return set.toArray(new String[set.size()]); } catch (Exception ex) { diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothInputStreamThread.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothInputStreamThread.java index 30ada8c9..455054a8 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothInputStreamThread.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothInputStreamThread.java @@ -37,10 +37,13 @@ import java.io.InputStream; import java.io.IOException; import android.util.Log; +@SuppressWarnings("WeakerAccess") public class QtBluetoothInputStreamThread extends Thread { /* Pointer to the Qt object that "owns" the Java object */ + @SuppressWarnings("CanBeFinal") long qtObject = 0; + @SuppressWarnings("CanBeFinal") public boolean logEnabled = false; private static final String TAG = "QtBluetooth"; private InputStream m_inputStream = null; @@ -68,7 +71,7 @@ public class QtBluetoothInputStreamThread extends Thread } byte[] buffer = new byte[1000]; - int bytesRead = 0; + int bytesRead; try { while (!isInterrupted()) { diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java index b9f7e184..10aaf9ca 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java @@ -45,7 +45,6 @@ import android.bluetooth.BluetoothProfile; import android.util.Log; import java.util.ArrayList; -import java.util.Arrays; import java.util.Hashtable; import java.util.LinkedList; import java.util.List; @@ -58,7 +57,7 @@ public class QtBluetoothLE { private BluetoothGatt mBluetoothGatt = null; private String mRemoteGattAddress; - final UUID clientCharacteristicUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); + private final UUID clientCharacteristicUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); /* Pointer to the Qt object that "owns" the Java object */ @@ -67,6 +66,7 @@ public class QtBluetoothLE { @SuppressWarnings("WeakerAccess") Activity qtactivity = null; + @SuppressWarnings("WeakerAccess") public QtBluetoothLE() { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } @@ -917,7 +917,7 @@ public class QtBluetoothLE { /* For some reason, Android splits characteristic notifications into two operations. BluetoothGatt.enableCharacteristicNotification - ensures the local Blueooth stack forwards the notifications. In addition, + ensures the local Bluetooth stack forwards the notifications. In addition, BluetoothGattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) must be written to the peripheral. */ diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer.java index ae0a03a5..1b1aaac9 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer.java @@ -40,11 +40,14 @@ import android.util.Log; import java.io.IOException; import java.util.UUID; +@SuppressWarnings("WeakerAccess") public class QtBluetoothSocketServer extends Thread { /* Pointer to the Qt object that "owns" the Java object */ + @SuppressWarnings({"WeakerAccess", "CanBeFinal"}) long qtObject = 0; + @SuppressWarnings({"WeakerAccess", "CanBeFinal"}) public boolean logEnabled = false; private static final String TAG = "QtBluetooth"; @@ -54,9 +57,9 @@ public class QtBluetoothSocketServer extends Thread private BluetoothServerSocket m_serverSocket = null; //error codes - public static final int QT_NO_BLUETOOTH_SUPPORTED = 0; - public static final int QT_LISTEN_FAILED = 1; - public static final int QT_ACCEPT_FAILED = 2; + private static final int QT_NO_BLUETOOTH_SUPPORTED = 0; + private static final int QT_LISTEN_FAILED = 1; + private static final int QT_ACCEPT_FAILED = 2; public QtBluetoothSocketServer() { @@ -97,7 +100,7 @@ public class QtBluetoothSocketServer extends Thread return; } - BluetoothSocket s = null; + BluetoothSocket s; if (m_serverSocket != null) { try { while (!isInterrupted()) { |