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