1 /* 2 * Copyright (C) 2020 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.hal; 18 19 import android.os.IBinder; 20 import android.util.Slog; 21 22 import com.android.car.CarLog; 23 24 /** 25 * Factory for constructing wrappers around IAudioControl HAL instances. 26 */ 27 public final class AudioControlFactory { 28 private static final String TAG = CarLog.tagFor(AudioControlFactory.class); 29 AudioControlFactory()30 private AudioControlFactory() { 31 } 32 33 /** 34 * Generates {@link AudioControlWrapper} for interacting with IAudioControl HAL service. The HAL 35 * version priority is: Current AIDL, HIDL V2, HIDL V1. The wrapper will try to fetch the 36 * highest priority service, and then fall back to older versions if it's not available. The 37 * wrapper will throw if none is registered on the manifest. 38 * 39 * @return {@link AudioControlWrapper} for registered IAudioControl service. 40 */ newAudioControl()41 public static AudioControlWrapper newAudioControl() { 42 IBinder binder = AudioControlWrapperAidl.getService(); 43 if (binder != null) { 44 return new AudioControlWrapperAidl(binder); 45 } 46 Slog.i(TAG, "AIDL AudioControl HAL not in the manifest"); 47 48 android.hardware.automotive.audiocontrol.V2_0.IAudioControl audioControlV2 = 49 AudioControlWrapperV2.getService(); 50 if (audioControlV2 != null) { 51 return new AudioControlWrapperV2(audioControlV2); 52 } 53 Slog.i(TAG, "HIDL AudioControl@V2.0 not in the manifest"); 54 55 android.hardware.automotive.audiocontrol.V1_0.IAudioControl audioControlV1 = 56 AudioControlWrapperV1.getService(); 57 if (audioControlV1 != null) { 58 Slog.w(TAG, "HIDL AudioControl V1.0 is deprecated. Consider upgrading to AIDL"); 59 return new AudioControlWrapperV1(audioControlV1); 60 } 61 62 throw new IllegalStateException("No version of AudioControl HAL in the manifest"); 63 } 64 } 65