android: DiagLog thread-safe timestamps; auto-connect survives stop/start
- SimpleDateFormat is now used under the lock; rotation counts bytes - AutoConnectManager.stop() clears pendingEvaluate, whose reset runnable it removes, so later connects are not silently swallowed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
01c398f2f7
commit
e6c893219c
2 files changed
+6
-2
No files matched your search
@@ -62,9 +62,10 @@ object DiagLog
|
|||||||
val base = dir ?: return
|
val base = dir ?: return
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
val line = "${format.format(Date())} $tag: $message\n"
|
|
||||||
synchronized(this)
|
synchronized(this)
|
||||||
{
|
{
|
||||||
|
/* SimpleDateFormat is not thread-safe: format under the lock */
|
||||||
|
val line = "${format.format(Date())} $tag: $message\n"
|
||||||
if (written > MAX_SIZE)
|
if (written > MAX_SIZE)
|
||||||
{
|
{
|
||||||
rotate(base)
|
rotate(base)
|
||||||
@@ -79,7 +80,7 @@ object DiagLog
|
|||||||
}
|
}
|
||||||
w.write(line)
|
w.write(line)
|
||||||
w.flush()
|
w.flush()
|
||||||
written += line.length + 1
|
written += line.toByteArray(Charsets.UTF_8).size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (_: Exception)
|
catch (_: Exception)
|
||||||
|
|||||||
+3
@@ -145,6 +145,9 @@ class AutoConnectManager private constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
handler.removeCallbacksAndMessages(null)
|
handler.removeCallbacksAndMessages(null)
|
||||||
|
/* the runnable that clears this flag was just removed with the
|
||||||
|
* callbacks: clear it here or every later connect is swallowed */
|
||||||
|
pendingEvaluate.set(false)
|
||||||
service?.unregisterListener(this)
|
service?.unregisterListener(this)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user