• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 public interface ICarBase {
32     /**
33      * Gets the context.
34      */
getContext()35     Context getContext();
36 
37     /**
38      * Gets the event handler.
39      */
getEventHandler()40     Handler getEventHandler();
41 
42     /**
43      * Handles a {@link RemoteException} thrown from car service.
44      */
handleRemoteExceptionFromCarService(RemoteException e, T returnValue)45     <T> T handleRemoteExceptionFromCarService(RemoteException e, T returnValue);
46 
47     /**
48      * Handles a {@link RemoteException} thrown from car service.
49      */
handleRemoteExceptionFromCarService(RemoteException e)50     void handleRemoteExceptionFromCarService(RemoteException e);
51 
52     /**
53      * Get car specific service manager as in {@link Context#getSystemService(String)}. Returned
54      * {@link Object} should be type-casted to the desired service manager.
55      *
56      * @deprecated Use {@link #getCarManager(Class)} instead.
57      *
58      * @param serviceName Name of service that should be created like {@link #SENSOR_SERVICE}.
59      * @return Matching service manager or null if there is no such service.
60      */
61     @Deprecated
62     @Nullable
getCarManager(String serviceName)63     Object getCarManager(String serviceName);
64 
65     /**
66      * Get car specific service manager by class as in {@link Context#getSystemService(Class)}.
67      * Returns the desired service. No type casting is needed.
68      *
69      * <p>For example, to get the manager for sensor service,
70      * <code>CarSensorManager carSensorManager = car.getCarManager(CarSensorManager.class);</code>
71      *
72      * @param serviceClass The class of the desired service.
73      * @return Matching service manager or {@code null} if there is no such service.
74      */
75     @Nullable
getCarManager(@onNull Class<T> serviceClass)76     <T> T getCarManager(@NonNull Class<T> serviceClass);
77 }
78