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