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