Set InputMethoMananger#mCurRootView to null when window dismissed
InputMethodManager#sInstance is a long live static object so we have to set its field with right value, otherwise any object referenced by it cannot be gc including potential activity context. Now InputMethodManager#mCurRootView is set to null in InputMethodManager#onPreWindowFocus which is invoked when app's ViewRootImpl received ViewRootImpl#W#windowfocusChanged from WMS. However, in the ViewRootImpl#W#windowfocusChanged, mViewAncestor is a weak reference which get() may returns null sometimes. One scenario is the ViewRootImpl#W#windowfocusChanged is called after ActivityThread#handleDestroyActivity. The activity is destroyed and its ViewRootImpl get GC'd. Then InputMethodManager#onPreWindowFocus won't get called and InputMethodManager#mCurRootView won't be set to null. And it is a proper time to set InputMethodManager#mCurRootView to null when the window it served dismissed. Fix: 116078227 Test: Break at ActivityThread#handleDestroyActivity and ViewRootImpl#W#windowfocusChanged Change-Id: I8fabb30f14bcb2cd7019e29b6642b4562d49d248 Signed-off-by: daqi <daqi@xiaomi.com>
This commit is contained in:
@@ -1420,6 +1420,10 @@ public final class InputMethodManager {
|
||||
mServedView.getWindowToken() == appWindowToken) {
|
||||
finishInputLocked();
|
||||
}
|
||||
if (mCurRootView != null &&
|
||||
mCurRootView.getWindowToken() == appWindowToken) {
|
||||
mCurRootView = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user