Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.hdmi; |
| 18 | |
Jinsuk Kim | 0340bbc | 2014-06-05 11:07:47 +0900 | [diff] [blame] | 19 | import android.hardware.hdmi.HdmiPortInfo; |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 20 | import android.os.Handler; |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 21 | import android.os.Looper; |
Jungshik Jang | 4085d0e | 2014-05-27 19:52:39 +0900 | [diff] [blame] | 22 | import android.os.MessageQueue; |
Yuncheol Heo | ece603b | 2014-05-23 20:10:19 +0900 | [diff] [blame] | 23 | import android.util.Slog; |
Jungshik Jang | 7d9a843 | 2014-04-29 15:12:43 +0900 | [diff] [blame] | 24 | import android.util.SparseArray; |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 25 | |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 26 | import com.android.internal.util.IndentingPrintWriter; |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 27 | import com.android.internal.util.Predicate; |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 28 | import com.android.server.hdmi.HdmiAnnotations.IoThreadOnly; |
| 29 | import com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly; |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 30 | import com.android.server.hdmi.HdmiControlService.DevicePollingCallback; |
| 31 | |
Jungshik Jang | 3f74ab0 | 2014-04-30 14:31:02 +0900 | [diff] [blame] | 32 | import libcore.util.EmptyArray; |
| 33 | |
Jungshik Jang | 7d9a843 | 2014-04-29 15:12:43 +0900 | [diff] [blame] | 34 | import java.util.ArrayList; |
Jungshik Jang | 7d9a843 | 2014-04-29 15:12:43 +0900 | [diff] [blame] | 35 | import java.util.List; |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Manages HDMI-CEC command and behaviors. It converts user's command into CEC command |
| 39 | * and pass it to CEC HAL so that it sends message to other device. For incoming |
| 40 | * message it translates the message and delegates it to proper module. |
| 41 | * |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 42 | * <p>It should be careful to access member variables on IO thread because |
| 43 | * it can be accessed from system thread as well. |
| 44 | * |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 45 | * <p>It can be created only by {@link HdmiCecController#create} |
| 46 | * |
| 47 | * <p>Declared as package-private, accessed by {@link HdmiControlService} only. |
| 48 | */ |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 49 | final class HdmiCecController { |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 50 | private static final String TAG = "HdmiCecController"; |
| 51 | |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 52 | /** |
| 53 | * Interface to report allocated logical address. |
| 54 | */ |
| 55 | interface AllocateAddressCallback { |
| 56 | /** |
| 57 | * Called when a new logical address is allocated. |
| 58 | * |
| 59 | * @param deviceType requested device type to allocate logical address |
| 60 | * @param logicalAddress allocated logical address. If it is |
Jungshik Jang | 4223072 | 2014-07-07 17:40:25 +0900 | [diff] [blame] | 61 | * {@link Constants#ADDR_UNREGISTERED}, it means that |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 62 | * it failed to allocate logical address for the given device type |
| 63 | */ |
| 64 | void onAllocated(int deviceType, int logicalAddress); |
| 65 | } |
| 66 | |
Jungshik Jang | 3f74ab0 | 2014-04-30 14:31:02 +0900 | [diff] [blame] | 67 | private static final byte[] EMPTY_BODY = EmptyArray.BYTE; |
| 68 | |
Jungshik Jang | 3f74ab0 | 2014-04-30 14:31:02 +0900 | [diff] [blame] | 69 | private static final int NUM_LOGICAL_ADDRESS = 16; |
| 70 | |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 71 | // Predicate for whether the given logical address is remote device's one or not. |
| 72 | private final Predicate<Integer> mRemoteDeviceAddressPredicate = new Predicate<Integer>() { |
| 73 | @Override |
| 74 | public boolean apply(Integer address) { |
| 75 | return !isAllocatedLocalDeviceAddress(address); |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | // Predicate whether the given logical address is system audio's one or not |
| 80 | private final Predicate<Integer> mSystemAudioAddressPredicate = new Predicate<Integer>() { |
| 81 | @Override |
| 82 | public boolean apply(Integer address) { |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 83 | return HdmiUtils.getTypeFromAddress(address) == Constants.ADDR_AUDIO_SYSTEM; |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 84 | } |
| 85 | }; |
| 86 | |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 87 | // Handler instance to process synchronous I/O (mainly send) message. |
| 88 | private Handler mIoHandler; |
| 89 | |
| 90 | // Handler instance to process various messages coming from other CEC |
| 91 | // device or issued by internal state change. |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 92 | private Handler mControlHandler; |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 93 | |
| 94 | // Stores the pointer to the native implementation of the service that |
| 95 | // interacts with HAL. |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 96 | private volatile long mNativePtr; |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 97 | |
Jungshik Jang | 7df5286 | 2014-08-11 14:35:27 +0900 | [diff] [blame] | 98 | private final HdmiControlService mService; |
Jungshik Jang | a1fa91f | 2014-05-08 20:56:41 +0900 | [diff] [blame] | 99 | |
Jinsuk Kim | 7fe2ae0 | 2014-05-26 17:33:05 +0900 | [diff] [blame] | 100 | // Stores the local CEC devices in the system. Device type is used for key. |
| 101 | private final SparseArray<HdmiCecLocalDevice> mLocalDevices = new SparseArray<>(); |
Jungshik Jang | 7d9a843 | 2014-04-29 15:12:43 +0900 | [diff] [blame] | 102 | |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 103 | // Private constructor. Use HdmiCecController.create(). |
Jungshik Jang | 7df5286 | 2014-08-11 14:35:27 +0900 | [diff] [blame] | 104 | private HdmiCecController(HdmiControlService service) { |
| 105 | mService = service; |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
| 109 | * A factory method to get {@link HdmiCecController}. If it fails to initialize |
| 110 | * inner device or has no device it will return {@code null}. |
| 111 | * |
| 112 | * <p>Declared as package-private, accessed by {@link HdmiControlService} only. |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 113 | * @param service {@link HdmiControlService} instance used to create internal handler |
| 114 | * and to pass callback for incoming message or event. |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 115 | * @return {@link HdmiCecController} if device is initialized successfully. Otherwise, |
| 116 | * returns {@code null}. |
| 117 | */ |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 118 | static HdmiCecController create(HdmiControlService service) { |
Jungshik Jang | 7df5286 | 2014-08-11 14:35:27 +0900 | [diff] [blame] | 119 | HdmiCecController controller = new HdmiCecController(service); |
Jungshik Jang | 4085d0e | 2014-05-27 19:52:39 +0900 | [diff] [blame] | 120 | long nativePtr = nativeInit(controller, service.getServiceLooper().getQueue()); |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 121 | if (nativePtr == 0L) { |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 122 | controller = null; |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 123 | return null; |
| 124 | } |
| 125 | |
Jungshik Jang | 7df5286 | 2014-08-11 14:35:27 +0900 | [diff] [blame] | 126 | controller.init(nativePtr); |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 127 | return controller; |
| 128 | } |
| 129 | |
Jungshik Jang | 7df5286 | 2014-08-11 14:35:27 +0900 | [diff] [blame] | 130 | private void init(long nativePtr) { |
| 131 | mIoHandler = new Handler(mService.getServiceLooper()); |
| 132 | mControlHandler = new Handler(mService.getServiceLooper()); |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 133 | mNativePtr = nativePtr; |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 134 | } |
| 135 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 136 | @ServiceThreadOnly |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 137 | void addLocalDevice(int deviceType, HdmiCecLocalDevice device) { |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 138 | assertRunOnServiceThread(); |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 139 | mLocalDevices.put(deviceType, device); |
Jungshik Jang | 3f74ab0 | 2014-04-30 14:31:02 +0900 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Allocate a new logical address of the given device type. Allocated |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 144 | * address will be reported through {@link AllocateAddressCallback}. |
Jungshik Jang | 3f74ab0 | 2014-04-30 14:31:02 +0900 | [diff] [blame] | 145 | * |
| 146 | * <p> Declared as package-private, accessed by {@link HdmiControlService} only. |
| 147 | * |
| 148 | * @param deviceType type of device to used to determine logical address |
| 149 | * @param preferredAddress a logical address preferred to be allocated. |
Jungshik Jang | 4223072 | 2014-07-07 17:40:25 +0900 | [diff] [blame] | 150 | * If sets {@link Constants#ADDR_UNREGISTERED}, scans |
Jungshik Jang | 3f74ab0 | 2014-04-30 14:31:02 +0900 | [diff] [blame] | 151 | * the smallest logical address matched with the given device type. |
| 152 | * Otherwise, scan address will start from {@code preferredAddress} |
| 153 | * @param callback callback interface to report allocated logical address to caller |
| 154 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 155 | @ServiceThreadOnly |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 156 | void allocateLogicalAddress(final int deviceType, final int preferredAddress, |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 157 | final AllocateAddressCallback callback) { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 158 | assertRunOnServiceThread(); |
| 159 | |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 160 | runOnIoThread(new Runnable() { |
| 161 | @Override |
| 162 | public void run() { |
| 163 | handleAllocateLogicalAddress(deviceType, preferredAddress, callback); |
| 164 | } |
| 165 | }); |
| 166 | } |
| 167 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 168 | @IoThreadOnly |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 169 | private void handleAllocateLogicalAddress(final int deviceType, int preferredAddress, |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 170 | final AllocateAddressCallback callback) { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 171 | assertRunOnIoThread(); |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 172 | int startAddress = preferredAddress; |
| 173 | // If preferred address is "unregistered", start address will be the smallest |
| 174 | // address matched with the given device type. |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 175 | if (preferredAddress == Constants.ADDR_UNREGISTERED) { |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 176 | for (int i = 0; i < NUM_LOGICAL_ADDRESS; ++i) { |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 177 | if (deviceType == HdmiUtils.getTypeFromAddress(i)) { |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 178 | startAddress = i; |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 184 | int logicalAddress = Constants.ADDR_UNREGISTERED; |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 185 | // Iterates all possible addresses which has the same device type. |
| 186 | for (int i = 0; i < NUM_LOGICAL_ADDRESS; ++i) { |
| 187 | int curAddress = (startAddress + i) % NUM_LOGICAL_ADDRESS; |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 188 | if (curAddress != Constants.ADDR_UNREGISTERED |
| 189 | && deviceType == HdmiUtils.getTypeFromAddress(curAddress)) { |
Jungshik Jang | 8e93c84 | 2014-08-06 15:48:33 +0900 | [diff] [blame] | 190 | int failedPollingCount = 0; |
| 191 | for (int j = 0; j < HdmiConfig.ADDRESS_ALLOCATION_RETRY; ++j) { |
| 192 | if (!sendPollMessage(curAddress, curAddress, 1)) { |
| 193 | failedPollingCount++; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Pick logical address if failed ratio is more than a half of all retries. |
| 198 | if (failedPollingCount * 2 > HdmiConfig.ADDRESS_ALLOCATION_RETRY) { |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 199 | logicalAddress = curAddress; |
| 200 | break; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | final int assignedAddress = logicalAddress; |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 206 | HdmiLogger.debug("New logical address for device [%d]: [preferred:%d, assigned:%d]", |
| 207 | deviceType, preferredAddress, assignedAddress); |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 208 | if (callback != null) { |
| 209 | runOnServiceThread(new Runnable() { |
Jungshik Jang | 8e93c84 | 2014-08-06 15:48:33 +0900 | [diff] [blame] | 210 | @Override |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 211 | public void run() { |
| 212 | callback.onAllocated(deviceType, assignedAddress); |
| 213 | } |
| 214 | }); |
| 215 | } |
Jungshik Jang | 3f74ab0 | 2014-04-30 14:31:02 +0900 | [diff] [blame] | 216 | } |
| 217 | |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 218 | private static byte[] buildBody(int opcode, byte[] params) { |
| 219 | byte[] body = new byte[params.length + 1]; |
| 220 | body[0] = (byte) opcode; |
| 221 | System.arraycopy(params, 0, body, 1, params.length); |
| 222 | return body; |
| 223 | } |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 224 | |
Jungshik Jang | 7d9a843 | 2014-04-29 15:12:43 +0900 | [diff] [blame] | 225 | |
Jinsuk Kim | 0340bbc | 2014-06-05 11:07:47 +0900 | [diff] [blame] | 226 | HdmiPortInfo[] getPortInfos() { |
| 227 | return nativeGetPortInfos(mNativePtr); |
| 228 | } |
| 229 | |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 230 | /** |
Jinsuk Kim | 7fe2ae0 | 2014-05-26 17:33:05 +0900 | [diff] [blame] | 231 | * Return the locally hosted logical device of a given type. |
| 232 | * |
| 233 | * @param deviceType logical device type |
| 234 | * @return {@link HdmiCecLocalDevice} instance if the instance of the type is available; |
| 235 | * otherwise null. |
| 236 | */ |
| 237 | HdmiCecLocalDevice getLocalDevice(int deviceType) { |
| 238 | return mLocalDevices.get(deviceType); |
| 239 | } |
| 240 | |
| 241 | /** |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 242 | * Add a new logical address to the device. Device's HW should be notified |
| 243 | * when a new logical address is assigned to a device, so that it can accept |
| 244 | * a command having available destinations. |
| 245 | * |
| 246 | * <p>Declared as package-private. accessed by {@link HdmiControlService} only. |
| 247 | * |
| 248 | * @param newLogicalAddress a logical address to be added |
| 249 | * @return 0 on success. Otherwise, returns negative value |
| 250 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 251 | @ServiceThreadOnly |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 252 | int addLogicalAddress(int newLogicalAddress) { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 253 | assertRunOnServiceThread(); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 254 | if (HdmiUtils.isValidAddress(newLogicalAddress)) { |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 255 | return nativeAddLogicalAddress(mNativePtr, newLogicalAddress); |
| 256 | } else { |
| 257 | return -1; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Clear all logical addresses registered in the device. |
| 263 | * |
| 264 | * <p>Declared as package-private. accessed by {@link HdmiControlService} only. |
| 265 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 266 | @ServiceThreadOnly |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 267 | void clearLogicalAddress() { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 268 | assertRunOnServiceThread(); |
Jinsuk Kim | 7fe2ae0 | 2014-05-26 17:33:05 +0900 | [diff] [blame] | 269 | for (int i = 0; i < mLocalDevices.size(); ++i) { |
| 270 | mLocalDevices.valueAt(i).clearAddress(); |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 271 | } |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 272 | nativeClearLogicalAddress(mNativePtr); |
| 273 | } |
| 274 | |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 275 | @ServiceThreadOnly |
| 276 | void clearLocalDevices() { |
| 277 | assertRunOnServiceThread(); |
| 278 | mLocalDevices.clear(); |
| 279 | } |
| 280 | |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 281 | /** |
| 282 | * Return the physical address of the device. |
| 283 | * |
| 284 | * <p>Declared as package-private. accessed by {@link HdmiControlService} only. |
| 285 | * |
| 286 | * @return CEC physical address of the device. The range of success address |
| 287 | * is between 0x0000 and 0xFFFF. If failed it returns -1 |
| 288 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 289 | @ServiceThreadOnly |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 290 | int getPhysicalAddress() { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 291 | assertRunOnServiceThread(); |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 292 | return nativeGetPhysicalAddress(mNativePtr); |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Return CEC version of the device. |
| 297 | * |
| 298 | * <p>Declared as package-private. accessed by {@link HdmiControlService} only. |
| 299 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 300 | @ServiceThreadOnly |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 301 | int getVersion() { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 302 | assertRunOnServiceThread(); |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 303 | return nativeGetVersion(mNativePtr); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Return vendor id of the device. |
| 308 | * |
| 309 | * <p>Declared as package-private. accessed by {@link HdmiControlService} only. |
| 310 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 311 | @ServiceThreadOnly |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 312 | int getVendorId() { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 313 | assertRunOnServiceThread(); |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 314 | return nativeGetVendorId(mNativePtr); |
| 315 | } |
| 316 | |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 317 | /** |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 318 | * Set an option to CEC HAL. |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 319 | * |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 320 | * @param flag key of option |
| 321 | * @param value value of option |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 322 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 323 | @ServiceThreadOnly |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 324 | void setOption(int flag, int value) { |
| 325 | assertRunOnServiceThread(); |
| 326 | nativeSetOption(mNativePtr, flag, value); |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Configure ARC circuit in the hardware logic to start or stop the feature. |
| 331 | * |
| 332 | * @param enabled whether to enable/disable ARC |
| 333 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 334 | @ServiceThreadOnly |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 335 | void setAudioReturnChannel(boolean enabled) { |
| 336 | assertRunOnServiceThread(); |
| 337 | nativeSetAudioReturnChannel(mNativePtr, enabled); |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Return the connection status of the specified port |
| 342 | * |
| 343 | * @param port port number to check connection status |
| 344 | * @return true if connected; otherwise, return false |
| 345 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 346 | @ServiceThreadOnly |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 347 | boolean isConnected(int port) { |
| 348 | assertRunOnServiceThread(); |
| 349 | return nativeIsConnected(mNativePtr, port); |
| 350 | } |
| 351 | |
| 352 | /** |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 353 | * Poll all remote devices. It sends <Polling Message> to all remote |
| 354 | * devices. |
| 355 | * |
| 356 | * <p>Declared as package-private. accessed by {@link HdmiControlService} only. |
| 357 | * |
| 358 | * @param callback an interface used to get a list of all remote devices' address |
Jungshik Jang | 1de5142 | 2014-07-03 11:14:26 +0900 | [diff] [blame] | 359 | * @param sourceAddress a logical address of source device where sends polling message |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 360 | * @param pickStrategy strategy how to pick polling candidates |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 361 | * @param retryCount the number of retry used to send polling message to remote devices |
| 362 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 363 | @ServiceThreadOnly |
Jungshik Jang | 1de5142 | 2014-07-03 11:14:26 +0900 | [diff] [blame] | 364 | void pollDevices(DevicePollingCallback callback, int sourceAddress, int pickStrategy, |
| 365 | int retryCount) { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 366 | assertRunOnServiceThread(); |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 367 | |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 368 | // Extract polling candidates. No need to poll against local devices. |
| 369 | List<Integer> pollingCandidates = pickPollCandidates(pickStrategy); |
Jungshik Jang | 1de5142 | 2014-07-03 11:14:26 +0900 | [diff] [blame] | 370 | runDevicePolling(sourceAddress, pollingCandidates, retryCount, callback); |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 371 | } |
| 372 | |
Jungshik Jang | cc5ef8c | 2014-05-27 13:27:36 +0900 | [diff] [blame] | 373 | /** |
| 374 | * Return a list of all {@link HdmiCecLocalDevice}s. |
| 375 | * |
| 376 | * <p>Declared as package-private. accessed by {@link HdmiControlService} only. |
| 377 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 378 | @ServiceThreadOnly |
Jungshik Jang | cc5ef8c | 2014-05-27 13:27:36 +0900 | [diff] [blame] | 379 | List<HdmiCecLocalDevice> getLocalDeviceList() { |
| 380 | assertRunOnServiceThread(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 381 | return HdmiUtils.sparseArrayToList(mLocalDevices); |
Jungshik Jang | cc5ef8c | 2014-05-27 13:27:36 +0900 | [diff] [blame] | 382 | } |
| 383 | |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 384 | private List<Integer> pickPollCandidates(int pickStrategy) { |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 385 | int strategy = pickStrategy & Constants.POLL_STRATEGY_MASK; |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 386 | Predicate<Integer> pickPredicate = null; |
| 387 | switch (strategy) { |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 388 | case Constants.POLL_STRATEGY_SYSTEM_AUDIO: |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 389 | pickPredicate = mSystemAudioAddressPredicate; |
| 390 | break; |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 391 | case Constants.POLL_STRATEGY_REMOTES_DEVICES: |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 392 | default: // The default is POLL_STRATEGY_REMOTES_DEVICES. |
| 393 | pickPredicate = mRemoteDeviceAddressPredicate; |
| 394 | break; |
| 395 | } |
| 396 | |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 397 | int iterationStrategy = pickStrategy & Constants.POLL_ITERATION_STRATEGY_MASK; |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 398 | ArrayList<Integer> pollingCandidates = new ArrayList<>(); |
| 399 | switch (iterationStrategy) { |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 400 | case Constants.POLL_ITERATION_IN_ORDER: |
| 401 | for (int i = Constants.ADDR_TV; i <= Constants.ADDR_SPECIFIC_USE; ++i) { |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 402 | if (pickPredicate.apply(i)) { |
| 403 | pollingCandidates.add(i); |
| 404 | } |
| 405 | } |
| 406 | break; |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 407 | case Constants.POLL_ITERATION_REVERSE_ORDER: |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 408 | default: // The default is reverse order. |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 409 | for (int i = Constants.ADDR_SPECIFIC_USE; i >= Constants.ADDR_TV; --i) { |
Jungshik Jang | 0f8b4b7 | 2014-05-28 17:58:58 +0900 | [diff] [blame] | 410 | if (pickPredicate.apply(i)) { |
| 411 | pollingCandidates.add(i); |
| 412 | } |
| 413 | } |
| 414 | break; |
| 415 | } |
| 416 | return pollingCandidates; |
| 417 | } |
| 418 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 419 | @ServiceThreadOnly |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 420 | private boolean isAllocatedLocalDeviceAddress(int address) { |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 421 | assertRunOnServiceThread(); |
Jinsuk Kim | 7fe2ae0 | 2014-05-26 17:33:05 +0900 | [diff] [blame] | 422 | for (int i = 0; i < mLocalDevices.size(); ++i) { |
| 423 | if (mLocalDevices.valueAt(i).isAddressOf(address)) { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 424 | return true; |
| 425 | } |
| 426 | } |
| 427 | return false; |
| 428 | } |
| 429 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 430 | @ServiceThreadOnly |
Jungshik Jang | 1de5142 | 2014-07-03 11:14:26 +0900 | [diff] [blame] | 431 | private void runDevicePolling(final int sourceAddress, |
| 432 | final List<Integer> candidates, final int retryCount, |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 433 | final DevicePollingCallback callback) { |
| 434 | assertRunOnServiceThread(); |
| 435 | runOnIoThread(new Runnable() { |
| 436 | @Override |
| 437 | public void run() { |
| 438 | final ArrayList<Integer> allocated = new ArrayList<>(); |
| 439 | for (Integer address : candidates) { |
Jungshik Jang | 1de5142 | 2014-07-03 11:14:26 +0900 | [diff] [blame] | 440 | if (sendPollMessage(sourceAddress, address, retryCount)) { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 441 | allocated.add(address); |
| 442 | } |
| 443 | } |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 444 | HdmiLogger.debug("[P]:Allocated Address=" + allocated); |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 445 | if (callback != null) { |
| 446 | runOnServiceThread(new Runnable() { |
| 447 | @Override |
| 448 | public void run() { |
| 449 | callback.onPollingFinished(allocated); |
| 450 | } |
| 451 | }); |
| 452 | } |
| 453 | } |
| 454 | }); |
| 455 | } |
| 456 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 457 | @IoThreadOnly |
Jungshik Jang | 1de5142 | 2014-07-03 11:14:26 +0900 | [diff] [blame] | 458 | private boolean sendPollMessage(int sourceAddress, int destinationAddress, int retryCount) { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 459 | assertRunOnIoThread(); |
| 460 | for (int i = 0; i < retryCount; ++i) { |
Jungshik Jang | 1de5142 | 2014-07-03 11:14:26 +0900 | [diff] [blame] | 461 | // <Polling Message> is a message which has empty body. |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 462 | // If sending <Polling Message> failed (NAK), it becomes |
| 463 | // new logical address for the device because no device uses |
| 464 | // it as logical address of the device. |
Jungshik Jang | 1de5142 | 2014-07-03 11:14:26 +0900 | [diff] [blame] | 465 | if (nativeSendCecCommand(mNativePtr, sourceAddress, destinationAddress, EMPTY_BODY) |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 466 | == Constants.SEND_RESULT_SUCCESS) { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 467 | return true; |
| 468 | } |
| 469 | } |
| 470 | return false; |
| 471 | } |
| 472 | |
| 473 | private void assertRunOnIoThread() { |
| 474 | if (Looper.myLooper() != mIoHandler.getLooper()) { |
| 475 | throw new IllegalStateException("Should run on io thread."); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | private void assertRunOnServiceThread() { |
| 480 | if (Looper.myLooper() != mControlHandler.getLooper()) { |
| 481 | throw new IllegalStateException("Should run on service thread."); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | // Run a Runnable on IO thread. |
| 486 | // It should be careful to access member variables on IO thread because |
| 487 | // it can be accessed from system thread as well. |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 488 | private void runOnIoThread(Runnable runnable) { |
| 489 | mIoHandler.post(runnable); |
| 490 | } |
| 491 | |
| 492 | private void runOnServiceThread(Runnable runnable) { |
| 493 | mControlHandler.post(runnable); |
| 494 | } |
| 495 | |
Jungshik Jang | a1fa91f | 2014-05-08 20:56:41 +0900 | [diff] [blame] | 496 | private boolean isAcceptableAddress(int address) { |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 497 | // Can access command targeting devices available in local device or broadcast command. |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 498 | if (address == Constants.ADDR_BROADCAST) { |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 499 | return true; |
| 500 | } |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 501 | return isAllocatedLocalDeviceAddress(address); |
Jungshik Jang | a1fa91f | 2014-05-08 20:56:41 +0900 | [diff] [blame] | 502 | } |
| 503 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 504 | @ServiceThreadOnly |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 505 | private void onReceiveCommand(HdmiCecMessage message) { |
Jungshik Jang | 02bb426 | 2014-05-23 16:48:31 +0900 | [diff] [blame] | 506 | assertRunOnServiceThread(); |
Yuncheol Heo | 6aae652 | 2014-08-05 14:48:37 +0900 | [diff] [blame] | 507 | if (isAcceptableAddress(message.getDestination()) && mService.handleCecCommand(message)) { |
Jungshik Jang | a1fa91f | 2014-05-08 20:56:41 +0900 | [diff] [blame] | 508 | return; |
| 509 | } |
Yuncheol Heo | 6aae652 | 2014-08-05 14:48:37 +0900 | [diff] [blame] | 510 | // Not handled message, so we will reply it with <Feature Abort>. |
| 511 | maySendFeatureAbortCommand(message, Constants.ABORT_UNRECOGNIZED_OPCODE); |
| 512 | } |
Jungshik Jang | 1827fdc | 2014-07-17 13:58:14 +0900 | [diff] [blame] | 513 | |
Yuncheol Heo | 6aae652 | 2014-08-05 14:48:37 +0900 | [diff] [blame] | 514 | @ServiceThreadOnly |
| 515 | void maySendFeatureAbortCommand(HdmiCecMessage message, int reason) { |
| 516 | assertRunOnServiceThread(); |
| 517 | // Swap the source and the destination. |
| 518 | int src = message.getDestination(); |
| 519 | int dest = message.getSource(); |
| 520 | if (src == Constants.ADDR_BROADCAST || dest == Constants.ADDR_UNREGISTERED) { |
| 521 | // Don't reply <Feature Abort> from the unregistered devices or for the broadcasted |
| 522 | // messages. See CEC 12.2 Protocol General Rules for detail. |
| 523 | return; |
| 524 | } |
| 525 | int originalOpcode = message.getOpcode(); |
| 526 | if (originalOpcode == Constants.MESSAGE_FEATURE_ABORT) { |
| 527 | return; |
| 528 | } |
| 529 | sendCommand( |
| 530 | HdmiCecMessageBuilder.buildFeatureAbortCommand(src, dest, originalOpcode, reason)); |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 531 | } |
| 532 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 533 | @ServiceThreadOnly |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 534 | void sendCommand(HdmiCecMessage cecMessage) { |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 535 | assertRunOnServiceThread(); |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 536 | sendCommand(cecMessage, null); |
| 537 | } |
| 538 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 539 | @ServiceThreadOnly |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 540 | void sendCommand(final HdmiCecMessage cecMessage, |
| 541 | final HdmiControlService.SendMessageCallback callback) { |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 542 | assertRunOnServiceThread(); |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 543 | runOnIoThread(new Runnable() { |
| 544 | @Override |
| 545 | public void run() { |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 546 | HdmiLogger.debug("[S]:" + cecMessage); |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 547 | byte[] body = buildBody(cecMessage.getOpcode(), cecMessage.getParams()); |
Jungshik Jang | 8ed86c4 | 2014-07-11 11:56:46 +0900 | [diff] [blame] | 548 | int i = 0; |
| 549 | int errorCode = Constants.SEND_RESULT_SUCCESS; |
| 550 | do { |
| 551 | errorCode = nativeSendCecCommand(mNativePtr, cecMessage.getSource(), |
| 552 | cecMessage.getDestination(), body); |
| 553 | if (errorCode == Constants.SEND_RESULT_SUCCESS) { |
| 554 | break; |
| 555 | } |
| 556 | } while (i++ < HdmiConfig.RETRANSMISSION_COUNT); |
| 557 | |
| 558 | final int finalError = errorCode; |
| 559 | if (finalError != Constants.SEND_RESULT_SUCCESS) { |
Yuncheol Heo | ece603b | 2014-05-23 20:10:19 +0900 | [diff] [blame] | 560 | Slog.w(TAG, "Failed to send " + cecMessage); |
| 561 | } |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 562 | if (callback != null) { |
| 563 | runOnServiceThread(new Runnable() { |
| 564 | @Override |
| 565 | public void run() { |
Jungshik Jang | 8ed86c4 | 2014-07-11 11:56:46 +0900 | [diff] [blame] | 566 | callback.onSendCompleted(finalError); |
Jungshik Jang | d643f76 | 2014-05-22 19:28:09 +0900 | [diff] [blame] | 567 | } |
| 568 | }); |
| 569 | } |
| 570 | } |
| 571 | }); |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 572 | } |
| 573 | |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 574 | /** |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 575 | * Called by native when incoming CEC message arrived. |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 576 | */ |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 577 | @ServiceThreadOnly |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 578 | private void handleIncomingCecCommand(int srcAddress, int dstAddress, byte[] body) { |
Jungshik Jang | 4085d0e | 2014-05-27 19:52:39 +0900 | [diff] [blame] | 579 | assertRunOnServiceThread(); |
Jungshik Jang | c94ac5c | 2014-08-27 13:48:37 +0900 | [diff] [blame] | 580 | HdmiCecMessage command = HdmiCecMessageBuilder.of(srcAddress, dstAddress, body); |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 581 | HdmiLogger.debug("[R]:" + command); |
Jungshik Jang | c94ac5c | 2014-08-27 13:48:37 +0900 | [diff] [blame] | 582 | onReceiveCommand(command); |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /** |
| 586 | * Called by native when a hotplug event issues. |
| 587 | */ |
Jungshik Jang | 4223072 | 2014-07-07 17:40:25 +0900 | [diff] [blame] | 588 | @ServiceThreadOnly |
| 589 | private void handleHotplug(int port, boolean connected) { |
| 590 | assertRunOnServiceThread(); |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 591 | HdmiLogger.debug("Hotplug event:[port:%d, connected:%b]", port, connected); |
Jungshik Jang | 4223072 | 2014-07-07 17:40:25 +0900 | [diff] [blame] | 592 | mService.onHotplug(port, connected); |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 593 | } |
| 594 | |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 595 | void dump(final IndentingPrintWriter pw) { |
| 596 | for (int i = 0; i < mLocalDevices.size(); ++i) { |
| 597 | pw.println("HdmiCecLocalDevice #" + i + ":"); |
| 598 | pw.increaseIndent(); |
| 599 | mLocalDevices.valueAt(i).dump(pw); |
| 600 | pw.decreaseIndent(); |
| 601 | } |
| 602 | } |
| 603 | |
Jungshik Jang | 4085d0e | 2014-05-27 19:52:39 +0900 | [diff] [blame] | 604 | private static native long nativeInit(HdmiCecController handler, MessageQueue messageQueue); |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 605 | private static native int nativeSendCecCommand(long controllerPtr, int srcAddress, |
Jungshik Jang | e9c77c8 | 2014-04-24 20:30:09 +0900 | [diff] [blame] | 606 | int dstAddress, byte[] body); |
Jungshik Jang | a9095ba | 2014-05-02 13:06:22 +0900 | [diff] [blame] | 607 | private static native int nativeAddLogicalAddress(long controllerPtr, int logicalAddress); |
| 608 | private static native void nativeClearLogicalAddress(long controllerPtr); |
| 609 | private static native int nativeGetPhysicalAddress(long controllerPtr); |
| 610 | private static native int nativeGetVersion(long controllerPtr); |
| 611 | private static native int nativeGetVendorId(long controllerPtr); |
Jinsuk Kim | 0340bbc | 2014-06-05 11:07:47 +0900 | [diff] [blame] | 612 | private static native HdmiPortInfo[] nativeGetPortInfos(long controllerPtr); |
Jungshik Jang | 092b445 | 2014-06-11 15:19:17 +0900 | [diff] [blame] | 613 | private static native void nativeSetOption(long controllerPtr, int flag, int value); |
| 614 | private static native void nativeSetAudioReturnChannel(long controllerPtr, boolean flag); |
| 615 | private static native boolean nativeIsConnected(long controllerPtr, int port); |
Jungshik Jang | 0792d37 | 2014-04-23 17:57:26 +0900 | [diff] [blame] | 616 | } |