phoneEvent.addElement("callerIDName").setText(callerIDName);
    protected void handleOnPhone(NewStateEvent event) {        // Do nothing when the phoneManager is being removed/destroyed        if (!phoneManager.isReady()) {            return;        }        //everything after the hyphen should be skipped        String device = getDevice(event.getChannel());        try {            PhoneUser phoneUser = phoneManager.getPhoneUserByDevice(device);            //If there is no jid for this device don't do anything else            if (phoneUser == null) {                Log.debug("Asterisk-IM OnPhoneTask: Could not find device/jid mapping for device " +                        device + " returning");                return;            }            Log.debug("Asterisk-IM OnPhoneTask called for user " + phoneUser);            CallSession callSession = getCallSessionFactory().getCallSession(event.getUniqueId(), phoneUser.getUsername());            XMPPServer server = getInstance();            // Notify the client that they have answered the phone            Message message = new Message();            message.setFrom(phoneManager.getComponentJID());            message.setID(event.getUniqueId());            PhoneEvent phoneEvent =                    new PhoneEvent(callSession.getId(), PhoneEvent.Type.ON_PHONE, device);            // Get the callerID to add to the phone-event. If no callerID info is available            // then just set an empty string and let clients do the proper rendering            String callerID = callSession.getCallerID() == null ? "" : callSession.getCallerID();            phoneEvent.addElement("callerID").setText(callerID);            message.getElement().add(phoneEvent);            //Acquire the xmpp sessions for the user            SessionManager sessionManager = server.getSessionManager();            Collection<ClientSession> sessions = sessionManager.getSessions(phoneUser.getUsername());            // We don't care about people without a session            if (sessions.size() == 0) {                // Release call session since the user is not logged into the server                getCallSessionFactory().destroyPhoneSession(event.getUniqueId());                return;            }            Log.debug("Asterisk-IM OnPhoneTask: setting presence to away for " + phoneUser);            // If we haven't determined their original presence, set it            // If there is already and original presence, it means the user is            // receiving an additional phone call. In this case we should not save the presence            // because the current precense would also be "on phone"            synchronized (phoneUser.getUsername().intern()) {                if (UserPresenceUtil.getPresences(phoneUser.getUsername()) == null ||                        UserPresenceUtil.getPresences(phoneUser.getUsername()).isEmpty()) {                    // Iterate through all of the sessions sending out new presences for each                    Presence presence = new Presence();                    presence.setShow(Presence.Show.away);                    presence.setStatus("On the phone");                    PhoneStatus phoneStatus = new PhoneStatus(PhoneStatus.Status.ON_PHONE);                    presence.getElement().add(phoneStatus);                    Collection<Presence> prevPresences = new ArrayList<Presence>();                    for (ClientSession session : sessions) {                        message.setTo(session.getAddress());                        phoneManager.sendPacket(message);                        Presence prevPresence = session.getPresence();                        // Only add the presence if it does not contain a phone element                        if (prevPresence.getElement().element(PhoneStatus.Status.ON_PHONE.name()) == null) {                            prevPresences.add(prevPresence);                            JID fullJID = session.getAddress();                            presence.setFrom(fullJID);                            server.getPresenceRouter().route(presence);                        }                    }                    UserPresenceUtil.setPresences(phoneUser.getUsername(), prevPresences);                }            }        }        catch (Throwable e) {            Log.error(e.getMessage(), e);        }    }