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
This commit is contained in:
Bruno Martins
2020-09-25 01:13:59 +01:00
parent 063a591095
commit c06e32dcc2

View File

@@ -69,6 +69,7 @@ public class TrustInterfaceService extends LineageSystemService {
public TrustInterfaceService(Context context) { public TrustInterfaceService(Context context) {
super(context); super(context);
mContext = context; mContext = context;
mNotificationManager = context.getSystemService(NotificationManager.class);
if (context.getPackageManager().hasSystemFeature(LineageContextConstants.Features.TRUST)) { if (context.getPackageManager().hasSystemFeature(LineageContextConstants.Features.TRUST)) {
publishBinderService(LineageContextConstants.LINEAGE_TRUST_INTERFACE, mService); publishBinderService(LineageContextConstants.LINEAGE_TRUST_INTERFACE, mService);
} else { } else {
@@ -84,8 +85,6 @@ public class TrustInterfaceService extends LineageSystemService {
@Override @Override
public void onStart() { public void onStart() {
mNotificationManager = mContext.getSystemService(NotificationManager.class);
try { try {
mUsbRestrictor = IUsbRestrict.getService(); mUsbRestrictor = IUsbRestrict.getService();
} catch (NoSuchElementException | RemoteException e) { } catch (NoSuchElementException | RemoteException e) {