1 /* 2 * Copyright (C) 2024 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.car.audio; 18 19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 20 21 import android.car.media.CarVolumeGroupEvent; 22 import android.car.media.ICarVolumeEventCallback; 23 24 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 25 26 import java.util.List; 27 import java.util.concurrent.CountDownLatch; 28 import java.util.concurrent.TimeUnit; 29 30 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 31 final class TestCarVolumeEventCallback extends ICarVolumeEventCallback.Stub { 32 private final long mTimeOutMs; 33 private CountDownLatch mStatusLatch = new CountDownLatch(1); 34 private List<CarVolumeGroupEvent> mVolumeGroupEvents; 35 TestCarVolumeEventCallback(long timeOutMs)36 TestCarVolumeEventCallback(long timeOutMs) { 37 mTimeOutMs = timeOutMs; 38 } 39 40 @Override onVolumeGroupEvent(List<CarVolumeGroupEvent> volumeGroupEvents)41 public void onVolumeGroupEvent(List<CarVolumeGroupEvent> volumeGroupEvents) { 42 mVolumeGroupEvents = volumeGroupEvents; 43 mStatusLatch.countDown(); 44 } 45 46 @Override onMasterMuteChanged(int zoneId, int flags)47 public void onMasterMuteChanged(int zoneId, int flags) { 48 mStatusLatch.countDown(); 49 } 50 waitForCallback()51 boolean waitForCallback() throws Exception { 52 return mStatusLatch.await(mTimeOutMs, TimeUnit.MILLISECONDS); 53 } 54 getVolumeGroupEvents()55 List<CarVolumeGroupEvent> getVolumeGroupEvents() { 56 return mVolumeGroupEvents; 57 } 58 reset()59 public void reset() { 60 mVolumeGroupEvents = null; 61 mStatusLatch = new CountDownLatch(1); 62 } 63 } 64