SMS: fix crash on Android<12

This commit is contained in:
Milos Kozak 2022-02-25 09:16:51 +01:00
parent 21a3069a40
commit bd61e53bc8
6 changed files with 9 additions and 9 deletions

View file

@ -67,7 +67,7 @@ class SmsCommunicatorPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
rh: ResourceHelper,
private val smsManager: SmsManager,
private val smsManager: SmsManager?,
private val aapsSchedulers: AapsSchedulers,
private val sp: SP,
private val constraintChecker: ConstraintChecker,
@ -1100,10 +1100,10 @@ class SmsCommunicatorPlugin @Inject constructor(
sms.text = stripAccents(sms.text)
try {
aapsLogger.debug(LTag.SMS, "Sending SMS to " + sms.phoneNumber + ": " + sms.text)
if (sms.text.toByteArray().size <= 140) smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null)
if (sms.text.toByteArray().size <= 140) smsManager?.sendTextMessage(sms.phoneNumber, null, sms.text, null, null)
else {
val parts = smsManager.divideMessage(sms.text)
smsManager.sendMultipartTextMessage(sms.phoneNumber, null, parts,
val parts = smsManager?.divideMessage(sms.text)
smsManager?.sendMultipartTextMessage(sms.phoneNumber, null, parts,
null, null)
}
messages.add(sms)

View file

@ -52,7 +52,7 @@ class QueueThread internal constructor(
val secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000
val pump = activePlugin.activePump
// Manifest.permission.BLUETOOTH_CONNECT
if (config.PUMPDRIVERS && Build.VERSION.SDK_INT >= /*Build.VERSION_CODES.S*/31)
if (config.PUMPDRIVERS && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
if (androidPermission.permissionNotGranted(context, "android.permission.BLUETOOTH_CONNECT")) {
aapsLogger.debug(LTag.PUMPQUEUE, "no permission")
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING))

View file

@ -97,7 +97,7 @@ class AndroidPermission @Inject constructor(
@Synchronized
fun notifyForBtConnectPermission(activity: FragmentActivity) {
if (Build.VERSION.SDK_INT >= /*Build.VERSION_CODES.S*/31) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// Manifest.permission.BLUETOOTH_CONNECT
if (permissionNotGranted(activity, "android.permission.BLUETOOTH_CONNECT") || permissionNotGranted(activity, "android.permission.BLUETOOTH_SCAN")) {
val notification = NotificationWithAction(injector, Notification.PERMISSION_BT, rh.gs(R.string.needconnectpermission), Notification.URGENT)

View file

@ -21,5 +21,5 @@ open class CoreModule {
fun provideResources(context: Context, fabricPrivacy: FabricPrivacy): ResourceHelper = ResourceHelperImplementation(context, fabricPrivacy)
@Provides
fun smsManager(context: Context) : SmsManager = context.getSystemService(SmsManager::class.java)
fun smsManager(context: Context) : SmsManager? = context.getSystemService(SmsManager::class.java)
}

View file

@ -42,7 +42,7 @@ class BlePreCheck @Inject constructor(
ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), PERMISSION_REQUEST_COARSE_LOCATION)
}
// change after SDK = 31+
if (Build.VERSION.SDK_INT >= /*Build.VERSION_CODES.S*/31) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_CONNECT") != PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_SCAN") != PackageManager.PERMISSION_GRANTED
) {

View file

@ -159,7 +159,7 @@ class RileyLinkBLE @Inject constructor(
aapsLogger.error(LTag.PUMPBTCOMM, "RileyLink device is null, can't do connectGatt.")
return
}
if (config.PUMPDRIVERS && Build.VERSION.SDK_INT >= /*Build.VERSION_CODES.S*/31 &&
if (config.PUMPDRIVERS && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_CONNECT") == PackageManager.PERMISSION_GRANTED
) {
aapsLogger.debug(LTag.PUMPBTCOMM, "no permission")