Jinsuk Kim | 4f512fb | 2014-02-28 17:41:17 +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 android.hardware.hdmi; |
| 18 | |
| 19 | /** |
| 20 | * Defines constants and utility methods related to HDMI-CEC protocol. |
| 21 | */ |
| 22 | public final class HdmiCec { |
| 23 | |
| 24 | /** TV device type. */ |
| 25 | public static final int DEVICE_TV = 0; |
| 26 | |
| 27 | /** Recording device type. */ |
| 28 | public static final int DEVICE_RECORDER = 1; |
| 29 | |
| 30 | /** Device type reserved for future usage. */ |
| 31 | public static final int DEVICE_RESERVED = 2; |
| 32 | |
| 33 | /** Tuner device type. */ |
| 34 | public static final int DEVICE_TUNER = 3; |
| 35 | |
| 36 | /** Playback device type. */ |
| 37 | public static final int DEVICE_PLAYBACK = 4; |
| 38 | |
| 39 | /** Audio system device type. */ |
| 40 | public static final int DEVICE_AUDIO_SYSTEM = 5; |
| 41 | |
| 42 | // Value indicating the device is not an active source. |
| 43 | public static final int DEVICE_INACTIVE = -1; |
| 44 | |
| 45 | /** Logical address for TV */ |
| 46 | public static final int ADDR_TV = 0; |
| 47 | |
| 48 | /** Logical address for recorder 1 */ |
| 49 | public static final int ADDR_RECORDER_1 = 1; |
| 50 | |
| 51 | /** Logical address for recorder 2 */ |
| 52 | public static final int ADDR_RECORDER_2 = 2; |
| 53 | |
| 54 | /** Logical address for tuner 1 */ |
| 55 | public static final int ADDR_TUNER_1 = 3; |
| 56 | |
| 57 | /** Logical address for playback 1 */ |
| 58 | public static final int ADDR_PLAYBACK_1 = 4; |
| 59 | |
| 60 | /** Logical address for audio system */ |
| 61 | public static final int ADDR_AUDIO_SYSTEM = 5; |
| 62 | |
| 63 | /** Logical address for tuner 2 */ |
| 64 | public static final int ADDR_TUNER_2 = 6; |
| 65 | |
| 66 | /** Logical address for tuner 3 */ |
| 67 | public static final int ADDR_TUNER_3 = 7; |
| 68 | |
| 69 | /** Logical address for playback 2 */ |
| 70 | public static final int ADDR_PLAYBACK_2 = 8; |
| 71 | |
| 72 | /** Logical address for recorder 3 */ |
| 73 | public static final int ADDR_RECORDER_3 = 9; |
| 74 | |
| 75 | /** Logical address for tuner 4 */ |
| 76 | public static final int ADDR_TUNER_4 = 10; |
| 77 | |
| 78 | /** Logical address for playback 3 */ |
| 79 | public static final int ADDR_PLAYBACK_3 = 11; |
| 80 | |
| 81 | /** Logical address reserved for future usage */ |
| 82 | public static final int ADDR_RESERVED_1 = 12; |
| 83 | |
| 84 | /** Logical address reserved for future usage */ |
| 85 | public static final int ADDR_RESERVED_2 = 13; |
| 86 | |
| 87 | /** Logical address for TV other than the one assigned with {@link #ADDR_TV} */ |
| 88 | public static final int ADDR_FREE_USE = 14; |
| 89 | |
| 90 | /** Logical address for devices to which address cannot be allocated */ |
| 91 | public static final int ADDR_UNREGISTERED = 15; |
| 92 | |
| 93 | /** Logical address used in the destination address field for broadcast messages */ |
| 94 | public static final int ADDR_BROADCAST = 15; |
| 95 | |
| 96 | /** Logical address used to indicate it is not initialized or invalid. */ |
| 97 | public static final int ADDR_INVALID = -1; |
| 98 | |
| 99 | // TODO: Complete the list of CEC messages definition. |
Jinsuk Kim | fbcd503 | 2014-03-21 16:25:13 +0900 | [diff] [blame] | 100 | public static final int MESSAGE_FEATURE_ABORT = 0x00; |
| 101 | public static final int MESSAGE_IMAGE_VIEW_ON = 0x04; |
| 102 | public static final int MESSAGE_TUNER_STEP_INCREMENT = 0x05; |
| 103 | public static final int MESSAGE_TUNER_STEP_DECREMENT = 0x06; |
| 104 | public static final int MESSAGE_TUNER_DEVICE_STATUS = 0x07; |
| 105 | public static final int MESSAGE_GIVE_TUNER_DEVICE_STATUS = 0x08; |
| 106 | public static final int MESSAGE_RECORD_ON = 0x09; |
| 107 | public static final int MESSAGE_RECORD_STATUS = 0x0A; |
| 108 | public static final int MESSAGE_RECORD_OFF = 0x0B; |
| 109 | public static final int MESSAGE_TEXT_VIEW_ON = 0x0D; |
| 110 | public static final int MESSAGE_RECORD_TV_SCREEN = 0x0F; |
| 111 | public static final int MESSAGE_GIVE_DECK_STATUS = 0x1A; |
| 112 | public static final int MESSAGE_DECK_STATUS = 0x1B; |
| 113 | public static final int MESSAGE_SET_MENU_LANGUAGE = 0x32; |
| 114 | public static final int MESSAGE_CLEAR_ANALOG_TIMER = 0x33; |
| 115 | public static final int MESSAGE_SET_ANALOG_TIMER = 0x34; |
| 116 | public static final int MESSAGE_TIMER_STATUS = 0x35; |
| 117 | public static final int MESSAGE_STANDBY = 0x36; |
| 118 | public static final int MESSAGE_PLAY = 0x41; |
| 119 | public static final int MESSAGE_DECK_CONTROL = 0x42; |
| 120 | public static final int MESSAGE_TIMER_CLEARED_STATUS = 0x043; |
| 121 | public static final int MESSAGE_USER_CONTROL_PRESSED = 0x44; |
| 122 | public static final int MESSAGE_USER_CONTROL_RELEASED = 0x45; |
| 123 | public static final int MESSAGE_GET_OSD_NAME = 0x46; |
| 124 | public static final int MESSAGE_SET_OSD_NAME = 0x47; |
| 125 | public static final int MESSAGE_SET_OSD_STRING = 0x64; |
| 126 | public static final int MESSAGE_SET_TIMER_PROGRAM_TITLE = 0x67; |
| 127 | public static final int MESSAGE_SYSTEM_AUDIO_MODE_REQUEST = 0x70; |
| 128 | public static final int MESSAGE_GIVE_AUDIO_STATUS = 0x71; |
| 129 | public static final int MESSAGE_SET_SYSTEM_AUDIO_MODE = 0x72; |
| 130 | public static final int MESSAGE_REPORT_AUDIO_STATUS = 0x7A; |
| 131 | public static final int MESSAGE_GIVE_SYSTEM_AUDIO_MODE_STATUS = 0x7D; |
| 132 | public static final int MESSAGE_SYSTEM_AUDIO_MODE_STATUS = 0x7E; |
| 133 | public static final int MESSAGE_ROUTING_CHANGE = 0x80; |
| 134 | public static final int MESSAGE_ROUTING_INFORMATION = 0x81; |
| 135 | public static final int MESSAGE_ACTIVE_SOURCE = 0x82; |
| 136 | public static final int MESSAGE_GIVE_PHYSICAL_ADDRESS = 0x83; |
| 137 | public static final int MESSAGE_REPORT_PHYSICAL_ADDRESS = 0x84; |
| 138 | public static final int MESSAGE_REQUEST_ACTIVE_SOURCE = 0x85; |
| 139 | public static final int MESSAGE_SET_STREAM_PATH = 0x86; |
| 140 | public static final int MESSAGE_DEVICE_VENDOR_ID = 0x87; |
| 141 | public static final int MESSAGE_VENDOR_COMMAND = 0x89; |
| 142 | public static final int MESSAGE_VENDOR_REMOTE_BUTTON_DOWN = 0x8A; |
| 143 | public static final int MESSAGE_VENDOR_REMOTE_BUTTON_UP = 0x8B; |
| 144 | public static final int MESSAGE_GIVE_DEVICE_VENDOR_ID = 0x8C; |
| 145 | public static final int MESSAGE_MENU_REQUEST = 0x8D; |
| 146 | public static final int MESSAGE_MENU_STATUS = 0x8E; |
| 147 | public static final int MESSAGE_GIVE_DEVICE_POWER_STATUS = 0x8F; |
| 148 | public static final int MESSAGE_REPORT_POWER_STATUS = 0x90; |
| 149 | public static final int MESSAGE_GET_MENU_LANGUAGE = 0x91; |
| 150 | public static final int MESSAGE_SELECT_ANALOG_SERVICE = 0x92; |
| 151 | public static final int MESSAGE_SELECT_DIGITAL_SERVICE = 0x93; |
| 152 | public static final int MESSAGE_SET_DIGITAL_TIMER = 0x97; |
| 153 | public static final int MESSAGE_CLEAR_DIGITAL_TIMER = 0x99; |
| 154 | public static final int MESSAGE_SET_AUDIO_RATE = 0x9A; |
| 155 | public static final int MESSAGE_INACTIVE_SOURCE = 0x9D; |
| 156 | public static final int MESSAGE_CEC_VERSION = 0x9E; |
| 157 | public static final int MESSAGE_GET_CEC_VERSION = 0x9F; |
| 158 | public static final int MESSAGE_VENDOR_COMMAND_WITH_ID = 0xA0; |
| 159 | public static final int MESSAGE_CLEAR_EXTERNAL_TIMER = 0xA1; |
| 160 | public static final int MESSAGE_SET_EXTERNAL_TIMER = 0xA2; |
| 161 | public static final int MESSAGE_ABORT = 0xFF; |
Jinsuk Kim | 4f512fb | 2014-02-28 17:41:17 +0900 | [diff] [blame] | 162 | |
| 163 | private static final int[] ADDRESS_TO_TYPE = { |
| 164 | DEVICE_TV, // ADDR_TV |
| 165 | DEVICE_RECORDER, // ADDR_RECORDER_1 |
| 166 | DEVICE_RECORDER, // ADDR_RECORDER_2 |
| 167 | DEVICE_TUNER, // ADDR_TUNER_1 |
| 168 | DEVICE_PLAYBACK, // ADDR_PLAYBACK_1 |
| 169 | DEVICE_AUDIO_SYSTEM, // ADDR_AUDIO_SYSTEM |
| 170 | DEVICE_TUNER, // ADDR_TUNER_2 |
| 171 | DEVICE_TUNER, // ADDR_TUNER_3 |
| 172 | DEVICE_PLAYBACK, // ADDR_PLAYBACK_2 |
| 173 | DEVICE_RECORDER, // ADDR_RECORDER_3 |
| 174 | DEVICE_TUNER, // ADDR_TUNER_4 |
| 175 | DEVICE_PLAYBACK, // ADDR_PLAYBACK_3 |
| 176 | }; |
| 177 | |
| 178 | private static final String[] DEFAULT_NAMES = { |
| 179 | "TV", |
| 180 | "Recorder_1", |
| 181 | "Recorder_2", |
| 182 | "Tuner_1", |
| 183 | "Playback_1", |
| 184 | "AudioSystem", |
| 185 | "Tuner_2", |
| 186 | "Tuner_3", |
| 187 | "Playback_2", |
| 188 | "Recorder_3", |
| 189 | "Tuner_4", |
| 190 | "Playback_3", |
| 191 | }; |
| 192 | |
| 193 | private HdmiCec() { } // Prevents instantiation. |
| 194 | |
| 195 | /** |
| 196 | * Check if the given type is valid. A valid type is one of the actual |
| 197 | * logical device types defined in the standard ({@link #DEVICE_TV}, |
| 198 | * {@link #DEVICE_PLAYBACK}, {@link #DEVICE_TUNER}, {@link #DEVICE_RECORDER}, |
| 199 | * and {@link #DEVICE_AUDIO_SYSTEM}). |
| 200 | * |
| 201 | * @param type device type |
| 202 | * @return true if the given type is valid |
| 203 | */ |
| 204 | public static boolean isValidType(int type) { |
| 205 | return (DEVICE_TV <= type && type <= DEVICE_AUDIO_SYSTEM) |
| 206 | && type != DEVICE_RESERVED; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Check if the given logical address is valid. A logical address is valid |
| 211 | * if it is one allocated for an actual device which allows communication |
| 212 | * with other logical devices. |
| 213 | * |
| 214 | * @param address logical address |
| 215 | * @return true if the given address is valid |
| 216 | */ |
| 217 | public static boolean isValidAddress(int address) { |
| 218 | // TODO: We leave out the address 'free use(14)' for now. Check this later |
| 219 | // again to make sure it is a valid address for communication. |
| 220 | return (ADDR_TV <= address && address <= ADDR_PLAYBACK_3); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Return the device type for the given logical address. |
| 225 | * |
| 226 | * @param address logical address |
| 227 | * @return device type for the given logical address; DEVICE_INACTIVE |
| 228 | * if the address is not valid. |
| 229 | */ |
| 230 | public static int getTypeFromAddress(int address) { |
| 231 | if (isValidAddress(address)) { |
| 232 | return ADDRESS_TO_TYPE[address]; |
| 233 | } |
| 234 | return DEVICE_INACTIVE; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Return the default device name for a logical address. This is the name |
| 239 | * by which the logical device is known to others until a name is |
| 240 | * set explicitly using HdmiCecService.setOsdName. |
| 241 | * |
| 242 | * @param address logical address |
| 243 | * @return default device name; empty string if the address is not valid |
| 244 | */ |
| 245 | public static String getDefaultDeviceName(int address) { |
| 246 | if (isValidAddress(address)) { |
| 247 | return DEFAULT_NAMES[address]; |
| 248 | } |
| 249 | return ""; |
| 250 | } |
| 251 | } |