bug fixes. stuff more smoother

This commit is contained in:
Daniel Gultsch 2014-03-06 03:57:29 +01:00
parent 2f0b2b865e
commit ac93f7419a
5 changed files with 32 additions and 32 deletions

View File

@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PROFILE" /> <uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
@ -24,6 +25,7 @@
<receiver android:name="eu.siacs.conversations.services.EventReceiver" > <receiver android:name="eu.siacs.conversations.services.EventReceiver" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter> </intent-filter>
</receiver> </receiver>

View File

@ -3,9 +3,6 @@ package eu.siacs.conversations.services;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class EventReceiver extends BroadcastReceiver { public class EventReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -16,13 +13,6 @@ public class EventReceiver extends BroadcastReceiver {
.equals("android.intent.action.BOOT_COMPLETED"))) { .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); context.startService(mIntentForService);
} }

View File

@ -52,6 +52,8 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.database.DatabaseUtils; import android.database.DatabaseUtils;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Binder; import android.os.Binder;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
@ -378,19 +380,15 @@ public class XmppConnectionService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
boolean internet; ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
if ((intent!=null)&&(intent.hasExtra("has_internet"))) {
if (intent.getExtras().getBoolean("has_internet",true)) { NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
internet = true; boolean isConnected = activeNetwork != null
} else { && activeNetwork.isConnected();
internet = false;
}
} else {
internet = true;
}
for (Account account : accounts) { for (Account account : accounts) {
if (!internet) { if (!isConnected) {
account.setStatus(Account.STATUS_NO_INTERNET); account.setStatus(Account.STATUS_NO_INTERNET);
Log.d(LOGTAG,"set no internet status to account");
break; break;
} else { } else {
if (account.getStatus() == Account.STATUS_NO_INTERNET) { if (account.getStatus() == Account.STATUS_NO_INTERNET) {
@ -398,13 +396,13 @@ public class XmppConnectionService extends Service {
} }
} }
if (account.getXmppConnection() == null) { if (account.getXmppConnection() == null) {
if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(internet)) { if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(isConnected)) {
account.setXmppConnection(this.createConnection(account)); account.setXmppConnection(this.createConnection(account));
Thread thread = new Thread(account.getXmppConnection()); Thread thread = new Thread(account.getXmppConnection());
thread.start(); thread.start();
} }
} else { } else {
if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(internet)) { if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(isConnected)) {
if (account.getStatus()==Account.STATUS_OFFLINE) { if (account.getStatus()==Account.STATUS_OFFLINE) {
Thread thread = new Thread(account.getXmppConnection()); Thread thread = new Thread(account.getXmppConnection());
thread.start(); thread.start();

View File

@ -90,6 +90,10 @@ public class ManageAccountActivity extends XmppActivity {
statusView.setText("online"); statusView.setText("online");
statusView.setTextColor(0xFF83b600); statusView.setTextColor(0xFF83b600);
break; break;
case Account.STATUS_CONNECTING:
statusView.setText("connecting\u2026");
statusView.setTextColor(0xFF1da9da);
break;
case Account.STATUS_OFFLINE: case Account.STATUS_OFFLINE:
statusView.setText("offline"); statusView.setText("offline");
statusView.setTextColor(0xFFe92727); statusView.setTextColor(0xFFe92727);
@ -102,6 +106,10 @@ public class ManageAccountActivity extends XmppActivity {
statusView.setText("server not found"); statusView.setText("server not found");
statusView.setTextColor(0xFFe92727); statusView.setTextColor(0xFFe92727);
break; break;
case Account.STATUS_NO_INTERNET:
statusView.setText("no internet");
statusView.setTextColor(0xFFe92727);
break;
default: default:
break; break;
} }

View File

@ -66,10 +66,17 @@ public class XmppConnection implements Runnable {
tagReader = new XmlReader(wakeLock); tagReader = new XmlReader(wakeLock);
tagWriter = new TagWriter(); tagWriter = new TagWriter();
} }
protected void changeStatus(int nextStatus) {
account.setStatus(nextStatus);
if (statusListener != null) {
statusListener.onStatusChanged(account);
}
}
protected void connect() { protected void connect() {
try { try {
account.setStatus(Account.STATUS_CONNECTING); this.changeStatus(Account.STATUS_CONNECTING);
Bundle namePort = DNSHelper.getSRVRecord(account.getServer()); Bundle namePort = DNSHelper.getSRVRecord(account.getServer());
String srvRecordServer = namePort.getString("name"); String srvRecordServer = namePort.getString("name");
int srvRecordPort = namePort.getInt("port"); int srvRecordPort = namePort.getInt("port");
@ -100,24 +107,19 @@ public class XmppConnection implements Runnable {
socket.close(); socket.close();
} }
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
account.setStatus(Account.STATUS_SERVER_NOT_FOUND); this.changeStatus(Account.STATUS_SERVER_NOT_FOUND);
if (statusListener != null) {
statusListener.onStatusChanged(account);
}
if (wakeLock.isHeld()) { if (wakeLock.isHeld()) {
wakeLock.release(); wakeLock.release();
} }
return; return;
} catch (IOException e) { } catch (IOException e) {
account.setStatus(Account.STATUS_OFFLINE); this.changeStatus(Account.STATUS_OFFLINE);
if (statusListener != null) {
statusListener.onStatusChanged(account);
}
if (wakeLock.isHeld()) { if (wakeLock.isHeld()) {
wakeLock.release(); wakeLock.release();
} }
return; return;
} catch (XmlPullParserException e) { } catch (XmlPullParserException e) {
this.changeStatus(Account.STATUS_OFFLINE);
Log.d(LOGTAG, "xml exception " + e.getMessage()); Log.d(LOGTAG, "xml exception " + e.getMessage());
if (wakeLock.isHeld()) { if (wakeLock.isHeld()) {
wakeLock.release(); wakeLock.release();