blob: eb5119b8a233cb59afb032d835575a18b8c6afe1 [file] [log] [blame]
Yuncheol Heo63a2e062014-05-27 23:06:01 +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;
Jinsuk Kimc0c20d02014-07-04 14:34:31 +090020import android.hardware.hdmi.HdmiControlManager;
Jungshik Jangea67c182014-06-19 22:19:20 +090021import android.hardware.hdmi.IHdmiControlCallback;
Yuncheol Heo63a2e062014-05-27 23:06:01 +090022
23/**
24 * Feature action that handles System Audio initiated by AVR devices.
25 */
Yuncheol Heoc516d652014-07-11 18:23:24 +090026// Seq #33
Yuncheol Heo63a2e062014-05-27 23:06:01 +090027final class SystemAudioActionFromAvr extends SystemAudioAction {
28 /**
29 * Constructor
30 *
Jungshik Jang79c58a42014-06-16 16:45:36 +090031 * @param source {@link HdmiCecLocalDevice} instance
Yuncheol Heo63a2e062014-05-27 23:06:01 +090032 * @param avrAddress logical address of AVR device
33 * @param targetStatus Whether to enable the system audio mode or not
Jungshik Jangea67c182014-06-19 22:19:20 +090034 * @param callback callback interface to be notified when it's done
Yuncheol Heo63a2e062014-05-27 23:06:01 +090035 * @throw IllegalArugmentException if device type of tvAddress and avrAddress is invalid
36 */
Jungshik Jang79c58a42014-06-16 16:45:36 +090037 SystemAudioActionFromAvr(HdmiCecLocalDevice source, int avrAddress,
Jungshik Jangea67c182014-06-19 22:19:20 +090038 boolean targetStatus, IHdmiControlCallback callback) {
39 super(source, avrAddress, targetStatus, callback);
Jungshik Jang61f4fbd2014-08-06 19:21:12 +090040 HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV);
Yuncheol Heo63a2e062014-05-27 23:06:01 +090041 }
42
43 @Override
44 boolean start() {
45 removeSystemAudioActionInProgress();
46 handleSystemAudioActionFromAvr();
47 return true;
48 }
49
50 private void handleSystemAudioActionFromAvr() {
Jungshik Jang377dcbd2014-07-15 15:49:02 +090051 if (mTargetAudioStatus == tv().isSystemAudioActivated()) {
Jinsuk Kimc0c20d02014-07-04 14:34:31 +090052 finishWithCallback(HdmiControlManager.RESULT_SUCCESS);
Yuncheol Heo63a2e062014-05-27 23:06:01 +090053 return;
54 }
Jinsuk Kim4d43d932014-07-03 16:43:58 +090055 if (tv().isProhibitMode()) {
Yuncheol Heo63a2e062014-05-27 23:06:01 +090056 sendCommand(HdmiCecMessageBuilder.buildFeatureAbortCommand(
Jungshik Jang79c58a42014-06-16 16:45:36 +090057 getSourceAddress(), mAvrLogicalAddress,
Jinsuk Kimc0c20d02014-07-04 14:34:31 +090058 Constants.MESSAGE_SET_SYSTEM_AUDIO_MODE, Constants.ABORT_REFUSED));
Yuncheol Heo63a2e062014-05-27 23:06:01 +090059 mTargetAudioStatus = false;
60 sendSystemAudioModeRequest();
61 return;
62 }
Jungshik Jangca5be9a2014-07-01 18:01:26 +090063
64 removeAction(SystemAudioAutoInitiationAction.class);
65
Yuncheol Heo63a2e062014-05-27 23:06:01 +090066 if (mTargetAudioStatus) {
67 setSystemAudioMode(true);
Jungshik Jang16321b82014-06-19 19:39:27 +090068 startAudioStatusAction();
Yuncheol Heo63a2e062014-05-27 23:06:01 +090069 } else {
70 setSystemAudioMode(false);
Jinsuk Kimc0c20d02014-07-04 14:34:31 +090071 finishWithCallback(HdmiControlManager.RESULT_SUCCESS);
Yuncheol Heo63a2e062014-05-27 23:06:01 +090072 }
73 }
74}