HdmiCecLocalDevice.java revision 43c23e273e1b78caf26899eca5a4f51df9d52400
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 17package com.android.server.hdmi; 18 19import android.hardware.hdmi.HdmiCecDeviceInfo; 20import android.os.Handler; 21import android.os.Looper; 22import android.os.Message; 23import android.util.Slog; 24 25import com.android.internal.annotations.GuardedBy; 26import com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly; 27 28import java.util.ArrayList; 29import java.util.Collections; 30import java.util.Iterator; 31import java.util.LinkedList; 32import java.util.List; 33 34/** 35 * Class that models a logical CEC device hosted in this system. Handles initialization, 36 * CEC commands that call for actions customized per device type. 37 */ 38abstract class HdmiCecLocalDevice { 39 private static final String TAG = "HdmiCecLocalDevice"; 40 41 private static final int MSG_DISABLE_DEVICE_TIMEOUT = 1; 42 // Timeout in millisecond for device clean up (5s). 43 // Normal actions timeout is 2s but some of them would have several sequence of timeout. 44 private static final int DEVICE_CLEANUP_TIMEOUT = 5000; 45 46 protected final HdmiControlService mService; 47 protected final int mDeviceType; 48 protected int mAddress; 49 protected int mPreferredAddress; 50 protected HdmiCecDeviceInfo mDeviceInfo; 51 52 static class ActiveSource { 53 int logicalAddress; 54 int physicalAddress; 55 56 public ActiveSource() { 57 invalidate(); 58 } 59 public ActiveSource(int logical, int physical) { 60 logicalAddress = logical; 61 physicalAddress = physical; 62 } 63 public static ActiveSource of(int logical, int physical) { 64 return new ActiveSource(logical, physical); 65 } 66 public boolean isValid() { 67 return HdmiUtils.isValidAddress(logicalAddress); 68 } 69 public void invalidate() { 70 logicalAddress = Constants.ADDR_INVALID; 71 physicalAddress = Constants.INVALID_PHYSICAL_ADDRESS; 72 } 73 public boolean equals(int logical, int physical) { 74 return logicalAddress == logical && physicalAddress == physical; 75 } 76 @Override 77 public boolean equals(Object obj) { 78 if (obj instanceof ActiveSource) { 79 ActiveSource that = (ActiveSource) obj; 80 return that.logicalAddress == logicalAddress && 81 that.physicalAddress == physicalAddress; 82 } 83 return false; 84 } 85 @Override 86 public int hashCode() { 87 return logicalAddress * 29 + physicalAddress; 88 } 89 } 90 // Logical address of the active source. 91 @GuardedBy("mLock") 92 protected final ActiveSource mActiveSource = new ActiveSource(); 93 94 // Active routing path. Physical address of the active source but not all the time, such as 95 // when the new active source does not claim itself to be one. Note that we don't keep 96 // the active port id (or active input) since it can be gotten by {@link #pathToPortId(int)}. 97 @GuardedBy("mLock") 98 private int mActiveRoutingPath; 99 100 protected final HdmiCecMessageCache mCecMessageCache = new HdmiCecMessageCache(); 101 protected final Object mLock; 102 103 // A collection of FeatureAction. 104 // Note that access to this collection should happen in service thread. 105 private final LinkedList<FeatureAction> mActions = new LinkedList<>(); 106 107 private final Handler mHandler = new Handler () { 108 @Override 109 public void handleMessage(Message msg) { 110 switch (msg.what) { 111 case MSG_DISABLE_DEVICE_TIMEOUT: 112 handleDisableDeviceTimeout(); 113 break; 114 } 115 } 116 }; 117 118 /** 119 * A callback interface to get notified when all pending action is cleared. 120 * It can be called when timeout happened. 121 */ 122 interface PendingActionClearedCallback { 123 void onCleared(HdmiCecLocalDevice device); 124 } 125 126 protected PendingActionClearedCallback mPendingActionClearedCallback; 127 128 protected HdmiCecLocalDevice(HdmiControlService service, int deviceType) { 129 mService = service; 130 mDeviceType = deviceType; 131 mAddress = Constants.ADDR_UNREGISTERED; 132 mLock = service.getServiceLock(); 133 } 134 135 // Factory method that returns HdmiCecLocalDevice of corresponding type. 136 static HdmiCecLocalDevice create(HdmiControlService service, int deviceType) { 137 switch (deviceType) { 138 case HdmiCecDeviceInfo.DEVICE_TV: 139 return new HdmiCecLocalDeviceTv(service); 140 case HdmiCecDeviceInfo.DEVICE_PLAYBACK: 141 return new HdmiCecLocalDevicePlayback(service); 142 default: 143 return null; 144 } 145 } 146 147 @ServiceThreadOnly 148 void init() { 149 assertRunOnServiceThread(); 150 mPreferredAddress = getPreferredAddress(); 151 } 152 153 /** 154 * Called once a logical address of the local device is allocated. 155 */ 156 protected abstract void onAddressAllocated(int logicalAddress, boolean fromBootup); 157 158 /** 159 * Get the preferred logical address from system properties. 160 */ 161 protected abstract int getPreferredAddress(); 162 163 /** 164 * Set the preferred logical address to system properties. 165 */ 166 protected abstract void setPreferredAddress(int addr); 167 168 /** 169 * Dispatch incoming message. 170 * 171 * @param message incoming message 172 * @return true if consumed a message; otherwise, return false. 173 */ 174 @ServiceThreadOnly 175 final boolean dispatchMessage(HdmiCecMessage message) { 176 assertRunOnServiceThread(); 177 int dest = message.getDestination(); 178 if (dest != mAddress && dest != Constants.ADDR_BROADCAST) { 179 return false; 180 } 181 // Cache incoming message. Note that it caches only white-listed one. 182 mCecMessageCache.cacheMessage(message); 183 return onMessage(message); 184 } 185 186 @ServiceThreadOnly 187 protected final boolean onMessage(HdmiCecMessage message) { 188 assertRunOnServiceThread(); 189 if (dispatchMessageToAction(message)) { 190 return true; 191 } 192 switch (message.getOpcode()) { 193 case Constants.MESSAGE_ACTIVE_SOURCE: 194 return handleActiveSource(message); 195 case Constants.MESSAGE_INACTIVE_SOURCE: 196 return handleInactiveSource(message); 197 case Constants.MESSAGE_REQUEST_ACTIVE_SOURCE: 198 return handleRequestActiveSource(message); 199 case Constants.MESSAGE_GET_MENU_LANGUAGE: 200 return handleGetMenuLanguage(message); 201 case Constants.MESSAGE_GIVE_PHYSICAL_ADDRESS: 202 return handleGivePhysicalAddress(); 203 case Constants.MESSAGE_GIVE_OSD_NAME: 204 return handleGiveOsdName(message); 205 case Constants.MESSAGE_GIVE_DEVICE_VENDOR_ID: 206 return handleGiveDeviceVendorId(); 207 case Constants.MESSAGE_GET_CEC_VERSION: 208 return handleGetCecVersion(message); 209 case Constants.MESSAGE_REPORT_PHYSICAL_ADDRESS: 210 return handleReportPhysicalAddress(message); 211 case Constants.MESSAGE_ROUTING_CHANGE: 212 return handleRoutingChange(message); 213 case Constants.MESSAGE_INITIATE_ARC: 214 return handleInitiateArc(message); 215 case Constants.MESSAGE_TERMINATE_ARC: 216 return handleTerminateArc(message); 217 case Constants.MESSAGE_SET_SYSTEM_AUDIO_MODE: 218 return handleSetSystemAudioMode(message); 219 case Constants.MESSAGE_SYSTEM_AUDIO_MODE_STATUS: 220 return handleSystemAudioModeStatus(message); 221 case Constants.MESSAGE_REPORT_AUDIO_STATUS: 222 return handleReportAudioStatus(message); 223 case Constants.MESSAGE_STANDBY: 224 return handleStandby(message); 225 case Constants.MESSAGE_TEXT_VIEW_ON: 226 return handleTextViewOn(message); 227 case Constants.MESSAGE_IMAGE_VIEW_ON: 228 return handleImageViewOn(message); 229 case Constants.MESSAGE_USER_CONTROL_PRESSED: 230 return handleUserControlPressed(message); 231 case Constants.MESSAGE_SET_STREAM_PATH: 232 return handleSetStreamPath(message); 233 case Constants.MESSAGE_GIVE_DEVICE_POWER_STATUS: 234 return handleGiveDevicePowerStatus(message); 235 case Constants.MESSAGE_VENDOR_COMMAND: 236 return handleVendorCommand(message); 237 case Constants.MESSAGE_VENDOR_COMMAND_WITH_ID: 238 return handleVendorCommandWithId(message); 239 case Constants.MESSAGE_SET_OSD_NAME: 240 return handleSetOsdName(message); 241 case Constants.MESSAGE_RECORD_TV_SCREEN: 242 return handleRecordTvScreen(message); 243 default: 244 return false; 245 } 246 } 247 248 @ServiceThreadOnly 249 private boolean dispatchMessageToAction(HdmiCecMessage message) { 250 assertRunOnServiceThread(); 251 for (FeatureAction action : mActions) { 252 if (action.processCommand(message)) { 253 return true; 254 } 255 } 256 return false; 257 } 258 259 @ServiceThreadOnly 260 protected boolean handleGivePhysicalAddress() { 261 assertRunOnServiceThread(); 262 263 int physicalAddress = mService.getPhysicalAddress(); 264 HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( 265 mAddress, physicalAddress, mDeviceType); 266 mService.sendCecCommand(cecMessage); 267 return true; 268 } 269 270 @ServiceThreadOnly 271 protected boolean handleGiveDeviceVendorId() { 272 assertRunOnServiceThread(); 273 int vendorId = mService.getVendorId(); 274 HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildDeviceVendorIdCommand( 275 mAddress, vendorId); 276 mService.sendCecCommand(cecMessage); 277 return true; 278 } 279 280 @ServiceThreadOnly 281 protected boolean handleGetCecVersion(HdmiCecMessage message) { 282 assertRunOnServiceThread(); 283 int version = mService.getCecVersion(); 284 HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildCecVersion(message.getDestination(), 285 message.getSource(), version); 286 mService.sendCecCommand(cecMessage); 287 return true; 288 } 289 290 @ServiceThreadOnly 291 protected boolean handleActiveSource(HdmiCecMessage message) { 292 return false; 293 } 294 295 @ServiceThreadOnly 296 protected boolean handleInactiveSource(HdmiCecMessage message) { 297 return false; 298 } 299 300 @ServiceThreadOnly 301 protected boolean handleRequestActiveSource(HdmiCecMessage message) { 302 return false; 303 } 304 305 @ServiceThreadOnly 306 protected boolean handleGetMenuLanguage(HdmiCecMessage message) { 307 assertRunOnServiceThread(); 308 Slog.w(TAG, "Only TV can handle <Get Menu Language>:" + message.toString()); 309 mService.sendCecCommand( 310 HdmiCecMessageBuilder.buildFeatureAbortCommand(mAddress, 311 message.getSource(), Constants.MESSAGE_GET_MENU_LANGUAGE, 312 Constants.ABORT_UNRECOGNIZED_MODE)); 313 return true; 314 } 315 316 @ServiceThreadOnly 317 protected boolean handleGiveOsdName(HdmiCecMessage message) { 318 assertRunOnServiceThread(); 319 // Note that since this method is called after logical address allocation is done, 320 // mDeviceInfo should not be null. 321 HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildSetOsdNameCommand( 322 mAddress, message.getSource(), mDeviceInfo.getDisplayName()); 323 if (cecMessage != null) { 324 mService.sendCecCommand(cecMessage); 325 } else { 326 Slog.w(TAG, "Failed to build <Get Osd Name>:" + mDeviceInfo.getDisplayName()); 327 } 328 return true; 329 } 330 331 protected boolean handleRoutingChange(HdmiCecMessage message) { 332 return false; 333 } 334 335 protected boolean handleReportPhysicalAddress(HdmiCecMessage message) { 336 return false; 337 } 338 339 protected boolean handleSystemAudioModeStatus(HdmiCecMessage message) { 340 return false; 341 } 342 343 protected boolean handleSetSystemAudioMode(HdmiCecMessage message) { 344 return false; 345 } 346 347 protected boolean handleTerminateArc(HdmiCecMessage message) { 348 return false; 349 } 350 351 protected boolean handleInitiateArc(HdmiCecMessage message) { 352 return false; 353 } 354 355 protected boolean handleReportAudioStatus(HdmiCecMessage message) { 356 return false; 357 } 358 359 @ServiceThreadOnly 360 protected boolean handleStandby(HdmiCecMessage message) { 361 assertRunOnServiceThread(); 362 // Seq #12 363 if (mService.isControlEnabled() && !mService.isProhibitMode() 364 && mService.isPowerOnOrTransient()) { 365 mService.standby(); 366 return true; 367 } 368 return false; 369 } 370 371 @ServiceThreadOnly 372 protected boolean handleUserControlPressed(HdmiCecMessage message) { 373 assertRunOnServiceThread(); 374 if (mService.isPowerOnOrTransient() && isPowerOffOrToggleCommand(message)) { 375 mService.standby(); 376 return true; 377 } else if (mService.isPowerStandbyOrTransient() && isPowerOnOrToggleCommand(message)) { 378 mService.wakeUp(); 379 return true; 380 } 381 return false; 382 } 383 384 private static boolean isPowerOnOrToggleCommand(HdmiCecMessage message) { 385 byte[] params = message.getParams(); 386 return message.getOpcode() == Constants.MESSAGE_USER_CONTROL_PRESSED 387 && (params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER 388 || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_ON_FUNCTION 389 || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_TOGGLE_FUNCTION); 390 } 391 392 private static boolean isPowerOffOrToggleCommand(HdmiCecMessage message) { 393 byte[] params = message.getParams(); 394 return message.getOpcode() == Constants.MESSAGE_USER_CONTROL_PRESSED 395 && (params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER 396 || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_OFF_FUNCTION 397 || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_TOGGLE_FUNCTION); 398 } 399 400 protected boolean handleTextViewOn(HdmiCecMessage message) { 401 return false; 402 } 403 404 protected boolean handleImageViewOn(HdmiCecMessage message) { 405 return false; 406 } 407 408 protected boolean handleSetStreamPath(HdmiCecMessage message) { 409 return false; 410 } 411 412 protected boolean handleGiveDevicePowerStatus(HdmiCecMessage message) { 413 mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPowerStatus( 414 mAddress, message.getSource(), mService.getPowerStatus())); 415 return true; 416 } 417 418 protected boolean handleVendorCommand(HdmiCecMessage message) { 419 mService.invokeVendorCommandListeners(mDeviceType, message.getSource(), 420 message.getParams(), false); 421 return true; 422 } 423 424 protected boolean handleVendorCommandWithId(HdmiCecMessage message) { 425 byte[] params = message.getParams(); 426 int vendorId = HdmiUtils.threeBytesToInt(params); 427 if (vendorId == mService.getVendorId()) { 428 mService.invokeVendorCommandListeners(mDeviceType, message.getSource(), params, true); 429 } else if (message.getDestination() != Constants.ADDR_BROADCAST && 430 message.getSource() != Constants.ADDR_UNREGISTERED) { 431 Slog.v(TAG, "Wrong direct vendor command. Replying with <Feature Abort>"); 432 mService.sendCecCommand(HdmiCecMessageBuilder.buildFeatureAbortCommand(mAddress, 433 message.getSource(), Constants.MESSAGE_VENDOR_COMMAND_WITH_ID, 434 Constants.ABORT_UNRECOGNIZED_MODE)); 435 } else { 436 Slog.v(TAG, "Wrong broadcast vendor command. Ignoring"); 437 } 438 return true; 439 } 440 441 protected boolean handleSetOsdName(HdmiCecMessage message) { 442 // The default behavior of <Set Osd Name> is doing nothing. 443 return true; 444 } 445 446 protected boolean handleRecordTvScreen(HdmiCecMessage message) { 447 // The default behavior of <Record TV Screen> is replying <Feature Abort> with "Refused". 448 mService.sendCecCommand(HdmiCecMessageBuilder.buildFeatureAbortCommand(mAddress, 449 message.getSource(), message.getOpcode(), Constants.ABORT_REFUSED)); 450 return true; 451 } 452 453 @ServiceThreadOnly 454 final void handleAddressAllocated(int logicalAddress, boolean fromBootup) { 455 assertRunOnServiceThread(); 456 mAddress = mPreferredAddress = logicalAddress; 457 onAddressAllocated(logicalAddress, fromBootup); 458 setPreferredAddress(logicalAddress); 459 } 460 461 @ServiceThreadOnly 462 HdmiCecDeviceInfo getDeviceInfo() { 463 assertRunOnServiceThread(); 464 return mDeviceInfo; 465 } 466 467 @ServiceThreadOnly 468 void setDeviceInfo(HdmiCecDeviceInfo info) { 469 assertRunOnServiceThread(); 470 mDeviceInfo = info; 471 } 472 473 // Returns true if the logical address is same as the argument. 474 @ServiceThreadOnly 475 boolean isAddressOf(int addr) { 476 assertRunOnServiceThread(); 477 return addr == mAddress; 478 } 479 480 // Resets the logical address to unregistered(15), meaning the logical device is invalid. 481 @ServiceThreadOnly 482 void clearAddress() { 483 assertRunOnServiceThread(); 484 mAddress = Constants.ADDR_UNREGISTERED; 485 } 486 487 @ServiceThreadOnly 488 void addAndStartAction(final FeatureAction action) { 489 assertRunOnServiceThread(); 490 if (mService.isPowerStandbyOrTransient()) { 491 Slog.w(TAG, "Skip the action during Standby: " + action); 492 return; 493 } 494 mActions.add(action); 495 action.start(); 496 } 497 498 // See if we have an action of a given type in progress. 499 @ServiceThreadOnly 500 <T extends FeatureAction> boolean hasAction(final Class<T> clazz) { 501 assertRunOnServiceThread(); 502 for (FeatureAction action : mActions) { 503 if (action.getClass().equals(clazz)) { 504 return true; 505 } 506 } 507 return false; 508 } 509 510 // Returns all actions matched with given class type. 511 @ServiceThreadOnly 512 <T extends FeatureAction> List<T> getActions(final Class<T> clazz) { 513 assertRunOnServiceThread(); 514 List<T> actions = Collections.<T>emptyList(); 515 for (FeatureAction action : mActions) { 516 if (action.getClass().equals(clazz)) { 517 if (actions.isEmpty()) { 518 actions = new ArrayList<T>(); 519 } 520 actions.add((T) action); 521 } 522 } 523 return actions; 524 } 525 526 /** 527 * Remove the given {@link FeatureAction} object from the action queue. 528 * 529 * @param action {@link FeatureAction} to remove 530 */ 531 @ServiceThreadOnly 532 void removeAction(final FeatureAction action) { 533 assertRunOnServiceThread(); 534 action.finish(false); 535 mActions.remove(action); 536 checkIfPendingActionsCleared(); 537 } 538 539 // Remove all actions matched with the given Class type. 540 @ServiceThreadOnly 541 <T extends FeatureAction> void removeAction(final Class<T> clazz) { 542 assertRunOnServiceThread(); 543 removeActionExcept(clazz, null); 544 } 545 546 // Remove all actions matched with the given Class type besides |exception|. 547 @ServiceThreadOnly 548 <T extends FeatureAction> void removeActionExcept(final Class<T> clazz, 549 final FeatureAction exception) { 550 assertRunOnServiceThread(); 551 Iterator<FeatureAction> iter = mActions.iterator(); 552 while (iter.hasNext()) { 553 FeatureAction action = iter.next(); 554 if (action != exception && action.getClass().equals(clazz)) { 555 action.finish(false); 556 iter.remove(); 557 } 558 } 559 checkIfPendingActionsCleared(); 560 } 561 562 protected void checkIfPendingActionsCleared() { 563 if (mActions.isEmpty() && mPendingActionClearedCallback != null) { 564 PendingActionClearedCallback callback = mPendingActionClearedCallback; 565 // To prevent from calling the callback again during handling the callback itself. 566 mPendingActionClearedCallback = null; 567 callback.onCleared(this); 568 } 569 } 570 571 protected void assertRunOnServiceThread() { 572 if (Looper.myLooper() != mService.getServiceLooper()) { 573 throw new IllegalStateException("Should run on service thread."); 574 } 575 } 576 577 /** 578 * Called when a hot-plug event issued. 579 * 580 * @param portId id of port where a hot-plug event happened 581 * @param connected whether to connected or not on the event 582 */ 583 void onHotplug(int portId, boolean connected) { 584 } 585 586 final HdmiControlService getService() { 587 return mService; 588 } 589 590 @ServiceThreadOnly 591 final boolean isConnectedToArcPort(int path) { 592 assertRunOnServiceThread(); 593 return mService.isConnectedToArcPort(path); 594 } 595 596 ActiveSource getActiveSource() { 597 synchronized (mLock) { 598 return mActiveSource; 599 } 600 } 601 602 void setActiveSource(ActiveSource newActive) { 603 setActiveSource(newActive.logicalAddress, newActive.physicalAddress); 604 } 605 606 void setActiveSource(HdmiCecDeviceInfo info) { 607 setActiveSource(info.getLogicalAddress(), info.getPhysicalAddress()); 608 } 609 610 void setActiveSource(int logicalAddress, int physicalAddress) { 611 synchronized (mLock) { 612 mActiveSource.logicalAddress = logicalAddress; 613 mActiveSource.physicalAddress = physicalAddress; 614 } 615 } 616 617 int getActivePath() { 618 synchronized (mLock) { 619 return mActiveRoutingPath; 620 } 621 } 622 623 void setActivePath(int path) { 624 synchronized (mLock) { 625 mActiveRoutingPath = path; 626 } 627 } 628 629 /** 630 * Returns the ID of the active HDMI port. The active port is the one that has the active 631 * routing path connected to it directly or indirectly under the device hierarchy. 632 */ 633 int getActivePortId() { 634 synchronized (mLock) { 635 return mService.pathToPortId(mActiveRoutingPath); 636 } 637 } 638 639 /** 640 * Update the active port. 641 * 642 * @param portId the new active port id 643 */ 644 void setActivePortId(int portId) { 645 synchronized (mLock) { 646 // We update active routing path instead, since we get the active port id from 647 // the active routing path. 648 mActiveRoutingPath = mService.portIdToPath(portId); 649 } 650 } 651 652 @ServiceThreadOnly 653 HdmiCecMessageCache getCecMessageCache() { 654 assertRunOnServiceThread(); 655 return mCecMessageCache; 656 } 657 658 @ServiceThreadOnly 659 int pathToPortId(int newPath) { 660 assertRunOnServiceThread(); 661 return mService.pathToPortId(newPath); 662 } 663 664 /** 665 * Called when the system goes to standby mode. 666 * 667 * @param initiatedByCec true if this power sequence is initiated 668 * by the reception the CEC messages like <Standby> 669 */ 670 protected void onStandby(boolean initiatedByCec) {} 671 672 /** 673 * Disable device. {@code callback} is used to get notified when all pending 674 * actions are completed or timeout is issued. 675 * 676 * @param initiatedByCec true if this sequence is initiated 677 * by the reception the CEC messages like <Standby> 678 * @param origialCallback callback interface to get notified when all pending actions are 679 * cleared 680 */ 681 protected void disableDevice(boolean initiatedByCec, 682 final PendingActionClearedCallback origialCallback) { 683 mPendingActionClearedCallback = new PendingActionClearedCallback() { 684 @Override 685 public void onCleared(HdmiCecLocalDevice device) { 686 mHandler.removeMessages(MSG_DISABLE_DEVICE_TIMEOUT); 687 origialCallback.onCleared(device); 688 } 689 }; 690 mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_DISABLE_DEVICE_TIMEOUT), 691 DEVICE_CLEANUP_TIMEOUT); 692 } 693 694 @ServiceThreadOnly 695 private void handleDisableDeviceTimeout() { 696 assertRunOnServiceThread(); 697 698 // If all actions are not cleared in DEVICE_CLEANUP_TIMEOUT, enforce to finish them. 699 // onCleard will be called at the last action's finish method. 700 Iterator<FeatureAction> iter = mActions.iterator(); 701 while (iter.hasNext()) { 702 FeatureAction action = iter.next(); 703 action.finish(false); 704 iter.remove(); 705 } 706 } 707 708 /** 709 * Send a key event to other device. 710 * 711 * @param keyCode key code defined in {@link android.view.KeyEvent} 712 * @param isPressed {@code true} for key down event 713 */ 714 protected void sendKeyEvent(int keyCode, boolean isPressed) { 715 Slog.w(TAG, "sendKeyEvent not implemented"); 716 } 717} 718