2018-01-24 19:17:44 -08:00
|
|
|
/*
|
2016-09-14 23:58:24 +02:00
|
|
|
* Copyright (C) 2011 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;
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
import android.annotation.SuppressLint;
|
2018-02-01 19:22:48 -08:00
|
|
|
import android.content.BroadcastReceiver;
|
2016-09-14 23:58:24 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.AsyncTask;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.core.app.NotificationManagerCompat;
|
2016-09-14 23:58:24 +02:00
|
|
|
|
2020-06-26 16:18:19 +10:00
|
|
|
import org.thoughtcrime.securesms.ApplicationContext;
|
2016-09-14 23:58:24 +02:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
|
|
|
import org.whispersystems.libsignal.logging.Log;
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks an Android Auto as read after the driver have listened to it
|
|
|
|
*/
|
2018-02-01 19:22:48 -08:00
|
|
|
public class AndroidAutoHeardReceiver extends BroadcastReceiver {
|
2016-09-14 23:58:24 +02:00
|
|
|
|
2016-12-25 15:27:59 -08:00
|
|
|
public static final String TAG = AndroidAutoHeardReceiver.class.getSimpleName();
|
2020-03-12 09:52:42 +11:00
|
|
|
public static final String HEARD_ACTION = "network.loki.securesms.notifications.ANDROID_AUTO_HEARD";
|
2016-12-25 15:27:59 -08:00
|
|
|
public static final String THREAD_IDS_EXTRA = "car_heard_thread_ids";
|
|
|
|
public static final String NOTIFICATION_ID_EXTRA = "car_notification_id";
|
2016-09-14 23:58:24 +02:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2016-09-14 23:58:24 +02:00
|
|
|
@Override
|
2018-02-01 19:22:48 -08:00
|
|
|
public void onReceive(final Context context, Intent intent)
|
2016-09-14 23:58:24 +02:00
|
|
|
{
|
|
|
|
if (!HEARD_ACTION.equals(intent.getAction()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);
|
|
|
|
|
|
|
|
if (threadIds != null) {
|
2016-12-25 15:27:59 -08:00
|
|
|
int notificationId = intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1);
|
|
|
|
NotificationManagerCompat.from(context).cancel(notificationId);
|
2016-09-14 23:58:24 +02:00
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();
|
|
|
|
|
|
|
|
for (long threadId : threadIds) {
|
|
|
|
Log.i(TAG, "Marking meassage as read: " + threadId);
|
2017-02-22 15:05:35 -08:00
|
|
|
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);
|
2016-09-14 23:58:24 +02:00
|
|
|
|
|
|
|
messageIdsCollection.addAll(messageIds);
|
|
|
|
}
|
|
|
|
|
2020-06-26 16:18:19 +10:00
|
|
|
ApplicationContext.getInstance(context).messageNotifier.updateNotification(context);
|
2016-09-14 23:58:24 +02:00
|
|
|
MarkReadReceiver.process(context, messageIdsCollection);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2016-09-14 23:58:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|