re-register when network state changes to CONNECTED
This commit is contained in:
@ -4,9 +4,10 @@ import android.Manifest
|
|||||||
import android.app.Notification.VISIBILITY_PUBLIC
|
import android.app.Notification.VISIBILITY_PUBLIC
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.app.PendingIntent.getActivity
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
@ -23,7 +24,7 @@ import android.view.*
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.os.SystemClock
|
import android.net.NetworkInfo
|
||||||
import android.support.v7.app.NotificationCompat
|
import android.support.v7.app.NotificationCompat
|
||||||
import android.support.v7.view.menu.ActionMenuItemView
|
import android.support.v7.view.menu.ActionMenuItemView
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
@ -79,6 +80,19 @@ class MainActivity : AppCompatActivity() {
|
|||||||
PendingIntent.FLAG_UPDATE_CURRENT))
|
PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
.setContent(RemoteViews(getPackageName(), R.layout.notification))
|
.setContent(RemoteViews(getPackageName(), R.layout.notification))
|
||||||
|
|
||||||
|
val intentFilter = IntentFilter("android.net.conn.CONNECTIVITY_CHANGE")
|
||||||
|
val receiver = object : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
val intentExtras = intent.extras
|
||||||
|
val info = intentExtras.getParcelable<NetworkInfo>("networkInfo")
|
||||||
|
if (running && (info.state == NetworkInfo.State.CONNECTED)) {
|
||||||
|
Log.d("Baresip", "Registering upon CONNECTED event")
|
||||||
|
UserAgent.register(uas)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
registerReceiver(receiver, intentFilter)
|
||||||
|
|
||||||
aorSpinner = findViewById(R.id.AoRList) as Spinner
|
aorSpinner = findViewById(R.id.AoRList) as Spinner
|
||||||
uaAdapter = UaSpinnerAdapter(applicationContext, uas, images)
|
uaAdapter = UaSpinnerAdapter(applicationContext, uas, images)
|
||||||
aorSpinner.adapter = uaAdapter
|
aorSpinner.adapter = uaAdapter
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
|
||||||
class UserAgent (val uap: String) {
|
class UserAgent (val uap: String) {
|
||||||
|
|
||||||
val account = Account(ua_account(uap))
|
val account = Account(ua_account(uap))
|
||||||
@ -13,20 +15,19 @@ class UserAgent (val uap: String) {
|
|||||||
external fun ua_isregistered(ua: String): Boolean
|
external fun ua_isregistered(ua: String): Boolean
|
||||||
external fun ua_unregister(ua: String)
|
external fun ua_unregister(ua: String)
|
||||||
|
|
||||||
fun userAgents(): ArrayList<UserAgent> {
|
|
||||||
val res = ArrayList<UserAgent>()
|
|
||||||
for (ua in MainActivity.uas) {
|
|
||||||
res.add(ua)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
fun find(uas: ArrayList<UserAgent>, uap: String): UserAgent? {
|
fun find(uas: ArrayList<UserAgent>, uap: String): UserAgent? {
|
||||||
for (u in uas) {
|
for (ua in uas) {
|
||||||
if (u.uap == uap) return u
|
if (ua.uap == uap) return ua
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun register(uas: ArrayList<UserAgent>) {
|
||||||
|
for (ua in uas) {
|
||||||
|
if (ua_register(ua.uap) != 0)
|
||||||
|
Log.e("Baresip", "Failed to register ${ua.aor}")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user