keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | package com.android.car.hal; |
| 17 | |
Pavel Maltsev | cfe9310 | 2017-02-02 12:38:08 -0800 | [diff] [blame] | 18 | import static android.hardware.automotive.vehicle.V2_0.VehicleProperty.AUDIO_EXT_ROUTING_HINT; |
| 19 | import static android.hardware.automotive.vehicle.V2_0.VehicleProperty.AUDIO_FOCUS; |
| 20 | import static android.hardware.automotive.vehicle.V2_0.VehicleProperty.AUDIO_HW_VARIANT; |
| 21 | import static android.hardware.automotive.vehicle.V2_0.VehicleProperty.AUDIO_PARAMETERS; |
| 22 | import static android.hardware.automotive.vehicle.V2_0.VehicleProperty.AUDIO_ROUTING_POLICY; |
Pavel Maltsev | de714b7 | 2017-03-24 12:46:40 -0700 | [diff] [blame^] | 23 | import static android.hardware.automotive.vehicle.V2_0.VehicleProperty.AUDIO_STREAM_STATE; |
Pavel Maltsev | cfe9310 | 2017-02-02 12:38:08 -0800 | [diff] [blame] | 24 | import static android.hardware.automotive.vehicle.V2_0.VehicleProperty.AUDIO_VOLUME; |
| 25 | import static android.hardware.automotive.vehicle.V2_0.VehicleProperty.AUDIO_VOLUME_LIMIT; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 26 | import static com.android.car.CarServiceUtils.toIntArray; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 27 | |
| 28 | import android.annotation.Nullable; |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 29 | import android.car.VehicleZoneUtil; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 30 | import android.car.media.CarAudioManager; |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 31 | import android.car.media.CarAudioManager.OnParameterChangeListener; |
Pavel Maltsev | de714b7 | 2017-03-24 12:46:40 -0700 | [diff] [blame^] | 32 | import android.hardware.automotive.vehicle.V2_0.SubscribeFlags; |
Pavel Maltsev | cfe9310 | 2017-02-02 12:38:08 -0800 | [diff] [blame] | 33 | import android.hardware.automotive.vehicle.V2_0.VehicleAudioContextFlag; |
| 34 | import android.hardware.automotive.vehicle.V2_0.VehicleAudioExtFocusFlag; |
| 35 | import android.hardware.automotive.vehicle.V2_0.VehicleAudioFocusIndex; |
| 36 | import android.hardware.automotive.vehicle.V2_0.VehicleAudioFocusRequest; |
| 37 | import android.hardware.automotive.vehicle.V2_0.VehicleAudioFocusState; |
| 38 | import android.hardware.automotive.vehicle.V2_0.VehicleAudioHwVariantConfigFlag; |
| 39 | import android.hardware.automotive.vehicle.V2_0.VehicleAudioRoutingPolicyIndex; |
| 40 | import android.hardware.automotive.vehicle.V2_0.VehicleAudioVolumeCapabilityFlag; |
| 41 | import android.hardware.automotive.vehicle.V2_0.VehicleAudioVolumeIndex; |
| 42 | import android.hardware.automotive.vehicle.V2_0.VehicleAudioVolumeLimitIndex; |
| 43 | import android.hardware.automotive.vehicle.V2_0.VehiclePropConfig; |
| 44 | import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; |
| 45 | import android.hardware.automotive.vehicle.V2_0.VehicleProperty; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 46 | import android.text.TextUtils; |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 47 | import android.util.Log; |
| 48 | |
| 49 | import com.android.car.AudioRoutingPolicy; |
Keun-young Park | 9ba6e8b | 2016-03-04 16:21:19 -0800 | [diff] [blame] | 50 | import com.android.car.CarAudioAttributesUtil; |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 51 | import com.android.car.CarLog; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 52 | |
| 53 | import java.io.PrintWriter; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 54 | import java.util.ArrayList; |
| 55 | import java.util.Arrays; |
| 56 | import java.util.Collection; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 57 | import java.util.HashMap; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 58 | import java.util.List; |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 59 | import java.util.Map; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 60 | |
| 61 | public class AudioHalService extends HalServiceBase { |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 62 | public static final int VEHICLE_AUDIO_FOCUS_REQUEST_INVALID = -1; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 63 | public static final int VEHICLE_AUDIO_FOCUS_REQUEST_GAIN = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 64 | VehicleAudioFocusRequest.REQUEST_GAIN; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 65 | public static final int VEHICLE_AUDIO_FOCUS_REQUEST_GAIN_TRANSIENT = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 66 | VehicleAudioFocusRequest.REQUEST_GAIN_TRANSIENT; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 67 | public static final int VEHICLE_AUDIO_FOCUS_REQUEST_GAIN_TRANSIENT_MAY_DUCK = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 68 | VehicleAudioFocusRequest.REQUEST_GAIN_TRANSIENT_MAY_DUCK; |
Keun-young Park | 32b6382 | 2016-08-02 11:22:29 -0700 | [diff] [blame] | 69 | public static final int VEHICLE_AUDIO_FOCUS_REQUEST_GAIN_TRANSIENT_NO_DUCK = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 70 | VehicleAudioFocusRequest.REQUEST_GAIN_TRANSIENT_NO_DUCK; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 71 | public static final int VEHICLE_AUDIO_FOCUS_REQUEST_RELEASE = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 72 | VehicleAudioFocusRequest.REQUEST_RELEASE; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 73 | |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 74 | public static final int VEHICLE_AUDIO_FOCUS_STATE_INVALID = -1; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 75 | public static final int VEHICLE_AUDIO_FOCUS_STATE_GAIN = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 76 | VehicleAudioFocusState.STATE_GAIN; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 77 | public static final int VEHICLE_AUDIO_FOCUS_STATE_GAIN_TRANSIENT = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 78 | VehicleAudioFocusState.STATE_GAIN_TRANSIENT; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 79 | public static final int VEHICLE_AUDIO_FOCUS_STATE_LOSS_TRANSIENT_CAN_DUCK = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 80 | VehicleAudioFocusState.STATE_LOSS_TRANSIENT_CAN_DUCK; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 81 | public static final int VEHICLE_AUDIO_FOCUS_STATE_LOSS_TRANSIENT = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 82 | VehicleAudioFocusState.STATE_LOSS_TRANSIENT; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 83 | public static final int VEHICLE_AUDIO_FOCUS_STATE_LOSS = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 84 | VehicleAudioFocusState.STATE_LOSS; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 85 | public static final int VEHICLE_AUDIO_FOCUS_STATE_LOSS_TRANSIENT_EXLCUSIVE = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 86 | VehicleAudioFocusState.STATE_LOSS_TRANSIENT_EXLCUSIVE; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 87 | |
Pavel Maltsev | de714b7 | 2017-03-24 12:46:40 -0700 | [diff] [blame^] | 88 | public static final int VEHICLE_AUDIO_STREAM_STATE_STOPPED = 0; |
| 89 | public static final int VEHICLE_AUDIO_STREAM_STATE_STARTED = 1; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 90 | |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 91 | public static final int VEHICLE_AUDIO_EXT_FOCUS_NONE_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 92 | VehicleAudioExtFocusFlag.NONE_FLAG; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 93 | public static final int VEHICLE_AUDIO_EXT_FOCUS_CAR_PERMANENT_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 94 | VehicleAudioExtFocusFlag.PERMANENT_FLAG; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 95 | public static final int VEHICLE_AUDIO_EXT_FOCUS_CAR_TRANSIENT_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 96 | VehicleAudioExtFocusFlag.TRANSIENT_FLAG; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 97 | public static final int VEHICLE_AUDIO_EXT_FOCUS_CAR_PLAY_ONLY_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 98 | VehicleAudioExtFocusFlag.PLAY_ONLY_FLAG; |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 99 | public static final int VEHICLE_AUDIO_EXT_FOCUS_CAR_MUTE_MEDIA_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 100 | VehicleAudioExtFocusFlag.MUTE_MEDIA_FLAG; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 101 | |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 102 | public static final int STREAM_NUM_DEFAULT = 0; |
| 103 | |
Keun-young Park | 1fdf91c | 2016-01-21 10:17:41 -0800 | [diff] [blame] | 104 | public static final int FOCUS_STATE_ARRAY_INDEX_STATE = 0; |
| 105 | public static final int FOCUS_STATE_ARRAY_INDEX_STREAMS = 1; |
| 106 | public static final int FOCUS_STATE_ARRAY_INDEX_EXTERNAL_FOCUS = 2; |
| 107 | |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 108 | public static final int AUDIO_CONTEXT_MUSIC_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 109 | VehicleAudioContextFlag.MUSIC_FLAG; |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 110 | public static final int AUDIO_CONTEXT_NAVIGATION_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 111 | VehicleAudioContextFlag.NAVIGATION_FLAG; |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 112 | public static final int AUDIO_CONTEXT_VOICE_COMMAND_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 113 | VehicleAudioContextFlag.VOICE_COMMAND_FLAG; |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 114 | public static final int AUDIO_CONTEXT_CALL_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 115 | VehicleAudioContextFlag.CALL_FLAG; |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 116 | public static final int AUDIO_CONTEXT_ALARM_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 117 | VehicleAudioContextFlag.ALARM_FLAG; |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 118 | public static final int AUDIO_CONTEXT_NOTIFICATION_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 119 | VehicleAudioContextFlag.NOTIFICATION_FLAG; |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 120 | public static final int AUDIO_CONTEXT_UNKNOWN_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 121 | VehicleAudioContextFlag.UNKNOWN_FLAG; |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 122 | public static final int AUDIO_CONTEXT_SAFETY_ALERT_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 123 | VehicleAudioContextFlag.SAFETY_ALERT_FLAG; |
Keun-young Park | d8c22f2 | 2016-03-03 17:16:51 -0800 | [diff] [blame] | 124 | public static final int AUDIO_CONTEXT_RADIO_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 125 | VehicleAudioContextFlag.RADIO_FLAG; |
Keun-young Park | d8c22f2 | 2016-03-03 17:16:51 -0800 | [diff] [blame] | 126 | public static final int AUDIO_CONTEXT_CD_ROM_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 127 | VehicleAudioContextFlag.CD_ROM_FLAG; |
Keun-young Park | d8c22f2 | 2016-03-03 17:16:51 -0800 | [diff] [blame] | 128 | public static final int AUDIO_CONTEXT_AUX_AUDIO_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 129 | VehicleAudioContextFlag.AUX_AUDIO_FLAG; |
Keun-young Park | d8c22f2 | 2016-03-03 17:16:51 -0800 | [diff] [blame] | 130 | public static final int AUDIO_CONTEXT_SYSTEM_SOUND_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 131 | VehicleAudioContextFlag.SYSTEM_SOUND_FLAG; |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 132 | public static final int AUDIO_CONTEXT_EXT_SOURCE_FLAG = |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 133 | VehicleAudioContextFlag.EXT_SOURCE_FLAG; |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 134 | |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 135 | public interface AudioHalFocusListener { |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 136 | /** |
| 137 | * Audio focus change from car. |
| 138 | * @param focusState |
| 139 | * @param streams |
| 140 | * @param externalFocus Flags of active external audio focus. |
| 141 | * 0 means no external audio focus. |
| 142 | */ |
| 143 | void onFocusChange(int focusState, int streams, int externalFocus); |
| 144 | /** |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 145 | * Stream state change (start / stop) from android |
Keun-young Park | 32b6382 | 2016-08-02 11:22:29 -0700 | [diff] [blame] | 146 | * @param streamNumber stream number like 0, 1, ... |
| 147 | * @param streamActive Whether the stream is active or not. |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 148 | */ |
Keun-young Park | 32b6382 | 2016-08-02 11:22:29 -0700 | [diff] [blame] | 149 | void onStreamStatusChange(int streamNumber, boolean streamActive); |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | public interface AudioHalVolumeListener { |
| 153 | /** |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 154 | * Audio volume change from car. |
| 155 | * @param streamNumber |
| 156 | * @param volume |
| 157 | * @param volumeState |
| 158 | */ |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 159 | void onVolumeChange(int streamNumber, int volume, int volumeState); |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 160 | /** |
| 161 | * Volume limit change from car. |
| 162 | * @param streamNumber |
| 163 | * @param volume |
| 164 | */ |
| 165 | void onVolumeLimitChange(int streamNumber, int volume); |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Vitalii Tomkiv | 1b1247b | 2016-09-30 11:27:19 -0700 | [diff] [blame] | 168 | private static final boolean DBG = false; |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 169 | |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 170 | private final VehicleHal mVehicleHal; |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 171 | private AudioHalFocusListener mFocusListener; |
| 172 | private AudioHalVolumeListener mVolumeListener; |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 173 | private int mVariant; |
| 174 | |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 175 | private final HashMap<Integer, VehiclePropConfig> mProperties = new HashMap<>(); |
| 176 | |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 177 | private OnParameterChangeListener mOnParameterChangeListener; |
| 178 | |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 179 | public AudioHalService(VehicleHal vehicleHal) { |
| 180 | mVehicleHal = vehicleHal; |
| 181 | } |
| 182 | |
Keun-young Park | 6b3f719 | 2016-03-25 18:41:49 -0700 | [diff] [blame] | 183 | public synchronized void setFocusListener(AudioHalFocusListener focusListener) { |
| 184 | mFocusListener = focusListener; |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Keun-young Park | 6b3f719 | 2016-03-25 18:41:49 -0700 | [diff] [blame] | 187 | public synchronized void setVolumeListener(AudioHalVolumeListener volumeListener) { |
| 188 | mVolumeListener = volumeListener; |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | public void setAudioRoutingPolicy(AudioRoutingPolicy policy) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 192 | if (!mVehicleHal.isPropertySupported(VehicleProperty.AUDIO_ROUTING_POLICY)) { |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 193 | Log.w(CarLog.TAG_AUDIO, |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 194 | "Vehicle HAL did not implement VehicleProperty.AUDIO_ROUTING_POLICY"); |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | int[] policyToSet = new int[2]; |
| 198 | for (int i = 0; i < policy.getPhysicalStreamsCount(); i++) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 199 | policyToSet[VehicleAudioRoutingPolicyIndex.STREAM] = i; |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 200 | int contexts = 0; |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 201 | for (int logicalStream : policy.getLogicalStreamsForPhysicalStream(i)) { |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 202 | contexts |= logicalStreamToHalContextType(logicalStream); |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 203 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 204 | policyToSet[VehicleAudioRoutingPolicyIndex.CONTEXTS] = contexts; |
Keun-young Park | e78bf53 | 2016-04-25 18:59:22 -0700 | [diff] [blame] | 205 | try { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 206 | mVehicleHal.set(AUDIO_ROUTING_POLICY).to(policyToSet); |
| 207 | } catch (PropertyTimeoutException e) { |
| 208 | Log.e(CarLog.TAG_AUDIO, "Cannot write to VehicleProperty.AUDIO_ROUTING_POLICY", e); |
Keun-young Park | e78bf53 | 2016-04-25 18:59:22 -0700 | [diff] [blame] | 209 | } |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 213 | /** |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 214 | * Returns the volume limits of a stream. Returns null if max value wasn't defined for |
| 215 | * AUDIO_VOLUME property. |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 216 | */ |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 217 | @Nullable |
| 218 | public synchronized Integer getStreamMaxVolume(int stream) { |
| 219 | VehiclePropConfig config = mProperties.get(VehicleProperty.AUDIO_VOLUME); |
| 220 | if (config == null) { |
| 221 | throw new IllegalStateException("VehicleProperty.AUDIO_VOLUME not supported"); |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 222 | } |
| 223 | int supportedContext = getSupportedAudioVolumeContexts(); |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 224 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 225 | int MAX_VALUES_FIRST_ELEMENT_INDEX = 4; |
| 226 | ArrayList<Integer> maxValues = new ArrayList<>(); |
| 227 | for (int i = MAX_VALUES_FIRST_ELEMENT_INDEX; i < config.configArray.size(); i++) { |
| 228 | maxValues.add(config.configArray.get(i)); |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 231 | Integer result = null; |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 232 | if (supportedContext != 0) { |
| 233 | int index = VehicleZoneUtil.zoneToIndex(supportedContext, stream); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 234 | if (index < maxValues.size()) { |
| 235 | result = maxValues.get(index); |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 236 | } |
| 237 | } else { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 238 | if (stream < maxValues.size()) { |
| 239 | result = maxValues.get(stream); |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | if (result == null) { |
| 244 | Log.e(CarLog.TAG_AUDIO, "No min/max volume found in vehicle" + |
| 245 | " prop config for stream: " + stream); |
| 246 | } |
| 247 | |
| 248 | return result; |
| 249 | } |
| 250 | |
| 251 | /** |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 252 | * Convert car audio manager stream type (usage) into audio context type. |
| 253 | */ |
| 254 | public static int logicalStreamToHalContextType(int logicalStream) { |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 255 | return logicalStreamWithExtTypeToHalContextType(logicalStream, null); |
| 256 | } |
| 257 | |
| 258 | public static int logicalStreamWithExtTypeToHalContextType(int logicalStream, String extType) { |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 259 | switch (logicalStream) { |
Keun-young Park | d8c22f2 | 2016-03-03 17:16:51 -0800 | [diff] [blame] | 260 | case CarAudioManager.CAR_AUDIO_USAGE_RADIO: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 261 | return VehicleAudioContextFlag.RADIO_FLAG; |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 262 | case CarAudioManager.CAR_AUDIO_USAGE_VOICE_CALL: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 263 | return VehicleAudioContextFlag.CALL_FLAG; |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 264 | case CarAudioManager.CAR_AUDIO_USAGE_MUSIC: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 265 | return VehicleAudioContextFlag.MUSIC_FLAG; |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 266 | case CarAudioManager.CAR_AUDIO_USAGE_NAVIGATION_GUIDANCE: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 267 | return VehicleAudioContextFlag.NAVIGATION_FLAG; |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 268 | case CarAudioManager.CAR_AUDIO_USAGE_VOICE_COMMAND: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 269 | return VehicleAudioContextFlag.VOICE_COMMAND_FLAG; |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 270 | case CarAudioManager.CAR_AUDIO_USAGE_ALARM: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 271 | return VehicleAudioContextFlag.ALARM_FLAG; |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 272 | case CarAudioManager.CAR_AUDIO_USAGE_NOTIFICATION: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 273 | return VehicleAudioContextFlag.NOTIFICATION_FLAG; |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 274 | case CarAudioManager.CAR_AUDIO_USAGE_SYSTEM_SAFETY_ALERT: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 275 | return VehicleAudioContextFlag.SAFETY_ALERT_FLAG; |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 276 | case CarAudioManager.CAR_AUDIO_USAGE_SYSTEM_SOUND: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 277 | return VehicleAudioContextFlag.SYSTEM_SOUND_FLAG; |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 278 | case CarAudioManager.CAR_AUDIO_USAGE_DEFAULT: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 279 | return VehicleAudioContextFlag.UNKNOWN_FLAG; |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 280 | case CarAudioManager.CAR_AUDIO_USAGE_EXTERNAL_AUDIO_SOURCE: |
| 281 | if (extType != null) { |
| 282 | switch (extType) { |
| 283 | case CarAudioManager.CAR_EXTERNAL_SOURCE_TYPE_CD_DVD: |
| 284 | return AudioHalService.AUDIO_CONTEXT_CD_ROM_FLAG; |
| 285 | case CarAudioManager.CAR_EXTERNAL_SOURCE_TYPE_AUX_IN0: |
| 286 | case CarAudioManager.CAR_EXTERNAL_SOURCE_TYPE_AUX_IN1: |
| 287 | return AudioHalService.AUDIO_CONTEXT_AUX_AUDIO_FLAG; |
| 288 | default: |
| 289 | if (extType.startsWith("RADIO_")) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 290 | return VehicleAudioContextFlag.RADIO_FLAG; |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 291 | } else { |
| 292 | return AudioHalService.AUDIO_CONTEXT_EXT_SOURCE_FLAG; |
| 293 | } |
| 294 | } |
| 295 | } else { // no external source specified. fall back to radio |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 296 | return VehicleAudioContextFlag.RADIO_FLAG; |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 297 | } |
Keun-young Park | 9ba6e8b | 2016-03-04 16:21:19 -0800 | [diff] [blame] | 298 | case CarAudioAttributesUtil.CAR_AUDIO_USAGE_CARSERVICE_BOTTOM: |
| 299 | case CarAudioAttributesUtil.CAR_AUDIO_USAGE_CARSERVICE_CAR_PROXY: |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 300 | case CarAudioAttributesUtil.CAR_AUDIO_USAGE_CARSERVICE_MEDIA_MUTE: |
Keun-young Park | 9ba6e8b | 2016-03-04 16:21:19 -0800 | [diff] [blame] | 301 | // internal tag not associated with any stream |
| 302 | return 0; |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 303 | default: |
| 304 | Log.w(CarLog.TAG_AUDIO, "Unknown logical stream:" + logicalStream); |
| 305 | return 0; |
| 306 | } |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 309 | /** |
| 310 | * Converts car audio context type to car stream usage. |
| 311 | */ |
| 312 | public static int carContextToCarUsage(int carContext) { |
| 313 | switch (carContext) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 314 | case VehicleAudioContextFlag.MUSIC_FLAG: |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 315 | return CarAudioManager.CAR_AUDIO_USAGE_MUSIC; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 316 | case VehicleAudioContextFlag.NAVIGATION_FLAG: |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 317 | return CarAudioManager.CAR_AUDIO_USAGE_NAVIGATION_GUIDANCE; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 318 | case VehicleAudioContextFlag.ALARM_FLAG: |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 319 | return CarAudioManager.CAR_AUDIO_USAGE_ALARM; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 320 | case VehicleAudioContextFlag.VOICE_COMMAND_FLAG: |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 321 | return CarAudioManager.CAR_AUDIO_USAGE_VOICE_COMMAND; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 322 | case VehicleAudioContextFlag.AUX_AUDIO_FLAG: |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 323 | return CarAudioManager.CAR_AUDIO_USAGE_EXTERNAL_AUDIO_SOURCE; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 324 | case VehicleAudioContextFlag.CALL_FLAG: |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 325 | return CarAudioManager.CAR_AUDIO_USAGE_VOICE_CALL; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 326 | case VehicleAudioContextFlag.CD_ROM_FLAG: |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 327 | return CarAudioManager.CAR_AUDIO_USAGE_EXTERNAL_AUDIO_SOURCE; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 328 | case VehicleAudioContextFlag.NOTIFICATION_FLAG: |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 329 | return CarAudioManager.CAR_AUDIO_USAGE_NOTIFICATION; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 330 | case VehicleAudioContextFlag.RADIO_FLAG: |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 331 | return CarAudioManager.CAR_AUDIO_USAGE_RADIO; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 332 | case VehicleAudioContextFlag.SAFETY_ALERT_FLAG: |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 333 | return CarAudioManager.CAR_AUDIO_USAGE_SYSTEM_SAFETY_ALERT; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 334 | case VehicleAudioContextFlag.SYSTEM_SOUND_FLAG: |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 335 | return CarAudioManager.CAR_AUDIO_USAGE_SYSTEM_SOUND; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 336 | case VehicleAudioContextFlag.UNKNOWN_FLAG: |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 337 | return CarAudioManager.CAR_AUDIO_USAGE_DEFAULT; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 338 | case VehicleAudioContextFlag.EXT_SOURCE_FLAG: |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 339 | return CarAudioManager.CAR_AUDIO_USAGE_EXTERNAL_AUDIO_SOURCE; |
Yao Chen | 75279c9 | 2016-05-06 14:41:37 -0700 | [diff] [blame] | 340 | default: |
| 341 | Log.w(CarLog.TAG_AUDIO, "Unknown car context:" + carContext); |
| 342 | return 0; |
| 343 | } |
| 344 | } |
| 345 | |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 346 | public void requestAudioFocusChange(int request, int streams, int audioContexts) { |
| 347 | requestAudioFocusChange(request, streams, VEHICLE_AUDIO_EXT_FOCUS_NONE_FLAG, audioContexts); |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Keun-young Park | 1488ef2 | 2016-02-25 14:00:54 -0800 | [diff] [blame] | 350 | public void requestAudioFocusChange(int request, int streams, int extFocus, int audioContexts) { |
| 351 | int[] payload = { request, streams, extFocus, audioContexts }; |
Keun-young Park | e78bf53 | 2016-04-25 18:59:22 -0700 | [diff] [blame] | 352 | try { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 353 | mVehicleHal.set(AUDIO_FOCUS).to(payload); |
| 354 | } catch (PropertyTimeoutException e) { |
| 355 | Log.e(CarLog.TAG_AUDIO, "Cannot write to VehicleProperty.AUDIO_FOCUS", e); |
Keun-young Park | e78bf53 | 2016-04-25 18:59:22 -0700 | [diff] [blame] | 356 | // focus timeout will reset it anyway |
| 357 | } |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 360 | public void setStreamVolume(int streamType, int index) { |
| 361 | int[] payload = {streamType, index, 0}; |
Keun-young Park | e78bf53 | 2016-04-25 18:59:22 -0700 | [diff] [blame] | 362 | try { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 363 | mVehicleHal.set(VehicleProperty.AUDIO_VOLUME).to(payload); |
| 364 | } catch (PropertyTimeoutException e) { |
| 365 | Log.e(CarLog.TAG_AUDIO, "Cannot write to VehicleProperty.AUDIO_VOLUME", e); |
Keun-young Park | f921520 | 2016-10-10 12:34:08 -0700 | [diff] [blame] | 366 | //TODO should reset volume, bug: 32096870 |
Keun-young Park | e78bf53 | 2016-04-25 18:59:22 -0700 | [diff] [blame] | 367 | } |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | public int getStreamVolume(int stream) { |
| 371 | int[] volume = {stream, 0, 0}; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 372 | VehiclePropValue requestedStreamVolume = new VehiclePropValue(); |
| 373 | requestedStreamVolume.prop = VehicleProperty.AUDIO_VOLUME; |
| 374 | requestedStreamVolume.value.int32Values.addAll(Arrays.asList(stream, 0 , 0)); |
| 375 | VehiclePropValue propValue; |
Keun-young Park | 021310d | 2016-04-25 21:09:39 -0700 | [diff] [blame] | 376 | try { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 377 | propValue = mVehicleHal.get(requestedStreamVolume); |
| 378 | } catch (PropertyTimeoutException e) { |
| 379 | Log.e(CarLog.TAG_AUDIO, "VehicleProperty.AUDIO_VOLUME not ready", e); |
Keun-young Park | 021310d | 2016-04-25 21:09:39 -0700 | [diff] [blame] | 380 | return 0; |
| 381 | } |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 382 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 383 | if (propValue.value.int32Values.size() != 3) { |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 384 | Log.e(CarLog.TAG_AUDIO, "returned value not valid"); |
| 385 | throw new IllegalStateException("Invalid preset returned from service: " |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 386 | + Arrays.toString(propValue.value.int32Values.toArray())); |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 389 | int retStreamNum = propValue.value.int32Values.get(0); |
| 390 | int retVolume = propValue.value.int32Values.get(1); |
| 391 | int retVolumeState = propValue.value.int32Values.get(2); |
Yao Chen | c4d442f | 2016-04-08 11:33:47 -0700 | [diff] [blame] | 392 | |
| 393 | if (retStreamNum != stream) { |
| 394 | Log.e(CarLog.TAG_AUDIO, "Stream number is not the same: " |
| 395 | + stream + " vs " + retStreamNum); |
| 396 | throw new IllegalStateException("Stream number is not the same"); |
| 397 | } |
| 398 | return retVolume; |
| 399 | } |
| 400 | |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 401 | public synchronized int getHwVariant() { |
| 402 | return mVariant; |
| 403 | } |
| 404 | |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 405 | public synchronized boolean isRadioExternal() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 406 | VehiclePropConfig config = mProperties.get(VehicleProperty.AUDIO_HW_VARIANT); |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 407 | if (config == null) { |
| 408 | return true; |
| 409 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 410 | return (config.configArray.get(0) |
| 411 | & VehicleAudioHwVariantConfigFlag.INTERNAL_RADIO_FLAG) == 0; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | public synchronized boolean isFocusSupported() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 415 | return isPropertySupportedLocked(AUDIO_FOCUS); |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 418 | public synchronized boolean isAudioVolumeSupported() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 419 | return isPropertySupportedLocked(VehicleProperty.AUDIO_VOLUME); |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | public synchronized int getSupportedAudioVolumeContexts() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 423 | if (!isPropertySupportedLocked(VehicleProperty.AUDIO_VOLUME)) { |
| 424 | throw new IllegalStateException("VehicleProperty.AUDIO_VOLUME not supported"); |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 425 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 426 | VehiclePropConfig config = mProperties.get(VehicleProperty.AUDIO_VOLUME); |
| 427 | return config.configArray.get(0); |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Whether external audio module can memorize logical audio volumes or not. |
| 432 | * @return |
| 433 | */ |
| 434 | public synchronized boolean isExternalAudioVolumePersistent() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 435 | if (!isPropertySupportedLocked(VehicleProperty.AUDIO_VOLUME)) { |
| 436 | throw new IllegalStateException("VehicleProperty.AUDIO_VOLUME not supported"); |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 437 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 438 | VehiclePropConfig config = mProperties.get(VehicleProperty.AUDIO_VOLUME); |
| 439 | if (config.configArray.get(0) == 0) { // physical streams only |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 440 | return false; |
| 441 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 442 | if ((config.configArray.get(1) |
| 443 | & VehicleAudioVolumeCapabilityFlag.PERSISTENT_STORAGE) != 0) { |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 444 | return true; |
| 445 | } |
| 446 | return false; |
| 447 | } |
| 448 | |
| 449 | public synchronized boolean isAudioVolumeLimitSupported() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 450 | return isPropertySupportedLocked(AUDIO_VOLUME_LIMIT); |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Keun-young Park | d36a995 | 2016-05-24 10:03:59 -0700 | [diff] [blame] | 453 | public synchronized boolean isAudioVolumeMasterOnly() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 454 | if (!isPropertySupportedLocked(VehicleProperty.AUDIO_VOLUME)) { |
| 455 | throw new IllegalStateException("VehicleProperty.AUDIO_VOLUME not supported"); |
Keun-young Park | d36a995 | 2016-05-24 10:03:59 -0700 | [diff] [blame] | 456 | } |
| 457 | VehiclePropConfig config = mProperties.get( |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 458 | AUDIO_VOLUME); |
| 459 | if ((config.configArray.get(1) & |
| 460 | VehicleAudioVolumeCapabilityFlag.MASTER_VOLUME_ONLY) |
Keun-young Park | d36a995 | 2016-05-24 10:03:59 -0700 | [diff] [blame] | 461 | != 0) { |
| 462 | return true; |
| 463 | } |
| 464 | return false; |
| 465 | } |
| 466 | |
Keun-young Park | 1fdf91c | 2016-01-21 10:17:41 -0800 | [diff] [blame] | 467 | /** |
| 468 | * Get the current audio focus state. |
| 469 | * @return 0: focusState, 1: streams, 2: externalFocus |
| 470 | */ |
| 471 | public int[] getCurrentFocusState() { |
| 472 | if (!isFocusSupported()) { |
| 473 | return new int[] { VEHICLE_AUDIO_FOCUS_STATE_GAIN, 0xffffffff, 0}; |
| 474 | } |
Keun-young Park | ba48548 | 2016-03-24 13:24:31 -0700 | [diff] [blame] | 475 | try { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 476 | VehiclePropValue propValue = mVehicleHal.get(VehicleProperty.AUDIO_FOCUS); |
| 477 | return toIntArray(propValue.value.int32Values); |
| 478 | } catch (PropertyTimeoutException e) { |
| 479 | Log.e(CarLog.TAG_AUDIO, "VehicleProperty.AUDIO_HW_VARIANT not ready", e); |
Keun-young Park | ba48548 | 2016-03-24 13:24:31 -0700 | [diff] [blame] | 480 | return new int[] { VEHICLE_AUDIO_FOCUS_STATE_LOSS, 0x0, 0}; |
| 481 | } |
Keun-young Park | 1fdf91c | 2016-01-21 10:17:41 -0800 | [diff] [blame] | 482 | } |
| 483 | |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 484 | public static class ExtRoutingSourceInfo { |
| 485 | /** Represents an external route which will not disable any physical stream in android side. |
| 486 | */ |
| 487 | public static final int NO_DISABLED_PHYSICAL_STREAM = -1; |
| 488 | |
| 489 | /** Bit position of this source in vhal */ |
| 490 | public final int bitPosition; |
| 491 | /** |
| 492 | * Physical stream replaced by this routing. will be {@link #NO_DISABLED_PHYSICAL_STREAM} |
| 493 | * if no physical stream for android is replaced by this routing. |
| 494 | */ |
| 495 | public final int physicalStreamNumber; |
| 496 | |
| 497 | public ExtRoutingSourceInfo(int bitPosition, int physycalStreamNumber) { |
| 498 | this.bitPosition = bitPosition; |
| 499 | this.physicalStreamNumber = physycalStreamNumber; |
| 500 | } |
| 501 | |
| 502 | @Override |
| 503 | public String toString() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 504 | return "[bitPosition=" + bitPosition + ", physicalStreamNumber=" |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 505 | + physicalStreamNumber + "]"; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Get external audio routing types from AUDIO_EXT_ROUTING_HINT property. |
| 511 | * |
| 512 | * @return null if AUDIO_EXT_ROUTING_HINT is not supported. |
| 513 | */ |
| 514 | public Map<String, ExtRoutingSourceInfo> getExternalAudioRoutingTypes() { |
| 515 | VehiclePropConfig config; |
| 516 | synchronized (this) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 517 | if (!isPropertySupportedLocked(AUDIO_EXT_ROUTING_HINT)) { |
| 518 | if (DBG) { |
| 519 | Log.i(CarLog.TAG_AUDIO, "AUDIO_EXT_ROUTING_HINT is not supported"); |
| 520 | } |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 521 | return null; |
| 522 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 523 | config = mProperties.get(AUDIO_EXT_ROUTING_HINT); |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 524 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 525 | if (TextUtils.isEmpty(config.configString)) { |
| 526 | Log.w(CarLog.TAG_AUDIO, "AUDIO_EXT_ROUTING_HINT with empty config string"); |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 527 | return null; |
| 528 | } |
| 529 | Map<String, ExtRoutingSourceInfo> routingTypes = new HashMap<>(); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 530 | String configString = config.configString; |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 531 | if (DBG) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 532 | Log.i(CarLog.TAG_AUDIO, "AUDIO_EXT_ROUTING_HINT config string:" + configString); |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 533 | } |
| 534 | String[] routes = configString.split(","); |
| 535 | for (String routeString : routes) { |
| 536 | String[] tokens = routeString.split(":"); |
| 537 | int bitPosition = 0; |
| 538 | String name = null; |
| 539 | int physicalStreamNumber = ExtRoutingSourceInfo.NO_DISABLED_PHYSICAL_STREAM; |
| 540 | if (tokens.length == 2) { |
| 541 | bitPosition = Integer.parseInt(tokens[0]); |
| 542 | name = tokens[1]; |
| 543 | } else if (tokens.length == 3) { |
| 544 | bitPosition = Integer.parseInt(tokens[0]); |
| 545 | name = tokens[1]; |
| 546 | physicalStreamNumber = Integer.parseInt(tokens[2]); |
| 547 | } else { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 548 | Log.w(CarLog.TAG_AUDIO, "AUDIO_EXT_ROUTING_HINT has wrong entry:" + |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 549 | routeString); |
| 550 | continue; |
| 551 | } |
| 552 | routingTypes.put(name, new ExtRoutingSourceInfo(bitPosition, physicalStreamNumber)); |
| 553 | } |
| 554 | return routingTypes; |
| 555 | } |
| 556 | |
| 557 | public void setExternalRoutingSource(int[] externalRoutings) { |
| 558 | try { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 559 | mVehicleHal.set(AUDIO_EXT_ROUTING_HINT).to(externalRoutings); |
| 560 | } catch (PropertyTimeoutException e) { |
| 561 | Log.e(CarLog.TAG_AUDIO, "Cannot write to VehicleProperty.AUDIO_EXT_ROUTING_HINT", e); |
Keun-young Park | 4c6834a | 2016-06-28 12:58:23 -0700 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 565 | private boolean isPropertySupportedLocked(int property) { |
| 566 | VehiclePropConfig config = mProperties.get(property); |
| 567 | return config != null; |
| 568 | } |
| 569 | |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 570 | @Override |
| 571 | public synchronized void init() { |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 572 | for (VehiclePropConfig config : mProperties.values()) { |
| 573 | if (VehicleHal.isPropertySubscribable(config)) { |
Pavel Maltsev | de714b7 | 2017-03-24 12:46:40 -0700 | [diff] [blame^] | 574 | int subsribeFlag = SubscribeFlags.HAL_EVENT; |
| 575 | if (AUDIO_STREAM_STATE == config.prop) { |
| 576 | subsribeFlag |= SubscribeFlags.SET_CALL; |
| 577 | } |
| 578 | mVehicleHal.subscribeProperty(this, config.prop, 0, subsribeFlag); |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | try { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 582 | mVariant = mVehicleHal.get(int.class, AUDIO_HW_VARIANT); |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 583 | } catch (IllegalArgumentException e) { |
| 584 | // no variant. Set to default, 0. |
| 585 | mVariant = 0; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 586 | } catch (PropertyTimeoutException e) { |
| 587 | Log.e(CarLog.TAG_AUDIO, "VehicleProperty.AUDIO_HW_VARIANT not ready", e); |
Keun-young Park | ba48548 | 2016-03-24 13:24:31 -0700 | [diff] [blame] | 588 | mVariant = 0; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
| 592 | @Override |
| 593 | public synchronized void release() { |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 594 | for (VehiclePropConfig config : mProperties.values()) { |
| 595 | if (VehicleHal.isPropertySubscribable(config)) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 596 | mVehicleHal.unsubscribeProperty(this, config.prop); |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 597 | } |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 598 | } |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 599 | mProperties.clear(); |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | @Override |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 603 | public synchronized Collection<VehiclePropConfig> takeSupportedProperties( |
| 604 | Collection<VehiclePropConfig> allProperties) { |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 605 | for (VehiclePropConfig p : allProperties) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 606 | switch (p.prop) { |
| 607 | case VehicleProperty.AUDIO_FOCUS: |
| 608 | case VehicleProperty.AUDIO_VOLUME: |
| 609 | case VehicleProperty.AUDIO_VOLUME_LIMIT: |
| 610 | case VehicleProperty.AUDIO_HW_VARIANT: |
| 611 | case VehicleProperty.AUDIO_EXT_ROUTING_HINT: |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 612 | case VehicleProperty.AUDIO_PARAMETERS: |
Pavel Maltsev | de714b7 | 2017-03-24 12:46:40 -0700 | [diff] [blame^] | 613 | case VehicleProperty.AUDIO_STREAM_STATE: |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 614 | mProperties.put(p.prop, p); |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 615 | break; |
| 616 | } |
| 617 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 618 | return new ArrayList<>(mProperties.values()); |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | @Override |
| 622 | public void handleHalEvents(List<VehiclePropValue> values) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 623 | AudioHalFocusListener focusListener; |
| 624 | AudioHalVolumeListener volumeListener; |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 625 | OnParameterChangeListener parameterListener; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 626 | synchronized (this) { |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 627 | focusListener = mFocusListener; |
| 628 | volumeListener = mVolumeListener; |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 629 | parameterListener = mOnParameterChangeListener; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 630 | } |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 631 | dispatchEventToListener(focusListener, volumeListener, parameterListener, values); |
| 632 | } |
| 633 | |
| 634 | public String[] getAudioParameterKeys() { |
| 635 | VehiclePropConfig config; |
| 636 | synchronized (this) { |
| 637 | if (!isPropertySupportedLocked(AUDIO_PARAMETERS)) { |
| 638 | if (DBG) { |
| 639 | Log.i(CarLog.TAG_AUDIO, "AUDIO_PARAMETERS is not supported"); |
| 640 | } |
| 641 | return null; |
| 642 | } |
| 643 | config = mProperties.get(AUDIO_PARAMETERS); |
| 644 | } |
| 645 | return config.configString.split(";"); |
| 646 | } |
| 647 | |
| 648 | public void setAudioParameters(String parameters) { |
| 649 | synchronized (this) { |
| 650 | if (!isPropertySupportedLocked(AUDIO_PARAMETERS)) { |
| 651 | throw new IllegalStateException("VehicleProperty.AUDIO_PARAMETERS not supported"); |
| 652 | } |
| 653 | } |
| 654 | VehiclePropValue value = new VehiclePropValue(); |
| 655 | value.prop = AUDIO_PARAMETERS; |
| 656 | value.value.stringValue = parameters; |
| 657 | try { |
| 658 | mVehicleHal.set(value); |
| 659 | } catch (PropertyTimeoutException e) { |
| 660 | Log.e(CarLog.TAG_AUDIO, "Cannot write to VehicleProperty.AUDIO_EXT_ROUTING_HINT", e); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | public String getAudioParameters(String keys) { |
| 665 | synchronized (this) { |
| 666 | if (!isPropertySupportedLocked(AUDIO_PARAMETERS)) { |
| 667 | throw new IllegalStateException("VehicleProperty.AUDIO_PARAMETERS not supported"); |
| 668 | } |
| 669 | } |
| 670 | try { |
| 671 | VehiclePropValue requested = new VehiclePropValue(); |
| 672 | requested.prop = AUDIO_PARAMETERS; |
| 673 | requested.value.stringValue = keys; |
| 674 | VehiclePropValue propValue = mVehicleHal.get(requested); |
| 675 | return propValue.value.stringValue; |
| 676 | } catch (PropertyTimeoutException e) { |
| 677 | Log.e(CarLog.TAG_AUDIO, "VehicleProperty.AUDIO_PARAMETERS not ready", e); |
| 678 | return new String(""); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | public synchronized void setOnParameterChangeListener(OnParameterChangeListener listener) { |
| 683 | mOnParameterChangeListener = listener; |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | private void dispatchEventToListener(AudioHalFocusListener focusListener, |
| 687 | AudioHalVolumeListener volumeListener, |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 688 | OnParameterChangeListener parameterListener, |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 689 | List<VehiclePropValue> values) { |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 690 | for (VehiclePropValue v : values) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 691 | switch (v.prop) { |
| 692 | case VehicleProperty.AUDIO_FOCUS: { |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 693 | ArrayList<Integer> vec = v.value.int32Values; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 694 | int focusState = vec.get(VehicleAudioFocusIndex.FOCUS); |
| 695 | int streams = vec.get(VehicleAudioFocusIndex.STREAMS); |
| 696 | int externalFocus = vec.get(VehicleAudioFocusIndex.EXTERNAL_FOCUS_STATE); |
Keun-young Park | 6b3f719 | 2016-03-25 18:41:49 -0700 | [diff] [blame] | 697 | if (focusListener != null) { |
| 698 | focusListener.onFocusChange(focusState, streams, externalFocus); |
| 699 | } |
| 700 | } break; |
Pavel Maltsev | de714b7 | 2017-03-24 12:46:40 -0700 | [diff] [blame^] | 701 | case VehicleProperty.AUDIO_STREAM_STATE: { |
| 702 | ArrayList<Integer> vec = v.value.int32Values; |
| 703 | boolean streamStarted = vec.get(0) == VEHICLE_AUDIO_STREAM_STATE_STARTED; |
| 704 | int streamNum = vec.get(1); |
| 705 | if (focusListener != null) { |
| 706 | focusListener.onStreamStatusChange(streamNum, streamStarted); |
| 707 | } |
| 708 | } break; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 709 | case AUDIO_VOLUME: { |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 710 | ArrayList<Integer> vec = v.value.int32Values; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 711 | int volume = vec.get(VehicleAudioVolumeIndex.INDEX_VOLUME); |
| 712 | int streamNum = vec.get(VehicleAudioVolumeIndex.INDEX_STREAM); |
| 713 | int volumeState = vec.get(VehicleAudioVolumeIndex.INDEX_STATE); |
Keun-young Park | 6b3f719 | 2016-03-25 18:41:49 -0700 | [diff] [blame] | 714 | if (volumeListener != null) { |
| 715 | volumeListener.onVolumeChange(streamNum, volume, volumeState); |
| 716 | } |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 717 | } break; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 718 | case AUDIO_VOLUME_LIMIT: { |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 719 | ArrayList<Integer> vec = v.value.int32Values; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 720 | int stream = vec.get(VehicleAudioVolumeLimitIndex.STREAM); |
| 721 | int maxVolume = vec.get(VehicleAudioVolumeLimitIndex.MAX_VOLUME); |
Keun-young Park | 6b3f719 | 2016-03-25 18:41:49 -0700 | [diff] [blame] | 722 | if (volumeListener != null) { |
| 723 | volumeListener.onVolumeLimitChange(stream, maxVolume); |
| 724 | } |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 725 | } break; |
Keun-young Park | fe1a8f1 | 2017-01-17 20:06:34 -0800 | [diff] [blame] | 726 | case AUDIO_PARAMETERS: { |
| 727 | String params = v.value.stringValue; |
| 728 | if (parameterListener != null) { |
| 729 | parameterListener.onParameterChange(params); |
| 730 | } |
| 731 | } |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 732 | } |
| 733 | } |
Keun-young Park | 07182c7 | 2016-03-18 18:01:29 -0700 | [diff] [blame] | 734 | values.clear(); |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | @Override |
| 738 | public void dump(PrintWriter writer) { |
keunyoung | 5c7cb26 | 2015-10-19 10:47:45 -0700 | [diff] [blame] | 739 | writer.println("*Audio HAL*"); |
| 740 | writer.println(" audio H/W variant:" + mVariant); |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 741 | writer.println(" Supported properties"); |
| 742 | VehicleHal.dumpProperties(writer, mProperties.values()); |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | } |