blob: 3d1cf08a1fe5b3d832ac20bd6ae33f4473cf29ce [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;
felipeal080e5652019-11-02 17:04:04 -070020import android.annotation.Nullable;
Keun young Parkf3523cd2019-04-08 10:09:17 -070021import android.app.ActivityManager;
Keun young Park09ca8492019-10-15 10:34:11 -070022import android.app.ActivityOptions;
Yao Chene33f07e2016-07-26 12:02:51 -070023import android.app.UiModeManager;
Keun-young Parke54ac272016-02-16 19:02:18 -080024import android.car.Car;
Keun young Park9a91efb2019-11-15 18:10:47 -080025import android.car.CarFeatures;
Keun-young Parke54ac272016-02-16 19:02:18 -080026import android.car.ICar;
Pavel Maltsev0477e292016-05-27 12:22:36 -070027import android.car.cluster.renderer.IInstrumentClusterNavigation;
Ying Zheng9fc99402018-09-19 14:23:59 -070028import android.car.userlib.CarUserManagerHelper;
Keun young Park09ca8492019-10-15 10:34:11 -070029import android.content.ComponentName;
keunyoungca515072015-07-10 12:21:47 -070030import android.content.Context;
Keun young Park09ca8492019-10-15 10:34:11 -070031import android.content.Intent;
keunyoung1ab8e182015-09-24 09:25:22 -070032import android.content.pm.PackageManager;
Keun young Parkf3523cd2019-04-08 10:09:17 -070033import android.content.res.Resources;
Pavel Maltsevcfe93102017-02-02 12:38:08 -080034import android.hardware.automotive.vehicle.V2_0.IVehicle;
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -080035import android.hardware.automotive.vehicle.V2_0.VehicleArea;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070036import android.os.Binder;
Enrico Granatae8056ca2018-04-03 13:19:52 -070037import android.os.Build;
keunyoungca515072015-07-10 12:21:47 -070038import android.os.IBinder;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070039import android.os.Process;
felipeal72bf6422019-11-02 17:04:04 -070040import android.os.RemoteException;
41import android.os.ResultReceiver;
42import android.os.ShellCallback;
43import android.os.ShellCommand;
Steve Paikc302c7c2017-08-04 14:01:58 -070044import android.os.Trace;
Anthony Hugh9932a252019-06-12 16:19:56 -070045import android.os.UserManager;
keunyoungca515072015-07-10 12:21:47 -070046import android.util.Log;
Steve Paikc302c7c2017-08-04 14:01:58 -070047import android.util.Slog;
Keun-young Park4a79a382017-08-10 18:19:14 -070048import android.util.TimingsTraceLog;
Gregory Clark26fa6012018-03-14 18:38:56 -070049
Keun young Parka4d12202019-10-03 10:51:12 -070050import com.android.car.am.FixedActivityService;
Hongwei Wang38549092018-08-22 12:32:42 -070051import com.android.car.audio.CarAudioService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080052import com.android.car.cluster.InstrumentClusterService;
Serik Beketayev06a66682018-06-12 16:54:29 -070053import com.android.car.garagemode.GarageModeService;
keunyoungcc449f72015-08-12 10:46:27 -070054import com.android.car.hal.VehicleHal;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080055import com.android.car.pm.CarPackageManagerService;
Mark Tabry7e2a7822019-10-17 10:18:32 -070056import com.android.car.stats.CarStatsService;
Enrico Granatab19bc322017-10-12 12:25:06 -070057import com.android.car.systeminterface.SystemInterface;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070058import com.android.car.trust.CarTrustedDeviceService;
Keun young Park7af7d6c2019-09-12 10:31:48 -070059import com.android.car.user.CarUserNoticeService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070060import com.android.car.user.CarUserService;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080061import com.android.car.vms.VmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -080062import com.android.car.vms.VmsClientManager;
keunyoungca515072015-07-10 12:21:47 -070063import com.android.internal.annotations.GuardedBy;
Felipe Leme6ef89652019-12-19 16:47:14 -080064import com.android.internal.annotations.VisibleForTesting;
Steve Paik1d8bea22018-02-03 01:54:06 +000065import com.android.internal.car.ICarServiceHelper;
Oscar Azucena3f3a25e2019-07-12 14:28:24 -070066import com.android.internal.util.ArrayUtils;
Gregory Clark26fa6012018-03-14 18:38:56 -070067
Enrico Granatae8056ca2018-04-03 13:19:52 -070068import java.io.FileDescriptor;
keunyounga3b28d82015-08-25 13:05:15 -070069import java.io.PrintWriter;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070070import java.util.ArrayList;
Antonio Cortese4619c72017-02-02 07:53:27 -080071import java.util.Arrays;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070072import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070073
keunyoungca515072015-07-10 12:21:47 -070074public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070075
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -080076 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070077 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
78 "system_activity_monitoring";
Yan Zhub07585d2019-10-29 14:16:40 -070079 public static final String INTERNAL_VMS_MANAGER = "vms_manager";
Keun-young Parka28d7b22016-02-29 16:54:29 -080080
keunyoungca515072015-07-10 12:21:47 -070081 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080082 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070083
Keun young Park9a91efb2019-11-15 18:10:47 -080084 private final CarFeatureController mFeatureController;
85
Anthony Chen12aec302018-04-25 16:41:48 -070086 private final SystemInterface mSystemInterface;
87
Keun-young Park4727da32016-05-31 10:00:51 -070088 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070089 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080090 private final CarPackageManagerService mCarPackageManagerService;
91 private final CarInputService mCarInputService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -080092 private final CarDrivingStateService mCarDrivingStateService;
Ram Periathiruvadi4526a432018-01-24 13:00:54 -080093 private final CarUxRestrictionsManagerService mCarUXRestrictionsService;
keunyoungd32f4e62015-09-21 11:33:06 -070094 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080095 private final CarProjectionService mCarProjectionService;
Steve Paik9ec53d72018-04-27 13:28:31 -070096 private final CarPropertyService mCarPropertyService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080097 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070098 private final AppFocusService mAppFocusService;
Keun young Parka4d12202019-10-03 10:51:12 -070099 private final FixedActivityService mFixedActivityService;
Yao Chen3a7976d2016-01-20 17:27:08 -0800100 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800101 private final InstrumentClusterService mInstrumentClusterService;
Gregory Clarkd8136062017-12-11 14:27:53 -0800102 private final CarLocationService mCarLocationService;
Keun-young Parkd73afae2016-04-08 20:03:32 -0700103 private final SystemStateControllerService mSystemStateControllerService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800104 private final CarBluetoothService mCarBluetoothService;
Ram Periathiruvadiacb60242017-04-13 16:19:09 -0700105 private final PerUserCarServiceHelper mPerUserCarServiceHelper;
Enrico Granata9a916d72017-09-19 14:33:08 -0700106 private final CarDiagnosticService mCarDiagnosticService;
107 private final CarStorageMonitoringService mCarStorageMonitoringService;
Anthony Chen12aec302018-04-25 16:41:48 -0700108 private final CarConfigurationService mCarConfigurationService;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700109 private final CarTrustedDeviceService mCarTrustedDeviceService;
Simon Dai527eb552019-02-12 13:06:15 -0800110 private final CarMediaService mCarMediaService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700111 private final CarUserManagerHelper mUserManagerHelper;
Keun-young Parkd462a912019-02-11 08:53:42 -0800112 private final CarUserService mCarUserService;
Keun young Parkbb877e22019-08-02 10:38:01 -0700113 private final CarOccupantZoneService mCarOccupantZoneService;
Keun young Park7af7d6c2019-09-12 10:31:48 -0700114 private final CarUserNoticeService mCarUserNoticeService;
Mark Tabrya8fce562019-01-16 16:24:01 -0800115 private final VmsClientManager mVmsClientManager;
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800116 private final VmsBrokerService mVmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -0800117 private final VmsSubscriberService mVmsSubscriberService;
118 private final VmsPublisherService mVmsPublisherService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700119 private final CarBugreportManagerService mCarBugreportManagerService;
Mark Tabry7e2a7822019-10-17 10:18:32 -0700120 private final CarStatsService mCarStatsService;
Keun young Park9a91efb2019-11-15 18:10:47 -0800121 private final CarExperimentalFeatureServiceController mCarExperimentalFeatureServiceController;
keunyounga74b9ca2015-10-21 13:33:58 -0700122
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700123 private final CarServiceBase[] mAllServices;
124
Steve Paikc302c7c2017-08-04 14:01:58 -0700125 private static final String TAG = "ICarImpl";
126 private static final String VHAL_TIMING_TAG = "VehicleHalTiming";
Serik Beketayev74debf22018-10-04 12:18:09 -0700127
128 private TimingsTraceLog mBootTiming;
Steve Paikc302c7c2017-08-04 14:01:58 -0700129
keunyoung1ab8e182015-09-24 09:25:22 -0700130 /** Test only service. Populate it only when necessary. */
131 @GuardedBy("this")
132 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -0700133
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700134 @GuardedBy("this")
135 private ICarServiceHelper mICarServiceHelper;
136
Enrico Granatae8056ca2018-04-03 13:19:52 -0700137 private final String mVehicleInterfaceName;
138
Pavel Maltsevec83b632017-01-05 15:10:55 -0800139 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
Enrico Granatae8056ca2018-04-03 13:19:52 -0700140 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) {
Felipe Leme6ef89652019-12-19 16:47:14 -0800141 this(serviceContext, vehicle, systemInterface, errorNotifier, vehicleInterfaceName,
142 /* carUserService= */ null);
143 }
144
145 @VisibleForTesting
146 ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
147 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName,
148 @Nullable CarUserService carUserService) {
keunyoungca515072015-07-10 12:21:47 -0700149 mContext = serviceContext;
Steve Paik0f9fc002018-02-09 17:42:00 -0800150 mSystemInterface = systemInterface;
Mark Tabryb588d2e2019-09-12 10:50:11 -0700151 mHal = new VehicleHal(serviceContext, vehicle);
Keun young Park9a91efb2019-11-15 18:10:47 -0800152 Resources res = mContext.getResources();
153 String[] defaultEnabledFeatures = res.getStringArray(
154 R.array.config_allowed_optional_car_features);
155 // Do this before any other service components to allow feature check. It should work
156 // even without init.
157 // TODO (b/144504820) Add vhal plumbing
158 mFeatureController = new CarFeatureController(serviceContext, defaultEnabledFeatures,
159 /* disabledFeaturesFromVhal= */ new String[0], mSystemInterface.getSystemCarDir());
160 CarLocalServices.addService(CarFeatureController.class, mFeatureController);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700161 mVehicleInterfaceName = vehicleInterfaceName;
Yao, Yuxing0811d5a2018-11-29 16:18:53 -0800162 mUserManagerHelper = new CarUserManagerHelper(serviceContext);
Felipe Leme6ef89652019-12-19 16:47:14 -0800163 if (carUserService != null) {
164 mCarUserService = carUserService;
165 } else {
166 UserManager userManager =
167 (UserManager) serviceContext.getSystemService(Context.USER_SERVICE);
168 int maxRunningUsers = res.getInteger(
169 com.android.internal.R.integer.config_multiuserMaxRunningUsers);
170 mCarUserService = new CarUserService(serviceContext, mUserManagerHelper, userManager,
171 ActivityManager.getService(), maxRunningUsers);
172 }
Keun young Parkbb877e22019-08-02 10:38:01 -0700173 mCarOccupantZoneService = new CarOccupantZoneService(serviceContext);
Keun-young Park4727da32016-05-31 10:00:51 -0700174 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Steve Paik388d7772018-02-12 10:54:51 -0800175 mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(),
Keun young Park9b3f2662019-03-19 10:30:25 -0700176 systemInterface, mUserManagerHelper);
Keun young Park9a91efb2019-11-15 18:10:47 -0800177 if (mFeatureController.isFeatureEnabled(CarFeatures.FEATURE_CAR_USER_NOTICE_SERVICE)) {
178 mCarUserNoticeService = new CarUserNoticeService(serviceContext);
179 } else {
180 mCarUserNoticeService = null;
181 }
Steve Paik9ec53d72018-04-27 13:28:31 -0700182 mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal());
183 mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService);
Ram Periathiruvadi4526a432018-01-24 13:00:54 -0800184 mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext,
Yao, Yuxing9bfb7492019-02-15 11:53:34 -0800185 mCarDrivingStateService, mCarPropertyService);
Ram Periathiruvadi2da6d0e2018-01-26 18:02:10 -0800186 mCarPackageManagerService = new CarPackageManagerService(serviceContext,
187 mCarUXRestrictionsService,
Anthony Hughfbb67762019-10-15 12:54:54 -0700188 mSystemActivityMonitoringService);
Justin Paupore44985ba2019-01-30 18:53:41 -0800189 mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext);
Sal Savage703c46f2019-04-15 08:39:25 -0700190 mCarBluetoothService = new CarBluetoothService(serviceContext, mPerUserCarServiceHelper);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700191 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Justin Paupore44985ba2019-01-30 18:53:41 -0800192 mCarProjectionService = new CarProjectionService(
Pavel Maltsev079873b2019-02-25 12:15:09 -0800193 serviceContext, null /* handler */, mCarInputService, mCarBluetoothService);
Serik Beketayevc6ab8be2018-08-28 21:20:53 -0700194 mGarageModeService = new GarageModeService(mContext);
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700195 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Hongwei Wang30557232018-01-02 10:25:08 -0800196 mCarAudioService = new CarAudioService(serviceContext);
Steve Paik9ec53d72018-04-27 13:28:31 -0700197 mCarNightService = new CarNightService(serviceContext, mCarPropertyService);
Keun young Parka4d12202019-10-03 10:51:12 -0700198 mFixedActivityService = new FixedActivityService(serviceContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700199 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700200 mAppFocusService, mCarInputService);
Serik Beketayevf9f2ef02018-09-06 12:37:02 -0700201 mSystemStateControllerService = new SystemStateControllerService(
202 serviceContext, mCarAudioService, this);
Mark Tabry7e2a7822019-10-17 10:18:32 -0700203 mCarStatsService = new CarStatsService(serviceContext);
Mark Tabry61a06c72019-06-17 10:37:49 -0700204 mVmsBrokerService = new VmsBrokerService();
Mark Tabry1534c062019-03-29 01:30:49 -0700205 mVmsClientManager = new VmsClientManager(
Mark Tabry7e2a7822019-10-17 10:18:32 -0700206 // CarStatsService needs to be passed to the constructor due to HAL init order
207 serviceContext, mCarStatsService, mCarUserService, mVmsBrokerService,
208 mHal.getVmsHal());
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800209 mVmsSubscriberService = new VmsSubscriberService(
Mark Tabry61a06c72019-06-17 10:37:49 -0700210 serviceContext, mVmsBrokerService, mVmsClientManager, mHal.getVmsHal());
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800211 mVmsPublisherService = new VmsPublisherService(
Mark Tabry7e2a7822019-10-17 10:18:32 -0700212 serviceContext, mCarStatsService, mVmsBrokerService, mVmsClientManager);
Enrico Granatab3634e22017-05-05 18:02:31 -0700213 mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal());
Keun young Park9a91efb2019-11-15 18:10:47 -0800214 if (mFeatureController.isFeatureEnabled(Car.STORAGE_MONITORING_SERVICE)) {
215 mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext,
216 systemInterface);
217 } else {
218 mCarStorageMonitoringService = null;
219 }
Anthony Chen12aec302018-04-25 16:41:48 -0700220 mCarConfigurationService =
221 new CarConfigurationService(serviceContext, new JsonReaderImpl());
Anthony Hugh5f2465e2019-10-08 15:07:01 -0700222 mCarLocationService = new CarLocationService(serviceContext);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700223 mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext);
Simon Dai527eb552019-02-12 13:06:15 -0800224 mCarMediaService = new CarMediaService(serviceContext);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700225 mCarBugreportManagerService = new CarBugreportManagerService(serviceContext);
Keun young Park9a91efb2019-11-15 18:10:47 -0800226 if (!Build.IS_USER) {
227 mCarExperimentalFeatureServiceController = new CarExperimentalFeatureServiceController(
228 serviceContext);
229 } else {
230 mCarExperimentalFeatureServiceController = null;
231 }
keunyounga74b9ca2015-10-21 13:33:58 -0700232
Keun young Parka5fa4782019-04-16 18:56:27 -0700233 CarLocalServices.addService(CarPowerManagementService.class, mCarPowerManagementService);
Keun young Parkbb877e22019-08-02 10:38:01 -0700234 CarLocalServices.addService(CarPropertyService.class, mCarPropertyService);
Keun-young Parkd462a912019-02-11 08:53:42 -0800235 CarLocalServices.addService(CarUserService.class, mCarUserService);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700236 CarLocalServices.addService(CarTrustedDeviceService.class, mCarTrustedDeviceService);
Gregory Clarka440e812019-02-14 16:05:51 -0800237 CarLocalServices.addService(SystemInterface.class, mSystemInterface);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700238 CarLocalServices.addService(CarDrivingStateService.class, mCarDrivingStateService);
Gregory Clark55620c12019-06-03 17:42:58 -0700239 CarLocalServices.addService(PerUserCarServiceHelper.class, mPerUserCarServiceHelper);
Keun young Parka4d12202019-10-03 10:51:12 -0700240 CarLocalServices.addService(FixedActivityService.class, mFixedActivityService);
Keun-young Parkd462a912019-02-11 08:53:42 -0800241
keunyounga3b28d82015-08-25 13:05:15 -0700242 // Be careful with order. Service depending on other service should be inited later.
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700243 List<CarServiceBase> allServices = new ArrayList<>();
Keun young Park9a91efb2019-11-15 18:10:47 -0800244 allServices.add(mFeatureController);
Keun-young Parkd462a912019-02-11 08:53:42 -0800245 allServices.add(mCarUserService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700246 allServices.add(mSystemActivityMonitoringService);
247 allServices.add(mCarPowerManagementService);
248 allServices.add(mCarPropertyService);
249 allServices.add(mCarDrivingStateService);
Keun young Parkbb877e22019-08-02 10:38:01 -0700250 allServices.add(mCarOccupantZoneService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700251 allServices.add(mCarUXRestrictionsService);
252 allServices.add(mCarPackageManagerService);
253 allServices.add(mCarInputService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700254 allServices.add(mGarageModeService);
Keun young Park9a91efb2019-11-15 18:10:47 -0800255 addServiceIfNonNull(allServices, mCarUserNoticeService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700256 allServices.add(mAppFocusService);
257 allServices.add(mCarAudioService);
258 allServices.add(mCarNightService);
Keun young Parka4d12202019-10-03 10:51:12 -0700259 allServices.add(mFixedActivityService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700260 allServices.add(mInstrumentClusterService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700261 allServices.add(mSystemStateControllerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700262 allServices.add(mPerUserCarServiceHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800263 allServices.add(mCarBluetoothService);
264 allServices.add(mCarProjectionService);
265 allServices.add(mCarDiagnosticService);
Keun young Park9a91efb2019-11-15 18:10:47 -0800266 addServiceIfNonNull(allServices, mCarStorageMonitoringService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700267 allServices.add(mCarConfigurationService);
Mark Tabrya8fce562019-01-16 16:24:01 -0800268 allServices.add(mVmsClientManager);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700269 allServices.add(mVmsSubscriberService);
270 allServices.add(mVmsPublisherService);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700271 allServices.add(mCarTrustedDeviceService);
Simon Dai527eb552019-02-12 13:06:15 -0800272 allServices.add(mCarMediaService);
Gregory Clarka63ba022018-06-07 16:42:12 -0700273 allServices.add(mCarLocationService);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700274 allServices.add(mCarBugreportManagerService);
Keun young Park9a91efb2019-11-15 18:10:47 -0800275 // Always put mCarExperimentalFeatureServiceController in last.
276 addServiceIfNonNull(allServices, mCarExperimentalFeatureServiceController);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700277 mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]);
keunyoungca515072015-07-10 12:21:47 -0700278 }
279
Keun young Park9a91efb2019-11-15 18:10:47 -0800280 private void addServiceIfNonNull(List<CarServiceBase> services, CarServiceBase service) {
281 if (service != null) {
282 services.add(service);
283 }
284 }
285
Pavel Maltsevabd47232017-10-10 16:54:57 -0700286 @MainThread
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700287 void init() {
Serik Beketayev74debf22018-10-04 12:18:09 -0700288 mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL);
Steve Paikc302c7c2017-08-04 14:01:58 -0700289 traceBegin("VehicleHal.init");
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700290 mHal.init();
Steve Paikc302c7c2017-08-04 14:01:58 -0700291 traceEnd();
292 traceBegin("CarService.initAllServices");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800293 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700294 service.init();
295 }
Steve Paikc302c7c2017-08-04 14:01:58 -0700296 traceEnd();
keunyoungca515072015-07-10 12:21:47 -0700297 }
298
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700299 void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700300 // release done in opposite order from init
301 for (int i = mAllServices.length - 1; i >= 0; i--) {
302 mAllServices[i].release();
303 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700304 mHal.release();
keunyoung1ab8e182015-09-24 09:25:22 -0700305 }
306
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700307 void vehicleHalReconnected(IVehicle vehicle) {
Pavel Maltsevec83b632017-01-05 15:10:55 -0800308 mHal.vehicleHalReconnected(vehicle);
309 for (CarServiceBase service : mAllServices) {
310 service.vehicleHalReconnected();
311 }
312 }
313
keunyoungca515072015-07-10 12:21:47 -0700314 @Override
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700315 public void setCarServiceHelper(IBinder helper) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700316 assertCallingFromSystemProcess();
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700317 synchronized (this) {
318 mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper);
Steve Paik0f9fc002018-02-09 17:42:00 -0800319 mSystemInterface.setCarServiceHelper(mICarServiceHelper);
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700320 }
321 }
322
323 @Override
Eric Jeong1545f3b2019-09-16 13:56:52 -0700324 public void setUserLockStatus(int userId, int unlocked) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700325 assertCallingFromSystemProcess();
Eric Jeong1545f3b2019-09-16 13:56:52 -0700326 mCarUserService.setUserLockStatus(userId, unlocked == 1);
327 mCarMediaService.setUserLockStatus(userId, unlocked == 1);
Pavel Maltsev17e81832019-04-04 14:38:41 -0700328 }
329
330 @Override
Eric Jeong1545f3b2019-09-16 13:56:52 -0700331 public void onSwitchUser(int userId) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700332 assertCallingFromSystemProcess();
333
Eric Jeong1545f3b2019-09-16 13:56:52 -0700334 Log.i(TAG, "Foreground user switched to " + userId);
335 mCarUserService.onSwitchUser(userId);
Pavel Maltsev17e81832019-04-04 14:38:41 -0700336 }
337
Keun young Park9a91efb2019-11-15 18:10:47 -0800338 @Override
339 public boolean isFeatureEnabled(String featureName) {
340 return mFeatureController.isFeatureEnabled(featureName);
341 }
342
343 @Override
344 public int enableFeature(String featureName) {
345 // permission check inside the controller
346 return mFeatureController.enableFeature(featureName);
347 }
348
349 @Override
350 public int disableFeature(String featureName) {
351 // permission check inside the controller
352 return mFeatureController.disableFeature(featureName);
353 }
354
355 @Override
356 public List<String> getAllEnabledFeatures() {
357 // permission check inside the controller
358 return mFeatureController.getAllEnabledFeatures();
359 }
360
361 @Override
362 public List<String> getAllPendingDisabledFeatures() {
363 // permission check inside the controller
364 return mFeatureController.getAllPendingDisabledFeatures();
365 }
366
367 @Override
368 public List<String> getAllPendingEnabledFeatures() {
369 // permission check inside the controller
370 return mFeatureController.getAllPendingEnabledFeatures();
371 }
372
373 @Override
374 public String getCarManagerClassForFeature(String featureName) {
375 if (mCarExperimentalFeatureServiceController == null) {
376 return null;
377 }
378 return mCarExperimentalFeatureServiceController.getCarManagerClassForFeature(featureName);
379 }
380
Jim Kayee5133162019-04-22 12:50:27 -0700381 static void assertCallingFromSystemProcess() {
Keun-young Parkd462a912019-02-11 08:53:42 -0800382 int uid = Binder.getCallingUid();
383 if (uid != Process.SYSTEM_UID) {
384 throw new SecurityException("Only allowed from system");
385 }
Keun-young Parkd462a912019-02-11 08:53:42 -0800386 }
387
Keun young Parkaabecd92019-05-03 17:31:27 -0700388 /**
389 * Assert if binder call is coming from system process like system server or if it is called
390 * from its own process even if it is not system. The latter can happen in test environment.
391 * Note that car service runs as system user but test like car service test will not.
392 */
393 static void assertCallingFromSystemProcessOrSelf() {
394 int uid = Binder.getCallingUid();
395 int pid = Binder.getCallingPid();
396 if (uid != Process.SYSTEM_UID && pid != Process.myPid()) {
397 throw new SecurityException("Only allowed from system or self");
398 }
399 }
400
Keun-young Parkd462a912019-02-11 08:53:42 -0800401 @Override
keunyoungca515072015-07-10 12:21:47 -0700402 public IBinder getCarService(String serviceName) {
Keun young Park9a91efb2019-11-15 18:10:47 -0800403 if (!mFeatureController.isFeatureEnabled(serviceName)) {
404 Log.w(CarLog.TAG_SERVICE, "getCarService for disabled service:" + serviceName);
405 return null;
406 }
keunyoungca515072015-07-10 12:21:47 -0700407 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800408 case Car.AUDIO_SERVICE:
409 return mCarAudioService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700410 case Car.APP_FOCUS_SERVICE:
411 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800412 case Car.PACKAGE_SERVICE:
413 return mCarPackageManagerService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800414 case Car.DIAGNOSTIC_SERVICE:
Enrico Granatab3634e22017-05-05 18:02:31 -0700415 assertAnyDiagnosticPermission(mContext);
416 return mCarDiagnosticService;
Steve Paik388d7772018-02-12 10:54:51 -0800417 case Car.POWER_SERVICE:
418 assertPowerPermission(mContext);
419 return mCarPowerManagementService;
Steve Paik9ec53d72018-04-27 13:28:31 -0700420 case Car.CABIN_SERVICE:
421 case Car.HVAC_SERVICE:
422 case Car.INFO_SERVICE:
423 case Car.PROPERTY_SERVICE:
424 case Car.SENSOR_SERVICE:
425 case Car.VENDOR_EXTENSION_SERVICE:
426 return mCarPropertyService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800427 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700428 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700429 IInstrumentClusterNavigation navService =
430 mInstrumentClusterService.getNavigationService();
431 return navService == null ? null : navService.asBinder();
Pavel Maltsev905968c2017-07-16 19:48:57 -0700432 case Car.CAR_INSTRUMENT_CLUSTER_SERVICE:
433 assertClusterManagerPermission(mContext);
434 return mInstrumentClusterService.getManagerService();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800435 case Car.PROJECTION_SERVICE:
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800436 return mCarProjectionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800437 case Car.VMS_SUBSCRIBER_SERVICE:
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700438 assertVmsSubscriberPermission(mContext);
439 return mVmsSubscriberService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800440 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700441 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700442 synchronized (this) {
443 if (mCarTestService == null) {
444 mCarTestService = new CarTestService(mContext, this);
445 }
446 return mCarTestService;
447 }
448 }
Ram Periathiruvadi76a84892017-07-27 18:10:35 -0700449 case Car.BLUETOOTH_SERVICE:
450 return mCarBluetoothService;
Enrico Granata9a916d72017-09-19 14:33:08 -0700451 case Car.STORAGE_MONITORING_SERVICE:
Enrico Granata1172f882017-09-21 14:51:30 -0700452 assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING);
Enrico Granata9a916d72017-09-19 14:33:08 -0700453 return mCarStorageMonitoringService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800454 case Car.CAR_DRIVING_STATE_SERVICE:
455 assertDrivingStatePermission(mContext);
456 return mCarDrivingStateService;
457 case Car.CAR_UX_RESTRICTION_SERVICE:
458 return mCarUXRestrictionsService;
Anthony Chend4203d82018-05-16 16:21:52 -0700459 case Car.CAR_CONFIGURATION_SERVICE:
460 return mCarConfigurationService;
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800461 case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE:
462 assertTrustAgentEnrollmentPermission(mContext);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700463 return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService();
Simon Dai527eb552019-02-12 13:06:15 -0800464 case Car.CAR_MEDIA_SERVICE:
465 return mCarMediaService;
Keun young Parkbb877e22019-08-02 10:38:01 -0700466 case Car.CAR_OCCUPANT_ZONE_SERVICE:
467 return mCarOccupantZoneService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700468 case Car.CAR_BUGREPORT_SERVICE:
469 return mCarBugreportManagerService;
Eric Jeong1545f3b2019-09-16 13:56:52 -0700470 case Car.CAR_USER_SERVICE:
471 return mCarUserService;
keunyoungca515072015-07-10 12:21:47 -0700472 default:
Keun young Park9a91efb2019-11-15 18:10:47 -0800473 IBinder service = null;
474 if (mCarExperimentalFeatureServiceController != null) {
475 service = mCarExperimentalFeatureServiceController.getCarService(serviceName);
476 }
477 if (service == null) {
478 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:"
479 + serviceName);
480 }
481 return service;
keunyoungca515072015-07-10 12:21:47 -0700482 }
483 }
484
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800485 @Override
486 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700487 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800488 }
489
Keun-young Parka28d7b22016-02-29 16:54:29 -0800490 public CarServiceBase getCarInternalService(String serviceName) {
491 switch (serviceName) {
492 case INTERNAL_INPUT_SERVICE:
493 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700494 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
495 return mSystemActivityMonitoringService;
Yan Zhub07585d2019-10-29 14:16:40 -0700496 // TODO(b/144027497): temporary until tests are refactored to not use it
497 case INTERNAL_VMS_MANAGER:
498 return mVmsClientManager;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800499 default:
500 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
501 serviceName);
502 return null;
503 }
504 }
505
Mark Tabryf7319ae2019-11-07 11:26:35 -0800506 CarStatsService getStatsService() {
507 return mCarStatsService;
508 }
509
keunyoung1ab8e182015-09-24 09:25:22 -0700510 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700511 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700512 }
513
Keun-young Parke31a8b22016-03-16 17:34:08 -0700514 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700515 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800516 }
517
Pavel Maltsev905968c2017-07-16 19:48:57 -0700518 public static void assertClusterManagerPermission(Context context) {
519 assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL);
520 }
521
Steve Paik388d7772018-02-12 10:54:51 -0800522 public static void assertPowerPermission(Context context) {
523 assertPermission(context, Car.PERMISSION_CAR_POWER);
524 }
525
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800526 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700527 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
528 }
529
Pavel Maltsev079873b2019-02-25 12:15:09 -0800530 /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */
531 public static void assertProjectionStatusPermission(Context context) {
532 assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS);
533 }
534
Enrico Granata3c7a6662017-02-23 18:07:59 -0800535 public static void assertAnyDiagnosticPermission(Context context) {
536 assertAnyPermission(context,
Enrico Granataae25b922017-07-07 11:28:15 -0700537 Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL,
Enrico Granata3c7a6662017-02-23 18:07:59 -0800538 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
539 }
540
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800541 public static void assertDrivingStatePermission(Context context) {
542 assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE);
543 }
544
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800545 public static void assertVmsPublisherPermission(Context context) {
546 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
547 }
548
Antonio Cortese4619c72017-02-02 07:53:27 -0800549 public static void assertVmsSubscriberPermission(Context context) {
550 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
551 }
552
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800553 /**
554 * Ensures the caller has the permission to enroll a Trust Agent.
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800555 */
556 public static void assertTrustAgentEnrollmentPermission(Context context) {
557 assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST);
558 }
559
Steve Paik461ecc62016-06-08 15:28:32 -0700560 public static void assertPermission(Context context, String permission) {
561 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
562 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800563 }
564 }
565
Steve Paik9ec53d72018-04-27 13:28:31 -0700566 /**
567 * Checks to see if the caller has a permission.
Steve Paik9ec53d72018-04-27 13:28:31 -0700568 *
569 * @return boolean TRUE if caller has the permission.
570 */
571 public static boolean hasPermission(Context context, String permission) {
572 return context.checkCallingOrSelfPermission(permission)
573 == PackageManager.PERMISSION_GRANTED;
574 }
575
Enrico Granata3c7a6662017-02-23 18:07:59 -0800576 public static void assertAnyPermission(Context context, String... permissions) {
577 for (String permission : permissions) {
578 if (context.checkCallingOrSelfPermission(permission) ==
579 PackageManager.PERMISSION_GRANTED) {
580 return;
581 }
582 }
583 throw new SecurityException("requires any of " + Arrays.toString(permissions));
584 }
585
Enrico Granatae8056ca2018-04-03 13:19:52 -0700586 @Override
587 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
588 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Anthony Chen12aec302018-04-25 16:41:48 -0700589 != PackageManager.PERMISSION_GRANTED) {
Enrico Granatae8056ca2018-04-03 13:19:52 -0700590 writer.println("Permission Denial: can't dump CarService from from pid="
Anthony Chen12aec302018-04-25 16:41:48 -0700591 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
592 + " without permission " + android.Manifest.permission.DUMP);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700593 return;
keunyounga3b28d82015-08-25 13:05:15 -0700594 }
Enrico Granatae8056ca2018-04-03 13:19:52 -0700595
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700596 if (args == null || args.length == 0 || (args.length > 0 && "-a".equals(args[0]))) {
597 writer.println("*Dump car service*");
Enrico Granatae8056ca2018-04-03 13:19:52 -0700598 writer.println("*Dump all services*");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700599
Mark Tabry7e2a7822019-10-17 10:18:32 -0700600 dumpAllServices(writer);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700601
Enrico Granatae8056ca2018-04-03 13:19:52 -0700602 writer.println("*Dump Vehicle HAL*");
603 writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName);
604 try {
605 // TODO dump all feature flags by creating a dumpable interface
606 mHal.dump(writer);
607 } catch (Exception e) {
608 writer.println("Failed dumping: " + mHal.getClass().getName());
609 e.printStackTrace(writer);
610 }
felipeal080e5652019-11-02 17:04:04 -0700611 } else if ("--list".equals(args[0])) {
612 dumpListOfServices(writer);
613 return;
614 } else if ("--services".equals(args[0])) {
615 if (args.length < 2) {
616 writer.print("Must pass services to dump when using --services");
617 return;
618 }
619 int length = args.length - 1;
620 String[] services = new String[length];
621 System.arraycopy(args, 1, services, 0, length);
622 dumpIndividualServices(writer, services);
623 return;
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700624 } else if ("--metrics".equals(args[0])) {
Mark Tabry7e2a7822019-10-17 10:18:32 -0700625 // Strip the --metrics flag when passing dumpsys arguments to CarStatsService
Mark Tabryc98f9952019-12-03 11:03:48 -0800626 // allowing for nested flag selection
Mark Tabry7e2a7822019-10-17 10:18:32 -0700627 mCarStatsService.dump(fd, writer, Arrays.copyOfRange(args, 1, args.length));
Mark Tabryb588d2e2019-09-12 10:50:11 -0700628 } else if ("--vms-hal".equals(args[0])) {
629 mHal.getVmsHal().dumpMetrics(fd);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700630 } else if (Build.IS_USERDEBUG || Build.IS_ENG) {
631 execShellCmd(args, writer);
632 } else {
633 writer.println("Commands not supported in " + Build.TYPE);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800634 }
635 }
636
felipeal72bf6422019-11-02 17:04:04 -0700637 @Override
638 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
639 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
640 throws RemoteException {
641 new CarShellCommand().exec(this, in, out, err, args, callback, resultReceiver);
642 }
643
felipeal080e5652019-11-02 17:04:04 -0700644 private void dumpListOfServices(PrintWriter writer) {
645 for (CarServiceBase service : mAllServices) {
646 writer.println(service.getClass().getName());
647 }
648 }
649
Mark Tabry7e2a7822019-10-17 10:18:32 -0700650 private void dumpAllServices(PrintWriter writer) {
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700651 for (CarServiceBase service : mAllServices) {
Mark Tabry7e2a7822019-10-17 10:18:32 -0700652 dumpService(service, writer);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700653 }
654 if (mCarTestService != null) {
Mark Tabry7e2a7822019-10-17 10:18:32 -0700655 dumpService(mCarTestService, writer);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700656 }
felipeal080e5652019-11-02 17:04:04 -0700657 }
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700658
felipeal080e5652019-11-02 17:04:04 -0700659 private void dumpIndividualServices(PrintWriter writer, String... serviceNames) {
660 for (String serviceName : serviceNames) {
661 writer.println("** Dumping " + serviceName + "\n");
662 CarServiceBase service = getCarServiceBySubstring(serviceName);
663 if (service == null) {
664 writer.println("No such service!");
665 } else {
Mark Tabry7e2a7822019-10-17 10:18:32 -0700666 dumpService(service, writer);
felipeal080e5652019-11-02 17:04:04 -0700667 }
668 writer.println();
669 }
670 }
671
672 @Nullable
673 private CarServiceBase getCarServiceBySubstring(String className) {
674 return Arrays.asList(mAllServices).stream()
675 .filter(s -> s.getClass().getSimpleName().equals(className))
676 .findFirst().orElse(null);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700677 }
678
Mark Tabry7e2a7822019-10-17 10:18:32 -0700679 private void dumpService(CarServiceBase service, PrintWriter writer) {
Brad Stenninged3d59b2017-11-09 16:15:17 -0800680 try {
Mark Tabry7e2a7822019-10-17 10:18:32 -0700681 service.dump(writer);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800682 } catch (Exception e) {
683 writer.println("Failed dumping: " + service.getClass().getName());
684 e.printStackTrace(writer);
685 }
keunyoungcc449f72015-08-12 10:46:27 -0700686 }
Yao Chene33f07e2016-07-26 12:02:51 -0700687
688 void execShellCmd(String[] args, PrintWriter writer) {
689 new CarShellCommand().exec(args, writer);
690 }
691
Pavel Maltsevabd47232017-10-10 16:54:57 -0700692 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700693 private void traceBegin(String name) {
Steve Paikc302c7c2017-08-04 14:01:58 -0700694 Slog.i(TAG, name);
695 mBootTiming.traceBegin(name);
696 }
697
Pavel Maltsevabd47232017-10-10 16:54:57 -0700698 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700699 private void traceEnd() {
Steve Paikc302c7c2017-08-04 14:01:58 -0700700 mBootTiming.traceEnd();
701 }
702
felipeal72bf6422019-11-02 17:04:04 -0700703 private final class CarShellCommand extends ShellCommand {
Yao Chene33f07e2016-07-26 12:02:51 -0700704 private static final String COMMAND_HELP = "-h";
705 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800706 private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event";
Kai4b098cf2019-06-05 15:03:28 -0700707 private static final String COMMAND_INJECT_ERROR_EVENT = "inject-error-event";
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800708 private static final String COMMAND_ENABLE_UXR = "enable-uxr";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800709 private static final String COMMAND_GARAGE_MODE = "garage-mode";
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800710 private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities";
Kaidd4ef5a2019-03-04 14:07:26 -0800711 private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig";
Kai29fba112019-04-22 18:37:38 -0700712 private static final String COMMAND_GET_PROPERTY_VALUE = "get-property-value";
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700713 private static final String COMMAND_PROJECTION_AP_TETHERING = "projection-tethering";
Pavel Maltsev48a31942019-03-03 22:08:28 -0800714 private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode";
Jim Kayed76c2742019-04-02 11:33:27 -0700715 private static final String COMMAND_RESUME = "resume";
716 private static final String COMMAND_SUSPEND = "suspend";
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700717 private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device";
718 private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices";
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700719 private static final String COMMAND_SET_UID_TO_ZONE = "set-zoneid-for-uid";
Keun young Park09ca8492019-10-15 10:34:11 -0700720 private static final String COMMAND_START_FIXED_ACTIVITY_MODE = "start-fixed-activity-mode";
721 private static final String COMMAND_STOP_FIXED_ACTIVITY_MODE = "stop-fixed-activity-mode";
Keun young Park9a91efb2019-11-15 18:10:47 -0800722 private static final String COMMAND_ENABLE_FEATURE = "enable-feature";
723 private static final String COMMAND_DISABLE_FEATURE = "disable-feature";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800724
Yao Chene33f07e2016-07-26 12:02:51 -0700725 private static final String PARAM_DAY_MODE = "day";
726 private static final String PARAM_NIGHT_MODE = "night";
727 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800728 private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800729 private static final String PARAM_ON_MODE = "on";
730 private static final String PARAM_OFF_MODE = "off";
731 private static final String PARAM_QUERY_MODE = "query";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800732
felipeal72bf6422019-11-02 17:04:04 -0700733 private static final int RESULT_OK = 0;
734 private static final int RESULT_ERROR = -1; // Arbitrary value, any non-0 is fine
735
736
737 @Override
738 public int onCommand(String cmd) {
739 if (cmd == null) {
740 onHelp();
741 return RESULT_ERROR;
742 }
743 ArrayList<String> argsList = new ArrayList<>();
744 argsList.add(cmd);
745 String arg = null;
746 do {
747 arg = getNextArg();
748 if (arg != null) {
749 argsList.add(arg);
750 }
751 } while (arg != null);
752 String[] args = new String[argsList.size()];
753 argsList.toArray(args);
754 return exec(args, getOutPrintWriter());
755 }
756
757 @Override
758 public void onHelp() {
759 dumpHelp(getOutPrintWriter());
760 }
Yao Chene33f07e2016-07-26 12:02:51 -0700761
762 private void dumpHelp(PrintWriter pw) {
763 pw.println("Car service commands:");
764 pw.println("\t-h");
765 pw.println("\t Print this help text.");
766 pw.println("\tday-night-mode [day|night|sensor]");
767 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800768 pw.println("\tinject-vhal-event property [zone] data(can be comma separated list)");
Jim Kayef10b7d82019-02-26 12:53:22 -0800769 pw.println("\t Inject a vehicle property for testing.");
Kai4b098cf2019-06-05 15:03:28 -0700770 pw.println("\tinject-error-event property zone errorCode");
771 pw.println("\t Inject an error event from VHAL for testing.");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700772 pw.println("\tenable-uxr true|false");
773 pw.println("\t Enable/Disable UX restrictions and App blocking.");
Bryan Eylera32a7c12018-02-27 15:40:00 -0800774 pw.println("\tgarage-mode [on|off|query]");
775 pw.println("\t Force into garage mode or check status.");
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800776 pw.println("\tget-do-activities pkgname");
Jim Kayef10b7d82019-02-26 12:53:22 -0800777 pw.println("\t Get Distraction Optimized activities in given package.");
Kaidd4ef5a2019-03-04 14:07:26 -0800778 pw.println("\tget-carpropertyconfig [propertyId]");
779 pw.println("\t Get a CarPropertyConfig by Id in Hex or list all CarPropertyConfigs");
Kai29fba112019-04-22 18:37:38 -0700780 pw.println("\tget-property-value [propertyId] [areaId]");
781 pw.println("\t Get a vehicle property value by property id in Hex and areaId");
782 pw.println("\t or list all property values for all areaId");
Jim Kayed76c2742019-04-02 11:33:27 -0700783 pw.println("\tsuspend");
784 pw.println("\t Suspend the system to Deep Sleep.");
785 pw.println("\tresume");
786 pw.println("\t Wake the system up after a 'suspend.'");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700787 pw.println("\tenable-trusted-device true|false");
788 pw.println("\t Enable/Disable Trusted device feature.");
789 pw.println("\tremove-trusted-devices");
790 pw.println("\t Remove all trusted devices for the current foreground user.");
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700791 pw.println("\tprojection-tethering [true|false]");
792 pw.println("\t Whether tethering should be used when creating access point for"
793 + " wireless projection");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700794 pw.println("\t--metrics");
795 pw.println("\t When used with dumpsys, only metrics will be in the dumpsys output.");
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700796 pw.println("\tset-zoneid-for-uid [zoneid] [uid]");
797 pw.println("\t Maps the audio zoneid to uid.");
Keun young Park09ca8492019-10-15 10:34:11 -0700798 pw.println("\tstart-fixed-activity displayId packageName activityName");
799 pw.println("\t Start an Activity the specified display as fixed mode");
800 pw.println("\tstop-fixed-mode displayId");
801 pw.println("\t Stop fixed Activity mode for the given display. "
802 + "The Activity will not be restarted upon crash.");
Keun young Park9a91efb2019-11-15 18:10:47 -0800803 pw.println("\tenable-feature featureName");
804 pw.println("\t Enable the requested feature. Change will happen after reboot.");
805 pw.println("\t This requires root/su.");
806 pw.println("\tdisable-feature featureName");
807 pw.println("\t Disable the requested feature. Change will happen after reboot");
808 pw.println("\t This requires root/su.");
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700809 }
810
felipeal72bf6422019-11-02 17:04:04 -0700811 private int dumpInvalidArguments(PrintWriter pw) {
812 pw.println("Incorrect number of arguments.");
813 dumpHelp(pw);
814 return RESULT_ERROR;
815 }
816
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700817 private String runSetZoneIdForUid(String zoneString, String uidString) {
818 int uid = Integer.parseInt(uidString);
819 int zoneId = Integer.parseInt(zoneString);
820 if (!ArrayUtils.contains(mCarAudioService.getAudioZoneIds(), zoneId)) {
821 return "zoneid " + zoneId + " not found";
822 }
823 mCarAudioService.setZoneIdForUid(zoneId, uid);
824 return null;
Yao Chene33f07e2016-07-26 12:02:51 -0700825 }
826
felipeal72bf6422019-11-02 17:04:04 -0700827 public int exec(String[] args, PrintWriter writer) {
Yao Chene33f07e2016-07-26 12:02:51 -0700828 String arg = args[0];
829 switch (arg) {
830 case COMMAND_HELP:
831 dumpHelp(writer);
832 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800833 case COMMAND_DAY_NIGHT_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800834 String value = args.length < 2 ? "" : args[1];
Yao Chene33f07e2016-07-26 12:02:51 -0700835 forceDayNightMode(value, writer);
836 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800837 }
838 case COMMAND_GARAGE_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800839 String value = args.length < 2 ? "" : args[1];
Bryan Eylera32a7c12018-02-27 15:40:00 -0800840 forceGarageMode(value, writer);
841 break;
842 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800843 case COMMAND_INJECT_VHAL_EVENT:
844 String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL;
845 String data;
Jim Kayef10b7d82019-02-26 12:53:22 -0800846 if (args.length != 3 && args.length != 4) {
felipeal72bf6422019-11-02 17:04:04 -0700847 return dumpInvalidArguments(writer);
Jim Kayef10b7d82019-02-26 12:53:22 -0800848 } else if (args.length == 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800849 // Zoned
850 zone = args[2];
851 data = args[3];
852 } else {
853 // Global
854 data = args[2];
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800855 }
Kai4b098cf2019-06-05 15:03:28 -0700856 injectVhalEvent(args[1], zone, data, false, writer);
857 break;
858 case COMMAND_INJECT_ERROR_EVENT:
859 if (args.length != 4) {
felipeal72bf6422019-11-02 17:04:04 -0700860 return dumpInvalidArguments(writer);
Kai4b098cf2019-06-05 15:03:28 -0700861 }
862 String errorAreaId = args[2];
863 String errorCode = args[3];
864 injectVhalEvent(args[1], errorAreaId, errorCode, true, writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800865 break;
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800866 case COMMAND_ENABLE_UXR:
Jim Kayef10b7d82019-02-26 12:53:22 -0800867 if (args.length != 2) {
felipeal72bf6422019-11-02 17:04:04 -0700868 return dumpInvalidArguments(writer);
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800869 }
870 boolean enableBlocking = Boolean.valueOf(args[1]);
871 if (mCarPackageManagerService != null) {
872 mCarPackageManagerService.setEnableActivityBlocking(enableBlocking);
873 }
874 break;
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800875 case COMMAND_GET_DO_ACTIVITIES:
Jim Kayef10b7d82019-02-26 12:53:22 -0800876 if (args.length != 2) {
felipeal72bf6422019-11-02 17:04:04 -0700877 return dumpInvalidArguments(writer);
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800878 }
879 String pkgName = args[1].toLowerCase();
880 if (mCarPackageManagerService != null) {
881 String[] doActivities =
882 mCarPackageManagerService.getDistractionOptimizedActivities(
883 pkgName);
884 if (doActivities != null) {
885 writer.println("DO Activities for " + pkgName);
886 for (String a : doActivities) {
887 writer.println(a);
888 }
889 } else {
890 writer.println("No DO Activities for " + pkgName);
891 }
892 }
893 break;
Kaidd4ef5a2019-03-04 14:07:26 -0800894 case COMMAND_GET_CARPROPERTYCONFIG:
895 String propertyId = args.length < 2 ? "" : args[1];
896 mHal.dumpPropertyConfigs(writer, propertyId);
897 break;
Kai29fba112019-04-22 18:37:38 -0700898 case COMMAND_GET_PROPERTY_VALUE:
899 String propId = args.length < 2 ? "" : args[1];
900 String areaId = args.length < 3 ? "" : args[2];
901 mHal.dumpPropertyValueByCommend(writer, propId, areaId);
902 break;
Pavel Maltsev48a31942019-03-03 22:08:28 -0800903 case COMMAND_PROJECTION_UI_MODE:
904 if (args.length != 2) {
felipeal72bf6422019-11-02 17:04:04 -0700905 return dumpInvalidArguments(writer);
Pavel Maltsev48a31942019-03-03 22:08:28 -0800906 }
907 mCarProjectionService.setUiMode(Integer.valueOf(args[1]));
Pavel Maltsevd6961f62019-03-26 10:22:31 -0700908 break;
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700909 case COMMAND_PROJECTION_AP_TETHERING:
910 if (args.length != 2) {
felipeal72bf6422019-11-02 17:04:04 -0700911 return dumpInvalidArguments(writer);
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700912 }
913 mCarProjectionService.setAccessPointTethering(Boolean.valueOf(args[1]));
914 break;
Jim Kayed76c2742019-04-02 11:33:27 -0700915 case COMMAND_RESUME:
916 mCarPowerManagementService.forceSimulatedResume();
917 writer.println("Resume: Simulating resuming from Deep Sleep");
918 break;
919 case COMMAND_SUSPEND:
920 mCarPowerManagementService.forceSimulatedSuspend();
921 writer.println("Resume: Simulating powering down to Deep Sleep");
922 break;
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700923 case COMMAND_ENABLE_TRUSTED_DEVICE:
924 if (args.length != 2) {
felipeal72bf6422019-11-02 17:04:04 -0700925 return dumpInvalidArguments(writer);
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700926 }
927 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
928 .setTrustedDeviceEnrollmentEnabled(Boolean.valueOf(args[1]));
929 mCarTrustedDeviceService.getCarTrustAgentUnlockService()
930 .setTrustedDeviceUnlockEnabled(Boolean.valueOf(args[1]));
931 break;
932 case COMMAND_REMOVE_TRUSTED_DEVICES:
933 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
Anthony Hughfbb67762019-10-15 12:54:54 -0700934 .removeAllTrustedDevices(ActivityManager.getCurrentUser());
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700935 break;
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700936 case COMMAND_SET_UID_TO_ZONE:
937 if (args.length != 3) {
felipeal72bf6422019-11-02 17:04:04 -0700938 return dumpInvalidArguments(writer);
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700939 }
940 String results = runSetZoneIdForUid(args[1], args[2]);
941 if (results != null) {
942 writer.println(results);
943 dumpHelp(writer);
944 }
945 break;
Keun young Park09ca8492019-10-15 10:34:11 -0700946 case COMMAND_START_FIXED_ACTIVITY_MODE:
947 handleStartFixedActivity(args, writer);
948 break;
949 case COMMAND_STOP_FIXED_ACTIVITY_MODE:
950 handleStopFixedMode(args, writer);
951 break;
Keun young Park9a91efb2019-11-15 18:10:47 -0800952 case COMMAND_ENABLE_FEATURE:
953 if (args.length != 2) {
954 return dumpInvalidArguments(writer);
955 }
956 handleEnableDisableFeature(args, writer, /* enable= */ true);
957 break;
958 case COMMAND_DISABLE_FEATURE:
959 if (args.length != 2) {
960 return dumpInvalidArguments(writer);
961 }
962 handleEnableDisableFeature(args, writer, /* enable= */ false);
963 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700964 default:
Jim Kayef10b7d82019-02-26 12:53:22 -0800965 writer.println("Unknown command: \"" + arg + "\"");
Yao Chene33f07e2016-07-26 12:02:51 -0700966 dumpHelp(writer);
felipeal72bf6422019-11-02 17:04:04 -0700967 return RESULT_ERROR;
Yao Chene33f07e2016-07-26 12:02:51 -0700968 }
felipeal72bf6422019-11-02 17:04:04 -0700969 return RESULT_OK;
Yao Chene33f07e2016-07-26 12:02:51 -0700970 }
971
Keun young Park09ca8492019-10-15 10:34:11 -0700972 private void handleStartFixedActivity(String[] args, PrintWriter writer) {
973 if (args.length != 4) {
974 writer.println("Incorrect number of arguments");
975 dumpHelp(writer);
976 return;
977 }
978 int displayId;
979 try {
980 displayId = Integer.parseInt(args[1]);
981 } catch (NumberFormatException e) {
982 writer.println("Wrong display id:" + args[1]);
983 return;
984 }
985 String packageName = args[2];
986 String activityName = args[3];
987 Intent intent = new Intent();
988 intent.setComponent(new ComponentName(packageName, activityName));
989 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
990 ActivityOptions options = ActivityOptions.makeBasic();
991 options.setLaunchDisplayId(displayId);
992 if (!mFixedActivityService.startFixedActivityModeForDisplayAndUser(intent, options,
993 displayId, ActivityManager.getCurrentUser())) {
994 writer.println("Failed to start");
995 return;
996 }
997 writer.println("Succeeded");
998 }
999
1000 private void handleStopFixedMode(String[] args, PrintWriter writer) {
1001 if (args.length != 2) {
1002 writer.println("Incorrect number of arguments");
1003 dumpHelp(writer);
1004 return;
1005 }
1006 int displayId;
1007 try {
1008 displayId = Integer.parseInt(args[1]);
1009 } catch (NumberFormatException e) {
1010 writer.println("Wrong display id:" + args[1]);
1011 return;
1012 }
1013 mFixedActivityService.stopFixedActivityMode(displayId);
1014 }
1015
Keun young Park9a91efb2019-11-15 18:10:47 -08001016 private void handleEnableDisableFeature(String[] args, PrintWriter writer, boolean enable) {
1017 if (Binder.getCallingUid() != Process.ROOT_UID) {
1018 writer.println("Only allowed to root/su");
1019 return;
1020 }
1021 String featureName = args[1];
1022 long id = Binder.clearCallingIdentity();
1023 // no permission check here
1024 int r;
1025 if (enable) {
1026 r = mFeatureController.enableFeature(featureName);
1027 } else {
1028 r = mFeatureController.disableFeature(featureName);
1029 }
1030 switch (r) {
1031 case Car.FEATURE_REQUEST_SUCCESS:
1032 if (enable) {
1033 writer.println("Enabled feature:" + featureName);
1034 } else {
1035 writer.println("Disabled feature:" + featureName);
1036 }
1037 break;
1038 case Car.FEATURE_REQUEST_ALREADY_IN_THE_STATE:
1039 if (enable) {
1040 writer.println("Already enabled:" + featureName);
1041 } else {
1042 writer.println("Already disabled:" + featureName);
1043 }
1044 break;
1045 case Car.FEATURE_REQUEST_MANDATORY:
1046 writer.println("Cannot change mandatory feature:" + featureName);
1047 break;
1048 case Car.FEATURE_REQUEST_NOT_EXISTING:
1049 writer.println("Non-existing feature:" + featureName);
1050 break;
1051 default:
1052 writer.println("Unknown error:" + r);
1053 break;
1054 }
1055 Binder.restoreCallingIdentity(id);
1056 }
1057
Yao Chene33f07e2016-07-26 12:02:51 -07001058 private void forceDayNightMode(String arg, PrintWriter writer) {
1059 int mode;
1060 switch (arg) {
1061 case PARAM_DAY_MODE:
1062 mode = CarNightService.FORCED_DAY_MODE;
1063 break;
1064 case PARAM_NIGHT_MODE:
1065 mode = CarNightService.FORCED_NIGHT_MODE;
1066 break;
1067 case PARAM_SENSOR_MODE:
1068 mode = CarNightService.FORCED_SENSOR_MODE;
1069 break;
1070 default:
1071 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
1072 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
1073 return;
1074 }
1075 int current = mCarNightService.forceDayNightMode(mode);
1076 String currentMode = null;
1077 switch (current) {
1078 case UiModeManager.MODE_NIGHT_AUTO:
1079 currentMode = PARAM_SENSOR_MODE;
1080 break;
1081 case UiModeManager.MODE_NIGHT_YES:
1082 currentMode = PARAM_NIGHT_MODE;
1083 break;
1084 case UiModeManager.MODE_NIGHT_NO:
1085 currentMode = PARAM_DAY_MODE;
1086 break;
1087 }
1088 writer.println("DayNightMode changed to: " + currentMode);
1089 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001090
Bryan Eylera32a7c12018-02-27 15:40:00 -08001091 private void forceGarageMode(String arg, PrintWriter writer) {
1092 switch (arg) {
1093 case PARAM_ON_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -07001094 mGarageModeService.forceStartGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -07001095 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -08001096 break;
1097 case PARAM_OFF_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -07001098 mGarageModeService.stopAndResetGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -07001099 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -08001100 break;
1101 case PARAM_QUERY_MODE:
Jim Kaye1b5e6182019-05-24 15:48:32 -07001102 mGarageModeService.dump(writer);
Bryan Eylera32a7c12018-02-27 15:40:00 -08001103 break;
1104 default:
1105 writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|"
1106 + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE);
Bryan Eylera32a7c12018-02-27 15:40:00 -08001107 }
Bryan Eylera32a7c12018-02-27 15:40:00 -08001108 }
1109
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001110 /**
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001111 * Inject a fake VHAL event
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -08001112 *
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001113 * @param property the Vehicle property Id as defined in the HAL
1114 * @param zone Zone that this event services
Kai4b098cf2019-06-05 15:03:28 -07001115 * @param isErrorEvent indicates the type of event
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001116 * @param value Data value of the event
1117 * @param writer PrintWriter
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001118 */
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001119 private void injectVhalEvent(String property, String zone, String value,
Kai4b098cf2019-06-05 15:03:28 -07001120 boolean isErrorEvent, PrintWriter writer) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001121 if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) {
1122 if (!isPropertyAreaTypeGlobal(property)) {
1123 writer.println("Property area type inconsistent with given zone");
1124 return;
1125 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001126 }
1127 try {
Kai4b098cf2019-06-05 15:03:28 -07001128 if (isErrorEvent) {
1129 mHal.injectOnPropertySetError(property, zone, value);
1130 } else {
1131 mHal.injectVhalEvent(property, zone, value);
1132 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001133 } catch (NumberFormatException e) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001134 writer.println("Invalid property Id zone Id or value" + e);
1135 dumpHelp(writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001136 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001137 }
1138
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001139 // Check if the given property is global
1140 private boolean isPropertyAreaTypeGlobal(String property) {
1141 if (property == null) {
1142 return false;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -08001143 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001144 return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -08001145 }
Yao Chene33f07e2016-07-26 12:02:51 -07001146 }
kevinjm55822c42018-08-15 11:26:00 -07001147}