From 0f8966ae90fb84e38213fe3c1914ef8bbc74b215 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Thu, 17 Nov 2011 08:51:06 +0000 Subject: [PATCH] Fixes a NPE and tests. --- .../notification/NotificationManager.java | 143 ++++++++---------- .../notification/NotificationService.java | 61 ++++++++ 2 files changed, 126 insertions(+), 78 deletions(-) diff --git a/src/net/java/sip/communicator/impl/notification/NotificationManager.java b/src/net/java/sip/communicator/impl/notification/NotificationManager.java index 18a3c32b1..b2f490e6b 100644 --- a/src/net/java/sip/communicator/impl/notification/NotificationManager.java +++ b/src/net/java/sip/communicator/impl/notification/NotificationManager.java @@ -48,30 +48,6 @@ public class NotificationManager private static final Logger logger = Logger.getLogger(NotificationManager.class); - public static final String INCOMING_MESSAGE = "IncomingMessage"; - - public static final String INCOMING_CALL = "IncomingCall"; - - public static final String OUTGOING_CALL = "OutgoingCall"; - - public static final String BUSY_CALL = "BusyCall"; - - public static final String DIALING = "Dialing"; - - public static final String HANG_UP = "HangUp"; - - public static final String PROACTIVE_NOTIFICATION = "ProactiveNotification"; - - public static final String SECURITY_MESSAGE = "SecurityMessage"; - - public static final String CALL_SECURITY_ON = "CallSecurityOn"; - - public static final String CALL_SECURITY_ERROR = "CallSecurityError"; - - public static final String INCOMING_FILE = "IncomingFile"; - - public static final String CALL_SAVED = "CallSaved"; - /** * The image used, when a contact has no photo specified. */ @@ -125,20 +101,20 @@ private void registerDefaultNotifications() // Register incoming message notifications. notificationService.registerDefaultNotificationForEvent( - INCOMING_MESSAGE, + NotificationService.INCOMING_MESSAGE, NotificationService.ACTION_POPUP_MESSAGE, null, null); notificationService.registerDefaultNotificationForEvent( - INCOMING_MESSAGE, + NotificationService.INCOMING_MESSAGE, NotificationService.ACTION_SOUND, SoundProperties.INCOMING_MESSAGE, null); // Register incoming call notifications. notificationService.registerDefaultNotificationForEvent( - INCOMING_CALL, + NotificationService.INCOMING_CALL, NotificationService.ACTION_POPUP_MESSAGE, null, null); @@ -149,7 +125,7 @@ private void registerDefaultNotifications() 2000); notificationService.registerDefaultNotificationForEvent( - INCOMING_CALL, + NotificationService.INCOMING_CALL, NotificationService.ACTION_SOUND, inCallSoundHandler); @@ -160,7 +136,7 @@ private void registerDefaultNotifications() 3000); notificationService.registerDefaultNotificationForEvent( - OUTGOING_CALL, + NotificationService.OUTGOING_CALL, NotificationService.ACTION_SOUND, outCallSoundHandler); @@ -170,7 +146,7 @@ private void registerDefaultNotifications() .createSoundNotificationHandler(SoundProperties.BUSY, 1); notificationService.registerDefaultNotificationForEvent( - BUSY_CALL, + NotificationService.BUSY_CALL, NotificationService.ACTION_SOUND, busyCallSoundHandler); @@ -180,7 +156,7 @@ private void registerDefaultNotifications() .createSoundNotificationHandler(SoundProperties.DIALING, 0); notificationService.registerDefaultNotificationForEvent( - DIALING, + NotificationService.DIALING, NotificationService.ACTION_SOUND, dialSoundHandler); @@ -190,54 +166,54 @@ private void registerDefaultNotifications() .createSoundNotificationHandler(SoundProperties.HANG_UP, -1); notificationService.registerDefaultNotificationForEvent( - HANG_UP, + NotificationService.HANG_UP, NotificationService.ACTION_SOUND, hangupSoundHandler); // Register proactive notifications. notificationService.registerDefaultNotificationForEvent( - PROACTIVE_NOTIFICATION, + NotificationService.PROACTIVE_NOTIFICATION, NotificationService.ACTION_POPUP_MESSAGE, null, null); // Register warning message notifications. notificationService.registerDefaultNotificationForEvent( - SECURITY_MESSAGE, + NotificationService.SECURITY_MESSAGE, NotificationService.ACTION_POPUP_MESSAGE, null, null); // Register sound notification for security state on during a call. notificationService.registerDefaultNotificationForEvent( - CALL_SECURITY_ON, + NotificationService.CALL_SECURITY_ON, NotificationService.ACTION_SOUND, SoundProperties.CALL_SECURITY_ON, null); // Register sound notification for security state off during a call. notificationService.registerDefaultNotificationForEvent( - CALL_SECURITY_ERROR, + NotificationService.CALL_SECURITY_ERROR, NotificationService.ACTION_SOUND, SoundProperties.CALL_SECURITY_ERROR, null); // Register sound notification for incoming files. notificationService.registerDefaultNotificationForEvent( - INCOMING_FILE, + NotificationService.INCOMING_FILE, NotificationService.ACTION_POPUP_MESSAGE, null, null); notificationService.registerDefaultNotificationForEvent( - INCOMING_FILE, + NotificationService.INCOMING_FILE, NotificationService.ACTION_SOUND, SoundProperties.INCOMING_FILE, null); // Register notification for saved calls. notificationService.registerDefaultNotificationForEvent( - CALL_SAVED, + NotificationService.CALL_SAVED, NotificationService.ACTION_POPUP_MESSAGE, null, null); @@ -562,6 +538,7 @@ public static void fireChatNotification(Object chatContact, return; NotificationActionHandler popupActionHandler = null; + UIService uiService = NotificationActivator.getUIService(); Chat chatPanel = null; byte[] contactIcon = null; @@ -569,7 +546,8 @@ public static void fireChatNotification(Object chatContact, { Contact contact = (Contact) chatContact; - chatPanel = NotificationActivator.getUIService().getChat(contact); + if(uiService != null) + chatPanel = uiService.getChat(contact); contactIcon = contact.getImage(); if(contactIcon == null) @@ -586,12 +564,14 @@ else if (chatContact instanceof ChatRoom) if (chatRoom.isSystem()) return; - chatPanel = NotificationActivator.getUIService().getChat(chatRoom); + if(uiService != null) + chatPanel = uiService.getChat(chatRoom); } if (chatPanel != null) { - if (eventType.equals(INCOMING_MESSAGE) && chatPanel.isChatFocused()) + if (eventType.equals(NotificationService.INCOMING_MESSAGE) + && chatPanel.isChatFocused()) { popupActionHandler = notificationService .getEventNotificationActionHandler(eventType, @@ -695,10 +675,10 @@ public static BufferedImage getImage(ImageID imageID) */ private static void stopAllTelephonySounds() { - NotificationManager.stopSound(NotificationManager.DIALING); - NotificationManager.stopSound(NotificationManager.BUSY_CALL); - NotificationManager.stopSound(NotificationManager.INCOMING_CALL); - NotificationManager.stopSound(NotificationManager.OUTGOING_CALL); + NotificationManager.stopSound(NotificationService.DIALING); + NotificationManager.stopSound(NotificationService.BUSY_CALL); + NotificationManager.stopSound(NotificationService.INCOMING_CALL); + NotificationManager.stopSound(NotificationService.OUTGOING_CALL); } /** @@ -781,7 +761,7 @@ public void messageReceived(MessageReceivedEvent evt) fireChatNotification( evt.getSourceContact(), - NotificationManager.INCOMING_MESSAGE, + NotificationService.INCOMING_MESSAGE, title, evt.getSourceMessage().getContent()); @@ -822,7 +802,7 @@ public void fileTransferRequestReceived(FileTransferRequestEvent event) NotificationManager .fireChatNotification( sourceContact, - NotificationManager.INCOMING_FILE, + NotificationService.INCOMING_FILE, title, request.getFileName()); } @@ -867,16 +847,20 @@ public void typingNotificationReceived(TypingNotificationEvent event) // check whether the current chat window shows the // chat we received a typing info for and in such case don't show // notifications - Chat chat = NotificationActivator.getUIService().getCurrentChat(); - if(chat != null) - { - MetaContact metaContact = - NotificationActivator.getUIService().getChatContact(chat); + UIService uiService = NotificationActivator.getUIService(); - if(metaContact != null && metaContact.containsContact(contact) - && chat.isChatFocused()) + if(uiService != null) + { + Chat chat = uiService.getCurrentChat(); + if(chat != null) { - return; + MetaContact metaContact = uiService.getChatContact(chat); + + if(metaContact != null && metaContact.containsContact(contact) + && chat.isChatFocused()) + { + return; + } } } @@ -911,7 +895,7 @@ public void typingNotificationReceived(TypingNotificationEvent event) NotificationManager.fireChatNotification( contact, - NotificationManager.PROACTIVE_NOTIFICATION, + NotificationService.PROACTIVE_NOTIFICATION, contact.getDisplayName(), NotificationActivator.getResources() .getI18NString("service.gui.PROACTIVE_NOTIFICATION")); @@ -929,7 +913,7 @@ public void incomingCallReceived(CallEvent event) .getCallPeers().next().getDisplayName(); NotificationManager.fireNotification( - NotificationManager.INCOMING_CALL, + NotificationService.INCOMING_CALL, "", NotificationActivator.getResources() .getI18NString("service.gui.INCOMING_CALL", @@ -975,7 +959,7 @@ public void callEnded(CallEvent event) stopAllTelephonySounds(); // Play the hangup sound. - NotificationManager.fireNotification(NotificationManager.HANG_UP); + NotificationManager.fireNotification(NotificationService.HANG_UP); } /** @@ -1027,11 +1011,11 @@ public void peerStateChanged(CallPeerChangeEvent evt) || newState == CallPeerState.CONNECTING) { NotificationManager - .fireNotification(NotificationManager.DIALING); + .fireNotification(NotificationService.DIALING); } else { - NotificationManager.stopSound(NotificationManager.DIALING); + NotificationManager.stopSound(NotificationService.DIALING); } if (newState == CallPeerState.ALERTING_REMOTE_SIDE @@ -1041,17 +1025,17 @@ public void peerStateChanged(CallPeerChangeEvent evt) && oldState != CallPeerState.CONNECTING_WITH_EARLY_MEDIA) { NotificationManager - .fireNotification(NotificationManager.OUTGOING_CALL); + .fireNotification(NotificationService.OUTGOING_CALL); } else if (newState == CallPeerState.BUSY) { - NotificationManager.stopSound(NotificationManager.OUTGOING_CALL); + NotificationManager.stopSound(NotificationService.OUTGOING_CALL); // We start the busy sound only if we're in a simple call. if (!isConference(sourcePeer.getCall())) { NotificationManager.fireNotification( - NotificationManager.BUSY_CALL); + NotificationService.BUSY_CALL); } } else if (newState == CallPeerState.CONNECTING_INCOMING_CALL || @@ -1060,9 +1044,9 @@ else if (newState == CallPeerState.CONNECTING_INCOMING_CALL || if (!CallPeerState.isOnHold(oldState)) { NotificationManager - .stopSound(NotificationManager.OUTGOING_CALL); + .stopSound(NotificationService.OUTGOING_CALL); NotificationManager - .stopSound(NotificationManager.INCOMING_CALL); + .stopSound(NotificationService.INCOMING_CALL); } } else if (newState == CallPeerState.CONNECTING_WITH_EARLY_MEDIA) @@ -1070,16 +1054,16 @@ else if (newState == CallPeerState.CONNECTING_WITH_EARLY_MEDIA) //this means a call with early media. make sure that we are not //playing local notifications any more. NotificationManager - .stopSound(NotificationManager.OUTGOING_CALL); + .stopSound(NotificationService.OUTGOING_CALL); } else if (newState == CallPeerState.CONNECTED) { if (!CallPeerState.isOnHold(oldState)) { NotificationManager - .stopSound(NotificationManager.OUTGOING_CALL); + .stopSound(NotificationService.OUTGOING_CALL); NotificationManager - .stopSound(NotificationManager.INCOMING_CALL); + .stopSound(NotificationService.INCOMING_CALL); } } else if (newState == CallPeerState.DISCONNECTED @@ -1087,7 +1071,7 @@ else if (newState == CallPeerState.DISCONNECTED { stopAllTelephonySounds(); - NotificationManager.fireNotification(NotificationManager.HANG_UP); + NotificationManager.fireNotification(NotificationService.HANG_UP); } } @@ -1136,7 +1120,7 @@ public void securityOn(CallPeerSecurityOnEvent evt) || !evt.getSecurityController().requiresSecureSignalingTransport()) { NotificationManager.fireNotification( - NotificationManager.CALL_SECURITY_ON); + NotificationService.CALL_SECURITY_ON); } } @@ -1179,12 +1163,12 @@ public void securityMessageRecieved(CallPeerSecurityMessageEvent event) messageTitle = NotificationActivator.getResources() .getI18NString("service.gui.SECURITY_ERROR"); NotificationManager.fireNotification( - NotificationManager.CALL_SECURITY_ERROR); + NotificationService.CALL_SECURITY_ERROR); } } NotificationManager.fireNotification( - NotificationManager.SECURITY_MESSAGE, + NotificationService.SECURITY_MESSAGE, messageTitle, event.getI18nMessage()); } @@ -1220,7 +1204,10 @@ public void messageReceived(ChatRoomMessageReceivedEvent evt) { String nickname = sourceChatRoom.getUserNickname(); - int atIx = nickname.indexOf("@"); + int atIx = -1; + + if(nickname != null) + atIx = nickname.indexOf("@"); fireChatNotification = (nickname == null) @@ -1239,7 +1226,7 @@ public void messageReceived(ChatRoomMessageReceivedEvent evt) NotificationManager.fireChatNotification( sourceChatRoom, - NotificationManager.INCOMING_MESSAGE, + NotificationService.INCOMING_MESSAGE, title, messageContent); } @@ -1353,7 +1340,7 @@ public void messageReceived(AdHocChatRoomMessageReceivedEvent evt) NotificationManager.fireChatNotification( sourceChatRoom, - NotificationManager.INCOMING_MESSAGE, + NotificationService.INCOMING_MESSAGE, title, messageContent); } @@ -1407,7 +1394,7 @@ public void conferenceMemberAdded(CallPeerConferenceEvent conferenceEvent) if (securityEvent instanceof CallPeerSecurityOnEvent) { NotificationManager.fireNotification( - NotificationManager.CALL_SECURITY_ON); + NotificationService.CALL_SECURITY_ON); } } } @@ -1431,7 +1418,7 @@ public void conferenceMemberRemoved(CallPeerConferenceEvent conferenceEvent) public void recorderStopped(Recorder recorder) { NotificationManager.fireNotification( - NotificationManager.CALL_SAVED, + NotificationService.CALL_SAVED, NotificationActivator.getResources().getI18NString( "plugin.callrecordingconfig.CALL_SAVED"), NotificationActivator.getResources().getI18NString( diff --git a/src/net/java/sip/communicator/service/notification/NotificationService.java b/src/net/java/sip/communicator/service/notification/NotificationService.java index eae46c713..cb0e2a5aa 100644 --- a/src/net/java/sip/communicator/service/notification/NotificationService.java +++ b/src/net/java/sip/communicator/service/notification/NotificationService.java @@ -46,6 +46,67 @@ public interface NotificationService * when a notification is fired. */ public static final String ACTION_COMMAND = "CommandAction"; + + /** + * Default event type for receiving messages. + */ + public static final String INCOMING_MESSAGE = "IncomingMessage"; + + /** + * Default event type for receiving calls (incoming calls). + */ + public static final String INCOMING_CALL = "IncomingCall"; + + /** + * Default event type for outgoing calls. + */ + public static final String OUTGOING_CALL = "OutgoingCall"; + + /** + * Default event type for a busy call. + */ + public static final String BUSY_CALL = "BusyCall"; + + /** + * Default event type for dialing. + */ + public static final String DIALING = "Dialing"; + + /** + * Default event type for hanging up calls. + */ + public static final String HANG_UP = "HangUp"; + + /** + * Default event type for + * proactive notifications (typing notifications when chatting). + */ + public static final String PROACTIVE_NOTIFICATION = "ProactiveNotification"; + + /** + * Default event type when a secure message received. + */ + public static final String SECURITY_MESSAGE = "SecurityMessage"; + + /** + * Default event type for activated security on a call. + */ + public static final String CALL_SECURITY_ON = "CallSecurityOn"; + + /** + * Default event type for security error on a call. + */ + public static final String CALL_SECURITY_ERROR = "CallSecurityError"; + + /** + * Default event type for incoming file transfers. + */ + public static final String INCOMING_FILE = "IncomingFile"; + + /** + * Default event type for call been saved using a recorder. + */ + public static final String CALL_SAVED = "CallSaved"; /** * Creates a SoundNotificationHandler, by specifying the