1 /* 2 * Copyright (C) 2022 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.oemcarservice.testapp; 18 19 import android.car.CarVersion; 20 import android.car.oem.OemCarAudioDuckingService; 21 import android.car.oem.OemCarAudioFocusService; 22 import android.car.oem.OemCarAudioVolumeService; 23 import android.car.oem.OemCarService; 24 import android.util.Slog; 25 26 import com.android.internal.annotations.GuardedBy; 27 28 import java.io.FileDescriptor; 29 import java.io.PrintWriter; 30 31 public final class OemCarServiceImpl extends OemCarService { 32 33 private static final String TAG = OemCarServiceImpl.class.getSimpleName(); 34 private static final boolean DEBUG = true; 35 private static final CarVersion SUPPORTED_CAR_VERSION = 36 CarVersion.VERSION_CODES.UPSIDE_DOWN_CAKE_0; 37 38 private final Object mLock = new Object(); 39 @GuardedBy("mLock") 40 private OemCarAudioVolumeServiceImp mOemCarAudioVolumeService; 41 @GuardedBy("mLock") 42 private OemCarAudioFocusServiceImpl mOemCarAudioFocusServiceImpl; 43 @GuardedBy("mLock") 44 private OemCarAudioDuckingServiceImpl mOemCarAudioDuckingService; 45 46 @Override onCreate()47 public void onCreate() { 48 if (DEBUG) { 49 Slog.d(TAG, "onCreate"); 50 } 51 super.onCreate(); 52 } 53 54 @Override onDestroy()55 public void onDestroy() { 56 if (DEBUG) { 57 Slog.d(TAG, "onDestroy"); 58 } 59 // Releases resource from subcomponents. 60 super.onDestroy(); 61 } 62 63 @Override dump(FileDescriptor fd, PrintWriter writer, String[] args)64 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) { 65 if (DEBUG) { 66 Slog.d(TAG, "dump"); 67 } 68 writer.println("Dump OemCarServiceImpl"); 69 writer.printf("\tSUPPORTED_CAR_VERSION: %s\n", SUPPORTED_CAR_VERSION); 70 super.dump(fd, writer, args); 71 } 72 73 @Override getOemAudioFocusService()74 public OemCarAudioFocusService getOemAudioFocusService() { 75 if (DEBUG) { 76 Slog.d(TAG, "getOemAudioFocusService returning car audio focus service"); 77 } 78 synchronized (mLock) { 79 if (mOemCarAudioFocusServiceImpl == null) { 80 mOemCarAudioFocusServiceImpl = new OemCarAudioFocusServiceImpl( 81 getApplicationContext()); 82 } 83 return mOemCarAudioFocusServiceImpl; 84 } 85 } 86 87 @Override getOemAudioDuckingService()88 public OemCarAudioDuckingService getOemAudioDuckingService() { 89 if (DEBUG) { 90 Slog.d(TAG, "getOemAudioDuckingService returning car ducking service"); 91 } 92 synchronized (mLock) { 93 if (mOemCarAudioDuckingService == null) { 94 mOemCarAudioDuckingService = new OemCarAudioDuckingServiceImpl( 95 getApplicationContext()); 96 } 97 return mOemCarAudioDuckingService; 98 } 99 } 100 101 @Override getOemAudioVolumeService()102 public OemCarAudioVolumeService getOemAudioVolumeService() { 103 if (DEBUG) { 104 Slog.d(TAG, "getOemAudioVolumeService returning car ducking service"); 105 } 106 107 synchronized (mLock) { 108 if (mOemCarAudioVolumeService == null) { 109 mOemCarAudioVolumeService = new OemCarAudioVolumeServiceImp( 110 getApplicationContext()); 111 } 112 return mOemCarAudioVolumeService; 113 } 114 } 115 116 @Override onCarServiceReady()117 public void onCarServiceReady() { 118 if (DEBUG) { 119 Slog.d(TAG, "onCarServiceReady"); 120 } 121 } 122 123 @Override getSupportedCarVersion()124 public CarVersion getSupportedCarVersion() { 125 if (DEBUG) { 126 Slog.d(TAG, "OemCarServiceImpl getSupportedCarVersion called"); 127 } 128 return SUPPORTED_CAR_VERSION; 129 } 130 } 131