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

Commit fb23ff98 authored by Heemin Seog's avatar Heemin Seog
Browse files

Add null check for handler on Clock view

On reboot, we've encountered an issue where the handler returns null,
causing a null pointer exception in the broadcast receiver.

In this CL, we add a null check and an error message to prevent a sysui
crash.

Bug: 148869042
Test: build, reboot a few times
Change-Id: Iac7f3a538be9a53d4a76926523aa2a3f4f22723d
Merged-In: Ie8a2627004876cf35291d52bd3686a5014498f52
parent e693b797
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.text.format.DateFormat;
import android.text.style.CharacterStyle;
import android.text.style.RelativeSizeSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.widget.TextView;
@@ -67,6 +68,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
        DarkReceiver, ConfigurationListener {

    public static final String CLOCK_SECONDS = "clock_seconds";
    private static final String TAG = "StatusBarClock";
    private static final String CLOCK_SUPER_PARCELABLE = "clock_super_parcelable";
    private static final String CURRENT_USER_ID = "current_user_id";
    private static final String VISIBLE_BY_POLICY = "visible_by_policy";
@@ -228,9 +230,18 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Handler handler = getHandler();
            if (handler == null) {
                Log.e(TAG,
                        "Received intent, but handler is null - still attached to window? Window "
                                + "token: "
                                + getWindowToken());
                return;
            }

            if (action.equals(Intent.ACTION_TIMEZONE_CHANGED)) {
                String tz = intent.getStringExtra("time-zone");
                getHandler().post(() -> {
                handler.post(() -> {
                    mCalendar = Calendar.getInstance(TimeZone.getTimeZone(tz));
                    if (mClockFormat != null) {
                        mClockFormat.setTimeZone(mCalendar.getTimeZone());
@@ -238,14 +249,14 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
                });
            } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
                final Locale newLocale = getResources().getConfiguration().locale;
                getHandler().post(() -> {
                handler.post(() -> {
                    if (!newLocale.equals(mLocale)) {
                        mLocale = newLocale;
                        mClockFormatString = ""; // force refresh
                    }
                });
            }
            getHandler().post(() -> updateClock());
            handler.post(() -> updateClock());
        }
    };