Skip to content

Commit

Permalink
Android source: Prepare for 3.2.7 release
Browse files Browse the repository at this point in the history
- Android SDK target lift from 29 to 31
- small enhancements and bug fixes
  • Loading branch information
JOikarinen committed Feb 7, 2022
1 parent 90d1f51 commit e33f055
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 267 deletions.
4 changes: 2 additions & 2 deletions sources/Android/android-communications/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.5.31'
ext.kotlin_version = '1.6.10'
ext.protobuf_version = '0.8.12'
ext.dokka_version = '1.4.32'

Expand All @@ -11,7 +11,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.protobuf:protobuf-gradle-plugin:$protobuf_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 10 10:03:55 EEST 2021
#Mon Feb 07 10:00:30 EET 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
14 changes: 7 additions & 7 deletions sources/Android/android-communications/library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def getVersion = { ->
}

android {
compileSdkVersion 29
compileSdkVersion 31

defaultConfig {
minSdkVersion 21
targetSdkVersion 29
targetSdkVersion 31
versionCode 14
versionName "14"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -155,16 +155,16 @@ protobuf {

dependencies {
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'io.reactivex.rxjava3:rxjava:3.1.1'
implementation 'io.reactivex.rxjava3:rxjava:3.1.3'
implementation 'commons-io:commons-io:2.10.0'
implementation 'androidx.annotation:annotation:1.2.0'
implementation "androidx.core:core-ktx:1.6.0"
implementation 'androidx.annotation:annotation:1.3.0'
implementation "androidx.core:core-ktx:1.7.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
sdkImplementation 'com.google.protobuf:protobuf-javalite:3.17.3'
sdkProprietaryImplementation 'com.google.protobuf:protobuf-javalite:3.17.3'
testImplementation 'junit:junit:4.13.2'
testImplementation "org.mockito:mockito-core:3.11.1"
testImplementation "io.mockk:mockk:1.10.6"
testImplementation 'org.mockito:mockito-core:4.3.1'
testImplementation 'io.mockk:mockk:1.12.2'
testImplementation 'androidx.test:runner:1.4.0'
testImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'junit:junit:4.13.2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.polar.androidcommunications">
<!-- Polar SDK needs Bluetooth scan permission to search for BLE devices.-->
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" />

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Polar SDK needs Bluetooth connect permission to connect for found BLE devices.-->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

<!-- Allows Polar SDK to connect to paired bluetooth devices. Legacy Bluetooth permission,
which is needed on devices with API 30 (Android Q) or older. -->
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />

<!-- Allows Polar SDK to discover and pair bluetooth devices. Legacy Bluetooth permission,
which is needed on devices with API 30 (Android Q) or older. -->
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />

<!-- Polar SDK needs the fine location permission to get results for Bluetooth scan. Request
fine location permission on devices with API 30 (Android Q). -->
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"
android:maxSdkVersion="30" />

<!-- The coarse location permission is needed, if fine location permission is requested. Request
coarse location permission on devices with API 30 (Android Q). -->
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
android:maxSdkVersion="30" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.polar.androidcommunications.api.ble.exceptions

class BleStartScanError(message: String, val error: Int) : Exception("$message failed with error: $error")
class BleStartScanError(message: String) : Exception(message)
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class BlePMDClient(txInterface: BleGattTxInterface) : BleGattBase(txInterface, P
var offset = 0
var channelCount = 0
val mask = -0x1 shl resolution - 1
val resolutionInBytes = Math.ceil(resolution / 8.0).toInt()
val resolutionInBytes = ceil(resolution / 8.0).toInt()
while (channelCount++ < channels) {
var sample: Int
if (type == PmdDataFieldEncoding.SIGNED_INT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import java.io.ByteArrayOutputStream
class PmdControlPointResponse(data: ByteArray) {
val responseCode: Byte = data[0]
val opCode: PmdControlPointCommand = PmdControlPointCommand.values()[data[1].toInt()]
val measurementType: Byte

@JvmField
val status: PmdControlPointResponseCode

@JvmField
val measurementType: Byte = data[2]
val status: PmdControlPointResponseCode = PmdControlPointResponseCode.values()[data[3].toInt()]
val more: Boolean
val parameters = ByteArrayOutputStream()

@JvmField
var more = false

enum class PmdControlPointResponseCode(val numVal: Int) {
SUCCESS(0),
ERROR_INVALID_OP_CODE(1),
Expand All @@ -34,8 +28,6 @@ class PmdControlPointResponse(data: ByteArray) {
}

init {
measurementType = data[2]
status = PmdControlPointResponseCode.values()[data[3].toInt()]
if (status == PmdControlPointResponseCode.SUCCESS) {
more = data.size > 4 && data[4] != 0.toByte()
if (data.size > 5) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class PpgData internal constructor(val timeStamp: Long) {

// PPG Data frame type 4
data class PpgDataSampleFrameType4 internal constructor(
val channel1GainTs: List<Int>,
val channel2GainTs: List<Int>,
val numIntTs: List<UInt>
val numIntTs: List<UInt>,
val channel1GainTs: List<UInt>,
val channel2GainTs: List<UInt>
) : PpgDataSample()

// PPG Data frame type 5
Expand Down Expand Up @@ -86,18 +86,16 @@ class PpgData internal constructor(val timeStamp: Long) {
val ppgData = PpgData(timeStamp)
var offset = 0
while (offset < frame.size) {
val channel1GainTs = frame.sliceArray(offset..(offset + 11)).map { (it and 0x07).toInt() }
offset += 12
val channel2GainTs = frame.sliceArray(offset..(offset + 11)).map { (it and 0x07).toInt() }
offset += 12
val numIntTs = frame.sliceArray(offset..(offset + 11)).map { it.toUByte().toUInt() }
offset += 12

val channel1GainTs = frame.sliceArray(offset..(offset + 23)).toList().mapIndexedNotNull { idx, v -> if (idx % 2 == 0) (v and 0x07).toUInt() else null }
val channel2GainTs = frame.sliceArray(offset..(offset + 23)).toList().mapIndexedNotNull { idx, v -> if (idx % 2 == 1) (v and 0x07).toUInt() else null }
offset += 24
ppgData.ppgSamples.add(
PpgDataSampleFrameType4(
numIntTs = numIntTs,
channel1GainTs = channel1GainTs,
channel2GainTs = channel2GainTs,
numIntTs = numIntTs
channel2GainTs = channel2GainTs
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import java.util.List;
import java.util.UUID;

import protocol.PftpError;

/**
* RFC76 and RFC 60 related utils
*/
Expand Down Expand Up @@ -61,7 +59,7 @@ public static class PftpResponseError extends Exception {
private final int error;

public PftpResponseError(String detailMessage, int error) {
super(detailMessage + " Error: " + error + " : " + PftpError.PbPFtpError.forNumber(error));
super(detailMessage + " Error: " + error);
this.error = error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ public boolean isScanningNeeded() {
}

@Override
public void scanStartError(int error) {
RxUtils.postError(observers, new BleStartScanError("scan start failed ", error));
public void scanStartError(@NonNull String error) {
RxUtils.postError(observers, new BleStartScanError(error));
}

public void deviceDiscovered(BluetoothDevice device, int rssi, byte[] scanRecord, BleUtils.EVENT_TYPE type) {
public void deviceDiscovered(BluetoothDevice device, int rssi, @NonNull byte[] scanRecord, @NonNull BleUtils.EVENT_TYPE type) {
BDDeviceSessionImpl deviceSession = sessions.getSession(device);
HashMap<BleUtils.AD_TYPE, byte[]> advData = BleUtils.advertisementBytes2Map(scanRecord);
final String manufacturer = Build.MANUFACTURER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ internal class BDScanCallback(
private var opportunisticScanTimer: Disposable? = null

internal interface BDScanCallbackInterface {
fun deviceDiscovered(device: BluetoothDevice?, rssi: Int, scanRecord: ByteArray?, type: EVENT_TYPE?)
fun scanStartError(error: Int)
fun deviceDiscovered(device: BluetoothDevice?, rssi: Int, scanRecord: ByteArray, type: EVENT_TYPE)
fun scanStartError(error: String)
fun isScanningNeeded(): Boolean
}

Expand Down Expand Up @@ -102,8 +102,9 @@ internal class BDScanCallback(
}

override fun onScanFailed(errorCode: Int) {
BleLogger.e(TAG, "START scan error: $errorCode")
scanCallbackInterface.scanStartError(errorCode)
val scanFailureString = "Scan start failed to ScanCallback errorCode: $errorCode"
BleLogger.e(TAG, scanFailureString)
scanCallbackInterface.scanStartError(scanFailureString)
}
}

Expand Down Expand Up @@ -131,6 +132,7 @@ internal class BDScanCallback(
private fun scannerIdleState(action: ScanAction) {
when (action) {
ScanAction.ENTRY -> {
bluetoothAdapter.isEnabled
if (bluetoothAdapter.isEnabled && scanCallbackInterface.isScanningNeeded()) {
changeState(ScannerState.SCANNING)
}
Expand Down Expand Up @@ -297,7 +299,9 @@ internal class BDScanCallback(
try {
bluetoothAdapter.bluetoothLeScanner.startScan(filters, scanSettings, leScanCallback)
} catch (e: Exception) {
BleLogger.e(TAG, "Failed to start scan e: " + e.localizedMessage)
val errorString = "Failed to start scan. Reason: ${e.message}"
BleLogger.e(TAG, errorString)
scanCallbackInterface.scanStartError(errorString)
changeState(ScannerState.IDLE)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ object PolarBleApiDefaultImpl {
*/
@JvmStatic
fun versionInfo(): String {
return "3.2.3"
return "3.2.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class PolarAccelerometerData {

public static class PolarAccelerometerDataSample {
/**
* x axis in millig
* x axis in millig (including gravity)
*/
public final int x;
/**
* y axis in millig
* y axis in millig (including gravity)
*/
public final int y;
/**
* z axis in millig
* z axis in millig (including gravity)
*/
public final int z;

Expand Down
Loading

0 comments on commit e33f055

Please sign in to comment.