diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 44d84438ed559d19e8b3a6874b1bd8b0afbce3ca..b42ee55a2ecf1e8dc46a4efbab1ba4f5e6767001 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1249,7 +1249,11 @@ public class XmppConnectionService extends Service { } final PowerManager powerManager = getSystemService(PowerManager.class); - this.wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Conversations:Service"); + if (powerManager != null) { + this.wakeLock = + powerManager.newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, "Conversations:Service"); + } toggleForegroundService(); updateUnreadCountBadge(); diff --git a/src/main/java/eu/siacs/conversations/utils/WakeLockHelper.java b/src/main/java/eu/siacs/conversations/utils/WakeLockHelper.java index 9fb38ef86eede1658e50a74f074d29cb26676f51..3ddb5738b6122792c628953ce15f1295b6e267ec 100644 --- a/src/main/java/eu/siacs/conversations/utils/WakeLockHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/WakeLockHelper.java @@ -36,24 +36,28 @@ import eu.siacs.conversations.Config; public class WakeLockHelper { - public static void acquire(final PowerManager.WakeLock wakeLock) { - try { - wakeLock.acquire(2000); - } catch (final RuntimeException e) { - Log.d(Config.LOGTAG, "unable to acquire wake lock", e); - } - } + public static void acquire(final PowerManager.WakeLock wakeLock) { + if (wakeLock == null) { + Log.d(Config.LOGTAG, "could not acquire WakeLock. PowerManager was null"); + return; + } + try { + wakeLock.acquire(2000); + } catch (final RuntimeException e) { + Log.d(Config.LOGTAG, "Could not acquire WakeLock", e); + } + } - public static void release(final PowerManager.WakeLock wakeLock) { - if (wakeLock == null) { - return; - } - try { - if (wakeLock.isHeld()) { - wakeLock.release(); - } - } catch (final RuntimeException e) { - Log.d(Config.LOGTAG, "unable to release wake lock", e); - } - } + public static void release(final PowerManager.WakeLock wakeLock) { + if (wakeLock == null) { + return; + } + try { + if (wakeLock.isHeld()) { + wakeLock.release(); + } + } catch (final RuntimeException e) { + Log.d(Config.LOGTAG, "unable to release wake lock", e); + } + } }