1 /* 2 * Copyright (C) 2019 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.audio; 17 18 import android.annotation.NonNull; 19 import android.car.media.ICarVolumeCallback; 20 import android.os.IBinder; 21 import android.os.RemoteException; 22 import android.util.Slog; 23 24 import com.android.car.BinderInterfaceContainer; 25 import com.android.car.CarLog; 26 27 /** 28 * Manages callbacks for changes in car volume 29 */ 30 class CarVolumeCallbackHandler { 31 private final BinderInterfaceContainer<ICarVolumeCallback> mVolumeCallbackContainer = 32 new BinderInterfaceContainer<>(); 33 release()34 void release() { 35 mVolumeCallbackContainer.clear(); 36 } 37 onVolumeGroupChange(int zoneId, int groupId, int flags)38 void onVolumeGroupChange(int zoneId, int groupId, int flags) { 39 for (BinderInterfaceContainer.BinderInterface<ICarVolumeCallback> callback : 40 mVolumeCallbackContainer.getInterfaces()) { 41 try { 42 callback.binderInterface.onGroupVolumeChanged(zoneId, groupId, flags); 43 } catch (RemoteException e) { 44 Slog.e(CarLog.TAG_AUDIO, "Failed to callback onGroupVolumeChanged", e); 45 } 46 } 47 } 48 onMasterMuteChanged(int zoneId, int flags)49 void onMasterMuteChanged(int zoneId, int flags) { 50 for (BinderInterfaceContainer.BinderInterface<ICarVolumeCallback> callback : 51 mVolumeCallbackContainer.getInterfaces()) { 52 try { 53 callback.binderInterface.onMasterMuteChanged(zoneId, flags); 54 } catch (RemoteException e) { 55 Slog.e(CarLog.TAG_AUDIO, "Failed to callback onMasterMuteChanged", e); 56 } 57 } 58 } 59 registerCallback(@onNull IBinder binder)60 public void registerCallback(@NonNull IBinder binder) { 61 mVolumeCallbackContainer.addBinder(ICarVolumeCallback.Stub.asInterface(binder)); 62 } 63 unregisterCallback(@onNull IBinder binder)64 public void unregisterCallback(@NonNull IBinder binder) { 65 mVolumeCallbackContainer.removeBinder(ICarVolumeCallback.Stub.asInterface(binder)); 66 } 67 onGroupMuteChange(int zoneId, int groupId, int flags)68 public void onGroupMuteChange(int zoneId, int groupId, int flags) { 69 for (BinderInterfaceContainer.BinderInterface<ICarVolumeCallback> callback : 70 mVolumeCallbackContainer.getInterfaces()) { 71 try { 72 callback.binderInterface.onGroupMuteChanged(zoneId, groupId, flags); 73 } catch (RemoteException e) { 74 Slog.e(CarLog.TAG_AUDIO, "Failed to callback onGroupMuteChanged", e); 75 } 76 } 77 } 78 } 79