Skip to content

Commit

Permalink
Merge branch 'release/6.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Sep 12, 2024
2 parents 3c8f9fa + 16faf51 commit 05fdaa6
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Load logs if failed
if: ${{ failure() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: logcat-${{ matrix.api-level }}
path: logcat.log
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 6.0.6 (2024-09-12)
--------------------------
Set negative battery levels to null in mobile context (#698)

Version 6.0.5 (2024-06-22)
--------------------------
Handle exceptions raised by the Executor during initialization of the thread pool for emitter (#694)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.5
6.0.6
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {

subprojects {
group = 'com.snowplowanalytics'
version = '6.0.5'
version = '6.0.6'
repositories {
google()
maven {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ systemProp.org.gradle.internal.http.socketTimeout=120000
SONATYPE_STAGING_PROFILE=comsnowplowanalytics
GROUP=com.snowplowanalytics
POM_ARTIFACT_ID=snowplow-android-tracker
VERSION_NAME=6.0.5
VERSION_NAME=6.0.6

POM_NAME=snowplow-android-tracker
POM_PACKAGING=aar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import com.snowplowanalytics.core.utils.DeviceInfoMonitor
class MockDeviceInfoMonitor : DeviceInfoMonitor() {
private val methodAccessCounts: MutableMap<String, Int> = HashMap()
var customIdfa: String? = "XJKLJSALFKJ"
var batteryLevel: Int = 20

override val osType: String
get() {
increaseMethodAccessCount("getOsType")
Expand Down Expand Up @@ -73,7 +75,7 @@ class MockDeviceInfoMonitor : DeviceInfoMonitor() {

override fun getBatteryStateAndLevel(context: Context): Pair<String?, Int>? {
increaseMethodAccessCount("getBatteryStateAndLevel")
return Pair("charging", 20)
return Pair("charging", batteryLevel)
}

override val availableStorage: Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,20 @@ class PlatformContextTest {
Assert.assertEquals("r13", sdjData[Parameters.APP_SET_ID_SCOPE])
}

@Test
fun batteryLevelNotTrackedIfNegative() {
val deviceInfoMonitor = MockDeviceInfoMonitor()
deviceInfoMonitor.batteryLevel = -1
val platformContext = PlatformContext(0, 0, deviceInfoMonitor, context = context)

val sdj = platformContext.getMobileContext(false)
Assert.assertNotNull(sdj)
val sdjData = sdj!!.map["data"] as Map<*, *>

Assert.assertEquals("charging", sdjData[Parameters.BATTERY_STATE])
Assert.assertFalse(sdjData.containsKey(Parameters.BATTERY_LEVEL))
}

// --- PRIVATE
private val context: Context
get() = InstrumentationRegistry.getInstrumentation().targetContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package com.snowplowanalytics.core.tracker

import android.content.Context
import android.util.Pair
import com.snowplowanalytics.core.constants.Parameters
import com.snowplowanalytics.core.constants.TrackerConstants
import com.snowplowanalytics.core.utils.DeviceInfoMonitor
Expand Down Expand Up @@ -147,7 +148,11 @@ class PlatformContext(
if (trackBatState || trackBatLevel) {
val batteryInfo = deviceInfoMonitor.getBatteryStateAndLevel(context)
if (trackBatState) { addToMap(Parameters.BATTERY_STATE, fromRetrieverOr(retriever.batteryState) { batteryInfo?.first }, pairs) }
if (trackBatLevel) { addToMap(Parameters.BATTERY_LEVEL, fromRetrieverOr(retriever.batteryLevel) { batteryInfo?.second }, pairs) }
if (trackBatLevel) {
val batteryLevel = fromRetrieverOr(retriever.batteryLevel) { batteryInfo?.second }
val validBatteryLevel = if (batteryLevel != null && batteryLevel >= 0) batteryLevel else null
addToMap(Parameters.BATTERY_LEVEL, validBatteryLevel, pairs)
}
}
// Memory
if (shouldTrack(PlatformContextProperty.SYSTEM_AVAILABLE_MEMORY)) {
Expand Down

0 comments on commit 05fdaa6

Please sign in to comment.