- Made backup/restore to work also on Android 10 (API level 29)

- Suppressed some warnings.
This commit is contained in:
Juha Heinanen
2020-04-12 11:52:14 +03:00
parent 43f5a003f2
commit 54e1a53075
5 changed files with 71 additions and 57 deletions
+4 -1
View File
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.tutpro.baresip"> package="com.tutpro.baresip">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
@@ -34,7 +35,9 @@
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:requestLegacyExternalStorage="true"
android:theme="@style/AppTheme"
tools:targetApi="q">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize" android:configChanges="orientation|keyboardHidden|screenSize"
@@ -86,24 +86,26 @@ class BaresipService: Service() {
override fun onAvailable(network: Network) { override fun onAvailable(network: Network) {
super.onAvailable(network) super.onAvailable(network)
val linkProperties = cm.getLinkProperties(network) val linkProps = cm.getLinkProperties(network)
val interfaceName = linkProperties.interfaceName!! if (linkProps != null) {
val interfaceName = linkProps.interfaceName!!
if (((Build.VERSION.SDK_INT >= 23) && (network == cm.activeNetwork)) || if (((Build.VERSION.SDK_INT >= 23) && (network == cm.activeNetwork)) ||
((Build.VERSION.SDK_INT < 23) && ((Build.VERSION.SDK_INT < 23) &&
(cm.activeNetworkInfo.toString() == (cm.activeNetworkInfo.toString() ==
cm.getNetworkInfo(network).toString()))) { cm.getNetworkInfo(network).toString()))) {
Log.i(LOG_TAG, "Active network $network@$interfaceName " + Log.i(LOG_TAG, "Active network $network@$interfaceName " +
" is available: $linkProperties") " is available: $linkProps")
activeNetwork = "$network" activeNetwork = "$network"
if (isServiceRunning) { if (isServiceRunning) {
Utils.updateLinkProperties(linkProperties) Utils.updateLinkProperties(linkProps)
} else { } else {
dnsServers = linkProperties.dnsServers dnsServers = linkProps.dnsServers
linkAddresses = linkProperties.linkAddresses linkAddresses = linkProps.linkAddresses
} }
} else { } else {
Log.i(LOG_TAG, "Non-active network $network@$interfaceName " + Log.i(LOG_TAG, "Non-active network $network@$interfaceName " +
" is available: $linkProperties") " is available: $linkProps")
}
} }
} }
@@ -124,12 +126,14 @@ class BaresipService: Service() {
} }
} }
if (newNetwork != null) { if (newNetwork != null) {
val interfaceName = cm.getLinkProperties(newNetwork).interfaceName!! val linkProps = cm.getLinkProperties(newNetwork)
val linkProperties = cm.getLinkProperties(newNetwork) if (linkProps != null) {
val interfaceName = linkProps.interfaceName
Log.d(LOG_TAG, "Updating new active network " + Log.d(LOG_TAG, "Updating new active network " +
"$newNetwork@$interfaceName link properties: $linkProperties") "$newNetwork@$interfaceName link properties: $linkProps")
activeNetwork = "$newNetwork" activeNetwork = "$newNetwork"
Utils.updateLinkProperties(cm.getLinkProperties(newNetwork)) Utils.updateLinkProperties(linkProps)
}
} }
} else { } else {
Log.d(LOG_TAG, "Network '$network' is lost") Log.d(LOG_TAG, "Network '$network' is lost")
@@ -138,7 +142,9 @@ class BaresipService: Service() {
override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) { override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) {
super.onLinkPropertiesChanged(network, linkProperties) super.onLinkPropertiesChanged(network, linkProperties)
val interfaceName = cm.getLinkProperties(network).interfaceName!! val linkProps = cm.getLinkProperties(network)
if (linkProps != null) {
val interfaceName = linkProps.interfaceName
if (((Build.VERSION.SDK_INT >= 23) && (network == cm.activeNetwork)) || if (((Build.VERSION.SDK_INT >= 23) && (network == cm.activeNetwork)) ||
((Build.VERSION.SDK_INT < 23) && ((Build.VERSION.SDK_INT < 23) &&
(cm.activeNetworkInfo.toString() == (cm.activeNetworkInfo.toString() ==
@@ -158,6 +164,7 @@ class BaresipService: Service() {
} }
} }
} }
}
) )
pm = getSystemService(Context.POWER_SERVICE) as PowerManager pm = getSystemService(Context.POWER_SERVICE) as PowerManager
@@ -331,7 +338,7 @@ class BaresipService: Service() {
} }
"Call Reject" -> { "Call Reject" -> {
val callp = intent!!.getStringExtra("callp") val callp = intent!!.getStringExtra("callp")!!
val call = Call.find(callp) val call = Call.find(callp)
if (call == null) { if (call == null) {
Log.w(LOG_TAG, "onStartCommand did not find call $callp") Log.w(LOG_TAG, "onStartCommand did not find call $callp")
@@ -348,7 +355,7 @@ class BaresipService: Service() {
} }
"Transfer Show", "Transfer Accept" -> { "Transfer Show", "Transfer Accept" -> {
val uap = intent!!.getStringExtra("uap") val uap = intent!!.getStringExtra("uap")!!
val ua = UserAgent.find(uap) val ua = UserAgent.find(uap)
if (ua == null) { if (ua == null) {
Log.w(LOG_TAG, "onStartCommand did not find ua $uap") Log.w(LOG_TAG, "onStartCommand did not find ua $uap")
@@ -365,7 +372,7 @@ class BaresipService: Service() {
} }
"Transfer Deny" -> { "Transfer Deny" -> {
val callp = intent!!.getStringExtra("callp") val callp = intent!!.getStringExtra("callp")!!
val call = Call.find(callp) val call = Call.find(callp)
if (call == null) if (call == null)
Log.w(LOG_TAG, "onStartCommand did not find call $callp") Log.w(LOG_TAG, "onStartCommand did not find call $callp")
@@ -386,24 +393,24 @@ class BaresipService: Service() {
} }
"Message Save" -> { "Message Save" -> {
val uap = intent!!.getStringExtra("uap") val uap = intent!!.getStringExtra("uap")!!
val ua = UserAgent.find(uap) val ua = UserAgent.find(uap)
if (ua == null) if (ua == null)
Log.w(LOG_TAG, "onStartCommand did not find UA $uap") Log.w(LOG_TAG, "onStartCommand did not find UA $uap")
else else
ChatsActivity.saveUaMessage(ua.account.aor, ChatsActivity.saveUaMessage(ua.account.aor,
intent.getStringExtra("time").toLong()) intent.getStringExtra("time")!!.toLong())
nm.cancel(MESSAGE_NOTIFICATION_ID) nm.cancel(MESSAGE_NOTIFICATION_ID)
} }
"Message Delete" -> { "Message Delete" -> {
val uap = intent!!.getStringExtra("uap") val uap = intent!!.getStringExtra("uap")!!
val ua = UserAgent.find(uap) val ua = UserAgent.find(uap)
if (ua == null) if (ua == null)
Log.w(LOG_TAG, "onStartCommand did not find UA $uap") Log.w(LOG_TAG, "onStartCommand did not find UA $uap")
else else
ChatsActivity.deleteUaMessage(ua.account.aor, ChatsActivity.deleteUaMessage(ua.account.aor,
intent.getStringExtra("time").toLong()) intent.getStringExtra("time")!!.toLong())
nm.cancel(MESSAGE_NOTIFICATION_ID) nm.cancel(MESSAGE_NOTIFICATION_ID)
} }
@@ -517,7 +524,9 @@ class BaresipService: Service() {
if (Build.VERSION.SDK_INT >= 23) { 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 linkProps = cm.getLinkProperties(activeNetwork)
if (linkProps != null) {
val dnsServers = linkProps.dnsServers
Log.d(LOG_TAG, "Updating DNS Servers = $dnsServers") Log.d(LOG_TAG, "Updating DNS Servers = $dnsServers")
if (Config.updateDnsServers(dnsServers) != 0) { if (Config.updateDnsServers(dnsServers) != 0) {
Log.w(LOG_TAG, "Failed to update DNS servers '$dnsServers'") Log.w(LOG_TAG, "Failed to update DNS servers '$dnsServers'")
@@ -528,7 +537,7 @@ class BaresipService: Service() {
Api.ua_register(uap) Api.ua_register(uap)
} }
} }
}
} else { } else {
Log.d(LOG_TAG, "No active network!") Log.d(LOG_TAG, "No active network!")
} }
@@ -62,6 +62,7 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String,
try { try {
val fis = FileInputStream(file) val fis = FileInputStream(file)
val ois = ObjectInputStream(fis) val ois = ObjectInputStream(fis)
@Suppress("UNCHECKED_CAST")
BaresipService.callHistory = ois.readObject() as ArrayList<CallHistory> BaresipService.callHistory = ois.readObject() as ArrayList<CallHistory>
ois.close() ois.close()
fis.close() fis.close()
@@ -156,8 +156,8 @@ class ChatActivity : AppCompatActivity() {
messageResponseReceiver = object : BroadcastReceiver() { messageResponseReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
handleMessageResponse(intent.getIntExtra("response code", 0), handleMessageResponse(intent.getIntExtra("response code", 0),
intent.getStringExtra("response reason"), intent.getStringExtra("response reason")!!,
intent.getStringExtra("time")) intent.getStringExtra("time")!!)
} }
} }
LocalBroadcastManager.getInstance(this).registerReceiver(messageResponseReceiver, LocalBroadcastManager.getInstance(this).registerReceiver(messageResponseReceiver,
@@ -57,6 +57,7 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
try { try {
val fis = FileInputStream(file) val fis = FileInputStream(file)
val ois = ObjectInputStream(fis) val ois = ObjectInputStream(fis)
@Suppress("UNCHECKED_CAST")
BaresipService.messages = ois.readObject() as ArrayList<Message> BaresipService.messages = ois.readObject() as ArrayList<Message>
ois.close() ois.close()
fis.close() fis.close()