From 26aaf07e9dcb5777ee2069992ab8168d9de791de Mon Sep 17 00:00:00 2001 From: Daniel Hunt Date: Thu, 20 Feb 2020 13:34:02 +0100 Subject: [PATCH] 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 --- src/com/android/settings/panel/PanelFragment.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/com/android/settings/panel/PanelFragment.java b/src/com/android/settings/panel/PanelFragment.java index 79d1ac592d9..5080d9b3e07 100644 --- a/src/com/android/settings/panel/PanelFragment.java +++ b/src/com/android/settings/panel/PanelFragment.java @@ -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();