Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

perf(android): no binder call per countdown tick for the notification channel

Duarte Santos263719e889cd
diff --git a/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlert.java b/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlert.java
index bc394344b..6d91100f6 100644
--- a/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlert.java
+++ b/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlert.java
@@ -500,9 +500,13 @@ public final class RestAlert {
return (sec / 60) + ":" + (sec % 60 < 10 ? "0" : "") + (sec % 60);
}
+ // The countdown is posted again every second; asking the system for the channel each time was
+ // a binder call per tick. Once it is known to exist (the app never deletes it), it is not asked.
+ private static volatile boolean countdownChannelReady = false;
+
private static void ensureCountdownChannel(Context ctx, NotificationManager nm) {
- if (Build.VERSION.SDK_INT < 26) return;
- if (nm.getNotificationChannel(COUNTDOWN_CHANNEL_ID) != null) return;
+ if (Build.VERSION.SDK_INT < 26 || countdownChannelReady) return;
+ if (nm.getNotificationChannel(COUNTDOWN_CHANNEL_ID) != null) { countdownChannelReady = true; return; }
NotificationChannel channel = new NotificationChannel(
COUNTDOWN_CHANNEL_ID,
ctx.getString(R.string.rest_countdown_channel_name),
@@ -512,6 +516,7 @@ public final class RestAlert {
channel.setSound(null, null);
channel.enableVibration(false);
nm.createNotificationChannel(channel);
+ countdownChannelReady = true;
}
/**