From 28b479c47844f985f35c4631341e6d9df8717985 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 29 Jul 2022 18:11:32 +0200 Subject: [PATCH] Refactoring --- .../main/java/eu/faircode/email/Helper.java | 18 +++++++++++++ app/src/main/java/eu/faircode/email/Log.java | 26 +++---------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index d94aa0bc8d..6be0b0fd91 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -30,6 +30,7 @@ import android.app.Activity; import android.app.ActivityManager; import android.app.ApplicationExitInfo; import android.app.KeyguardManager; +import android.app.NotificationManager; import android.app.UiModeManager; import android.app.usage.UsageEvents; import android.app.usage.UsageStatsManager; @@ -732,6 +733,23 @@ public class Helper { } } + static String getInterruptionFilter(int filter) { + switch (filter) { + case NotificationManager.INTERRUPTION_FILTER_UNKNOWN: + return "Unknown"; + case NotificationManager.INTERRUPTION_FILTER_ALL: + return "All"; + case NotificationManager.INTERRUPTION_FILTER_PRIORITY: + return "Priority"; + case NotificationManager.INTERRUPTION_FILTER_NONE: + return "None"; + case NotificationManager.INTERRUPTION_FILTER_ALARMS: + return "Alarms"; + default: + return Integer.toString(filter); + } + } + static T getSystemService(Context context, Class type) { return ContextCompat.getSystemService(context.getApplicationContext(), type); } diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index 42eb4d4bbb..cc7e8cfa51 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -2674,37 +2674,17 @@ public class Log { paused, (paused ? "!!!" : ""))); } - String name; int filter = nm.getCurrentInterruptionFilter(); - switch (filter) { - case NotificationManager.INTERRUPTION_FILTER_UNKNOWN: - name = "Unknown"; - break; - case NotificationManager.INTERRUPTION_FILTER_ALL: - name = "All"; - break; - case NotificationManager.INTERRUPTION_FILTER_PRIORITY: - name = "Priority"; - break; - case NotificationManager.INTERRUPTION_FILTER_NONE: - name = "None"; - break; - case NotificationManager.INTERRUPTION_FILTER_ALARMS: - name = "Alarms"; - break; - default: - name = Integer.toString(filter); - } - size += write(os, String.format("Interruption filter allow=%s %s\r\n\r\n", - name, (filter == NotificationManager.INTERRUPTION_FILTER_ALL ? "" : "!!!"))); + Helper.getInterruptionFilter(filter), + (filter == NotificationManager.INTERRUPTION_FILTER_ALL ? "" : "!!!"))); for (NotificationChannel channel : nm.getNotificationChannels()) try { JSONObject jchannel = NotificationHelper.channelToJSON(channel); size += write(os, jchannel.toString(2) + "\r\n\r\n"); } catch (JSONException ex) { - size += write(os, ex.toString() + "\r\n"); + size += write(os, ex + "\r\n"); } size += write(os,