From f8dde57133fecc8e1137e282a00e3d424ce0364f Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 18 Feb 2021 13:14:40 -0500 Subject: [PATCH] Add notification settings to debuglogs. --- .../logsubmit/LogSectionNotifications.java | 68 +++++++++++++++++++ .../logsubmit/SubmitDebugLogRepository.java | 1 + .../NotificationPrivacyPreference.java | 6 ++ 3 files changed, 75 insertions(+) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/logsubmit/LogSectionNotifications.java diff --git a/app/src/main/java/org/thoughtcrime/securesms/logsubmit/LogSectionNotifications.java b/app/src/main/java/org/thoughtcrime/securesms/logsubmit/LogSectionNotifications.java new file mode 100644 index 0000000000..95a9f8ac5b --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/logsubmit/LogSectionNotifications.java @@ -0,0 +1,68 @@ +package org.thoughtcrime.securesms.logsubmit; + +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; +import android.os.Build; + +import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; +import androidx.core.app.NotificationManagerCompat; + +import org.thoughtcrime.securesms.util.ServiceUtil; +import org.thoughtcrime.securesms.util.TextSecurePreferences; + +final class LogSectionNotifications implements LogSection { + + @Override + public @NonNull String getTitle() { + return "NOTIFICATIONS"; + } + + @Override + public @NonNull CharSequence getContent(@NonNull Context context) { + StringBuilder output = new StringBuilder(); + + output.append("Message notifications: ").append(TextSecurePreferences.isNotificationsEnabled(context)).append("\n") + .append("Call notifications : ").append(TextSecurePreferences.isCallNotificationsEnabled(context)).append("\n") + .append("New contact alerts : ").append(TextSecurePreferences.isNewContactsNotificationEnabled(context)).append("\n") + .append("In-chat sounds : ").append(TextSecurePreferences.isInThreadNotifications(context)).append("\n") + .append("Repeat alerts : ").append(TextSecurePreferences.getRepeatAlertsCount(context)).append("\n") + .append("Notification display : ").append(TextSecurePreferences.getNotificationPrivacy(context)).append("\n\n"); + + if (Build.VERSION.SDK_INT >= 26) { + NotificationManager manager = ServiceUtil.getNotificationManager(context); + for (NotificationChannel channel : manager.getNotificationChannels()) { + output.append(buildChannelString(channel)); + } + } + + + return output; + } + + @RequiresApi(26) + private static @NonNull String buildChannelString(@NonNull NotificationChannel channel) { + return "-- " + channel.getId() + "\n" + + "importance : " + importanceString(channel.getImportance()) + "\n" + + "hasUserSetImportance: " + (Build.VERSION.SDK_INT >= 29 ? channel.hasUserSetImportance() : "N/A (Requires API 29)") + "\n" + + "hasUserSetSound : " + (Build.VERSION.SDK_INT >= 30 ? channel.hasUserSetSound() : "N/A (Requires API 30)") + "\n" + + "shouldVibrate : " + channel.shouldVibrate() + "\n" + + "shouldShowLights : " + channel.shouldShowLights() + "\n" + + "canBypassDnd : " + channel.canBypassDnd() + "\n" + + "canShowBadge : " + channel.canShowBadge() + "\n" + + "canBubble : " + (Build.VERSION.SDK_INT >= 29 ? channel.canBubble() : "N/A (Requires API 29)") + "\n\n"; + } + + private static @NonNull String importanceString(int value) { + switch (value) { + case NotificationManager.IMPORTANCE_NONE: return "NONE (0)"; + case NotificationManager.IMPORTANCE_MIN: return "MIN (1)"; + case NotificationManager.IMPORTANCE_LOW: return "LOW (2)"; + case NotificationManager.IMPORTANCE_DEFAULT: return "DEFAULT (3)"; + case NotificationManager.IMPORTANCE_HIGH: return "HIGH (4)"; + case NotificationManager.IMPORTANCE_MAX: return "MAX (5)"; + default: return "UNSPECIFIED (" + value + ")"; + } + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/logsubmit/SubmitDebugLogRepository.java b/app/src/main/java/org/thoughtcrime/securesms/logsubmit/SubmitDebugLogRepository.java index a31e2b1cc8..b134b1bd0a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/logsubmit/SubmitDebugLogRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/logsubmit/SubmitDebugLogRepository.java @@ -61,6 +61,7 @@ public class SubmitDebugLogRepository { add(new LogSectionPin()); add(new LogSectionCapabilities()); add(new LogSectionFeatureFlags()); + add(new LogSectionNotifications()); add(new LogSectionKeyPreferences()); add(new LogSectionPermissions()); add(new LogSectionTrace()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/widgets/NotificationPrivacyPreference.java b/app/src/main/java/org/thoughtcrime/securesms/preferences/widgets/NotificationPrivacyPreference.java index 251af9b93b..c5ccbedd40 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/widgets/NotificationPrivacyPreference.java +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/widgets/NotificationPrivacyPreference.java @@ -1,5 +1,7 @@ package org.thoughtcrime.securesms.preferences.widgets; +import androidx.annotation.NonNull; + public class NotificationPrivacyPreference { private final String preference; @@ -16,4 +18,8 @@ public class NotificationPrivacyPreference { return "all".equals(preference); } + @Override + public @NonNull String toString() { + return preference; + } }