Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +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 | |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 19 | import android.hardware.hdmi.HdmiDeviceInfo; |
Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +0900 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Base feature action class for <Request ARC Initiation>/<Request ARC Termination>. |
| 23 | */ |
Jungshik Jang | b509c2e | 2014-08-07 13:45:01 +0900 | [diff] [blame] | 24 | abstract class RequestArcAction extends HdmiCecFeatureAction { |
Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +0900 | [diff] [blame] | 25 | private static final String TAG = "RequestArcAction"; |
| 26 | |
| 27 | // State in which waits for ARC response. |
| 28 | protected static final int STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE = 1; |
| 29 | |
| 30 | // Logical address of AV Receiver. |
| 31 | protected final int mAvrAddress; |
| 32 | |
| 33 | /** |
| 34 | * @Constructor |
| 35 | * |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 36 | * @param source {@link HdmiCecLocalDevice} instance |
Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +0900 | [diff] [blame] | 37 | * @param avrAddress address of AV receiver. It should be AUDIO_SYSTEM type |
| 38 | * @throw IllegalArugmentException if device type of sourceAddress and avrAddress |
| 39 | * is invalid |
| 40 | */ |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 41 | RequestArcAction(HdmiCecLocalDevice source, int avrAddress) { |
| 42 | super(source); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 43 | HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV); |
| 44 | HdmiUtils.verifyAddressType(avrAddress, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM); |
Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +0900 | [diff] [blame] | 45 | mAvrAddress = avrAddress; |
| 46 | } |
| 47 | |
Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +0900 | [diff] [blame] | 48 | @Override |
| 49 | boolean processCommand(HdmiCecMessage cmd) { |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 50 | if (mState != STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE |
| 51 | || !HdmiUtils.checkCommandSource(cmd, mAvrAddress, TAG)) { |
Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +0900 | [diff] [blame] | 52 | return false; |
| 53 | } |
| 54 | int opcode = cmd.getOpcode(); |
| 55 | switch (opcode) { |
| 56 | // Handles only <Feature Abort> here and, both <Initiate ARC> and <Terminate ARC> |
| 57 | // are handled in HdmiControlService itself because both can be |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 58 | // received without <Request ARC Initiation> or <Request ARC Termination>. |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 59 | case Constants.MESSAGE_FEATURE_ABORT: |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 60 | int originalOpcode = cmd.getParams()[0] & 0xFF; |
Jinsuk Kim | 71651d3 | 2015-03-27 08:21:15 +0900 | [diff] [blame] | 61 | if (originalOpcode == Constants.MESSAGE_REQUEST_ARC_TERMINATION) { |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 62 | disableArcTransmission(); |
| 63 | finish(); |
| 64 | return true; |
Jinsuk Kim | 71651d3 | 2015-03-27 08:21:15 +0900 | [diff] [blame] | 65 | } else if (originalOpcode == Constants.MESSAGE_REQUEST_ARC_INITIATION) { |
| 66 | tv().setArcStatus(false); |
| 67 | finish(); |
| 68 | return true; |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 69 | } |
Jinsuk Kim | 71651d3 | 2015-03-27 08:21:15 +0900 | [diff] [blame] | 70 | return false; |
Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +0900 | [diff] [blame] | 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | protected final void disableArcTransmission() { |
| 76 | // Start Set ARC Transmission State action. |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 77 | SetArcTransmissionStateAction action = new SetArcTransmissionStateAction(localDevice(), |
| 78 | mAvrAddress, false); |
| 79 | addAndStartAction(action); |
Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +0900 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | final void handleTimerEvent(int state) { |
| 84 | if (mState != state || state != STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE) { |
| 85 | return; |
| 86 | } |
Jinsuk Kim | 71651d3 | 2015-03-27 08:21:15 +0900 | [diff] [blame] | 87 | HdmiLogger.debug("[T] RequestArcAction."); |
Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +0900 | [diff] [blame] | 88 | disableArcTransmission(); |
Jungshik Jang | 358164c | 2014-05-21 18:25:47 +0900 | [diff] [blame] | 89 | finish(); |
Jungshik Jang | 67ea521 | 2014-05-15 14:05:24 +0900 | [diff] [blame] | 90 | } |
| 91 | } |