Skip to content

Commit 135e5fb

Browse files
committed
Always accept API calls from processes which have INTERACT_ACROSS_USERS_FULL in InputMethodManagerService
Bug: 6931482 Change-Id: I1620413578b9e8da6564664219f65bdc00d5ecfd
1 parent bdac829 commit 135e5fb

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

services/java/com/android/server/InputMethodManagerService.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -900,14 +900,28 @@ private boolean calledFromValidUser() {
900900
Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? "
901901
+ "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID
902902
+ " calling userId = " + userId + ", foreground user id = "
903-
+ mSettings.getCurrentUserId());
903+
+ mSettings.getCurrentUserId() + ", calling uid = " + Binder.getCallingPid());
904904
}
905905
if (uid == Process.SYSTEM_UID || userId == mSettings.getCurrentUserId()) {
906906
return true;
907-
} else {
908-
Slog.w(TAG, "--- IPC called from background users. Ignore. \n" + getStackTrace());
909-
return false;
910907
}
908+
909+
// Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the
910+
// foreground user, not for the user of that process. Accordingly InputMethodManagerService
911+
// must not manage background users' states in any functions.
912+
// Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded
913+
// by a token.
914+
if (mContext.checkCallingOrSelfPermission(
915+
android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
916+
== PackageManager.PERMISSION_GRANTED) {
917+
if (DEBUG) {
918+
Slog.d(TAG, "--- Access granted because the calling process has "
919+
+ "the INTERACT_ACROSS_USERS_FULL permission");
920+
}
921+
return true;
922+
}
923+
Slog.w(TAG, "--- IPC called from background users. Ignore. \n" + getStackTrace());
924+
return false;
911925
}
912926

913927
private boolean bindCurrentInputMethodService(
@@ -1475,9 +1489,6 @@ public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
14751489
final CharSequence title = mRes.getText(
14761490
com.android.internal.R.string.select_input_method);
14771491
final CharSequence imiLabel = imi.loadLabel(pm);
1478-
if (DEBUG) {
1479-
Slog.d(TAG, "--- imiLabel = " + imiLabel);
1480-
}
14811492
final CharSequence summary = mCurrentSubtype != null
14821493
? TextUtils.concat(mCurrentSubtype.getDisplayName(mContext,
14831494
imi.getPackageName(), imi.getServiceInfo().applicationInfo),
@@ -1488,15 +1499,22 @@ public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
14881499
mImeSwitcherNotification.setLatestEventInfo(
14891500
mContext, title, summary, mImeSwitchPendingIntent);
14901501
if (mNotificationManager != null) {
1491-
mNotificationManager.notify(
1502+
if (DEBUG) {
1503+
Slog.d(TAG, "--- show notification: label = " + imiLabel
1504+
+ ", summary = " + summary);
1505+
}
1506+
mNotificationManager.notifyAsUser(null,
14921507
com.android.internal.R.string.select_input_method,
1493-
mImeSwitcherNotification);
1508+
mImeSwitcherNotification, UserHandle.ALL);
14941509
mNotificationShown = true;
14951510
}
14961511
} else {
14971512
if (mNotificationShown && mNotificationManager != null) {
1498-
mNotificationManager.cancel(
1499-
com.android.internal.R.string.select_input_method);
1513+
if (DEBUG) {
1514+
Slog.d(TAG, "--- hide notification");
1515+
}
1516+
mNotificationManager.cancelAsUser(null,
1517+
com.android.internal.R.string.select_input_method, UserHandle.ALL);
15001518
mNotificationShown = false;
15011519
}
15021520
}

0 commit comments

Comments
 (0)