NPE protection for invokeJobRecheck() in the fragment

Ensure getContext() is not null before invokeJobRecheck() in the
background, since the main fragment may be detached to return null
context (in the corner case)

Test: atest
Fix: 331719252
Change-Id: Ia7ba757d2e6ebaf3fd371af51270c0eb0ad0a9f7
This commit is contained in:
YK Hung
2024-03-29 02:40:07 +00:00
parent 9507bdb3ac
commit e78fd23820

View File

@@ -95,7 +95,11 @@ public class PowerUsageAdvanced extends PowerUsageBase {
super.onCreate(icicle);
mHistPref = findPreference(KEY_BATTERY_CHART);
setBatteryChartPreferenceController();
AsyncTask.execute(() -> BootBroadcastReceiver.invokeJobRecheck(getContext()));
AsyncTask.execute(() -> {
if (getContext() != null) {
BootBroadcastReceiver.invokeJobRecheck(getContext());
}
});
}
@Override