Fix an exception in PackageInstaller

It is apparently possible for an activity to get
a configuration change callback when its view is
no longer attached to the window manager. Check
if a view is attached before removing it from the
window manager.

bug:30389560

Change-Id: I384401742eca61d140c7590eb5c67150a15da83b
diff --git a/src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java b/src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java
index c4471be..b134729 100644
--- a/src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java
+++ b/src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java
@@ -196,10 +196,12 @@
         // window height needed to show all content. We have to
         // re-add the window to force it to be resized if needed.
         View decor = getWindow().getDecorView();
-        getWindowManager().removeViewImmediate(decor);
-        getWindowManager().addView(decor, decor.getLayoutParams());
-        if (mViewHandler instanceof GrantPermissionsViewHandlerImpl) {
-            ((GrantPermissionsViewHandlerImpl) mViewHandler).onConfigurationChanged();
+        if (decor.getParent() != null) {
+            getWindowManager().removeViewImmediate(decor);
+            getWindowManager().addView(decor, decor.getLayoutParams());
+            if (mViewHandler instanceof GrantPermissionsViewHandlerImpl) {
+                ((GrantPermissionsViewHandlerImpl) mViewHandler).onConfigurationChanged();
+            }
         }
     }