Le proxy devrait marcher a peu pres.
authorDa Risk <darisk972@gmail.com>
Tue, 07 Apr 2009 10:25:40 +0200
changeset 80 29f0d6a23321
parent 76 144e837ee4a6
child 81 b99c01522c62
child 84 9a4dbd7fe546
child 87 84cad8522aa6
Le proxy devrait marcher a peu pres. Ca se connecte par le proxy mais les serveurs que j'ai essayƩ ne repondent pas fixes #83
res/values/strings.xml
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/service/Contact.java
src/com/beem/project/beem/service/RosterAdapter.java
src/com/beem/project/beem/service/XmppConnectionAdapter.java
src/com/beem/project/beem/ui/ContactList.java
--- a/res/values/strings.xml	Tue Apr 07 01:18:19 2009 +0200
+++ b/res/values/strings.xml	Tue Apr 07 10:25:40 2009 +0200
@@ -17,6 +17,15 @@
 	<string name="PreferenceHostKey">host</string>
 	<string name="PreferenceJID">Jabber ID</string><string name="PreferenceLoginKey">login</string><string name="PreferencePasswordKey">password</string>
 	<string name="PreferencePortKey">port</string>
+	<string name="PreferenceProxyHost">proxy_host</string>
+	<string name="PreferenceProxyPort">proxy_port</string>
+	<string name="PreferenceUseProxy">use_proxy</string>
+	<string name="PreferenceProxyType">proxy_type</string>
+	<string name="PreferenceProxyUser">proxy_user</string>
+	<string name="PreferenceProxyPassword">proxy_password</string>
+	<string name="PreferenceProxyTypeHttp">HTTP</string>
+	<string name="PreferenceProxyTypeSocks4">SOCKS4</string>
+	<string name="PreferenceProxyTypeSocks5">SOCKS5</string>
 
 	<!--  SendIM class -->
 	<string name="SendIMSays">says :\n</string>
--- a/src/com/beem/project/beem/BeemService.java	Tue Apr 07 01:18:19 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Tue Apr 07 10:25:40 2009 +0200
@@ -1,20 +1,19 @@
 package com.beem.project.beem;
 
+import org.jivesoftware.smack.ConnectionConfiguration;
+import org.jivesoftware.smack.proxy.ProxyInfo;
+import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
 import android.app.Notification;
 import android.app.NotificationManager;
-import android.app.PendingIntent;
 import android.app.Service;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.IBinder;
 import android.os.RemoteException;
-import android.widget.Toast;
-
 import com.beem.project.beem.service.XmppConnectionAdapter;
 import com.beem.project.beem.service.XmppFacade;
-import com.beem.project.beem.service.aidl.IBeemConnectionListener;
+import com.beem.project.beem.service.aidl.IXmppConnection;
 import com.beem.project.beem.service.aidl.IXmppFacade;
-import com.beem.project.beem.service.aidl.IXmppConnection;
 
 /**
  * This class is for the Beem service.
@@ -35,8 +34,9 @@
     private String mLogin;
     private String mPassword;
     private String mHost;
-
-
+    private ConnectionConfiguration mConnectionConfiguration;
+    private ProxyInfo mProxyInfo;
+    private boolean mUseProxy;
     private IXmppFacade.Stub mBind;
 
     /**
@@ -65,12 +65,36 @@
 	mLogin = mSettings.getString(getString(R.string.PreferenceLoginKey), "");
 	mPassword = mSettings.getString(getString(R.string.PreferencePasswordKey), "");
 	mHost = mSettings.getString(getString(R.string.PreferenceHostKey), "");
+	mHost = "10.0.2.2";
+	initConnectionConfig();
 	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-	mConnection = new XmppConnectionAdapter("10.0.2.2", mLogin, mPassword); // address
+	mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword);
 	mBind = new XmppFacade(mConnection, this);
     }
 
     /**
+     * Initialise la configuration de la connexion.
+     */
+    private void initConnectionConfig() {
+	//TODO mettre a false par defaut et remplacer les valeurs par defaut
+	mUseProxy = mSettings.getBoolean(getString(R.string.PreferenceUseProxy), false);
+	if (mUseProxy) {
+	    String stype = mSettings.getString(getString(R.string.PreferenceProxyType),
+		getString(R.string.PreferenceProxyTypeHttp));
+	    String phost = mSettings.getString(getString(R.string.PreferenceProxyHost), "");
+	    String puser = mSettings.getString(getString(R.string.PreferenceProxyUser), "");
+	    String ppass = mSettings.getString(getString(R.string.PreferenceProxyPassword), "");
+	    int pport =  mSettings.getInt(getString(R.string.PreferenceProxyPort), 3128);
+	    ProxyInfo.ProxyType type = ProxyType.valueOf(stype);
+	    mProxyInfo = new ProxyInfo(type, phost, pport, puser, ppass);
+	    mConnectionConfiguration = new ConnectionConfiguration(mHost, mProxyInfo);
+	} else {
+	    mConnectionConfiguration = new ConnectionConfiguration(mHost);
+	}
+	mConnectionConfiguration.setSendPresence(false);
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override
--- a/src/com/beem/project/beem/service/Contact.java	Tue Apr 07 01:18:19 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java	Tue Apr 07 10:25:40 2009 +0200
@@ -20,12 +20,36 @@
  */
 public class Contact implements Parcelable {
 
+    /**
+     * Status of a disconnected contact.
+     */
     public static final int CONTACT_STATUS_DISCONNECT = 100;
+
+    /**
+     * Status of a unavailable (long away) contact.
+     */
     public static final int CONTACT_STATUS_UNAVAILABLE = 200;
+
+    /**
+     * Status of a away contact.
+     */
     public static final int CONTACT_STATUS_AWAY = 300;
+
+    /**
+     * Status of a busy contact.
+     */
     public static final int CONTACT_STATUS_BUSY = 400;
+
+    /**
+     * Status of a available contact.
+     */
     public static final int CONTACT_STATUS_AVAILABLE = 500;
+
+    /**
+     * Status of a available for chat contact.
+     */
     public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
+
     private static final String TAG = "Contact";
 
     private int mID;
@@ -51,6 +75,24 @@
     };
 
     /**
+     * Constructor.
+     */
+    public Contact() {
+	// TODO Auto-generated constructor stub
+    }
+
+    /**
+     * Constructor.
+     * @param jid JID of the contact
+     */
+    public Contact(final String jid) {
+	mJID = jid;
+	mStatus = Contact.CONTACT_STATUS_DISCONNECT;
+	mRes = new ArrayList<String>();
+	mRes.add("none");
+    }
+
+    /**
      * Construct a contact from a parcel.
      * @param in parcel to use for construction
      */
@@ -60,7 +102,7 @@
 	mJID = in.readString();
 	mMsgState = in.readString();
 	mRes = new ArrayList<String>();
-	in.readStringList(mRes); 
+	in.readStringList(mRes);
     }
 
     /**
@@ -85,24 +127,7 @@
     }
 
     /**
-     * Constructor.
-     */
-    public Contact() {
-	// TODO Auto-generated constructor stub
-    }
-
-    /**
-     * Constructor.
-     * @param jid JID of the contact
-     */
-    public Contact(final String jid) {
-	mJID = jid;
-	mStatus = Contact.CONTACT_STATUS_DISCONNECT;
-	mRes = new ArrayList<String>();
-	mRes.add("none");
-    }
-
-    /**
+     * Get the id of the contact on the phone contact list.
      * @return the mID
      */
     public int getID() {
@@ -110,6 +135,7 @@
     }
 
     /**
+     * set the id of te contact on the phone contact list.
      * @param mid the mID to set
      */
     public void setID(int mid) {
@@ -117,6 +143,7 @@
     }
 
     /**
+     * Get the status of the contact.
      * @return the mStatus
      */
     public int getStatus() {
@@ -124,6 +151,7 @@
     }
 
     /**
+     * Set the status of the contact.
      * @param status the mStatus to set
      */
     public void setStatus(int status) {
@@ -131,6 +159,7 @@
     }
 
     /**
+     * Set the status of the contact using a presence packet.
      * @param presence the presence containing status
      */
     public void setStatus(Presence presence) {
@@ -138,7 +167,7 @@
 	    Log.d(TAG, "Presence pas dispo");
 	    mStatus = Contact.CONTACT_STATUS_DISCONNECT;
 	} else {
-	    Log.d(TAG,"Presence OK");
+	    Log.d(TAG, "Presence OK");
 	    Mode mode = presence.getMode();
 	    switch (mode) {
 		case available:
@@ -158,23 +187,25 @@
 		    break;
 		default:
 		    Log.e("RosterAdapter", "Status mode non gere");
-		mStatus = Contact.CONTACT_STATUS_DISCONNECT;
-		break;
+		    mStatus = Contact.CONTACT_STATUS_DISCONNECT;
+		    break;
 	    }
 	}
     }
 
     /**
-     * @return the mMsgState
+     * Get the message status of the contact.
+     * @return the message status of the contact.
      */
-    public String getMMsgState() {
+    public String getMsgState() {
 	return mMsgState;
     }
 
     /**
-     * @param msgState the mMsgState to set
+     * Set the message status of the contact.
+     * @param msgState the message status of the contact to set
      */
-    public void setMMsgState(String msgState) {
+    public void setMsgState(String msgState) {
 	mMsgState = msgState;
     }
 
@@ -188,17 +219,25 @@
 
     /**
      * Set the Jabber ID of the contact.
-     * @param mjid	the jabber ID to set
+     * @param mjid the jabber ID to set
      */
     public void setJID(String mjid) {
 	mJID = mjid;
     }
 
+    /**
+     * 
+     * @param res
+     */
     public void addRes(String res) {
 	if (!mRes.contains(res))
 	    mRes.add(res);
     }
 
+    /**
+     * 
+     * @param res
+     */
     public void delRes(String res) {
 	mRes.remove(res);
     }
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Tue Apr 07 01:18:19 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Tue Apr 07 10:25:40 2009 +0200
@@ -46,16 +46,22 @@
 	roster.addRosterListener(mRosterListener);
 	for (RosterEntry entry : roster.getEntries()) {
 	    String user = StringUtils.parseBareAddress(entry.getUser());
-	    if ( !mContacts.containsKey(user))
+	    if (!mContacts.containsKey(user))
 		mContacts.put(user, new Contact(user));
 	}
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void createGroup(String groupname) throws RemoteException {
 	mAdaptee.createGroup(groupname);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Contact addContact(String user, String name, String[] groups) throws RemoteException {
 	try {
@@ -76,18 +82,27 @@
 	mContacts.remove(contact.getJID());
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void addConnectionListener(IBeemRosterListener listen) throws RemoteException {
 	if (listen != null)
 	    mRemoteRosListeners.register(listen);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void removeConnectionListener(IBeemRosterListener listen) throws RemoteException {
 	if (listen != null)
 	    mRemoteRosListeners.unregister(listen);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Contact getContact(String jid) throws RemoteException {
 	return mContacts.get(jid);
@@ -103,8 +118,24 @@
 	return res;
     }
 
+    /**
+     * Listener for the roster events.
+     * It will call the remote listeners registered.
+     * @author darisk
+     *
+     */
     private class RosterListenerAdapter implements RosterListener {
 
+	/**
+	 * Constructor.
+	 */
+	public RosterListenerAdapter() {
+	    // TODO Auto-generated constructor stub
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
 	@Override
 	public void entriesAdded(Collection<String> addresses) {
 	    Log.i(TAG, "Ajout de l'entry");
@@ -125,6 +156,9 @@
 	    mRemoteRosListeners.finishBroadcast();
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	@Override
 	public void entriesDeleted(Collection<String> addresses) {
 	    Log.i(TAG, "Suppression de l'entry");
@@ -142,9 +176,12 @@
 		    Log.w(TAG, "Error while deleting roster entries", e);
 		}
 	    }
-	    mRemoteRosListeners.finishBroadcast();			
+	    mRemoteRosListeners.finishBroadcast();
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	@Override
 	public void entriesUpdated(Collection<String> addresses) {
 	    Log.i(TAG, "Update de l'entry");
@@ -162,15 +199,18 @@
 		    Log.w(TAG, "Error while updating roster entries", e);
 		}
 	    }
-	    mRemoteRosListeners.finishBroadcast();			
+	    mRemoteRosListeners.finishBroadcast();
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	@Override
 	public void presenceChanged(Presence presence) {
 	    Log.i(TAG, "Changement de Presence");
 	    /* gestion du roster coter sedirvice */
 	    String user = StringUtils.parseBareAddress(presence.getFrom());
-	    Log.d(TAG, "User : "+user);
+	    Log.d(TAG, "User : " + user);
 	    Contact c = mContacts.get(StringUtils.parseBareAddress(user));
 	    if (c == null) {
 		c = new Contact(user);
@@ -191,7 +231,7 @@
 		    Log.w(TAG, "Error while updating roster entries", e);
 		}
 	    }
-	    mRemoteRosListeners.finishBroadcast();			
+	    mRemoteRosListeners.finishBroadcast();
 	}
     }
 
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Apr 07 01:18:19 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Apr 07 10:25:40 2009 +0200
@@ -73,20 +73,21 @@
      */
     @Override
     public boolean connectSync() throws RemoteException {
-	    try {
-		mAdaptee.connect();
-		mAdaptee.addConnectionListener(mConListener);
-		mAdaptee.login(mLogin, mPassword, "BEEM");
-		mChatManager = new BeemChatManager(mAdaptee.getChatManager());
-		// TODO find why this cause a null pointer exception
-		// this.initFeatures(); // pour declarer les features xmpp qu'on supporte
-		mLastException = null;
-		triggerAsynchronousConnectEvent();
-		return true;
-	    } catch (XMPPException e) {
-		mLastException = new BeemException(e);
-	    }
-	    return false;
+	try {
+	    mAdaptee.connect();
+	    mAdaptee.addConnectionListener(mConListener);
+	    mAdaptee.login(mLogin, mPassword, "BEEM");
+	    mChatManager = new BeemChatManager(mAdaptee.getChatManager());
+	    // TODO find why this cause a null pointer exception
+	    // this.initFeatures(); // pour declarer les features xmpp qu'on supporte
+	    mLastException = null;
+	    triggerAsynchronousConnectEvent();
+	    return true;
+	} catch (XMPPException e) {
+	    Log.e(TAG, "Error while connecting", e);
+	    mLastException = new BeemException(e);
+	}
+	return false;
     }
 
     /**
@@ -106,10 +107,10 @@
     public IRoster getRoster() throws RemoteException {
 	if (mRoster != null)
 	    return mRoster;
-	    Roster adap = mAdaptee.getRoster();
-	    if (adap == null)
-		return null;
-	    mRoster = new RosterAdapter(adap);
+	Roster adap = mAdaptee.getRoster();
+	if (adap == null)
+	    return null;
+	mRoster = new RosterAdapter(adap);
 	return mRoster;
     }
 
@@ -264,6 +265,7 @@
 		} 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();
@@ -311,7 +313,11 @@
 
     }
 
-    public boolean isAuthentificated() throws RemoteException {
+    /**
+     * Returns true if currently authenticated by successfully calling the login method.
+     * @return true when successfully authenticated
+     */
+    public boolean isAuthentificated() {
 	return mAdaptee.isAuthenticated();
     }
 
--- a/src/com/beem/project/beem/ui/ContactList.java	Tue Apr 07 01:18:19 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Tue Apr 07 10:25:40 2009 +0200
@@ -276,7 +276,7 @@
 		 */
 		v = (TextView) view.findViewById(to[2]);
 		if (v != null) {
-		    v.setText(c.getMMsgState());
+		    v.setText(c.getMsgState());
 		}
 
 		/*