Ejemplo n.º 1
0
  /**
   * Capabilities update notification has been received
   *
   * @param contact Contact
   * @param capabilities Capabilities
   */
  public void handleCapabilitiesNotification(String contact, Capabilities capabilities) {
    if (logger.isActivated()) {
      logger.debug(
          "Handle capabilities update notification for "
              + contact
              + " ("
              + capabilities.toString()
              + ")");
    }

    // Extract number from contact
    String number = PhoneUtils.extractNumberFromUri(contact);

    // Broadcast intent containing the new capabilities
    Intent intent = new Intent(CapabilityApiIntents.CONTACT_CAPABILITIES);
    intent.putExtra("contact", number);
    intent.putExtra("capabilities", capabilities);
    getApplicationContext().sendBroadcast(intent);
    // TODO keep only one intent here

    // Send GSMA UI Connector intent
    Intent intentGsma = new Intent(GsmaUiConnector.ACTION_CAPABILITIES_CHANGED);
    intentGsma.putExtra(GsmaUiConnector.EXTRA_CONTACT, number);
    intentGsma.putExtra(GsmaUiConnector.EXTRA_CAPABILITY_CHAT, capabilities.isImSessionSupported());
    intentGsma.putExtra(
        GsmaUiConnector.EXTRA_CAPABILITY_FT, capabilities.isFileTransferSupported());
    intentGsma.putExtra(
        GsmaUiConnector.EXTRA_CAPABILITY_IMAGE_SHARE, capabilities.isImageSharingSupported());
    intentGsma.putExtra(
        GsmaUiConnector.EXTRA_CAPABILITY_VIDEO_SHARE, capabilities.isVideoSharingSupported());
    intentGsma.putExtra(
        GsmaUiConnector.EXTRA_CAPABILITY_GEOLOCATION_PUSH,
        capabilities.isGeolocationPushSupported());
    intentGsma.putExtra(
        GsmaUiConnector.EXTRA_CAPABILITY_CS_VIDEO, capabilities.isCsVideoSupported());
    intentGsma.putExtra(
        GsmaUiConnector.EXTRA_CAPABILITY_PRESENCE_DISCOVERY,
        capabilities.isPresenceDiscoverySupported());
    intentGsma.putExtra(
        GsmaUiConnector.EXTRA_CAPABILITY_SOCIAL_PRESENCE, capabilities.isSocialPresenceSupported());
    intentGsma.putExtra(
        GsmaUiConnector.EXTRA_CAPABILITY_IPVOICECALL, capabilities.isIPVoiceCallSupported());
    intentGsma.putExtra(
        GsmaUiConnector.EXTRA_CAPABILITY_IPVIDEOCALL, capabilities.isIPVideoCallSupported());
    intentGsma.putStringArrayListExtra(
        GsmaUiConnector.EXTRA_CAPABILITY_EXTENSIONS, capabilities.getSupportedExtensions());
    getApplicationContext().sendBroadcast(intentGsma);
  }
Ejemplo n.º 2
0
  /**
   * Receive a capability request (options procedure)
   *
   * @param options Received options message
   */
  public void receiveCapabilityRequest(SipRequest options) {
    String contact = SipUtils.getAssertedIdentity(options);

    if (logger.isActivated()) {
      logger.debug("OPTIONS request received during a call from " + contact);
    }

    try {
      // Create 200 OK response
      String ipAddress =
          getImsModule().getCurrentNetworkInterface().getNetworkAccess().getIpAddress();
      boolean richcall = getImsModule().getCallManager().isRichcallSupportedWith(contact);
      SipResponse resp =
          SipMessageFactory.create200OkOptionsResponse(
              options,
              getImsModule().getSipManager().getSipStack().getLocalContact(),
              CapabilityUtils.getSupportedFeatureTags(richcall),
              CapabilityUtils.buildSdp(ipAddress, richcall));

      // Send 200 OK response
      getImsModule().getSipManager().sendSipResponse(resp);
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Can't send 200 OK for OPTIONS", e);
      }
    }

    // Extract capabilities from the request
    Capabilities capabilities = CapabilityUtils.extractCapabilities(options);
    logger.debug("capabilities = " + capabilities);
    if (capabilities.isImSessionSupported()) {
      // The contact is RCS capable
      ContactsManager.getInstance()
          .setContactCapabilities(
              contact,
              capabilities,
              ContactInfo.RCS_CAPABLE,
              ContactInfo.REGISTRATION_STATUS_ONLINE);
      /** M: Added to fix the issue that RCS-e icon does not display in contact list of People.@{ */
      capabilities.setRcseContact(true);
      /** @} */
    } else {
      // The contact is not RCS
      ContactsManager.getInstance()
          .setContactCapabilities(
              contact, capabilities, ContactInfo.NOT_RCS, ContactInfo.REGISTRATION_STATUS_UNKNOWN);
      /** M: Added to fix the issue that RCS-e icon does not display in contact list of People.@{ */
      capabilities.setRcseContact(false);
      /** @} */
    }
    /** M: Added to fix the issue that RCS-e icon does not display in contact list of People.@{ */
    if (logger.isActivated()) {
      logger.debug(
          "receiveCapabilityRequest setRcseContact contact: "
              + contact
              + " "
              + capabilities.isImSessionSupported());
    }
    /** @} */
    // Notify listener
    getImsModule().getCore().getListener().handleCapabilitiesNotification(contact, capabilities);
  }
Ejemplo n.º 3
0
  /**
   * A new presence info notification has been received for a given contact
   *
   * @param contact Contact
   * @param presense Presence info document
   */
  public void presenceInfoNotificationForContact(String contact, PidfDocument presence) {
    if (logger.isActivated()) {
      logger.debug("Presence info notification for contact " + contact);
    }

    try {
      // Extract number from contact
      String number = PhoneUtils.extractNumberFromUri(contact);

      // Get the current presence info
      ContactInfo currentContactInfo = ContactsManager.getInstance().getContactInfo(contact);
      ContactInfo newContactInfo = currentContactInfo;
      if (currentContactInfo == null) {
        if (logger.isActivated()) {
          logger.warn("Contact " + contact + " not found in EAB: by-pass the notification");
        }
        return;
      }
      PresenceInfo newPresenceInfo = currentContactInfo.getPresenceInfo();
      if (newPresenceInfo == null) {
        newPresenceInfo = new PresenceInfo();
        newContactInfo.setPresenceInfo(newPresenceInfo);
      }

      // Update the current capabilities
      Capabilities capabilities = new Capabilities();
      Vector<Tuple> tuples = presence.getTuplesList();
      for (int i = 0; i < tuples.size(); i++) {
        Tuple tuple = (Tuple) tuples.elementAt(i);

        boolean state = false;
        if (tuple.getStatus().getBasic().getValue().equals("open")) {
          state = true;
        }

        String id = tuple.getService().getId();
        if (id.equalsIgnoreCase(PresenceUtils.FEATURE_RCS2_VIDEO_SHARE)) {
          capabilities.setVideoSharingSupport(state);
        } else if (id.equalsIgnoreCase(PresenceUtils.FEATURE_RCS2_IMAGE_SHARE)) {
          capabilities.setImageSharingSupport(state);
        } else if (id.equalsIgnoreCase(PresenceUtils.FEATURE_RCS2_FT)) {
          capabilities.setFileTransferSupport(state);
        } else if (id.equalsIgnoreCase(PresenceUtils.FEATURE_RCS2_CS_VIDEO)) {
          capabilities.setCsVideoSupport(state);
        } else if (id.equalsIgnoreCase(PresenceUtils.FEATURE_RCS2_CHAT)) {
          capabilities.setImSessionSupport(state);
        }
      }
      newContactInfo.setCapabilities(capabilities);

      // 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();
        }
      }
      newPresenceInfo.setPresenceStatus(presenceStatus);

      // Update the presence info
      newPresenceInfo.setTimestamp(person.getTimestamp());
      if (person.getNote() != null) {
        newPresenceInfo.setFreetext(person.getNote().getValue());
      }
      if (person.getHomePage() != null) {
        newPresenceInfo.setFavoriteLink(new FavoriteLink(person.getHomePage()));
      }

      // Update geoloc info
      if (presence.getGeopriv() != null) {
        Geoloc geoloc =
            new Geoloc(
                presence.getGeopriv().getLatitude(),
                presence.getGeopriv().getLongitude(),
                presence.getGeopriv().getAltitude());
        newPresenceInfo.setGeoloc(geoloc);
      }
      newContactInfo.setPresenceInfo(newPresenceInfo);

      // Update contacts database
      ContactsManager.getInstance().setContactInfo(newContactInfo, currentContactInfo);

      // Get photo Etag values
      String lastEtag = ContactsManager.getInstance().getContactPhotoEtag(contact);
      String newEtag = null;
      if (person.getStatusIcon() != null) {
        newEtag = person.getStatusIcon().getEtag();
      }

      // Test if the photo has been removed
      if ((lastEtag != null) && (person.getStatusIcon() == null)) {
        if (logger.isActivated()) {
          logger.debug("Photo has been removed for " + contact);
        }

        // Update contacts database
        ContactsManager.getInstance().setContactPhotoIcon(contact, null);

        // Broadcast intent
        Intent intent = new Intent(PresenceApiIntents.CONTACT_PHOTO_CHANGED);
        intent.putExtra("contact", number);
        AndroidFactory.getApplicationContext().sendBroadcast(intent);
      } 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 " + contact + ", download it in background");
          }

          // Download the photo in background
          downloadPhotoForContact(contact, presence.getPerson().getStatusIcon().getUrl(), newEtag);
        }
      }

      // Broadcast intent
      Intent intent = new Intent(PresenceApiIntents.CONTACT_INFO_CHANGED);
      intent.putExtra("contact", number);
      getApplicationContext().sendBroadcast(intent);
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Internal exception", e);
      }
    }
  }