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<T>) while at it.

Change-Id: Ib3f65ba2e726149089ab1fb12030321e0ecdeab1
This commit is contained in:
LuK1337
2018-08-25 20:11:18 +02:00
committed by Bruno Martins
parent 3cc3d4d2ad
commit dee3258356

View File

@@ -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) {