blob: b85a41f03463c76cbe8b6d6744a7bb1e0e84e511 [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;
keunyoungca515072015-07-10 12:21:47 -070027import android.os.IBinder;
keunyoungca515072015-07-10 12:21:47 -070028import android.util.Log;
29
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080030import com.android.car.cluster.InstrumentClusterService;
keunyoungcc449f72015-08-12 10:46:27 -070031import com.android.car.hal.VehicleHal;
Antonio Cortesc52d5f92017-02-06 08:47:38 -080032import com.android.car.internal.FeatureConfiguration;
33import com.android.car.internal.FeatureUtil;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080034import com.android.car.pm.CarPackageManagerService;
keunyoungca515072015-07-10 12:21:47 -070035import com.android.internal.annotations.GuardedBy;
36
keunyounga3b28d82015-08-25 13:05:15 -070037import java.io.PrintWriter;
Antonio Cortese4619c72017-02-02 07:53:27 -080038import java.util.ArrayList;
39import java.util.Arrays;
40import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070041
keunyoungca515072015-07-10 12:21:47 -070042public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070043
Keun-young Parka28d7b22016-02-29 16:54:29 -080044 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070045 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
46 "system_activity_monitoring";
Keun-young Parka28d7b22016-02-29 16:54:29 -080047
48 // load jni for all services here
49 static {
Pavel Maltsev0d07c762016-11-03 16:40:15 -070050 try {
51 System.loadLibrary("jni_car_service");
52 } catch (UnsatisfiedLinkError ex) {
53 // Unable to load native library when loaded from the testing framework.
54 Log.e(CarLog.TAG_SERVICE, "Failed to load jni_car_service library: " + ex.getMessage());
55 }
Keun-young Parka28d7b22016-02-29 16:54:29 -080056 }
57
keunyoungca515072015-07-10 12:21:47 -070058 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080059 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070060
Keun-young Park4727da32016-05-31 10:00:51 -070061 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070062 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080063 private final CarPackageManagerService mCarPackageManagerService;
64 private final CarInputService mCarInputService;
keunyoungca515072015-07-10 12:21:47 -070065 private final CarSensorService mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -070066 private final CarInfoService mCarInfoService;
keunyoungd32f4e62015-09-21 11:33:06 -070067 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080068 private final CarProjectionService mCarProjectionService;
Steve Paik43c04a72016-07-08 19:12:09 -070069 private final CarCabinService mCarCabinService;
Steve Paik875616c2016-02-05 10:55:59 -080070 private final CarCameraService mCarCameraService;
Steve Paik66481982015-10-27 15:22:38 -070071 private final CarHvacService mCarHvacService;
Sanket Agarwal3cf096a2015-10-13 14:46:31 -070072 private final CarRadioService mCarRadioService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080073 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070074 private final AppFocusService mAppFocusService;
Yao Chen3a7976d2016-01-20 17:27:08 -080075 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080076 private final InstrumentClusterService mInstrumentClusterService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070077 private final SystemStateControllerService mSystemStateControllerService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -070078 private final CarVendorExtensionService mCarVendorExtensionService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080079 private final CarBluetoothService mCarBluetoothService;
Antonio Cortese4619c72017-02-02 07:53:27 -080080 @FutureFeature
Enrico Granata5c56d2a2017-02-07 15:38:12 -080081 private CarDiagnosticService mCarDiagnosticService;
82 @FutureFeature
Antonio Cortese4619c72017-02-02 07:53:27 -080083 private VmsSubscriberService mVmsSubscriberService;
Antonio Cortes6b3544c2017-02-06 16:54:58 -080084 @FutureFeature
85 private VmsPublisherService mVmsPublisherService;
keunyounga74b9ca2015-10-21 13:33:58 -070086
Pavel Maltsev0d07c762016-11-03 16:40:15 -070087 private final CarServiceBase[] mAllServices;
88
keunyoung1ab8e182015-09-24 09:25:22 -070089 /** Test only service. Populate it only when necessary. */
90 @GuardedBy("this")
91 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -070092
Pavel Maltsevec83b632017-01-05 15:10:55 -080093 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
94 CanBusErrorNotifier errorNotifier) {
keunyoungca515072015-07-10 12:21:47 -070095 mContext = serviceContext;
Pavel Maltsev0d07c762016-11-03 16:40:15 -070096 mHal = new VehicleHal(vehicle);
Keun-young Park4727da32016-05-31 10:00:51 -070097 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Pavel Maltsev0d07c762016-11-03 16:40:15 -070098 mCarPowerManagementService = new CarPowerManagementService(
99 mHal.getPowerHal(), systemInterface);
100 mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal());
Keun-young Park4727da32016-05-31 10:00:51 -0700101 mCarPackageManagerService = new CarPackageManagerService(serviceContext, mCarSensorService,
102 mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700103 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800104 mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService);
Yao Chen3a7976d2016-01-20 17:27:08 -0800105 mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700106 mCarInfoService = new CarInfoService(serviceContext, mHal.getInfoHal());
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700107 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700108 mCarAudioService = new CarAudioService(serviceContext, mHal.getAudioHal(),
Pavel Maltsevec83b632017-01-05 15:10:55 -0800109 mCarInputService, errorNotifier);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700110 mCarCabinService = new CarCabinService(serviceContext, mHal.getCabinHal());
111 mCarHvacService = new CarHvacService(serviceContext, mHal.getHvacHal());
112 mCarRadioService = new CarRadioService(serviceContext, mHal.getRadioHal());
Steve Paik875616c2016-02-05 10:55:59 -0800113 mCarCameraService = new CarCameraService(serviceContext);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700114 mCarNightService = new CarNightService(serviceContext, mCarSensorService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700115 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700116 mAppFocusService, mCarInputService);
Keun-young Parkd73afae2016-04-08 20:03:32 -0700117 mSystemStateControllerService = new SystemStateControllerService(serviceContext,
Keun-young Park3cb89102016-05-05 13:16:03 -0700118 mCarPowerManagementService, mCarAudioService, this);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700119 mCarVendorExtensionService = new CarVendorExtensionService(serviceContext,
120 mHal.getVendorExtensionHal());
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800121 mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService);
Antonio Cortese4619c72017-02-02 07:53:27 -0800122 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
123 mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal());
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800124 mVmsPublisherService = new VmsPublisherService(serviceContext, mHal.getVmsHal());
Antonio Cortese4619c72017-02-02 07:53:27 -0800125 }
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800126 if (FeatureConfiguration.ENABLE_DIAGNOSTIC) {
127 mCarDiagnosticService = new CarDiagnosticService(serviceContext,
128 mHal.getDiagnosticHal());
129 }
keunyounga74b9ca2015-10-21 13:33:58 -0700130
keunyounga3b28d82015-08-25 13:05:15 -0700131 // Be careful with order. Service depending on other service should be inited later.
Antonio Cortese4619c72017-02-02 07:53:27 -0800132 List<CarServiceBase> allServices = new ArrayList<>(Arrays.asList(
Keun-young Park4727da32016-05-31 10:00:51 -0700133 mSystemActivityMonitoringService,
keunyoung4b0212c2015-10-29 17:11:57 -0700134 mCarPowerManagementService,
Keun-young Park4727da32016-05-31 10:00:51 -0700135 mCarSensorService,
Keun-young Park45fdcba2015-12-08 11:38:58 -0800136 mCarPackageManagerService,
Keun-young Parka28d7b22016-02-29 16:54:29 -0800137 mCarInputService,
138 mGarageModeService,
keunyounga3b28d82015-08-25 13:05:15 -0700139 mCarInfoService,
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700140 mAppFocusService,
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700141 mCarAudioService,
Steve Paik43c04a72016-07-08 19:12:09 -0700142 mCarCabinService,
Steve Paik66481982015-10-27 15:22:38 -0700143 mCarHvacService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800144 mCarRadioService,
145 mCarCameraService,
Joseph Pirozzo317343d2016-01-25 10:22:37 -0800146 mCarNightService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800147 mInstrumentClusterService,
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800148 mCarProjectionService,
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700149 mSystemStateControllerService,
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800150 mCarVendorExtensionService,
151 mCarBluetoothService
Antonio Cortese4619c72017-02-02 07:53:27 -0800152 ));
153 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
154 allServices.add(mVmsSubscriberService);
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800155 allServices.add(mVmsPublisherService);
Antonio Cortese4619c72017-02-02 07:53:27 -0800156 }
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800157 if (FeatureConfiguration.ENABLE_DIAGNOSTIC) {
158 allServices.add(mCarDiagnosticService);
159 }
Antonio Cortese4619c72017-02-02 07:53:27 -0800160 mAllServices = allServices.toArray(new CarServiceBase[0]);
keunyoungca515072015-07-10 12:21:47 -0700161 }
162
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700163 public void init() {
164 mHal.init();
keunyounga3b28d82015-08-25 13:05:15 -0700165 for (CarServiceBase service: mAllServices) {
166 service.init();
167 }
keunyoungca515072015-07-10 12:21:47 -0700168 }
169
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700170 public void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700171 // release done in opposite order from init
172 for (int i = mAllServices.length - 1; i >= 0; i--) {
173 mAllServices[i].release();
174 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700175 mHal.release();
keunyoung1ab8e182015-09-24 09:25:22 -0700176 }
177
Pavel Maltsevec83b632017-01-05 15:10:55 -0800178 public void vehicleHalReconnected(IVehicle vehicle) {
179 mHal.vehicleHalReconnected(vehicle);
180 for (CarServiceBase service : mAllServices) {
181 service.vehicleHalReconnected();
182 }
183 }
184
keunyoungca515072015-07-10 12:21:47 -0700185 @Override
keunyoungca515072015-07-10 12:21:47 -0700186 public IBinder getCarService(String serviceName) {
187 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800188 case Car.AUDIO_SERVICE:
189 return mCarAudioService;
keunyoungca515072015-07-10 12:21:47 -0700190 case Car.SENSOR_SERVICE:
191 return mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -0700192 case Car.INFO_SERVICE:
193 return mCarInfoService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700194 case Car.APP_FOCUS_SERVICE:
195 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800196 case Car.PACKAGE_SERVICE:
197 return mCarPackageManagerService;
Steve Paik43c04a72016-07-08 19:12:09 -0700198 case Car.CABIN_SERVICE:
199 assertCabinPermission(mContext);
200 return mCarCabinService;
Steve Paik875616c2016-02-05 10:55:59 -0800201 case Car.CAMERA_SERVICE:
202 assertCameraPermission(mContext);
203 return mCarCameraService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800204 case Car.DIAGNOSTIC_SERVICE:
205 //TODO(egranata): handle permissions
206 return mCarDiagnosticService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800207 case Car.HVAC_SERVICE:
Steve Paik66481982015-10-27 15:22:38 -0700208 assertHvacPermission(mContext);
209 return mCarHvacService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800210 case Car.RADIO_SERVICE:
keunyoung6b197692015-11-16 13:54:38 -0800211 assertRadioPermission(mContext);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700212 return mCarRadioService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800213 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700214 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700215 IInstrumentClusterNavigation navService =
216 mInstrumentClusterService.getNavigationService();
217 return navService == null ? null : navService.asBinder();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800218 case Car.PROJECTION_SERVICE:
219 assertProjectionPermission(mContext);
220 return mCarProjectionService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700221 case Car.VENDOR_EXTENSION_SERVICE:
222 assertVendorExtensionPermission(mContext);
223 return mCarVendorExtensionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800224 case Car.VMS_SUBSCRIBER_SERVICE:
225 FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE);
226 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
227 assertVmsSubscriberPermission(mContext);
228 return mVmsSubscriberService;
229 }
Keun-young Parke54ac272016-02-16 19:02:18 -0800230 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700231 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700232 synchronized (this) {
233 if (mCarTestService == null) {
234 mCarTestService = new CarTestService(mContext, this);
235 }
236 return mCarTestService;
237 }
238 }
keunyoungca515072015-07-10 12:21:47 -0700239 default:
240 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
241 return null;
242 }
243 }
244
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800245 @Override
246 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700247 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800248 }
249
Keun-young Parka28d7b22016-02-29 16:54:29 -0800250 public CarServiceBase getCarInternalService(String serviceName) {
251 switch (serviceName) {
252 case INTERNAL_INPUT_SERVICE:
253 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700254 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
255 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800256 default:
257 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
258 serviceName);
259 return null;
260 }
261 }
262
keunyoung1ab8e182015-09-24 09:25:22 -0700263 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700264 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700265 }
266
Steve Paik43c04a72016-07-08 19:12:09 -0700267 public static void assertCabinPermission(Context context) {
268 assertPermission(context, Car.PERMISSION_CAR_CABIN);
269 }
270
Steve Paik875616c2016-02-05 10:55:59 -0800271 public static void assertCameraPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700272 assertPermission(context, Car.PERMISSION_CAR_CAMERA);
Steve Paik875616c2016-02-05 10:55:59 -0800273 }
274
Keun-young Parke31a8b22016-03-16 17:34:08 -0700275 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700276 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800277 }
278
Steve Paik66481982015-10-27 15:22:38 -0700279 public static void assertHvacPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700280 assertPermission(context, Car.PERMISSION_CAR_HVAC);
Steve Paik66481982015-10-27 15:22:38 -0700281 }
282
keunyoung6b197692015-11-16 13:54:38 -0800283 private static void assertRadioPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700284 assertPermission(context, Car.PERMISSION_CAR_RADIO);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700285 }
286
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800287 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700288 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
289 }
290
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700291 public static void assertVendorExtensionPermission(Context context) {
292 assertPermission(context, Car.PERMISSION_VENDOR_EXTENSION);
293 }
294
Antonio Cortese4619c72017-02-02 07:53:27 -0800295 @FutureFeature
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800296 public static void assertVmsPublisherPermission(Context context) {
297 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
298 }
299
300 @FutureFeature
Antonio Cortese4619c72017-02-02 07:53:27 -0800301 public static void assertVmsSubscriberPermission(Context context) {
302 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
303 }
304
Steve Paik461ecc62016-06-08 15:28:32 -0700305 public static void assertPermission(Context context, String permission) {
306 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
307 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800308 }
309 }
310
keunyoungcc449f72015-08-12 10:46:27 -0700311 void dump(PrintWriter writer) {
Keun-young Parkbae6e252017-01-25 12:30:15 -0800312 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
313 //TODO dump all feature flags by reflection
keunyounga3b28d82015-08-25 13:05:15 -0700314 writer.println("*Dump all services*");
315 for (CarServiceBase service: mAllServices) {
316 service.dump(writer);
317 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700318 if (mCarTestService != null) {
319 mCarTestService.dump(writer);
keunyoung1ab8e182015-09-24 09:25:22 -0700320 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700321 writer.println("*Dump Vehicle HAL*");
322 mHal.dump(writer);
keunyoungcc449f72015-08-12 10:46:27 -0700323 }
Yao Chene33f07e2016-07-26 12:02:51 -0700324
325 void execShellCmd(String[] args, PrintWriter writer) {
326 new CarShellCommand().exec(args, writer);
327 }
328
329 private class CarShellCommand {
330 private static final String COMMAND_HELP = "-h";
331 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
332 private static final String PARAM_DAY_MODE = "day";
333 private static final String PARAM_NIGHT_MODE = "night";
334 private static final String PARAM_SENSOR_MODE = "sensor";
335
336 private void dumpHelp(PrintWriter pw) {
337 pw.println("Car service commands:");
338 pw.println("\t-h");
339 pw.println("\t Print this help text.");
340 pw.println("\tday-night-mode [day|night|sensor]");
341 pw.println("\t Force into day/night mode or restore to auto.");
342 }
343
344 public void exec(String[] args, PrintWriter writer) {
345 String arg = args[0];
346 switch (arg) {
347 case COMMAND_HELP:
348 dumpHelp(writer);
349 break;
350 case COMMAND_DAY_NIGHT_MODE:
351 String value = args.length < 1 ? "" : args[1];
352 forceDayNightMode(value, writer);
353 break;
354 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 }
392 }
Antonio Cortese4619c72017-02-02 07:53:27 -0800393}