Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8daf476f authored by Dave Mankoff's avatar Dave Mankoff
Browse files

Add debug logging to try to catch NPE in the wild.

~0.5% (or less) of our dogfooders are getting NPE's in the
KeyguardSliceProvider. It is unclear why this is happening and
we do not currently have reproduction steps for it.

Add some try/catch logging to the KeyguardSliceProvider to try
to catch this phenomenon so that we can narrow down why it is
occuring. This change can be reverted once we know more.

Bug: 168778439
Test: manual
Change-Id: Id65ee5bece75ef8497f7464079e5258781079fa9
parent 210c931b
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.Log;

import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
@@ -52,6 +53,8 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.SystemUIAppComponentFactory;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.dagger.SysUIComponent;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.StatusBarState;
@@ -62,6 +65,8 @@ import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.util.wakelock.SettableWakeLock;
import com.android.systemui.util.wakelock.WakeLock;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
@@ -80,6 +85,8 @@ public class KeyguardSliceProvider extends SliceProvider implements
        NotificationMediaManager.MediaListener, StatusBarStateController.StateListener,
        SystemUIAppComponentFactory.ContextInitializer {

    private static final String TAG = "KgdSliceProvider";

    private static final StyleSpan BOLD_STYLE = new StyleSpan(Typeface.BOLD);
    public static final String KEYGUARD_SLICE_URI = "content://com.android.systemui.keyguard/main";
    private static final String KEYGUARD_HEADER_URI =
@@ -310,7 +317,25 @@ public class KeyguardSliceProvider extends SliceProvider implements
            mDatePattern = getContext().getString(R.string.system_ui_aod_date_pattern);
            mPendingIntent = PendingIntent.getActivity(getContext(), 0,
                    new Intent(getContext(), KeyguardSliceProvider.class), 0);
            try {
                //TODO(b/168778439): Remove this whole try catch. This is for debugging in dogfood.
                mMediaManager.addCallback(this);
            } catch (NullPointerException e) {
                // We are sometimes failing to set the media manager. Why?
                Log.w(TAG, "Failed to setup mMediaManager. Trying again.");
                SysUIComponent rootComponent = SystemUIFactory.getInstance().getSysUIComponent();
                try {
                    Method injectMethod = rootComponent.getClass()
                            .getMethod("inject", getClass());
                    injectMethod.invoke(rootComponent, this);
                    Log.w("TAG", "mMediaManager is now: " + mMediaManager);
                } catch (NoSuchMethodException ex) {
                    Log.e(TAG, "Failed to find inject method for KeyguardSliceProvider", ex);
                } catch (IllegalAccessException | InvocationTargetException ex) {
                    Log.e(TAG, "Failed to call inject", ex);
                }
                throw e;
            }
            mStatusBarStateController.addCallback(this);
            mNextAlarmController.addCallback(this);
            mZenModeController.addCallback(this);