From f43db5235cddf502efb7d35da4dbcada236fd83e Mon Sep 17 00:00:00 2001 From: Fiouz Date: Wed, 1 Sep 2010 22:26:36 +0000 Subject: [PATCH] Fixes issue 1711 Owner: fiouzy Don't display message subject in notification bar when keyguard is active (system locked) --- res/values/strings.xml | 3 + res/xml/global_preferences.xml | 5 ++ src/com/fsck/k9/K9.java | 18 +++++ src/com/fsck/k9/activity/setup/Prefs.java | 9 +++ .../k9/controller/MessagingController.java | 67 ++++++++++--------- 5 files changed, 71 insertions(+), 31 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index cb5786195..54a42a73a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -326,6 +326,9 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Spam Send + Privacy mode + Don\'t display message subject in notification bar when system is locked + Set up a new account Enter this account\'s email address: (You may add %d more accounts.) diff --git a/res/xml/global_preferences.xml b/res/xml/global_preferences.xml index 95e8001a7..39c8c3fb5 100644 --- a/res/xml/global_preferences.xml +++ b/res/xml/global_preferences.xml @@ -79,6 +79,11 @@ android:negativeButtonText="@android:string/cancel" /> + + diff --git a/src/com/fsck/k9/K9.java b/src/com/fsck/k9/K9.java index 31235999e..8db076f27 100644 --- a/src/com/fsck/k9/K9.java +++ b/src/com/fsck/k9/K9.java @@ -107,6 +107,7 @@ public class K9 extends Application private static boolean mAnimations = true; private static boolean mConfirmDelete = false; + private static boolean mKeyguardPrivacy = false; private static boolean mMessageListStars = true; private static boolean mMessageListCheckboxes = false; @@ -356,6 +357,8 @@ public class K9 extends Application editor.putBoolean("confirmDelete", mConfirmDelete); + editor.putBoolean("keyguardPrivacy", mKeyguardPrivacy); + fontSizes.save(editor); } @@ -389,6 +392,8 @@ public class K9 extends Application mConfirmDelete = sprefs.getBoolean("confirmDelete", false); + mKeyguardPrivacy = sprefs.getBoolean("keyguardPrivacy", false); + fontSizes.load(sprefs); try @@ -699,6 +704,19 @@ public class K9 extends Application mConfirmDelete = confirm; } + /** + * @return Whether privacy rules should be applied when system is locked + */ + public static boolean keyguardPrivacy() + { + return mKeyguardPrivacy; + } + + public static void setKeyguardPrivacy(final boolean state) + { + mKeyguardPrivacy = state; + } + /** * Check if this system contains a buggy Gallery 3D package. * diff --git a/src/com/fsck/k9/activity/setup/Prefs.java b/src/com/fsck/k9/activity/setup/Prefs.java index 69b54276d..b26a99544 100644 --- a/src/com/fsck/k9/activity/setup/Prefs.java +++ b/src/com/fsck/k9/activity/setup/Prefs.java @@ -58,6 +58,8 @@ public class Prefs extends K9PreferenceActivity private static final String PREFERENCE_CONFIRM_ACTIONS = "confirm_actions"; + private static final String PREFERENCE_PRIVACY_MODE = "privacy_mode"; + private ListPreference mLanguage; private ListPreference mTheme; private ListPreference mDateFormat; @@ -82,6 +84,8 @@ public class Prefs extends K9PreferenceActivity private CheckboxListPreference mConfirmActions; + private CheckBoxPreference mPrivacyMode; + private String initBackgroundOps; @@ -243,6 +247,9 @@ public class Prefs extends K9PreferenceActivity mConfirmActions = (CheckboxListPreference) findPreference(PREFERENCE_CONFIRM_ACTIONS); mConfirmActions.setItems(new CharSequence[] {getString(R.string.global_settings_confirm_action_delete)}); mConfirmActions.setCheckedItems(new boolean[] {K9.confirmDelete()}); + + mPrivacyMode = (CheckBoxPreference) findPreference(PREFERENCE_PRIVACY_MODE); + mPrivacyMode.setChecked(K9.keyguardPrivacy()); } @Override @@ -284,6 +291,8 @@ public class Prefs extends K9PreferenceActivity K9.setConfirmDelete(mConfirmActions.getCheckedItems()[0]); + K9.setKeyguardPrivacy(mPrivacyMode.isChecked()); + Editor editor = preferences.edit(); K9.save(editor); DateFormatter.setDateFormat(editor, mDateFormat.getValue()); diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 44ba79120..fcc101c18 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -22,6 +22,7 @@ import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import android.app.Application; +import android.app.KeyguardManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -4565,52 +4566,56 @@ public class MessagingController implements Runnable { // If we have a message, set the notification to ": " StringBuffer messageNotice = new StringBuffer(); - try + final KeyguardManager keyguardService = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); + if (!K9.keyguardPrivacy() || !keyguardService.inKeyguardRestrictedInputMode()) { - if (message != null && message.getFrom() != null) + try { - Address[] fromAddrs = message.getFrom(); - String from = fromAddrs.length > 0 ? fromAddrs[0].toFriendly().toString() : null; - String subject = message.getSubject(); - if (subject == null) + if (message != null && message.getFrom() != null) { - subject = context.getString(R.string.general_no_subject); - } - - if (from != null) - { - // Show From: address by default - if (!account.isAnIdentity(fromAddrs)) + Address[] fromAddrs = message.getFrom(); + String from = fromAddrs.length > 0 ? fromAddrs[0].toFriendly().toString() : null; + String subject = message.getSubject(); + if (subject == null) { - messageNotice.append(from + ": " + subject); + subject = context.getString(R.string.general_no_subject); } - // show To: if the message was sent from me - else - { - if (!account.isNotifySelfNewMail()) - { - return false; - } - Address[] rcpts = message.getRecipients(Message.RecipientType.TO); - String to = rcpts.length > 0 ? rcpts[0].toFriendly().toString() : null; - if (to != null) + if (from != null) + { + // Show From: address by default + if (!account.isAnIdentity(fromAddrs)) { - messageNotice.append(String.format(context.getString(R.string.message_list_to_fmt), to) +": "+subject); + messageNotice.append(from + ": " + subject); } + // show To: if the message was sent from me else { - messageNotice.append(context.getString(R.string.general_no_sender) + ": "+subject); + if (!account.isNotifySelfNewMail()) + { + return false; + } + + Address[] rcpts = message.getRecipients(Message.RecipientType.TO); + String to = rcpts.length > 0 ? rcpts[0].toFriendly().toString() : null; + if (to != null) + { + messageNotice.append(String.format(context.getString(R.string.message_list_to_fmt), to) +": "+subject); + } + else + { + messageNotice.append(context.getString(R.string.general_no_sender) + ": "+subject); + + } } - } } } - } - catch (MessagingException e) - { - Log.e(K9.LOG_TAG, "Unable to get message information for notification.", e); + catch (MessagingException e) + { + Log.e(K9.LOG_TAG, "Unable to get message information for notification.", e); + } }