SystemAudioActionFromAvr.java revision ea67c183fe5511ad99aeaae1a32b5245bd020e36
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.IHdmiControlCallback; 21 22/** 23 * Feature action that handles System Audio initiated by AVR devices. 24 */ 25final class SystemAudioActionFromAvr extends SystemAudioAction { 26 /** 27 * Constructor 28 * 29 * @param source {@link HdmiCecLocalDevice} instance 30 * @param avrAddress logical address of AVR device 31 * @param targetStatus Whether to enable the system audio mode or not 32 * @param callback callback interface to be notified when it's done 33 * @throw IllegalArugmentException if device type of tvAddress and avrAddress is invalid 34 */ 35 SystemAudioActionFromAvr(HdmiCecLocalDevice source, int avrAddress, 36 boolean targetStatus, IHdmiControlCallback callback) { 37 super(source, avrAddress, targetStatus, callback); 38 HdmiUtils.verifyAddressType(getSourceAddress(), HdmiCec.DEVICE_TV); 39 } 40 41 @Override 42 boolean start() { 43 removeSystemAudioActionInProgress(); 44 handleSystemAudioActionFromAvr(); 45 return true; 46 } 47 48 private void handleSystemAudioActionFromAvr() { 49 if (mTargetAudioStatus == tv().getSystemAudioMode()) { 50 finishWithCallback(HdmiCec.RESULT_SUCCESS); 51 return; 52 } 53 if (tv().isInPresetInstallationMode()) { 54 sendCommand(HdmiCecMessageBuilder.buildFeatureAbortCommand( 55 getSourceAddress(), mAvrLogicalAddress, 56 HdmiCec.MESSAGE_SET_SYSTEM_AUDIO_MODE, HdmiConstants.ABORT_REFUSED)); 57 mTargetAudioStatus = false; 58 sendSystemAudioModeRequest(); 59 return; 60 } 61 // TODO: Stop the action for System Audio Mode initialization if it is running. 62 if (mTargetAudioStatus) { 63 setSystemAudioMode(true); 64 startAudioStatusAction(); 65 } else { 66 setSystemAudioMode(false); 67 finishWithCallback(HdmiCec.RESULT_SUCCESS); 68 } 69 } 70} 71