2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.services;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2017-10-01 16:44:28 +00:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.util.Log;
|
2014-10-22 16:38:44 +00:00
|
|
|
|
2017-10-01 16:44:28 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2015-07-20 12:26:29 +00:00
|
|
|
import eu.siacs.conversations.persistance.DatabaseBackend;
|
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
public class EventReceiver extends BroadcastReceiver {
|
2017-10-01 16:44:28 +00:00
|
|
|
|
|
|
|
public static final String SETTING_ENABLED_ACCOUNTS = "enabled_accounts";
|
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2017-09-22 11:31:00 +00:00
|
|
|
Intent mIntentForService = new Intent(context, XmppConnectionService.class);
|
2014-10-22 16:38:44 +00:00
|
|
|
if (intent.getAction() != null) {
|
|
|
|
mIntentForService.setAction(intent.getAction());
|
|
|
|
} else {
|
|
|
|
mIntentForService.setAction("other");
|
|
|
|
}
|
2016-08-09 17:21:54 +00:00
|
|
|
final String action = intent.getAction();
|
2017-10-01 16:44:28 +00:00
|
|
|
if (action.equals("ui") || hasEnabledAccounts(context)) {
|
2014-10-22 16:38:44 +00:00
|
|
|
context.startService(mIntentForService);
|
2017-10-01 16:44:28 +00:00
|
|
|
} else {
|
|
|
|
Log.d(Config.LOGTAG,"EventReceiver ignored action "+mIntentForService.getAction());
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-01 16:44:28 +00:00
|
|
|
public boolean hasEnabledAccounts(Context context) {
|
|
|
|
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTING_ENABLED_ACCOUNTS,true);
|
|
|
|
}
|
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|