From c06e32dcc2b6a487b91f359ca9fc2ba166449127 Mon Sep 17 00:00:00 2001 From: Bruno Martins Date: Fri, 25 Sep 2020 01:13:59 +0100 Subject: [PATCH] TrustInterfaceService: Init mNotificationManager in the constructor Ensure that the variable is not null when removeNotificationForFeatureInternal(int) is called so to avoid the NPE: E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.NotificationManager.cancel(int)' on a null object reference This fixes LineageParts crashing when disabling Trust notifications. Change-Id: Ia0fa793378116101821a7bd424e0859869db48f5 --- .../org/lineageos/platform/internal/TrustInterfaceService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java b/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java index f199b654..dc8e53bd 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java @@ -69,6 +69,7 @@ public class TrustInterfaceService extends LineageSystemService { public TrustInterfaceService(Context context) { super(context); mContext = context; + mNotificationManager = context.getSystemService(NotificationManager.class); if (context.getPackageManager().hasSystemFeature(LineageContextConstants.Features.TRUST)) { publishBinderService(LineageContextConstants.LINEAGE_TRUST_INTERFACE, mService); } else { @@ -84,8 +85,6 @@ public class TrustInterfaceService extends LineageSystemService { @Override public void onStart() { - mNotificationManager = mContext.getSystemService(NotificationManager.class); - try { mUsbRestrictor = IUsbRestrict.getService(); } catch (NoSuchElementException | RemoteException e) {