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 21 /** 22 * Helper class to translate android keycode to hdmi cec keycode and vice versa. 23 */ 24 final class HdmiCecKeycode { 25 public static final int UNSUPPORTED_KEYCODE = -1; 26 public static final int NO_PARAM = -1; 27 28 // ========================================================================= 29 // Hdmi CEC keycodes 30 public static final int CEC_KEYCODE_SELECT = 0x00; 31 public static final int CEC_KEYCODE_UP = 0x01; 32 public static final int CEC_KEYCODE_DOWN = 0x02; 33 public static final int CEC_KEYCODE_LEFT = 0x03; 34 public static final int CEC_KEYCODE_RIGHT = 0x04; 35 public static final int CEC_KEYCODE_RIGHT_UP = 0x05; 36 public static final int CEC_KEYCODE_RIGHT_DOWN = 0x06; 37 public static final int CEC_KEYCODE_LEFT_UP = 0x07; 38 public static final int CEC_KEYCODE_LEFT_DOWN = 0x08; 39 public static final int CEC_KEYCODE_ROOT_MENU = 0x09; 40 public static final int CEC_KEYCODE_SETUP_MENU = 0x0A; 41 public static final int CEC_KEYCODE_CONTENTS_MENU = 0x0B; 42 public static final int CEC_KEYCODE_FAVORITE_MENU = 0x0C; 43 public static final int CEC_KEYCODE_EXIT = 0x0D; 44 // RESERVED = 0x0E - 0x0F 45 public static final int CEC_KEYCODE_MEDIA_TOP_MENU = 0x10; 46 public static final int CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU = 0x11; 47 // RESERVED = 0x12 0x1C 48 public static final int CEC_KEYCODE_NUMBER_ENTRY_MODE = 0x1D; 49 public static final int CEC_KEYCODE_NUMBER_11 = 0x1E; 50 public static final int CEC_KEYCODE_NUMBER_12 = 0x1F; 51 public static final int CEC_KEYCODE_NUMBER_0_OR_NUMBER_10 = 0x20; 52 public static final int CEC_KEYCODE_NUMBERS_1 = 0x21; 53 public static final int CEC_KEYCODE_NUMBERS_2 = 0x22; 54 public static final int CEC_KEYCODE_NUMBERS_3 = 0x23; 55 public static final int CEC_KEYCODE_NUMBERS_4 = 0x24; 56 public static final int CEC_KEYCODE_NUMBERS_5 = 0x25; 57 public static final int CEC_KEYCODE_NUMBERS_6 = 0x26; 58 public static final int CEC_KEYCODE_NUMBERS_7 = 0x27; 59 public static final int CEC_KEYCODE_NUMBERS_8 = 0x28; 60 public static final int CEC_KEYCODE_NUMBERS_9 = 0x29; 61 public static final int CEC_KEYCODE_DOT = 0x2A; 62 public static final int CEC_KEYCODE_ENTER = 0x2B; 63 public static final int CEC_KEYCODE_CLEAR = 0x2C; 64 // RESERVED = 0x2D - 0x2E 65 public static final int CEC_KEYCODE_NEXT_FAVORITE = 0x2F; 66 public static final int CEC_KEYCODE_CHANNEL_UP = 0x30; 67 public static final int CEC_KEYCODE_CHANNEL_DOWN = 0x31; 68 public static final int CEC_KEYCODE_PREVIOUS_CHANNEL = 0x32; 69 public static final int CEC_KEYCODE_SOUND_SELECT = 0x33; 70 public static final int CEC_KEYCODE_INPUT_SELECT = 0x34; 71 public static final int CEC_KEYCODE_DISPLAY_INFORMATION = 0x35; 72 public static final int CEC_KEYCODE_HELP = 0x36; 73 public static final int CEC_KEYCODE_PAGE_UP = 0x37; 74 public static final int CEC_KEYCODE_PAGE_DOWN = 0x38; 75 // RESERVED = 0x39 - 0x3F 76 public static final int CEC_KEYCODE_POWER = 0x40; 77 public static final int CEC_KEYCODE_VOLUME_UP = 0x41; 78 public static final int CEC_KEYCODE_VOLUME_DOWN = 0x42; 79 public static final int CEC_KEYCODE_MUTE = 0x43; 80 public static final int CEC_KEYCODE_PLAY = 0x44; 81 public static final int CEC_KEYCODE_STOP = 0x45; 82 public static final int CEC_KEYCODE_PAUSE = 0x46; 83 public static final int CEC_KEYCODE_RECORD = 0x47; 84 public static final int CEC_KEYCODE_REWIND = 0x48; 85 public static final int CEC_KEYCODE_FAST_FORWARD = 0x49; 86 public static final int CEC_KEYCODE_EJECT = 0x4A; 87 public static final int CEC_KEYCODE_FORWARD = 0x4B; 88 public static final int CEC_KEYCODE_BACKWARD = 0x4C; 89 public static final int CEC_KEYCODE_STOP_RECORD = 0x4D; 90 public static final int CEC_KEYCODE_PAUSE_RECORD = 0x4E; 91 public static final int CEC_KEYCODE_RESERVED = 0x4F; 92 public static final int CEC_KEYCODE_ANGLE = 0x50; 93 public static final int CEC_KEYCODE_SUB_PICTURE = 0x51; 94 public static final int CEC_KEYCODE_VIDEO_ON_DEMAND = 0x52; 95 public static final int CEC_KEYCODE_ELECTRONIC_PROGRAM_GUIDE = 0x53; 96 public static final int CEC_KEYCODE_TIMER_PROGRAMMING = 0x54; 97 public static final int CEC_KEYCODE_INITIAL_CONFIGURATION = 0x55; 98 public static final int CEC_KEYCODE_SELECT_BROADCAST_TYPE = 0x56; 99 public static final int CEC_KEYCODE_SELECT_SOUND_PRESENTATION = 0x57; 100 // RESERVED = 0x58-0x5F 101 public static final int CEC_KEYCODE_PLAY_FUNCTION = 0x60; 102 public static final int CEC_KEYCODE_PAUSE_PLAY_FUNCTION = 0x61; 103 public static final int CEC_KEYCODE_RECORD_FUNCTION = 0x62; 104 public static final int CEC_KEYCODE_PAUSE_RECORD_FUNCTION = 0x63; 105 public static final int CEC_KEYCODE_STOP_FUNCTION = 0x64; 106 public static final int CEC_KEYCODE_MUTE_FUNCTION = 0x65; 107 public static final int CEC_KEYCODE_RESTORE_VOLUME_FUNCTION = 0x66; 108 public static final int CEC_KEYCODE_TUNE_FUNCTION = 0x67; 109 public static final int CEC_KEYCODE_SELECT_MEDIA_FUNCTION = 0x68; 110 public static final int CEC_KEYCODE_SELECT_AV_INPUT_FUNCTION = 0x69; 111 public static final int CEC_KEYCODE_SELECT_AUDIO_INPUT_FUNCTION = 0x6A; 112 public static final int CEC_KEYCODE_POWER_TOGGLE_FUNCTION = 0x6B; 113 public static final int CEC_KEYCODE_POWER_OFF_FUNCTION = 0x6C; 114 public static final int CEC_KEYCODE_POWER_ON_FUNCTION = 0x6D; 115 // RESERVED = 0x6E-0x70 116 public static final int CEC_KEYCODE_F1_BLUE = 0x71; 117 public static final int CEC_KEYCODE_F2_RED = 0x72; 118 public static final int CEC_KEYCODE_F3_GREEN = 0x73; 119 public static final int CEC_KEYCODE_F4_YELLOW = 0x74; 120 public static final int CEC_KEYCODE_F5 = 0x75; 121 public static final int CEC_KEYCODE_DATA = 0x76; 122 // RESERVED = 0x77-0xFF 123 124 // ========================================================================= 125 // UI Broadcast Type 126 public static final int UI_BROADCAST_TOGGLE_ALL = 0x00; 127 public static final int UI_BROADCAST_TOGGLE_ANALOGUE_DIGITAL = 0x01; 128 public static final int UI_BROADCAST_ANALOGUE = 0x10; 129 public static final int UI_BROADCAST_ANALOGUE_TERRESTRIAL = 0x20; 130 public static final int UI_BROADCAST_ANALOGUE_CABLE = 0x30; 131 public static final int UI_BROADCAST_ANALOGUE_SATELLITE = 0x40; 132 public static final int UI_BROADCAST_DIGITAL = 0x50; 133 public static final int UI_BROADCAST_DIGITAL_TERRESTRIAL = 0x60; 134 public static final int UI_BROADCAST_DIGITAL_CABLE = 0x70; 135 public static final int UI_BROADCAST_DIGITAL_SATELLITE = 0x80; 136 public static final int UI_BROADCAST_DIGITAL_COMMNICATIONS_SATELLITE = 0x90; 137 public static final int UI_BROADCAST_DIGITAL_COMMNICATIONS_SATELLITE_2 = 0x91; 138 public static final int UI_BROADCAST_IP = 0xA0; 139 140 // ========================================================================= 141 // UI Sound Presentation Control 142 public static final int UI_SOUND_PRESENTATION_SOUND_MIX_DUAL_MONO = 0x20; 143 public static final int UI_SOUND_PRESENTATION_SOUND_MIX_KARAOKE = 0x30; 144 public static final int UI_SOUND_PRESENTATION_SELECT_AUDIO_DOWN_MIX = 0x80; 145 public static final int UI_SOUND_PRESENTATION_SELECT_AUDIO_AUTO_REVERBERATION = 0x90; 146 public static final int UI_SOUND_PRESENTATION_SELECT_AUDIO_AUTO_EQUALIZER = 0xA0; 147 public static final int UI_SOUND_PRESENTATION_BASS_STEP_PLUS = 0xB1; 148 public static final int UI_SOUND_PRESENTATION_BASS_NEUTRAL = 0xB2; 149 public static final int UI_SOUND_PRESENTATION_BASS_STEP_MINUS = 0xB3; 150 public static final int UI_SOUND_PRESENTATION_TREBLE_STEP_PLUS = 0xC1; 151 public static final int UI_SOUND_PRESENTATION_TREBLE_NEUTRAL = 0xC2; 152 public static final int UI_SOUND_PRESENTATION_TREBLE_STEP_MINUS = 0xC3; 153 154 private HdmiCecKeycode() { 155 } 156 157 /** 158 * A mapping between Android and CEC keycode. 159 * 160 * <p>Normal implementation of this looks like 161 * <pre> 162 * new KeycodeEntry(KeyEvent.KEYCODE_DPAD_CENTER, CEC_KEYCODE_SELECT); 163 * </pre> 164 * <p>However, some keys in CEC requires additional parameter. 165 * In order to use parameterized cec key, add unique android keycode (existing or custom) 166 * corresponding to a pair of cec keycode and and its param. 167 * <pre> 168 * new KeycodeEntry(CUSTOME_ANDORID_KEY_1, CEC_KEYCODE_SELECT_BROADCAST_TYPE, 169 * UI_BROADCAST_TOGGLE_ALL); 170 * new KeycodeEntry(CUSTOME_ANDORID_KEY_2, CEC_KEYCODE_SELECT_BROADCAST_TYPE, 171 * UI_BROADCAST_ANALOGUE); 172 * </pre> 173 */ 174 private static class KeycodeEntry { 175 private final int mAndroidKeycode; 176 private final int mCecKeycode; 177 private final boolean mIsRepeatable; 178 179 private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable) { 180 mAndroidKeycode = androidKeycode; 181 mCecKeycode = cecKeycode; 182 mIsRepeatable = isRepeatable; 183 } 184 185 private KeycodeEntry(int androidKeycode, int cecKeycode) { 186 this(androidKeycode, cecKeycode, true); 187 } 188 189 private int toCecKeycodeIfMatched(int androidKeycode) { 190 if (mAndroidKeycode == androidKeycode) { 191 return mCecKeycode; 192 } else { 193 return UNSUPPORTED_KEYCODE; 194 } 195 } 196 197 private int toAndroidKeycodeIfMatched(int cecKeycode) { 198 if (cecKeycode == mCecKeycode) { 199 return mAndroidKeycode; 200 } else { 201 return UNSUPPORTED_KEYCODE; 202 } 203 } 204 205 private Boolean isRepeatableIfMatched(int androidKeycode) { 206 if (mAndroidKeycode == androidKeycode) { 207 return mIsRepeatable; 208 } else { 209 return null; 210 } 211 } 212 } 213 214 // Keycode entry container for all mappings. 215 // Note that order of entry is the same as above cec keycode definition. 216 private static final KeycodeEntry[] KEYCODE_ENTRIES = new KeycodeEntry[] { 217 new KeycodeEntry(KeyEvent.KEYCODE_DPAD_CENTER, CEC_KEYCODE_SELECT), 218 new KeycodeEntry(KeyEvent.KEYCODE_DPAD_UP, CEC_KEYCODE_UP), 219 new KeycodeEntry(KeyEvent.KEYCODE_DPAD_DOWN, CEC_KEYCODE_DOWN), 220 new KeycodeEntry(KeyEvent.KEYCODE_DPAD_LEFT, CEC_KEYCODE_LEFT), 221 new KeycodeEntry(KeyEvent.KEYCODE_DPAD_RIGHT, CEC_KEYCODE_RIGHT), 222 // No Android keycode defined for CEC_KEYCODE_RIGHT_UP 223 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RIGHT_UP), 224 // No Android keycode defined for CEC_KEYCODE_RIGHT_DOWN 225 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RIGHT_DOWN), 226 // No Android keycode defined for CEC_KEYCODE_LEFT_UP 227 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_LEFT_UP), 228 // No Android keycode defined for CEC_KEYCODE_LEFT_DOWN 229 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_LEFT_DOWN), 230 new KeycodeEntry(KeyEvent.KEYCODE_HOME, CEC_KEYCODE_ROOT_MENU, false), 231 new KeycodeEntry(KeyEvent.KEYCODE_SETTINGS, CEC_KEYCODE_SETUP_MENU, false), 232 new KeycodeEntry(KeyEvent.KEYCODE_MENU, CEC_KEYCODE_CONTENTS_MENU, false), 233 // No Android keycode defined for CEC_KEYCODE_FAVORITE_MENU 234 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_FAVORITE_MENU), 235 new KeycodeEntry(KeyEvent.KEYCODE_BACK, CEC_KEYCODE_EXIT), 236 // RESERVED 237 new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_TOP_MENU, CEC_KEYCODE_MEDIA_TOP_MENU), 238 // No Android keycode defined for CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU 239 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU), 240 // RESERVED 241 // No Android keycode defined for CEC_KEYCODE_NUMBER_ENTRY_MODE 242 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_NUMBER_ENTRY_MODE), 243 new KeycodeEntry(KeyEvent.KEYCODE_11, CEC_KEYCODE_NUMBER_11), 244 new KeycodeEntry(KeyEvent.KEYCODE_12, CEC_KEYCODE_NUMBER_12), 245 new KeycodeEntry(KeyEvent.KEYCODE_0, CEC_KEYCODE_NUMBER_0_OR_NUMBER_10), 246 new KeycodeEntry(KeyEvent.KEYCODE_1, CEC_KEYCODE_NUMBERS_1), 247 new KeycodeEntry(KeyEvent.KEYCODE_2, CEC_KEYCODE_NUMBERS_2), 248 new KeycodeEntry(KeyEvent.KEYCODE_3, CEC_KEYCODE_NUMBERS_3), 249 new KeycodeEntry(KeyEvent.KEYCODE_4, CEC_KEYCODE_NUMBERS_4), 250 new KeycodeEntry(KeyEvent.KEYCODE_5, CEC_KEYCODE_NUMBERS_5), 251 new KeycodeEntry(KeyEvent.KEYCODE_6, CEC_KEYCODE_NUMBERS_6), 252 new KeycodeEntry(KeyEvent.KEYCODE_7, CEC_KEYCODE_NUMBERS_7), 253 new KeycodeEntry(KeyEvent.KEYCODE_8, CEC_KEYCODE_NUMBERS_8), 254 new KeycodeEntry(KeyEvent.KEYCODE_9, CEC_KEYCODE_NUMBERS_9), 255 new KeycodeEntry(KeyEvent.KEYCODE_PERIOD, CEC_KEYCODE_DOT), 256 new KeycodeEntry(KeyEvent.KEYCODE_NUMPAD_ENTER, CEC_KEYCODE_ENTER), 257 new KeycodeEntry(KeyEvent.KEYCODE_CLEAR, CEC_KEYCODE_CLEAR), 258 // RESERVED 259 // No Android keycode defined for CEC_KEYCODE_NEXT_FAVORITE 260 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_NEXT_FAVORITE), 261 new KeycodeEntry(KeyEvent.KEYCODE_CHANNEL_UP, CEC_KEYCODE_CHANNEL_UP), 262 new KeycodeEntry(KeyEvent.KEYCODE_CHANNEL_DOWN, CEC_KEYCODE_CHANNEL_DOWN), 263 new KeycodeEntry(KeyEvent.KEYCODE_LAST_CHANNEL, CEC_KEYCODE_PREVIOUS_CHANNEL), 264 // No Android keycode defined for CEC_KEYCODE_SOUND_SELECT 265 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SOUND_SELECT), 266 new KeycodeEntry(KeyEvent.KEYCODE_TV_INPUT, CEC_KEYCODE_INPUT_SELECT), 267 new KeycodeEntry(KeyEvent.KEYCODE_INFO, CEC_KEYCODE_DISPLAY_INFORMATION), 268 // No Android keycode defined for CEC_KEYCODE_HELP 269 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_HELP), 270 new KeycodeEntry(KeyEvent.KEYCODE_PAGE_UP, CEC_KEYCODE_PAGE_UP), 271 new KeycodeEntry(KeyEvent.KEYCODE_PAGE_DOWN, CEC_KEYCODE_PAGE_DOWN), 272 // RESERVED 273 new KeycodeEntry(KeyEvent.KEYCODE_POWER, CEC_KEYCODE_POWER, false), 274 new KeycodeEntry(KeyEvent.KEYCODE_VOLUME_UP, CEC_KEYCODE_VOLUME_UP), 275 new KeycodeEntry(KeyEvent.KEYCODE_VOLUME_DOWN, CEC_KEYCODE_VOLUME_DOWN), 276 new KeycodeEntry(KeyEvent.KEYCODE_VOLUME_MUTE, CEC_KEYCODE_MUTE, false), 277 new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PLAY, CEC_KEYCODE_PLAY), 278 new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_STOP, CEC_KEYCODE_STOP), 279 new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PAUSE, CEC_KEYCODE_PAUSE), 280 new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_RECORD, CEC_KEYCODE_RECORD), 281 new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_REWIND, CEC_KEYCODE_REWIND), 282 new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, CEC_KEYCODE_FAST_FORWARD), 283 new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_EJECT, CEC_KEYCODE_EJECT), 284 new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_NEXT, CEC_KEYCODE_FORWARD), 285 new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PREVIOUS, CEC_KEYCODE_BACKWARD), 286 // No Android keycode defined for CEC_KEYCODE_STOP_RECORD 287 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_STOP_RECORD), 288 // No Android keycode defined for CEC_KEYCODE_PAUSE_RECORD 289 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PAUSE_RECORD), 290 // No Android keycode defined for CEC_KEYCODE_RESERVED 291 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RESERVED), 292 // No Android keycode defined for CEC_KEYCODE_ANGLE 293 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_ANGLE), 294 // No Android keycode defined for CEC_KEYCODE_SUB_PICTURE 295 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SUB_PICTURE), 296 // No Android keycode defined for CEC_KEYCODE_VIDEO_ON_DEMAND 297 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_VIDEO_ON_DEMAND), 298 new KeycodeEntry(KeyEvent.KEYCODE_GUIDE, CEC_KEYCODE_ELECTRONIC_PROGRAM_GUIDE), 299 // No Android keycode defined for CEC_KEYCODE_TIMER_PROGRAMMING 300 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_TIMER_PROGRAMMING), 301 // No Android keycode defined for CEC_KEYCODE_INITIAL_CONFIGURATION 302 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_INITIAL_CONFIGURATION), 303 // No Android keycode defined for CEC_KEYCODE_SELECT_BROADCAST_TYPE 304 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_BROADCAST_TYPE), 305 // No Android keycode defined for CEC_KEYCODE_SELECT_SOUND_PRESENTATION 306 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_SOUND_PRESENTATION), 307 // RESERVED 308 // The following deterministic key definitions do not need key mapping 309 // since they are supposed to be generated programmatically only. 310 // No Android keycode defined for CEC_KEYCODE_PLAY_FUNCTION 311 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PLAY_FUNCTION), 312 // No Android keycode defined for CEC_KEYCODE_PAUSE_PLAY_FUNCTION 313 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PAUSE_PLAY_FUNCTION), 314 // No Android keycode defined for CEC_KEYCODE_RECORD_FUNCTION 315 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RECORD_FUNCTION), 316 // No Android keycode defined for CEC_KEYCODE_PAUSE_RECORD_FUNCTION 317 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PAUSE_RECORD_FUNCTION), 318 // No Android keycode defined for CEC_KEYCODE_STOP_FUNCTION 319 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_STOP_FUNCTION), 320 // No Android keycode defined for CEC_KEYCODE_MUTE_FUNCTION 321 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_MUTE_FUNCTION, false), 322 // No Android keycode defined for CEC_KEYCODE_RESTORE_VOLUME_FUNCTION 323 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RESTORE_VOLUME_FUNCTION, false), 324 // No Android keycode defined for CEC_KEYCODE_TUNE_FUNCTION 325 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_TUNE_FUNCTION), 326 // No Android keycode defined for CEC_KEYCODE_SELECT_MEDIA_FUNCTION 327 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_MEDIA_FUNCTION), 328 // No Android keycode defined for CEC_KEYCODE_SELECT_AV_INPUT_FUNCTION 329 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_AV_INPUT_FUNCTION), 330 // No Android keycode defined for CEC_KEYCODE_SELECT_AUDIO_INPUT_FUNCTION 331 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_AUDIO_INPUT_FUNCTION), 332 // No Android keycode defined for CEC_KEYCODE_POWER_TOGGLE_FUNCTION 333 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_POWER_TOGGLE_FUNCTION), 334 // No Android keycode defined for CEC_KEYCODE_POWER_OFF_FUNCTION 335 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_POWER_OFF_FUNCTION), 336 // No Android keycode defined for CEC_KEYCODE_POWER_ON_FUNCTION 337 new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_POWER_ON_FUNCTION, false), 338 // RESERVED 339 new KeycodeEntry(KeyEvent.KEYCODE_PROG_BLUE, CEC_KEYCODE_F1_BLUE), 340 new KeycodeEntry(KeyEvent.KEYCODE_PROG_RED, CEC_KEYCODE_F2_RED), 341 new KeycodeEntry(KeyEvent.KEYCODE_PROG_GREEN, CEC_KEYCODE_F3_GREEN), 342 new KeycodeEntry(KeyEvent.KEYCODE_PROG_YELLOW, CEC_KEYCODE_F4_YELLOW), 343 new KeycodeEntry(KeyEvent.KEYCODE_F5, CEC_KEYCODE_F5), 344 new KeycodeEntry(KeyEvent.KEYCODE_TV_DATA_SERVICE, CEC_KEYCODE_DATA), 345 // RESERVED 346 // Add a new key mapping here if new keycode is introduced. 347 }; 348 349 /** 350 * Translate Android keycode to Hdmi Cec keycode. 351 * 352 * @param keycode Android keycode. For details, refer {@link KeyEvent} 353 * @return single byte CEC keycode if matched. 354 */ 355 static int androidKeyToCecKey(int keycode) { 356 for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { 357 int cecKeycode = KEYCODE_ENTRIES[i].toCecKeycodeIfMatched(keycode); 358 if (cecKeycode != UNSUPPORTED_KEYCODE) { 359 return cecKeycode; 360 } 361 } 362 return UNSUPPORTED_KEYCODE; 363 } 364 365 /** 366 * Translate Hdmi CEC keycode to Android keycode. 367 * 368 * @param keycode CEC keycode 369 * @return cec keycode corresponding to the given android keycode. 370 * If finds no matched keycode, return {@link #UNSUPPORTED_KEYCODE} 371 */ 372 static int cecKeyToAndroidKey(int keycode) { 373 for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { 374 int androidKey = KEYCODE_ENTRIES[i].toAndroidKeycodeIfMatched(keycode); 375 if (androidKey != UNSUPPORTED_KEYCODE) { 376 return androidKey; 377 } 378 } 379 return UNSUPPORTED_KEYCODE; 380 } 381 382 /** 383 * Whether the given {@code androidKeycode} is repeatable key or not. 384 * 385 * @param androidKeycode keycode of android 386 * @return false if the given {@code androidKeycode} is not supported key code 387 */ 388 static boolean isRepeatableKey(int androidKeycode) { 389 for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { 390 Boolean isRepeatable = KEYCODE_ENTRIES[i].isRepeatableIfMatched(androidKeycode); 391 if (isRepeatable != null) { 392 return isRepeatable; 393 } 394 } 395 return false; 396 } 397 398 /** 399 * Returns {@code true} if given Android keycode is supported, otherwise {@code false}. 400 */ 401 static boolean isSupportedKeycode(int androidKeycode) { 402 return HdmiCecKeycode.androidKeyToCecKey(androidKeycode) 403 != HdmiCecKeycode.UNSUPPORTED_KEYCODE; 404 } 405 } 406