Merge "Fix NPE in date time settings" into main

This commit is contained in:
Edgar Wang
2024-08-09 02:07:51 +00:00
committed by Android (Google) Code Review
3 changed files with 15 additions and 0 deletions

View File

@@ -39,6 +39,11 @@ public class AutoTimePreferenceController extends TogglePreferenceController {
public AutoTimePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
mTimeManager = context.getSystemService(TimeManager.class);
// This is a no-op implementation of UpdateTimeAndDateCallback to avoid a NPE when
// setTimeAndDateCallback() isn't called, e.g. for slices and other cases where the
// controller is instantiated outside of the context of the real Date & Time settings
// screen.
mCallback = (c) -> {};
}
public void setDateAndTimeCallback(UpdateTimeAndDateCallback callback) {

View File

@@ -40,6 +40,11 @@ public class AutoTimeZonePreferenceController extends TogglePreferenceController
public AutoTimeZonePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
mTimeManager = context.getSystemService(TimeManager.class);
// This is a no-op implementation of UpdateTimeAndDateCallback to avoid a NPE when
// setTimeAndDateCallback() isn't called, e.g. for slices and other cases where the
// controller is instantiated outside of the context of the real Date & Time settings
// screen.
mCallback = (c) -> {};
}
/**

View File

@@ -43,6 +43,11 @@ public class TimeFormatPreferenceController extends TogglePreferenceController {
public TimeFormatPreferenceController(Context context, String key) {
super(context, key);
mDummyDate = Calendar.getInstance();
// This is a no-op implementation of UpdateTimeAndDateCallback to avoid a NPE when
// setTimeAndDateCallback() isn't called, e.g. for slices and other cases where the
// controller is instantiated outside of the context of the real Date & Time settings
// screen.
mUpdateTimeAndDateCallback = (c) -> {};
}
/**