Ignore unchecked IME show/hide when no root
Both showSoftInputUnchecked() and closeCurrenInput() rely on rootView to
obtain window token. If view root is null, window has already gone away
and IME control had been revoked. Trying to show or hide at this time
would be a no-op.
Bug: 149900693
Test: Manually using the steps mentioned in bug and verify that there is
no NPE.
Change-Id: I294bb2ec5395d7502a855bafbac672af069e9b4a
Merged-In: I294bb2ec5395d7502a855bafbac672af069e9b4a
(cherry picked from commit ba9b716a70)
This commit is contained in:
committed by
Taran Singh
parent
81866d4149
commit
7bbce8ee6b
@@ -1634,14 +1634,20 @@ public final class InputMethodManager {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768499)
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768499)
|
||||||
public void showSoftInputUnchecked(int flags, ResultReceiver resultReceiver) {
|
public void showSoftInputUnchecked(int flags, ResultReceiver resultReceiver) {
|
||||||
try {
|
synchronized (mH) {
|
||||||
Log.w(TAG, "showSoftInputUnchecked() is a hidden method, which will be removed "
|
try {
|
||||||
+ "soon. If you are using android.support.v7.widget.SearchView, please update "
|
Log.w(TAG, "showSoftInputUnchecked() is a hidden method, which will be"
|
||||||
+ "to version 26.0 or newer version.");
|
+ " removed soon. If you are using android.support.v7.widget.SearchView,"
|
||||||
mService.showSoftInput(
|
+ " please update to version 26.0 or newer version.");
|
||||||
mClient, mCurRootView.getView().getWindowToken(), flags, resultReceiver);
|
if (mCurRootView == null || mCurRootView.getView() == null) {
|
||||||
} catch (RemoteException e) {
|
Log.w(TAG, "No current root view, ignoring showSoftInputUnchecked()");
|
||||||
throw e.rethrowFromSystemServer();
|
return;
|
||||||
|
}
|
||||||
|
mService.showSoftInput(
|
||||||
|
mClient, mCurRootView.getView().getWindowToken(), flags, resultReceiver);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw e.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1986,11 +1992,17 @@ public final class InputMethodManager {
|
|||||||
|
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
void closeCurrentInput() {
|
void closeCurrentInput() {
|
||||||
try {
|
synchronized (mH) {
|
||||||
mService.hideSoftInput(
|
if (mCurRootView == null || mCurRootView.getView() == null) {
|
||||||
mClient, mCurRootView.getView().getWindowToken(), HIDE_NOT_ALWAYS, null);
|
Log.w(TAG, "No current root view, ignoring closeCurrentInput()");
|
||||||
} catch (RemoteException e) {
|
return;
|
||||||
throw e.rethrowFromSystemServer();
|
}
|
||||||
|
try {
|
||||||
|
mService.hideSoftInput(
|
||||||
|
mClient, mCurRootView.getView().getWindowToken(), HIDE_NOT_ALWAYS, null);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw e.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user