Skip to content

Commit

Permalink
Fix possible missing OnSuspend() / OnResume() call
Browse files Browse the repository at this point in the history
This bug was recently introduced with the change to call
HandleEventAndUpdateState() instead of Inject() for intermediate
events.

b/223218633

Change-Id: I4deb159cd2989f31e76c37848bb51271adf23722
(cherry picked from commit d3e76188663c07318681ffdf0bde530e1222c390)
  • Loading branch information
tphamg committed Jun 7, 2022
1 parent fcdf0c4 commit 12ab92f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions starboard/shared/starboard/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ bool Application::DispatchAndDelete(Application::Event* event) {
HandleEventAndUpdateState(scoped_event.release());
return true;
case kStateConcealed:
OnSuspend();
break;
case kStateFrozen:
case kStateStopped:
Expand All @@ -379,7 +378,6 @@ bool Application::DispatchAndDelete(Application::Event* event) {
case kStateStopped:
return true;
case kStateFrozen:
OnResume();
break;
case kStateConcealed:
case kStateBlurred:
Expand Down Expand Up @@ -482,9 +480,6 @@ bool Application::DispatchAndDelete(Application::Event* event) {
if (state() == kStateStarted || state() == kStatePaused) {
return true;
}
if (state() == kStateSuspended) {
OnResume();
}
break;
case kSbEventTypeStop:
// There is a race condition with kSbEventTypeStop processing and
Expand Down Expand Up @@ -527,7 +522,25 @@ bool Application::HandleEventAndUpdateState(Application::Event* event) {
// Ensure the event is deleted unless it is released.
scoped_ptr<Event> scoped_event(event);

// Call OnSuspend() and OnResume() before the event as needed.
#if SB_API_VERSION >= 13
if (scoped_event->event->type == kSbEventTypeUnfreeze &&
state() == kStateFrozen) {
OnResume();
} else if (scoped_event->event->type == kSbEventTypeFreeze &&
state() == kStateConcealed) {
OnSuspend();
}
#else
if (scoped_event->event->type == kSbEventTypeResume &&
state() == kStateSuspended) {
OnResume();
}
// OnSuspend() is called after SbEventHandle(kSbEventTypeSuspend).
#endif // SB_API_VERSION >= 13

SbEventHandle(scoped_event->event);

#if SB_API_VERSION >= 13
switch (scoped_event->event->type) {
case kSbEventTypePreload:
Expand Down

0 comments on commit 12ab92f

Please sign in to comment.