show heads-up notification when call comes in
use ua_hold_answer to answer incoming call removed failing attempt to remove key guard
This commit is contained in:
@ -22,7 +22,6 @@ import android.util.Log
|
|||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.net.NetworkInfo
|
import android.net.NetworkInfo
|
||||||
import android.os.PowerManager
|
|
||||||
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
|
||||||
@ -48,8 +47,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
internal lateinit var am: AudioManager
|
internal lateinit var am: AudioManager
|
||||||
internal lateinit var imm: InputMethodManager
|
internal lateinit var imm: InputMethodManager
|
||||||
internal lateinit var nm: NotificationManager
|
internal lateinit var nm: NotificationManager
|
||||||
internal lateinit var pm: PowerManager
|
|
||||||
internal lateinit var wl: PowerManager.WakeLock
|
|
||||||
internal lateinit var nb: NotificationCompat.Builder
|
internal lateinit var nb: NotificationCompat.Builder
|
||||||
internal lateinit var receiver: BroadcastReceiver
|
internal lateinit var receiver: BroadcastReceiver
|
||||||
|
|
||||||
@ -57,10 +54,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
|
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
||||||
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or
|
||||||
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
|
WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES)
|
||||||
|
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
appContext = applicationContext
|
appContext = applicationContext
|
||||||
@ -76,9 +72,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
am = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
am = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
pm = getSystemService(Context.POWER_SERVICE) as PowerManager
|
|
||||||
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK or
|
|
||||||
PowerManager.ACQUIRE_CAUSES_WAKEUP, "")
|
|
||||||
|
|
||||||
nb = NotificationCompat.Builder(this)
|
nb = NotificationCompat.Builder(this)
|
||||||
nb.setVisibility(VISIBILITY_PUBLIC).setOngoing(true).setSmallIcon(R.drawable.ic_stat)
|
nb.setVisibility(VISIBILITY_PUBLIC).setOngoing(true).setSmallIcon(R.drawable.ic_stat)
|
||||||
@ -455,7 +448,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
baresipStop()
|
baresipStop()
|
||||||
nm.cancel(10)
|
nm.cancelAll()
|
||||||
running = false
|
running = false
|
||||||
}
|
}
|
||||||
unregisterReceiver(receiver)
|
unregisterReceiver(receiver)
|
||||||
@ -635,8 +628,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
answer_button.setOnClickListener { v ->
|
answer_button.setOnClickListener { v ->
|
||||||
when ((v as ImageButton).tag) {
|
when ((v as ImageButton).tag) {
|
||||||
"Answer" -> {
|
"Answer" -> {
|
||||||
Log.i("Baresip", "UA ${call.ua.uap} accepting incoming call ${call.callp}")
|
Log.i("Baresip", "UA ${ua.uap} accepting incoming call ${call.callp}")
|
||||||
ua_answer(call.ua.uap, call.callp)
|
ua_hold_answer(ua.uap, "")
|
||||||
if (call.dir == "in") {
|
if (call.dir == "in") {
|
||||||
this@MainActivity.runOnUiThread {
|
this@MainActivity.runOnUiThread {
|
||||||
call.status = "Hangup"
|
call.status = "Hangup"
|
||||||
@ -787,12 +780,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
"call ringing" -> {
|
"call ringing" -> {
|
||||||
}
|
}
|
||||||
"call incoming" -> {
|
"call incoming" -> {
|
||||||
if (!pm.isInteractive) {
|
|
||||||
Log.d("Baresip", "Acquiring wake lock")
|
|
||||||
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK or
|
|
||||||
PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag")
|
|
||||||
wl.acquire()
|
|
||||||
}
|
|
||||||
val peer_uri = call_peeruri(callp)
|
val peer_uri = call_peeruri(callp)
|
||||||
Log.d("Baresip", "Incoming call $uap/$callp/$peer_uri")
|
Log.d("Baresip", "Incoming call $uap/$callp/$peer_uri")
|
||||||
val new_call = Call(callp, ua, peer_uri, "in", "Answer", null)
|
val new_call = Call(callp, ua, peer_uri, "in", "Answer", null)
|
||||||
@ -803,12 +790,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
else
|
else
|
||||||
addCallViews(ua, new_call, Call.uaCalls(calls, ua,"in").size * 10)
|
addCallViews(ua, new_call, Call.uaCalls(calls, ua,"in").size * 10)
|
||||||
am.mode = AudioManager.MODE_RINGTONE
|
am.mode = AudioManager.MODE_RINGTONE
|
||||||
|
if (Utils.foregrounded()) {
|
||||||
|
val i = Intent(this, MainActivity::class.java)
|
||||||
|
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
|
||||||
|
startActivity(i)
|
||||||
|
} else {
|
||||||
|
showNotification(peer_uri)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Utils.foregrounded()) {
|
|
||||||
val i = Intent(this, MainActivity::class.java)
|
|
||||||
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
|
|
||||||
startActivity(i)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"call established" -> {
|
"call established" -> {
|
||||||
val call = Call.find(calls, callp)
|
val call = Call.find(calls, callp)
|
||||||
@ -865,7 +855,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
history.add(History(aor, call.peerURI, "in", true))
|
history.add(History(aor, call.peerURI, "in", true))
|
||||||
call.hasHistory = true
|
call.hasHistory = true
|
||||||
if (wl.isHeld) wl.release()
|
|
||||||
}
|
}
|
||||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
am.isSpeakerphoneOn = false
|
am.isSpeakerphoneOn = false
|
||||||
@ -986,6 +975,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
historyButton.visibility = View.VISIBLE
|
historyButton.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
nm.cancel(INCOMING_ID)
|
||||||
}
|
}
|
||||||
if (!call.hasHistory) {
|
if (!call.hasHistory) {
|
||||||
if (History.aorHistory(history, aor) > HISTORY_SIZE)
|
if (History.aorHistory(history, aor) > HISTORY_SIZE)
|
||||||
@ -1020,7 +1010,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
false))
|
false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (wl.isHeld) wl.release()
|
|
||||||
if (calls.size == 0) am.mode = AudioManager.MODE_NORMAL
|
if (calls.size == 0) am.mode = AudioManager.MODE_NORMAL
|
||||||
}
|
}
|
||||||
else -> Log.d("Baresip", "Unknown event '${ev[0]}'")
|
else -> Log.d("Baresip", "Unknown event '${ev[0]}'")
|
||||||
@ -1055,10 +1044,30 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showNotification(peerUri: String) {
|
||||||
|
Log.d("Baresip", "Showing notification")
|
||||||
|
val nb = NotificationCompat.Builder(this)
|
||||||
|
.setVisibility(VISIBILITY_PUBLIC)
|
||||||
|
.setSmallIcon(R.drawable.ic_stat)
|
||||||
|
.setContentTitle("Incoming call from")
|
||||||
|
.setContentText("$peerUri")
|
||||||
|
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.setContentIntent(
|
||||||
|
PendingIntent.getActivity(this, INCOMING_ID,
|
||||||
|
Intent(this, MainActivity::class.java)
|
||||||
|
.setAction(Intent.ACTION_MAIN)
|
||||||
|
.addCategory(Intent.CATEGORY_LAUNCHER),
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
|
nm.notify(INCOMING_ID, nb.build())
|
||||||
|
}
|
||||||
|
|
||||||
external fun baresipStart(path: String)
|
external fun baresipStart(path: String)
|
||||||
external fun baresipStop()
|
external fun baresipStop()
|
||||||
external fun ua_connect(ua: String, peer_uri: String): String
|
external fun ua_connect(ua: String, peer_uri: String): String
|
||||||
external fun ua_answer(ua: String, call: String)
|
external fun ua_answer(ua: String, call: String)
|
||||||
|
external fun ua_hold_answer(ua: String, call: String): Int
|
||||||
external fun ua_hangup(ua: String, call: String, code: Int, reason: String)
|
external fun ua_hangup(ua: String, call: String, code: Int, reason: String)
|
||||||
external fun call_peeruri(call: String): String
|
external fun call_peeruri(call: String): String
|
||||||
external fun call_hold(call: String): Int
|
external fun call_hold(call: String): Int
|
||||||
|
|||||||
Reference in New Issue
Block a user