some work on adding answer/reject buttons to call notification
some minor improvements
This commit is contained in:
@@ -111,6 +111,16 @@
|
|||||||
<service android:name=".BaresipService" >
|
<service android:name=".BaresipService" >
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true"
|
||||||
|
android:name="com.tutpro.baresip.RunOnStartup"
|
||||||
|
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ class BaresipService: Service() {
|
|||||||
private val LOG_TAG = "Baresip Service"
|
private val LOG_TAG = "Baresip Service"
|
||||||
internal lateinit var intent: Intent
|
internal lateinit var intent: Intent
|
||||||
internal lateinit var nm: NotificationManager
|
internal lateinit var nm: NotificationManager
|
||||||
internal lateinit var nb: NotificationCompat.Builder
|
internal lateinit var snb: NotificationCompat.Builder
|
||||||
|
internal lateinit var cnb: NotificationCompat.Builder
|
||||||
internal lateinit var ni: Intent
|
internal lateinit var ni: Intent
|
||||||
internal lateinit var npi: PendingIntent
|
internal lateinit var npi: PendingIntent
|
||||||
internal lateinit var nr: BroadcastReceiver
|
internal lateinit var nr: BroadcastReceiver
|
||||||
@@ -46,7 +47,8 @@ class BaresipService: Service() {
|
|||||||
intent.setPackage("com.tutpro.baresip")
|
intent.setPackage("com.tutpro.baresip")
|
||||||
|
|
||||||
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
nb = NotificationCompat.Builder(this)
|
snb = NotificationCompat.Builder(this)
|
||||||
|
cnb = NotificationCompat.Builder(this)
|
||||||
|
|
||||||
ni = Intent(this, MainActivity::class.java)
|
ni = Intent(this, MainActivity::class.java)
|
||||||
.setAction(Intent.ACTION_MAIN)
|
.setAction(Intent.ACTION_MAIN)
|
||||||
@@ -162,13 +164,13 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showNotification() {
|
private fun showNotification() {
|
||||||
nb.setVisibility(VISIBILITY_PUBLIC)
|
snb.setVisibility(VISIBILITY_PUBLIC)
|
||||||
.setSmallIcon(R.drawable.ic_stat)
|
.setSmallIcon(R.drawable.ic_stat)
|
||||||
.setContentIntent(npi)
|
.setContentIntent(npi)
|
||||||
.setPriority(Notification.PRIORITY_HIGH)
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setContent(RemoteViews(packageName, R.layout.notification))
|
.setContent(RemoteViews(packageName, R.layout.status_notification))
|
||||||
startForeground(STATUS_NOTIFICATION_ID, nb.build())
|
startForeground(STATUS_NOTIFICATION_ID, snb.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
@@ -194,7 +196,7 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
fun updateStatus(event: String, uap: String, callp: String) {
|
fun updateStatus(event: String, uap: String, callp: String) {
|
||||||
Log.d(LOG_TAG, "updateStatus got event $event")
|
Log.d(LOG_TAG, "updateStatus got event $event/$uap/$callp")
|
||||||
if (!IS_SERVICE_RUNNING) return
|
if (!IS_SERVICE_RUNNING) return
|
||||||
val ua = UserAgent.find(MainActivity.uas, uap)
|
val ua = UserAgent.find(MainActivity.uas, uap)
|
||||||
if (ua == null) {
|
if (ua == null) {
|
||||||
@@ -231,22 +233,55 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
"call incoming" -> {
|
"call incoming" -> {
|
||||||
if (!Utils.isVisible()) {
|
if (!Utils.isVisible()) {
|
||||||
nb.setVibrate(LongArray(0))
|
snb.setVibrate(LongArray(0))
|
||||||
val view = RemoteViews(getPackageName(), R.layout.notification)
|
val view = RemoteViews(getPackageName(), R.layout.status_notification)
|
||||||
view.setTextViewText(R.id.incoming, "Call from ${Api.call_peeruri(callp)}")
|
view.setTextViewText(R.id.callFrom, "Call from ${Api.call_peeruri(callp)}")
|
||||||
view.setViewVisibility(R.id.incoming, View.VISIBLE)
|
view.setViewVisibility(R.id.incomingCall, View.VISIBLE)
|
||||||
nb.setContent(view)
|
snb.setContent(view)
|
||||||
nm.notify(STATUS_NOTIFICATION_ID, nb.build())
|
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||||
}
|
}
|
||||||
rt.play()
|
rt.play()
|
||||||
|
/* if (!Utils.isVisible()) {
|
||||||
|
nm.cancel(STATUS_NOTIFICATION_ID)
|
||||||
|
val cnb = NotificationCompat.Builder(this)
|
||||||
|
.setSmallIcon(R.drawable.ic_stat)
|
||||||
|
.setContentIntent(npi)
|
||||||
|
.setVisibility(VISIBILITY_PUBLIC)
|
||||||
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
|
.setVibrate(LongArray(0))
|
||||||
|
val answerIntent = Intent(this, MainActivity::class.java)
|
||||||
|
answerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||||
|
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
|
answerIntent.putExtra("action", "answer")
|
||||||
|
answerIntent.putExtra("uap", uap)
|
||||||
|
answerIntent.putExtra("callp", callp)
|
||||||
|
val answerPendingIntent = PendingIntent.getActivity(this,
|
||||||
|
0, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
|
val rejectIntent = Intent(this, MainActivity::class.java)
|
||||||
|
rejectIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||||
|
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
|
rejectIntent.putExtra("action", "reject")
|
||||||
|
rejectIntent.putExtra("uap", uap)
|
||||||
|
rejectIntent.putExtra("callp", callp)
|
||||||
|
val rejectPendingIntent = PendingIntent.getActivity(this,
|
||||||
|
0, rejectIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
|
val view = RemoteViews(getPackageName(), R.layout.call_notification)
|
||||||
|
view.setTextViewText(R.id.caller, "${Api.call_peeruri(callp)}")
|
||||||
|
view.setOnClickPendingIntent(R.id.answerButton, answerPendingIntent)
|
||||||
|
view.setOnClickPendingIntent(R.id.rejectButton, rejectPendingIntent)
|
||||||
|
cnb.setCustomBigContentView(view)
|
||||||
|
cnb.setVibrate(LongArray(0))
|
||||||
|
nm.notify(CALL_NOTIFICATION_ID, cnb.build())
|
||||||
|
return
|
||||||
|
} */
|
||||||
}
|
}
|
||||||
"call established", "call closed" -> {
|
"call established", "call closed" -> {
|
||||||
nm.cancel(STATUS_NOTIFICATION_ID)
|
nm.cancel(CALL_NOTIFICATION_ID)
|
||||||
val view = RemoteViews(getPackageName(), R.layout.notification)
|
val view = RemoteViews(getPackageName(), R.layout.status_notification)
|
||||||
view.setViewVisibility(R.id.incoming, View.GONE)
|
view.setViewVisibility(R.id.incomingCall, View.GONE)
|
||||||
nb.setContent(view)
|
snb.setContent(view)
|
||||||
nb.setVibrate(null)
|
snb.setVibrate(null)
|
||||||
nm.notify(STATUS_NOTIFICATION_ID, nb.build())
|
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||||
rt.stop()
|
rt.stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,7 +304,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateNotification() {
|
fun updateNotification() {
|
||||||
val contentView = RemoteViews(getPackageName(), R.layout.notification)
|
val contentView = RemoteViews(getPackageName(), R.layout.status_notification)
|
||||||
for (i: Int in 0 .. 5) {
|
for (i: Int in 0 .. 5) {
|
||||||
val resID = resources.getIdentifier("status$i", "id", packageName)
|
val resID = resources.getIdentifier("status$i", "id", packageName)
|
||||||
if (i < MainActivity.images.size) {
|
if (i < MainActivity.images.size) {
|
||||||
@@ -283,8 +318,8 @@ class BaresipService: Service() {
|
|||||||
contentView.setViewVisibility(R.id.etc, View.VISIBLE)
|
contentView.setViewVisibility(R.id.etc, View.VISIBLE)
|
||||||
else
|
else
|
||||||
contentView.setViewVisibility(R.id.etc, View.INVISIBLE)
|
contentView.setViewVisibility(R.id.etc, View.INVISIBLE)
|
||||||
nb.setContent(contentView)
|
snb.setContent(contentView)
|
||||||
nm.notify(STATUS_NOTIFICATION_ID, nb.build())
|
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
external fun baresipStart(path: String)
|
external fun baresipStart(path: String)
|
||||||
@@ -294,6 +329,7 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
var IS_SERVICE_RUNNING = false
|
var IS_SERVICE_RUNNING = false
|
||||||
val STATUS_NOTIFICATION_ID = 101
|
val STATUS_NOTIFICATION_ID = 101
|
||||||
|
val CALL_NOTIFICATION_ID = 102
|
||||||
var disconnected = false
|
var disconnected = false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -287,6 +287,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
baresipService.setAction("Start")
|
baresipService.setAction("Start")
|
||||||
startService(baresipService)
|
startService(baresipService)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (intent.hasExtra("onStartup"))
|
||||||
|
moveTaskToBack(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleServiceEvent(event: String, uap: String, callp: String) {
|
private fun handleServiceEvent(event: String, uap: String, callp: String) {
|
||||||
@@ -311,8 +314,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if (ONE_CALL_ONLY && (calls.size > 0)) {
|
if (ONE_CALL_ONLY && (calls.size > 0)) {
|
||||||
Log.d("Baresip", "Auto-rejecting incoming call $uap/$callp/$peer_uri")
|
Log.d("Baresip", "Auto-rejecting incoming call $uap/$callp/$peer_uri")
|
||||||
ua_hangup(uap, callp, 486, "Busy Here")
|
ua_hangup(uap, callp, 486, "Busy Here")
|
||||||
|
if (History.aorHistory(history, aor) > HISTORY_SIZE)
|
||||||
|
History.aorRemoveHistory(history, aor)
|
||||||
history.add(History(aor, peer_uri, "in", false))
|
history.add(History(aor, peer_uri, "in", false))
|
||||||
new_call.hasHistory = true
|
|
||||||
} else {
|
} else {
|
||||||
Log.d("Baresip", "Incoming call $uap/$callp/$peer_uri")
|
Log.d("Baresip", "Incoming call $uap/$callp/$peer_uri")
|
||||||
calls.add(new_call)
|
calls.add(new_call)
|
||||||
@@ -540,6 +544,31 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
setIntent(intent)
|
||||||
|
val action = intent.getStringExtra("action")
|
||||||
|
Log.d("Baresip", "Got onNewIntent action $action")
|
||||||
|
if (action == null) return
|
||||||
|
val uap = intent.getStringExtra("uap")
|
||||||
|
val callp = intent.getStringExtra("callp")
|
||||||
|
val ua = UserAgent.find(uas, intent.getStringExtra("uap"))!!
|
||||||
|
val aor = ua.account.aor
|
||||||
|
val peer_uri = Api.call_peeruri(callp)
|
||||||
|
when (action) {
|
||||||
|
"answer" -> {
|
||||||
|
/* TODO */
|
||||||
|
}
|
||||||
|
"reject" -> {
|
||||||
|
Log.d("Baresip", "Rejecting incoming call from $peer_uri")
|
||||||
|
ua_hangup(uap, callp, 486, "Busy Here")
|
||||||
|
if (History.aorHistory(history, aor) > HISTORY_SIZE)
|
||||||
|
History.aorRemoveHistory(history, aor)
|
||||||
|
history.add(History(aor, peer_uri, "in", false))
|
||||||
|
moveTaskToBack(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
Log.d("Baresip", "Paused")
|
Log.d("Baresip", "Paused")
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class RunOnStartup : BroadcastReceiver() {
|
|||||||
val i = Intent(context, MainActivity::class.java)
|
val i = Intent(context, MainActivity::class.java)
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
val b = Bundle()
|
val b = Bundle()
|
||||||
b.putBoolean("onstartup", true)
|
b.putBoolean("onStartup", true)
|
||||||
i.putExtras(b)
|
i.putExtras(b)
|
||||||
context.startActivity(i)
|
context.startActivity(i)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/callHeading"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="14dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:orientation="horizontal" >
|
||||||
|
|
||||||
|
<ImageView android:id="@+id/headingImage"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:paddingStart="10dp"
|
||||||
|
android:paddingEnd="5dp"
|
||||||
|
android:src="@drawable/baresip" />
|
||||||
|
|
||||||
|
<TextView android:id="@+id/headingText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textSize="15dp"
|
||||||
|
android:textColor="#000000"
|
||||||
|
android:text="Call from"
|
||||||
|
style = "@android:style/TextAppearance.Medium" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView android:id="@+id/caller"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:layout_below="@id/callHeading"
|
||||||
|
android:textSize="15dp"
|
||||||
|
android:text="peer uri"
|
||||||
|
style = "@android:style/TextAppearance.Medium" />
|
||||||
|
|
||||||
|
<Button android:id="@+id/answerButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/caller"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginBottom="14dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:text="Answer" />
|
||||||
|
|
||||||
|
<Button android:id="@+id/rejectButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/caller"
|
||||||
|
android:layout_toEndOf="@id/answerButton"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginBottom="14dp"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:text="Reject" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
+1
-1
@@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView android:id="@+id/incoming"
|
<TextView android:id="@+id/callFrom"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/mainRow"
|
android:layout_below="@id/mainRow"
|
||||||
Reference in New Issue
Block a user