Merge "Remove IME surface when hidden" into rvc-dev

This commit is contained in:
Taran Singh
2020-02-27 00:53:09 +00:00
committed by Android (Google) Code Review
9 changed files with 83 additions and 7 deletions

View File

@@ -53,6 +53,7 @@ class IInputMethodSessionWrapper extends IInputMethodSession.Stub
private static final int DO_FINISH_SESSION = 110;
private static final int DO_VIEW_CLICKED = 115;
private static final int DO_NOTIFY_IME_HIDDEN = 120;
private static final int DO_REMOVE_IME_SURFACE = 130;
@UnsupportedAppUsage
HandlerCaller mCaller;
@@ -136,6 +137,10 @@ class IInputMethodSessionWrapper extends IInputMethodSession.Stub
mInputMethodSession.notifyImeHidden();
return;
}
case DO_REMOVE_IME_SURFACE: {
mInputMethodSession.removeImeSurface();
return;
}
}
Log.w(TAG, "Unhandled message code: " + msg.what);
}
@@ -183,6 +188,11 @@ class IInputMethodSessionWrapper extends IInputMethodSession.Stub
mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_NOTIFY_IME_HIDDEN));
}
@Override
public void removeImeSurface() {
mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_REMOVE_IME_SURFACE));
}
@Override
public void updateCursor(Rect newCursor) {
mCaller.executeOrSendMessage(

View File

@@ -814,6 +814,13 @@ public class InputMethodService extends AbstractInputMethodService {
onPreRenderedWindowVisibilityChanged(false /* setVisible */);
}
private void removeImeSurface() {
if (!mShowInputRequested && !mWindowVisible) {
// hiding a window removes its surface.
mWindow.hide();
}
}
private void setImeWindowStatus(int visibilityFlags, int backDisposition) {
mPrivOps.setImeWindowStatus(visibilityFlags, backDisposition);
}
@@ -932,6 +939,14 @@ public class InputMethodService extends AbstractInputMethodService {
public final void notifyImeHidden() {
InputMethodService.this.notifyImeHidden();
}
/**
* Notify IME that surface can be now removed.
* @hide
*/
public final void removeImeSurface() {
InputMethodService.this.removeImeSurface();
}
}
/**

View File

@@ -296,6 +296,12 @@ final class MultiClientInputMethodClientCallbackAdaptor {
// no-op for multi-session since IME is responsible controlling navigation bar buttons.
reportNotSupported();
}
@Override
public void removeImeSurface() {
// no-op for multi-session
reportNotSupported();
}
}
private static final class MultiClientInputMethodSessionImpl

View File

@@ -17,7 +17,6 @@
package android.view;
import static android.view.InsetsState.ITYPE_IME;
import static android.view.InsetsState.toPublicType;
import android.annotation.Nullable;
import android.inputmethodservice.InputMethodService;
@@ -99,6 +98,15 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
}
}
@Override
void hide(boolean animationFinished) {
super.hide();
if (animationFinished) {
// remove IME surface as IME has finished hide animation.
removeSurface();
}
}
/**
* Request {@link InputMethodManager} to show the IME.
* @return @see {@link android.view.InsetsSourceConsumer.ShowResult}.
@@ -127,6 +135,11 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
getImm().notifyImeHidden();
}
@Override
public void removeSurface() {
getImm().removeImeSurface();
}
@Override
public void setControl(@Nullable InsetsSourceControl control, int[] showTypes,
int[] hideTypes) {

View File

@@ -694,7 +694,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
if (shown) {
showDirectly(controller.getTypes());
} else {
hideDirectly(controller.getTypes());
hideDirectly(controller.getTypes(), true /* animationFinished */);
}
}
@@ -852,10 +852,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
: LAYOUT_INSETS_DURING_ANIMATION_HIDDEN);
}
private void hideDirectly(@InsetsType int types) {
private void hideDirectly(@InsetsType int types, boolean animationFinished) {
final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types);
for (int i = internalTypes.size() - 1; i >= 0; i--) {
getSourceConsumer(internalTypes.valueAt(i)).hide();
getSourceConsumer(internalTypes.valueAt(i)).hide(animationFinished);
}
}
@@ -887,7 +887,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
if (layoutDuringAnimation == LAYOUT_INSETS_DURING_ANIMATION_SHOWN) {
showDirectly(types);
} else {
hideDirectly(types);
hideDirectly(types, false /* animationFinished */);
}
if (mViewRoot.mView == null) {
return;

View File

@@ -16,12 +16,10 @@
package android.view;
import static android.view.InsetsController.ANIMATION_TYPE_NONE;
import static android.view.InsetsState.toPublicType;
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.util.MutableShort;
import android.view.InsetsState.InternalInsetsType;
import android.view.SurfaceControl.Transaction;
import android.view.WindowInsets.Type.InsetsType;
@@ -137,6 +135,10 @@ public class InsetsSourceConsumer {
setRequestedVisible(false);
}
void hide(boolean animationFinished) {
hide();
}
/**
* Called when current window gains focus
*/
@@ -200,6 +202,13 @@ public class InsetsSourceConsumer {
// no-op for types that always return ShowResult#SHOW_IMMEDIATELY.
}
/**
* Remove surface on which this consumer type is drawn.
*/
public void removeSurface() {
// no-op for types that always return ShowResult#SHOW_IMMEDIATELY.
}
/**
* Sets requested visibility from the client, regardless of whether we are able to control it at
* the moment.

View File

@@ -2055,6 +2055,21 @@ public final class InputMethodManager {
}
}
/**
* Notify IME directly to remove surface as it is no longer visible.
* @hide
*/
public void removeImeSurface() {
synchronized (mH) {
try {
if (mCurMethod != null) {
mCurMethod.removeImeSurface();
}
} catch (RemoteException re) {
}
}
}
/**
* Report the current selection range.
*

View File

@@ -191,4 +191,10 @@ public interface InputMethodSession {
* @hide
*/
public void notifyImeHidden();
/**
* Notify IME directly to remove surface as it is no longer visible.
* @hide
*/
public void removeImeSurface();
}

View File

@@ -50,4 +50,6 @@ oneway interface IInputMethodSession {
void updateCursorAnchorInfo(in CursorAnchorInfo cursorAnchorInfo);
void notifyImeHidden();
void removeImeSurface();
}