Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,21 @@ public static Uri persist(Context context, byte[] response, MmsConfig.Overridden
});
return null;
}
Timber.d("DownloadRequest.persist: responseLength=" + response.length + " locationUrl=" + locationUrl + " supportContentDisposition=" + mmsConfig.getSupportMmsContentDisposition());
final long identity = Binder.clearCallingIdentity();
try {
final GenericPdu pdu =
(new PduParser(response, mmsConfig.getSupportMmsContentDisposition())).parse();
if (pdu == null || !(pdu instanceof RetrieveConf)) {
Timber.e("DownloadRequest.persistIfRequired: invalid parsed PDU");
Timber.e("DownloadRequest.persistIfRequired: invalid parsed PDU. pdu=" + pdu + (pdu != null ? " type=" + pdu.getMessageType() : ""));

// Update the error type of the NotificationInd
setErrorType(context, locationUrl, Telephony.MmsSms.ERR_TYPE_MMS_PROTO_PERMANENT);
return null;
}
final RetrieveConf retrieveConf = (RetrieveConf) pdu;
final int status = retrieveConf.getRetrieveStatus();
Timber.d("DownloadRequest.persist: PDU parsed ok, retrieveStatus=" + status + " partCount=" + retrieveConf.getBody().getPartsNum());
// if (status != PduHeaders.RETRIEVE_STATUS_OK) {
// Timber.e("DownloadRequest.persistIfRequired: retrieve failed "
// + status);
Expand All @@ -131,6 +133,7 @@ public static Uri persist(Context context, byte[] response, MmsConfig.Overridden
// Store the downloaded message
final PduPersister persister = PduPersister.getPduPersister(context);
final Uri messageUri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, PduPersister.DUMMY_THREAD_ID, true, true, null);
Timber.d("DownloadRequest.persist: PduPersister.persist returned uri=" + messageUri);
if (messageUri == null) {
Timber.e("DownloadRequest.persistIfRequired: can not persist message");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Build;

import androidx.core.content.ContextCompat;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.util.ArrayMap;
Expand Down Expand Up @@ -79,7 +80,12 @@ public void init(final Context context) {
IntentFilter intentFilterLoaded = new IntentFilter("LOADED");

try {
context.registerReceiver(mReceiver, intentFilterLoaded);
ContextCompat.registerReceiver(
context,
mReceiver,
intentFilterLoaded,
ContextCompat.RECEIVER_NOT_EXPORTED
);
} catch (Exception e) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;

import androidx.core.content.ContextCompat;
import android.database.sqlite.SqliteWrapper;
import android.net.Uri;
import android.os.Bundle;
Expand Down Expand Up @@ -57,7 +59,12 @@ public void downloadMultimediaMessage(final Context context, final String locati
mMap.put(location, receiver);

// Use unique action in order to avoid cancellation of notifying download result.
context.getApplicationContext().registerReceiver(receiver, new IntentFilter(receiver.mAction));
ContextCompat.registerReceiver(
context.getApplicationContext(),
receiver,
new IntentFilter(receiver.mAction),
ContextCompat.RECEIVER_NOT_EXPORTED
);

Timber.v("receiving with system method");
final String fileName = "download." + String.valueOf(Math.abs(new Random().nextLong())) + ".dat";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ protected Void doInBackground(Intent... intents) {
}

int subId = intent.getIntExtra("subscription", Utils.getDefaultSubscriptionId());
Timber.d("PushReceiver: MMS notification received, triggering download. location=" + location + " notifUri=" + uri + " subId=" + subId);
DownloadManager.getInstance().downloadMultimediaMessage(mContext, location, uri, true, subId);
} else {
Timber.v("Skip downloading duplicate message: " + new String(nInd.getContentLocation()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import androidx.core.content.ContextCompat;
import android.database.Cursor;
import android.database.sqlite.SqliteWrapper;
import android.net.ConnectivityManager;
Expand Down Expand Up @@ -186,7 +188,12 @@ public void onCreate() {
mReceiver = new ConnectivityBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(mReceiver, intentFilter);
ContextCompat.registerReceiver(
this,
mReceiver,
intentFilter,
ContextCompat.RECEIVER_NOT_EXPORTED
);
mConnMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import androidx.core.content.ContextCompat;
import android.database.Cursor;
import android.database.sqlite.SqliteWrapper;
import android.provider.Telephony.Mms.Rate;
Expand Down Expand Up @@ -124,8 +126,12 @@ synchronized public boolean isAllowedByUser() {
}
sMutexLock = true;

mContext.registerReceiver(mBroadcastReceiver,
new IntentFilter(RATE_LIMIT_CONFIRMED_ACTION));
ContextCompat.registerReceiver(
mContext,
mBroadcastReceiver,
new IntentFilter(RATE_LIMIT_CONFIRMED_ACTION),
ContextCompat.RECEIVER_NOT_EXPORTED
);

mAnswer = NO_ANSWER;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class Transaction @JvmOverloads constructor(private val context: Context, settin
} catch (e: IOException) {
Timber.e(e, "Error writing send file")
null
} catch (e: OutOfMemoryError) {
Timber.e(e, "Not enough memory to compose MMS")
null
}

val configOverrides = bundleOf(
Expand All @@ -140,7 +143,7 @@ class Transaction @JvmOverloads constructor(private val context: Context, settin
}

}
} catch (e: Exception) {
} catch (e: Throwable) {
Timber.e(e, "Error using system sending method")
}

Expand Down
10 changes: 7 additions & 3 deletions data/src/main/java/com/moez/QKSMS/manager/BluetoothMicManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.content.IntentFilter
import android.media.AudioDeviceInfo
import android.media.AudioManager
import android.media.AudioManager.GET_DEVICES_INPUTS
import androidx.core.content.ContextCompat


// this class is, by design, as simplistic it can be to support easy and fast connection
Expand All @@ -45,9 +46,12 @@ class BluetoothMicManager(

init {
// register for bluetooth sco broadcast intents
context.registerReceiver(this, IntentFilter().apply {
addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)
})
ContextCompat.registerReceiver(
context,
this,
IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED),
ContextCompat.RECEIVER_NOT_EXPORTED
)
}

enum class StartBluetoothDevice {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@ import android.net.Uri
import com.klinker.android.send_message.MmsReceivedReceiver
import dagger.android.AndroidInjection
import org.prauga.messages.interactor.ReceiveMms
import timber.log.Timber
import javax.inject.Inject

class MmsReceivedReceiver : MmsReceivedReceiver() {

@Inject lateinit var receiveMms: ReceiveMms

override fun onReceive(context: Context?, intent: Intent?) {
Timber.d("MmsReceivedReceiver.onReceive: action=${intent?.action} extras=${intent?.extras?.keySet()}")
AndroidInjection.inject(this, context)
super.onReceive(context, intent)
}

override fun onMessageReceived(messageUri: Uri?) {
messageUri?.let { uri ->
val pendingResult = goAsync()
receiveMms.execute(uri) { pendingResult.finish() }
Timber.d("MmsReceivedReceiver.onMessageReceived: uri=$messageUri")
if (messageUri == null) {
Timber.w("MmsReceivedReceiver.onMessageReceived: uri is null, skipping sync")
return
}
val pendingResult = goAsync()
receiveMms.execute(messageUri) { pendingResult.finish() }
}

}
24 changes: 8 additions & 16 deletions data/src/main/java/com/moez/QKSMS/receiver/SmsReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,29 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.provider.Telephony.Sms
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.OutOfQuotaPolicy
import androidx.work.WorkManager
import androidx.work.workDataOf
import dagger.android.AndroidInjection
import org.prauga.messages.interactor.ReceiveSms
import org.prauga.messages.repository.MessageRepository
import org.prauga.messages.worker.ReceiveSmsWorker
import org.prauga.messages.worker.ReceiveSmsWorker.Companion.INPUT_DATA_KEY_MESSAGE_ID
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
import javax.inject.Inject

class SmsReceiver : BroadcastReceiver() {
@Inject lateinit var messageRepo: MessageRepository
@Inject lateinit var receiveSms: ReceiveSms

override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)

val pendingResult = goAsync()

Sms.Intents.getMessagesFromIntent(intent)?.let { messages ->
// reduce list of messages to single message and save in db
val messageId = Single.just(messages)
.observeOn(Schedulers.io())
.map {
Timber.v("onReceive() new sms") // here so runs on io thread
Timber.v("onReceive() new sms")

messageRepo.insertReceivedSms(
intent.extras?.getInt("subscription", -1) ?: -1,
Expand All @@ -57,14 +55,8 @@ class SmsReceiver : BroadcastReceiver() {
}
.blockingGet()

// start worker with message id as param
WorkManager.getInstance(context).enqueue(
OneTimeWorkRequestBuilder<ReceiveSmsWorker>()
.setInputData(workDataOf(INPUT_DATA_KEY_MESSAGE_ID to messageId))
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.build()
)
}
receiveSms.execute(messageId) { pendingResult.finish() }
} ?: pendingResult.finish()
}

}
}
Loading
Loading