Home | History | Annotate | Download | only in hdmi
      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 
     19 import android.hardware.hdmi.HdmiDeviceInfo;
     20 
     21 /**
     22  * Base feature action class for <Request ARC Initiation>/<Request ARC Termination>.
     23  */
     24 abstract class RequestArcAction extends HdmiCecFeatureAction {
     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      *
     36      * @param source {@link HdmiCecLocalDevice} instance
     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      */
     41     RequestArcAction(HdmiCecLocalDevice source, int avrAddress) {
     42         super(source);
     43         HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV);
     44         HdmiUtils.verifyAddressType(avrAddress, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
     45         mAvrAddress = avrAddress;
     46     }
     47 
     48     @Override
     49     boolean processCommand(HdmiCecMessage cmd) {
     50         if (mState != STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE
     51                 || !HdmiUtils.checkCommandSource(cmd, mAvrAddress, TAG)) {
     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
     58             // received without <Request ARC Initiation> or <Request ARC Termination>.
     59             case Constants.MESSAGE_FEATURE_ABORT:
     60                 int originalOpcode = cmd.getParams()[0] & 0xFF;
     61                 if (originalOpcode == Constants.MESSAGE_REQUEST_ARC_TERMINATION) {
     62                     disableArcTransmission();
     63                     finish();
     64                     return true;
     65                 } else if (originalOpcode == Constants.MESSAGE_REQUEST_ARC_INITIATION) {
     66                     tv().setArcStatus(false);
     67                     finish();
     68                     return true;
     69                 }
     70                 return false;
     71         }
     72         return false;
     73     }
     74 
     75     protected final void disableArcTransmission() {
     76         // Start Set ARC Transmission State action.
     77         SetArcTransmissionStateAction action = new SetArcTransmissionStateAction(localDevice(),
     78                 mAvrAddress, false);
     79         addAndStartAction(action);
     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         }
     87         HdmiLogger.debug("[T] RequestArcAction.");
     88         disableArcTransmission();
     89         finish();
     90     }
     91 }
     92