blob: 51d2ad0b072dcc9ba992b12b61acb4e9ce6bf666 [file] [log] [blame]
keunyoungca515072015-07-10 12:21:47 -07001/*
2 * Copyright (C) 2015 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
17package com.android.car;
18
Pavel Maltsevabd47232017-10-10 16:54:57 -070019import android.annotation.MainThread;
Keun young Parkf3523cd2019-04-08 10:09:17 -070020import android.app.ActivityManager;
Yao Chene33f07e2016-07-26 12:02:51 -070021import android.app.UiModeManager;
Keun-young Parke54ac272016-02-16 19:02:18 -080022import android.car.Car;
23import android.car.ICar;
Pavel Maltsev0477e292016-05-27 12:22:36 -070024import android.car.cluster.renderer.IInstrumentClusterNavigation;
Ying Zheng9fc99402018-09-19 14:23:59 -070025import android.car.userlib.CarUserManagerHelper;
keunyoungca515072015-07-10 12:21:47 -070026import android.content.Context;
keunyoung1ab8e182015-09-24 09:25:22 -070027import android.content.pm.PackageManager;
Keun young Parkf3523cd2019-04-08 10:09:17 -070028import android.content.res.Resources;
Pavel Maltsevcfe93102017-02-02 12:38:08 -080029import android.hardware.automotive.vehicle.V2_0.IVehicle;
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -080030import android.hardware.automotive.vehicle.V2_0.VehicleArea;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070031import android.os.Binder;
Enrico Granatae8056ca2018-04-03 13:19:52 -070032import android.os.Build;
keunyoungca515072015-07-10 12:21:47 -070033import android.os.IBinder;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070034import android.os.Process;
Steve Paikc302c7c2017-08-04 14:01:58 -070035import android.os.Trace;
keunyoungca515072015-07-10 12:21:47 -070036import android.util.Log;
Steve Paikc302c7c2017-08-04 14:01:58 -070037import android.util.Slog;
Keun-young Park4a79a382017-08-10 18:19:14 -070038import android.util.TimingsTraceLog;
Gregory Clark26fa6012018-03-14 18:38:56 -070039
Hongwei Wang38549092018-08-22 12:32:42 -070040import com.android.car.audio.CarAudioService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080041import com.android.car.cluster.InstrumentClusterService;
Serik Beketayev06a66682018-06-12 16:54:29 -070042import com.android.car.garagemode.GarageModeService;
keunyoungcc449f72015-08-12 10:46:27 -070043import com.android.car.hal.VehicleHal;
Antonio Cortesc52d5f92017-02-06 08:47:38 -080044import com.android.car.internal.FeatureConfiguration;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080045import com.android.car.pm.CarPackageManagerService;
Enrico Granatab19bc322017-10-12 12:25:06 -070046import com.android.car.systeminterface.SystemInterface;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070047import com.android.car.trust.CarTrustedDeviceService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070048import com.android.car.user.CarUserService;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080049import com.android.car.vms.VmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -080050import com.android.car.vms.VmsClientManager;
keunyoungca515072015-07-10 12:21:47 -070051import com.android.internal.annotations.GuardedBy;
Steve Paik1d8bea22018-02-03 01:54:06 +000052import com.android.internal.car.ICarServiceHelper;
Gregory Clark26fa6012018-03-14 18:38:56 -070053
Enrico Granatae8056ca2018-04-03 13:19:52 -070054import java.io.FileDescriptor;
keunyounga3b28d82015-08-25 13:05:15 -070055import java.io.PrintWriter;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070056import java.util.ArrayList;
Antonio Cortese4619c72017-02-02 07:53:27 -080057import java.util.Arrays;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070058import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070059
keunyoungca515072015-07-10 12:21:47 -070060public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070061
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -080062 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070063 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
64 "system_activity_monitoring";
Keun-young Parka28d7b22016-02-29 16:54:29 -080065
keunyoungca515072015-07-10 12:21:47 -070066 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080067 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070068
Anthony Chen12aec302018-04-25 16:41:48 -070069 private final SystemInterface mSystemInterface;
70
Keun-young Park4727da32016-05-31 10:00:51 -070071 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070072 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080073 private final CarPackageManagerService mCarPackageManagerService;
74 private final CarInputService mCarInputService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -080075 private final CarDrivingStateService mCarDrivingStateService;
Ram Periathiruvadi4526a432018-01-24 13:00:54 -080076 private final CarUxRestrictionsManagerService mCarUXRestrictionsService;
keunyoungd32f4e62015-09-21 11:33:06 -070077 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080078 private final CarProjectionService mCarProjectionService;
Steve Paik9ec53d72018-04-27 13:28:31 -070079 private final CarPropertyService mCarPropertyService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080080 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070081 private final AppFocusService mAppFocusService;
Yao Chen3a7976d2016-01-20 17:27:08 -080082 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080083 private final InstrumentClusterService mInstrumentClusterService;
Gregory Clarkd8136062017-12-11 14:27:53 -080084 private final CarLocationService mCarLocationService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070085 private final SystemStateControllerService mSystemStateControllerService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080086 private final CarBluetoothService mCarBluetoothService;
Ram Periathiruvadiacb60242017-04-13 16:19:09 -070087 private final PerUserCarServiceHelper mPerUserCarServiceHelper;
Enrico Granata9a916d72017-09-19 14:33:08 -070088 private final CarDiagnosticService mCarDiagnosticService;
89 private final CarStorageMonitoringService mCarStorageMonitoringService;
Anthony Chen12aec302018-04-25 16:41:48 -070090 private final CarConfigurationService mCarConfigurationService;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070091 private final CarTrustedDeviceService mCarTrustedDeviceService;
Simon Dai527eb552019-02-12 13:06:15 -080092 private final CarMediaService mCarMediaService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070093 private final CarUserManagerHelper mUserManagerHelper;
Keun-young Parkd462a912019-02-11 08:53:42 -080094 private final CarUserService mCarUserService;
Mark Tabrya8fce562019-01-16 16:24:01 -080095 private final VmsClientManager mVmsClientManager;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080096 private final VmsBrokerService mVmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -080097 private final VmsSubscriberService mVmsSubscriberService;
98 private final VmsPublisherService mVmsPublisherService;
keunyounga74b9ca2015-10-21 13:33:58 -070099
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700100 private final CarServiceBase[] mAllServices;
101
Steve Paikc302c7c2017-08-04 14:01:58 -0700102 private static final String TAG = "ICarImpl";
103 private static final String VHAL_TIMING_TAG = "VehicleHalTiming";
Serik Beketayev74debf22018-10-04 12:18:09 -0700104
105 private TimingsTraceLog mBootTiming;
Steve Paikc302c7c2017-08-04 14:01:58 -0700106
keunyoung1ab8e182015-09-24 09:25:22 -0700107 /** Test only service. Populate it only when necessary. */
108 @GuardedBy("this")
109 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -0700110
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700111 @GuardedBy("this")
112 private ICarServiceHelper mICarServiceHelper;
113
Enrico Granatae8056ca2018-04-03 13:19:52 -0700114 private final String mVehicleInterfaceName;
115
Pavel Maltsevec83b632017-01-05 15:10:55 -0800116 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
Enrico Granatae8056ca2018-04-03 13:19:52 -0700117 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) {
keunyoungca515072015-07-10 12:21:47 -0700118 mContext = serviceContext;
Steve Paik0f9fc002018-02-09 17:42:00 -0800119 mSystemInterface = systemInterface;
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700120 mHal = new VehicleHal(vehicle);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700121 mVehicleInterfaceName = vehicleInterfaceName;
Yao, Yuxing0811d5a2018-11-29 16:18:53 -0800122 mUserManagerHelper = new CarUserManagerHelper(serviceContext);
Keun young Parkf3523cd2019-04-08 10:09:17 -0700123 final Resources res = mContext.getResources();
124 final int maxRunningUsers = res.getInteger(
125 com.android.internal.R.integer.config_multiuserMaxRunningUsers);
126 mCarUserService = new CarUserService(serviceContext, mUserManagerHelper,
127 ActivityManager.getService(), maxRunningUsers);
Keun-young Park4727da32016-05-31 10:00:51 -0700128 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Steve Paik388d7772018-02-12 10:54:51 -0800129 mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(),
Keun young Park9b3f2662019-03-19 10:30:25 -0700130 systemInterface, mUserManagerHelper);
Steve Paik9ec53d72018-04-27 13:28:31 -0700131 mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal());
132 mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService);
Ram Periathiruvadi4526a432018-01-24 13:00:54 -0800133 mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext,
Yao, Yuxing9bfb7492019-02-15 11:53:34 -0800134 mCarDrivingStateService, mCarPropertyService);
Ram Periathiruvadi2da6d0e2018-01-26 18:02:10 -0800135 mCarPackageManagerService = new CarPackageManagerService(serviceContext,
136 mCarUXRestrictionsService,
Pavel Maltsev38da4312019-04-08 10:38:38 -0700137 mSystemActivityMonitoringService,
138 mUserManagerHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800139 mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext);
140 mCarBluetoothService = new CarBluetoothService(serviceContext, mCarPropertyService,
141 mPerUserCarServiceHelper, mCarUXRestrictionsService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700142 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Justin Paupore44985ba2019-01-30 18:53:41 -0800143 mCarProjectionService = new CarProjectionService(
Pavel Maltsev079873b2019-02-25 12:15:09 -0800144 serviceContext, null /* handler */, mCarInputService, mCarBluetoothService);
Serik Beketayevc6ab8be2018-08-28 21:20:53 -0700145 mGarageModeService = new GarageModeService(mContext);
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700146 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Hongwei Wang30557232018-01-02 10:25:08 -0800147 mCarAudioService = new CarAudioService(serviceContext);
Steve Paik9ec53d72018-04-27 13:28:31 -0700148 mCarNightService = new CarNightService(serviceContext, mCarPropertyService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700149 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700150 mAppFocusService, mCarInputService);
Serik Beketayevf9f2ef02018-09-06 12:37:02 -0700151 mSystemStateControllerService = new SystemStateControllerService(
152 serviceContext, mCarAudioService, this);
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800153 mVmsBrokerService = new VmsBrokerService();
Mark Tabry1534c062019-03-29 01:30:49 -0700154 mVmsClientManager = new VmsClientManager(
Mark Tabry41437562019-04-04 10:37:33 -0700155 serviceContext, mCarUserService, mUserManagerHelper, mHal.getVmsHal());
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800156 mVmsSubscriberService = new VmsSubscriberService(
157 serviceContext, mVmsBrokerService, mHal.getVmsHal());
158 mVmsPublisherService = new VmsPublisherService(
Mark Tabry1534c062019-03-29 01:30:49 -0700159 serviceContext, mVmsBrokerService, mVmsClientManager);
Enrico Granatab3634e22017-05-05 18:02:31 -0700160 mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal());
Enrico Granata517a1e02017-09-20 16:15:50 -0700161 mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext,
162 systemInterface);
Anthony Chen12aec302018-04-25 16:41:48 -0700163 mCarConfigurationService =
164 new CarConfigurationService(serviceContext, new JsonReaderImpl());
Gregory Clarka440e812019-02-14 16:05:51 -0800165 mCarLocationService = new CarLocationService(mContext, mCarPropertyService,
166 mUserManagerHelper);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700167 mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext);
Simon Dai527eb552019-02-12 13:06:15 -0800168 mCarMediaService = new CarMediaService(serviceContext);
keunyounga74b9ca2015-10-21 13:33:58 -0700169
Keun-young Parkd462a912019-02-11 08:53:42 -0800170 CarLocalServices.addService(CarUserService.class, mCarUserService);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700171 Log.d(TAG, "Adding CarTrustedDeviceService");
172 CarLocalServices.addService(CarTrustedDeviceService.class,
173 mCarTrustedDeviceService);
Gregory Clarka440e812019-02-14 16:05:51 -0800174 CarLocalServices.addService(SystemInterface.class, mSystemInterface);
Keun-young Parkd462a912019-02-11 08:53:42 -0800175
keunyounga3b28d82015-08-25 13:05:15 -0700176 // Be careful with order. Service depending on other service should be inited later.
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700177 List<CarServiceBase> allServices = new ArrayList<>();
Keun-young Parkd462a912019-02-11 08:53:42 -0800178 allServices.add(mCarUserService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700179 allServices.add(mSystemActivityMonitoringService);
180 allServices.add(mCarPowerManagementService);
181 allServices.add(mCarPropertyService);
182 allServices.add(mCarDrivingStateService);
183 allServices.add(mCarUXRestrictionsService);
184 allServices.add(mCarPackageManagerService);
185 allServices.add(mCarInputService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700186 allServices.add(mGarageModeService);
187 allServices.add(mAppFocusService);
188 allServices.add(mCarAudioService);
189 allServices.add(mCarNightService);
190 allServices.add(mInstrumentClusterService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700191 allServices.add(mSystemStateControllerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700192 allServices.add(mPerUserCarServiceHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800193 allServices.add(mCarBluetoothService);
194 allServices.add(mCarProjectionService);
195 allServices.add(mCarDiagnosticService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700196 allServices.add(mCarStorageMonitoringService);
197 allServices.add(mCarConfigurationService);
Mark Tabrya8fce562019-01-16 16:24:01 -0800198 allServices.add(mVmsClientManager);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700199 allServices.add(mVmsSubscriberService);
200 allServices.add(mVmsPublisherService);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700201 allServices.add(mCarTrustedDeviceService);
Simon Dai527eb552019-02-12 13:06:15 -0800202 allServices.add(mCarMediaService);
Gregory Clarka63ba022018-06-07 16:42:12 -0700203 allServices.add(mCarLocationService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700204 mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]);
keunyoungca515072015-07-10 12:21:47 -0700205 }
206
Pavel Maltsevabd47232017-10-10 16:54:57 -0700207 @MainThread
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700208 void init() {
Serik Beketayev74debf22018-10-04 12:18:09 -0700209 mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL);
Steve Paikc302c7c2017-08-04 14:01:58 -0700210 traceBegin("VehicleHal.init");
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700211 mHal.init();
Steve Paikc302c7c2017-08-04 14:01:58 -0700212 traceEnd();
213 traceBegin("CarService.initAllServices");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800214 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700215 service.init();
216 }
Steve Paikc302c7c2017-08-04 14:01:58 -0700217 traceEnd();
keunyoungca515072015-07-10 12:21:47 -0700218 }
219
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700220 void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700221 // release done in opposite order from init
222 for (int i = mAllServices.length - 1; i >= 0; i--) {
223 mAllServices[i].release();
224 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700225 mHal.release();
Keun-young Parkd462a912019-02-11 08:53:42 -0800226 CarLocalServices.removeAllServices();
keunyoung1ab8e182015-09-24 09:25:22 -0700227 }
228
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700229 void vehicleHalReconnected(IVehicle vehicle) {
Pavel Maltsevec83b632017-01-05 15:10:55 -0800230 mHal.vehicleHalReconnected(vehicle);
231 for (CarServiceBase service : mAllServices) {
232 service.vehicleHalReconnected();
233 }
234 }
235
keunyoungca515072015-07-10 12:21:47 -0700236 @Override
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700237 public void setCarServiceHelper(IBinder helper) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700238 assertCallingFromSystemProcess();
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700239 synchronized (this) {
240 mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper);
Steve Paik0f9fc002018-02-09 17:42:00 -0800241 mSystemInterface.setCarServiceHelper(mICarServiceHelper);
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700242 }
243 }
244
245 @Override
Keun-young Parkd462a912019-02-11 08:53:42 -0800246 public void setUserLockStatus(int userHandle, int unlocked) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700247 assertCallingFromSystemProcess();
248 mCarUserService.setUserLockStatus(userHandle, unlocked == 1);
249 }
250
251 @Override
252 public void onSwitchUser(int userHandle) {
253 assertCallingFromSystemProcess();
254
255 Log.i(TAG, "Foreground user switched to " + userHandle);
256 mCarUserService.onSwitchUser(userHandle);
257 }
258
259 private static void assertCallingFromSystemProcess() {
Keun-young Parkd462a912019-02-11 08:53:42 -0800260 int uid = Binder.getCallingUid();
261 if (uid != Process.SYSTEM_UID) {
262 throw new SecurityException("Only allowed from system");
263 }
Keun-young Parkd462a912019-02-11 08:53:42 -0800264 }
265
266 @Override
keunyoungca515072015-07-10 12:21:47 -0700267 public IBinder getCarService(String serviceName) {
268 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800269 case Car.AUDIO_SERVICE:
270 return mCarAudioService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700271 case Car.APP_FOCUS_SERVICE:
272 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800273 case Car.PACKAGE_SERVICE:
274 return mCarPackageManagerService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800275 case Car.DIAGNOSTIC_SERVICE:
Enrico Granatab3634e22017-05-05 18:02:31 -0700276 assertAnyDiagnosticPermission(mContext);
277 return mCarDiagnosticService;
Steve Paik388d7772018-02-12 10:54:51 -0800278 case Car.POWER_SERVICE:
279 assertPowerPermission(mContext);
280 return mCarPowerManagementService;
Steve Paik9ec53d72018-04-27 13:28:31 -0700281 case Car.CABIN_SERVICE:
282 case Car.HVAC_SERVICE:
283 case Car.INFO_SERVICE:
284 case Car.PROPERTY_SERVICE:
285 case Car.SENSOR_SERVICE:
286 case Car.VENDOR_EXTENSION_SERVICE:
287 return mCarPropertyService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800288 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700289 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700290 IInstrumentClusterNavigation navService =
291 mInstrumentClusterService.getNavigationService();
292 return navService == null ? null : navService.asBinder();
Pavel Maltsev905968c2017-07-16 19:48:57 -0700293 case Car.CAR_INSTRUMENT_CLUSTER_SERVICE:
294 assertClusterManagerPermission(mContext);
295 return mInstrumentClusterService.getManagerService();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800296 case Car.PROJECTION_SERVICE:
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800297 return mCarProjectionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800298 case Car.VMS_SUBSCRIBER_SERVICE:
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700299 assertVmsSubscriberPermission(mContext);
300 return mVmsSubscriberService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800301 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700302 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700303 synchronized (this) {
304 if (mCarTestService == null) {
305 mCarTestService = new CarTestService(mContext, this);
306 }
307 return mCarTestService;
308 }
309 }
Ram Periathiruvadi76a84892017-07-27 18:10:35 -0700310 case Car.BLUETOOTH_SERVICE:
311 return mCarBluetoothService;
Enrico Granata9a916d72017-09-19 14:33:08 -0700312 case Car.STORAGE_MONITORING_SERVICE:
Enrico Granata1172f882017-09-21 14:51:30 -0700313 assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING);
Enrico Granata9a916d72017-09-19 14:33:08 -0700314 return mCarStorageMonitoringService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800315 case Car.CAR_DRIVING_STATE_SERVICE:
316 assertDrivingStatePermission(mContext);
317 return mCarDrivingStateService;
318 case Car.CAR_UX_RESTRICTION_SERVICE:
319 return mCarUXRestrictionsService;
Anthony Chend4203d82018-05-16 16:21:52 -0700320 case Car.CAR_CONFIGURATION_SERVICE:
321 return mCarConfigurationService;
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800322 case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE:
323 assertTrustAgentEnrollmentPermission(mContext);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700324 return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService();
Simon Dai527eb552019-02-12 13:06:15 -0800325 case Car.CAR_MEDIA_SERVICE:
326 return mCarMediaService;
keunyoungca515072015-07-10 12:21:47 -0700327 default:
328 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
329 return null;
330 }
331 }
332
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800333 @Override
334 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700335 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800336 }
337
Keun-young Parka28d7b22016-02-29 16:54:29 -0800338 public CarServiceBase getCarInternalService(String serviceName) {
339 switch (serviceName) {
340 case INTERNAL_INPUT_SERVICE:
341 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700342 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
343 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800344 default:
345 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
346 serviceName);
347 return null;
348 }
349 }
350
keunyoung1ab8e182015-09-24 09:25:22 -0700351 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700352 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700353 }
354
Keun-young Parke31a8b22016-03-16 17:34:08 -0700355 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700356 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800357 }
358
Pavel Maltsev905968c2017-07-16 19:48:57 -0700359 public static void assertClusterManagerPermission(Context context) {
360 assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL);
361 }
362
Steve Paik388d7772018-02-12 10:54:51 -0800363 public static void assertPowerPermission(Context context) {
364 assertPermission(context, Car.PERMISSION_CAR_POWER);
365 }
366
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800367 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700368 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
369 }
370
Pavel Maltsev079873b2019-02-25 12:15:09 -0800371 /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */
372 public static void assertProjectionStatusPermission(Context context) {
373 assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS);
374 }
375
Enrico Granata3c7a6662017-02-23 18:07:59 -0800376 public static void assertAnyDiagnosticPermission(Context context) {
377 assertAnyPermission(context,
Enrico Granataae25b922017-07-07 11:28:15 -0700378 Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL,
Enrico Granata3c7a6662017-02-23 18:07:59 -0800379 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
380 }
381
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800382 public static void assertDrivingStatePermission(Context context) {
383 assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE);
384 }
385
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800386 public static void assertVmsPublisherPermission(Context context) {
387 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
388 }
389
Antonio Cortese4619c72017-02-02 07:53:27 -0800390 public static void assertVmsSubscriberPermission(Context context) {
391 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
392 }
393
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800394 /**
395 * Ensures the caller has the permission to enroll a Trust Agent.
396 * @param context
397 */
398 public static void assertTrustAgentEnrollmentPermission(Context context) {
399 assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST);
400 }
401
Steve Paik461ecc62016-06-08 15:28:32 -0700402 public static void assertPermission(Context context, String permission) {
403 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
404 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800405 }
406 }
407
Steve Paik9ec53d72018-04-27 13:28:31 -0700408 /**
409 * Checks to see if the caller has a permission.
410 * @param context
411 * @param permission
412 *
413 * @return boolean TRUE if caller has the permission.
414 */
415 public static boolean hasPermission(Context context, String permission) {
416 return context.checkCallingOrSelfPermission(permission)
417 == PackageManager.PERMISSION_GRANTED;
418 }
419
Enrico Granata3c7a6662017-02-23 18:07:59 -0800420 public static void assertAnyPermission(Context context, String... permissions) {
421 for (String permission : permissions) {
422 if (context.checkCallingOrSelfPermission(permission) ==
423 PackageManager.PERMISSION_GRANTED) {
424 return;
425 }
426 }
427 throw new SecurityException("requires any of " + Arrays.toString(permissions));
428 }
429
Enrico Granatae8056ca2018-04-03 13:19:52 -0700430 @Override
431 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
432 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Anthony Chen12aec302018-04-25 16:41:48 -0700433 != PackageManager.PERMISSION_GRANTED) {
Enrico Granatae8056ca2018-04-03 13:19:52 -0700434 writer.println("Permission Denial: can't dump CarService from from pid="
Anthony Chen12aec302018-04-25 16:41:48 -0700435 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
436 + " without permission " + android.Manifest.permission.DUMP);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700437 return;
keunyounga3b28d82015-08-25 13:05:15 -0700438 }
Enrico Granatae8056ca2018-04-03 13:19:52 -0700439 if (args == null || args.length == 0) {
440 writer.println("*dump car service*");
441
442 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
443 writer.println("*Dump all services*");
444 for (CarServiceBase service : mAllServices) {
445 dumpService(service, writer);
446 }
447 if (mCarTestService != null) {
448 dumpService(mCarTestService, writer);
449 }
450 writer.println("*Dump Vehicle HAL*");
451 writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName);
452 try {
453 // TODO dump all feature flags by creating a dumpable interface
454 mHal.dump(writer);
455 } catch (Exception e) {
456 writer.println("Failed dumping: " + mHal.getClass().getName());
457 e.printStackTrace(writer);
458 }
459 } else if (Build.IS_USERDEBUG || Build.IS_ENG) {
460 execShellCmd(args, writer);
461 } else {
462 writer.println("Commands not supported in " + Build.TYPE);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800463 }
464 }
465
466 private void dumpService(CarServiceBase service, PrintWriter writer) {
467 try {
468 service.dump(writer);
469 } catch (Exception e) {
470 writer.println("Failed dumping: " + service.getClass().getName());
471 e.printStackTrace(writer);
472 }
keunyoungcc449f72015-08-12 10:46:27 -0700473 }
Yao Chene33f07e2016-07-26 12:02:51 -0700474
475 void execShellCmd(String[] args, PrintWriter writer) {
476 new CarShellCommand().exec(args, writer);
477 }
478
Pavel Maltsevabd47232017-10-10 16:54:57 -0700479 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700480 private void traceBegin(String name) {
Steve Paikc302c7c2017-08-04 14:01:58 -0700481 Slog.i(TAG, name);
482 mBootTiming.traceBegin(name);
483 }
484
Pavel Maltsevabd47232017-10-10 16:54:57 -0700485 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700486 private void traceEnd() {
Steve Paikc302c7c2017-08-04 14:01:58 -0700487 mBootTiming.traceEnd();
488 }
489
Yao Chene33f07e2016-07-26 12:02:51 -0700490 private class CarShellCommand {
491 private static final String COMMAND_HELP = "-h";
492 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800493 private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event";
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800494 private static final String COMMAND_ENABLE_UXR = "enable-uxr";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800495 private static final String COMMAND_GARAGE_MODE = "garage-mode";
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800496 private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities";
Kaidd4ef5a2019-03-04 14:07:26 -0800497 private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig";
Pavel Maltsev48a31942019-03-03 22:08:28 -0800498 private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode";
Jim Kayed76c2742019-04-02 11:33:27 -0700499 private static final String COMMAND_RESUME = "resume";
500 private static final String COMMAND_SUSPEND = "suspend";
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700501 private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device";
502 private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800503
Yao Chene33f07e2016-07-26 12:02:51 -0700504 private static final String PARAM_DAY_MODE = "day";
505 private static final String PARAM_NIGHT_MODE = "night";
506 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800507 private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800508 private static final String PARAM_ON_MODE = "on";
509 private static final String PARAM_OFF_MODE = "off";
510 private static final String PARAM_QUERY_MODE = "query";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800511
Yao Chene33f07e2016-07-26 12:02:51 -0700512
513 private void dumpHelp(PrintWriter pw) {
514 pw.println("Car service commands:");
515 pw.println("\t-h");
516 pw.println("\t Print this help text.");
517 pw.println("\tday-night-mode [day|night|sensor]");
518 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800519 pw.println("\tinject-vhal-event property [zone] data(can be comma separated list)");
Jim Kayef10b7d82019-02-26 12:53:22 -0800520 pw.println("\t Inject a vehicle property for testing.");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700521 pw.println("\tenable-uxr true|false");
522 pw.println("\t Enable/Disable UX restrictions and App blocking.");
Bryan Eylera32a7c12018-02-27 15:40:00 -0800523 pw.println("\tgarage-mode [on|off|query]");
524 pw.println("\t Force into garage mode or check status.");
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800525 pw.println("\tget-do-activities pkgname");
Jim Kayef10b7d82019-02-26 12:53:22 -0800526 pw.println("\t Get Distraction Optimized activities in given package.");
Kaidd4ef5a2019-03-04 14:07:26 -0800527 pw.println("\tget-carpropertyconfig [propertyId]");
528 pw.println("\t Get a CarPropertyConfig by Id in Hex or list all CarPropertyConfigs");
Jim Kayed76c2742019-04-02 11:33:27 -0700529 pw.println("\tsuspend");
530 pw.println("\t Suspend the system to Deep Sleep.");
531 pw.println("\tresume");
532 pw.println("\t Wake the system up after a 'suspend.'");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700533 pw.println("\tenable-trusted-device true|false");
534 pw.println("\t Enable/Disable Trusted device feature.");
535 pw.println("\tremove-trusted-devices");
536 pw.println("\t Remove all trusted devices for the current foreground user.");
Yao Chene33f07e2016-07-26 12:02:51 -0700537 }
538
539 public void exec(String[] args, PrintWriter writer) {
540 String arg = args[0];
541 switch (arg) {
542 case COMMAND_HELP:
543 dumpHelp(writer);
544 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800545 case COMMAND_DAY_NIGHT_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800546 String value = args.length < 2 ? "" : args[1];
Yao Chene33f07e2016-07-26 12:02:51 -0700547 forceDayNightMode(value, writer);
548 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800549 }
550 case COMMAND_GARAGE_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800551 String value = args.length < 2 ? "" : args[1];
Bryan Eylera32a7c12018-02-27 15:40:00 -0800552 forceGarageMode(value, writer);
553 break;
554 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800555 case COMMAND_INJECT_VHAL_EVENT:
556 String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL;
557 String data;
Jim Kayef10b7d82019-02-26 12:53:22 -0800558 if (args.length != 3 && args.length != 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800559 writer.println("Incorrect number of arguments.");
560 dumpHelp(writer);
561 break;
Jim Kayef10b7d82019-02-26 12:53:22 -0800562 } else if (args.length == 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800563 // Zoned
564 zone = args[2];
565 data = args[3];
566 } else {
567 // Global
568 data = args[2];
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800569 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800570 injectVhalEvent(args[1], zone, data, writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800571 break;
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800572 case COMMAND_ENABLE_UXR:
Jim Kayef10b7d82019-02-26 12:53:22 -0800573 if (args.length != 2) {
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800574 writer.println("Incorrect number of arguments");
575 dumpHelp(writer);
576 break;
577 }
578 boolean enableBlocking = Boolean.valueOf(args[1]);
579 if (mCarPackageManagerService != null) {
580 mCarPackageManagerService.setEnableActivityBlocking(enableBlocking);
581 }
582 break;
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800583 case COMMAND_GET_DO_ACTIVITIES:
Jim Kayef10b7d82019-02-26 12:53:22 -0800584 if (args.length != 2) {
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800585 writer.println("Incorrect number of arguments");
586 dumpHelp(writer);
587 break;
588 }
589 String pkgName = args[1].toLowerCase();
590 if (mCarPackageManagerService != null) {
591 String[] doActivities =
592 mCarPackageManagerService.getDistractionOptimizedActivities(
593 pkgName);
594 if (doActivities != null) {
595 writer.println("DO Activities for " + pkgName);
596 for (String a : doActivities) {
597 writer.println(a);
598 }
599 } else {
600 writer.println("No DO Activities for " + pkgName);
601 }
602 }
603 break;
Kaidd4ef5a2019-03-04 14:07:26 -0800604 case COMMAND_GET_CARPROPERTYCONFIG:
605 String propertyId = args.length < 2 ? "" : args[1];
606 mHal.dumpPropertyConfigs(writer, propertyId);
607 break;
Pavel Maltsev48a31942019-03-03 22:08:28 -0800608 case COMMAND_PROJECTION_UI_MODE:
609 if (args.length != 2) {
610 writer.println("Incorrect number of arguments");
611 dumpHelp(writer);
612 break;
613 }
614 mCarProjectionService.setUiMode(Integer.valueOf(args[1]));
Pavel Maltsevd6961f62019-03-26 10:22:31 -0700615 break;
Jim Kayed76c2742019-04-02 11:33:27 -0700616 case COMMAND_RESUME:
617 mCarPowerManagementService.forceSimulatedResume();
618 writer.println("Resume: Simulating resuming from Deep Sleep");
619 break;
620 case COMMAND_SUSPEND:
621 mCarPowerManagementService.forceSimulatedSuspend();
622 writer.println("Resume: Simulating powering down to Deep Sleep");
623 break;
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700624 case COMMAND_ENABLE_TRUSTED_DEVICE:
625 if (args.length != 2) {
626 writer.println("Incorrect number of arguments");
627 dumpHelp(writer);
628 break;
629 }
630 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
631 .setTrustedDeviceEnrollmentEnabled(Boolean.valueOf(args[1]));
632 mCarTrustedDeviceService.getCarTrustAgentUnlockService()
633 .setTrustedDeviceUnlockEnabled(Boolean.valueOf(args[1]));
634 break;
635 case COMMAND_REMOVE_TRUSTED_DEVICES:
636 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
637 .removeAllTrustedDevices(
638 mUserManagerHelper.getCurrentForegroundUserId());
639 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700640 default:
Jim Kayef10b7d82019-02-26 12:53:22 -0800641 writer.println("Unknown command: \"" + arg + "\"");
Yao Chene33f07e2016-07-26 12:02:51 -0700642 dumpHelp(writer);
643 }
644 }
645
646 private void forceDayNightMode(String arg, PrintWriter writer) {
647 int mode;
648 switch (arg) {
649 case PARAM_DAY_MODE:
650 mode = CarNightService.FORCED_DAY_MODE;
651 break;
652 case PARAM_NIGHT_MODE:
653 mode = CarNightService.FORCED_NIGHT_MODE;
654 break;
655 case PARAM_SENSOR_MODE:
656 mode = CarNightService.FORCED_SENSOR_MODE;
657 break;
658 default:
659 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
660 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
661 return;
662 }
663 int current = mCarNightService.forceDayNightMode(mode);
664 String currentMode = null;
665 switch (current) {
666 case UiModeManager.MODE_NIGHT_AUTO:
667 currentMode = PARAM_SENSOR_MODE;
668 break;
669 case UiModeManager.MODE_NIGHT_YES:
670 currentMode = PARAM_NIGHT_MODE;
671 break;
672 case UiModeManager.MODE_NIGHT_NO:
673 currentMode = PARAM_DAY_MODE;
674 break;
675 }
676 writer.println("DayNightMode changed to: " + currentMode);
677 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800678
Bryan Eylera32a7c12018-02-27 15:40:00 -0800679 private void forceGarageMode(String arg, PrintWriter writer) {
680 switch (arg) {
681 case PARAM_ON_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700682 mGarageModeService.forceStartGarageMode();
Bryan Eylera32a7c12018-02-27 15:40:00 -0800683 break;
684 case PARAM_OFF_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700685 mGarageModeService.stopAndResetGarageMode();
Bryan Eylera32a7c12018-02-27 15:40:00 -0800686 break;
687 case PARAM_QUERY_MODE:
688 // Nothing to do. Always query at the end anyway.
689 break;
690 default:
691 writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|"
692 + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE);
693 return;
694 }
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700695 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -0800696 }
697
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800698 /**
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800699 * Inject a fake VHAL event
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800700 *
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800701 * @param property the Vehicle property Id as defined in the HAL
702 * @param zone Zone that this event services
703 * @param value Data value of the event
704 * @param writer PrintWriter
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800705 */
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800706 private void injectVhalEvent(String property, String zone, String value,
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800707 PrintWriter writer) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800708 if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) {
709 if (!isPropertyAreaTypeGlobal(property)) {
710 writer.println("Property area type inconsistent with given zone");
711 return;
712 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800713 }
714 try {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800715 mHal.injectVhalEvent(property, zone, value);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800716 } catch (NumberFormatException e) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800717 writer.println("Invalid property Id zone Id or value" + e);
718 dumpHelp(writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800719 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800720 }
721
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800722 // Check if the given property is global
723 private boolean isPropertyAreaTypeGlobal(String property) {
724 if (property == null) {
725 return false;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800726 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800727 return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800728 }
Yao Chene33f07e2016-07-26 12:02:51 -0700729 }
kevinjm55822c42018-08-15 11:26:00 -0700730}