From 32fc8e41dde99760eb769a0d0c17f6c485a0b5cf Mon Sep 17 00:00:00 2001 From: Scott Kennedy Date: Tue, 30 Jul 2013 11:50:42 -0700 Subject: Add more logs for NotificationUtils Bug: 10039955 Change-Id: I1dd719b48f8fd2569a83a5f6906f539dfcc2fcb1 --- src/com/android/mail/utils/LogUtils.java | 16 ++++++++++---- src/com/android/mail/utils/NotificationUtils.java | 27 ++++++++++++++++------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/com/android/mail/utils/LogUtils.java b/src/com/android/mail/utils/LogUtils.java index 3bc82e52a..32034222f 100644 --- a/src/com/android/mail/utils/LogUtils.java +++ b/src/com/android/mail/utils/LogUtils.java @@ -18,6 +18,7 @@ package com.android.mail.utils; import android.net.Uri; import android.text.TextUtils; import android.util.Log; + import com.google.common.annotations.VisibleForTesting; import java.util.List; @@ -146,14 +147,21 @@ public class LogUtils { return ""; } - if (isDebugLoggingEnabled(TAG)) { - return accountName; + return ACCOUNT_PREFIX + sanitizeName(TAG, accountName); + } + + public static String sanitizeName(final String tag, final String name) { + if (TextUtils.isEmpty(name)) { + return ""; + } + + if (isDebugLoggingEnabled(tag)) { + return name; } - return ACCOUNT_PREFIX + String.valueOf(accountName.hashCode()); + return String.valueOf(name.hashCode()); } - /** * Checks to see whether or not a log for the specified tag is loggable at the specified level. */ diff --git a/src/com/android/mail/utils/NotificationUtils.java b/src/com/android/mail/utils/NotificationUtils.java index 5ea19f9b9..28b899f63 100644 --- a/src/com/android/mail/utils/NotificationUtils.java +++ b/src/com/android/mail/utils/NotificationUtils.java @@ -449,9 +449,12 @@ public class NotificationUtils { final NotificationMap notificationMap = getNotificationMap(context); if (LogUtils.isLoggable(LOG_TAG, LogUtils.VERBOSE)) { - LogUtils.v(LOG_TAG, "Validating Notification: %s mapSize: %d " + LogUtils.i(LOG_TAG, "Validating Notification: %s mapSize: %d " + "folder: %s getAttention: %b", createNotificationString(notificationMap), notificationMap.size(), folder.name, getAttention); + } else { + LogUtils.i(LOG_TAG, "Validating Notification, mapSize: %d " + + "getAttention: %b", notificationMap.size(), getAttention); } // The number of unread messages for this account and label. final Integer unread = notificationMap.getUnread(key); @@ -474,6 +477,8 @@ public class NotificationUtils { UIProvider.CONVERSATION_PROJECTION, null, null, null); if (cursor == null) { // This folder doesn't exist. + LogUtils.i(LOG_TAG, + "The cursor is null, so the specified folder probably does not exist"); clearFolderNotification(context, account, folder, false); return; } @@ -482,7 +487,7 @@ public class NotificationUtils { // Make sure the unseen count matches the number of items in the cursor. But, we don't // want to overwrite a 0 unseen count that was specified in the intent if (unseenCount != 0 && unseenCount != cursorUnseenCount) { - LogUtils.d(LOG_TAG, + LogUtils.i(LOG_TAG, "Unseen count doesn't match cursor count. unseen: %d cursor count: %d", unseenCount, cursorUnseenCount); unseenCount = cursorUnseenCount; @@ -497,8 +502,9 @@ public class NotificationUtils { final int notificationId = getNotificationId(account.name, folder); if (unseenCount == 0) { - LogUtils.d(LOG_TAG, "validateNotifications - cancelling %s / %s", account.name, - folder.persistentId); + LogUtils.i(LOG_TAG, "validateNotifications - cancelling account %s / folder %s", + LogUtils.sanitizeName(LOG_TAG, account.name), + LogUtils.sanitizeName(LOG_TAG, folder.persistentId)); nm.cancel(notificationId); return; } @@ -555,6 +561,7 @@ public class NotificationUtils { } if (!folderPreferences.areNotificationsEnabled()) { + LogUtils.i(LOG_TAG, "Notifications are disabled for this folder; not notifying"); // Don't notify return; } @@ -597,7 +604,8 @@ public class NotificationUtils { notification.setOnlyAlertOnce(true); } - LogUtils.d(LOG_TAG, "Account: %s vibrate: %s", account.name, + LogUtils.i(LOG_TAG, "Account: %s vibrate: %s", + LogUtils.sanitizeName(LOG_TAG, account.name), Boolean.toString(folderPreferences.isNotificationVibrateEnabled())); int defaults = 0; @@ -616,11 +624,12 @@ public class NotificationUtils { notification.setSound(TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri)); - LogUtils.d(LOG_TAG, "New email in %s vibrateWhen: %s, playing notification: %s", - account.name, vibrate, ringtoneUri); + LogUtils.i(LOG_TAG, "New email in %s vibrateWhen: %s, playing notification: %s", + LogUtils.sanitizeName(LOG_TAG, account.name), vibrate, ringtoneUri); } } + // TODO(skennedy) Why do we do any of the above if we're just going to bail here? if (eventInfoConfigured) { defaults |= Notification.DEFAULT_LIGHTS; notification.setDefaults(defaults); @@ -632,6 +641,8 @@ public class NotificationUtils { } nm.notify(notificationId, notification.build()); + } else { + LogUtils.i(LOG_TAG, "event info not configured - not notifying"); } } finally { if (cursor != null) { @@ -708,7 +719,7 @@ public class NotificationUtils { final Folder folder, final long when) { final Resources res = context.getResources(); - LogUtils.w(LOG_TAG, "Showing notification with unreadCount of %d and unseenCount of %d", + LogUtils.i(LOG_TAG, "Showing notification with unreadCount of %d and unseenCount of %d", unreadCount, unseenCount); String notificationTicker = null; -- cgit v1.2.3