Make isStylusHwAvailable() user-aware
IMM#isStylusHandwritingAvailable() should return result for current user. Also introduce internal API method isStylusHandwritingAvailable(int userId) to query for other users when TextView#setTextOperationUser() uses a non-current user. Bug: 236318991 Bug: 237439688 Bug: 237418160 Test: atest StylusHandwritingTest Change-Id: Ie5681eba3b0f1757f90377bddce9f731d4c32097
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user