• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 package android.car.test;
17 
18 import android.annotation.NonNull;
19 import android.annotation.RequiresPermission;
20 import android.annotation.TestApi;
21 import android.car.Car;
22 import android.car.CarManagerBase;
23 import android.car.annotation.AddedInOrBefore;
24 import android.car.annotation.ApiRequirements;
25 import android.os.IBinder;
26 import android.os.RemoteException;
27 
28 import java.util.List;
29 
30 /**
31  * API for testing only. Allows mocking vehicle hal.
32  *
33  * @hide
34  */
35 @TestApi
36 public final class CarTestManager extends CarManagerBase {
37 
38     private final ICarTest mService;
39 
40     /**
41      * Constructs a new {@link CarTestManager}
42      *
43      * @hide
44      */
45     @TestApi
CarTestManager(@onNull Car car, @NonNull IBinder carServiceBinder)46     public CarTestManager(@NonNull Car car, @NonNull IBinder carServiceBinder) {
47         super(car);
48         mService = ICarTest.Stub.asInterface(carServiceBinder);
49     }
50 
51     /**
52      * @hide
53      */
54     @Override
55     @AddedInOrBefore(majorVersion = 33)
onCarDisconnected()56     public void onCarDisconnected() {
57         // test will fail. nothing to do.
58     }
59 
60     /**
61      * Releases all car services. This make sense for test purpose when it is necessary to reduce
62      * interference between testing and real instances of Car Service. For example changing audio
63      * focus in CarAudioService may affect framework's AudioManager listeners. AudioManager has a
64      * lot of complex logic which is hard to mock.
65      *
66      * @hide
67      */
68     @TestApi
69     @RequiresPermission(Car.PERMISSION_CAR_TEST_SERVICE)
70     @AddedInOrBefore(majorVersion = 33)
stopCarService(@onNull IBinder token)71     public void stopCarService(@NonNull IBinder token) {
72         try {
73             mService.stopCarService(token);
74         } catch (RemoteException e) {
75             handleRemoteExceptionFromCarService(e);
76         }
77     }
78 
79     /**
80      * Re-initializes previously released car service.
81      *
82      * @see {@link #stopCarService(IBinder)}
83      *
84      * @hide
85      */
86     @TestApi
87     @RequiresPermission(Car.PERMISSION_CAR_TEST_SERVICE)
88     @AddedInOrBefore(majorVersion = 33)
startCarService(@onNull IBinder token)89     public void startCarService(@NonNull IBinder token) {
90         try {
91             mService.startCarService(token);
92         } catch (RemoteException e) {
93             handleRemoteExceptionFromCarService(e);
94         }
95     }
96 
97     /**
98      * Dumps VHAL information or debug VHAL.
99      *
100      * {@code waitTimeoutMs} specifies the longest time CarTestService will wait to receive all
101      * dumped information from VHAL before timeout. A correctly implemented VHAL should finish
102      * dumping all the info before returning. As a result, {@code waitTimeoutMs} is used to regulate
103      * how long CarTestService would wait before it determines that VHAL is dead or stuck and
104      * returns error.
105      *
106      * @hide
107      */
108     @TestApi
109     @RequiresPermission(Car.PERMISSION_CAR_TEST_SERVICE)
110     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
111              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
dumpVhal(List<String> options, long waitTimeoutMs)112     public String dumpVhal(List<String> options, long waitTimeoutMs) {
113         try {
114             return mService.dumpVhal(options, waitTimeoutMs);
115         } catch (RemoteException e) {
116             handleRemoteExceptionFromCarService(e);
117             return "";
118         }
119     }
120 
121     /**
122      * Returns whether AIDL VHAL is used for VHAL backend.
123      *
124      * @hide
125      */
126     @TestApi
127     @RequiresPermission(Car.PERMISSION_CAR_TEST_SERVICE)
128     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
129              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
hasAidlVhal()130     public boolean hasAidlVhal() throws RemoteException {
131         return mService.hasAidlVhal();
132     }
133 
134     /**
135      * Returns OEM service name.
136      *
137      * @hide
138      */
139     @TestApi
140     @RequiresPermission(Car.PERMISSION_CAR_TEST_SERVICE)
141     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
142              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
getOemServiceName()143     public String getOemServiceName() throws RemoteException {
144         return mService.getOemServiceName();
145     }
146 }
147