mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
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
90 lines
3.5 KiB
Java
90 lines
3.5 KiB
Java
/*
|
|
* Copyright (C) 2016 Open Whisper Systems
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms.notifications;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.AsyncTask;
|
|
import android.os.Bundle;
|
|
import android.support.v4.app.RemoteInput;
|
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Get the response text from the Wearable Device and sends an message as a reply
|
|
*/
|
|
public class RemoteReplyReceiver extends BroadcastReceiver {
|
|
|
|
public static final String TAG = RemoteReplyReceiver.class.getSimpleName();
|
|
public static final String REPLY_ACTION = "org.thoughtcrime.securesms.notifications.WEAR_REPLY";
|
|
public static final String ADDRESS_EXTRA = "address";
|
|
|
|
@SuppressLint("StaticFieldLeak")
|
|
@Override
|
|
public void onReceive(final Context context, Intent intent) {
|
|
if (!REPLY_ACTION.equals(intent.getAction())) return;
|
|
|
|
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
|
|
|
|
if (remoteInput == null) return;
|
|
|
|
final Address address = intent.getParcelableExtra(ADDRESS_EXTRA);
|
|
final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_REMOTE_REPLY);
|
|
|
|
if (responseText != null) {
|
|
new AsyncTask<Void, Void, Void>() {
|
|
@Override
|
|
protected Void doInBackground(Void... params) {
|
|
long threadId;
|
|
|
|
Recipient recipient = Recipient.from(context, address, false);
|
|
int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
|
|
long expiresIn = recipient.getExpireMessages() * 1000L;
|
|
|
|
if (recipient.isGroupRecipient()) {
|
|
OutgoingMediaMessage reply = new OutgoingMediaMessage(recipient, responseText.toString(), new LinkedList<>(), System.currentTimeMillis(), subscriptionId, expiresIn, 0);
|
|
threadId = MessageSender.send(context, reply, -1, false, null);
|
|
} else {
|
|
OutgoingTextMessage reply = new OutgoingTextMessage(recipient, responseText.toString(), expiresIn, subscriptionId);
|
|
threadId = MessageSender.send(context, reply, -1, false, null);
|
|
}
|
|
|
|
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);
|
|
|
|
MessageNotifier.updateNotification(context);
|
|
MarkReadReceiver.process(context, messageIds);
|
|
|
|
return null;
|
|
}
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
}
|
|
|
|
}
|
|
}
|