@Override
 public boolean connect() throws RemoteException {
   if (mAdaptee.isConnected()) return true;
   else {
     try {
       mAdaptee.connect();
       mAdaptee.addConnectionListener(mConListener);
       return true;
     } catch (XMPPException e) {
       Log.e(TAG, "Error while connecting", e);
       try {
         // TODO NIKITA DOES SOME SHIT !!! Fix this monstruosity
         String str =
             mService
                 .getResources()
                 .getString(
                     mService
                         .getResources()
                         .getIdentifier(
                             e.getXMPPError().getCondition().replace("-", "_"),
                             "string",
                             "com.beem.project.beem"));
         mErrorMsg = str;
       } catch (NullPointerException e2) {
         if (!"".equals(e.getMessage())) mErrorMsg = e.getMessage();
         else mErrorMsg = e.toString();
       }
     }
     return false;
   }
 }
  @Override
  public boolean login() throws RemoteException {
    if (mAdaptee.isAuthenticated()) return true;
    if (!mAdaptee.isConnected()) return false;
    try {

      this.initFeatures(); // pour declarer les features xmpp qu'on
      // supporte

      PacketFilter filter =
          new PacketFilter() {

            @Override
            public boolean accept(Packet packet) {
              if (packet instanceof Presence) {
                Presence pres = (Presence) packet;
                if (pres.getType() == Presence.Type.subscribe) return true;
              }
              return false;
            }
          };

      mAdaptee.addPacketListener(mSubscribePacketListener, filter);

      filter = new PacketTypeFilter(PingExtension.class);
      mAdaptee.addPacketListener(mPingListener, filter);

      mAdaptee.login(mLogin, mPassword, mResource);
      mUserInfo = new UserInfo(mAdaptee.getUser());

      mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService, mAdaptee.getRoster());
      // nikita: I commented this line because of the logs provided in
      // http://www.beem-project.com/issues/321
      // Also, since the privacylistmanager isn't finished and used, it will be safer to not
      // initialize it
      // mPrivacyListManager = new
      // PrivacyListManagerAdapter(PrivacyListManager.getInstanceFor(mAdaptee));
      mService.initJingle(mAdaptee);
      discoverServerFeatures();

      mRoster = new RosterAdapter(mAdaptee.getRoster(), mService, mAvatarManager);
      mApplication.setConnected(true);
      int mode = mPref.getInt(BeemApplication.STATUS_KEY, 0);
      String status = mPref.getString(BeemApplication.STATUS_TEXT_KEY, "");
      changeStatus(mode, status);
      return true;
    } catch (XMPPException e) {
      Log.e(TAG, "Error while connecting", e);
      mErrorMsg = mService.getString(R.string.error_login_authentication);
      return false;
    }
  }
 /**
  * Constructor.
  *
  * @param con The connection to adapt
  * @param login The login to use
  * @param password The password to use
  * @param service the background service associated with the connection.
  */
 public XmppConnectionAdapter(
     final XMPPConnection con,
     final String login,
     final String password,
     final BeemService service) {
   mAdaptee = con;
   PrivacyListManager.getInstanceFor(mAdaptee);
   mLogin = login;
   mPassword = password;
   mService = service;
   Context ctx = mService.getApplicationContext();
   if (ctx instanceof BeemApplication) {
     mApplication = (BeemApplication) ctx;
   }
   mPref = mService.getServicePreference();
   try {
     mPreviousPriority =
         Integer.parseInt(mPref.getString(BeemApplication.CONNECTION_PRIORITY_KEY, "0"));
   } catch (NumberFormatException ex) {
     mPreviousPriority = 0;
   }
   mResource = mPref.getString(BeemApplication.CONNECTION_RESOURCE_KEY, "Beem");
 }
  /**
   * Update the notification for the Beem status.
   *
   * @param text the text to display.
   */
  private void updateNotification(String text) {
    Notification mStatusNotification;
    mStatusNotification =
        new Notification(
            com.beem.project.beem.R.drawable.beem_status_icon, text, System.currentTimeMillis());
    mStatusNotification.defaults = Notification.DEFAULT_LIGHTS;
    mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    // DA modified latest event info from "Beem status" to "TxtFeedback activity"
    mStatusNotification.setLatestEventInfo(
        mService,
        "TxtFeedback activity",
        text,
        PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0));
    // bypass the preferences for notification
    mService
        .getNotificationManager()
        .notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
  }