@@ -334,7 +334,7 @@ status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandle
334334// --- InputConsumer ---
335335
336336InputConsumer::InputConsumer (const sp<InputChannel>& channel) :
337- mChannel (channel), mDeferredEventSeq ( 0 ) {
337+ mChannel (channel), mMsgDeferred ( false ) {
338338}
339339
340340InputConsumer::~InputConsumer () {
@@ -350,55 +350,44 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
350350 *outSeq = 0 ;
351351 *outEvent = NULL ;
352352
353- // Report deferred event first, if we had to end a batch earlier than we expected
354- // during the previous time consume was called.
355- if (mDeferredEventSeq ) {
356- MotionEvent* motionEvent = factory->createMotionEvent ();
357- if (! motionEvent) return NO_MEMORY;
358-
359- motionEvent->copyFrom (&mDeferredEvent , true /* keepHistory*/ );
360- *outSeq = mDeferredEventSeq ;
361- *outEvent = motionEvent;
362- mDeferredEventSeq = 0 ;
363- #if DEBUG_TRANSPORT_ACTIONS
364- ALOGD (" channel '%s' consumer ~ consumed deferred event, seq=%u" ,
365- mChannel ->getName ().string (), *outSeq);
366- #endif
367- return OK;
368- }
369-
370353 // Fetch the next input message.
371354 // Loop until an event can be returned or no additional events are received.
372355 while (!*outEvent) {
373- InputMessage msg;
374- status_t result = mChannel ->receiveMessage (&msg);
375- if (result) {
376- // Consume the next batched event unless batches are being held for later.
377- if (!mBatches .isEmpty () && (consumeBatches || result != WOULD_BLOCK)) {
378- MotionEvent* motionEvent = factory->createMotionEvent ();
379- if (! motionEvent) return NO_MEMORY;
380-
381- const Batch& batch = mBatches .top ();
382- motionEvent->copyFrom (&batch.event , true /* keepHistory*/ );
383- *outSeq = batch.seq ;
384- *outEvent = motionEvent;
385- mBatches .pop ();
356+ if (mMsgDeferred ) {
357+ // mMsg contains a valid input message from the previous call to consume
358+ // that has not yet been processed.
359+ mMsgDeferred = false ;
360+ } else {
361+ // Receive a fresh message.
362+ status_t result = mChannel ->receiveMessage (&mMsg );
363+ if (result) {
364+ // Consume the next batched event unless batches are being held for later.
365+ if (!mBatches .isEmpty () && (consumeBatches || result != WOULD_BLOCK)) {
366+ MotionEvent* motionEvent = factory->createMotionEvent ();
367+ if (! motionEvent) return NO_MEMORY;
368+
369+ const Batch& batch = mBatches .top ();
370+ motionEvent->copyFrom (&batch.event , true /* keepHistory*/ );
371+ *outSeq = batch.seq ;
372+ *outEvent = motionEvent;
373+ mBatches .pop ();
386374#if DEBUG_TRANSPORT_ACTIONS
387- ALOGD (" channel '%s' consumer ~ consumed batch event, seq=%u" ,
388- mChannel ->getName ().string (), *outSeq);
375+ ALOGD (" channel '%s' consumer ~ consumed batch event, seq=%u" ,
376+ mChannel ->getName ().string (), *outSeq);
389377#endif
390- break ;
378+ break ;
379+ }
380+ return result;
391381 }
392- return result;
393382 }
394383
395- switch (msg .header .type ) {
384+ switch (mMsg .header .type ) {
396385 case InputMessage::TYPE_KEY: {
397386 KeyEvent* keyEvent = factory->createKeyEvent ();
398387 if (!keyEvent) return NO_MEMORY;
399388
400- initializeKeyEvent (keyEvent, &msg );
401- *outSeq = msg .body .key .seq ;
389+ initializeKeyEvent (keyEvent, &mMsg );
390+ *outSeq = mMsg .body .key .seq ;
402391 *outEvent = keyEvent;
403392#if DEBUG_TRANSPORT_ACTIONS
404393 ALOGD (" channel '%s' consumer ~ consumed key event, seq=%u" ,
@@ -408,10 +397,10 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
408397 }
409398
410399 case AINPUT_EVENT_TYPE_MOTION: {
411- ssize_t batchIndex = findBatch (msg .body .motion .deviceId , msg .body .motion .source );
400+ ssize_t batchIndex = findBatch (mMsg .body .motion .deviceId , mMsg .body .motion .source );
412401 if (batchIndex >= 0 ) {
413402 Batch& batch = mBatches .editItemAt (batchIndex);
414- if (canAppendSamples (&batch.event , &msg )) {
403+ if (canAppendSamples (&batch.event , &mMsg )) {
415404 // Send finished message for the earlier part of the batch.
416405 // Claim that we handled the event. (The dispatcher doesn't care either
417406 // way at the moment.)
@@ -421,8 +410,8 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
421410 }
422411
423412 // Append to the batch and save the new sequence number for the tail end.
424- appendSamples (&batch.event , &msg );
425- batch.seq = msg .body .motion .seq ;
413+ appendSamples (&batch.event , &mMsg );
414+ batch.seq = mMsg .body .motion .seq ;
426415#if DEBUG_TRANSPORT_ACTIONS
427416 ALOGD (" channel '%s' consumer ~ appended to batch event" ,
428417 mChannel ->getName ().string ());
@@ -433,9 +422,8 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
433422 if (! motionEvent) return NO_MEMORY;
434423
435424 // We cannot append to the batch in progress, so we need to consume
436- // the previous batch right now and defer the new event until later.
437- mDeferredEventSeq = msg.body .motion .seq ;
438- initializeMotionEvent (&mDeferredEvent , &msg);
425+ // the previous batch right now and defer the new message until later.
426+ mMsgDeferred = true ;
439427
440428 // Return the end of the previous batch.
441429 motionEvent->copyFrom (&batch.event , true /* keepHistory*/ );
@@ -452,12 +440,12 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
452440 }
453441
454442 // Start a new batch if needed.
455- if (msg .body .motion .action == AMOTION_EVENT_ACTION_MOVE
456- || msg .body .motion .action == AMOTION_EVENT_ACTION_HOVER_MOVE) {
443+ if (mMsg .body .motion .action == AMOTION_EVENT_ACTION_MOVE
444+ || mMsg .body .motion .action == AMOTION_EVENT_ACTION_HOVER_MOVE) {
457445 mBatches .push ();
458446 Batch& batch = mBatches .editTop ();
459- batch.seq = msg .body .motion .seq ;
460- initializeMotionEvent (&batch.event , &msg );
447+ batch.seq = mMsg .body .motion .seq ;
448+ initializeMotionEvent (&batch.event , &mMsg );
461449#if DEBUG_TRANSPORT_ACTIONS
462450 ALOGD (" channel '%s' consumer ~ started batch event" ,
463451 mChannel ->getName ().string ());
@@ -468,8 +456,8 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
468456 MotionEvent* motionEvent = factory->createMotionEvent ();
469457 if (! motionEvent) return NO_MEMORY;
470458
471- initializeMotionEvent (motionEvent, &msg );
472- *outSeq = msg .body .motion .seq ;
459+ initializeMotionEvent (motionEvent, &mMsg );
460+ *outSeq = mMsg .body .motion .seq ;
473461 *outEvent = motionEvent;
474462#if DEBUG_TRANSPORT_ACTIONS
475463 ALOGD (" channel '%s' consumer ~ consumed motion event, seq=%u" ,
@@ -480,7 +468,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
480468
481469 default :
482470 ALOGE (" channel '%s' consumer ~ Received unexpected message of type %d" ,
483- mChannel ->getName ().string (), msg .header .type );
471+ mChannel ->getName ().string (), mMsg .header .type );
484472 return UNKNOWN_ERROR;
485473 }
486474 }
0 commit comments