コード例 #1
0
  public static void startEventStreamService(Context context) {
    // the events stream service is launched
    // either the application has never be launched
    // or the service has been killed on low memory
    if (EventStreamService.getInstance() == null) {
      ArrayList<String> matrixIds = new ArrayList<String>();
      Collection<MXSession> sessions =
          Matrix.getInstance(context.getApplicationContext()).getSessions();

      if ((null != sessions) && (sessions.size() > 0)) {
        Log.d(LOG_TAG, "restart EventStreamService");

        for (MXSession session : sessions) {
          Boolean isSessionReady = session.getDataHandler().getStore().isReady();

          if (!isSessionReady) {
            session.getDataHandler().getStore().open();
          }

          // session to activate
          matrixIds.add(session.getCredentials().userId);
        }

        Intent intent = new Intent(context, EventStreamService.class);
        intent.putExtra(
            EventStreamService.EXTRA_MATRIX_IDS, matrixIds.toArray(new String[matrixIds.size()]));
        intent.putExtra(
            EventStreamService.EXTRA_STREAM_ACTION,
            EventStreamService.StreamAction.START.ordinal());
        context.startService(intent);
      }
    }
  }
コード例 #2
0
  public static void logout(Activity activity, MXSession session, Boolean clearCredentials) {
    if (session.isActive()) {
      // stop the service
      EventStreamService eventStreamService = EventStreamService.getInstance();
      ArrayList<String> matrixIds = new ArrayList<String>();
      matrixIds.add(session.getMyUser().userId);
      eventStreamService.stopAccounts(matrixIds);

      // Publish to the server that we're now offline
      MyPresenceManager.getInstance(activity, session).advertiseOffline();
      MyPresenceManager.remove(session);

      // unregister from the GCM.
      Matrix.getInstance(activity)
          .getSharedGcmRegistrationManager()
          .unregisterSession(session, null);

      // clear credentials
      Matrix.getInstance(activity).clearSession(activity, session, clearCredentials);
    }
  }
コード例 #3
0
 public static Boolean shouldRestartApp() {
   EventStreamService eventStreamService = EventStreamService.getInstance();
   return !Matrix.hasValidSessions() || (null == eventStreamService);
 }