blob: d98ca2527976aa86be471225f64d9f34cfc258f8 [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;
keunyounga74b9ca2015-10-21 13:33:58 -070084
Pavel Maltsev0d07c762016-11-03 16:40:15 -070085 private final CarServiceBase[] mAllServices;
86
keunyoung1ab8e182015-09-24 09:25:22 -070087 /** Test only service. Populate it only when necessary. */
88 @GuardedBy("this")
89 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -070090
Pavel Maltsevec83b632017-01-05 15:10:55 -080091 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
92 CanBusErrorNotifier errorNotifier) {
keunyoungca515072015-07-10 12:21:47 -070093 mContext = serviceContext;
Pavel Maltsev0d07c762016-11-03 16:40:15 -070094 mHal = new VehicleHal(vehicle);
Keun-young Park4727da32016-05-31 10:00:51 -070095 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Pavel Maltsev0d07c762016-11-03 16:40:15 -070096 mCarPowerManagementService = new CarPowerManagementService(
97 mHal.getPowerHal(), systemInterface);
98 mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal());
Keun-young Park4727da32016-05-31 10:00:51 -070099 mCarPackageManagerService = new CarPackageManagerService(serviceContext, mCarSensorService,
100 mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700101 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800102 mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService);
Yao Chen3a7976d2016-01-20 17:27:08 -0800103 mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700104 mCarInfoService = new CarInfoService(serviceContext, mHal.getInfoHal());
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700105 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700106 mCarAudioService = new CarAudioService(serviceContext, mHal.getAudioHal(),
Pavel Maltsevec83b632017-01-05 15:10:55 -0800107 mCarInputService, errorNotifier);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700108 mCarCabinService = new CarCabinService(serviceContext, mHal.getCabinHal());
109 mCarHvacService = new CarHvacService(serviceContext, mHal.getHvacHal());
110 mCarRadioService = new CarRadioService(serviceContext, mHal.getRadioHal());
Steve Paik875616c2016-02-05 10:55:59 -0800111 mCarCameraService = new CarCameraService(serviceContext);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700112 mCarNightService = new CarNightService(serviceContext, mCarSensorService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700113 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700114 mAppFocusService, mCarInputService);
Keun-young Parkd73afae2016-04-08 20:03:32 -0700115 mSystemStateControllerService = new SystemStateControllerService(serviceContext,
Keun-young Park3cb89102016-05-05 13:16:03 -0700116 mCarPowerManagementService, mCarAudioService, this);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700117 mCarVendorExtensionService = new CarVendorExtensionService(serviceContext,
118 mHal.getVendorExtensionHal());
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800119 mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService);
Antonio Cortese4619c72017-02-02 07:53:27 -0800120 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
121 mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal());
122 }
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800123 if (FeatureConfiguration.ENABLE_DIAGNOSTIC) {
124 mCarDiagnosticService = new CarDiagnosticService(serviceContext,
125 mHal.getDiagnosticHal());
126 }
keunyounga74b9ca2015-10-21 13:33:58 -0700127
keunyounga3b28d82015-08-25 13:05:15 -0700128 // Be careful with order. Service depending on other service should be inited later.
Antonio Cortese4619c72017-02-02 07:53:27 -0800129 List<CarServiceBase> allServices = new ArrayList<>(Arrays.asList(
Keun-young Park4727da32016-05-31 10:00:51 -0700130 mSystemActivityMonitoringService,
keunyoung4b0212c2015-10-29 17:11:57 -0700131 mCarPowerManagementService,
Keun-young Park4727da32016-05-31 10:00:51 -0700132 mCarSensorService,
Keun-young Park45fdcba2015-12-08 11:38:58 -0800133 mCarPackageManagerService,
Keun-young Parka28d7b22016-02-29 16:54:29 -0800134 mCarInputService,
135 mGarageModeService,
keunyounga3b28d82015-08-25 13:05:15 -0700136 mCarInfoService,
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700137 mAppFocusService,
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700138 mCarAudioService,
Steve Paik43c04a72016-07-08 19:12:09 -0700139 mCarCabinService,
Steve Paik66481982015-10-27 15:22:38 -0700140 mCarHvacService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800141 mCarRadioService,
142 mCarCameraService,
Joseph Pirozzo317343d2016-01-25 10:22:37 -0800143 mCarNightService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800144 mInstrumentClusterService,
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800145 mCarProjectionService,
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700146 mSystemStateControllerService,
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800147 mCarVendorExtensionService,
148 mCarBluetoothService
Antonio Cortese4619c72017-02-02 07:53:27 -0800149 ));
150 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
151 allServices.add(mVmsSubscriberService);
152 }
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800153 if (FeatureConfiguration.ENABLE_DIAGNOSTIC) {
154 allServices.add(mCarDiagnosticService);
155 }
Antonio Cortese4619c72017-02-02 07:53:27 -0800156 mAllServices = allServices.toArray(new CarServiceBase[0]);
keunyoungca515072015-07-10 12:21:47 -0700157 }
158
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700159 public void init() {
160 mHal.init();
keunyounga3b28d82015-08-25 13:05:15 -0700161 for (CarServiceBase service: mAllServices) {
162 service.init();
163 }
keunyoungca515072015-07-10 12:21:47 -0700164 }
165
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700166 public void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700167 // release done in opposite order from init
168 for (int i = mAllServices.length - 1; i >= 0; i--) {
169 mAllServices[i].release();
170 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700171 mHal.release();
keunyoung1ab8e182015-09-24 09:25:22 -0700172 }
173
Pavel Maltsevec83b632017-01-05 15:10:55 -0800174 public void vehicleHalReconnected(IVehicle vehicle) {
175 mHal.vehicleHalReconnected(vehicle);
176 for (CarServiceBase service : mAllServices) {
177 service.vehicleHalReconnected();
178 }
179 }
180
keunyoungca515072015-07-10 12:21:47 -0700181 @Override
keunyoungca515072015-07-10 12:21:47 -0700182 public IBinder getCarService(String serviceName) {
183 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800184 case Car.AUDIO_SERVICE:
185 return mCarAudioService;
keunyoungca515072015-07-10 12:21:47 -0700186 case Car.SENSOR_SERVICE:
187 return mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -0700188 case Car.INFO_SERVICE:
189 return mCarInfoService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700190 case Car.APP_FOCUS_SERVICE:
191 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800192 case Car.PACKAGE_SERVICE:
193 return mCarPackageManagerService;
Steve Paik43c04a72016-07-08 19:12:09 -0700194 case Car.CABIN_SERVICE:
195 assertCabinPermission(mContext);
196 return mCarCabinService;
Steve Paik875616c2016-02-05 10:55:59 -0800197 case Car.CAMERA_SERVICE:
198 assertCameraPermission(mContext);
199 return mCarCameraService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800200 case Car.DIAGNOSTIC_SERVICE:
201 //TODO(egranata): handle permissions
202 return mCarDiagnosticService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800203 case Car.HVAC_SERVICE:
Steve Paik66481982015-10-27 15:22:38 -0700204 assertHvacPermission(mContext);
205 return mCarHvacService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800206 case Car.RADIO_SERVICE:
keunyoung6b197692015-11-16 13:54:38 -0800207 assertRadioPermission(mContext);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700208 return mCarRadioService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800209 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700210 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700211 IInstrumentClusterNavigation navService =
212 mInstrumentClusterService.getNavigationService();
213 return navService == null ? null : navService.asBinder();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800214 case Car.PROJECTION_SERVICE:
215 assertProjectionPermission(mContext);
216 return mCarProjectionService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700217 case Car.VENDOR_EXTENSION_SERVICE:
218 assertVendorExtensionPermission(mContext);
219 return mCarVendorExtensionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800220 case Car.VMS_SUBSCRIBER_SERVICE:
221 FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE);
222 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
223 assertVmsSubscriberPermission(mContext);
224 return mVmsSubscriberService;
225 }
Keun-young Parke54ac272016-02-16 19:02:18 -0800226 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700227 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700228 synchronized (this) {
229 if (mCarTestService == null) {
230 mCarTestService = new CarTestService(mContext, this);
231 }
232 return mCarTestService;
233 }
234 }
keunyoungca515072015-07-10 12:21:47 -0700235 default:
236 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
237 return null;
238 }
239 }
240
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800241 @Override
242 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700243 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800244 }
245
Keun-young Parka28d7b22016-02-29 16:54:29 -0800246 public CarServiceBase getCarInternalService(String serviceName) {
247 switch (serviceName) {
248 case INTERNAL_INPUT_SERVICE:
249 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700250 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
251 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800252 default:
253 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
254 serviceName);
255 return null;
256 }
257 }
258
keunyoung1ab8e182015-09-24 09:25:22 -0700259 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700260 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700261 }
262
Steve Paik43c04a72016-07-08 19:12:09 -0700263 public static void assertCabinPermission(Context context) {
264 assertPermission(context, Car.PERMISSION_CAR_CABIN);
265 }
266
Steve Paik875616c2016-02-05 10:55:59 -0800267 public static void assertCameraPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700268 assertPermission(context, Car.PERMISSION_CAR_CAMERA);
Steve Paik875616c2016-02-05 10:55:59 -0800269 }
270
Keun-young Parke31a8b22016-03-16 17:34:08 -0700271 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700272 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800273 }
274
Steve Paik66481982015-10-27 15:22:38 -0700275 public static void assertHvacPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700276 assertPermission(context, Car.PERMISSION_CAR_HVAC);
Steve Paik66481982015-10-27 15:22:38 -0700277 }
278
keunyoung6b197692015-11-16 13:54:38 -0800279 private static void assertRadioPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700280 assertPermission(context, Car.PERMISSION_CAR_RADIO);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700281 }
282
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800283 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700284 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
285 }
286
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700287 public static void assertVendorExtensionPermission(Context context) {
288 assertPermission(context, Car.PERMISSION_VENDOR_EXTENSION);
289 }
290
Antonio Cortese4619c72017-02-02 07:53:27 -0800291 @FutureFeature
292 public static void assertVmsSubscriberPermission(Context context) {
293 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
294 }
295
Steve Paik461ecc62016-06-08 15:28:32 -0700296 public static void assertPermission(Context context, String permission) {
297 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
298 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800299 }
300 }
301
keunyoungcc449f72015-08-12 10:46:27 -0700302 void dump(PrintWriter writer) {
Keun-young Parkbae6e252017-01-25 12:30:15 -0800303 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
304 //TODO dump all feature flags by reflection
keunyounga3b28d82015-08-25 13:05:15 -0700305 writer.println("*Dump all services*");
306 for (CarServiceBase service: mAllServices) {
307 service.dump(writer);
308 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700309 if (mCarTestService != null) {
310 mCarTestService.dump(writer);
keunyoung1ab8e182015-09-24 09:25:22 -0700311 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700312 writer.println("*Dump Vehicle HAL*");
313 mHal.dump(writer);
keunyoungcc449f72015-08-12 10:46:27 -0700314 }
Yao Chene33f07e2016-07-26 12:02:51 -0700315
316 void execShellCmd(String[] args, PrintWriter writer) {
317 new CarShellCommand().exec(args, writer);
318 }
319
320 private class CarShellCommand {
321 private static final String COMMAND_HELP = "-h";
322 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
323 private static final String PARAM_DAY_MODE = "day";
324 private static final String PARAM_NIGHT_MODE = "night";
325 private static final String PARAM_SENSOR_MODE = "sensor";
326
327 private void dumpHelp(PrintWriter pw) {
328 pw.println("Car service commands:");
329 pw.println("\t-h");
330 pw.println("\t Print this help text.");
331 pw.println("\tday-night-mode [day|night|sensor]");
332 pw.println("\t Force into day/night mode or restore to auto.");
333 }
334
335 public void exec(String[] args, PrintWriter writer) {
336 String arg = args[0];
337 switch (arg) {
338 case COMMAND_HELP:
339 dumpHelp(writer);
340 break;
341 case COMMAND_DAY_NIGHT_MODE:
342 String value = args.length < 1 ? "" : args[1];
343 forceDayNightMode(value, writer);
344 break;
345 default:
346 writer.println("Unknown command.");
347 dumpHelp(writer);
348 }
349 }
350
351 private void forceDayNightMode(String arg, PrintWriter writer) {
352 int mode;
353 switch (arg) {
354 case PARAM_DAY_MODE:
355 mode = CarNightService.FORCED_DAY_MODE;
356 break;
357 case PARAM_NIGHT_MODE:
358 mode = CarNightService.FORCED_NIGHT_MODE;
359 break;
360 case PARAM_SENSOR_MODE:
361 mode = CarNightService.FORCED_SENSOR_MODE;
362 break;
363 default:
364 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
365 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
366 return;
367 }
368 int current = mCarNightService.forceDayNightMode(mode);
369 String currentMode = null;
370 switch (current) {
371 case UiModeManager.MODE_NIGHT_AUTO:
372 currentMode = PARAM_SENSOR_MODE;
373 break;
374 case UiModeManager.MODE_NIGHT_YES:
375 currentMode = PARAM_NIGHT_MODE;
376 break;
377 case UiModeManager.MODE_NIGHT_NO:
378 currentMode = PARAM_DAY_MODE;
379 break;
380 }
381 writer.println("DayNightMode changed to: " + currentMode);
382 }
383 }
Antonio Cortese4619c72017-02-02 07:53:27 -0800384}