Radio updates happen frequently on some phones, switch to dynamic.

This commit is contained in:
Moxie Marlinspike 2013-02-14 20:42:29 -08:00
parent d0d85ea52c
commit 0a7181670c
3 changed files with 27 additions and 2 deletions

View File

@ -168,7 +168,6 @@
android:enabled="true" android:enabled="true"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.SERVICE_STATE"></action>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"></action> <action android:name="android.net.conn.CONNECTIVITY_CHANGE"></action>
</intent-filter> </intent-filter>
</receiver> </receiver>

View File

@ -20,6 +20,7 @@ import android.app.Activity;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -121,16 +122,19 @@ public class SmsSender {
if (result == Activity.RESULT_OK) { if (result == Activity.RESULT_OK) {
DatabaseFactory.getSmsDatabase(context).markAsSent(messageId, type); DatabaseFactory.getSmsDatabase(context).markAsSent(messageId, type);
unregisterForRadioChanges();
} else if (result == SmsManager.RESULT_ERROR_NO_SERVICE || result == SmsManager.RESULT_ERROR_RADIO_OFF) { } else if (result == SmsManager.RESULT_ERROR_NO_SERVICE || result == SmsManager.RESULT_ERROR_RADIO_OFF) {
toastHandler toastHandler
.obtainMessage(0, context.getString(R.string.SmsReceiver_currently_unable_to_send_your_sms_message)) .obtainMessage(0, context.getString(R.string.SmsReceiver_currently_unable_to_send_your_sms_message))
.sendToTarget(); .sendToTarget();
registerForRadioChanges();
} else { } else {
long threadId = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageId); long threadId = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageId);
Recipients recipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(context, threadId); Recipients recipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(context, threadId);
DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId); DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId);
MessageNotifier.notifyMessageDeliveryFailed(context, recipients, threadId); MessageNotifier.notifyMessageDeliveryFailed(context, recipients, threadId);
unregisterForRadioChanges();
} }
pendingMessages.remove(messageId); pendingMessages.remove(messageId);
@ -150,6 +154,22 @@ public class SmsSender {
DatabaseFactory.getSmsDatabase(context).markStatus(messageId, message.getStatus()); DatabaseFactory.getSmsDatabase(context).markStatus(messageId, message.getStatus());
} }
private void registerForRadioChanges() {
unregisterForRadioChanges();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(SystemStateListener.ACTION_SERVICE_STATE);
context.registerReceiver(SystemStateListener.getInstance(), intentFilter);
}
private void unregisterForRadioChanges() {
try {
context.unregisterReceiver(SystemStateListener.getInstance());
} catch (IllegalArgumentException iae) {
}
}
private String getClearTextBody(MasterCipher masterCipher, String body) { private String getClearTextBody(MasterCipher masterCipher, String body) {
if (body.startsWith(Prefix.SYMMETRIC_ENCRYPT)) { if (body.startsWith(Prefix.SYMMETRIC_ENCRYPT)) {
try { try {

View File

@ -9,9 +9,15 @@ import android.telephony.ServiceState;
public class SystemStateListener extends BroadcastReceiver { public class SystemStateListener extends BroadcastReceiver {
private static final String ACTION_SERVICE_STATE = "android.intent.action.SERVICE_STATE"; public static final String ACTION_SERVICE_STATE = "android.intent.action.SERVICE_STATE";
private static final String ACTION_CONNECTIVITY_CHANGE = "android.net.conn.CONNECTIVITY_CHANGE"; private static final String ACTION_CONNECTIVITY_CHANGE = "android.net.conn.CONNECTIVITY_CHANGE";
private static final SystemStateListener instance = new SystemStateListener();
public static SystemStateListener getInstance() {
return instance;
}
private void sendSmsOutbox(Context context) { private void sendSmsOutbox(Context context) {
Intent smsSenderIntent = new Intent(SendReceiveService.SEND_SMS_ACTION, null, context, Intent smsSenderIntent = new Intent(SendReceiveService.SEND_SMS_ACTION, null, context,
SendReceiveService.class); SendReceiveService.class);