blob: 40f863a351bc7662815d6dab30b714f4691dceec [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;
Keun young Park313dfaf2019-12-19 11:32:38 -080044import android.os.SystemClock;
Steve Paikc302c7c2017-08-04 14:01:58 -070045import android.os.Trace;
Anthony Hugh9932a252019-06-12 16:19:56 -070046import android.os.UserManager;
keunyoungca515072015-07-10 12:21:47 -070047import android.util.Log;
Steve Paikc302c7c2017-08-04 14:01:58 -070048import android.util.Slog;
Keun-young Park4a79a382017-08-10 18:19:14 -070049import android.util.TimingsTraceLog;
Keun young Park313dfaf2019-12-19 11:32:38 -080050import android.view.KeyEvent;
Gregory Clark26fa6012018-03-14 18:38:56 -070051
Keun young Parka4d12202019-10-03 10:51:12 -070052import com.android.car.am.FixedActivityService;
Hongwei Wang38549092018-08-22 12:32:42 -070053import com.android.car.audio.CarAudioService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080054import com.android.car.cluster.InstrumentClusterService;
Serik Beketayev06a66682018-06-12 16:54:29 -070055import com.android.car.garagemode.GarageModeService;
Keun young Park313dfaf2019-12-19 11:32:38 -080056import com.android.car.hal.InputHalService;
keunyoungcc449f72015-08-12 10:46:27 -070057import com.android.car.hal.VehicleHal;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080058import com.android.car.pm.CarPackageManagerService;
Mark Tabry7e2a7822019-10-17 10:18:32 -070059import com.android.car.stats.CarStatsService;
Enrico Granatab19bc322017-10-12 12:25:06 -070060import com.android.car.systeminterface.SystemInterface;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070061import com.android.car.trust.CarTrustedDeviceService;
Keun young Park7af7d6c2019-09-12 10:31:48 -070062import com.android.car.user.CarUserNoticeService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070063import com.android.car.user.CarUserService;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080064import com.android.car.vms.VmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -080065import com.android.car.vms.VmsClientManager;
keunyoungca515072015-07-10 12:21:47 -070066import com.android.internal.annotations.GuardedBy;
Felipe Leme6ef89652019-12-19 16:47:14 -080067import com.android.internal.annotations.VisibleForTesting;
Steve Paik1d8bea22018-02-03 01:54:06 +000068import com.android.internal.car.ICarServiceHelper;
Oscar Azucena3f3a25e2019-07-12 14:28:24 -070069import com.android.internal.util.ArrayUtils;
Gregory Clark26fa6012018-03-14 18:38:56 -070070
Enrico Granatae8056ca2018-04-03 13:19:52 -070071import java.io.FileDescriptor;
keunyounga3b28d82015-08-25 13:05:15 -070072import java.io.PrintWriter;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070073import java.util.ArrayList;
Antonio Cortese4619c72017-02-02 07:53:27 -080074import java.util.Arrays;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070075import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070076
keunyoungca515072015-07-10 12:21:47 -070077public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070078
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -080079 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070080 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
81 "system_activity_monitoring";
Yan Zhub07585d2019-10-29 14:16:40 -070082 public static final String INTERNAL_VMS_MANAGER = "vms_manager";
Keun-young Parka28d7b22016-02-29 16:54:29 -080083
keunyoungca515072015-07-10 12:21:47 -070084 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080085 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070086
Keun young Park9a91efb2019-11-15 18:10:47 -080087 private final CarFeatureController mFeatureController;
88
Anthony Chen12aec302018-04-25 16:41:48 -070089 private final SystemInterface mSystemInterface;
90
Keun-young Park4727da32016-05-31 10:00:51 -070091 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070092 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080093 private final CarPackageManagerService mCarPackageManagerService;
94 private final CarInputService mCarInputService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -080095 private final CarDrivingStateService mCarDrivingStateService;
Ram Periathiruvadi4526a432018-01-24 13:00:54 -080096 private final CarUxRestrictionsManagerService mCarUXRestrictionsService;
Michael Kellerc0f0bdb2019-12-11 14:58:19 -080097 private final OccupantAwarenessService mOccupantAwarenessService;
keunyoungd32f4e62015-09-21 11:33:06 -070098 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080099 private final CarProjectionService mCarProjectionService;
Steve Paik9ec53d72018-04-27 13:28:31 -0700100 private final CarPropertyService mCarPropertyService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -0800101 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700102 private final AppFocusService mAppFocusService;
Keun young Parka4d12202019-10-03 10:51:12 -0700103 private final FixedActivityService mFixedActivityService;
Yao Chen3a7976d2016-01-20 17:27:08 -0800104 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800105 private final InstrumentClusterService mInstrumentClusterService;
Gregory Clarkd8136062017-12-11 14:27:53 -0800106 private final CarLocationService mCarLocationService;
Keun-young Parkd73afae2016-04-08 20:03:32 -0700107 private final SystemStateControllerService mSystemStateControllerService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800108 private final CarBluetoothService mCarBluetoothService;
Ram Periathiruvadiacb60242017-04-13 16:19:09 -0700109 private final PerUserCarServiceHelper mPerUserCarServiceHelper;
Enrico Granata9a916d72017-09-19 14:33:08 -0700110 private final CarDiagnosticService mCarDiagnosticService;
111 private final CarStorageMonitoringService mCarStorageMonitoringService;
Anthony Chen12aec302018-04-25 16:41:48 -0700112 private final CarConfigurationService mCarConfigurationService;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700113 private final CarTrustedDeviceService mCarTrustedDeviceService;
Simon Dai527eb552019-02-12 13:06:15 -0800114 private final CarMediaService mCarMediaService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700115 private final CarUserManagerHelper mUserManagerHelper;
Keun-young Parkd462a912019-02-11 08:53:42 -0800116 private final CarUserService mCarUserService;
Keun young Parkbb877e22019-08-02 10:38:01 -0700117 private final CarOccupantZoneService mCarOccupantZoneService;
Keun young Park7af7d6c2019-09-12 10:31:48 -0700118 private final CarUserNoticeService mCarUserNoticeService;
Mark Tabrya8fce562019-01-16 16:24:01 -0800119 private final VmsClientManager mVmsClientManager;
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800120 private final VmsBrokerService mVmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -0800121 private final VmsSubscriberService mVmsSubscriberService;
122 private final VmsPublisherService mVmsPublisherService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700123 private final CarBugreportManagerService mCarBugreportManagerService;
Mark Tabry7e2a7822019-10-17 10:18:32 -0700124 private final CarStatsService mCarStatsService;
Keun young Park9a91efb2019-11-15 18:10:47 -0800125 private final CarExperimentalFeatureServiceController mCarExperimentalFeatureServiceController;
keunyounga74b9ca2015-10-21 13:33:58 -0700126
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700127 private final CarServiceBase[] mAllServices;
128
Steve Paikc302c7c2017-08-04 14:01:58 -0700129 private static final String TAG = "ICarImpl";
130 private static final String VHAL_TIMING_TAG = "VehicleHalTiming";
Serik Beketayev74debf22018-10-04 12:18:09 -0700131
132 private TimingsTraceLog mBootTiming;
Steve Paikc302c7c2017-08-04 14:01:58 -0700133
keunyoung1ab8e182015-09-24 09:25:22 -0700134 /** Test only service. Populate it only when necessary. */
135 @GuardedBy("this")
136 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -0700137
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700138 @GuardedBy("this")
139 private ICarServiceHelper mICarServiceHelper;
140
Enrico Granatae8056ca2018-04-03 13:19:52 -0700141 private final String mVehicleInterfaceName;
142
Pavel Maltsevec83b632017-01-05 15:10:55 -0800143 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
Enrico Granatae8056ca2018-04-03 13:19:52 -0700144 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) {
Felipe Leme6ef89652019-12-19 16:47:14 -0800145 this(serviceContext, vehicle, systemInterface, errorNotifier, vehicleInterfaceName,
146 /* carUserService= */ null);
147 }
148
149 @VisibleForTesting
150 ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
151 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName,
152 @Nullable CarUserService carUserService) {
keunyoungca515072015-07-10 12:21:47 -0700153 mContext = serviceContext;
Steve Paik0f9fc002018-02-09 17:42:00 -0800154 mSystemInterface = systemInterface;
Mark Tabryb588d2e2019-09-12 10:50:11 -0700155 mHal = new VehicleHal(serviceContext, vehicle);
Keun young Park9a91efb2019-11-15 18:10:47 -0800156 Resources res = mContext.getResources();
157 String[] defaultEnabledFeatures = res.getStringArray(
158 R.array.config_allowed_optional_car_features);
159 // Do this before any other service components to allow feature check. It should work
160 // even without init.
161 // TODO (b/144504820) Add vhal plumbing
162 mFeatureController = new CarFeatureController(serviceContext, defaultEnabledFeatures,
163 /* disabledFeaturesFromVhal= */ new String[0], mSystemInterface.getSystemCarDir());
164 CarLocalServices.addService(CarFeatureController.class, mFeatureController);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700165 mVehicleInterfaceName = vehicleInterfaceName;
Yao, Yuxing0811d5a2018-11-29 16:18:53 -0800166 mUserManagerHelper = new CarUserManagerHelper(serviceContext);
Felipe Leme6ef89652019-12-19 16:47:14 -0800167 if (carUserService != null) {
168 mCarUserService = carUserService;
169 } else {
170 UserManager userManager =
171 (UserManager) serviceContext.getSystemService(Context.USER_SERVICE);
172 int maxRunningUsers = res.getInteger(
173 com.android.internal.R.integer.config_multiuserMaxRunningUsers);
Felipe Leme58412202020-01-09 13:45:33 -0800174 mCarUserService = new CarUserService(serviceContext, mHal.getUserHal(),
175 mUserManagerHelper, userManager, ActivityManager.getService(), maxRunningUsers);
Felipe Leme6ef89652019-12-19 16:47:14 -0800176 }
Keun young Parkbb877e22019-08-02 10:38:01 -0700177 mCarOccupantZoneService = new CarOccupantZoneService(serviceContext);
Keun-young Park4727da32016-05-31 10:00:51 -0700178 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Steve Paik388d7772018-02-12 10:54:51 -0800179 mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(),
Keun young Park9b3f2662019-03-19 10:30:25 -0700180 systemInterface, mUserManagerHelper);
Keun young Park9a91efb2019-11-15 18:10:47 -0800181 if (mFeatureController.isFeatureEnabled(CarFeatures.FEATURE_CAR_USER_NOTICE_SERVICE)) {
182 mCarUserNoticeService = new CarUserNoticeService(serviceContext);
183 } else {
184 mCarUserNoticeService = null;
185 }
Steve Paik9ec53d72018-04-27 13:28:31 -0700186 mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal());
187 mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService);
Ram Periathiruvadi4526a432018-01-24 13:00:54 -0800188 mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext,
Yao, Yuxing9bfb7492019-02-15 11:53:34 -0800189 mCarDrivingStateService, mCarPropertyService);
Michael Kellerc0f0bdb2019-12-11 14:58:19 -0800190 if (mFeatureController.isFeatureEnabled(Car.OCCUPANT_AWARENESS_SERVICE)) {
191 mOccupantAwarenessService = new OccupantAwarenessService(serviceContext);
192 } else {
193 mOccupantAwarenessService = null;
194 }
Ram Periathiruvadi2da6d0e2018-01-26 18:02:10 -0800195 mCarPackageManagerService = new CarPackageManagerService(serviceContext,
196 mCarUXRestrictionsService,
Mayank Garg31e73042020-01-23 00:10:38 -0800197 mSystemActivityMonitoringService,
198 mCarUserService);
199 mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext, mCarUserService);
Sal Savage703c46f2019-04-15 08:39:25 -0700200 mCarBluetoothService = new CarBluetoothService(serviceContext, mPerUserCarServiceHelper);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700201 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Justin Paupore44985ba2019-01-30 18:53:41 -0800202 mCarProjectionService = new CarProjectionService(
Pavel Maltsev079873b2019-02-25 12:15:09 -0800203 serviceContext, null /* handler */, mCarInputService, mCarBluetoothService);
Serik Beketayevc6ab8be2018-08-28 21:20:53 -0700204 mGarageModeService = new GarageModeService(mContext);
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700205 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Hongwei Wang30557232018-01-02 10:25:08 -0800206 mCarAudioService = new CarAudioService(serviceContext);
Steve Paik9ec53d72018-04-27 13:28:31 -0700207 mCarNightService = new CarNightService(serviceContext, mCarPropertyService);
Keun young Parka4d12202019-10-03 10:51:12 -0700208 mFixedActivityService = new FixedActivityService(serviceContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700209 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700210 mAppFocusService, mCarInputService);
Serik Beketayevf9f2ef02018-09-06 12:37:02 -0700211 mSystemStateControllerService = new SystemStateControllerService(
212 serviceContext, mCarAudioService, this);
Mark Tabry7e2a7822019-10-17 10:18:32 -0700213 mCarStatsService = new CarStatsService(serviceContext);
Ruchir Rastogia683d742020-01-22 00:17:51 -0800214 mCarStatsService.init();
Keun young Parkc6d80af2020-01-17 18:14:28 -0800215 if (mFeatureController.isFeatureEnabled(Car.VMS_SUBSCRIBER_SERVICE)) {
216 mVmsBrokerService = new VmsBrokerService();
217 mVmsClientManager = new VmsClientManager(
218 // CarStatsService needs to be passed to the constructor due to HAL init order
219 serviceContext, mCarStatsService, mCarUserService, mVmsBrokerService,
220 mHal.getVmsHal());
221 mVmsSubscriberService = new VmsSubscriberService(
222 serviceContext, mVmsBrokerService, mVmsClientManager, mHal.getVmsHal());
223 mVmsPublisherService = new VmsPublisherService(
224 serviceContext, mCarStatsService, mVmsBrokerService, mVmsClientManager);
225 } else {
226 mVmsBrokerService = null;
227 mVmsClientManager = null;
228 mVmsSubscriberService = null;
229 mVmsPublisherService = null;
230 }
231 if (mFeatureController.isFeatureEnabled(Car.DIAGNOSTIC_SERVICE)) {
232 mCarDiagnosticService = new CarDiagnosticService(serviceContext,
233 mHal.getDiagnosticHal());
234 } else {
235 mCarDiagnosticService = null;
236 }
Keun young Park9a91efb2019-11-15 18:10:47 -0800237 if (mFeatureController.isFeatureEnabled(Car.STORAGE_MONITORING_SERVICE)) {
238 mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext,
239 systemInterface);
240 } else {
241 mCarStorageMonitoringService = null;
242 }
Anthony Chen12aec302018-04-25 16:41:48 -0700243 mCarConfigurationService =
244 new CarConfigurationService(serviceContext, new JsonReaderImpl());
Anthony Hugh5f2465e2019-10-08 15:07:01 -0700245 mCarLocationService = new CarLocationService(serviceContext);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700246 mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext);
Mayank Garg31e73042020-01-23 00:10:38 -0800247 mCarMediaService = new CarMediaService(serviceContext, mCarUserService);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700248 mCarBugreportManagerService = new CarBugreportManagerService(serviceContext);
Keun young Park9a91efb2019-11-15 18:10:47 -0800249 if (!Build.IS_USER) {
250 mCarExperimentalFeatureServiceController = new CarExperimentalFeatureServiceController(
251 serviceContext);
252 } else {
253 mCarExperimentalFeatureServiceController = null;
254 }
keunyounga74b9ca2015-10-21 13:33:58 -0700255
Keun young Parka5fa4782019-04-16 18:56:27 -0700256 CarLocalServices.addService(CarPowerManagementService.class, mCarPowerManagementService);
Keun young Parkbb877e22019-08-02 10:38:01 -0700257 CarLocalServices.addService(CarPropertyService.class, mCarPropertyService);
Keun-young Parkd462a912019-02-11 08:53:42 -0800258 CarLocalServices.addService(CarUserService.class, mCarUserService);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700259 CarLocalServices.addService(CarTrustedDeviceService.class, mCarTrustedDeviceService);
Gregory Clarka440e812019-02-14 16:05:51 -0800260 CarLocalServices.addService(SystemInterface.class, mSystemInterface);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700261 CarLocalServices.addService(CarDrivingStateService.class, mCarDrivingStateService);
Gregory Clark55620c12019-06-03 17:42:58 -0700262 CarLocalServices.addService(PerUserCarServiceHelper.class, mPerUserCarServiceHelper);
Keun young Parka4d12202019-10-03 10:51:12 -0700263 CarLocalServices.addService(FixedActivityService.class, mFixedActivityService);
Keun-young Parkd462a912019-02-11 08:53:42 -0800264
keunyounga3b28d82015-08-25 13:05:15 -0700265 // Be careful with order. Service depending on other service should be inited later.
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700266 List<CarServiceBase> allServices = new ArrayList<>();
Keun young Park9a91efb2019-11-15 18:10:47 -0800267 allServices.add(mFeatureController);
Keun-young Parkd462a912019-02-11 08:53:42 -0800268 allServices.add(mCarUserService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700269 allServices.add(mSystemActivityMonitoringService);
270 allServices.add(mCarPowerManagementService);
271 allServices.add(mCarPropertyService);
272 allServices.add(mCarDrivingStateService);
Keun young Parkbb877e22019-08-02 10:38:01 -0700273 allServices.add(mCarOccupantZoneService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700274 allServices.add(mCarUXRestrictionsService);
Michael Kellerc0f0bdb2019-12-11 14:58:19 -0800275 addServiceIfNonNull(allServices, mOccupantAwarenessService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700276 allServices.add(mCarPackageManagerService);
277 allServices.add(mCarInputService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700278 allServices.add(mGarageModeService);
Keun young Park9a91efb2019-11-15 18:10:47 -0800279 addServiceIfNonNull(allServices, mCarUserNoticeService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700280 allServices.add(mAppFocusService);
281 allServices.add(mCarAudioService);
282 allServices.add(mCarNightService);
Keun young Parka4d12202019-10-03 10:51:12 -0700283 allServices.add(mFixedActivityService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700284 allServices.add(mInstrumentClusterService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700285 allServices.add(mSystemStateControllerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700286 allServices.add(mPerUserCarServiceHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800287 allServices.add(mCarBluetoothService);
288 allServices.add(mCarProjectionService);
Keun young Parkc6d80af2020-01-17 18:14:28 -0800289 addServiceIfNonNull(allServices, mCarDiagnosticService);
Keun young Park9a91efb2019-11-15 18:10:47 -0800290 addServiceIfNonNull(allServices, mCarStorageMonitoringService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700291 allServices.add(mCarConfigurationService);
Keun young Parkc6d80af2020-01-17 18:14:28 -0800292 addServiceIfNonNull(allServices, mVmsClientManager);
293 addServiceIfNonNull(allServices, mVmsSubscriberService);
294 addServiceIfNonNull(allServices, mVmsPublisherService);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700295 allServices.add(mCarTrustedDeviceService);
Simon Dai527eb552019-02-12 13:06:15 -0800296 allServices.add(mCarMediaService);
Gregory Clarka63ba022018-06-07 16:42:12 -0700297 allServices.add(mCarLocationService);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700298 allServices.add(mCarBugreportManagerService);
Keun young Park9a91efb2019-11-15 18:10:47 -0800299 // Always put mCarExperimentalFeatureServiceController in last.
300 addServiceIfNonNull(allServices, mCarExperimentalFeatureServiceController);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700301 mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]);
keunyoungca515072015-07-10 12:21:47 -0700302 }
303
Keun young Park9a91efb2019-11-15 18:10:47 -0800304 private void addServiceIfNonNull(List<CarServiceBase> services, CarServiceBase service) {
305 if (service != null) {
306 services.add(service);
307 }
308 }
309
Pavel Maltsevabd47232017-10-10 16:54:57 -0700310 @MainThread
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700311 void init() {
Serik Beketayev74debf22018-10-04 12:18:09 -0700312 mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL);
Steve Paikc302c7c2017-08-04 14:01:58 -0700313 traceBegin("VehicleHal.init");
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700314 mHal.init();
Steve Paikc302c7c2017-08-04 14:01:58 -0700315 traceEnd();
316 traceBegin("CarService.initAllServices");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800317 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700318 service.init();
319 }
Steve Paikc302c7c2017-08-04 14:01:58 -0700320 traceEnd();
keunyoungca515072015-07-10 12:21:47 -0700321 }
322
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700323 void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700324 // release done in opposite order from init
325 for (int i = mAllServices.length - 1; i >= 0; i--) {
326 mAllServices[i].release();
327 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700328 mHal.release();
keunyoung1ab8e182015-09-24 09:25:22 -0700329 }
330
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700331 void vehicleHalReconnected(IVehicle vehicle) {
Pavel Maltsevec83b632017-01-05 15:10:55 -0800332 mHal.vehicleHalReconnected(vehicle);
333 for (CarServiceBase service : mAllServices) {
334 service.vehicleHalReconnected();
335 }
336 }
337
keunyoungca515072015-07-10 12:21:47 -0700338 @Override
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700339 public void setCarServiceHelper(IBinder helper) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700340 assertCallingFromSystemProcess();
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700341 synchronized (this) {
342 mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper);
Steve Paik0f9fc002018-02-09 17:42:00 -0800343 mSystemInterface.setCarServiceHelper(mICarServiceHelper);
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700344 }
345 }
346
347 @Override
Eric Jeong1545f3b2019-09-16 13:56:52 -0700348 public void setUserLockStatus(int userId, int unlocked) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700349 assertCallingFromSystemProcess();
Eric Jeong1545f3b2019-09-16 13:56:52 -0700350 mCarUserService.setUserLockStatus(userId, unlocked == 1);
351 mCarMediaService.setUserLockStatus(userId, unlocked == 1);
Pavel Maltsev17e81832019-04-04 14:38:41 -0700352 }
353
354 @Override
Eric Jeong1545f3b2019-09-16 13:56:52 -0700355 public void onSwitchUser(int userId) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700356 assertCallingFromSystemProcess();
357
Eric Jeong1545f3b2019-09-16 13:56:52 -0700358 Log.i(TAG, "Foreground user switched to " + userId);
359 mCarUserService.onSwitchUser(userId);
Pavel Maltsev17e81832019-04-04 14:38:41 -0700360 }
361
Keun young Park9a91efb2019-11-15 18:10:47 -0800362 @Override
363 public boolean isFeatureEnabled(String featureName) {
364 return mFeatureController.isFeatureEnabled(featureName);
365 }
366
367 @Override
368 public int enableFeature(String featureName) {
369 // permission check inside the controller
370 return mFeatureController.enableFeature(featureName);
371 }
372
373 @Override
374 public int disableFeature(String featureName) {
375 // permission check inside the controller
376 return mFeatureController.disableFeature(featureName);
377 }
378
379 @Override
380 public List<String> getAllEnabledFeatures() {
381 // permission check inside the controller
382 return mFeatureController.getAllEnabledFeatures();
383 }
384
385 @Override
386 public List<String> getAllPendingDisabledFeatures() {
387 // permission check inside the controller
388 return mFeatureController.getAllPendingDisabledFeatures();
389 }
390
391 @Override
392 public List<String> getAllPendingEnabledFeatures() {
393 // permission check inside the controller
394 return mFeatureController.getAllPendingEnabledFeatures();
395 }
396
397 @Override
398 public String getCarManagerClassForFeature(String featureName) {
399 if (mCarExperimentalFeatureServiceController == null) {
400 return null;
401 }
402 return mCarExperimentalFeatureServiceController.getCarManagerClassForFeature(featureName);
403 }
404
Jim Kayee5133162019-04-22 12:50:27 -0700405 static void assertCallingFromSystemProcess() {
Keun-young Parkd462a912019-02-11 08:53:42 -0800406 int uid = Binder.getCallingUid();
407 if (uid != Process.SYSTEM_UID) {
408 throw new SecurityException("Only allowed from system");
409 }
Keun-young Parkd462a912019-02-11 08:53:42 -0800410 }
411
Keun young Parkaabecd92019-05-03 17:31:27 -0700412 /**
413 * Assert if binder call is coming from system process like system server or if it is called
414 * from its own process even if it is not system. The latter can happen in test environment.
415 * Note that car service runs as system user but test like car service test will not.
416 */
417 static void assertCallingFromSystemProcessOrSelf() {
418 int uid = Binder.getCallingUid();
419 int pid = Binder.getCallingPid();
420 if (uid != Process.SYSTEM_UID && pid != Process.myPid()) {
421 throw new SecurityException("Only allowed from system or self");
422 }
423 }
424
Keun-young Parkd462a912019-02-11 08:53:42 -0800425 @Override
keunyoungca515072015-07-10 12:21:47 -0700426 public IBinder getCarService(String serviceName) {
Keun young Park9a91efb2019-11-15 18:10:47 -0800427 if (!mFeatureController.isFeatureEnabled(serviceName)) {
428 Log.w(CarLog.TAG_SERVICE, "getCarService for disabled service:" + serviceName);
429 return null;
430 }
keunyoungca515072015-07-10 12:21:47 -0700431 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800432 case Car.AUDIO_SERVICE:
433 return mCarAudioService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700434 case Car.APP_FOCUS_SERVICE:
435 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800436 case Car.PACKAGE_SERVICE:
437 return mCarPackageManagerService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800438 case Car.DIAGNOSTIC_SERVICE:
Enrico Granatab3634e22017-05-05 18:02:31 -0700439 assertAnyDiagnosticPermission(mContext);
440 return mCarDiagnosticService;
Steve Paik388d7772018-02-12 10:54:51 -0800441 case Car.POWER_SERVICE:
442 assertPowerPermission(mContext);
443 return mCarPowerManagementService;
Steve Paik9ec53d72018-04-27 13:28:31 -0700444 case Car.CABIN_SERVICE:
445 case Car.HVAC_SERVICE:
446 case Car.INFO_SERVICE:
447 case Car.PROPERTY_SERVICE:
448 case Car.SENSOR_SERVICE:
449 case Car.VENDOR_EXTENSION_SERVICE:
450 return mCarPropertyService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800451 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700452 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700453 IInstrumentClusterNavigation navService =
454 mInstrumentClusterService.getNavigationService();
455 return navService == null ? null : navService.asBinder();
Pavel Maltsev905968c2017-07-16 19:48:57 -0700456 case Car.CAR_INSTRUMENT_CLUSTER_SERVICE:
457 assertClusterManagerPermission(mContext);
458 return mInstrumentClusterService.getManagerService();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800459 case Car.PROJECTION_SERVICE:
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800460 return mCarProjectionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800461 case Car.VMS_SUBSCRIBER_SERVICE:
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700462 assertVmsSubscriberPermission(mContext);
463 return mVmsSubscriberService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800464 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700465 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700466 synchronized (this) {
467 if (mCarTestService == null) {
468 mCarTestService = new CarTestService(mContext, this);
469 }
470 return mCarTestService;
471 }
472 }
Ram Periathiruvadi76a84892017-07-27 18:10:35 -0700473 case Car.BLUETOOTH_SERVICE:
474 return mCarBluetoothService;
Enrico Granata9a916d72017-09-19 14:33:08 -0700475 case Car.STORAGE_MONITORING_SERVICE:
Enrico Granata1172f882017-09-21 14:51:30 -0700476 assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING);
Enrico Granata9a916d72017-09-19 14:33:08 -0700477 return mCarStorageMonitoringService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800478 case Car.CAR_DRIVING_STATE_SERVICE:
479 assertDrivingStatePermission(mContext);
480 return mCarDrivingStateService;
481 case Car.CAR_UX_RESTRICTION_SERVICE:
482 return mCarUXRestrictionsService;
Michael Kellerac2ed202020-01-30 14:11:16 -0800483 case Car.OCCUPANT_AWARENESS_SERVICE:
484 return mOccupantAwarenessService;
Anthony Chend4203d82018-05-16 16:21:52 -0700485 case Car.CAR_CONFIGURATION_SERVICE:
486 return mCarConfigurationService;
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800487 case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE:
488 assertTrustAgentEnrollmentPermission(mContext);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700489 return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService();
Simon Dai527eb552019-02-12 13:06:15 -0800490 case Car.CAR_MEDIA_SERVICE:
491 return mCarMediaService;
Keun young Parkbb877e22019-08-02 10:38:01 -0700492 case Car.CAR_OCCUPANT_ZONE_SERVICE:
493 return mCarOccupantZoneService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700494 case Car.CAR_BUGREPORT_SERVICE:
495 return mCarBugreportManagerService;
Eric Jeong1545f3b2019-09-16 13:56:52 -0700496 case Car.CAR_USER_SERVICE:
497 return mCarUserService;
keunyoungca515072015-07-10 12:21:47 -0700498 default:
Keun young Park9a91efb2019-11-15 18:10:47 -0800499 IBinder service = null;
500 if (mCarExperimentalFeatureServiceController != null) {
501 service = mCarExperimentalFeatureServiceController.getCarService(serviceName);
502 }
503 if (service == null) {
504 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:"
505 + serviceName);
506 }
507 return service;
keunyoungca515072015-07-10 12:21:47 -0700508 }
509 }
510
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800511 @Override
512 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700513 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800514 }
515
Keun-young Parka28d7b22016-02-29 16:54:29 -0800516 public CarServiceBase getCarInternalService(String serviceName) {
517 switch (serviceName) {
518 case INTERNAL_INPUT_SERVICE:
519 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700520 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
521 return mSystemActivityMonitoringService;
Yan Zhub07585d2019-10-29 14:16:40 -0700522 // TODO(b/144027497): temporary until tests are refactored to not use it
523 case INTERNAL_VMS_MANAGER:
524 return mVmsClientManager;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800525 default:
526 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
527 serviceName);
528 return null;
529 }
530 }
531
keunyoung1ab8e182015-09-24 09:25:22 -0700532 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700533 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700534 }
535
Keun-young Parke31a8b22016-03-16 17:34:08 -0700536 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700537 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800538 }
539
Pavel Maltsev905968c2017-07-16 19:48:57 -0700540 public static void assertClusterManagerPermission(Context context) {
541 assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL);
542 }
543
Steve Paik388d7772018-02-12 10:54:51 -0800544 public static void assertPowerPermission(Context context) {
545 assertPermission(context, Car.PERMISSION_CAR_POWER);
546 }
547
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800548 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700549 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
550 }
551
Pavel Maltsev079873b2019-02-25 12:15:09 -0800552 /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */
553 public static void assertProjectionStatusPermission(Context context) {
554 assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS);
555 }
556
Enrico Granata3c7a6662017-02-23 18:07:59 -0800557 public static void assertAnyDiagnosticPermission(Context context) {
558 assertAnyPermission(context,
Enrico Granataae25b922017-07-07 11:28:15 -0700559 Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL,
Enrico Granata3c7a6662017-02-23 18:07:59 -0800560 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
561 }
562
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800563 public static void assertDrivingStatePermission(Context context) {
564 assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE);
565 }
566
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800567 public static void assertVmsPublisherPermission(Context context) {
568 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
569 }
570
Antonio Cortese4619c72017-02-02 07:53:27 -0800571 public static void assertVmsSubscriberPermission(Context context) {
572 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
573 }
574
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800575 /**
576 * Ensures the caller has the permission to enroll a Trust Agent.
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800577 */
578 public static void assertTrustAgentEnrollmentPermission(Context context) {
579 assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST);
580 }
581
Steve Paik461ecc62016-06-08 15:28:32 -0700582 public static void assertPermission(Context context, String permission) {
583 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
584 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800585 }
586 }
587
Steve Paik9ec53d72018-04-27 13:28:31 -0700588 /**
589 * Checks to see if the caller has a permission.
Steve Paik9ec53d72018-04-27 13:28:31 -0700590 *
591 * @return boolean TRUE if caller has the permission.
592 */
593 public static boolean hasPermission(Context context, String permission) {
594 return context.checkCallingOrSelfPermission(permission)
595 == PackageManager.PERMISSION_GRANTED;
596 }
597
Enrico Granata3c7a6662017-02-23 18:07:59 -0800598 public static void assertAnyPermission(Context context, String... permissions) {
599 for (String permission : permissions) {
600 if (context.checkCallingOrSelfPermission(permission) ==
601 PackageManager.PERMISSION_GRANTED) {
602 return;
603 }
604 }
605 throw new SecurityException("requires any of " + Arrays.toString(permissions));
606 }
607
Enrico Granatae8056ca2018-04-03 13:19:52 -0700608 @Override
609 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
610 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Anthony Chen12aec302018-04-25 16:41:48 -0700611 != PackageManager.PERMISSION_GRANTED) {
Enrico Granatae8056ca2018-04-03 13:19:52 -0700612 writer.println("Permission Denial: can't dump CarService from from pid="
Anthony Chen12aec302018-04-25 16:41:48 -0700613 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
614 + " without permission " + android.Manifest.permission.DUMP);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700615 return;
keunyounga3b28d82015-08-25 13:05:15 -0700616 }
Enrico Granatae8056ca2018-04-03 13:19:52 -0700617
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700618 if (args == null || args.length == 0 || (args.length > 0 && "-a".equals(args[0]))) {
619 writer.println("*Dump car service*");
Enrico Granatae8056ca2018-04-03 13:19:52 -0700620 writer.println("*Dump all services*");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700621
Mark Tabry7e2a7822019-10-17 10:18:32 -0700622 dumpAllServices(writer);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700623
Enrico Granatae8056ca2018-04-03 13:19:52 -0700624 writer.println("*Dump Vehicle HAL*");
625 writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName);
626 try {
627 // TODO dump all feature flags by creating a dumpable interface
628 mHal.dump(writer);
629 } catch (Exception e) {
630 writer.println("Failed dumping: " + mHal.getClass().getName());
631 e.printStackTrace(writer);
632 }
felipeal080e5652019-11-02 17:04:04 -0700633 } else if ("--list".equals(args[0])) {
634 dumpListOfServices(writer);
635 return;
636 } else if ("--services".equals(args[0])) {
637 if (args.length < 2) {
638 writer.print("Must pass services to dump when using --services");
639 return;
640 }
641 int length = args.length - 1;
642 String[] services = new String[length];
643 System.arraycopy(args, 1, services, 0, length);
644 dumpIndividualServices(writer, services);
645 return;
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700646 } else if ("--metrics".equals(args[0])) {
Mark Tabry7e2a7822019-10-17 10:18:32 -0700647 // Strip the --metrics flag when passing dumpsys arguments to CarStatsService
Mark Tabryc98f9952019-12-03 11:03:48 -0800648 // allowing for nested flag selection
Mark Tabry7e2a7822019-10-17 10:18:32 -0700649 mCarStatsService.dump(fd, writer, Arrays.copyOfRange(args, 1, args.length));
Mark Tabryb588d2e2019-09-12 10:50:11 -0700650 } else if ("--vms-hal".equals(args[0])) {
651 mHal.getVmsHal().dumpMetrics(fd);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700652 } else if (Build.IS_USERDEBUG || Build.IS_ENG) {
653 execShellCmd(args, writer);
654 } else {
655 writer.println("Commands not supported in " + Build.TYPE);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800656 }
657 }
658
felipeal72bf6422019-11-02 17:04:04 -0700659 @Override
660 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
661 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
662 throws RemoteException {
663 new CarShellCommand().exec(this, in, out, err, args, callback, resultReceiver);
664 }
665
felipeal080e5652019-11-02 17:04:04 -0700666 private void dumpListOfServices(PrintWriter writer) {
667 for (CarServiceBase service : mAllServices) {
668 writer.println(service.getClass().getName());
669 }
670 }
671
Mark Tabry7e2a7822019-10-17 10:18:32 -0700672 private void dumpAllServices(PrintWriter writer) {
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700673 for (CarServiceBase service : mAllServices) {
Mark Tabry7e2a7822019-10-17 10:18:32 -0700674 dumpService(service, writer);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700675 }
676 if (mCarTestService != null) {
Mark Tabry7e2a7822019-10-17 10:18:32 -0700677 dumpService(mCarTestService, writer);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700678 }
felipeal080e5652019-11-02 17:04:04 -0700679 }
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700680
felipeal080e5652019-11-02 17:04:04 -0700681 private void dumpIndividualServices(PrintWriter writer, String... serviceNames) {
682 for (String serviceName : serviceNames) {
683 writer.println("** Dumping " + serviceName + "\n");
684 CarServiceBase service = getCarServiceBySubstring(serviceName);
685 if (service == null) {
686 writer.println("No such service!");
687 } else {
Mark Tabry7e2a7822019-10-17 10:18:32 -0700688 dumpService(service, writer);
felipeal080e5652019-11-02 17:04:04 -0700689 }
690 writer.println();
691 }
692 }
693
694 @Nullable
695 private CarServiceBase getCarServiceBySubstring(String className) {
696 return Arrays.asList(mAllServices).stream()
697 .filter(s -> s.getClass().getSimpleName().equals(className))
698 .findFirst().orElse(null);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700699 }
700
Mark Tabry7e2a7822019-10-17 10:18:32 -0700701 private void dumpService(CarServiceBase service, PrintWriter writer) {
Brad Stenninged3d59b2017-11-09 16:15:17 -0800702 try {
Mark Tabry7e2a7822019-10-17 10:18:32 -0700703 service.dump(writer);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800704 } catch (Exception e) {
705 writer.println("Failed dumping: " + service.getClass().getName());
706 e.printStackTrace(writer);
707 }
keunyoungcc449f72015-08-12 10:46:27 -0700708 }
Yao Chene33f07e2016-07-26 12:02:51 -0700709
710 void execShellCmd(String[] args, PrintWriter writer) {
711 new CarShellCommand().exec(args, writer);
712 }
713
Pavel Maltsevabd47232017-10-10 16:54:57 -0700714 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700715 private void traceBegin(String name) {
Steve Paikc302c7c2017-08-04 14:01:58 -0700716 Slog.i(TAG, name);
717 mBootTiming.traceBegin(name);
718 }
719
Pavel Maltsevabd47232017-10-10 16:54:57 -0700720 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700721 private void traceEnd() {
Steve Paikc302c7c2017-08-04 14:01:58 -0700722 mBootTiming.traceEnd();
723 }
724
felipeal72bf6422019-11-02 17:04:04 -0700725 private final class CarShellCommand extends ShellCommand {
Yao Chene33f07e2016-07-26 12:02:51 -0700726 private static final String COMMAND_HELP = "-h";
727 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800728 private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event";
Kai4b098cf2019-06-05 15:03:28 -0700729 private static final String COMMAND_INJECT_ERROR_EVENT = "inject-error-event";
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800730 private static final String COMMAND_ENABLE_UXR = "enable-uxr";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800731 private static final String COMMAND_GARAGE_MODE = "garage-mode";
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800732 private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities";
Kaidd4ef5a2019-03-04 14:07:26 -0800733 private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig";
Kai29fba112019-04-22 18:37:38 -0700734 private static final String COMMAND_GET_PROPERTY_VALUE = "get-property-value";
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700735 private static final String COMMAND_PROJECTION_AP_TETHERING = "projection-tethering";
Pavel Maltsev48a31942019-03-03 22:08:28 -0800736 private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode";
Jim Kayed76c2742019-04-02 11:33:27 -0700737 private static final String COMMAND_RESUME = "resume";
738 private static final String COMMAND_SUSPEND = "suspend";
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700739 private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device";
740 private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices";
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700741 private static final String COMMAND_SET_UID_TO_ZONE = "set-zoneid-for-uid";
Keun young Park09ca8492019-10-15 10:34:11 -0700742 private static final String COMMAND_START_FIXED_ACTIVITY_MODE = "start-fixed-activity-mode";
743 private static final String COMMAND_STOP_FIXED_ACTIVITY_MODE = "stop-fixed-activity-mode";
Keun young Park9a91efb2019-11-15 18:10:47 -0800744 private static final String COMMAND_ENABLE_FEATURE = "enable-feature";
745 private static final String COMMAND_DISABLE_FEATURE = "disable-feature";
Keun young Park313dfaf2019-12-19 11:32:38 -0800746 private static final String COMMAND_INJECT_KEY = "inject-key";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800747
Yao Chene33f07e2016-07-26 12:02:51 -0700748 private static final String PARAM_DAY_MODE = "day";
749 private static final String PARAM_NIGHT_MODE = "night";
750 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800751 private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800752 private static final String PARAM_ON_MODE = "on";
753 private static final String PARAM_OFF_MODE = "off";
754 private static final String PARAM_QUERY_MODE = "query";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800755
felipeal72bf6422019-11-02 17:04:04 -0700756 private static final int RESULT_OK = 0;
757 private static final int RESULT_ERROR = -1; // Arbitrary value, any non-0 is fine
758
759
760 @Override
761 public int onCommand(String cmd) {
762 if (cmd == null) {
763 onHelp();
764 return RESULT_ERROR;
765 }
766 ArrayList<String> argsList = new ArrayList<>();
767 argsList.add(cmd);
768 String arg = null;
769 do {
770 arg = getNextArg();
771 if (arg != null) {
772 argsList.add(arg);
773 }
774 } while (arg != null);
775 String[] args = new String[argsList.size()];
776 argsList.toArray(args);
777 return exec(args, getOutPrintWriter());
778 }
779
780 @Override
781 public void onHelp() {
782 dumpHelp(getOutPrintWriter());
783 }
Yao Chene33f07e2016-07-26 12:02:51 -0700784
785 private void dumpHelp(PrintWriter pw) {
786 pw.println("Car service commands:");
787 pw.println("\t-h");
788 pw.println("\t Print this help text.");
789 pw.println("\tday-night-mode [day|night|sensor]");
790 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800791 pw.println("\tinject-vhal-event property [zone] data(can be comma separated list)");
Jim Kayef10b7d82019-02-26 12:53:22 -0800792 pw.println("\t Inject a vehicle property for testing.");
Kai4b098cf2019-06-05 15:03:28 -0700793 pw.println("\tinject-error-event property zone errorCode");
794 pw.println("\t Inject an error event from VHAL for testing.");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700795 pw.println("\tenable-uxr true|false");
796 pw.println("\t Enable/Disable UX restrictions and App blocking.");
Bryan Eylera32a7c12018-02-27 15:40:00 -0800797 pw.println("\tgarage-mode [on|off|query]");
798 pw.println("\t Force into garage mode or check status.");
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800799 pw.println("\tget-do-activities pkgname");
Jim Kayef10b7d82019-02-26 12:53:22 -0800800 pw.println("\t Get Distraction Optimized activities in given package.");
Kaidd4ef5a2019-03-04 14:07:26 -0800801 pw.println("\tget-carpropertyconfig [propertyId]");
802 pw.println("\t Get a CarPropertyConfig by Id in Hex or list all CarPropertyConfigs");
Kai29fba112019-04-22 18:37:38 -0700803 pw.println("\tget-property-value [propertyId] [areaId]");
804 pw.println("\t Get a vehicle property value by property id in Hex and areaId");
805 pw.println("\t or list all property values for all areaId");
Jim Kayed76c2742019-04-02 11:33:27 -0700806 pw.println("\tsuspend");
807 pw.println("\t Suspend the system to Deep Sleep.");
808 pw.println("\tresume");
809 pw.println("\t Wake the system up after a 'suspend.'");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700810 pw.println("\tenable-trusted-device true|false");
811 pw.println("\t Enable/Disable Trusted device feature.");
812 pw.println("\tremove-trusted-devices");
813 pw.println("\t Remove all trusted devices for the current foreground user.");
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700814 pw.println("\tprojection-tethering [true|false]");
815 pw.println("\t Whether tethering should be used when creating access point for"
816 + " wireless projection");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700817 pw.println("\t--metrics");
818 pw.println("\t When used with dumpsys, only metrics will be in the dumpsys output.");
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700819 pw.println("\tset-zoneid-for-uid [zoneid] [uid]");
820 pw.println("\t Maps the audio zoneid to uid.");
Keun young Park09ca8492019-10-15 10:34:11 -0700821 pw.println("\tstart-fixed-activity displayId packageName activityName");
822 pw.println("\t Start an Activity the specified display as fixed mode");
823 pw.println("\tstop-fixed-mode displayId");
824 pw.println("\t Stop fixed Activity mode for the given display. "
825 + "The Activity will not be restarted upon crash.");
Keun young Park9a91efb2019-11-15 18:10:47 -0800826 pw.println("\tenable-feature featureName");
827 pw.println("\t Enable the requested feature. Change will happen after reboot.");
828 pw.println("\t This requires root/su.");
829 pw.println("\tdisable-feature featureName");
830 pw.println("\t Disable the requested feature. Change will happen after reboot");
831 pw.println("\t This requires root/su.");
Keun young Park313dfaf2019-12-19 11:32:38 -0800832 pw.println("\tinject-key [-d display] [-t down_delay_ms] key_code");
833 pw.println("\t inject key down / up event to car service");
834 pw.println("\t display: 0 for main, 1 for cluster. If not specified, it will be 0.");
835 pw.println("\t down_delay_ms: delay from down to up key event. If not specified,");
836 pw.println("\t it will be 0");
837 pw.println("\t key_code: int key code defined in android KeyEvent");
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700838 }
839
felipeal72bf6422019-11-02 17:04:04 -0700840 private int dumpInvalidArguments(PrintWriter pw) {
841 pw.println("Incorrect number of arguments.");
842 dumpHelp(pw);
843 return RESULT_ERROR;
844 }
845
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700846 private String runSetZoneIdForUid(String zoneString, String uidString) {
847 int uid = Integer.parseInt(uidString);
848 int zoneId = Integer.parseInt(zoneString);
849 if (!ArrayUtils.contains(mCarAudioService.getAudioZoneIds(), zoneId)) {
850 return "zoneid " + zoneId + " not found";
851 }
852 mCarAudioService.setZoneIdForUid(zoneId, uid);
853 return null;
Yao Chene33f07e2016-07-26 12:02:51 -0700854 }
855
felipeal72bf6422019-11-02 17:04:04 -0700856 public int exec(String[] args, PrintWriter writer) {
Yao Chene33f07e2016-07-26 12:02:51 -0700857 String arg = args[0];
858 switch (arg) {
859 case COMMAND_HELP:
860 dumpHelp(writer);
861 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800862 case COMMAND_DAY_NIGHT_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800863 String value = args.length < 2 ? "" : args[1];
Yao Chene33f07e2016-07-26 12:02:51 -0700864 forceDayNightMode(value, writer);
865 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800866 }
867 case COMMAND_GARAGE_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800868 String value = args.length < 2 ? "" : args[1];
Bryan Eylera32a7c12018-02-27 15:40:00 -0800869 forceGarageMode(value, writer);
870 break;
871 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800872 case COMMAND_INJECT_VHAL_EVENT:
873 String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL;
874 String data;
Jim Kayef10b7d82019-02-26 12:53:22 -0800875 if (args.length != 3 && args.length != 4) {
felipeal72bf6422019-11-02 17:04:04 -0700876 return dumpInvalidArguments(writer);
Jim Kayef10b7d82019-02-26 12:53:22 -0800877 } else if (args.length == 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800878 // Zoned
879 zone = args[2];
880 data = args[3];
881 } else {
882 // Global
883 data = args[2];
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800884 }
Kai4b098cf2019-06-05 15:03:28 -0700885 injectVhalEvent(args[1], zone, data, false, writer);
886 break;
887 case COMMAND_INJECT_ERROR_EVENT:
888 if (args.length != 4) {
felipeal72bf6422019-11-02 17:04:04 -0700889 return dumpInvalidArguments(writer);
Kai4b098cf2019-06-05 15:03:28 -0700890 }
891 String errorAreaId = args[2];
892 String errorCode = args[3];
893 injectVhalEvent(args[1], errorAreaId, errorCode, true, writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800894 break;
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800895 case COMMAND_ENABLE_UXR:
Jim Kayef10b7d82019-02-26 12:53:22 -0800896 if (args.length != 2) {
felipeal72bf6422019-11-02 17:04:04 -0700897 return dumpInvalidArguments(writer);
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800898 }
899 boolean enableBlocking = Boolean.valueOf(args[1]);
900 if (mCarPackageManagerService != null) {
901 mCarPackageManagerService.setEnableActivityBlocking(enableBlocking);
902 }
903 break;
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800904 case COMMAND_GET_DO_ACTIVITIES:
Jim Kayef10b7d82019-02-26 12:53:22 -0800905 if (args.length != 2) {
felipeal72bf6422019-11-02 17:04:04 -0700906 return dumpInvalidArguments(writer);
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800907 }
908 String pkgName = args[1].toLowerCase();
909 if (mCarPackageManagerService != null) {
910 String[] doActivities =
911 mCarPackageManagerService.getDistractionOptimizedActivities(
912 pkgName);
913 if (doActivities != null) {
914 writer.println("DO Activities for " + pkgName);
915 for (String a : doActivities) {
916 writer.println(a);
917 }
918 } else {
919 writer.println("No DO Activities for " + pkgName);
920 }
921 }
922 break;
Kaidd4ef5a2019-03-04 14:07:26 -0800923 case COMMAND_GET_CARPROPERTYCONFIG:
924 String propertyId = args.length < 2 ? "" : args[1];
925 mHal.dumpPropertyConfigs(writer, propertyId);
926 break;
Kai29fba112019-04-22 18:37:38 -0700927 case COMMAND_GET_PROPERTY_VALUE:
928 String propId = args.length < 2 ? "" : args[1];
929 String areaId = args.length < 3 ? "" : args[2];
930 mHal.dumpPropertyValueByCommend(writer, propId, areaId);
931 break;
Pavel Maltsev48a31942019-03-03 22:08:28 -0800932 case COMMAND_PROJECTION_UI_MODE:
933 if (args.length != 2) {
felipeal72bf6422019-11-02 17:04:04 -0700934 return dumpInvalidArguments(writer);
Pavel Maltsev48a31942019-03-03 22:08:28 -0800935 }
936 mCarProjectionService.setUiMode(Integer.valueOf(args[1]));
Pavel Maltsevd6961f62019-03-26 10:22:31 -0700937 break;
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700938 case COMMAND_PROJECTION_AP_TETHERING:
939 if (args.length != 2) {
felipeal72bf6422019-11-02 17:04:04 -0700940 return dumpInvalidArguments(writer);
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700941 }
942 mCarProjectionService.setAccessPointTethering(Boolean.valueOf(args[1]));
943 break;
Jim Kayed76c2742019-04-02 11:33:27 -0700944 case COMMAND_RESUME:
945 mCarPowerManagementService.forceSimulatedResume();
946 writer.println("Resume: Simulating resuming from Deep Sleep");
947 break;
948 case COMMAND_SUSPEND:
949 mCarPowerManagementService.forceSimulatedSuspend();
950 writer.println("Resume: Simulating powering down to Deep Sleep");
951 break;
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700952 case COMMAND_ENABLE_TRUSTED_DEVICE:
953 if (args.length != 2) {
felipeal72bf6422019-11-02 17:04:04 -0700954 return dumpInvalidArguments(writer);
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700955 }
956 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
957 .setTrustedDeviceEnrollmentEnabled(Boolean.valueOf(args[1]));
958 mCarTrustedDeviceService.getCarTrustAgentUnlockService()
959 .setTrustedDeviceUnlockEnabled(Boolean.valueOf(args[1]));
960 break;
961 case COMMAND_REMOVE_TRUSTED_DEVICES:
962 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
Anthony Hughfbb67762019-10-15 12:54:54 -0700963 .removeAllTrustedDevices(ActivityManager.getCurrentUser());
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700964 break;
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700965 case COMMAND_SET_UID_TO_ZONE:
966 if (args.length != 3) {
felipeal72bf6422019-11-02 17:04:04 -0700967 return dumpInvalidArguments(writer);
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700968 }
969 String results = runSetZoneIdForUid(args[1], args[2]);
970 if (results != null) {
971 writer.println(results);
972 dumpHelp(writer);
973 }
974 break;
Keun young Park09ca8492019-10-15 10:34:11 -0700975 case COMMAND_START_FIXED_ACTIVITY_MODE:
976 handleStartFixedActivity(args, writer);
977 break;
978 case COMMAND_STOP_FIXED_ACTIVITY_MODE:
979 handleStopFixedMode(args, writer);
980 break;
Keun young Park9a91efb2019-11-15 18:10:47 -0800981 case COMMAND_ENABLE_FEATURE:
982 if (args.length != 2) {
983 return dumpInvalidArguments(writer);
984 }
985 handleEnableDisableFeature(args, writer, /* enable= */ true);
986 break;
987 case COMMAND_DISABLE_FEATURE:
988 if (args.length != 2) {
989 return dumpInvalidArguments(writer);
990 }
991 handleEnableDisableFeature(args, writer, /* enable= */ false);
992 break;
Keun young Park313dfaf2019-12-19 11:32:38 -0800993 case COMMAND_INJECT_KEY:
994 if (args.length < 2) {
995 return dumpInvalidArguments(writer);
996 }
997 handleInjectKey(args, writer);
998 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700999 default:
Jim Kayef10b7d82019-02-26 12:53:22 -08001000 writer.println("Unknown command: \"" + arg + "\"");
Yao Chene33f07e2016-07-26 12:02:51 -07001001 dumpHelp(writer);
felipeal72bf6422019-11-02 17:04:04 -07001002 return RESULT_ERROR;
Yao Chene33f07e2016-07-26 12:02:51 -07001003 }
felipeal72bf6422019-11-02 17:04:04 -07001004 return RESULT_OK;
Yao Chene33f07e2016-07-26 12:02:51 -07001005 }
1006
Keun young Park09ca8492019-10-15 10:34:11 -07001007 private void handleStartFixedActivity(String[] args, PrintWriter writer) {
1008 if (args.length != 4) {
1009 writer.println("Incorrect number of arguments");
1010 dumpHelp(writer);
1011 return;
1012 }
1013 int displayId;
1014 try {
1015 displayId = Integer.parseInt(args[1]);
1016 } catch (NumberFormatException e) {
1017 writer.println("Wrong display id:" + args[1]);
1018 return;
1019 }
1020 String packageName = args[2];
1021 String activityName = args[3];
1022 Intent intent = new Intent();
1023 intent.setComponent(new ComponentName(packageName, activityName));
1024 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
1025 ActivityOptions options = ActivityOptions.makeBasic();
1026 options.setLaunchDisplayId(displayId);
1027 if (!mFixedActivityService.startFixedActivityModeForDisplayAndUser(intent, options,
1028 displayId, ActivityManager.getCurrentUser())) {
1029 writer.println("Failed to start");
1030 return;
1031 }
1032 writer.println("Succeeded");
1033 }
1034
1035 private void handleStopFixedMode(String[] args, PrintWriter writer) {
1036 if (args.length != 2) {
1037 writer.println("Incorrect number of arguments");
1038 dumpHelp(writer);
1039 return;
1040 }
1041 int displayId;
1042 try {
1043 displayId = Integer.parseInt(args[1]);
1044 } catch (NumberFormatException e) {
1045 writer.println("Wrong display id:" + args[1]);
1046 return;
1047 }
1048 mFixedActivityService.stopFixedActivityMode(displayId);
1049 }
1050
Keun young Park9a91efb2019-11-15 18:10:47 -08001051 private void handleEnableDisableFeature(String[] args, PrintWriter writer, boolean enable) {
1052 if (Binder.getCallingUid() != Process.ROOT_UID) {
1053 writer.println("Only allowed to root/su");
1054 return;
1055 }
1056 String featureName = args[1];
1057 long id = Binder.clearCallingIdentity();
1058 // no permission check here
1059 int r;
1060 if (enable) {
1061 r = mFeatureController.enableFeature(featureName);
1062 } else {
1063 r = mFeatureController.disableFeature(featureName);
1064 }
1065 switch (r) {
1066 case Car.FEATURE_REQUEST_SUCCESS:
1067 if (enable) {
1068 writer.println("Enabled feature:" + featureName);
1069 } else {
1070 writer.println("Disabled feature:" + featureName);
1071 }
1072 break;
1073 case Car.FEATURE_REQUEST_ALREADY_IN_THE_STATE:
1074 if (enable) {
1075 writer.println("Already enabled:" + featureName);
1076 } else {
1077 writer.println("Already disabled:" + featureName);
1078 }
1079 break;
1080 case Car.FEATURE_REQUEST_MANDATORY:
1081 writer.println("Cannot change mandatory feature:" + featureName);
1082 break;
1083 case Car.FEATURE_REQUEST_NOT_EXISTING:
1084 writer.println("Non-existing feature:" + featureName);
1085 break;
1086 default:
1087 writer.println("Unknown error:" + r);
1088 break;
1089 }
1090 Binder.restoreCallingIdentity(id);
1091 }
1092
Keun young Park313dfaf2019-12-19 11:32:38 -08001093 private void handleInjectKey(String[] args, PrintWriter writer) {
1094 int i = 1; // 0 is command itself
1095 int display = InputHalService.DISPLAY_MAIN;
1096 int delayMs = 0;
1097 int keyCode = KeyEvent.KEYCODE_UNKNOWN;
1098 try {
1099 while (i < args.length) {
1100 switch (args[i]) {
1101 case "-d":
1102 i++;
1103 display = Integer.parseInt(args[i]);
1104 break;
1105 case "-t":
1106 i++;
1107 delayMs = Integer.parseInt(args[i]);
1108 break;
1109 default:
1110 if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
1111 throw new IllegalArgumentException("key_code already set:"
1112 + keyCode);
1113 }
1114 keyCode = Integer.parseInt(args[i]);
1115 }
1116 i++;
1117 }
1118 } catch (Exception e) {
1119 writer.println("Invalid args:" + e);
1120 dumpHelp(writer);
1121 return;
1122 }
1123 if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
1124 writer.println("Missing key code or invalid keycode");
1125 dumpHelp(writer);
1126 return;
1127 }
1128 if (display != InputHalService.DISPLAY_MAIN
1129 && display != InputHalService.DISPLAY_INSTRUMENT_CLUSTER) {
1130 writer.println("Invalid display:" + display);
1131 dumpHelp(writer);
1132 return;
1133 }
1134 if (delayMs < 0) {
1135 writer.println("Invalid delay:" + delayMs);
1136 dumpHelp(writer);
1137 return;
1138 }
1139 KeyEvent keyDown = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
1140 mCarInputService.onKeyEvent(keyDown, display);
1141 SystemClock.sleep(delayMs);
1142 KeyEvent keyUp = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
1143 mCarInputService.onKeyEvent(keyUp, display);
1144 writer.println("Succeeded");
1145 }
1146
Yao Chene33f07e2016-07-26 12:02:51 -07001147 private void forceDayNightMode(String arg, PrintWriter writer) {
1148 int mode;
1149 switch (arg) {
1150 case PARAM_DAY_MODE:
1151 mode = CarNightService.FORCED_DAY_MODE;
1152 break;
1153 case PARAM_NIGHT_MODE:
1154 mode = CarNightService.FORCED_NIGHT_MODE;
1155 break;
1156 case PARAM_SENSOR_MODE:
1157 mode = CarNightService.FORCED_SENSOR_MODE;
1158 break;
1159 default:
1160 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
1161 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
1162 return;
1163 }
1164 int current = mCarNightService.forceDayNightMode(mode);
1165 String currentMode = null;
1166 switch (current) {
1167 case UiModeManager.MODE_NIGHT_AUTO:
1168 currentMode = PARAM_SENSOR_MODE;
1169 break;
1170 case UiModeManager.MODE_NIGHT_YES:
1171 currentMode = PARAM_NIGHT_MODE;
1172 break;
1173 case UiModeManager.MODE_NIGHT_NO:
1174 currentMode = PARAM_DAY_MODE;
1175 break;
1176 }
1177 writer.println("DayNightMode changed to: " + currentMode);
1178 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001179
Bryan Eylera32a7c12018-02-27 15:40:00 -08001180 private void forceGarageMode(String arg, PrintWriter writer) {
1181 switch (arg) {
1182 case PARAM_ON_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -07001183 mGarageModeService.forceStartGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -07001184 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -08001185 break;
1186 case PARAM_OFF_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -07001187 mGarageModeService.stopAndResetGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -07001188 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -08001189 break;
1190 case PARAM_QUERY_MODE:
Jim Kaye1b5e6182019-05-24 15:48:32 -07001191 mGarageModeService.dump(writer);
Bryan Eylera32a7c12018-02-27 15:40:00 -08001192 break;
1193 default:
1194 writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|"
1195 + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE);
Bryan Eylera32a7c12018-02-27 15:40:00 -08001196 }
Bryan Eylera32a7c12018-02-27 15:40:00 -08001197 }
1198
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001199 /**
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001200 * Inject a fake VHAL event
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -08001201 *
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001202 * @param property the Vehicle property Id as defined in the HAL
1203 * @param zone Zone that this event services
Kai4b098cf2019-06-05 15:03:28 -07001204 * @param isErrorEvent indicates the type of event
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001205 * @param value Data value of the event
1206 * @param writer PrintWriter
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001207 */
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001208 private void injectVhalEvent(String property, String zone, String value,
Kai4b098cf2019-06-05 15:03:28 -07001209 boolean isErrorEvent, PrintWriter writer) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001210 if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) {
1211 if (!isPropertyAreaTypeGlobal(property)) {
1212 writer.println("Property area type inconsistent with given zone");
1213 return;
1214 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001215 }
1216 try {
Kai4b098cf2019-06-05 15:03:28 -07001217 if (isErrorEvent) {
1218 mHal.injectOnPropertySetError(property, zone, value);
1219 } else {
1220 mHal.injectVhalEvent(property, zone, value);
1221 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001222 } catch (NumberFormatException e) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001223 writer.println("Invalid property Id zone Id or value" + e);
1224 dumpHelp(writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001225 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -08001226 }
1227
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001228 // Check if the given property is global
1229 private boolean isPropertyAreaTypeGlobal(String property) {
1230 if (property == null) {
1231 return false;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -08001232 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -08001233 return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -08001234 }
Yao Chene33f07e2016-07-26 12:02:51 -07001235 }
kevinjm55822c42018-08-15 11:26:00 -07001236}