SMS: fix crash on Android<12
This commit is contained in:
parent
21a3069a40
commit
bd61e53bc8
|
@ -67,7 +67,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
injector: HasAndroidInjector,
|
injector: HasAndroidInjector,
|
||||||
aapsLogger: AAPSLogger,
|
aapsLogger: AAPSLogger,
|
||||||
rh: ResourceHelper,
|
rh: ResourceHelper,
|
||||||
private val smsManager: SmsManager,
|
private val smsManager: SmsManager?,
|
||||||
private val aapsSchedulers: AapsSchedulers,
|
private val aapsSchedulers: AapsSchedulers,
|
||||||
private val sp: SP,
|
private val sp: SP,
|
||||||
private val constraintChecker: ConstraintChecker,
|
private val constraintChecker: ConstraintChecker,
|
||||||
|
@ -1100,10 +1100,10 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
sms.text = stripAccents(sms.text)
|
sms.text = stripAccents(sms.text)
|
||||||
try {
|
try {
|
||||||
aapsLogger.debug(LTag.SMS, "Sending SMS to " + sms.phoneNumber + ": " + sms.text)
|
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 {
|
else {
|
||||||
val parts = smsManager.divideMessage(sms.text)
|
val parts = smsManager?.divideMessage(sms.text)
|
||||||
smsManager.sendMultipartTextMessage(sms.phoneNumber, null, parts,
|
smsManager?.sendMultipartTextMessage(sms.phoneNumber, null, parts,
|
||||||
null, null)
|
null, null)
|
||||||
}
|
}
|
||||||
messages.add(sms)
|
messages.add(sms)
|
||||||
|
|
|
@ -52,7 +52,7 @@ class QueueThread internal constructor(
|
||||||
val secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000
|
val secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000
|
||||||
val pump = activePlugin.activePump
|
val pump = activePlugin.activePump
|
||||||
// Manifest.permission.BLUETOOTH_CONNECT
|
// 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")) {
|
if (androidPermission.permissionNotGranted(context, "android.permission.BLUETOOTH_CONNECT")) {
|
||||||
aapsLogger.debug(LTag.PUMPQUEUE, "no permission")
|
aapsLogger.debug(LTag.PUMPQUEUE, "no permission")
|
||||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING))
|
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING))
|
||||||
|
|
|
@ -97,7 +97,7 @@ class AndroidPermission @Inject constructor(
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun notifyForBtConnectPermission(activity: FragmentActivity) {
|
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
|
// Manifest.permission.BLUETOOTH_CONNECT
|
||||||
if (permissionNotGranted(activity, "android.permission.BLUETOOTH_CONNECT") || permissionNotGranted(activity, "android.permission.BLUETOOTH_SCAN")) {
|
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)
|
val notification = NotificationWithAction(injector, Notification.PERMISSION_BT, rh.gs(R.string.needconnectpermission), Notification.URGENT)
|
||||||
|
|
|
@ -21,5 +21,5 @@ open class CoreModule {
|
||||||
fun provideResources(context: Context, fabricPrivacy: FabricPrivacy): ResourceHelper = ResourceHelperImplementation(context, fabricPrivacy)
|
fun provideResources(context: Context, fabricPrivacy: FabricPrivacy): ResourceHelper = ResourceHelperImplementation(context, fabricPrivacy)
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun smsManager(context: Context) : SmsManager = context.getSystemService(SmsManager::class.java)
|
fun smsManager(context: Context) : SmsManager? = context.getSystemService(SmsManager::class.java)
|
||||||
}
|
}
|
|
@ -42,7 +42,7 @@ class BlePreCheck @Inject constructor(
|
||||||
ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), PERMISSION_REQUEST_COARSE_LOCATION)
|
ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), PERMISSION_REQUEST_COARSE_LOCATION)
|
||||||
}
|
}
|
||||||
// change after SDK = 31+
|
// 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 ||
|
if (ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_CONNECT") != PackageManager.PERMISSION_GRANTED ||
|
||||||
ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_SCAN") != PackageManager.PERMISSION_GRANTED
|
ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_SCAN") != PackageManager.PERMISSION_GRANTED
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -159,7 +159,7 @@ class RileyLinkBLE @Inject constructor(
|
||||||
aapsLogger.error(LTag.PUMPBTCOMM, "RileyLink device is null, can't do connectGatt.")
|
aapsLogger.error(LTag.PUMPBTCOMM, "RileyLink device is null, can't do connectGatt.")
|
||||||
return
|
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
|
ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_CONNECT") == PackageManager.PERMISSION_GRANTED
|
||||||
) {
|
) {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "no permission")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "no permission")
|
||||||
|
|
Loading…
Reference in a new issue