From 215c87f6364ff31c42bf7e5bccf84c434c9a88a7 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 4 Jan 2024 12:46:34 +0600 Subject: [PATCH 1/2] Fix notification not showing problem issue: https://gitlab.e.foundation/e/backlog/-/issues/7578 --- app/src/main/AndroidManifest.xml | 1 + .../e/drive/account/AccountUserInfoWorker.java | 16 ++++++++++++++-- .../receivers/AccountRemoveCallbackReceiver.java | 6 ++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ac42e944..e2c9882c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ package="foundation.e.drive"> + diff --git a/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java b/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java index 8d4d0aa6..dc55ee71 100644 --- a/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java +++ b/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java @@ -18,6 +18,7 @@ import static foundation.e.drive.utils.AppConstants.ACCOUNT_USER_ID_KEY; import android.accounts.Account; import android.accounts.AccountManager; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.SharedPreferences; @@ -55,6 +56,8 @@ public class AccountUserInfoWorker extends Worker { private final AccountManager accountManager; private final GetUserInfoRemoteOperation GetUserInfoRemoteOperation = new GetUserInfoRemoteOperation(); + private static final int QUOTA_NOTIFICATION_ID = 0; + private final Context mContext; private Account account; @@ -157,7 +160,11 @@ public class AccountUserInfoWorker extends Worker { } else if (relativeQuota >= 80.0 && needToNotify) { addNotification(manager, context.getString(R.string.notif_quota_80plus_title), context.getString(R.string.notif_quota_80Plus_text), false); } else { - manager.cancelAll(); + try { + manager.cancel(QUOTA_NOTIFICATION_ID); + } catch (Exception e) { + Timber.e(e, "Failed to cancel quota notification"); + } } } @@ -192,6 +199,11 @@ public class AccountUserInfoWorker extends Worker { * - else with different notification. File conflict for example. **/ private void addNotification(NotificationManager manager, String title, String text, boolean isOnGoing) { + NotificationChannel channel = manager.getNotificationChannel(AppConstants.notificationChannelID); + if (channel == null) { + CommonUtils.createNotificationChannel(getApplicationContext()); + } + final NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), AppConstants.notificationChannelID) .setSmallIcon(android.R.drawable.stat_sys_warning) @@ -200,7 +212,7 @@ public class AccountUserInfoWorker extends Worker { .setOngoing(isOnGoing) .setStyle(new NotificationCompat.BigTextStyle().bigText(text)); // Add as notification - manager.notify(0, builder.build()); + manager.notify(QUOTA_NOTIFICATION_ID, builder.build()); } private boolean fetchAliases() { diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java b/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java index 668fb93d..a04a6b18 100644 --- a/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java @@ -150,12 +150,10 @@ public class AccountRemoveCallbackReceiver extends BroadcastReceiver { private void deleteNotificationChannels(Context context) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.cancelAll(); try { - notificationManager.deleteNotificationChannel(AppConstants.notificationChannelID); - notificationManager.deleteNotificationChannel(SyncWorker.NOTIF_CHANNEL_ID); + notificationManager.cancelAll(); } catch (Exception exception) { - Timber.e(exception, "Cannot delete notification Channel"); + Timber.e(exception, "Cannot cancel all notifications"); } } } -- GitLab From 8f76f76c26df8cc8c48eff3bfb5852f469fa0246 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Mon, 8 Jan 2024 14:47:11 +0600 Subject: [PATCH 2/2] update the quota notification id --- .../java/foundation/e/drive/account/AccountUserInfoWorker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java b/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java index dc55ee71..ef376d0c 100644 --- a/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java +++ b/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java @@ -56,7 +56,7 @@ public class AccountUserInfoWorker extends Worker { private final AccountManager accountManager; private final GetUserInfoRemoteOperation GetUserInfoRemoteOperation = new GetUserInfoRemoteOperation(); - private static final int QUOTA_NOTIFICATION_ID = 0; + private static final int QUOTA_NOTIFICATION_ID = 11; private final Context mContext; private Account account; -- GitLab