Fix NPE in PanelFragment

When updating the panel after getting a second intent to the
activity, there is a small window of opportunity for the user
to close the activity before the animation ends, causing an
NPE when onFinish is called as the activity already closed down.
This change will check that there is an activity before trying
to finish it.

Bug: 150322041
Test:
For an easy way to reproduce this, turn the screen on and run the
following in a terminal:
 while true; do adb shell am start -a \
 android.settings.panel.action.INTERNET_CONNECTIVITY; \
 sleep 0.1; done
Then press the back button while the screen is attempting to
display the fragment. There should be no Settings crash.
Change-Id: I4ca831d71a7221a7a4a62bb29e802f507ce5213c
This commit is contained in:
Daniel Hunt
2020-02-20 13:34:02 +01:00
committed by Edward Savage-Jones
parent 4f4c05addb
commit 26aaf07e9d

View File

@@ -144,8 +144,13 @@ public class PanelFragment extends Fragment {
private void createPanelContent() {
final FragmentActivity activity = getActivity();
if (activity == null) {
return;
}
if (mLayoutView == null) {
activity.finish();
return;
}
mPanelSlices = mLayoutView.findViewById(R.id.panel_parent_layout);
@@ -172,6 +177,7 @@ public class PanelFragment extends Fragment {
if (mPanel == null) {
activity.finish();
return;
}
mMetricsProvider = FeatureFactory.getFactory(activity).getMetricsFeatureProvider();