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