- 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) {
if (((Build.VERSION.SDK_INT >= 23) && (network == cm.activeNetwork)) || val interfaceName = linkProps.interfaceName!!
((Build.VERSION.SDK_INT < 23) && if (((Build.VERSION.SDK_INT >= 23) && (network == cm.activeNetwork)) ||
(cm.activeNetworkInfo.toString() == ((Build.VERSION.SDK_INT < 23) &&
cm.getNetworkInfo(network).toString()))) { (cm.activeNetworkInfo.toString() ==
Log.i(LOG_TAG, "Active network $network@$interfaceName " + cm.getNetworkInfo(network).toString()))) {
" is available: $linkProperties") Log.i(LOG_TAG, "Active network $network@$interfaceName " +
activeNetwork = "$network" " is available: $linkProps")
if (isServiceRunning) { activeNetwork = "$network"
Utils.updateLinkProperties(linkProperties) if (isServiceRunning) {
Utils.updateLinkProperties(linkProps)
} else {
dnsServers = linkProps.dnsServers
linkAddresses = linkProps.linkAddresses
}
} else { } else {
dnsServers = linkProperties.dnsServers Log.i(LOG_TAG, "Non-active network $network@$interfaceName " +
linkAddresses = linkProperties.linkAddresses " is available: $linkProps")
} }
} else {
Log.i(LOG_TAG, "Non-active network $network@$interfaceName " +
" is available: $linkProperties")
} }
} }
@@ -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) {
Log.d(LOG_TAG, "Updating new active network " + val interfaceName = linkProps.interfaceName
"$newNetwork@$interfaceName link properties: $linkProperties") Log.d(LOG_TAG, "Updating new active network " +
activeNetwork = "$newNetwork" "$newNetwork@$interfaceName link properties: $linkProps")
Utils.updateLinkProperties(cm.getLinkProperties(newNetwork)) activeNetwork = "$newNetwork"
Utils.updateLinkProperties(linkProps)
}
} }
} else { } else {
Log.d(LOG_TAG, "Network '$network' is lost") Log.d(LOG_TAG, "Network '$network' is lost")
@@ -138,23 +142,26 @@ 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 (((Build.VERSION.SDK_INT >= 23) && (network == cm.activeNetwork)) || if (linkProps != null) {
((Build.VERSION.SDK_INT < 23) && val interfaceName = linkProps.interfaceName
(cm.activeNetworkInfo.toString() == if (((Build.VERSION.SDK_INT >= 23) && (network == cm.activeNetwork)) ||
cm.getNetworkInfo(network).toString()))) { ((Build.VERSION.SDK_INT < 23) &&
Log.d(LOG_TAG, "Active network $network@$interfaceName " + (cm.activeNetworkInfo.toString() ==
" link properties changed: $linkProperties") cm.getNetworkInfo(network).toString()))) {
activeNetwork = "$network" Log.d(LOG_TAG, "Active network $network@$interfaceName " +
if (isServiceRunning) { " link properties changed: $linkProperties")
Utils.updateLinkProperties(linkProperties) activeNetwork = "$network"
if (isServiceRunning) {
Utils.updateLinkProperties(linkProperties)
} else {
dnsServers = linkProperties.dnsServers
linkAddresses = linkProperties.linkAddresses
}
} else { } else {
dnsServers = linkProperties.dnsServers Log.d(LOG_TAG, "Network $network@$interfaceName " +
linkAddresses = linkProperties.linkAddresses " link properties changed: $linkProperties")
} }
} else {
Log.d(LOG_TAG, "Network $network@$interfaceName " +
" link properties changed: $linkProperties")
} }
} }
} }
@@ -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,18 +524,20 @@ 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)
Log.d(LOG_TAG, "Updating DNS Servers = $dnsServers") if (linkProps != null) {
if (Config.updateDnsServers(dnsServers) != 0) { val dnsServers = linkProps.dnsServers
Log.w(LOG_TAG, "Failed to update DNS servers '$dnsServers'") Log.d(LOG_TAG, "Updating DNS Servers = $dnsServers")
} else { if (Config.updateDnsServers(dnsServers) != 0) {
Api.net_dns_debug() Log.w(LOG_TAG, "Failed to update DNS servers '$dnsServers'")
if (!ua.registrationFailed) { } else {
ua.registrationFailed = true Api.net_dns_debug()
Api.ua_register(uap) if (!ua.registrationFailed) {
ua.registrationFailed = true
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()