Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 215c87f6 authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Fix notification not showing problem

parent 95b0c431
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
    package="foundation.e.drive">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
        tools:ignore="ProtectedPermissions" />
+14 −2
Original line number Diff line number Diff line
@@ -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() {
+2 −4
Original line number Diff line number Diff line
@@ -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");
        }
    }
}