HdmiCecLocalDevice.java revision 61f4fbd2e8436a1ecd478c2a1f516d064a24d43b
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.HdmiDeviceInfo; 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 HdmiDeviceInfo 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 HdmiDeviceInfo.DEVICE_TV: 139 return new HdmiCecLocalDeviceTv(service); 140 case HdmiDeviceInfo.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, int reason); 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 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 case Constants.MESSAGE_TIMER_CLEARED_STATUS: 244 return handleTimerClearedStatus(message); 245 default: 246 return false; 247 } 248 } 249 250 @ServiceThreadOnly 251 private boolean dispatchMessageToAction(HdmiCecMessage message) { 252 assertRunOnServiceThread(); 253 for (FeatureAction action : mActions) { 254 if (action.processCommand(message)) { 255 return true; 256 } 257 } 258 return false; 259 } 260 261 @ServiceThreadOnly 262 protected boolean handleGivePhysicalAddress() { 263 assertRunOnServiceThread(); 264 265 int physicalAddress = mService.getPhysicalAddress(); 266 HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( 267 mAddress, physicalAddress, mDeviceType); 268 mService.sendCecCommand(cecMessage); 269 return true; 270 } 271 272 @ServiceThreadOnly 273 protected boolean handleGiveDeviceVendorId() { 274 assertRunOnServiceThread(); 275 int vendorId = mService.getVendorId(); 276 HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildDeviceVendorIdCommand( 277 mAddress, vendorId); 278 mService.sendCecCommand(cecMessage); 279 return true; 280 } 281 282 @ServiceThreadOnly 283 protected boolean handleGetCecVersion(HdmiCecMessage message) { 284 assertRunOnServiceThread(); 285 int version = mService.getCecVersion(); 286 HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildCecVersion(message.getDestination(), 287 message.getSource(), version); 288 mService.sendCecCommand(cecMessage); 289 return true; 290 } 291 292 @ServiceThreadOnly 293 protected boolean handleActiveSource(HdmiCecMessage message) { 294 return false; 295 } 296 297 @ServiceThreadOnly 298 protected boolean handleInactiveSource(HdmiCecMessage message) { 299 return false; 300 } 301 302 @ServiceThreadOnly 303 protected boolean handleRequestActiveSource(HdmiCecMessage message) { 304 return false; 305 } 306 307 @ServiceThreadOnly 308 protected boolean handleGetMenuLanguage(HdmiCecMessage message) { 309 assertRunOnServiceThread(); 310 Slog.w(TAG, "Only TV can handle <Get Menu Language>:" + message.toString()); 311 // 'return false' will cause to reply with <Feature Abort>. 312 return false; 313 } 314 315 @ServiceThreadOnly 316 protected boolean handleGiveOsdName(HdmiCecMessage message) { 317 assertRunOnServiceThread(); 318 // Note that since this method is called after logical address allocation is done, 319 // mDeviceInfo should not be null. 320 HdmiCecMessage cecMessage = HdmiCecMessageBuilder.buildSetOsdNameCommand( 321 mAddress, message.getSource(), mDeviceInfo.getDisplayName()); 322 if (cecMessage != null) { 323 mService.sendCecCommand(cecMessage); 324 } else { 325 Slog.w(TAG, "Failed to build <Get Osd Name>:" + mDeviceInfo.getDisplayName()); 326 } 327 return true; 328 } 329 330 protected boolean handleRoutingChange(HdmiCecMessage message) { 331 return false; 332 } 333 334 protected boolean handleReportPhysicalAddress(HdmiCecMessage message) { 335 return false; 336 } 337 338 protected boolean handleSystemAudioModeStatus(HdmiCecMessage message) { 339 return false; 340 } 341 342 protected boolean handleSetSystemAudioMode(HdmiCecMessage message) { 343 return false; 344 } 345 346 protected boolean handleTerminateArc(HdmiCecMessage message) { 347 return false; 348 } 349 350 protected boolean handleInitiateArc(HdmiCecMessage message) { 351 return false; 352 } 353 354 protected boolean handleReportAudioStatus(HdmiCecMessage message) { 355 return false; 356 } 357 358 @ServiceThreadOnly 359 protected boolean handleStandby(HdmiCecMessage message) { 360 assertRunOnServiceThread(); 361 // Seq #12 362 if (mService.isControlEnabled() && !mService.isProhibitMode() 363 && mService.isPowerOnOrTransient()) { 364 mService.standby(); 365 return true; 366 } 367 return false; 368 } 369 370 @ServiceThreadOnly 371 protected boolean handleUserControlPressed(HdmiCecMessage message) { 372 assertRunOnServiceThread(); 373 if (mService.isPowerOnOrTransient() && isPowerOffOrToggleCommand(message)) { 374 mService.standby(); 375 return true; 376 } else if (mService.isPowerStandbyOrTransient() && isPowerOnOrToggleCommand(message)) { 377 mService.wakeUp(); 378 return true; 379 } 380 return false; 381 } 382 383 static boolean isPowerOnOrToggleCommand(HdmiCecMessage message) { 384 byte[] params = message.getParams(); 385 return message.getOpcode() == Constants.MESSAGE_USER_CONTROL_PRESSED 386 && (params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER 387 || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_ON_FUNCTION 388 || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_TOGGLE_FUNCTION); 389 } 390 391 static boolean isPowerOffOrToggleCommand(HdmiCecMessage message) { 392 byte[] params = message.getParams(); 393 return message.getOpcode() == Constants.MESSAGE_USER_CONTROL_PRESSED 394 && (params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER 395 || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_OFF_FUNCTION 396 || params[0] == HdmiCecKeycode.CEC_KEYCODE_POWER_TOGGLE_FUNCTION); 397 } 398 399 protected boolean handleTextViewOn(HdmiCecMessage message) { 400 return false; 401 } 402 403 protected boolean handleImageViewOn(HdmiCecMessage message) { 404 return false; 405 } 406 407 protected boolean handleSetStreamPath(HdmiCecMessage message) { 408 return false; 409 } 410 411 protected boolean handleGiveDevicePowerStatus(HdmiCecMessage message) { 412 mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPowerStatus( 413 mAddress, message.getSource(), mService.getPowerStatus())); 414 return true; 415 } 416 417 protected boolean handleVendorCommand(HdmiCecMessage message) { 418 mService.invokeVendorCommandListeners(mDeviceType, message.getSource(), 419 message.getParams(), false); 420 return true; 421 } 422 423 protected boolean handleVendorCommandWithId(HdmiCecMessage message) { 424 byte[] params = message.getParams(); 425 int vendorId = HdmiUtils.threeBytesToInt(params); 426 if (vendorId == mService.getVendorId()) { 427 mService.invokeVendorCommandListeners(mDeviceType, message.getSource(), params, true); 428 } else if (message.getDestination() != Constants.ADDR_BROADCAST && 429 message.getSource() != Constants.ADDR_UNREGISTERED) { 430 Slog.v(TAG, "Wrong direct vendor command. Replying with <Feature Abort>"); 431 mService.maySendFeatureAbortCommand(message, Constants.ABORT_UNRECOGNIZED_OPCODE); 432 } else { 433 Slog.v(TAG, "Wrong broadcast vendor command. Ignoring"); 434 } 435 return true; 436 } 437 438 protected boolean handleSetOsdName(HdmiCecMessage message) { 439 // The default behavior of <Set Osd Name> is doing nothing. 440 return true; 441 } 442 443 protected boolean handleRecordTvScreen(HdmiCecMessage message) { 444 // The default behavior of <Record TV Screen> is replying <Feature Abort> with 445 // "Cannot provide source". 446 mService.maySendFeatureAbortCommand(message, Constants.ABORT_CANNOT_PROVIDE_SOURCE); 447 return true; 448 } 449 450 protected boolean handleTimerClearedStatus(HdmiCecMessage message) { 451 return false; 452 } 453 454 @ServiceThreadOnly 455 final void handleAddressAllocated(int logicalAddress, int reason) { 456 assertRunOnServiceThread(); 457 mAddress = mPreferredAddress = logicalAddress; 458 onAddressAllocated(logicalAddress, reason); 459 setPreferredAddress(logicalAddress); 460 } 461 462 @ServiceThreadOnly 463 HdmiDeviceInfo getDeviceInfo() { 464 assertRunOnServiceThread(); 465 return mDeviceInfo; 466 } 467 468 @ServiceThreadOnly 469 void setDeviceInfo(HdmiDeviceInfo info) { 470 assertRunOnServiceThread(); 471 mDeviceInfo = info; 472 } 473 474 // Returns true if the logical address is same as the argument. 475 @ServiceThreadOnly 476 boolean isAddressOf(int addr) { 477 assertRunOnServiceThread(); 478 return addr == mAddress; 479 } 480 481 // Resets the logical address to unregistered(15), meaning the logical device is invalid. 482 @ServiceThreadOnly 483 void clearAddress() { 484 assertRunOnServiceThread(); 485 mAddress = Constants.ADDR_UNREGISTERED; 486 } 487 488 @ServiceThreadOnly 489 void addAndStartAction(final FeatureAction action) { 490 assertRunOnServiceThread(); 491 if (mService.isPowerStandbyOrTransient()) { 492 Slog.w(TAG, "Skip the action during Standby: " + action); 493 return; 494 } 495 mActions.add(action); 496 action.start(); 497 } 498 499 // See if we have an action of a given type in progress. 500 @ServiceThreadOnly 501 <T extends FeatureAction> boolean hasAction(final Class<T> clazz) { 502 assertRunOnServiceThread(); 503 for (FeatureAction action : mActions) { 504 if (action.getClass().equals(clazz)) { 505 return true; 506 } 507 } 508 return false; 509 } 510 511 // Returns all actions matched with given class type. 512 @ServiceThreadOnly 513 <T extends FeatureAction> List<T> getActions(final Class<T> clazz) { 514 assertRunOnServiceThread(); 515 List<T> actions = Collections.<T>emptyList(); 516 for (FeatureAction action : mActions) { 517 if (action.getClass().equals(clazz)) { 518 if (actions.isEmpty()) { 519 actions = new ArrayList<T>(); 520 } 521 actions.add((T) action); 522 } 523 } 524 return actions; 525 } 526 527 /** 528 * Remove the given {@link FeatureAction} object from the action queue. 529 * 530 * @param action {@link FeatureAction} to remove 531 */ 532 @ServiceThreadOnly 533 void removeAction(final FeatureAction action) { 534 assertRunOnServiceThread(); 535 action.finish(false); 536 mActions.remove(action); 537 checkIfPendingActionsCleared(); 538 } 539 540 // Remove all actions matched with the given Class type. 541 @ServiceThreadOnly 542 <T extends FeatureAction> void removeAction(final Class<T> clazz) { 543 assertRunOnServiceThread(); 544 removeActionExcept(clazz, null); 545 } 546 547 // Remove all actions matched with the given Class type besides |exception|. 548 @ServiceThreadOnly 549 <T extends FeatureAction> void removeActionExcept(final Class<T> clazz, 550 final FeatureAction exception) { 551 assertRunOnServiceThread(); 552 Iterator<FeatureAction> iter = mActions.iterator(); 553 while (iter.hasNext()) { 554 FeatureAction action = iter.next(); 555 if (action != exception && action.getClass().equals(clazz)) { 556 action.finish(false); 557 iter.remove(); 558 } 559 } 560 checkIfPendingActionsCleared(); 561 } 562 563 protected void checkIfPendingActionsCleared() { 564 if (mActions.isEmpty() && mPendingActionClearedCallback != null) { 565 PendingActionClearedCallback callback = mPendingActionClearedCallback; 566 // To prevent from calling the callback again during handling the callback itself. 567 mPendingActionClearedCallback = null; 568 callback.onCleared(this); 569 } 570 } 571 572 protected void assertRunOnServiceThread() { 573 if (Looper.myLooper() != mService.getServiceLooper()) { 574 throw new IllegalStateException("Should run on service thread."); 575 } 576 } 577 578 /** 579 * Called when a hot-plug event issued. 580 * 581 * @param portId id of port where a hot-plug event happened 582 * @param connected whether to connected or not on the event 583 */ 584 void onHotplug(int portId, boolean connected) { 585 } 586 587 final HdmiControlService getService() { 588 return mService; 589 } 590 591 @ServiceThreadOnly 592 final boolean isConnectedToArcPort(int path) { 593 assertRunOnServiceThread(); 594 return mService.isConnectedToArcPort(path); 595 } 596 597 ActiveSource getActiveSource() { 598 synchronized (mLock) { 599 return mActiveSource; 600 } 601 } 602 603 void setActiveSource(ActiveSource newActive) { 604 setActiveSource(newActive.logicalAddress, newActive.physicalAddress); 605 } 606 607 void setActiveSource(HdmiDeviceInfo info) { 608 setActiveSource(info.getLogicalAddress(), info.getPhysicalAddress()); 609 } 610 611 void setActiveSource(int logicalAddress, int physicalAddress) { 612 synchronized (mLock) { 613 mActiveSource.logicalAddress = logicalAddress; 614 mActiveSource.physicalAddress = physicalAddress; 615 } 616 } 617 618 int getActivePath() { 619 synchronized (mLock) { 620 return mActiveRoutingPath; 621 } 622 } 623 624 void setActivePath(int path) { 625 synchronized (mLock) { 626 mActiveRoutingPath = path; 627 } 628 } 629 630 /** 631 * Returns the ID of the active HDMI port. The active port is the one that has the active 632 * routing path connected to it directly or indirectly under the device hierarchy. 633 */ 634 int getActivePortId() { 635 synchronized (mLock) { 636 return mService.pathToPortId(mActiveRoutingPath); 637 } 638 } 639 640 /** 641 * Update the active port. 642 * 643 * @param portId the new active port id 644 */ 645 void setActivePortId(int portId) { 646 synchronized (mLock) { 647 // We update active routing path instead, since we get the active port id from 648 // the active routing path. 649 mActiveRoutingPath = mService.portIdToPath(portId); 650 } 651 } 652 653 @ServiceThreadOnly 654 HdmiCecMessageCache getCecMessageCache() { 655 assertRunOnServiceThread(); 656 return mCecMessageCache; 657 } 658 659 @ServiceThreadOnly 660 int pathToPortId(int newPath) { 661 assertRunOnServiceThread(); 662 return mService.pathToPortId(newPath); 663 } 664 665 /** 666 * Called when the system goes to standby mode. 667 * 668 * @param initiatedByCec true if this power sequence is initiated 669 * by the reception the CEC messages like <Standby> 670 */ 671 protected void onStandby(boolean initiatedByCec) {} 672 673 /** 674 * Disable device. {@code callback} is used to get notified when all pending 675 * actions are completed or timeout is issued. 676 * 677 * @param initiatedByCec true if this sequence is initiated 678 * by the reception the CEC messages like <Standby> 679 * @param origialCallback callback interface to get notified when all pending actions are 680 * cleared 681 */ 682 protected void disableDevice(boolean initiatedByCec, 683 final PendingActionClearedCallback origialCallback) { 684 mPendingActionClearedCallback = new PendingActionClearedCallback() { 685 @Override 686 public void onCleared(HdmiCecLocalDevice device) { 687 mHandler.removeMessages(MSG_DISABLE_DEVICE_TIMEOUT); 688 origialCallback.onCleared(device); 689 } 690 }; 691 mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_DISABLE_DEVICE_TIMEOUT), 692 DEVICE_CLEANUP_TIMEOUT); 693 } 694 695 @ServiceThreadOnly 696 private void handleDisableDeviceTimeout() { 697 assertRunOnServiceThread(); 698 699 // If all actions are not cleared in DEVICE_CLEANUP_TIMEOUT, enforce to finish them. 700 // onCleard will be called at the last action's finish method. 701 Iterator<FeatureAction> iter = mActions.iterator(); 702 while (iter.hasNext()) { 703 FeatureAction action = iter.next(); 704 action.finish(false); 705 iter.remove(); 706 } 707 } 708 709 /** 710 * Send a key event to other device. 711 * 712 * @param keyCode key code defined in {@link android.view.KeyEvent} 713 * @param isPressed {@code true} for key down event 714 */ 715 protected void sendKeyEvent(int keyCode, boolean isPressed) { 716 Slog.w(TAG, "sendKeyEvent not implemented"); 717 } 718} 719