From 3bea6d470bdb11ea0756ace2ac62891e6fe00976 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 3 Jun 2024 13:37:40 +0200 Subject: [PATCH] refactor: make sure updateAppWidget is not called twice at the same time Sentry has weird NullPointException & ArrayIndexOutOfBoundsException. Since a lot of stuffs are done in the BroadcastReceiver.onReceived() callback and it could be called twice quite fast, let's make sure it is a least thread safe. --- .../main/java/foundation/e/drive/widgets/EDriveWidget.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java index 4f2cc638..d5891220 100644 --- a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java +++ b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java @@ -103,7 +103,7 @@ public class EDriveWidget extends AppWidgetProvider { return convertedData; } - public void updateAppWidget(@NonNull final Context context) { + public synchronized void updateAppWidget(@NonNull final Context context) { final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); final ComponentName provider = new ComponentName(context, getClass()); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(provider); @@ -113,7 +113,7 @@ public class EDriveWidget extends AppWidgetProvider { } } - public void updateAppWidget(@NonNull final Context context, @NonNull final AppWidgetManager appWidgetManager, + private void updateAppWidget(@NonNull final Context context, @NonNull final AppWidgetManager appWidgetManager, final int appWidgetId) { final AccountManager accountManager = AccountManager.get(context); -- GitLab