1212import android .app .Presentation ;
1313import android .content .Context ;
1414import android .content .ContextWrapper ;
15+ import android .content .MutableContextWrapper ;
1516import android .graphics .Rect ;
1617import android .graphics .drawable .ColorDrawable ;
1718import android .os .Build ;
@@ -72,8 +73,6 @@ static class PresentationState {
7273 private FakeWindowViewGroup fakeWindowViewGroup ;
7374 }
7475
75- private final PlatformViewFactory viewFactory ;
76-
7776 // A reference to the current accessibility bridge to which accessibility events will be
7877 // delegated.
7978 private final AccessibilityEventsDelegate accessibilityEventsDelegate ;
@@ -112,19 +111,19 @@ static class PresentationState {
112111 public SingleViewPresentation (
113112 Context outerContext ,
114113 Display display ,
115- PlatformViewFactory viewFactory ,
114+ PlatformView view ,
116115 AccessibilityEventsDelegate accessibilityEventsDelegate ,
117116 int viewId ,
118117 Object createParams ,
119118 OnFocusChangeListener focusChangeListener ) {
120119 super (new ImmContext (outerContext ), display );
121- this .viewFactory = viewFactory ;
122120 this .accessibilityEventsDelegate = accessibilityEventsDelegate ;
123121 this .viewId = viewId ;
124122 this .createParams = createParams ;
125123 this .focusChangeListener = focusChangeListener ;
126124 this .outerContext = outerContext ;
127125 state = new PresentationState ();
126+ state .platformView = view ;
128127 getWindow ()
129128 .setFlags (
130129 WindowManager .LayoutParams .FLAG_NOT_FOCUSABLE ,
@@ -148,7 +147,6 @@ public SingleViewPresentation(
148147 boolean startFocused ) {
149148 super (new ImmContext (outerContext ), display );
150149 this .accessibilityEventsDelegate = accessibilityEventsDelegate ;
151- viewFactory = null ;
152150 this .state = state ;
153151 this .focusChangeListener = focusChangeListener ;
154152 this .outerContext = outerContext ;
@@ -178,14 +176,18 @@ protected void onCreate(Bundle savedInstanceState) {
178176
179177 // Our base mContext has already been wrapped with an IMM cache at instantiation time, but
180178 // we want to wrap it again here to also return state.windowManagerHandler.
181- Context context =
179+ Context baseContext =
182180 new PresentationContext (getContext (), state .windowManagerHandler , outerContext );
183181
184- if (state .platformView == null ) {
185- state .platformView = viewFactory .create (context , viewId , createParams );
182+ View embeddedView = state .platformView .getView ();
183+ if (embeddedView .getContext () instanceof MutableContextWrapper ) {
184+ MutableContextWrapper currentContext = (MutableContextWrapper ) embeddedView .getContext ();
185+ currentContext .setBaseContext (baseContext );
186+ } else {
187+ throw new IllegalStateException (
188+ "embedded view context must be a MutableContextWrapper: " + viewId );
186189 }
187190
188- View embeddedView = state .platformView .getView ();
189191 container .addView (embeddedView );
190192 rootView =
191193 new AccessibilityDelegatingFrameLayout (
0 commit comments