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