ajout du debut de la gestion d'erreur de connection bout en bout, il
faudra rajouter les differents evenements.
--- a/src/com/beem/project/beem/BeemApplication.java Wed Apr 08 20:11:24 2009 +0200
+++ b/src/com/beem/project/beem/BeemApplication.java Thu Apr 09 17:58:19 2009 +0200
@@ -19,6 +19,8 @@
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
+import android.util.Log;
+import android.widget.Toast;
import com.beem.project.beem.service.aidl.IBeemConnectionListener;
import com.beem.project.beem.service.aidl.IXmppConnection;
@@ -31,7 +33,9 @@
public class BeemApplication extends Application {
private static BeemApplication mBeemApp;
+ private Activity mActivity;
private static final Intent SERVICE_INTENT = new Intent();
+ public static final String TAG = "BeemApplication";
private IXmppFacade mFacade;
private Context mApplicationContext;
private Resources mPrivateResources;
@@ -87,6 +91,7 @@
if (mBeemApp == null) {
mBeemApp = new BeemApplication();
}
+ mBeemApp.mActivity = activity;
mBeemApp.mProgressDialog = new ProgressDialog(activity);
mBeemApp.mProgressDialog.setTitle("Beem");
mBeemApp.mProgressDialog.setIcon(R.drawable.logo);
@@ -153,6 +158,34 @@
return mIsConnected;
}
+ private class ConnectionRunnable implements Runnable {
+ private String mErrorMsg;
+
+ public ConnectionRunnable(String string) {
+ this.mErrorMsg = string;
+ }
+
+ @Override
+ public void run() {
+ mBeemApp.mProgressDialog.setMessage("Connection failed");
+ }
+
+ /**
+ * @param mErrorMsg the mErrorMsg to set
+ */
+ public void setMErrorMsg(String mErrorMsg) {
+ this.mErrorMsg = mErrorMsg;
+ }
+
+ /**
+ * @return the mErrorMsg
+ */
+ public String getMErrorMsg() {
+ return mErrorMsg;
+ }
+
+ }
+
/**
* Connection listener use to hide the progress dialog.
* @author darisk
@@ -172,6 +205,7 @@
@Override
public void connectionClosed() throws RemoteException {
// TODO Auto-generated method stub
+ Log.e("BeemApp","test1");
}
@@ -180,7 +214,8 @@
*/
@Override
public void connectionClosedOnError() throws RemoteException {
- // TODO Auto-generated method stub
+ mBeemApp.mProgressDialog.setMessage("Connexion closed on error");
+ Log.e(TAG,"onnectionClosedOnError");
// afficher une notification et reafficher le progress dialog
}
@@ -215,6 +250,7 @@
@Override
public void reconnectionFailed() throws RemoteException {
// TODO Auto-generated method stub
+ Log.e("BeemApp","test3");
}
@@ -227,6 +263,13 @@
}
+ @Override
+ public void connectionFailed() throws RemoteException {
+ Log.i(TAG, "Connection Failed");
+ ConnectionRunnable cRun = new ConnectionRunnable("Connection failed");
+ mBeemApp.mActivity.runOnUiThread(cRun);
+ }
+
}
}
--- a/src/com/beem/project/beem/BeemService.java Wed Apr 08 20:11:24 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java Thu Apr 09 17:58:19 2009 +0200
@@ -77,7 +77,7 @@
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";
+ mHost = "10.0.2.5";
initConnectionConfig();
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword);
@@ -137,95 +137,99 @@
}
mConnectionConfiguration.setSendPresence(true);
}
-
+
private void initRosterRequestListener() {
Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
final XMPPConnection con = mConnection.getAdaptee();
try {
// l'ajout d'un packet listener ne peut etre effectuer que lorsqu'on est connecte au serveur
mConnection.addConnectionListener(new IBeemConnectionListener.Stub() {
-
- @Override
- public void reconnectionSuccessful() throws RemoteException {
- // TODO Auto-generated method stub
- 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;
- }
- };
- con.addPacketListener(new PacketListener() {
-
- @Override
- public void processPacket(Packet packet) {
- // TODO Auto-generated method stub
- Log.i("TEST", "Une demande recue");
- }
- }, filter);
-
- }
-
- @Override
- public void reconnectionFailed() throws RemoteException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void reconnectingIn(int seconds) throws RemoteException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onConnect() throws RemoteException {
- // TODO Auto-generated method stub
- 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;
- }
- };
- con.addPacketListener(new PacketListener() {
-
- @Override
- public void processPacket(Packet packet) {
- // TODO Auto-generated method stub
- Log.i("TEST", "Une demande recue");
- }
- }, filter);
-
- }
-
- @Override
- public void connectionClosedOnError() throws RemoteException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void connectionClosed() throws RemoteException {
- // TODO Auto-generated method stub
-
- }
+
+ @Override
+ public void reconnectionSuccessful() throws RemoteException {
+ // TODO Auto-generated method stub
+ 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;
+ }
+ };
+ con.addPacketListener(new PacketListener() {
+
+ @Override
+ public void processPacket(Packet packet) {
+ // TODO Auto-generated method stub
+ Log.i("TEST", "Une demande recue");
+ }
+ }, filter);
+ }
+
+ @Override
+ public void reconnectionFailed() throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void reconnectingIn(int seconds) throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onConnect() throws RemoteException {
+ // TODO Auto-generated method stub
+ 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;
+ }
+ };
+ con.addPacketListener(new PacketListener() {
+
+ @Override
+ public void processPacket(Packet packet) {
+ // TODO Auto-generated method stub
+ Log.i("TEST", "Une demande recue");
+ }
+ }, filter);
+
+ }
+
+ @Override
+ public void connectionClosedOnError() throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void connectionClosed() throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void connectionFailed() throws RemoteException {
+ Log.d("TEST", "Connection Failed");
+ }
});
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
+
}
/**
--- a/src/com/beem/project/beem/service/BeemChatManager.java Wed Apr 08 20:11:24 2009 +0200
+++ b/src/com/beem/project/beem/service/BeemChatManager.java Thu Apr 09 17:58:19 2009 +0200
@@ -11,6 +11,8 @@
import org.jivesoftware.smack.ChatManagerListener;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smackx.ChatState;
+import org.jivesoftware.smackx.ChatStateListener;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
@@ -88,7 +90,7 @@
public void removeChatCreationListener(IChatManagerListener listener) throws RemoteException {
mRemoteChatCreationListeners.unregister(listener);
}
-
+
private IChat getChat(Chat chat) {
if (mChats.containsKey(chat.getParticipant())) {
return mChats.get(chat.getParticipant());
@@ -102,13 +104,12 @@
* A listener for all the chat creation event that happens on the connection.
* @author darisk
*/
- private class ChatListener implements ChatManagerListener, MessageListener {
+ private class ChatListener implements ChatStateListener, ChatManagerListener, MessageListener {
/**
* Constructor.
*/
public ChatListener() {
- // TODO Auto-generated constructor stub
}
/**
@@ -138,8 +139,8 @@
@Override
public void processMessage(Chat chat, Message message) {
IChat newchat = getChat(chat);
- final int n = mRemoteMessageListeners.beginBroadcast();
- for (int i = 0; i < n; i++) {
+ final int n = mRemoteMessageListeners.beginBroadcast();
+ for (int i = 0; i < n; i++) {
IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i);
try {
listener.processMessage(newchat, new com.beem.project.beem.service.Message(message));
@@ -152,6 +153,15 @@
}
mRemoteMessageListeners.finishBroadcast();
}
+
+ @Override
+ public void stateChanged(Chat chat, ChatState state) {
+ try {
+ mChats.get(chat.getParticipant()).setState(state.name());
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
}
}
--- a/src/com/beem/project/beem/service/ChatAdapter.java Wed Apr 08 20:11:24 2009 +0200
+++ b/src/com/beem/project/beem/service/ChatAdapter.java Thu Apr 09 17:58:19 2009 +0200
@@ -17,6 +17,7 @@
public class ChatAdapter extends IChat.Stub {
private Chat mAdaptee;
private Contact mParticipant;
+ private String mState;
/**
* Constructor.
@@ -56,4 +57,14 @@
}
}
+ @Override
+ public String getState() throws RemoteException {
+ return mState;
+ }
+
+ @Override
+ public void setState(String state) throws RemoteException {
+ mState = state;
+ }
+
}
--- a/src/com/beem/project/beem/service/Contact.java Wed Apr 08 20:11:24 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java Thu Apr 09 17:58:19 2009 +0200
@@ -6,7 +6,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
@@ -163,6 +162,7 @@
* @param presence the presence containing status
*/
public void setStatus(Presence presence) {
+ Log.i(TAG,"PRESENCE");
if (presence.getType().equals(Presence.Type.unavailable)) {
Log.d(TAG, "Presence pas dispo");
mStatus = Contact.CONTACT_STATUS_DISCONNECT;
--- a/src/com/beem/project/beem/service/RosterAdapter.java Wed Apr 08 20:11:24 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java Thu Apr 09 17:58:19 2009 +0200
@@ -42,6 +42,7 @@
* @param roster the roster to adapt
*/
public RosterAdapter(final Roster roster) {
+ Log.d(TAG, "CTOR");
mAdaptee = roster;
roster.addRosterListener(mRosterListener);
for (RosterEntry entry : roster.getEntries()) {
@@ -185,7 +186,7 @@
*/
@Override
public void entriesUpdated(Collection<String> addresses) {
- Log.i(TAG, "Update de l'entry");
+ Log.d(TAG, "Update de l'entry");
final int n = mRemoteRosListeners.beginBroadcast();
List<String> tab = new ArrayList<String>();
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Wed Apr 08 20:11:24 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Thu Apr 09 17:58:19 2009 +0200
@@ -4,10 +4,12 @@
package com.beem.project.beem.service;
import org.jivesoftware.smack.ConnectionConfiguration;
+import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.jingle.JingleManager;
import android.os.RemoteCallbackList;
@@ -85,6 +87,7 @@
return true;
} catch (XMPPException e) {
Log.e(TAG, "Error while connecting", e);
+ mConListener.connectionFailed();
mLastException = new BeemException(e);
}
return false;
@@ -310,7 +313,23 @@
}
mRemoteConnListeners.finishBroadcast();
}
+
+ public void connectionFailed() {
+ Log.i(TAG, "Connection Failed");
+ final int n = mRemoteConnListeners.beginBroadcast();
+ for (int i = 0; i < n; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ listener.connectionFailed();
+ } 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();
+ }
}
/**
--- a/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Wed Apr 08 20:11:24 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Thu Apr 09 17:58:19 2009 +0200
@@ -36,4 +36,9 @@
* Callback to call when the reconnection is successfull
*/
void reconnectionSuccessful();
+
+ /**
+ * Callback to call when the connection Failed
+ */
+ void connectionFailed();
}
--- a/src/com/beem/project/beem/service/aidl/IChat.aidl Wed Apr 08 20:11:24 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IChat.aidl Thu Apr 09 17:58:19 2009 +0200
@@ -18,5 +18,9 @@
* Get the participant of the chat
* @return the participant
*/
- Contact getParticipant();
+ Contact getParticipant();
+
+ String getState();
+
+ void setState(String state);
}
\ No newline at end of file