From dc3c98e8180b3a9ba3a2352aa30c6a8fb5a5cfb6 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Sat, 7 Oct 2023 08:39:59 +0300 Subject: [PATCH] Migration to API level 34 (Android 14) --- app/build.gradle | 8 +++----- app/src/main/AndroidManifest.xml | 1 + .../kotlin/com/tutpro/baresip/BaresipService.kt | 16 ++++++++++++++-- .../com/tutpro/baresip/OnSwipeTouchListener.kt | 4 ++-- build.gradle | 3 ++- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c3a55b66..c80477f7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,13 +3,12 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' android { - compileSdkVersion = 33 + compileSdkVersion = 34 ndkVersion '26.0.10792818' defaultConfig { applicationId = 'com.tutpro.baresip' minSdkVersion 23 - //noinspection OldTargetApi becuase 34 has not been released yet - targetSdkVersion 33 + targetSdkVersion 34 versionCode = 292 versionName = '58.0.0' externalNativeBuild { @@ -69,8 +68,7 @@ dependencies { implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation "androidx.preference:preference-ktx:1.2.1" implementation "androidx.exifinterface:exifinterface:1.3.6" - //noinspection GradleDependency would require targetSdkVersion 34 which is still beta - implementation "androidx.core:core-ktx:1.10.1" + implementation "androidx.core:core-ktx:1.12.0" implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" implementation "androidx.activity:activity-ktx:1.8.0" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 29dad07c..7677cbc3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ android:maxSdkVersion="30" /> + diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 4cd70ad5..3e815b40 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -11,6 +11,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager +import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL import android.database.ContentObserver import android.media.* import android.media.AudioManager.MODE_IN_COMMUNICATION @@ -245,7 +246,12 @@ class BaresipService: Service() { proximityWakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "com.tutpro.baresip:proximity_wakelog") - wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Baresip") + wifiLock = if (VERSION.SDK_INT < 29) + @Suppress("DEPRECATION") + wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Baresip") + else + wm.createWifiLock(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, "Baresip") + wifiLock.setReferenceCounted(false) bluetoothReceiver = object : BroadcastReceiver() { @@ -1155,7 +1161,10 @@ class BaresipService: Service() { .setCustomContentView(notificationLayout) if (VERSION.SDK_INT >= 31) snb.foregroundServiceBehavior = Notification.FOREGROUND_SERVICE_DEFAULT - startForeground(STATUS_NOTIFICATION_ID, snb.build()) + if (VERSION.SDK_INT >= 29) + startForeground(STATUS_NOTIFICATION_ID, snb.build(), FOREGROUND_SERVICE_TYPE_PHONE_CALL) + else + startForeground(STATUS_NOTIFICATION_ID, snb.build()) } private fun updateStatusNotification() { @@ -1614,6 +1623,7 @@ class BaresipService: Service() { private fun isBluetoothScoOn(am: AudioManager): Boolean { return if (VERSION.SDK_INT < 31) + @Suppress("DEPRECATION") am.isBluetoothScoOn else if (am.communicationDevice != null) @@ -1631,6 +1641,7 @@ class BaresipService: Service() { Log.d(TAG, "Starting Bluetooth SCO at count $count") Handler(Looper.getMainLooper()).postDelayed({ if (VERSION.SDK_INT < 31) { + @Suppress("DEPRECATION") am.startBluetoothSco() } else { Utils.setCommunicationDevice(am, AudioDeviceInfo.TYPE_BLUETOOTH_SCO) @@ -1651,6 +1662,7 @@ class BaresipService: Service() { } Handler(Looper.getMainLooper()).postDelayed({ if (VERSION.SDK_INT < 31) + @Suppress("DEPRECATION") am.stopBluetoothSco() else am.clearCommunicationDevice() diff --git a/app/src/main/kotlin/com/tutpro/baresip/OnSwipeTouchListener.kt b/app/src/main/kotlin/com/tutpro/baresip/OnSwipeTouchListener.kt index f7b03207..d7bca55b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/OnSwipeTouchListener.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/OnSwipeTouchListener.kt @@ -37,10 +37,10 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener { return true } - override fun onFling(e1: MotionEvent, e2: MotionEvent, velX: Float, velY: Float): Boolean { + override fun onFling(e1: MotionEvent?, e2: MotionEvent, velX: Float, velY: Float): Boolean { var result = false try { - val diffY = e2.y - e1.y + val diffY = e2.y - e1!!.y val diffX = e2.x - e1.x if (abs(diffX) > abs(diffY)) { if (abs(diffX) > SWIPE_THRESHOLD && abs(velX) > SWIPE_VELOCITY_THRESHOLD) { diff --git a/build.gradle b/build.gradle index f34d97ba..4f02e4b0 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,8 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.0.2' + //noinspection AndroidGradlePluginVersion + classpath 'com.android.tools.build:gradle:8.1.0-alpha09' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files