Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +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 | |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 19 | import android.hardware.hdmi.HdmiDeviceInfo; |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 20 | import android.hardware.input.InputManager; |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 21 | import android.os.Handler; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 22 | import android.os.Looper; |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 23 | import android.os.Message; |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 24 | import android.os.SystemClock; |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 25 | import android.util.Slog; |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 26 | import android.view.InputDevice; |
| 27 | import android.view.KeyCharacterMap; |
| 28 | import android.view.KeyEvent; |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 29 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 30 | import com.android.internal.annotations.GuardedBy; |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 31 | import com.android.internal.util.IndentingPrintWriter; |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 32 | import com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 33 | |
| 34 | import java.util.ArrayList; |
Jinsuk Kim | 43c23e2 | 2014-07-29 13:59:14 +0900 | [diff] [blame] | 35 | import java.util.Collections; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 36 | import java.util.Iterator; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 37 | import java.util.List; |
| 38 | |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 39 | /** |
| 40 | * Class that models a logical CEC device hosted in this system. Handles initialization, |
| 41 | * CEC commands that call for actions customized per device type. |
| 42 | */ |
| 43 | abstract class HdmiCecLocalDevice { |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 44 | private static final String TAG = "HdmiCecLocalDevice"; |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 45 | |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 46 | private static final int MSG_DISABLE_DEVICE_TIMEOUT = 1; |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 47 | private static final int MSG_USER_CONTROL_RELEASE_TIMEOUT = 2; |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 48 | // Timeout in millisecond for device clean up (5s). |
| 49 | // Normal actions timeout is 2s but some of them would have several sequence of timeout. |
| 50 | private static final int DEVICE_CLEANUP_TIMEOUT = 5000; |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 51 | // Within the timer, a received <User Control Pressed> will start "Press and Hold" behavior. |
| 52 | // When it expires, we can assume <User Control Release> is received. |
| 53 | private static final int FOLLOWER_SAFETY_TIMEOUT = 550; |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 54 | |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 55 | protected final HdmiControlService mService; |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 56 | protected final int mDeviceType; |
| 57 | protected int mAddress; |
| 58 | protected int mPreferredAddress; |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 59 | protected HdmiDeviceInfo mDeviceInfo; |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 60 | protected int mLastKeycode = HdmiCecKeycode.UNSUPPORTED_KEYCODE; |
| 61 | protected int mLastKeyRepeatCount = 0; |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 62 | |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 63 | static class ActiveSource { |
| 64 | int logicalAddress; |
| 65 | int physicalAddress; |
| 66 | |
Jinsuk Kim | 43c23e2 | 2014-07-29 13:59:14 +0900 | [diff] [blame] | 67 | public ActiveSource() { |
| 68 | invalidate(); |
| 69 | } |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 70 | public ActiveSource(int logical, int physical) { |
| 71 | logicalAddress = logical; |
| 72 | physicalAddress = physical; |
| 73 | } |
Jinsuk Kim | 04f813c | 2015-04-02 16:56:49 +0900 | [diff] [blame] | 74 | public static ActiveSource of(ActiveSource source) { |
| 75 | return new ActiveSource(source.logicalAddress, source.physicalAddress); |
| 76 | } |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 77 | public static ActiveSource of(int logical, int physical) { |
| 78 | return new ActiveSource(logical, physical); |
| 79 | } |
| 80 | public boolean isValid() { |
| 81 | return HdmiUtils.isValidAddress(logicalAddress); |
| 82 | } |
Jinsuk Kim | 43c23e2 | 2014-07-29 13:59:14 +0900 | [diff] [blame] | 83 | public void invalidate() { |
| 84 | logicalAddress = Constants.ADDR_INVALID; |
| 85 | physicalAddress = Constants.INVALID_PHYSICAL_ADDRESS; |
| 86 | } |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 87 | public boolean equals(int logical, int physical) { |
| 88 | return logicalAddress == logical && physicalAddress == physical; |
| 89 | } |
| 90 | @Override |
| 91 | public boolean equals(Object obj) { |
| 92 | if (obj instanceof ActiveSource) { |
| 93 | ActiveSource that = (ActiveSource) obj; |
| 94 | return that.logicalAddress == logicalAddress && |
| 95 | that.physicalAddress == physicalAddress; |
| 96 | } |
| 97 | return false; |
| 98 | } |
| 99 | @Override |
| 100 | public int hashCode() { |
| 101 | return logicalAddress * 29 + physicalAddress; |
| 102 | } |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 103 | @Override |
| 104 | public String toString() { |
| 105 | StringBuffer s = new StringBuffer(); |
| 106 | String logicalAddressString = (logicalAddress == Constants.ADDR_INVALID) |
| 107 | ? "invalid" : String.format("0x%02x", logicalAddress); |
Jinsuk Kim | 04f813c | 2015-04-02 16:56:49 +0900 | [diff] [blame] | 108 | s.append("(").append(logicalAddressString); |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 109 | String physicalAddressString = (physicalAddress == Constants.INVALID_PHYSICAL_ADDRESS) |
| 110 | ? "invalid" : String.format("0x%04x", physicalAddress); |
Jinsuk Kim | 04f813c | 2015-04-02 16:56:49 +0900 | [diff] [blame] | 111 | s.append(", ").append(physicalAddressString).append(")"); |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 112 | return s.toString(); |
| 113 | } |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 114 | } |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 115 | // Logical address of the active source. |
| 116 | @GuardedBy("mLock") |
Jinsuk Kim | 43c23e2 | 2014-07-29 13:59:14 +0900 | [diff] [blame] | 117 | protected final ActiveSource mActiveSource = new ActiveSource(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 118 | |
| 119 | // Active routing path. Physical address of the active source but not all the time, such as |
| 120 | // when the new active source does not claim itself to be one. Note that we don't keep |
| 121 | // the active port id (or active input) since it can be gotten by {@link #pathToPortId(int)}. |
| 122 | @GuardedBy("mLock") |
| 123 | private int mActiveRoutingPath; |
| 124 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 125 | protected final HdmiCecMessageCache mCecMessageCache = new HdmiCecMessageCache(); |
| 126 | protected final Object mLock; |
| 127 | |
| 128 | // A collection of FeatureAction. |
| 129 | // Note that access to this collection should happen in service thread. |
Jungshik Jang | 5352081c | 2014-09-22 15:14:49 +0900 | [diff] [blame] | 130 | private final ArrayList<HdmiCecFeatureAction> mActions = new ArrayList<>(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 131 | |
Yuncheol Heo | c516d65 | 2014-07-11 18:23:24 +0900 | [diff] [blame] | 132 | private final Handler mHandler = new Handler () { |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 133 | @Override |
| 134 | public void handleMessage(Message msg) { |
| 135 | switch (msg.what) { |
| 136 | case MSG_DISABLE_DEVICE_TIMEOUT: |
| 137 | handleDisableDeviceTimeout(); |
| 138 | break; |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 139 | case MSG_USER_CONTROL_RELEASE_TIMEOUT: |
| 140 | handleUserControlReleased(); |
| 141 | break; |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | /** |
| 147 | * A callback interface to get notified when all pending action is cleared. |
| 148 | * It can be called when timeout happened. |
| 149 | */ |
| 150 | interface PendingActionClearedCallback { |
| 151 | void onCleared(HdmiCecLocalDevice device); |
| 152 | } |
| 153 | |
| 154 | protected PendingActionClearedCallback mPendingActionClearedCallback; |
| 155 | |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 156 | protected HdmiCecLocalDevice(HdmiControlService service, int deviceType) { |
| 157 | mService = service; |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 158 | mDeviceType = deviceType; |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 159 | mAddress = Constants.ADDR_UNREGISTERED; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 160 | mLock = service.getServiceLock(); |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | // Factory method that returns HdmiCecLocalDevice of corresponding type. |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 164 | static HdmiCecLocalDevice create(HdmiControlService service, int deviceType) { |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 165 | switch (deviceType) { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 166 | case HdmiDeviceInfo.DEVICE_TV: |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 167 | return new HdmiCecLocalDeviceTv(service); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 168 | case HdmiDeviceInfo.DEVICE_PLAYBACK: |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 169 | return new HdmiCecLocalDevicePlayback(service); |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 170 | default: |
| 171 | return null; |
| 172 | } |
| 173 | } |
| 174 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 175 | @ServiceThreadOnly |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 176 | void init() { |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 177 | assertRunOnServiceThread(); |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 178 | mPreferredAddress = getPreferredAddress(); |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 179 | } |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 180 | |
Jungshik Jang | 8b308d9 | 2014-05-29 21:52:28 +0900 | [diff] [blame] | 181 | /** |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 182 | * Called once a logical address of the local device is allocated. |
Jungshik Jang | 8b308d9 | 2014-05-29 21:52:28 +0900 | [diff] [blame] | 183 | */ |
Yuncheol Heo | fc44e4e | 2014-08-04 19:41:09 +0900 | [diff] [blame] | 184 | protected abstract void onAddressAllocated(int logicalAddress, int reason); |
Jungshik Jang | 8b308d9 | 2014-05-29 21:52:28 +0900 | [diff] [blame] | 185 | |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 186 | /** |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 187 | * Get the preferred logical address from system properties. |
| 188 | */ |
| 189 | protected abstract int getPreferredAddress(); |
| 190 | |
| 191 | /** |
| 192 | * Set the preferred logical address to system properties. |
| 193 | */ |
| 194 | protected abstract void setPreferredAddress(int addr); |
| 195 | |
| 196 | /** |
Jinsuk Kim | 6e26f7f | 2015-01-07 16:45:14 +0900 | [diff] [blame] | 197 | * Returns true if the TV input associated with the CEC device is ready |
| 198 | * to accept further processing such as input switching. This is used |
| 199 | * to buffer certain CEC commands and process it later if the input is not |
| 200 | * ready yet. For other types of local devices(non-TV), this method returns |
| 201 | * true by default to let the commands be processed right away. |
| 202 | */ |
| 203 | protected boolean isInputReady(int deviceId) { |
| 204 | return true; |
| 205 | } |
| 206 | |
| 207 | /** |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 208 | * Returns true if the local device allows the system to be put to standby. |
| 209 | * The default implementation returns true. |
| 210 | */ |
| 211 | protected boolean canGoToStandby() { |
| 212 | return true; |
| 213 | } |
| 214 | |
| 215 | /** |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 216 | * Dispatch incoming message. |
| 217 | * |
| 218 | * @param message incoming message |
| 219 | * @return true if consumed a message; otherwise, return false. |
| 220 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 221 | @ServiceThreadOnly |
Yuncheol Heo | 25c2029 | 2014-07-31 17:59:39 +0900 | [diff] [blame] | 222 | boolean dispatchMessage(HdmiCecMessage message) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 223 | assertRunOnServiceThread(); |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 224 | int dest = message.getDestination(); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 225 | if (dest != mAddress && dest != Constants.ADDR_BROADCAST) { |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 226 | return false; |
| 227 | } |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 228 | // Cache incoming message. Note that it caches only white-listed one. |
| 229 | mCecMessageCache.cacheMessage(message); |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 230 | return onMessage(message); |
| 231 | } |
| 232 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 233 | @ServiceThreadOnly |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 234 | protected final boolean onMessage(HdmiCecMessage message) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 235 | assertRunOnServiceThread(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 236 | if (dispatchMessageToAction(message)) { |
| 237 | return true; |
| 238 | } |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 239 | switch (message.getOpcode()) { |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 240 | case Constants.MESSAGE_ACTIVE_SOURCE: |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 241 | return handleActiveSource(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 242 | case Constants.MESSAGE_INACTIVE_SOURCE: |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 243 | return handleInactiveSource(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 244 | case Constants.MESSAGE_REQUEST_ACTIVE_SOURCE: |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 245 | return handleRequestActiveSource(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 246 | case Constants.MESSAGE_GET_MENU_LANGUAGE: |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 247 | return handleGetMenuLanguage(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 248 | case Constants.MESSAGE_GIVE_PHYSICAL_ADDRESS: |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 249 | return handleGivePhysicalAddress(); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 250 | case Constants.MESSAGE_GIVE_OSD_NAME: |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 251 | return handleGiveOsdName(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 252 | case Constants.MESSAGE_GIVE_DEVICE_VENDOR_ID: |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 253 | return handleGiveDeviceVendorId(); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 254 | case Constants.MESSAGE_GET_CEC_VERSION: |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 255 | return handleGetCecVersion(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 256 | case Constants.MESSAGE_REPORT_PHYSICAL_ADDRESS: |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 257 | return handleReportPhysicalAddress(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 258 | case Constants.MESSAGE_ROUTING_CHANGE: |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 259 | return handleRoutingChange(message); |
Yuncheol Heo | 64bafd9 | 2014-08-11 11:17:54 +0900 | [diff] [blame] | 260 | case Constants.MESSAGE_ROUTING_INFORMATION: |
| 261 | return handleRoutingInformation(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 262 | case Constants.MESSAGE_INITIATE_ARC: |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 263 | return handleInitiateArc(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 264 | case Constants.MESSAGE_TERMINATE_ARC: |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 265 | return handleTerminateArc(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 266 | case Constants.MESSAGE_SET_SYSTEM_AUDIO_MODE: |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 267 | return handleSetSystemAudioMode(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 268 | case Constants.MESSAGE_SYSTEM_AUDIO_MODE_STATUS: |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 269 | return handleSystemAudioModeStatus(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 270 | case Constants.MESSAGE_REPORT_AUDIO_STATUS: |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 271 | return handleReportAudioStatus(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 272 | case Constants.MESSAGE_STANDBY: |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 273 | return handleStandby(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 274 | case Constants.MESSAGE_TEXT_VIEW_ON: |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 275 | return handleTextViewOn(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 276 | case Constants.MESSAGE_IMAGE_VIEW_ON: |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 277 | return handleImageViewOn(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 278 | case Constants.MESSAGE_USER_CONTROL_PRESSED: |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 279 | return handleUserControlPressed(message); |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 280 | case Constants.MESSAGE_USER_CONTROL_RELEASED: |
| 281 | return handleUserControlReleased(); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 282 | case Constants.MESSAGE_SET_STREAM_PATH: |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 283 | return handleSetStreamPath(message); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 284 | case Constants.MESSAGE_GIVE_DEVICE_POWER_STATUS: |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 285 | return handleGiveDevicePowerStatus(message); |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 286 | case Constants.MESSAGE_MENU_REQUEST: |
Yuncheol Heo | 184b124 | 2014-09-12 15:09:07 +0900 | [diff] [blame] | 287 | return handleMenuRequest(message); |
| 288 | case Constants.MESSAGE_MENU_STATUS: |
| 289 | return handleMenuStatus(message); |
Jinsuk Kim | 119160a | 2014-07-07 18:48:10 +0900 | [diff] [blame] | 290 | case Constants.MESSAGE_VENDOR_COMMAND: |
| 291 | return handleVendorCommand(message); |
| 292 | case Constants.MESSAGE_VENDOR_COMMAND_WITH_ID: |
| 293 | return handleVendorCommandWithId(message); |
Jungshik Jang | 8f2ed35 | 2014-07-07 15:02:47 +0900 | [diff] [blame] | 294 | case Constants.MESSAGE_SET_OSD_NAME: |
| 295 | return handleSetOsdName(message); |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 296 | case Constants.MESSAGE_RECORD_TV_SCREEN: |
| 297 | return handleRecordTvScreen(message); |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 298 | case Constants.MESSAGE_TIMER_CLEARED_STATUS: |
| 299 | return handleTimerClearedStatus(message); |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 300 | case Constants.MESSAGE_REPORT_POWER_STATUS: |
| 301 | return handleReportPowerStatus(message); |
| 302 | case Constants.MESSAGE_TIMER_STATUS: |
| 303 | return handleTimerStatus(message); |
| 304 | case Constants.MESSAGE_RECORD_STATUS: |
| 305 | return handleRecordStatus(message); |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 306 | default: |
| 307 | return false; |
| 308 | } |
| 309 | } |
| 310 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 311 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 312 | private boolean dispatchMessageToAction(HdmiCecMessage message) { |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 313 | assertRunOnServiceThread(); |
Jungshik Jang | 5352081c | 2014-09-22 15:14:49 +0900 | [diff] [blame] | 314 | boolean processed = false; |
| 315 | // Use copied action list in that processCommand may remove itself. |
| 316 | for (HdmiCecFeatureAction action : new ArrayList<>(mActions)) { |
| 317 | // Iterates all actions to check whether incoming message is consumed. |
| 318 | boolean result = action.processCommand(message); |
| 319 | processed = processed || result; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 320 | } |
Jungshik Jang | 5352081c | 2014-09-22 15:14:49 +0900 | [diff] [blame] | 321 | return processed; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 322 | } |
| 323 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 324 | @ServiceThreadOnly |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 325 | protected boolean handleGivePhysicalAddress() { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 326 | assertRunOnServiceThread(); |
| 327 | |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 328 | int physicalAddress = mService.getPhysicalAddress(); |
| 329 | HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( |
| 330 | mAddress, physicalAddress, mDeviceType); |
| 331 | mService.sendCecCommand(cecMessage); |
| 332 | return true; |
| 333 | } |
| 334 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 335 | @ServiceThreadOnly |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 336 | protected boolean handleGiveDeviceVendorId() { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 337 | assertRunOnServiceThread(); |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 338 | int vendorId = mService.getVendorId(); |
| 339 | HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildDeviceVendorIdCommand( |
| 340 | mAddress, vendorId); |
| 341 | mService.sendCecCommand(cecMessage); |
| 342 | return true; |
| 343 | } |
| 344 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 345 | @ServiceThreadOnly |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 346 | protected boolean handleGetCecVersion(HdmiCecMessage message) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 347 | assertRunOnServiceThread(); |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 348 | int version = mService.getCecVersion(); |
| 349 | HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildCecVersion(message.getDestination(), |
| 350 | message.getSource(), version); |
| 351 | mService.sendCecCommand(cecMessage); |
| 352 | return true; |
| 353 | } |
| 354 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 355 | @ServiceThreadOnly |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 356 | protected boolean handleActiveSource(HdmiCecMessage message) { |
| 357 | return false; |
| 358 | } |
| 359 | |
| 360 | @ServiceThreadOnly |
| 361 | protected boolean handleInactiveSource(HdmiCecMessage message) { |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | @ServiceThreadOnly |
| 366 | protected boolean handleRequestActiveSource(HdmiCecMessage message) { |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | @ServiceThreadOnly |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 371 | protected boolean handleGetMenuLanguage(HdmiCecMessage message) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 372 | assertRunOnServiceThread(); |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 373 | Slog.w(TAG, "Only TV can handle <Get Menu Language>:" + message.toString()); |
Yuncheol Heo | 6aae652 | 2014-08-05 14:48:37 +0900 | [diff] [blame] | 374 | // 'return false' will cause to reply with <Feature Abort>. |
| 375 | return false; |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 376 | } |
| 377 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 378 | @ServiceThreadOnly |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 379 | protected boolean handleGiveOsdName(HdmiCecMessage message) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 380 | assertRunOnServiceThread(); |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 381 | // Note that since this method is called after logical address allocation is done, |
| 382 | // mDeviceInfo should not be null. |
| 383 | HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildSetOsdNameCommand( |
| 384 | mAddress, message.getSource(), mDeviceInfo.getDisplayName()); |
| 385 | if (cecMessage != null) { |
| 386 | mService.sendCecCommand(cecMessage); |
| 387 | } else { |
| 388 | Slog.w(TAG, "Failed to build <Get Osd Name>:" + mDeviceInfo.getDisplayName()); |
| 389 | } |
| 390 | return true; |
| 391 | } |
| 392 | |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 393 | protected boolean handleRoutingChange(HdmiCecMessage message) { |
| 394 | return false; |
| 395 | } |
| 396 | |
Yuncheol Heo | 64bafd9 | 2014-08-11 11:17:54 +0900 | [diff] [blame] | 397 | protected boolean handleRoutingInformation(HdmiCecMessage message) { |
| 398 | return false; |
| 399 | } |
| 400 | |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 401 | protected boolean handleReportPhysicalAddress(HdmiCecMessage message) { |
| 402 | return false; |
| 403 | } |
| 404 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 405 | protected boolean handleSystemAudioModeStatus(HdmiCecMessage message) { |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | protected boolean handleSetSystemAudioMode(HdmiCecMessage message) { |
| 410 | return false; |
| 411 | } |
| 412 | |
| 413 | protected boolean handleTerminateArc(HdmiCecMessage message) { |
| 414 | return false; |
| 415 | } |
| 416 | |
| 417 | protected boolean handleInitiateArc(HdmiCecMessage message) { |
| 418 | return false; |
| 419 | } |
| 420 | |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 421 | protected boolean handleReportAudioStatus(HdmiCecMessage message) { |
| 422 | return false; |
| 423 | } |
| 424 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 425 | @ServiceThreadOnly |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 426 | protected boolean handleStandby(HdmiCecMessage message) { |
| 427 | assertRunOnServiceThread(); |
| 428 | // Seq #12 |
Jinsuk Kim | 4d43d93 | 2014-07-03 16:43:58 +0900 | [diff] [blame] | 429 | if (mService.isControlEnabled() && !mService.isProhibitMode() |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 430 | && mService.isPowerOnOrTransient()) { |
| 431 | mService.standby(); |
| 432 | return true; |
| 433 | } |
| 434 | return false; |
| 435 | } |
| 436 | |
| 437 | @ServiceThreadOnly |
| 438 | protected boolean handleUserControlPressed(HdmiCecMessage message) { |
| 439 | assertRunOnServiceThread(); |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 440 | mHandler.removeMessages(MSG_USER_CONTROL_RELEASE_TIMEOUT); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 441 | if (mService.isPowerOnOrTransient() && isPowerOffOrToggleCommand(message)) { |
| 442 | mService.standby(); |
| 443 | return true; |
| 444 | } else if (mService.isPowerStandbyOrTransient() && isPowerOnOrToggleCommand(message)) { |
| 445 | mService.wakeUp(); |
| 446 | return true; |
| 447 | } |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 448 | |
| 449 | final long downTime = SystemClock.uptimeMillis(); |
| 450 | final byte[] params = message.getParams(); |
Jungshik Jang | 73483b6b | 2014-09-26 14:00:59 +0900 | [diff] [blame] | 451 | final int keycode = HdmiCecKeycode.cecKeycodeAndParamsToAndroidKey(params); |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 452 | int keyRepeatCount = 0; |
| 453 | if (mLastKeycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) { |
| 454 | if (keycode == mLastKeycode) { |
| 455 | keyRepeatCount = mLastKeyRepeatCount + 1; |
| 456 | } else { |
| 457 | injectKeyEvent(downTime, KeyEvent.ACTION_UP, mLastKeycode, 0); |
| 458 | } |
| 459 | } |
| 460 | mLastKeycode = keycode; |
| 461 | mLastKeyRepeatCount = keyRepeatCount; |
| 462 | |
| 463 | if (keycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) { |
| 464 | injectKeyEvent(downTime, KeyEvent.ACTION_DOWN, keycode, keyRepeatCount); |
| 465 | mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_USER_CONTROL_RELEASE_TIMEOUT), |
| 466 | FOLLOWER_SAFETY_TIMEOUT); |
| 467 | return true; |
| 468 | } |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 469 | return false; |
| 470 | } |
| 471 | |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 472 | @ServiceThreadOnly |
| 473 | protected boolean handleUserControlReleased() { |
| 474 | assertRunOnServiceThread(); |
| 475 | mHandler.removeMessages(MSG_USER_CONTROL_RELEASE_TIMEOUT); |
| 476 | mLastKeyRepeatCount = 0; |
| 477 | if (mLastKeycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) { |
| 478 | final long upTime = SystemClock.uptimeMillis(); |
| 479 | injectKeyEvent(upTime, KeyEvent.ACTION_UP, mLastKeycode, 0); |
| 480 | mLastKeycode = HdmiCecKeycode.UNSUPPORTED_KEYCODE; |
| 481 | return true; |
| 482 | } |
| 483 | return false; |
| 484 | } |
| 485 | |
| 486 | static void injectKeyEvent(long time, int action, int keycode, int repeat) { |
| 487 | KeyEvent keyEvent = KeyEvent.obtain(time, time, action, keycode, |
| 488 | repeat, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, |
| 489 | InputDevice.SOURCE_HDMI, null); |
| 490 | InputManager.getInstance().injectInputEvent(keyEvent, |
| 491 | InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); |
| 492 | keyEvent.recycle(); |
| 493 | } |
| 494 | |
Yuncheol Heo | 25c2029 | 2014-07-31 17:59:39 +0900 | [diff] [blame] | 495 | static boolean isPowerOnOrToggleCommand(HdmiCecMessage message) { |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 496 | byte[] params = message.getParams(); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 497 | return message.getOpcode() == Constants.MESSAGE_USER_CONTROL_PRESSED |
Jungshik Jang | 210d73d | 2014-07-04 11:11:29 +0900 | [diff] [blame] | 498 | && (params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER |
| 499 | || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_ON_FUNCTION |
| 500 | || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_TOGGLE_FUNCTION); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 501 | } |
| 502 | |
Yuncheol Heo | 25c2029 | 2014-07-31 17:59:39 +0900 | [diff] [blame] | 503 | static boolean isPowerOffOrToggleCommand(HdmiCecMessage message) { |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 504 | byte[] params = message.getParams(); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 505 | return message.getOpcode() == Constants.MESSAGE_USER_CONTROL_PRESSED |
Jungshik Jang | 210d73d | 2014-07-04 11:11:29 +0900 | [diff] [blame] | 506 | && (params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER |
| 507 | || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_OFF_FUNCTION |
| 508 | || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_TOGGLE_FUNCTION); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | protected boolean handleTextViewOn(HdmiCecMessage message) { |
| 512 | return false; |
| 513 | } |
| 514 | |
| 515 | protected boolean handleImageViewOn(HdmiCecMessage message) { |
| 516 | return false; |
| 517 | } |
| 518 | |
| 519 | protected boolean handleSetStreamPath(HdmiCecMessage message) { |
| 520 | return false; |
| 521 | } |
| 522 | |
| 523 | protected boolean handleGiveDevicePowerStatus(HdmiCecMessage message) { |
| 524 | mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPowerStatus( |
| 525 | mAddress, message.getSource(), mService.getPowerStatus())); |
| 526 | return true; |
| 527 | } |
| 528 | |
Yuncheol Heo | 184b124 | 2014-09-12 15:09:07 +0900 | [diff] [blame] | 529 | protected boolean handleMenuRequest(HdmiCecMessage message) { |
Terry Heo | 3e1564e | 2014-08-12 14:41:00 +0900 | [diff] [blame] | 530 | // Always report menu active to receive Remote Control. |
| 531 | mService.sendCecCommand(HdmiCecMessageBuilder.buildReportMenuStatus( |
| 532 | mAddress, message.getSource(), Constants.MENU_STATE_ACTIVATED)); |
| 533 | return true; |
| 534 | } |
| 535 | |
Yuncheol Heo | 184b124 | 2014-09-12 15:09:07 +0900 | [diff] [blame] | 536 | protected boolean handleMenuStatus(HdmiCecMessage message) { |
| 537 | return false; |
| 538 | } |
| 539 | |
Jinsuk Kim | 119160a | 2014-07-07 18:48:10 +0900 | [diff] [blame] | 540 | protected boolean handleVendorCommand(HdmiCecMessage message) { |
Yuncheol Heo | 0608b93 | 2014-10-13 16:39:18 +0900 | [diff] [blame] | 541 | if (!mService.invokeVendorCommandListenersOnReceived(mDeviceType, message.getSource(), |
| 542 | message.getDestination(), message.getParams(), false)) { |
Jinsuk Kim | d4a94db | 2014-09-12 13:51:10 +0900 | [diff] [blame] | 543 | // Vendor command listener may not have been registered yet. Respond with |
| 544 | // <Feature Abort> [NOT_IN_CORRECT_MODE] so that the sender can try again later. |
| 545 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_NOT_IN_CORRECT_MODE); |
| 546 | } |
Jinsuk Kim | 119160a | 2014-07-07 18:48:10 +0900 | [diff] [blame] | 547 | return true; |
| 548 | } |
| 549 | |
| 550 | protected boolean handleVendorCommandWithId(HdmiCecMessage message) { |
| 551 | byte[] params = message.getParams(); |
| 552 | int vendorId = HdmiUtils.threeBytesToInt(params); |
| 553 | if (vendorId == mService.getVendorId()) { |
Yuncheol Heo | 0608b93 | 2014-10-13 16:39:18 +0900 | [diff] [blame] | 554 | if (!mService.invokeVendorCommandListenersOnReceived(mDeviceType, message.getSource(), |
| 555 | message.getDestination(), params, true)) { |
Jinsuk Kim | d4a94db | 2014-09-12 13:51:10 +0900 | [diff] [blame] | 556 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_NOT_IN_CORRECT_MODE); |
| 557 | } |
Jinsuk Kim | 119160a | 2014-07-07 18:48:10 +0900 | [diff] [blame] | 558 | } else if (message.getDestination() != Constants.ADDR_BROADCAST && |
| 559 | message.getSource() != Constants.ADDR_UNREGISTERED) { |
| 560 | Slog.v(TAG, "Wrong direct vendor command. Replying with <Feature Abort>"); |
Yuncheol Heo | 6aae652 | 2014-08-05 14:48:37 +0900 | [diff] [blame] | 561 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_UNRECOGNIZED_OPCODE); |
Jinsuk Kim | 119160a | 2014-07-07 18:48:10 +0900 | [diff] [blame] | 562 | } else { |
| 563 | Slog.v(TAG, "Wrong broadcast vendor command. Ignoring"); |
| 564 | } |
| 565 | return true; |
| 566 | } |
| 567 | |
Jinsuk Kim | d4a94db | 2014-09-12 13:51:10 +0900 | [diff] [blame] | 568 | protected void sendStandby(int deviceId) { |
| 569 | // Do nothing. |
| 570 | } |
| 571 | |
Jungshik Jang | 8f2ed35 | 2014-07-07 15:02:47 +0900 | [diff] [blame] | 572 | protected boolean handleSetOsdName(HdmiCecMessage message) { |
| 573 | // The default behavior of <Set Osd Name> is doing nothing. |
| 574 | return true; |
| 575 | } |
| 576 | |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 577 | protected boolean handleRecordTvScreen(HdmiCecMessage message) { |
Yuncheol Heo | 25c2029 | 2014-07-31 17:59:39 +0900 | [diff] [blame] | 578 | // The default behavior of <Record TV Screen> is replying <Feature Abort> with |
| 579 | // "Cannot provide source". |
Yuncheol Heo | 6aae652 | 2014-08-05 14:48:37 +0900 | [diff] [blame] | 580 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_CANNOT_PROVIDE_SOURCE); |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 581 | return true; |
| 582 | } |
| 583 | |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 584 | protected boolean handleTimerClearedStatus(HdmiCecMessage message) { |
| 585 | return false; |
| 586 | } |
| 587 | |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 588 | protected boolean handleReportPowerStatus(HdmiCecMessage message) { |
| 589 | return false; |
| 590 | } |
| 591 | |
| 592 | protected boolean handleTimerStatus(HdmiCecMessage message) { |
| 593 | return false; |
| 594 | } |
| 595 | |
| 596 | protected boolean handleRecordStatus(HdmiCecMessage message) { |
| 597 | return false; |
| 598 | } |
| 599 | |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 600 | @ServiceThreadOnly |
Yuncheol Heo | fc44e4e | 2014-08-04 19:41:09 +0900 | [diff] [blame] | 601 | final void handleAddressAllocated(int logicalAddress, int reason) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 602 | assertRunOnServiceThread(); |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 603 | mAddress = mPreferredAddress = logicalAddress; |
Yuncheol Heo | fc44e4e | 2014-08-04 19:41:09 +0900 | [diff] [blame] | 604 | onAddressAllocated(logicalAddress, reason); |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 605 | setPreferredAddress(logicalAddress); |
Jungshik Jang | 1a4485d | 2014-05-26 11:02:36 +0900 | [diff] [blame] | 606 | } |
| 607 | |
Yuncheol Heo | b502186 | 2014-09-02 10:36:04 +0900 | [diff] [blame] | 608 | int getType() { |
| 609 | return mDeviceType; |
| 610 | } |
| 611 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 612 | @ServiceThreadOnly |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 613 | HdmiDeviceInfo getDeviceInfo() { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 614 | assertRunOnServiceThread(); |
Jungshik Jang | 1a4485d | 2014-05-26 11:02:36 +0900 | [diff] [blame] | 615 | return mDeviceInfo; |
| 616 | } |
| 617 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 618 | @ServiceThreadOnly |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 619 | void setDeviceInfo(HdmiDeviceInfo info) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 620 | assertRunOnServiceThread(); |
Jungshik Jang | 1a4485d | 2014-05-26 11:02:36 +0900 | [diff] [blame] | 621 | mDeviceInfo = info; |
| 622 | } |
| 623 | |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 624 | // Returns true if the logical address is same as the argument. |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 625 | @ServiceThreadOnly |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 626 | boolean isAddressOf(int addr) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 627 | assertRunOnServiceThread(); |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 628 | return addr == mAddress; |
| 629 | } |
| 630 | |
| 631 | // Resets the logical address to unregistered(15), meaning the logical device is invalid. |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 632 | @ServiceThreadOnly |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 633 | void clearAddress() { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 634 | assertRunOnServiceThread(); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 635 | mAddress = Constants.ADDR_UNREGISTERED; |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 636 | } |
| 637 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 638 | @ServiceThreadOnly |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 639 | void addAndStartAction(final HdmiCecFeatureAction action) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 640 | assertRunOnServiceThread(); |
Jinsuk Kim | 6f87b4e | 2014-10-10 14:40:29 +0900 | [diff] [blame] | 641 | mActions.add(action); |
Jinsuk Kim | a5445ce | 2015-03-30 17:14:58 +0900 | [diff] [blame] | 642 | if (mService.isPowerStandby()) { |
Jinsuk Kim | 6f87b4e | 2014-10-10 14:40:29 +0900 | [diff] [blame] | 643 | Slog.i(TAG, "Not ready to start action. Queued for deferred start:" + action); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 644 | return; |
| 645 | } |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 646 | action.start(); |
| 647 | } |
| 648 | |
Jinsuk Kim | 6f87b4e | 2014-10-10 14:40:29 +0900 | [diff] [blame] | 649 | @ServiceThreadOnly |
| 650 | void startQueuedActions() { |
| 651 | assertRunOnServiceThread(); |
| 652 | for (HdmiCecFeatureAction action : mActions) { |
| 653 | if (!action.started()) { |
| 654 | Slog.i(TAG, "Starting queued action:" + action); |
| 655 | action.start(); |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 660 | // See if we have an action of a given type in progress. |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 661 | @ServiceThreadOnly |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 662 | <T extends HdmiCecFeatureAction> boolean hasAction(final Class<T> clazz) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 663 | assertRunOnServiceThread(); |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 664 | for (HdmiCecFeatureAction action : mActions) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 665 | if (action.getClass().equals(clazz)) { |
| 666 | return true; |
| 667 | } |
| 668 | } |
| 669 | return false; |
| 670 | } |
| 671 | |
| 672 | // Returns all actions matched with given class type. |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 673 | @ServiceThreadOnly |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 674 | <T extends HdmiCecFeatureAction> List<T> getActions(final Class<T> clazz) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 675 | assertRunOnServiceThread(); |
Jinsuk Kim | 43c23e2 | 2014-07-29 13:59:14 +0900 | [diff] [blame] | 676 | List<T> actions = Collections.<T>emptyList(); |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 677 | for (HdmiCecFeatureAction action : mActions) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 678 | if (action.getClass().equals(clazz)) { |
Jinsuk Kim | 43c23e2 | 2014-07-29 13:59:14 +0900 | [diff] [blame] | 679 | if (actions.isEmpty()) { |
| 680 | actions = new ArrayList<T>(); |
| 681 | } |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 682 | actions.add((T) action); |
| 683 | } |
| 684 | } |
| 685 | return actions; |
| 686 | } |
| 687 | |
| 688 | /** |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 689 | * Remove the given {@link HdmiCecFeatureAction} object from the action queue. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 690 | * |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 691 | * @param action {@link HdmiCecFeatureAction} to remove |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 692 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 693 | @ServiceThreadOnly |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 694 | void removeAction(final HdmiCecFeatureAction action) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 695 | assertRunOnServiceThread(); |
Yuncheol Heo | c516d65 | 2014-07-11 18:23:24 +0900 | [diff] [blame] | 696 | action.finish(false); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 697 | mActions.remove(action); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 698 | checkIfPendingActionsCleared(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | // Remove all actions matched with the given Class type. |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 702 | @ServiceThreadOnly |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 703 | <T extends HdmiCecFeatureAction> void removeAction(final Class<T> clazz) { |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 704 | assertRunOnServiceThread(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 705 | removeActionExcept(clazz, null); |
| 706 | } |
| 707 | |
| 708 | // Remove all actions matched with the given Class type besides |exception|. |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 709 | @ServiceThreadOnly |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 710 | <T extends HdmiCecFeatureAction> void removeActionExcept(final Class<T> clazz, |
| 711 | final HdmiCecFeatureAction exception) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 712 | assertRunOnServiceThread(); |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 713 | Iterator<HdmiCecFeatureAction> iter = mActions.iterator(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 714 | while (iter.hasNext()) { |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 715 | HdmiCecFeatureAction action = iter.next(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 716 | if (action != exception && action.getClass().equals(clazz)) { |
Yuncheol Heo | c516d65 | 2014-07-11 18:23:24 +0900 | [diff] [blame] | 717 | action.finish(false); |
| 718 | iter.remove(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 719 | } |
| 720 | } |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 721 | checkIfPendingActionsCleared(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 722 | } |
| 723 | |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 724 | protected void checkIfPendingActionsCleared() { |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 725 | if (mActions.isEmpty() && mPendingActionClearedCallback != null) { |
Yuncheol Heo | 26ba7fd | 2014-07-29 18:21:25 +0900 | [diff] [blame] | 726 | PendingActionClearedCallback callback = mPendingActionClearedCallback; |
| 727 | // To prevent from calling the callback again during handling the callback itself. |
| 728 | mPendingActionClearedCallback = null; |
| 729 | callback.onCleared(this); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 730 | } |
| 731 | } |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 732 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 733 | protected void assertRunOnServiceThread() { |
| 734 | if (Looper.myLooper() != mService.getServiceLooper()) { |
| 735 | throw new IllegalStateException("Should run on service thread."); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * Called when a hot-plug event issued. |
| 741 | * |
| 742 | * @param portId id of port where a hot-plug event happened |
| 743 | * @param connected whether to connected or not on the event |
| 744 | */ |
| 745 | void onHotplug(int portId, boolean connected) { |
| 746 | } |
| 747 | |
| 748 | final HdmiControlService getService() { |
| 749 | return mService; |
| 750 | } |
| 751 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 752 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 753 | final boolean isConnectedToArcPort(int path) { |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 754 | assertRunOnServiceThread(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 755 | return mService.isConnectedToArcPort(path); |
| 756 | } |
| 757 | |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 758 | ActiveSource getActiveSource() { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 759 | synchronized (mLock) { |
| 760 | return mActiveSource; |
| 761 | } |
| 762 | } |
| 763 | |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 764 | void setActiveSource(ActiveSource newActive) { |
| 765 | setActiveSource(newActive.logicalAddress, newActive.physicalAddress); |
| 766 | } |
| 767 | |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 768 | void setActiveSource(HdmiDeviceInfo info) { |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 769 | setActiveSource(info.getLogicalAddress(), info.getPhysicalAddress()); |
| 770 | } |
| 771 | |
| 772 | void setActiveSource(int logicalAddress, int physicalAddress) { |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 773 | synchronized (mLock) { |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 774 | mActiveSource.logicalAddress = logicalAddress; |
| 775 | mActiveSource.physicalAddress = physicalAddress; |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 776 | } |
Jinsuk Kim | e9f6ed3 | 2014-08-20 17:45:22 +0900 | [diff] [blame] | 777 | mService.setLastInputForMhl(Constants.INVALID_PORT_ID); |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 778 | } |
| 779 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 780 | int getActivePath() { |
| 781 | synchronized (mLock) { |
| 782 | return mActiveRoutingPath; |
| 783 | } |
| 784 | } |
| 785 | |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 786 | void setActivePath(int path) { |
| 787 | synchronized (mLock) { |
| 788 | mActiveRoutingPath = path; |
| 789 | } |
Jungshik Jang | 867b4e0 | 2014-08-12 13:41:30 +0900 | [diff] [blame] | 790 | mService.setActivePortId(pathToPortId(path)); |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 791 | } |
| 792 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 793 | /** |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 794 | * Returns the ID of the active HDMI port. The active port is the one that has the active |
| 795 | * routing path connected to it directly or indirectly under the device hierarchy. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 796 | */ |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 797 | int getActivePortId() { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 798 | synchronized (mLock) { |
| 799 | return mService.pathToPortId(mActiveRoutingPath); |
| 800 | } |
| 801 | } |
| 802 | |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 803 | /** |
| 804 | * Update the active port. |
| 805 | * |
| 806 | * @param portId the new active port id |
| 807 | */ |
| 808 | void setActivePortId(int portId) { |
Jungshik Jang | 867b4e0 | 2014-08-12 13:41:30 +0900 | [diff] [blame] | 809 | // We update active routing path instead, since we get the active port id from |
| 810 | // the active routing path. |
| 811 | setActivePath(mService.portIdToPath(portId)); |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 812 | } |
| 813 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 814 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 815 | HdmiCecMessageCache getCecMessageCache() { |
| 816 | assertRunOnServiceThread(); |
| 817 | return mCecMessageCache; |
| 818 | } |
| 819 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 820 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 821 | int pathToPortId(int newPath) { |
| 822 | assertRunOnServiceThread(); |
| 823 | return mService.pathToPortId(newPath); |
| 824 | } |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 825 | |
| 826 | /** |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 827 | * Called when the system goes to standby mode. |
| 828 | * |
| 829 | * @param initiatedByCec true if this power sequence is initiated |
Jungshik Jang | b3e114a | 2014-07-11 17:50:05 +0900 | [diff] [blame] | 830 | * by the reception the CEC messages like <Standby> |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 831 | */ |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 832 | protected void onStandby(boolean initiatedByCec) {} |
| 833 | |
| 834 | /** |
| 835 | * Disable device. {@code callback} is used to get notified when all pending |
| 836 | * actions are completed or timeout is issued. |
| 837 | * |
| 838 | * @param initiatedByCec true if this sequence is initiated |
Jungshik Jang | b3e114a | 2014-07-11 17:50:05 +0900 | [diff] [blame] | 839 | * by the reception the CEC messages like <Standby> |
| 840 | * @param origialCallback callback interface to get notified when all pending actions are |
| 841 | * cleared |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 842 | */ |
Jungshik Jang | b3e114a | 2014-07-11 17:50:05 +0900 | [diff] [blame] | 843 | protected void disableDevice(boolean initiatedByCec, |
| 844 | final PendingActionClearedCallback origialCallback) { |
| 845 | mPendingActionClearedCallback = new PendingActionClearedCallback() { |
| 846 | @Override |
| 847 | public void onCleared(HdmiCecLocalDevice device) { |
| 848 | mHandler.removeMessages(MSG_DISABLE_DEVICE_TIMEOUT); |
| 849 | origialCallback.onCleared(device); |
| 850 | } |
| 851 | }; |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 852 | mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_DISABLE_DEVICE_TIMEOUT), |
| 853 | DEVICE_CLEANUP_TIMEOUT); |
| 854 | } |
| 855 | |
| 856 | @ServiceThreadOnly |
| 857 | private void handleDisableDeviceTimeout() { |
| 858 | assertRunOnServiceThread(); |
| 859 | |
| 860 | // If all actions are not cleared in DEVICE_CLEANUP_TIMEOUT, enforce to finish them. |
| 861 | // onCleard will be called at the last action's finish method. |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 862 | Iterator<HdmiCecFeatureAction> iter = mActions.iterator(); |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 863 | while (iter.hasNext()) { |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 864 | HdmiCecFeatureAction action = iter.next(); |
Yuncheol Heo | c516d65 | 2014-07-11 18:23:24 +0900 | [diff] [blame] | 865 | action.finish(false); |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 866 | iter.remove(); |
| 867 | } |
| 868 | } |
Jinsuk Kim | c068bb5 | 2014-07-07 16:59:20 +0900 | [diff] [blame] | 869 | |
| 870 | /** |
| 871 | * Send a key event to other device. |
| 872 | * |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 873 | * @param keyCode key code defined in {@link android.view.KeyEvent} |
Jinsuk Kim | c068bb5 | 2014-07-07 16:59:20 +0900 | [diff] [blame] | 874 | * @param isPressed {@code true} for key down event |
| 875 | */ |
| 876 | protected void sendKeyEvent(int keyCode, boolean isPressed) { |
| 877 | Slog.w(TAG, "sendKeyEvent not implemented"); |
| 878 | } |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 879 | |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 880 | void sendUserControlPressedAndReleased(int targetAddress, int cecKeycode) { |
| 881 | mService.sendCecCommand(HdmiCecMessageBuilder.buildUserControlPressed( |
| 882 | mAddress, targetAddress, cecKeycode)); |
| 883 | mService.sendCecCommand(HdmiCecMessageBuilder.buildUserControlReleased( |
| 884 | mAddress, targetAddress)); |
| 885 | } |
| 886 | |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 887 | /** |
| 888 | * Dump internal status of HdmiCecLocalDevice object. |
| 889 | */ |
| 890 | protected void dump(final IndentingPrintWriter pw) { |
| 891 | pw.println("mDeviceType: " + mDeviceType); |
| 892 | pw.println("mAddress: " + mAddress); |
| 893 | pw.println("mPreferredAddress: " + mPreferredAddress); |
| 894 | pw.println("mDeviceInfo: " + mDeviceInfo); |
| 895 | pw.println("mActiveSource: " + mActiveSource); |
| 896 | pw.println(String.format("mActiveRoutingPath: 0x%04x", mActiveRoutingPath)); |
| 897 | } |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 898 | } |