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.car.builtin.util.Slogf; 20 import android.media.AudioManager; 21 22 import com.android.car.CarLog; 23 24 import java.util.Objects; 25 26 final class CarAudioServerStateCallback extends AudioManager.AudioServerStateCallback { 27 28 private static final String TAG = CarLog.TAG_AUDIO; 29 private final CarAudioService mCarAudioService; 30 CarAudioServerStateCallback(CarAudioService carAudioService)31 CarAudioServerStateCallback(CarAudioService carAudioService) { 32 mCarAudioService = Objects.requireNonNull(carAudioService, 33 "Car audio service can not be null"); 34 } 35 36 @Override onAudioServerDown()37 public void onAudioServerDown() { 38 Slogf.w(TAG, "Audio server died, setting audio as disabled"); 39 mCarAudioService.releaseAudioCallbacks(/* isAudioServerDown= */ true); 40 } 41 42 @Override onAudioServerUp()43 public void onAudioServerUp() { 44 Slogf.w(TAG, "Audio server up"); 45 mCarAudioService.release(); 46 // No need to re-enable audio as initialization will query the power policy 47 // and enable as required. 48 mCarAudioService.init(); 49 } 50 } 51