From dee32583568b2b9fbd085fd4479d5e62ece72c47 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Sat, 25 Aug 2018 20:11:18 +0200 Subject: [PATCH] LineageNotificationLights: Don't create KeyguardManager in constructor * Apparently creating it so early can cause serious breakages that make StorageManagerService and UsbDeviceManager end up getting null pointer when trying to get KeyguardManager with ctx.getSystemService(KeyguardManager.class). * Moving ctx.getSystemService(KeyguardManager.class) out of constructor to isKeyguardLocked() solves these issues. * Also move to getSystemService(Class) while at it. Change-Id: Ib3f65ba2e726149089ab1fb12030321e0ecdeab1 --- .../notification/LineageNotificationLights.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java b/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java index 73377543..75a325fb 100644 --- a/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java +++ b/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java @@ -1,6 +1,6 @@ /** * Copyright (C) 2015 The CyanogenMod Project - * Copyright (C) 2017 The LineageOS Project + * Copyright (C) 2017-2018 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,9 +77,6 @@ public final class LineageNotificationLights { private int mZenMode; - // For checking lockscreen status - private KeyguardManager mKeyguardManager; - private final SettingsObserver mSettingsObserver; private final Context mContext; @@ -122,9 +119,6 @@ public final class LineageNotificationLights { mPackageNameMappings.put(map[0], map[1]); } - mKeyguardManager = - (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); - mSettingsObserver = new SettingsObserver(new Handler()); mSettingsObserver.observe(); } @@ -138,7 +132,8 @@ public final class LineageNotificationLights { // when lights should / should not be cleared. // TODO: put this somewhere else public boolean isKeyguardLocked() { - return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked(); + KeyguardManager keyguardManager = mContext.getSystemService(KeyguardManager.class); + return keyguardManager != null && keyguardManager.isKeyguardLocked(); } private void parseNotificationPulseCustomValuesString(String customLedValuesString) {