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.annotation.Nullable; 20 import android.car.builtin.util.Slogf; 21 import android.car.oem.IOemCarAudioVolumeService; 22 import android.car.oem.OemCarAudioVolumeRequest; 23 import android.car.oem.OemCarVolumeChangeInfo; 24 import android.os.RemoteException; 25 import android.os.SystemClock; 26 import android.util.Log; 27 28 import com.android.car.CarLog; 29 import com.android.car.internal.util.IndentingPrintWriter; 30 import com.android.car.internal.util.LocalLog; 31 import com.android.internal.util.Preconditions; 32 33 /** 34 * Provides functionality of the OEM Audio Volume Service. 35 */ 36 public final class CarOemAudioVolumeProxyService { 37 38 private static final String TAG = CarLog.tagFor(CarOemAudioVolumeProxyService.class); 39 private static final int QUEUE_SIZE = 10; 40 41 private static final boolean DBG = Slogf.isLoggable(TAG, Log.DEBUG); 42 private static final String CALLER_TAG = CarLog.tagFor(CarOemAudioVolumeProxyService.class); 43 44 private final CarOemProxyServiceHelper mHelper; 45 private final IOemCarAudioVolumeService mOemCarAudioVolumeService; 46 @Nullable 47 private final LocalLog mLocalLog; // Is null if DBG is false. No logging will be produced. 48 CarOemAudioVolumeProxyService(CarOemProxyServiceHelper helper, IOemCarAudioVolumeService oemAudioVolumeService)49 public CarOemAudioVolumeProxyService(CarOemProxyServiceHelper helper, 50 IOemCarAudioVolumeService oemAudioVolumeService) { 51 mHelper = helper; 52 mOemCarAudioVolumeService = oemAudioVolumeService; 53 mLocalLog = DBG ? new LocalLog(QUEUE_SIZE) : null; 54 } 55 56 /** 57 * Call to evaluate a volume change. 58 */ 59 @NonNull getSuggestedGroupForVolumeChange( @onNull OemCarAudioVolumeRequest requestInfo, int volumeAdjustment)60 public OemCarVolumeChangeInfo getSuggestedGroupForVolumeChange( 61 @NonNull OemCarAudioVolumeRequest requestInfo, int volumeAdjustment) { 62 Preconditions.checkArgument(requestInfo != null, 63 "Audio volume evaluation request can not be null"); 64 65 long startTime = 0; 66 if (mLocalLog != null) { 67 startTime = SystemClock.uptimeMillis(); 68 } 69 70 OemCarVolumeChangeInfo result = mHelper.doBinderTimedCallWithDefaultValue(CALLER_TAG, 71 () -> { 72 try { 73 return mOemCarAudioVolumeService.getSuggestedGroupForVolumeChange( 74 requestInfo, volumeAdjustment); 75 } catch (RemoteException e) { 76 Slogf.e(TAG, e, 77 "Suggested group for volume Change with request " + requestInfo); 78 } 79 return OemCarVolumeChangeInfo.EMPTY_OEM_VOLUME_CHANGE; 80 }, OemCarVolumeChangeInfo.EMPTY_OEM_VOLUME_CHANGE); 81 82 if (mLocalLog != null) { 83 mLocalLog.log(startTime + ", " + (SystemClock.uptimeMillis() - startTime)); 84 } 85 86 return result; 87 } 88 dump(IndentingPrintWriter writer)89 public void dump(IndentingPrintWriter writer) { 90 if (mLocalLog == null) { 91 return; 92 } 93 writer.println("** Dump for CarOemAudioVolumeProxyService **"); 94 mLocalLog.dump(writer); 95 // This print statement is used to indicate the end of a test. Do not change or remove 96 // this statement. 97 writer.println("Dump CarOemAudioVolumeProxyService time log complete"); 98 } 99 } 100