Skip to content

Commit c7c8d90

Browse files
committed
Consider network activity for app running detection
Bandwidth-sharing apps often run as background services without foreground notifications. Now also marks apps as running if they have >1KB network activity in the last 24h.
1 parent 8736f5a commit c7c8d90

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

app/src/main/java/com/cashpilot/android/service/AppDetector.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@ class AppDetector(private val context: Context) {
4848
val lastActive = getLastActiveTime(app.packageName)
4949
val (tx, rx) = getNetworkStats(app.packageName)
5050

51-
// App is "running" if it has an active foreground notification
52-
// OR was active within the last 15 minutes
51+
// App is "running" if:
52+
// 1. It has an active foreground notification, OR
53+
// 2. It was in foreground within the last 15 minutes, OR
54+
// 3. It has network activity in the last 24h (bandwidth apps run as background services)
5355
val recentlyActive = lastActive?.let {
5456
(System.currentTimeMillis() - it) < 15 * 60 * 1000
5557
} ?: false
58+
val hasNetworkActivity = (tx + rx) > 1024 // >1KB to filter noise
5659

5760
return AppStatus(
5861
slug = app.slug,
59-
running = notificationActive || recentlyActive,
62+
running = notificationActive || recentlyActive || hasNetworkActivity,
6063
notificationActive = notificationActive,
6164
netTx24h = tx,
6265
netRx24h = rx,

0 commit comments

Comments
 (0)