Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | package com.android.server.hdmi; |
| 17 | |
Amy | 6506bd6 | 2018-07-02 17:29:36 -0700 | [diff] [blame] | 18 | import static com.android.server.hdmi.Constants.ALWAYS_SYSTEM_AUDIO_CONTROL_ON_POWER_ON; |
| 19 | import static com.android.server.hdmi.Constants.PROPERTY_SYSTEM_AUDIO_CONTROL_ON_POWER_ON; |
| 20 | import static com.android.server.hdmi.Constants.USE_LAST_STATE_SYSTEM_AUDIO_CONTROL_ON_POWER_ON; |
| 21 | |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 22 | import android.annotation.Nullable; |
Amy | 4aef3b40 | 2019-01-18 14:17:55 -0800 | [diff] [blame] | 23 | import android.content.ActivityNotFoundException; |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 24 | import android.content.Intent; |
shubang | d932cb5 | 2018-09-14 17:55:16 -0700 | [diff] [blame] | 25 | import android.hardware.hdmi.HdmiControlManager; |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 26 | import android.hardware.hdmi.HdmiDeviceInfo; |
Amy | 59176da | 2018-10-12 16:30:54 -0700 | [diff] [blame] | 27 | import android.hardware.hdmi.HdmiPortInfo; |
shubang | d932cb5 | 2018-09-14 17:55:16 -0700 | [diff] [blame] | 28 | import android.hardware.hdmi.IHdmiControlCallback; |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 29 | import android.media.AudioDeviceInfo; |
Nick Chalko | d70c413 | 2018-08-27 16:22:53 -0700 | [diff] [blame] | 30 | import android.media.AudioFormat; |
Amy | 2a6c3dc | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 31 | import android.media.AudioManager; |
Shubang | 81170da | 2018-07-12 18:02:52 -0700 | [diff] [blame] | 32 | import android.media.AudioSystem; |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 33 | import android.media.tv.TvContract; |
Amy | edd71e3 | 2019-02-11 13:39:39 -0800 | [diff] [blame] | 34 | import android.media.tv.TvInputInfo; |
| 35 | import android.media.tv.TvInputManager.TvInputCallback; |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 36 | import android.os.SystemProperties; |
Amy | 0c2e29f | 2018-10-23 12:17:52 -0700 | [diff] [blame] | 37 | import android.provider.Settings.Global; |
Amy | 89e93af | 2018-10-15 09:56:54 -0700 | [diff] [blame] | 38 | import android.util.Slog; |
| 39 | import android.util.SparseArray; |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 40 | |
Amy | 87eda82 | 2018-06-06 17:56:39 -0700 | [diff] [blame] | 41 | import com.android.internal.annotations.GuardedBy; |
Amy | 6506bd6 | 2018-07-02 17:29:36 -0700 | [diff] [blame] | 42 | import com.android.internal.annotations.VisibleForTesting; |
Nick Chalko | b9e48e2 | 2018-10-23 06:59:39 -0700 | [diff] [blame] | 43 | import com.android.internal.util.IndentingPrintWriter; |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 44 | import com.android.server.hdmi.Constants.AudioCodec; |
Amy | c00cd4e | 2018-10-16 20:21:33 -0700 | [diff] [blame] | 45 | import com.android.server.hdmi.DeviceDiscoveryAction.DeviceDiscoveryCallback; |
Amy | 4a92266 | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 46 | import com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly; |
Amy | d984bc6 | 2018-11-28 18:53:54 -0800 | [diff] [blame] | 47 | import com.android.server.hdmi.HdmiUtils.CodecSad; |
| 48 | import com.android.server.hdmi.HdmiUtils.DeviceConfig; |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 49 | |
Amy | d984bc6 | 2018-11-28 18:53:54 -0800 | [diff] [blame] | 50 | import org.xmlpull.v1.XmlPullParserException; |
| 51 | |
| 52 | import java.io.File; |
| 53 | import java.io.FileInputStream; |
| 54 | import java.io.IOException; |
| 55 | import java.io.InputStream; |
Amy | 89e93af | 2018-10-15 09:56:54 -0700 | [diff] [blame] | 56 | import java.io.UnsupportedEncodingException; |
Nick Chalko | d70c413 | 2018-08-27 16:22:53 -0700 | [diff] [blame] | 57 | import java.util.ArrayList; |
| 58 | import java.util.Arrays; |
Amy | ec126a5 | 2018-10-30 16:51:14 -0700 | [diff] [blame] | 59 | import java.util.Collections; |
Amy | 3403742 | 2018-09-06 13:21:08 -0700 | [diff] [blame] | 60 | import java.util.HashMap; |
Amy | c00cd4e | 2018-10-16 20:21:33 -0700 | [diff] [blame] | 61 | import java.util.List; |
Nick Chalko | d70c413 | 2018-08-27 16:22:53 -0700 | [diff] [blame] | 62 | import java.util.stream.Collectors; |
| 63 | |
Amy | 3403742 | 2018-09-06 13:21:08 -0700 | [diff] [blame] | 64 | |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 65 | /** |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 66 | * Represent a logical device of type {@link HdmiDeviceInfo#DEVICE_AUDIO_SYSTEM} residing in Android |
| 67 | * system. |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 68 | */ |
Amy | 848a9f2 | 2018-08-27 17:21:26 -0700 | [diff] [blame] | 69 | public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource { |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 70 | |
Amy | 4a92266 | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 71 | private static final String TAG = "HdmiCecLocalDeviceAudioSystem"; |
| 72 | |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 73 | // Whether the System Audio Control feature is enabled or not. True by default. |
| 74 | @GuardedBy("mLock") |
| 75 | private boolean mSystemAudioControlFeatureEnabled; |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 76 | |
Amy | 613330e | 2019-03-22 16:53:59 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Indicates if the TV that the current device is connected to supports System Audio Mode or not |
| 79 | * |
| 80 | * <p>If the current device has no information on this, keep mTvSystemAudioModeSupport null |
| 81 | * |
| 82 | * <p>The boolean will be reset to null every time when the current device goes to standby |
| 83 | * or loses its physical address. |
| 84 | */ |
| 85 | private Boolean mTvSystemAudioModeSupport = null; |
Shubang | ec66896 | 2018-07-13 19:03:19 -0700 | [diff] [blame] | 86 | |
Shubang | 81170da | 2018-07-12 18:02:52 -0700 | [diff] [blame] | 87 | // Whether ARC is available or not. "true" means that ARC is established between TV and |
| 88 | // AVR as audio receiver. |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 89 | @ServiceThreadOnly private boolean mArcEstablished = false; |
Shubang | 81170da | 2018-07-12 18:02:52 -0700 | [diff] [blame] | 90 | |
Amy | 3403742 | 2018-09-06 13:21:08 -0700 | [diff] [blame] | 91 | // If the current device uses TvInput for ARC. We assume all other inputs also use TvInput |
| 92 | // when ARC is using TvInput. |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 93 | private boolean mArcIntentUsed = SystemProperties |
| 94 | .get(Constants.PROPERTY_SYSTEM_AUDIO_DEVICE_ARC_PORT, "0").contains("tvinput"); |
Amy | 6a6d618 | 2018-08-20 17:38:47 -0700 | [diff] [blame] | 95 | |
Amy | 3403742 | 2018-09-06 13:21:08 -0700 | [diff] [blame] | 96 | // Keeps the mapping (HDMI port ID to TV input URI) to keep track of the TV inputs ready to |
Amy | edd71e3 | 2019-02-11 13:39:39 -0800 | [diff] [blame] | 97 | // accept input switching request from HDMI devices. |
| 98 | @GuardedBy("mLock") |
| 99 | private final HashMap<Integer, String> mPortIdToTvInputs = new HashMap<>(); |
| 100 | |
| 101 | // A map from TV input id to HDMI device info. |
| 102 | @GuardedBy("mLock") |
| 103 | private final HashMap<String, HdmiDeviceInfo> mTvInputsToDeviceInfo = new HashMap<>(); |
Amy | 3403742 | 2018-09-06 13:21:08 -0700 | [diff] [blame] | 104 | |
Amy | ec126a5 | 2018-10-30 16:51:14 -0700 | [diff] [blame] | 105 | // Copy of mDeviceInfos to guarantee thread-safety. |
| 106 | @GuardedBy("mLock") |
| 107 | private List<HdmiDeviceInfo> mSafeAllDeviceInfos = Collections.emptyList(); |
| 108 | |
Amy | 5c6026b | 2018-10-12 14:42:43 -0700 | [diff] [blame] | 109 | // Map-like container of all cec devices. |
| 110 | // device id is used as key of container. |
| 111 | private final SparseArray<HdmiDeviceInfo> mDeviceInfos = new SparseArray<>(); |
| 112 | |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 113 | protected HdmiCecLocalDeviceAudioSystem(HdmiControlService service) { |
| 114 | super(service, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM); |
Amy | 0c2e29f | 2018-10-23 12:17:52 -0700 | [diff] [blame] | 115 | mRoutingControlFeatureEnabled = |
Amy | 77e672c | 2018-10-31 15:55:40 -0700 | [diff] [blame] | 116 | mService.readBooleanSetting(Global.HDMI_CEC_SWITCH_ENABLED, false); |
Amy | 79db52f | 2018-10-23 12:45:17 -0700 | [diff] [blame] | 117 | mSystemAudioControlFeatureEnabled = |
| 118 | mService.readBooleanSetting(Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED, true); |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Amy | d984bc6 | 2018-11-28 18:53:54 -0800 | [diff] [blame] | 121 | private static final String SHORT_AUDIO_DESCRIPTOR_CONFIG_PATH = "/vendor/etc/sadConfig.xml"; |
| 122 | |
Amy | edd71e3 | 2019-02-11 13:39:39 -0800 | [diff] [blame] | 123 | private final TvInputCallback mTvInputCallback = new TvInputCallback() { |
| 124 | @Override |
| 125 | public void onInputAdded(String inputId) { |
| 126 | addOrUpdateTvInput(inputId); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void onInputRemoved(String inputId) { |
| 131 | removeTvInput(inputId); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public void onInputUpdated(String inputId) { |
| 136 | addOrUpdateTvInput(inputId); |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | @ServiceThreadOnly |
| 141 | private void addOrUpdateTvInput(String inputId) { |
| 142 | assertRunOnServiceThread(); |
| 143 | synchronized (mLock) { |
| 144 | TvInputInfo tvInfo = mService.getTvInputManager().getTvInputInfo(inputId); |
| 145 | if (tvInfo == null) { |
| 146 | return; |
| 147 | } |
| 148 | HdmiDeviceInfo info = tvInfo.getHdmiDeviceInfo(); |
| 149 | if (info == null) { |
| 150 | return; |
| 151 | } |
| 152 | mPortIdToTvInputs.put(info.getPortId(), inputId); |
| 153 | mTvInputsToDeviceInfo.put(inputId, info); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | @ServiceThreadOnly |
| 158 | private void removeTvInput(String inputId) { |
| 159 | assertRunOnServiceThread(); |
| 160 | synchronized (mLock) { |
| 161 | if (mTvInputsToDeviceInfo.get(inputId) == null) { |
| 162 | return; |
| 163 | } |
| 164 | int portId = mTvInputsToDeviceInfo.get(inputId).getPortId(); |
| 165 | mPortIdToTvInputs.remove(portId); |
| 166 | mTvInputsToDeviceInfo.remove(inputId); |
| 167 | } |
| 168 | } |
| 169 | |
Amy | 5c6026b | 2018-10-12 14:42:43 -0700 | [diff] [blame] | 170 | /** |
| 171 | * Called when a device is newly added or a new device is detected or |
Amy | 1e4a8cc | 2018-10-15 10:18:14 -0700 | [diff] [blame] | 172 | * an existing device is updated. |
Amy | 5c6026b | 2018-10-12 14:42:43 -0700 | [diff] [blame] | 173 | * |
| 174 | * @param info device info of a new device. |
| 175 | */ |
| 176 | @ServiceThreadOnly |
| 177 | final void addCecDevice(HdmiDeviceInfo info) { |
| 178 | assertRunOnServiceThread(); |
| 179 | HdmiDeviceInfo old = addDeviceInfo(info); |
Amy | 89e93af | 2018-10-15 09:56:54 -0700 | [diff] [blame] | 180 | if (info.getPhysicalAddress() == mService.getPhysicalAddress()) { |
Amy | 5c6026b | 2018-10-12 14:42:43 -0700 | [diff] [blame] | 181 | // The addition of the device itself should not be notified. |
Amy | 89e93af | 2018-10-15 09:56:54 -0700 | [diff] [blame] | 182 | // Note that different logical address could still be the same local device. |
Amy | 5c6026b | 2018-10-12 14:42:43 -0700 | [diff] [blame] | 183 | return; |
| 184 | } |
| 185 | if (old == null) { |
| 186 | invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_ADD_DEVICE); |
| 187 | } else if (!old.equals(info)) { |
| 188 | invokeDeviceEventListener(old, HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE); |
| 189 | invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_ADD_DEVICE); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Called when a device is removed or removal of device is detected. |
| 195 | * |
| 196 | * @param address a logical address of a device to be removed |
| 197 | */ |
| 198 | @ServiceThreadOnly |
| 199 | final void removeCecDevice(int address) { |
| 200 | assertRunOnServiceThread(); |
| 201 | HdmiDeviceInfo info = removeDeviceInfo(HdmiDeviceInfo.idForCecDevice(address)); |
| 202 | |
| 203 | mCecMessageCache.flushMessagesFrom(address); |
| 204 | invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE); |
| 205 | } |
| 206 | |
| 207 | /** |
Amy | 89e93af | 2018-10-15 09:56:54 -0700 | [diff] [blame] | 208 | * Called when a device is updated. |
| 209 | * |
| 210 | * @param info device info of the updating device. |
| 211 | */ |
| 212 | @ServiceThreadOnly |
| 213 | final void updateCecDevice(HdmiDeviceInfo info) { |
| 214 | assertRunOnServiceThread(); |
| 215 | HdmiDeviceInfo old = addDeviceInfo(info); |
| 216 | |
| 217 | if (old == null) { |
| 218 | invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_ADD_DEVICE); |
| 219 | } else if (!old.equals(info)) { |
| 220 | invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_UPDATE_DEVICE); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Add a new {@link HdmiDeviceInfo}. It returns old device info which has the same |
Amy | 5c6026b | 2018-10-12 14:42:43 -0700 | [diff] [blame] | 226 | * logical address as new device info's. |
| 227 | * |
| 228 | * @param deviceInfo a new {@link HdmiDeviceInfo} to be added. |
| 229 | * @return {@code null} if it is new device. Otherwise, returns old {@HdmiDeviceInfo} |
| 230 | * that has the same logical address as new one has. |
| 231 | */ |
| 232 | @ServiceThreadOnly |
Amy | 89e93af | 2018-10-15 09:56:54 -0700 | [diff] [blame] | 233 | @VisibleForTesting |
| 234 | protected HdmiDeviceInfo addDeviceInfo(HdmiDeviceInfo deviceInfo) { |
Amy | 5c6026b | 2018-10-12 14:42:43 -0700 | [diff] [blame] | 235 | assertRunOnServiceThread(); |
| 236 | HdmiDeviceInfo oldDeviceInfo = getCecDeviceInfo(deviceInfo.getLogicalAddress()); |
| 237 | if (oldDeviceInfo != null) { |
| 238 | removeDeviceInfo(deviceInfo.getId()); |
| 239 | } |
| 240 | mDeviceInfos.append(deviceInfo.getId(), deviceInfo); |
Amy | ec126a5 | 2018-10-30 16:51:14 -0700 | [diff] [blame] | 241 | updateSafeDeviceInfoList(); |
Amy | 5c6026b | 2018-10-12 14:42:43 -0700 | [diff] [blame] | 242 | return oldDeviceInfo; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Remove a device info corresponding to the given {@code logicalAddress}. |
| 247 | * It returns removed {@link HdmiDeviceInfo} if exists. |
| 248 | * |
| 249 | * @param id id of device to be removed |
| 250 | * @return removed {@link HdmiDeviceInfo} it exists. Otherwise, returns {@code null} |
| 251 | */ |
| 252 | @ServiceThreadOnly |
| 253 | private HdmiDeviceInfo removeDeviceInfo(int id) { |
| 254 | assertRunOnServiceThread(); |
| 255 | HdmiDeviceInfo deviceInfo = mDeviceInfos.get(id); |
| 256 | if (deviceInfo != null) { |
| 257 | mDeviceInfos.remove(id); |
| 258 | } |
Amy | ec126a5 | 2018-10-30 16:51:14 -0700 | [diff] [blame] | 259 | updateSafeDeviceInfoList(); |
Amy | 5c6026b | 2018-10-12 14:42:43 -0700 | [diff] [blame] | 260 | return deviceInfo; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Return a {@link HdmiDeviceInfo} corresponding to the given {@code logicalAddress}. |
| 265 | * |
| 266 | * @param logicalAddress logical address of the device to be retrieved |
| 267 | * @return {@link HdmiDeviceInfo} matched with the given {@code logicalAddress}. |
| 268 | * Returns null if no logical address matched |
| 269 | */ |
| 270 | @ServiceThreadOnly |
| 271 | HdmiDeviceInfo getCecDeviceInfo(int logicalAddress) { |
| 272 | assertRunOnServiceThread(); |
| 273 | return mDeviceInfos.get(HdmiDeviceInfo.idForCecDevice(logicalAddress)); |
| 274 | } |
| 275 | |
Amy | ec126a5 | 2018-10-30 16:51:14 -0700 | [diff] [blame] | 276 | @ServiceThreadOnly |
| 277 | private void updateSafeDeviceInfoList() { |
| 278 | assertRunOnServiceThread(); |
| 279 | List<HdmiDeviceInfo> copiedDevices = HdmiUtils.sparseArrayToList(mDeviceInfos); |
| 280 | synchronized (mLock) { |
| 281 | mSafeAllDeviceInfos = copiedDevices; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | @GuardedBy("mLock") |
| 286 | List<HdmiDeviceInfo> getSafeCecDevicesLocked() { |
| 287 | ArrayList<HdmiDeviceInfo> infoList = new ArrayList<>(); |
| 288 | for (HdmiDeviceInfo info : mSafeAllDeviceInfos) { |
| 289 | infoList.add(info); |
| 290 | } |
| 291 | return infoList; |
| 292 | } |
| 293 | |
Amy | 5c6026b | 2018-10-12 14:42:43 -0700 | [diff] [blame] | 294 | private void invokeDeviceEventListener(HdmiDeviceInfo info, int status) { |
| 295 | mService.invokeDeviceEventListeners(info, status); |
| 296 | } |
| 297 | |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 298 | @Override |
Amy | 4a92266 | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 299 | @ServiceThreadOnly |
Amy | 59176da | 2018-10-12 16:30:54 -0700 | [diff] [blame] | 300 | void onHotplug(int portId, boolean connected) { |
| 301 | assertRunOnServiceThread(); |
| 302 | if (connected) { |
| 303 | mService.wakeUp(); |
| 304 | } |
| 305 | if (mService.getPortInfo(portId).getType() == HdmiPortInfo.PORT_OUTPUT) { |
| 306 | mCecMessageCache.flushAll(); |
Amy | edd71e3 | 2019-02-11 13:39:39 -0800 | [diff] [blame] | 307 | } else if (!connected && mPortIdToTvInputs.get(portId) != null) { |
| 308 | String tvInputId = mPortIdToTvInputs.get(portId); |
| 309 | HdmiDeviceInfo info = mTvInputsToDeviceInfo.get(tvInputId); |
| 310 | if (info == null) { |
| 311 | return; |
| 312 | } |
| 313 | // Update with TIF on the device removal. TIF callback will update |
| 314 | // mPortIdToTvInputs and mPortIdToTvInputs. |
| 315 | removeCecDevice(info.getLogicalAddress()); |
Amy | 59176da | 2018-10-12 16:30:54 -0700 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
| 319 | @Override |
| 320 | @ServiceThreadOnly |
Amy | edd71e3 | 2019-02-11 13:39:39 -0800 | [diff] [blame] | 321 | protected void disableDevice(boolean initiatedByCec, PendingActionClearedCallback callback) { |
| 322 | super.disableDevice(initiatedByCec, callback); |
| 323 | assertRunOnServiceThread(); |
| 324 | mService.unregisterTvInputCallback(mTvInputCallback); |
Amy | d5a1514 | 2019-03-22 11:22:05 -0700 | [diff] [blame] | 325 | // TODO(b/129088603): check disableDevice and onStandby behaviors per spec |
Amy | edd71e3 | 2019-02-11 13:39:39 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | @Override |
| 329 | @ServiceThreadOnly |
Amy | b887fa0 | 2018-06-21 11:22:13 -0700 | [diff] [blame] | 330 | protected void onStandby(boolean initiatedByCec, int standbyAction) { |
| 331 | assertRunOnServiceThread(); |
Amy | 8ecb001 | 2019-05-09 19:06:42 -0700 | [diff] [blame] | 332 | // Invalidate the internal active source record when goes to standby |
| 333 | // This set will also update mIsActiveSource |
| 334 | mService.setActiveSource(Constants.ADDR_INVALID, Constants.INVALID_PHYSICAL_ADDRESS); |
Amy | 613330e | 2019-03-22 16:53:59 -0700 | [diff] [blame] | 335 | mTvSystemAudioModeSupport = null; |
Amy | 6506bd6 | 2018-07-02 17:29:36 -0700 | [diff] [blame] | 336 | // Record the last state of System Audio Control before going to standby |
| 337 | synchronized (mLock) { |
Amy | 59c06c1 | 2019-01-18 15:35:15 -0800 | [diff] [blame] | 338 | mService.writeStringSystemProperty( |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 339 | Constants.PROPERTY_LAST_SYSTEM_AUDIO_CONTROL, |
Amy | 489454f | 2019-01-24 19:06:57 -0800 | [diff] [blame] | 340 | isSystemAudioActivated() ? "true" : "false"); |
Amy | 6506bd6 | 2018-07-02 17:29:36 -0700 | [diff] [blame] | 341 | } |
Shubang | bc2aab3 | 2018-07-19 16:41:17 -0700 | [diff] [blame] | 342 | terminateSystemAudioMode(); |
Amy | b887fa0 | 2018-06-21 11:22:13 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | @Override |
| 346 | @ServiceThreadOnly |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 347 | protected void onAddressAllocated(int logicalAddress, int reason) { |
| 348 | assertRunOnServiceThread(); |
Amy | b9d7f43 | 2018-11-30 15:08:30 -0800 | [diff] [blame] | 349 | if (reason == mService.INITIATED_BY_ENABLE_CEC) { |
| 350 | mService.setAndBroadcastActiveSource(mService.getPhysicalAddress(), |
| 351 | getDeviceInfo().getDeviceType(), Constants.ADDR_BROADCAST); |
| 352 | } |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 353 | mService.sendCecCommand( |
| 354 | HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( |
| 355 | mAddress, mService.getPhysicalAddress(), mDeviceType)); |
| 356 | mService.sendCecCommand( |
| 357 | HdmiCecMessageBuilder.buildDeviceVendorIdCommand(mAddress, mService.getVendorId())); |
Amy | edd71e3 | 2019-02-11 13:39:39 -0800 | [diff] [blame] | 358 | mService.registerTvInputCallback(mTvInputCallback); |
Amy | 86347ba | 2019-04-04 16:22:54 -0700 | [diff] [blame] | 359 | // Some TVs, for example Mi TV, need ARC on before turning System Audio Mode on |
| 360 | // to request Short Audio Descriptor. Since ARC and SAM are independent, |
| 361 | // we can turn on ARC anyways when audio system device just boots up. |
| 362 | initArcOnFromAvr(); |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 363 | int systemAudioControlOnPowerOnProp = |
| 364 | SystemProperties.getInt( |
| 365 | PROPERTY_SYSTEM_AUDIO_CONTROL_ON_POWER_ON, |
| 366 | ALWAYS_SYSTEM_AUDIO_CONTROL_ON_POWER_ON); |
| 367 | boolean lastSystemAudioControlStatus = |
| 368 | SystemProperties.getBoolean(Constants.PROPERTY_LAST_SYSTEM_AUDIO_CONTROL, true); |
Amy | 6506bd6 | 2018-07-02 17:29:36 -0700 | [diff] [blame] | 369 | systemAudioControlOnPowerOn(systemAudioControlOnPowerOnProp, lastSystemAudioControlStatus); |
Amy | c00cd4e | 2018-10-16 20:21:33 -0700 | [diff] [blame] | 370 | clearDeviceInfoList(); |
| 371 | launchDeviceDiscovery(); |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 372 | startQueuedActions(); |
| 373 | } |
| 374 | |
Shubang Lu | 00b976a | 2018-08-01 18:11:46 -0700 | [diff] [blame] | 375 | @Override |
| 376 | protected int findKeyReceiverAddress() { |
Amy | 2a5e245 | 2018-11-29 20:32:20 -0800 | [diff] [blame] | 377 | if (getActiveSource().isValid()) { |
| 378 | return getActiveSource().logicalAddress; |
| 379 | } |
| 380 | return Constants.ADDR_INVALID; |
Shubang Lu | 00b976a | 2018-08-01 18:11:46 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Amy | 6506bd6 | 2018-07-02 17:29:36 -0700 | [diff] [blame] | 383 | @VisibleForTesting |
| 384 | protected void systemAudioControlOnPowerOn( |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 385 | int systemAudioOnPowerOnProp, boolean lastSystemAudioControlStatus) { |
| 386 | if ((systemAudioOnPowerOnProp == ALWAYS_SYSTEM_AUDIO_CONTROL_ON_POWER_ON) |
| 387 | || ((systemAudioOnPowerOnProp == USE_LAST_STATE_SYSTEM_AUDIO_CONTROL_ON_POWER_ON) |
Amy | 79db52f | 2018-10-23 12:45:17 -0700 | [diff] [blame] | 388 | && lastSystemAudioControlStatus && isSystemAudioControlFeatureEnabled())) { |
Amy | 6506bd6 | 2018-07-02 17:29:36 -0700 | [diff] [blame] | 389 | addAndStartAction(new SystemAudioInitiationActionFromAvr(this)); |
| 390 | } |
| 391 | } |
| 392 | |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 393 | @Override |
Amy | 4a92266 | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 394 | @ServiceThreadOnly |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 395 | protected int getPreferredAddress() { |
| 396 | assertRunOnServiceThread(); |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 397 | return SystemProperties.getInt( |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 398 | Constants.PROPERTY_PREFERRED_ADDRESS_AUDIO_SYSTEM, Constants.ADDR_UNREGISTERED); |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | @Override |
Amy | 4a92266 | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 402 | @ServiceThreadOnly |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 403 | protected void setPreferredAddress(int addr) { |
| 404 | assertRunOnServiceThread(); |
Amy | 59c06c1 | 2019-01-18 15:35:15 -0800 | [diff] [blame] | 405 | mService.writeStringSystemProperty( |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 406 | Constants.PROPERTY_PREFERRED_ADDRESS_AUDIO_SYSTEM, String.valueOf(addr)); |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 407 | } |
Amy | 4a92266 | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 408 | |
| 409 | @Override |
| 410 | @ServiceThreadOnly |
Amy | 89e93af | 2018-10-15 09:56:54 -0700 | [diff] [blame] | 411 | protected boolean handleReportPhysicalAddress(HdmiCecMessage message) { |
| 412 | assertRunOnServiceThread(); |
| 413 | int path = HdmiUtils.twoBytesToInt(message.getParams()); |
| 414 | int address = message.getSource(); |
| 415 | int type = message.getParams()[2]; |
| 416 | |
| 417 | // Ignore if [Device Discovery Action] is going on. |
| 418 | if (hasAction(DeviceDiscoveryAction.class)) { |
| 419 | Slog.i(TAG, "Ignored while Device Discovery Action is in progress: " + message); |
| 420 | return true; |
| 421 | } |
| 422 | |
| 423 | // Update the device info with TIF, note that the same device info could have added in |
| 424 | // device discovery and we do not want to override it with default OSD name. Therefore we |
| 425 | // need the following check to skip redundant device info updating. |
| 426 | HdmiDeviceInfo oldDevice = getCecDeviceInfo(address); |
| 427 | if (oldDevice == null || oldDevice.getPhysicalAddress() != path) { |
| 428 | addCecDevice(new HdmiDeviceInfo( |
| 429 | address, path, mService.pathToPortId(path), type, |
| 430 | Constants.UNKNOWN_VENDOR_ID, HdmiUtils.getDefaultDeviceName(address))); |
| 431 | // if we are adding a new device info, send out a give osd name command |
| 432 | // to update the name of the device in TIF |
| 433 | mService.sendCecCommand( |
| 434 | HdmiCecMessageBuilder.buildGiveOsdNameCommand(mAddress, address)); |
| 435 | return true; |
| 436 | } |
| 437 | |
| 438 | Slog.w(TAG, "Device info exists. Not updating on Physical Address."); |
| 439 | return true; |
| 440 | } |
| 441 | |
| 442 | @Override |
Amy | 1e4a8cc | 2018-10-15 10:18:14 -0700 | [diff] [blame] | 443 | protected boolean handleReportPowerStatus(HdmiCecMessage command) { |
| 444 | int newStatus = command.getParams()[0] & 0xFF; |
| 445 | updateDevicePowerStatus(command.getSource(), newStatus); |
| 446 | return true; |
| 447 | } |
| 448 | |
| 449 | @Override |
Amy | 89e93af | 2018-10-15 09:56:54 -0700 | [diff] [blame] | 450 | @ServiceThreadOnly |
| 451 | protected boolean handleSetOsdName(HdmiCecMessage message) { |
| 452 | int source = message.getSource(); |
| 453 | String osdName; |
| 454 | HdmiDeviceInfo deviceInfo = getCecDeviceInfo(source); |
| 455 | // If the device is not in device list, ignore it. |
| 456 | if (deviceInfo == null) { |
| 457 | Slog.i(TAG, "No source device info for <Set Osd Name>." + message); |
| 458 | return true; |
| 459 | } |
| 460 | try { |
| 461 | osdName = new String(message.getParams(), "US-ASCII"); |
| 462 | } catch (UnsupportedEncodingException e) { |
| 463 | Slog.e(TAG, "Invalid <Set Osd Name> request:" + message, e); |
| 464 | return true; |
| 465 | } |
| 466 | |
| 467 | if (deviceInfo.getDisplayName().equals(osdName)) { |
| 468 | Slog.d(TAG, "Ignore incoming <Set Osd Name> having same osd name:" + message); |
| 469 | return true; |
| 470 | } |
| 471 | |
| 472 | Slog.d(TAG, "Updating device OSD name from " |
| 473 | + deviceInfo.getDisplayName() |
| 474 | + " to " + osdName); |
| 475 | updateCecDevice(new HdmiDeviceInfo(deviceInfo.getLogicalAddress(), |
| 476 | deviceInfo.getPhysicalAddress(), deviceInfo.getPortId(), |
| 477 | deviceInfo.getDeviceType(), deviceInfo.getVendorId(), osdName)); |
| 478 | return true; |
| 479 | } |
| 480 | |
| 481 | @Override |
| 482 | @ServiceThreadOnly |
Amy | 4a92266 | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 483 | protected boolean handleInitiateArc(HdmiCecMessage message) { |
| 484 | assertRunOnServiceThread(); |
| 485 | // TODO(amyjojo): implement initiate arc handler |
| 486 | HdmiLogger.debug(TAG + "Stub handleInitiateArc"); |
| 487 | return true; |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | @ServiceThreadOnly |
| 492 | protected boolean handleReportArcInitiate(HdmiCecMessage message) { |
| 493 | assertRunOnServiceThread(); |
| 494 | // TODO(amyjojo): implement report arc initiate handler |
| 495 | HdmiLogger.debug(TAG + "Stub handleReportArcInitiate"); |
| 496 | return true; |
| 497 | } |
| 498 | |
| 499 | @Override |
| 500 | @ServiceThreadOnly |
| 501 | protected boolean handleReportArcTermination(HdmiCecMessage message) { |
| 502 | assertRunOnServiceThread(); |
| 503 | // TODO(amyjojo): implement report arc terminate handler |
| 504 | HdmiLogger.debug(TAG + "Stub handleReportArcTermination"); |
| 505 | return true; |
| 506 | } |
Amy | 2a6c3dc | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 507 | |
| 508 | @Override |
| 509 | @ServiceThreadOnly |
| 510 | protected boolean handleGiveAudioStatus(HdmiCecMessage message) { |
| 511 | assertRunOnServiceThread(); |
Amy | 79db52f | 2018-10-23 12:45:17 -0700 | [diff] [blame] | 512 | if (isSystemAudioControlFeatureEnabled()) { |
| 513 | reportAudioStatus(message.getSource()); |
| 514 | } else { |
| 515 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED); |
| 516 | } |
Amy | 2a6c3dc | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 517 | return true; |
| 518 | } |
| 519 | |
Amy | 87eda82 | 2018-06-06 17:56:39 -0700 | [diff] [blame] | 520 | @Override |
| 521 | @ServiceThreadOnly |
| 522 | protected boolean handleGiveSystemAudioModeStatus(HdmiCecMessage message) { |
| 523 | assertRunOnServiceThread(); |
Amy | 27ae403 | 2019-01-31 16:42:16 -0800 | [diff] [blame] | 524 | // If the audio system is initiating the system audio mode on and TV asks the sam status at |
| 525 | // the same time, respond with true. Since we know TV supports sam in this situation. |
| 526 | // If the query comes from STB, we should respond with the current sam status and the STB |
| 527 | // should listen to the <Set System Audio Mode> broadcasting. |
| 528 | boolean isSystemAudioModeOnOrTurningOn = isSystemAudioActivated(); |
| 529 | if (!isSystemAudioModeOnOrTurningOn |
| 530 | && message.getSource() == Constants.ADDR_TV |
| 531 | && hasAction(SystemAudioInitiationActionFromAvr.class)) { |
| 532 | isSystemAudioModeOnOrTurningOn = true; |
| 533 | } |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 534 | mService.sendCecCommand( |
| 535 | HdmiCecMessageBuilder.buildReportSystemAudioMode( |
Amy | 27ae403 | 2019-01-31 16:42:16 -0800 | [diff] [blame] | 536 | mAddress, message.getSource(), isSystemAudioModeOnOrTurningOn)); |
Amy | 87eda82 | 2018-06-06 17:56:39 -0700 | [diff] [blame] | 537 | return true; |
| 538 | } |
| 539 | |
Amy | 4e7ff1a | 2018-06-07 16:24:31 -0700 | [diff] [blame] | 540 | @Override |
| 541 | @ServiceThreadOnly |
| 542 | protected boolean handleRequestArcInitiate(HdmiCecMessage message) { |
| 543 | assertRunOnServiceThread(); |
Amy | 03afe48 | 2018-09-18 16:57:45 -0700 | [diff] [blame] | 544 | removeAction(ArcInitiationActionFromAvr.class); |
Amy | 59c06c1 | 2019-01-18 15:35:15 -0800 | [diff] [blame] | 545 | if (!mService.readBooleanSystemProperty(Constants.PROPERTY_ARC_SUPPORT, true)) { |
Amy | 77c7c98 | 2018-07-23 18:27:36 -0700 | [diff] [blame] | 546 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_UNRECOGNIZED_OPCODE); |
| 547 | } else if (!isDirectConnectToTv()) { |
| 548 | HdmiLogger.debug("AVR device is not directly connected with TV"); |
| 549 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_NOT_IN_CORRECT_MODE); |
| 550 | } else { |
| 551 | addAndStartAction(new ArcInitiationActionFromAvr(this)); |
| 552 | } |
Amy | 4e7ff1a | 2018-06-07 16:24:31 -0700 | [diff] [blame] | 553 | return true; |
| 554 | } |
| 555 | |
| 556 | @Override |
| 557 | @ServiceThreadOnly |
| 558 | protected boolean handleRequestArcTermination(HdmiCecMessage message) { |
| 559 | assertRunOnServiceThread(); |
Amy | 77c7c98 | 2018-07-23 18:27:36 -0700 | [diff] [blame] | 560 | if (!SystemProperties.getBoolean(Constants.PROPERTY_ARC_SUPPORT, true)) { |
| 561 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_UNRECOGNIZED_OPCODE); |
| 562 | } else if (!isArcEnabled()) { |
| 563 | HdmiLogger.debug("ARC is not established between TV and AVR device"); |
| 564 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_NOT_IN_CORRECT_MODE); |
| 565 | } else { |
Amy | 03afe48 | 2018-09-18 16:57:45 -0700 | [diff] [blame] | 566 | removeAction(ArcTerminationActionFromAvr.class); |
Amy | 77c7c98 | 2018-07-23 18:27:36 -0700 | [diff] [blame] | 567 | addAndStartAction(new ArcTerminationActionFromAvr(this)); |
| 568 | } |
Amy | 4e7ff1a | 2018-06-07 16:24:31 -0700 | [diff] [blame] | 569 | return true; |
| 570 | } |
| 571 | |
Nick Chalko | 6f5d69e | 2018-07-17 16:07:11 -0700 | [diff] [blame] | 572 | @ServiceThreadOnly |
| 573 | protected boolean handleRequestShortAudioDescriptor(HdmiCecMessage message) { |
| 574 | assertRunOnServiceThread(); |
Nick Chalko | 6f5d69e | 2018-07-17 16:07:11 -0700 | [diff] [blame] | 575 | HdmiLogger.debug(TAG + "Stub handleRequestShortAudioDescriptor"); |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 576 | if (!isSystemAudioControlFeatureEnabled()) { |
| 577 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED); |
| 578 | return true; |
| 579 | } |
| 580 | if (!isSystemAudioActivated()) { |
| 581 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_NOT_IN_CORRECT_MODE); |
| 582 | return true; |
| 583 | } |
Amy | d984bc6 | 2018-11-28 18:53:54 -0800 | [diff] [blame] | 584 | |
| 585 | List<DeviceConfig> config = null; |
| 586 | File file = new File(SHORT_AUDIO_DESCRIPTOR_CONFIG_PATH); |
| 587 | if (file.exists()) { |
| 588 | try { |
| 589 | InputStream in = new FileInputStream(file); |
| 590 | config = HdmiUtils.ShortAudioDescriptorXmlParser.parse(in); |
| 591 | in.close(); |
| 592 | } catch (IOException e) { |
| 593 | Slog.e(TAG, "Error reading file: " + file, e); |
| 594 | } catch (XmlPullParserException e) { |
| 595 | Slog.e(TAG, "Unable to parse file: " + file, e); |
| 596 | } |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 597 | } |
Amy | d984bc6 | 2018-11-28 18:53:54 -0800 | [diff] [blame] | 598 | |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 599 | @AudioCodec int[] audioFormatCodes = parseAudioFormatCodes(message.getParams()); |
Amy | d984bc6 | 2018-11-28 18:53:54 -0800 | [diff] [blame] | 600 | byte[] sadBytes; |
| 601 | if (config != null && config.size() > 0) { |
| 602 | sadBytes = getSupportedShortAudioDescriptorsFromConfig(config, audioFormatCodes); |
| 603 | } else { |
| 604 | AudioDeviceInfo deviceInfo = getSystemAudioDeviceInfo(); |
| 605 | if (deviceInfo == null) { |
| 606 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_UNABLE_TO_DETERMINE); |
| 607 | return true; |
| 608 | } |
| 609 | |
| 610 | sadBytes = getSupportedShortAudioDescriptors(deviceInfo, audioFormatCodes); |
| 611 | } |
| 612 | |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 613 | if (sadBytes.length == 0) { |
| 614 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_INVALID_OPERAND); |
| 615 | } else { |
| 616 | mService.sendCecCommand( |
| 617 | HdmiCecMessageBuilder.buildReportShortAudioDescriptor( |
| 618 | mAddress, message.getSource(), sadBytes)); |
| 619 | } |
Nick Chalko | 6f5d69e | 2018-07-17 16:07:11 -0700 | [diff] [blame] | 620 | return true; |
| 621 | } |
| 622 | |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 623 | private byte[] getSupportedShortAudioDescriptors( |
| 624 | AudioDeviceInfo deviceInfo, @AudioCodec int[] audioFormatCodes) { |
Nick Chalko | d70c413 | 2018-08-27 16:22:53 -0700 | [diff] [blame] | 625 | ArrayList<byte[]> sads = new ArrayList<>(audioFormatCodes.length); |
| 626 | for (@AudioCodec int audioFormatCode : audioFormatCodes) { |
| 627 | byte[] sad = getSupportedShortAudioDescriptor(deviceInfo, audioFormatCode); |
| 628 | if (sad != null) { |
| 629 | if (sad.length == 3) { |
| 630 | |
| 631 | sads.add(sad); |
| 632 | } else { |
| 633 | HdmiLogger.warning( |
| 634 | "Dropping Short Audio Descriptor with length %d for requested codec %x", |
| 635 | sad.length, audioFormatCode); |
| 636 | } |
| 637 | } |
| 638 | } |
Amy | d984bc6 | 2018-11-28 18:53:54 -0800 | [diff] [blame] | 639 | return getShortAudioDescriptorBytes(sads); |
| 640 | } |
| 641 | |
| 642 | private byte[] getSupportedShortAudioDescriptorsFromConfig( |
| 643 | List<DeviceConfig> deviceConfig, @AudioCodec int[] audioFormatCodes) { |
| 644 | DeviceConfig deviceConfigToUse = null; |
| 645 | for (DeviceConfig device : deviceConfig) { |
| 646 | // TODO(amyjojo) use PROPERTY_SYSTEM_AUDIO_MODE_AUDIO_PORT to get the audio device name |
| 647 | if (device.name.equals("VX_AUDIO_DEVICE_IN_HDMI_ARC")) { |
| 648 | deviceConfigToUse = device; |
| 649 | break; |
| 650 | } |
| 651 | } |
| 652 | if (deviceConfigToUse == null) { |
| 653 | // TODO(amyjojo) use PROPERTY_SYSTEM_AUDIO_MODE_AUDIO_PORT to get the audio device name |
| 654 | Slog.w(TAG, "sadConfig.xml does not have required device info for " |
| 655 | + "VX_AUDIO_DEVICE_IN_HDMI_ARC"); |
| 656 | return new byte[0]; |
| 657 | } |
| 658 | HashMap<Integer, byte[]> map = new HashMap<>(); |
| 659 | ArrayList<byte[]> sads = new ArrayList<>(audioFormatCodes.length); |
| 660 | for (CodecSad codecSad : deviceConfigToUse.supportedCodecs) { |
| 661 | map.put(codecSad.audioCodec, codecSad.sad); |
| 662 | } |
| 663 | for (int i = 0; i < audioFormatCodes.length; i++) { |
| 664 | if (map.containsKey(audioFormatCodes[i])) { |
| 665 | byte[] sad = map.get(audioFormatCodes[i]); |
| 666 | if (sad != null && sad.length == 3) { |
| 667 | sads.add(sad); |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | return getShortAudioDescriptorBytes(sads); |
| 672 | } |
| 673 | |
| 674 | private byte[] getShortAudioDescriptorBytes(ArrayList<byte[]> sads) { |
Nick Chalko | d70c413 | 2018-08-27 16:22:53 -0700 | [diff] [blame] | 675 | // Short Audio Descriptors are always 3 bytes long. |
| 676 | byte[] bytes = new byte[sads.size() * 3]; |
| 677 | int index = 0; |
| 678 | for (byte[] sad : sads) { |
| 679 | System.arraycopy(sad, 0, bytes, index, 3); |
| 680 | index += 3; |
| 681 | } |
| 682 | return bytes; |
| 683 | } |
| 684 | |
| 685 | /** |
| 686 | * Returns a 3 byte short audio descriptor as described in CEC 1.4 table 29 or null if the |
| 687 | * audioFormatCode is not supported. |
| 688 | */ |
| 689 | @Nullable |
| 690 | private byte[] getSupportedShortAudioDescriptor( |
| 691 | AudioDeviceInfo deviceInfo, @AudioCodec int audioFormatCode) { |
| 692 | switch (audioFormatCode) { |
| 693 | case Constants.AUDIO_CODEC_NONE: { |
| 694 | return null; |
| 695 | } |
| 696 | case Constants.AUDIO_CODEC_LPCM: { |
| 697 | return getLpcmShortAudioDescriptor(deviceInfo); |
| 698 | } |
| 699 | // TODO(b/80297701): implement the rest of the codecs |
| 700 | case Constants.AUDIO_CODEC_DD: |
| 701 | case Constants.AUDIO_CODEC_MPEG1: |
| 702 | case Constants.AUDIO_CODEC_MP3: |
| 703 | case Constants.AUDIO_CODEC_MPEG2: |
| 704 | case Constants.AUDIO_CODEC_AAC: |
| 705 | case Constants.AUDIO_CODEC_DTS: |
| 706 | case Constants.AUDIO_CODEC_ATRAC: |
| 707 | case Constants.AUDIO_CODEC_ONEBITAUDIO: |
| 708 | case Constants.AUDIO_CODEC_DDP: |
| 709 | case Constants.AUDIO_CODEC_DTSHD: |
| 710 | case Constants.AUDIO_CODEC_TRUEHD: |
| 711 | case Constants.AUDIO_CODEC_DST: |
| 712 | case Constants.AUDIO_CODEC_WMAPRO: |
| 713 | default: { |
| 714 | return null; |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | @Nullable |
| 720 | private byte[] getLpcmShortAudioDescriptor(AudioDeviceInfo deviceInfo) { |
| 721 | // TODO(b/80297701): implement |
| 722 | return null; |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | @Nullable |
| 726 | private AudioDeviceInfo getSystemAudioDeviceInfo() { |
Nick Chalko | d70c413 | 2018-08-27 16:22:53 -0700 | [diff] [blame] | 727 | AudioManager audioManager = mService.getContext().getSystemService(AudioManager.class); |
| 728 | if (audioManager == null) { |
| 729 | HdmiLogger.error( |
| 730 | "Error getting system audio device because AudioManager not available."); |
| 731 | return null; |
| 732 | } |
| 733 | AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS); |
| 734 | HdmiLogger.debug("Found %d audio input devices", devices.length); |
| 735 | for (AudioDeviceInfo device : devices) { |
| 736 | HdmiLogger.debug("%s at port %s", device.getProductName(), device.getPort()); |
| 737 | HdmiLogger.debug("Supported encodings are %s", |
| 738 | Arrays.stream(device.getEncodings()).mapToObj( |
| 739 | AudioFormat::toLogFriendlyEncoding |
| 740 | ).collect(Collectors.joining(", "))); |
| 741 | // TODO(b/80297701) use the actual device type that system audio mode is connected to. |
| 742 | if (device.getType() == AudioDeviceInfo.TYPE_HDMI_ARC) { |
| 743 | return device; |
| 744 | } |
| 745 | } |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 746 | return null; |
| 747 | } |
| 748 | |
| 749 | @AudioCodec |
| 750 | private int[] parseAudioFormatCodes(byte[] params) { |
| 751 | @AudioCodec int[] audioFormatCodes = new int[params.length]; |
| 752 | for (int i = 0; i < params.length; i++) { |
| 753 | byte val = params[i]; |
| 754 | audioFormatCodes[i] = |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 755 | val >= 1 && val <= Constants.AUDIO_CODEC_MAX ? val : Constants.AUDIO_CODEC_NONE; |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 756 | } |
| 757 | return audioFormatCodes; |
| 758 | } |
| 759 | |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 760 | @Override |
| 761 | @ServiceThreadOnly |
| 762 | protected boolean handleSystemAudioModeRequest(HdmiCecMessage message) { |
| 763 | assertRunOnServiceThread(); |
| 764 | boolean systemAudioStatusOn = message.getParams().length != 0; |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 765 | // Check if the request comes from a non-TV device. |
| 766 | // Need to check if TV supports System Audio Control |
| 767 | // if non-TV device tries to turn on the feature |
| 768 | if (message.getSource() != Constants.ADDR_TV) { |
| 769 | if (systemAudioStatusOn) { |
| 770 | handleSystemAudioModeOnFromNonTvDevice(message); |
| 771 | return true; |
| 772 | } |
| 773 | } else { |
| 774 | // If TV request the feature on |
| 775 | // cache TV supporting System Audio Control |
| 776 | // until Audio System loses its physical address. |
| 777 | setTvSystemAudioModeSupport(true); |
| 778 | } |
| 779 | // If TV or Audio System does not support the feature, |
| 780 | // will send abort command. |
| 781 | if (!checkSupportAndSetSystemAudioMode(systemAudioStatusOn)) { |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 782 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED); |
| 783 | return true; |
| 784 | } |
| 785 | |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 786 | mService.sendCecCommand( |
| 787 | HdmiCecMessageBuilder.buildSetSystemAudioMode( |
| 788 | mAddress, Constants.ADDR_BROADCAST, systemAudioStatusOn)); |
Amy | 98c311f | 2019-04-09 13:14:47 -0700 | [diff] [blame] | 789 | |
| 790 | if (systemAudioStatusOn) { |
| 791 | int sourcePhysicalAddress = HdmiUtils.twoBytesToInt(message.getParams()); |
| 792 | if (sourcePhysicalAddress != getActiveSource().physicalAddress) { |
| 793 | // If the Active Source recorded by the current device is not synced up with TV, |
| 794 | // TODO(amyjojo): update Active Source internally |
| 795 | } |
| 796 | switchInputOnReceivingNewActivePath(sourcePhysicalAddress); |
| 797 | } |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 798 | return true; |
| 799 | } |
| 800 | |
| 801 | @Override |
| 802 | @ServiceThreadOnly |
| 803 | protected boolean handleSetSystemAudioMode(HdmiCecMessage message) { |
| 804 | assertRunOnServiceThread(); |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 805 | if (!checkSupportAndSetSystemAudioMode( |
| 806 | HdmiUtils.parseCommandParamSystemAudioStatus(message))) { |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 807 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED); |
| 808 | } |
| 809 | return true; |
| 810 | } |
| 811 | |
| 812 | @Override |
| 813 | @ServiceThreadOnly |
| 814 | protected boolean handleSystemAudioModeStatus(HdmiCecMessage message) { |
| 815 | assertRunOnServiceThread(); |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 816 | if (!checkSupportAndSetSystemAudioMode( |
| 817 | HdmiUtils.parseCommandParamSystemAudioStatus(message))) { |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 818 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED); |
| 819 | } |
| 820 | return true; |
| 821 | } |
| 822 | |
Shubang | 81170da | 2018-07-12 18:02:52 -0700 | [diff] [blame] | 823 | @ServiceThreadOnly |
| 824 | void setArcStatus(boolean enabled) { |
| 825 | // TODO(shubang): add tests |
| 826 | assertRunOnServiceThread(); |
| 827 | |
| 828 | HdmiLogger.debug("Set Arc Status[old:%b new:%b]", mArcEstablished, enabled); |
| 829 | // 1. Enable/disable ARC circuit. |
| 830 | enableAudioReturnChannel(enabled); |
| 831 | // 2. Notify arc status to audio service. |
| 832 | notifyArcStatusToAudioService(enabled); |
| 833 | // 3. Update arc status; |
| 834 | mArcEstablished = enabled; |
| 835 | } |
| 836 | |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 837 | /** Switch hardware ARC circuit in the system. */ |
Shubang | 81170da | 2018-07-12 18:02:52 -0700 | [diff] [blame] | 838 | @ServiceThreadOnly |
| 839 | private void enableAudioReturnChannel(boolean enabled) { |
| 840 | assertRunOnServiceThread(); |
| 841 | mService.enableAudioReturnChannel( |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 842 | SystemProperties.getInt(Constants.PROPERTY_SYSTEM_AUDIO_DEVICE_ARC_PORT, 0), |
Shubang | 81170da | 2018-07-12 18:02:52 -0700 | [diff] [blame] | 843 | enabled); |
| 844 | } |
| 845 | |
| 846 | private void notifyArcStatusToAudioService(boolean enabled) { |
| 847 | // Note that we don't set any name to ARC. |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 848 | mService.getAudioManager() |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 849 | .setWiredDeviceConnectionState(AudioSystem.DEVICE_IN_HDMI, enabled ? 1 : 0, "", ""); |
Shubang | 81170da | 2018-07-12 18:02:52 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Nick Chalko | 01b979c | 2018-10-19 14:54:30 -0700 | [diff] [blame] | 852 | void reportAudioStatus(int source) { |
Amy | 2a6c3dc | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 853 | assertRunOnServiceThread(); |
| 854 | |
| 855 | int volume = mService.getAudioManager().getStreamVolume(AudioManager.STREAM_MUSIC); |
| 856 | boolean mute = mService.getAudioManager().isStreamMute(AudioManager.STREAM_MUSIC); |
| 857 | int maxVolume = mService.getAudioManager().getStreamMaxVolume(AudioManager.STREAM_MUSIC); |
Nick Chalko | 01b979c | 2018-10-19 14:54:30 -0700 | [diff] [blame] | 858 | int minVolume = mService.getAudioManager().getStreamMinVolume(AudioManager.STREAM_MUSIC); |
Amy | 2a6c3dc | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 859 | int scaledVolume = VolumeControlAction.scaleToCecVolume(volume, maxVolume); |
Dmitry Shmidt | 8bac7b8 | 2018-10-22 13:24:38 -0700 | [diff] [blame] | 860 | HdmiLogger.debug("Reporting volume %d (%d-%d) as CEC volume %d", volume, |
Nick Chalko | 01b979c | 2018-10-19 14:54:30 -0700 | [diff] [blame] | 861 | minVolume, maxVolume, scaledVolume); |
Amy | 2a6c3dc | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 862 | |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 863 | mService.sendCecCommand( |
| 864 | HdmiCecMessageBuilder.buildReportAudioStatus( |
Nick Chalko | 01b979c | 2018-10-19 14:54:30 -0700 | [diff] [blame] | 865 | mAddress, source, scaledVolume, mute)); |
Amy | 2a6c3dc | 2018-06-05 17:31:55 -0700 | [diff] [blame] | 866 | } |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 867 | |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 868 | /** |
| 869 | * Method to check if device support System Audio Control. If so, wake up device if necessary. |
| 870 | * |
| 871 | * <p> then call {@link #setSystemAudioMode(boolean)} to turn on or off System Audio Mode |
| 872 | * @param newSystemAudioMode turning feature on or off. True is on. False is off. |
| 873 | * @return true or false. |
| 874 | * |
| 875 | * <p>False when device does not support the feature. Otherwise returns true. |
| 876 | */ |
| 877 | protected boolean checkSupportAndSetSystemAudioMode(boolean newSystemAudioMode) { |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 878 | if (!isSystemAudioControlFeatureEnabled()) { |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 879 | HdmiLogger.debug( |
| 880 | "Cannot turn " |
| 881 | + (newSystemAudioMode ? "on" : "off") |
| 882 | + "system audio mode " |
| 883 | + "because the System Audio Control feature is disabled."); |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 884 | return false; |
| 885 | } |
Nick Chalko | f32fcea | 2018-07-17 16:17:40 -0700 | [diff] [blame] | 886 | HdmiLogger.debug( |
| 887 | "System Audio Mode change[old:%b new:%b]", |
Amy | 489454f | 2019-01-24 19:06:57 -0800 | [diff] [blame] | 888 | isSystemAudioActivated(), newSystemAudioMode); |
Amy | ae4ee34 | 2018-10-09 16:55:14 -0700 | [diff] [blame] | 889 | // Wake up device if System Audio Control is turned on |
| 890 | if (newSystemAudioMode) { |
Amy | 0fd41e3 | 2018-06-21 13:40:27 -0700 | [diff] [blame] | 891 | mService.wakeUp(); |
Amy | ac1a55c | 2018-07-13 16:38:23 -0700 | [diff] [blame] | 892 | } |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 893 | setSystemAudioMode(newSystemAudioMode); |
| 894 | return true; |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Real work to turn on or off System Audio Mode. |
| 899 | * |
| 900 | * Use {@link #checkSupportAndSetSystemAudioMode(boolean)} |
| 901 | * if trying to turn on or off the feature. |
| 902 | */ |
| 903 | private void setSystemAudioMode(boolean newSystemAudioMode) { |
Amy | ac1a55c | 2018-07-13 16:38:23 -0700 | [diff] [blame] | 904 | int targetPhysicalAddress = getActiveSource().physicalAddress; |
Amy | 0063811 | 2018-10-31 17:47:17 -0700 | [diff] [blame] | 905 | int port = mService.pathToPortId(targetPhysicalAddress); |
Amy | 6a6d618 | 2018-08-20 17:38:47 -0700 | [diff] [blame] | 906 | if (newSystemAudioMode && port >= 0) { |
Amy | ac1a55c | 2018-07-13 16:38:23 -0700 | [diff] [blame] | 907 | switchToAudioInput(); |
Amy | 0fd41e3 | 2018-06-21 13:40:27 -0700 | [diff] [blame] | 908 | } |
Amy | cce55e0 | 2018-08-20 15:42:25 -0700 | [diff] [blame] | 909 | // Mute device when feature is turned off and unmute device when feature is turned on. |
| 910 | // PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE is false when device never needs to be muted. |
| 911 | boolean currentMuteStatus = |
| 912 | mService.getAudioManager().isStreamMute(AudioManager.STREAM_MUSIC); |
Amy | 61fc25f | 2018-11-02 17:53:21 -0700 | [diff] [blame] | 913 | if (currentMuteStatus == newSystemAudioMode) { |
Amy | 59c06c1 | 2019-01-18 15:35:15 -0800 | [diff] [blame] | 914 | if (mService.readBooleanSystemProperty( |
Amy | 61fc25f | 2018-11-02 17:53:21 -0700 | [diff] [blame] | 915 | Constants.PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE, true) |
| 916 | || newSystemAudioMode) { |
| 917 | mService.getAudioManager() |
| 918 | .adjustStreamVolume( |
| 919 | AudioManager.STREAM_MUSIC, |
| 920 | newSystemAudioMode |
| 921 | ? AudioManager.ADJUST_UNMUTE |
| 922 | : AudioManager.ADJUST_MUTE, |
| 923 | 0); |
| 924 | } |
Amy | cce55e0 | 2018-08-20 15:42:25 -0700 | [diff] [blame] | 925 | } |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 926 | updateAudioManagerForSystemAudio(newSystemAudioMode); |
| 927 | synchronized (mLock) { |
Amy | 489454f | 2019-01-24 19:06:57 -0800 | [diff] [blame] | 928 | if (isSystemAudioActivated() != newSystemAudioMode) { |
| 929 | mService.setSystemAudioActivated(newSystemAudioMode); |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 930 | mService.announceSystemAudioModeChange(newSystemAudioMode); |
| 931 | } |
| 932 | } |
Amy | acc1dab | 2018-09-06 17:09:51 -0700 | [diff] [blame] | 933 | // Init arc whenever System Audio Mode is on |
Amy | 03afe48 | 2018-09-18 16:57:45 -0700 | [diff] [blame] | 934 | // Since some TVs don't request ARC on with System Audio Mode on request |
| 935 | if (SystemProperties.getBoolean(Constants.PROPERTY_ARC_SUPPORT, true) |
Amy | 46ad11f | 2019-06-03 16:59:01 -0700 | [diff] [blame^] | 936 | && isDirectConnectToTv() && mService.isSystemAudioActivated()) { |
Amy | f05bbe1 | 2019-04-22 15:50:49 -0700 | [diff] [blame] | 937 | if (!hasAction(ArcInitiationActionFromAvr.class)) { |
Amy | 03afe48 | 2018-09-18 16:57:45 -0700 | [diff] [blame] | 938 | addAndStartAction(new ArcInitiationActionFromAvr(this)); |
Amy | 03afe48 | 2018-09-18 16:57:45 -0700 | [diff] [blame] | 939 | } |
Amy | acc1dab | 2018-09-06 17:09:51 -0700 | [diff] [blame] | 940 | } |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Amy | ac1a55c | 2018-07-13 16:38:23 -0700 | [diff] [blame] | 943 | protected void switchToAudioInput() { |
| 944 | // TODO(b/111396634): switch input according to PROPERTY_SYSTEM_AUDIO_MODE_AUDIO_PORT |
| 945 | } |
| 946 | |
Amy | 77c7c98 | 2018-07-23 18:27:36 -0700 | [diff] [blame] | 947 | protected boolean isDirectConnectToTv() { |
| 948 | int myPhysicalAddress = mService.getPhysicalAddress(); |
| 949 | return (myPhysicalAddress & Constants.ROUTING_PATH_TOP_MASK) == myPhysicalAddress; |
| 950 | } |
| 951 | |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 952 | private void updateAudioManagerForSystemAudio(boolean on) { |
| 953 | int device = mService.getAudioManager().setHdmiSystemAudioSupported(on); |
| 954 | HdmiLogger.debug("[A]UpdateSystemAudio mode[on=%b] output=[%X]", on, device); |
| 955 | } |
| 956 | |
Amy | 79db52f | 2018-10-23 12:45:17 -0700 | [diff] [blame] | 957 | void onSystemAduioControlFeatureSupportChanged(boolean enabled) { |
| 958 | setSystemAudioControlFeatureEnabled(enabled); |
| 959 | if (enabled) { |
| 960 | addAndStartAction(new SystemAudioInitiationActionFromAvr(this)); |
| 961 | } |
| 962 | } |
| 963 | |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 964 | @ServiceThreadOnly |
| 965 | void setSystemAudioControlFeatureEnabled(boolean enabled) { |
| 966 | assertRunOnServiceThread(); |
| 967 | synchronized (mLock) { |
| 968 | mSystemAudioControlFeatureEnabled = enabled; |
| 969 | } |
| 970 | } |
| 971 | |
shubang | d932cb5 | 2018-09-14 17:55:16 -0700 | [diff] [blame] | 972 | @ServiceThreadOnly |
Amy | 0c2e29f | 2018-10-23 12:17:52 -0700 | [diff] [blame] | 973 | void setRoutingControlFeatureEnables(boolean enabled) { |
| 974 | assertRunOnServiceThread(); |
| 975 | synchronized (mLock) { |
| 976 | mRoutingControlFeatureEnabled = enabled; |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | @ServiceThreadOnly |
shubang | d932cb5 | 2018-09-14 17:55:16 -0700 | [diff] [blame] | 981 | void doManualPortSwitching(int portId, IHdmiControlCallback callback) { |
| 982 | assertRunOnServiceThread(); |
Amy | baa9704 | 2019-03-22 16:33:48 -0700 | [diff] [blame] | 983 | if (!mService.isValidPortId(portId)) { |
| 984 | invokeCallback(callback, HdmiControlManager.RESULT_TARGET_NOT_AVAILABLE); |
| 985 | return; |
| 986 | } |
shubang | d932cb5 | 2018-09-14 17:55:16 -0700 | [diff] [blame] | 987 | if (portId == getLocalActivePort()) { |
| 988 | invokeCallback(callback, HdmiControlManager.RESULT_SUCCESS); |
| 989 | return; |
| 990 | } |
shubang | d932cb5 | 2018-09-14 17:55:16 -0700 | [diff] [blame] | 991 | if (!mService.isControlEnabled()) { |
Amy | f9fa617 | 2018-10-11 16:47:12 -0700 | [diff] [blame] | 992 | setRoutingPort(portId); |
shubang | d932cb5 | 2018-09-14 17:55:16 -0700 | [diff] [blame] | 993 | setLocalActivePort(portId); |
| 994 | invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE); |
| 995 | return; |
| 996 | } |
Amy | f9fa617 | 2018-10-11 16:47:12 -0700 | [diff] [blame] | 997 | int oldPath = getRoutingPort() != Constants.CEC_SWITCH_HOME |
| 998 | ? mService.portIdToPath(getRoutingPort()) |
shubang | d932cb5 | 2018-09-14 17:55:16 -0700 | [diff] [blame] | 999 | : getDeviceInfo().getPhysicalAddress(); |
Amy | f9fa617 | 2018-10-11 16:47:12 -0700 | [diff] [blame] | 1000 | int newPath = mService.portIdToPath(portId); |
shubang | d932cb5 | 2018-09-14 17:55:16 -0700 | [diff] [blame] | 1001 | if (oldPath == newPath) { |
| 1002 | return; |
| 1003 | } |
Amy | f9fa617 | 2018-10-11 16:47:12 -0700 | [diff] [blame] | 1004 | setRoutingPort(portId); |
shubang | d932cb5 | 2018-09-14 17:55:16 -0700 | [diff] [blame] | 1005 | setLocalActivePort(portId); |
| 1006 | HdmiCecMessage routingChange = |
| 1007 | HdmiCecMessageBuilder.buildRoutingChange(mAddress, oldPath, newPath); |
| 1008 | mService.sendCecCommand(routingChange); |
| 1009 | } |
| 1010 | |
Nick Chalko | 167529c | 2018-07-18 13:11:31 -0700 | [diff] [blame] | 1011 | boolean isSystemAudioControlFeatureEnabled() { |
Amy | 9b91e8c | 2018-06-11 17:26:26 -0700 | [diff] [blame] | 1012 | synchronized (mLock) { |
| 1013 | return mSystemAudioControlFeatureEnabled; |
| 1014 | } |
| 1015 | } |
Nick Chalko | f28c7b5 | 2018-06-14 07:46:00 -0700 | [diff] [blame] | 1016 | |
Shubang | 595a183 | 2018-06-27 17:52:18 -0700 | [diff] [blame] | 1017 | protected boolean isSystemAudioActivated() { |
Amy | 489454f | 2019-01-24 19:06:57 -0800 | [diff] [blame] | 1018 | return mService.isSystemAudioActivated(); |
Shubang | 595a183 | 2018-06-27 17:52:18 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
Shubang | 2fd186e | 2018-07-18 16:53:12 -0700 | [diff] [blame] | 1021 | protected void terminateSystemAudioMode() { |
| 1022 | // remove pending initiation actions |
| 1023 | removeAction(SystemAudioInitiationActionFromAvr.class); |
Shubang | bc2aab3 | 2018-07-19 16:41:17 -0700 | [diff] [blame] | 1024 | if (!isSystemAudioActivated()) { |
| 1025 | return; |
Shubang | 2fd186e | 2018-07-18 16:53:12 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 1028 | if (checkSupportAndSetSystemAudioMode(false)) { |
Shubang | bc2aab3 | 2018-07-19 16:41:17 -0700 | [diff] [blame] | 1029 | // send <Set System Audio Mode> [“Off”] |
| 1030 | mService.sendCecCommand( |
| 1031 | HdmiCecMessageBuilder.buildSetSystemAudioMode( |
| 1032 | mAddress, Constants.ADDR_BROADCAST, false)); |
Shubang | 2fd186e | 2018-07-18 16:53:12 -0700 | [diff] [blame] | 1033 | } |
| 1034 | } |
| 1035 | |
Nick Chalko | f28c7b5 | 2018-06-14 07:46:00 -0700 | [diff] [blame] | 1036 | /** Reports if System Audio Mode is supported by the connected TV */ |
| 1037 | interface TvSystemAudioModeSupportedCallback { |
| 1038 | |
| 1039 | /** {@code supported} is true if the TV is connected and supports System Audio Mode. */ |
| 1040 | void onResult(boolean supported); |
Nick Chalko | f28c7b5 | 2018-06-14 07:46:00 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * Queries the connected TV to detect if System Audio Mode is supported by the TV. |
| 1045 | * |
| 1046 | * <p>This query may take up to 2 seconds to complete. |
| 1047 | * |
| 1048 | * <p>The result of the query may be cached until Audio device type is put in standby or loses |
| 1049 | * its physical address. |
| 1050 | */ |
| 1051 | void queryTvSystemAudioModeSupport(TvSystemAudioModeSupportedCallback callback) { |
Amy | 613330e | 2019-03-22 16:53:59 -0700 | [diff] [blame] | 1052 | if (mTvSystemAudioModeSupport == null) { |
Shubang | ec66896 | 2018-07-13 19:03:19 -0700 | [diff] [blame] | 1053 | addAndStartAction(new DetectTvSystemAudioModeSupportAction(this, callback)); |
| 1054 | } else { |
Amy | 613330e | 2019-03-22 16:53:59 -0700 | [diff] [blame] | 1055 | callback.onResult(mTvSystemAudioModeSupport); |
Shubang | ec66896 | 2018-07-13 19:03:19 -0700 | [diff] [blame] | 1056 | } |
| 1057 | } |
| 1058 | |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 1059 | /** |
| 1060 | * Handler of System Audio Mode Request on from non TV device |
| 1061 | */ |
| 1062 | void handleSystemAudioModeOnFromNonTvDevice(HdmiCecMessage message) { |
| 1063 | if (!isSystemAudioControlFeatureEnabled()) { |
| 1064 | HdmiLogger.debug( |
| 1065 | "Cannot turn on" + "system audio mode " |
| 1066 | + "because the System Audio Control feature is disabled."); |
| 1067 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED); |
| 1068 | return; |
| 1069 | } |
Amy | ae4ee34 | 2018-10-09 16:55:14 -0700 | [diff] [blame] | 1070 | // Wake up device |
| 1071 | mService.wakeUp(); |
Amy | 00a122a | 2019-02-19 12:45:20 -0800 | [diff] [blame] | 1072 | // If Audio device is the active source or is on the active path, |
| 1073 | // enable system audio mode without querying TV's support on sam. |
| 1074 | // This is per HDMI spec 1.4b CEC 13.15.4.2. |
| 1075 | if (mService.pathToPortId(getActiveSource().physicalAddress) |
| 1076 | != Constants.INVALID_PORT_ID) { |
| 1077 | setSystemAudioMode(true); |
| 1078 | mService.sendCecCommand( |
| 1079 | HdmiCecMessageBuilder.buildSetSystemAudioMode( |
| 1080 | mAddress, Constants.ADDR_BROADCAST, true)); |
| 1081 | return; |
| 1082 | } |
Amy | 06dc4cd | 2018-08-09 18:22:40 -0700 | [diff] [blame] | 1083 | // Check if TV supports System Audio Control. |
| 1084 | // Handle broadcasting setSystemAudioMode on or aborting message on callback. |
| 1085 | queryTvSystemAudioModeSupport(new TvSystemAudioModeSupportedCallback() { |
| 1086 | public void onResult(boolean supported) { |
| 1087 | if (supported) { |
| 1088 | setSystemAudioMode(true); |
| 1089 | mService.sendCecCommand( |
| 1090 | HdmiCecMessageBuilder.buildSetSystemAudioMode( |
| 1091 | mAddress, Constants.ADDR_BROADCAST, true)); |
| 1092 | } else { |
| 1093 | mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED); |
| 1094 | } |
| 1095 | } |
| 1096 | }); |
| 1097 | } |
| 1098 | |
Shubang | ec66896 | 2018-07-13 19:03:19 -0700 | [diff] [blame] | 1099 | void setTvSystemAudioModeSupport(boolean supported) { |
| 1100 | mTvSystemAudioModeSupport = supported; |
Nick Chalko | f28c7b5 | 2018-06-14 07:46:00 -0700 | [diff] [blame] | 1101 | } |
Amy | 77c7c98 | 2018-07-23 18:27:36 -0700 | [diff] [blame] | 1102 | |
| 1103 | @VisibleForTesting |
| 1104 | protected boolean isArcEnabled() { |
| 1105 | synchronized (mLock) { |
| 1106 | return mArcEstablished; |
| 1107 | } |
| 1108 | } |
Amy | 93a97b9 | 2018-08-17 14:58:41 -0700 | [diff] [blame] | 1109 | |
Amy | 86347ba | 2019-04-04 16:22:54 -0700 | [diff] [blame] | 1110 | private void initArcOnFromAvr() { |
Amy | f05bbe1 | 2019-04-22 15:50:49 -0700 | [diff] [blame] | 1111 | removeAction(ArcTerminationActionFromAvr.class); |
Amy | 86347ba | 2019-04-04 16:22:54 -0700 | [diff] [blame] | 1112 | if (SystemProperties.getBoolean(Constants.PROPERTY_ARC_SUPPORT, true) |
| 1113 | && isDirectConnectToTv() && !isArcEnabled()) { |
| 1114 | removeAction(ArcInitiationActionFromAvr.class); |
| 1115 | addAndStartAction(new ArcInitiationActionFromAvr(this)); |
| 1116 | } |
| 1117 | } |
| 1118 | |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1119 | @Override |
| 1120 | protected void switchInputOnReceivingNewActivePath(int physicalAddress) { |
Amy | 0063811 | 2018-10-31 17:47:17 -0700 | [diff] [blame] | 1121 | int port = mService.pathToPortId(physicalAddress); |
Amy | 3403742 | 2018-09-06 13:21:08 -0700 | [diff] [blame] | 1122 | if (isSystemAudioActivated() && port < 0) { |
| 1123 | // If system audio mode is on and the new active source is not under the current device, |
| 1124 | // Will switch to ARC input. |
| 1125 | // TODO(b/115637145): handle system aduio without ARC |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1126 | routeToInputFromPortId(Constants.CEC_SWITCH_ARC); |
Amy | 3403742 | 2018-09-06 13:21:08 -0700 | [diff] [blame] | 1127 | } else if (mIsSwitchDevice && port >= 0) { |
| 1128 | // If current device is a switch and the new active source is under it, |
| 1129 | // will switch to the corresponding active path. |
| 1130 | routeToInputFromPortId(port); |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1131 | } |
| 1132 | } |
| 1133 | |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1134 | protected void routeToInputFromPortId(int portId) { |
Amy | 0c2e29f | 2018-10-23 12:17:52 -0700 | [diff] [blame] | 1135 | if (!isRoutingControlFeatureEnabled()) { |
| 1136 | HdmiLogger.debug("Routing Control Feature is not enabled."); |
| 1137 | return; |
| 1138 | } |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1139 | if (mArcIntentUsed) { |
| 1140 | routeToTvInputFromPortId(portId); |
| 1141 | } else { |
| 1142 | // TODO(): implement input switching for devices not using TvInput. |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | protected void routeToTvInputFromPortId(int portId) { |
| 1147 | if (portId < 0 || portId >= Constants.CEC_SWITCH_PORT_MAX) { |
| 1148 | HdmiLogger.debug("Invalid port number for Tv Input switching."); |
| 1149 | return; |
| 1150 | } |
Amy | 03afe48 | 2018-09-18 16:57:45 -0700 | [diff] [blame] | 1151 | // Wake up if the current device if ready to route. |
Amy | ae4ee34 | 2018-10-09 16:55:14 -0700 | [diff] [blame] | 1152 | mService.wakeUp(); |
Amy | 2d8f4e6 | 2019-05-02 16:29:19 -0700 | [diff] [blame] | 1153 | // Switch to HOME if the current active port is not HOME yet |
| 1154 | if (portId == Constants.CEC_SWITCH_HOME |
| 1155 | && mService.isPlaybackDevice() |
| 1156 | && getLocalActivePort() != Constants.CEC_SWITCH_HOME) { |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1157 | switchToHomeTvInput(); |
| 1158 | } else if (portId == Constants.CEC_SWITCH_ARC) { |
| 1159 | switchToTvInput(SystemProperties.get(Constants.PROPERTY_SYSTEM_AUDIO_DEVICE_ARC_PORT)); |
Amy | 03afe48 | 2018-09-18 16:57:45 -0700 | [diff] [blame] | 1160 | setLocalActivePort(portId); |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1161 | return; |
| 1162 | } else { |
Amy | edd71e3 | 2019-02-11 13:39:39 -0800 | [diff] [blame] | 1163 | String uri = mPortIdToTvInputs.get(portId); |
Amy | 3403742 | 2018-09-06 13:21:08 -0700 | [diff] [blame] | 1164 | if (uri != null) { |
Amy | edd71e3 | 2019-02-11 13:39:39 -0800 | [diff] [blame] | 1165 | switchToTvInput(uri); |
Amy | 3403742 | 2018-09-06 13:21:08 -0700 | [diff] [blame] | 1166 | } else { |
| 1167 | HdmiLogger.debug("Port number does not match any Tv Input."); |
| 1168 | return; |
| 1169 | } |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | setLocalActivePort(portId); |
Amy | 03afe48 | 2018-09-18 16:57:45 -0700 | [diff] [blame] | 1173 | setRoutingPort(portId); |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | // For device to switch to specific TvInput with corresponding URI. |
| 1177 | private void switchToTvInput(String uri) { |
Amy | 4aef3b40 | 2019-01-18 14:17:55 -0800 | [diff] [blame] | 1178 | try { |
| 1179 | mService.getContext().startActivity(new Intent(Intent.ACTION_VIEW, |
| 1180 | TvContract.buildChannelUriForPassthroughInput(uri)) |
| 1181 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); |
| 1182 | } catch (ActivityNotFoundException e) { |
| 1183 | Slog.e(TAG, "Can't find activity to switch to " + uri, e); |
| 1184 | } |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | // For device using TvInput to switch to Home. |
| 1188 | private void switchToHomeTvInput() { |
Amy | 4aef3b40 | 2019-01-18 14:17:55 -0800 | [diff] [blame] | 1189 | try { |
| 1190 | Intent activityIntent = new Intent(Intent.ACTION_MAIN) |
| 1191 | .addCategory(Intent.CATEGORY_HOME) |
| 1192 | .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
| 1193 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 1194 | | Intent.FLAG_ACTIVITY_NEW_TASK |
| 1195 | | Intent.FLAG_ACTIVITY_NO_ANIMATION); |
| 1196 | mService.getContext().startActivity(activityIntent); |
| 1197 | } catch (ActivityNotFoundException e) { |
| 1198 | Slog.e(TAG, "Can't find activity to switch to HOME", e); |
| 1199 | } |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 1200 | } |
Amy | 79b54e9 | 2018-09-11 17:02:28 -0700 | [diff] [blame] | 1201 | |
| 1202 | @Override |
| 1203 | protected void handleRoutingChangeAndInformation(int physicalAddress, HdmiCecMessage message) { |
Amy | 0063811 | 2018-10-31 17:47:17 -0700 | [diff] [blame] | 1204 | int port = mService.pathToPortId(physicalAddress); |
Amy | 79b54e9 | 2018-09-11 17:02:28 -0700 | [diff] [blame] | 1205 | // Routing change or information sent from switches under the current device can be ignored. |
| 1206 | if (port > 0) { |
| 1207 | return; |
| 1208 | } |
| 1209 | // When other switches route to some other devices not under the current device, |
| 1210 | // check system audio mode status and do ARC switch if needed. |
| 1211 | if (port < 0 && isSystemAudioActivated()) { |
| 1212 | handleRoutingChangeAndInformationForSystemAudio(); |
| 1213 | return; |
| 1214 | } |
| 1215 | // When other switches route to the current device |
| 1216 | // and the current device is also a switch. |
| 1217 | if (port == 0) { |
| 1218 | handleRoutingChangeAndInformationForSwitch(message); |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | // Handle the system audio(ARC) part of the logic on receiving routing change or information. |
| 1223 | private void handleRoutingChangeAndInformationForSystemAudio() { |
Amy | 79b54e9 | 2018-09-11 17:02:28 -0700 | [diff] [blame] | 1224 | // TODO(b/115637145): handle system aduio without ARC |
| 1225 | routeToInputFromPortId(Constants.CEC_SWITCH_ARC); |
| 1226 | } |
| 1227 | |
| 1228 | // Handle the routing control part of the logic on receiving routing change or information. |
| 1229 | private void handleRoutingChangeAndInformationForSwitch(HdmiCecMessage message) { |
Amy | 03afe48 | 2018-09-18 16:57:45 -0700 | [diff] [blame] | 1230 | if (getRoutingPort() == Constants.CEC_SWITCH_HOME && mService.isPlaybackDevice()) { |
Amy | 79b54e9 | 2018-09-11 17:02:28 -0700 | [diff] [blame] | 1231 | routeToInputFromPortId(Constants.CEC_SWITCH_HOME); |
Amy | 123ec40 | 2018-09-25 10:56:31 -0700 | [diff] [blame] | 1232 | mService.setAndBroadcastActiveSourceFromOneDeviceType( |
| 1233 | message.getSource(), mService.getPhysicalAddress()); |
Amy | 79b54e9 | 2018-09-11 17:02:28 -0700 | [diff] [blame] | 1234 | return; |
| 1235 | } |
| 1236 | |
Amy | 238f64f | 2018-11-30 11:27:56 -0800 | [diff] [blame] | 1237 | int routingInformationPath = mService.portIdToPath(getRoutingPort()); |
Amy | 79b54e9 | 2018-09-11 17:02:28 -0700 | [diff] [blame] | 1238 | // If current device is already the leaf of the whole HDMI system, will do nothing. |
| 1239 | if (routingInformationPath == mService.getPhysicalAddress()) { |
| 1240 | HdmiLogger.debug("Current device can't assign valid physical address" |
| 1241 | + "to devices under it any more. " |
Amy | 4aef3b40 | 2019-01-18 14:17:55 -0800 | [diff] [blame] | 1242 | + "It's physical address is " |
| 1243 | + routingInformationPath); |
Amy | 79b54e9 | 2018-09-11 17:02:28 -0700 | [diff] [blame] | 1244 | return; |
| 1245 | } |
| 1246 | // Otherwise will switch to the current active port and broadcast routing information. |
| 1247 | mService.sendCecCommand(HdmiCecMessageBuilder.buildRoutingInformation( |
| 1248 | mAddress, routingInformationPath)); |
Amy | 03afe48 | 2018-09-18 16:57:45 -0700 | [diff] [blame] | 1249 | routeToInputFromPortId(getRoutingPort()); |
Amy | 79b54e9 | 2018-09-11 17:02:28 -0700 | [diff] [blame] | 1250 | } |
Amy | 1e4a8cc | 2018-10-15 10:18:14 -0700 | [diff] [blame] | 1251 | |
| 1252 | protected void updateDevicePowerStatus(int logicalAddress, int newPowerStatus) { |
| 1253 | HdmiDeviceInfo info = getCecDeviceInfo(logicalAddress); |
| 1254 | if (info == null) { |
| 1255 | Slog.w(TAG, "Can not update power status of non-existing device:" + logicalAddress); |
| 1256 | return; |
| 1257 | } |
| 1258 | |
| 1259 | if (info.getDevicePowerStatus() == newPowerStatus) { |
| 1260 | return; |
| 1261 | } |
| 1262 | |
| 1263 | HdmiDeviceInfo newInfo = HdmiUtils.cloneHdmiDeviceInfo(info, newPowerStatus); |
| 1264 | // addDeviceInfo replaces old device info with new one if exists. |
| 1265 | addDeviceInfo(newInfo); |
| 1266 | |
| 1267 | invokeDeviceEventListener(newInfo, HdmiControlManager.DEVICE_EVENT_UPDATE_DEVICE); |
| 1268 | } |
Amy | c00cd4e | 2018-10-16 20:21:33 -0700 | [diff] [blame] | 1269 | |
| 1270 | @ServiceThreadOnly |
| 1271 | private void launchDeviceDiscovery() { |
| 1272 | assertRunOnServiceThread(); |
Amy | 47fe0b1 | 2018-11-06 14:45:18 -0800 | [diff] [blame] | 1273 | if (hasAction(DeviceDiscoveryAction.class)) { |
| 1274 | Slog.i(TAG, "Device Discovery Action is in progress. Restarting."); |
| 1275 | removeAction(DeviceDiscoveryAction.class); |
| 1276 | } |
Amy | c00cd4e | 2018-10-16 20:21:33 -0700 | [diff] [blame] | 1277 | DeviceDiscoveryAction action = new DeviceDiscoveryAction(this, |
| 1278 | new DeviceDiscoveryCallback() { |
| 1279 | @Override |
| 1280 | public void onDeviceDiscoveryDone(List<HdmiDeviceInfo> deviceInfos) { |
| 1281 | for (HdmiDeviceInfo info : deviceInfos) { |
| 1282 | addCecDevice(info); |
| 1283 | } |
| 1284 | } |
| 1285 | }); |
| 1286 | addAndStartAction(action); |
| 1287 | } |
| 1288 | |
| 1289 | // Clear all device info. |
| 1290 | @ServiceThreadOnly |
| 1291 | private void clearDeviceInfoList() { |
| 1292 | assertRunOnServiceThread(); |
| 1293 | for (HdmiDeviceInfo info : HdmiUtils.sparseArrayToList(mDeviceInfos)) { |
| 1294 | if (info.getPhysicalAddress() == mService.getPhysicalAddress()) { |
| 1295 | continue; |
| 1296 | } |
| 1297 | invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE); |
| 1298 | } |
| 1299 | mDeviceInfos.clear(); |
Amy | ec126a5 | 2018-10-30 16:51:14 -0700 | [diff] [blame] | 1300 | updateSafeDeviceInfoList(); |
Amy | c00cd4e | 2018-10-16 20:21:33 -0700 | [diff] [blame] | 1301 | } |
Nick Chalko | b9e48e2 | 2018-10-23 06:59:39 -0700 | [diff] [blame] | 1302 | |
| 1303 | @Override |
| 1304 | protected void dump(IndentingPrintWriter pw) { |
| 1305 | pw.println("HdmiCecLocalDeviceAudioSystem:"); |
| 1306 | pw.increaseIndent(); |
Amy | 77e672c | 2018-10-31 15:55:40 -0700 | [diff] [blame] | 1307 | pw.println("isRoutingFeatureEnabled " + isRoutingControlFeatureEnabled()); |
Nick Chalko | b9e48e2 | 2018-10-23 06:59:39 -0700 | [diff] [blame] | 1308 | pw.println("mSystemAudioControlFeatureEnabled: " + mSystemAudioControlFeatureEnabled); |
| 1309 | pw.println("mTvSystemAudioModeSupport: " + mTvSystemAudioModeSupport); |
| 1310 | pw.println("mArcEstablished: " + mArcEstablished); |
| 1311 | pw.println("mArcIntentUsed: " + mArcIntentUsed); |
Amy | 2e4b25c | 2018-10-30 18:08:49 -0700 | [diff] [blame] | 1312 | pw.println("mRoutingPort: " + getRoutingPort()); |
| 1313 | pw.println("mLocalActivePort: " + getLocalActivePort()); |
Amy | edd71e3 | 2019-02-11 13:39:39 -0800 | [diff] [blame] | 1314 | HdmiUtils.dumpMap(pw, "mPortIdToTvInputs:", mPortIdToTvInputs); |
| 1315 | HdmiUtils.dumpMap(pw, "mTvInputsToDeviceInfo:", mTvInputsToDeviceInfo); |
Nick Chalko | b9e48e2 | 2018-10-23 06:59:39 -0700 | [diff] [blame] | 1316 | HdmiUtils.dumpSparseArray(pw, "mDeviceInfos:", mDeviceInfos); |
| 1317 | pw.decreaseIndent(); |
| 1318 | super.dump(pw); |
| 1319 | } |
Nick Chalko | b89d6ff | 2018-05-25 10:29:01 -0700 | [diff] [blame] | 1320 | } |