- Use Int build version values rather than VERSION_CODES constants.

This commit is contained in:
Juha Heinanen
2019-10-13 14:55:04 +03:00
parent 374ee09050
commit d7a3a91302
3 changed files with 16 additions and 16 deletions
@@ -161,7 +161,7 @@ class BaresipService: Service() {
} }
if (a == "config") { if (a == "config") {
var dnsServers = listOf<InetAddress>() var dnsServers = listOf<InetAddress>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= 23) {
val activeNetwork = cm.activeNetwork val activeNetwork = cm.activeNetwork
if (activeNetwork != null) { if (activeNetwork != null) {
dnsServers = cm.getLinkProperties(activeNetwork).dnsServers dnsServers = cm.getLinkProperties(activeNetwork).dnsServers
@@ -382,7 +382,7 @@ class BaresipService: Service() {
newEvent = "registering failed,DNS lookup failed" newEvent = "registering failed,DNS lookup failed"
Api.net_dns_debug() Api.net_dns_debug()
if (dynDns) if (dynDns)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= 23) {
val activeNetwork = cm.activeNetwork val activeNetwork = cm.activeNetwork
if (activeNetwork != null) { if (activeNetwork != null) {
val dnsServers = cm.getLinkProperties(activeNetwork).dnsServers val dnsServers = cm.getLinkProperties(activeNetwork).dnsServers
@@ -437,7 +437,7 @@ class BaresipService: Service() {
calls.add(Call(callp, ua, peerUri, "in", "incoming", calls.add(Call(callp, ua, peerUri, "in", "incoming",
Utils.dtmfWatcher(callp))) Utils.dtmfWatcher(callp)))
if (ua.account.answerMode == "manual") { if (ua.account.answerMode == "manual") {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= 23) {
Log.d(LOG_TAG, "CurrentInterruptionFilter ${nm.currentInterruptionFilter}") Log.d(LOG_TAG, "CurrentInterruptionFilter ${nm.currentInterruptionFilter}")
if (nm.currentInterruptionFilter <= NotificationManager.INTERRUPTION_FILTER_ALL) if (nm.currentInterruptionFilter <= NotificationManager.INTERRUPTION_FILTER_ALL)
startRinging() startRinging()
@@ -472,7 +472,7 @@ class BaresipService: Service() {
.setOngoing(true) .setOngoing(true)
.setContentTitle(getString(R.string.incoming_call_from)) .setContentTitle(getString(R.string.incoming_call_from))
.setContentText(caller) .setContentText(caller)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT < 26) {
nb.setVibrate(LongArray(0)) nb.setVibrate(LongArray(0))
.setVisibility(VISIBILITY_PRIVATE) .setVisibility(VISIBILITY_PRIVATE)
.setPriority(Notification.PRIORITY_HIGH) .setPriority(Notification.PRIORITY_HIGH)
@@ -558,7 +558,7 @@ class BaresipService: Service() {
.setAutoCancel(true) .setAutoCancel(true)
.setContentTitle(getString(R.string.transfer_request)) .setContentTitle(getString(R.string.transfer_request))
.setContentText(target) .setContentText(target)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT < 26) {
nb.setVibrate(LongArray(0)) nb.setVibrate(LongArray(0))
.setVisibility(VISIBILITY_PRIVATE) .setVisibility(VISIBILITY_PRIVATE)
.setPriority(Notification.PRIORITY_HIGH) .setPriority(Notification.PRIORITY_HIGH)
@@ -661,7 +661,7 @@ class BaresipService: Service() {
.setAutoCancel(true) .setAutoCancel(true)
.setContentTitle(getString(R.string.message_from) + " " + sender) .setContentTitle(getString(R.string.message_from) + " " + sender)
.setContentText(text) .setContentText(text)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT < 26) {
nb.setVibrate(LongArray(0)) nb.setVibrate(LongArray(0))
.setVisibility(VISIBILITY_PRIVATE) .setVisibility(VISIBILITY_PRIVATE)
.setPriority(Notification.PRIORITY_HIGH) .setPriority(Notification.PRIORITY_HIGH)
@@ -725,7 +725,7 @@ class BaresipService: Service() {
} }
private fun createNotificationChannels() { private fun createNotificationChannels() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= 26) {
val defaultChannel = NotificationChannel(DEFAULT_CHANNEL_ID, "Default", val defaultChannel = NotificationChannel(DEFAULT_CHANNEL_ID, "Default",
NotificationManager.IMPORTANCE_LOW) NotificationManager.IMPORTANCE_LOW)
defaultChannel.lockscreenVisibility = VISIBILITY_PUBLIC defaultChannel.lockscreenVisibility = VISIBILITY_PUBLIC
@@ -771,7 +771,7 @@ class BaresipService: Service() {
} }
private fun requestAudioFocus(streamType: Int) { private fun requestAudioFocus(streamType: Int) {
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) && (audioFocusRequest == null)) { if ((Build.VERSION.SDK_INT >= 26) && (audioFocusRequest == null)) {
@TargetApi(26) @TargetApi(26)
audioFocusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN).run { audioFocusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN).run {
setAudioAttributes(AudioAttributes.Builder().run { setAudioAttributes(AudioAttributes.Builder().run {
@@ -800,14 +800,14 @@ class BaresipService: Service() {
} }
private fun isAudioFocused(): Boolean { private fun isAudioFocused(): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= 26)
return audioFocusRequest != null return audioFocusRequest != null
else else
return audioFocused return audioFocused
} }
private fun abandonAudioFocus() { private fun abandonAudioFocus() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= 26) {
if (audioFocusRequest != null) { if (audioFocusRequest != null) {
am.abandonAudioFocusRequest(audioFocusRequest!!) am.abandonAudioFocusRequest(audioFocusRequest!!)
audioFocusRequest = null audioFocusRequest = null
@@ -825,7 +825,7 @@ class BaresipService: Service() {
private fun startRinging() { private fun startRinging() {
am.mode = AudioManager.MODE_RINGTONE am.mode = AudioManager.MODE_RINGTONE
requestAudioFocus(AudioManager.STREAM_RING) requestAudioFocus(AudioManager.STREAM_RING)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= 28) {
rt.isLooping = true rt.isLooping = true
rt.play() rt.play()
} else { } else {
@@ -842,7 +842,7 @@ class BaresipService: Service() {
} }
private fun stopRinging() { private fun stopRinging() {
if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.P) && (rtTimer != null)) { if ((Build.VERSION.SDK_INT < 28) && (rtTimer != null)) {
rtTimer!!.cancel() rtTimer!!.cancel()
rtTimer = null rtTimer = null
} }
@@ -205,7 +205,7 @@ class ConfigActivity : AppCompatActivity() {
} }
} else { } else {
Config.add("dyn_dns", "yes") Config.add("dyn_dns", "yes")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= 23) {
val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
Config.updateDnsServers(cm.getLinkProperties(cm.activeNetwork).getDnsServers()) Config.updateDnsServers(cm.getLinkProperties(cm.activeNetwork).getDnsServers())
} else { } else {
@@ -62,7 +62,7 @@ class MainActivity : AppCompatActivity() {
Log.d("Baresip", "Main created with action '$intentAction'") Log.d("Baresip", "Main created with action '$intentAction'")
kgm = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager kgm = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if (Build.VERSION.SDK_INT >= 27) {
setShowWhenLocked(true) setShowWhenLocked(true)
setTurnScreenOn(true) setTurnScreenOn(true)
kgm.requestDismissKeyguard(this, null) kgm.requestDismissKeyguard(this, null)
@@ -182,14 +182,14 @@ class MainActivity : AppCompatActivity() {
callUri.threshold = 2 callUri.threshold = 2
callUri.setOnFocusChangeListener { view, b -> callUri.setOnFocusChangeListener { view, b ->
if (b) { if (b) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if (Build.VERSION.SDK_INT >= 27) {
kgm.requestDismissKeyguard(this, null) kgm.requestDismissKeyguard(this, null)
} }
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT) imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
} }
} }
callUri.setOnClickListener { view -> callUri.setOnClickListener { view ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if (Build.VERSION.SDK_INT >= 27) {
kgm.requestDismissKeyguard(this, null) kgm.requestDismissKeyguard(this, null)
} }
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT) imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)