Commit eb035d0d authored by Andreas Schildbach's avatar Andreas Schildbach
Browse files

UpdateClockJob: Print time out message if connectGatt() takes too long.

parent dc0e5f5c
......@@ -72,17 +72,18 @@ class UpdateClockJob(context: Context, workerParameters: WorkerParameters) : Wor
}
}
gatt = device.connectGatt(applicationContext, true, callback)
if (!gattLatch.await(1, TimeUnit.MINUTES))
return Result.retry()
val buffer = ByteBuffer.allocate(8)
buffer.putLong(System.currentTimeMillis())
timeCharacteristic?.value = buffer.array()
if (gatt.writeCharacteristic(timeCharacteristic)) {
writeLatch = CountDownLatch(1)
if (!writeLatch.await(1, TimeUnit.MINUTES))
return Result.failure()
System.out.println("=== doWork() updated time")
if (!gattLatch.await(1, TimeUnit.MINUTES)) {
System.out.println("=== doWork() connectGatt timed out")
} else {
val buffer = ByteBuffer.allocate(8)
buffer.putLong(System.currentTimeMillis())
timeCharacteristic?.value = buffer.array()
if (gatt.writeCharacteristic(timeCharacteristic)) {
writeLatch = CountDownLatch(1)
if (!writeLatch.await(1, TimeUnit.MINUTES))
return Result.failure()
System.out.println("=== doWork() updated time")
}
}
} catch (x: Exception) {
x.printStackTrace()
......@@ -92,7 +93,7 @@ class UpdateClockJob(context: Context, workerParameters: WorkerParameters) : Wor
}
}
System.out.println("=== doWork() job finished (success)")
System.out.println("=== doWork() job finished")
return Result.success()
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment