diff options
| author | 2022-10-14 07:41:53 -0700 | |
|---|---|---|
| committer | 2022-10-14 07:41:53 -0700 | |
| commit | 1a7fc5b62bad86c3d582f6baf1c963dedbd402a9 (patch) | |
| tree | 0bfddac80fc5c9da22cd14b424c44fff62d4b1be | |
| parent | 7f0c721fc714d12bb9f302ae039c35aac37dfa99 (diff) | |
Decouple DisplayImeController and IInputMethodManager
This CL removes the direct dependency on IInputMethodManager from
DisplayImeController by using IInputMethodManagerGlobal, which was
introduced recently [1].
This is mechanical refactoring. There must be no observable behavior
change.
[1]: I5412eb1d44e3d515ca955f00a2e777b659a15b14
Fix: 192610976
Test: presubmit
Test: atest DisplayImeControllerTest
Change-Id: I9de401ad0a1051790d95fcfc8d2552a656281273
3 files changed, 22 insertions, 25 deletions
diff --git a/core/java/com/android/internal/inputmethod/IInputMethodManagerGlobal.java b/core/java/com/android/internal/inputmethod/IInputMethodManagerGlobal.java index f0fe573d20e0..5392bdcec5ee 100644 --- a/core/java/com/android/internal/inputmethod/IInputMethodManagerGlobal.java +++ b/core/java/com/android/internal/inputmethod/IInputMethodManagerGlobal.java @@ -155,4 +155,21 @@ public final class IInputMethodManagerGlobal { throw e.rethrowFromSystemServer(); } } + + /** + * Invokes {@link IInputMethodManager#removeImeSurface()} + */ + @RequiresPermission(android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) + @AnyThread + public static void removeImeSurface(@Nullable Consumer<RemoteException> exceptionHandler) { + final IInputMethodManager service = getService(); + if (service == null) { + return; + } + try { + service.removeImeSurface(); + } catch (RemoteException e) { + handleRemoteExceptionOrRethrow(e, exceptionHandler); + } + } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java index 266cf294a950..66202ad1cbfd 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java @@ -21,12 +21,10 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.annotation.IntDef; import android.content.ComponentName; -import android.content.Context; import android.content.res.Configuration; import android.graphics.Point; import android.graphics.Rect; import android.os.RemoteException; -import android.os.ServiceManager; import android.util.Slog; import android.util.SparseArray; import android.view.IDisplayWindowInsetsController; @@ -43,7 +41,7 @@ import android.view.animation.PathInterpolator; import androidx.annotation.VisibleForTesting; -import com.android.internal.view.IInputMethodManager; +import com.android.internal.inputmethod.IInputMethodManagerGlobal; import com.android.wm.shell.sysui.ShellInit; import java.util.ArrayList; @@ -514,16 +512,10 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged } void removeImeSurface() { - final IInputMethodManager imms = getImms(); - if (imms != null) { - try { - // Remove the IME surface to make the insets invisible for - // non-client controlled insets. - imms.removeImeSurface(); - } catch (RemoteException e) { - Slog.e(TAG, "Failed to remove IME surface.", e); - } - } + // Remove the IME surface to make the insets invisible for + // non-client controlled insets. + IInputMethodManagerGlobal.removeImeSurface( + e -> Slog.e(TAG, "Failed to remove IME surface.", e)); } /** @@ -597,11 +589,6 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged } } - public IInputMethodManager getImms() { - return IInputMethodManager.Stub.asInterface( - ServiceManager.getService(Context.INPUT_METHOD_SERVICE)); - } - private static boolean haveSameLeash(InsetsSourceControl a, InsetsSourceControl b) { if (a == b) { return true; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java index 9967e5f47752..a6f19e7d11d3 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java @@ -39,7 +39,6 @@ import android.view.SurfaceControl; import androidx.test.filters.SmallTest; -import com.android.internal.view.IInputMethodManager; import com.android.wm.shell.ShellTestCase; import com.android.wm.shell.sysui.ShellInit; @@ -56,8 +55,6 @@ public class DisplayImeControllerTest extends ShellTestCase { @Mock private SurfaceControl.Transaction mT; @Mock - private IInputMethodManager mMock; - @Mock private ShellInit mShellInit; private DisplayImeController.PerDisplay mPerDisplay; private Executor mExecutor; @@ -77,10 +74,6 @@ public class DisplayImeControllerTest extends ShellTestCase { } }, mExecutor) { @Override - public IInputMethodManager getImms() { - return mMock; - } - @Override void removeImeSurface() { } }.new PerDisplay(DEFAULT_DISPLAY, ROTATION_0); } |