Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 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 | |
| 17 | package com.android.server.hdmi; |
| 18 | |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 19 | import android.hardware.hdmi.HdmiDeviceInfo; |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 20 | import android.hardware.hdmi.HdmiControlManager; |
Jungshik Jang | ea67c18 | 2014-06-19 22:19:20 +0900 | [diff] [blame] | 21 | import android.hardware.hdmi.IHdmiControlCallback; |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Feature action that handles System Audio initiated by AVR devices. |
| 25 | */ |
Yuncheol Heo | c516d65 | 2014-07-11 18:23:24 +0900 | [diff] [blame] | 26 | // Seq #33 |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 27 | final class SystemAudioActionFromAvr extends SystemAudioAction { |
| 28 | /** |
| 29 | * Constructor |
| 30 | * |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 31 | * @param source {@link HdmiCecLocalDevice} instance |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 32 | * @param avrAddress logical address of AVR device |
| 33 | * @param targetStatus Whether to enable the system audio mode or not |
Jungshik Jang | ea67c18 | 2014-06-19 22:19:20 +0900 | [diff] [blame] | 34 | * @param callback callback interface to be notified when it's done |
Shubang | a3f5950 | 2018-06-05 16:32:53 -0700 | [diff] [blame] | 35 | * @throws IllegalArgumentException if device type of tvAddress and avrAddress is invalid |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 36 | */ |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 37 | SystemAudioActionFromAvr(HdmiCecLocalDevice source, int avrAddress, |
Jungshik Jang | ea67c18 | 2014-06-19 22:19:20 +0900 | [diff] [blame] | 38 | boolean targetStatus, IHdmiControlCallback callback) { |
| 39 | super(source, avrAddress, targetStatus, callback); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 40 | HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV); |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | @Override |
| 44 | boolean start() { |
| 45 | removeSystemAudioActionInProgress(); |
| 46 | handleSystemAudioActionFromAvr(); |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | private void handleSystemAudioActionFromAvr() { |
Jungshik Jang | 377dcbd | 2014-07-15 15:49:02 +0900 | [diff] [blame] | 51 | if (mTargetAudioStatus == tv().isSystemAudioActivated()) { |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 52 | finishWithCallback(HdmiControlManager.RESULT_SUCCESS); |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 53 | return; |
| 54 | } |
Jinsuk Kim | 4d43d93 | 2014-07-03 16:43:58 +0900 | [diff] [blame] | 55 | if (tv().isProhibitMode()) { |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 56 | sendCommand(HdmiCecMessageBuilder.buildFeatureAbortCommand( |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 57 | getSourceAddress(), mAvrLogicalAddress, |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 58 | Constants.MESSAGE_SET_SYSTEM_AUDIO_MODE, Constants.ABORT_REFUSED)); |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 59 | mTargetAudioStatus = false; |
| 60 | sendSystemAudioModeRequest(); |
| 61 | return; |
| 62 | } |
Jungshik Jang | ca5be9a | 2014-07-01 18:01:26 +0900 | [diff] [blame] | 63 | |
| 64 | removeAction(SystemAudioAutoInitiationAction.class); |
| 65 | |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 66 | if (mTargetAudioStatus) { |
| 67 | setSystemAudioMode(true); |
Jungshik Jang | 16321b8 | 2014-06-19 19:39:27 +0900 | [diff] [blame] | 68 | startAudioStatusAction(); |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 69 | } else { |
| 70 | setSystemAudioMode(false); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 71 | finishWithCallback(HdmiControlManager.RESULT_SUCCESS); |
Yuncheol Heo | 63a2e06 | 2014-05-27 23:06:01 +0900 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | } |