/**
   * Receive a new geoloc sharing invitation
   *
   * @param session Geoloc sharing session
   */
  public void receiveGeolocSharingInvitation(GeolocTransferSession session) {
    if (logger.isActivated()) {
      logger.info("Receive geoloc sharing invitation from " + session.getRemoteContact());
    }

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

    // Update rich call history
    RichCall.getInstance()
        .addCall(
            number,
            session.getSessionID(),
            RichCallData.EVENT_INCOMING,
            session.getContent(),
            RichCallData.STATUS_STARTED);

    // Add session in the list
    GeolocSharingSession sessionApi = new GeolocSharingSession(session);
    addGeolocSharingSession(sessionApi);

    // Broadcast intent related to the received invitation
    Intent intent = new Intent(RichCallApiIntents.GEOLOC_SHARING_INVITATION);
    intent.putExtra("contact", number);
    intent.putExtra("contactDisplayname", session.getRemoteDisplayName());
    intent.putExtra("sessionId", session.getSessionID());
    AndroidFactory.getApplicationContext().sendBroadcast(intent);
  }
  /**
   * Receive a new video sharing invitation
   *
   * @param session Video sharing session
   */
  public void receiveVideoSharingInvitation(VideoStreamingSession session) {
    if (logger.isActivated()) {
      logger.info("Receive video sharing invitation from " + session.getRemoteContact());
    }

    // Extract number from contact
    String number = PhoneUtils.extractNumberFromUri(session.getRemoteContact());
    VideoContent content = (VideoContent) session.getContent();

    // Update rich call history
    RichCall.getInstance()
        .addCall(
            number,
            session.getSessionID(),
            RichCallData.EVENT_INCOMING,
            content,
            RichCallData.STATUS_STARTED);

    // Add session in the list
    VideoSharingSession sessionApi = new VideoSharingSession(session);
    addVideoSharingSession(sessionApi);

    // Broadcast intent related to the received invitation
    Intent intent = new Intent(RichCallApiIntents.VIDEO_SHARING_INVITATION);
    intent.putExtra("contact", number);
    intent.putExtra("contactDisplayname", session.getRemoteDisplayName());
    intent.putExtra("sessionId", session.getSessionID());
    intent.putExtra("videotype", content.getEncoding());
    intent.putExtra("videowidth", content.getWidth());
    intent.putExtra("videoheight", content.getHeight());
    AndroidFactory.getApplicationContext().sendBroadcast(intent);
  }
  /**
   * Initiate a geoloc sharing session
   *
   * @param contact Contact
   * @param geoloc Geoloc info
   * @return Geoloc sharing session
   * @throws ServerApiException
   */
  public IGeolocSharingSession initiateGeolocSharing(String contact, GeolocPush geoloc)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Initiate a geoloc sharing session with " + contact);
    }

    // Check permission
    ServerApiUtils.testPermission();

    // Test IMS connection
    ServerApiUtils.testIms();

    try {
      // Create a geoloc content
      String msgId = ChatUtils.generateMessageId();
      String geolocDoc =
          ChatUtils.buildGeolocDocument(geoloc, ImsModule.IMS_USER_PROFILE.getPublicUri(), msgId);
      MmContent content =
          new GeolocContent("geoloc.xml", geolocDoc.getBytes().length, geolocDoc.getBytes());

      // Initiate a sharing session
      GeolocTransferSession session =
          Core.getInstance()
              .getRichcallService()
              .initiateGeolocSharingSession(contact, content, geoloc);

      // Update rich call
      RichCall.getInstance()
          .addCall(
              contact,
              session.getSessionID(),
              RichCallData.EVENT_OUTGOING,
              session.getContent(),
              RichCallData.STATUS_STARTED);

      // Update rich messaging history
      GeolocMessage geolocMsg = new GeolocMessage(null, contact, geoloc, false);
      RichMessaging.getInstance().addOutgoingGeoloc(geolocMsg);

      // Add session in the list
      GeolocSharingSession sessionApi = new GeolocSharingSession(session);
      addGeolocSharingSession(sessionApi);
      return sessionApi;
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Unexpected error", e);
      }
      throw new ServerApiException(e.getMessage());
    }
  }
  /**
   * Initiate an image sharing session
   *
   * @param contact Contact
   * @param file Image file
   * @param thumbnail Thumbnail option
   * @throws ServerApiException
   */
  public IImageSharingSession initiateImageSharing(String contact, String file, boolean thumbnail)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Initiate an image sharing session with " + contact);
    }

    // Check permission
    ServerApiUtils.testPermission();

    // Test IMS connection
    ServerApiUtils.testIms();

    try {
      // Create an image content
      FileDescription desc = FileFactory.getFactory().getFileDescription(file);
      MmContent content = ContentManager.createMmContentFromUrl(file, desc.getSize());

      // Initiate a sharing session
      ImageTransferSession session =
          Core.getInstance()
              .getRichcallService()
              .initiateImageSharingSession(contact, content, thumbnail);

      // Update rich call history
      RichCall.getInstance()
          .addCall(
              contact,
              session.getSessionID(),
              RichCallData.EVENT_OUTGOING,
              session.getContent(),
              RichCallData.STATUS_STARTED);

      // Add session in the list
      ImageSharingSession sessionApi = new ImageSharingSession(session);
      addImageSharingSession(sessionApi);
      return sessionApi;
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Unexpected error", e);
      }
      throw new ServerApiException(e.getMessage());
    }
  }
  /**
   * Initiate a live video sharing session
   *
   * @param contact Contact
   * @param player Media player
   * @throws ServerApiException
   */
  public IVideoSharingSession initiateLiveVideoSharing(String contact, IVideoPlayer player)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Initiate a live video session with " + contact);
    }

    // Check permission
    ServerApiUtils.testPermission();

    // Test IMS connection
    ServerApiUtils.testIms();

    try {
      // Initiate a new session
      VideoStreamingSession session =
          Core.getInstance().getRichcallService().initiateLiveVideoSharingSession(contact, player);

      // Update rich call history
      RichCall.getInstance()
          .addCall(
              contact,
              session.getSessionID(),
              RichCallData.EVENT_OUTGOING,
              session.getContent(),
              RichCallData.STATUS_STARTED);

      // Add session in the list
      VideoSharingSession sessionApi = new VideoSharingSession(session);
      addVideoSharingSession(sessionApi);
      return sessionApi;
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Unexpected error", e);
      }
      throw new ServerApiException(e.getMessage());
    }
  }
示例#6
0
  /** Start core */
  public synchronized void startCore() {
    if (Core.getInstance() != null) {
      // Already started
      return;
    }

    try {
      if (logger.isActivated()) {
        logger.debug("Start RCS core service");
      }

      // Send service intent
      Intent intent = new Intent(ClientApiIntents.SERVICE_STATUS);
      intent.putExtra("status", ClientApiIntents.SERVICE_STATUS_STARTING);
      getApplicationContext().sendBroadcast(intent);

      // Terminal version
      if (logger.isActivated()) {
        logger.info("RCS stack release is " + TerminalInfo.getProductVersion());
      }

      // Instantiate the contacts manager
      ContactsManager.createInstance(getApplicationContext());

      // Instantiate the rich messaging history
      RichMessaging.createInstance(getApplicationContext());

      // Instantiate the rich call history
      RichCall.createInstance(getApplicationContext());

      // Instantiate the IP call history
      IPCall.createInstance(getApplicationContext());

      // Create the core
      Core.createCore(this);

      // Start the core
      Core.getInstance().startCore();

      // Create multimedia directory on sdcard
      FileFactory.createDirectory(RcsSettings.getInstance().getPhotoRootDirectory());
      FileFactory.createDirectory(RcsSettings.getInstance().getVideoRootDirectory());
      FileFactory.createDirectory(RcsSettings.getInstance().getFileRootDirectory());

      // Init CPU manager
      cpuManager.init();

      // Register account changed event receiver
      if (accountChangedReceiver == null) {
        accountChangedReceiver = new AccountChangedReceiver();

        // Register account changed broadcast receiver after a timeout of 2s (This is not done
        // immediately, as we do not want to catch
        // the removal of the account (creating and removing accounts is done asynchronously). We
        // can reasonably assume that no
        // RCS account deletion will be done by user during this amount of time, as he just started
        // his service.
        Handler handler = new Handler();
        handler.postDelayed(
            new Runnable() {
              public void run() {
                registerReceiver(
                    accountChangedReceiver,
                    new IntentFilter("android.accounts.LOGIN_ACCOUNTS_CHANGED"));
              }
            },
            2000);
      }

      // Register SMS receiver for network initiated configuration

      if (reconfSMSReceiver == null) {
        reconfSMSReceiver = new HttpsProvisioningSMS(this);
        reconfSMSReceiver.registerSmsProvisioningReceiver(
            Integer.toString(HttpsProvisioningUtils.DEFAULT_SMS_PORT), null, null, null);
      }

      // Show a first notification
      addRcsServiceNotification(false, getString(R.string.rcs_core_loaded));

      // Update GSMA client API
      GsmaUtils.setClientActivationState(getApplicationContext(), true);

      // Send service intent
      intent = new Intent(ClientApiIntents.SERVICE_STATUS);
      intent.putExtra("status", ClientApiIntents.SERVICE_STATUS_STARTED);
      getApplicationContext().sendBroadcast(intent);

      if (logger.isActivated()) {
        logger.info("RCS core service started with success");
      }
    } catch (Exception e) {
      // Unexpected error
      if (logger.isActivated()) {
        logger.error("Can't instanciate the RCS core service", e);
      }

      // Send service intent
      Intent intent = new Intent(ClientApiIntents.SERVICE_STATUS);
      intent.putExtra("status", ClientApiIntents.SERVICE_STATUS_FAILED);
      getApplicationContext().sendBroadcast(intent);

      // Show error in notification bar
      addRcsServiceNotification(false, getString(R.string.rcs_core_failed));

      // Exit service
      stopSelf();
    }
  }