v1.0.30: fix sync loop root causes + icon redesign
Three root causes found via live logcat on device: 1. concurrent refresh() race: onStartCommand received twice causes two refresh() coroutines to run in parallel, doubling FileObserver and catchupScan registrations. Fixed with Mutex.withLock on refresh(). 2. catchupScan no cooldown: catchup syncs write files but never set syncCooldownUntil, so every written file immediately re-triggers onChangeDetected. Fixed by setting cooldown before enqueue and watching work completion same as onChangeDetected does. 3. CancellationException caught silently: exception handler catch(_: Exception) was catching CancellationException and resetting cooldown to 0L, re-opening the loop. Fixed by rethrowing CancellationException and setting 60s cooldown on other errors. Icon: interlocked rings (blue/red/green/orange) with sync arrow at center, pure black background — matches reference image. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,8 @@ import com.syncflow.data.db.SyncPairDao
|
|||||||
import com.syncflow.domain.model.ScheduleType
|
import com.syncflow.domain.model.ScheduleType
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -35,6 +37,8 @@ class FileWatchService : Service() {
|
|||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||||
private val mainHandler = Handler(Looper.getMainLooper())
|
private val mainHandler = Handler(Looper.getMainLooper())
|
||||||
|
// Prevents concurrent refresh() calls from doubling watchers + catchup scans
|
||||||
|
private val refreshMutex = Mutex()
|
||||||
|
|
||||||
// Multiple FileObserver instances per pair: one per directory (recursive)
|
// Multiple FileObserver instances per pair: one per directory (recursive)
|
||||||
private val fileObservers = mutableMapOf<Long, MutableList<FileObserver>>()
|
private val fileObservers = mutableMapOf<Long, MutableList<FileObserver>>()
|
||||||
@@ -81,7 +85,7 @@ class FileWatchService : Service() {
|
|||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder? = null
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
private suspend fun refresh() {
|
private suspend fun refresh() = refreshMutex.withLock {
|
||||||
clearWatchers()
|
clearWatchers()
|
||||||
val pairs = syncPairDao.getEnabled().filter { it.scheduleType == ScheduleType.ON_CHANGE }
|
val pairs = syncPairDao.getEnabled().filter { it.scheduleType == ScheduleType.ON_CHANGE }
|
||||||
|
|
||||||
@@ -203,12 +207,23 @@ class FileWatchService : Service() {
|
|||||||
if (hasNew || hasModified || hasDeleted) {
|
if (hasNew || hasModified || hasDeleted) {
|
||||||
Timber.d("FileWatchService: catchup detected changes for pair $pairId, scheduling sync")
|
Timber.d("FileWatchService: catchup detected changes for pair $pairId, scheduling sync")
|
||||||
val pair = syncPairDao.getById(pairId) ?: return
|
val pair = syncPairDao.getById(pairId) ?: return
|
||||||
|
// Set cooldown so file writes during this sync don't immediately re-trigger
|
||||||
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 120_000
|
||||||
|
val req = SyncWorker.buildOneTimeRequest(pairId, wifiOnly, chargingOnly)
|
||||||
WorkManager.getInstance(applicationContext)
|
WorkManager.getInstance(applicationContext)
|
||||||
.enqueueUniqueWork(
|
.enqueueUniqueWork("catchup_$pairId", ExistingWorkPolicy.KEEP, req)
|
||||||
"catchup_$pairId",
|
scope.launch {
|
||||||
ExistingWorkPolicy.KEEP,
|
try {
|
||||||
SyncWorker.buildOneTimeRequest(pairId, wifiOnly, chargingOnly),
|
WorkManager.getInstance(applicationContext)
|
||||||
)
|
.getWorkInfoByIdFlow(req.id)
|
||||||
|
.first { it?.state?.isFinished == true }
|
||||||
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 60_000
|
||||||
|
} catch (e: CancellationException) {
|
||||||
|
throw e
|
||||||
|
} catch (_: Exception) {
|
||||||
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 60_000
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,8 +268,10 @@ class FileWatchService : Service() {
|
|||||||
}
|
}
|
||||||
delay(12_000)
|
delay(12_000)
|
||||||
updateNotificationDynamic(null)
|
updateNotificationDynamic(null)
|
||||||
|
} catch (e: CancellationException) {
|
||||||
|
throw e
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
syncCooldownUntil[pairId] = 0L
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 60_000
|
||||||
updateNotificationDynamic(null)
|
updateNotificationDynamic(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:aapt="http://schemas.android.com/aapt"
|
|
||||||
android:width="108dp"
|
android:width="108dp"
|
||||||
android:height="108dp"
|
android:height="108dp"
|
||||||
android:viewportWidth="108"
|
android:viewportWidth="108"
|
||||||
android:viewportHeight="108">
|
android:viewportHeight="108">
|
||||||
|
|
||||||
<!-- Dark charcoal background, matching Avast-style dark icon bg -->
|
<!-- Pure black background -->
|
||||||
<path android:pathData="M0,0 H108 V108 H0 Z"
|
<path android:pathData="M0,0 H108 V108 H0 Z"
|
||||||
android:fillColor="#1F1F2E"/>
|
android:fillColor="#000000"/>
|
||||||
|
|
||||||
<!-- Very subtle inner glow -->
|
|
||||||
<path android:pathData="M0,0 H108 V108 H0 Z"
|
|
||||||
android:fillAlpha="0.25">
|
|
||||||
<aapt:attr name="android:fillColor">
|
|
||||||
<gradient android:type="radial"
|
|
||||||
android:gradientRadius="60"
|
|
||||||
android:centerX="54" android:centerY="50"
|
|
||||||
android:startColor="#3D3A50"
|
|
||||||
android:endColor="#00000000"/>
|
|
||||||
</aapt:attr>
|
|
||||||
</path>
|
|
||||||
|
|
||||||
</vector>
|
</vector>
|
||||||
|
|||||||
@@ -1,67 +1,76 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
|
||||||
SyncFlow icon foreground.
|
|
||||||
Three bold teardrop shapes in Avast-palette colors (teal, red, amber),
|
|
||||||
tips meeting at center (54,54), wide heads pointing outward at 0/120/240 deg.
|
|
||||||
White cloud centred over the intersection point.
|
|
||||||
-->
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:width="108dp"
|
android:width="108dp"
|
||||||
android:height="108dp"
|
android:height="108dp"
|
||||||
android:viewportWidth="108"
|
android:viewportWidth="108"
|
||||||
android:viewportHeight="108">
|
android:viewportHeight="108">
|
||||||
|
|
||||||
<!-- Teal teardrop — head pointing straight up -->
|
<!--
|
||||||
<group android:rotation="0"
|
Four interlocked ring arcs (blue/red/green/orange), each a thick rounded band
|
||||||
android:pivotX="54"
|
arranged in a 2x2 offset so they interweave. A white sync-arrow circle sits
|
||||||
android:pivotY="54">
|
at the center. Designed to match the braided-knot reference icon.
|
||||||
<path
|
-->
|
||||||
android:fillColor="#00C4A7"
|
|
||||||
android:pathData="M 54,57 C 50,57 38,52 34,41 C 30,30 38,20 54,20 C 70,20 78,30 74,41 C 70,52 58,57 54,57 Z"/>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<!-- Red teardrop — head pointing lower-right (120 deg CW from up) -->
|
<!-- Blue ring - top-left -->
|
||||||
<group android:rotation="120"
|
<path
|
||||||
android:pivotX="54"
|
android:strokeColor="#2979FF"
|
||||||
android:pivotY="54">
|
android:strokeWidth="7"
|
||||||
<path
|
android:fillColor="#00000000"
|
||||||
android:fillColor="#F44336"
|
android:strokeLineCap="round"
|
||||||
android:pathData="M 54,57 C 50,57 38,52 34,41 C 30,30 38,20 54,20 C 70,20 78,30 74,41 C 70,52 58,57 54,57 Z"/>
|
android:pathData="M 38,36
|
||||||
</group>
|
A 16,16 0 1,1 54,52
|
||||||
|
A 16,16 0 1,1 38,36 Z"/>
|
||||||
|
|
||||||
<!-- Amber teardrop — head pointing lower-left (240 deg CW from up) -->
|
<!-- Red ring - top-right -->
|
||||||
<group android:rotation="240"
|
<path
|
||||||
android:pivotX="54"
|
android:strokeColor="#F44336"
|
||||||
android:pivotY="54">
|
android:strokeWidth="7"
|
||||||
<path
|
android:fillColor="#00000000"
|
||||||
android:fillColor="#FFC107"
|
android:strokeLineCap="round"
|
||||||
android:pathData="M 54,57 C 50,57 38,52 34,41 C 30,30 38,20 54,20 C 70,20 78,30 74,41 C 70,52 58,57 54,57 Z"/>
|
android:pathData="M 54,36
|
||||||
</group>
|
A 16,16 0 1,1 70,52
|
||||||
|
A 16,16 0 1,1 54,36 Z"/>
|
||||||
|
|
||||||
<!-- White cloud centred at (54,52), sits over the teardrop intersection -->
|
<!-- Green ring - bottom-left -->
|
||||||
|
<path
|
||||||
|
android:strokeColor="#00C853"
|
||||||
|
android:strokeWidth="7"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:pathData="M 38,52
|
||||||
|
A 16,16 0 1,1 54,68
|
||||||
|
A 16,16 0 1,1 38,52 Z"/>
|
||||||
|
|
||||||
|
<!-- Orange ring - bottom-right -->
|
||||||
|
<path
|
||||||
|
android:strokeColor="#FF6D00"
|
||||||
|
android:strokeWidth="7"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:pathData="M 54,52
|
||||||
|
A 16,16 0 1,1 70,68
|
||||||
|
A 16,16 0 1,1 54,52 Z"/>
|
||||||
|
|
||||||
|
<!-- White filled circle at center to create interlock illusion -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#000000"
|
||||||
|
android:pathData="M 46,52 A 8,8 0 1,0 62,52 A 8,8 0 1,0 46,52 Z"/>
|
||||||
|
|
||||||
|
<!-- Sync arrow ring (outer white circle) -->
|
||||||
|
<path
|
||||||
|
android:strokeColor="#FFFFFF"
|
||||||
|
android:strokeWidth="3.5"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M 47,52 A 7,7 0 1,0 61,52 A 7,7 0 1,0 47,52 Z"/>
|
||||||
|
|
||||||
|
<!-- Sync arrow head top -->
|
||||||
<path
|
<path
|
||||||
android:fillColor="#FFFFFF"
|
android:fillColor="#FFFFFF"
|
||||||
android:pathData="
|
android:pathData="M 54,45 L 57,49 L 51,49 Z"/>
|
||||||
M 42,62
|
|
||||||
A 8,8 0 0,1 42,46
|
|
||||||
A 8,8 0 0,1 51,39
|
|
||||||
A 11,11 0 0,1 67,42
|
|
||||||
A 7,7 0 0,1 68,56
|
|
||||||
A 7,7 0 0,1 66,62
|
|
||||||
Z"/>
|
|
||||||
|
|
||||||
<!-- Cloud inner shadow to make it pop from the coloured teardrops -->
|
<!-- Sync arrow head bottom -->
|
||||||
<path
|
<path
|
||||||
android:fillColor="#00000000"
|
android:fillColor="#FFFFFF"
|
||||||
android:strokeColor="#18000000"
|
android:pathData="M 54,59 L 51,55 L 57,55 Z"/>
|
||||||
android:strokeWidth="1.5"
|
|
||||||
android:pathData="
|
|
||||||
M 42,62
|
|
||||||
A 8,8 0 0,1 42,46
|
|
||||||
A 8,8 0 0,1 51,39
|
|
||||||
A 11,11 0 0,1 67,42
|
|
||||||
A 7,7 0 0,1 68,56
|
|
||||||
A 7,7 0 0,1 66,62
|
|
||||||
Z"/>
|
|
||||||
|
|
||||||
</vector>
|
</vector>
|
||||||
|
|||||||
+2
-2
@@ -1,2 +1,2 @@
|
|||||||
VERSION_NAME=1.0.29
|
VERSION_NAME=1.0.30
|
||||||
VERSION_CODE=30
|
VERSION_CODE=31
|
||||||
|
|||||||
Reference in New Issue
Block a user