Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [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.tv; |
| 18 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 19 | import static android.media.tv.TvInputManager.INPUT_STATE_CONNECTED; |
| 20 | import static android.media.tv.TvInputManager.INPUT_STATE_DISCONNECTED; |
| 21 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 22 | import android.content.Context; |
Jinsuk Kim | b2b3151 | 2014-07-21 17:14:44 +0900 | [diff] [blame] | 23 | import android.content.Intent; |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 24 | import android.hardware.hdmi.HdmiDeviceInfo; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 25 | import android.hardware.hdmi.HdmiHotplugEvent; |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 26 | import android.hardware.hdmi.IHdmiControlService; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 27 | import android.hardware.hdmi.IHdmiDeviceEventListener; |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 28 | import android.hardware.hdmi.IHdmiHotplugEventListener; |
| 29 | import android.hardware.hdmi.IHdmiInputChangeListener; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 30 | import android.media.AudioDevicePort; |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 31 | import android.media.AudioFormat; |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 32 | import android.media.AudioGain; |
| 33 | import android.media.AudioGainConfig; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 34 | import android.media.AudioManager; |
| 35 | import android.media.AudioPatch; |
| 36 | import android.media.AudioPort; |
| 37 | import android.media.AudioPortConfig; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 38 | import android.media.tv.ITvInputHardware; |
| 39 | import android.media.tv.ITvInputHardwareCallback; |
Jinsuk Kim | b2b3151 | 2014-07-21 17:14:44 +0900 | [diff] [blame] | 40 | import android.media.tv.TvContract; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 41 | import android.media.tv.TvInputHardwareInfo; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 42 | import android.media.tv.TvInputInfo; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 43 | import android.media.tv.TvStreamConfig; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 44 | import android.os.Handler; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 45 | import android.os.IBinder; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 46 | import android.os.Message; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 47 | import android.os.RemoteException; |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 48 | import android.os.ServiceManager; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 49 | import android.util.ArrayMap; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 50 | import android.util.Slog; |
| 51 | import android.util.SparseArray; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 52 | import android.util.SparseBooleanArray; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 53 | import android.view.KeyEvent; |
| 54 | import android.view.Surface; |
| 55 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 56 | import com.android.server.SystemService; |
| 57 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 58 | import java.util.ArrayList; |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 59 | import java.util.Arrays; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 60 | import java.util.Collections; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 61 | import java.util.Iterator; |
| 62 | import java.util.LinkedList; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 63 | import java.util.List; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 64 | import java.util.Map; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * A helper class for TvInputManagerService to handle TV input hardware. |
| 68 | * |
| 69 | * This class does a basic connection management and forwarding calls to TvInputHal which eventually |
| 70 | * calls to tv_input HAL module. |
| 71 | * |
| 72 | * @hide |
| 73 | */ |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 74 | class TvInputHardwareManager implements TvInputHal.Callback { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 75 | private static final String TAG = TvInputHardwareManager.class.getSimpleName(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 76 | |
| 77 | private final Context mContext; |
| 78 | private final Listener mListener; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 79 | private final TvInputHal mHal = new TvInputHal(this); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 80 | private final SparseArray<Connection> mConnections = new SparseArray<>(); |
| 81 | private final List<TvInputHardwareInfo> mHardwareList = new ArrayList<>(); |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 82 | private final List<HdmiDeviceInfo> mHdmiDeviceList = new LinkedList<>(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 83 | /* A map from a device ID to the matching TV input ID. */ |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 84 | private final SparseArray<String> mHardwareInputIdMap = new SparseArray<>(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 85 | /* A map from a HDMI logical address to the matching TV input ID. */ |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 86 | private final SparseArray<String> mHdmiInputIdMap = new SparseArray<>(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 87 | private final Map<String, TvInputInfo> mInputMap = new ArrayMap<>(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 88 | |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 89 | private final AudioManager mAudioManager; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 90 | private IHdmiControlService mHdmiControlService; |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 91 | private final IHdmiHotplugEventListener mHdmiHotplugEventListener = |
| 92 | new HdmiHotplugEventListener(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 93 | private final IHdmiDeviceEventListener mHdmiDeviceEventListener = new HdmiDeviceEventListener(); |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 94 | private final IHdmiInputChangeListener mHdmiInputChangeListener = new HdmiInputChangeListener(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 95 | // TODO: Should handle STANDBY case. |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 96 | private final SparseBooleanArray mHdmiStateMap = new SparseBooleanArray(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 97 | private final List<Message> mPendingHdmiDeviceEvents = new LinkedList<>(); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 98 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 99 | // Calls to mListener should happen here. |
| 100 | private final Handler mHandler = new ListenerHandler(); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 101 | |
| 102 | private final Object mLock = new Object(); |
| 103 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 104 | public TvInputHardwareManager(Context context, Listener listener) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 105 | mContext = context; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 106 | mListener = listener; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 107 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 108 | mHal.init(); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | public void onBootPhase(int phase) { |
| 112 | if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 113 | mHdmiControlService = IHdmiControlService.Stub.asInterface(ServiceManager.getService( |
| 114 | Context.HDMI_CONTROL_SERVICE)); |
| 115 | if (mHdmiControlService != null) { |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 116 | try { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 117 | mHdmiControlService.addHotplugEventListener(mHdmiHotplugEventListener); |
| 118 | mHdmiControlService.addDeviceEventListener(mHdmiDeviceEventListener); |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 119 | mHdmiDeviceList.addAll(mHdmiControlService.getInputDevices()); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 120 | mHdmiControlService.setInputChangeListener(mHdmiInputChangeListener); |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 121 | } catch (RemoteException e) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 122 | Slog.w(TAG, "Error registering listeners to HdmiControlService:", e); |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 123 | } |
| 124 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 125 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | @Override |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 129 | public void onDeviceAvailable(TvInputHardwareInfo info, TvStreamConfig[] configs) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 130 | synchronized (mLock) { |
| 131 | Connection connection = new Connection(info); |
| 132 | connection.updateConfigsLocked(configs); |
| 133 | mConnections.put(info.getDeviceId(), connection); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 134 | buildHardwareListLocked(); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 135 | mHandler.obtainMessage( |
| 136 | ListenerHandler.HARDWARE_DEVICE_ADDED, 0, 0, info).sendToTarget(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 137 | if (info.getType() == TvInputHardwareInfo.TV_INPUT_TYPE_HDMI) { |
| 138 | processPendingHdmiDeviceEventsLocked(); |
| 139 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 143 | private void buildHardwareListLocked() { |
| 144 | mHardwareList.clear(); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 145 | for (int i = 0; i < mConnections.size(); ++i) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 146 | mHardwareList.add(mConnections.valueAt(i).getHardwareInfoLocked()); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public void onDeviceUnavailable(int deviceId) { |
| 152 | synchronized (mLock) { |
| 153 | Connection connection = mConnections.get(deviceId); |
| 154 | if (connection == null) { |
| 155 | Slog.e(TAG, "onDeviceUnavailable: Cannot find a connection with " + deviceId); |
| 156 | return; |
| 157 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 158 | connection.resetLocked(null, null, null, null, null); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 159 | mConnections.remove(deviceId); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 160 | buildHardwareListLocked(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 161 | TvInputHardwareInfo info = connection.getHardwareInfoLocked(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 162 | if (info.getType() == TvInputHardwareInfo.TV_INPUT_TYPE_HDMI) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 163 | // Remove HDMI devices linked with this hardware. |
| 164 | for (Iterator<HdmiDeviceInfo> it = mHdmiDeviceList.iterator(); it.hasNext();) { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 165 | HdmiDeviceInfo deviceInfo = it.next(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 166 | if (deviceInfo.getPortId() == info.getHdmiPortId()) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 167 | mHandler.obtainMessage(ListenerHandler.HDMI_DEVICE_REMOVED, 0, 0, |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 168 | deviceInfo).sendToTarget(); |
| 169 | it.remove(); |
| 170 | } |
| 171 | } |
| 172 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 173 | mHandler.obtainMessage( |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 174 | ListenerHandler.HARDWARE_DEVICE_REMOVED, 0, 0, info).sendToTarget(); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public void onStreamConfigurationChanged(int deviceId, TvStreamConfig[] configs) { |
| 180 | synchronized (mLock) { |
| 181 | Connection connection = mConnections.get(deviceId); |
| 182 | if (connection == null) { |
| 183 | Slog.e(TAG, "StreamConfigurationChanged: Cannot find a connection with " |
| 184 | + deviceId); |
| 185 | return; |
| 186 | } |
| 187 | connection.updateConfigsLocked(configs); |
| 188 | try { |
| 189 | connection.getCallbackLocked().onStreamConfigChanged(configs); |
| 190 | } catch (RemoteException e) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 191 | Slog.e(TAG, "error in onStreamConfigurationChanged", e); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 196 | @Override |
| 197 | public void onFirstFrameCaptured(int deviceId, int streamId) { |
| 198 | synchronized (mLock) { |
| 199 | Connection connection = mConnections.get(deviceId); |
| 200 | if (connection == null) { |
| 201 | Slog.e(TAG, "FirstFrameCaptured: Cannot find a connection with " |
| 202 | + deviceId); |
| 203 | return; |
| 204 | } |
| 205 | Runnable runnable = connection.getOnFirstFrameCapturedLocked(); |
| 206 | if (runnable != null) { |
| 207 | runnable.run(); |
| 208 | connection.setOnFirstFrameCapturedLocked(null); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 213 | public List<TvInputHardwareInfo> getHardwareList() { |
| 214 | synchronized (mLock) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 215 | return Collections.unmodifiableList(mHardwareList); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 219 | public List<HdmiDeviceInfo> getHdmiDeviceList() { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 220 | synchronized (mLock) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 221 | return Collections.unmodifiableList(mHdmiDeviceList); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 222 | } |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 223 | } |
| 224 | |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 225 | private boolean checkUidChangedLocked( |
| 226 | Connection connection, int callingUid, int resolvedUserId) { |
| 227 | Integer connectionCallingUid = connection.getCallingUidLocked(); |
| 228 | Integer connectionResolvedUserId = connection.getResolvedUserIdLocked(); |
| 229 | if (connectionCallingUid == null || connectionResolvedUserId == null) { |
| 230 | return true; |
| 231 | } |
| 232 | if (connectionCallingUid != callingUid || connectionResolvedUserId != resolvedUserId) { |
| 233 | return true; |
| 234 | } |
| 235 | return false; |
| 236 | } |
| 237 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 238 | private int convertConnectedToState(boolean connected) { |
| 239 | if (connected) { |
| 240 | return INPUT_STATE_CONNECTED; |
| 241 | } else { |
| 242 | return INPUT_STATE_DISCONNECTED; |
| 243 | } |
| 244 | } |
| 245 | |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 246 | public void addHardwareTvInput(int deviceId, TvInputInfo info) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 247 | synchronized (mLock) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 248 | String oldInputId = mHardwareInputIdMap.get(deviceId); |
| 249 | if (oldInputId != null) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 250 | Slog.w(TAG, "Trying to override previous registration: old = " |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 251 | + mInputMap.get(oldInputId) + ":" + deviceId + ", new = " |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 252 | + info + ":" + deviceId); |
| 253 | } |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 254 | mHardwareInputIdMap.put(deviceId, info.getId()); |
| 255 | mInputMap.put(info.getId(), info); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 256 | |
| 257 | for (int i = 0; i < mHdmiStateMap.size(); ++i) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 258 | TvInputHardwareInfo hardwareInfo = |
| 259 | findHardwareInfoForHdmiPortLocked(mHdmiStateMap.keyAt(i)); |
| 260 | if (hardwareInfo == null) { |
| 261 | continue; |
| 262 | } |
| 263 | String inputId = mHardwareInputIdMap.get(hardwareInfo.getDeviceId()); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 264 | if (inputId != null && inputId.equals(info.getId())) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 265 | mHandler.obtainMessage(ListenerHandler.STATE_CHANGED, |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 266 | convertConnectedToState(mHdmiStateMap.valueAt(i)), 0, |
| 267 | inputId).sendToTarget(); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
Wonsik Kim | 38feae9 | 2014-07-21 21:35:50 +0900 | [diff] [blame] | 273 | private static <T> int indexOfEqualValue(SparseArray<T> map, T value) { |
| 274 | for (int i = 0; i < map.size(); ++i) { |
| 275 | if (map.valueAt(i).equals(value)) { |
| 276 | return i; |
| 277 | } |
| 278 | } |
| 279 | return -1; |
| 280 | } |
| 281 | |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 282 | public void addHdmiTvInput(int logicalAddress, TvInputInfo info) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 283 | if (info.getType() != TvInputInfo.TYPE_HDMI) { |
| 284 | throw new IllegalArgumentException("info (" + info + ") has non-HDMI type."); |
| 285 | } |
| 286 | synchronized (mLock) { |
| 287 | String parentId = info.getParentId(); |
Wonsik Kim | 38feae9 | 2014-07-21 21:35:50 +0900 | [diff] [blame] | 288 | int parentIndex = indexOfEqualValue(mHardwareInputIdMap, parentId); |
| 289 | if (parentIndex < 0) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 290 | throw new IllegalArgumentException("info (" + info + ") has invalid parentId."); |
| 291 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 292 | String oldInputId = mHdmiInputIdMap.get(logicalAddress); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 293 | if (oldInputId != null) { |
| 294 | Slog.w(TAG, "Trying to override previous registration: old = " |
| 295 | + mInputMap.get(oldInputId) + ":" + logicalAddress + ", new = " |
| 296 | + info + ":" + logicalAddress); |
| 297 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 298 | mHdmiInputIdMap.put(logicalAddress, info.getId()); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 299 | mInputMap.put(info.getId(), info); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | public void removeTvInput(String inputId) { |
| 304 | synchronized (mLock) { |
| 305 | mInputMap.remove(inputId); |
Wonsik Kim | 38feae9 | 2014-07-21 21:35:50 +0900 | [diff] [blame] | 306 | int hardwareIndex = indexOfEqualValue(mHardwareInputIdMap, inputId); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 307 | if (hardwareIndex >= 0) { |
| 308 | mHardwareInputIdMap.removeAt(hardwareIndex); |
| 309 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 310 | int deviceIndex = indexOfEqualValue(mHdmiInputIdMap, inputId); |
| 311 | if (deviceIndex >= 0) { |
| 312 | mHdmiInputIdMap.removeAt(deviceIndex); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 317 | /** |
| 318 | * Create a TvInputHardware object with a specific deviceId. One service at a time can access |
| 319 | * the object, and if more than one process attempts to create hardware with the same deviceId, |
| 320 | * the latest service will get the object and all the other hardware are released. The |
| 321 | * release is notified via ITvInputHardwareCallback.onReleased(). |
| 322 | */ |
| 323 | public ITvInputHardware acquireHardware(int deviceId, ITvInputHardwareCallback callback, |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 324 | TvInputInfo info, int callingUid, int resolvedUserId) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 325 | if (callback == null) { |
| 326 | throw new NullPointerException(); |
| 327 | } |
| 328 | synchronized (mLock) { |
| 329 | Connection connection = mConnections.get(deviceId); |
| 330 | if (connection == null) { |
| 331 | Slog.e(TAG, "Invalid deviceId : " + deviceId); |
| 332 | return null; |
| 333 | } |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 334 | if (checkUidChangedLocked(connection, callingUid, resolvedUserId)) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 335 | TvInputHardwareImpl hardware = |
| 336 | new TvInputHardwareImpl(connection.getHardwareInfoLocked()); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 337 | try { |
| 338 | callback.asBinder().linkToDeath(connection, 0); |
| 339 | } catch (RemoteException e) { |
| 340 | hardware.release(); |
| 341 | return null; |
| 342 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 343 | connection.resetLocked(hardware, callback, info, callingUid, resolvedUserId); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 344 | } |
| 345 | return connection.getHardwareLocked(); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Release the specified hardware. |
| 351 | */ |
| 352 | public void releaseHardware(int deviceId, ITvInputHardware hardware, int callingUid, |
| 353 | int resolvedUserId) { |
| 354 | synchronized (mLock) { |
| 355 | Connection connection = mConnections.get(deviceId); |
| 356 | if (connection == null) { |
| 357 | Slog.e(TAG, "Invalid deviceId : " + deviceId); |
| 358 | return; |
| 359 | } |
| 360 | if (connection.getHardwareLocked() != hardware |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 361 | || checkUidChangedLocked(connection, callingUid, resolvedUserId)) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 362 | return; |
| 363 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 364 | connection.resetLocked(null, null, null, null, null); |
| 365 | } |
| 366 | } |
| 367 | |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 368 | private TvInputHardwareInfo findHardwareInfoForHdmiPortLocked(int port) { |
| 369 | for (TvInputHardwareInfo hardwareInfo : mHardwareList) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 370 | if (hardwareInfo.getType() == TvInputHardwareInfo.TV_INPUT_TYPE_HDMI |
| 371 | && hardwareInfo.getHdmiPortId() == port) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 372 | return hardwareInfo; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | return null; |
| 376 | } |
| 377 | |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 378 | private int findDeviceIdForInputIdLocked(String inputId) { |
| 379 | for (int i = 0; i < mConnections.size(); ++i) { |
| 380 | Connection connection = mConnections.get(i); |
| 381 | if (connection.getInfoLocked().getId().equals(inputId)) { |
| 382 | return i; |
| 383 | } |
| 384 | } |
| 385 | return -1; |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Get the list of TvStreamConfig which is buffered mode. |
| 390 | */ |
| 391 | public List<TvStreamConfig> getAvailableTvStreamConfigList(String inputId, int callingUid, |
| 392 | int resolvedUserId) { |
| 393 | List<TvStreamConfig> configsList = new ArrayList<TvStreamConfig>(); |
| 394 | synchronized (mLock) { |
| 395 | int deviceId = findDeviceIdForInputIdLocked(inputId); |
| 396 | if (deviceId < 0) { |
| 397 | Slog.e(TAG, "Invalid inputId : " + inputId); |
| 398 | return configsList; |
| 399 | } |
| 400 | Connection connection = mConnections.get(deviceId); |
| 401 | for (TvStreamConfig config : connection.getConfigsLocked()) { |
| 402 | if (config.getType() == TvStreamConfig.STREAM_TYPE_BUFFER_PRODUCER) { |
| 403 | configsList.add(config); |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | return configsList; |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Take a snapshot of the given TV input into the provided Surface. |
| 412 | */ |
| 413 | public boolean captureFrame(String inputId, Surface surface, final TvStreamConfig config, |
| 414 | int callingUid, int resolvedUserId) { |
| 415 | synchronized (mLock) { |
| 416 | int deviceId = findDeviceIdForInputIdLocked(inputId); |
| 417 | if (deviceId < 0) { |
| 418 | Slog.e(TAG, "Invalid inputId : " + inputId); |
| 419 | return false; |
| 420 | } |
| 421 | Connection connection = mConnections.get(deviceId); |
| 422 | final TvInputHardwareImpl hardwareImpl = connection.getHardwareImplLocked(); |
| 423 | if (hardwareImpl != null) { |
| 424 | // Stop previous capture. |
| 425 | Runnable runnable = connection.getOnFirstFrameCapturedLocked(); |
| 426 | if (runnable != null) { |
| 427 | runnable.run(); |
| 428 | connection.setOnFirstFrameCapturedLocked(null); |
| 429 | } |
| 430 | |
| 431 | boolean result = hardwareImpl.startCapture(surface, config); |
| 432 | if (result) { |
| 433 | connection.setOnFirstFrameCapturedLocked(new Runnable() { |
| 434 | @Override |
| 435 | public void run() { |
| 436 | hardwareImpl.stopCapture(config); |
| 437 | } |
| 438 | }); |
| 439 | } |
| 440 | return result; |
| 441 | } |
| 442 | } |
| 443 | return false; |
| 444 | } |
| 445 | |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 446 | private void processPendingHdmiDeviceEventsLocked() { |
| 447 | for (Iterator<Message> it = mPendingHdmiDeviceEvents.iterator(); it.hasNext(); ) { |
| 448 | Message msg = it.next(); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 449 | HdmiDeviceInfo deviceInfo = (HdmiDeviceInfo) msg.obj; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 450 | TvInputHardwareInfo hardwareInfo = |
| 451 | findHardwareInfoForHdmiPortLocked(deviceInfo.getPortId()); |
| 452 | if (hardwareInfo != null) { |
| 453 | msg.sendToTarget(); |
| 454 | it.remove(); |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 459 | private class Connection implements IBinder.DeathRecipient { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 460 | private final TvInputHardwareInfo mHardwareInfo; |
| 461 | private TvInputInfo mInfo; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 462 | private TvInputHardwareImpl mHardware = null; |
| 463 | private ITvInputHardwareCallback mCallback; |
| 464 | private TvStreamConfig[] mConfigs = null; |
| 465 | private Integer mCallingUid = null; |
| 466 | private Integer mResolvedUserId = null; |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 467 | private Runnable mOnFirstFrameCaptured; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 468 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 469 | public Connection(TvInputHardwareInfo hardwareInfo) { |
| 470 | mHardwareInfo = hardwareInfo; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | // *Locked methods assume TvInputHardwareManager.mLock is held. |
| 474 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 475 | public void resetLocked(TvInputHardwareImpl hardware, ITvInputHardwareCallback callback, |
| 476 | TvInputInfo info, Integer callingUid, Integer resolvedUserId) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 477 | if (mHardware != null) { |
| 478 | try { |
| 479 | mCallback.onReleased(); |
| 480 | } catch (RemoteException e) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 481 | Slog.e(TAG, "error in Connection::resetLocked", e); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 482 | } |
| 483 | mHardware.release(); |
| 484 | } |
| 485 | mHardware = hardware; |
| 486 | mCallback = callback; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 487 | mInfo = info; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 488 | mCallingUid = callingUid; |
| 489 | mResolvedUserId = resolvedUserId; |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 490 | mOnFirstFrameCaptured = null; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 491 | |
| 492 | if (mHardware != null && mCallback != null) { |
| 493 | try { |
| 494 | mCallback.onStreamConfigChanged(getConfigsLocked()); |
| 495 | } catch (RemoteException e) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 496 | Slog.e(TAG, "error in Connection::resetLocked", e); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | public void updateConfigsLocked(TvStreamConfig[] configs) { |
| 502 | mConfigs = configs; |
| 503 | } |
| 504 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 505 | public TvInputHardwareInfo getHardwareInfoLocked() { |
| 506 | return mHardwareInfo; |
| 507 | } |
| 508 | |
| 509 | public TvInputInfo getInfoLocked() { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 510 | return mInfo; |
| 511 | } |
| 512 | |
| 513 | public ITvInputHardware getHardwareLocked() { |
| 514 | return mHardware; |
| 515 | } |
| 516 | |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 517 | public TvInputHardwareImpl getHardwareImplLocked() { |
| 518 | return mHardware; |
| 519 | } |
| 520 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 521 | public ITvInputHardwareCallback getCallbackLocked() { |
| 522 | return mCallback; |
| 523 | } |
| 524 | |
| 525 | public TvStreamConfig[] getConfigsLocked() { |
| 526 | return mConfigs; |
| 527 | } |
| 528 | |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 529 | public Integer getCallingUidLocked() { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 530 | return mCallingUid; |
| 531 | } |
| 532 | |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 533 | public Integer getResolvedUserIdLocked() { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 534 | return mResolvedUserId; |
| 535 | } |
| 536 | |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 537 | public void setOnFirstFrameCapturedLocked(Runnable runnable) { |
| 538 | mOnFirstFrameCaptured = runnable; |
| 539 | } |
| 540 | |
| 541 | public Runnable getOnFirstFrameCapturedLocked() { |
| 542 | return mOnFirstFrameCaptured; |
| 543 | } |
| 544 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 545 | @Override |
| 546 | public void binderDied() { |
| 547 | synchronized (mLock) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 548 | resetLocked(null, null, null, null, null); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | private class TvInputHardwareImpl extends ITvInputHardware.Stub { |
| 554 | private final TvInputHardwareInfo mInfo; |
| 555 | private boolean mReleased = false; |
| 556 | private final Object mImplLock = new Object(); |
| 557 | |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 558 | private final AudioManager.OnAudioPortUpdateListener mAudioListener = |
| 559 | new AudioManager.OnAudioPortUpdateListener() { |
| 560 | @Override |
| 561 | public void onAudioPortListUpdate(AudioPort[] portList) { |
| 562 | synchronized (mImplLock) { |
| 563 | updateAudioSinkLocked(); |
| 564 | if (mInfo.getAudioType() != AudioManager.DEVICE_NONE && mAudioSource == null) { |
| 565 | mAudioSource = findAudioDevicePort(mInfo.getAudioType(), |
| 566 | mInfo.getAudioAddress()); |
| 567 | if (mActiveConfig != null) { |
| 568 | updateAudioPatchLocked(); |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | @Override |
| 575 | public void onAudioPatchListUpdate(AudioPatch[] patchList) { |
| 576 | // No-op |
| 577 | } |
| 578 | |
| 579 | @Override |
| 580 | public void onServiceDied() { |
| 581 | synchronized (mImplLock) { |
| 582 | mAudioSource = null; |
| 583 | mAudioSink = null; |
| 584 | mAudioPatch = null; |
| 585 | } |
| 586 | } |
| 587 | }; |
| 588 | private int mOverrideAudioType = AudioManager.DEVICE_NONE; |
| 589 | private String mOverrideAudioAddress = ""; |
| 590 | private AudioDevicePort mAudioSource; |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 591 | private AudioDevicePort mAudioSink; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 592 | private AudioPatch mAudioPatch = null; |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 593 | private float mCommittedVolume = 0.0f; |
| 594 | private float mVolume = 0.0f; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 595 | |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 596 | private TvStreamConfig mActiveConfig = null; |
| 597 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 598 | private int mDesiredSamplingRate = 0; |
| 599 | private int mDesiredChannelMask = AudioFormat.CHANNEL_OUT_DEFAULT; |
| 600 | private int mDesiredFormat = AudioFormat.ENCODING_DEFAULT; |
| 601 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 602 | public TvInputHardwareImpl(TvInputHardwareInfo info) { |
| 603 | mInfo = info; |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 604 | mAudioManager.registerAudioPortUpdateListener(mAudioListener); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 605 | if (mInfo.getAudioType() != AudioManager.DEVICE_NONE) { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 606 | mAudioSource = findAudioDevicePort(mInfo.getAudioType(), mInfo.getAudioAddress()); |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 607 | mAudioSink = findAudioSinkFromAudioPolicy(); |
| 608 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | private AudioDevicePort findAudioSinkFromAudioPolicy() { |
| 612 | ArrayList<AudioPort> devicePorts = new ArrayList<AudioPort>(); |
| 613 | if (mAudioManager.listAudioDevicePorts(devicePorts) == AudioManager.SUCCESS) { |
| 614 | int sinkDevice = mAudioManager.getDevicesForStream(AudioManager.STREAM_MUSIC); |
| 615 | for (AudioPort port : devicePorts) { |
| 616 | AudioDevicePort devicePort = (AudioDevicePort) port; |
| 617 | if (devicePort.type() == sinkDevice) { |
| 618 | return devicePort; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 622 | return null; |
| 623 | } |
| 624 | |
| 625 | private AudioDevicePort findAudioDevicePort(int type, String address) { |
| 626 | if (type == AudioManager.DEVICE_NONE) { |
| 627 | return null; |
| 628 | } |
| 629 | ArrayList<AudioPort> devicePorts = new ArrayList<AudioPort>(); |
| 630 | if (mAudioManager.listAudioDevicePorts(devicePorts) != AudioManager.SUCCESS) { |
| 631 | return null; |
| 632 | } |
| 633 | for (AudioPort port : devicePorts) { |
| 634 | AudioDevicePort devicePort = (AudioDevicePort) port; |
| 635 | if (devicePort.type() == type && devicePort.address().equals(address)) { |
| 636 | return devicePort; |
| 637 | } |
| 638 | } |
| 639 | return null; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | public void release() { |
| 643 | synchronized (mImplLock) { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 644 | mAudioManager.unregisterAudioPortUpdateListener(mAudioListener); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 645 | if (mAudioPatch != null) { |
| 646 | mAudioManager.releaseAudioPatch(mAudioPatch); |
| 647 | mAudioPatch = null; |
| 648 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 649 | mReleased = true; |
| 650 | } |
| 651 | } |
| 652 | |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 653 | // A TvInputHardwareImpl object holds only one active session. Therefore, if a client |
| 654 | // attempts to call setSurface with different TvStreamConfig objects, the last call will |
| 655 | // prevail. |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 656 | @Override |
| 657 | public boolean setSurface(Surface surface, TvStreamConfig config) |
| 658 | throws RemoteException { |
| 659 | synchronized (mImplLock) { |
| 660 | if (mReleased) { |
| 661 | throw new IllegalStateException("Device already released."); |
| 662 | } |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 663 | if (surface != null && config == null) { |
| 664 | return false; |
| 665 | } |
| 666 | if (surface == null && mActiveConfig == null) { |
| 667 | return false; |
| 668 | } |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 669 | if (mAudioSource != null && mAudioSink != null) { |
| 670 | if (surface != null) { |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 671 | updateAudioPatchLocked(); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 672 | } else { |
| 673 | mAudioManager.releaseAudioPatch(mAudioPatch); |
| 674 | mAudioPatch = null; |
| 675 | } |
| 676 | } |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 677 | int result = TvInputHal.ERROR_UNKNOWN; |
| 678 | if (surface == null) { |
| 679 | result = mHal.removeStream(mInfo.getDeviceId(), mActiveConfig); |
| 680 | mActiveConfig = null; |
| 681 | } else { |
| 682 | if (config != mActiveConfig && mActiveConfig != null) { |
| 683 | result = mHal.removeStream(mInfo.getDeviceId(), mActiveConfig); |
| 684 | if (result != TvInputHal.SUCCESS) { |
| 685 | mActiveConfig = null; |
| 686 | return false; |
| 687 | } |
| 688 | } |
| 689 | result = mHal.addStream(mInfo.getDeviceId(), surface, config); |
| 690 | if (result == TvInputHal.SUCCESS) { |
| 691 | mActiveConfig = config; |
| 692 | } |
| 693 | } |
| 694 | return result == TvInputHal.SUCCESS; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 698 | private void updateAudioPatchLocked() { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 699 | if (mAudioSource == null || mAudioSink == null) { |
| 700 | if (mAudioPatch != null) { |
| 701 | throw new IllegalStateException("Audio patch should be null if audio source " |
| 702 | + "or sink is null."); |
| 703 | } |
| 704 | return; |
| 705 | } |
| 706 | |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 707 | AudioGainConfig sourceGainConfig = null; |
| 708 | if (mAudioSource.gains().length > 0 && mVolume != mCommittedVolume) { |
| 709 | AudioGain sourceGain = null; |
| 710 | for (AudioGain gain : mAudioSource.gains()) { |
| 711 | if ((gain.mode() & AudioGain.MODE_JOINT) != 0) { |
| 712 | sourceGain = gain; |
| 713 | break; |
| 714 | } |
| 715 | } |
| 716 | // NOTE: we only change the source gain in MODE_JOINT here. |
| 717 | if (sourceGain != null) { |
| 718 | int steps = (sourceGain.maxValue() - sourceGain.minValue()) |
| 719 | / sourceGain.stepValue(); |
| 720 | int gainValue = sourceGain.minValue(); |
| 721 | if (mVolume < 1.0f) { |
| 722 | gainValue += sourceGain.stepValue() * (int) (mVolume * steps + 0.5); |
| 723 | } else { |
| 724 | gainValue = sourceGain.maxValue(); |
| 725 | } |
| 726 | int numChannels = 0; |
| 727 | for (int mask = sourceGain.channelMask(); mask > 0; mask >>= 1) { |
| 728 | numChannels += (mask & 1); |
| 729 | } |
| 730 | int[] gainValues = new int[numChannels]; |
| 731 | Arrays.fill(gainValues, gainValue); |
| 732 | sourceGainConfig = sourceGain.buildConfig(AudioGain.MODE_JOINT, |
| 733 | sourceGain.channelMask(), gainValues, 0); |
| 734 | } else { |
| 735 | Slog.w(TAG, "No audio source gain with MODE_JOINT support exists."); |
| 736 | } |
| 737 | } |
| 738 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 739 | AudioPortConfig sourceConfig = mAudioSource.activeConfig(); |
| 740 | AudioPortConfig sinkConfig = mAudioSink.activeConfig(); |
| 741 | AudioPatch[] audioPatchArray = new AudioPatch[] { mAudioPatch }; |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 742 | boolean shouldRecreateAudioPatch = false; |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 743 | if (sinkConfig == null |
| 744 | || (mDesiredSamplingRate != 0 |
| 745 | && sinkConfig.samplingRate() != mDesiredSamplingRate) |
| 746 | || (mDesiredChannelMask != AudioFormat.CHANNEL_OUT_DEFAULT |
| 747 | && sinkConfig.channelMask() != mDesiredChannelMask) |
| 748 | || (mDesiredFormat != AudioFormat.ENCODING_DEFAULT |
| 749 | && sinkConfig.format() != mDesiredFormat)) { |
| 750 | sinkConfig = mAudioSource.buildConfig(mDesiredSamplingRate, mDesiredChannelMask, |
| 751 | mDesiredFormat, null); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 752 | shouldRecreateAudioPatch = true; |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 753 | } |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 754 | if (sourceConfig == null || sourceGainConfig != null) { |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 755 | sourceConfig = mAudioSource.buildConfig(sinkConfig.samplingRate(), |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 756 | sinkConfig.channelMask(), sinkConfig.format(), sourceGainConfig); |
| 757 | shouldRecreateAudioPatch = true; |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 758 | } |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 759 | if (shouldRecreateAudioPatch) { |
| 760 | mCommittedVolume = mVolume; |
| 761 | mAudioManager.createAudioPatch( |
| 762 | audioPatchArray, |
| 763 | new AudioPortConfig[] { sourceConfig }, |
| 764 | new AudioPortConfig[] { sinkConfig }); |
| 765 | mAudioPatch = audioPatchArray[0]; |
| 766 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 767 | } |
| 768 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 769 | @Override |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 770 | public void setStreamVolume(float volume) throws RemoteException { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 771 | synchronized (mImplLock) { |
| 772 | if (mReleased) { |
| 773 | throw new IllegalStateException("Device already released."); |
| 774 | } |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 775 | mVolume = volume; |
| 776 | updateAudioPatchLocked(); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 777 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | @Override |
| 781 | public boolean dispatchKeyEventToHdmi(KeyEvent event) throws RemoteException { |
| 782 | synchronized (mImplLock) { |
| 783 | if (mReleased) { |
| 784 | throw new IllegalStateException("Device already released."); |
| 785 | } |
| 786 | } |
Wonsik Kim | 610ccd9 | 2014-07-19 18:49:49 +0900 | [diff] [blame] | 787 | if (mInfo.getType() != TvInputHardwareInfo.TV_INPUT_TYPE_HDMI) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 788 | return false; |
| 789 | } |
| 790 | // TODO(hdmi): mHdmiClient.sendKeyEvent(event); |
| 791 | return false; |
| 792 | } |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 793 | |
| 794 | private boolean startCapture(Surface surface, TvStreamConfig config) { |
| 795 | synchronized (mImplLock) { |
| 796 | if (mReleased) { |
| 797 | return false; |
| 798 | } |
| 799 | if (surface == null || config == null) { |
| 800 | return false; |
| 801 | } |
| 802 | if (config.getType() != TvStreamConfig.STREAM_TYPE_BUFFER_PRODUCER) { |
| 803 | return false; |
| 804 | } |
| 805 | |
| 806 | int result = mHal.addStream(mInfo.getDeviceId(), surface, config); |
| 807 | return result == TvInputHal.SUCCESS; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | private boolean stopCapture(TvStreamConfig config) { |
| 812 | synchronized (mImplLock) { |
| 813 | if (mReleased) { |
| 814 | return false; |
| 815 | } |
| 816 | if (config == null) { |
| 817 | return false; |
| 818 | } |
| 819 | |
| 820 | int result = mHal.removeStream(mInfo.getDeviceId(), config); |
| 821 | return result == TvInputHal.SUCCESS; |
| 822 | } |
| 823 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 824 | |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 825 | private void updateAudioSinkLocked() { |
| 826 | if (mInfo.getAudioType() == AudioManager.DEVICE_NONE) { |
| 827 | return; |
| 828 | } |
| 829 | if (mOverrideAudioType == AudioManager.DEVICE_NONE) { |
| 830 | mAudioSink = findAudioSinkFromAudioPolicy(); |
| 831 | } else { |
| 832 | AudioDevicePort audioSink = |
| 833 | findAudioDevicePort(mOverrideAudioType, mOverrideAudioAddress); |
| 834 | if (audioSink != null) { |
| 835 | mAudioSink = audioSink; |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 840 | @Override |
| 841 | public void overrideAudioSink(int audioType, String audioAddress, int samplingRate, |
| 842 | int channelMask, int format) { |
| 843 | synchronized (mImplLock) { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 844 | mOverrideAudioType = audioType; |
| 845 | mOverrideAudioAddress = audioAddress; |
| 846 | updateAudioSinkLocked(); |
| 847 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 848 | mDesiredSamplingRate = samplingRate; |
| 849 | mDesiredChannelMask = channelMask; |
| 850 | mDesiredFormat = format; |
| 851 | |
| 852 | if (mAudioPatch != null) { |
| 853 | updateAudioPatchLocked(); |
| 854 | } |
| 855 | } |
| 856 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 857 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 858 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 859 | interface Listener { |
| 860 | public void onStateChanged(String inputId, int state); |
| 861 | public void onHardwareDeviceAdded(TvInputHardwareInfo info); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 862 | public void onHardwareDeviceRemoved(TvInputHardwareInfo info); |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 863 | public void onHdmiDeviceAdded(HdmiDeviceInfo device); |
| 864 | public void onHdmiDeviceRemoved(HdmiDeviceInfo device); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 865 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 866 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 867 | private class ListenerHandler extends Handler { |
| 868 | private static final int STATE_CHANGED = 1; |
| 869 | private static final int HARDWARE_DEVICE_ADDED = 2; |
| 870 | private static final int HARDWARE_DEVICE_REMOVED = 3; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 871 | private static final int HDMI_DEVICE_ADDED = 4; |
| 872 | private static final int HDMI_DEVICE_REMOVED = 5; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 873 | |
| 874 | @Override |
| 875 | public final void handleMessage(Message msg) { |
| 876 | switch (msg.what) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 877 | case STATE_CHANGED: { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 878 | String inputId = (String) msg.obj; |
| 879 | int state = msg.arg1; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 880 | mListener.onStateChanged(inputId, state); |
| 881 | break; |
| 882 | } |
| 883 | case HARDWARE_DEVICE_ADDED: { |
| 884 | TvInputHardwareInfo info = (TvInputHardwareInfo) msg.obj; |
| 885 | mListener.onHardwareDeviceAdded(info); |
| 886 | break; |
| 887 | } |
| 888 | case HARDWARE_DEVICE_REMOVED: { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 889 | TvInputHardwareInfo info = (TvInputHardwareInfo) msg.obj; |
| 890 | mListener.onHardwareDeviceRemoved(info); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 891 | break; |
| 892 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 893 | case HDMI_DEVICE_ADDED: { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 894 | HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 895 | mListener.onHdmiDeviceAdded(info); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 896 | break; |
| 897 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 898 | case HDMI_DEVICE_REMOVED: { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 899 | HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 900 | mListener.onHdmiDeviceRemoved(info); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 901 | break; |
| 902 | } |
| 903 | default: { |
| 904 | Slog.w(TAG, "Unhandled message: " + msg); |
| 905 | break; |
| 906 | } |
| 907 | } |
| 908 | } |
| 909 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 910 | |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 911 | // Listener implementations for HdmiControlService |
| 912 | |
| 913 | private final class HdmiHotplugEventListener extends IHdmiHotplugEventListener.Stub { |
| 914 | @Override |
| 915 | public void onReceived(HdmiHotplugEvent event) { |
| 916 | synchronized (mLock) { |
| 917 | mHdmiStateMap.put(event.getPort(), event.isConnected()); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 918 | TvInputHardwareInfo hardwareInfo = |
| 919 | findHardwareInfoForHdmiPortLocked(event.getPort()); |
| 920 | if (hardwareInfo == null) { |
| 921 | return; |
| 922 | } |
| 923 | String inputId = mHardwareInputIdMap.get(hardwareInfo.getDeviceId()); |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 924 | if (inputId == null) { |
| 925 | return; |
| 926 | } |
| 927 | mHandler.obtainMessage(ListenerHandler.STATE_CHANGED, |
| 928 | convertConnectedToState(event.isConnected()), 0, inputId).sendToTarget(); |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 933 | private final class HdmiDeviceEventListener extends IHdmiDeviceEventListener.Stub { |
| 934 | @Override |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 935 | public void onStatusChanged(HdmiDeviceInfo deviceInfo, boolean activated) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 936 | synchronized (mLock) { |
| 937 | if (activated) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 938 | if (!mHdmiDeviceList.contains(deviceInfo)) { |
| 939 | mHdmiDeviceList.add(deviceInfo); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 940 | } else { |
| 941 | Slog.w(TAG, "The list already contains " + deviceInfo + "; ignoring."); |
| 942 | return; |
| 943 | } |
| 944 | } else { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 945 | if (!mHdmiDeviceList.remove(deviceInfo)) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 946 | Slog.w(TAG, "The list doesn't contain " + deviceInfo + "; ignoring."); |
| 947 | return; |
| 948 | } |
| 949 | } |
| 950 | Message msg = mHandler.obtainMessage( |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 951 | activated ? ListenerHandler.HDMI_DEVICE_ADDED |
| 952 | : ListenerHandler.HDMI_DEVICE_REMOVED, |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 953 | 0, 0, deviceInfo); |
| 954 | if (findHardwareInfoForHdmiPortLocked(deviceInfo.getPortId()) != null) { |
| 955 | msg.sendToTarget(); |
| 956 | } else { |
| 957 | mPendingHdmiDeviceEvents.add(msg); |
| 958 | } |
| 959 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 960 | } |
| 961 | } |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 962 | |
| 963 | private final class HdmiInputChangeListener extends IHdmiInputChangeListener.Stub { |
| 964 | @Override |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 965 | public void onChanged(HdmiDeviceInfo device) throws RemoteException { |
Jinsuk Kim | b2b3151 | 2014-07-21 17:14:44 +0900 | [diff] [blame] | 966 | String inputId; |
| 967 | synchronized (mLock) { |
| 968 | if (device.isCecDevice()) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame^] | 969 | inputId = mHdmiInputIdMap.get(device.getLogicalAddress()); |
Jinsuk Kim | b2b3151 | 2014-07-21 17:14:44 +0900 | [diff] [blame] | 970 | } else { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 971 | TvInputHardwareInfo hardwareInfo = |
| 972 | findHardwareInfoForHdmiPortLocked(device.getPortId()); |
| 973 | inputId = (hardwareInfo == null) ? null |
| 974 | : mHardwareInputIdMap.get(hardwareInfo.getDeviceId()); |
Jinsuk Kim | b2b3151 | 2014-07-21 17:14:44 +0900 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | if (inputId != null) { |
| 978 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 979 | intent.setData(TvContract.buildChannelUriForPassthroughTvInput(inputId)); |
Jinsuk Kim | 58500f4 | 2014-08-05 12:48:35 +0900 | [diff] [blame] | 980 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jinsuk Kim | b2b3151 | 2014-07-21 17:14:44 +0900 | [diff] [blame] | 981 | mContext.startActivity(intent); |
| 982 | } else { |
| 983 | Slog.w(TAG, "onChanged: InputId cannot be found for :" + device); |
| 984 | } |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 985 | } |
| 986 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 987 | } |