diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index bcf1f704..d615891c 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -111,6 +111,16 @@
+
+
+
+
+
+
diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt
index 8b3ed0be..253a37e7 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt
@@ -30,7 +30,8 @@ class BaresipService: Service() {
private val LOG_TAG = "Baresip Service"
internal lateinit var intent: Intent
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 npi: PendingIntent
internal lateinit var nr: BroadcastReceiver
@@ -46,7 +47,8 @@ class BaresipService: Service() {
intent.setPackage("com.tutpro.baresip")
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
- nb = NotificationCompat.Builder(this)
+ snb = NotificationCompat.Builder(this)
+ cnb = NotificationCompat.Builder(this)
ni = Intent(this, MainActivity::class.java)
.setAction(Intent.ACTION_MAIN)
@@ -162,13 +164,13 @@ class BaresipService: Service() {
}
private fun showNotification() {
- nb.setVisibility(VISIBILITY_PUBLIC)
+ snb.setVisibility(VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.ic_stat)
.setContentIntent(npi)
.setPriority(Notification.PRIORITY_HIGH)
.setOngoing(true)
- .setContent(RemoteViews(packageName, R.layout.notification))
- startForeground(STATUS_NOTIFICATION_ID, nb.build())
+ .setContent(RemoteViews(packageName, R.layout.status_notification))
+ startForeground(STATUS_NOTIFICATION_ID, snb.build())
}
@Keep
@@ -194,7 +196,7 @@ class BaresipService: Service() {
@Keep
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
val ua = UserAgent.find(MainActivity.uas, uap)
if (ua == null) {
@@ -231,22 +233,55 @@ class BaresipService: Service() {
}
"call incoming" -> {
if (!Utils.isVisible()) {
- nb.setVibrate(LongArray(0))
- val view = RemoteViews(getPackageName(), R.layout.notification)
- view.setTextViewText(R.id.incoming, "Call from ${Api.call_peeruri(callp)}")
- view.setViewVisibility(R.id.incoming, View.VISIBLE)
- nb.setContent(view)
- nm.notify(STATUS_NOTIFICATION_ID, nb.build())
+ snb.setVibrate(LongArray(0))
+ val view = RemoteViews(getPackageName(), R.layout.status_notification)
+ view.setTextViewText(R.id.callFrom, "Call from ${Api.call_peeruri(callp)}")
+ view.setViewVisibility(R.id.incomingCall, View.VISIBLE)
+ snb.setContent(view)
+ nm.notify(STATUS_NOTIFICATION_ID, snb.build())
}
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" -> {
- nm.cancel(STATUS_NOTIFICATION_ID)
- val view = RemoteViews(getPackageName(), R.layout.notification)
- view.setViewVisibility(R.id.incoming, View.GONE)
- nb.setContent(view)
- nb.setVibrate(null)
- nm.notify(STATUS_NOTIFICATION_ID, nb.build())
+ nm.cancel(CALL_NOTIFICATION_ID)
+ val view = RemoteViews(getPackageName(), R.layout.status_notification)
+ view.setViewVisibility(R.id.incomingCall, View.GONE)
+ snb.setContent(view)
+ snb.setVibrate(null)
+ nm.notify(STATUS_NOTIFICATION_ID, snb.build())
rt.stop()
}
}
@@ -269,7 +304,7 @@ class BaresipService: Service() {
}
fun updateNotification() {
- val contentView = RemoteViews(getPackageName(), R.layout.notification)
+ val contentView = RemoteViews(getPackageName(), R.layout.status_notification)
for (i: Int in 0 .. 5) {
val resID = resources.getIdentifier("status$i", "id", packageName)
if (i < MainActivity.images.size) {
@@ -283,8 +318,8 @@ class BaresipService: Service() {
contentView.setViewVisibility(R.id.etc, View.VISIBLE)
else
contentView.setViewVisibility(R.id.etc, View.INVISIBLE)
- nb.setContent(contentView)
- nm.notify(STATUS_NOTIFICATION_ID, nb.build())
+ snb.setContent(contentView)
+ nm.notify(STATUS_NOTIFICATION_ID, snb.build())
}
external fun baresipStart(path: String)
@@ -294,6 +329,7 @@ class BaresipService: Service() {
var IS_SERVICE_RUNNING = false
val STATUS_NOTIFICATION_ID = 101
+ val CALL_NOTIFICATION_ID = 102
var disconnected = false
}
diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt
index a9a4f47a..7c034043 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt
@@ -287,6 +287,9 @@ class MainActivity : AppCompatActivity() {
baresipService.setAction("Start")
startService(baresipService)
}
+
+ if (intent.hasExtra("onStartup"))
+ moveTaskToBack(true)
}
private fun handleServiceEvent(event: String, uap: String, callp: String) {
@@ -311,8 +314,9 @@ class MainActivity : AppCompatActivity() {
if (ONE_CALL_ONLY && (calls.size > 0)) {
Log.d("Baresip", "Auto-rejecting incoming call $uap/$callp/$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))
- new_call.hasHistory = true
} else {
Log.d("Baresip", "Incoming call $uap/$callp/$peer_uri")
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() {
super.onPause()
Log.d("Baresip", "Paused")
diff --git a/app/src/main/kotlin/com/tutpro/baresip/RunOnStartup.kt b/app/src/main/kotlin/com/tutpro/baresip/RunOnStartup.kt
index a4c71d0d..763d19ba 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/RunOnStartup.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/RunOnStartup.kt
@@ -12,7 +12,7 @@ class RunOnStartup : BroadcastReceiver() {
val i = Intent(context, MainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val b = Bundle()
- b.putBoolean("onstartup", true)
+ b.putBoolean("onStartup", true)
i.putExtras(b)
context.startActivity(i)
}
diff --git a/app/src/main/res/layout/call_notification.xml b/app/src/main/res/layout/call_notification.xml
new file mode 100644
index 00000000..eb59f805
--- /dev/null
+++ b/app/src/main/res/layout/call_notification.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/notification.xml b/app/src/main/res/layout/status_notification.xml
similarity index 98%
rename from app/src/main/res/layout/notification.xml
rename to app/src/main/res/layout/status_notification.xml
index 3ed223ee..ffeb9166 100644
--- a/app/src/main/res/layout/notification.xml
+++ b/app/src/main/res/layout/status_notification.xml
@@ -64,7 +64,7 @@
-