From ae87b79e302ea1e20ebd06d779edb934eebc3bb3 Mon Sep 17 00:00:00 2001 From: yibaiba <946100224@qq.com> Date: Mon, 24 Aug 2026 18:21:32 +0800 Subject: [PATCH] fix(volte): unique native call IDs and bounded ALSA open QMI reuses call slot 1, so volte-{device}-{qmiID} overwrote history. Identify live calls by QMI id and mint a unique persistent call_id. Cap ALSA open at 800ms, refine hwparams before HW_PARAMS, and skip later opens after a failure so dialing is not blocked by set_interface. --- internal/db/voice_call_records_test.go | 43 ++++++++++ internal/volte/alsa_hwparams.go | 70 ++++++++++++++++ internal/volte/alsa_hwparams_test.go | 42 ++++++++++ internal/volte/alsa_pcm_linux.go | 59 +++----------- internal/volte/controller.go | 9 ++- internal/volte/fakes_test.go | 7 ++ internal/volte/voice.go | 108 +++++++++++++++++++++++-- internal/volte/voice_test.go | 83 ++++++++++++++++++- 8 files changed, 359 insertions(+), 62 deletions(-) create mode 100644 internal/volte/alsa_hwparams.go create mode 100644 internal/volte/alsa_hwparams_test.go diff --git a/internal/db/voice_call_records_test.go b/internal/db/voice_call_records_test.go index 94780dab..df795402 100644 --- a/internal/db/voice_call_records_test.go +++ b/internal/db/voice_call_records_test.go @@ -55,3 +55,46 @@ func TestVoiceCallStoreUpsertsAndListsNewestFirst(t *testing.T) { t.Fatalf("updated record = %+v", records[0]) } } + +func TestVoiceCallStoreKeepsBothRecordsWhenQMISlotIsReused(t *testing.T) { + database, err := gorm.Open(sqlite.Open(filepath.Join(t.TempDir(), "calls.db")), &gorm.Config{}) + if err != nil { + t.Fatal(err) + } + if err := database.AutoMigrate(&VoiceCallRecord{}); err != nil { + t.Fatal(err) + } + store := NewVoiceCallStore(database) + ctx := context.Background() + firstStart := time.Now().Add(-2 * time.Minute).UTC() + firstEnd := firstStart.Add(116 * time.Second) + if err := store.Upsert(ctx, phone.CallRecord{ + CallID: "volte-wwan0-1-100-1", DeviceID: "wwan0", Direction: "inbound", + Peer: "13200000002", Status: phone.StatusRejected, StartedAt: firstStart, + EndedAt: &firstEnd, DurationSeconds: 116, EndReason: "rejected", + }); err != nil { + t.Fatal(err) + } + secondStart := time.Now().UTC() + secondEnd := secondStart.Add(29 * time.Second) + if err := store.Upsert(ctx, phone.CallRecord{ + CallID: "volte-wwan0-1-200-2", DeviceID: "wwan0", Direction: "outbound", + Peer: "10000", Status: phone.StatusFailed, StartedAt: secondStart, + EndedAt: &secondEnd, DurationSeconds: 29, EndReason: "local_hangup", + }); err != nil { + t.Fatal(err) + } + records, err := store.List(ctx, 10) + if err != nil { + t.Fatal(err) + } + if len(records) != 2 { + t.Fatalf("records = %d, want 2 (QMI slot reuse must not overwrite history)", len(records)) + } + if records[0].CallID != "volte-wwan0-1-200-2" || records[1].CallID != "volte-wwan0-1-100-1" { + t.Fatalf("records = %+v", records) + } + if records[1].Status != phone.StatusRejected || records[1].Peer != "13200000002" { + t.Fatalf("first inbound overwritten: %+v", records[1]) + } +} diff --git a/internal/volte/alsa_hwparams.go b/internal/volte/alsa_hwparams.go new file mode 100644 index 00000000..7ca40432 --- /dev/null +++ b/internal/volte/alsa_hwparams.go @@ -0,0 +1,70 @@ +package volte + +import "encoding/binary" + +const ( + alsaHWParamsSize = 608 + alsaParamAccess = 0 + alsaParamFormat = 1 + alsaParamChannels = 10 + alsaParamRate = 11 + alsaParamPeriodSz = 13 + alsaParamBufferSz = 17 + alsaAccessRWInter = 3 + alsaFormatS16LE = 2 + alsaIntervalFirst = 8 + alsaIntervalCount = 21 + alsaRmaskOff = 512 + alsaIntervalInt = 1 << 2 +) + +func newALSAHWParams() [alsaHWParamsSize]byte { + var params [alsaHWParamsSize]byte + for i := 4; i < 4+8*32; i++ { + params[i] = 0xff + } + for i := 0; i < alsaIntervalCount; i++ { + off := 260 + i*12 + binary.LittleEndian.PutUint32(params[off+4:], 0xffffffff) + } + binary.LittleEndian.PutUint32(params[alsaRmaskOff:], 0xffffffff) + return params +} + +func constrainALSAMask(params *[alsaHWParamsSize]byte, param, bit int) { + if param < 0 || param > 2 { + return + } + off := 4 + param*32 + for i := 0; i < 32; i++ { + params[off+i] = 0 + } + word := bit / 32 + shift := uint(bit % 32) + if word < 0 || word >= 8 { + return + } + binary.LittleEndian.PutUint32(params[off+word*4:], uint32(1)<= 12 { + return + } + off := 260 + idx*12 + binary.LittleEndian.PutUint32(params[off:], value) + binary.LittleEndian.PutUint32(params[off+4:], value) + binary.LittleEndian.PutUint32(params[off+8:], alsaIntervalInt) +} + +func alsaIntervalValue(params [alsaHWParamsSize]byte, param int) (min, max, flags uint32) { + idx := param - alsaIntervalFirst + if idx < 0 || idx >= 12 { + return 0, 0, 0 + } + off := 260 + idx*12 + return binary.LittleEndian.Uint32(params[off:]), + binary.LittleEndian.Uint32(params[off+4:]), + binary.LittleEndian.Uint32(params[off+8:]) +} diff --git a/internal/volte/alsa_hwparams_test.go b/internal/volte/alsa_hwparams_test.go new file mode 100644 index 00000000..df4b628a --- /dev/null +++ b/internal/volte/alsa_hwparams_test.go @@ -0,0 +1,42 @@ +package volte + +import "testing" + +func TestNewALSAHWParamsLeavesIntervalsOpen(t *testing.T) { + params := newALSAHWParams() + min, max, flags := alsaIntervalValue(params, alsaParamRate) + if min != 0 || max != 0xffffffff || flags != 0 { + t.Fatalf("any rate interval min=%d max=%d flags=%d", min, max, flags) + } +} + +func TestConstrainALSAIntervalSetsIntegerNotOpenMin(t *testing.T) { + params := newALSAHWParams() + constrainALSAInterval(¶ms, alsaParamRate, 8000) + min, max, flags := alsaIntervalValue(params, alsaParamRate) + if min != 8000 || max != 8000 { + t.Fatalf("rate min=%d max=%d", min, max) + } + if flags&alsaIntervalInt == 0 { + t.Fatal("integer flag missing") + } + if flags&1 != 0 { + t.Fatal("openmin must stay 0 when min==max, otherwise HW_PARAMS is empty and returns EINVAL") + } +} + +func TestConstrainALSAVoicePCM(t *testing.T) { + params := newALSAHWParams() + constrainALSAMask(¶ms, alsaParamAccess, alsaAccessRWInter) + constrainALSAMask(¶ms, alsaParamFormat, alsaFormatS16LE) + constrainALSAInterval(¶ms, alsaParamChannels, 1) + constrainALSAInterval(¶ms, alsaParamRate, uint32(pcmuClockRate)) + min, max, flags := alsaIntervalValue(params, alsaParamChannels) + if min != 1 || max != 1 || flags != alsaIntervalInt { + t.Fatalf("channels min=%d max=%d flags=%d", min, max, flags) + } + min, max, flags = alsaIntervalValue(params, alsaParamRate) + if min != 8000 || max != 8000 || flags != alsaIntervalInt { + t.Fatalf("rate min=%d max=%d flags=%d", min, max, flags) + } +} diff --git a/internal/volte/alsa_pcm_linux.go b/internal/volte/alsa_pcm_linux.go index 5231fb8d..02dc31b6 100644 --- a/internal/volte/alsa_pcm_linux.go +++ b/internal/volte/alsa_pcm_linux.go @@ -3,7 +3,6 @@ package volte import ( - "encoding/binary" "fmt" "os" "sync" @@ -13,19 +12,10 @@ import ( ) const ( - alsaHWParamsSize = 608 - alsaIoctlHWParams = 0xc2604111 - alsaIoctlPrepare = 0x4140 - alsaIoctlDrop = 0x4143 - alsaParamAccess = 0 - alsaParamFormat = 1 - alsaParamChannels = 10 - alsaParamRate = 11 - alsaParamPeriodSz = 13 - alsaParamBufferSz = 17 - alsaAccessRWInter = 3 - alsaFormatS16LE = 2 - alsaIntervalFirst = 8 + alsaIoctlHWRefine = 0xc2604110 + alsaIoctlHWParams = 0xc2604111 + alsaIoctlPrepare = 0x4140 + alsaIoctlDrop = 0x4143 ) type alsaStream struct { @@ -73,45 +63,20 @@ func openALSAStream(path string, playback bool) (alsaStream, error) { } func configureALSA(f *os.File) error { - var params [alsaHWParamsSize]byte - binary.LittleEndian.PutUint32(params[512:], 0xffffffff) // rmask - setALSAMask(¶ms, alsaParamAccess, alsaAccessRWInter) - setALSAMask(¶ms, alsaParamFormat, alsaFormatS16LE) - setALSAInterval(¶ms, alsaParamChannels, 1) - setALSAInterval(¶ms, alsaParamRate, uint32(pcmuClockRate)) - setALSAInterval(¶ms, alsaParamPeriodSz, uint32(pcmuFrameSamples)) - setALSAInterval(¶ms, alsaParamBufferSz, uint32(pcmuFrameSamples*8)) + params := newALSAHWParams() + constrainALSAMask(¶ms, alsaParamAccess, alsaAccessRWInter) + constrainALSAMask(¶ms, alsaParamFormat, alsaFormatS16LE) + constrainALSAInterval(¶ms, alsaParamChannels, 1) + constrainALSAInterval(¶ms, alsaParamRate, uint32(pcmuClockRate)) + if err := ioctl(f, alsaIoctlHWRefine, unsafe.Pointer(¶ms[0])); err != nil { + return err + } if err := ioctl(f, alsaIoctlHWParams, unsafe.Pointer(¶ms[0])); err != nil { return err } return ioctl(f, alsaIoctlPrepare, nil) } -func setALSAMask(params *[alsaHWParamsSize]byte, param, bit int) { - if param < 0 || param > 2 { - return - } - off := 4 + param*32 - word := bit / 32 - shift := uint(bit % 32) - if word < 0 || word >= 8 { - return - } - val := binary.LittleEndian.Uint32(params[off+word*4:]) - binary.LittleEndian.PutUint32(params[off+word*4:], val|uint32(1)< 11 { - return - } - off := 260 + idx*12 - binary.LittleEndian.PutUint32(params[off:], value) - binary.LittleEndian.PutUint32(params[off+4:], value) - binary.LittleEndian.PutUint32(params[off+8:], 1) // integer -} - func ioctl(f *os.File, req uint, arg unsafe.Pointer) error { var ap uintptr if arg != nil { diff --git a/internal/volte/controller.go b/internal/volte/controller.go index 06df4a95..b2d0636e 100644 --- a/internal/volte/controller.go +++ b/internal/volte/controller.go @@ -28,10 +28,11 @@ type Controller struct { } type session struct { - gen uint64 - imsHooked bool - status Status - voice *voiceSession + gen uint64 + imsHooked bool + status Status + voice *voiceSession + alsaUnavailable bool } func NewController(host Host) *Controller { diff --git a/internal/volte/fakes_test.go b/internal/volte/fakes_test.go index f8229a91..3cb16ec3 100644 --- a/internal/volte/fakes_test.go +++ b/internal/volte/fakes_test.go @@ -45,6 +45,7 @@ type FakeModem struct { imsCID int imsActive bool hangupErr error + dialVoice *qmi.VoiceAllCallInfo } func newFakeModem() *FakeModem { @@ -264,6 +265,12 @@ func (f *FakeModem) IMSAStatus(context.Context, string) (Registration, error) { } func (f *FakeModem) AudioDevice(string) string { return f.Audio } func (f *FakeModem) VOICEDial(context.Context, string, string) (uint8, error) { + f.mu.Lock() + info := f.dialVoice + f.mu.Unlock() + if info != nil { + f.fireVoice(info) + } return 1, nil } func (f *FakeModem) VOICEAnswer(context.Context, string, uint8) error { return nil } diff --git a/internal/volte/voice.go b/internal/volte/voice.go index 75755d84..a7516c0d 100644 --- a/internal/volte/voice.go +++ b/internal/volte/voice.go @@ -6,6 +6,7 @@ import ( "fmt" "strings" "sync" + "sync/atomic" "time" "github.com/iniwex5/quectel-qmi-go/pkg/qmi" @@ -26,6 +27,7 @@ const ( type voiceSession struct { mu sync.Mutex active map[string]nativeCall + byQMI map[uint8]string emitted map[string]map[string]bool incomingSeen map[string]bool attached bool @@ -48,6 +50,7 @@ type nativeCall struct { func newVoiceSession() *voiceSession { return &voiceSession{ active: make(map[string]nativeCall), + byQMI: make(map[uint8]string), emitted: make(map[string]map[string]bool), incomingSeen: make(map[string]bool), } @@ -177,8 +180,19 @@ func (c *Controller) BeginCall(ctx context.Context, request voicehost.BeginCallR if err != nil { return voicehost.CallSnapshot{}, err } - id := callID(deviceID, qmiID) now := time.Now() + id := "" + if vs := c.sessionVoice(deviceID); vs != nil { + if prev, ok := vs.getByQMI(qmiID); ok && stateRank(prev.State) != rankTerminal { + id = prev.ID + if !prev.Start.IsZero() { + now = prev.Start + } + } + } + if id == "" { + id = newPersistentCallID(deviceID, qmiID) + } media, mediaErr := startCallMedia(request.SDP, c.callPCM(deviceID), sdpHasRecvOnly(request.SDP)) sdp := "" if mediaErr != nil { @@ -356,18 +370,21 @@ func (c *Controller) handleVoiceInfo(deviceID string, vs *voiceSession, info *qm now := time.Now() seen := make(map[string]bool, len(info.Calls)) for _, item := range info.Calls { - id := callID(deviceID, item.ID) - seen[id] = true peer := remoteNumber(info, item.ID) state, eventType := mapQMIState(item.State) dir := "outbound" if item.Direction == qmiDirMT { dir = "inbound" } - prev, existed := vs.get(id) + prev, existed := vs.getByQMI(item.ID) if !existed && stateRank(state) == rankTerminal { continue } + id := prev.ID + if !existed { + id = newPersistentCallID(deviceID, item.ID) + } + seen[id] = true if existed && stateRank(state) < stateRank(prev.State) && stateRank(state) != rankTerminal { continue } @@ -517,8 +534,11 @@ func stateRank(state string) int { } } -func callID(deviceID string, qmiID uint8) string { - return fmt.Sprintf("volte-%s-%d", deviceID, qmiID) +var callIDSeq atomic.Uint64 + +func newPersistentCallID(deviceID string, qmiID uint8) string { + seq := callIDSeq.Add(1) + return fmt.Sprintf("volte-%s-%d-%d-%d", strings.TrimSpace(deviceID), qmiID, time.Now().UnixNano(), seq) } func remoteNumber(info *qmi.VoiceAllCallInfo, id uint8) string { @@ -547,23 +567,77 @@ func audioError(st Status) string { return "VoLTE 音频不可用:未检测到 UAC 声卡" } +const alsaOpenBudget = 800 * time.Millisecond + +func openALSAPCMBounded(device string, budget time.Duration) (PCMPort, error) { + if budget <= 0 { + budget = alsaOpenBudget + } + type result struct { + pcm PCMPort + err error + } + ch := make(chan result, 1) + go func() { + pcm, err := openALSAPCM(device) + ch <- result{pcm: pcm, err: err} + }() + timer := time.NewTimer(budget) + defer timer.Stop() + select { + case r := <-ch: + return r.pcm, r.err + case <-timer.C: + return nil, fmt.Errorf("volte: open %s timed out after %s", device, budget) + } +} + func (c *Controller) callPCM(deviceID string) PCMPort { if c == nil || c.host == nil { return nullPCM{} } + if c.alsaUnavailable(deviceID) { + return nullPCM{} + } dev := strings.TrimSpace(c.host.AudioDevice(deviceID)) if dev == "" { logger.Warn("VoLTE 无模组声卡,本次通话无音频", "device", deviceID) return nullPCM{} } - pcm, err := openALSAPCM(dev) + pcm, err := openALSAPCMBounded(dev, alsaOpenBudget) if err != nil { - logger.Warn("VoLTE 打开模组声卡失败,本次通话无音频", "device", deviceID, "alsa", dev, "err", err) + c.markALSAUnavailable(deviceID) + logger.Warn("VoLTE 打开模组声卡失败,本次通话无音频,后续不再同步打开以免卡住拨号", + "device", deviceID, "alsa", dev, "err", err) return nullPCM{} } return pcm } +func (c *Controller) alsaUnavailable(deviceID string) bool { + c.mu.Lock() + defer c.mu.Unlock() + s := c.sess[strings.TrimSpace(deviceID)] + return s != nil && s.alsaUnavailable +} + +func (c *Controller) markALSAUnavailable(deviceID string) { + c.mu.Lock() + defer c.mu.Unlock() + s := c.ensureLocked(deviceID) + s.alsaUnavailable = true +} + +func (c *Controller) sessionVoice(deviceID string) *voiceSession { + c.mu.Lock() + defer c.mu.Unlock() + s := c.sess[strings.TrimSpace(deviceID)] + if s == nil { + return nil + } + return s.voice +} + func (c *Controller) storeCall(deviceID string, call nativeCall) { c.mu.Lock() s := c.ensureLocked(deviceID) @@ -629,7 +703,11 @@ func (vs *voiceSession) put(call nativeCall) { if vs.active == nil { vs.active = make(map[string]nativeCall) } + if vs.byQMI == nil { + vs.byQMI = make(map[uint8]string) + } vs.active[call.ID] = call + vs.byQMI[call.QMI] = call.ID vs.mu.Unlock() } @@ -640,6 +718,17 @@ func (vs *voiceSession) get(id string) (nativeCall, bool) { return call, ok } +func (vs *voiceSession) getByQMI(qmiID uint8) (nativeCall, bool) { + vs.mu.Lock() + defer vs.mu.Unlock() + id, ok := vs.byQMI[qmiID] + if !ok { + return nativeCall{}, false + } + call, ok := vs.active[id] + return call, ok +} + func (vs *voiceSession) list() []nativeCall { vs.mu.Lock() defer vs.mu.Unlock() @@ -668,6 +757,9 @@ func (vs *voiceSession) markEmitted(id, eventType string) bool { func (vs *voiceSession) forget(id string) { vs.mu.Lock() + if call, ok := vs.active[id]; ok && vs.byQMI[call.QMI] == id { + delete(vs.byQMI, call.QMI) + } delete(vs.active, id) delete(vs.emitted, id) delete(vs.incomingSeen, id) diff --git a/internal/volte/voice_test.go b/internal/volte/voice_test.go index 007dd795..4af876ca 100644 --- a/internal/volte/voice_test.go +++ b/internal/volte/voice_test.go @@ -22,6 +22,33 @@ func enableVoice(t *testing.T) (*Controller, *FakeModem) { return ctl, host } +func TestBeginCallReusesIndicationCallID(t *testing.T) { + ctl, host := enableVoice(t) + var events []voicehost.CallEvent + ctl.SubscribeCallEvents(func(ev voicehost.CallEvent) { events = append(events, ev) }) + host.dialVoice = &qmi.VoiceAllCallInfo{ + Calls: []qmi.VoiceCallInfo{{ID: 1, State: qmiCallOriginating, Direction: qmiDirMO}}, + RemotePartyNumbers: []qmi.VoiceRemotePartyNumber{{CallID: 1, Number: "10000"}}, + } + snap, err := ctl.BeginCall(context.Background(), voicehost.BeginCallRequest{DeviceID: "wwan1", Callee: "10000"}) + if err != nil { + t.Fatal(err) + } + if len(events) == 0 { + t.Fatal("expected ringing from dial indication") + } + if events[0].CallID != snap.CallID { + t.Fatalf("BeginCall id %s != indication id %s", snap.CallID, events[0].CallID) + } + ids := map[string]bool{} + for _, ev := range events { + ids[ev.CallID] = true + } + if len(ids) != 1 { + t.Fatalf("split call ids %v", ids) + } +} + func TestVoiceAgentMOSequenceOnce(t *testing.T) { ctl, host := enableVoice(t) var events []voicehost.CallEvent @@ -49,7 +76,7 @@ func TestVoiceAgentMOSequenceOnce(t *testing.T) { host.fireVoice(&qmi.VoiceAllCallInfo{ Calls: []qmi.VoiceCallInfo{{ID: 1, State: qmiCallEnd, Direction: qmiDirMO}}, }) - if snap.CallID != "volte-wwan1-1" { + if !strings.HasPrefix(snap.CallID, "volte-wwan1-1-") { t.Fatalf("call id %s", snap.CallID) } got := eventTypes(events) @@ -110,7 +137,8 @@ func TestVoiceAgentReusesQMICallIDAfterEnd(t *testing.T) { ctl, host := enableVoice(t) var events []voicehost.CallEvent ctl.SubscribeCallEvents(func(ev voicehost.CallEvent) { events = append(events, ev) }) - if _, err := ctl.BeginCall(context.Background(), voicehost.BeginCallRequest{DeviceID: "wwan1", Callee: "10086"}); err != nil { + first, err := ctl.BeginCall(context.Background(), voicehost.BeginCallRequest{DeviceID: "wwan1", Callee: "10086"}) + if err != nil { t.Fatal(err) } host.fireVoice(&qmi.VoiceAllCallInfo{ @@ -119,15 +147,64 @@ func TestVoiceAgentReusesQMICallIDAfterEnd(t *testing.T) { host.fireVoice(&qmi.VoiceAllCallInfo{ Calls: []qmi.VoiceCallInfo{{ID: 1, State: qmiCallEnd, Direction: qmiDirMO}}, }) - if _, err := ctl.BeginCall(context.Background(), voicehost.BeginCallRequest{DeviceID: "wwan1", Callee: "10010"}); err != nil { + second, err := ctl.BeginCall(context.Background(), voicehost.BeginCallRequest{DeviceID: "wwan1", Callee: "10010"}) + if err != nil { t.Fatal(err) } host.fireVoice(&qmi.VoiceAllCallInfo{ Calls: []qmi.VoiceCallInfo{{ID: 1, State: qmiCallConversation, Direction: qmiDirMO}}, }) + if first.CallID == second.CallID { + t.Fatalf("persistent call id reused after QMI slot recycle: %s", first.CallID) + } + if !strings.HasPrefix(first.CallID, "volte-wwan1-1-") || !strings.HasPrefix(second.CallID, "volte-wwan1-1-") { + t.Fatalf("call ids %s %s", first.CallID, second.CallID) + } if countType(events, "CallAnswered") != 2 { t.Fatalf("second call must answer after id reuse: %v", eventTypes(events)) } + answered := 0 + for _, ev := range events { + if ev.Type != "CallAnswered" { + continue + } + answered++ + if answered == 1 && ev.CallID != first.CallID { + t.Fatalf("first answered call id %s want %s", ev.CallID, first.CallID) + } + if answered == 2 && ev.CallID != second.CallID { + t.Fatalf("second answered call id %s want %s", ev.CallID, second.CallID) + } + } +} + +func TestVoiceAgentMTReusesQMISlotKeepsDistinctCallIDs(t *testing.T) { + ctl, host := enableVoice(t) + var incoming []voicehost.IncomingCall + ctl.SubscribeIncomingCalls(func(call voicehost.IncomingCall) { incoming = append(incoming, call) }) + host.fireVoice(&qmi.VoiceAllCallInfo{ + Calls: []qmi.VoiceCallInfo{{ID: 2, State: qmiCallIncoming, Direction: qmiDirMT}}, + RemotePartyNumbers: []qmi.VoiceRemotePartyNumber{{CallID: 2, Number: "13000000001"}}, + }) + if err := ctl.RejectIncomingCall(voicehost.RejectRequest{DeviceID: "wwan1", CallID: incoming[0].CallID}); err != nil { + t.Fatal(err) + } + host.fireVoice(&qmi.VoiceAllCallInfo{ + Calls: []qmi.VoiceCallInfo{{ID: 2, State: qmiCallEnd, Direction: qmiDirMT}}, + }) + host.fireVoice(&qmi.VoiceAllCallInfo{ + Calls: []qmi.VoiceCallInfo{{ID: 2, State: qmiCallIncoming, Direction: qmiDirMT}}, + RemotePartyNumbers: []qmi.VoiceRemotePartyNumber{{CallID: 2, Number: "13200000002"}}, + }) + if len(incoming) != 2 { + t.Fatalf("incoming %d want 2", len(incoming)) + } + if incoming[0].CallID == incoming[1].CallID { + t.Fatalf("MT call id reused after QMI slot recycle: %s", incoming[0].CallID) + } + if incoming[0].Caller != "13000000001" || incoming[1].Caller != "13200000002" { + t.Fatalf("callers %s %s", incoming[0].Caller, incoming[1].Caller) + } } func TestVoiceAgentIgnoresBackwardAndReconcilesMissing(t *testing.T) {