Ensure window has been added in isTopOfTask

Bug 27893230

When isTopOfTask is called prior to the window being added, it
will throw an IllegalArgumentException. This checks that the
window has been added before making the call.

Change-Id: Idd14c0f1051e16d96a0a1fa9f990f380a1f69911
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 887932a..0d387e6 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -5920,6 +5920,9 @@
      * @return true if this is the topmost, non-finishing activity in its task.
      */
     private boolean isTopOfTask() {
+        if (mToken == null || mWindow == null || !mWindowAdded) {
+            return false;
+        }
         try {
             return ActivityManagerNative.getDefault().isTopOfTask(mToken);
         } catch (RemoteException e) {