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