Improve API annotation for InputMethodManager

Annotate null-ness for APIs and parameter for
InputMethodManager, IInputMethodManagerInvoker
and IInputMethodManager.aidl.

This is a annotation improvement without any user
visible changes.

Bug: 237959367
Test: presubmit
Change-Id: I426fb9ca9009f0f91a4d2d6a39094ea9c20671f7
This commit is contained in:
Wilson Wu
2022-07-05 14:20:50 +08:00
parent cb7d9ca548
commit 956374833a
4 changed files with 73 additions and 49 deletions

View File

@@ -53240,11 +53240,11 @@ package android.view.inputmethod {
public final class InputMethodManager {
method public void dispatchKeyEventFromInputMethod(@Nullable android.view.View, @NonNull android.view.KeyEvent);
method public void displayCompletions(android.view.View, android.view.inputmethod.CompletionInfo[]);
method public android.view.inputmethod.InputMethodSubtype getCurrentInputMethodSubtype();
method public java.util.List<android.view.inputmethod.InputMethodInfo> getEnabledInputMethodList();
method public java.util.List<android.view.inputmethod.InputMethodSubtype> getEnabledInputMethodSubtypeList(android.view.inputmethod.InputMethodInfo, boolean);
method public java.util.List<android.view.inputmethod.InputMethodInfo> getInputMethodList();
method public android.view.inputmethod.InputMethodSubtype getLastInputMethodSubtype();
method @Nullable public android.view.inputmethod.InputMethodSubtype getCurrentInputMethodSubtype();
method @NonNull public java.util.List<android.view.inputmethod.InputMethodInfo> getEnabledInputMethodList();
method @NonNull public java.util.List<android.view.inputmethod.InputMethodSubtype> getEnabledInputMethodSubtypeList(@Nullable android.view.inputmethod.InputMethodInfo, boolean);
method @NonNull public java.util.List<android.view.inputmethod.InputMethodInfo> getInputMethodList();
method @Nullable public android.view.inputmethod.InputMethodSubtype getLastInputMethodSubtype();
method public java.util.Map<android.view.inputmethod.InputMethodInfo,java.util.List<android.view.inputmethod.InputMethodSubtype>> getShortcutInputMethodsAndSubtypes();
method @Deprecated public void hideSoftInputFromInputMethod(android.os.IBinder, int);
method public boolean hideSoftInputFromWindow(android.os.IBinder, int);
@@ -53260,12 +53260,12 @@ package android.view.inputmethod {
method @Deprecated public boolean isWatchingCursor(android.view.View);
method public void restartInput(android.view.View);
method public void sendAppPrivateCommand(android.view.View, String, android.os.Bundle);
method @Deprecated public void setAdditionalInputMethodSubtypes(String, android.view.inputmethod.InputMethodSubtype[]);
method @Deprecated public void setAdditionalInputMethodSubtypes(@NonNull String, @NonNull android.view.inputmethod.InputMethodSubtype[]);
method @Deprecated @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean setCurrentInputMethodSubtype(android.view.inputmethod.InputMethodSubtype);
method @Deprecated public void setInputMethod(android.os.IBinder, String);
method @Deprecated public void setInputMethodAndSubtype(@NonNull android.os.IBinder, String, android.view.inputmethod.InputMethodSubtype);
method @Deprecated public boolean shouldOfferSwitchingToNextInputMethod(android.os.IBinder);
method public void showInputMethodAndSubtypeEnabler(String);
method public void showInputMethodAndSubtypeEnabler(@Nullable String);
method public void showInputMethodPicker();
method public boolean showSoftInput(android.view.View, int);
method public boolean showSoftInput(android.view.View, int, android.os.ResultReceiver);

View File

@@ -18,10 +18,13 @@ package android.view.inputmethod;
import android.annotation.AnyThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import android.window.ImeOnBackInvokedDispatcher;
import com.android.internal.inputmethod.DirectBootAwareness;
@@ -54,8 +57,8 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
void addClient(IInputMethodClient client, IRemoteInputConnection fallbackInputConnection,
int untrustedDisplayId) {
void addClient(@NonNull IInputMethodClient client,
@NonNull IRemoteInputConnection fallbackInputConnection, int untrustedDisplayId) {
try {
mTarget.addClient(client, fallbackInputConnection, untrustedDisplayId);
} catch (RemoteException e) {
@@ -64,6 +67,7 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
@NonNull
List<InputMethodInfo> getInputMethodList(@UserIdInt int userId) {
try {
return mTarget.getInputMethodList(userId);
@@ -73,6 +77,7 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
@NonNull
List<InputMethodInfo> getAwareLockedInputMethodList(@UserIdInt int userId,
@DirectBootAwareness int directBootAwareness) {
try {
@@ -83,6 +88,7 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
@NonNull
List<InputMethodInfo> getEnabledInputMethodList(@UserIdInt int userId) {
try {
return mTarget.getEnabledInputMethodList(userId);
@@ -92,7 +98,8 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId,
@NonNull
List<InputMethodSubtype> getEnabledInputMethodSubtypeList(@Nullable String imiId,
boolean allowsImplicitlySelectedSubtypes) {
try {
return mTarget.getEnabledInputMethodSubtypeList(imiId,
@@ -103,6 +110,7 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
@Nullable
InputMethodSubtype getLastInputMethodSubtype() {
try {
return mTarget.getLastInputMethodSubtype();
@@ -112,8 +120,9 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
boolean showSoftInput(IInputMethodClient client, IBinder windowToken,
int flags, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason) {
boolean showSoftInput(@NonNull IInputMethodClient client, @Nullable IBinder windowToken,
int flags, @Nullable ResultReceiver resultReceiver,
@SoftInputShowHideReason int reason) {
try {
return mTarget.showSoftInput(client, windowToken, flags, resultReceiver, reason);
} catch (RemoteException e) {
@@ -122,8 +131,9 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
boolean hideSoftInput(IInputMethodClient client, IBinder windowToken,
int flags, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason) {
boolean hideSoftInput(@NonNull IInputMethodClient client, @Nullable IBinder windowToken,
int flags, @Nullable ResultReceiver resultReceiver,
@SoftInputShowHideReason int reason) {
try {
return mTarget.hideSoftInput(client, windowToken, flags, resultReceiver, reason);
} catch (RemoteException e) {
@@ -132,13 +142,14 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
@NonNull
InputBindResult startInputOrWindowGainedFocus(@StartInputReason int startInputReason,
IInputMethodClient client, IBinder windowToken,
@StartInputFlags int startInputFlags,
@android.view.WindowManager.LayoutParams.SoftInputModeFlags int softInputMode,
int windowFlags, EditorInfo editorInfo, IRemoteInputConnection remoteInputConnection,
IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
int unverifiedTargetSdkVersion, ImeOnBackInvokedDispatcher imeDispatcher) {
@NonNull IInputMethodClient client, @Nullable IBinder windowToken,
@StartInputFlags int startInputFlags, @SoftInputModeFlags int softInputMode,
@WindowManager.LayoutParams.Flags int windowFlags, @Nullable EditorInfo editorInfo,
@Nullable IRemoteInputConnection remoteInputConnection,
@Nullable IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
int unverifiedTargetSdkVersion, @NonNull ImeOnBackInvokedDispatcher imeDispatcher) {
try {
return mTarget.startInputOrWindowGainedFocus(startInputReason, client, windowToken,
startInputFlags, softInputMode, windowFlags, editorInfo, remoteInputConnection,
@@ -149,7 +160,8 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
void showInputMethodPickerFromClient(IInputMethodClient client, int auxiliarySubtypeMode) {
void showInputMethodPickerFromClient(@NonNull IInputMethodClient client,
int auxiliarySubtypeMode) {
try {
mTarget.showInputMethodPickerFromClient(client, auxiliarySubtypeMode);
} catch (RemoteException e) {
@@ -158,8 +170,8 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
void showInputMethodPickerFromSystem(IInputMethodClient client, int auxiliarySubtypeMode,
int displayId) {
void showInputMethodPickerFromSystem(@NonNull IInputMethodClient client,
int auxiliarySubtypeMode, int displayId) {
try {
mTarget.showInputMethodPickerFromSystem(client, auxiliarySubtypeMode, displayId);
} catch (RemoteException e) {
@@ -168,7 +180,8 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
void showInputMethodAndSubtypeEnablerFromClient(IInputMethodClient client, String imeId) {
void showInputMethodAndSubtypeEnablerFromClient(@NonNull IInputMethodClient client,
@Nullable String imeId) {
try {
mTarget.showInputMethodAndSubtypeEnablerFromClient(client, imeId);
} catch (RemoteException e) {
@@ -186,6 +199,7 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
@Nullable
InputMethodSubtype getCurrentInputMethodSubtype() {
try {
return mTarget.getCurrentInputMethodSubtype();
@@ -195,7 +209,8 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
void setAdditionalInputMethodSubtypes(String imeId, InputMethodSubtype[] subtypes) {
void setAdditionalInputMethodSubtypes(@NonNull String imeId,
@NonNull InputMethodSubtype[] subtypes) {
try {
mTarget.setAdditionalInputMethodSubtypes(imeId, subtypes);
} catch (RemoteException e) {
@@ -204,7 +219,7 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
int getInputMethodWindowVisibleHeight(IInputMethodClient client) {
int getInputMethodWindowVisibleHeight(@NonNull IInputMethodClient client) {
try {
return mTarget.getInputMethodWindowVisibleHeight(client);
} catch (RemoteException e) {
@@ -213,8 +228,8 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
void reportVirtualDisplayGeometryAsync(IInputMethodClient client, int childDisplayId,
float[] matrixValues) {
void reportVirtualDisplayGeometryAsync(@NonNull IInputMethodClient client, int childDisplayId,
@Nullable float[] matrixValues) {
try {
mTarget.reportVirtualDisplayGeometryAsync(client, childDisplayId, matrixValues);
} catch (RemoteException e) {
@@ -223,7 +238,7 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
void reportPerceptibleAsync(IBinder windowToken, boolean perceptible) {
void reportPerceptibleAsync(@NonNull IBinder windowToken, boolean perceptible) {
try {
mTarget.reportPerceptibleAsync(windowToken, perceptible);
} catch (RemoteException e) {
@@ -232,7 +247,7 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
void removeImeSurfaceFromWindowAsync(IBinder windowToken) {
void removeImeSurfaceFromWindowAsync(@NonNull IBinder windowToken) {
try {
mTarget.removeImeSurfaceFromWindowAsync(windowToken);
} catch (RemoteException e) {
@@ -241,7 +256,7 @@ final class IInputMethodManagerInvoker {
}
@AnyThread
void startStylusHandwriting(IInputMethodClient client) {
void startStylusHandwriting(@NonNull IInputMethodClient client) {
try {
mTarget.startStylusHandwriting(client);
} catch (RemoteException e) {

View File

@@ -637,7 +637,7 @@ public final class InputMethodManager {
* {@link android.view.WindowInsetsController}.
* @hide
*/
public void reportPerceptible(IBinder windowToken, boolean perceptible) {
public void reportPerceptible(@NonNull IBinder windowToken, boolean perceptible) {
mServiceInvoker.reportPerceptibleAsync(windowToken, perceptible);
}
@@ -1396,6 +1396,7 @@ public final class InputMethodManager {
*
* @return {@link List} of {@link InputMethodInfo}.
*/
@NonNull
public List<InputMethodInfo> getInputMethodList() {
// We intentionally do not use UserHandle.getCallingUserId() here because for system
// services InputMethodManagerInternal.getInputMethodListAsUser() should be used
@@ -1474,6 +1475,7 @@ public final class InputMethodManager {
*
* @return {@link List} of {@link InputMethodInfo}.
*/
@NonNull
public List<InputMethodInfo> getEnabledInputMethodList() {
// We intentionally do not use UserHandle.getCallingUserId() here because for system
// services InputMethodManagerInternal.getEnabledInputMethodListAsUser() should be used
@@ -1498,12 +1500,14 @@ public final class InputMethodManager {
*
* <p>On multi user environment, this API returns a result for the calling process user.</p>
*
* @param imi An input method info whose subtypes list will be returned.
* @param imi The {@link InputMethodInfo} whose subtypes list will be returned. If {@code null},
* returns enabled subtypes for the currently selected {@link InputMethodInfo}.
* @param allowsImplicitlySelectedSubtypes A boolean flag to allow to return the implicitly
* selected subtypes. If an input method info doesn't have enabled subtypes, the framework
* will implicitly enable subtypes according to the current system language.
*/
public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(InputMethodInfo imi,
@NonNull
public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(@Nullable InputMethodInfo imi,
boolean allowsImplicitlySelectedSubtypes) {
return mServiceInvoker.getEnabledInputMethodSubtypeList(
imi == null ? null : imi.getId(),
@@ -2606,7 +2610,7 @@ public final class InputMethodManager {
* @param windowToken The client window token that requests the IME to remove its surface.
* @hide
*/
public void removeImeSurface(IBinder windowToken) {
public void removeImeSurface(@NonNull IBinder windowToken) {
synchronized (mH) {
mServiceInvoker.removeImeSurfaceFromWindowAsync(windowToken);
}
@@ -3238,7 +3242,7 @@ public final class InputMethodManager {
* @param imiId An input method, whose subtypes settings will be shown. If imiId is null,
* subtypes of all input methods will be shown.
*/
public void showInputMethodAndSubtypeEnabler(String imiId) {
public void showInputMethodAndSubtypeEnabler(@Nullable String imiId) {
mServiceInvoker.showInputMethodAndSubtypeEnablerFromClient(mClient, imiId);
}
@@ -3247,6 +3251,7 @@ public final class InputMethodManager {
* the current input method. This method returns null when the current input method doesn't
* have any input method subtype.
*/
@Nullable
public InputMethodSubtype getCurrentInputMethodSubtype() {
return mServiceInvoker.getCurrentInputMethodSubtype();
}
@@ -3481,10 +3486,12 @@ public final class InputMethodManager {
* of "Additional Subtype" may be completely dropped in a future version of Android.
*/
@Deprecated
public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
public void setAdditionalInputMethodSubtypes(@NonNull String imiId,
@NonNull InputMethodSubtype[] subtypes) {
mServiceInvoker.setAdditionalInputMethodSubtypes(imiId, subtypes);
}
@Nullable
public InputMethodSubtype getLastInputMethodSubtype() {
return mServiceInvoker.getLastInputMethodSubtype();
}

View File

@@ -49,14 +49,14 @@ interface IInputMethodManager {
+ "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
List<InputMethodInfo> getEnabledInputMethodList(int userId);
List<InputMethodSubtype> getEnabledInputMethodSubtypeList(in String imiId,
List<InputMethodSubtype> getEnabledInputMethodSubtypeList(in @nullable String imiId,
boolean allowsImplicitlySelectedSubtypes);
InputMethodSubtype getLastInputMethodSubtype();
@nullable InputMethodSubtype getLastInputMethodSubtype();
boolean showSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
in ResultReceiver resultReceiver, int reason);
boolean hideSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
in ResultReceiver resultReceiver, int reason);
boolean showSoftInput(in IInputMethodClient client, @nullable IBinder windowToken, int flags,
in @nullable ResultReceiver resultReceiver, int reason);
boolean hideSoftInput(in IInputMethodClient client, @nullable IBinder windowToken, int flags,
in @nullable ResultReceiver resultReceiver, int reason);
// If windowToken is null, this just does startInput(). Otherwise this reports that a window
// has gained focus, and if 'editorInfo' is non-null then also does startInput.
@@ -65,11 +65,12 @@ interface IInputMethodManager {
+ "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
InputBindResult startInputOrWindowGainedFocus(
/* @StartInputReason */ int startInputReason,
in IInputMethodClient client, in IBinder windowToken,
in IInputMethodClient client, in @nullable IBinder windowToken,
/* @StartInputFlags */ int startInputFlags,
/* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode,
int windowFlags, in EditorInfo editorInfo, in IRemoteInputConnection inputConnection,
in IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
/* @android.view.WindowManager.LayoutParams.Flags */ int windowFlags,
in @nullable EditorInfo editorInfo, in @nullable IRemoteInputConnection inputConnection,
in @nullable IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
int unverifiedTargetSdkVersion, in ImeOnBackInvokedDispatcher imeDispatcher);
void showInputMethodPickerFromClient(in IInputMethodClient client,
@@ -80,20 +81,21 @@ interface IInputMethodManager {
void showInputMethodPickerFromSystem(in IInputMethodClient client,
int auxiliarySubtypeMode, int displayId);
void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client, String topId);
void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client,
@nullable String topId);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
+ "android.Manifest.permission.TEST_INPUT_METHOD)")
boolean isInputMethodPickerShownForTest();
InputMethodSubtype getCurrentInputMethodSubtype();
@nullable InputMethodSubtype getCurrentInputMethodSubtype();
void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
// This is kept due to @UnsupportedAppUsage.
// TODO(Bug 113914148): Consider removing this.
int getInputMethodWindowVisibleHeight(in IInputMethodClient client);
oneway void reportVirtualDisplayGeometryAsync(in IInputMethodClient parentClient,
int childDisplayId, in float[] matrixValues);
int childDisplayId, in @nullable float[] matrixValues);
oneway void reportPerceptibleAsync(in IBinder windowToken, boolean perceptible);