Ejemplo n.º 1
0
 public IImConnection getConnectionByAccount(long accountId) {
   synchronized (mConnections) {
     for (IImConnection conn : mConnections.values()) {
       try {
         if (conn.getAccountId() == accountId) {
           return conn;
         }
       } catch (RemoteException e) {
         // No server!
       }
     }
     return null;
   }
 }
Ejemplo n.º 2
0
  void handleIntent() {
    ContentResolver cr = getContentResolver();
    long providerId = Imps.Provider.getProviderIdForName(cr, mProviderName);
    long accountId;

    mConn = mApp.getConnection(providerId);
    if (mConn == null) {
      Cursor c = DatabaseUtils.queryAccountsForProvider(cr, ACCOUNT_PROJECTION, providerId);
      if (c == null) {
        addAccount(providerId);
      } else {
        accountId = c.getLong(ACCOUNT_ID_COLUMN);
        if (c.isNull(ACCOUNT_PW_COLUMN)) {
          editAccount(accountId);
        } else {
          signInAccount(accountId);
        }
      }
    } else {
      try {
        int state = mConn.getState();
        accountId = mConn.getAccountId();

        if (state < ImConnection.LOGGED_IN) {
          signInAccount(accountId);
        } else if (state == ImConnection.LOGGED_IN || state == ImConnection.SUSPENDED) {
          if (!isValidToAddress()) {
            showContactList(accountId);
          } else {
            openChat(providerId, accountId);
          }
        }
      } catch (RemoteException e) {
        // Ouch!  Service died!  We'll just disappear.
        Log.w("ImUrlActivity", "Connection disappeared!");
      }
    }
    finish();
  }