Keun young Park | 2a65ed2 | 2021-06-17 17:28:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 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 android.car.apitest.media; |
| 18 | |
| 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
| 21 | import static org.junit.Assume.assumeTrue; |
| 22 | |
| 23 | import android.car.Car; |
| 24 | import android.car.apitest.CarApiTestBase; |
| 25 | import android.car.media.CarAudioManager; |
| 26 | import android.media.AudioAttributes; |
| 27 | import android.media.AudioDeviceInfo; |
| 28 | import android.os.Process; |
| 29 | |
| 30 | import androidx.test.ext.junit.runners.AndroidJUnit4; |
| 31 | |
| 32 | import org.junit.Before; |
| 33 | import org.junit.Test; |
| 34 | import org.junit.runner.RunWith; |
| 35 | |
| 36 | import java.util.List; |
| 37 | |
| 38 | @RunWith(AndroidJUnit4.class) |
| 39 | public class CarAudioManagerTest extends CarApiTestBase { |
| 40 | |
| 41 | private CarAudioManager mCarAudioManager; |
| 42 | |
| 43 | @Before |
| 44 | public void setUp() throws Exception { |
| 45 | mCarAudioManager = (CarAudioManager) getCar().getCarManager(Car.AUDIO_SERVICE); |
| 46 | assertThat(mCarAudioManager).isNotNull(); |
| 47 | } |
| 48 | |
| 49 | @Test |
| 50 | public void test_getAudioZoneIds() throws Exception { |
| 51 | assumeDynamicRoutingIsEnabled(); |
| 52 | |
| 53 | List<Integer> zoneIds = mCarAudioManager.getAudioZoneIds(); |
| 54 | assertThat(zoneIds).isNotEmpty(); |
| 55 | assertThat(zoneIds).contains(CarAudioManager.PRIMARY_AUDIO_ZONE); |
| 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void test_isAudioFeatureEnabled() throws Exception { |
| 60 | // nothing to assert. Just call the API. |
| 61 | mCarAudioManager.isAudioFeatureEnabled(CarAudioManager.AUDIO_FEATURE_DYNAMIC_ROUTING); |
| 62 | mCarAudioManager.isAudioFeatureEnabled(CarAudioManager.AUDIO_FEATURE_VOLUME_GROUP_MUTING); |
| 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void test_getVolumeGroupCount() throws Exception { |
| 67 | int primaryZoneCount = mCarAudioManager.getVolumeGroupCount(); |
| 68 | assertThat( |
| 69 | mCarAudioManager.getVolumeGroupCount(CarAudioManager.PRIMARY_AUDIO_ZONE)).isEqualTo( |
| 70 | primaryZoneCount); |
| 71 | } |
| 72 | |
| 73 | @Test |
| 74 | public void test_getGroupVolume() throws Exception { |
| 75 | int groudId = 0; |
| 76 | int volume = mCarAudioManager.getGroupVolume(groudId); |
| 77 | assertThat(mCarAudioManager.getGroupVolume(CarAudioManager.PRIMARY_AUDIO_ZONE, |
| 78 | groudId)).isEqualTo(volume); |
| 79 | int maxVolume = mCarAudioManager.getGroupMaxVolume(groudId); |
| 80 | assertThat(mCarAudioManager.getGroupMaxVolume(CarAudioManager.PRIMARY_AUDIO_ZONE, |
| 81 | groudId)).isEqualTo(maxVolume); |
| 82 | int minVolume = mCarAudioManager.getGroupMinVolume(groudId); |
| 83 | assertThat(mCarAudioManager.getGroupMinVolume(CarAudioManager.PRIMARY_AUDIO_ZONE, |
| 84 | groudId)).isEqualTo(minVolume); |
| 85 | assertThat(volume).isAtLeast(minVolume); |
| 86 | assertThat(volume).isAtMost(maxVolume); |
| 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void test_setGroupVolume() throws Exception { |
| 91 | int groudId = 0; |
| 92 | int volume = mCarAudioManager.getGroupVolume(groudId); |
| 93 | mCarAudioManager.setGroupVolume(groudId, volume, 0); |
| 94 | mCarAudioManager.setGroupVolume(CarAudioManager.PRIMARY_AUDIO_ZONE, groudId, volume, 0); |
| 95 | assertThat(mCarAudioManager.getGroupVolume(groudId)).isEqualTo(volume); |
| 96 | } |
| 97 | |
| 98 | @Test |
| 99 | public void test_getInputDevicesForZoneId() throws Exception { |
| 100 | assumeDynamicRoutingIsEnabled(); |
| 101 | |
| 102 | List<AudioDeviceInfo> info = mCarAudioManager.getInputDevicesForZoneId( |
| 103 | CarAudioManager.PRIMARY_AUDIO_ZONE); |
| 104 | assertThat(info).isNotEmpty(); |
| 105 | } |
| 106 | |
| 107 | @Test |
| 108 | public void test_getOutputDeviceForUsage() throws Exception { |
| 109 | assumeDynamicRoutingIsEnabled(); |
| 110 | |
| 111 | AudioDeviceInfo device = mCarAudioManager.getOutputDeviceForUsage( |
| 112 | CarAudioManager.PRIMARY_AUDIO_ZONE, AudioAttributes.USAGE_MEDIA); |
| 113 | assertThat(device).isNotNull(); |
| 114 | } |
| 115 | |
| 116 | @Test |
| 117 | public void test_getVolumeGroupIdForUsage() throws Exception { |
| 118 | int groupId = mCarAudioManager.getVolumeGroupIdForUsage(AudioAttributes.USAGE_MEDIA); |
| 119 | assertThat(mCarAudioManager.getVolumeGroupIdForUsage(CarAudioManager.PRIMARY_AUDIO_ZONE, |
| 120 | AudioAttributes.USAGE_MEDIA)).isEqualTo(groupId); |
| 121 | int primaryZoneCount = mCarAudioManager.getVolumeGroupCount(); |
| 122 | assertThat(groupId).isLessThan(primaryZoneCount); |
| 123 | } |
| 124 | |
| 125 | @Test |
| 126 | public void test_getZoneIdForUid() throws Exception { |
| 127 | assumeDynamicRoutingIsEnabled(); |
| 128 | |
| 129 | assertThat(mCarAudioManager.getZoneIdForUid(Process.myUid())).isEqualTo( |
| 130 | CarAudioManager.PRIMARY_AUDIO_ZONE); |
| 131 | } |
| 132 | |
| 133 | @Test |
| 134 | public void test_isPlaybackOnVolumeGroupActive() throws Exception { |
| 135 | assumeDynamicRoutingIsEnabled(); |
| 136 | |
| 137 | // TODO(b/191660867): Better to change this to play something and asert true. |
| 138 | assertThat( |
| 139 | mCarAudioManager.isPlaybackOnVolumeGroupActive(CarAudioManager.PRIMARY_AUDIO_ZONE, |
| 140 | 0)).isFalse(); |
| 141 | } |
| 142 | |
| 143 | private void assumeDynamicRoutingIsEnabled() { |
| 144 | assumeTrue(mCarAudioManager.isAudioFeatureEnabled( |
| 145 | CarAudioManager.AUDIO_FEATURE_DYNAMIC_ROUTING)); |
| 146 | } |
| 147 | } |