Skip to content

Commit

Permalink
truncate timezone ID if too long
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed Nov 29, 2024
1 parent 3ac7b52 commit a436039
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.rebble.cobble.pigeons.BooleanWrapper
import io.rebble.cobble.pigeons.Pigeons
import io.rebble.cobble.shared.domain.state.ConnectionStateManager
import io.rebble.cobble.shared.domain.state.watchOrNull
import io.rebble.cobble.shared.handlers.SystemHandler
import io.rebble.cobble.shared.util.zippedSource
import io.rebble.cobble.util.launchPigeonResult
import io.rebble.libpebblecommon.metadata.WatchHardwarePlatform
Expand Down Expand Up @@ -84,7 +85,7 @@ class FirmwareUpdateControlFlutterBridge @Inject constructor(
val updateTimePacket = TimeMessage.SetUTC(
now.toUInt(),
offsetMinutes.toShort(),
timezone.id
timezone.id.take(SystemHandler.MAX_TIMEZONE_NAME_LENGTH)
)

ConnectionStateManager.connectionState.value.watchOrNull?.systemService?.send(updateTimePacket)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class SystemHandler(
}
}

companion object {
const val MAX_TIMEZONE_NAME_LENGTH = 32
}

fun negotiationsComplete(watch: PebbleDevice) {
if (ConnectionStateManager.connectionState.value is ConnectionState.Negotiating) {
ConnectionStateManager.connectionState.value = ConnectionState.Connected(watch)
Expand Down Expand Up @@ -118,11 +122,11 @@ class SystemHandler(
val timezone = TimeZone.currentSystemDefault()
val now = Clock.System.now()
val timezoneOffsetMinutes = timezone.offsetAt(now).totalSeconds.seconds.inWholeMinutes
Logging.i("Sending current time to watch: $now, timezone: $timezone, offset: $timezoneOffsetMinutes")
Logging.i("Sending current time to watch: $now, timezone: ${timezone.id} (truncated: ${timezone.id.take(MAX_TIMEZONE_NAME_LENGTH)}), offset: $timezoneOffsetMinutes")
val updateTimePacket = TimeMessage.SetUTC(
now.epochSeconds.toUInt(),
timezoneOffsetMinutes.toShort(),
timezone.id
timezone.id.take(MAX_TIMEZONE_NAME_LENGTH)
)

systemService.send(updateTimePacket)
Expand Down

0 comments on commit a436039

Please sign in to comment.