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_PROFILE" />
<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.RECEIVE_BOOT_COMPLETED" />
@ -24,6 +25,7 @@
<receiver android:name="eu.siacs.conversations.services.EventReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>

View File

@ -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);
}

View File

@ -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();

View File

@ -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;
}

View File

@ -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();