RequestArcInitiationAction.java revision d643f764f72efc1e7aa67392bf9ac40720ae14c3
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.HdmiCecMessage;
20import android.util.Slog;
21
22/**
23 * Feature action that handles ARC action initiated by TV devices.
24 *
25 * <p>This action is created by TV's hot plug event of ARC port.
26 */
27final class RequestArcInitiationAction extends RequestArcAction {
28    private static final String TAG = "RequestArcInitiationAction";
29
30    /**
31     * @Constructor
32     *
33     * For more details look at {@link RequestArcAction#RequestArcAction}.
34     */
35    RequestArcInitiationAction(HdmiControlService service, int sourceAddress, int avrAddress) {
36        super(service, sourceAddress, avrAddress);
37    }
38
39    @Override
40    boolean start() {
41        HdmiCecMessage command = HdmiCecMessageBuilder.buildRequestArcInitiation(mSourceAddress,
42                mAvrAddress);
43        sendCommand(command, new HdmiControlService.SendMessageCallback() {
44            @Override
45            public void onSendCompleted(int error) {
46                // success.
47                if (error == 0) {
48                    mState = STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE;
49                    addTimer(mState, TIMEOUT_MS);
50                } else {
51                    Slog.w(TAG, "Failed to send <Request ARC Initiation>");
52                    // If failed to send <Request ARC Initiation>, start "Disabled"
53                    // ARC transmission action.
54                    disableArcTransmission();
55                    finish();
56                }
57            }
58        });
59        return true;
60    }
61}
62