1 /* 2 * Copyright (C) 2023 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 android.media.AudioDeviceCallback; 20 import android.media.AudioDeviceInfo; 21 22 import java.util.Objects; 23 24 /** 25 * Class to allow for car audio service to listen to audio device info updates. 26 * This can be used to monitor changes to dynamic devices as seen by the audio service. 27 */ 28 final class CarAudioDeviceCallback extends AudioDeviceCallback { 29 30 private final CarAudioService mCarAudioService; 31 CarAudioDeviceCallback(CarAudioService carAudioService)32 CarAudioDeviceCallback(CarAudioService carAudioService) { 33 mCarAudioService = Objects.requireNonNull(carAudioService, 34 "Car audio service can not be null"); 35 } 36 37 /** 38 * see {@link AudioDeviceCallback#onAudioDevicesAdded(AudioDeviceInfo[])} 39 */ 40 @Override onAudioDevicesAdded(AudioDeviceInfo[] addedDevices)41 public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) { 42 mCarAudioService.audioDevicesAdded(addedDevices); 43 } 44 45 /** 46 * see {@link AudioDeviceCallback#onAudioDevicesRemoved(AudioDeviceInfo[])} 47 */ 48 @Override onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices)49 public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) { 50 mCarAudioService.audioDevicesRemoved(removedDevices); 51 } 52 } 53