1 /* 2 * Copyright (C) 2022 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.oem; 17 18 import android.annotation.NonNull; 19 import android.car.builtin.util.Slogf; 20 import android.car.oem.IOemCarAudioDuckingService; 21 import android.car.oem.OemCarAudioVolumeRequest; 22 import android.media.AudioAttributes; 23 import android.os.RemoteException; 24 25 import com.android.car.CarLog; 26 import com.android.internal.util.Preconditions; 27 28 import java.util.Collections; 29 import java.util.List; 30 31 /** 32 * Provides functionality of the OEM Audio Ducking Service. 33 */ 34 public final class CarOemAudioDuckingProxyService { 35 36 private static final String TAG = CarLog.tagFor(CarOemAudioDuckingProxyService.class); 37 private static final String CALLER_TAG = CarLog.tagFor(CarOemAudioDuckingProxyService.class); 38 39 private final CarOemProxyServiceHelper mHelper; 40 private final IOemCarAudioDuckingService mOemCarAudioDuckingService; 41 CarOemAudioDuckingProxyService(CarOemProxyServiceHelper helper, IOemCarAudioDuckingService oemAudioDuckingService)42 public CarOemAudioDuckingProxyService(CarOemProxyServiceHelper helper, 43 IOemCarAudioDuckingService oemAudioDuckingService) { 44 mHelper = helper; 45 mOemCarAudioDuckingService = oemAudioDuckingService; 46 } 47 48 /** 49 * Call to evaluate a ducking change. 50 */ 51 @NonNull evaluateAttributesToDuck( @onNull OemCarAudioVolumeRequest requestInfo)52 public List<AudioAttributes> evaluateAttributesToDuck( 53 @NonNull OemCarAudioVolumeRequest requestInfo) { 54 Preconditions.checkArgument(requestInfo != null, 55 "Audio ducking evaluation request can not be null"); 56 return mHelper.doBinderTimedCallWithDefaultValue(CALLER_TAG, 57 () -> { 58 try { 59 return mOemCarAudioDuckingService.evaluateAttributesToDuck(requestInfo); 60 } catch (RemoteException e) { 61 Slogf.e(TAG, e, "Ducking evaluation request " + requestInfo); 62 } 63 return Collections.EMPTY_LIST; 64 }, Collections.EMPTY_LIST); 65 } 66 } 67