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