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.util.Log; 20 21 /** 22 * Factory for constructing wrappers around IAudioControl HAL instances. 23 */ 24 public final class AudioControlFactory { 25 private static final String TAG = AudioControlWrapper.class.getSimpleName(); 26 27 /** 28 * Generates {@link AudioControlWrapper} for interacting with IAudioControl HAL service. Checks 29 * for V2.0 first, and then falls back to V1.0 if that is not available. Will throw if none is 30 * registered on the manifest. 31 * @return {@link AudioControlWrapper} for registered IAudioControl service. 32 */ newAudioControl()33 public static AudioControlWrapper newAudioControl() { 34 android.hardware.automotive.audiocontrol.V2_0.IAudioControl audioControlV2 = 35 AudioControlWrapperV2.getService(); 36 if (audioControlV2 != null) { 37 return new AudioControlWrapperV2(audioControlV2); 38 } 39 Log.i(TAG, "IAudioControl@V2.0 not in the manifest"); 40 41 android.hardware.automotive.audiocontrol.V1_0.IAudioControl audioControlV1 = 42 AudioControlWrapperV1.getService(); 43 if (audioControlV1 != null) { 44 Log.w(TAG, "IAudioControl V1.0 is deprecated. Consider upgrading to V2.0"); 45 return new AudioControlWrapperV1(audioControlV1); 46 } 47 48 throw new IllegalStateException("No version of AudioControl HAL in the manifest"); 49 } 50 } 51