Migration to API level 34 (Android 14)

This commit is contained in:
Juha Heinanen
2023-10-07 08:39:59 +03:00
parent 494530c4f7
commit dc3c98e818
5 changed files with 22 additions and 10 deletions
@@ -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()