2013-12-02 20:31:59 +00:00
|
|
|
package org.thoughtcrime.securesms.service;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
2015-06-22 15:54:54 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2013-12-02 20:31:59 +00:00
|
|
|
import android.telephony.TelephonyManager;
|
2015-06-22 15:54:54 +00:00
|
|
|
import android.text.TextUtils;
|
2013-12-02 20:31:59 +00:00
|
|
|
import android.util.Log;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
2015-06-22 15:54:54 +00:00
|
|
|
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;
|
2013-12-02 20:31:59 +00:00
|
|
|
|
2015-06-22 15:54:54 +00:00
|
|
|
import java.net.URISyntaxException;
|
2015-07-03 13:08:27 +00:00
|
|
|
import java.net.URLDecoder;
|
2013-12-02 20:31:59 +00:00
|
|
|
|
2015-06-22 15:54:54 +00:00
|
|
|
public class QuickResponseService extends MasterSecretIntentService {
|
2013-12-02 20:31:59 +00:00
|
|
|
|
2015-06-22 15:54:54 +00:00
|
|
|
private static final String TAG = QuickResponseService.class.getSimpleName();
|
2013-12-02 20:31:59 +00:00
|
|
|
|
2015-06-22 15:54:54 +00:00
|
|
|
public QuickResponseService() {
|
|
|
|
super("QuickResponseService");
|
2013-12-02 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-22 15:54:54 +00:00
|
|
|
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);
|
2015-07-03 13:08:27 +00:00
|
|
|
String numbers = uri.getPath();
|
|
|
|
if(numbers.contains("%")){
|
|
|
|
numbers = URLDecoder.decode(numbers);
|
|
|
|
}
|
|
|
|
Recipients recipients = RecipientFactory.getRecipientsFromString(this, numbers, false);
|
2015-06-22 15:54:54 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2013-12-02 20:31:59 +00:00
|
|
|
}
|
|
|
|
}
|