Angelo Rampersad
Edited

Android failing events due to negative availableStorage in platformContext

Hi there,

We have been seeing some odd behaviour on a few failing events, concerning the platform context automatically added by the Snowplow Android SDK. While our Android SDK has been upgraded to v6.0.6 which took care of the Snowplow SDK passing a negative `batteryLevel`, seemingly occurrences have been registered where the SDK now appended a negative `availableStorage`:

```

{
    "schema": "iglu:com.snowplowanalytics.snowplow/mobile_context/jsonschema/1-0-3",
    "data": {
        "scale": 1.7,
        "language": "nld",
        "isPortrait": true,
        "resolution": "720x1464",
        "carrier": "vodafone NL",
        "totalStorage": 512000000000,
        "systemAvailableMemory": 1718472704,
        "osVersion": "12",
        "batteryState": "unplugged",
        "availableStorage": -2107899904,
        "osType": "android",
        "androidIdfa": "",
        "deviceModel": "S25 Ultra",
        "deviceManufacturer": "alps",
        "networkType": "wifi",
        "physicalMemory": 4049813504,
        "batteryLevel": 100
    }
}

```

In turn, this causes events to fail validation:

```

ValidationError with DataReports:1 SchemaIssues:0 for 'iglu:com.snowplowanalytics.snowplow/mobile_context/jsonschema/1-0-3'
dataReport -- Path:'$.availableStorage' Keyword:'minimum' Message:'$.availableStorage: must have a minimum value of 0' Targets:'0'

```

How to best remedy this and is a similar patch to snowplow-android-tracker as in v6.0.6 required possibly?

 

Thank you. 

Regards,
Angelo

0 3 3
Matúš Tomlein

Thank you for the report Angelo, this seems like an issue we will have to fix in the tracker similar to the `batteryLevel` fix in the 6.0.6 version, have created a ticket for it!

Angelo Rampersad

Hi there,

Checking in. Is this on the planning to include in any upcoming releases soon?

We're currently on version 6.3.0 of the Android tracker and still experiencing this issue.

Regards,
Angelo

Jordan Ellis

Hi Angelo,

Yeah this looks like the exact same issue as the batteryLevel fix in v6.0.6 — just hitting availableStorage this time. Probably an integer overflow on large storage devices (the S25 Ultra with 512GB is a likely trigger).

A similar patch to the tracker should fix it — just need a maxOf(0L, value) guard before the value gets added to the context, same as what was done for batteryLevel.

In the meantime, clamping negative availableStorage values to 0 on the pipeline side will stop events from getting dropped.

We'll look into it and get a fix raised. Thanks for flagging!

Regards