From 4c00fee45610586df3b6c9b569d18c2ec8ab3418 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Mon, 18 Nov 2024 01:56:02 +0200 Subject: [PATCH] Removed code that is not needed at API level 28 and above Modified strings mentioning Android version below 9 --- .../com/tutpro/baresip/BaresipService.kt | 121 ++++++------------ .../kotlin/com/tutpro/baresip/MainActivity.kt | 12 +- .../main/kotlin/com/tutpro/baresip/Utils.kt | 32 +---- app/src/main/res/values-fi/strings.xml | 10 +- app/src/main/res/values/strings.xml | 11 +- 5 files changed, 59 insertions(+), 127 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 501a1579..5589d5df 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -77,7 +77,6 @@ class BaresipService: Service() { private lateinit var stopState: String private lateinit var quitTimer: CountDownTimer - private var rtTimer: Timer? = null private var vbTimer: Timer? = null private var origVolume = mutableMapOf() private var linkAddresses = mutableMapOf() @@ -129,7 +128,7 @@ class BaresipService: Service() { partialWakeLock = pm.run { newWakeLock( PowerManager.PARTIAL_WAKE_LOCK, - "com.tutpro.baresip:partial_wakelog" + "com.tutpro.baresip:partial_wakelock" ).apply { acquire() } @@ -147,9 +146,6 @@ class BaresipService: Service() { Log.d(TAG, "Network $network is available") if (network !in allNetworks) allNetworks.add(network) - // If API >= 26, this will be followed by onCapabilitiesChanged - if (isServiceRunning && VERSION.SDK_INT < 26) - updateNetwork() } override fun onLosing(network: Network, maxMsToLive: Int) { @@ -249,7 +245,7 @@ class BaresipService: Service() { btAdapter = btm.adapter proximityWakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, - "com.tutpro.baresip:proximity_wakelog") + "com.tutpro.baresip:proximity_wakelock") wifiLock = if (VERSION.SDK_INT < 29) @Suppress("DEPRECATION") @@ -445,6 +441,8 @@ class BaresipService: Service() { activeNetwork = cm.activeNetwork Log.i(TAG, "Active network: $activeNetwork") + Log.d(TAG, "AEC/AGC/NS available = $aec/$agc/$ns") + val userAgent = Config.variable("user_agent") Thread { baresipStart( @@ -635,6 +633,14 @@ class BaresipService: Service() { return } + if (ev[0] == "player sessionid") { + val sessionId = ev[1].toInt() + Log.d(TAG, "got recorder sessionid $sessionId") + if (aec) + AcousticEchoCanceler.create(sessionId) + return + } + if (ev[0] == "recorder sessionid") { val sessionId = ev[1].toInt() Log.d(TAG, "got recorder sessionid $sessionId") @@ -807,11 +813,6 @@ class BaresipService: Service() { .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setPriority(NotificationCompat.PRIORITY_HIGH) .setFullScreenIntent(pi, true) - if (VERSION.SDK_INT < 26) { - @Suppress("DEPRECATION") - nb.setVibrate(LongArray(0)) - .priority = Notification.PRIORITY_HIGH - } val answerIntent = Intent(applicationContext, MainActivity::class.java) answerIntent.putExtra("action", "call answer") .putExtra("callp", callp) @@ -895,11 +896,6 @@ class BaresipService: Service() { .setAutoCancel(true) .setContentTitle(getString(R.string.transfer_request_to)) .setContentText(target) - if (VERSION.SDK_INT < 26) - @Suppress("DEPRECATION") - nb.setVibrate(LongArray(0)) - .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) - .priority = Notification.PRIORITY_HIGH val acceptIntent = Intent(applicationContext, MainActivity::class.java) acceptIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK @@ -1001,12 +997,6 @@ class BaresipService: Service() { String.format(getString(R.string.missed_calls_count), missedCalls + 1)) } - if (VERSION.SDK_INT < 26) { - @Suppress("DEPRECATION") - nb.setVibrate(LongArray(0)) - .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) - .priority = Notification.PRIORITY_HIGH - } nm.notify(CALL_MISSED_NOTIFICATION_ID, nb.build()) } return @@ -1088,12 +1078,6 @@ class BaresipService: Service() { .setAutoCancel(true) .setContentTitle(getString(R.string.message_from) + " " + sender) .setContentText(text) - if (VERSION.SDK_INT < 26) { - @Suppress("DEPRECATION") - nb.setVibrate(LongArray(0)) - .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) - .priority = Notification.PRIORITY_HIGH - } val replyIntent = Intent(applicationContext, MainActivity::class.java) replyIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK @@ -1172,22 +1156,20 @@ class BaresipService: Service() { } private fun createNotificationChannels() { - if (VERSION.SDK_INT >= 26) { - val defaultChannel = NotificationChannel(DEFAULT_CHANNEL_ID, "Default", - NotificationManager.IMPORTANCE_LOW) - defaultChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC - nm.createNotificationChannel(defaultChannel) - val highChannel = NotificationChannel(HIGH_CHANNEL_ID, "High", - NotificationManager.IMPORTANCE_HIGH) - highChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC - highChannel.enableVibration(true) - nm.createNotificationChannel(highChannel) - val mediumChannel = NotificationChannel(MEDIUM_CHANNEL_ID, "Medium", - NotificationManager.IMPORTANCE_HIGH) - highChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC - highChannel.enableVibration(false) - nm.createNotificationChannel(mediumChannel) - } + val defaultChannel = NotificationChannel(DEFAULT_CHANNEL_ID, "Default", + NotificationManager.IMPORTANCE_LOW) + defaultChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC + nm.createNotificationChannel(defaultChannel) + val highChannel = NotificationChannel(HIGH_CHANNEL_ID, "High", + NotificationManager.IMPORTANCE_HIGH) + highChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC + highChannel.enableVibration(true) + nm.createNotificationChannel(highChannel) + val mediumChannel = NotificationChannel(MEDIUM_CHANNEL_ID, "Medium", + NotificationManager.IMPORTANCE_HIGH) + highChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC + highChannel.enableVibration(false) + nm.createNotificationChannel(mediumChannel) } @SuppressLint("UnspecifiedImmutableFlag") @@ -1257,43 +1239,25 @@ class BaresipService: Service() { private fun getActionText(@StringRes stringRes: Int, @ColorRes colorRes: Int): Spannable { val spannable: Spannable = SpannableString(applicationContext.getText(stringRes)) - if (VERSION.SDK_INT >= 25) { spannable.setSpan( ForegroundColorSpan(applicationContext.getColor(colorRes)), 0, spannable.length, 0) - } return spannable } private fun startRinging() { - if (VERSION.SDK_INT >= 28) { - rt.isLooping = true - rt.play() - } else { - rt.play() - rtTimer = Timer() - rtTimer!!.schedule(object : TimerTask() { - override fun run() { - if (!rt.isPlaying) - rt.play() - } - }, 1000, 1000) - } + rt.isLooping = true + rt.play() if (shouldVibrate()) { vbTimer = Timer() vbTimer!!.schedule(object : TimerTask() { override fun run() { - if (VERSION.SDK_INT < 26) { - @Suppress("DEPRECATION") - vibrator.vibrate(500) - } else { - vibrator.vibrate( - VibrationEffect.createOneShot( - 500, - VibrationEffect.DEFAULT_AMPLITUDE - ) + vibrator.vibrate( + VibrationEffect.createOneShot( + 500, + VibrationEffect.DEFAULT_AMPLITUDE ) - } + ) } }, 500L, 2000L) } @@ -1317,10 +1281,6 @@ class BaresipService: Service() { } private fun stopRinging() { - if (VERSION.SDK_INT < 28 && rtTimer != null) { - rtTimer!!.cancel() - rtTimer = null - } rt.stop() if (vbTimer != null) { vbTimer!!.cancel() @@ -1481,14 +1441,13 @@ class BaresipService: Service() { val addresses = mutableMapOf() for (n in allNetworks) { val caps = cm.getNetworkCapabilities(n) ?: continue - if (VERSION.SDK_INT < 28 || - caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOREGROUND)) { - val props = cm.getLinkProperties(n) ?: continue - for (la in props.linkAddresses) - if (la.scope == android.system.OsConstants.RT_SCOPE_UNIVERSE && - props.interfaceName != null && la.address.hostAddress != null && - afMatch(la.address.hostAddress!!)) - addresses[la.address.hostAddress!!] = props.interfaceName!! + if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOREGROUND)) { + val props = cm.getLinkProperties(n) ?: continue + for (la in props.linkAddresses) + if (la.scope == android.system.OsConstants.RT_SCOPE_UNIVERSE && + props.interfaceName != null && la.address.hostAddress != null && + afMatch(la.address.hostAddress!!)) + addresses[la.address.hostAddress!!] = props.interfaceName!! } } if (hotSpotIsEnabled) { diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index f99777c8..a960f385 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -137,8 +137,8 @@ class MainActivity : AppCompatActivity() { setContentView(binding.root) // Must be done after view has been created - Utils.setShowWhenLocked(this, true) - Utils.setTurnScreenOn(this, true) + this.setShowWhenLocked(true) + this.setTurnScreenOn( true) Utils.requestDismissKeyguard(this) setSupportActionBar(binding.toolbar) @@ -189,7 +189,7 @@ class MainActivity : AppCompatActivity() { override fun onReceive(contxt: Context, intent: Intent) { if (kgm.isKeyguardLocked) { Log.d(TAG, "Screen on when locked") - Utils.setShowWhenLocked(this@MainActivity, Call.inCall()) + this@MainActivity.setShowWhenLocked(Call.inCall()) } } } @@ -863,8 +863,8 @@ class MainActivity : AppCompatActivity() { // Called when MainActivity already exists at the top of current task super.onNewIntent(intent) - Utils.setShowWhenLocked(this, true) - Utils.setTurnScreenOn(this, true) + this.setShowWhenLocked(true) + this.setTurnScreenOn(true) resumeAction = "" resumeUri = "" @@ -1289,7 +1289,7 @@ class MainActivity : AppCompatActivity() { callsButton.setImageResource(R.drawable.calls_missed) } if (kgm.isDeviceLocked) - Utils.setShowWhenLocked(this, false) + this.setShowWhenLocked(false) } "message", "message show", "message reply" -> { val i = Intent(applicationContext, ChatActivity::class.java) diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index f9dbf6ca..a22e41b1 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -20,7 +20,6 @@ import android.text.Editable import android.text.TextWatcher import android.text.format.DateUtils import android.view.View -import android.view.WindowManager import android.widget.ImageView import android.widget.TextView import android.media.AudioDeviceInfo @@ -869,35 +868,10 @@ object Utils { BaresipService.activities.add(0, activity) } - @Suppress("DEPRECATION") - fun setShowWhenLocked(activity: Activity, show: Boolean) { - when { - Build.VERSION.SDK_INT >= 27 -> activity.setShowWhenLocked(show) - show -> activity.window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) - else -> activity.window.clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) - } - } - - fun setTurnScreenOn(activity: Activity, turn: Boolean) { - if (Build.VERSION.SDK_INT >= 27) { - activity.setTurnScreenOn(turn) - } else - @Suppress("DEPRECATION") - if (turn) { - activity.window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) - } else { - activity.window.clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) - } - } - - @Suppress("DEPRECATION") fun requestDismissKeyguard(activity: Activity) { - if (Build.VERSION.SDK_INT >= 26) { - val kgm = activity.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager - kgm.requestDismissKeyguard(activity, null) - } else { - activity.window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD) - } + val kgm = activity.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager + kgm.requestDismissKeyguard(activity, null) + } fun relativeTime(ctx: Context, time: GregorianCalendar): String { diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 339d2392..923be0b5 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -341,7 +341,7 @@ TLS-sertifikaattitiedosto Jos merkitty, tiedosto joka sisältää tämän baresip-sovelluksen julkisen ja yksityisen TLS-sertifikaatin, on joko jo ladattu - tai tullaan lataamaan. Android versioon 9 saakka tiedosto nimeltään \'cert.pem\' + tai tullaan lataamaan. Android versiossa 9 tiedosto nimeltään \'cert.pem\' ladataan Download-kansiosta. Turvallisuusyistä tuhoa tiedosto heti lataamisen jälkeen. Tarkista palvelinten sertifikaatit @@ -351,7 +351,7 @@ TLS CA-tiedosto Jos merkitty, tiedosto on joko jo ladattu tai tullaan lataamaan, joka sisältää sellaisten sertifikaattiauktoriteettien (CA) julkiset sertifikaatit, - jotka eivät sisälly Android-käyttöjärjestelmään. Android versioon 9 saakka tiedosto + jotka eivät sisälly Android-käyttöjärjestelmään. Android versiossa 9 tiedosto nimeltään \'ca_certs.crt\' ladataan Download-kansiosta. Audio-asetukset @@ -558,14 +558,14 @@ Sovelluksen tiedot talletettiin tiedostoon \'%1$s\'. Android versioon 9 saakka tiedosto löytyy Download-kansiosta. Sovelluksen tietojen talletus - tiedostoon \'%1$s\' epäonnistui. Android versioon 9 saakka - Tarkista Asetukset → Sovellukset → baresip → Käyttöluvat → Tallennustila. + tiedostoon \'%1$s\' epäonnistui. Android versiossa 9 tarkista + Asetukset → Sovellukset → baresip → Käyttöluvat → Tallennustila. Uudelleenkäynnistyspyyntö Sovelluksen tiedot palautettiin. baresip pitää käynnistää uudelleen. Käynnistä uudelleen nyt\? Sovelluksen tietojen palauttaminen epäonnistui. Tarkista, että annoit oikean salasanan ja että palautustiedosto kuuluu tällä sovellukselle. - Android versioon 9 saakka tarkista myös Asetukset → Sovellukset → baresip → Käyttöluvat → + Android versiossa 9 tarkista myös Asetukset → Sovellukset → baresip → Käyttöluvat → Tallennustila ja että tiedosto \'%1$s\' on Download-kansiossa. Sovelluksen tietojen palauttaminen epäonnistui. Android versiosta 14 alkaen ei salli tietojen palauttamista, jos ne on tallettu ennen %1$s versioa diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 994a7a98..b6ae6b1c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -321,8 +321,8 @@ Failed to set DNS servers TLS Certificate File If checked, a file containing TLS certificate and - private key of this baresip instance has been or will be loaded. In Android versions 9 and - below, a file called \'cert.pem\' is loaded from Download folder. For security reasons, + private key of this baresip instance has been or will be loaded. In Android version 9, + a file called \'cert.pem\' is loaded from Download folder. For security reasons, delete the file after loading. Verify Server Certificates If checked, baresip verifies TLS certificates of SIP User @@ -330,8 +330,7 @@ TLS CA File If checked, a file has been or will be loaded that contains TLS certificates of such Certificate Authorities that are not included in Android OS. - In Android versions 9 and below, a file called \'ca_certs.crt\' is loaded from - Download folder. + In Android version 9, a file called \'ca_certs.crt\' is loaded from Download folder. Audio Settings Speaker Phone If checked, speaker phone is turned automatically on @@ -529,7 +528,7 @@ Unverify Application data has been backed up to file \'%1$s\'. In Android - versions 9 and below, the file is in Download folder. + version 9, the file is in Download folder. Failed to back up application data to file \'%1$s\'. Check Apps → baresip → Permissions → Storage. Restart Request @@ -537,7 +536,7 @@ Restart now\? Failed to restore application data. Check that you gave correct - password and that the backup file is from this application. In Android versions 9 and below, + password and that the backup file is from this application. In Android versions 9, also check Apps → baresip → Permissions → Storage and that file \'%1$s\' exists in Download folder.