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.internal; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.Context; 22 import android.os.Handler; 23 import android.os.RemoteException; 24 25 /** 26 * ICarBase exposes the APIs in {@link android.car.Car} that are used internally by car service 27 * or car manager. 28 * 29 * This interface allows faking the implementation in unit tests. 30 * 31 * @hide 32 */ 33 public interface ICarBase { 34 /** 35 * Gets the context. 36 */ getContext()37 Context getContext(); 38 39 /** 40 * Gets the event handler. 41 */ getEventHandler()42 Handler getEventHandler(); 43 44 /** 45 * Handles a {@link RemoteException} thrown from car service. 46 */ handleRemoteExceptionFromCarService(RemoteException e, T returnValue)47 <T> T handleRemoteExceptionFromCarService(RemoteException e, T returnValue); 48 49 /** 50 * Handles a {@link RemoteException} thrown from car service. 51 */ handleRemoteExceptionFromCarService(RemoteException e)52 void handleRemoteExceptionFromCarService(RemoteException e); 53 54 /** 55 * Get car specific service manager as in {@link Context#getSystemService(String)}. Returned 56 * {@link Object} should be type-casted to the desired service manager. 57 * 58 * @deprecated Use {@link #getCarManager(Class)} instead. 59 * 60 * @param serviceName Name of service that should be created like {@link #SENSOR_SERVICE}. 61 * @return Matching service manager or null if there is no such service. 62 */ 63 @Deprecated 64 @Nullable getCarManager(String serviceName)65 Object getCarManager(String serviceName); 66 67 /** 68 * Get car specific service manager by class as in {@link Context#getSystemService(Class)}. 69 * Returns the desired service. No type casting is needed. 70 * 71 * <p>For example, to get the manager for sensor service, 72 * <code>CarSensorManager carSensorManager = car.getCarManager(CarSensorManager.class);</code> 73 * 74 * @param serviceClass The class of the desired service. 75 * @return Matching service manager or {@code null} if there is no such service. 76 */ 77 @Nullable getCarManager(@onNull Class<T> serviceClass)78 <T> T getCarManager(@NonNull Class<T> serviceClass); 79 } 80