2013-12-02 20:31:59 +00:00
|
|
|
package org.thoughtcrime.securesms.service;
|
|
|
|
|
2018-02-02 03:22:48 +00:00
|
|
|
import android.app.IntentService;
|
2013-12-02 20:31:59 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
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.widget.Toast;
|
|
|
|
|
2019-07-24 02:30:23 +00:00
|
|
|
import network.loki.messenger.R;
|
2017-07-26 16:59:15 +00:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2018-08-01 15:09:24 +00:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2017-08-01 15:56:00 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2015-06-22 15:54:54 +00:00
|
|
|
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
|
|
|
|
2018-02-02 03:22:48 +00:00
|
|
|
public class QuickResponseService extends IntentService {
|
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
|
2018-02-02 03:22:48 +00:00
|
|
|
protected void onHandleIntent(Intent intent) {
|
2015-06-22 15:54:54 +00:00
|
|
|
if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
|
|
|
|
Log.w(TAG, "Received unknown intent: " + intent.getAction());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-02 03:22:48 +00:00
|
|
|
if (KeyCachingService.isLocked(this)) {
|
2015-06-22 15:54:54 +00:00
|
|
|
Log.w(TAG, "Got quick response request when locked...");
|
2015-09-23 20:35:18 +00:00
|
|
|
Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_Signal_is_locked, Toast.LENGTH_LONG).show();
|
2015-06-22 15:54:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Rfc5724Uri uri = new Rfc5724Uri(intent.getDataString());
|
|
|
|
String content = intent.getStringExtra(Intent.EXTRA_TEXT);
|
2017-08-01 15:56:00 +00:00
|
|
|
String number = uri.getPath();
|
2017-07-26 16:59:15 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
if (number.contains("%")){
|
|
|
|
number = URLDecoder.decode(number);
|
2015-07-03 13:08:27 +00:00
|
|
|
}
|
2016-02-06 00:10:33 +00:00
|
|
|
|
2017-08-22 17:44:04 +00:00
|
|
|
Address address = Address.fromExternal(this, number);
|
|
|
|
Recipient recipient = Recipient.from(this, address, false);
|
|
|
|
int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
|
2018-01-12 11:39:10 +00:00
|
|
|
long expiresIn = recipient.getExpireMessages() * 1000L;
|
2015-06-22 15:54:54 +00:00
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(content)) {
|
2018-01-25 03:17:44 +00:00
|
|
|
MessageSender.send(this, new OutgoingTextMessage(recipient, content, expiresIn, subscriptionId), -1, false, null);
|
2015-06-22 15:54:54 +00:00
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|