blob: 2f90d3dd9d8201573d70e95a7e84ea0092c3e1a9 [file] [log] [blame]
keunyoungca515072015-07-10 12:21:47 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car;
18
Pavel Maltsevabd47232017-10-10 16:54:57 -070019import android.annotation.MainThread;
Keun young Parkf3523cd2019-04-08 10:09:17 -070020import android.app.ActivityManager;
Yao Chene33f07e2016-07-26 12:02:51 -070021import android.app.UiModeManager;
Keun-young Parke54ac272016-02-16 19:02:18 -080022import android.car.Car;
23import android.car.ICar;
Pavel Maltsev0477e292016-05-27 12:22:36 -070024import android.car.cluster.renderer.IInstrumentClusterNavigation;
Ying Zheng9fc99402018-09-19 14:23:59 -070025import android.car.userlib.CarUserManagerHelper;
keunyoungca515072015-07-10 12:21:47 -070026import android.content.Context;
keunyoung1ab8e182015-09-24 09:25:22 -070027import android.content.pm.PackageManager;
Keun young Parkf3523cd2019-04-08 10:09:17 -070028import android.content.res.Resources;
Pavel Maltsevcfe93102017-02-02 12:38:08 -080029import android.hardware.automotive.vehicle.V2_0.IVehicle;
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -080030import android.hardware.automotive.vehicle.V2_0.VehicleArea;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070031import android.os.Binder;
Enrico Granatae8056ca2018-04-03 13:19:52 -070032import android.os.Build;
keunyoungca515072015-07-10 12:21:47 -070033import android.os.IBinder;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070034import android.os.Process;
Steve Paikc302c7c2017-08-04 14:01:58 -070035import android.os.Trace;
keunyoungca515072015-07-10 12:21:47 -070036import android.util.Log;
Steve Paikc302c7c2017-08-04 14:01:58 -070037import android.util.Slog;
Keun-young Park4a79a382017-08-10 18:19:14 -070038import android.util.TimingsTraceLog;
Gregory Clark26fa6012018-03-14 18:38:56 -070039
Hongwei Wang38549092018-08-22 12:32:42 -070040import com.android.car.audio.CarAudioService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080041import com.android.car.cluster.InstrumentClusterService;
Serik Beketayev06a66682018-06-12 16:54:29 -070042import com.android.car.garagemode.GarageModeService;
keunyoungcc449f72015-08-12 10:46:27 -070043import com.android.car.hal.VehicleHal;
Antonio Cortesc52d5f92017-02-06 08:47:38 -080044import com.android.car.internal.FeatureConfiguration;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080045import com.android.car.pm.CarPackageManagerService;
Enrico Granatab19bc322017-10-12 12:25:06 -070046import com.android.car.systeminterface.SystemInterface;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070047import com.android.car.trust.CarTrustedDeviceService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070048import com.android.car.user.CarUserService;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080049import com.android.car.vms.VmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -080050import com.android.car.vms.VmsClientManager;
keunyoungca515072015-07-10 12:21:47 -070051import com.android.internal.annotations.GuardedBy;
Steve Paik1d8bea22018-02-03 01:54:06 +000052import com.android.internal.car.ICarServiceHelper;
Gregory Clark26fa6012018-03-14 18:38:56 -070053
Enrico Granatae8056ca2018-04-03 13:19:52 -070054import java.io.FileDescriptor;
keunyounga3b28d82015-08-25 13:05:15 -070055import java.io.PrintWriter;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070056import java.util.ArrayList;
Antonio Cortese4619c72017-02-02 07:53:27 -080057import java.util.Arrays;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070058import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070059
keunyoungca515072015-07-10 12:21:47 -070060public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070061
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -080062 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070063 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
64 "system_activity_monitoring";
Keun-young Parka28d7b22016-02-29 16:54:29 -080065
keunyoungca515072015-07-10 12:21:47 -070066 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080067 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070068
Anthony Chen12aec302018-04-25 16:41:48 -070069 private final SystemInterface mSystemInterface;
70
Keun-young Park4727da32016-05-31 10:00:51 -070071 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070072 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080073 private final CarPackageManagerService mCarPackageManagerService;
74 private final CarInputService mCarInputService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -080075 private final CarDrivingStateService mCarDrivingStateService;
Ram Periathiruvadi4526a432018-01-24 13:00:54 -080076 private final CarUxRestrictionsManagerService mCarUXRestrictionsService;
keunyoungd32f4e62015-09-21 11:33:06 -070077 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080078 private final CarProjectionService mCarProjectionService;
Steve Paik9ec53d72018-04-27 13:28:31 -070079 private final CarPropertyService mCarPropertyService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080080 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070081 private final AppFocusService mAppFocusService;
Yao Chen3a7976d2016-01-20 17:27:08 -080082 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080083 private final InstrumentClusterService mInstrumentClusterService;
Gregory Clarkd8136062017-12-11 14:27:53 -080084 private final CarLocationService mCarLocationService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070085 private final SystemStateControllerService mSystemStateControllerService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080086 private final CarBluetoothService mCarBluetoothService;
Ram Periathiruvadiacb60242017-04-13 16:19:09 -070087 private final PerUserCarServiceHelper mPerUserCarServiceHelper;
Enrico Granata9a916d72017-09-19 14:33:08 -070088 private final CarDiagnosticService mCarDiagnosticService;
89 private final CarStorageMonitoringService mCarStorageMonitoringService;
Anthony Chen12aec302018-04-25 16:41:48 -070090 private final CarConfigurationService mCarConfigurationService;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070091 private final CarTrustedDeviceService mCarTrustedDeviceService;
Simon Dai527eb552019-02-12 13:06:15 -080092 private final CarMediaService mCarMediaService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070093 private final CarUserManagerHelper mUserManagerHelper;
Keun-young Parkd462a912019-02-11 08:53:42 -080094 private final CarUserService mCarUserService;
Mark Tabrya8fce562019-01-16 16:24:01 -080095 private final VmsClientManager mVmsClientManager;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080096 private final VmsBrokerService mVmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -080097 private final VmsSubscriberService mVmsSubscriberService;
98 private final VmsPublisherService mVmsPublisherService;
Selim Gurunc8c82f62019-04-17 14:07:30 -070099 private final CarBugreportManagerService mCarBugreportManagerService;
keunyounga74b9ca2015-10-21 13:33:58 -0700100
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700101 private final CarServiceBase[] mAllServices;
102
Steve Paikc302c7c2017-08-04 14:01:58 -0700103 private static final String TAG = "ICarImpl";
104 private static final String VHAL_TIMING_TAG = "VehicleHalTiming";
Serik Beketayev74debf22018-10-04 12:18:09 -0700105
106 private TimingsTraceLog mBootTiming;
Steve Paikc302c7c2017-08-04 14:01:58 -0700107
keunyoung1ab8e182015-09-24 09:25:22 -0700108 /** Test only service. Populate it only when necessary. */
109 @GuardedBy("this")
110 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -0700111
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700112 @GuardedBy("this")
113 private ICarServiceHelper mICarServiceHelper;
114
Enrico Granatae8056ca2018-04-03 13:19:52 -0700115 private final String mVehicleInterfaceName;
116
Pavel Maltsevec83b632017-01-05 15:10:55 -0800117 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
Enrico Granatae8056ca2018-04-03 13:19:52 -0700118 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) {
keunyoungca515072015-07-10 12:21:47 -0700119 mContext = serviceContext;
Steve Paik0f9fc002018-02-09 17:42:00 -0800120 mSystemInterface = systemInterface;
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700121 mHal = new VehicleHal(vehicle);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700122 mVehicleInterfaceName = vehicleInterfaceName;
Yao, Yuxing0811d5a2018-11-29 16:18:53 -0800123 mUserManagerHelper = new CarUserManagerHelper(serviceContext);
Keun young Parkf3523cd2019-04-08 10:09:17 -0700124 final Resources res = mContext.getResources();
125 final int maxRunningUsers = res.getInteger(
126 com.android.internal.R.integer.config_multiuserMaxRunningUsers);
127 mCarUserService = new CarUserService(serviceContext, mUserManagerHelper,
128 ActivityManager.getService(), maxRunningUsers);
Keun-young Park4727da32016-05-31 10:00:51 -0700129 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Steve Paik388d7772018-02-12 10:54:51 -0800130 mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(),
Keun young Park9b3f2662019-03-19 10:30:25 -0700131 systemInterface, mUserManagerHelper);
Steve Paik9ec53d72018-04-27 13:28:31 -0700132 mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal());
133 mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService);
Ram Periathiruvadi4526a432018-01-24 13:00:54 -0800134 mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext,
Yao, Yuxing9bfb7492019-02-15 11:53:34 -0800135 mCarDrivingStateService, mCarPropertyService);
Ram Periathiruvadi2da6d0e2018-01-26 18:02:10 -0800136 mCarPackageManagerService = new CarPackageManagerService(serviceContext,
137 mCarUXRestrictionsService,
Pavel Maltsev38da4312019-04-08 10:38:38 -0700138 mSystemActivityMonitoringService,
139 mUserManagerHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800140 mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext);
Sal Savage703c46f2019-04-15 08:39:25 -0700141 mCarBluetoothService = new CarBluetoothService(serviceContext, mPerUserCarServiceHelper);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700142 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Justin Paupore44985ba2019-01-30 18:53:41 -0800143 mCarProjectionService = new CarProjectionService(
Pavel Maltsev079873b2019-02-25 12:15:09 -0800144 serviceContext, null /* handler */, mCarInputService, mCarBluetoothService);
Serik Beketayevc6ab8be2018-08-28 21:20:53 -0700145 mGarageModeService = new GarageModeService(mContext);
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700146 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Hongwei Wang30557232018-01-02 10:25:08 -0800147 mCarAudioService = new CarAudioService(serviceContext);
Steve Paik9ec53d72018-04-27 13:28:31 -0700148 mCarNightService = new CarNightService(serviceContext, mCarPropertyService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700149 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700150 mAppFocusService, mCarInputService);
Serik Beketayevf9f2ef02018-09-06 12:37:02 -0700151 mSystemStateControllerService = new SystemStateControllerService(
152 serviceContext, mCarAudioService, this);
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800153 mVmsBrokerService = new VmsBrokerService();
Mark Tabry1534c062019-03-29 01:30:49 -0700154 mVmsClientManager = new VmsClientManager(
Mark Tabry41437562019-04-04 10:37:33 -0700155 serviceContext, mCarUserService, mUserManagerHelper, mHal.getVmsHal());
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800156 mVmsSubscriberService = new VmsSubscriberService(
157 serviceContext, mVmsBrokerService, mHal.getVmsHal());
158 mVmsPublisherService = new VmsPublisherService(
Mark Tabry1534c062019-03-29 01:30:49 -0700159 serviceContext, mVmsBrokerService, mVmsClientManager);
Enrico Granatab3634e22017-05-05 18:02:31 -0700160 mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal());
Enrico Granata517a1e02017-09-20 16:15:50 -0700161 mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext,
162 systemInterface);
Anthony Chen12aec302018-04-25 16:41:48 -0700163 mCarConfigurationService =
164 new CarConfigurationService(serviceContext, new JsonReaderImpl());
Gregory Clarke1519532019-05-10 16:25:57 -0700165 mCarLocationService = new CarLocationService(mContext, mUserManagerHelper);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700166 mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext);
Simon Dai527eb552019-02-12 13:06:15 -0800167 mCarMediaService = new CarMediaService(serviceContext);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700168 mCarBugreportManagerService = new CarBugreportManagerService(serviceContext);
keunyounga74b9ca2015-10-21 13:33:58 -0700169
Keun young Parka5fa4782019-04-16 18:56:27 -0700170 CarLocalServices.addService(CarPowerManagementService.class, mCarPowerManagementService);
Keun-young Parkd462a912019-02-11 08:53:42 -0800171 CarLocalServices.addService(CarUserService.class, mCarUserService);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700172 CarLocalServices.addService(CarTrustedDeviceService.class,
173 mCarTrustedDeviceService);
Gregory Clarka440e812019-02-14 16:05:51 -0800174 CarLocalServices.addService(SystemInterface.class, mSystemInterface);
Keun-young Parkd462a912019-02-11 08:53:42 -0800175
keunyounga3b28d82015-08-25 13:05:15 -0700176 // Be careful with order. Service depending on other service should be inited later.
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700177 List<CarServiceBase> allServices = new ArrayList<>();
Keun-young Parkd462a912019-02-11 08:53:42 -0800178 allServices.add(mCarUserService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700179 allServices.add(mSystemActivityMonitoringService);
180 allServices.add(mCarPowerManagementService);
181 allServices.add(mCarPropertyService);
182 allServices.add(mCarDrivingStateService);
183 allServices.add(mCarUXRestrictionsService);
184 allServices.add(mCarPackageManagerService);
185 allServices.add(mCarInputService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700186 allServices.add(mGarageModeService);
187 allServices.add(mAppFocusService);
188 allServices.add(mCarAudioService);
189 allServices.add(mCarNightService);
190 allServices.add(mInstrumentClusterService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700191 allServices.add(mSystemStateControllerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700192 allServices.add(mPerUserCarServiceHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800193 allServices.add(mCarBluetoothService);
194 allServices.add(mCarProjectionService);
195 allServices.add(mCarDiagnosticService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700196 allServices.add(mCarStorageMonitoringService);
197 allServices.add(mCarConfigurationService);
Mark Tabrya8fce562019-01-16 16:24:01 -0800198 allServices.add(mVmsClientManager);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700199 allServices.add(mVmsSubscriberService);
200 allServices.add(mVmsPublisherService);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700201 allServices.add(mCarTrustedDeviceService);
Simon Dai527eb552019-02-12 13:06:15 -0800202 allServices.add(mCarMediaService);
Gregory Clarka63ba022018-06-07 16:42:12 -0700203 allServices.add(mCarLocationService);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700204 allServices.add(mCarBugreportManagerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700205 mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]);
keunyoungca515072015-07-10 12:21:47 -0700206 }
207
Pavel Maltsevabd47232017-10-10 16:54:57 -0700208 @MainThread
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700209 void init() {
Serik Beketayev74debf22018-10-04 12:18:09 -0700210 mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL);
Steve Paikc302c7c2017-08-04 14:01:58 -0700211 traceBegin("VehicleHal.init");
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700212 mHal.init();
Steve Paikc302c7c2017-08-04 14:01:58 -0700213 traceEnd();
214 traceBegin("CarService.initAllServices");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800215 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700216 service.init();
217 }
Steve Paikc302c7c2017-08-04 14:01:58 -0700218 traceEnd();
keunyoungca515072015-07-10 12:21:47 -0700219 }
220
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700221 void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700222 // release done in opposite order from init
223 for (int i = mAllServices.length - 1; i >= 0; i--) {
224 mAllServices[i].release();
225 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700226 mHal.release();
Keun-young Parkd462a912019-02-11 08:53:42 -0800227 CarLocalServices.removeAllServices();
keunyoung1ab8e182015-09-24 09:25:22 -0700228 }
229
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700230 void vehicleHalReconnected(IVehicle vehicle) {
Pavel Maltsevec83b632017-01-05 15:10:55 -0800231 mHal.vehicleHalReconnected(vehicle);
232 for (CarServiceBase service : mAllServices) {
233 service.vehicleHalReconnected();
234 }
235 }
236
keunyoungca515072015-07-10 12:21:47 -0700237 @Override
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700238 public void setCarServiceHelper(IBinder helper) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700239 assertCallingFromSystemProcess();
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700240 synchronized (this) {
241 mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper);
Steve Paik0f9fc002018-02-09 17:42:00 -0800242 mSystemInterface.setCarServiceHelper(mICarServiceHelper);
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700243 }
244 }
245
246 @Override
Keun-young Parkd462a912019-02-11 08:53:42 -0800247 public void setUserLockStatus(int userHandle, int unlocked) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700248 assertCallingFromSystemProcess();
249 mCarUserService.setUserLockStatus(userHandle, unlocked == 1);
250 }
251
252 @Override
253 public void onSwitchUser(int userHandle) {
254 assertCallingFromSystemProcess();
255
256 Log.i(TAG, "Foreground user switched to " + userHandle);
257 mCarUserService.onSwitchUser(userHandle);
258 }
259
Jim Kayee5133162019-04-22 12:50:27 -0700260 static void assertCallingFromSystemProcess() {
Keun-young Parkd462a912019-02-11 08:53:42 -0800261 int uid = Binder.getCallingUid();
262 if (uid != Process.SYSTEM_UID) {
263 throw new SecurityException("Only allowed from system");
264 }
Keun-young Parkd462a912019-02-11 08:53:42 -0800265 }
266
Keun young Parkaabecd92019-05-03 17:31:27 -0700267 /**
268 * Assert if binder call is coming from system process like system server or if it is called
269 * from its own process even if it is not system. The latter can happen in test environment.
270 * Note that car service runs as system user but test like car service test will not.
271 */
272 static void assertCallingFromSystemProcessOrSelf() {
273 int uid = Binder.getCallingUid();
274 int pid = Binder.getCallingPid();
275 if (uid != Process.SYSTEM_UID && pid != Process.myPid()) {
276 throw new SecurityException("Only allowed from system or self");
277 }
278 }
279
Keun-young Parkd462a912019-02-11 08:53:42 -0800280 @Override
keunyoungca515072015-07-10 12:21:47 -0700281 public IBinder getCarService(String serviceName) {
282 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800283 case Car.AUDIO_SERVICE:
284 return mCarAudioService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700285 case Car.APP_FOCUS_SERVICE:
286 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800287 case Car.PACKAGE_SERVICE:
288 return mCarPackageManagerService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800289 case Car.DIAGNOSTIC_SERVICE:
Enrico Granatab3634e22017-05-05 18:02:31 -0700290 assertAnyDiagnosticPermission(mContext);
291 return mCarDiagnosticService;
Steve Paik388d7772018-02-12 10:54:51 -0800292 case Car.POWER_SERVICE:
293 assertPowerPermission(mContext);
294 return mCarPowerManagementService;
Steve Paik9ec53d72018-04-27 13:28:31 -0700295 case Car.CABIN_SERVICE:
296 case Car.HVAC_SERVICE:
297 case Car.INFO_SERVICE:
298 case Car.PROPERTY_SERVICE:
299 case Car.SENSOR_SERVICE:
300 case Car.VENDOR_EXTENSION_SERVICE:
301 return mCarPropertyService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800302 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700303 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700304 IInstrumentClusterNavigation navService =
305 mInstrumentClusterService.getNavigationService();
306 return navService == null ? null : navService.asBinder();
Pavel Maltsev905968c2017-07-16 19:48:57 -0700307 case Car.CAR_INSTRUMENT_CLUSTER_SERVICE:
308 assertClusterManagerPermission(mContext);
309 return mInstrumentClusterService.getManagerService();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800310 case Car.PROJECTION_SERVICE:
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800311 return mCarProjectionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800312 case Car.VMS_SUBSCRIBER_SERVICE:
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700313 assertVmsSubscriberPermission(mContext);
314 return mVmsSubscriberService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800315 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700316 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700317 synchronized (this) {
318 if (mCarTestService == null) {
319 mCarTestService = new CarTestService(mContext, this);
320 }
321 return mCarTestService;
322 }
323 }
Ram Periathiruvadi76a84892017-07-27 18:10:35 -0700324 case Car.BLUETOOTH_SERVICE:
325 return mCarBluetoothService;
Enrico Granata9a916d72017-09-19 14:33:08 -0700326 case Car.STORAGE_MONITORING_SERVICE:
Enrico Granata1172f882017-09-21 14:51:30 -0700327 assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING);
Enrico Granata9a916d72017-09-19 14:33:08 -0700328 return mCarStorageMonitoringService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800329 case Car.CAR_DRIVING_STATE_SERVICE:
330 assertDrivingStatePermission(mContext);
331 return mCarDrivingStateService;
332 case Car.CAR_UX_RESTRICTION_SERVICE:
333 return mCarUXRestrictionsService;
Anthony Chend4203d82018-05-16 16:21:52 -0700334 case Car.CAR_CONFIGURATION_SERVICE:
335 return mCarConfigurationService;
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800336 case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE:
337 assertTrustAgentEnrollmentPermission(mContext);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700338 return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService();
Simon Dai527eb552019-02-12 13:06:15 -0800339 case Car.CAR_MEDIA_SERVICE:
340 return mCarMediaService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700341 case Car.CAR_BUGREPORT_SERVICE:
342 return mCarBugreportManagerService;
keunyoungca515072015-07-10 12:21:47 -0700343 default:
344 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
345 return null;
346 }
347 }
348
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800349 @Override
350 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700351 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800352 }
353
Keun-young Parka28d7b22016-02-29 16:54:29 -0800354 public CarServiceBase getCarInternalService(String serviceName) {
355 switch (serviceName) {
356 case INTERNAL_INPUT_SERVICE:
357 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700358 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
359 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800360 default:
361 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
362 serviceName);
363 return null;
364 }
365 }
366
keunyoung1ab8e182015-09-24 09:25:22 -0700367 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700368 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700369 }
370
Keun-young Parke31a8b22016-03-16 17:34:08 -0700371 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700372 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800373 }
374
Pavel Maltsev905968c2017-07-16 19:48:57 -0700375 public static void assertClusterManagerPermission(Context context) {
376 assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL);
377 }
378
Steve Paik388d7772018-02-12 10:54:51 -0800379 public static void assertPowerPermission(Context context) {
380 assertPermission(context, Car.PERMISSION_CAR_POWER);
381 }
382
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800383 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700384 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
385 }
386
Pavel Maltsev079873b2019-02-25 12:15:09 -0800387 /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */
388 public static void assertProjectionStatusPermission(Context context) {
389 assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS);
390 }
391
Enrico Granata3c7a6662017-02-23 18:07:59 -0800392 public static void assertAnyDiagnosticPermission(Context context) {
393 assertAnyPermission(context,
Enrico Granataae25b922017-07-07 11:28:15 -0700394 Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL,
Enrico Granata3c7a6662017-02-23 18:07:59 -0800395 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
396 }
397
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800398 public static void assertDrivingStatePermission(Context context) {
399 assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE);
400 }
401
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800402 public static void assertVmsPublisherPermission(Context context) {
403 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
404 }
405
Antonio Cortese4619c72017-02-02 07:53:27 -0800406 public static void assertVmsSubscriberPermission(Context context) {
407 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
408 }
409
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800410 /**
411 * Ensures the caller has the permission to enroll a Trust Agent.
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800412 */
413 public static void assertTrustAgentEnrollmentPermission(Context context) {
414 assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST);
415 }
416
Steve Paik461ecc62016-06-08 15:28:32 -0700417 public static void assertPermission(Context context, String permission) {
418 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
419 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800420 }
421 }
422
Steve Paik9ec53d72018-04-27 13:28:31 -0700423 /**
424 * Checks to see if the caller has a permission.
Steve Paik9ec53d72018-04-27 13:28:31 -0700425 *
426 * @return boolean TRUE if caller has the permission.
427 */
428 public static boolean hasPermission(Context context, String permission) {
429 return context.checkCallingOrSelfPermission(permission)
430 == PackageManager.PERMISSION_GRANTED;
431 }
432
Enrico Granata3c7a6662017-02-23 18:07:59 -0800433 public static void assertAnyPermission(Context context, String... permissions) {
434 for (String permission : permissions) {
435 if (context.checkCallingOrSelfPermission(permission) ==
436 PackageManager.PERMISSION_GRANTED) {
437 return;
438 }
439 }
440 throw new SecurityException("requires any of " + Arrays.toString(permissions));
441 }
442
Enrico Granatae8056ca2018-04-03 13:19:52 -0700443 @Override
444 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
445 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Anthony Chen12aec302018-04-25 16:41:48 -0700446 != PackageManager.PERMISSION_GRANTED) {
Enrico Granatae8056ca2018-04-03 13:19:52 -0700447 writer.println("Permission Denial: can't dump CarService from from pid="
Anthony Chen12aec302018-04-25 16:41:48 -0700448 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
449 + " without permission " + android.Manifest.permission.DUMP);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700450 return;
keunyounga3b28d82015-08-25 13:05:15 -0700451 }
Enrico Granatae8056ca2018-04-03 13:19:52 -0700452 if (args == null || args.length == 0) {
453 writer.println("*dump car service*");
454
455 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
456 writer.println("*Dump all services*");
457 for (CarServiceBase service : mAllServices) {
458 dumpService(service, writer);
459 }
460 if (mCarTestService != null) {
461 dumpService(mCarTestService, writer);
462 }
463 writer.println("*Dump Vehicle HAL*");
464 writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName);
465 try {
466 // TODO dump all feature flags by creating a dumpable interface
467 mHal.dump(writer);
468 } catch (Exception e) {
469 writer.println("Failed dumping: " + mHal.getClass().getName());
470 e.printStackTrace(writer);
471 }
472 } else if (Build.IS_USERDEBUG || Build.IS_ENG) {
473 execShellCmd(args, writer);
474 } else {
475 writer.println("Commands not supported in " + Build.TYPE);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800476 }
477 }
478
479 private void dumpService(CarServiceBase service, PrintWriter writer) {
480 try {
481 service.dump(writer);
482 } catch (Exception e) {
483 writer.println("Failed dumping: " + service.getClass().getName());
484 e.printStackTrace(writer);
485 }
keunyoungcc449f72015-08-12 10:46:27 -0700486 }
Yao Chene33f07e2016-07-26 12:02:51 -0700487
488 void execShellCmd(String[] args, PrintWriter writer) {
489 new CarShellCommand().exec(args, writer);
490 }
491
Pavel Maltsevabd47232017-10-10 16:54:57 -0700492 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700493 private void traceBegin(String name) {
Steve Paikc302c7c2017-08-04 14:01:58 -0700494 Slog.i(TAG, name);
495 mBootTiming.traceBegin(name);
496 }
497
Pavel Maltsevabd47232017-10-10 16:54:57 -0700498 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700499 private void traceEnd() {
Steve Paikc302c7c2017-08-04 14:01:58 -0700500 mBootTiming.traceEnd();
501 }
502
Yao Chene33f07e2016-07-26 12:02:51 -0700503 private class CarShellCommand {
504 private static final String COMMAND_HELP = "-h";
505 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800506 private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event";
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800507 private static final String COMMAND_ENABLE_UXR = "enable-uxr";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800508 private static final String COMMAND_GARAGE_MODE = "garage-mode";
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800509 private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities";
Kaidd4ef5a2019-03-04 14:07:26 -0800510 private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig";
Kai29fba112019-04-22 18:37:38 -0700511 private static final String COMMAND_GET_PROPERTY_VALUE = "get-property-value";
Pavel Maltsev48a31942019-03-03 22:08:28 -0800512 private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode";
Jim Kayed76c2742019-04-02 11:33:27 -0700513 private static final String COMMAND_RESUME = "resume";
514 private static final String COMMAND_SUSPEND = "suspend";
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700515 private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device";
516 private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800517
Yao Chene33f07e2016-07-26 12:02:51 -0700518 private static final String PARAM_DAY_MODE = "day";
519 private static final String PARAM_NIGHT_MODE = "night";
520 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800521 private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800522 private static final String PARAM_ON_MODE = "on";
523 private static final String PARAM_OFF_MODE = "off";
524 private static final String PARAM_QUERY_MODE = "query";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800525
Yao Chene33f07e2016-07-26 12:02:51 -0700526
527 private void dumpHelp(PrintWriter pw) {
528 pw.println("Car service commands:");
529 pw.println("\t-h");
530 pw.println("\t Print this help text.");
531 pw.println("\tday-night-mode [day|night|sensor]");
532 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800533 pw.println("\tinject-vhal-event property [zone] data(can be comma separated list)");
Jim Kayef10b7d82019-02-26 12:53:22 -0800534 pw.println("\t Inject a vehicle property for testing.");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700535 pw.println("\tenable-uxr true|false");
536 pw.println("\t Enable/Disable UX restrictions and App blocking.");
Bryan Eylera32a7c12018-02-27 15:40:00 -0800537 pw.println("\tgarage-mode [on|off|query]");
538 pw.println("\t Force into garage mode or check status.");
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800539 pw.println("\tget-do-activities pkgname");
Jim Kayef10b7d82019-02-26 12:53:22 -0800540 pw.println("\t Get Distraction Optimized activities in given package.");
Kaidd4ef5a2019-03-04 14:07:26 -0800541 pw.println("\tget-carpropertyconfig [propertyId]");
542 pw.println("\t Get a CarPropertyConfig by Id in Hex or list all CarPropertyConfigs");
Kai29fba112019-04-22 18:37:38 -0700543 pw.println("\tget-property-value [propertyId] [areaId]");
544 pw.println("\t Get a vehicle property value by property id in Hex and areaId");
545 pw.println("\t or list all property values for all areaId");
Jim Kayed76c2742019-04-02 11:33:27 -0700546 pw.println("\tsuspend");
547 pw.println("\t Suspend the system to Deep Sleep.");
548 pw.println("\tresume");
549 pw.println("\t Wake the system up after a 'suspend.'");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700550 pw.println("\tenable-trusted-device true|false");
551 pw.println("\t Enable/Disable Trusted device feature.");
552 pw.println("\tremove-trusted-devices");
553 pw.println("\t Remove all trusted devices for the current foreground user.");
Yao Chene33f07e2016-07-26 12:02:51 -0700554 }
555
556 public void exec(String[] args, PrintWriter writer) {
557 String arg = args[0];
558 switch (arg) {
559 case COMMAND_HELP:
560 dumpHelp(writer);
561 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800562 case COMMAND_DAY_NIGHT_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800563 String value = args.length < 2 ? "" : args[1];
Yao Chene33f07e2016-07-26 12:02:51 -0700564 forceDayNightMode(value, writer);
565 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800566 }
567 case COMMAND_GARAGE_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800568 String value = args.length < 2 ? "" : args[1];
Bryan Eylera32a7c12018-02-27 15:40:00 -0800569 forceGarageMode(value, writer);
570 break;
571 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800572 case COMMAND_INJECT_VHAL_EVENT:
573 String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL;
574 String data;
Jim Kayef10b7d82019-02-26 12:53:22 -0800575 if (args.length != 3 && args.length != 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800576 writer.println("Incorrect number of arguments.");
577 dumpHelp(writer);
578 break;
Jim Kayef10b7d82019-02-26 12:53:22 -0800579 } else if (args.length == 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800580 // Zoned
581 zone = args[2];
582 data = args[3];
583 } else {
584 // Global
585 data = args[2];
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800586 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800587 injectVhalEvent(args[1], zone, data, writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800588 break;
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800589 case COMMAND_ENABLE_UXR:
Jim Kayef10b7d82019-02-26 12:53:22 -0800590 if (args.length != 2) {
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800591 writer.println("Incorrect number of arguments");
592 dumpHelp(writer);
593 break;
594 }
595 boolean enableBlocking = Boolean.valueOf(args[1]);
596 if (mCarPackageManagerService != null) {
597 mCarPackageManagerService.setEnableActivityBlocking(enableBlocking);
598 }
599 break;
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800600 case COMMAND_GET_DO_ACTIVITIES:
Jim Kayef10b7d82019-02-26 12:53:22 -0800601 if (args.length != 2) {
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800602 writer.println("Incorrect number of arguments");
603 dumpHelp(writer);
604 break;
605 }
606 String pkgName = args[1].toLowerCase();
607 if (mCarPackageManagerService != null) {
608 String[] doActivities =
609 mCarPackageManagerService.getDistractionOptimizedActivities(
610 pkgName);
611 if (doActivities != null) {
612 writer.println("DO Activities for " + pkgName);
613 for (String a : doActivities) {
614 writer.println(a);
615 }
616 } else {
617 writer.println("No DO Activities for " + pkgName);
618 }
619 }
620 break;
Kaidd4ef5a2019-03-04 14:07:26 -0800621 case COMMAND_GET_CARPROPERTYCONFIG:
622 String propertyId = args.length < 2 ? "" : args[1];
623 mHal.dumpPropertyConfigs(writer, propertyId);
624 break;
Kai29fba112019-04-22 18:37:38 -0700625 case COMMAND_GET_PROPERTY_VALUE:
626 String propId = args.length < 2 ? "" : args[1];
627 String areaId = args.length < 3 ? "" : args[2];
628 mHal.dumpPropertyValueByCommend(writer, propId, areaId);
629 break;
Pavel Maltsev48a31942019-03-03 22:08:28 -0800630 case COMMAND_PROJECTION_UI_MODE:
631 if (args.length != 2) {
632 writer.println("Incorrect number of arguments");
633 dumpHelp(writer);
634 break;
635 }
636 mCarProjectionService.setUiMode(Integer.valueOf(args[1]));
Pavel Maltsevd6961f62019-03-26 10:22:31 -0700637 break;
Jim Kayed76c2742019-04-02 11:33:27 -0700638 case COMMAND_RESUME:
639 mCarPowerManagementService.forceSimulatedResume();
640 writer.println("Resume: Simulating resuming from Deep Sleep");
641 break;
642 case COMMAND_SUSPEND:
643 mCarPowerManagementService.forceSimulatedSuspend();
644 writer.println("Resume: Simulating powering down to Deep Sleep");
645 break;
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700646 case COMMAND_ENABLE_TRUSTED_DEVICE:
647 if (args.length != 2) {
648 writer.println("Incorrect number of arguments");
649 dumpHelp(writer);
650 break;
651 }
652 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
653 .setTrustedDeviceEnrollmentEnabled(Boolean.valueOf(args[1]));
654 mCarTrustedDeviceService.getCarTrustAgentUnlockService()
655 .setTrustedDeviceUnlockEnabled(Boolean.valueOf(args[1]));
656 break;
657 case COMMAND_REMOVE_TRUSTED_DEVICES:
658 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
659 .removeAllTrustedDevices(
660 mUserManagerHelper.getCurrentForegroundUserId());
661 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700662 default:
Jim Kayef10b7d82019-02-26 12:53:22 -0800663 writer.println("Unknown command: \"" + arg + "\"");
Yao Chene33f07e2016-07-26 12:02:51 -0700664 dumpHelp(writer);
665 }
666 }
667
668 private void forceDayNightMode(String arg, PrintWriter writer) {
669 int mode;
670 switch (arg) {
671 case PARAM_DAY_MODE:
672 mode = CarNightService.FORCED_DAY_MODE;
673 break;
674 case PARAM_NIGHT_MODE:
675 mode = CarNightService.FORCED_NIGHT_MODE;
676 break;
677 case PARAM_SENSOR_MODE:
678 mode = CarNightService.FORCED_SENSOR_MODE;
679 break;
680 default:
681 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
682 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
683 return;
684 }
685 int current = mCarNightService.forceDayNightMode(mode);
686 String currentMode = null;
687 switch (current) {
688 case UiModeManager.MODE_NIGHT_AUTO:
689 currentMode = PARAM_SENSOR_MODE;
690 break;
691 case UiModeManager.MODE_NIGHT_YES:
692 currentMode = PARAM_NIGHT_MODE;
693 break;
694 case UiModeManager.MODE_NIGHT_NO:
695 currentMode = PARAM_DAY_MODE;
696 break;
697 }
698 writer.println("DayNightMode changed to: " + currentMode);
699 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800700
Bryan Eylera32a7c12018-02-27 15:40:00 -0800701 private void forceGarageMode(String arg, PrintWriter writer) {
702 switch (arg) {
703 case PARAM_ON_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700704 mGarageModeService.forceStartGarageMode();
Bryan Eylera32a7c12018-02-27 15:40:00 -0800705 break;
706 case PARAM_OFF_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700707 mGarageModeService.stopAndResetGarageMode();
Bryan Eylera32a7c12018-02-27 15:40:00 -0800708 break;
709 case PARAM_QUERY_MODE:
710 // Nothing to do. Always query at the end anyway.
711 break;
712 default:
713 writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|"
714 + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE);
715 return;
716 }
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700717 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -0800718 }
719
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800720 /**
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800721 * Inject a fake VHAL event
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800722 *
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800723 * @param property the Vehicle property Id as defined in the HAL
724 * @param zone Zone that this event services
725 * @param value Data value of the event
726 * @param writer PrintWriter
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800727 */
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800728 private void injectVhalEvent(String property, String zone, String value,
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800729 PrintWriter writer) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800730 if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) {
731 if (!isPropertyAreaTypeGlobal(property)) {
732 writer.println("Property area type inconsistent with given zone");
733 return;
734 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800735 }
736 try {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800737 mHal.injectVhalEvent(property, zone, value);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800738 } catch (NumberFormatException e) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800739 writer.println("Invalid property Id zone Id or value" + e);
740 dumpHelp(writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800741 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800742 }
743
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800744 // Check if the given property is global
745 private boolean isPropertyAreaTypeGlobal(String property) {
746 if (property == null) {
747 return false;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800748 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800749 return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800750 }
Yao Chene33f07e2016-07-26 12:02:51 -0700751 }
kevinjm55822c42018-08-15 11:26:00 -0700752}