Skip to content

Commit 939143c

Browse files
committed
fixed compiler warnings
1 parent 69be05e commit 939143c

63 files changed

Lines changed: 503 additions & 659 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

android_app/app/build.gradle.kts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import java.util.TimeZone
88

99
plugins {
1010
alias(libs.plugins.android.application)
11-
alias(libs.plugins.kotlin.android)
1211
alias(libs.plugins.kotlin.compose)
1312
alias(libs.plugins.hilt.android)
1413
alias(libs.plugins.ksp)
@@ -24,12 +23,12 @@ ksp {
2423

2524
android {
2625
namespace = "com.health.openscale"
27-
compileSdk = 36
26+
compileSdk = 37
2827

2928
defaultConfig {
3029
applicationId = "com.health.openscale"
3130
minSdk = 31
32-
targetSdk = 36
31+
targetSdk = 37
3332
versionCode = 75
3433
versionName = "3.1.1"
3534

@@ -50,7 +49,7 @@ android {
5049
keystoreProperties.load(fis)
5150
}
5251
propertiesLoaded = true
53-
} catch (e: FileNotFoundException) {
52+
} catch (_: FileNotFoundException) {
5453
project.logger.warn("Keystore properties file not found: ${keystorePropertiesFile.absolutePath}. Release signing might fail if not configured via environment variables.")
5554
propertiesLoaded = false
5655
}
@@ -75,7 +74,7 @@ android {
7574
keystoreOSSProperties.load(fis)
7675
}
7776
propertiesLoaded = true
78-
} catch (e: FileNotFoundException) {
77+
} catch (_: FileNotFoundException) {
7978
project.logger.warn("OSS Keystore properties file not found: ${keystoreOSSPropertiesFile.absolutePath}. OSS signing might fail if not configured via environment variables.")
8079
propertiesLoaded = false
8180
}
@@ -135,22 +134,37 @@ android {
135134
}
136135
}
137136

138-
applicationVariants.all {
139-
val variant = this
140-
val buildType = variant.buildType.name
137+
compileOptions {
138+
sourceCompatibility = JavaVersion.VERSION_21
139+
targetCompatibility = JavaVersion.VERSION_21
140+
}
141+
142+
buildFeatures {
143+
compose = true
144+
buildConfig = true
145+
}
146+
147+
testOptions {
148+
// JVM unit tests touch android.util.Log (via LogManager); return defaults
149+
// instead of throwing "not mocked" so pure-logic tests can run on the JVM.
150+
unitTests.isReturnDefaultValues = true
151+
}
152+
}
153+
154+
androidComponents {
155+
onVariants { variant ->
141156
// Include the version number for every build type except debug.
142-
val baseName = if (buildType == "debug") {
143-
"openScale-$buildType"
157+
val baseName = if (variant.buildType == "debug") {
158+
"openScale-${variant.buildType}"
144159
} else {
145-
"openScale-${defaultConfig.versionName}-$buildType"
160+
"openScale-${android.defaultConfig.versionName}-${variant.buildType}"
146161
}
147162

148-
// APK naming.
149-
outputs.all {
150-
val output = this
151-
if (output is com.android.build.gradle.internal.api.BaseVariantOutputImpl) {
152-
output.outputFileName = "$baseName.apk"
153-
}
163+
// APK naming. outputFileName is the official replacement for the removed
164+
// applicationVariants API but still marked @Incubating in AGP 9.
165+
@Suppress("UnstableApiUsage")
166+
variant.outputs.forEach { output ->
167+
output.outputFileName.set("$baseName.apk")
154168
}
155169

156170
// AAB naming: the outputs API above only covers APKs, so rename the
@@ -171,24 +185,9 @@ android {
171185
}
172186
}
173187
}
174-
175-
compileOptions {
176-
sourceCompatibility = JavaVersion.VERSION_21
177-
targetCompatibility = JavaVersion.VERSION_21
178-
}
179-
180-
buildFeatures {
181-
compose = true
182-
buildConfig = true
183-
}
184-
185-
testOptions {
186-
// JVM unit tests touch android.util.Log (via LogManager); return defaults
187-
// instead of throwing "not mocked" so pure-logic tests can run on the JVM.
188-
unitTests.isReturnDefaultValues = true
189-
}
190188
}
191189

190+
192191
dependencies {
193192

194193
implementation(libs.androidx.core.ktx)

android_app/app/src/main/java/com/health/openscale/core/bluetooth/ScaleFactory.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ import kotlinx.coroutines.runBlocking
7878
import kotlinx.coroutines.withTimeout
7979
import javax.inject.Inject
8080
import javax.inject.Singleton
81+
import kotlin.time.Duration.Companion.milliseconds
8182

8283
/**
8384
* Factory class responsible for creating appropriate [ScaleCommunicator] instances
8485
* for different Bluetooth scale devices.
8586
*/
8687
@Singleton
8788
class ScaleFactory @Inject constructor(
88-
@ApplicationContext private val applicationContext: Context,
89+
@param:ApplicationContext private val applicationContext: Context,
8990
private val settingsFacade: SettingsFacade,
9091
private val measurementFacade: MeasurementFacade,
9192
private val userFacade: UserFacade,
@@ -155,7 +156,7 @@ class ScaleFactory @Inject constructor(
155156
val effectiveTuning: TuningProfile = run {
156157
val saved: String? = runCatching {
157158
runBlocking(Dispatchers.IO) {
158-
withTimeout(250) {
159+
withTimeout(250.milliseconds) {
159160
settingsFacade.savedBluetoothTuneProfile.firstOrNull()
160161
}
161162
}
@@ -205,7 +206,7 @@ class ScaleFactory @Inject constructor(
205206
* @return A [ScaleCommunicator] instance if a suitable handler or adapter is found, otherwise null.
206207
*/
207208
fun createCommunicator(deviceInfo: ScannedDeviceInfo): ScaleCommunicator? {
208-
val primaryIdentifier = deviceInfo.name ?: "UnknownDevice"
209+
val primaryIdentifier = deviceInfo.name
209210
LogManager.d(TAG, "createCommunicator: Searching for communicator for '${primaryIdentifier}' (${deviceInfo.address}). Handler hint: '${deviceInfo.determinedHandlerDisplayName}'")
210211

211212
// 1. Check if a modern Kotlin handler explicitly supports the device.

android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/ActiveEraBF06Handler.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ActiveEraBF06Handler : ScaleDeviceHandler() {
7272
override fun supportFor(device: ScannedDeviceInfo): DeviceSupport? {
7373
// Match by name heuristics and/or advertised service UUID
7474
val name = device.name.lowercase()
75-
val hasSvc = device.serviceUuids?.any { it == SERVICE } == true
75+
val hasSvc = device.serviceUuids.any { it == SERVICE }
7676
if (
7777
hasSvc ||
7878
name.contains("AE BS-06".lowercase())
@@ -196,7 +196,7 @@ class ActiveEraBF06Handler : ScaleDeviceHandler() {
196196
0x00 // checksum placeholder
197197
)
198198
// original legacy code summed 2..(len-3). We keep that to stay protocol-compatible.
199-
pkt[pkt.lastIndex] = sumChecksum(pkt, from = 2, toExclusive = pkt.size - 3)
199+
pkt[pkt.lastIndex] = sumChecksum(pkt, toExclusive = pkt.size - 3)
200200
return pkt
201201
}
202202

@@ -355,10 +355,10 @@ class ActiveEraBF06Handler : ScaleDeviceHandler() {
355355

356356
// --- Small helpers --------------------------------------------------------
357357

358-
/** Legacy "sumChecksum": sum of bytes in [from, toExclusive) truncated to 8-bit. */
359-
private fun sumChecksum(data: ByteArray, from: Int, toExclusive: Int): Byte {
358+
/** Legacy "sumChecksum": sum of bytes in [2, toExclusive) truncated to 8-bit. */
359+
private fun sumChecksum(data: ByteArray, toExclusive: Int): Byte {
360360
var sum = 0
361-
for (i in from until toExclusive) sum = (sum + (data[i].toInt() and 0xFF)) and 0xFF
361+
for (i in 2 until toExclusive) sum = (sum + (data[i].toInt() and 0xFF)) and 0xFF
362362
return sum.toByte()
363363
}
364364

android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/BroadcastScaleAdapter.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import kotlinx.coroutines.Job
3434
import kotlinx.coroutines.delay
3535
import kotlinx.coroutines.launch
3636
import java.util.UUID
37+
import kotlin.time.Duration.Companion.milliseconds
3738

3839
// -------------------------------------------------------------------------------------------------
3940
// Broadcast adapter (no GATT)
@@ -119,8 +120,8 @@ class BroadcastScaleAdapter(
119120
lastForwardAtMs = t
120121
LogManager.d(TAG, "Measurement stabilized → BroadcastComplete for ${peripheral.address}")
121122
_events.tryEmit(BluetoothEvent.BroadcastComplete(peripheral.address))
122-
stopScanInternal(peripheral.address)
123-
cleanup(peripheral.address)
123+
stopScanInternal()
124+
cleanup()
124125
broadcastAttached = false
125126
}
126127
}
@@ -164,24 +165,24 @@ class BroadcastScaleAdapter(
164165
} catch (e: Exception) {
165166
LogManager.e(TAG, "Failed to start broadcast scan: ${e.message}", e)
166167
_events.tryEmit(BluetoothEvent.ConnectionFailed(address, e.message ?: context.getString(R.string.bt_error_generic)))
167-
cleanup(address)
168+
cleanup()
168169
return
169170
}
170171

171172
// Arm scan timeout for this attempt
172173
scanTimeoutJob?.cancel()
173174
scanTimeoutJob = scope.launch {
174-
delay(tuning.maxScanMs)
175+
delay(tuning.maxScanMs.milliseconds)
175176
if (!isScanning) return@launch
176177
LogManager.w(TAG, "Broadcast scan timed out for $address")
177-
stopScanInternal(address)
178+
stopScanInternal()
178179

179180
attempt++
180181
if (attempt <= tuning.common.maxRetries) {
181-
delay(tuning.common.retryBackoffMs)
182+
delay(tuning.common.retryBackoffMs.milliseconds)
182183
startScanAttempt(address)
183184
} else {
184-
cleanup(address)
185+
cleanup()
185186
// keep attached? we detach to be consistent with failure
186187
runCatching { handler.handleDisconnected() }
187188
runCatching { handler.detach() }
@@ -190,7 +191,7 @@ class BroadcastScaleAdapter(
190191
}
191192
}
192193

193-
private fun stopScanInternal(address: String) {
194+
private fun stopScanInternal() {
194195
scanTimeoutJob?.cancel(); scanTimeoutJob = null
195196
runCatching { if (::central.isInitialized) central.stopScan() }
196197
isScanning = false
@@ -240,7 +241,7 @@ class BroadcastScaleAdapter(
240241
}
241242

242243
override fun doDisconnect() {
243-
stopScanInternal(targetAddress ?: "")
244+
stopScanInternal()
244245
runCatching { handler.handleDisconnected() }
245246
runCatching { handler.detach() }
246247
broadcastAttached = false

android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/DebugGattHandler.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import com.health.openscale.core.bluetooth.data.ScaleUser
1919
import com.health.openscale.core.service.ScannedDeviceInfo
2020
import java.util.Locale
2121
import java.util.UUID
22-
import kotlin.math.min
2322

2423
/**
2524
* ## DebugGattHandler
@@ -117,7 +116,7 @@ class DebugGattHandler : ScaleDeviceHandler() {
117116
return
118117
}
119118

120-
val services = peripheral.services ?: emptyList()
119+
val services = peripheral.services
121120
logD("=== GATT Service Dump BEGIN ===")
122121
if (services.isEmpty()) {
123122
logD( "(no services)")

android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/DigooDGSO38HHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class DigooDGSO38HHandler : ScaleDeviceHandler() {
4848
private val CHR_EXTRA get() = uuid16(0xFFF2) // write
4949

5050
override fun supportFor(device: ScannedDeviceInfo): DeviceSupport? {
51-
val name = device.name ?: return null
51+
val name = device.name
5252
// Historically these scales often advertise as "Mengii". Keep both labels.
5353
val supported = name.equals("Mengii", true)
5454
if (!supported) return null

android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/EbelterBodyFatB2Handler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class EbelterBodyFatB2Handler : ScaleDeviceHandler() {
4343
private var lastPublishedFatRaw: Int = -1
4444

4545
override fun supportFor(device: ScannedDeviceInfo): DeviceSupport? {
46-
val name = (device.name ?: "").uppercase()
46+
val name = device.name.uppercase()
4747

4848
// En tus capturas sale como "Body Fat-B2"
4949
if (name.startsWith("BODY FAT-B2")) {

android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/EufyC20Handler.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.health.openscale.core.bluetooth.scales
22

33
import android.bluetooth.le.ScanResult
44
import android.util.SparseArray
5+
import androidx.core.util.isEmpty
6+
import androidx.core.util.size
57
import com.health.openscale.core.bluetooth.data.ScaleMeasurement
68
import com.health.openscale.core.bluetooth.data.ScaleUser
79
import com.health.openscale.core.bluetooth.libs.MiScaleLib
@@ -32,7 +34,7 @@ class EufyC20Handler : ScaleDeviceHandler() {
3234

3335
private fun extractManufacturerIds(m: Any?): Iterable<Int> = when (m) {
3436
is Map<*, *> -> m.keys.filterIsInstance<Int>()
35-
is SparseArray<*> -> (0 until m.size()).mapNotNull { m.keyAt(it) as? Int }
37+
is SparseArray<*> -> (0 until m.size).map { m.keyAt(it) }
3638
is List<*> -> m.mapNotNull {
3739
if (it is Pair<*, *>) (it.first as? Int) else null
3840
}
@@ -43,9 +45,7 @@ class EufyC20Handler : ScaleDeviceHandler() {
4345
override fun supportFor(device: ScannedDeviceInfo): DeviceSupport? {
4446
val m = device.manufacturerData
4547
if (m != null && extractManufacturerIds(m).any { it == MANUFACTURER_ID }) return deviceSupport
46-
val name = device.name
47-
if (name == null) return null
48-
val un = name.uppercase(Locale.US)
48+
val un = device.name.uppercase(Locale.US)
4949
if (un.startsWith("EUFY") && (un.contains("C20") || un.contains("T9130"))) {
5050
return deviceSupport
5151
}
@@ -56,12 +56,12 @@ class EufyC20Handler : ScaleDeviceHandler() {
5656
override fun onAdvertisement(result: ScanResult, user: ScaleUser): BroadcastAction {
5757
val msdRaw = result.scanRecord?.manufacturerSpecificData ?: return BroadcastAction.IGNORED
5858
val msd = msdRaw as? SparseArray<*> ?: return BroadcastAction.IGNORED
59-
if (msd.size() == 0) return BroadcastAction.IGNORED
60-
val values = (0 until msd.size()).mapNotNull { msd.valueAt(it) as? ByteArray }
59+
if (msd.isEmpty()) return BroadcastAction.IGNORED
60+
val values = (0 until msd.size).mapNotNull { msd.valueAt(it) as? ByteArray }
6161

6262
val payload = values.firstOrNull { it.size >= 14 } ?: return BroadcastAction.IGNORED
6363

64-
return try {
64+
try {
6565
val flags = payload[10].toInt() and 0xFF
6666
val hasWeight = (flags and 0x01) != 0
6767
val hasImpedance = (flags and 0x40) != 0

0 commit comments

Comments
 (0)