167ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang/* 267ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * Copyright (C) 2014 The Android Open Source Project 367ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * 467ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * Licensed under the Apache License, Version 2.0 (the "License"); 567ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * you may not use this file except in compliance with the License. 667ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * You may obtain a copy of the License at 767ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * 867ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * http://www.apache.org/licenses/LICENSE-2.0 967ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * 1067ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * Unless required by applicable law or agreed to in writing, software 1167ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * distributed under the License is distributed on an "AS IS" BASIS, 1267ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1367ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * See the License for the specific language governing permissions and 1467ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * limitations under the License. 1567ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang */ 1667ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang 1767ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jangpackage com.android.server.hdmi; 1867ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang 1961f4fbd2e8436a1ecd478c2a1f516d064a24d43bJungshik Jangimport android.hardware.hdmi.HdmiDeviceInfo; 2067ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang 2167ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang/** 2267ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * Base feature action class for <Request ARC Initiation>/<Request ARC Termination>. 2367ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang */ 24b509c2ecd99619248b7a07fb0fa978bb27f25cc3Jungshik Jangabstract class RequestArcAction extends HdmiCecFeatureAction { 2567ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang private static final String TAG = "RequestArcAction"; 2667ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang 2767ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang // State in which waits for ARC response. 2867ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang protected static final int STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE = 1; 2967ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang 3067ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang // Logical address of AV Receiver. 3167ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang protected final int mAvrAddress; 3267ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang 3367ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang /** 3467ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * @Constructor 3567ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * 3679c58a4b97f27ede6a1b680d2fece9c2a0edf7b7Jungshik Jang * @param source {@link HdmiCecLocalDevice} instance 3767ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * @param avrAddress address of AV receiver. It should be AUDIO_SYSTEM type 3867ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * @throw IllegalArugmentException if device type of sourceAddress and avrAddress 3967ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang * is invalid 4067ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang */ 4179c58a4b97f27ede6a1b680d2fece9c2a0edf7b7Jungshik Jang RequestArcAction(HdmiCecLocalDevice source, int avrAddress) { 4279c58a4b97f27ede6a1b680d2fece9c2a0edf7b7Jungshik Jang super(source); 4361f4fbd2e8436a1ecd478c2a1f516d064a24d43bJungshik Jang HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV); 4461f4fbd2e8436a1ecd478c2a1f516d064a24d43bJungshik Jang HdmiUtils.verifyAddressType(avrAddress, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM); 4567ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang mAvrAddress = avrAddress; 4667ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang } 4767ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang 4867ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang @Override 4967ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang boolean processCommand(HdmiCecMessage cmd) { 5063a2e0696ce2a04fbe0f1f00cfe9c93189f944daYuncheol Heo if (mState != STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE 5163a2e0696ce2a04fbe0f1f00cfe9c93189f944daYuncheol Heo || !HdmiUtils.checkCommandSource(cmd, mAvrAddress, TAG)) { 5267ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang return false; 5367ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang } 5467ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang int opcode = cmd.getOpcode(); 5567ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang switch (opcode) { 5667ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang // Handles only <Feature Abort> here and, both <Initiate ARC> and <Terminate ARC> 5767ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang // are handled in HdmiControlService itself because both can be 58339227da7cf025ce4ae0c85ddc52643d63972321Jungshik Jang // received without <Request ARC Initiation> or <Request ARC Termination>. 59c0c20d0522d7756d80f011e7a54bf3b51c78df41Jinsuk Kim case Constants.MESSAGE_FEATURE_ABORT: 60339227da7cf025ce4ae0c85ddc52643d63972321Jungshik Jang int originalOpcode = cmd.getParams()[0] & 0xFF; 6171651d37125a5fe7339fb5f140876c891a8275dfJinsuk Kim if (originalOpcode == Constants.MESSAGE_REQUEST_ARC_TERMINATION) { 62339227da7cf025ce4ae0c85ddc52643d63972321Jungshik Jang disableArcTransmission(); 63339227da7cf025ce4ae0c85ddc52643d63972321Jungshik Jang finish(); 64339227da7cf025ce4ae0c85ddc52643d63972321Jungshik Jang return true; 6571651d37125a5fe7339fb5f140876c891a8275dfJinsuk Kim } else if (originalOpcode == Constants.MESSAGE_REQUEST_ARC_INITIATION) { 6671651d37125a5fe7339fb5f140876c891a8275dfJinsuk Kim tv().setArcStatus(false); 6771651d37125a5fe7339fb5f140876c891a8275dfJinsuk Kim finish(); 6871651d37125a5fe7339fb5f140876c891a8275dfJinsuk Kim return true; 69339227da7cf025ce4ae0c85ddc52643d63972321Jungshik Jang } 7071651d37125a5fe7339fb5f140876c891a8275dfJinsuk Kim return false; 7167ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang } 7267ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang return false; 7367ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang } 7467ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang 7567ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang protected final void disableArcTransmission() { 7667ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang // Start Set ARC Transmission State action. 7779c58a4b97f27ede6a1b680d2fece9c2a0edf7b7Jungshik Jang SetArcTransmissionStateAction action = new SetArcTransmissionStateAction(localDevice(), 7879c58a4b97f27ede6a1b680d2fece9c2a0edf7b7Jungshik Jang mAvrAddress, false); 7979c58a4b97f27ede6a1b680d2fece9c2a0edf7b7Jungshik Jang addAndStartAction(action); 8067ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang } 8167ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang 8267ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang @Override 8367ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang final void handleTimerEvent(int state) { 8467ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang if (mState != state || state != STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE) { 8567ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang return; 8667ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang } 8771651d37125a5fe7339fb5f140876c891a8275dfJinsuk Kim HdmiLogger.debug("[T] RequestArcAction."); 8867ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang disableArcTransmission(); 89358164c09e367199cd3d4af6381a9f342ac9f0efJungshik Jang finish(); 9067ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang } 9167ea521d14f366fe5aac09e512865d31bfa0ee53Jungshik Jang} 92