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