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 | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 19 | import static android.hardware.hdmi.HdmiControlManager.CLEAR_TIMER_STATUS_CEC_DISABLE; |
| 20 | import static android.hardware.hdmi.HdmiControlManager.CLEAR_TIMER_STATUS_CHECK_RECORDER_CONNECTION; |
| 21 | import static android.hardware.hdmi.HdmiControlManager.CLEAR_TIMER_STATUS_FAIL_TO_CLEAR_SELECTED_SOURCE; |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 22 | import static android.hardware.hdmi.HdmiControlManager.ONE_TOUCH_RECORD_CEC_DISABLED; |
| 23 | import static android.hardware.hdmi.HdmiControlManager.ONE_TOUCH_RECORD_CHECK_RECORDER_CONNECTION; |
| 24 | import static android.hardware.hdmi.HdmiControlManager.ONE_TOUCH_RECORD_FAIL_TO_RECORD_DISPLAYED_SCREEN; |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 25 | import static android.hardware.hdmi.HdmiControlManager.OSD_MESSAGE_ARC_CONNECTED_INVALID_PORT; |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 26 | import static android.hardware.hdmi.HdmiControlManager.TIMER_RECORDING_RESULT_EXTRA_CEC_DISABLED; |
| 27 | import static android.hardware.hdmi.HdmiControlManager.TIMER_RECORDING_RESULT_EXTRA_CHECK_RECORDER_CONNECTION; |
| 28 | import static android.hardware.hdmi.HdmiControlManager.TIMER_RECORDING_RESULT_EXTRA_FAIL_TO_RECORD_SELECTED_SOURCE; |
| 29 | import static android.hardware.hdmi.HdmiControlManager.TIMER_RECORDING_TYPE_ANALOGUE; |
| 30 | import static android.hardware.hdmi.HdmiControlManager.TIMER_RECORDING_TYPE_DIGITAL; |
| 31 | import static android.hardware.hdmi.HdmiControlManager.TIMER_RECORDING_TYPE_EXTERNAL; |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 32 | |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 33 | import android.hardware.hdmi.HdmiControlManager; |
Jinsuk Kim | 5008486 | 2014-08-07 13:11:40 +0900 | [diff] [blame] | 34 | import android.hardware.hdmi.HdmiDeviceInfo; |
Jinsuk Kim | 2ee0d6f | 2015-01-28 17:38:28 +0900 | [diff] [blame] | 35 | import android.hardware.hdmi.HdmiPortInfo; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 36 | import android.hardware.hdmi.HdmiRecordSources; |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 37 | import android.hardware.hdmi.HdmiTimerRecordSources; |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 38 | import android.hardware.hdmi.IHdmiControlCallback; |
Jungshik Jang | b69aafbf | 2014-07-11 16:29:06 +0900 | [diff] [blame] | 39 | import android.media.AudioManager; |
Jungshik Jang | a858d22 | 2014-06-23 17:17:47 +0900 | [diff] [blame] | 40 | import android.media.AudioSystem; |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 41 | import android.media.tv.TvInputInfo; |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 42 | import android.media.tv.TvInputManager.TvInputCallback; |
Jinsuk Kim | a6ce770 | 2014-05-11 06:54:49 +0900 | [diff] [blame] | 43 | import android.os.RemoteException; |
Jinsuk Kim | 7ecfbae | 2014-07-11 14:16:29 +0900 | [diff] [blame] | 44 | import android.provider.Settings.Global; |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 45 | import android.util.ArraySet; |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 46 | import android.util.Slog; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 47 | import android.util.SparseArray; |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 48 | import android.util.SparseBooleanArray; |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 49 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 50 | import com.android.internal.annotations.GuardedBy; |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 51 | import com.android.internal.util.IndentingPrintWriter; |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 52 | import com.android.server.hdmi.DeviceDiscoveryAction.DeviceDiscoveryCallback; |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 53 | import com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly; |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 54 | import com.android.server.hdmi.HdmiControlService.SendMessageCallback; |
Jungshik Jang | 8f2ed35 | 2014-07-07 15:02:47 +0900 | [diff] [blame] | 55 | import java.io.UnsupportedEncodingException; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 56 | import java.util.ArrayList; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 57 | import java.util.Arrays; |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 58 | import java.util.Collection; |
Jinsuk Kim | 0a3316b | 2014-06-14 09:33:55 +0900 | [diff] [blame] | 59 | import java.util.Collections; |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 60 | import java.util.Iterator; |
Jinsuk Kim | 0a3316b | 2014-06-14 09:33:55 +0900 | [diff] [blame] | 61 | import java.util.List; |
Jinsuk Kim | 6e26f7f | 2015-01-07 16:45:14 +0900 | [diff] [blame] | 62 | import java.util.HashMap; |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Represent a logical device of type TV residing in Android system. |
| 66 | */ |
| 67 | final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 68 | private static final String TAG = "HdmiCecLocalDeviceTv"; |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 69 | |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 70 | // Whether ARC is available or not. "true" means that ARC is established between TV and |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 71 | // AVR as audio receiver. |
| 72 | @ServiceThreadOnly |
| 73 | private boolean mArcEstablished = false; |
| 74 | |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 75 | // Stores whether ARC feature is enabled per port. True by default for all the ARC-enabled ports. |
| 76 | private final SparseBooleanArray mArcFeatureEnabled = new SparseBooleanArray(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 77 | |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 78 | // Whether System audio mode is activated or not. |
| 79 | // This becomes true only when all system audio sequences are finished. |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 80 | @GuardedBy("mLock") |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 81 | private boolean mSystemAudioActivated = false; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 82 | |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 83 | // The previous port id (input) before switching to the new one. This is remembered in order to |
| 84 | // be able to switch to it upon receiving <Inactive Source> from currently active source. |
| 85 | // This remains valid only when the active source was switched via one touch play operation |
| 86 | // (either by TV or source device). Manual port switching invalidates this value to |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 87 | // Constants.PORT_INVALID, for which case <Inactive Source> does not do anything. |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 88 | @GuardedBy("mLock") |
| 89 | private int mPrevPortId; |
| 90 | |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 91 | @GuardedBy("mLock") |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 92 | private int mSystemAudioVolume = Constants.UNKNOWN_VOLUME; |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 93 | |
| 94 | @GuardedBy("mLock") |
| 95 | private boolean mSystemAudioMute = false; |
| 96 | |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 97 | // Copy of mDeviceInfos to guarantee thread-safety. |
| 98 | @GuardedBy("mLock") |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 99 | private List<HdmiDeviceInfo> mSafeAllDeviceInfos = Collections.emptyList(); |
Jinsuk Kim | 9c37e1f | 2014-07-02 08:29:26 +0900 | [diff] [blame] | 100 | // All external cec input(source) devices. Does not include system audio device. |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 101 | @GuardedBy("mLock") |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 102 | private List<HdmiDeviceInfo> mSafeExternalInputs = Collections.emptyList(); |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 103 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 104 | // Map-like container of all cec devices including local ones. |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 105 | // device id is used as key of container. |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 106 | // This is not thread-safe. For external purpose use mSafeDeviceInfos. |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 107 | private final SparseArray<HdmiDeviceInfo> mDeviceInfos = new SparseArray<>(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 108 | |
Jinsuk Kim | 160a6e5 | 2014-07-02 06:16:36 +0900 | [diff] [blame] | 109 | // If true, TV going to standby mode puts other devices also to standby. |
| 110 | private boolean mAutoDeviceOff; |
| 111 | |
Jinsuk Kim | 544b62b | 2014-07-14 14:01:23 +0900 | [diff] [blame] | 112 | // If true, TV wakes itself up when receiving <Text/Image View On>. |
| 113 | private boolean mAutoWakeup; |
| 114 | |
Jinsuk Kim | bdf27fb | 2014-10-20 10:00:04 +0900 | [diff] [blame] | 115 | // List of the logical address of local CEC devices. Unmodifiable, thread-safe. |
| 116 | private List<Integer> mLocalDeviceAddresses; |
| 117 | |
Yuncheol Heo | 25c2029 | 2014-07-31 17:59:39 +0900 | [diff] [blame] | 118 | private final HdmiCecStandbyModeHandler mStandbyHandler; |
| 119 | |
Jinsuk Kim | d530719 | 2014-08-22 09:07:40 +0900 | [diff] [blame] | 120 | // If true, do not do routing control/send active source for internal source. |
| 121 | // Set to true when the device was woken up by <Text/Image View On>. |
| 122 | private boolean mSkipRoutingControl; |
| 123 | |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 124 | // Set of physical addresses of CEC switches on the CEC bus. Managed independently from |
| 125 | // other CEC devices since they might not have logical address. |
| 126 | private final ArraySet<Integer> mCecSwitches = new ArraySet<Integer>(); |
| 127 | |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 128 | // Message buffer used to buffer selected messages to process later. <Active Source> |
| 129 | // from a source device, for instance, needs to be buffered if the device is not |
| 130 | // discovered yet. The buffered commands are taken out and when they are ready to |
| 131 | // handle. |
| 132 | private final DelayedMessageBuffer mDelayedMessageBuffer = new DelayedMessageBuffer(this); |
| 133 | |
| 134 | // Defines the callback invoked when TV input framework is updated with input status. |
| 135 | // We are interested in the notification for HDMI input addition event, in order to |
| 136 | // process any CEC commands that arrived before the input is added. |
| 137 | private final TvInputCallback mTvInputCallback = new TvInputCallback() { |
| 138 | @Override |
| 139 | public void onInputAdded(String inputId) { |
| 140 | TvInputInfo tvInfo = mService.getTvInputManager().getTvInputInfo(inputId); |
| 141 | HdmiDeviceInfo info = tvInfo.getHdmiDeviceInfo(); |
Jinsuk Kim | 6e26f7f | 2015-01-07 16:45:14 +0900 | [diff] [blame] | 142 | if (info == null) return; |
| 143 | addTvInput(inputId, info.getId()); |
| 144 | if (info.isCecDevice()) { |
| 145 | processDelayedActiveSource(info.getLogicalAddress()); |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 146 | } |
| 147 | } |
Jinsuk Kim | 6e26f7f | 2015-01-07 16:45:14 +0900 | [diff] [blame] | 148 | |
| 149 | @Override |
| 150 | public void onInputRemoved(String inputId) { |
| 151 | removeTvInput(inputId); |
| 152 | } |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 153 | }; |
| 154 | |
Jinsuk Kim | 6e26f7f | 2015-01-07 16:45:14 +0900 | [diff] [blame] | 155 | // Keeps the mapping (TV input ID, HDMI device ID) to keep track of the TV inputs ready to |
| 156 | // accept input switching request from HDMI devices. Requests for which the corresponding |
| 157 | // input ID is not yet registered by TV input framework need to be buffered for delayed |
| 158 | // processing. |
| 159 | private final HashMap<String, Integer> mTvInputs = new HashMap<>(); |
| 160 | |
| 161 | @ServiceThreadOnly |
| 162 | private void addTvInput(String inputId, int deviceId) { |
| 163 | assertRunOnServiceThread(); |
| 164 | mTvInputs.put(inputId, deviceId); |
| 165 | } |
| 166 | |
| 167 | @ServiceThreadOnly |
| 168 | private void removeTvInput(String inputId) { |
| 169 | assertRunOnServiceThread(); |
| 170 | mTvInputs.remove(inputId); |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | @ServiceThreadOnly |
| 175 | protected boolean isInputReady(int deviceId) { |
| 176 | assertRunOnServiceThread(); |
| 177 | return mTvInputs.containsValue(deviceId); |
| 178 | } |
| 179 | |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 180 | HdmiCecLocalDeviceTv(HdmiControlService service) { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 181 | super(service, HdmiDeviceInfo.DEVICE_TV); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 182 | mPrevPortId = Constants.INVALID_PORT_ID; |
Jinsuk Kim | 544b62b | 2014-07-14 14:01:23 +0900 | [diff] [blame] | 183 | mAutoDeviceOff = mService.readBooleanSetting(Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED, |
| 184 | true); |
| 185 | mAutoWakeup = mService.readBooleanSetting(Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED, true); |
Yuncheol Heo | 25c2029 | 2014-07-31 17:59:39 +0900 | [diff] [blame] | 186 | mStandbyHandler = new HdmiCecStandbyModeHandler(service, this); |
Jungshik Jang | 8b308d9 | 2014-05-29 21:52:28 +0900 | [diff] [blame] | 187 | } |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 188 | |
Jungshik Jang | 8b308d9 | 2014-05-29 21:52:28 +0900 | [diff] [blame] | 189 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 190 | @ServiceThreadOnly |
Yuncheol Heo | fc44e4e | 2014-08-04 19:41:09 +0900 | [diff] [blame] | 191 | protected void onAddressAllocated(int logicalAddress, int reason) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 192 | assertRunOnServiceThread(); |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 193 | List<HdmiPortInfo> ports = mService.getPortInfo(); |
| 194 | for (HdmiPortInfo port : ports) { |
| 195 | mArcFeatureEnabled.put(port.getId(), port.isArcSupported()); |
| 196 | } |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 197 | mService.registerTvInputCallback(mTvInputCallback); |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 198 | mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( |
| 199 | mAddress, mService.getPhysicalAddress(), mDeviceType)); |
| 200 | mService.sendCecCommand(HdmiCecMessageBuilder.buildDeviceVendorIdCommand( |
| 201 | mAddress, mService.getVendorId())); |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 202 | mCecSwitches.add(mService.getPhysicalAddress()); // TV is a CEC switch too. |
Jinsuk Kim | 6e26f7f | 2015-01-07 16:45:14 +0900 | [diff] [blame] | 203 | mTvInputs.clear(); |
Jinsuk Kim | d530719 | 2014-08-22 09:07:40 +0900 | [diff] [blame] | 204 | mSkipRoutingControl = (reason == HdmiControlService.INITIATED_BY_WAKE_UP_MESSAGE); |
Yuncheol Heo | fc44e4e | 2014-08-04 19:41:09 +0900 | [diff] [blame] | 205 | launchRoutingControl(reason != HdmiControlService.INITIATED_BY_ENABLE_CEC && |
| 206 | reason != HdmiControlService.INITIATED_BY_BOOT_UP); |
Jinsuk Kim | bdf27fb | 2014-10-20 10:00:04 +0900 | [diff] [blame] | 207 | mLocalDeviceAddresses = initLocalDeviceAddresses(); |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 208 | launchDeviceDiscovery(); |
Jungshik Jang | 6f34f5a | 2014-07-08 21:17:29 +0900 | [diff] [blame] | 209 | } |
| 210 | |
Jinsuk Kim | bdf27fb | 2014-10-20 10:00:04 +0900 | [diff] [blame] | 211 | |
| 212 | @ServiceThreadOnly |
| 213 | private List<Integer> initLocalDeviceAddresses() { |
| 214 | assertRunOnServiceThread(); |
| 215 | List<Integer> addresses = new ArrayList<>(); |
| 216 | for (HdmiCecLocalDevice device : mService.getAllLocalDevices()) { |
| 217 | addresses.add(device.getDeviceInfo().getLogicalAddress()); |
| 218 | } |
| 219 | return Collections.unmodifiableList(addresses); |
| 220 | } |
| 221 | |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 222 | @Override |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 223 | protected int getPreferredAddress() { |
Jinsuk Kim | d47abef | 2015-01-17 07:38:24 +0900 | [diff] [blame] | 224 | return Constants.ADDR_TV; |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | @Override |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 228 | protected void setPreferredAddress(int addr) { |
Jinsuk Kim | d47abef | 2015-01-17 07:38:24 +0900 | [diff] [blame] | 229 | Slog.w(TAG, "Preferred addres will not be stored for TV"); |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 230 | } |
| 231 | |
Yuncheol Heo | 25c2029 | 2014-07-31 17:59:39 +0900 | [diff] [blame] | 232 | @Override |
| 233 | @ServiceThreadOnly |
| 234 | boolean dispatchMessage(HdmiCecMessage message) { |
| 235 | assertRunOnServiceThread(); |
| 236 | if (mService.isPowerStandby() && mStandbyHandler.handleCommand(message)) { |
| 237 | return true; |
| 238 | } |
| 239 | return super.onMessage(message); |
| 240 | } |
| 241 | |
Jinsuk Kim | a6ce770 | 2014-05-11 06:54:49 +0900 | [diff] [blame] | 242 | /** |
| 243 | * Performs the action 'device select', or 'one touch play' initiated by TV. |
| 244 | * |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 245 | * @param id id of HDMI device to select |
Jinsuk Kim | a6ce770 | 2014-05-11 06:54:49 +0900 | [diff] [blame] | 246 | * @param callback callback object to report the result with |
| 247 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 248 | @ServiceThreadOnly |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 249 | void deviceSelect(int id, IHdmiControlCallback callback) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 250 | assertRunOnServiceThread(); |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 251 | HdmiDeviceInfo targetDevice = mDeviceInfos.get(id); |
| 252 | if (targetDevice == null) { |
| 253 | invokeCallback(callback, HdmiControlManager.RESULT_TARGET_NOT_AVAILABLE); |
| 254 | return; |
| 255 | } |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 256 | int targetAddress = targetDevice.getLogicalAddress(); |
Jinsuk Kim | 58500f4 | 2014-08-05 12:48:35 +0900 | [diff] [blame] | 257 | ActiveSource active = getActiveSource(); |
Yu.Ishihara | 6b2a617 | 2015-03-25 09:44:06 +0900 | [diff] [blame] | 258 | if (targetDevice.getDevicePowerStatus() == HdmiControlManager.POWER_STATUS_ON |
| 259 | && active.isValid() |
| 260 | && targetAddress == active.logicalAddress) { |
Jinsuk Kim | 58500f4 | 2014-08-05 12:48:35 +0900 | [diff] [blame] | 261 | invokeCallback(callback, HdmiControlManager.RESULT_SUCCESS); |
| 262 | return; |
| 263 | } |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 264 | if (targetAddress == Constants.ADDR_INTERNAL) { |
Jinsuk Kim | 5ad5716 | 2014-07-21 13:31:45 +0900 | [diff] [blame] | 265 | handleSelectInternalSource(); |
| 266 | // Switching to internal source is always successful even when CEC control is disabled. |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 267 | setActiveSource(targetAddress, mService.getPhysicalAddress()); |
Jinsuk Kim | 7e74206 | 2014-07-30 13:19:13 +0900 | [diff] [blame] | 268 | setActivePath(mService.getPhysicalAddress()); |
Jinsuk Kim | 5ad5716 | 2014-07-21 13:31:45 +0900 | [diff] [blame] | 269 | invokeCallback(callback, HdmiControlManager.RESULT_SUCCESS); |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 270 | return; |
| 271 | } |
Jinsuk Kim | 09ffc84 | 2014-07-11 17:04:32 +0900 | [diff] [blame] | 272 | if (!mService.isControlEnabled()) { |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 273 | setActiveSource(targetDevice); |
Jinsuk Kim | 09ffc84 | 2014-07-11 17:04:32 +0900 | [diff] [blame] | 274 | invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE); |
| 275 | return; |
| 276 | } |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 277 | removeAction(DeviceSelectAction.class); |
| 278 | addAndStartAction(new DeviceSelectAction(this, targetDevice, callback)); |
Jinsuk Kim | a6ce770 | 2014-05-11 06:54:49 +0900 | [diff] [blame] | 279 | } |
| 280 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 281 | @ServiceThreadOnly |
Jinsuk Kim | 5ad5716 | 2014-07-21 13:31:45 +0900 | [diff] [blame] | 282 | private void handleSelectInternalSource() { |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 283 | assertRunOnServiceThread(); |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 284 | // Seq #18 |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 285 | if (mService.isControlEnabled() && mActiveSource.logicalAddress != mAddress) { |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 286 | updateActiveSource(mAddress, mService.getPhysicalAddress()); |
Jinsuk Kim | d530719 | 2014-08-22 09:07:40 +0900 | [diff] [blame] | 287 | if (mSkipRoutingControl) { |
| 288 | mSkipRoutingControl = false; |
| 289 | return; |
| 290 | } |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 291 | HdmiCecMessage activeSource = HdmiCecMessageBuilder.buildActiveSource( |
| 292 | mAddress, mService.getPhysicalAddress()); |
| 293 | mService.sendCecCommand(activeSource); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | @ServiceThreadOnly |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 298 | void updateActiveSource(int logicalAddress, int physicalAddress) { |
| 299 | assertRunOnServiceThread(); |
| 300 | updateActiveSource(ActiveSource.of(logicalAddress, physicalAddress)); |
| 301 | } |
| 302 | |
| 303 | @ServiceThreadOnly |
| 304 | void updateActiveSource(ActiveSource newActive) { |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 305 | assertRunOnServiceThread(); |
| 306 | // Seq #14 |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 307 | if (mActiveSource.equals(newActive)) { |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 308 | return; |
| 309 | } |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 310 | setActiveSource(newActive); |
| 311 | int logicalAddress = newActive.logicalAddress; |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 312 | if (getCecDeviceInfo(logicalAddress) != null && logicalAddress != mAddress) { |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 313 | if (mService.pathToPortId(newActive.physicalAddress) == getActivePortId()) { |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 314 | setPrevPortId(getActivePortId()); |
| 315 | } |
| 316 | // TODO: Show the OSD banner related to the new active source device. |
| 317 | } else { |
| 318 | // TODO: If displayed, remove the OSD banner related to the previous |
| 319 | // active source device. |
| 320 | } |
| 321 | } |
| 322 | |
Jinsuk Kim | 2b15201 | 2014-07-25 08:22:26 +0900 | [diff] [blame] | 323 | int getPortId(int physicalAddress) { |
| 324 | return mService.pathToPortId(physicalAddress); |
| 325 | } |
| 326 | |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 327 | /** |
| 328 | * Returns the previous port id kept to handle input switching on <Inactive Source>. |
| 329 | */ |
| 330 | int getPrevPortId() { |
| 331 | synchronized (mLock) { |
| 332 | return mPrevPortId; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Sets the previous port id. INVALID_PORT_ID invalidates it, hence no actions will be |
| 338 | * taken for <Inactive Source>. |
| 339 | */ |
| 340 | void setPrevPortId(int portId) { |
| 341 | synchronized (mLock) { |
| 342 | mPrevPortId = portId; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | @ServiceThreadOnly |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 347 | void updateActiveInput(int path, boolean notifyInputChange) { |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 348 | assertRunOnServiceThread(); |
| 349 | // Seq #15 |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 350 | setActivePath(path); |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 351 | // TODO: Handle PAP/PIP case. |
| 352 | // Show OSD port change banner |
| 353 | if (notifyInputChange) { |
| 354 | ActiveSource activeSource = getActiveSource(); |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 355 | HdmiDeviceInfo info = getCecDeviceInfo(activeSource.logicalAddress); |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 356 | if (info == null) { |
Jinsuk Kim | 6ad7cbd | 2015-01-06 11:30:56 +0900 | [diff] [blame] | 357 | info = mService.getDeviceInfoByPort(getActivePortId()); |
| 358 | if (info == null) { |
| 359 | // No CEC/MHL device is present at the port. Attempt to switch to |
| 360 | // the hardware port itself for non-CEC devices that may be connected. |
| 361 | info = new HdmiDeviceInfo(path, getActivePortId()); |
| 362 | } |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 363 | } |
| 364 | mService.invokeInputChangeListener(info); |
| 365 | } |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | @ServiceThreadOnly |
| 369 | void doManualPortSwitching(int portId, IHdmiControlCallback callback) { |
| 370 | assertRunOnServiceThread(); |
| 371 | // Seq #20 |
Jinsuk Kim | 09ffc84 | 2014-07-11 17:04:32 +0900 | [diff] [blame] | 372 | if (!mService.isValidPortId(portId)) { |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 373 | invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE); |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 374 | return; |
| 375 | } |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 376 | if (portId == getActivePortId()) { |
| 377 | invokeCallback(callback, HdmiControlManager.RESULT_SUCCESS); |
| 378 | return; |
| 379 | } |
Jinsuk Kim | 43c23e2 | 2014-07-29 13:59:14 +0900 | [diff] [blame] | 380 | mActiveSource.invalidate(); |
Jinsuk Kim | 09ffc84 | 2014-07-11 17:04:32 +0900 | [diff] [blame] | 381 | if (!mService.isControlEnabled()) { |
| 382 | setActivePortId(portId); |
| 383 | invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE); |
| 384 | return; |
| 385 | } |
Jinsuk Kim | 1f8d1c57 | 2014-08-12 15:39:53 +0900 | [diff] [blame] | 386 | int oldPath = getActivePortId() != Constants.INVALID_PORT_ID |
| 387 | ? mService.portIdToPath(getActivePortId()) : getDeviceInfo().getPhysicalAddress(); |
Jinsuk Kim | d530719 | 2014-08-22 09:07:40 +0900 | [diff] [blame] | 388 | setActivePath(oldPath); |
| 389 | if (mSkipRoutingControl) { |
| 390 | mSkipRoutingControl = false; |
| 391 | return; |
| 392 | } |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 393 | int newPath = mService.portIdToPath(portId); |
Jinsuk Kim | 546d867 | 2014-11-24 07:30:54 +0900 | [diff] [blame] | 394 | startRoutingControl(oldPath, newPath, true, callback); |
| 395 | } |
| 396 | |
| 397 | @ServiceThreadOnly |
| 398 | void startRoutingControl(int oldPath, int newPath, boolean queryDevicePowerStatus, |
| 399 | IHdmiControlCallback callback) { |
| 400 | assertRunOnServiceThread(); |
| 401 | if (oldPath == newPath) { |
| 402 | return; |
| 403 | } |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 404 | HdmiCecMessage routingChange = |
| 405 | HdmiCecMessageBuilder.buildRoutingChange(mAddress, oldPath, newPath); |
| 406 | mService.sendCecCommand(routingChange); |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 407 | removeAction(RoutingControlAction.class); |
Jinsuk Kim | 546d867 | 2014-11-24 07:30:54 +0900 | [diff] [blame] | 408 | addAndStartAction( |
| 409 | new RoutingControlAction(this, newPath, queryDevicePowerStatus, callback)); |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 410 | } |
| 411 | |
Jungshik Jang | f67113f | 2014-08-22 16:27:19 +0900 | [diff] [blame] | 412 | @ServiceThreadOnly |
Jinsuk Kim | cae6627 | 2014-07-04 13:26:44 +0900 | [diff] [blame] | 413 | int getPowerStatus() { |
Jungshik Jang | f67113f | 2014-08-22 16:27:19 +0900 | [diff] [blame] | 414 | assertRunOnServiceThread(); |
Jinsuk Kim | cae6627 | 2014-07-04 13:26:44 +0900 | [diff] [blame] | 415 | return mService.getPowerStatus(); |
| 416 | } |
| 417 | |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 418 | /** |
| 419 | * Sends key to a target CEC device. |
| 420 | * |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 421 | * @param keyCode key code to send. Defined in {@link android.view.KeyEvent}. |
Jinsuk Kim | c068bb5 | 2014-07-07 16:59:20 +0900 | [diff] [blame] | 422 | * @param isPressed true if this is key press event |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 423 | */ |
Jinsuk Kim | c068bb5 | 2014-07-07 16:59:20 +0900 | [diff] [blame] | 424 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 425 | @ServiceThreadOnly |
Jinsuk Kim | c068bb5 | 2014-07-07 16:59:20 +0900 | [diff] [blame] | 426 | protected void sendKeyEvent(int keyCode, boolean isPressed) { |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 427 | assertRunOnServiceThread(); |
Dongil Seo | b64c2ba | 2014-08-26 19:41:39 +0900 | [diff] [blame] | 428 | if (!HdmiCecKeycode.isSupportedKeycode(keyCode)) { |
| 429 | Slog.w(TAG, "Unsupported key: " + keyCode); |
| 430 | return; |
| 431 | } |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 432 | List<SendKeyAction> action = getActions(SendKeyAction.class); |
Jinsuk Kim | 454fab5 | 2015-01-29 16:38:36 +0900 | [diff] [blame] | 433 | int logicalAddress = findKeyReceiverAddress(); |
| 434 | if (logicalAddress == mAddress) { |
| 435 | Slog.w(TAG, "Discard key event to itself :" + keyCode + " pressed:" + isPressed); |
| 436 | return; |
| 437 | } |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 438 | if (!action.isEmpty()) { |
| 439 | action.get(0).processKeyEvent(keyCode, isPressed); |
| 440 | } else { |
Jinsuk Kim | 7543497 | 2014-09-25 13:52:50 +0900 | [diff] [blame] | 441 | if (isPressed) { |
Jinsuk Kim | 7543497 | 2014-09-25 13:52:50 +0900 | [diff] [blame] | 442 | if (logicalAddress != Constants.ADDR_INVALID) { |
| 443 | addAndStartAction(new SendKeyAction(this, logicalAddress, keyCode)); |
| 444 | return; |
| 445 | } |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 446 | } |
Jinsuk Kim | 7543497 | 2014-09-25 13:52:50 +0900 | [diff] [blame] | 447 | Slog.w(TAG, "Discard key event: " + keyCode + " pressed:" + isPressed); |
Jinsuk Kim | a062a93 | 2014-06-18 10:00:39 +0900 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
Jinsuk Kim | 7543497 | 2014-09-25 13:52:50 +0900 | [diff] [blame] | 451 | private int findKeyReceiverAddress() { |
| 452 | if (getActiveSource().isValid()) { |
| 453 | return getActiveSource().logicalAddress; |
| 454 | } |
| 455 | HdmiDeviceInfo info = getDeviceInfoByPath(getActivePath()); |
| 456 | if (info != null) { |
| 457 | return info.getLogicalAddress(); |
| 458 | } |
| 459 | return Constants.ADDR_INVALID; |
| 460 | } |
| 461 | |
Jinsuk Kim | a6ce770 | 2014-05-11 06:54:49 +0900 | [diff] [blame] | 462 | private static void invokeCallback(IHdmiControlCallback callback, int result) { |
Jinsuk Kim | 4893c7e | 2014-06-19 14:13:22 +0900 | [diff] [blame] | 463 | if (callback == null) { |
| 464 | return; |
| 465 | } |
Jinsuk Kim | a6ce770 | 2014-05-11 06:54:49 +0900 | [diff] [blame] | 466 | try { |
| 467 | callback.onComplete(result); |
| 468 | } catch (RemoteException e) { |
| 469 | Slog.e(TAG, "Invoking callback failed:" + e); |
| 470 | } |
| 471 | } |
| 472 | |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 473 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 474 | @ServiceThreadOnly |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 475 | protected boolean handleActiveSource(HdmiCecMessage message) { |
| 476 | assertRunOnServiceThread(); |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 477 | int logicalAddress = message.getSource(); |
| 478 | int physicalAddress = HdmiUtils.twoBytesToInt(message.getParams()); |
Jinsuk Kim | bdf27fb | 2014-10-20 10:00:04 +0900 | [diff] [blame] | 479 | HdmiDeviceInfo info = getCecDeviceInfo(logicalAddress); |
| 480 | if (info == null) { |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 481 | if (!handleNewDeviceAtTheTailOfActivePath(physicalAddress)) { |
Jinsuk Kim | cb8661c | 2015-01-19 12:39:06 +0900 | [diff] [blame] | 482 | HdmiLogger.debug("Device info %X not found; buffering the command", logicalAddress); |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 483 | mDelayedMessageBuffer.add(message); |
| 484 | } |
Jinsuk Kim | 6e26f7f | 2015-01-07 16:45:14 +0900 | [diff] [blame] | 485 | } else if (!isInputReady(info.getId())) { |
| 486 | HdmiLogger.debug("Input not ready for device: %X; buffering the command", info.getId()); |
| 487 | mDelayedMessageBuffer.add(message); |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 488 | } else { |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 489 | ActiveSource activeSource = ActiveSource.of(logicalAddress, physicalAddress); |
Jinsuk Kim | bdf27fb | 2014-10-20 10:00:04 +0900 | [diff] [blame] | 490 | ActiveSourceHandler.create(this, null).process(activeSource, info.getDeviceType()); |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 491 | } |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 492 | return true; |
| 493 | } |
| 494 | |
| 495 | @Override |
| 496 | @ServiceThreadOnly |
| 497 | protected boolean handleInactiveSource(HdmiCecMessage message) { |
| 498 | assertRunOnServiceThread(); |
| 499 | // Seq #10 |
| 500 | |
| 501 | // Ignore <Inactive Source> from non-active source device. |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 502 | if (getActiveSource().logicalAddress != message.getSource()) { |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 503 | return true; |
| 504 | } |
Jinsuk Kim | 4d43d93 | 2014-07-03 16:43:58 +0900 | [diff] [blame] | 505 | if (isProhibitMode()) { |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 506 | return true; |
| 507 | } |
| 508 | int portId = getPrevPortId(); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 509 | if (portId != Constants.INVALID_PORT_ID) { |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 510 | // TODO: Do this only if TV is not showing multiview like PIP/PAP. |
| 511 | |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 512 | HdmiDeviceInfo inactiveSource = getCecDeviceInfo(message.getSource()); |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 513 | if (inactiveSource == null) { |
| 514 | return true; |
| 515 | } |
| 516 | if (mService.pathToPortId(inactiveSource.getPhysicalAddress()) == portId) { |
| 517 | return true; |
| 518 | } |
| 519 | // TODO: Switch the TV freeze mode off |
| 520 | |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 521 | doManualPortSwitching(portId, null); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 522 | setPrevPortId(Constants.INVALID_PORT_ID); |
Jinsuk Kim | cb8661c | 2015-01-19 12:39:06 +0900 | [diff] [blame] | 523 | } else { |
| 524 | // No HDMI port to switch to was found. Notify the input change listers to |
| 525 | // switch to the lastly shown internal input. |
| 526 | mActiveSource.invalidate(); |
| 527 | setActivePath(Constants.INVALID_PHYSICAL_ADDRESS); |
| 528 | mService.invokeInputChangeListener(HdmiDeviceInfo.INACTIVE_DEVICE); |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 529 | } |
| 530 | return true; |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | @ServiceThreadOnly |
| 535 | protected boolean handleRequestActiveSource(HdmiCecMessage message) { |
| 536 | assertRunOnServiceThread(); |
| 537 | // Seq #19 |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 538 | if (mAddress == getActiveSource().logicalAddress) { |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 539 | mService.sendCecCommand( |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 540 | HdmiCecMessageBuilder.buildActiveSource(mAddress, getActivePath())); |
Jinsuk Kim | 8333571 | 2014-06-24 07:57:00 +0900 | [diff] [blame] | 541 | } |
| 542 | return true; |
| 543 | } |
| 544 | |
| 545 | @Override |
| 546 | @ServiceThreadOnly |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 547 | protected boolean handleGetMenuLanguage(HdmiCecMessage message) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 548 | assertRunOnServiceThread(); |
Jungshik Jang | f67113f | 2014-08-22 16:27:19 +0900 | [diff] [blame] | 549 | if (!broadcastMenuLanguage(mService.getLanguage())) { |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 550 | Slog.w(TAG, "Failed to respond to <Get Menu Language>: " + message.toString()); |
| 551 | } |
| 552 | return true; |
| 553 | } |
| 554 | |
Terry Heo | 1ca0a43 | 2014-08-18 10:30:32 +0900 | [diff] [blame] | 555 | @ServiceThreadOnly |
| 556 | boolean broadcastMenuLanguage(String language) { |
| 557 | assertRunOnServiceThread(); |
| 558 | HdmiCecMessage command = HdmiCecMessageBuilder.buildSetMenuLanguageCommand( |
| 559 | mAddress, language); |
| 560 | if (command != null) { |
| 561 | mService.sendCecCommand(command); |
| 562 | return true; |
| 563 | } |
| 564 | return false; |
| 565 | } |
| 566 | |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 567 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 568 | @ServiceThreadOnly |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 569 | protected boolean handleReportPhysicalAddress(HdmiCecMessage message) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 570 | assertRunOnServiceThread(); |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 571 | int path = HdmiUtils.twoBytesToInt(message.getParams()); |
| 572 | int address = message.getSource(); |
Jinsuk Kim | bcfa067 | 2014-08-11 11:56:58 +0900 | [diff] [blame] | 573 | int type = message.getParams()[2]; |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 574 | |
Jinsuk Kim | bcfa067 | 2014-08-11 11:56:58 +0900 | [diff] [blame] | 575 | if (updateCecSwitchInfo(address, type, path)) return true; |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 576 | |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 577 | // Ignore if [Device Discovery Action] is going on. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 578 | if (hasAction(DeviceDiscoveryAction.class)) { |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 579 | Slog.i(TAG, "Ignored while Device Discovery Action is in progress: " + message); |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 580 | return true; |
| 581 | } |
| 582 | |
Jinsuk Kim | 4b4b940 | 2014-09-02 10:30:10 +0900 | [diff] [blame] | 583 | if (!isInDeviceList(address, path)) { |
Jungshik Jang | 8f2ed35 | 2014-07-07 15:02:47 +0900 | [diff] [blame] | 584 | handleNewDeviceAtTheTailOfActivePath(path); |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 585 | } |
Jinsuk Kim | 7cd4a58 | 2015-01-29 09:50:25 +0900 | [diff] [blame] | 586 | |
| 587 | // Add the device ahead with default information to handle <Active Source> |
| 588 | // promptly, rather than waiting till the new device action is finished. |
| 589 | HdmiDeviceInfo deviceInfo = new HdmiDeviceInfo(address, path, getPortId(path), type, |
| 590 | Constants.UNKNOWN_VENDOR_ID, HdmiUtils.getDefaultDeviceName(address)); |
| 591 | addCecDevice(deviceInfo); |
Jinsuk Kim | bdf27fb | 2014-10-20 10:00:04 +0900 | [diff] [blame] | 592 | startNewDeviceAction(ActiveSource.of(address, path), type); |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 593 | return true; |
| 594 | } |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 595 | |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 596 | @Override |
| 597 | protected boolean handleReportPowerStatus(HdmiCecMessage command) { |
| 598 | int newStatus = command.getParams()[0] & 0xFF; |
| 599 | updateDevicePowerStatus(command.getSource(), newStatus); |
| 600 | return true; |
| 601 | } |
| 602 | |
| 603 | @Override |
| 604 | protected boolean handleTimerStatus(HdmiCecMessage message) { |
| 605 | // Do nothing. |
| 606 | return true; |
| 607 | } |
| 608 | |
| 609 | @Override |
| 610 | protected boolean handleRecordStatus(HdmiCecMessage message) { |
| 611 | // Do nothing. |
| 612 | return true; |
| 613 | } |
| 614 | |
Jinsuk Kim | bcfa067 | 2014-08-11 11:56:58 +0900 | [diff] [blame] | 615 | boolean updateCecSwitchInfo(int address, int type, int path) { |
| 616 | if (address == Constants.ADDR_UNREGISTERED |
| 617 | && type == HdmiDeviceInfo.DEVICE_PURE_CEC_SWITCH) { |
| 618 | mCecSwitches.add(path); |
| 619 | updateSafeDeviceInfoList(); |
| 620 | return true; // Pure switch does not need further processing. Return here. |
| 621 | } |
| 622 | if (type == HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM) { |
| 623 | mCecSwitches.add(path); |
| 624 | } |
| 625 | return false; |
| 626 | } |
| 627 | |
Jinsuk Kim | bdf27fb | 2014-10-20 10:00:04 +0900 | [diff] [blame] | 628 | void startNewDeviceAction(ActiveSource activeSource, int deviceType) { |
Jungshik Jang | 97affee | 2014-07-11 17:04:43 +0900 | [diff] [blame] | 629 | for (NewDeviceAction action : getActions(NewDeviceAction.class)) { |
| 630 | // If there is new device action which has the same logical address and path |
| 631 | // ignore new request. |
| 632 | // NewDeviceAction is created whenever it receives <Report Physical Address>. |
| 633 | // And there is a chance starting NewDeviceAction for the same source. |
| 634 | // Usually, new device sends <Report Physical Address> when it's plugged |
| 635 | // in. However, TV can detect a new device from HotPlugDetectionAction, |
| 636 | // which sends <Give Physical Address> to the source for newly detected |
| 637 | // device. |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 638 | if (action.isActionOf(activeSource)) { |
Jungshik Jang | 97affee | 2014-07-11 17:04:43 +0900 | [diff] [blame] | 639 | return; |
| 640 | } |
| 641 | } |
| 642 | |
Jinsuk Kim | 72b7d73 | 2014-07-24 09:15:35 +0900 | [diff] [blame] | 643 | addAndStartAction(new NewDeviceAction(this, activeSource.logicalAddress, |
Jinsuk Kim | bdf27fb | 2014-10-20 10:00:04 +0900 | [diff] [blame] | 644 | activeSource.physicalAddress, deviceType)); |
Jungshik Jang | 97affee | 2014-07-11 17:04:43 +0900 | [diff] [blame] | 645 | } |
| 646 | |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 647 | private boolean handleNewDeviceAtTheTailOfActivePath(int path) { |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 648 | // Seq #22 |
| 649 | if (isTailOfActivePath(path, getActivePath())) { |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 650 | int newPath = mService.portIdToPath(getActivePortId()); |
Jinsuk Kim | 7c3a956 | 2014-08-01 11:07:42 +0900 | [diff] [blame] | 651 | setActivePath(newPath); |
Jinsuk Kim | 546d867 | 2014-11-24 07:30:54 +0900 | [diff] [blame] | 652 | startRoutingControl(getActivePath(), newPath, false, null); |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 653 | return true; |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 654 | } |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 655 | return false; |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /** |
| 659 | * Whether the given path is located in the tail of current active path. |
| 660 | * |
| 661 | * @param path to be tested |
| 662 | * @param activePath current active path |
| 663 | * @return true if the given path is located in the tail of current active path; otherwise, |
| 664 | * false |
| 665 | */ |
| 666 | static boolean isTailOfActivePath(int path, int activePath) { |
| 667 | // If active routing path is internal source, return false. |
| 668 | if (activePath == 0) { |
| 669 | return false; |
| 670 | } |
| 671 | for (int i = 12; i >= 0; i -= 4) { |
| 672 | int curActivePath = (activePath >> i) & 0xF; |
| 673 | if (curActivePath == 0) { |
| 674 | return true; |
| 675 | } else { |
| 676 | int curPath = (path >> i) & 0xF; |
| 677 | if (curPath != curActivePath) { |
| 678 | return false; |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | return false; |
| 683 | } |
| 684 | |
| 685 | @Override |
| 686 | @ServiceThreadOnly |
| 687 | protected boolean handleRoutingChange(HdmiCecMessage message) { |
| 688 | assertRunOnServiceThread(); |
| 689 | // Seq #21 |
| 690 | byte[] params = message.getParams(); |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 691 | int currentPath = HdmiUtils.twoBytesToInt(params); |
| 692 | if (HdmiUtils.isAffectingActiveRoutingPath(getActivePath(), currentPath)) { |
Jinsuk Kim | 43c23e2 | 2014-07-29 13:59:14 +0900 | [diff] [blame] | 693 | mActiveSource.invalidate(); |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 694 | removeAction(RoutingControlAction.class); |
Jinsuk Kim | 43c23e2 | 2014-07-29 13:59:14 +0900 | [diff] [blame] | 695 | int newPath = HdmiUtils.twoBytesToInt(params, 2); |
Jinsuk Kim | 04fd280 | 2014-07-03 14:04:02 +0900 | [diff] [blame] | 696 | addAndStartAction(new RoutingControlAction(this, newPath, true, null)); |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 697 | } |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 698 | return true; |
| 699 | } |
Jinsuk Kim | 0a3316b | 2014-06-14 09:33:55 +0900 | [diff] [blame] | 700 | |
| 701 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 702 | @ServiceThreadOnly |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 703 | protected boolean handleReportAudioStatus(HdmiCecMessage message) { |
| 704 | assertRunOnServiceThread(); |
| 705 | |
| 706 | byte params[] = message.getParams(); |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 707 | int mute = params[0] & 0x80; |
| 708 | int volume = params[0] & 0x7F; |
| 709 | setAudioStatus(mute == 0x80, volume); |
| 710 | return true; |
| 711 | } |
| 712 | |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 713 | @Override |
| 714 | @ServiceThreadOnly |
| 715 | protected boolean handleTextViewOn(HdmiCecMessage message) { |
| 716 | assertRunOnServiceThread(); |
Jinsuk Kim | 544b62b | 2014-07-14 14:01:23 +0900 | [diff] [blame] | 717 | if (mService.isPowerStandbyOrTransient() && mAutoWakeup) { |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 718 | mService.wakeUp(); |
| 719 | } |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 720 | return true; |
| 721 | } |
| 722 | |
| 723 | @Override |
| 724 | @ServiceThreadOnly |
| 725 | protected boolean handleImageViewOn(HdmiCecMessage message) { |
| 726 | assertRunOnServiceThread(); |
| 727 | // Currently, it's the same as <Text View On>. |
| 728 | return handleTextViewOn(message); |
| 729 | } |
| 730 | |
Jungshik Jang | 8f2ed35 | 2014-07-07 15:02:47 +0900 | [diff] [blame] | 731 | @Override |
| 732 | @ServiceThreadOnly |
| 733 | protected boolean handleSetOsdName(HdmiCecMessage message) { |
| 734 | int source = message.getSource(); |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 735 | HdmiDeviceInfo deviceInfo = getCecDeviceInfo(source); |
Jungshik Jang | 8f2ed35 | 2014-07-07 15:02:47 +0900 | [diff] [blame] | 736 | // If the device is not in device list, ignore it. |
| 737 | if (deviceInfo == null) { |
| 738 | Slog.e(TAG, "No source device info for <Set Osd Name>." + message); |
| 739 | return true; |
| 740 | } |
| 741 | String osdName = null; |
| 742 | try { |
| 743 | osdName = new String(message.getParams(), "US-ASCII"); |
| 744 | } catch (UnsupportedEncodingException e) { |
| 745 | Slog.e(TAG, "Invalid <Set Osd Name> request:" + message, e); |
| 746 | return true; |
| 747 | } |
| 748 | |
| 749 | if (deviceInfo.getDisplayName().equals(osdName)) { |
| 750 | Slog.i(TAG, "Ignore incoming <Set Osd Name> having same osd name:" + message); |
| 751 | return true; |
| 752 | } |
| 753 | |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 754 | addCecDevice(new HdmiDeviceInfo(deviceInfo.getLogicalAddress(), |
Jinsuk Kim | 2b15201 | 2014-07-25 08:22:26 +0900 | [diff] [blame] | 755 | deviceInfo.getPhysicalAddress(), deviceInfo.getPortId(), |
| 756 | deviceInfo.getDeviceType(), deviceInfo.getVendorId(), osdName)); |
Jungshik Jang | 8f2ed35 | 2014-07-07 15:02:47 +0900 | [diff] [blame] | 757 | return true; |
| 758 | } |
| 759 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 760 | @ServiceThreadOnly |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 761 | private void launchDeviceDiscovery() { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 762 | assertRunOnServiceThread(); |
| 763 | clearDeviceInfoList(); |
| 764 | DeviceDiscoveryAction action = new DeviceDiscoveryAction(this, |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 765 | new DeviceDiscoveryCallback() { |
| 766 | @Override |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 767 | public void onDeviceDiscoveryDone(List<HdmiDeviceInfo> deviceInfos) { |
| 768 | for (HdmiDeviceInfo info : deviceInfos) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 769 | addCecDevice(info); |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | // Since we removed all devices when it's start and |
| 773 | // device discovery action does not poll local devices, |
| 774 | // we should put device info of local device manually here |
| 775 | for (HdmiCecLocalDevice device : mService.getAllLocalDevices()) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 776 | addCecDevice(device.getDeviceInfo()); |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 777 | } |
| 778 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 779 | addAndStartAction(new HotplugDetectionAction(HdmiCecLocalDeviceTv.this)); |
Jungshik Jang | 410ca9c | 2014-08-07 18:04:14 +0900 | [diff] [blame] | 780 | addAndStartAction(new PowerStatusMonitorAction(HdmiCecLocalDeviceTv.this)); |
Jungshik Jang | 187d017 | 2014-06-17 17:48:42 +0900 | [diff] [blame] | 781 | |
| 782 | // If there is AVR, initiate System Audio Auto initiation action, |
| 783 | // which turns on and off system audio according to last system |
| 784 | // audio setting. |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 785 | HdmiDeviceInfo avr = getAvrDeviceInfo(); |
| 786 | if (avr != null) { |
| 787 | onNewAvrAdded(avr); |
Wally Yau | 951e3e4 | 2015-04-03 15:12:52 -0700 | [diff] [blame] | 788 | } else { |
| 789 | setSystemAudioMode(false, true); |
Jungshik Jang | 187d017 | 2014-06-17 17:48:42 +0900 | [diff] [blame] | 790 | } |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 791 | } |
| 792 | }); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 793 | addAndStartAction(action); |
| 794 | } |
| 795 | |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 796 | @ServiceThreadOnly |
| 797 | void onNewAvrAdded(HdmiDeviceInfo avr) { |
| 798 | assertRunOnServiceThread(); |
Jinsuk Kim | ad1e3d7 | 2015-01-02 13:27:15 +0900 | [diff] [blame] | 799 | if (getSystemAudioModeSetting() && !isSystemAudioActivated()) { |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 800 | addAndStartAction(new SystemAudioAutoInitiationAction(this, avr.getLogicalAddress())); |
| 801 | } |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 802 | if (isArcFeatureEnabled(avr.getPortId()) |
| 803 | && !hasAction(SetArcTransmissionStateAction.class)) { |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 804 | startArcAction(true); |
| 805 | } |
| 806 | } |
| 807 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 808 | // Clear all device info. |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 809 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 810 | private void clearDeviceInfoList() { |
| 811 | assertRunOnServiceThread(); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 812 | for (HdmiDeviceInfo info : mSafeExternalInputs) { |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 813 | invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE); |
Jinsuk Kim | 49b47bb | 2014-07-22 10:40:35 +0900 | [diff] [blame] | 814 | } |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 815 | mDeviceInfos.clear(); |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 816 | updateSafeDeviceInfoList(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 817 | } |
| 818 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 819 | @ServiceThreadOnly |
Yuncheol Heo | c516d65 | 2014-07-11 18:23:24 +0900 | [diff] [blame] | 820 | // Seq #32 |
Jungshik Jang | ea67c18 | 2014-06-19 22:19:20 +0900 | [diff] [blame] | 821 | void changeSystemAudioMode(boolean enabled, IHdmiControlCallback callback) { |
| 822 | assertRunOnServiceThread(); |
Yuncheol Heo | c516d65 | 2014-07-11 18:23:24 +0900 | [diff] [blame] | 823 | if (!mService.isControlEnabled() || hasAction(DeviceDiscoveryAction.class)) { |
| 824 | setSystemAudioMode(false, true); |
| 825 | invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE); |
| 826 | return; |
| 827 | } |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 828 | HdmiDeviceInfo avr = getAvrDeviceInfo(); |
Jungshik Jang | ea67c18 | 2014-06-19 22:19:20 +0900 | [diff] [blame] | 829 | if (avr == null) { |
Yuncheol Heo | c516d65 | 2014-07-11 18:23:24 +0900 | [diff] [blame] | 830 | setSystemAudioMode(false, true); |
Yuncheol Heo | d05f67f | 2014-07-11 16:06:40 +0900 | [diff] [blame] | 831 | invokeCallback(callback, HdmiControlManager.RESULT_TARGET_NOT_AVAILABLE); |
Jungshik Jang | ea67c18 | 2014-06-19 22:19:20 +0900 | [diff] [blame] | 832 | return; |
| 833 | } |
| 834 | |
| 835 | addAndStartAction( |
| 836 | new SystemAudioActionFromTv(this, avr.getLogicalAddress(), enabled, callback)); |
Jungshik Jang | ea67c18 | 2014-06-19 22:19:20 +0900 | [diff] [blame] | 837 | } |
| 838 | |
Jungshik Jang | ca5be9a | 2014-07-01 18:01:26 +0900 | [diff] [blame] | 839 | // # Seq 25 |
Jinsuk Kim | 7ecfbae | 2014-07-11 14:16:29 +0900 | [diff] [blame] | 840 | void setSystemAudioMode(boolean on, boolean updateSetting) { |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 841 | HdmiLogger.debug("System Audio Mode change[old:%b new:%b]", mSystemAudioActivated, on); |
Jungshik Jang | 473119f | 2014-08-27 16:43:22 +0900 | [diff] [blame] | 842 | |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 843 | if (updateSetting) { |
| 844 | mService.writeBooleanSetting(Global.HDMI_SYSTEM_AUDIO_ENABLED, on); |
| 845 | } |
| 846 | updateAudioManagerForSystemAudio(on); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 847 | synchronized (mLock) { |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 848 | if (mSystemAudioActivated != on) { |
| 849 | mSystemAudioActivated = on; |
Jungshik Jang | ea67c18 | 2014-06-19 22:19:20 +0900 | [diff] [blame] | 850 | mService.announceSystemAudioModeChange(on); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | } |
| 854 | |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 855 | private void updateAudioManagerForSystemAudio(boolean on) { |
Jungshik Jang | 6b096d3 | 2014-09-12 18:49:08 +0900 | [diff] [blame] | 856 | int device = mService.getAudioManager().setHdmiSystemAudioSupported(on); |
| 857 | HdmiLogger.debug("[A]UpdateSystemAudio mode[on=%b] output=[%X]", on, device); |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | boolean isSystemAudioActivated() { |
Jinsuk Kim | 86a1e5a | 2014-11-19 06:04:50 +0900 | [diff] [blame] | 861 | if (!hasSystemAudioDevice()) { |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 862 | return false; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 863 | } |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 864 | synchronized (mLock) { |
| 865 | return mSystemAudioActivated; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | boolean getSystemAudioModeSetting() { |
| 870 | return mService.readBooleanSetting(Global.HDMI_SYSTEM_AUDIO_ENABLED, false); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /** |
| 874 | * Change ARC status into the given {@code enabled} status. |
| 875 | * |
| 876 | * @return {@code true} if ARC was in "Enabled" status |
| 877 | */ |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 878 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 879 | boolean setArcStatus(boolean enabled) { |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 880 | assertRunOnServiceThread(); |
Jungshik Jang | 6b096d3 | 2014-09-12 18:49:08 +0900 | [diff] [blame] | 881 | |
| 882 | HdmiLogger.debug("Set Arc Status[old:%b new:%b]", mArcEstablished, enabled); |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 883 | boolean oldStatus = mArcEstablished; |
| 884 | // 1. Enable/disable ARC circuit. |
Jinsuk Kim | 757c097 | 2015-02-23 10:15:42 +0900 | [diff] [blame] | 885 | setAudioReturnChannel(enabled); |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 886 | // 2. Notify arc status to audio service. |
| 887 | notifyArcStatusToAudioService(enabled); |
| 888 | // 3. Update arc status; |
| 889 | mArcEstablished = enabled; |
| 890 | return oldStatus; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 891 | } |
| 892 | |
Jinsuk Kim | 757c097 | 2015-02-23 10:15:42 +0900 | [diff] [blame] | 893 | /** |
| 894 | * Switch hardware ARC circuit in the system. |
| 895 | */ |
| 896 | @ServiceThreadOnly |
| 897 | void setAudioReturnChannel(boolean enabled) { |
| 898 | assertRunOnServiceThread(); |
| 899 | HdmiDeviceInfo avr = getAvrDeviceInfo(); |
| 900 | if (avr != null) { |
| 901 | mService.setAudioReturnChannel(avr.getPortId(), enabled); |
| 902 | } |
| 903 | } |
| 904 | |
Jinsuk Kim | 2ee0d6f | 2015-01-28 17:38:28 +0900 | [diff] [blame] | 905 | @ServiceThreadOnly |
| 906 | private void updateArcFeatureStatus(int portId, boolean isConnected) { |
| 907 | assertRunOnServiceThread(); |
| 908 | // HEAC 2.4, HEACT 5-15 |
| 909 | // Should not activate ARC if +5V status is false. |
| 910 | HdmiPortInfo portInfo = mService.getPortInfo(portId); |
| 911 | if (portInfo.isArcSupported()) { |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 912 | changeArcFeatureEnabled(portId, isConnected); |
Jinsuk Kim | 2ee0d6f | 2015-01-28 17:38:28 +0900 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
Jinsuk Kim | 7b0cf64 | 2015-04-14 09:43:45 +0900 | [diff] [blame] | 916 | @ServiceThreadOnly |
| 917 | boolean isConnected(int portId) { |
| 918 | assertRunOnServiceThread(); |
| 919 | return mService.isConnected(portId); |
| 920 | } |
| 921 | |
Jungshik Jang | a858d22 | 2014-06-23 17:17:47 +0900 | [diff] [blame] | 922 | private void notifyArcStatusToAudioService(boolean enabled) { |
| 923 | // Note that we don't set any name to ARC. |
| 924 | mService.getAudioManager().setWiredDeviceConnectionState( |
| 925 | AudioSystem.DEVICE_OUT_HDMI_ARC, |
Paul McLean | 10804eb | 2015-01-28 11:16:35 -0800 | [diff] [blame] | 926 | enabled ? 1 : 0, "", ""); |
Jungshik Jang | a858d22 | 2014-06-23 17:17:47 +0900 | [diff] [blame] | 927 | } |
| 928 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 929 | /** |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 930 | * Returns true if ARC is currently established on a certain port. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 931 | */ |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 932 | @ServiceThreadOnly |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 933 | boolean isArcEstablished() { |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 934 | assertRunOnServiceThread(); |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 935 | if (mArcEstablished) { |
| 936 | for (int i = 0; i < mArcFeatureEnabled.size(); i++) { |
| 937 | if (mArcFeatureEnabled.valueAt(i)) return true; |
| 938 | } |
| 939 | } |
| 940 | return false; |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | @ServiceThreadOnly |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 944 | void changeArcFeatureEnabled(int portId, boolean enabled) { |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 945 | assertRunOnServiceThread(); |
| 946 | |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 947 | if (mArcFeatureEnabled.get(portId) != enabled) { |
| 948 | mArcFeatureEnabled.put(portId, enabled); |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 949 | if (enabled) { |
| 950 | if (!mArcEstablished) { |
| 951 | startArcAction(true); |
| 952 | } |
| 953 | } else { |
| 954 | if (mArcEstablished) { |
| 955 | startArcAction(false); |
| 956 | } |
| 957 | } |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
| 961 | @ServiceThreadOnly |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 962 | boolean isArcFeatureEnabled(int portId) { |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 963 | assertRunOnServiceThread(); |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 964 | return mArcFeatureEnabled.get(portId); |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | @ServiceThreadOnly |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 968 | void startArcAction(boolean enabled) { |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 969 | assertRunOnServiceThread(); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 970 | HdmiDeviceInfo info = getAvrDeviceInfo(); |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 971 | if (info == null) { |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 972 | Slog.w(TAG, "Failed to start arc action; No AVR device."); |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 973 | return; |
| 974 | } |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 975 | if (!canStartArcUpdateAction(info.getLogicalAddress(), enabled)) { |
| 976 | Slog.w(TAG, "Failed to start arc action; ARC configuration check failed."); |
| 977 | if (enabled && !isConnectedToArcPort(info.getPhysicalAddress())) { |
| 978 | displayOsd(OSD_MESSAGE_ARC_CONNECTED_INVALID_PORT); |
| 979 | } |
Jungshik Jang | a13da0d | 2014-06-30 16:26:06 +0900 | [diff] [blame] | 980 | return; |
| 981 | } |
| 982 | |
| 983 | // Terminate opposite action and start action if not exist. |
| 984 | if (enabled) { |
| 985 | removeAction(RequestArcTerminationAction.class); |
| 986 | if (!hasAction(RequestArcInitiationAction.class)) { |
| 987 | addAndStartAction(new RequestArcInitiationAction(this, info.getLogicalAddress())); |
| 988 | } |
| 989 | } else { |
| 990 | removeAction(RequestArcInitiationAction.class); |
| 991 | if (!hasAction(RequestArcTerminationAction.class)) { |
| 992 | addAndStartAction(new RequestArcTerminationAction(this, info.getLogicalAddress())); |
| 993 | } |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 997 | private boolean isDirectConnectAddress(int physicalAddress) { |
| 998 | return (physicalAddress & Constants.ROUTING_PATH_TOP_MASK) == physicalAddress; |
| 999 | } |
| 1000 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1001 | void setAudioStatus(boolean mute, int volume) { |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 1002 | synchronized (mLock) { |
| 1003 | mSystemAudioMute = mute; |
| 1004 | mSystemAudioVolume = volume; |
Jungshik Jang | b69aafbf | 2014-07-11 16:29:06 +0900 | [diff] [blame] | 1005 | int maxVolume = mService.getAudioManager().getStreamMaxVolume( |
| 1006 | AudioManager.STREAM_MUSIC); |
| 1007 | mService.setAudioStatus(mute, |
| 1008 | VolumeControlAction.scaleToCustomVolume(volume, maxVolume)); |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 1009 | displayOsd(HdmiControlManager.OSD_MESSAGE_AVR_VOLUME_CHANGED, |
| 1010 | mute ? HdmiControlManager.AVR_VOLUME_MUTED : volume); |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | @ServiceThreadOnly |
| 1015 | void changeVolume(int curVolume, int delta, int maxVolume) { |
| 1016 | assertRunOnServiceThread(); |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 1017 | if (delta == 0 || !isSystemAudioActivated()) { |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 1018 | return; |
| 1019 | } |
| 1020 | |
| 1021 | int targetVolume = curVolume + delta; |
| 1022 | int cecVolume = VolumeControlAction.scaleToCecVolume(targetVolume, maxVolume); |
| 1023 | synchronized (mLock) { |
| 1024 | // If new volume is the same as current system audio volume, just ignore it. |
| 1025 | // Note that UNKNOWN_VOLUME is not in range of cec volume scale. |
| 1026 | if (cecVolume == mSystemAudioVolume) { |
| 1027 | // Update tv volume with system volume value. |
| 1028 | mService.setAudioStatus(false, |
| 1029 | VolumeControlAction.scaleToCustomVolume(mSystemAudioVolume, maxVolume)); |
| 1030 | return; |
| 1031 | } |
| 1032 | } |
| 1033 | |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 1034 | List<VolumeControlAction> actions = getActions(VolumeControlAction.class); |
| 1035 | if (actions.isEmpty()) { |
| 1036 | addAndStartAction(new VolumeControlAction(this, |
| 1037 | getAvrDeviceInfo().getLogicalAddress(), delta > 0)); |
| 1038 | } else { |
| 1039 | actions.get(0).handleVolumeChange(delta > 0); |
| 1040 | } |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | @ServiceThreadOnly |
| 1044 | void changeMute(boolean mute) { |
| 1045 | assertRunOnServiceThread(); |
Jungshik Jang | 6b096d3 | 2014-09-12 18:49:08 +0900 | [diff] [blame] | 1046 | HdmiLogger.debug("[A]:Change mute:%b", mute); |
Jungshik Jang | 720407a | 2014-09-15 17:48:41 +0900 | [diff] [blame] | 1047 | synchronized (mLock) { |
| 1048 | if (mSystemAudioMute == mute) { |
| 1049 | HdmiLogger.debug("No need to change mute."); |
| 1050 | return; |
| 1051 | } |
| 1052 | } |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 1053 | if (!isSystemAudioActivated()) { |
Jungshik Jang | 6b096d3 | 2014-09-12 18:49:08 +0900 | [diff] [blame] | 1054 | HdmiLogger.debug("[A]:System audio is not activated."); |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 1055 | return; |
| 1056 | } |
| 1057 | |
| 1058 | // Remove existing volume action. |
| 1059 | removeAction(VolumeControlAction.class); |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 1060 | sendUserControlPressedAndReleased(getAvrDeviceInfo().getLogicalAddress(), |
| 1061 | mute ? HdmiCecKeycode.CEC_KEYCODE_MUTE_FUNCTION : |
| 1062 | HdmiCecKeycode.CEC_KEYCODE_RESTORE_VOLUME_FUNCTION); |
Jungshik Jang | 8fa36b1 | 2014-06-25 15:51:36 +0900 | [diff] [blame] | 1063 | } |
| 1064 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1065 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1066 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1067 | protected boolean handleInitiateArc(HdmiCecMessage message) { |
| 1068 | assertRunOnServiceThread(); |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 1069 | |
| 1070 | if (!canStartArcUpdateAction(message.getSource(), true)) { |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 1071 | if (getAvrDeviceInfo() == null) { |
| 1072 | // AVR may not have been discovered yet. Delay the message processing. |
| 1073 | mDelayedMessageBuffer.add(message); |
| 1074 | return true; |
| 1075 | } |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 1076 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED); |
| 1077 | if (!isConnectedToArcPort(message.getSource())) { |
| 1078 | displayOsd(OSD_MESSAGE_ARC_CONNECTED_INVALID_PORT); |
| 1079 | } |
| 1080 | return true; |
| 1081 | } |
| 1082 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1083 | // In case where <Initiate Arc> is started by <Request ARC Initiation> |
| 1084 | // need to clean up RequestArcInitiationAction. |
| 1085 | removeAction(RequestArcInitiationAction.class); |
| 1086 | SetArcTransmissionStateAction action = new SetArcTransmissionStateAction(this, |
| 1087 | message.getSource(), true); |
| 1088 | addAndStartAction(action); |
| 1089 | return true; |
| 1090 | } |
| 1091 | |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 1092 | private boolean canStartArcUpdateAction(int avrAddress, boolean shouldCheckArcFeatureEnabled) { |
| 1093 | HdmiDeviceInfo avr = getAvrDeviceInfo(); |
| 1094 | if (avr != null |
| 1095 | && (avrAddress == avr.getLogicalAddress()) |
| 1096 | && isConnectedToArcPort(avr.getPhysicalAddress()) |
| 1097 | && isDirectConnectAddress(avr.getPhysicalAddress())) { |
| 1098 | if (shouldCheckArcFeatureEnabled) { |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 1099 | return isArcFeatureEnabled(avr.getPortId()); |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 1100 | } else { |
| 1101 | return true; |
| 1102 | } |
| 1103 | } else { |
| 1104 | return false; |
| 1105 | } |
| 1106 | } |
| 1107 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1108 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1109 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1110 | protected boolean handleTerminateArc(HdmiCecMessage message) { |
| 1111 | assertRunOnServiceThread(); |
Jinsuk Kim | 7e4b480 | 2015-04-20 13:17:13 +0900 | [diff] [blame] | 1112 | if (mService .isPowerStandbyOrTransient()) { |
| 1113 | setArcStatus(false); |
| 1114 | return true; |
| 1115 | } |
| 1116 | // Do not check ARC configuration since the AVR might have been already removed. |
| 1117 | // Clean up RequestArcTerminationAction in case <Terminate Arc> was started by |
| 1118 | // <Request ARC Termination>. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1119 | removeAction(RequestArcTerminationAction.class); |
| 1120 | SetArcTransmissionStateAction action = new SetArcTransmissionStateAction(this, |
| 1121 | message.getSource(), false); |
| 1122 | addAndStartAction(action); |
| 1123 | return true; |
| 1124 | } |
| 1125 | |
| 1126 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1127 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1128 | protected boolean handleSetSystemAudioMode(HdmiCecMessage message) { |
| 1129 | assertRunOnServiceThread(); |
| 1130 | if (!isMessageForSystemAudio(message)) { |
Jinsuk Kim | ad1e3d7 | 2015-01-02 13:27:15 +0900 | [diff] [blame] | 1131 | if (getAvrDeviceInfo() == null) { |
| 1132 | // AVR may not have been discovered yet. Delay the message processing. |
| 1133 | mDelayedMessageBuffer.add(message); |
| 1134 | return true; |
| 1135 | } |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 1136 | HdmiLogger.warning("Invalid <Set System Audio Mode> message:" + message); |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 1137 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED); |
| 1138 | return true; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1139 | } |
| 1140 | SystemAudioActionFromAvr action = new SystemAudioActionFromAvr(this, |
Jungshik Jang | 7f0a1c5 | 2014-06-23 16:00:07 +0900 | [diff] [blame] | 1141 | message.getSource(), HdmiUtils.parseCommandParamSystemAudioStatus(message), null); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1142 | addAndStartAction(action); |
| 1143 | return true; |
| 1144 | } |
| 1145 | |
| 1146 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1147 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1148 | protected boolean handleSystemAudioModeStatus(HdmiCecMessage message) { |
| 1149 | assertRunOnServiceThread(); |
| 1150 | if (!isMessageForSystemAudio(message)) { |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 1151 | HdmiLogger.warning("Invalid <System Audio Mode Status> message:" + message); |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 1152 | // Ignore this message. |
| 1153 | return true; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1154 | } |
Jinsuk Kim | 7ecfbae | 2014-07-11 14:16:29 +0900 | [diff] [blame] | 1155 | setSystemAudioMode(HdmiUtils.parseCommandParamSystemAudioStatus(message), true); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1156 | return true; |
| 1157 | } |
| 1158 | |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1159 | // Seq #53 |
| 1160 | @Override |
| 1161 | @ServiceThreadOnly |
| 1162 | protected boolean handleRecordTvScreen(HdmiCecMessage message) { |
| 1163 | List<OneTouchRecordAction> actions = getActions(OneTouchRecordAction.class); |
| 1164 | if (!actions.isEmpty()) { |
| 1165 | // Assumes only one OneTouchRecordAction. |
| 1166 | OneTouchRecordAction action = actions.get(0); |
| 1167 | if (action.getRecorderAddress() != message.getSource()) { |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 1168 | announceOneTouchRecordResult( |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1169 | message.getSource(), |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 1170 | HdmiControlManager.ONE_TOUCH_RECORD_PREVIOUS_RECORDING_IN_PROGRESS); |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1171 | } |
| 1172 | return super.handleRecordTvScreen(message); |
| 1173 | } |
| 1174 | |
| 1175 | int recorderAddress = message.getSource(); |
| 1176 | byte[] recordSource = mService.invokeRecordRequestListener(recorderAddress); |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 1177 | int reason = startOneTouchRecord(recorderAddress, recordSource); |
| 1178 | if (reason != Constants.ABORT_NO_ERROR) { |
| 1179 | mService.maySendFeatureAbortCommand(message, reason); |
| 1180 | } |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1181 | return true; |
| 1182 | } |
| 1183 | |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1184 | @Override |
| 1185 | protected boolean handleTimerClearedStatus(HdmiCecMessage message) { |
| 1186 | byte[] params = message.getParams(); |
Jungshik Jang | e9e0f07 | 2014-08-05 17:48:59 +0900 | [diff] [blame] | 1187 | int timerClearedStatusData = params[0] & 0xFF; |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1188 | announceTimerRecordingResult(message.getSource(), timerClearedStatusData); |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1189 | return true; |
| 1190 | } |
| 1191 | |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1192 | void announceOneTouchRecordResult(int recorderAddress, int result) { |
| 1193 | mService.invokeOneTouchRecordResult(recorderAddress, result); |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 1194 | } |
| 1195 | |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1196 | void announceTimerRecordingResult(int recorderAddress, int result) { |
| 1197 | mService.invokeTimerRecordingResult(recorderAddress, result); |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 1198 | } |
| 1199 | |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1200 | void announceClearTimerRecordingResult(int recorderAddress, int result) { |
| 1201 | mService.invokeClearTimerRecordingResult(recorderAddress, result); |
Jungshik Jang | faa49bc | 2014-08-05 16:10:21 +0900 | [diff] [blame] | 1202 | } |
| 1203 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1204 | private boolean isMessageForSystemAudio(HdmiCecMessage message) { |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 1205 | return mService.isControlEnabled() |
| 1206 | && message.getSource() == Constants.ADDR_AUDIO_SYSTEM |
Jungshik Jang | 473119f | 2014-08-27 16:43:22 +0900 | [diff] [blame] | 1207 | && (message.getDestination() == Constants.ADDR_TV |
| 1208 | || message.getDestination() == Constants.ADDR_BROADCAST) |
| 1209 | && getAvrDeviceInfo() != null; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | /** |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1213 | * Add a new {@link HdmiDeviceInfo}. It returns old device info which has the same |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1214 | * logical address as new device info's. |
| 1215 | * |
| 1216 | * <p>Declared as package-private. accessed by {@link HdmiControlService} only. |
| 1217 | * |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1218 | * @param deviceInfo a new {@link HdmiDeviceInfo} to be added. |
| 1219 | * @return {@code null} if it is new device. Otherwise, returns old {@HdmiDeviceInfo} |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1220 | * that has the same logical address as new one has. |
| 1221 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1222 | @ServiceThreadOnly |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1223 | private HdmiDeviceInfo addDeviceInfo(HdmiDeviceInfo deviceInfo) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1224 | assertRunOnServiceThread(); |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1225 | HdmiDeviceInfo oldDeviceInfo = getCecDeviceInfo(deviceInfo.getLogicalAddress()); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1226 | if (oldDeviceInfo != null) { |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1227 | removeDeviceInfo(deviceInfo.getId()); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1228 | } |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1229 | mDeviceInfos.append(deviceInfo.getId(), deviceInfo); |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1230 | updateSafeDeviceInfoList(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1231 | return oldDeviceInfo; |
| 1232 | } |
| 1233 | |
| 1234 | /** |
| 1235 | * Remove a device info corresponding to the given {@code logicalAddress}. |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1236 | * It returns removed {@link HdmiDeviceInfo} if exists. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1237 | * |
| 1238 | * <p>Declared as package-private. accessed by {@link HdmiControlService} only. |
| 1239 | * |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1240 | * @param id id of device to be removed |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1241 | * @return removed {@link HdmiDeviceInfo} it exists. Otherwise, returns {@code null} |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1242 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1243 | @ServiceThreadOnly |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1244 | private HdmiDeviceInfo removeDeviceInfo(int id) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1245 | assertRunOnServiceThread(); |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1246 | HdmiDeviceInfo deviceInfo = mDeviceInfos.get(id); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1247 | if (deviceInfo != null) { |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1248 | mDeviceInfos.remove(id); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1249 | } |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1250 | updateSafeDeviceInfoList(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1251 | return deviceInfo; |
| 1252 | } |
| 1253 | |
| 1254 | /** |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1255 | * Return a list of all {@link HdmiDeviceInfo}. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1256 | * |
| 1257 | * <p>Declared as package-private. accessed by {@link HdmiControlService} only. |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 1258 | * This is not thread-safe. For thread safety, call {@link #getSafeExternalInputsLocked} which |
Jungshik Jang | 8e93c84 | 2014-08-06 15:48:33 +0900 | [diff] [blame] | 1259 | * does not include local device. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1260 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1261 | @ServiceThreadOnly |
Jinsuk Kim | 4b4b940 | 2014-09-02 10:30:10 +0900 | [diff] [blame] | 1262 | List<HdmiDeviceInfo> getDeviceInfoList(boolean includeLocalDevice) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1263 | assertRunOnServiceThread(); |
Jinsuk Kim | 4b4b940 | 2014-09-02 10:30:10 +0900 | [diff] [blame] | 1264 | if (includeLocalDevice) { |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1265 | return HdmiUtils.sparseArrayToList(mDeviceInfos); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1266 | } else { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1267 | ArrayList<HdmiDeviceInfo> infoList = new ArrayList<>(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1268 | for (int i = 0; i < mDeviceInfos.size(); ++i) { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1269 | HdmiDeviceInfo info = mDeviceInfos.valueAt(i); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1270 | if (!isLocalDeviceAddress(info.getLogicalAddress())) { |
| 1271 | infoList.add(info); |
| 1272 | } |
| 1273 | } |
| 1274 | return infoList; |
| 1275 | } |
| 1276 | } |
| 1277 | |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1278 | /** |
Jinsuk Kim | 9c37e1f | 2014-07-02 08:29:26 +0900 | [diff] [blame] | 1279 | * Return external input devices. |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1280 | */ |
Jinsuk Kim | ed08645 | 2014-08-18 15:01:53 +0900 | [diff] [blame] | 1281 | List<HdmiDeviceInfo> getSafeExternalInputsLocked() { |
| 1282 | return mSafeExternalInputs; |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1283 | } |
| 1284 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1285 | @ServiceThreadOnly |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1286 | private void updateSafeDeviceInfoList() { |
| 1287 | assertRunOnServiceThread(); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1288 | List<HdmiDeviceInfo> copiedDevices = HdmiUtils.sparseArrayToList(mDeviceInfos); |
| 1289 | List<HdmiDeviceInfo> externalInputs = getInputDevices(); |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1290 | synchronized (mLock) { |
| 1291 | mSafeAllDeviceInfos = copiedDevices; |
Jinsuk Kim | 9c37e1f | 2014-07-02 08:29:26 +0900 | [diff] [blame] | 1292 | mSafeExternalInputs = externalInputs; |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1293 | } |
| 1294 | } |
| 1295 | |
Jinsuk Kim | 9c37e1f | 2014-07-02 08:29:26 +0900 | [diff] [blame] | 1296 | /** |
| 1297 | * Return a list of external cec input (source) devices. |
| 1298 | * |
| 1299 | * <p>Note that this effectively excludes non-source devices like system audio, |
| 1300 | * secondary TV. |
| 1301 | */ |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1302 | private List<HdmiDeviceInfo> getInputDevices() { |
| 1303 | ArrayList<HdmiDeviceInfo> infoList = new ArrayList<>(); |
Jinsuk Kim | 9c37e1f | 2014-07-02 08:29:26 +0900 | [diff] [blame] | 1304 | for (int i = 0; i < mDeviceInfos.size(); ++i) { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1305 | HdmiDeviceInfo info = mDeviceInfos.valueAt(i); |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1306 | if (isLocalDeviceAddress(info.getLogicalAddress())) { |
Jinsuk Kim | 9c37e1f | 2014-07-02 08:29:26 +0900 | [diff] [blame] | 1307 | continue; |
| 1308 | } |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 1309 | if (info.isSourceType() && !hideDevicesBehindLegacySwitch(info)) { |
Jinsuk Kim | 9c37e1f | 2014-07-02 08:29:26 +0900 | [diff] [blame] | 1310 | infoList.add(info); |
| 1311 | } |
| 1312 | } |
| 1313 | return infoList; |
| 1314 | } |
| 1315 | |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 1316 | // Check if we are hiding CEC devices connected to a legacy (non-CEC) switch. |
| 1317 | // Returns true if the policy is set to true, and the device to check does not have |
| 1318 | // a parent CEC device (which should be the CEC-enabled switch) in the list. |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1319 | private boolean hideDevicesBehindLegacySwitch(HdmiDeviceInfo info) { |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 1320 | return HdmiConfig.HIDE_DEVICES_BEHIND_LEGACY_SWITCH |
| 1321 | && !isConnectedToCecSwitch(info.getPhysicalAddress(), mCecSwitches); |
| 1322 | } |
| 1323 | |
| 1324 | private static boolean isConnectedToCecSwitch(int path, Collection<Integer> switches) { |
| 1325 | for (int switchPath : switches) { |
| 1326 | if (isParentPath(switchPath, path)) { |
| 1327 | return true; |
| 1328 | } |
| 1329 | } |
| 1330 | return false; |
| 1331 | } |
| 1332 | |
| 1333 | private static boolean isParentPath(int parentPath, int childPath) { |
| 1334 | // (A000, AB00) (AB00, ABC0), (ABC0, ABCD) |
| 1335 | // If child's last non-zero nibble is removed, the result equals to the parent. |
| 1336 | for (int i = 0; i <= 12; i += 4) { |
| 1337 | int nibble = (childPath >> i) & 0xF; |
| 1338 | if (nibble != 0) { |
| 1339 | int parentNibble = (parentPath >> i) & 0xF; |
| 1340 | return parentNibble == 0 && (childPath >> i+4) == (parentPath >> i+4); |
| 1341 | } |
| 1342 | } |
| 1343 | return false; |
| 1344 | } |
| 1345 | |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1346 | private void invokeDeviceEventListener(HdmiDeviceInfo info, int status) { |
Jinsuk Kim | 98d760e | 2014-12-23 07:01:51 +0900 | [diff] [blame] | 1347 | if (!hideDevicesBehindLegacySwitch(info)) { |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1348 | mService.invokeDeviceEventListeners(info, status); |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1352 | private boolean isLocalDeviceAddress(int address) { |
Jinsuk Kim | bdf27fb | 2014-10-20 10:00:04 +0900 | [diff] [blame] | 1353 | return mLocalDeviceAddresses.contains(address); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1354 | } |
| 1355 | |
Jungshik Jang | e9cf158 | 2014-06-23 17:28:58 +0900 | [diff] [blame] | 1356 | @ServiceThreadOnly |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1357 | HdmiDeviceInfo getAvrDeviceInfo() { |
Jungshik Jang | e9cf158 | 2014-06-23 17:28:58 +0900 | [diff] [blame] | 1358 | assertRunOnServiceThread(); |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1359 | return getCecDeviceInfo(Constants.ADDR_AUDIO_SYSTEM); |
Jungshik Jang | e9cf158 | 2014-06-23 17:28:58 +0900 | [diff] [blame] | 1360 | } |
| 1361 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1362 | /** |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1363 | * Return a {@link HdmiDeviceInfo} corresponding to the given {@code logicalAddress}. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1364 | * |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1365 | * This is not thread-safe. For thread safety, call {@link #getSafeCecDeviceInfo(int)}. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1366 | * |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 1367 | * @param logicalAddress logical address of the device to be retrieved |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1368 | * @return {@link HdmiDeviceInfo} matched with the given {@code logicalAddress}. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1369 | * Returns null if no logical address matched |
| 1370 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1371 | @ServiceThreadOnly |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1372 | HdmiDeviceInfo getCecDeviceInfo(int logicalAddress) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1373 | assertRunOnServiceThread(); |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1374 | return mDeviceInfos.get(HdmiDeviceInfo.idForCecDevice(logicalAddress)); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1375 | } |
| 1376 | |
Jungshik Jang | e9cf158 | 2014-06-23 17:28:58 +0900 | [diff] [blame] | 1377 | boolean hasSystemAudioDevice() { |
| 1378 | return getSafeAvrDeviceInfo() != null; |
| 1379 | } |
| 1380 | |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1381 | HdmiDeviceInfo getSafeAvrDeviceInfo() { |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1382 | return getSafeCecDeviceInfo(Constants.ADDR_AUDIO_SYSTEM); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | /** |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1386 | * Thread safe version of {@link #getCecDeviceInfo(int)}. |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1387 | * |
| 1388 | * @param logicalAddress logical address to be retrieved |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1389 | * @return {@link HdmiDeviceInfo} matched with the given {@code logicalAddress}. |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1390 | * Returns null if no logical address matched |
| 1391 | */ |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1392 | HdmiDeviceInfo getSafeCecDeviceInfo(int logicalAddress) { |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1393 | synchronized (mLock) { |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1394 | for (HdmiDeviceInfo info : mSafeAllDeviceInfos) { |
| 1395 | if (info.isCecDevice() && info.getLogicalAddress() == logicalAddress) { |
| 1396 | return info; |
| 1397 | } |
| 1398 | } |
| 1399 | return null; |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | |
Jinsuk Kim | bdf27fb | 2014-10-20 10:00:04 +0900 | [diff] [blame] | 1403 | List<HdmiDeviceInfo> getSafeCecDevicesLocked() { |
| 1404 | ArrayList<HdmiDeviceInfo> infoList = new ArrayList<>(); |
| 1405 | for (HdmiDeviceInfo info : mSafeAllDeviceInfos) { |
| 1406 | if (isLocalDeviceAddress(info.getLogicalAddress())) { |
| 1407 | continue; |
| 1408 | } |
| 1409 | infoList.add(info); |
| 1410 | } |
| 1411 | return infoList; |
| 1412 | } |
| 1413 | |
Jungshik Jang | fa8e90d | 2014-06-23 14:40:32 +0900 | [diff] [blame] | 1414 | /** |
Jungshik Jang | 8f2ed35 | 2014-07-07 15:02:47 +0900 | [diff] [blame] | 1415 | * Called when a device is newly added or a new device is detected or |
| 1416 | * existing device is updated. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1417 | * |
| 1418 | * @param info device info of a new device. |
| 1419 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1420 | @ServiceThreadOnly |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1421 | final void addCecDevice(HdmiDeviceInfo info) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1422 | assertRunOnServiceThread(); |
Jinsuk Kim | 6102bac7 | 2014-12-09 00:11:58 +0900 | [diff] [blame] | 1423 | HdmiDeviceInfo old = addDeviceInfo(info); |
Jinsuk Kim | 13c030e | 2014-06-20 13:25:17 +0900 | [diff] [blame] | 1424 | if (info.getLogicalAddress() == mAddress) { |
| 1425 | // The addition of TV device itself should not be notified. |
| 1426 | return; |
| 1427 | } |
Jinsuk Kim | 6102bac7 | 2014-12-09 00:11:58 +0900 | [diff] [blame] | 1428 | if (old == null) { |
| 1429 | invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_ADD_DEVICE); |
| 1430 | } else if (!old.equals(info)) { |
Jinsuk Kim | 4fcbf0b | 2014-12-09 06:48:13 +0900 | [diff] [blame] | 1431 | invokeDeviceEventListener(old, HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE); |
| 1432 | invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_ADD_DEVICE); |
Jinsuk Kim | 6102bac7 | 2014-12-09 00:11:58 +0900 | [diff] [blame] | 1433 | } |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | /** |
| 1437 | * Called when a device is removed or removal of device is detected. |
| 1438 | * |
| 1439 | * @param address a logical address of a device to be removed |
| 1440 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1441 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1442 | final void removeCecDevice(int address) { |
| 1443 | assertRunOnServiceThread(); |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1444 | HdmiDeviceInfo info = removeDeviceInfo(HdmiDeviceInfo.idForCecDevice(address)); |
Jungshik Jang | 26dc71e | 2014-07-04 10:53:27 +0900 | [diff] [blame] | 1445 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1446 | mCecMessageCache.flushMessagesFrom(address); |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1447 | invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1448 | } |
| 1449 | |
Jungshik Jang | 26dc71e | 2014-07-04 10:53:27 +0900 | [diff] [blame] | 1450 | @ServiceThreadOnly |
| 1451 | void handleRemoveActiveRoutingPath(int path) { |
| 1452 | assertRunOnServiceThread(); |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 1453 | // Seq #23 |
| 1454 | if (isTailOfActivePath(path, getActivePath())) { |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 1455 | int newPath = mService.portIdToPath(getActivePortId()); |
Jinsuk Kim | 546d867 | 2014-11-24 07:30:54 +0900 | [diff] [blame] | 1456 | startRoutingControl(getActivePath(), newPath, true, null); |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | |
Jinsuk Kim | 5344cd9 | 2014-07-03 18:02:01 +0900 | [diff] [blame] | 1460 | /** |
| 1461 | * Launch routing control process. |
| 1462 | * |
| 1463 | * @param routingForBootup true if routing control is initiated due to One Touch Play |
| 1464 | * or TV power on |
| 1465 | */ |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 1466 | @ServiceThreadOnly |
Jinsuk Kim | 5344cd9 | 2014-07-03 18:02:01 +0900 | [diff] [blame] | 1467 | void launchRoutingControl(boolean routingForBootup) { |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 1468 | assertRunOnServiceThread(); |
| 1469 | // Seq #24 |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 1470 | if (getActivePortId() != Constants.INVALID_PORT_ID) { |
Jinsuk Kim | 5344cd9 | 2014-07-03 18:02:01 +0900 | [diff] [blame] | 1471 | if (!routingForBootup && !isProhibitMode()) { |
Jinsuk Kim | 5344cd9 | 2014-07-03 18:02:01 +0900 | [diff] [blame] | 1472 | int newPath = mService.portIdToPath(getActivePortId()); |
| 1473 | setActivePath(newPath); |
Jinsuk Kim | 546d867 | 2014-11-24 07:30:54 +0900 | [diff] [blame] | 1474 | startRoutingControl(getActivePath(), newPath, routingForBootup, null); |
Jinsuk Kim | 5344cd9 | 2014-07-03 18:02:01 +0900 | [diff] [blame] | 1475 | } |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 1476 | } else { |
| 1477 | int activePath = mService.getPhysicalAddress(); |
| 1478 | setActivePath(activePath); |
Jinsuk Kim | 2ab6d9f | 2015-01-16 15:49:16 +0900 | [diff] [blame] | 1479 | if (!routingForBootup |
| 1480 | && !mDelayedMessageBuffer.isBuffered(Constants.MESSAGE_ACTIVE_SOURCE)) { |
Jinsuk Kim | 5344cd9 | 2014-07-03 18:02:01 +0900 | [diff] [blame] | 1481 | mService.sendCecCommand(HdmiCecMessageBuilder.buildActiveSource(mAddress, |
| 1482 | activePath)); |
| 1483 | } |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1487 | /** |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1488 | * Returns the {@link HdmiDeviceInfo} instance whose physical address matches |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1489 | * the given routing path. CEC devices use routing path for its physical address to |
| 1490 | * describe the hierarchy of the devices in the network. |
| 1491 | * |
| 1492 | * @param path routing path or physical address |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1493 | * @return {@link HdmiDeviceInfo} if the matched info is found; otherwise null |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1494 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1495 | @ServiceThreadOnly |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1496 | final HdmiDeviceInfo getDeviceInfoByPath(int path) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1497 | assertRunOnServiceThread(); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1498 | for (HdmiDeviceInfo info : getDeviceInfoList(false)) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1499 | if (info.getPhysicalAddress() == path) { |
| 1500 | return info; |
| 1501 | } |
| 1502 | } |
| 1503 | return null; |
| 1504 | } |
| 1505 | |
| 1506 | /** |
Jinsuk Kim | 7640d98 | 2015-01-28 16:44:07 +0900 | [diff] [blame] | 1507 | * Returns the {@link HdmiDeviceInfo} instance whose physical address matches |
| 1508 | * the given routing path. This is the version accessible safely from threads |
| 1509 | * other than service thread. |
| 1510 | * |
| 1511 | * @param path routing path or physical address |
| 1512 | * @return {@link HdmiDeviceInfo} if the matched info is found; otherwise null |
| 1513 | */ |
| 1514 | HdmiDeviceInfo getSafeDeviceInfoByPath(int path) { |
| 1515 | synchronized (mLock) { |
| 1516 | for (HdmiDeviceInfo info : mSafeAllDeviceInfos) { |
| 1517 | if (info.getPhysicalAddress() == path) { |
| 1518 | return info; |
| 1519 | } |
| 1520 | } |
| 1521 | return null; |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | /** |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1526 | * Whether a device of the specified physical address and logical address exists |
| 1527 | * in a device info list. However, both are minimal condition and it could |
| 1528 | * be different device from the original one. |
| 1529 | * |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1530 | * @param logicalAddress logical address of a device to be searched |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 1531 | * @param physicalAddress physical address of a device to be searched |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1532 | * @return true if exist; otherwise false |
| 1533 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1534 | @ServiceThreadOnly |
Jinsuk Kim | 7cd4a58 | 2015-01-29 09:50:25 +0900 | [diff] [blame] | 1535 | boolean isInDeviceList(int logicalAddress, int physicalAddress) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1536 | assertRunOnServiceThread(); |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1537 | HdmiDeviceInfo device = getCecDeviceInfo(logicalAddress); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1538 | if (device == null) { |
| 1539 | return false; |
| 1540 | } |
| 1541 | return device.getPhysicalAddress() == physicalAddress; |
| 1542 | } |
| 1543 | |
| 1544 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 1545 | @ServiceThreadOnly |
Jinsuk Kim | 92b77cf | 2014-06-27 16:39:26 +0900 | [diff] [blame] | 1546 | void onHotplug(int portId, boolean connected) { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1547 | assertRunOnServiceThread(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1548 | |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 1549 | if (!connected) { |
| 1550 | removeCecSwitches(portId); |
| 1551 | } |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1552 | // Tv device will have permanent HotplugDetectionAction. |
| 1553 | List<HotplugDetectionAction> hotplugActions = getActions(HotplugDetectionAction.class); |
| 1554 | if (!hotplugActions.isEmpty()) { |
| 1555 | // Note that hotplug action is single action running on a machine. |
| 1556 | // "pollAllDevicesNow" cleans up timer and start poll action immediately. |
Jungshik Jang | 24c23c1 | 2014-07-07 18:04:39 +0900 | [diff] [blame] | 1557 | // It covers seq #40, #43. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 1558 | hotplugActions.get(0).pollAllDevicesNow(); |
| 1559 | } |
Jinsuk Kim | 2ee0d6f | 2015-01-28 17:38:28 +0900 | [diff] [blame] | 1560 | updateArcFeatureStatus(portId, connected); |
Jungshik Jang | 60cffce | 2014-06-12 18:03:04 +0900 | [diff] [blame] | 1561 | } |
Jinsuk Kim | 160a6e5 | 2014-07-02 06:16:36 +0900 | [diff] [blame] | 1562 | |
Jinsuk Kim | 4fdd0f4 | 2014-08-06 07:23:32 +0900 | [diff] [blame] | 1563 | private void removeCecSwitches(int portId) { |
| 1564 | Iterator<Integer> it = mCecSwitches.iterator(); |
| 1565 | while (!it.hasNext()) { |
| 1566 | int path = it.next(); |
| 1567 | if (pathToPortId(path) == portId) { |
| 1568 | it.remove(); |
| 1569 | } |
| 1570 | } |
| 1571 | } |
| 1572 | |
Jinsuk Kim | 160a6e5 | 2014-07-02 06:16:36 +0900 | [diff] [blame] | 1573 | @ServiceThreadOnly |
| 1574 | void setAutoDeviceOff(boolean enabled) { |
| 1575 | assertRunOnServiceThread(); |
| 1576 | mAutoDeviceOff = enabled; |
Jinsuk Kim | 544b62b | 2014-07-14 14:01:23 +0900 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | @ServiceThreadOnly |
| 1580 | void setAutoWakeup(boolean enabled) { |
| 1581 | assertRunOnServiceThread(); |
| 1582 | mAutoWakeup = enabled; |
Jinsuk Kim | 160a6e5 | 2014-07-02 06:16:36 +0900 | [diff] [blame] | 1583 | } |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 1584 | |
Yuncheol Heo | 25c2029 | 2014-07-31 17:59:39 +0900 | [diff] [blame] | 1585 | @ServiceThreadOnly |
| 1586 | boolean getAutoWakeup() { |
| 1587 | assertRunOnServiceThread(); |
| 1588 | return mAutoWakeup; |
| 1589 | } |
| 1590 | |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 1591 | @Override |
| 1592 | @ServiceThreadOnly |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 1593 | protected void disableDevice(boolean initiatedByCec, PendingActionClearedCallback callback) { |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 1594 | assertRunOnServiceThread(); |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 1595 | mService.unregisterTvInputCallback(mTvInputCallback); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 1596 | // Remove any repeated working actions. |
| 1597 | // HotplugDetectionAction will be reinstated during the wake up process. |
| 1598 | // HdmiControlService.onWakeUp() -> initializeLocalDevices() -> |
| 1599 | // LocalDeviceTv.onAddressAllocated() -> launchDeviceDiscovery(). |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 1600 | removeAction(DeviceDiscoveryAction.class); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 1601 | removeAction(HotplugDetectionAction.class); |
Jungshik Jang | 410ca9c | 2014-08-07 18:04:14 +0900 | [diff] [blame] | 1602 | removeAction(PowerStatusMonitorAction.class); |
Jungshik Jang | faa49bc | 2014-08-05 16:10:21 +0900 | [diff] [blame] | 1603 | // Remove recording actions. |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1604 | removeAction(OneTouchRecordAction.class); |
Jungshik Jang | faa49bc | 2014-08-05 16:10:21 +0900 | [diff] [blame] | 1605 | removeAction(TimerRecordingAction.class); |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 1606 | |
| 1607 | disableSystemAudioIfExist(); |
| 1608 | disableArcIfExist(); |
Jinsuk Kim | a5445ce | 2015-03-30 17:14:58 +0900 | [diff] [blame] | 1609 | |
| 1610 | super.disableDevice(initiatedByCec, callback); |
Jinsuk Kim | 49b47bb | 2014-07-22 10:40:35 +0900 | [diff] [blame] | 1611 | clearDeviceInfoList(); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 1612 | checkIfPendingActionsCleared(); |
| 1613 | } |
| 1614 | |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 1615 | @ServiceThreadOnly |
| 1616 | private void disableSystemAudioIfExist() { |
| 1617 | assertRunOnServiceThread(); |
| 1618 | if (getAvrDeviceInfo() == null) { |
| 1619 | return; |
| 1620 | } |
| 1621 | |
| 1622 | // Seq #31. |
| 1623 | removeAction(SystemAudioActionFromAvr.class); |
| 1624 | removeAction(SystemAudioActionFromTv.class); |
| 1625 | removeAction(SystemAudioAutoInitiationAction.class); |
| 1626 | removeAction(SystemAudioStatusAction.class); |
| 1627 | removeAction(VolumeControlAction.class); |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | @ServiceThreadOnly |
| 1631 | private void disableArcIfExist() { |
| 1632 | assertRunOnServiceThread(); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1633 | HdmiDeviceInfo avr = getAvrDeviceInfo(); |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 1634 | if (avr == null) { |
| 1635 | return; |
| 1636 | } |
| 1637 | |
| 1638 | // Seq #44. |
| 1639 | removeAction(RequestArcInitiationAction.class); |
Jinsuk Kim | 5bcf5bf | 2015-04-02 07:31:21 +0900 | [diff] [blame] | 1640 | if (!hasAction(RequestArcTerminationAction.class) && isArcEstablished()) { |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 1641 | addAndStartAction(new RequestArcTerminationAction(this, avr.getLogicalAddress())); |
| 1642 | } |
| 1643 | } |
| 1644 | |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 1645 | @Override |
| 1646 | @ServiceThreadOnly |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 1647 | protected void onStandby(boolean initiatedByCec) { |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 1648 | assertRunOnServiceThread(); |
| 1649 | // Seq #11 |
| 1650 | if (!mService.isControlEnabled()) { |
| 1651 | return; |
| 1652 | } |
Jinsuk Kim | 544b62b | 2014-07-14 14:01:23 +0900 | [diff] [blame] | 1653 | if (!initiatedByCec && mAutoDeviceOff) { |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 1654 | mService.sendCecCommand(HdmiCecMessageBuilder.buildStandby( |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 1655 | mAddress, Constants.ADDR_BROADCAST)); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | |
Jinsuk Kim | 4d43d93 | 2014-07-03 16:43:58 +0900 | [diff] [blame] | 1659 | boolean isProhibitMode() { |
| 1660 | return mService.isProhibitMode(); |
| 1661 | } |
Jinsuk Kim | b38cd68 | 2014-07-07 08:05:03 +0900 | [diff] [blame] | 1662 | |
| 1663 | boolean isPowerStandbyOrTransient() { |
| 1664 | return mService.isPowerStandbyOrTransient(); |
Jungshik Jang | 8866c81 | 2014-07-08 14:42:28 +0900 | [diff] [blame] | 1665 | } |
Jinsuk Kim | c7eba0f | 2014-07-07 14:18:02 +0900 | [diff] [blame] | 1666 | |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 1667 | @ServiceThreadOnly |
Jinsuk Kim | c7eba0f | 2014-07-07 14:18:02 +0900 | [diff] [blame] | 1668 | void displayOsd(int messageId) { |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 1669 | assertRunOnServiceThread(); |
| 1670 | mService.displayOsd(messageId); |
Jinsuk Kim | b38cd68 | 2014-07-07 08:05:03 +0900 | [diff] [blame] | 1671 | } |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1672 | |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 1673 | @ServiceThreadOnly |
| 1674 | void displayOsd(int messageId, int extra) { |
| 1675 | assertRunOnServiceThread(); |
| 1676 | mService.displayOsd(messageId, extra); |
| 1677 | } |
| 1678 | |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1679 | // Seq #54 and #55 |
| 1680 | @ServiceThreadOnly |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 1681 | int startOneTouchRecord(int recorderAddress, byte[] recordSource) { |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1682 | assertRunOnServiceThread(); |
| 1683 | if (!mService.isControlEnabled()) { |
| 1684 | Slog.w(TAG, "Can not start one touch record. CEC control is disabled."); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1685 | announceOneTouchRecordResult(recorderAddress, ONE_TOUCH_RECORD_CEC_DISABLED); |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 1686 | return Constants.ABORT_NOT_IN_CORRECT_MODE; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | if (!checkRecorder(recorderAddress)) { |
| 1690 | Slog.w(TAG, "Invalid recorder address:" + recorderAddress); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1691 | announceOneTouchRecordResult(recorderAddress, |
| 1692 | ONE_TOUCH_RECORD_CHECK_RECORDER_CONNECTION); |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 1693 | return Constants.ABORT_NOT_IN_CORRECT_MODE; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | if (!checkRecordSource(recordSource)) { |
| 1697 | Slog.w(TAG, "Invalid record source." + Arrays.toString(recordSource)); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1698 | announceOneTouchRecordResult(recorderAddress, |
| 1699 | ONE_TOUCH_RECORD_FAIL_TO_RECORD_DISPLAYED_SCREEN); |
Jinsuk Kim | d47abef | 2015-01-17 07:38:24 +0900 | [diff] [blame] | 1700 | return Constants.ABORT_CANNOT_PROVIDE_SOURCE; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | addAndStartAction(new OneTouchRecordAction(this, recorderAddress, recordSource)); |
| 1704 | Slog.i(TAG, "Start new [One Touch Record]-Target:" + recorderAddress + ", recordSource:" |
| 1705 | + Arrays.toString(recordSource)); |
Jungshik Jang | 4480efa | 2014-09-04 17:08:34 +0900 | [diff] [blame] | 1706 | return Constants.ABORT_NO_ERROR; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | @ServiceThreadOnly |
| 1710 | void stopOneTouchRecord(int recorderAddress) { |
| 1711 | assertRunOnServiceThread(); |
| 1712 | if (!mService.isControlEnabled()) { |
| 1713 | Slog.w(TAG, "Can not stop one touch record. CEC control is disabled."); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1714 | announceOneTouchRecordResult(recorderAddress, ONE_TOUCH_RECORD_CEC_DISABLED); |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1715 | return; |
| 1716 | } |
| 1717 | |
| 1718 | if (!checkRecorder(recorderAddress)) { |
| 1719 | Slog.w(TAG, "Invalid recorder address:" + recorderAddress); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1720 | announceOneTouchRecordResult(recorderAddress, |
| 1721 | ONE_TOUCH_RECORD_CHECK_RECORDER_CONNECTION); |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1722 | return; |
| 1723 | } |
| 1724 | |
| 1725 | // Remove one touch record action so that other one touch record can be started. |
| 1726 | removeAction(OneTouchRecordAction.class); |
| 1727 | mService.sendCecCommand(HdmiCecMessageBuilder.buildRecordOff(mAddress, recorderAddress)); |
| 1728 | Slog.i(TAG, "Stop [One Touch Record]-Target:" + recorderAddress); |
| 1729 | } |
| 1730 | |
| 1731 | private boolean checkRecorder(int recorderAddress) { |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1732 | HdmiDeviceInfo device = getCecDeviceInfo(recorderAddress); |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1733 | return (device != null) |
| 1734 | && (HdmiUtils.getTypeFromAddress(recorderAddress) |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1735 | == HdmiDeviceInfo.DEVICE_RECORDER); |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | private boolean checkRecordSource(byte[] recordSource) { |
| 1739 | return (recordSource != null) && HdmiRecordSources.checkRecordSource(recordSource); |
| 1740 | } |
| 1741 | |
| 1742 | @ServiceThreadOnly |
| 1743 | void startTimerRecording(int recorderAddress, int sourceType, byte[] recordSource) { |
| 1744 | assertRunOnServiceThread(); |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 1745 | if (!mService.isControlEnabled()) { |
| 1746 | Slog.w(TAG, "Can not start one touch record. CEC control is disabled."); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1747 | announceTimerRecordingResult(recorderAddress, |
| 1748 | TIMER_RECORDING_RESULT_EXTRA_CEC_DISABLED); |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 1749 | return; |
| 1750 | } |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1751 | |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 1752 | if (!checkRecorder(recorderAddress)) { |
| 1753 | Slog.w(TAG, "Invalid recorder address:" + recorderAddress); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1754 | announceTimerRecordingResult(recorderAddress, |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1755 | TIMER_RECORDING_RESULT_EXTRA_CHECK_RECORDER_CONNECTION); |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 1756 | return; |
| 1757 | } |
| 1758 | |
| 1759 | if (!checkTimerRecordingSource(sourceType, recordSource)) { |
| 1760 | Slog.w(TAG, "Invalid record source." + Arrays.toString(recordSource)); |
| 1761 | announceTimerRecordingResult( |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1762 | recorderAddress, |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1763 | TIMER_RECORDING_RESULT_EXTRA_FAIL_TO_RECORD_SELECTED_SOURCE); |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 1764 | return; |
| 1765 | } |
| 1766 | |
| 1767 | addAndStartAction( |
| 1768 | new TimerRecordingAction(this, recorderAddress, sourceType, recordSource)); |
| 1769 | Slog.i(TAG, "Start [Timer Recording]-Target:" + recorderAddress + ", SourceType:" |
| 1770 | + sourceType + ", RecordSource:" + Arrays.toString(recordSource)); |
| 1771 | } |
| 1772 | |
| 1773 | private boolean checkTimerRecordingSource(int sourceType, byte[] recordSource) { |
| 1774 | return (recordSource != null) |
| 1775 | && HdmiTimerRecordSources.checkTimerRecordSource(sourceType, recordSource); |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | @ServiceThreadOnly |
| 1779 | void clearTimerRecording(int recorderAddress, int sourceType, byte[] recordSource) { |
| 1780 | assertRunOnServiceThread(); |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1781 | if (!mService.isControlEnabled()) { |
| 1782 | Slog.w(TAG, "Can not start one touch record. CEC control is disabled."); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1783 | announceClearTimerRecordingResult(recorderAddress, CLEAR_TIMER_STATUS_CEC_DISABLE); |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1784 | return; |
| 1785 | } |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1786 | |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1787 | if (!checkRecorder(recorderAddress)) { |
| 1788 | Slog.w(TAG, "Invalid recorder address:" + recorderAddress); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1789 | announceClearTimerRecordingResult(recorderAddress, |
| 1790 | CLEAR_TIMER_STATUS_CHECK_RECORDER_CONNECTION); |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1791 | return; |
| 1792 | } |
| 1793 | |
| 1794 | if (!checkTimerRecordingSource(sourceType, recordSource)) { |
| 1795 | Slog.w(TAG, "Invalid record source." + Arrays.toString(recordSource)); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1796 | announceClearTimerRecordingResult(recorderAddress, |
| 1797 | CLEAR_TIMER_STATUS_FAIL_TO_CLEAR_SELECTED_SOURCE); |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1798 | return; |
| 1799 | } |
| 1800 | |
| 1801 | sendClearTimerMessage(recorderAddress, sourceType, recordSource); |
| 1802 | } |
| 1803 | |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1804 | private void sendClearTimerMessage(final int recorderAddress, int sourceType, |
| 1805 | byte[] recordSource) { |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1806 | HdmiCecMessage message = null; |
| 1807 | switch (sourceType) { |
| 1808 | case TIMER_RECORDING_TYPE_DIGITAL: |
| 1809 | message = HdmiCecMessageBuilder.buildClearDigitalTimer(mAddress, recorderAddress, |
| 1810 | recordSource); |
| 1811 | break; |
| 1812 | case TIMER_RECORDING_TYPE_ANALOGUE: |
| 1813 | message = HdmiCecMessageBuilder.buildClearAnalogueTimer(mAddress, recorderAddress, |
| 1814 | recordSource); |
| 1815 | break; |
| 1816 | case TIMER_RECORDING_TYPE_EXTERNAL: |
| 1817 | message = HdmiCecMessageBuilder.buildClearExternalTimer(mAddress, recorderAddress, |
| 1818 | recordSource); |
| 1819 | break; |
| 1820 | default: |
| 1821 | Slog.w(TAG, "Invalid source type:" + recorderAddress); |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1822 | announceClearTimerRecordingResult(recorderAddress, |
| 1823 | CLEAR_TIMER_STATUS_FAIL_TO_CLEAR_SELECTED_SOURCE); |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1824 | return; |
| 1825 | |
| 1826 | } |
| 1827 | mService.sendCecCommand(message, new SendMessageCallback() { |
| 1828 | @Override |
| 1829 | public void onSendCompleted(int error) { |
| 1830 | if (error != Constants.SEND_RESULT_SUCCESS) { |
Jungshik Jang | 326aef0 | 2014-11-05 12:50:35 +0900 | [diff] [blame] | 1831 | announceClearTimerRecordingResult(recorderAddress, |
Jungshik Jang | faa49bc | 2014-08-05 16:10:21 +0900 | [diff] [blame] | 1832 | CLEAR_TIMER_STATUS_FAIL_TO_CLEAR_SELECTED_SOURCE); |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 1833 | } |
| 1834 | } |
| 1835 | }); |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 1836 | } |
Jungshik Jang | 410ca9c | 2014-08-07 18:04:14 +0900 | [diff] [blame] | 1837 | |
| 1838 | void updateDevicePowerStatus(int logicalAddress, int newPowerStatus) { |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 1839 | HdmiDeviceInfo info = getCecDeviceInfo(logicalAddress); |
Jungshik Jang | 410ca9c | 2014-08-07 18:04:14 +0900 | [diff] [blame] | 1840 | if (info == null) { |
| 1841 | Slog.w(TAG, "Can not update power status of non-existing device:" + logicalAddress); |
| 1842 | return; |
| 1843 | } |
| 1844 | |
| 1845 | if (info.getDevicePowerStatus() == newPowerStatus) { |
| 1846 | return; |
| 1847 | } |
| 1848 | |
| 1849 | HdmiDeviceInfo newInfo = HdmiUtils.cloneHdmiDeviceInfo(info, newPowerStatus); |
| 1850 | // addDeviceInfo replaces old device info with new one if exists. |
| 1851 | addDeviceInfo(newInfo); |
| 1852 | |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1853 | invokeDeviceEventListener(newInfo, HdmiControlManager.DEVICE_EVENT_UPDATE_DEVICE); |
Jungshik Jang | 410ca9c | 2014-08-07 18:04:14 +0900 | [diff] [blame] | 1854 | } |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 1855 | |
| 1856 | @Override |
Yuncheol Heo | 184b124 | 2014-09-12 15:09:07 +0900 | [diff] [blame] | 1857 | protected boolean handleMenuStatus(HdmiCecMessage message) { |
| 1858 | // Do nothing and just return true not to prevent from responding <Feature Abort>. |
| 1859 | return true; |
| 1860 | } |
| 1861 | |
| 1862 | @Override |
Jinsuk Kim | d4a94db | 2014-09-12 13:51:10 +0900 | [diff] [blame] | 1863 | protected void sendStandby(int deviceId) { |
| 1864 | HdmiDeviceInfo targetDevice = mDeviceInfos.get(deviceId); |
| 1865 | if (targetDevice == null) { |
| 1866 | return; |
| 1867 | } |
| 1868 | int targetAddress = targetDevice.getLogicalAddress(); |
| 1869 | mService.sendCecCommand(HdmiCecMessageBuilder.buildStandby(mAddress, targetAddress)); |
| 1870 | } |
| 1871 | |
Jinsuk Kim | 7fa3a66 | 2014-11-07 15:20:24 +0900 | [diff] [blame] | 1872 | @ServiceThreadOnly |
| 1873 | void processAllDelayedMessages() { |
| 1874 | assertRunOnServiceThread(); |
| 1875 | mDelayedMessageBuffer.processAllMessages(); |
| 1876 | } |
| 1877 | |
| 1878 | @ServiceThreadOnly |
| 1879 | void processDelayedMessages(int address) { |
| 1880 | assertRunOnServiceThread(); |
| 1881 | mDelayedMessageBuffer.processMessagesForDevice(address); |
| 1882 | } |
| 1883 | |
Jinsuk Kim | 6e26f7f | 2015-01-07 16:45:14 +0900 | [diff] [blame] | 1884 | @ServiceThreadOnly |
| 1885 | void processDelayedActiveSource(int address) { |
| 1886 | assertRunOnServiceThread(); |
| 1887 | mDelayedMessageBuffer.processActiveSource(address); |
| 1888 | } |
| 1889 | |
Jinsuk Kim | d4a94db | 2014-09-12 13:51:10 +0900 | [diff] [blame] | 1890 | @Override |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 1891 | protected void dump(final IndentingPrintWriter pw) { |
| 1892 | super.dump(pw); |
| 1893 | pw.println("mArcEstablished: " + mArcEstablished); |
| 1894 | pw.println("mArcFeatureEnabled: " + mArcFeatureEnabled); |
| 1895 | pw.println("mSystemAudioActivated: " + mSystemAudioActivated); |
| 1896 | pw.println("mSystemAudioMute: " + mSystemAudioMute); |
| 1897 | pw.println("mAutoDeviceOff: " + mAutoDeviceOff); |
| 1898 | pw.println("mAutoWakeup: " + mAutoWakeup); |
| 1899 | pw.println("mSkipRoutingControl: " + mSkipRoutingControl); |
Jinsuk Kim | cb8661c | 2015-01-19 12:39:06 +0900 | [diff] [blame] | 1900 | pw.println("mPrevPortId: " + mPrevPortId); |
Jinsuk Kim | 4b4b940 | 2014-09-02 10:30:10 +0900 | [diff] [blame] | 1901 | pw.println("CEC devices:"); |
| 1902 | pw.increaseIndent(); |
| 1903 | for (HdmiDeviceInfo info : mSafeAllDeviceInfos) { |
| 1904 | pw.println(info); |
| 1905 | } |
| 1906 | pw.decreaseIndent(); |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 1907 | } |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 1908 | } |