From ce1ecf1f346e55a02159b3a1bb7f5d648efb042b Mon Sep 17 00:00:00 2001 From: Andrii Kulian Date: Fri, 17 Mar 2017 14:58:36 -0700 Subject: [PATCH] Fix NPE when config is updated before ViewRootImpl is set If activity received a configuration change before it had its ViewRootImpl initialize, then there was a NPE when trying to notify the ViewRootImpl instance about latest changes. Bug: 36396248 Test: android.server.cts.ActivityManagerAppConfigurationTests Test: #testLaunchWithUiModeChange Test: Launch AndroidAuto app Change-Id: I71e0f316f885a30dadce388bbd3d9f21f419076b --- core/java/android/app/ActivityThread.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 6b53cd841dff9..30f7646904ee2 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -5070,7 +5070,9 @@ public final class ActivityThread { performConfigurationChangedForActivity(r, mCompatConfiguration, displayId, true /* movedToDifferentDisplay */); - viewRoot.onMovedToDisplay(displayId); + if (viewRoot != null) { + viewRoot.onMovedToDisplay(displayId); + } } else { if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " + r.activityInfo.name + ", config=" + data.overrideConfig); @@ -5078,7 +5080,9 @@ public final class ActivityThread { } // Notify the ViewRootImpl instance about configuration changes. It may have initiated this // update to make sure that resources are updated before updating itself. - viewRoot.updateConfiguration(); + if (viewRoot != null) { + viewRoot.updateConfiguration(); + } mSomeActivitiesChanged = true; }