Notification set when beem is launched.
author"Vincent Veronis"
Tue, 18 Oct 2011 01:02:23 +0200
changeset 906 4ee4a608f97b
parent 905 dfbc48b4eae1
child 907 d26b442143f9
Notification set when beem is launched.
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/service/XmppConnectionAdapter.java
src/com/beem/project/beem/ui/Login.java
--- a/src/com/beem/project/beem/BeemService.java	Tue Oct 18 00:37:46 2011 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Tue Oct 18 01:02:23 2011 +0200
@@ -59,9 +59,9 @@
 import org.jivesoftware.smackx.pubsub.provider.ItemsProvider;
 import org.jivesoftware.smackx.pubsub.provider.PubSubProvider;
 
-import android.accounts.Account;
 import android.app.Notification;
 import android.app.NotificationManager;
+import android.app.PendingIntent;
 import android.app.Service;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -85,6 +85,7 @@
 import com.beem.project.beem.smack.avatar.AvatarMetadataProvider;
 import com.beem.project.beem.smack.avatar.AvatarProvider;
 import com.beem.project.beem.smack.caps.CapsProvider;
+import com.beem.project.beem.ui.Login;
 import com.beem.project.beem.utils.BeemBroadcastReceiver;
 import com.beem.project.beem.utils.BeemConnectivity;
 import com.beem.project.beem.utils.Status;
@@ -136,8 +137,7 @@
      */
     @Override
     public IBinder onBind(Intent intent) {
-	Log.d(TAG, "ONBIND()");
-	return null;//(IBinder) mBind.get(accountName);
+	return null;
     }
 
     @Override
@@ -170,6 +170,18 @@
 	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
 	Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
 	Log.d(TAG, "ONCREATE");
+
+	Notification mStatusNotification;
+	mStatusNotification = new Notification(com.beem.project.beem.R.drawable.beem_status_icon, "Beem",
+	    System.currentTimeMillis());
+	mStatusNotification.defaults = Notification.DEFAULT_LIGHTS;
+	mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
+
+	mStatusNotification.setLatestEventInfo(this, "Beem", "Beem",
+	    PendingIntent.getActivity(this, 0, new Intent(this, Login.class), 0));
+	// bypass the preferences for notification
+	mNotificationManager.notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
+
     }
 
     /**
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Oct 18 00:37:46 2011 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Oct 18 01:02:23 2011 +0200
@@ -91,625 +91,616 @@
  */
 public class XmppConnectionAdapter extends IXmppConnection.Stub {
 
-	/**
-	 * Beem connection closed Intent name.
-	 */
+    /**
+     * Beem connection closed Intent name.
+     */
+
+    private static final int SMACK_PRIORITY_MIN = -128;
+    private static final int SMACK_PRIORITY_MAX = 128;
+    private static final String TAG = "XMPPConnectionAdapter";
+    private final XMPPConnection mAdaptee;
+    private IChatManager mChatManager;
+    private final String mLogin;
+    private final String mPassword;
+    private String mResource;
+    private String mErrorMsg;
+    private RosterAdapter mRoster;
+    private int mPreviousPriority;
+    private int mPreviousMode;
+    private String mPreviousStatus;
+    private PrivacyListManagerAdapter mPrivacyListManager;
+    private ChatStateManager mChatStateManager;
+    private final BeemService mService;
+    private BeemApplication mApplication;
+    private AvatarManager mAvatarManager;
+    private PepSubManager mPepManager;
+    private SharedPreferences mPref;
+    private final RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners = new RemoteCallbackList<IBeemConnectionListener>();
+    private final SubscribePacketListener mSubscribePacketListener = new SubscribePacketListener();
+
+    private final ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter();
+
+    /**
+     * Constructor.
+     * @param config Configuration to use in order to connect
+     * @param login login to use on connect
+     * @param password password to use on connect
+     * @param service the background service associated with the connection.
+     */
+    public XmppConnectionAdapter(final ConnectionConfiguration config, final String login, final String password,
+	final BeemService service) {
+	this(new XMPPConnection(config), login, password, service);
+    }
+
+    /**
+     * Constructor.
+     * @param serviceName name of the service to connect to
+     * @param login login to use on connect
+     * @param password password to use on connect
+     * @param service the background service associated with the connection.
+     */
+    public XmppConnectionAdapter(final String serviceName, final String login, final String password,
+	final BeemService service) {
+	this(new XMPPConnection(serviceName), login, password, service);
+    }
+
+    /**
+     * 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 = StringUtils.parseName(login);
+
+	mPassword = password;
+	mService = service;
+	Context ctx = mService.getApplicationContext();
+	if (ctx instanceof BeemApplication) {
+	    mApplication = (BeemApplication) ctx;
+	}
+	mPref = mService.getServicePreference(login); // login is the jid
+	try {
+	    mPreviousPriority = Integer.parseInt(mPref.getString("settings_key_priority", "0"));
+	} catch (NumberFormatException ex) {
+	    mPreviousPriority = 0;
+	}
+	mResource = mPref.getString("settings_key_resource", "BEEM");
+    }
 
-	private static final int SMACK_PRIORITY_MIN = -128;
-	private static final int SMACK_PRIORITY_MAX = 128;
-	private static final String TAG = "XMPPConnectionAdapter";
-	private final XMPPConnection mAdaptee;
-	private IChatManager mChatManager;
-	private final String mLogin;
-	private final String mPassword;
-	private String mResource;
-	private String mErrorMsg;
-	private RosterAdapter mRoster;
-	private int mPreviousPriority;
-	private int mPreviousMode;
-	private String mPreviousStatus;
-	private PrivacyListManagerAdapter mPrivacyListManager;
-	private ChatStateManager mChatStateManager;
-	private final BeemService mService;
-	private BeemApplication mApplication;
-	private AvatarManager mAvatarManager;
-	private PepSubManager mPepManager;
-	private SharedPreferences mPref;
-	private final RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners = new RemoteCallbackList<IBeemConnectionListener>();
-	private final SubscribePacketListener mSubscribePacketListener = new SubscribePacketListener();
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void addConnectionListener(IBeemConnectionListener listen) throws RemoteException {
+	if (listen != null)
+	    mRemoteConnListeners.register(listen);
+    }
+
+    @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;
+	}
+    }
 
-	private final ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter();
+    @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() {
 
-	/**
-	 * Constructor.
-	 * @param config Configuration to use in order to connect
-	 * @param login login to use on connect
-	 * @param password password to use on connect
-	 * @param service the background service associated with the connection.
-	 */
-	public XmppConnectionAdapter(final ConnectionConfiguration config, final String login, final String password,
-		final BeemService service) {
-		this(new XMPPConnection(config), login, password, service);
+		@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);
+	    Log.e(TAG, mLogin + mPassword + mResource);
+	    mAdaptee.login(mLogin, mPassword, mResource);
+	    mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService);
+	    //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 serviceName name of the service to connect to
-	 * @param login login to use on connect
-	 * @param password password to use on connect
-	 * @param service the background service associated with the connection.
-	 */
-	public XmppConnectionAdapter(final String serviceName, final String login, final String password,
-		final BeemService service) {
-		this(new XMPPConnection(serviceName), login, password, service);
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final void connectAsync() throws RemoteException {
+	if (mAdaptee.isConnected() || mAdaptee.isAuthenticated())
+	    return;
+	Thread t = new Thread(new Runnable() {
+
+	    @Override
+	    public void run() {
+		try {
+		    connectSync();
+		} catch (RemoteException e) {
+		    Log.e(TAG, "Error while connecting asynchronously", e);
+		}
+	    }
+	});
+	t.start();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean connectSync() throws RemoteException {
+	if (connect())
+	    return login();
+	return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void changeStatusAndPriority(int status, String msg, int priority) {
+	Presence pres = new Presence(Presence.Type.available);
+	String m;
+	if (msg != null)
+	    m = msg;
+	else
+	    m = mPreviousStatus;
+	pres.setStatus(m);
+	mPreviousStatus = m;
+	Presence.Mode mode = Status.getPresenceModeFromStatus(status);
+	if (mode != null) {
+	    pres.setMode(mode);
+	    mPreviousMode = status;
+	} else {
+	    pres.setMode(Status.getPresenceModeFromStatus(mPreviousMode));
 	}
+	int p = priority;
+	if (priority < SMACK_PRIORITY_MIN)
+	    p = SMACK_PRIORITY_MIN;
+	if (priority > SMACK_PRIORITY_MAX)
+	    p = SMACK_PRIORITY_MAX;
+	mPreviousPriority = p;
+	pres.setPriority(p);
+	mAdaptee.sendPacket(pres);
+	updateNotification(m);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void changeStatus(int status, String msg) {
+	changeStatusAndPriority(status, msg, mPreviousPriority);
+    }
+
+    /**
+     * Get the AvatarManager of this connection.
+     * @return the AvatarManager or null if there is not
+     */
+    public AvatarManager getAvatarManager() {
+	return mAvatarManager;
+    }
+
+    /**
+     * get the previous status.
+     * @return previous status.
+     */
+    public String getPreviousStatus() {
+	return mPreviousStatus;
+    }
+
+    /**
+     * get the previous mode.
+     * @return previous mode.
+     */
+    public int getPreviousMode() {
+	return mPreviousMode;
+    }
+
+    /**
+     * Update the notification for the Beem status.
+     * @param text the text to display.
+     */
+    private void updateNotification(String text) {
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean disconnect() {
+	if (mAdaptee != null && mAdaptee.isConnected())
+	    mAdaptee.disconnect();
+	return true;
+    }
+
+    /**
+     * Get the Smack XmppConnection.
+     * @return Smack XmppConnection
+     */
+    public XMPPConnection getAdaptee() {
+	return mAdaptee;
+    }
 
-	/**
-	 * 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 = StringUtils.parseName(login);
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IChatManager getChatManager() throws RemoteException {
+	return mChatManager;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IRoster getRoster() throws RemoteException {
+	if (mRoster != null)
+	    return mRoster;
+	Roster adap = mAdaptee.getRoster();
+	if (adap == null)
+	    return null;
+	mRoster = new RosterAdapter(adap, mService, mAvatarManager);
+	return mRoster;
+    }
+
+    /**
+     * Returns true if currently authenticated by successfully calling the login method.
+     * @return true when successfully authenticated
+     */
+    public boolean isAuthentificated() {
+	return mAdaptee.isAuthenticated();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void removeConnectionListener(IBeemConnectionListener listen) throws RemoteException {
+	if (listen != null)
+	    mRemoteConnListeners.unregister(listen);
+    }
+
+    /**
+     * PrivacyListManagerAdapter mutator.
+     * @param privacyListManager the privacy list manager
+     */
+    public void setPrivacyListManager(PrivacyListManagerAdapter privacyListManager) {
+	this.mPrivacyListManager = privacyListManager;
+    }
+
+    /**
+     * PrivacyListManagerAdapter accessor.
+     * @return the mPrivacyList
+     */
+    public PrivacyListManagerAdapter getPrivacyListManager() {
+	return mPrivacyListManager;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getErrorMessage() {
+	return mErrorMsg;
+    }
+
+    public void handleMessage(android.os.Message msg) {
+	Log.e(TAG, "HANDLEMESSAGE");
+	Bundle b = (Bundle) msg.obj;
+	switch (msg.what) {
 
-		mPassword = password;
-		mService = service;
-		Context ctx = mService.getApplicationContext();
-		if (ctx instanceof BeemApplication) {
-			mApplication = (BeemApplication) ctx;
+	    default:
+		Log.w(TAG, "Unknown message " + msg);
+	}
+    }
+
+    /**
+     * Initialize the features provided by beem.
+     */
+    private void initFeatures() {
+	ServiceDiscoveryManager.setIdentityName("Beem");
+	ServiceDiscoveryManager.setIdentityType("phone");
+	ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
+	if (sdm == null)
+	    sdm = new ServiceDiscoveryManager(mAdaptee);
+
+	sdm.addFeature("http://jabber.org/protocol/disco#info");
+	//nikita: must be uncommented when the feature will be enabled
+	//sdm.addFeature("jabber:iq:privacy");
+	sdm.addFeature("http://jabber.org/protocol/caps");
+	sdm.addFeature("urn:xmpp:avatar:metadata");
+	sdm.addFeature("urn:xmpp:avatar:metadata+notify");
+	sdm.addFeature("urn:xmpp:avatar:data");
+	sdm.addFeature("http://jabber.org/protocol/nick");
+	sdm.addFeature("http://jabber.org/protocol/nick+notify");
+
+	mChatStateManager = ChatStateManager.getInstance(mAdaptee);
+	BeemCapsManager caps = new BeemCapsManager(sdm, mAdaptee, mService);
+	caps.setNode("http://www.beem-project.com");
+    }
+
+    /**
+     * Discover the features provided by the server.
+     */
+    private void discoverServerFeatures() {
+	try {
+	    // jid et server
+	    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
+	    DiscoverInfo info = sdm.discoverInfo(mAdaptee.getServiceName());
+	    Iterator<DiscoverInfo.Identity> it = info.getIdentities();
+	    while (it.hasNext()) {
+		DiscoverInfo.Identity identity = it.next();
+		if ("pubsub".equals(identity.getCategory()) && "pep".equals(identity.getType())) {
+		    initPEP();
 		}
-		mPref = mService.getServicePreference(login); // login is the jid
-		try {
-			mPreviousPriority = Integer.parseInt(mPref.getString("settings_key_priority", "0"));
-		} catch (NumberFormatException ex) {
-			mPreviousPriority = 0;
-		}
-		mResource = mPref.getString("settings_key_resource", "BEEM");
+	    }
+	} catch (XMPPException e) {
+	    // No Pep
 	}
+    }
+
+    /**
+     * Initialize PEP.
+     */
+    private void initPEP() {
+	// Enable pep sending
+	// API 8
+	// mService.getExternalCacheDir()
+	mPepManager = new PepSubManager(mAdaptee);
+	AvatarCache avatarCache = new BeemAvatarCache(mService);
+	mAvatarManager = new AvatarManager(mAdaptee, mPepManager, avatarCache, true);
+    }
+
+    /**
+     * Listener for XMPP connection events. It will calls the remote listeners for connection events.
+     * @author darisk
+     */
+    private class ConnexionListenerAdapter implements ConnectionListener {
 
 	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void addConnectionListener(IBeemConnectionListener listen) throws RemoteException {
-		if (listen != null)
-			mRemoteConnListeners.register(listen);
-	}
-
-	@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);
-			Log.e(TAG, mLogin + mPassword + mResource);
-			mAdaptee.login(mLogin, mPassword, mResource);
-			mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService);
-			//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;
-		}
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public final void connectAsync() throws RemoteException {
-		if (mAdaptee.isConnected() || mAdaptee.isAuthenticated())
-			return;
-		Thread t = new Thread(new Runnable() {
-
-			@Override
-			public void run() {
-				try {
-					connectSync();
-				} catch (RemoteException e) {
-					Log.e(TAG, "Error while connecting asynchronously", e);
-				}
-			}
-		});
-		t.start();
-	}
-
-	/**
-	 * {@inheritDoc}
+	 * Defaut constructor.
 	 */
-	@Override
-	public boolean connectSync() throws RemoteException {
-		if (connect())
-			return login();
-		return false;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void changeStatusAndPriority(int status, String msg, int priority) {
-		Presence pres = new Presence(Presence.Type.available);
-		String m;
-		if (msg != null)
-			m = msg;
-		else
-			m = mPreviousStatus;
-		pres.setStatus(m);
-		mPreviousStatus = m;
-		Presence.Mode mode = Status.getPresenceModeFromStatus(status);
-		if (mode != null) {
-			pres.setMode(mode);
-			mPreviousMode = status;
-		} else {
-			pres.setMode(Status.getPresenceModeFromStatus(mPreviousMode));
-		}
-		int p = priority;
-		if (priority < SMACK_PRIORITY_MIN)
-			p = SMACK_PRIORITY_MIN;
-		if (priority > SMACK_PRIORITY_MAX)
-			p = SMACK_PRIORITY_MAX;
-		mPreviousPriority = p;
-		pres.setPriority(p);
-		mAdaptee.sendPacket(pres);
-		updateNotification(m);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void changeStatus(int status, String msg) {
-		changeStatusAndPriority(status, msg, mPreviousPriority);
-	}
-
-	/**
-	 * Get the AvatarManager of this connection.
-	 * @return the AvatarManager or null if there is not
-	 */
-	public AvatarManager getAvatarManager() {
-		return mAvatarManager;
-	}
-
-	/**
-	 * get the previous status.
-	 * @return previous status.
-	 */
-	public String getPreviousStatus() {
-		return mPreviousStatus;
-	}
-
-	/**
-	 * get the previous mode.
-	 * @return previous mode.
-	 */
-	public int getPreviousMode() {
-		return mPreviousMode;
-	}
-
-	/**
-	 * 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;
-//
-//		mStatusNotification.setLatestEventInfo(mService, "Beem Status", text, PendingIntent.getActivity(mService, 0,
-//			new Intent(mService, ChangeStatus.class), 0));
-//		// bypass the preferences for notification
-//		mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public boolean disconnect() {
-		if (mAdaptee != null && mAdaptee.isConnected())
-			mAdaptee.disconnect();
-		return true;
-	}
-
-	/**
-	 * Get the Smack XmppConnection.
-	 * @return Smack XmppConnection
-	 */
-	public XMPPConnection getAdaptee() {
-		return mAdaptee;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public IChatManager getChatManager() throws RemoteException {
-		return mChatManager;
+	public ConnexionListenerAdapter() {
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	public IRoster getRoster() throws RemoteException {
-		if (mRoster != null)
-			return mRoster;
-		Roster adap = mAdaptee.getRoster();
-		if (adap == null)
-			return null;
-		mRoster = new RosterAdapter(adap, mService, mAvatarManager);
-		return mRoster;
-	}
-
-	/**
-	 * Returns true if currently authenticated by successfully calling the login method.
-	 * @return true when successfully authenticated
-	 */
-	public boolean isAuthentificated() {
-		return mAdaptee.isAuthenticated();
+	public void connectionClosed() {
+	    Log.d(TAG, "closing connection");
+	    mRoster = null;
+	    Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
+	    intent.putExtra("message", mService.getString(R.string.BeemBroadcastReceiverDisconnect));
+	    intent.putExtra("normally", true);
+	    mService.sendBroadcast(intent);
+	    mService.stopSelf();
+	    mApplication.setConnected(false);
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	public void removeConnectionListener(IBeemConnectionListener listen) throws RemoteException {
-		if (listen != null)
-			mRemoteConnListeners.unregister(listen);
+	public void connectionClosedOnError(Exception exception) {
+	    Log.d(TAG, "connectionClosedOnError");
+	    mRoster = null;
+	    Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
+	    intent.putExtra("message", exception.getMessage());
+	    mService.sendBroadcast(intent);
+	    mService.stopSelf();
+	    mApplication.setConnected(false);
 	}
 
 	/**
-	 * PrivacyListManagerAdapter mutator.
-	 * @param privacyListManager the privacy list manager
+	 * Connection failed callback.
+	 * @param errorMsg smack failure message
 	 */
-	public void setPrivacyListManager(PrivacyListManagerAdapter privacyListManager) {
-		this.mPrivacyListManager = privacyListManager;
+	public void connectionFailed(String errorMsg) {
+	    Log.d(TAG, "Connection Failed");
+	    final int n = mRemoteConnListeners.beginBroadcast();
+
+	    for (int i = 0; i < n; i++) {
+		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+		try {
+		    if (listener != null)
+			listener.connectionFailed(errorMsg);
+		} catch (RemoteException e) {
+		    // The RemoteCallbackList will take care of removing the
+		    // dead listeners.
+		    Log.w(TAG, "Error while triggering remote connection listeners", e);
+		}
+	    }
+	    mRemoteConnListeners.finishBroadcast();
+	    mService.stopSelf();
+	    mApplication.setConnected(false);
 	}
 
 	/**
-	 * PrivacyListManagerAdapter accessor.
-	 * @return the mPrivacyList
+	 * {@inheritDoc}
 	 */
-	public PrivacyListManagerAdapter getPrivacyListManager() {
-		return mPrivacyListManager;
+	@Override
+	public void reconnectingIn(int arg0) {
+	    Log.d(TAG, "reconnectingIn");
+	    final int n = mRemoteConnListeners.beginBroadcast();
+
+	    for (int i = 0; i < n; i++) {
+		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+		try {
+		    if (listener != null)
+			listener.reconnectingIn(arg0);
+		} catch (RemoteException e) {
+		    // The RemoteCallbackList will take care of removing the
+		    // dead listeners.
+		    Log.w(TAG, "Error while triggering remote connection listeners", e);
+		}
+	    }
+	    mRemoteConnListeners.finishBroadcast();
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	public String getErrorMessage() {
-		return mErrorMsg;
-	}
-
-	public void handleMessage(android.os.Message msg) {
-		Log.e(TAG, "HANDLEMESSAGE");
-		Bundle b = (Bundle) msg.obj;
-		switch (msg.what) {
-
-			default:
-				Log.w(TAG, "Unknown message " + msg);
-		}
-	}
-
-	/**
-	 * Initialize the features provided by beem.
-	 */
-	private void initFeatures() {
-		ServiceDiscoveryManager.setIdentityName("Beem");
-		ServiceDiscoveryManager.setIdentityType("phone");
-		ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
-		if (sdm == null)
-			sdm = new ServiceDiscoveryManager(mAdaptee);
-
-		sdm.addFeature("http://jabber.org/protocol/disco#info");
-		//nikita: must be uncommented when the feature will be enabled
-		//sdm.addFeature("jabber:iq:privacy");
-		sdm.addFeature("http://jabber.org/protocol/caps");
-		sdm.addFeature("urn:xmpp:avatar:metadata");
-		sdm.addFeature("urn:xmpp:avatar:metadata+notify");
-		sdm.addFeature("urn:xmpp:avatar:data");
-		sdm.addFeature("http://jabber.org/protocol/nick");
-		sdm.addFeature("http://jabber.org/protocol/nick+notify");
+	public void reconnectionFailed(Exception arg0) {
+	    Log.d(TAG, "reconnectionFailed");
+	    final int r = mRemoteConnListeners.beginBroadcast();
 
-		mChatStateManager = ChatStateManager.getInstance(mAdaptee);
-		BeemCapsManager caps = new BeemCapsManager(sdm, mAdaptee, mService);
-		caps.setNode("http://www.beem-project.com");
-	}
-
-	/**
-	 * Discover the features provided by the server.
-	 */
-	private void discoverServerFeatures() {
+	    for (int i = 0; i < r; i++) {
+		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
 		try {
-			// jid et server
-			ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
-			DiscoverInfo info = sdm.discoverInfo(mAdaptee.getServiceName());
-			Iterator<DiscoverInfo.Identity> it = info.getIdentities();
-			while (it.hasNext()) {
-				DiscoverInfo.Identity identity = it.next();
-				if ("pubsub".equals(identity.getCategory()) && "pep".equals(identity.getType())) {
-					initPEP();
-				}
-			}
-		} catch (XMPPException e) {
-			// No Pep
+		    if (listener != null)
+			listener.reconnectionFailed();
+		} catch (RemoteException e) {
+		    // The RemoteCallbackList will take care of removing the
+		    // dead listeners.
+		    Log.w(TAG, "Error while triggering remote connection listeners", e);
 		}
-	}
-
-	/**
-	 * Initialize PEP.
-	 */
-	private void initPEP() {
-		// Enable pep sending
-		// API 8
-		// mService.getExternalCacheDir()
-		mPepManager = new PepSubManager(mAdaptee);
-		AvatarCache avatarCache = new BeemAvatarCache(mService);
-		mAvatarManager = new AvatarManager(mAdaptee, mPepManager, avatarCache, true);
+	    }
+	    mRemoteConnListeners.finishBroadcast();
 	}
 
 	/**
-	 * Listener for XMPP connection events. It will calls the remote listeners for connection events.
-	 * @author darisk
+	 * {@inheritDoc}
 	 */
-	private class ConnexionListenerAdapter implements ConnectionListener {
-
-		/**
-		 * Defaut constructor.
-		 */
-		public ConnexionListenerAdapter() {
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void connectionClosed() {
-			Log.d(TAG, "closing connection");
-			mRoster = null;
-			Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
-			intent.putExtra("message", mService.getString(R.string.BeemBroadcastReceiverDisconnect));
-			intent.putExtra("normally", true);
-			mService.sendBroadcast(intent);
-			mService.stopSelf();
-			mApplication.setConnected(false);
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void connectionClosedOnError(Exception exception) {
-			Log.d(TAG, "connectionClosedOnError");
-			mRoster = null;
-			Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
-			intent.putExtra("message", exception.getMessage());
-			mService.sendBroadcast(intent);
-			mService.stopSelf();
-			mApplication.setConnected(false);
-		}
-
-		/**
-		 * Connection failed callback.
-		 * @param errorMsg smack failure message
-		 */
-		public void connectionFailed(String errorMsg) {
-			Log.d(TAG, "Connection Failed");
-			final int n = mRemoteConnListeners.beginBroadcast();
-
-			for (int i = 0; i < n; i++) {
-				IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
-				try {
-					if (listener != null)
-						listener.connectionFailed(errorMsg);
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, "Error while triggering remote connection listeners", e);
-				}
-			}
-			mRemoteConnListeners.finishBroadcast();
-			mService.stopSelf();
-			mApplication.setConnected(false);
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void reconnectingIn(int arg0) {
-			Log.d(TAG, "reconnectingIn");
-			final int n = mRemoteConnListeners.beginBroadcast();
-
-			for (int i = 0; i < n; i++) {
-				IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
-				try {
-					if (listener != null)
-						listener.reconnectingIn(arg0);
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, "Error while triggering remote connection listeners", e);
-				}
-			}
-			mRemoteConnListeners.finishBroadcast();
-		}
+	@Override
+	public void reconnectionSuccessful() {
+	    Log.d(TAG, "reconnectionSuccessful");
+	    mApplication.setConnected(true);
+	    PacketFilter filter = new PacketFilter() {
 
-		/**
-		 * {@inheritDoc}
-		 */
 		@Override
-		public void reconnectionFailed(Exception arg0) {
-			Log.d(TAG, "reconnectionFailed");
-			final int r = mRemoteConnListeners.beginBroadcast();
-
-			for (int i = 0; i < r; i++) {
-				IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
-				try {
-					if (listener != null)
-						listener.reconnectionFailed();
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, "Error while triggering remote connection listeners", e);
-				}
-			}
-			mRemoteConnListeners.finishBroadcast();
+		public boolean accept(Packet packet) {
+		    if (packet instanceof Presence) {
+			Presence pres = (Presence) packet;
+			if (pres.getType() == Presence.Type.subscribe)
+			    return true;
+		    }
+		    return false;
 		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void reconnectionSuccessful() {
-			Log.d(TAG, "reconnectionSuccessful");
-			mApplication.setConnected(true);
-			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(new PacketListener() {
+	    };
 
-				@Override
-				public void processPacket(Packet packet) {
-					String from = packet.getFrom();
-					Notification notif = new Notification(android.R.drawable.stat_notify_more, mService.getString(
-						R.string.AcceptContactRequest, from), System.currentTimeMillis());
-					notif.flags = Notification.FLAG_AUTO_CANCEL;
-					Intent intent = new Intent(mService, Subscription.class);
-					intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra("from", from);
-					notif.setLatestEventInfo(mService, from, mService
-						.getString(R.string.AcceptContactRequestFrom, from), PendingIntent.getActivity(mService, 0,
-						intent, PendingIntent.FLAG_ONE_SHOT));
-					int id = packet.hashCode();
-					mService.sendNotification(id, notif);
-				}
-			}, filter);
-
-			final int n = mRemoteConnListeners.beginBroadcast();
-
-			for (int i = 0; i < n; i++) {
-				IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
-				try {
-					if (listener != null)
-						listener.reconnectionSuccessful();
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, "Error while triggering remote connection listeners", e);
-				}
-			}
-			mRemoteConnListeners.finishBroadcast();
-		}
-	}
-
-	/**
-	 * This PacketListener will set a notification when you got a subscribtion request.
-	 * @author Da Risk <da_risk@elyzion.net>
-	 */
-	private class SubscribePacketListener implements PacketListener {
-
-		/**
-		 * Constructor.
-		 */
-		public SubscribePacketListener() {
-		}
+	    mAdaptee.addPacketListener(new PacketListener() {
 
 		@Override
 		public void processPacket(Packet packet) {
-			if (!(packet instanceof Presence))
-				return;
-			Presence p = (Presence) packet;
-			if (p.getType() != Presence.Type.subscribe)
-				return;
-			String from = p.getFrom();
-			Notification notification = new Notification(android.R.drawable.stat_notify_more, mService.getString(
-				R.string.AcceptContactRequest, from), System.currentTimeMillis());
-			notification.flags = Notification.FLAG_AUTO_CANCEL;
-			Intent intent = new Intent(mService, Subscription.class);
-			intent.setData(Contact.makeXmppUri(from));
-			notification.setLatestEventInfo(mService, from,
-				mService.getString(R.string.AcceptContactRequestFrom, from), PendingIntent.getActivity(mService, 0,
-					intent, PendingIntent.FLAG_ONE_SHOT));
-			int id = p.hashCode();
-			mService.sendNotification(id, notification);
+		    String from = packet.getFrom();
+		    Notification notif = new Notification(android.R.drawable.stat_notify_more, mService.getString(
+			R.string.AcceptContactRequest, from), System.currentTimeMillis());
+		    notif.flags = Notification.FLAG_AUTO_CANCEL;
+		    Intent intent = new Intent(mService, Subscription.class);
+		    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra("from", from);
+		    notif.setLatestEventInfo(mService, from,
+			mService.getString(R.string.AcceptContactRequestFrom, from),
+			PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
+		    int id = packet.hashCode();
+		    mService.sendNotification(id, notif);
 		}
+	    }, filter);
+
+	    final int n = mRemoteConnListeners.beginBroadcast();
+
+	    for (int i = 0; i < n; i++) {
+		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+		try {
+		    if (listener != null)
+			listener.reconnectionSuccessful();
+		} catch (RemoteException e) {
+		    // The RemoteCallbackList will take care of removing the
+		    // dead listeners.
+		    Log.w(TAG, "Error while triggering remote connection listeners", e);
+		}
+	    }
+	    mRemoteConnListeners.finishBroadcast();
+	}
+    }
+
+    /**
+     * This PacketListener will set a notification when you got a subscribtion request.
+     * @author Da Risk <da_risk@elyzion.net>
+     */
+    private class SubscribePacketListener implements PacketListener {
+
+	/**
+	 * Constructor.
+	 */
+	public SubscribePacketListener() {
 	}
 
+	@Override
+	public void processPacket(Packet packet) {
+	    if (!(packet instanceof Presence))
+		return;
+	    Presence p = (Presence) packet;
+	    if (p.getType() != Presence.Type.subscribe)
+		return;
+	    String from = p.getFrom();
+	    Notification notification = new Notification(android.R.drawable.stat_notify_more, mService.getString(
+		R.string.AcceptContactRequest, from), System.currentTimeMillis());
+	    notification.flags = Notification.FLAG_AUTO_CANCEL;
+	    Intent intent = new Intent(mService, Subscription.class);
+	    intent.setData(Contact.makeXmppUri(from));
+	    notification.setLatestEventInfo(mService, from,
+		mService.getString(R.string.AcceptContactRequestFrom, from),
+		PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
+	    int id = p.hashCode();
+	    mService.sendNotification(id, notification);
+	}
+    }
+
 }
--- a/src/com/beem/project/beem/ui/Login.java	Tue Oct 18 00:37:46 2011 +0200
+++ b/src/com/beem/project/beem/ui/Login.java	Tue Oct 18 01:02:23 2011 +0200
@@ -73,6 +73,7 @@
 import android.widget.TextView;
 
 import com.beem.project.beem.BeemIntent;
+import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
 
 /**
@@ -96,6 +97,10 @@
     protected void onCreate(Bundle savedInstanceState) {
 	super.onCreate(savedInstanceState);
 	setContentView(R.layout.login);
+
+	Intent intent = new Intent(this, BeemService.class);
+	startService(intent);
+
 	ListView listView = (ListView) findViewById(R.id.accountlist);
 	mAdapterAccountList = new BeemAccountList(getLayoutInflater());
 	listView.setClickable(true);