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

Commit 2f3df6ce authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents dfd366ed 8daf476f
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);