diff options
Diffstat (limited to 'src/android')
9 files changed, 138 insertions, 120 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver.java b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver.java index 6c74c3e3..5df5cb81 100644 --- a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver.java +++ b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver.java @@ -32,11 +32,12 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver private static final int TURN_BT_DISABLED = 3332; // The 'Disable' action identifier is hidden in the public APIs so we define it here - public static final String ACTION_REQUEST_DISABLE = + static final String ACTION_REQUEST_DISABLE = "android.bluetooth.adapter.action.REQUEST_DISABLE"; private static final String TAG = "QtBluetoothBroadcastReceiver"; + @Override public void onReceive(Context context, Intent intent) { synchronized (qtContext) { @@ -47,7 +48,7 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver } } - public void unregisterReceiver() + void unregisterReceiver() { synchronized (qtContext) { qtObject = 0; @@ -59,14 +60,14 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver } } - public native void jniOnReceive(long qtObject, Context context, Intent intent); + native void jniOnReceive(long qtObject, Context context, Intent intent); - static public void setContext(Context context) + public static void setContext(Context context) { qtContext = context; } - static public boolean setDisabled() + static boolean setDisabled() { if (!(qtContext instanceof android.app.Activity)) { Log.w(TAG, "Bluetooth cannot be disabled from a service."); @@ -86,7 +87,7 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver return true; } - static public boolean setDiscoverable() + static boolean setDiscoverable() { if (!(qtContext instanceof android.app.Activity)) { Log.w(TAG, "Discovery mode cannot be enabled from a service."); @@ -105,7 +106,7 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver return true; } - static public boolean setEnabled() + static boolean setEnabled() { if (!(qtContext instanceof android.app.Activity)) { Log.w(TAG, "Bluetooth cannot be enabled from a service."); @@ -123,7 +124,7 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver return true; } - static public boolean setPairingMode(String address, boolean isPairing) + static boolean setPairingMode(String address, boolean isPairing) { BluetoothManager manager = (BluetoothManager)qtContext.getSystemService(Context.BLUETOOTH_SERVICE); @@ -159,7 +160,7 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver * Unfortunately there is no API that provides the complete list. * */ - static public String[] getConnectedDevices() + static String[] getConnectedDevices() { BluetoothManager bluetoothManager = (BluetoothManager) qtContext.getSystemService(Context.BLUETOOTH_SERVICE); diff --git a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothGattCharacteristic.java b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothGattCharacteristic.java index 375aebb5..6473541a 100644 --- a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothGattCharacteristic.java +++ b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothGattCharacteristic.java @@ -8,22 +8,22 @@ import android.os.Build; import java.util.UUID; -public class QtBluetoothGattCharacteristic extends BluetoothGattCharacteristic { - public QtBluetoothGattCharacteristic(UUID uuid, int properties, int permissions, +class QtBluetoothGattCharacteristic extends BluetoothGattCharacteristic { + QtBluetoothGattCharacteristic(UUID uuid, int properties, int permissions, int minimumValueLength, int maximumValueLength) { super(uuid, properties, permissions); minValueLength = minimumValueLength; maxValueLength = maximumValueLength; } - public int minValueLength; - public int maxValueLength; + int minValueLength; + int maxValueLength; // Starting from API 33 Android Bluetooth deprecates characteristic local value caching by // deprecating the getValue() and setValue() accessors. For peripheral role we store the value // locally in the characteristic as a convenience - looking up the value on the C++ side would // be somewhat complicated. This should be safe as all accesses to this class are synchronized. // For clarity: For API levels below 33 we still need to use the setValue() of the base class // because Android internally uses getValue() with APIs below 33. - public boolean setLocalValue(byte[] value) { + boolean setLocalValue(byte[] value) { if (Build.VERSION.SDK_INT >= 33) { m_localValue = value; return true; @@ -32,7 +32,7 @@ public class QtBluetoothGattCharacteristic extends BluetoothGattCharacteristic { } } - public byte[] getLocalValue() + byte[] getLocalValue() { if (Build.VERSION.SDK_INT >= 33) return m_localValue; diff --git a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothGattDescriptor.java b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothGattDescriptor.java index 10194ea4..b6c195d3 100644 --- a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothGattDescriptor.java +++ b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothGattDescriptor.java @@ -8,8 +8,8 @@ import android.os.Build; import java.util.UUID; -public class QtBluetoothGattDescriptor extends BluetoothGattDescriptor { - public QtBluetoothGattDescriptor(UUID uuid, int permissions) { +class QtBluetoothGattDescriptor extends BluetoothGattDescriptor { + QtBluetoothGattDescriptor(UUID uuid, int permissions) { super(uuid, permissions); } // Starting from API 33 Android Bluetooth deprecates descriptor local value caching by @@ -18,7 +18,7 @@ public class QtBluetoothGattDescriptor extends BluetoothGattDescriptor { // be somewhat complicated. This should be safe as all accesses to this class are synchronized. // For clarity: For API levels below 33 we still need to use the setValue() of the base class // because Android internally uses getValue() with APIs below 33. - public boolean setLocalValue(byte[] value) { + boolean setLocalValue(byte[] value) { if (Build.VERSION.SDK_INT >= 33) { m_localValue = value; return true; @@ -27,7 +27,7 @@ public class QtBluetoothGattDescriptor extends BluetoothGattDescriptor { } } - public byte[] getLocalValue() + byte[] getLocalValue() { if (Build.VERSION.SDK_INT >= 33) return m_localValue; diff --git a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothInputStreamThread.java b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothInputStreamThread.java index 0fd6f292..3c12cb34 100644 --- a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothInputStreamThread.java +++ b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothInputStreamThread.java @@ -8,31 +8,32 @@ import java.io.IOException; import android.util.Log; @SuppressWarnings("WeakerAccess") -public class QtBluetoothInputStreamThread extends Thread +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; + boolean logEnabled = false; private static final String TAG = "QtBluetooth"; private InputStream m_inputStream = null; //error codes - public static final int QT_MISSING_INPUT_STREAM = 0; - public static final int QT_READ_FAILED = 1; - public static final int QT_THREAD_INTERRUPTED = 2; + static final int QT_MISSING_INPUT_STREAM = 0; + static final int QT_READ_FAILED = 1; + static final int QT_THREAD_INTERRUPTED = 2; - public QtBluetoothInputStreamThread() + QtBluetoothInputStreamThread() { setName("QtBtInputStreamThread"); } - public void setInputStream(InputStream stream) + void setInputStream(InputStream stream) { m_inputStream = stream; } + @Override public void run() { if (m_inputStream == null) { @@ -63,6 +64,6 @@ public class QtBluetoothInputStreamThread extends Thread Log.d(TAG, "Leaving input stream thread"); } - public static native void errorOccurred(long qtObject, int errorCode); - public static native void readyData(long qtObject, byte[] buffer, int bufferLength); + static native void errorOccurred(long qtObject, int errorCode); + static native void readyData(long qtObject, byte[] buffer, int bufferLength); } diff --git a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothLE.java b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothLE.java index 0e612add..d133d8dc 100644 --- a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothLE.java +++ b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothLE.java @@ -39,7 +39,7 @@ import java.util.NoSuchElementException; import java.util.UUID; -public class QtBluetoothLE { +class QtBluetoothLE { private static final String TAG = "QtBluetoothGatt"; private BluetoothAdapter mBluetoothAdapter = null; private boolean mLeScanRunning = false; @@ -72,7 +72,7 @@ public class QtBluetoothLE { private BluetoothLeScanner mBluetoothLeScanner = null; private class TimeoutRunnable implements Runnable { - public TimeoutRunnable(int handle) { pendingJobHandle = handle; } + TimeoutRunnable(int handle) { pendingJobHandle = handle; } @Override public void run() { boolean timeoutStillValid = handleForTimeout.compareAndSet(pendingJobHandle, HANDLE_FOR_RESET); @@ -170,7 +170,7 @@ public class QtBluetoothLE { Context qtContext = null; @SuppressWarnings("WeakerAccess") - public QtBluetoothLE(Context context) { + QtBluetoothLE(Context context) { qtContext = context; BluetoothManager manager = @@ -185,7 +185,7 @@ public class QtBluetoothLE { mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); } - public QtBluetoothLE(final String remoteAddress, Context context) { + QtBluetoothLE(final String remoteAddress, Context context) { this(context); mRemoteGattAddress = remoteAddress; } @@ -197,7 +197,7 @@ public class QtBluetoothLE { /* variables that are not accessed from Java threads */ /*************************************************************/ - public boolean scanForLeDevice(final boolean isEnabled) { + boolean scanForLeDevice(final boolean isEnabled) { if (isEnabled == mLeScanRunning) return true; @@ -253,7 +253,7 @@ public class QtBluetoothLE { } }; - public native void leScanResult(long qtObject, BluetoothDevice device, int rssi, byte[] scanRecord); + native void leScanResult(long qtObject, BluetoothDevice device, int rssi, byte[] scanRecord); private synchronized void handleOnConnectionStateChange(BluetoothGatt gatt, int status, int newState) { @@ -646,18 +646,20 @@ public class QtBluetoothLE { /*************************************************************/ private final BluetoothGattCallback gattCallback = new BluetoothGattCallback() { - + @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); handleOnConnectionStateChange(gatt, status, newState); } + @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { super.onServicesDiscovered(gatt, status); handleOnServicesDiscovered(gatt, status); } + @Override // API < 33 public void onCharacteristicRead(android.bluetooth.BluetoothGatt gatt, android.bluetooth.BluetoothGattCharacteristic characteristic, @@ -667,6 +669,7 @@ public class QtBluetoothLE { handleOnCharacteristicRead(gatt, characteristic, characteristic.getValue(), status); } + @Override // API >= 33 public void onCharacteristicRead(android.bluetooth.BluetoothGatt gatt, android.bluetooth.BluetoothGattCharacteristic characteristic, @@ -678,6 +681,7 @@ public class QtBluetoothLE { handleOnCharacteristicRead(gatt, characteristic, value, status); } + @Override public void onCharacteristicWrite(android.bluetooth.BluetoothGatt gatt, android.bluetooth.BluetoothGattCharacteristic characteristic, int status) @@ -687,6 +691,7 @@ public class QtBluetoothLE { } // API < 33 + @Override public void onCharacteristicChanged(android.bluetooth.BluetoothGatt gatt, android.bluetooth.BluetoothGattCharacteristic characteristic) { @@ -695,6 +700,7 @@ public class QtBluetoothLE { } // API >= 33 + @Override public void onCharacteristicChanged(android.bluetooth.BluetoothGatt gatt, android.bluetooth.BluetoothGattCharacteristic characteristic, byte[] value) @@ -705,6 +711,7 @@ public class QtBluetoothLE { } // API < 33 + @Override public void onDescriptorRead(android.bluetooth.BluetoothGatt gatt, android.bluetooth.BluetoothGattDescriptor descriptor, int status) @@ -714,6 +721,7 @@ public class QtBluetoothLE { } // API >= 33 + @Override public void onDescriptorRead(android.bluetooth.BluetoothGatt gatt, android.bluetooth.BluetoothGattDescriptor descriptor, int status, @@ -724,6 +732,7 @@ public class QtBluetoothLE { handleOnDescriptorRead(gatt, descriptor, status, value); } + @Override public void onDescriptorWrite(android.bluetooth.BluetoothGatt gatt, android.bluetooth.BluetoothGattDescriptor descriptor, int status) @@ -732,17 +741,20 @@ public class QtBluetoothLE { handleOnDescriptorWrite(gatt, descriptor, status); } //TODO currently not supported -// public void onReliableWriteCompleted(android.bluetooth.BluetoothGatt gatt, +// @Override +// void onReliableWriteCompleted(android.bluetooth.BluetoothGatt gatt, // int status) { // System.out.println("onReliableWriteCompleted"); // } // + @Override public void onReadRemoteRssi(android.bluetooth.BluetoothGatt gatt, int rssi, int status) { super.onReadRemoteRssi(gatt, rssi, status); handleOnReadRemoteRssi(gatt, rssi, status); } + @Override public void onMtuChanged(android.bluetooth.BluetoothGatt gatt, int mtu, int status) { super.onMtuChanged(gatt, mtu, status); @@ -751,7 +763,7 @@ public class QtBluetoothLE { }; // This function is called from Qt thread - public synchronized int mtu() { + synchronized int mtu() { if (mSupportedMtu == -1) { return DEFAULT_MTU; } else { @@ -760,7 +772,7 @@ public class QtBluetoothLE { } // This function is called from Qt thread - public synchronized boolean readRemoteRssi() { + synchronized boolean readRemoteRssi() { if (mBluetoothGatt == null) return false; @@ -781,7 +793,7 @@ public class QtBluetoothLE { } // This function is called from Qt thread - public synchronized boolean connect() { + synchronized boolean connect() { BluetoothDevice mRemoteGattDevice; if (mBluetoothAdapter == null) { @@ -863,7 +875,7 @@ public class QtBluetoothLE { } // This function is called from Qt thread - public synchronized void disconnect() { + synchronized void disconnect() { if (mBluetoothGatt == null) return; @@ -871,7 +883,7 @@ public class QtBluetoothLE { } // This function is called from Qt thread - public synchronized boolean discoverServices() + synchronized boolean discoverServices() { return mBluetoothGatt != null && mBluetoothGatt.discoverServices(); } @@ -882,20 +894,20 @@ public class QtBluetoothLE { } private class GattEntry { - public GattEntryType type; - public boolean valueKnown = false; - public BluetoothGattService service = null; - public BluetoothGattCharacteristic characteristic = null; - public BluetoothGattDescriptor descriptor = null; + GattEntryType type; + boolean valueKnown = false; + BluetoothGattService service = null; + BluetoothGattCharacteristic characteristic = null; + BluetoothGattDescriptor descriptor = null; /* * endHandle defined for GattEntryType.Service and GattEntryType.CharacteristicValue * If the type is service this is the value of the last Gatt entry belonging to the very * same service. If the type is a char value it is the entries index inside * the "entries" list. */ - public int endHandle = -1; + int endHandle = -1; // pointer back to the handle that describes the service that this GATT entry belongs to - public int associatedServiceHandle; + int associatedServiceHandle; } private enum IoJobType @@ -908,10 +920,10 @@ public class QtBluetoothLE { private class ReadWriteJob { - public GattEntry entry; - public byte[] newValue; - public int requestedWriteType; - public IoJobType jobType; + GattEntry entry; + byte[] newValue; + int requestedWriteType; + IoJobType jobType; } // service uuid -> service handle mapping (there can be more than one service with same uuid) @@ -1084,7 +1096,7 @@ public class QtBluetoothLE { } // This function is called from Qt thread - public synchronized boolean discoverServiceDetails(String serviceUuid, boolean fullDiscovery) + synchronized boolean discoverServiceDetails(String serviceUuid, boolean fullDiscovery) { Log.d(TAG, "Discover service details for: " + serviceUuid + ", fullDiscovery: " + fullDiscovery + ", BluetoothGatt: " + (mBluetoothGatt != null)); @@ -1144,7 +1156,7 @@ public class QtBluetoothLE { Returns the uuids of the services included by the given service. Otherwise returns null. This function is called from Qt thread */ - public synchronized String includedServices(String serviceUuid) + synchronized String includedServices(String serviceUuid) { if (mBluetoothGatt == null) return null; @@ -1278,7 +1290,7 @@ public class QtBluetoothLE { /* This function is called from Qt thread */ /*************************************************************/ - public synchronized boolean writeCharacteristic(int charHandle, byte[] newValue, + synchronized boolean writeCharacteristic(int charHandle, byte[] newValue, int writeMode) { if (mBluetoothGatt == null) @@ -1327,7 +1339,7 @@ public class QtBluetoothLE { /* This function is called from Qt thread */ /*************************************************************/ - public synchronized boolean writeDescriptor(int descHandle, byte[] newValue) + synchronized boolean writeDescriptor(int descHandle, byte[] newValue) { if (mBluetoothGatt == null) return false; @@ -1363,7 +1375,7 @@ public class QtBluetoothLE { /* This function is called from Qt thread */ /*************************************************************/ - public synchronized boolean readCharacteristic(int charHandle) + synchronized boolean readCharacteristic(int charHandle) { if (mBluetoothGatt == null) return false; @@ -1393,7 +1405,7 @@ public class QtBluetoothLE { } // This function is called from Qt thread - public synchronized boolean readDescriptor(int descHandle) + synchronized boolean readDescriptor(int descHandle) { if (mBluetoothGatt == null) return false; @@ -1797,7 +1809,7 @@ public class QtBluetoothLE { } // This function is called from Qt thread - public synchronized boolean requestConnectionUpdatePriority(double minimalInterval) + synchronized boolean requestConnectionUpdatePriority(double minimalInterval) { if (mBluetoothGatt == null) return false; @@ -1816,22 +1828,22 @@ public class QtBluetoothLE { } } - public native void leConnectionStateChange(long qtObject, int wasErrorTransition, int newState); - public native void leMtuChanged(long qtObject, int mtu); - public native void leRemoteRssiRead(long qtObject, int rssi, boolean success); - public native void leServicesDiscovered(long qtObject, int errorCode, String uuidList); - public native void leServiceDetailDiscoveryFinished(long qtObject, final String serviceUuid, + native void leConnectionStateChange(long qtObject, int wasErrorTransition, int newState); + native void leMtuChanged(long qtObject, int mtu); + native void leRemoteRssiRead(long qtObject, int rssi, boolean success); + native void leServicesDiscovered(long qtObject, int errorCode, String uuidList); + native void leServiceDetailDiscoveryFinished(long qtObject, final String serviceUuid, int startHandle, int endHandle); - public native void leCharacteristicRead(long qtObject, String serviceUuid, + native void leCharacteristicRead(long qtObject, String serviceUuid, int charHandle, String charUuid, int properties, byte[] data); - public native void leDescriptorRead(long qtObject, String serviceUuid, String charUuid, + native void leDescriptorRead(long qtObject, String serviceUuid, String charUuid, int descHandle, String descUuid, byte[] data); - public native void leCharacteristicWritten(long qtObject, int charHandle, byte[] newData, + native void leCharacteristicWritten(long qtObject, int charHandle, byte[] newData, int errorCode); - public native void leDescriptorWritten(long qtObject, int charHandle, byte[] newData, + native void leDescriptorWritten(long qtObject, int charHandle, byte[] newData, int errorCode); - public native void leCharacteristicChanged(long qtObject, int charHandle, byte[] newData); - public native void leServiceError(long qtObject, int attributeHandle, int errorCode); + native void leCharacteristicChanged(long qtObject, int charHandle, byte[] newData); + native void leServiceError(long qtObject, int attributeHandle, int errorCode); } diff --git a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothLEServer.java b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothLEServer.java index 94601403..ae557de6 100644 --- a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothLEServer.java +++ b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothLEServer.java @@ -33,7 +33,7 @@ import java.util.ListIterator; import java.util.HashMap; import java.util.UUID; -public class QtBluetoothLEServer { +class QtBluetoothLEServer { private static final String TAG = "QtBluetoothGattServer"; /* Pointer to the Qt object that "owns" the Java object */ @@ -54,13 +54,13 @@ public class QtBluetoothLEServer { private String mRemoteName = ""; // This function is called from Qt thread - public synchronized String remoteName() { + synchronized String remoteName() { return mRemoteName; } private String mRemoteAddress = ""; // This function is called from Qt thread - public synchronized String remoteAddress() { + synchronized String remoteAddress() { return mRemoteAddress; } @@ -84,12 +84,12 @@ public class QtBluetoothLEServer { this.writes = new ArrayList<Pair<byte[], Integer>>(); } // Returns true if this is a proper entry for given device + target - public boolean match(BluetoothDevice device, Object target) { + boolean match(BluetoothDevice device, Object target) { return remoteDevice.equals(device) && target.equals(target); } - public final BluetoothDevice remoteDevice; // Device that issued the writes - public final Object target; // Characteristic or Descriptor - public final List<Pair<byte[], Integer>> writes; // Value, offset + final BluetoothDevice remoteDevice; // Device that issued the writes + final Object target; // Characteristic or Descriptor + final List<Pair<byte[], Integer>> writes; // Value, offset } private final List<WriteEntry> mPendingPreparedWrites = new ArrayList<>(); @@ -152,7 +152,7 @@ public class QtBluetoothLEServer { boolean isConnected = false; } - public void insertOrUpdate(BluetoothGattCharacteristic characteristic, + void insertOrUpdate(BluetoothGattCharacteristic characteristic, BluetoothDevice device, byte[] newValue) { if (notificationStore.containsKey(characteristic)) { @@ -192,7 +192,7 @@ public class QtBluetoothLEServer { This function avoids that existing configurations are not acted upon when the associated device is not connected. */ - public void markDeviceConnectivity(BluetoothDevice device, boolean isConnected) + void markDeviceConnectivity(BluetoothDevice device, boolean isConnected) { final Iterator<BluetoothGattCharacteristic> keys = notificationStore.keySet().iterator(); while (keys.hasNext()) { @@ -247,7 +247,7 @@ public class QtBluetoothLEServer { .fromString("00002902-0000-1000-8000-00805f9b34fb"); ClientCharacteristicManager clientCharacteristicManager = new ClientCharacteristicManager(); - public QtBluetoothLEServer(Context context) + QtBluetoothLEServer(Context context) { qtContext = context; if (qtContext == null) { @@ -284,7 +284,7 @@ public class QtBluetoothLEServer { // If each variable would be protected individually, the amount of (nested) locking // would become quite unreasonable - public synchronized void handleOnConnectionStateChange(BluetoothDevice device, + synchronized void handleOnConnectionStateChange(BluetoothDevice device, int status, int newState) { if (mGattServer == null) { @@ -351,7 +351,7 @@ public class QtBluetoothLEServer { leConnectionStateChange(qtObject, qtErrorCode, qtControllerState); } - public synchronized void handleOnServiceAdded(int status, BluetoothGattService service) + synchronized void handleOnServiceAdded(int status, BluetoothGattService service) { if (mGattServer == null) { Log.w(TAG, "Ignoring service addition event, server is disconnected"); @@ -382,7 +382,7 @@ public class QtBluetoothLEServer { } } - public synchronized void handleOnCharacteristicReadRequest(BluetoothDevice device, + synchronized void handleOnCharacteristicReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattCharacteristic characteristic) { @@ -408,7 +408,7 @@ public class QtBluetoothLEServer { } } - public synchronized void handleOnCharacteristicWriteRequest(BluetoothDevice device, + synchronized void handleOnCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, @@ -460,7 +460,7 @@ public class QtBluetoothLEServer { sendNotificationsOrIndications(characteristic); } - public synchronized void handleOnDescriptorReadRequest(BluetoothDevice device, int requestId, + synchronized void handleOnDescriptorReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattDescriptor descriptor) { if (mGattServer == null) { @@ -490,7 +490,7 @@ public class QtBluetoothLEServer { } } - public synchronized void handleOnDescriptorWriteRequest(BluetoothDevice device, int requestId, + synchronized void handleOnDescriptorWriteRequest(BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) { @@ -543,7 +543,7 @@ public class QtBluetoothLEServer { mGattServer.sendResponse(device, requestId, resultStatus, offset, value); } - public synchronized void handleOnExecuteWrite(BluetoothDevice device, + synchronized void handleOnExecuteWrite(BluetoothDevice device, int requestId, boolean execute) { if (mGattServer == null) { @@ -627,7 +627,7 @@ public class QtBluetoothLEServer { mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, null); } - public synchronized void handleOnMtuChanged(BluetoothDevice device, int mtu) + synchronized void handleOnMtuChanged(BluetoothDevice device, int mtu) { if (mSupportedMtu == mtu) return; @@ -706,12 +706,12 @@ public class QtBluetoothLEServer { }; // This function is called from Qt thread - public synchronized int mtu() { + synchronized int mtu() { return mSupportedMtu; } // This function is called from Qt thread - public synchronized boolean connectServer() + synchronized boolean connectServer() { if (mGattServer != null) return true; @@ -728,7 +728,7 @@ public class QtBluetoothLEServer { } // This function is called from Qt thread - public synchronized void disconnectServer() + synchronized void disconnectServer() { if (mGattServer == null) return; @@ -744,7 +744,7 @@ public class QtBluetoothLEServer { } // This function is called from Qt thread - public boolean startAdvertising(AdvertiseData advertiseData, + boolean startAdvertising(AdvertiseData advertiseData, AdvertiseData scanResponse, AdvertiseSettings settings) { @@ -775,7 +775,7 @@ public class QtBluetoothLEServer { } // This function is called from Qt thread - public void stopAdvertising() + void stopAdvertising() { if (mLeAdvertiser == null) return; @@ -785,7 +785,7 @@ public class QtBluetoothLEServer { } // This function is called from Qt thread - public synchronized void addService(BluetoothGattService service) + synchronized void addService(BluetoothGattService service) { if (!connectServer()) { Log.w(TAG, "Server::addService: Cannot open GATT server"); @@ -854,7 +854,7 @@ public class QtBluetoothLEServer { This function is called from the Qt thread. */ - public boolean writeCharacteristic(BluetoothGattService service, UUID charUuid, byte[] newValue) + boolean writeCharacteristic(BluetoothGattService service, UUID charUuid, byte[] newValue) { BluetoothGattCharacteristic foundChar = null; List<BluetoothGattCharacteristic> charList = service.getCharacteristics(); @@ -900,7 +900,7 @@ public class QtBluetoothLEServer { This function is called from the Qt thread. */ - public boolean writeDescriptor(BluetoothGattService service, UUID charUuid, UUID descUuid, + boolean writeDescriptor(BluetoothGattService service, UUID charUuid, UUID descUuid, byte[] newValue) { BluetoothGattDescriptor foundDesc = null; @@ -977,13 +977,13 @@ public class QtBluetoothLEServer { } }; - public native void leConnectionStateChange(long qtObject, int errorCode, int newState); - public native void leMtuChanged(long qtObject, int mtu); - public native void leServerAdvertisementError(long qtObject, int status); - public native void leServerCharacteristicChanged(long qtObject, + native void leConnectionStateChange(long qtObject, int errorCode, int newState); + native void leMtuChanged(long qtObject, int mtu); + native void leServerAdvertisementError(long qtObject, int status); + native void leServerCharacteristicChanged(long qtObject, BluetoothGattCharacteristic characteristic, byte[] newValue); - public native void leServerDescriptorWritten(long qtObject, + native void leServerDescriptorWritten(long qtObject, BluetoothGattDescriptor descriptor, byte[] newValue); } diff --git a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothSocketServer.java b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothSocketServer.java index cc78c5d7..cc96eb31 100644 --- a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothSocketServer.java +++ b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothSocketServer.java @@ -13,14 +13,14 @@ import java.io.IOException; import java.util.UUID; @SuppressWarnings("WeakerAccess") -public class QtBluetoothSocketServer extends Thread +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; + boolean logEnabled = false; @SuppressWarnings("WeakerAccess") static Context qtContext = null; @@ -35,13 +35,13 @@ public class QtBluetoothSocketServer extends Thread private static final int QT_LISTEN_FAILED = 1; private static final int QT_ACCEPT_FAILED = 2; - public QtBluetoothSocketServer(Context context) + QtBluetoothSocketServer(Context context) { qtContext = context; setName("QtSocketServerThread"); } - public void setServiceDetails(String uuid, String serviceName, boolean isSecure) + void setServiceDetails(String uuid, String serviceName, boolean isSecure) { m_uuid = UUID.fromString(uuid); m_serviceName = serviceName; @@ -49,6 +49,7 @@ public class QtBluetoothSocketServer extends Thread } + @Override public void run() { BluetoothManager manager = @@ -129,7 +130,7 @@ public class QtBluetoothSocketServer extends Thread // If the Java thread was in the middle of the blocking accept() call, it will get // interrupated by the close() call on the socket. After returning the run() will // notice it has been interrupted and return from the run() - public void close() + void close() { if (!isAlive()) return; @@ -149,6 +150,6 @@ public class QtBluetoothSocketServer extends Thread } } - public static native void errorOccurred(long qtObject, int errorCode); - public static native void newSocket(long qtObject, BluetoothSocket socket); + static native void errorOccurred(long qtObject, int errorCode); + static native void newSocket(long qtObject, BluetoothSocket socket); } diff --git a/src/android/nfc/src/org/qtproject/qt/android/nfc/QtNfc.java b/src/android/nfc/src/org/qtproject/qt/android/nfc/QtNfc.java index 9d8cae92..7753f182 100644 --- a/src/android/nfc/src/org/qtproject/qt/android/nfc/QtNfc.java +++ b/src/android/nfc/src/org/qtproject/qt/android/nfc/QtNfc.java @@ -17,7 +17,7 @@ import android.os.Parcelable; import android.util.Log; import android.content.pm.PackageManager; -public class QtNfc +class QtNfc { static private final String TAG = "QtNfc"; static private NfcAdapter m_adapter = null; @@ -25,7 +25,7 @@ public class QtNfc static private Context m_context = null; static private Activity m_activity = null; - static public void setContext(Context context) + static void setContext(Context context) { m_context = context; if (context instanceof Activity) m_activity = (Activity) context; @@ -52,13 +52,14 @@ public class QtNfc flags); } - static public boolean startDiscovery() + static boolean startDiscovery() { if (m_adapter == null || m_activity == null || !m_activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) return false; m_activity.runOnUiThread(new Runnable() { + @Override public void run() { IntentFilter[] filters = new IntentFilter[3]; filters[0] = new IntentFilter(); @@ -90,13 +91,14 @@ public class QtNfc return true; } - static public boolean stopDiscovery() + static boolean stopDiscovery() { if (m_adapter == null || m_activity == null || !m_activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) return false; m_activity.runOnUiThread(new Runnable() { + @Override public void run() { try { m_adapter.disableForegroundDispatch(m_activity); @@ -109,7 +111,7 @@ public class QtNfc return true; } - static public boolean isEnabled() + static boolean isEnabled() { if (m_adapter == null) { return false; @@ -118,12 +120,12 @@ public class QtNfc return m_adapter.isEnabled(); } - static public boolean isSupported() + static boolean isSupported() { return (m_adapter != null); } - static public Intent getStartIntent() + static Intent getStartIntent() { Log.d(TAG, "getStartIntent"); if (m_activity == null) return null; @@ -138,7 +140,7 @@ public class QtNfc } } - static public Parcelable getTag(Intent intent) + static Parcelable getTag(Intent intent) { return intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); } diff --git a/src/android/nfc/src/org/qtproject/qt/android/nfc/QtNfcBroadcastReceiver.java b/src/android/nfc/src/org/qtproject/qt/android/nfc/QtNfcBroadcastReceiver.java index e70ec9a5..cd6b6a43 100644 --- a/src/android/nfc/src/org/qtproject/qt/android/nfc/QtNfcBroadcastReceiver.java +++ b/src/android/nfc/src/org/qtproject/qt/android/nfc/QtNfcBroadcastReceiver.java @@ -9,12 +9,12 @@ import android.content.Intent; import android.content.IntentFilter; import android.nfc.NfcAdapter; -public class QtNfcBroadcastReceiver extends BroadcastReceiver +class QtNfcBroadcastReceiver extends BroadcastReceiver { final private long qtObject; final private Context qtContext; - public QtNfcBroadcastReceiver(long obj, Context context) + QtNfcBroadcastReceiver(long obj, Context context) { qtObject = obj; qtContext = context; @@ -22,16 +22,17 @@ public class QtNfcBroadcastReceiver extends BroadcastReceiver qtContext.registerReceiver(this, filter); } - public void unregisterReceiver() + void unregisterReceiver() { qtContext.unregisterReceiver(this); } + @Override public void onReceive(Context context, Intent intent) { final int state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF); jniOnReceive(qtObject, state); } - public native void jniOnReceive(long qtObject, int state); + native void jniOnReceive(long qtObject, int state); } |