mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
69f180a5ec
In a number of locations in the code, there were conversions of message expiration times from seconds to milliseconds, and then assigned to `long` contexts. However these conversions were being done as integer multiplication rather than long multiplication, meaning that there was a potential for overflows. Specifically, the maximum value that could be represented before overflowing was (2^31 / 1000 / 60 / 60 / 24) days = 24.8 days (< 1 month). Luckily the current allowed timeouts are all less than that value, but this fix would remove the artificial restriction, effectively allowing values of 1000x greater (68 years), at least for android. Related #5775 Closes #7338
63 lines
2.2 KiB
Java
63 lines
2.2 KiB
Java
package org.thoughtcrime.securesms.service;
|
|
|
|
import android.app.IntentService;
|
|
import android.content.Intent;
|
|
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.database.Address;
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
|
import org.thoughtcrime.securesms.util.Rfc5724Uri;
|
|
|
|
import java.net.URISyntaxException;
|
|
import java.net.URLDecoder;
|
|
|
|
public class QuickResponseService extends IntentService {
|
|
|
|
private static final String TAG = QuickResponseService.class.getSimpleName();
|
|
|
|
public QuickResponseService() {
|
|
super("QuickResponseService");
|
|
}
|
|
|
|
@Override
|
|
protected void onHandleIntent(Intent intent) {
|
|
if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
|
|
Log.w(TAG, "Received unknown intent: " + intent.getAction());
|
|
return;
|
|
}
|
|
|
|
if (KeyCachingService.isLocked(this)) {
|
|
Log.w(TAG, "Got quick response request when locked...");
|
|
Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_Signal_is_locked, Toast.LENGTH_LONG).show();
|
|
return;
|
|
}
|
|
|
|
try {
|
|
Rfc5724Uri uri = new Rfc5724Uri(intent.getDataString());
|
|
String content = intent.getStringExtra(Intent.EXTRA_TEXT);
|
|
String number = uri.getPath();
|
|
|
|
if (number.contains("%")){
|
|
number = URLDecoder.decode(number);
|
|
}
|
|
|
|
Address address = Address.fromExternal(this, number);
|
|
Recipient recipient = Recipient.from(this, address, false);
|
|
int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
|
|
long expiresIn = recipient.getExpireMessages() * 1000L;
|
|
|
|
if (!TextUtils.isEmpty(content)) {
|
|
MessageSender.send(this, new OutgoingTextMessage(recipient, content, expiresIn, subscriptionId), -1, false, null);
|
|
}
|
|
} catch (URISyntaxException e) {
|
|
Toast.makeText(this, R.string.QuickResponseService_problem_sending_message, Toast.LENGTH_LONG).show();
|
|
Log.w(TAG, e);
|
|
}
|
|
}
|
|
}
|