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" />
|
||||
<uses-permission android:name="android.permission.READ_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.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
@ -54,22 +55,14 @@
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</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>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<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.BROWSABLE" />
|
||||
<data android:scheme="sip" />
|
||||
<data android:scheme="sips" />
|
||||
<data android:scheme="tel" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
@ -178,7 +171,6 @@
|
||||
<action android:name="com.tutpro.baresip.QUIT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
</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);
|
||||
break;
|
||||
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;
|
||||
case UA_EVENT_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 char *native_reason = (*env)->GetStringUTFChars(env, reason, 0);
|
||||
LOGD("hanging up call %ld/%ld\n", (long)ua, (long)call);
|
||||
re_thread_enter();
|
||||
// re_thread_enter();
|
||||
if (strlen(native_reason) == 0)
|
||||
ua_hangup((struct ua *)ua, (struct call *)call, native_code, NULL);
|
||||
else
|
||||
ua_hangup((struct ua *)ua, (struct call *)call, native_code, native_reason);
|
||||
re_thread_leave();
|
||||
// re_thread_leave();
|
||||
(*env)->ReleaseStringUTFChars(env, reason, native_reason);
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ import android.os.Build.VERSION
|
||||
import android.provider.ContactsContract
|
||||
import android.provider.Settings
|
||||
import android.telecom.TelecomManager
|
||||
import android.telephony.TelephonyManager
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.ForegroundColorSpan
|
||||
@ -616,14 +617,11 @@ class BaresipService: Service() {
|
||||
Log.d(TAG, "got uaEvent $event/$aor/$callp")
|
||||
|
||||
val call = Call.ofCallp(callp)
|
||||
if (call == null && callp != 0L &&
|
||||
!setOf("call incoming", "call rejected", "call closed").contains(ev[0])) {
|
||||
if (call == null && callp != 0L && !setOf("call incoming", "call closed").contains(ev[0])) {
|
||||
Log.w(TAG, "uaEvent $event did not find call $callp")
|
||||
return
|
||||
}
|
||||
|
||||
var newEvent: String? = null
|
||||
|
||||
for (accountIndex in uas.indices) {
|
||||
if (uas[accountIndex].account.aor == aor) {
|
||||
when (ev[0]) {
|
||||
@ -685,22 +683,24 @@ class BaresipService: Service() {
|
||||
}
|
||||
"call incoming" -> {
|
||||
val peerUri = ev[1]
|
||||
val toast = if (!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO)))
|
||||
R.string.no_calls
|
||||
val toastMsg = if (!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO)))
|
||||
getString(R.string.no_calls)
|
||||
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
|
||||
0
|
||||
if (toast != 0) {
|
||||
toast(getString(toast))
|
||||
""
|
||||
if (toastMsg != "") {
|
||||
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) {
|
||||
CallHistory.add(CallHistory(aor, peerUri, "in"))
|
||||
CallHistory.save()
|
||||
ua.account.missedCalls = true
|
||||
}
|
||||
if (!isMainVisible)
|
||||
return
|
||||
newEvent = "call rejected"
|
||||
return
|
||||
} else {
|
||||
Log.d(TAG, "Incoming call $uap/$callp/$peerUri")
|
||||
Call(callp, ua, peerUri, "in", "incoming", Utils.dtmfWatcher(callp)).add()
|
||||
@ -766,19 +766,6 @@ class BaresipService: Service() {
|
||||
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" -> {
|
||||
stopMediaPlayer()
|
||||
if (call!!.status == "incoming")
|
||||
@ -962,8 +949,7 @@ class BaresipService: Service() {
|
||||
}
|
||||
}
|
||||
|
||||
postServiceEvent(ServiceEvent(newEvent ?: event, arrayListOf(uap, callp),
|
||||
System.nanoTime()))
|
||||
postServiceEvent(ServiceEvent(event, arrayListOf(uap, callp), System.nanoTime()))
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user