diff --git a/mobile/build.gradle b/mobile/build.gradle index 4bc8745cfd..e8ae5b94c5 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -40,7 +40,6 @@ if (!isFoss) { } android { - buildToolsVersion '34.0.0' useLibrary "org.apache.http.legacy" namespace 'org.openhab.habdroid' @@ -48,7 +47,7 @@ android { applicationId "org.openhab.habdroid" minSdkVersion 21 compileSdk 34 - targetSdkVersion 33 + targetSdkVersion 34 versionCode 557 versionName "3.16.3-beta" multiDexEnabled true diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml index ce433aacb6..226fda3ae3 100644 --- a/mobile/src/main/AndroidManifest.xml +++ b/mobile/src/main/AndroidManifest.xml @@ -23,7 +23,7 @@ - + diff --git a/mobile/src/main/java/org/openhab/habdroid/background/BackgroundTasksManager.kt b/mobile/src/main/java/org/openhab/habdroid/background/BackgroundTasksManager.kt index 9332ac9aa6..b4c52dc4c4 100644 --- a/mobile/src/main/java/org/openhab/habdroid/background/BackgroundTasksManager.kt +++ b/mobile/src/main/java/org/openhab/habdroid/background/BackgroundTasksManager.kt @@ -88,6 +88,7 @@ import org.openhab.habdroid.util.isItemUpdatePrefEnabled import org.openhab.habdroid.util.isTaskerPluginEnabled import org.openhab.habdroid.util.orDefaultIfEmpty import org.openhab.habdroid.util.parcelableArrayList +import org.openhab.habdroid.util.registerExportedReceiver import org.openhab.habdroid.util.withAttribution class BackgroundTasksManager : BroadcastReceiver() { @@ -782,7 +783,7 @@ class BackgroundTasksManager : BroadcastReceiver() { } VALUE_GETTER_MAP[PrefKeys.SEND_CHARGING_STATE] = { context, _ -> val batteryStatus: Intent? = IntentFilter(Intent.ACTION_BATTERY_CHANGED).let { ifilter -> - context.registerReceiver(null, ifilter) + context.registerExportedReceiver(null, ifilter) } val status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1) ?: -1 val plugged = batteryStatus?.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) diff --git a/mobile/src/main/java/org/openhab/habdroid/background/EventListenerService.kt b/mobile/src/main/java/org/openhab/habdroid/background/EventListenerService.kt index b07bce9c0f..6d39087211 100644 --- a/mobile/src/main/java/org/openhab/habdroid/background/EventListenerService.kt +++ b/mobile/src/main/java/org/openhab/habdroid/background/EventListenerService.kt @@ -26,6 +26,7 @@ import org.openhab.habdroid.util.PrefKeys import org.openhab.habdroid.util.getPrefs import org.openhab.habdroid.util.isEventListenerEnabled import org.openhab.habdroid.util.isItemUpdatePrefEnabled +import org.openhab.habdroid.util.registerExportedReceiver class EventListenerService : Service() { private var backgroundTasksManager = BackgroundTasksManager() @@ -42,7 +43,7 @@ class EventListenerService : Service() { if (intentFilter.countActions() == 0) { stopSelf(startId) } else { - registerReceiver(backgroundTasksManager, intentFilter) + registerExportedReceiver(backgroundTasksManager, intentFilter) isRegistered = true } diff --git a/mobile/src/main/java/org/openhab/habdroid/core/OpenHabApplication.kt b/mobile/src/main/java/org/openhab/habdroid/core/OpenHabApplication.kt index 73c50bb928..d9f459ea66 100644 --- a/mobile/src/main/java/org/openhab/habdroid/core/OpenHabApplication.kt +++ b/mobile/src/main/java/org/openhab/habdroid/core/OpenHabApplication.kt @@ -40,6 +40,7 @@ import org.openhab.habdroid.core.connection.ConnectionFactory import org.openhab.habdroid.util.CrashReportingHelper import org.openhab.habdroid.util.getDayNightMode import org.openhab.habdroid.util.getPrefs +import org.openhab.habdroid.util.registerExportedReceiver class OpenHabApplication : MultiDexApplication() { interface OnDataUsagePolicyChangedListener { @@ -96,7 +97,7 @@ class OpenHabApplication : MultiDexApplication() { BackgroundTasksManager.initialize(this) dataSaverChangeListener.let { listener -> - registerReceiver( + registerExportedReceiver( listener, IntentFilter().apply { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { diff --git a/mobile/src/main/java/org/openhab/habdroid/core/connection/ConnectionManagerHelper.kt b/mobile/src/main/java/org/openhab/habdroid/core/connection/ConnectionManagerHelper.kt index 06349017bd..3d678a3a0a 100644 --- a/mobile/src/main/java/org/openhab/habdroid/core/connection/ConnectionManagerHelper.kt +++ b/mobile/src/main/java/org/openhab/habdroid/core/connection/ConnectionManagerHelper.kt @@ -38,6 +38,7 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import org.openhab.habdroid.util.registerExportedReceiver typealias ConnectionChangedCallback = () -> Unit @@ -96,8 +97,8 @@ interface ConnectionManagerHelper { @Suppress("DEPRECATION") val filter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION) // Make sure to ignore the initial sticky broadcast, as we're only interested in changes - ignoreNextBroadcast = context.registerReceiver(null, filter) != null - context.registerReceiver(this, filter) + ignoreNextBroadcast = context.registerExportedReceiver(null, filter) != null + context.registerExportedReceiver(this, filter) } fun shutdown() { diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt b/mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt index 638647df9b..e842ac0362 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt @@ -146,6 +146,7 @@ import org.openhab.habdroid.util.openInAppStore import org.openhab.habdroid.util.orDefaultIfEmpty import org.openhab.habdroid.util.parcelable import org.openhab.habdroid.util.putActiveServerId +import org.openhab.habdroid.util.registerExportedReceiver import org.openhab.habdroid.util.resolveThemedColor import org.openhab.habdroid.util.updateDefaultSitemap @@ -377,7 +378,7 @@ class MainActivity : AbstractBaseActivity(), ConnectionFactory.UpdateListener { val intentFilter = BackgroundTasksManager.getIntentFilterForForeground(this) if (intentFilter.countActions() != 0 && !prefs.isEventListenerEnabled()) { - registerReceiver(backgroundTasksManager, intentFilter) + registerExportedReceiver(backgroundTasksManager, intentFilter) } showDataSaverHintSnackbarIfNeeded() diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/WriteTagActivity.kt b/mobile/src/main/java/org/openhab/habdroid/ui/WriteTagActivity.kt index bad9b59a52..65722f699d 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/WriteTagActivity.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/WriteTagActivity.kt @@ -52,6 +52,7 @@ import org.openhab.habdroid.model.NfcTag import org.openhab.habdroid.util.PendingIntent_Mutable import org.openhab.habdroid.util.appendQueryParameter import org.openhab.habdroid.util.parcelable +import org.openhab.habdroid.util.registerExportedReceiver import org.openhab.habdroid.util.showToast class WriteTagActivity : AbstractBaseActivity(), CoroutineScope { @@ -110,7 +111,7 @@ class WriteTagActivity : AbstractBaseActivity(), CoroutineScope { replaceFragment() val filter = IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED) - registerReceiver(nfcStateChangeReceiver, filter) + registerExportedReceiver(nfcStateChangeReceiver, filter) } private fun replaceFragment() { diff --git a/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt b/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt index 9b45b9f1ba..978fe6e66d 100644 --- a/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt +++ b/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt @@ -13,11 +13,14 @@ package org.openhab.habdroid.util +import android.annotation.SuppressLint import android.app.Activity import android.app.PendingIntent import android.content.ActivityNotFoundException +import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.content.IntentFilter import android.content.SharedPreferences import android.content.pm.PackageManager import android.content.res.Configuration @@ -638,6 +641,15 @@ val PendingIntent_Mutable = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) 0 } +@SuppressLint("UnspecifiedRegisterReceiverFlag") +fun Context.registerExportedReceiver(receiver: BroadcastReceiver?, intentFilter: IntentFilter): Intent? { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + registerReceiver(receiver, intentFilter, Context.RECEIVER_EXPORTED) + } else { + registerReceiver(receiver, intentFilter) + } +} + inline fun Intent.parcelable(key: String): T? { setExtrasClassLoader(T::class.java.classLoader) return when {