move SMS receiver into its own BroadcastReceiver

This commit is contained in:
Daniel Gultsch 2021-01-20 08:14:36 +01:00
parent 47d619b28e
commit eea484af01
5 changed files with 36 additions and 5 deletions

View File

@ -72,14 +72,12 @@
<service android:name=".services.XmppConnectionService" /> <service android:name=".services.XmppConnectionService" />
<receiver android:name=".services.EventReceiver" <receiver android:name=".services.EventReceiver">
android:permission="com.google.android.gms.auth.api.phone.permission.SEND">
<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" /> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.ACTION_SHUTDOWN" /> <action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.media.RINGER_MODE_CHANGED" /> <action android:name="android.media.RINGER_MODE_CHANGED" />
<action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED"/>
</intent-filter> </intent-filter>
</receiver> </receiver>

View File

@ -5,7 +5,9 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import android.util.Log; import android.util.Log;
import com.google.common.base.Strings; import com.google.common.base.Strings;
@ -27,7 +29,7 @@ public class EventReceiver extends BroadcastReceiver {
if (extras != null) { if (extras != null) {
intentForService.putExtras(extras); intentForService.putExtras(extras);
} }
if ("ui".equals(action) || QuickConversationsService.SMS_RETRIEVED_ACTION.equals(action) || hasEnabledAccounts(context)) { if ("ui".equals(action) || hasEnabledAccounts(context)) {
Compatibility.startService(context, intentForService); Compatibility.startService(context, intentForService);
} else { } else {
Log.d(Config.LOGTAG, "EventReceiver ignored action " + intentForService.getAction()); Log.d(Config.LOGTAG, "EventReceiver ignored action " + intentForService.getAction());

View File

@ -32,5 +32,14 @@
android:label="@string/enter_your_name" android:label="@string/enter_your_name"
android:launchMode="singleTask" /> android:launchMode="singleTask" />
<receiver
android:name=".services.SMSReceiver"
android:exported="true"
android:permission="com.google.android.gms.auth.api.phone.permission.SEND">
<intent-filter>
<action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED" />
</intent-filter>
</receiver>
</application> </application>
</manifest> </manifest>

View File

@ -134,7 +134,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
connection.setReadTimeout(Config.SOCKET_TIMEOUT * 1000); connection.setReadTimeout(Config.SOCKET_TIMEOUT * 1000);
setHeader(connection); setHeader(connection);
final int code = connection.getResponseCode(); final int code = connection.getResponseCode();
if (code == 200 || code == 201) { if (code == 200) {
createAccountAndWait(phoneNumber, 0L); createAccountAndWait(phoneNumber, 0L);
} else if (code == 429) { } else if (code == 429) {
createAccountAndWait(phoneNumber, retryAfter(connection)); createAccountAndWait(phoneNumber, retryAfter(connection));

View File

@ -0,0 +1,22 @@
package eu.siacs.conversations.services;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import com.google.common.base.Strings;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.Compatibility;
public class SMSReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
intent.setClass(context, XmppConnectionService.class);
Compatibility.startService(context, intent);
}
}