summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/view/inputmethod/InputMethodManager.java19
-rw-r--r--core/java/com/android/internal/view/IInputMethodManager.aidl2
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodManagerService.java19
3 files changed, 35 insertions, 5 deletions
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index b8ed05f73f46..a9fe34a9c0ff 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -1427,17 +1427,32 @@ public final class InputMethodManager {
* @see #startStylusHandwriting(View)
*/
public boolean isStylusHandwritingAvailable() {
+ return isStylusHandwritingAvailableAsUser(UserHandle.myUserId());
+ }
+
+ /**
+ * Returns {@code true} if currently selected IME supports Stylus handwriting & is enabled for
+ * the given userId.
+ * If the method returns {@code false}, {@link #startStylusHandwriting(View)} shouldn't be
+ * called and Stylus touch should continue as normal touch input.
+ * @see #startStylusHandwriting(View)
+ * @param userId user ID to query.
+ * @hide
+ */
+ public boolean isStylusHandwritingAvailableAsUser(@UserIdInt int userId) {
final Context fallbackContext = ActivityThread.currentApplication();
if (fallbackContext == null) {
return false;
}
if (Settings.Global.getInt(fallbackContext.getContentResolver(),
Settings.Global.STYLUS_HANDWRITING_ENABLED, 0) == 0) {
- Log.d(TAG, "Stylus handwriting is not enabled in settings.");
+ if (DEBUG) {
+ Log.d(TAG, "Stylus handwriting is not enabled in settings.");
+ }
return false;
}
try {
- return mService.isStylusHandwritingAvailable();
+ return mService.isStylusHandwritingAvailableAsUser(userId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl
index 508e4450d0f9..d550fef968a8 100644
--- a/core/java/com/android/internal/view/IInputMethodManager.aidl
+++ b/core/java/com/android/internal/view/IInputMethodManager.aidl
@@ -91,5 +91,5 @@ interface IInputMethodManager {
/** Start Stylus handwriting session **/
void startStylusHandwriting(in IInputMethodClient client);
/** Returns {@code true} if currently selected IME supports Stylus handwriting. */
- boolean isStylusHandwritingAvailable();
+ boolean isStylusHandwritingAvailableAsUser(int userId);
}
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 3fceba77567b..b45dc7ff0f6b 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -2108,9 +2108,24 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
}
@Override
- public boolean isStylusHandwritingAvailable() {
+ public boolean isStylusHandwritingAvailableAsUser(@UserIdInt int userId) {
+ if (UserHandle.getCallingUserId() != userId) {
+ mContext.enforceCallingPermission(
+ Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
+ }
+
synchronized (ImfLock.class) {
- return mBindingController.supportsStylusHandwriting();
+ if (userId == mSettings.getCurrentUserId()) {
+ return mBindingController.supportsStylusHandwriting();
+ }
+
+ //TODO(b/197848765): This can be optimized by caching multi-user methodMaps/methodList.
+ //TODO(b/210039666): use cache.
+ final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
+ final InputMethodSettings settings = new InputMethodSettings(mContext.getResources(),
+ mContext.getContentResolver(), methodMap, userId, true);
+ final InputMethodInfo imi = methodMap.get(settings.getSelectedInputMethod());
+ return imi != null && imi.supportsStylusHandwriting();
}
}