From 64406ebbe4257441f9ea68c639a5ad0098370fb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Tue, 7 Jan 2020 14:18:21 -0500
Subject: [PATCH] firebase: re-add wakelock to avoid to block incoming calls

Even if wakeLock is deprecated, without this part, some devices are blocking
during the call negotiation. So, re-add this code to avoid to block here.

Change-Id: Icd7ec3e0c441eab31efad5080dc79357edde2747
---
 .../services/JamiFirebaseMessagingService.java    | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/ring-android/app/src/withFirebase/java/cx/ring/services/JamiFirebaseMessagingService.java b/ring-android/app/src/withFirebase/java/cx/ring/services/JamiFirebaseMessagingService.java
index 87d7101f4..ded31b94a 100644
--- a/ring-android/app/src/withFirebase/java/cx/ring/services/JamiFirebaseMessagingService.java
+++ b/ring-android/app/src/withFirebase/java/cx/ring/services/JamiFirebaseMessagingService.java
@@ -18,6 +18,10 @@
  */
 package cx.ring.services;
 
+import android.content.Context;
+import android.os.PowerManager;
+import android.util.Log;
+
 import androidx.annotation.NonNull;
 
 import com.google.firebase.messaging.FirebaseMessagingService;
@@ -29,6 +33,17 @@ import cx.ring.application.JamiApplicationFirebase;
 public class JamiFirebaseMessagingService extends FirebaseMessagingService {
     @Override
     public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
+        try {
+            // Even if wakeLock is deprecated, without this part, some devices are blocking
+            // during the call negotiation. So, re-add this code to avoid to block here.
+            PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
+            PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wake:push");
+            wl.setReferenceCounted(false);
+            wl.acquire(20 * 1000);
+        } catch (Exception e) {
+            Log.w("JamiFirebaseMessaging", "Can't acquire wake lock", e);
+        }
+
         JamiApplicationFirebase app = (JamiApplicationFirebase)JamiApplication.getInstance();
         if (app != null)
             app.onMessageReceived(remoteMessage);
-- 
GitLab