blob: 55f93cae474fd5bec4f613d5c6d4accf6321da39 [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
Yao Chene33f07e2016-07-26 12:02:51 -070019import android.app.UiModeManager;
Keun-young Parke54ac272016-02-16 19:02:18 -080020import android.car.Car;
21import android.car.ICar;
Antonio Cortese4619c72017-02-02 07:53:27 -080022import android.car.annotation.FutureFeature;
Pavel Maltsev0477e292016-05-27 12:22:36 -070023import android.car.cluster.renderer.IInstrumentClusterNavigation;
keunyoungca515072015-07-10 12:21:47 -070024import android.content.Context;
keunyoung1ab8e182015-09-24 09:25:22 -070025import android.content.pm.PackageManager;
Pavel Maltsevcfe93102017-02-02 12:38:08 -080026import android.hardware.automotive.vehicle.V2_0.IVehicle;
Ram Periathiruvadiee28c002017-02-07 21:35:01 -080027import android.hardware.automotive.vehicle.V2_0.VehicleAreaDoor;
28import android.hardware.automotive.vehicle.V2_0.VehicleProperty;
keunyoungca515072015-07-10 12:21:47 -070029import android.os.IBinder;
keunyoungca515072015-07-10 12:21:47 -070030import android.util.Log;
31
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080032import com.android.car.cluster.InstrumentClusterService;
keunyoungcc449f72015-08-12 10:46:27 -070033import com.android.car.hal.VehicleHal;
Antonio Cortesc52d5f92017-02-06 08:47:38 -080034import com.android.car.internal.FeatureConfiguration;
35import com.android.car.internal.FeatureUtil;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080036import com.android.car.pm.CarPackageManagerService;
keunyoungca515072015-07-10 12:21:47 -070037import com.android.internal.annotations.GuardedBy;
38
keunyounga3b28d82015-08-25 13:05:15 -070039import java.io.PrintWriter;
Antonio Cortese4619c72017-02-02 07:53:27 -080040import java.util.ArrayList;
41import java.util.Arrays;
42import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070043
keunyoungca515072015-07-10 12:21:47 -070044public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070045
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -080046 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070047 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
48 "system_activity_monitoring";
Keun-young Parka28d7b22016-02-29 16:54:29 -080049
keunyoungca515072015-07-10 12:21:47 -070050 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080051 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070052
Keun-young Park4727da32016-05-31 10:00:51 -070053 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070054 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080055 private final CarPackageManagerService mCarPackageManagerService;
56 private final CarInputService mCarInputService;
keunyoungca515072015-07-10 12:21:47 -070057 private final CarSensorService mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -070058 private final CarInfoService mCarInfoService;
keunyoungd32f4e62015-09-21 11:33:06 -070059 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080060 private final CarProjectionService mCarProjectionService;
Steve Paik43c04a72016-07-08 19:12:09 -070061 private final CarCabinService mCarCabinService;
Steve Paik66481982015-10-27 15:22:38 -070062 private final CarHvacService mCarHvacService;
Sanket Agarwal3cf096a2015-10-13 14:46:31 -070063 private final CarRadioService mCarRadioService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080064 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070065 private final AppFocusService mAppFocusService;
Yao Chen3a7976d2016-01-20 17:27:08 -080066 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080067 private final InstrumentClusterService mInstrumentClusterService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070068 private final SystemStateControllerService mSystemStateControllerService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -070069 private final CarVendorExtensionService mCarVendorExtensionService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080070 private final CarBluetoothService mCarBluetoothService;
Antonio Cortese4619c72017-02-02 07:53:27 -080071 @FutureFeature
Enrico Granata5c56d2a2017-02-07 15:38:12 -080072 private CarDiagnosticService mCarDiagnosticService;
73 @FutureFeature
Antonio Cortese4619c72017-02-02 07:53:27 -080074 private VmsSubscriberService mVmsSubscriberService;
Antonio Cortes6b3544c2017-02-06 16:54:58 -080075 @FutureFeature
76 private VmsPublisherService mVmsPublisherService;
keunyounga74b9ca2015-10-21 13:33:58 -070077
Pavel Maltsev0d07c762016-11-03 16:40:15 -070078 private final CarServiceBase[] mAllServices;
79
keunyoung1ab8e182015-09-24 09:25:22 -070080 /** Test only service. Populate it only when necessary. */
81 @GuardedBy("this")
82 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -070083
Pavel Maltsevec83b632017-01-05 15:10:55 -080084 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
85 CanBusErrorNotifier errorNotifier) {
keunyoungca515072015-07-10 12:21:47 -070086 mContext = serviceContext;
Pavel Maltsev0d07c762016-11-03 16:40:15 -070087 mHal = new VehicleHal(vehicle);
Keun-young Park4727da32016-05-31 10:00:51 -070088 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Pavel Maltsev0d07c762016-11-03 16:40:15 -070089 mCarPowerManagementService = new CarPowerManagementService(
90 mHal.getPowerHal(), systemInterface);
91 mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal());
Keun-young Park4727da32016-05-31 10:00:51 -070092 mCarPackageManagerService = new CarPackageManagerService(serviceContext, mCarSensorService,
93 mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -070094 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080095 mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService);
Yao Chen3a7976d2016-01-20 17:27:08 -080096 mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -070097 mCarInfoService = new CarInfoService(serviceContext, mHal.getInfoHal());
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -070098 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -070099 mCarAudioService = new CarAudioService(serviceContext, mHal.getAudioHal(),
Pavel Maltsevec83b632017-01-05 15:10:55 -0800100 mCarInputService, errorNotifier);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700101 mCarCabinService = new CarCabinService(serviceContext, mHal.getCabinHal());
102 mCarHvacService = new CarHvacService(serviceContext, mHal.getHvacHal());
103 mCarRadioService = new CarRadioService(serviceContext, mHal.getRadioHal());
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700104 mCarNightService = new CarNightService(serviceContext, mCarSensorService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700105 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700106 mAppFocusService, mCarInputService);
Keun-young Parkd73afae2016-04-08 20:03:32 -0700107 mSystemStateControllerService = new SystemStateControllerService(serviceContext,
Keun-young Park3cb89102016-05-05 13:16:03 -0700108 mCarPowerManagementService, mCarAudioService, this);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700109 mCarVendorExtensionService = new CarVendorExtensionService(serviceContext,
110 mHal.getVendorExtensionHal());
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800111 mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService,
112 mCarSensorService);
Antonio Cortese4619c72017-02-02 07:53:27 -0800113 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
114 mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal());
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800115 mVmsPublisherService = new VmsPublisherService(serviceContext, mHal.getVmsHal());
Antonio Cortese4619c72017-02-02 07:53:27 -0800116 }
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800117 if (FeatureConfiguration.ENABLE_DIAGNOSTIC) {
118 mCarDiagnosticService = new CarDiagnosticService(serviceContext,
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800119 mHal.getDiagnosticHal());
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800120 }
keunyounga74b9ca2015-10-21 13:33:58 -0700121
keunyounga3b28d82015-08-25 13:05:15 -0700122 // Be careful with order. Service depending on other service should be inited later.
Antonio Cortese4619c72017-02-02 07:53:27 -0800123 List<CarServiceBase> allServices = new ArrayList<>(Arrays.asList(
Keun-young Park4727da32016-05-31 10:00:51 -0700124 mSystemActivityMonitoringService,
keunyoung4b0212c2015-10-29 17:11:57 -0700125 mCarPowerManagementService,
Keun-young Park4727da32016-05-31 10:00:51 -0700126 mCarSensorService,
Keun-young Park45fdcba2015-12-08 11:38:58 -0800127 mCarPackageManagerService,
Keun-young Parka28d7b22016-02-29 16:54:29 -0800128 mCarInputService,
129 mGarageModeService,
keunyounga3b28d82015-08-25 13:05:15 -0700130 mCarInfoService,
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700131 mAppFocusService,
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700132 mCarAudioService,
Steve Paik43c04a72016-07-08 19:12:09 -0700133 mCarCabinService,
Steve Paik66481982015-10-27 15:22:38 -0700134 mCarHvacService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800135 mCarRadioService,
Joseph Pirozzo317343d2016-01-25 10:22:37 -0800136 mCarNightService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800137 mInstrumentClusterService,
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800138 mCarProjectionService,
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700139 mSystemStateControllerService,
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800140 mCarVendorExtensionService,
141 mCarBluetoothService
Antonio Cortese4619c72017-02-02 07:53:27 -0800142 ));
143 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
144 allServices.add(mVmsSubscriberService);
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800145 allServices.add(mVmsPublisherService);
Antonio Cortese4619c72017-02-02 07:53:27 -0800146 }
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800147 if (FeatureConfiguration.ENABLE_DIAGNOSTIC) {
148 allServices.add(mCarDiagnosticService);
149 }
Antonio Cortese4619c72017-02-02 07:53:27 -0800150 mAllServices = allServices.toArray(new CarServiceBase[0]);
keunyoungca515072015-07-10 12:21:47 -0700151 }
152
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700153 public void init() {
154 mHal.init();
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800155 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700156 service.init();
157 }
keunyoungca515072015-07-10 12:21:47 -0700158 }
159
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700160 public void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700161 // release done in opposite order from init
162 for (int i = mAllServices.length - 1; i >= 0; i--) {
163 mAllServices[i].release();
164 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700165 mHal.release();
keunyoung1ab8e182015-09-24 09:25:22 -0700166 }
167
Pavel Maltsevec83b632017-01-05 15:10:55 -0800168 public void vehicleHalReconnected(IVehicle vehicle) {
169 mHal.vehicleHalReconnected(vehicle);
170 for (CarServiceBase service : mAllServices) {
171 service.vehicleHalReconnected();
172 }
173 }
174
keunyoungca515072015-07-10 12:21:47 -0700175 @Override
keunyoungca515072015-07-10 12:21:47 -0700176 public IBinder getCarService(String serviceName) {
177 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800178 case Car.AUDIO_SERVICE:
179 return mCarAudioService;
keunyoungca515072015-07-10 12:21:47 -0700180 case Car.SENSOR_SERVICE:
181 return mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -0700182 case Car.INFO_SERVICE:
183 return mCarInfoService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700184 case Car.APP_FOCUS_SERVICE:
185 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800186 case Car.PACKAGE_SERVICE:
187 return mCarPackageManagerService;
Steve Paik43c04a72016-07-08 19:12:09 -0700188 case Car.CABIN_SERVICE:
189 assertCabinPermission(mContext);
190 return mCarCabinService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800191 case Car.DIAGNOSTIC_SERVICE:
Enrico Granata34010ed2017-02-16 11:51:47 -0800192 FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_DIAGNOSTIC);
193 if (FeatureConfiguration.ENABLE_DIAGNOSTIC) {
Enrico Granata3c7a6662017-02-23 18:07:59 -0800194 assertAnyDiagnosticPermission(mContext);
Enrico Granata34010ed2017-02-16 11:51:47 -0800195 return mCarDiagnosticService;
196 }
Keun-young Parke54ac272016-02-16 19:02:18 -0800197 case Car.HVAC_SERVICE:
Steve Paik66481982015-10-27 15:22:38 -0700198 assertHvacPermission(mContext);
199 return mCarHvacService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800200 case Car.RADIO_SERVICE:
keunyoung6b197692015-11-16 13:54:38 -0800201 assertRadioPermission(mContext);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700202 return mCarRadioService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800203 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700204 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700205 IInstrumentClusterNavigation navService =
206 mInstrumentClusterService.getNavigationService();
207 return navService == null ? null : navService.asBinder();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800208 case Car.PROJECTION_SERVICE:
209 assertProjectionPermission(mContext);
210 return mCarProjectionService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700211 case Car.VENDOR_EXTENSION_SERVICE:
212 assertVendorExtensionPermission(mContext);
213 return mCarVendorExtensionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800214 case Car.VMS_SUBSCRIBER_SERVICE:
215 FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE);
216 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
217 assertVmsSubscriberPermission(mContext);
218 return mVmsSubscriberService;
219 }
Keun-young Parke54ac272016-02-16 19:02:18 -0800220 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700221 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700222 synchronized (this) {
223 if (mCarTestService == null) {
224 mCarTestService = new CarTestService(mContext, this);
225 }
226 return mCarTestService;
227 }
228 }
keunyoungca515072015-07-10 12:21:47 -0700229 default:
230 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
231 return null;
232 }
233 }
234
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800235 @Override
236 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700237 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800238 }
239
Keun-young Parka28d7b22016-02-29 16:54:29 -0800240 public CarServiceBase getCarInternalService(String serviceName) {
241 switch (serviceName) {
242 case INTERNAL_INPUT_SERVICE:
243 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700244 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
245 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800246 default:
247 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
248 serviceName);
249 return null;
250 }
251 }
252
keunyoung1ab8e182015-09-24 09:25:22 -0700253 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700254 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700255 }
256
Steve Paik43c04a72016-07-08 19:12:09 -0700257 public static void assertCabinPermission(Context context) {
258 assertPermission(context, Car.PERMISSION_CAR_CABIN);
259 }
260
Keun-young Parke31a8b22016-03-16 17:34:08 -0700261 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700262 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800263 }
264
Steve Paik66481982015-10-27 15:22:38 -0700265 public static void assertHvacPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700266 assertPermission(context, Car.PERMISSION_CAR_HVAC);
Steve Paik66481982015-10-27 15:22:38 -0700267 }
268
keunyoung6b197692015-11-16 13:54:38 -0800269 private static void assertRadioPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700270 assertPermission(context, Car.PERMISSION_CAR_RADIO);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700271 }
272
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800273 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700274 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
275 }
276
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700277 public static void assertVendorExtensionPermission(Context context) {
278 assertPermission(context, Car.PERMISSION_VENDOR_EXTENSION);
279 }
280
Antonio Cortese4619c72017-02-02 07:53:27 -0800281 @FutureFeature
Enrico Granata3c7a6662017-02-23 18:07:59 -0800282 public static void assertAnyDiagnosticPermission(Context context) {
283 assertAnyPermission(context,
284 Car.PERMISSION_CAR_DIAGNOSTIC_READ,
285 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
286 }
287
288 @FutureFeature
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800289 public static void assertVmsPublisherPermission(Context context) {
290 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
291 }
292
293 @FutureFeature
Antonio Cortese4619c72017-02-02 07:53:27 -0800294 public static void assertVmsSubscriberPermission(Context context) {
295 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
296 }
297
Steve Paik461ecc62016-06-08 15:28:32 -0700298 public static void assertPermission(Context context, String permission) {
299 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
300 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800301 }
302 }
303
Enrico Granata3c7a6662017-02-23 18:07:59 -0800304 public static void assertAnyPermission(Context context, String... permissions) {
305 for (String permission : permissions) {
306 if (context.checkCallingOrSelfPermission(permission) ==
307 PackageManager.PERMISSION_GRANTED) {
308 return;
309 }
310 }
311 throw new SecurityException("requires any of " + Arrays.toString(permissions));
312 }
313
keunyoungcc449f72015-08-12 10:46:27 -0700314 void dump(PrintWriter writer) {
Keun-young Parkbae6e252017-01-25 12:30:15 -0800315 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
316 //TODO dump all feature flags by reflection
keunyounga3b28d82015-08-25 13:05:15 -0700317 writer.println("*Dump all services*");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800318 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700319 service.dump(writer);
320 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700321 if (mCarTestService != null) {
322 mCarTestService.dump(writer);
keunyoung1ab8e182015-09-24 09:25:22 -0700323 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700324 writer.println("*Dump Vehicle HAL*");
325 mHal.dump(writer);
keunyoungcc449f72015-08-12 10:46:27 -0700326 }
Yao Chene33f07e2016-07-26 12:02:51 -0700327
328 void execShellCmd(String[] args, PrintWriter writer) {
329 new CarShellCommand().exec(args, writer);
330 }
331
332 private class CarShellCommand {
333 private static final String COMMAND_HELP = "-h";
334 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800335 private static final String COMMAND_INJECT_EVENT = "inject-event";
336
Yao Chene33f07e2016-07-26 12:02:51 -0700337 private static final String PARAM_DAY_MODE = "day";
338 private static final String PARAM_NIGHT_MODE = "night";
339 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800340 private static final String PARAM_ZONED_BOOLEAN = "zoned-boolean";
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800341 private static final String PARAM_GLOBAL_INT = "global-integer";
Yao Chene33f07e2016-07-26 12:02:51 -0700342
343 private void dumpHelp(PrintWriter pw) {
344 pw.println("Car service commands:");
345 pw.println("\t-h");
346 pw.println("\t Print this help text.");
347 pw.println("\tday-night-mode [day|night|sensor]");
348 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800349 pw.println("\tinject-event zoned-boolean propertyType zone [true|false]");
350 pw.println("\t Inject a Boolean HAL Event. ");
Yao Chene33f07e2016-07-26 12:02:51 -0700351 }
352
353 public void exec(String[] args, PrintWriter writer) {
354 String arg = args[0];
355 switch (arg) {
356 case COMMAND_HELP:
357 dumpHelp(writer);
358 break;
359 case COMMAND_DAY_NIGHT_MODE:
360 String value = args.length < 1 ? "" : args[1];
361 forceDayNightMode(value, writer);
362 break;
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800363 case COMMAND_INJECT_EVENT:
364 String eventType;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800365 if (args.length > 1) {
366 eventType = args[1].toLowerCase();
367 switch (eventType) {
368 case PARAM_ZONED_BOOLEAN:
369 if (args.length < 5) {
370 writer.println("Incorrect number of arguments.");
371 dumpHelp(writer);
372 break;
373 }
374 inject_zoned_boolean_event(args[2], args[3], args[4], writer);
375 break;
376
377 case PARAM_GLOBAL_INT:
378 if (args.length < 4) {
379 writer.println("Incorrect number of Arguments");
380 dumpHelp(writer);
381 break;
382 }
383 inject_global_integer_event(args[2], args[3], writer);
384 break;
385
386 default:
387 writer.println("Unsupported event type");
388 dumpHelp(writer);
389 break;
390 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800391 }
392 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700393 default:
394 writer.println("Unknown command.");
395 dumpHelp(writer);
396 }
397 }
398
399 private void forceDayNightMode(String arg, PrintWriter writer) {
400 int mode;
401 switch (arg) {
402 case PARAM_DAY_MODE:
403 mode = CarNightService.FORCED_DAY_MODE;
404 break;
405 case PARAM_NIGHT_MODE:
406 mode = CarNightService.FORCED_NIGHT_MODE;
407 break;
408 case PARAM_SENSOR_MODE:
409 mode = CarNightService.FORCED_SENSOR_MODE;
410 break;
411 default:
412 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
413 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
414 return;
415 }
416 int current = mCarNightService.forceDayNightMode(mode);
417 String currentMode = null;
418 switch (current) {
419 case UiModeManager.MODE_NIGHT_AUTO:
420 currentMode = PARAM_SENSOR_MODE;
421 break;
422 case UiModeManager.MODE_NIGHT_YES:
423 currentMode = PARAM_NIGHT_MODE;
424 break;
425 case UiModeManager.MODE_NIGHT_NO:
426 currentMode = PARAM_DAY_MODE;
427 break;
428 }
429 writer.println("DayNightMode changed to: " + currentMode);
430 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800431
432 /**
433 * Inject a fake boolean HAL event to help testing.
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800434 *
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800435 * @param property - Vehicle Property
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800436 * @param value - boolean value for the property
437 * @param writer - Printwriter
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800438 */
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800439 private void inject_zoned_boolean_event(String property, String zone, String value,
440 PrintWriter writer) {
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800441 Log.d(CarLog.TAG_SERVICE, "Injecting Boolean event");
442 boolean event;
443 int propId;
444 int zoneId;
445 if (value.equalsIgnoreCase("true")) {
446 event = true;
447 } else {
448 event = false;
449 }
450 try {
451 propId = Integer.decode(property);
452 zoneId = Integer.decode(zone);
453 } catch (NumberFormatException e) {
454 writer.println("Invalid property Id or Zone Id. Prefix hex values with 0x");
455 return;
456 }
457 mHal.injectBooleanEvent(propId, zoneId, event);
458 }
459
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800460 /**
461 * Inject a fake Integer HAL event to help testing.
462 *
463 * @param property - Vehicle Property
464 * @param value - Integer value to inject
465 * @param writer - PrintWriter
466 */
467 private void inject_global_integer_event(String property, String value,
468 PrintWriter writer) {
469 Log.d(CarLog.TAG_SERVICE, "Injecting integer event");
470 int propId;
471 int eventValue;
472 try {
473 propId = Integer.decode(property);
474 eventValue = Integer.decode(value);
475 } catch (NumberFormatException e) {
476 writer.println("Invalid property Id or event value. Prefix hex values with 0x");
477 return;
478 }
479 mHal.injectIntegerEvent(propId, eventValue);
480 }
481
Yao Chene33f07e2016-07-26 12:02:51 -0700482 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800483}