Always auto-reject incoming call in baresip service
Main activity intent filter improvements
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
tools:ignore="ScopedStorage" />
|
tools:ignore="ScopedStorage" />
|
||||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||||
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
|
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
|
||||||
|
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||||
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
|
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
@@ -54,22 +55,14 @@
|
|||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.DIAL" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<data android:scheme="sip" />
|
|
||||||
<data android:scheme="tel" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.DIAL" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<action android:name="android.intent.action.DIAL" />
|
<action android:name="android.intent.action.DIAL" />
|
||||||
|
<action android:name="android.intent.action.CALL" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
<data android:scheme="sip" />
|
<data android:scheme="sip" />
|
||||||
|
<data android:scheme="sips" />
|
||||||
<data android:scheme="tel" />
|
<data android:scheme="tel" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
@@ -178,7 +171,6 @@
|
|||||||
<action android:name="com.tutpro.baresip.QUIT" />
|
<action android:name="com.tutpro.baresip.QUIT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -167,13 +167,7 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
|
|||||||
len = re_snprintf(event_buf, sizeof event_buf, "registering failed,%s", prm);
|
len = re_snprintf(event_buf, sizeof event_buf, "registering failed,%s", prm);
|
||||||
break;
|
break;
|
||||||
case UA_EVENT_CALL_INCOMING:
|
case UA_EVENT_CALL_INCOMING:
|
||||||
if (uag_call_count() > 1) {
|
|
||||||
LOGD("auto-rejecting call from %s\n", prm);
|
|
||||||
ua_hangup(ua, call, 486, "Busy Here");
|
|
||||||
len = re_snprintf(event_buf, sizeof event_buf, "call rejected,%s", prm);
|
|
||||||
} else {
|
|
||||||
len = re_snprintf(event_buf, sizeof event_buf, "call incoming,%s", prm);
|
len = re_snprintf(event_buf, sizeof event_buf, "call incoming,%s", prm);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case UA_EVENT_CALL_OUTGOING:
|
case UA_EVENT_CALL_OUTGOING:
|
||||||
len = re_snprintf(event_buf, sizeof event_buf, "call outgoing");
|
len = re_snprintf(event_buf, sizeof event_buf, "call outgoing");
|
||||||
@@ -1065,12 +1059,12 @@ Java_com_tutpro_baresip_Api_ua_1hangup(JNIEnv *env, jobject thiz, jlong ua, jlon
|
|||||||
const uint16_t native_code = code;
|
const uint16_t native_code = code;
|
||||||
const char *native_reason = (*env)->GetStringUTFChars(env, reason, 0);
|
const char *native_reason = (*env)->GetStringUTFChars(env, reason, 0);
|
||||||
LOGD("hanging up call %ld/%ld\n", (long)ua, (long)call);
|
LOGD("hanging up call %ld/%ld\n", (long)ua, (long)call);
|
||||||
re_thread_enter();
|
// re_thread_enter();
|
||||||
if (strlen(native_reason) == 0)
|
if (strlen(native_reason) == 0)
|
||||||
ua_hangup((struct ua *)ua, (struct call *)call, native_code, NULL);
|
ua_hangup((struct ua *)ua, (struct call *)call, native_code, NULL);
|
||||||
else
|
else
|
||||||
ua_hangup((struct ua *)ua, (struct call *)call, native_code, native_reason);
|
ua_hangup((struct ua *)ua, (struct call *)call, native_code, native_reason);
|
||||||
re_thread_leave();
|
// re_thread_leave();
|
||||||
(*env)->ReleaseStringUTFChars(env, reason, native_reason);
|
(*env)->ReleaseStringUTFChars(env, reason, native_reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.os.Build.VERSION
|
|||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.telecom.TelecomManager
|
import android.telecom.TelecomManager
|
||||||
|
import android.telephony.TelephonyManager
|
||||||
import android.text.Spannable
|
import android.text.Spannable
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
import android.text.style.ForegroundColorSpan
|
import android.text.style.ForegroundColorSpan
|
||||||
@@ -616,14 +617,11 @@ class BaresipService: Service() {
|
|||||||
Log.d(TAG, "got uaEvent $event/$aor/$callp")
|
Log.d(TAG, "got uaEvent $event/$aor/$callp")
|
||||||
|
|
||||||
val call = Call.ofCallp(callp)
|
val call = Call.ofCallp(callp)
|
||||||
if (call == null && callp != 0L &&
|
if (call == null && callp != 0L && !setOf("call incoming", "call closed").contains(ev[0])) {
|
||||||
!setOf("call incoming", "call rejected", "call closed").contains(ev[0])) {
|
|
||||||
Log.w(TAG, "uaEvent $event did not find call $callp")
|
Log.w(TAG, "uaEvent $event did not find call $callp")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var newEvent: String? = null
|
|
||||||
|
|
||||||
for (accountIndex in uas.indices) {
|
for (accountIndex in uas.indices) {
|
||||||
if (uas[accountIndex].account.aor == aor) {
|
if (uas[accountIndex].account.aor == aor) {
|
||||||
when (ev[0]) {
|
when (ev[0]) {
|
||||||
@@ -685,22 +683,24 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
"call incoming" -> {
|
"call incoming" -> {
|
||||||
val peerUri = ev[1]
|
val peerUri = ev[1]
|
||||||
val toast = if (!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO)))
|
val toastMsg = if (!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO)))
|
||||||
R.string.no_calls
|
getString(R.string.no_calls)
|
||||||
else if (!requestAudioFocus(applicationContext))
|
else if (!requestAudioFocus(applicationContext))
|
||||||
R.string.audio_focus_denied
|
// request fails if there is an active telephony call
|
||||||
|
getString(R.string.audio_focus_denied)
|
||||||
else
|
else
|
||||||
0
|
""
|
||||||
if (toast != 0) {
|
if (toastMsg != "") {
|
||||||
toast(getString(toast))
|
Log.d(TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri")
|
||||||
|
Api.ua_hangup(uap, callp, 486, "Busy Here")
|
||||||
|
toast(toastMsg)
|
||||||
|
playUnInterrupted(R.raw.callwaiting, 1)
|
||||||
if (ua.account.callHistory) {
|
if (ua.account.callHistory) {
|
||||||
CallHistory.add(CallHistory(aor, peerUri, "in"))
|
CallHistory.add(CallHistory(aor, peerUri, "in"))
|
||||||
CallHistory.save()
|
CallHistory.save()
|
||||||
ua.account.missedCalls = true
|
ua.account.missedCalls = true
|
||||||
}
|
}
|
||||||
if (!isMainVisible)
|
|
||||||
return
|
return
|
||||||
newEvent = "call rejected"
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Incoming call $uap/$callp/$peerUri")
|
Log.d(TAG, "Incoming call $uap/$callp/$peerUri")
|
||||||
Call(callp, ua, peerUri, "in", "incoming", Utils.dtmfWatcher(callp)).add()
|
Call(callp, ua, peerUri, "in", "incoming", Utils.dtmfWatcher(callp)).add()
|
||||||
@@ -766,19 +766,6 @@ class BaresipService: Service() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"call rejected" -> {
|
|
||||||
playUnInterrupted(R.raw.callwaiting, 1)
|
|
||||||
if (ua.account.callHistory) {
|
|
||||||
CallHistory.add(CallHistory(aor, ev[1], "in"))
|
|
||||||
CallHistory.save()
|
|
||||||
ua.account.missedCalls = true
|
|
||||||
if (!isMainVisible)
|
|
||||||
return
|
|
||||||
newEvent = "call rejected"
|
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"call answered" -> {
|
"call answered" -> {
|
||||||
stopMediaPlayer()
|
stopMediaPlayer()
|
||||||
if (call!!.status == "incoming")
|
if (call!!.status == "incoming")
|
||||||
@@ -962,8 +949,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
postServiceEvent(ServiceEvent(newEvent ?: event, arrayListOf(uap, callp),
|
postServiceEvent(ServiceEvent(event, arrayListOf(uap, callp), System.nanoTime()))
|
||||||
System.nanoTime()))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user