blob: 1f891b90b59a9be4cdca46376581bd506643c07f [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;
Antonio Cortese4619c72017-02-02 07:53:27 -080024import android.car.internal.FeatureUtil;
keunyoungca515072015-07-10 12:21:47 -070025import android.content.Context;
keunyoung1ab8e182015-09-24 09:25:22 -070026import android.content.pm.PackageManager;
Pavel Maltsevcfe93102017-02-02 12:38:08 -080027import android.hardware.automotive.vehicle.V2_0.IVehicle;
Ram Periathiruvadiee28c002017-02-07 21:35:01 -080028import android.hardware.automotive.vehicle.V2_0.VehicleAreaDoor;
29import android.hardware.automotive.vehicle.V2_0.VehicleProperty;
keunyoungca515072015-07-10 12:21:47 -070030import android.os.IBinder;
keunyoungca515072015-07-10 12:21:47 -070031import android.util.Log;
32
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080033import com.android.car.cluster.InstrumentClusterService;
keunyoungcc449f72015-08-12 10:46:27 -070034import com.android.car.hal.VehicleHal;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080035import com.android.car.pm.CarPackageManagerService;
keunyoungca515072015-07-10 12:21:47 -070036import com.android.internal.annotations.GuardedBy;
37
keunyounga3b28d82015-08-25 13:05:15 -070038import java.io.PrintWriter;
Antonio Cortese4619c72017-02-02 07:53:27 -080039import java.util.ArrayList;
40import java.util.Arrays;
41import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070042
keunyoungca515072015-07-10 12:21:47 -070043public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070044
Keun-young Parka28d7b22016-02-29 16:54:29 -080045 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070046 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
47 "system_activity_monitoring";
Keun-young Parka28d7b22016-02-29 16:54:29 -080048
49 // load jni for all services here
50 static {
Pavel Maltsev0d07c762016-11-03 16:40:15 -070051 try {
52 System.loadLibrary("jni_car_service");
53 } catch (UnsatisfiedLinkError ex) {
54 // Unable to load native library when loaded from the testing framework.
55 Log.e(CarLog.TAG_SERVICE, "Failed to load jni_car_service library: " + ex.getMessage());
56 }
Keun-young Parka28d7b22016-02-29 16:54:29 -080057 }
58
keunyoungca515072015-07-10 12:21:47 -070059 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080060 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070061
Keun-young Park4727da32016-05-31 10:00:51 -070062 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070063 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080064 private final CarPackageManagerService mCarPackageManagerService;
65 private final CarInputService mCarInputService;
keunyoungca515072015-07-10 12:21:47 -070066 private final CarSensorService mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -070067 private final CarInfoService mCarInfoService;
keunyoungd32f4e62015-09-21 11:33:06 -070068 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080069 private final CarProjectionService mCarProjectionService;
Steve Paik43c04a72016-07-08 19:12:09 -070070 private final CarCabinService mCarCabinService;
Steve Paik875616c2016-02-05 10:55:59 -080071 private final CarCameraService mCarCameraService;
Steve Paik66481982015-10-27 15:22:38 -070072 private final CarHvacService mCarHvacService;
Sanket Agarwal3cf096a2015-10-13 14:46:31 -070073 private final CarRadioService mCarRadioService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080074 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070075 private final AppFocusService mAppFocusService;
Yao Chen3a7976d2016-01-20 17:27:08 -080076 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080077 private final InstrumentClusterService mInstrumentClusterService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070078 private final SystemStateControllerService mSystemStateControllerService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -070079 private final CarVendorExtensionService mCarVendorExtensionService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080080 private final CarBluetoothService mCarBluetoothService;
Antonio Cortese4619c72017-02-02 07:53:27 -080081 @FutureFeature
82 private VmsSubscriberService mVmsSubscriberService;
keunyounga74b9ca2015-10-21 13:33:58 -070083
Pavel Maltsev0d07c762016-11-03 16:40:15 -070084 private final CarServiceBase[] mAllServices;
85
keunyoung1ab8e182015-09-24 09:25:22 -070086 /** Test only service. Populate it only when necessary. */
87 @GuardedBy("this")
88 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -070089
Pavel Maltsevec83b632017-01-05 15:10:55 -080090 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
91 CanBusErrorNotifier errorNotifier) {
keunyoungca515072015-07-10 12:21:47 -070092 mContext = serviceContext;
Pavel Maltsev0d07c762016-11-03 16:40:15 -070093 mHal = new VehicleHal(vehicle);
Keun-young Park4727da32016-05-31 10:00:51 -070094 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Pavel Maltsev0d07c762016-11-03 16:40:15 -070095 mCarPowerManagementService = new CarPowerManagementService(
96 mHal.getPowerHal(), systemInterface);
97 mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal());
Keun-young Park4727da32016-05-31 10:00:51 -070098 mCarPackageManagerService = new CarPackageManagerService(serviceContext, mCarSensorService,
99 mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700100 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800101 mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService);
Yao Chen3a7976d2016-01-20 17:27:08 -0800102 mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700103 mCarInfoService = new CarInfoService(serviceContext, mHal.getInfoHal());
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700104 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700105 mCarAudioService = new CarAudioService(serviceContext, mHal.getAudioHal(),
Pavel Maltsevec83b632017-01-05 15:10:55 -0800106 mCarInputService, errorNotifier);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700107 mCarCabinService = new CarCabinService(serviceContext, mHal.getCabinHal());
108 mCarHvacService = new CarHvacService(serviceContext, mHal.getHvacHal());
109 mCarRadioService = new CarRadioService(serviceContext, mHal.getRadioHal());
Steve Paik875616c2016-02-05 10:55:59 -0800110 mCarCameraService = new CarCameraService(serviceContext);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700111 mCarNightService = new CarNightService(serviceContext, mCarSensorService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700112 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700113 mAppFocusService, mCarInputService);
Keun-young Parkd73afae2016-04-08 20:03:32 -0700114 mSystemStateControllerService = new SystemStateControllerService(serviceContext,
Keun-young Park3cb89102016-05-05 13:16:03 -0700115 mCarPowerManagementService, mCarAudioService, this);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700116 mCarVendorExtensionService = new CarVendorExtensionService(serviceContext,
117 mHal.getVendorExtensionHal());
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800118 mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService);
Antonio Cortese4619c72017-02-02 07:53:27 -0800119 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
120 mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal());
121 }
keunyounga74b9ca2015-10-21 13:33:58 -0700122
keunyounga3b28d82015-08-25 13:05:15 -0700123 // Be careful with order. Service depending on other service should be inited later.
Antonio Cortese4619c72017-02-02 07:53:27 -0800124 List<CarServiceBase> allServices = new ArrayList<>(Arrays.asList(
Keun-young Park4727da32016-05-31 10:00:51 -0700125 mSystemActivityMonitoringService,
keunyoung4b0212c2015-10-29 17:11:57 -0700126 mCarPowerManagementService,
Keun-young Park4727da32016-05-31 10:00:51 -0700127 mCarSensorService,
Keun-young Park45fdcba2015-12-08 11:38:58 -0800128 mCarPackageManagerService,
Keun-young Parka28d7b22016-02-29 16:54:29 -0800129 mCarInputService,
130 mGarageModeService,
keunyounga3b28d82015-08-25 13:05:15 -0700131 mCarInfoService,
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700132 mAppFocusService,
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700133 mCarAudioService,
Steve Paik43c04a72016-07-08 19:12:09 -0700134 mCarCabinService,
Steve Paik66481982015-10-27 15:22:38 -0700135 mCarHvacService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800136 mCarRadioService,
137 mCarCameraService,
Joseph Pirozzo317343d2016-01-25 10:22:37 -0800138 mCarNightService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800139 mInstrumentClusterService,
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800140 mCarProjectionService,
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700141 mSystemStateControllerService,
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800142 mCarVendorExtensionService,
143 mCarBluetoothService
Antonio Cortese4619c72017-02-02 07:53:27 -0800144 ));
145 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
146 allServices.add(mVmsSubscriberService);
147 }
148 mAllServices = allServices.toArray(new CarServiceBase[0]);
keunyoungca515072015-07-10 12:21:47 -0700149 }
150
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700151 public void init() {
152 mHal.init();
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800153 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700154 service.init();
155 }
keunyoungca515072015-07-10 12:21:47 -0700156 }
157
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700158 public void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700159 // release done in opposite order from init
160 for (int i = mAllServices.length - 1; i >= 0; i--) {
161 mAllServices[i].release();
162 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700163 mHal.release();
keunyoung1ab8e182015-09-24 09:25:22 -0700164 }
165
Pavel Maltsevec83b632017-01-05 15:10:55 -0800166 public void vehicleHalReconnected(IVehicle vehicle) {
167 mHal.vehicleHalReconnected(vehicle);
168 for (CarServiceBase service : mAllServices) {
169 service.vehicleHalReconnected();
170 }
171 }
172
keunyoungca515072015-07-10 12:21:47 -0700173 @Override
keunyoungca515072015-07-10 12:21:47 -0700174 public IBinder getCarService(String serviceName) {
175 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800176 case Car.AUDIO_SERVICE:
177 return mCarAudioService;
keunyoungca515072015-07-10 12:21:47 -0700178 case Car.SENSOR_SERVICE:
179 return mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -0700180 case Car.INFO_SERVICE:
181 return mCarInfoService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700182 case Car.APP_FOCUS_SERVICE:
183 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800184 case Car.PACKAGE_SERVICE:
185 return mCarPackageManagerService;
Steve Paik43c04a72016-07-08 19:12:09 -0700186 case Car.CABIN_SERVICE:
187 assertCabinPermission(mContext);
188 return mCarCabinService;
Steve Paik875616c2016-02-05 10:55:59 -0800189 case Car.CAMERA_SERVICE:
190 assertCameraPermission(mContext);
191 return mCarCameraService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800192 case Car.HVAC_SERVICE:
Steve Paik66481982015-10-27 15:22:38 -0700193 assertHvacPermission(mContext);
194 return mCarHvacService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800195 case Car.RADIO_SERVICE:
keunyoung6b197692015-11-16 13:54:38 -0800196 assertRadioPermission(mContext);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700197 return mCarRadioService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800198 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700199 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700200 IInstrumentClusterNavigation navService =
201 mInstrumentClusterService.getNavigationService();
202 return navService == null ? null : navService.asBinder();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800203 case Car.PROJECTION_SERVICE:
204 assertProjectionPermission(mContext);
205 return mCarProjectionService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700206 case Car.VENDOR_EXTENSION_SERVICE:
207 assertVendorExtensionPermission(mContext);
208 return mCarVendorExtensionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800209 case Car.VMS_SUBSCRIBER_SERVICE:
210 FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE);
211 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
212 assertVmsSubscriberPermission(mContext);
213 return mVmsSubscriberService;
214 }
Keun-young Parke54ac272016-02-16 19:02:18 -0800215 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700216 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700217 synchronized (this) {
218 if (mCarTestService == null) {
219 mCarTestService = new CarTestService(mContext, this);
220 }
221 return mCarTestService;
222 }
223 }
keunyoungca515072015-07-10 12:21:47 -0700224 default:
225 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
226 return null;
227 }
228 }
229
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800230 @Override
231 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700232 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800233 }
234
Keun-young Parka28d7b22016-02-29 16:54:29 -0800235 public CarServiceBase getCarInternalService(String serviceName) {
236 switch (serviceName) {
237 case INTERNAL_INPUT_SERVICE:
238 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700239 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
240 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800241 default:
242 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
243 serviceName);
244 return null;
245 }
246 }
247
keunyoung1ab8e182015-09-24 09:25:22 -0700248 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700249 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700250 }
251
Steve Paik43c04a72016-07-08 19:12:09 -0700252 public static void assertCabinPermission(Context context) {
253 assertPermission(context, Car.PERMISSION_CAR_CABIN);
254 }
255
Steve Paik875616c2016-02-05 10:55:59 -0800256 public static void assertCameraPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700257 assertPermission(context, Car.PERMISSION_CAR_CAMERA);
Steve Paik875616c2016-02-05 10:55:59 -0800258 }
259
Keun-young Parke31a8b22016-03-16 17:34:08 -0700260 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700261 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800262 }
263
Steve Paik66481982015-10-27 15:22:38 -0700264 public static void assertHvacPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700265 assertPermission(context, Car.PERMISSION_CAR_HVAC);
Steve Paik66481982015-10-27 15:22:38 -0700266 }
267
keunyoung6b197692015-11-16 13:54:38 -0800268 private static void assertRadioPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700269 assertPermission(context, Car.PERMISSION_CAR_RADIO);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700270 }
271
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800272 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700273 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
274 }
275
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700276 public static void assertVendorExtensionPermission(Context context) {
277 assertPermission(context, Car.PERMISSION_VENDOR_EXTENSION);
278 }
279
Antonio Cortese4619c72017-02-02 07:53:27 -0800280 @FutureFeature
281 public static void assertVmsSubscriberPermission(Context context) {
282 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
283 }
284
Steve Paik461ecc62016-06-08 15:28:32 -0700285 public static void assertPermission(Context context, String permission) {
286 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
287 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800288 }
289 }
290
keunyoungcc449f72015-08-12 10:46:27 -0700291 void dump(PrintWriter writer) {
Keun-young Parkbae6e252017-01-25 12:30:15 -0800292 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
293 //TODO dump all feature flags by reflection
keunyounga3b28d82015-08-25 13:05:15 -0700294 writer.println("*Dump all services*");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800295 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700296 service.dump(writer);
297 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700298 if (mCarTestService != null) {
299 mCarTestService.dump(writer);
keunyoung1ab8e182015-09-24 09:25:22 -0700300 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700301 writer.println("*Dump Vehicle HAL*");
302 mHal.dump(writer);
keunyoungcc449f72015-08-12 10:46:27 -0700303 }
Yao Chene33f07e2016-07-26 12:02:51 -0700304
305 void execShellCmd(String[] args, PrintWriter writer) {
306 new CarShellCommand().exec(args, writer);
307 }
308
309 private class CarShellCommand {
310 private static final String COMMAND_HELP = "-h";
311 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800312 private static final String COMMAND_INJECT_EVENT = "inject-event";
313
Yao Chene33f07e2016-07-26 12:02:51 -0700314 private static final String PARAM_DAY_MODE = "day";
315 private static final String PARAM_NIGHT_MODE = "night";
316 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800317 private static final String PARAM_ZONED_BOOLEAN = "zoned-boolean";
Yao Chene33f07e2016-07-26 12:02:51 -0700318
319 private void dumpHelp(PrintWriter pw) {
320 pw.println("Car service commands:");
321 pw.println("\t-h");
322 pw.println("\t Print this help text.");
323 pw.println("\tday-night-mode [day|night|sensor]");
324 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800325 pw.println("\tinject-event zoned-boolean propertyType zone [true|false]");
326 pw.println("\t Inject a Boolean HAL Event. ");
Yao Chene33f07e2016-07-26 12:02:51 -0700327 }
328
329 public void exec(String[] args, PrintWriter writer) {
330 String arg = args[0];
331 switch (arg) {
332 case COMMAND_HELP:
333 dumpHelp(writer);
334 break;
335 case COMMAND_DAY_NIGHT_MODE:
336 String value = args.length < 1 ? "" : args[1];
337 forceDayNightMode(value, writer);
338 break;
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800339 case COMMAND_INJECT_EVENT:
340 String eventType;
341 if(args.length > 1) {
342 eventType = args[1];
343 // Zoned boolean event
344 if(eventType.equalsIgnoreCase(PARAM_ZONED_BOOLEAN)) {
345 if(args.length < 5) {
346 writer.println("Incorrect number of arguments.");
347 dumpHelp(writer);
348 break;
349 }
350 inject_zoned_boolean_event(args[2], args[3], args[4], writer);
351 }
352 }
353 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700354 default:
355 writer.println("Unknown command.");
356 dumpHelp(writer);
357 }
358 }
359
360 private void forceDayNightMode(String arg, PrintWriter writer) {
361 int mode;
362 switch (arg) {
363 case PARAM_DAY_MODE:
364 mode = CarNightService.FORCED_DAY_MODE;
365 break;
366 case PARAM_NIGHT_MODE:
367 mode = CarNightService.FORCED_NIGHT_MODE;
368 break;
369 case PARAM_SENSOR_MODE:
370 mode = CarNightService.FORCED_SENSOR_MODE;
371 break;
372 default:
373 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
374 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
375 return;
376 }
377 int current = mCarNightService.forceDayNightMode(mode);
378 String currentMode = null;
379 switch (current) {
380 case UiModeManager.MODE_NIGHT_AUTO:
381 currentMode = PARAM_SENSOR_MODE;
382 break;
383 case UiModeManager.MODE_NIGHT_YES:
384 currentMode = PARAM_NIGHT_MODE;
385 break;
386 case UiModeManager.MODE_NIGHT_NO:
387 currentMode = PARAM_DAY_MODE;
388 break;
389 }
390 writer.println("DayNightMode changed to: " + currentMode);
391 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800392
393 /**
394 * Inject a fake boolean HAL event to help testing.
395 * Currently supporting Door Unlock/Lock
396 * @param property - Vehicle Property
397 * @param value - boolean value for the property
398 * @param writer - Printwriter
399 */
400 private void inject_zoned_boolean_event(String property, String zone, String value, PrintWriter writer) {
401 Log.d(CarLog.TAG_SERVICE, "Injecting Boolean event");
402 boolean event;
403 int propId;
404 int zoneId;
405 if (value.equalsIgnoreCase("true")) {
406 event = true;
407 } else {
408 event = false;
409 }
410 try {
411 propId = Integer.decode(property);
412 zoneId = Integer.decode(zone);
413 } catch (NumberFormatException e) {
414 writer.println("Invalid property Id or Zone Id. Prefix hex values with 0x");
415 return;
416 }
417 mHal.injectBooleanEvent(propId, zoneId, event);
418 }
419
Yao Chene33f07e2016-07-26 12:02:51 -0700420 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800421}