Fixed Kotlin lint warnings
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.app.*
|
import android.app.*
|
||||||
import android.app.PendingIntent.getActivity
|
import android.app.PendingIntent.getActivity
|
||||||
@@ -37,24 +38,25 @@ class BaresipService: Service() {
|
|||||||
internal lateinit var intent: Intent
|
internal lateinit var intent: Intent
|
||||||
internal lateinit var am: AudioManager
|
internal lateinit var am: AudioManager
|
||||||
internal lateinit var rt: Ringtone
|
internal lateinit var rt: Ringtone
|
||||||
internal lateinit var nt: Ringtone
|
private lateinit var nt: Ringtone
|
||||||
internal lateinit var nm: NotificationManager
|
private lateinit var nm: NotificationManager
|
||||||
internal lateinit var snb: NotificationCompat.Builder
|
private lateinit var snb: NotificationCompat.Builder
|
||||||
internal lateinit var cm: ConnectivityManager
|
private lateinit var cm: ConnectivityManager
|
||||||
internal lateinit var pm: PowerManager
|
private lateinit var pm: PowerManager
|
||||||
internal lateinit var tm: TelephonyManager
|
private lateinit var tm: TelephonyManager
|
||||||
internal lateinit var partialWakeLock: PowerManager.WakeLock
|
private lateinit var partialWakeLock: PowerManager.WakeLock
|
||||||
internal lateinit var proximityWakeLock: PowerManager.WakeLock
|
private lateinit var proximityWakeLock: PowerManager.WakeLock
|
||||||
internal lateinit var fl: WifiManager.WifiLock
|
private lateinit var fl: WifiManager.WifiLock
|
||||||
internal lateinit var br: BroadcastReceiver
|
private lateinit var br: BroadcastReceiver
|
||||||
|
|
||||||
internal var rtTimer: Timer? = null
|
internal var rtTimer: Timer? = null
|
||||||
internal var audioFocusRequest: AudioFocusRequest? = null
|
private var audioFocusRequest: AudioFocusRequest? = null
|
||||||
internal var audioFocusUsage = -1
|
private var audioFocusUsage = -1
|
||||||
internal var origVolumes = arrayOf(-1, -1, -1, -1)
|
private var origVolumes = arrayOf(-1, -1, -1, -1)
|
||||||
internal val btAdapter = BluetoothAdapter.getDefaultAdapter()
|
private val btAdapter = BluetoothAdapter.getDefaultAdapter()
|
||||||
internal var activeNetwork = ""
|
internal var activeNetwork = ""
|
||||||
|
|
||||||
|
@SuppressLint("WakelockTimeout")
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
|
|
||||||
Log.d(TAG, "At onCreate")
|
Log.d(TAG, "At onCreate")
|
||||||
@@ -116,9 +118,15 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
tm = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
tm = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||||
|
|
||||||
partialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
// This is needed to keep service running also in Doze Mode
|
||||||
"com.tutpro.baresip:partial_wakelog")
|
partialWakeLock = pm.run {
|
||||||
partialWakeLock.acquire()
|
newWakeLock(
|
||||||
|
PowerManager.PARTIAL_WAKE_LOCK,
|
||||||
|
"com.tutpro.baresip:partial_wakelog"
|
||||||
|
).apply {
|
||||||
|
acquire()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
proximityWakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
|
proximityWakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
|
||||||
"com.tutpro.baresip:proximity_wakelog")
|
"com.tutpro.baresip:proximity_wakelog")
|
||||||
@@ -257,10 +265,12 @@ class BaresipService: Service() {
|
|||||||
val dnsServers = Utils.findDnsServers(BaresipService.dnsServers)
|
val dnsServers = Utils.findDnsServers(BaresipService.dnsServers)
|
||||||
if ((ipV4Addr == "") && (ipV6Addr == ""))
|
if ((ipV4Addr == "") && (ipV6Addr == ""))
|
||||||
Log.w(TAG, "Starting baresip without IP addresses")
|
Log.w(TAG, "Starting baresip without IP addresses")
|
||||||
Thread({
|
|
||||||
baresipStart(filesPath, ipV4Addr, ipV6Addr, "",
|
Thread {
|
||||||
dnsServers, Api.AF_UNSPEC, logLevel)
|
baresipStart(
|
||||||
}).start()
|
filesPath, ipV4Addr, ipV6Addr, "", dnsServers, Api.AF_UNSPEC, logLevel
|
||||||
|
)
|
||||||
|
}.start()
|
||||||
|
|
||||||
isServiceRunning = true
|
isServiceRunning = true
|
||||||
|
|
||||||
@@ -279,7 +289,7 @@ class BaresipService: Service() {
|
|||||||
val newIntent = Intent(this, MainActivity::class.java)
|
val newIntent = Intent(this, MainActivity::class.java)
|
||||||
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
newIntent.putExtra("action", action.toLowerCase(Locale.ROOT))
|
newIntent.putExtra("action", action.lowercase(Locale.ROOT))
|
||||||
newIntent.putExtra("callp", intent!!.getStringExtra("callp"))
|
newIntent.putExtra("callp", intent!!.getStringExtra("callp"))
|
||||||
startActivity(newIntent)
|
startActivity(newIntent)
|
||||||
}
|
}
|
||||||
@@ -288,7 +298,7 @@ class BaresipService: Service() {
|
|||||||
val newIntent = Intent(this, MainActivity::class.java)
|
val newIntent = Intent(this, MainActivity::class.java)
|
||||||
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
newIntent.putExtra("action", action.toLowerCase(Locale.ROOT))
|
newIntent.putExtra("action", action.lowercase(Locale.ROOT))
|
||||||
newIntent.putExtra("uap", intent!!.getStringExtra("uap"))
|
newIntent.putExtra("uap", intent!!.getStringExtra("uap"))
|
||||||
startActivity(newIntent)
|
startActivity(newIntent)
|
||||||
}
|
}
|
||||||
@@ -319,7 +329,7 @@ class BaresipService: Service() {
|
|||||||
val newIntent = Intent(this, MainActivity::class.java)
|
val newIntent = Intent(this, MainActivity::class.java)
|
||||||
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or
|
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or
|
||||||
Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
|
Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
newIntent.putExtra("action", action.toLowerCase(Locale.ROOT))
|
newIntent.putExtra("action", action.lowercase(Locale.ROOT))
|
||||||
newIntent.putExtra("callp", intent.getStringExtra("callp"))
|
newIntent.putExtra("callp", intent.getStringExtra("callp"))
|
||||||
newIntent.putExtra("uri", intent.getStringExtra("uri"))
|
newIntent.putExtra("uri", intent.getStringExtra("uri"))
|
||||||
startActivity(newIntent)
|
startActivity(newIntent)
|
||||||
@@ -341,7 +351,7 @@ class BaresipService: Service() {
|
|||||||
val newIntent = Intent(this, MainActivity::class.java)
|
val newIntent = Intent(this, MainActivity::class.java)
|
||||||
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
newIntent.putExtra("action", action.toLowerCase(Locale.ROOT))
|
newIntent.putExtra("action", action.lowercase(Locale.ROOT))
|
||||||
newIntent.putExtra("uap", intent!!.getStringExtra("uap"))
|
newIntent.putExtra("uap", intent!!.getStringExtra("uap"))
|
||||||
newIntent.putExtra("peer", intent.getStringExtra("peer"))
|
newIntent.putExtra("peer", intent.getStringExtra("peer"))
|
||||||
startActivity(newIntent)
|
startActivity(newIntent)
|
||||||
@@ -565,6 +575,7 @@ class BaresipService: Service() {
|
|||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setFullScreenIntent(pi, true)
|
.setFullScreenIntent(pi, true)
|
||||||
if (VERSION.SDK_INT < 26) {
|
if (VERSION.SDK_INT < 26) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
nb.setVibrate(LongArray(0))
|
nb.setVibrate(LongArray(0))
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
||||||
.priority = Notification.PRIORITY_HIGH
|
.priority = Notification.PRIORITY_HIGH
|
||||||
@@ -656,6 +667,7 @@ class BaresipService: Service() {
|
|||||||
.setContentTitle(getString(R.string.transfer_request_to))
|
.setContentTitle(getString(R.string.transfer_request_to))
|
||||||
.setContentText(target)
|
.setContentText(target)
|
||||||
if (VERSION.SDK_INT < 26)
|
if (VERSION.SDK_INT < 26)
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
nb.setVibrate(LongArray(0))
|
nb.setVibrate(LongArray(0))
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE).priority =
|
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE).priority =
|
||||||
Notification.PRIORITY_HIGH
|
Notification.PRIORITY_HIGH
|
||||||
@@ -725,6 +737,7 @@ class BaresipService: Service() {
|
|||||||
.setContentTitle(getString(R.string.missed_call_from))
|
.setContentTitle(getString(R.string.missed_call_from))
|
||||||
.setContentText(caller)
|
.setContentText(caller)
|
||||||
if (VERSION.SDK_INT < 26) {
|
if (VERSION.SDK_INT < 26) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
nb.setVibrate(LongArray(0))
|
nb.setVibrate(LongArray(0))
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
||||||
.priority = Notification.PRIORITY_HIGH
|
.priority = Notification.PRIORITY_HIGH
|
||||||
@@ -792,6 +805,7 @@ class BaresipService: Service() {
|
|||||||
.setContentTitle(getString(R.string.message_from) + " " + sender)
|
.setContentTitle(getString(R.string.message_from) + " " + sender)
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
if (VERSION.SDK_INT < 26) {
|
if (VERSION.SDK_INT < 26) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
nb.setVibrate(LongArray(0))
|
nb.setVibrate(LongArray(0))
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
||||||
.priority = Notification.PRIORITY_HIGH
|
.priority = Notification.PRIORITY_HIGH
|
||||||
@@ -830,6 +844,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
|
@Suppress("UNUSED")
|
||||||
fun messageResponse(responseCode: Int, responseReason: String, time: String) {
|
fun messageResponse(responseCode: Int, responseReason: String, time: String) {
|
||||||
Log.d(TAG, "Message response '$responseCode $responseReason' at $time")
|
Log.d(TAG, "Message response '$responseCode $responseReason' at $time")
|
||||||
val intent = Intent("message response")
|
val intent = Intent("message response")
|
||||||
@@ -843,10 +858,10 @@ class BaresipService: Service() {
|
|||||||
fun getPassword(aor: String): String {
|
fun getPassword(aor: String): String {
|
||||||
if (!isServiceRunning) return ""
|
if (!isServiceRunning) return ""
|
||||||
Log.d(TAG, "getPassword of $aor")
|
Log.d(TAG, "getPassword of $aor")
|
||||||
if (MainActivity.aorPasswords[aor] != null)
|
return if (MainActivity.aorPasswords[aor] != null)
|
||||||
return MainActivity.aorPasswords[aor]!!
|
MainActivity.aorPasswords[aor]!!
|
||||||
else
|
else
|
||||||
return ""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
@@ -958,6 +973,7 @@ class BaresipService: Service() {
|
|||||||
audioFocusUsage = -1
|
audioFocusUsage = -1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
if (am.requestAudioFocus(null, usage, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE) ==
|
if (am.requestAudioFocus(null, usage, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE) ==
|
||||||
AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
|
AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
|
||||||
Log.d(TAG, "Audio focus granted for usage $usage")
|
Log.d(TAG, "Audio focus granted for usage $usage")
|
||||||
@@ -995,6 +1011,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (audioFocusUsage != -1) {
|
if (audioFocusUsage != -1) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
if (am.abandonAudioFocus(null) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
|
if (am.abandonAudioFocus(null) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
|
||||||
Log.d(TAG, "Audio focus abandoned")
|
Log.d(TAG, "Audio focus abandoned")
|
||||||
audioFocusUsage = -1
|
audioFocusUsage = -1
|
||||||
@@ -1058,6 +1075,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("WakelockTimeout")
|
||||||
private fun proximitySensing(enable: Boolean) {
|
private fun proximitySensing(enable: Boolean) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
if (!proximityWakeLock.isHeld) {
|
if (!proximityWakeLock.isHeld) {
|
||||||
@@ -1135,6 +1153,7 @@ class BaresipService: Service() {
|
|||||||
private fun isNetworkActive(network: Network): Boolean {
|
private fun isNetworkActive(network: Network): Boolean {
|
||||||
if (VERSION.SDK_INT >= 23)
|
if (VERSION.SDK_INT >= 23)
|
||||||
return network == cm.activeNetwork
|
return network == cm.activeNetwork
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
if ((cm.activeNetworkInfo != null) && (cm.getNetworkInfo(network) != null))
|
if ((cm.activeNetworkInfo != null) && (cm.getNetworkInfo(network) != null))
|
||||||
return cm.activeNetworkInfo!!.toString() == cm.getNetworkInfo(network)!!.toString()
|
return cm.activeNetworkInfo!!.toString() == cm.getNetworkInfo(network)!!.toString()
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -482,6 +482,7 @@ object Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
fun downloadsPath(fileName: String): String {
|
fun downloadsPath(fileName: String): String {
|
||||||
return Environment.getExternalStoragePublicDirectory(
|
return Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_DOWNLOADS).path + "/$fileName"
|
Environment.DIRECTORY_DOWNLOADS).path + "/$fileName"
|
||||||
@@ -517,7 +518,9 @@ object Utils {
|
|||||||
|
|
||||||
class Crypto(val salt: ByteArray, val iter: Int, val iv: ByteArray, val data: ByteArray):
|
class Crypto(val salt: ByteArray, val iter: Int, val iv: ByteArray, val data: ByteArray):
|
||||||
Serializable {
|
Serializable {
|
||||||
val serialVersionUID = -29238082928391L
|
companion object {
|
||||||
|
private const val serialVersionUID: Long = -29238082928391L
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun encrypt(content: ByteArray, password: CharArray): Crypto? {
|
private fun encrypt(content: ByteArray, password: CharArray): Crypto? {
|
||||||
@@ -643,6 +646,7 @@ object Utils {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNUSED")
|
||||||
fun dumpIntent(intent: Intent) {
|
fun dumpIntent(intent: Intent) {
|
||||||
val bundle: Bundle = intent.extras ?: return
|
val bundle: Bundle = intent.extras ?: return
|
||||||
val keys = bundle.keySet()
|
val keys = bundle.keySet()
|
||||||
|
|||||||
Reference in New Issue
Block a user