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

Commit 0fc5d10e authored by helen cheuk's avatar helen cheuk
Browse files

[Custom Key Glyph] KeyCombination should be parcelable

This CL fixes an issue that if there is hardware-defined-shortcut tag in keyboard-glyph-map xml, it throws exception when calling inputManager.getKeyGlyphMap because KeyCombination is not parcelable.

Bug: 375681062
Test: Manual, tested calling from SystemUI
Flag: com.android.hardware.input.keyboard_glyph_map
Change-Id: I3de7036d84d3ce0eee4212719755bf9ebe19a5b9
parent 66d04b47
Loading
Loading
Loading
Loading
+49 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.view.KeyEvent;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * This class provides access to device specific key glyphs, modifier glyphs and device specific
@@ -107,7 +108,54 @@ public final class KeyGlyphMap implements Parcelable {
    /**
     * Defines a key combination that includes a keycode and modifier state.
     */
    public record KeyCombination(int modifierState, int keycode) {}
    public static class KeyCombination implements Parcelable {
        private final int mModifierState;
        private final int mKeycode;

        public KeyCombination(int modifierState, int keycode) {
            this.mModifierState = modifierState;
            this.mKeycode = keycode;
        }

        public KeyCombination(Parcel in) {
            this(in.readInt(), in.readInt());
        }

        public static final Creator<KeyCombination> CREATOR = new Creator<>() {
            @Override
            public KeyCombination createFromParcel(Parcel in) {
                return new KeyCombination(in);
            }

            @Override
            public KeyCombination[] newArray(int size) {
                return new KeyCombination[size];
            }
        };

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(@androidx.annotation.NonNull Parcel dest, int flags) {
            dest.writeInt(mModifierState);
            dest.writeInt(mKeycode);
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof KeyCombination that)) return false;
            return mModifierState == that.mModifierState && mKeycode == that.mKeycode;
        }

        @Override
        public int hashCode() {
            return Objects.hash(mModifierState, mKeycode);
        }
    }

    /**
     * Returns keycodes generated from the functional row defined for the keyboard.