blob: 75a79cb0213c6ff2c2b2255043ff9d9274274a90 [file] [log] [blame]
Jungshik Jang67ea5212014-05-15 14:05:24 +09001/*
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
Jungshik Jang61f4fbd2014-08-06 19:21:12 +090019import android.hardware.hdmi.HdmiDeviceInfo;
Jungshik Jang67ea5212014-05-15 14:05:24 +090020
21/**
22 * Base feature action class for <Request ARC Initiation>/<Request ARC Termination>.
23 */
Jungshik Jangb509c2e2014-08-07 13:45:01 +090024abstract class RequestArcAction extends HdmiCecFeatureAction {
Jungshik Jang67ea5212014-05-15 14:05:24 +090025 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 Jang79c58a42014-06-16 16:45:36 +090036 * @param source {@link HdmiCecLocalDevice} instance
Jungshik Jang67ea5212014-05-15 14:05:24 +090037 * @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 Jang79c58a42014-06-16 16:45:36 +090041 RequestArcAction(HdmiCecLocalDevice source, int avrAddress) {
42 super(source);
Jungshik Jang61f4fbd2014-08-06 19:21:12 +090043 HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV);
44 HdmiUtils.verifyAddressType(avrAddress, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
Jungshik Jang67ea5212014-05-15 14:05:24 +090045 mAvrAddress = avrAddress;
46 }
47
Jungshik Jang67ea5212014-05-15 14:05:24 +090048 @Override
49 boolean processCommand(HdmiCecMessage cmd) {
Yuncheol Heo63a2e062014-05-27 23:06:01 +090050 if (mState != STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE
51 || !HdmiUtils.checkCommandSource(cmd, mAvrAddress, TAG)) {
Jungshik Jang67ea5212014-05-15 14:05:24 +090052 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 Jang339227d2014-08-25 15:37:20 +090058 // received without <Request ARC Initiation> or <Request ARC Termination>.
Jinsuk Kimc0c20d02014-07-04 14:34:31 +090059 case Constants.MESSAGE_FEATURE_ABORT:
Jungshik Jang339227d2014-08-25 15:37:20 +090060 int originalOpcode = cmd.getParams()[0] & 0xFF;
Jinsuk Kim71651d32015-03-27 08:21:15 +090061 if (originalOpcode == Constants.MESSAGE_REQUEST_ARC_TERMINATION) {
Jungshik Jang339227d2014-08-25 15:37:20 +090062 disableArcTransmission();
63 finish();
64 return true;
Jinsuk Kim71651d32015-03-27 08:21:15 +090065 } else if (originalOpcode == Constants.MESSAGE_REQUEST_ARC_INITIATION) {
66 tv().setArcStatus(false);
67 finish();
68 return true;
Jungshik Jang339227d2014-08-25 15:37:20 +090069 }
Jinsuk Kim71651d32015-03-27 08:21:15 +090070 return false;
Jungshik Jang67ea5212014-05-15 14:05:24 +090071 }
72 return false;
73 }
74
75 protected final void disableArcTransmission() {
76 // Start Set ARC Transmission State action.
Jungshik Jang79c58a42014-06-16 16:45:36 +090077 SetArcTransmissionStateAction action = new SetArcTransmissionStateAction(localDevice(),
78 mAvrAddress, false);
79 addAndStartAction(action);
Jungshik Jang67ea5212014-05-15 14:05:24 +090080 }
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 Kim71651d32015-03-27 08:21:15 +090087 HdmiLogger.debug("[T] RequestArcAction.");
Jungshik Jang67ea5212014-05-15 14:05:24 +090088 disableArcTransmission();
Jungshik Jang358164c2014-05-21 18:25:47 +090089 finish();
Jungshik Jang67ea5212014-05-15 14:05:24 +090090 }
91}