RequestArcAction.java revision 63a2e0696ce2a04fbe0f1f00cfe9c93189f944da
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.HdmiCec; 20import android.hardware.hdmi.HdmiCecMessage; 21import android.util.Slog; 22 23/** 24 * Base feature action class for <Request ARC Initiation>/<Request ARC Termination>. 25 */ 26abstract class RequestArcAction extends FeatureAction { 27 private static final String TAG = "RequestArcAction"; 28 29 // State in which waits for ARC response. 30 protected static final int STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE = 1; 31 32 // Logical address of AV Receiver. 33 protected final int mAvrAddress; 34 35 /** 36 * @Constructor 37 * 38 * @param service {@link HdmiControlService} instance 39 * @param sourceAddress logical address to be used as source address. It should 40 * TV type 41 * @param avrAddress address of AV receiver. It should be AUDIO_SYSTEM type 42 * @throw IllegalArugmentException if device type of sourceAddress and avrAddress 43 * is invalid 44 */ 45 RequestArcAction(HdmiControlService service, int sourceAddress, int avrAddress) { 46 super(service, sourceAddress); 47 HdmiUtils.verifyAddressType(sourceAddress, HdmiCec.DEVICE_TV); 48 HdmiUtils.verifyAddressType(avrAddress, HdmiCec.DEVICE_AUDIO_SYSTEM); 49 mAvrAddress = avrAddress; 50 } 51 52 @Override 53 boolean processCommand(HdmiCecMessage cmd) { 54 if (mState != STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE 55 || !HdmiUtils.checkCommandSource(cmd, mAvrAddress, TAG)) { 56 return false; 57 } 58 int opcode = cmd.getOpcode(); 59 switch (opcode) { 60 // Handles only <Feature Abort> here and, both <Initiate ARC> and <Terminate ARC> 61 // are handled in HdmiControlService itself because both can be 62 // received wihtout <Request ARC Initiation> or <Request ARC Termination>. 63 case HdmiCec.MESSAGE_FEATURE_ABORT: 64 disableArcTransmission(); 65 finish(); 66 return true; 67 default: 68 Slog.w(TAG, "Unsupported opcode:" + cmd.toString()); 69 } 70 return false; 71 } 72 73 protected final void disableArcTransmission() { 74 // Start Set ARC Transmission State action. 75 SetArcTransmissionStateAction action = new SetArcTransmissionStateAction(mService, 76 mSourceAddress, mAvrAddress, false); 77 mService.addAndStartAction(action); 78 } 79 80 @Override 81 final void handleTimerEvent(int state) { 82 if (mState != state || state != STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE) { 83 return; 84 } 85 disableArcTransmission(); 86 finish(); 87 } 88} 89