Merge "Support background users to call IMM#getLastInputMethodSubtype()"

This commit is contained in:
TreeHugger Robot
2022-07-26 09:27:33 +00:00
committed by Android (Google) Code Review
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();
}
}