Skip to content

Commit 11a0089

Browse files
committed
Acquire WakeLock before sending Intent to bound Service.
* Acquired the WakeLock in sendWakefulServiceIntent() before sending the Intent to the Service to avoid a race condition where the service could finish handling the Intent and call completeWakefulIntent() (trying to release the WakeLock) before the WakeLock was acquired.
1 parent aa5785a commit 11a0089

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

firebase-messaging/src/main/java/com/google/firebase/messaging/WakeLockHolder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ static void sendWakefulServiceIntent(
104104

105105
setAsWakefulIntent(intent, true);
106106

107-
connection
108-
.sendIntent(intent)
109-
.addOnCompleteListener(Runnable::run, t -> completeWakefulIntent(intent));
110-
111107
if (!isWakeLockAlreadyAcquired) {
112108
wakeLock.acquire(WAKE_LOCK_ACQUIRE_TIMEOUT_MILLIS);
113109
}
110+
111+
connection
112+
.sendIntent(intent)
113+
.addOnCompleteListener(Runnable::run, t -> completeWakefulIntent(intent));
114114
}
115115
}
116116

0 commit comments

Comments
 (0)