2013-12-02 12:31:59 -08:00
|
|
|
package org.thoughtcrime.securesms.service;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
2015-06-22 08:54:54 -07:00
|
|
|
import android.support.annotation.Nullable;
|
2013-12-02 12:31:59 -08:00
|
|
|
import android.telephony.TelephonyManager;
|
2015-06-22 08:54:54 -07:00
|
|
|
import android.text.TextUtils;
|
2013-12-02 12:31:59 -08:00
|
|
|
import android.util.Log;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
2015-06-22 08:54:54 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2017-07-26 09:59:15 -07:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2016-02-05 16:10:33 -08:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2017-08-21 18:47:37 -07:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2015-06-22 08:54:54 -07:00
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
|
|
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
|
|
|
import org.thoughtcrime.securesms.util.Rfc5724Uri;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2013-12-02 12:31:59 -08:00
|
|
|
|
2015-06-22 08:54:54 -07:00
|
|
|
import java.net.URISyntaxException;
|
2015-07-03 15:08:27 +02:00
|
|
|
import java.net.URLDecoder;
|
2013-12-02 12:31:59 -08:00
|
|
|
|
2015-06-22 08:54:54 -07:00
|
|
|
public class QuickResponseService extends MasterSecretIntentService {
|
2013-12-02 12:31:59 -08:00
|
|
|
|
2015-06-22 08:54:54 -07:00
|
|
|
private static final String TAG = QuickResponseService.class.getSimpleName();
|
2013-12-02 12:31:59 -08:00
|
|
|
|
2015-06-22 08:54:54 -07:00
|
|
|
public QuickResponseService() {
|
|
|
|
super("QuickResponseService");
|
2013-12-02 12:31:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-22 08:54:54 -07: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...");
|
2015-09-23 13:35:18 -07:00
|
|
|
Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_Signal_is_locked, Toast.LENGTH_LONG).show();
|
2015-06-22 08:54:54 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Rfc5724Uri uri = new Rfc5724Uri(intent.getDataString());
|
|
|
|
String content = intent.getStringExtra(Intent.EXTRA_TEXT);
|
2017-08-01 08:56:00 -07:00
|
|
|
String number = uri.getPath();
|
2017-07-26 09:59:15 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (number.contains("%")){
|
|
|
|
number = URLDecoder.decode(number);
|
2015-07-03 15:08:27 +02:00
|
|
|
}
|
2016-02-05 16:10:33 -08:00
|
|
|
|
2017-08-22 10:44:04 -07:00
|
|
|
Address address = Address.fromExternal(this, number);
|
|
|
|
Recipient recipient = Recipient.from(this, address, false);
|
|
|
|
int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
|
|
|
|
long expiresIn = recipient.getExpireMessages() * 1000;
|
2015-06-22 08:54:54 -07:00
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(content)) {
|
2017-08-01 08:56:00 -07:00
|
|
|
MessageSender.send(this, masterSecret, new OutgoingTextMessage(recipient, content, expiresIn, subscriptionId), -1, false, null);
|
2015-06-22 08:54:54 -07:00
|
|
|
}
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
Toast.makeText(this, R.string.QuickResponseService_problem_sending_message, Toast.LENGTH_LONG).show();
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
2013-12-02 12:31:59 -08:00
|
|
|
}
|
|
|
|
}
|