Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b806e156 authored by Taran Singh's avatar Taran Singh Committed by Android (Google) Code Review
Browse files

Merge "Make isStylusHwAvailable() user-aware"

parents a5f34dad 96407efd
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -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) {
            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();
        }
+1 −1
Original line number Diff line number Diff line
@@ -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);
}
+17 −2
Original line number Diff line number Diff line
@@ -2108,10 +2108,25 @@ 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) {
            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();
        }
    }

    @GuardedBy("ImfLock.class")