ignore (but log) ANR errors on network actions failing due to a bad/slow network

This commit is contained in:
Egor 2026-02-24 19:47:12 -08:00
parent 7439164b1d
commit f9d3343576
6 changed files with 45 additions and 4 deletions

1
.gitignore vendored
View file

@ -15,5 +15,6 @@ build
local.properties local.properties
.idea .idea
prism-release.keystore prism-release.keystore
.env
.kotlin/sessions/kotlin-compiler-* .kotlin/sessions/kotlin-compiler-*
.VSCodeCounter .VSCodeCounter

View file

@ -17,7 +17,12 @@ debug:
$(GRADLEW) assembleDebug --stacktrace $(GRADLEW) assembleDebug --stacktrace
release-local: release-local:
$(GRADLEW) assembleRelease --stacktrace @set -a && . ./.env && set +a && \
KEYSTORE_TMP=$$(mktemp /tmp/prism-release-XXXXXX.keystore) && \
echo "$$ANDROID_SIGNING_KEYSTORE_B64" | tr -d '[:space:]' | base64 -d > "$$KEYSTORE_TMP" && \
ANDROID_SIGNING_STORE_FILE="$$KEYSTORE_TMP" \
$(GRADLEW) assembleRelease --stacktrace; \
EXIT=$$?; rm -f "$$KEYSTORE_TMP"; exit $$EXIT
lint: lint:
$(GRADLEW) ktlintCheck detekt --stacktrace $(GRADLEW) ktlintCheck detekt --stacktrace

View file

@ -1 +1 @@
0.2.1 0.2.2

View file

@ -87,7 +87,7 @@ class NotificationActionReceiver : BroadcastReceiver() {
Log.d(TAG, "Executing action: $method $fullUrl with data: $jsonBody") Log.d(TAG, "Executing action: $method $fullUrl with data: $jsonBody")
HttpClientFactory.shared.newCall(request).execute().use { response -> HttpClientFactory.action.newCall(request).execute().use { response ->
if (response.isSuccessful) { if (response.isSuccessful) {
Log.d(TAG, "Action executed successfully: ${response.code}") Log.d(TAG, "Action executed successfully: ${response.code}")
} else { } else {

View file

@ -11,6 +11,12 @@ object HttpClientFactory {
.build() .build()
} }
val action: OkHttpClient by lazy {
OkHttpClient.Builder()
.callTimeout(8, TimeUnit.SECONDS)
.build()
}
val longLived: OkHttpClient by lazy { val longLived: OkHttpClient by lazy {
OkHttpClient.Builder() OkHttpClient.Builder()
.readTimeout(0, TimeUnit.MILLISECONDS) .readTimeout(0, TimeUnit.MILLISECONDS)

View file

@ -22,6 +22,7 @@ private const val MANUAL_CHANNEL_PREFIX = "manual_app_"
object ManualAppNotifications { object ManualAppNotifications {
private val notificationIds = mutableMapOf<String, Int>() private val notificationIds = mutableMapOf<String, Int>()
private val summaryNotificationIds = mutableMapOf<String, Int>()
private var nextNotificationId = NOTIFICATION_BASE_ID private var nextNotificationId = NOTIFICATION_BASE_ID
fun showNotification( fun showNotification(
@ -100,6 +101,8 @@ object ManualAppNotifications {
notificationBuilder.build() notificationBuilder.build()
) )
postGroupSummary(context, app.connectorToken, channelId, packageName)
incrementMessageCount(context, app) incrementMessageCount(context, app)
refreshMessageCount(context) refreshMessageCount(context)
@ -182,6 +185,32 @@ object ManualAppNotifications {
nextNotificationId++ nextNotificationId++
} }
private fun getSummaryNotificationId(connectorToken: String): Int = summaryNotificationIds.getOrPut(connectorToken) {
nextNotificationId++
}
private fun postGroupSummary(
context: Context,
connectorToken: String,
channelId: String,
packageName: String?
) {
val summaryId = getSummaryNotificationId(connectorToken)
val summaryBuilder = NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setGroup(connectorToken)
.setGroupSummary(true)
.setAutoCancel(true)
val contentIntent = packageName?.let { createContentIntent(context, it, summaryId) }
if (contentIntent != null) {
summaryBuilder.setContentIntent(contentIntent)
}
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(summaryId, summaryBuilder.build())
}
private fun resolveTargetPackage(app: Database.App): String? { private fun resolveTargetPackage(app: Database.App): String? {
val appPackage = app.packageName.takeIf { it.isNotBlank() } val appPackage = app.packageName.takeIf { it.isNotBlank() }
if (appPackage != null && appPackage != "app.lonecloud.prism" && appPackage != "app.lonecloud.prism.debug") { if (appPackage != null && appPackage != "app.lonecloud.prism" && appPackage != "app.lonecloud.prism.debug") {
@ -240,7 +269,7 @@ object ManualAppNotifications {
} }
} }
val requestCode = (channelID + action.id).hashCode() val requestCode = (channelID + action.id + notificationTag).hashCode()
return PendingIntent.getBroadcast( return PendingIntent.getBroadcast(
context, context,
requestCode, requestCode,