fix crashes
This commit is contained in:
parent
28c617aea2
commit
7543f3f118
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.general.dataBroadcaster
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.ResolveInfo
|
||||
import android.os.Bundle
|
||||
import dagger.android.HasAndroidInjector
|
||||
|
@ -10,6 +9,7 @@ import info.nightscout.androidaps.R
|
|||
import info.nightscout.androidaps.events.Event
|
||||
import info.nightscout.androidaps.events.EventAutosensCalculationFinished
|
||||
import info.nightscout.androidaps.extensions.durationInMinutes
|
||||
import info.nightscout.androidaps.extensions.safeQueryBroadcastReceivers
|
||||
import info.nightscout.androidaps.extensions.toStringFull
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||
|
@ -18,16 +18,16 @@ import info.nightscout.androidaps.plugins.general.nsclient.data.DeviceStatusData
|
|||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
||||
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||
import info.nightscout.androidaps.receivers.Intents
|
||||
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -65,21 +65,18 @@ class DataBroadcastPlugin @Inject constructor(
|
|||
private val disposable = CompositeDisposable()
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
disposable.add(rxBus
|
||||
disposable += rxBus
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.subscribe({ sendData(it) }, fabricPrivacy::logException)
|
||||
)
|
||||
disposable.add(rxBus
|
||||
disposable += rxBus
|
||||
.toObservable(EventAutosensCalculationFinished::class.java)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.subscribe({ sendData(it) }, fabricPrivacy::logException)
|
||||
)
|
||||
disposable.add(rxBus
|
||||
disposable += rxBus
|
||||
.toObservable(EventOverviewBolusProgress::class.java)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.subscribe({ sendData(it) }, fabricPrivacy::logException)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
|
@ -187,7 +184,7 @@ class DataBroadcastPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
private fun sendBroadcast(intent: Intent) {
|
||||
val receivers: List<ResolveInfo> = context.packageManager.queryBroadcastReceivers(intent, PackageManager.ResolveInfoFlags.of(0))
|
||||
val receivers: List<ResolveInfo> = context.packageManager.safeQueryBroadcastReceivers(intent, 0)
|
||||
for (resolveInfo in receivers)
|
||||
resolveInfo.activityInfo.packageName?.let {
|
||||
intent.setPackage(it)
|
||||
|
|
|
@ -19,13 +19,19 @@ import info.nightscout.androidaps.database.entities.ValueWithUnit
|
|||
import info.nightscout.androidaps.database.transactions.CgmSourceTransaction
|
||||
import info.nightscout.androidaps.database.transactions.InvalidateGlucoseValueTransaction
|
||||
import info.nightscout.androidaps.extensions.fromConstant
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.extensions.safeGetInstalledPackages
|
||||
import info.nightscout.androidaps.interfaces.BgSource
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.receivers.DataWorker
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.XDripBroadcast
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
|
@ -244,7 +250,7 @@ class DexcomPlugin @Inject constructor(
|
|||
|
||||
fun findDexcomPackageName(): String? {
|
||||
val packageManager = context.packageManager
|
||||
for (packageInfo in packageManager.getInstalledPackages(PackageManager.PackageInfoFlags.of(0))) {
|
||||
for (packageInfo in packageManager.safeGetInstalledPackages(0)) {
|
||||
if (PACKAGE_NAMES.contains(packageInfo.packageName)) return packageInfo.packageName
|
||||
}
|
||||
return null
|
||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.database.entities.TherapyEvent
|
|||
import info.nightscout.androidaps.database.entities.UserEntry
|
||||
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||
import info.nightscout.androidaps.database.transactions.CgmSourceTransaction
|
||||
import info.nightscout.androidaps.extensions.safeGetInstalledPackages
|
||||
import info.nightscout.androidaps.interfaces.BgSource
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
|
@ -91,7 +92,7 @@ class IntelligoPlugin @Inject constructor(
|
|||
private fun handleNewData() {
|
||||
if (!isEnabled()) return
|
||||
|
||||
for (pack in context.packageManager.getInstalledPackages(PackageManager.PackageInfoFlags.of(PackageManager.GET_PROVIDERS.toLong()))) {
|
||||
for (pack in context.packageManager.safeGetInstalledPackages(PackageManager.GET_PROVIDERS)) {
|
||||
val providers = pack.providers
|
||||
if (providers != null) {
|
||||
for (provider in providers) {
|
||||
|
@ -181,8 +182,10 @@ class IntelligoPlugin @Inject constructor(
|
|||
glucoseValue.sourceSensor == GlucoseValue.SourceSensor.INTELLIGO_NATIVE && sp.getBoolean(R.string.key_dexcomg5_nsupload, false)
|
||||
|
||||
companion object {
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
const val AUTHORITY = "alexpr.co.uk.infinivocgm.intelligo.cgm_db.CgmExternalProvider"
|
||||
|
||||
//const val AUTHORITY = "alexpr.co.uk.infinivocgm.cgm_db.CgmExternalProvider/"
|
||||
const val TABLE_NAME = "CgmReading"
|
||||
const val INTERVAL = 180000L // 3 min
|
||||
|
|
|
@ -2,11 +2,11 @@ package info.nightscout.androidaps.utils
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.annotations.OpenForTesting
|
||||
import info.nightscout.androidaps.database.entities.GlucoseValue
|
||||
import info.nightscout.androidaps.extensions.safeQueryBroadcastReceivers
|
||||
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
|
@ -42,8 +42,8 @@ class XDripBroadcast @Inject constructor(
|
|||
intent.putExtras(bundle)
|
||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
|
||||
context.sendBroadcast(intent)
|
||||
val q = context.packageManager.queryBroadcastReceivers(intent, PackageManager.ResolveInfoFlags.of(0))
|
||||
return if (q.size < 1) {
|
||||
val q = context.packageManager.safeQueryBroadcastReceivers(intent, 0)
|
||||
return if (q.isEmpty()) {
|
||||
ToastUtils.errorToast(context, R.string.xdripnotinstalled)
|
||||
aapsLogger.debug(rh.gs(R.string.xdripnotinstalled))
|
||||
false
|
||||
|
@ -75,8 +75,8 @@ class XDripBroadcast @Inject constructor(
|
|||
val intent = Intent(Intents.XDRIP_PLUS_NS_EMULATOR)
|
||||
intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
|
||||
context.sendBroadcast(intent)
|
||||
val receivers = context.packageManager.queryBroadcastReceivers(intent, PackageManager.ResolveInfoFlags.of(0))
|
||||
if (receivers.size < 1) {
|
||||
val receivers = context.packageManager.safeQueryBroadcastReceivers(intent, 0)
|
||||
if (receivers.isEmpty()) {
|
||||
//NSUpload.log.debug("No xDrip receivers found. ")
|
||||
aapsLogger.debug(LTag.BGSOURCE, "No xDrip receivers found.")
|
||||
} else {
|
||||
|
@ -151,7 +151,7 @@ class XDripBroadcast @Inject constructor(
|
|||
}
|
||||
|
||||
private fun broadcast(intent: Intent) {
|
||||
context.packageManager.queryBroadcastReceivers(intent, PackageManager.ResolveInfoFlags.of(0)).forEach { resolveInfo ->
|
||||
context.packageManager.safeQueryBroadcastReceivers(intent, 0).forEach { resolveInfo ->
|
||||
resolveInfo.activityInfo.packageName?.let {
|
||||
intent.setPackage(it)
|
||||
context.sendBroadcast(intent)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.extensions
|
||||
|
||||
import android.content.Intent
|
||||
import java.io.Serializable
|
||||
|
||||
/**
|
||||
* Safe version of getParcelableExtra depending on Android version running
|
||||
|
@ -8,3 +9,11 @@ import android.content.Intent
|
|||
fun <T> Intent.safeGetParcelableExtra(name: String?, clazz: Class<T>): T? =
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) getParcelableExtra(name, clazz)
|
||||
else @Suppress("DEPRECATION") getParcelableExtra(name)
|
||||
|
||||
/**
|
||||
* Safe version of getSerializableExtra depending on Android version running
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : Serializable?> Intent.safeGetSerializableExtra(name: String?, clazz: Class<T>): T? =
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) getSerializableExtra(name, clazz)
|
||||
else @Suppress("DEPRECATION") (getSerializableExtra(name) as T?)
|
||||
|
|
|
@ -41,6 +41,7 @@ import info.nightscout.androidaps.diaconn.pumplog.LOG_TB_START_V3
|
|||
import info.nightscout.androidaps.diaconn.pumplog.LOG_TB_STOP_V3
|
||||
import info.nightscout.androidaps.diaconn.pumplog.PumplogUtil
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
||||
import info.nightscout.androidaps.extensions.safeGetPackageInfo
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription
|
||||
import info.nightscout.androidaps.interfaces.PumpSync
|
||||
|
@ -911,7 +912,8 @@ class BigLogInquireResponsePacket(
|
|||
val api = retrofit?.create(DiaconnApiService::class.java)
|
||||
val pumpLogDto = PumpLogDto(
|
||||
app_uid = appUid,
|
||||
app_version = context.packageManager.getPackageInfo(context.packageName, PackageManager.PackageInfoFlags.of(0)).versionName,
|
||||
app_version = context.packageManager.safeGetPackageInfo(context.packageName, 0)
|
||||
.versionName,
|
||||
pump_uid = diaconnG8Pump.pumpUid,
|
||||
pump_version = diaconnG8Pump.pumpVersion,
|
||||
incarnation_num = diaconnG8Pump.pumpIncarnationNum,
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activat
|
|||
|
||||
import android.os.Bundle
|
||||
import androidx.annotation.IdRes
|
||||
import info.nightscout.androidaps.extensions.safeGetSerializableExtra
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.activity.OmnipodWizardActivityBase
|
||||
|
||||
|
@ -26,7 +27,7 @@ abstract class PodActivationWizardActivity : OmnipodWizardActivityBase() {
|
|||
setContentView(R.layout.omnipod_common_pod_activation_wizard_activity)
|
||||
|
||||
startDestination = savedInstanceState?.getInt(KEY_START_DESTINATION, R.id.startPodActivationFragment)
|
||||
?: if (intent.getSerializableExtra(KEY_TYPE, Type::class.java) == Type.LONG) {
|
||||
?: if (intent.safeGetSerializableExtra(KEY_TYPE, Type::class.java) == Type.LONG) {
|
||||
R.id.startPodActivationFragment
|
||||
} else {
|
||||
R.id.attachPodFragment
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package info.nightscout.androidaps.extensions
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.ResolveInfo
|
||||
|
||||
/**
|
||||
* Safe version of getInstalledPackages depending on Android version running
|
||||
*/
|
||||
fun PackageManager.safeGetInstalledPackages(flags: Int): List<PackageInfo> =
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) getInstalledPackages(PackageManager.PackageInfoFlags.of(flags.toLong()))
|
||||
else @Suppress("DEPRECATION") getInstalledPackages(flags)
|
||||
|
||||
/**
|
||||
* Safe version of queryBroadcastReceivers depending on Android version running
|
||||
*/
|
||||
fun PackageManager.safeQueryBroadcastReceivers(intent: Intent, flags: Int): List<ResolveInfo> =
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) queryBroadcastReceivers(intent, PackageManager.ResolveInfoFlags.of(flags.toLong()))
|
||||
else @Suppress("DEPRECATION") queryBroadcastReceivers(intent, flags)
|
||||
|
||||
/**
|
||||
* Safe version of getPackageInfo depending on Android version running
|
||||
*/
|
||||
@Throws(PackageManager.NameNotFoundException::class)
|
||||
fun PackageManager.safeGetPackageInfo(packageName: String, flags: Int): PackageInfo =
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong()))
|
||||
else @Suppress("DEPRECATION") getPackageInfo(packageName, flags)
|
|
@ -2,13 +2,13 @@ package info.nightscout.androidaps.interaction.actions
|
|||
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.PackageManager.PackageInfoFlags
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import dagger.android.DaggerActivity
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.events.EventWearToMobile
|
||||
import info.nightscout.androidaps.extensions.safeGetPackageInfo
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.shared.weardata.EventData
|
||||
import javax.inject.Inject
|
||||
|
@ -45,7 +45,7 @@ class QuickSnoozeActivity : DaggerActivity() {
|
|||
@Suppress("SameParameterValue")
|
||||
private fun isPackageExisted(targetPackage: String): Boolean {
|
||||
try {
|
||||
packageManager.getPackageInfo(targetPackage, PackageInfoFlags.of(0))
|
||||
packageManager.safeGetPackageInfo(targetPackage, 0)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue