@@ -164,11 +164,14 @@ public final class ViewRootImpl extends Handler implements ViewParent,
164164
165165 final W mWindow ;
166166
167+ final int mTargetSdkVersion ;
168+
167169 View mView ;
168170 View mFocusedView ;
169171 View mRealFocusedView ; // this is not set to null in touch mode
170172 int mViewVisibility ;
171173 boolean mAppVisible = true ;
174+ int mOrigWindowType = -1 ;
172175
173176 // Set to true if the owner of this window is in the stopped state,
174177 // so the window should no longer be active.
@@ -331,6 +334,7 @@ public ViewRootImpl(Context context) {
331334 mVisRect = new Rect ();
332335 mWinFrame = new Rect ();
333336 mWindow = new W (this );
337+ mTargetSdkVersion = context .getApplicationInfo ().targetSdkVersion ;
334338 mInputMethodCallback = new InputMethodCallback (this );
335339 mViewVisibility = View .GONE ;
336340 mTransparentRegion = new Region ();
@@ -461,6 +465,7 @@ public void setView(View view, WindowManager.LayoutParams attrs, View panelParen
461465 mInputChannel = new InputChannel ();
462466 }
463467 try {
468+ mOrigWindowType = mWindowAttributes .type ;
464469 res = sWindowSession .add (mWindow , mWindowAttributes ,
465470 getHostVisibility (), mAttachInfo .mContentInsets ,
466471 mInputChannel );
@@ -3481,6 +3486,14 @@ private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility
34813486 }
34823487 mPendingConfiguration .seq = 0 ;
34833488 //Log.d(TAG, ">>>>>> CALLING relayout");
3489+ if (params != null && mOrigWindowType != params .type ) {
3490+ // For compatibility with old apps, don't crash here.
3491+ if (mTargetSdkVersion < android .os .Build .VERSION_CODES .ICE_CREAM_SANDWICH ) {
3492+ Slog .w (TAG , "Window type can not be changed after "
3493+ + "the window is added; ignoring change of " + mView );
3494+ params .type = mOrigWindowType ;
3495+ }
3496+ }
34843497 int relayoutResult = sWindowSession .relayout (
34853498 mWindow , params ,
34863499 (int ) (mView .getMeasuredWidth () * appScale + 0.5f ),
0 commit comments