@@ -401,17 +401,16 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
401401 if (batchIndex >= 0 ) {
402402 Batch& batch = mBatches .editItemAt (batchIndex);
403403 if (canAppendSamples (&batch.event , &mMsg )) {
404- // Send finished message for the earlier part of the batch.
405- // Claim that we handled the event. (The dispatcher doesn't care either
406- // way at the moment.)
407- status_t status = sendFinishedSignal (batch.seq , true );
408- if (status) {
409- return status;
410- }
411-
412404 // Append to the batch and save the new sequence number for the tail end.
405+ uint32_t chain = batch.seq ;
413406 appendSamples (&batch.event , &mMsg );
414407 batch.seq = mMsg .body .motion .seq ;
408+
409+ // Update the sequence number chain.
410+ SeqChain seqChain;
411+ seqChain.seq = batch.seq ;
412+ seqChain.chain = chain;
413+ mSeqChains .push (seqChain);
415414#if DEBUG_TRANSPORT_ACTIONS
416415 ALOGD (" channel '%s' consumer ~ appended to batch event" ,
417416 mChannel ->getName ().string ());
@@ -486,6 +485,41 @@ status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) {
486485 return BAD_VALUE;
487486 }
488487
488+ // Send finished signals for the batch sequence chain first.
489+ size_t seqChainCount = mSeqChains .size ();
490+ if (seqChainCount) {
491+ uint32_t currentSeq = seq;
492+ uint32_t chainSeqs[seqChainCount];
493+ size_t chainIndex = 0 ;
494+ for (size_t i = seqChainCount; i-- > 0 ; ) {
495+ const SeqChain& seqChain = mSeqChains .itemAt (i);
496+ if (seqChain.seq == currentSeq) {
497+ currentSeq = seqChain.chain ;
498+ chainSeqs[chainIndex++] = currentSeq;
499+ mSeqChains .removeAt (i);
500+ }
501+ }
502+ status_t status = OK;
503+ while (!status && chainIndex-- > 0 ) {
504+ status = sendUnchainedFinishedSignal (chainSeqs[chainIndex], handled);
505+ }
506+ if (status) {
507+ // An error occurred so at least one signal was not sent, reconstruct the chain.
508+ do {
509+ SeqChain seqChain;
510+ seqChain.seq = chainIndex != 0 ? chainSeqs[chainIndex - 1 ] : seq;
511+ seqChain.chain = chainSeqs[chainIndex];
512+ mSeqChains .push (seqChain);
513+ } while (chainIndex-- > 0 );
514+ return status;
515+ }
516+ }
517+
518+ // Send finished signal for the last message in the batch.
519+ return sendUnchainedFinishedSignal (seq, handled);
520+ }
521+
522+ status_t InputConsumer::sendUnchainedFinishedSignal (uint32_t seq, bool handled) {
489523 InputMessage msg;
490524 msg.header .type = InputMessage::TYPE_FINISHED;
491525 msg.body .finished .seq = seq;
0 commit comments