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

Commit 15665492 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Change API to return KeyboardLayout[] to reduce IPC calls

Instead of using String[] to provide available layouts and
Settings calling getKeyboardLayout(desc) on each string, return
all KeyboardLayouts as an array to reduce IPC calls.

Also allowing null ime subtype. This can happen for certain IMEs
that dont have a valid subtype.

Test: manual
Bug: 259530132
Change-Id: I76e5c0b1b98062e917fc8a083c2db16f9b130a58
parent ee1e8fe7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -120,8 +120,8 @@ interface IInputManager {
            in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype,
            String keyboardLayoutDescriptor);

    String[] getKeyboardLayoutListForInputDevice(in InputDeviceIdentifier identifier, int userId,
            in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype);
    KeyboardLayout[] getKeyboardLayoutListForInputDevice(in InputDeviceIdentifier identifier,
            int userId, in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype);

    // Modifier key remapping APIs.
    @EnforcePermission("REMAP_MODIFIER_KEYS")
+6 −6
Original line number Diff line number Diff line
@@ -986,7 +986,7 @@ public final class InputManager {
    @Nullable
    public String getKeyboardLayoutForInputDevice(@NonNull InputDeviceIdentifier identifier,
            @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
            @NonNull InputMethodSubtype imeSubtype) {
            @Nullable InputMethodSubtype imeSubtype) {
        try {
            return mIm.getKeyboardLayoutForInputDevice(identifier, userId, imeInfo, imeSubtype);
        } catch (RemoteException ex) {
@@ -1014,7 +1014,7 @@ public final class InputManager {
    @RequiresPermission(Manifest.permission.SET_KEYBOARD_LAYOUT)
    public void setKeyboardLayoutForInputDevice(@NonNull InputDeviceIdentifier identifier,
            @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
            @NonNull InputMethodSubtype imeSubtype, @NonNull String keyboardLayoutDescriptor) {
            @Nullable InputMethodSubtype imeSubtype, @NonNull String keyboardLayoutDescriptor) {
        if (identifier == null) {
            throw new IllegalArgumentException("identifier must not be null");
        }
@@ -1031,8 +1031,8 @@ public final class InputManager {
    }

    /**
     * Gets all keyboard layout descriptors that are enabled for the specified input device, userId,
     * imeInfo and imeSubtype.
     * Gets all keyboard layouts that are enabled for the specified input device, userId, imeInfo
     * and imeSubtype.
     *
     * @param identifier The identifier for the input device.
     * @param userId user profile ID
@@ -1042,9 +1042,9 @@ public final class InputManager {
     *
     * @hide
     */
    public String[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
    public KeyboardLayout[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
            @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
            @NonNull InputMethodSubtype imeSubtype) {
            @Nullable InputMethodSubtype imeSubtype) {
        if (identifier == null) {
            throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
        }
+4 −4
Original line number Diff line number Diff line
@@ -1193,7 +1193,7 @@ public class InputManagerService extends IInputManager.Stub
    @Override // Binder call
    public String getKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
            @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
            @NonNull InputMethodSubtype imeSubtype) {
            @Nullable InputMethodSubtype imeSubtype) {
        return mKeyboardLayoutManager.getKeyboardLayoutForInputDevice(identifier, userId,
                imeInfo, imeSubtype);
    }
@@ -1202,16 +1202,16 @@ public class InputManagerService extends IInputManager.Stub
    @Override // Binder call
    public void setKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
            @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
            @NonNull InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor) {
            @Nullable InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor) {
        super.setKeyboardLayoutForInputDevice_enforcePermission();
        mKeyboardLayoutManager.setKeyboardLayoutForInputDevice(identifier, userId, imeInfo,
                imeSubtype, keyboardLayoutDescriptor);
    }

    @Override // Binder call
    public String[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
    public KeyboardLayout[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
            @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
            @NonNull InputMethodSubtype imeSubtype) {
            @Nullable InputMethodSubtype imeSubtype) {
        return mKeyboardLayoutManager.getKeyboardLayoutListForInputDevice(identifier, userId,
                imeInfo, imeSubtype);
    }
+6 −10
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.input;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.Notification;
import android.app.NotificationManager;
@@ -550,7 +551,7 @@ final class KeyboardLayoutManager implements InputManager.InputDeviceListener {

    public String getKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
            @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
            @NonNull InputMethodSubtype imeSubtype) {
            @Nullable InputMethodSubtype imeSubtype) {
        // TODO(b/259530132): Implement the new keyboard layout API: Returning non-IME specific
        //  layout for now.
        return getCurrentKeyboardLayoutForInputDevice(identifier);
@@ -558,23 +559,18 @@ final class KeyboardLayoutManager implements InputManager.InputDeviceListener {

    public void setKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
            @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
            @NonNull InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor) {
            @Nullable InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor) {
        // TODO(b/259530132): Implement the new keyboard layout API: setting non-IME specific
        //  layout for now.
        setCurrentKeyboardLayoutForInputDevice(identifier, keyboardLayoutDescriptor);
    }

    public String[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
    public KeyboardLayout[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
            @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
            @NonNull InputMethodSubtype imeSubtype) {
            @Nullable InputMethodSubtype imeSubtype) {
        // TODO(b/259530132): Implement the new keyboard layout API: Returning list of all
        //  layouts for now.
        KeyboardLayout[] allLayouts = getKeyboardLayouts();
        String[] allLayoutDesc = new String[allLayouts.length];
        for (int i = 0; i < allLayouts.length; i++) {
            allLayoutDesc[i] = allLayouts[i].getDescriptor();
        }
        return allLayoutDesc;
        return getKeyboardLayouts();
    }

    public void switchKeyboardLayout(int deviceId, int direction) {