From 180c48489f07ebd748700a5a312070583fefdb45 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Tue, 13 Sep 2011 12:39:25 -0700 Subject: [PATCH] Fix issue #5309443: Ninjump crashes on boot with... ...java.lang.IllegalArgumentException: Window type can not be changed after the window is added Change-Id: I4e34622c99d721fa214fd534a9bbfc8006184770 --- core/java/android/view/ViewRootImpl.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index fb3f6e818701e..81f9d78d1e011 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -164,11 +164,14 @@ public final class ViewRootImpl extends Handler implements ViewParent, final W mWindow; + final int mTargetSdkVersion; + View mView; View mFocusedView; View mRealFocusedView; // this is not set to null in touch mode int mViewVisibility; boolean mAppVisible = true; + int mOrigWindowType = -1; // Set to true if the owner of this window is in the stopped state, // so the window should no longer be active. @@ -331,6 +334,7 @@ public final class ViewRootImpl extends Handler implements ViewParent, mVisRect = new Rect(); mWinFrame = new Rect(); mWindow = new W(this); + mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion; mInputMethodCallback = new InputMethodCallback(this); mViewVisibility = View.GONE; mTransparentRegion = new Region(); @@ -461,6 +465,7 @@ public final class ViewRootImpl extends Handler implements ViewParent, mInputChannel = new InputChannel(); } try { + mOrigWindowType = mWindowAttributes.type; res = sWindowSession.add(mWindow, mWindowAttributes, getHostVisibility(), mAttachInfo.mContentInsets, mInputChannel); @@ -3481,6 +3486,14 @@ public final class ViewRootImpl extends Handler implements ViewParent, } mPendingConfiguration.seq = 0; //Log.d(TAG, ">>>>>> CALLING relayout"); + if (params != null && mOrigWindowType != params.type) { + // For compatibility with old apps, don't crash here. + if (mTargetSdkVersion < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + Slog.w(TAG, "Window type can not be changed after " + + "the window is added; ignoring change of " + mView); + params.type = mOrigWindowType; + } + } int relayoutResult = sWindowSession.relayout( mWindow, params, (int) (mView.getMeasuredWidth() * appScale + 0.5f),