Removed code that is not needed at API level 28 and above

Modified strings mentioning Android version below 9
This commit is contained in:
Juha Heinanen
2024-11-18 01:56:02 +02:00
parent bfa6e5285e
commit 4c00fee456
5 changed files with 59 additions and 127 deletions

View File

@ -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<Int, Int>()
private var linkAddresses = mutableMapOf<String, String>()
@ -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<String, String>()
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) {

View File

@ -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)

View File

@ -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 {

View File

@ -341,7 +341,7 @@
<string name="tls_certificate_file">TLS-sertifikaattitiedosto</string>
<string name="tls_certificate_file_help">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.
</string>
<string name="verify_server">Tarkista palvelinten sertifikaatit</string>
@ -351,7 +351,7 @@
<string name="tls_ca_file">TLS CA-tiedosto</string>
<string name="tls_ca_file_help">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.
</string>
<string name="audio_settings">Audio-asetukset</string>
@ -558,14 +558,14 @@
<string name="backed_up">Sovelluksen tiedot talletettiin tiedostoon \'%1$s\'. Android
versioon 9 saakka tiedosto löytyy Download-kansiosta.</string>
<string name="backup_failed">Sovelluksen tietojen talletus
tiedostoon \'%1$s\' epäonnistui. Android versioon 9 saakka
Tarkista Asetukset → Sovellukset → baresip → Käyttöluvat → Tallennustila.</string>
tiedostoon \'%1$s\' epäonnistui. Android versiossa 9 tarkista
Asetukset → Sovellukset → baresip → Käyttöluvat → Tallennustila.</string>
<string name="restart_request">Uudelleenkäynnistyspyyntö</string>
<string name="restored">Sovelluksen tiedot palautettiin. baresip pitää käynnistää
uudelleen. Käynnistä uudelleen nyt\?</string>
<string name="restore_failed">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.</string>
<string name="restore_unzip_failed">Sovelluksen tietojen palauttaminen epäonnistui. Android
versiosta 14 alkaen ei salli tietojen palauttamista, jos ne on tallettu ennen %1$s versioa

View File

@ -321,8 +321,8 @@
<string name="failed_to_set_dns_servers">Failed to set DNS servers</string>
<string name="tls_certificate_file">TLS Certificate File</string>
<string name="tls_certificate_file_help">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.</string>
<string name="verify_server">Verify Server Certificates</string>
<string name="verify_server_help">If checked, baresip verifies TLS certificates of SIP User
@ -330,8 +330,7 @@
<string name="tls_ca_file">TLS CA File</string>
<string name="tls_ca_file_help">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.</string>
In Android version 9, a file called \'ca_certs.crt\' is loaded from Download folder.</string>
<string name="audio_settings">Audio Settings</string>
<string name="speaker_phone">Speaker Phone</string>
<string name="speaker_phone_help">If checked, speaker phone is turned automatically on
@ -529,7 +528,7 @@
</string>
<string name="unverify">Unverify</string>
<string name="backed_up">Application data has been backed up to file \'%1$s\'. In Android
versions 9 and below, the file is in Download folder.</string>
version 9, the file is in Download folder.</string>
<string name="backup_failed">Failed to back up application data to file
\'%1$s\'. Check Apps → baresip → Permissions → Storage.</string>
<string name="restart_request">Restart Request</string>
@ -537,7 +536,7 @@
Restart now\?
</string>
<string name="restore_failed">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.
</string>