Support 'WiFi calling' devices.

// FREEBIE

Fixes #2254
Fixes #2240
Fixes #2160

Closes #2263
This commit is contained in:
Moxie Marlinspike 2014-12-24 12:40:28 -08:00
parent 1443d846c4
commit 6e85677c52
6 changed files with 60 additions and 14 deletions

View File

@ -731,6 +731,8 @@
<string name="preferences__sms_fallback_never_send_mms">Never send MMS</string>
<string name="preferences__sms_fallback_non_push_users">Non-TextSecure users</string>
<string name="preferences__sms_fallback_nobody">Nobody</string>
<string name="preferences__support_wifi_calling">\'WiFi Calling\' compatibility mode</string>
<string name="preferences__enable_if_your_device_supports_sms_mms_delivery_over_wifi">Enable if your device uses SMS/MMS delivery over WiFi (only enable when \'WiFi Calling\' is enabled on your device).</string>
<!-- **************************************** -->
<!-- menus -->

View File

@ -24,6 +24,11 @@
android:summary="@string/preferences__request_a_delivery_report_for_each_sms_message_you_send"
android:title="@string/preferences__sms_delivery_reports" />
<CheckBoxPreference android:defaultValue="false"
android:key="pref_wifi_sms"
android:title="@string/preferences__support_wifi_calling"
android:summary="@string/preferences__enable_if_your_device_supports_sms_mms_delivery_over_wifi"/>
<Preference android:key="pref_mms_preferences"
android:title="@string/preferences__advanced_mms_access_point_names"/>

View File

@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.database.EncryptingSmsDatabase;
import org.thoughtcrime.securesms.database.NoSuchMessageException;
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
import org.thoughtcrime.securesms.jobs.requirements.NetworkOrServiceRequirement;
import org.thoughtcrime.securesms.jobs.requirements.ServiceRequirement;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.recipients.Recipients;
@ -37,13 +38,7 @@ public class SmsSendJob extends MasterSecretJob {
private final long messageId;
public SmsSendJob(Context context, long messageId, String name) {
super(context, JobParameters.newBuilder()
.withPersistence()
.withRequirement(new MasterSecretRequirement(context))
.withRequirement(new ServiceRequirement(context))
.withGroupId(name)
.create());
super(context, constructParameters(context, name));
this.messageId = messageId;
}
@ -227,7 +222,7 @@ public class SmsSendJob extends MasterSecretJob {
return pending;
}
protected Intent constructDeliveredIntent(Context context, long messageId, long type) {
private Intent constructDeliveredIntent(Context context, long messageId, long type) {
Intent pending = new Intent(SmsDeliveryListener.DELIVERED_SMS_ACTION,
Uri.parse("custom://" + messageId + System.currentTimeMillis()),
context, SmsDeliveryListener.class);
@ -237,5 +232,20 @@ public class SmsSendJob extends MasterSecretJob {
return pending;
}
private static JobParameters constructParameters(Context context, String name) {
JobParameters.Builder builder = JobParameters.newBuilder()
.withPersistence()
.withRequirement(new MasterSecretRequirement(context))
.withGroupId(name);
if (TextSecurePreferences.isWifiSmsEnabled(context)) {
builder.withRequirement(new NetworkOrServiceRequirement(context));
} else {
builder.withRequirement(new ServiceRequirement(context));
}
return builder.create();
}
}

View File

@ -0,0 +1,29 @@
package org.thoughtcrime.securesms.jobs.requirements;
import android.content.Context;
import org.whispersystems.jobqueue.dependencies.ContextDependent;
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
import org.whispersystems.jobqueue.requirements.Requirement;
public class NetworkOrServiceRequirement implements Requirement, ContextDependent {
private transient Context context;
public NetworkOrServiceRequirement(Context context) {
this.context = context;
}
@Override
public void setContext(Context context) {
this.context = context;
}
@Override
public boolean isPresent() {
NetworkRequirement networkRequirement = new NetworkRequirement(context);
ServiceRequirement serviceRequirement = new ServiceRequirement(context);
return networkRequirement.isPresent() || serviceRequirement.isPresent();
}
}

View File

@ -17,15 +17,10 @@ public class ServiceRequirement implements Requirement, ContextDependent {
private static final String TAG = ServiceRequirement.class.getSimpleName();
private final transient ServiceRequirementProvider provider;
private transient Context context;
public ServiceRequirement(Context context) {
this.context = context;
this.provider = (ServiceRequirementProvider)ApplicationContext.getInstance(context)
.getJobManager()
.getRequirementProvider("telephony-service");
}
@Override

View File

@ -57,6 +57,7 @@ public class TextSecurePreferences {
private static final String DIRECT_SMS_ALLOWED_PREF = "pref_sms_non_data_out";
private static final String FALLBACK_MMS_ENABLED_PREF = "pref_mms_fallback_enabled";
private static final String SIGNED_PREKEY_REGISTERED_PREF = "pref_signed_prekey_registered";
private static final String WIFI_SMS_PREF = "pref_wifi_sms";
private static final String GCM_REGISTRATION_ID_PREF = "pref_gcm_registration_id";
private static final String GCM_REGISTRATION_ID_VERSION_PREF = "pref_gcm_registration_id_version";
@ -64,6 +65,10 @@ public class TextSecurePreferences {
private static final String PUSH_REGISTRATION_REMINDER_PREF = "pref_push_registration_reminder";
public static final String REPEAT_ALERTS_PREF = "pref_repeat_alerts";
public static boolean isWifiSmsEnabled(Context context) {
return getBooleanPreference(context, WIFI_SMS_PREF, false);
}
public static int getRepeatAlertsCount(Context context) {
try {
return Integer.parseInt(getStringPreference(context, REPEAT_ALERTS_PREF, "0"));