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