Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.hdmi; |
| 18 | |
| 19 | import android.view.KeyEvent; |
| 20 | |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 21 | import libcore.util.EmptyArray; |
| 22 | |
| 23 | import java.util.Arrays; |
| 24 | |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 25 | /** |
| 26 | * Helper class to translate android keycode to hdmi cec keycode and vice versa. |
| 27 | */ |
Jungshik Jang | 4612a6e | 2014-08-12 22:01:23 +0900 | [diff] [blame] | 28 | final class HdmiCecKeycode { |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 29 | public static final int UNSUPPORTED_KEYCODE = -1; |
| 30 | public static final int NO_PARAM = -1; |
| 31 | |
| 32 | // ========================================================================= |
| 33 | // Hdmi CEC keycodes |
| 34 | public static final int CEC_KEYCODE_SELECT = 0x00; |
| 35 | public static final int CEC_KEYCODE_UP = 0x01; |
| 36 | public static final int CEC_KEYCODE_DOWN = 0x02; |
| 37 | public static final int CEC_KEYCODE_LEFT = 0x03; |
| 38 | public static final int CEC_KEYCODE_RIGHT = 0x04; |
| 39 | public static final int CEC_KEYCODE_RIGHT_UP = 0x05; |
| 40 | public static final int CEC_KEYCODE_RIGHT_DOWN = 0x06; |
| 41 | public static final int CEC_KEYCODE_LEFT_UP = 0x07; |
| 42 | public static final int CEC_KEYCODE_LEFT_DOWN = 0x08; |
| 43 | public static final int CEC_KEYCODE_ROOT_MENU = 0x09; |
| 44 | public static final int CEC_KEYCODE_SETUP_MENU = 0x0A; |
| 45 | public static final int CEC_KEYCODE_CONTENTS_MENU = 0x0B; |
| 46 | public static final int CEC_KEYCODE_FAVORITE_MENU = 0x0C; |
| 47 | public static final int CEC_KEYCODE_EXIT = 0x0D; |
| 48 | // RESERVED = 0x0E - 0x0F |
| 49 | public static final int CEC_KEYCODE_MEDIA_TOP_MENU = 0x10; |
| 50 | public static final int CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU = 0x11; |
| 51 | // RESERVED = 0x12 – 0x1C |
| 52 | public static final int CEC_KEYCODE_NUMBER_ENTRY_MODE = 0x1D; |
| 53 | public static final int CEC_KEYCODE_NUMBER_11 = 0x1E; |
| 54 | public static final int CEC_KEYCODE_NUMBER_12 = 0x1F; |
| 55 | public static final int CEC_KEYCODE_NUMBER_0_OR_NUMBER_10 = 0x20; |
| 56 | public static final int CEC_KEYCODE_NUMBERS_1 = 0x21; |
| 57 | public static final int CEC_KEYCODE_NUMBERS_2 = 0x22; |
| 58 | public static final int CEC_KEYCODE_NUMBERS_3 = 0x23; |
| 59 | public static final int CEC_KEYCODE_NUMBERS_4 = 0x24; |
| 60 | public static final int CEC_KEYCODE_NUMBERS_5 = 0x25; |
| 61 | public static final int CEC_KEYCODE_NUMBERS_6 = 0x26; |
| 62 | public static final int CEC_KEYCODE_NUMBERS_7 = 0x27; |
| 63 | public static final int CEC_KEYCODE_NUMBERS_8 = 0x28; |
| 64 | public static final int CEC_KEYCODE_NUMBERS_9 = 0x29; |
| 65 | public static final int CEC_KEYCODE_DOT = 0x2A; |
| 66 | public static final int CEC_KEYCODE_ENTER = 0x2B; |
| 67 | public static final int CEC_KEYCODE_CLEAR = 0x2C; |
| 68 | // RESERVED = 0x2D - 0x2E |
| 69 | public static final int CEC_KEYCODE_NEXT_FAVORITE = 0x2F; |
| 70 | public static final int CEC_KEYCODE_CHANNEL_UP = 0x30; |
| 71 | public static final int CEC_KEYCODE_CHANNEL_DOWN = 0x31; |
| 72 | public static final int CEC_KEYCODE_PREVIOUS_CHANNEL = 0x32; |
| 73 | public static final int CEC_KEYCODE_SOUND_SELECT = 0x33; |
| 74 | public static final int CEC_KEYCODE_INPUT_SELECT = 0x34; |
| 75 | public static final int CEC_KEYCODE_DISPLAY_INFORMATION = 0x35; |
| 76 | public static final int CEC_KEYCODE_HELP = 0x36; |
| 77 | public static final int CEC_KEYCODE_PAGE_UP = 0x37; |
| 78 | public static final int CEC_KEYCODE_PAGE_DOWN = 0x38; |
| 79 | // RESERVED = 0x39 - 0x3F |
| 80 | public static final int CEC_KEYCODE_POWER = 0x40; |
| 81 | public static final int CEC_KEYCODE_VOLUME_UP = 0x41; |
| 82 | public static final int CEC_KEYCODE_VOLUME_DOWN = 0x42; |
| 83 | public static final int CEC_KEYCODE_MUTE = 0x43; |
| 84 | public static final int CEC_KEYCODE_PLAY = 0x44; |
| 85 | public static final int CEC_KEYCODE_STOP = 0x45; |
| 86 | public static final int CEC_KEYCODE_PAUSE = 0x46; |
| 87 | public static final int CEC_KEYCODE_RECORD = 0x47; |
| 88 | public static final int CEC_KEYCODE_REWIND = 0x48; |
| 89 | public static final int CEC_KEYCODE_FAST_FORWARD = 0x49; |
| 90 | public static final int CEC_KEYCODE_EJECT = 0x4A; |
| 91 | public static final int CEC_KEYCODE_FORWARD = 0x4B; |
| 92 | public static final int CEC_KEYCODE_BACKWARD = 0x4C; |
| 93 | public static final int CEC_KEYCODE_STOP_RECORD = 0x4D; |
| 94 | public static final int CEC_KEYCODE_PAUSE_RECORD = 0x4E; |
| 95 | public static final int CEC_KEYCODE_RESERVED = 0x4F; |
| 96 | public static final int CEC_KEYCODE_ANGLE = 0x50; |
| 97 | public static final int CEC_KEYCODE_SUB_PICTURE = 0x51; |
| 98 | public static final int CEC_KEYCODE_VIDEO_ON_DEMAND = 0x52; |
| 99 | public static final int CEC_KEYCODE_ELECTRONIC_PROGRAM_GUIDE = 0x53; |
| 100 | public static final int CEC_KEYCODE_TIMER_PROGRAMMING = 0x54; |
| 101 | public static final int CEC_KEYCODE_INITIAL_CONFIGURATION = 0x55; |
| 102 | public static final int CEC_KEYCODE_SELECT_BROADCAST_TYPE = 0x56; |
| 103 | public static final int CEC_KEYCODE_SELECT_SOUND_PRESENTATION = 0x57; |
| 104 | // RESERVED = 0x58-0x5F |
| 105 | public static final int CEC_KEYCODE_PLAY_FUNCTION = 0x60; |
| 106 | public static final int CEC_KEYCODE_PAUSE_PLAY_FUNCTION = 0x61; |
| 107 | public static final int CEC_KEYCODE_RECORD_FUNCTION = 0x62; |
| 108 | public static final int CEC_KEYCODE_PAUSE_RECORD_FUNCTION = 0x63; |
| 109 | public static final int CEC_KEYCODE_STOP_FUNCTION = 0x64; |
| 110 | public static final int CEC_KEYCODE_MUTE_FUNCTION = 0x65; |
| 111 | public static final int CEC_KEYCODE_RESTORE_VOLUME_FUNCTION = 0x66; |
| 112 | public static final int CEC_KEYCODE_TUNE_FUNCTION = 0x67; |
| 113 | public static final int CEC_KEYCODE_SELECT_MEDIA_FUNCTION = 0x68; |
| 114 | public static final int CEC_KEYCODE_SELECT_AV_INPUT_FUNCTION = 0x69; |
| 115 | public static final int CEC_KEYCODE_SELECT_AUDIO_INPUT_FUNCTION = 0x6A; |
| 116 | public static final int CEC_KEYCODE_POWER_TOGGLE_FUNCTION = 0x6B; |
| 117 | public static final int CEC_KEYCODE_POWER_OFF_FUNCTION = 0x6C; |
| 118 | public static final int CEC_KEYCODE_POWER_ON_FUNCTION = 0x6D; |
| 119 | // RESERVED = 0x6E-0x70 |
| 120 | public static final int CEC_KEYCODE_F1_BLUE = 0x71; |
| 121 | public static final int CEC_KEYCODE_F2_RED = 0x72; |
| 122 | public static final int CEC_KEYCODE_F3_GREEN = 0x73; |
| 123 | public static final int CEC_KEYCODE_F4_YELLOW = 0x74; |
| 124 | public static final int CEC_KEYCODE_F5 = 0x75; |
| 125 | public static final int CEC_KEYCODE_DATA = 0x76; |
| 126 | // RESERVED = 0x77-0xFF |
| 127 | |
| 128 | // ========================================================================= |
| 129 | // UI Broadcast Type |
| 130 | public static final int UI_BROADCAST_TOGGLE_ALL = 0x00; |
| 131 | public static final int UI_BROADCAST_TOGGLE_ANALOGUE_DIGITAL = 0x01; |
| 132 | public static final int UI_BROADCAST_ANALOGUE = 0x10; |
| 133 | public static final int UI_BROADCAST_ANALOGUE_TERRESTRIAL = 0x20; |
| 134 | public static final int UI_BROADCAST_ANALOGUE_CABLE = 0x30; |
| 135 | public static final int UI_BROADCAST_ANALOGUE_SATELLITE = 0x40; |
| 136 | public static final int UI_BROADCAST_DIGITAL = 0x50; |
| 137 | public static final int UI_BROADCAST_DIGITAL_TERRESTRIAL = 0x60; |
| 138 | public static final int UI_BROADCAST_DIGITAL_CABLE = 0x70; |
| 139 | public static final int UI_BROADCAST_DIGITAL_SATELLITE = 0x80; |
| 140 | public static final int UI_BROADCAST_DIGITAL_COMMNICATIONS_SATELLITE = 0x90; |
| 141 | public static final int UI_BROADCAST_DIGITAL_COMMNICATIONS_SATELLITE_2 = 0x91; |
| 142 | public static final int UI_BROADCAST_IP = 0xA0; |
| 143 | |
| 144 | // ========================================================================= |
| 145 | // UI Sound Presentation Control |
| 146 | public static final int UI_SOUND_PRESENTATION_SOUND_MIX_DUAL_MONO = 0x20; |
| 147 | public static final int UI_SOUND_PRESENTATION_SOUND_MIX_KARAOKE = 0x30; |
| 148 | public static final int UI_SOUND_PRESENTATION_SELECT_AUDIO_DOWN_MIX = 0x80; |
| 149 | public static final int UI_SOUND_PRESENTATION_SELECT_AUDIO_AUTO_REVERBERATION = 0x90; |
| 150 | public static final int UI_SOUND_PRESENTATION_SELECT_AUDIO_AUTO_EQUALIZER = 0xA0; |
| 151 | public static final int UI_SOUND_PRESENTATION_BASS_STEP_PLUS = 0xB1; |
| 152 | public static final int UI_SOUND_PRESENTATION_BASS_NEUTRAL = 0xB2; |
| 153 | public static final int UI_SOUND_PRESENTATION_BASS_STEP_MINUS = 0xB3; |
| 154 | public static final int UI_SOUND_PRESENTATION_TREBLE_STEP_PLUS = 0xC1; |
| 155 | public static final int UI_SOUND_PRESENTATION_TREBLE_NEUTRAL = 0xC2; |
| 156 | public static final int UI_SOUND_PRESENTATION_TREBLE_STEP_MINUS = 0xC3; |
| 157 | |
Jungshik Jang | cd3445c | 2014-06-16 13:34:56 +0900 | [diff] [blame] | 158 | private HdmiCecKeycode() { |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /** |
Jungshik Jang | 5691b2f | 2014-08-18 16:50:12 +0900 | [diff] [blame] | 162 | * A mapping between Android and CEC keycode. |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 163 | * <p> |
| 164 | * Normal implementation of this looks like |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 165 | * |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 166 | * <pre> |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 167 | * new KeycodeEntry(KeyEvent.KEYCODE_DPAD_CENTER, CEC_KEYCODE_SELECT); |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 168 | * </pre> |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 169 | * <p> |
| 170 | * However, some keys in CEC requires additional parameter. In order to use parameterized cec |
| 171 | * key, add unique android keycode (existing or custom) corresponding to a pair of cec keycode |
| 172 | * and and its param. |
| 173 | * |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 174 | * <pre> |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 175 | * new KeycodeEntry(CUSTOME_ANDORID_KEY_1, CEC_KEYCODE_SELECT_BROADCAST_TYPE, |
| 176 | * UI_BROADCAST_TOGGLE_ALL); |
| 177 | * new KeycodeEntry(CUSTOME_ANDORID_KEY_2, CEC_KEYCODE_SELECT_BROADCAST_TYPE, |
| 178 | * UI_BROADCAST_ANALOGUE); |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 179 | * </pre> |
| 180 | */ |
| 181 | private static class KeycodeEntry { |
| 182 | private final int mAndroidKeycode; |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 183 | private final boolean mIsRepeatable; |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 184 | private final byte[] mCecKeycodeAndParams; |
| 185 | |
| 186 | private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable, |
| 187 | byte[] cecParams) { |
| 188 | mAndroidKeycode = androidKeycode; |
| 189 | mIsRepeatable = isRepeatable; |
| 190 | mCecKeycodeAndParams = new byte[cecParams.length + 1]; |
| 191 | System.arraycopy(cecParams, 0, mCecKeycodeAndParams, 1, cecParams.length); |
| 192 | mCecKeycodeAndParams[0] = (byte) (cecKeycode & 0xFF); |
| 193 | } |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 194 | |
Jungshik Jang | 5691b2f | 2014-08-18 16:50:12 +0900 | [diff] [blame] | 195 | private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable) { |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 196 | this(androidKeycode, cecKeycode, isRepeatable, EmptyArray.BYTE); |
| 197 | } |
| 198 | |
| 199 | private KeycodeEntry(int androidKeycode, int cecKeycode, byte[] cecParams) { |
| 200 | this(androidKeycode, cecKeycode, true, cecParams); |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | private KeycodeEntry(int androidKeycode, int cecKeycode) { |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 204 | this(androidKeycode, cecKeycode, true, EmptyArray.BYTE); |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 205 | } |
| 206 | |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 207 | private byte[] toCecKeycodeAndParamIfMatched(int androidKeycode) { |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 208 | if (mAndroidKeycode == androidKeycode) { |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 209 | return mCecKeycodeAndParams; |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 210 | } else { |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 211 | return null; |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 215 | private int toAndroidKeycodeIfMatched(byte[] cecKeycodeAndParams) { |
| 216 | if (Arrays.equals(mCecKeycodeAndParams, cecKeycodeAndParams)) { |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 217 | return mAndroidKeycode; |
| 218 | } else { |
| 219 | return UNSUPPORTED_KEYCODE; |
| 220 | } |
| 221 | } |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 222 | |
| 223 | private Boolean isRepeatableIfMatched(int androidKeycode) { |
| 224 | if (mAndroidKeycode == androidKeycode) { |
| 225 | return mIsRepeatable; |
| 226 | } else { |
| 227 | return null; |
| 228 | } |
| 229 | } |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 230 | } |
| 231 | |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 232 | private static byte[] intToSingleByteArray(int value) { |
| 233 | return new byte[] { |
| 234 | (byte) (value & 0xFF) }; |
| 235 | } |
| 236 | |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 237 | // Keycode entry container for all mappings. |
| 238 | // Note that order of entry is the same as above cec keycode definition. |
| 239 | private static final KeycodeEntry[] KEYCODE_ENTRIES = new KeycodeEntry[] { |
| 240 | new KeycodeEntry(KeyEvent.KEYCODE_DPAD_CENTER, CEC_KEYCODE_SELECT), |
| 241 | new KeycodeEntry(KeyEvent.KEYCODE_DPAD_UP, CEC_KEYCODE_UP), |
| 242 | new KeycodeEntry(KeyEvent.KEYCODE_DPAD_DOWN, CEC_KEYCODE_DOWN), |
| 243 | new KeycodeEntry(KeyEvent.KEYCODE_DPAD_LEFT, CEC_KEYCODE_LEFT), |
| 244 | new KeycodeEntry(KeyEvent.KEYCODE_DPAD_RIGHT, CEC_KEYCODE_RIGHT), |
| 245 | // No Android keycode defined for CEC_KEYCODE_RIGHT_UP |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 246 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RIGHT_UP), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 247 | // No Android keycode defined for CEC_KEYCODE_RIGHT_DOWN |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 248 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RIGHT_DOWN), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 249 | // No Android keycode defined for CEC_KEYCODE_LEFT_UP |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 250 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_LEFT_UP), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 251 | // No Android keycode defined for CEC_KEYCODE_LEFT_DOWN |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 252 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_LEFT_DOWN), |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 253 | new KeycodeEntry(KeyEvent.KEYCODE_HOME, CEC_KEYCODE_ROOT_MENU), |
| 254 | new KeycodeEntry(KeyEvent.KEYCODE_SETTINGS, CEC_KEYCODE_SETUP_MENU), |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 255 | new KeycodeEntry(KeyEvent.KEYCODE_TV_CONTENTS_MENU, CEC_KEYCODE_CONTENTS_MENU, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 256 | // No Android keycode defined for CEC_KEYCODE_FAVORITE_MENU |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 257 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_FAVORITE_MENU), |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 258 | // Note that both BACK and ESCAPE are mapped to EXIT of CEC keycode. |
| 259 | // This would be problematic when translates CEC keycode to Android keycode. |
| 260 | // In current implementation, we pick BACK as mapping of EXIT key. |
| 261 | // If you'd like to map CEC EXIT to Android EXIT key, change order of |
| 262 | // the following two definition. |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 263 | new KeycodeEntry(KeyEvent.KEYCODE_BACK, CEC_KEYCODE_EXIT), |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 264 | new KeycodeEntry(KeyEvent.KEYCODE_ESCAPE, CEC_KEYCODE_EXIT), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 265 | // RESERVED |
| 266 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_TOP_MENU, CEC_KEYCODE_MEDIA_TOP_MENU), |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 267 | new KeycodeEntry(KeyEvent.KEYCODE_TV_MEDIA_CONTEXT_MENU, |
| 268 | CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 269 | // RESERVED |
| 270 | // No Android keycode defined for CEC_KEYCODE_NUMBER_ENTRY_MODE |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 271 | new KeycodeEntry(KeyEvent.KEYCODE_TV_NUMBER_ENTRY, CEC_KEYCODE_NUMBER_ENTRY_MODE), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 272 | new KeycodeEntry(KeyEvent.KEYCODE_11, CEC_KEYCODE_NUMBER_11), |
| 273 | new KeycodeEntry(KeyEvent.KEYCODE_12, CEC_KEYCODE_NUMBER_12), |
| 274 | new KeycodeEntry(KeyEvent.KEYCODE_0, CEC_KEYCODE_NUMBER_0_OR_NUMBER_10), |
| 275 | new KeycodeEntry(KeyEvent.KEYCODE_1, CEC_KEYCODE_NUMBERS_1), |
| 276 | new KeycodeEntry(KeyEvent.KEYCODE_2, CEC_KEYCODE_NUMBERS_2), |
| 277 | new KeycodeEntry(KeyEvent.KEYCODE_3, CEC_KEYCODE_NUMBERS_3), |
| 278 | new KeycodeEntry(KeyEvent.KEYCODE_4, CEC_KEYCODE_NUMBERS_4), |
| 279 | new KeycodeEntry(KeyEvent.KEYCODE_5, CEC_KEYCODE_NUMBERS_5), |
| 280 | new KeycodeEntry(KeyEvent.KEYCODE_6, CEC_KEYCODE_NUMBERS_6), |
| 281 | new KeycodeEntry(KeyEvent.KEYCODE_7, CEC_KEYCODE_NUMBERS_7), |
| 282 | new KeycodeEntry(KeyEvent.KEYCODE_8, CEC_KEYCODE_NUMBERS_8), |
| 283 | new KeycodeEntry(KeyEvent.KEYCODE_9, CEC_KEYCODE_NUMBERS_9), |
| 284 | new KeycodeEntry(KeyEvent.KEYCODE_PERIOD, CEC_KEYCODE_DOT), |
| 285 | new KeycodeEntry(KeyEvent.KEYCODE_NUMPAD_ENTER, CEC_KEYCODE_ENTER), |
| 286 | new KeycodeEntry(KeyEvent.KEYCODE_CLEAR, CEC_KEYCODE_CLEAR), |
| 287 | // RESERVED |
| 288 | // No Android keycode defined for CEC_KEYCODE_NEXT_FAVORITE |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 289 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_NEXT_FAVORITE), |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 290 | new KeycodeEntry(KeyEvent.KEYCODE_CHANNEL_UP, CEC_KEYCODE_CHANNEL_UP), |
| 291 | new KeycodeEntry(KeyEvent.KEYCODE_CHANNEL_DOWN, CEC_KEYCODE_CHANNEL_DOWN), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 292 | new KeycodeEntry(KeyEvent.KEYCODE_LAST_CHANNEL, CEC_KEYCODE_PREVIOUS_CHANNEL), |
elvis.chien | 39907f1 | 2019-07-19 11:17:40 +0800 | [diff] [blame^] | 293 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK, CEC_KEYCODE_SOUND_SELECT), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 294 | new KeycodeEntry(KeyEvent.KEYCODE_TV_INPUT, CEC_KEYCODE_INPUT_SELECT), |
| 295 | new KeycodeEntry(KeyEvent.KEYCODE_INFO, CEC_KEYCODE_DISPLAY_INFORMATION), |
| 296 | // No Android keycode defined for CEC_KEYCODE_HELP |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 297 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_HELP), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 298 | new KeycodeEntry(KeyEvent.KEYCODE_PAGE_UP, CEC_KEYCODE_PAGE_UP), |
| 299 | new KeycodeEntry(KeyEvent.KEYCODE_PAGE_DOWN, CEC_KEYCODE_PAGE_DOWN), |
| 300 | // RESERVED |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 301 | new KeycodeEntry(KeyEvent.KEYCODE_POWER, CEC_KEYCODE_POWER, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 302 | new KeycodeEntry(KeyEvent.KEYCODE_VOLUME_UP, CEC_KEYCODE_VOLUME_UP), |
| 303 | new KeycodeEntry(KeyEvent.KEYCODE_VOLUME_DOWN, CEC_KEYCODE_VOLUME_DOWN), |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 304 | new KeycodeEntry(KeyEvent.KEYCODE_VOLUME_MUTE, CEC_KEYCODE_MUTE, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 305 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PLAY, CEC_KEYCODE_PLAY), |
| 306 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_STOP, CEC_KEYCODE_STOP), |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 307 | // Note that we map both MEDIA_PAUSE and MEDIA_PLAY_PAUSE to CEC PAUSE key. |
| 308 | // When it translates CEC PAUSE key, it picks Android MEDIA_PAUSE key as a mapping of |
| 309 | // it. If you'd like to choose MEDIA_PLAY_PAUSE, please change order of the following |
| 310 | // two lines. |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 311 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PAUSE, CEC_KEYCODE_PAUSE), |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 312 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, CEC_KEYCODE_PAUSE), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 313 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_RECORD, CEC_KEYCODE_RECORD), |
| 314 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_REWIND, CEC_KEYCODE_REWIND), |
| 315 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, CEC_KEYCODE_FAST_FORWARD), |
| 316 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_EJECT, CEC_KEYCODE_EJECT), |
| 317 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_NEXT, CEC_KEYCODE_FORWARD), |
| 318 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PREVIOUS, CEC_KEYCODE_BACKWARD), |
| 319 | // No Android keycode defined for CEC_KEYCODE_STOP_RECORD |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 320 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_STOP_RECORD), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 321 | // No Android keycode defined for CEC_KEYCODE_PAUSE_RECORD |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 322 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PAUSE_RECORD), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 323 | // No Android keycode defined for CEC_KEYCODE_RESERVED |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 324 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RESERVED), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 325 | // No Android keycode defined for CEC_KEYCODE_ANGLE |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 326 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_ANGLE), |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 327 | new KeycodeEntry(KeyEvent.KEYCODE_CAPTIONS, CEC_KEYCODE_SUB_PICTURE), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 328 | // No Android keycode defined for CEC_KEYCODE_VIDEO_ON_DEMAND |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 329 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_VIDEO_ON_DEMAND), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 330 | new KeycodeEntry(KeyEvent.KEYCODE_GUIDE, CEC_KEYCODE_ELECTRONIC_PROGRAM_GUIDE), |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 331 | new KeycodeEntry(KeyEvent.KEYCODE_TV_TIMER_PROGRAMMING, CEC_KEYCODE_TIMER_PROGRAMMING), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 332 | // No Android keycode defined for CEC_KEYCODE_INITIAL_CONFIGURATION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 333 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_INITIAL_CONFIGURATION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 334 | // No Android keycode defined for CEC_KEYCODE_SELECT_BROADCAST_TYPE |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 335 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_BROADCAST_TYPE), |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 336 | new KeycodeEntry(KeyEvent.KEYCODE_TV_TERRESTRIAL_ANALOG, |
| 337 | CEC_KEYCODE_SELECT_BROADCAST_TYPE, true, |
| 338 | intToSingleByteArray(UI_BROADCAST_ANALOGUE)), |
| 339 | new KeycodeEntry(KeyEvent.KEYCODE_TV_TERRESTRIAL_DIGITAL, |
| 340 | CEC_KEYCODE_SELECT_BROADCAST_TYPE, true, |
| 341 | intToSingleByteArray(UI_BROADCAST_DIGITAL_TERRESTRIAL)), |
| 342 | new KeycodeEntry(KeyEvent.KEYCODE_TV_SATELLITE_BS, |
| 343 | CEC_KEYCODE_SELECT_BROADCAST_TYPE, true, |
| 344 | intToSingleByteArray(UI_BROADCAST_DIGITAL_SATELLITE)), |
| 345 | new KeycodeEntry(KeyEvent.KEYCODE_TV_SATELLITE_CS, |
| 346 | CEC_KEYCODE_SELECT_BROADCAST_TYPE, true, |
| 347 | intToSingleByteArray(UI_BROADCAST_DIGITAL_COMMNICATIONS_SATELLITE)), |
| 348 | new KeycodeEntry(KeyEvent.KEYCODE_TV_NETWORK, |
| 349 | CEC_KEYCODE_SELECT_BROADCAST_TYPE, true, |
| 350 | intToSingleByteArray(UI_BROADCAST_TOGGLE_ANALOGUE_DIGITAL)), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 351 | // No Android keycode defined for CEC_KEYCODE_SELECT_SOUND_PRESENTATION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 352 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_SOUND_PRESENTATION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 353 | // RESERVED |
| 354 | // The following deterministic key definitions do not need key mapping |
| 355 | // since they are supposed to be generated programmatically only. |
| 356 | // No Android keycode defined for CEC_KEYCODE_PLAY_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 357 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PLAY_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 358 | // No Android keycode defined for CEC_KEYCODE_PAUSE_PLAY_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 359 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PAUSE_PLAY_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 360 | // No Android keycode defined for CEC_KEYCODE_RECORD_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 361 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RECORD_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 362 | // No Android keycode defined for CEC_KEYCODE_PAUSE_RECORD_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 363 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PAUSE_RECORD_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 364 | // No Android keycode defined for CEC_KEYCODE_STOP_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 365 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_STOP_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 366 | // No Android keycode defined for CEC_KEYCODE_MUTE_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 367 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_MUTE_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 368 | // No Android keycode defined for CEC_KEYCODE_RESTORE_VOLUME_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 369 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RESTORE_VOLUME_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 370 | // No Android keycode defined for CEC_KEYCODE_TUNE_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 371 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_TUNE_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 372 | // No Android keycode defined for CEC_KEYCODE_SELECT_MEDIA_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 373 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_MEDIA_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 374 | // No Android keycode defined for CEC_KEYCODE_SELECT_AV_INPUT_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 375 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_AV_INPUT_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 376 | // No Android keycode defined for CEC_KEYCODE_SELECT_AUDIO_INPUT_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 377 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_AUDIO_INPUT_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 378 | // No Android keycode defined for CEC_KEYCODE_POWER_TOGGLE_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 379 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_POWER_TOGGLE_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 380 | // No Android keycode defined for CEC_KEYCODE_POWER_OFF_FUNCTION |
Jungshik Jang | d825aac | 2014-09-29 16:27:32 +0900 | [diff] [blame] | 381 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_POWER_OFF_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 382 | // No Android keycode defined for CEC_KEYCODE_POWER_ON_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 383 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_POWER_ON_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 384 | // RESERVED |
| 385 | new KeycodeEntry(KeyEvent.KEYCODE_PROG_BLUE, CEC_KEYCODE_F1_BLUE), |
| 386 | new KeycodeEntry(KeyEvent.KEYCODE_PROG_RED, CEC_KEYCODE_F2_RED), |
| 387 | new KeycodeEntry(KeyEvent.KEYCODE_PROG_GREEN, CEC_KEYCODE_F3_GREEN), |
| 388 | new KeycodeEntry(KeyEvent.KEYCODE_PROG_YELLOW, CEC_KEYCODE_F4_YELLOW), |
| 389 | new KeycodeEntry(KeyEvent.KEYCODE_F5, CEC_KEYCODE_F5), |
| 390 | new KeycodeEntry(KeyEvent.KEYCODE_TV_DATA_SERVICE, CEC_KEYCODE_DATA), |
| 391 | // RESERVED |
| 392 | // Add a new key mapping here if new keycode is introduced. |
| 393 | }; |
| 394 | |
| 395 | /** |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 396 | * Translate Android keycode to Hdmi Cec keycode and params. |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 397 | * |
| 398 | * @param keycode Android keycode. For details, refer {@link KeyEvent} |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 399 | * @return byte array of CEC keycode and params if matched. Otherwise, return null. |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 400 | */ |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 401 | static byte[] androidKeyToCecKey(int keycode) { |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 402 | for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 403 | byte[] cecKeycodeAndParams = KEYCODE_ENTRIES[i].toCecKeycodeAndParamIfMatched(keycode); |
| 404 | if (cecKeycodeAndParams != null) { |
| 405 | return cecKeycodeAndParams; |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 406 | } |
| 407 | } |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 408 | return null; |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | /** |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 412 | * Translate Hdmi CEC keycode with params to Android keycode. |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 413 | * |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 414 | * @param cecKeycodeAndParams CEC keycode and params |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 415 | * @return cec keycode corresponding to the given android keycode. If finds no matched keycode, |
| 416 | * return {@link #UNSUPPORTED_KEYCODE} |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 417 | */ |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 418 | static int cecKeycodeAndParamsToAndroidKey(byte[] cecKeycodeAndParams) { |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 419 | for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 420 | int androidKey = KEYCODE_ENTRIES[i].toAndroidKeycodeIfMatched(cecKeycodeAndParams); |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 421 | if (androidKey != UNSUPPORTED_KEYCODE) { |
| 422 | return androidKey; |
| 423 | } |
| 424 | } |
| 425 | return UNSUPPORTED_KEYCODE; |
| 426 | } |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 427 | |
| 428 | /** |
| 429 | * Whether the given {@code androidKeycode} is repeatable key or not. |
| 430 | * |
| 431 | * @param androidKeycode keycode of android |
| 432 | * @return false if the given {@code androidKeycode} is not supported key code |
| 433 | */ |
| 434 | static boolean isRepeatableKey(int androidKeycode) { |
| 435 | for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { |
| 436 | Boolean isRepeatable = KEYCODE_ENTRIES[i].isRepeatableIfMatched(androidKeycode); |
| 437 | if (isRepeatable != null) { |
| 438 | return isRepeatable; |
| 439 | } |
| 440 | } |
| 441 | return false; |
| 442 | } |
Dongil Seo | b64c2ba | 2014-08-26 19:41:39 +0900 | [diff] [blame] | 443 | |
| 444 | /** |
| 445 | * Returns {@code true} if given Android keycode is supported, otherwise {@code false}. |
| 446 | */ |
| 447 | static boolean isSupportedKeycode(int androidKeycode) { |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 448 | return HdmiCecKeycode.androidKeyToCecKey(androidKeycode) != null; |
Jungshik Jang | fe27961 | 2014-09-29 11:49:57 +0900 | [diff] [blame] | 449 | } |
Jinsuk Kim | 0ab3779 | 2015-10-17 06:53:52 +0900 | [diff] [blame] | 450 | |
| 451 | /** |
| 452 | * Returns CEC keycode to control audio mute status. |
| 453 | * |
| 454 | * @param muting {@code true} if audio is being muted |
| 455 | */ |
| 456 | public static int getMuteKey(boolean muting) { |
| 457 | // CEC_KEYCODE_MUTE_FUNCTION, CEC_KEYCODE_RESTORE_VOLUME_FUNCTION are deterministic |
| 458 | // commands that ensures the status changes to what we want, while CEC_KEYCODE_MUTE |
| 459 | // simply toggles the status. |
| 460 | // The former is a better choice in this regard, but there are compatibility issues |
| 461 | // observed - many audio receivers don't recognize the commands. We fall back on |
| 462 | // CEC_KEYCODE_MUTE for now. |
| 463 | // return muting ? CEC_KEYCODE_MUTE_FUNCTION : CEC_KEYCODE_RESTORE_VOLUME_FUNCTION; |
| 464 | return CEC_KEYCODE_MUTE; |
| 465 | } |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 466 | } |