Support background users to call IMM#getLastInputMethodSubtype()

This is a follow up CL to my previous CL [1], which let query APIs
defined in InputMethodManager support background users.

With this CL,

  InputMethodManager#getLastInputMethodSubtype()

is also fully supported under multi-user / multi-profile environment.

 [1]: I192a0f5a1375170d17a4c08af94f23966dbaea8b
      7f8ee4b9dd

Bug: 34886274
Bug: 122164939
Test: atest CtsInputMethodTestCases:InputMethodSubtypeTest
Change-Id: I48f57dc7184e85bdb422fd9d1d56e60381654125
This commit is contained in:
Yohei Yukawa
2022-07-26 08:12:34 +09:00
parent 19e18b6c85
commit e960986554
4 changed files with 18 additions and 8 deletions

View File

@@ -101,9 +101,9 @@ final class IInputMethodManagerInvoker {
@AnyThread
@Nullable
InputMethodSubtype getLastInputMethodSubtype() {
InputMethodSubtype getLastInputMethodSubtype(@UserIdInt int userId) {
try {
return mTarget.getLastInputMethodSubtype();
return mTarget.getLastInputMethodSubtype(userId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}

View File

@@ -3517,7 +3517,7 @@ public final class InputMethodManager {
@Nullable
public InputMethodSubtype getLastInputMethodSubtype() {
return mServiceInvoker.getLastInputMethodSubtype();
return mServiceInvoker.getLastInputMethodSubtype(UserHandle.myUserId());
}
/**

View File

@@ -50,7 +50,9 @@ interface IInputMethodManager {
List<InputMethodSubtype> getEnabledInputMethodSubtypeList(in @nullable String imiId,
boolean allowsImplicitlySelectedSubtypes, int userId);
@nullable InputMethodSubtype getLastInputMethodSubtype();
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
+ "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
InputMethodSubtype getLastInputMethodSubtype(int userId);
boolean showSoftInput(in IInputMethodClient client, @nullable IBinder windowToken, int flags,
in @nullable ResultReceiver resultReceiver, int reason);

View File

@@ -4160,12 +4160,20 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
}
@Override
public InputMethodSubtype getLastInputMethodSubtype() {
public InputMethodSubtype getLastInputMethodSubtype(@UserIdInt int userId) {
if (UserHandle.getCallingUserId() != userId) {
mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
}
synchronized (ImfLock.class) {
if (!calledFromValidUserLocked()) {
return null;
if (mSettings.getCurrentUserId() == userId) {
return mSettings.getLastInputMethodSubtypeLocked();
}
return mSettings.getLastInputMethodSubtypeLocked();
final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
final InputMethodSettings settings = new InputMethodSettings(
mContext.getResources(), mContext.getContentResolver(), methodMap,
userId, false);
return settings.getLastInputMethodSubtypeLocked();
}
}