From e4f61da07924e9440cde5b92c4364b1310c64ce5 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 6 Mar 2014 00:00:16 +0100 Subject: [PATCH 1/4] start service on boot --- AndroidManifest.xml | 35 ++++++++++++------- .../conversations/services/EventReceiver.java | 17 +++++++++ .../siacs/conversations/ui/XmppActivity.java | 2 +- 3 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 src/eu/siacs/conversations/services/EventReceiver.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 0e59383c0..881ed7e36 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -9,28 +9,39 @@ android:targetSdkVersion="19" /> - + - - + + + - + + + + + + + + + android:windowSoftInputMode="stateHidden" > + - + + + @@ -45,25 +56,25 @@ android:label="Manage Accounts" android:parentActivityName="eu.siacs.conversations.ui.ConversationActivity" > - + android:windowSoftInputMode="stateHidden" > + android:windowSoftInputMode="stateHidden" > + android:windowSoftInputMode="stateHidden" > - + \ No newline at end of file diff --git a/src/eu/siacs/conversations/services/EventReceiver.java b/src/eu/siacs/conversations/services/EventReceiver.java new file mode 100644 index 000000000..41e31114f --- /dev/null +++ b/src/eu/siacs/conversations/services/EventReceiver.java @@ -0,0 +1,17 @@ +package eu.siacs.conversations.services; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class EventReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + Intent mIntentForService = new Intent(context, XmppConnectionService.class); + if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { + + } + context.startService(mIntentForService); + } + +} diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index a2951c65a..c1b64f228 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -37,9 +37,9 @@ public abstract class XmppActivity extends Activity { @Override protected void onStart() { - startService(new Intent(this, XmppConnectionService.class)); super.onStart(); if (!xmppConnectionServiceBound) { + startService(new Intent(this, XmppConnectionService.class)); Intent intent = new Intent(this, XmppConnectionService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } From 2f0b2b865e4ec1b34d37120f085a9841ea11d1ed Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 6 Mar 2014 03:30:03 +0100 Subject: [PATCH 2/4] user alarmmanager to reschedule wakeups instead of just sleeping --- .../siacs/conversations/entities/Account.java | 9 +- .../conversations/services/EventReceiver.java | 26 +++- .../services/XmppConnectionService.java | 60 ++++++- .../ui/ManageAccountActivity.java | 146 +++++++++--------- .../siacs/conversations/utils/DNSHelper.java | 7 +- .../conversations/xmpp/XmppConnection.java | 34 ++-- 6 files changed, 169 insertions(+), 113 deletions(-) diff --git a/src/eu/siacs/conversations/entities/Account.java b/src/eu/siacs/conversations/entities/Account.java index a596aba15..52125b032 100644 --- a/src/eu/siacs/conversations/entities/Account.java +++ b/src/eu/siacs/conversations/entities/Account.java @@ -32,11 +32,12 @@ public class Account extends AbstractEntity{ public static final int OPTION_USETLS = 0; public static final int OPTION_DISABLED = 1; - public static final int STATUS_DISABLED = -1; - public static final int STATUS_OFFLINE = 0; + public static final int STATUS_CONNECTING = 0; + public static final int STATUS_DISABLED = -2; + public static final int STATUS_OFFLINE = -1; public static final int STATUS_ONLINE = 1; public static final int STATUS_UNAUTHORIZED = 2; - public static final int STATUS_NOINTERNET = 3; + public static final int STATUS_NO_INTERNET = 3; public static final int STATUS_TLS_ERROR = 4; public static final int STATUS_SERVER_NOT_FOUND = 5; @@ -46,7 +47,7 @@ public class Account extends AbstractEntity{ protected int options = 0; protected String rosterVersion; protected String resource; - protected int status = 0; + protected int status = -1; protected JSONObject keys = new JSONObject(); protected boolean online = false; diff --git a/src/eu/siacs/conversations/services/EventReceiver.java b/src/eu/siacs/conversations/services/EventReceiver.java index 41e31114f..66208bca3 100644 --- a/src/eu/siacs/conversations/services/EventReceiver.java +++ b/src/eu/siacs/conversations/services/EventReceiver.java @@ -3,15 +3,27 @@ package eu.siacs.conversations.services; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; public class EventReceiver extends BroadcastReceiver { @Override - public void onReceive(Context context, Intent intent) { - Intent mIntentForService = new Intent(context, XmppConnectionService.class); - if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { - - } + public void onReceive(Context context, Intent intent) { + Intent mIntentForService = new Intent(context, + XmppConnectionService.class); + if ((intent.getAction() != null) + && (intent.getAction() + .equals("android.intent.action.BOOT_COMPLETED"))) { + + } + ConnectivityManager cm = (ConnectivityManager) context + .getSystemService(Context.CONNECTIVITY_SERVICE); + + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + boolean isConnected = activeNetwork != null + && activeNetwork.isConnected(); + mIntentForService.putExtra("has_internet", isConnected); context.startService(mIntentForService); - } - + } + } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index e973afa9d..8c7d64ce1 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -5,6 +5,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Hashtable; import java.util.List; +import java.util.Random; import org.json.JSONException; import org.openintents.openpgp.util.OpenPgpApi; @@ -42,7 +43,9 @@ import eu.siacs.conversations.xmpp.OnPresencePacketReceived; import eu.siacs.conversations.xmpp.OnStatusChanged; import eu.siacs.conversations.xmpp.PresencePacket; import eu.siacs.conversations.xmpp.XmppConnection; +import android.app.AlarmManager; import android.app.NotificationManager; +import android.app.PendingIntent; import android.app.Service; import android.content.Context; import android.content.Intent; @@ -53,6 +56,7 @@ import android.os.Binder; import android.os.Bundle; import android.os.IBinder; import android.os.PowerManager; +import android.os.SystemClock; import android.preference.PreferenceManager; import android.provider.ContactsContract; import android.util.Log; @@ -70,6 +74,8 @@ public class XmppConnectionService extends Service { public OnConversationListChangedListener convChangedListener = null; private OnAccountListChangedListener accountChangedListener = null; + + private Random mRandom = new Random(System.currentTimeMillis()); private ContentObserver contactObserver = new ContentObserver(null) { @Override @@ -183,6 +189,14 @@ public class XmppConnectionService extends Service { // } } + } else if (account.getStatus() == Account.STATUS_OFFLINE) { + Log.d(LOGTAG,"onStatusChanged offline"); + databaseBackend.clearPresences(account); + if (!account.isOptionSet(Account.OPTION_DISABLED)) { + int timeToReconnect = mRandom.nextInt(50)+10; + scheduleWakeupCall(timeToReconnect); + } + } } }; @@ -364,10 +378,39 @@ public class XmppConnectionService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + boolean internet; + if ((intent!=null)&&(intent.hasExtra("has_internet"))) { + if (intent.getExtras().getBoolean("has_internet",true)) { + internet = true; + } else { + internet = false; + } + } else { + internet = true; + } for (Account account : accounts) { + if (!internet) { + account.setStatus(Account.STATUS_NO_INTERNET); + break; + } else { + if (account.getStatus() == Account.STATUS_NO_INTERNET) { + account.setStatus(Account.STATUS_OFFLINE); + } + } if (account.getXmppConnection() == null) { - if (!account.isOptionSet(Account.OPTION_DISABLED)) { + if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(internet)) { account.setXmppConnection(this.createConnection(account)); + Thread thread = new Thread(account.getXmppConnection()); + thread.start(); + } + } else { + if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(internet)) { + if (account.getStatus()==Account.STATUS_OFFLINE) { + Thread thread = new Thread(account.getXmppConnection()); + thread.start(); + } + } else { + disconnect(account); } } } @@ -384,6 +427,8 @@ public class XmppConnectionService extends Service { this.pgpServiceConnection = new OpenPgpServiceConnection( getApplicationContext(), "org.sufficientlysecure.keychain"); this.pgpServiceConnection.bindToService(); + + } @Override @@ -395,6 +440,17 @@ public class XmppConnectionService extends Service { } } } + + protected void scheduleWakeupCall(int seconds) { + Context context = getApplicationContext(); + AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + Intent intent = new Intent(context, EventReceiver.class); + PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); + alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, + SystemClock.elapsedRealtime() + + seconds * 1000, alarmIntent); + Log.d(LOGTAG,"wake up call scheduled in "+seconds+" seconds"); + } public XmppConnection createConnection(Account account) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); @@ -404,8 +460,6 @@ public class XmppConnectionService extends Service { connection.setOnPresencePacketReceivedListener(this.presenceListener); connection .setOnUnregisteredIqPacketReceivedListener(this.unknownIqListener); - Thread thread = new Thread(connection); - thread.start(); return connection; } diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 5d9c4059a..1a5ee902c 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -32,7 +32,7 @@ import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; -public class ManageAccountActivity extends XmppActivity implements ActionMode.Callback { +public class ManageAccountActivity extends XmppActivity { public static final int REQUEST_ANNOUNCE_PGP = 0x73731; @@ -54,10 +54,6 @@ public class ManageAccountActivity extends XmppActivity implements ActionMode.Ca @Override public void run() { - if (accountList.size() == 1) { - startActivity(new Intent(getApplicationContext(), - NewConversationActivity.class)); - } accountListViewAdapter.notifyDataSetChanged(); } }); @@ -113,7 +109,7 @@ public class ManageAccountActivity extends XmppActivity implements ActionMode.Ca return view; } }; - final Activity activity = this; + final XmppActivity activity = this; accountListView.setAdapter(this.accountListViewAdapter); accountListView.setOnItemClickListener(new OnItemClickListener() { @@ -146,7 +142,76 @@ public class ManageAccountActivity extends XmppActivity implements ActionMode.Ca accountListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); accountListView.setItemChecked(position,true); selectedAccountForActionMode = accountList.get(position); - actionMode = activity.startActionMode((Callback) activity); + actionMode = activity.startActionMode((new ActionMode.Callback() { + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + if (selectedAccountForActionMode.isOptionSet(Account.OPTION_DISABLED)) { + menu.findItem(R.id.account_enable).setVisible(true); + menu.findItem(R.id.account_disable).setVisible(false); + } else { + menu.findItem(R.id.account_disable).setVisible(true); + menu.findItem(R.id.account_enable).setVisible(false); + } + return true; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + // TODO Auto-generated method stub + + } + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + MenuInflater inflater = mode.getMenuInflater(); + inflater.inflate(R.menu.manageaccounts_context, menu); + return true; + } + + @Override + public boolean onActionItemClicked(final ActionMode mode, MenuItem item) { + if (item.getItemId()==R.id.account_disable) { + selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, true); + xmppConnectionService.updateAccount(selectedAccountForActionMode); + mode.finish(); + } else if (item.getItemId()==R.id.account_enable) { + selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, false); + xmppConnectionService.updateAccount(selectedAccountForActionMode); + mode.finish(); + } else if (item.getItemId()==R.id.account_delete) { + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle("Are you sure?"); + builder.setIconAttribute(android.R.attr.alertDialogIcon); + builder.setMessage("If you delete your account your entire conversation history will be lost"); + builder.setPositiveButton("Delete", new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + xmppConnectionService.deleteAccount(selectedAccountForActionMode); + selectedAccountForActionMode = null; + mode.finish(); + } + }); + builder.setNegativeButton("Cancel",null); + builder.create().show(); + } else if (item.getItemId()==R.id.announce_pgp) { + if (activity.hasPgp()) { + mode.finish(); + try { + xmppConnectionService.generatePgpAnnouncement(selectedAccountForActionMode); + } catch (PgpEngine.UserInputRequiredException e) { + try { + startIntentSenderForResult(e.getPendingIntent().getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); + } catch (SendIntentException e1) { + Log.d("gultsch","sending intent failed"); + } + } + } + } + return true; + } + })); return true; } else { return false; @@ -210,73 +275,6 @@ public class ManageAccountActivity extends XmppActivity implements ActionMode.Ca dialog.show(getFragmentManager(), "add_account"); } - @Override - public boolean onActionItemClicked(final ActionMode mode, MenuItem item) { - if (item.getItemId()==R.id.account_disable) { - selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, true); - xmppConnectionService.updateAccount(selectedAccountForActionMode); - mode.finish(); - } else if (item.getItemId()==R.id.account_enable) { - selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, false); - xmppConnectionService.updateAccount(selectedAccountForActionMode); - mode.finish(); - } else if (item.getItemId()==R.id.account_delete) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Are you sure?"); - builder.setIconAttribute(android.R.attr.alertDialogIcon); - builder.setMessage("If you delete your account your entire conversation history will be lost"); - builder.setPositiveButton("Delete", new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - xmppConnectionService.deleteAccount(selectedAccountForActionMode); - selectedAccountForActionMode = null; - mode.finish(); - } - }); - builder.setNegativeButton("Cancel",null); - builder.create().show(); - } else if (item.getItemId()==R.id.announce_pgp) { - if (this.hasPgp()) { - mode.finish(); - try { - xmppConnectionService.generatePgpAnnouncement(selectedAccountForActionMode); - } catch (PgpEngine.UserInputRequiredException e) { - try { - startIntentSenderForResult(e.getPendingIntent().getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); - } catch (SendIntentException e1) { - Log.d("gultsch","sending intent failed"); - } - } - } - } - return true; - } - - @Override - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - MenuInflater inflater = mode.getMenuInflater(); - inflater.inflate(R.menu.manageaccounts_context, menu); - return true; - } - - @Override - public void onDestroyActionMode(ActionMode mode) { - // TODO Auto-generated method stub - - } - - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - if (selectedAccountForActionMode.isOptionSet(Account.OPTION_DISABLED)) { - menu.findItem(R.id.account_enable).setVisible(true); - menu.findItem(R.id.account_disable).setVisible(false); - } else { - menu.findItem(R.id.account_disable).setVisible(true); - menu.findItem(R.id.account_enable).setVisible(false); - } - return true; - } @Override public void onActionModeStarted(ActionMode mode) { diff --git a/src/eu/siacs/conversations/utils/DNSHelper.java b/src/eu/siacs/conversations/utils/DNSHelper.java index 46fd69286..21d58edca 100644 --- a/src/eu/siacs/conversations/utils/DNSHelper.java +++ b/src/eu/siacs/conversations/utils/DNSHelper.java @@ -8,12 +8,10 @@ import java.net.InetAddress; import java.util.Random; import android.os.Bundle; -import android.util.Log; public class DNSHelper { - public static Bundle getSRVRecord(String host) { + public static Bundle getSRVRecord(String host) throws IOException { Bundle namePort = new Bundle(); - try { String[] hostParts = host.split("\\."); byte[] transId = new byte[2]; Random random = new Random(); @@ -70,9 +68,6 @@ public class DNSHelper { } builder.replace(0, 1, ""); namePort.putString("name",builder.toString()); - } catch (IOException e) { - Log.d("xmppService","gut" + e.getMessage()); - } return namePort; } diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index c426a8381..3b3faaed5 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -69,6 +69,7 @@ public class XmppConnection implements Runnable { protected void connect() { try { + account.setStatus(Account.STATUS_CONNECTING); Bundle namePort = DNSHelper.getSRVRecord(account.getServer()); String srvRecordServer = namePort.getString("name"); int srvRecordPort = namePort.getInt("port"); @@ -103,18 +104,24 @@ public class XmppConnection implements Runnable { if (statusListener != null) { statusListener.onStatusChanged(account); } + if (wakeLock.isHeld()) { + wakeLock.release(); + } return; } catch (IOException e) { - Log.d(LOGTAG, "bla " + e.getMessage()); - if (shouldConnect) { - Log.d(LOGTAG, account.getJid() + ": connection lost"); - account.setStatus(Account.STATUS_OFFLINE); - if (statusListener != null) { - statusListener.onStatusChanged(account); - } + account.setStatus(Account.STATUS_OFFLINE); + if (statusListener != null) { + statusListener.onStatusChanged(account); } + if (wakeLock.isHeld()) { + wakeLock.release(); + } + return; } catch (XmlPullParserException e) { Log.d(LOGTAG, "xml exception " + e.getMessage()); + if (wakeLock.isHeld()) { + wakeLock.release(); + } return; } @@ -122,18 +129,7 @@ public class XmppConnection implements Runnable { @Override public void run() { - shouldConnect = true; - while (shouldConnect) { - connect(); - try { - if (shouldConnect) { - Thread.sleep(30000); - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + connect(); Log.d(LOGTAG, "end run"); } From ac93f7419a40d9f94203d58dc00a5b51bea42ba5 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 6 Mar 2014 03:57:29 +0100 Subject: [PATCH 3/4] bug fixes. stuff more smoother --- AndroidManifest.xml | 2 ++ .../conversations/services/EventReceiver.java | 10 -------- .../services/XmppConnectionService.java | 24 +++++++++---------- .../ui/ManageAccountActivity.java | 8 +++++++ .../conversations/xmpp/XmppConnection.java | 20 +++++++++------- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 881ed7e36..7855986d2 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -11,6 +11,7 @@ + @@ -24,6 +25,7 @@ + diff --git a/src/eu/siacs/conversations/services/EventReceiver.java b/src/eu/siacs/conversations/services/EventReceiver.java index 66208bca3..d58fb2ec3 100644 --- a/src/eu/siacs/conversations/services/EventReceiver.java +++ b/src/eu/siacs/conversations/services/EventReceiver.java @@ -3,9 +3,6 @@ package eu.siacs.conversations.services; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; - public class EventReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { @@ -16,13 +13,6 @@ public class EventReceiver extends BroadcastReceiver { .equals("android.intent.action.BOOT_COMPLETED"))) { } - ConnectivityManager cm = (ConnectivityManager) context - .getSystemService(Context.CONNECTIVITY_SERVICE); - - NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); - boolean isConnected = activeNetwork != null - && activeNetwork.isConnected(); - mIntentForService.putExtra("has_internet", isConnected); context.startService(mIntentForService); } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 8c7d64ce1..a10ffb2be 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -52,6 +52,8 @@ import android.content.Intent; import android.content.SharedPreferences; import android.database.ContentObserver; import android.database.DatabaseUtils; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.os.Binder; import android.os.Bundle; import android.os.IBinder; @@ -378,19 +380,15 @@ public class XmppConnectionService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { - boolean internet; - if ((intent!=null)&&(intent.hasExtra("has_internet"))) { - if (intent.getExtras().getBoolean("has_internet",true)) { - internet = true; - } else { - internet = false; - } - } else { - internet = true; - } + ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); + + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + boolean isConnected = activeNetwork != null + && activeNetwork.isConnected(); for (Account account : accounts) { - if (!internet) { + if (!isConnected) { account.setStatus(Account.STATUS_NO_INTERNET); + Log.d(LOGTAG,"set no internet status to account"); break; } else { if (account.getStatus() == Account.STATUS_NO_INTERNET) { @@ -398,13 +396,13 @@ public class XmppConnectionService extends Service { } } if (account.getXmppConnection() == null) { - if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(internet)) { + if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(isConnected)) { account.setXmppConnection(this.createConnection(account)); Thread thread = new Thread(account.getXmppConnection()); thread.start(); } } else { - if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(internet)) { + if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(isConnected)) { if (account.getStatus()==Account.STATUS_OFFLINE) { Thread thread = new Thread(account.getXmppConnection()); thread.start(); diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 1a5ee902c..768241147 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -90,6 +90,10 @@ public class ManageAccountActivity extends XmppActivity { statusView.setText("online"); statusView.setTextColor(0xFF83b600); break; + case Account.STATUS_CONNECTING: + statusView.setText("connecting\u2026"); + statusView.setTextColor(0xFF1da9da); + break; case Account.STATUS_OFFLINE: statusView.setText("offline"); statusView.setTextColor(0xFFe92727); @@ -102,6 +106,10 @@ public class ManageAccountActivity extends XmppActivity { statusView.setText("server not found"); statusView.setTextColor(0xFFe92727); break; + case Account.STATUS_NO_INTERNET: + statusView.setText("no internet"); + statusView.setTextColor(0xFFe92727); + break; default: break; } diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 3b3faaed5..ec395de31 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -66,10 +66,17 @@ public class XmppConnection implements Runnable { tagReader = new XmlReader(wakeLock); tagWriter = new TagWriter(); } + + protected void changeStatus(int nextStatus) { + account.setStatus(nextStatus); + if (statusListener != null) { + statusListener.onStatusChanged(account); + } + } protected void connect() { try { - account.setStatus(Account.STATUS_CONNECTING); + this.changeStatus(Account.STATUS_CONNECTING); Bundle namePort = DNSHelper.getSRVRecord(account.getServer()); String srvRecordServer = namePort.getString("name"); int srvRecordPort = namePort.getInt("port"); @@ -100,24 +107,19 @@ public class XmppConnection implements Runnable { socket.close(); } } catch (UnknownHostException e) { - account.setStatus(Account.STATUS_SERVER_NOT_FOUND); - if (statusListener != null) { - statusListener.onStatusChanged(account); - } + this.changeStatus(Account.STATUS_SERVER_NOT_FOUND); if (wakeLock.isHeld()) { wakeLock.release(); } return; } catch (IOException e) { - account.setStatus(Account.STATUS_OFFLINE); - if (statusListener != null) { - statusListener.onStatusChanged(account); - } + this.changeStatus(Account.STATUS_OFFLINE); if (wakeLock.isHeld()) { wakeLock.release(); } return; } catch (XmlPullParserException e) { + this.changeStatus(Account.STATUS_OFFLINE); Log.d(LOGTAG, "xml exception " + e.getMessage()); if (wakeLock.isHeld()) { wakeLock.release(); From 0168f185ebb209dbfb69cb19bf221354c9a8561a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 6 Mar 2014 04:13:21 +0100 Subject: [PATCH 4/4] bug fixes --- .../services/XmppConnectionService.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index a10ffb2be..143d30795 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -388,28 +388,22 @@ public class XmppConnectionService extends Service { for (Account account : accounts) { if (!isConnected) { account.setStatus(Account.STATUS_NO_INTERNET); - Log.d(LOGTAG,"set no internet status to account"); - break; } else { if (account.getStatus() == Account.STATUS_NO_INTERNET) { account.setStatus(Account.STATUS_OFFLINE); } } - if (account.getXmppConnection() == null) { - if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(isConnected)) { + if (accountChangedListener!=null) { + accountChangedListener.onAccountListChangedListener(); + } + if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(isConnected)) { + if (account.getXmppConnection() == null) { account.setXmppConnection(this.createConnection(account)); + } + if (account.getStatus()==Account.STATUS_OFFLINE) { Thread thread = new Thread(account.getXmppConnection()); thread.start(); } - } else { - if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(isConnected)) { - if (account.getStatus()==Account.STATUS_OFFLINE) { - Thread thread = new Thread(account.getXmppConnection()); - thread.start(); - } - } else { - disconnect(account); - } } } return START_STICKY;