Support "quick response" when TextSecure is unlocked.

Fixes #299
Closes #3456
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-06-22 08:54:54 -07:00
parent 408d3a964d
commit dc60c011a6
3 changed files with 69 additions and 15 deletions

View File

@ -460,7 +460,9 @@
<string name="MessageNotifier_media_message">Media message</string>
<!-- QuickResponseService -->
<string name="QuickResponseService_sorry_quick_response_is_not_yet_supported_by_textsecure">Sorry, Quick Response is not yet supported by TextSecure!</string>
<string name="QuickResponseService_quick_response_unavailable_when_TextSecure_is_locked">Quick response unavailable when TextSecure is locked!</string>
<string name="QuickResponseService_problem_sending_message">Problem sending message!</string>
<!-- change_passphrase_activity -->
<string name="change_passphrase_activity__old_passphrase">OLD PASSPHRASE:</string>

View File

@ -0,0 +1,21 @@
package org.thoughtcrime.securesms.service;
import android.app.IntentService;
import android.content.Intent;
import android.support.annotation.Nullable;
import org.thoughtcrime.securesms.crypto.MasterSecret;
public abstract class MasterSecretIntentService extends IntentService {
public MasterSecretIntentService(String name) {
super(name);
}
@Override
protected final void onHandleIntent(Intent intent) {
onHandleIntent(intent, KeyCachingService.getMasterSecret(this));
}
protected abstract void onHandleIntent(Intent intent, @Nullable MasterSecret masterSecret);
}

View File

@ -1,31 +1,62 @@
package org.thoughtcrime.securesms.service;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.thoughtcrime.securesms.util.Rfc5724Uri;
public class QuickResponseService extends Service {
import java.net.URISyntaxException;
public int onStartCommand(Intent intent, int flags, int startId) {
if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
Log.w("QuickResponseService", "Received unknown intent: " + intent.getAction());
return START_NOT_STICKY;
}
public class QuickResponseService extends MasterSecretIntentService {
Toast.makeText(this,
getString(R.string.QuickResponseService_sorry_quick_response_is_not_yet_supported_by_textsecure),
Toast.LENGTH_LONG).show();
private static final String TAG = QuickResponseService.class.getSimpleName();
return START_NOT_STICKY;
public QuickResponseService() {
super("QuickResponseService");
}
@Override
public IBinder onBind(Intent intent) {
return null;
protected void onHandleIntent(Intent intent, @Nullable MasterSecret masterSecret) {
if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
Log.w(TAG, "Received unknown intent: " + intent.getAction());
return;
}
if (masterSecret == null) {
Log.w(TAG, "Got quick response request when locked...");
Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_TextSecure_is_locked, Toast.LENGTH_LONG).show();
return;
}
try {
Rfc5724Uri uri = new Rfc5724Uri(intent.getDataString());
String content = intent.getStringExtra(Intent.EXTRA_TEXT);
Recipients recipients = RecipientFactory.getRecipientsFromString(this, uri.getPath(), false);
if (!TextUtils.isEmpty(content)) {
if (recipients.isSingleRecipient()) {
MessageSender.send(this, masterSecret, new OutgoingTextMessage(recipients, content), -1, false);
} else {
MessageSender.send(this, masterSecret, new OutgoingMediaMessage(this, recipients, new SlideDeck(), content,
ThreadDatabase.DistributionTypes.DEFAULT), -1, false);
}
}
} catch (URISyntaxException e) {
Toast.makeText(this, R.string.QuickResponseService_problem_sending_message, Toast.LENGTH_LONG).show();
Log.w(TAG, e);
}
}
}