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 | |
| 21 | /** |
| 22 | * Helper class to translate android keycode to hdmi cec keycode and vice versa. |
| 23 | */ |
Jungshik Jang | 4612a6e | 2014-08-12 22:01:23 +0900 | [diff] [blame^] | 24 | final class HdmiCecKeycode { |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 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 | |
Jungshik Jang | cd3445c | 2014-06-16 13:34:56 +0900 | [diff] [blame] | 154 | private HdmiCecKeycode() { |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /** |
| 158 | * A mapping between andorid 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 int mParam; |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 178 | private final boolean mIsRepeatable; |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 179 | |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 180 | private KeycodeEntry(int androidKeycode, int cecKeycode, int param, boolean isRepeatable) { |
| 181 | mAndroidKeycode = androidKeycode; |
| 182 | mCecKeycode = cecKeycode; |
| 183 | mParam = param; |
| 184 | mIsRepeatable = isRepeatable; |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | private KeycodeEntry(int androidKeycode, int cecKeycode) { |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 188 | this(androidKeycode, cecKeycode, NO_PARAM, true); |
| 189 | } |
| 190 | |
| 191 | private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable) { |
| 192 | this(androidKeycode, cecKeycode, NO_PARAM, isRepeatable); |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | private byte[] toCecKeycodeIfMatched(int androidKeycode) { |
| 196 | if (mAndroidKeycode == androidKeycode) { |
| 197 | if (mParam == NO_PARAM) { |
| 198 | return new byte[] { |
| 199 | (byte) (mCecKeycode & 0xFF) |
| 200 | }; |
| 201 | } else { |
| 202 | return new byte[] { |
| 203 | (byte) (mCecKeycode & 0xFF), |
| 204 | (byte) (mParam & 0xFF) |
| 205 | }; |
| 206 | } |
| 207 | } else { |
| 208 | return null; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | private int toAndroidKeycodeIfMatched(int cecKeycode, int param) { |
| 213 | if (cecKeycode == mCecKeycode && mParam == param) { |
| 214 | return mAndroidKeycode; |
| 215 | } else { |
| 216 | return UNSUPPORTED_KEYCODE; |
| 217 | } |
| 218 | } |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 219 | |
| 220 | private Boolean isRepeatableIfMatched(int androidKeycode) { |
| 221 | if (mAndroidKeycode == androidKeycode) { |
| 222 | return mIsRepeatable; |
| 223 | } else { |
| 224 | return null; |
| 225 | } |
| 226 | } |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // Keycode entry container for all mappings. |
| 230 | // Note that order of entry is the same as above cec keycode definition. |
| 231 | private static final KeycodeEntry[] KEYCODE_ENTRIES = new KeycodeEntry[] { |
| 232 | new KeycodeEntry(KeyEvent.KEYCODE_DPAD_CENTER, CEC_KEYCODE_SELECT), |
| 233 | new KeycodeEntry(KeyEvent.KEYCODE_DPAD_UP, CEC_KEYCODE_UP), |
| 234 | new KeycodeEntry(KeyEvent.KEYCODE_DPAD_DOWN, CEC_KEYCODE_DOWN), |
| 235 | new KeycodeEntry(KeyEvent.KEYCODE_DPAD_LEFT, CEC_KEYCODE_LEFT), |
| 236 | new KeycodeEntry(KeyEvent.KEYCODE_DPAD_RIGHT, CEC_KEYCODE_RIGHT), |
| 237 | // No Android keycode defined for CEC_KEYCODE_RIGHT_UP |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 238 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RIGHT_UP), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 239 | // No Android keycode defined for CEC_KEYCODE_RIGHT_DOWN |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 240 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RIGHT_DOWN), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 241 | // No Android keycode defined for CEC_KEYCODE_LEFT_UP |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 242 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_LEFT_UP), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 243 | // No Android keycode defined for CEC_KEYCODE_LEFT_DOWN |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 244 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_LEFT_DOWN), |
| 245 | new KeycodeEntry(KeyEvent.KEYCODE_HOME, CEC_KEYCODE_ROOT_MENU, false), |
| 246 | new KeycodeEntry(KeyEvent.KEYCODE_SETTINGS, CEC_KEYCODE_SETUP_MENU, false), |
| 247 | new KeycodeEntry(KeyEvent.KEYCODE_MENU, CEC_KEYCODE_CONTENTS_MENU, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 248 | // No Android keycode defined for CEC_KEYCODE_FAVORITE_MENU |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 249 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_FAVORITE_MENU), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 250 | new KeycodeEntry(KeyEvent.KEYCODE_BACK, CEC_KEYCODE_EXIT), |
| 251 | // RESERVED |
| 252 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_TOP_MENU, CEC_KEYCODE_MEDIA_TOP_MENU), |
| 253 | // No Android keycode defined for CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 254 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 255 | // RESERVED |
| 256 | // No Android keycode defined for CEC_KEYCODE_NUMBER_ENTRY_MODE |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 257 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_NUMBER_ENTRY_MODE), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 258 | new KeycodeEntry(KeyEvent.KEYCODE_11, CEC_KEYCODE_NUMBER_11), |
| 259 | new KeycodeEntry(KeyEvent.KEYCODE_12, CEC_KEYCODE_NUMBER_12), |
| 260 | new KeycodeEntry(KeyEvent.KEYCODE_0, CEC_KEYCODE_NUMBER_0_OR_NUMBER_10), |
| 261 | new KeycodeEntry(KeyEvent.KEYCODE_1, CEC_KEYCODE_NUMBERS_1), |
| 262 | new KeycodeEntry(KeyEvent.KEYCODE_2, CEC_KEYCODE_NUMBERS_2), |
| 263 | new KeycodeEntry(KeyEvent.KEYCODE_3, CEC_KEYCODE_NUMBERS_3), |
| 264 | new KeycodeEntry(KeyEvent.KEYCODE_4, CEC_KEYCODE_NUMBERS_4), |
| 265 | new KeycodeEntry(KeyEvent.KEYCODE_5, CEC_KEYCODE_NUMBERS_5), |
| 266 | new KeycodeEntry(KeyEvent.KEYCODE_6, CEC_KEYCODE_NUMBERS_6), |
| 267 | new KeycodeEntry(KeyEvent.KEYCODE_7, CEC_KEYCODE_NUMBERS_7), |
| 268 | new KeycodeEntry(KeyEvent.KEYCODE_8, CEC_KEYCODE_NUMBERS_8), |
| 269 | new KeycodeEntry(KeyEvent.KEYCODE_9, CEC_KEYCODE_NUMBERS_9), |
| 270 | new KeycodeEntry(KeyEvent.KEYCODE_PERIOD, CEC_KEYCODE_DOT), |
| 271 | new KeycodeEntry(KeyEvent.KEYCODE_NUMPAD_ENTER, CEC_KEYCODE_ENTER), |
| 272 | new KeycodeEntry(KeyEvent.KEYCODE_CLEAR, CEC_KEYCODE_CLEAR), |
| 273 | // RESERVED |
| 274 | // No Android keycode defined for CEC_KEYCODE_NEXT_FAVORITE |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 275 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_NEXT_FAVORITE), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 276 | new KeycodeEntry(KeyEvent.KEYCODE_CHANNEL_UP, CEC_KEYCODE_CHANNEL_UP), |
| 277 | new KeycodeEntry(KeyEvent.KEYCODE_CHANNEL_DOWN, CEC_KEYCODE_CHANNEL_DOWN), |
| 278 | new KeycodeEntry(KeyEvent.KEYCODE_LAST_CHANNEL, CEC_KEYCODE_PREVIOUS_CHANNEL), |
| 279 | // No Android keycode defined for CEC_KEYCODE_SOUND_SELECT |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 280 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SOUND_SELECT), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 281 | new KeycodeEntry(KeyEvent.KEYCODE_TV_INPUT, CEC_KEYCODE_INPUT_SELECT), |
| 282 | new KeycodeEntry(KeyEvent.KEYCODE_INFO, CEC_KEYCODE_DISPLAY_INFORMATION), |
| 283 | // No Android keycode defined for CEC_KEYCODE_HELP |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 284 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_HELP), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 285 | new KeycodeEntry(KeyEvent.KEYCODE_PAGE_UP, CEC_KEYCODE_PAGE_UP), |
| 286 | new KeycodeEntry(KeyEvent.KEYCODE_PAGE_DOWN, CEC_KEYCODE_PAGE_DOWN), |
| 287 | // RESERVED |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 288 | new KeycodeEntry(KeyEvent.KEYCODE_POWER, CEC_KEYCODE_POWER, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 289 | new KeycodeEntry(KeyEvent.KEYCODE_VOLUME_UP, CEC_KEYCODE_VOLUME_UP), |
| 290 | new KeycodeEntry(KeyEvent.KEYCODE_VOLUME_DOWN, CEC_KEYCODE_VOLUME_DOWN), |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 291 | new KeycodeEntry(KeyEvent.KEYCODE_VOLUME_MUTE, CEC_KEYCODE_MUTE, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 292 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PLAY, CEC_KEYCODE_PLAY), |
| 293 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_STOP, CEC_KEYCODE_STOP), |
| 294 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PAUSE, CEC_KEYCODE_PAUSE), |
| 295 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_RECORD, CEC_KEYCODE_RECORD), |
| 296 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_REWIND, CEC_KEYCODE_REWIND), |
| 297 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, CEC_KEYCODE_FAST_FORWARD), |
| 298 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_EJECT, CEC_KEYCODE_EJECT), |
| 299 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_NEXT, CEC_KEYCODE_FORWARD), |
| 300 | new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PREVIOUS, CEC_KEYCODE_BACKWARD), |
| 301 | // No Android keycode defined for CEC_KEYCODE_STOP_RECORD |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 302 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_STOP_RECORD), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 303 | // No Android keycode defined for CEC_KEYCODE_PAUSE_RECORD |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 304 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PAUSE_RECORD), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 305 | // No Android keycode defined for CEC_KEYCODE_RESERVED |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 306 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RESERVED), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 307 | // No Android keycode defined for CEC_KEYCODE_ANGLE |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 308 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_ANGLE), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 309 | // No Android keycode defined for CEC_KEYCODE_SUB_PICTURE |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 310 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SUB_PICTURE), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 311 | // No Android keycode defined for CEC_KEYCODE_VIDEO_ON_DEMAND |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 312 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_VIDEO_ON_DEMAND), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 313 | new KeycodeEntry(KeyEvent.KEYCODE_GUIDE, CEC_KEYCODE_ELECTRONIC_PROGRAM_GUIDE), |
| 314 | // No Android keycode defined for CEC_KEYCODE_TIMER_PROGRAMMING |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 315 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_TIMER_PROGRAMMING), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 316 | // No Android keycode defined for CEC_KEYCODE_INITIAL_CONFIGURATION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 317 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_INITIAL_CONFIGURATION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 318 | // No Android keycode defined for CEC_KEYCODE_SELECT_BROADCAST_TYPE |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 319 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_BROADCAST_TYPE), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 320 | // No Android keycode defined for CEC_KEYCODE_SELECT_SOUND_PRESENTATION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 321 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_SOUND_PRESENTATION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 322 | // RESERVED |
| 323 | // The following deterministic key definitions do not need key mapping |
| 324 | // since they are supposed to be generated programmatically only. |
| 325 | // No Android keycode defined for CEC_KEYCODE_PLAY_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 326 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PLAY_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 327 | // No Android keycode defined for CEC_KEYCODE_PAUSE_PLAY_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 328 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PAUSE_PLAY_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 329 | // No Android keycode defined for CEC_KEYCODE_RECORD_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 330 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RECORD_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 331 | // No Android keycode defined for CEC_KEYCODE_PAUSE_RECORD_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 332 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_PAUSE_RECORD_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 333 | // No Android keycode defined for CEC_KEYCODE_STOP_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 334 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_STOP_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 335 | // No Android keycode defined for CEC_KEYCODE_MUTE_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 336 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_MUTE_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 337 | // No Android keycode defined for CEC_KEYCODE_RESTORE_VOLUME_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 338 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RESTORE_VOLUME_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 339 | // No Android keycode defined for CEC_KEYCODE_TUNE_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 340 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_TUNE_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 341 | // No Android keycode defined for CEC_KEYCODE_SELECT_MEDIA_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 342 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_MEDIA_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 343 | // No Android keycode defined for CEC_KEYCODE_SELECT_AV_INPUT_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 344 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_AV_INPUT_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 345 | // No Android keycode defined for CEC_KEYCODE_SELECT_AUDIO_INPUT_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 346 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_AUDIO_INPUT_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 347 | // No Android keycode defined for CEC_KEYCODE_POWER_TOGGLE_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 348 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_POWER_TOGGLE_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 349 | // No Android keycode defined for CEC_KEYCODE_POWER_OFF_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 350 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_POWER_OFF_FUNCTION), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 351 | // No Android keycode defined for CEC_KEYCODE_POWER_ON_FUNCTION |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 352 | new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_POWER_ON_FUNCTION, false), |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 353 | // RESERVED |
| 354 | new KeycodeEntry(KeyEvent.KEYCODE_PROG_BLUE, CEC_KEYCODE_F1_BLUE), |
| 355 | new KeycodeEntry(KeyEvent.KEYCODE_PROG_RED, CEC_KEYCODE_F2_RED), |
| 356 | new KeycodeEntry(KeyEvent.KEYCODE_PROG_GREEN, CEC_KEYCODE_F3_GREEN), |
| 357 | new KeycodeEntry(KeyEvent.KEYCODE_PROG_YELLOW, CEC_KEYCODE_F4_YELLOW), |
| 358 | new KeycodeEntry(KeyEvent.KEYCODE_F5, CEC_KEYCODE_F5), |
| 359 | new KeycodeEntry(KeyEvent.KEYCODE_TV_DATA_SERVICE, CEC_KEYCODE_DATA), |
| 360 | // RESERVED |
| 361 | // Add a new key mapping here if new keycode is introduced. |
| 362 | }; |
| 363 | |
| 364 | /** |
| 365 | * Translate Android keycode to Hdmi Cec keycode. |
| 366 | * |
| 367 | * @param keycode Android keycode. For details, refer {@link KeyEvent} |
| 368 | * @return array of byte which contains cec keycode and param if it has; |
| 369 | * return null if failed to find matched cec keycode |
| 370 | */ |
| 371 | static byte[] androidKeyToCecKey(int keycode) { |
| 372 | for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { |
| 373 | byte[] cecKeycode = KEYCODE_ENTRIES[i].toCecKeycodeIfMatched(keycode); |
| 374 | if (cecKeycode != null) { |
| 375 | return cecKeycode; |
| 376 | } |
| 377 | } |
| 378 | return null; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Translate Hdmi CEC keycode to Android keycode. |
| 383 | * |
| 384 | * @param keycode Cec keycode. If has no param, put {@link #NO_PARAM} |
| 385 | * @return cec keycode corresponding to the given android keycode. |
| 386 | * If finds no matched keycode, return {@link #UNSUPPORTED_KEYCODE} |
| 387 | */ |
| 388 | static int cecKeyToAndroidKey(int keycode, int param) { |
| 389 | for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { |
| 390 | int androidKey = KEYCODE_ENTRIES[i].toAndroidKeycodeIfMatched(keycode, param); |
| 391 | if (androidKey != UNSUPPORTED_KEYCODE) { |
| 392 | return androidKey; |
| 393 | } |
| 394 | } |
| 395 | return UNSUPPORTED_KEYCODE; |
| 396 | } |
Jungshik Jang | 250cda5 | 2014-07-02 17:32:22 +0900 | [diff] [blame] | 397 | |
| 398 | /** |
| 399 | * Whether the given {@code androidKeycode} is repeatable key or not. |
| 400 | * |
| 401 | * @param androidKeycode keycode of android |
| 402 | * @return false if the given {@code androidKeycode} is not supported key code |
| 403 | */ |
| 404 | static boolean isRepeatableKey(int androidKeycode) { |
| 405 | for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { |
| 406 | Boolean isRepeatable = KEYCODE_ENTRIES[i].isRepeatableIfMatched(androidKeycode); |
| 407 | if (isRepeatable != null) { |
| 408 | return isRepeatable; |
| 409 | } |
| 410 | } |
| 411 | return false; |
| 412 | } |
Jungshik Jang | 65c64c3 | 2014-06-10 20:20:33 +0900 | [diff] [blame] | 413 | } |