Skip to content

Commit

Permalink
Increase targetSdk to 34
Browse files Browse the repository at this point in the history
Closes openhab#3732

Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma committed Aug 29, 2024
1 parent 5bc588e commit c6a8ad9
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 10 deletions.
3 changes: 1 addition & 2 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ if (!isFoss) {
}

android {
buildToolsVersion '34.0.0'
useLibrary "org.apache.http.legacy"
namespace 'org.openhab.habdroid'

defaultConfig {
applicationId "org.openhab.habdroid"
minSdkVersion 21
compileSdk 34
targetSdkVersion 33
targetSdkVersion 34
versionCode 556
versionName "3.16.2"
multiDexEnabled true
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_TYPE_DATA_SYNC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -42,7 +43,7 @@ class EventListenerService : Service() {
if (intentFilter.countActions() == 0) {
stopSelf(startId)
} else {
registerReceiver(backgroundTasksManager, intentFilter)
registerExportedReceiver(backgroundTasksManager, intentFilter)
isRegistered = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
12 changes: 12 additions & 0 deletions mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <reified T> Intent.parcelable(key: String): T? {
setExtrasClassLoader(T::class.java.classLoader)
return when {
Expand Down

0 comments on commit c6a8ad9

Please sign in to comment.