/** * A new presence info notification has been received for me * * @param contact Contact * @param presense Presence info document */ public void presenceInfoNotificationForMe(PidfDocument presence) { if (logger.isActivated()) { logger.debug("Presence info notification for me"); } try { // Get the current presence info for me PresenceInfo currentPresenceInfo = ContactsManager.getInstance().getMyPresenceInfo(); if (currentPresenceInfo == null) { currentPresenceInfo = new PresenceInfo(); } // Update presence status String presenceStatus = PresenceInfo.UNKNOWN; Person person = presence.getPerson(); OverridingWillingness willingness = person.getOverridingWillingness(); if (willingness != null) { if ((willingness.getBasic() != null) && (willingness.getBasic().getValue() != null)) { presenceStatus = willingness.getBasic().getValue(); } } currentPresenceInfo.setPresenceStatus(presenceStatus); // Update the presence info currentPresenceInfo.setTimestamp(person.getTimestamp()); if (person.getNote() != null) { currentPresenceInfo.setFreetext(person.getNote().getValue()); } if (person.getHomePage() != null) { currentPresenceInfo.setFavoriteLink(new FavoriteLink(person.getHomePage())); } // Get photo Etag values String lastEtag = null; String newEtag = null; if (person.getStatusIcon() != null) { newEtag = person.getStatusIcon().getEtag(); } if (currentPresenceInfo.getPhotoIcon() != null) { lastEtag = currentPresenceInfo.getPhotoIcon().getEtag(); } // Test if the photo has been removed if ((lastEtag != null) && (person.getStatusIcon() == null)) { if (logger.isActivated()) { logger.debug("Photo has been removed for me"); } // Update the presence info currentPresenceInfo.setPhotoIcon(null); // Update EAB provider ContactsManager.getInstance().removeMyPhotoIcon(); } else // Test if the photo has been changed if ((person.getStatusIcon() != null) && (newEtag != null)) { if ((lastEtag == null) || (!lastEtag.equals(newEtag))) { if (logger.isActivated()) { logger.debug("Photo has changed for me, download it in background"); } // Download the photo in background downloadPhotoForMe(presence.getPerson().getStatusIcon().getUrl(), newEtag); } } // Update EAB provider ContactsManager.getInstance().setMyInfo(currentPresenceInfo); // Broadcast intent Intent intent = new Intent(PresenceApiIntents.MY_PRESENCE_INFO_CHANGED); getApplicationContext().sendBroadcast(intent); } catch (Exception e) { if (logger.isActivated()) { logger.error("Internal exception", e); } } }