Merge "Make isStylusHwAvailable() user-aware"

This commit is contained in:
Taran Singh
2022-06-29 21:35:25 +00:00
committed by Android (Google) Code Review
3 changed files with 35 additions and 5 deletions

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -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();
}
}