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;
|
2019-02-27 13:16:26 +00:00
|
|
|
import android.os.Bundle;
|
2017-10-01 16:44:28 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2021-01-18 17:26:46 +00:00
|
|
|
import androidx.core.content.ContextCompat;
|
2017-10-01 16:44:28 +00:00
|
|
|
import android.util.Log;
|
2014-10-22 16:38:44 +00:00
|
|
|
|
2020-08-19 11:57:33 +00:00
|
|
|
import com.google.common.base.Strings;
|
|
|
|
|
2017-10-01 16:44:28 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2018-09-18 09:33:18 +00:00
|
|
|
import eu.siacs.conversations.utils.Compatibility;
|
2015-07-20 12:26:29 +00:00
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
public class EventReceiver extends BroadcastReceiver {
|
2017-10-01 16:44:28 +00:00
|
|
|
|
2018-11-17 11:57:36 +00:00
|
|
|
public static final String SETTING_ENABLED_ACCOUNTS = "enabled_accounts";
|
|
|
|
public static final String EXTRA_NEEDS_FOREGROUND_SERVICE = "needs_foreground_service";
|
2017-10-01 16:44:28 +00:00
|
|
|
|
2018-11-17 11:57:36 +00:00
|
|
|
@Override
|
|
|
|
public void onReceive(final Context context, final Intent originalIntent) {
|
|
|
|
final Intent intentForService = new Intent(context, XmppConnectionService.class);
|
|
|
|
final String action = originalIntent.getAction();
|
2020-08-19 11:57:33 +00:00
|
|
|
intentForService.setAction(Strings.isNullOrEmpty(action) ? "other" : action);
|
|
|
|
final Bundle extras = originalIntent.getExtras();
|
|
|
|
if (extras != null) {
|
|
|
|
intentForService.putExtras(extras);
|
|
|
|
}
|
2021-01-19 14:45:41 +00:00
|
|
|
if ("ui".equals(action) || QuickConversationsService.SMS_RETRIEVED_ACTION.equals(action) || hasEnabledAccounts(context)) {
|
2019-01-13 08:42:44 +00:00
|
|
|
Compatibility.startService(context, intentForService);
|
2018-11-17 11:57:36 +00:00
|
|
|
} else {
|
|
|
|
Log.d(Config.LOGTAG, "EventReceiver ignored action " + intentForService.getAction());
|
|
|
|
}
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
|
2018-11-17 11:57:36 +00:00
|
|
|
public static boolean hasEnabledAccounts(final Context context) {
|
|
|
|
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTING_ENABLED_ACCOUNTS, true);
|
|
|
|
}
|
2017-10-01 16:44:28 +00:00
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|