Skip to content

Commit

Permalink
Support "quick response" when SMSSecure is unlocked.
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie0 authored and BLeQuerrec committed Jul 9, 2015
1 parent fe11c43 commit 0ead7b1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
4 changes: 3 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,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 SMSSecure!</string>
<string name="QuickResponseService_quick_response_unavailable_when_SMSSecure_is_locked">Quick response unavailable when SMSSecure 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>
Expand Down
21 changes: 21 additions & 0 deletions src/org/smssecure/smssecure/service/MasterSecretIntentService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.smssecure.smssecure.service;

import android.app.IntentService;
import android.content.Intent;
import android.support.annotation.Nullable;

import org.smssecure.smssecure.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);
}
59 changes: 45 additions & 14 deletions src/org/smssecure/smssecure/service/QuickResponseService.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
package org.smssecure.smssecure.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.smssecure.smssecure.R;
import org.smssecure.smssecure.crypto.MasterSecret;
import org.smssecure.smssecure.database.ThreadDatabase;
import org.smssecure.smssecure.mms.OutgoingMediaMessage;
import org.smssecure.smssecure.mms.SlideDeck;
import org.smssecure.smssecure.recipients.RecipientFactory;
import org.smssecure.smssecure.recipients.Recipients;
import org.smssecure.smssecure.sms.MessageSender;
import org.smssecure.smssecure.sms.OutgoingTextMessage;
import org.smssecure.smssecure.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_SMSSecure_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);
}
}
}

0 comments on commit 0ead7b1

Please sign in to comment.