Merge "Enable background users to call IMM#setAdditionalInputMethodSubtypes"

This commit is contained in:
Yohei Yukawa
2022-07-29 12:16:21 +00:00
committed by Android (Google) Code Review
4 changed files with 34 additions and 16 deletions

View File

@@ -192,9 +192,9 @@ final class IInputMethodManagerInvoker {
@AnyThread
void setAdditionalInputMethodSubtypes(@NonNull String imeId,
@NonNull InputMethodSubtype[] subtypes) {
@NonNull InputMethodSubtype[] subtypes, @UserIdInt int userId) {
try {
mTarget.setAdditionalInputMethodSubtypes(imeId, subtypes);
mTarget.setAdditionalInputMethodSubtypes(imeId, subtypes, userId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}

View File

@@ -3610,7 +3610,7 @@ public final class InputMethodManager {
@Deprecated
public void setAdditionalInputMethodSubtypes(@NonNull String imiId,
@NonNull InputMethodSubtype[] subtypes) {
mServiceInvoker.setAdditionalInputMethodSubtypes(imiId, subtypes);
mServiceInvoker.setAdditionalInputMethodSubtypes(imiId, subtypes, UserHandle.myUserId());
}
@Nullable

View File

@@ -92,7 +92,11 @@ interface IInputMethodManager {
+ "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
@nullable InputMethodSubtype getCurrentInputMethodSubtype(int userId);
void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
+ "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes,
int userId);
// This is kept due to @UnsupportedAppUsage.
// TODO(Bug 113914148): Consider removing this.
int getInputMethodWindowVisibleHeight(in IInputMethodClient client);

View File

@@ -4161,7 +4161,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
}
@Override
public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes,
@UserIdInt int userId) {
if (UserHandle.getCallingUserId() != userId) {
mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
}
// By this IPC call, only a process which shares the same uid with the IME can add
// additional input method subtypes to the IME.
if (TextUtils.isEmpty(imiId) || subtypes == null) return;
@@ -4175,23 +4180,32 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
}
}
synchronized (ImfLock.class) {
if (!calledFromValidUserLocked()) {
return;
}
if (!mSystemReady) {
return;
}
if (!mSettings.setAdditionalInputMethodSubtypes(imiId, toBeAdded,
mAdditionalSubtypeMap, mIPackageManager)) {
if (mSettings.getCurrentUserId() == userId) {
if (!mSettings.setAdditionalInputMethodSubtypes(imiId, toBeAdded,
mAdditionalSubtypeMap, mIPackageManager)) {
return;
}
final long ident = Binder.clearCallingIdentity();
try {
buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
} finally {
Binder.restoreCallingIdentity(ident);
}
return;
}
final long ident = Binder.clearCallingIdentity();
try {
buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
} finally {
Binder.restoreCallingIdentity(ident);
}
final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
final InputMethodSettings settings = new InputMethodSettings(mContext, methodMap,
userId, false);
final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap =
new ArrayMap<>();
AdditionalSubtypeUtils.load(additionalSubtypeMap, userId);
settings.setAdditionalInputMethodSubtypes(imiId, toBeAdded, additionalSubtypeMap,
mIPackageManager);
}
}