blob: 17d3e83e3eef6f844cf3e2d6704b0e9f899c8f9f [file] [log] [blame]
keunyoungca515072015-07-10 12:21:47 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car;
18
Pavel Maltsevabd47232017-10-10 16:54:57 -070019import android.annotation.MainThread;
Keun young Parkf3523cd2019-04-08 10:09:17 -070020import android.app.ActivityManager;
Yao Chene33f07e2016-07-26 12:02:51 -070021import android.app.UiModeManager;
Keun-young Parke54ac272016-02-16 19:02:18 -080022import android.car.Car;
23import android.car.ICar;
Pavel Maltsev0477e292016-05-27 12:22:36 -070024import android.car.cluster.renderer.IInstrumentClusterNavigation;
Ying Zheng9fc99402018-09-19 14:23:59 -070025import android.car.userlib.CarUserManagerHelper;
keunyoungca515072015-07-10 12:21:47 -070026import android.content.Context;
keunyoung1ab8e182015-09-24 09:25:22 -070027import android.content.pm.PackageManager;
Keun young Parkf3523cd2019-04-08 10:09:17 -070028import android.content.res.Resources;
Pavel Maltsevcfe93102017-02-02 12:38:08 -080029import android.hardware.automotive.vehicle.V2_0.IVehicle;
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -080030import android.hardware.automotive.vehicle.V2_0.VehicleArea;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070031import android.os.Binder;
Enrico Granatae8056ca2018-04-03 13:19:52 -070032import android.os.Build;
keunyoungca515072015-07-10 12:21:47 -070033import android.os.IBinder;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070034import android.os.Process;
Steve Paikc302c7c2017-08-04 14:01:58 -070035import android.os.Trace;
Anthony Hugh9932a252019-06-12 16:19:56 -070036import android.os.UserManager;
keunyoungca515072015-07-10 12:21:47 -070037import android.util.Log;
Steve Paikc302c7c2017-08-04 14:01:58 -070038import android.util.Slog;
Keun-young Park4a79a382017-08-10 18:19:14 -070039import android.util.TimingsTraceLog;
Gregory Clark26fa6012018-03-14 18:38:56 -070040
Hongwei Wang38549092018-08-22 12:32:42 -070041import com.android.car.audio.CarAudioService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080042import com.android.car.cluster.InstrumentClusterService;
Serik Beketayev06a66682018-06-12 16:54:29 -070043import com.android.car.garagemode.GarageModeService;
keunyoungcc449f72015-08-12 10:46:27 -070044import com.android.car.hal.VehicleHal;
Antonio Cortesc52d5f92017-02-06 08:47:38 -080045import com.android.car.internal.FeatureConfiguration;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080046import com.android.car.pm.CarPackageManagerService;
Enrico Granatab19bc322017-10-12 12:25:06 -070047import com.android.car.systeminterface.SystemInterface;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070048import com.android.car.trust.CarTrustedDeviceService;
Keun young Park7af7d6c2019-09-12 10:31:48 -070049import com.android.car.user.CarUserNoticeService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070050import com.android.car.user.CarUserService;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080051import com.android.car.vms.VmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -080052import com.android.car.vms.VmsClientManager;
keunyoungca515072015-07-10 12:21:47 -070053import com.android.internal.annotations.GuardedBy;
Steve Paik1d8bea22018-02-03 01:54:06 +000054import com.android.internal.car.ICarServiceHelper;
Oscar Azucena3f3a25e2019-07-12 14:28:24 -070055import com.android.internal.util.ArrayUtils;
Gregory Clark26fa6012018-03-14 18:38:56 -070056
Enrico Granatae8056ca2018-04-03 13:19:52 -070057import java.io.FileDescriptor;
keunyounga3b28d82015-08-25 13:05:15 -070058import java.io.PrintWriter;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070059import java.util.ArrayList;
Antonio Cortese4619c72017-02-02 07:53:27 -080060import java.util.Arrays;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070061import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070062
keunyoungca515072015-07-10 12:21:47 -070063public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070064
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -080065 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070066 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
67 "system_activity_monitoring";
Keun-young Parka28d7b22016-02-29 16:54:29 -080068
keunyoungca515072015-07-10 12:21:47 -070069 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080070 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070071
Anthony Chen12aec302018-04-25 16:41:48 -070072 private final SystemInterface mSystemInterface;
73
Keun-young Park4727da32016-05-31 10:00:51 -070074 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070075 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080076 private final CarPackageManagerService mCarPackageManagerService;
77 private final CarInputService mCarInputService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -080078 private final CarDrivingStateService mCarDrivingStateService;
Ram Periathiruvadi4526a432018-01-24 13:00:54 -080079 private final CarUxRestrictionsManagerService mCarUXRestrictionsService;
keunyoungd32f4e62015-09-21 11:33:06 -070080 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080081 private final CarProjectionService mCarProjectionService;
Steve Paik9ec53d72018-04-27 13:28:31 -070082 private final CarPropertyService mCarPropertyService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080083 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070084 private final AppFocusService mAppFocusService;
Yao Chen3a7976d2016-01-20 17:27:08 -080085 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080086 private final InstrumentClusterService mInstrumentClusterService;
Gregory Clarkd8136062017-12-11 14:27:53 -080087 private final CarLocationService mCarLocationService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070088 private final SystemStateControllerService mSystemStateControllerService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080089 private final CarBluetoothService mCarBluetoothService;
Ram Periathiruvadiacb60242017-04-13 16:19:09 -070090 private final PerUserCarServiceHelper mPerUserCarServiceHelper;
Enrico Granata9a916d72017-09-19 14:33:08 -070091 private final CarDiagnosticService mCarDiagnosticService;
92 private final CarStorageMonitoringService mCarStorageMonitoringService;
Anthony Chen12aec302018-04-25 16:41:48 -070093 private final CarConfigurationService mCarConfigurationService;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070094 private final CarTrustedDeviceService mCarTrustedDeviceService;
Simon Dai527eb552019-02-12 13:06:15 -080095 private final CarMediaService mCarMediaService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070096 private final CarUserManagerHelper mUserManagerHelper;
Keun-young Parkd462a912019-02-11 08:53:42 -080097 private final CarUserService mCarUserService;
Keun young Parkbb877e22019-08-02 10:38:01 -070098 private final CarOccupantZoneService mCarOccupantZoneService;
Keun young Park7af7d6c2019-09-12 10:31:48 -070099 private final CarUserNoticeService mCarUserNoticeService;
Mark Tabrya8fce562019-01-16 16:24:01 -0800100 private final VmsClientManager mVmsClientManager;
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800101 private final VmsBrokerService mVmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -0800102 private final VmsSubscriberService mVmsSubscriberService;
103 private final VmsPublisherService mVmsPublisherService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700104 private final CarBugreportManagerService mCarBugreportManagerService;
keunyounga74b9ca2015-10-21 13:33:58 -0700105
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700106 private final CarServiceBase[] mAllServices;
107
Steve Paikc302c7c2017-08-04 14:01:58 -0700108 private static final String TAG = "ICarImpl";
109 private static final String VHAL_TIMING_TAG = "VehicleHalTiming";
Serik Beketayev74debf22018-10-04 12:18:09 -0700110
111 private TimingsTraceLog mBootTiming;
Steve Paikc302c7c2017-08-04 14:01:58 -0700112
keunyoung1ab8e182015-09-24 09:25:22 -0700113 /** Test only service. Populate it only when necessary. */
114 @GuardedBy("this")
115 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -0700116
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700117 @GuardedBy("this")
118 private ICarServiceHelper mICarServiceHelper;
119
Enrico Granatae8056ca2018-04-03 13:19:52 -0700120 private final String mVehicleInterfaceName;
121
Pavel Maltsevec83b632017-01-05 15:10:55 -0800122 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
Enrico Granatae8056ca2018-04-03 13:19:52 -0700123 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) {
keunyoungca515072015-07-10 12:21:47 -0700124 mContext = serviceContext;
Steve Paik0f9fc002018-02-09 17:42:00 -0800125 mSystemInterface = systemInterface;
Mark Tabryb588d2e2019-09-12 10:50:11 -0700126 mHal = new VehicleHal(serviceContext, vehicle);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700127 mVehicleInterfaceName = vehicleInterfaceName;
Yao, Yuxing0811d5a2018-11-29 16:18:53 -0800128 mUserManagerHelper = new CarUserManagerHelper(serviceContext);
Anthony Hugh9932a252019-06-12 16:19:56 -0700129 UserManager userManager =
130 (UserManager) serviceContext.getSystemService(Context.USER_SERVICE);
Keun young Parkf3523cd2019-04-08 10:09:17 -0700131 final Resources res = mContext.getResources();
132 final int maxRunningUsers = res.getInteger(
133 com.android.internal.R.integer.config_multiuserMaxRunningUsers);
Anthony Hugh9932a252019-06-12 16:19:56 -0700134 mCarUserService = new CarUserService(serviceContext, mUserManagerHelper, userManager,
Keun young Parkf3523cd2019-04-08 10:09:17 -0700135 ActivityManager.getService(), maxRunningUsers);
Keun young Parkbb877e22019-08-02 10:38:01 -0700136 mCarOccupantZoneService = new CarOccupantZoneService(serviceContext);
Keun-young Park4727da32016-05-31 10:00:51 -0700137 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Steve Paik388d7772018-02-12 10:54:51 -0800138 mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(),
Keun young Park9b3f2662019-03-19 10:30:25 -0700139 systemInterface, mUserManagerHelper);
Keun young Park7af7d6c2019-09-12 10:31:48 -0700140 mCarUserNoticeService = new CarUserNoticeService(serviceContext);
Steve Paik9ec53d72018-04-27 13:28:31 -0700141 mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal());
142 mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService);
Ram Periathiruvadi4526a432018-01-24 13:00:54 -0800143 mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext,
Yao, Yuxing9bfb7492019-02-15 11:53:34 -0800144 mCarDrivingStateService, mCarPropertyService);
Ram Periathiruvadi2da6d0e2018-01-26 18:02:10 -0800145 mCarPackageManagerService = new CarPackageManagerService(serviceContext,
146 mCarUXRestrictionsService,
Pavel Maltsev38da4312019-04-08 10:38:38 -0700147 mSystemActivityMonitoringService,
148 mUserManagerHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800149 mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext);
Sal Savage703c46f2019-04-15 08:39:25 -0700150 mCarBluetoothService = new CarBluetoothService(serviceContext, mPerUserCarServiceHelper);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700151 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Justin Paupore44985ba2019-01-30 18:53:41 -0800152 mCarProjectionService = new CarProjectionService(
Pavel Maltsev079873b2019-02-25 12:15:09 -0800153 serviceContext, null /* handler */, mCarInputService, mCarBluetoothService);
Serik Beketayevc6ab8be2018-08-28 21:20:53 -0700154 mGarageModeService = new GarageModeService(mContext);
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700155 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Hongwei Wang30557232018-01-02 10:25:08 -0800156 mCarAudioService = new CarAudioService(serviceContext);
Steve Paik9ec53d72018-04-27 13:28:31 -0700157 mCarNightService = new CarNightService(serviceContext, mCarPropertyService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700158 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700159 mAppFocusService, mCarInputService);
Serik Beketayevf9f2ef02018-09-06 12:37:02 -0700160 mSystemStateControllerService = new SystemStateControllerService(
161 serviceContext, mCarAudioService, this);
Mark Tabry61a06c72019-06-17 10:37:49 -0700162 mVmsBrokerService = new VmsBrokerService();
Mark Tabry1534c062019-03-29 01:30:49 -0700163 mVmsClientManager = new VmsClientManager(
Mark Tabry61a06c72019-06-17 10:37:49 -0700164 serviceContext, mVmsBrokerService, mCarUserService, mUserManagerHelper,
165 mHal.getVmsHal());
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800166 mVmsSubscriberService = new VmsSubscriberService(
Mark Tabry61a06c72019-06-17 10:37:49 -0700167 serviceContext, mVmsBrokerService, mVmsClientManager, mHal.getVmsHal());
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800168 mVmsPublisherService = new VmsPublisherService(
Mark Tabry1534c062019-03-29 01:30:49 -0700169 serviceContext, mVmsBrokerService, mVmsClientManager);
Enrico Granatab3634e22017-05-05 18:02:31 -0700170 mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal());
Enrico Granata517a1e02017-09-20 16:15:50 -0700171 mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext,
172 systemInterface);
Anthony Chen12aec302018-04-25 16:41:48 -0700173 mCarConfigurationService =
174 new CarConfigurationService(serviceContext, new JsonReaderImpl());
Gregory Clarke1519532019-05-10 16:25:57 -0700175 mCarLocationService = new CarLocationService(mContext, mUserManagerHelper);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700176 mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext);
Simon Dai527eb552019-02-12 13:06:15 -0800177 mCarMediaService = new CarMediaService(serviceContext);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700178 mCarBugreportManagerService = new CarBugreportManagerService(serviceContext);
keunyounga74b9ca2015-10-21 13:33:58 -0700179
Keun young Parka5fa4782019-04-16 18:56:27 -0700180 CarLocalServices.addService(CarPowerManagementService.class, mCarPowerManagementService);
Keun young Parkbb877e22019-08-02 10:38:01 -0700181 CarLocalServices.addService(CarPropertyService.class, mCarPropertyService);
Keun-young Parkd462a912019-02-11 08:53:42 -0800182 CarLocalServices.addService(CarUserService.class, mCarUserService);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700183 CarLocalServices.addService(CarTrustedDeviceService.class, mCarTrustedDeviceService);
Gregory Clarka440e812019-02-14 16:05:51 -0800184 CarLocalServices.addService(SystemInterface.class, mSystemInterface);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700185 CarLocalServices.addService(CarDrivingStateService.class, mCarDrivingStateService);
Gregory Clark55620c12019-06-03 17:42:58 -0700186 CarLocalServices.addService(PerUserCarServiceHelper.class, mPerUserCarServiceHelper);
Keun-young Parkd462a912019-02-11 08:53:42 -0800187
keunyounga3b28d82015-08-25 13:05:15 -0700188 // Be careful with order. Service depending on other service should be inited later.
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700189 List<CarServiceBase> allServices = new ArrayList<>();
Keun-young Parkd462a912019-02-11 08:53:42 -0800190 allServices.add(mCarUserService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700191 allServices.add(mSystemActivityMonitoringService);
192 allServices.add(mCarPowerManagementService);
193 allServices.add(mCarPropertyService);
194 allServices.add(mCarDrivingStateService);
Keun young Parkbb877e22019-08-02 10:38:01 -0700195 allServices.add(mCarOccupantZoneService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700196 allServices.add(mCarUXRestrictionsService);
197 allServices.add(mCarPackageManagerService);
198 allServices.add(mCarInputService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700199 allServices.add(mGarageModeService);
Keun young Park7af7d6c2019-09-12 10:31:48 -0700200 allServices.add(mCarUserNoticeService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700201 allServices.add(mAppFocusService);
202 allServices.add(mCarAudioService);
203 allServices.add(mCarNightService);
204 allServices.add(mInstrumentClusterService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700205 allServices.add(mSystemStateControllerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700206 allServices.add(mPerUserCarServiceHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800207 allServices.add(mCarBluetoothService);
208 allServices.add(mCarProjectionService);
209 allServices.add(mCarDiagnosticService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700210 allServices.add(mCarStorageMonitoringService);
211 allServices.add(mCarConfigurationService);
Mark Tabrya8fce562019-01-16 16:24:01 -0800212 allServices.add(mVmsClientManager);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700213 allServices.add(mVmsSubscriberService);
214 allServices.add(mVmsPublisherService);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700215 allServices.add(mCarTrustedDeviceService);
Simon Dai527eb552019-02-12 13:06:15 -0800216 allServices.add(mCarMediaService);
Gregory Clarka63ba022018-06-07 16:42:12 -0700217 allServices.add(mCarLocationService);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700218 allServices.add(mCarBugreportManagerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700219 mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]);
keunyoungca515072015-07-10 12:21:47 -0700220 }
221
Pavel Maltsevabd47232017-10-10 16:54:57 -0700222 @MainThread
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700223 void init() {
Serik Beketayev74debf22018-10-04 12:18:09 -0700224 mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL);
Steve Paikc302c7c2017-08-04 14:01:58 -0700225 traceBegin("VehicleHal.init");
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700226 mHal.init();
Steve Paikc302c7c2017-08-04 14:01:58 -0700227 traceEnd();
228 traceBegin("CarService.initAllServices");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800229 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700230 service.init();
231 }
Steve Paikc302c7c2017-08-04 14:01:58 -0700232 traceEnd();
keunyoungca515072015-07-10 12:21:47 -0700233 }
234
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700235 void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700236 // release done in opposite order from init
237 for (int i = mAllServices.length - 1; i >= 0; i--) {
238 mAllServices[i].release();
239 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700240 mHal.release();
Keun-young Parkd462a912019-02-11 08:53:42 -0800241 CarLocalServices.removeAllServices();
keunyoung1ab8e182015-09-24 09:25:22 -0700242 }
243
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700244 void vehicleHalReconnected(IVehicle vehicle) {
Pavel Maltsevec83b632017-01-05 15:10:55 -0800245 mHal.vehicleHalReconnected(vehicle);
246 for (CarServiceBase service : mAllServices) {
247 service.vehicleHalReconnected();
248 }
249 }
250
keunyoungca515072015-07-10 12:21:47 -0700251 @Override
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700252 public void setCarServiceHelper(IBinder helper) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700253 assertCallingFromSystemProcess();
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700254 synchronized (this) {
255 mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper);
Steve Paik0f9fc002018-02-09 17:42:00 -0800256 mSystemInterface.setCarServiceHelper(mICarServiceHelper);
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700257 }
258 }
259
260 @Override
Keun-young Parkd462a912019-02-11 08:53:42 -0800261 public void setUserLockStatus(int userHandle, int unlocked) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700262 assertCallingFromSystemProcess();
263 mCarUserService.setUserLockStatus(userHandle, unlocked == 1);
Yabin Huang27712d72019-06-26 12:46:30 -0700264 mCarMediaService.setUserLockStatus(userHandle, unlocked == 1);
Pavel Maltsev17e81832019-04-04 14:38:41 -0700265 }
266
267 @Override
268 public void onSwitchUser(int userHandle) {
269 assertCallingFromSystemProcess();
270
271 Log.i(TAG, "Foreground user switched to " + userHandle);
272 mCarUserService.onSwitchUser(userHandle);
273 }
274
Jim Kayee5133162019-04-22 12:50:27 -0700275 static void assertCallingFromSystemProcess() {
Keun-young Parkd462a912019-02-11 08:53:42 -0800276 int uid = Binder.getCallingUid();
277 if (uid != Process.SYSTEM_UID) {
278 throw new SecurityException("Only allowed from system");
279 }
Keun-young Parkd462a912019-02-11 08:53:42 -0800280 }
281
Keun young Parkaabecd92019-05-03 17:31:27 -0700282 /**
283 * Assert if binder call is coming from system process like system server or if it is called
284 * from its own process even if it is not system. The latter can happen in test environment.
285 * Note that car service runs as system user but test like car service test will not.
286 */
287 static void assertCallingFromSystemProcessOrSelf() {
288 int uid = Binder.getCallingUid();
289 int pid = Binder.getCallingPid();
290 if (uid != Process.SYSTEM_UID && pid != Process.myPid()) {
291 throw new SecurityException("Only allowed from system or self");
292 }
293 }
294
Keun-young Parkd462a912019-02-11 08:53:42 -0800295 @Override
keunyoungca515072015-07-10 12:21:47 -0700296 public IBinder getCarService(String serviceName) {
297 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800298 case Car.AUDIO_SERVICE:
299 return mCarAudioService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700300 case Car.APP_FOCUS_SERVICE:
301 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800302 case Car.PACKAGE_SERVICE:
303 return mCarPackageManagerService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800304 case Car.DIAGNOSTIC_SERVICE:
Enrico Granatab3634e22017-05-05 18:02:31 -0700305 assertAnyDiagnosticPermission(mContext);
306 return mCarDiagnosticService;
Steve Paik388d7772018-02-12 10:54:51 -0800307 case Car.POWER_SERVICE:
308 assertPowerPermission(mContext);
309 return mCarPowerManagementService;
Steve Paik9ec53d72018-04-27 13:28:31 -0700310 case Car.CABIN_SERVICE:
311 case Car.HVAC_SERVICE:
312 case Car.INFO_SERVICE:
313 case Car.PROPERTY_SERVICE:
314 case Car.SENSOR_SERVICE:
315 case Car.VENDOR_EXTENSION_SERVICE:
316 return mCarPropertyService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800317 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700318 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700319 IInstrumentClusterNavigation navService =
320 mInstrumentClusterService.getNavigationService();
321 return navService == null ? null : navService.asBinder();
Pavel Maltsev905968c2017-07-16 19:48:57 -0700322 case Car.CAR_INSTRUMENT_CLUSTER_SERVICE:
323 assertClusterManagerPermission(mContext);
324 return mInstrumentClusterService.getManagerService();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800325 case Car.PROJECTION_SERVICE:
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800326 return mCarProjectionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800327 case Car.VMS_SUBSCRIBER_SERVICE:
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700328 assertVmsSubscriberPermission(mContext);
329 return mVmsSubscriberService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800330 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700331 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700332 synchronized (this) {
333 if (mCarTestService == null) {
334 mCarTestService = new CarTestService(mContext, this);
335 }
336 return mCarTestService;
337 }
338 }
Ram Periathiruvadi76a84892017-07-27 18:10:35 -0700339 case Car.BLUETOOTH_SERVICE:
340 return mCarBluetoothService;
Enrico Granata9a916d72017-09-19 14:33:08 -0700341 case Car.STORAGE_MONITORING_SERVICE:
Enrico Granata1172f882017-09-21 14:51:30 -0700342 assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING);
Enrico Granata9a916d72017-09-19 14:33:08 -0700343 return mCarStorageMonitoringService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800344 case Car.CAR_DRIVING_STATE_SERVICE:
345 assertDrivingStatePermission(mContext);
346 return mCarDrivingStateService;
347 case Car.CAR_UX_RESTRICTION_SERVICE:
348 return mCarUXRestrictionsService;
Anthony Chend4203d82018-05-16 16:21:52 -0700349 case Car.CAR_CONFIGURATION_SERVICE:
350 return mCarConfigurationService;
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800351 case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE:
352 assertTrustAgentEnrollmentPermission(mContext);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700353 return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService();
Simon Dai527eb552019-02-12 13:06:15 -0800354 case Car.CAR_MEDIA_SERVICE:
355 return mCarMediaService;
Keun young Parkbb877e22019-08-02 10:38:01 -0700356 case Car.CAR_OCCUPANT_ZONE_SERVICE:
357 return mCarOccupantZoneService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700358 case Car.CAR_BUGREPORT_SERVICE:
359 return mCarBugreportManagerService;
keunyoungca515072015-07-10 12:21:47 -0700360 default:
361 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
362 return null;
363 }
364 }
365
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800366 @Override
367 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700368 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800369 }
370
Keun-young Parka28d7b22016-02-29 16:54:29 -0800371 public CarServiceBase getCarInternalService(String serviceName) {
372 switch (serviceName) {
373 case INTERNAL_INPUT_SERVICE:
374 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700375 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
376 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800377 default:
378 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
379 serviceName);
380 return null;
381 }
382 }
383
keunyoung1ab8e182015-09-24 09:25:22 -0700384 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700385 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700386 }
387
Keun-young Parke31a8b22016-03-16 17:34:08 -0700388 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700389 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800390 }
391
Pavel Maltsev905968c2017-07-16 19:48:57 -0700392 public static void assertClusterManagerPermission(Context context) {
393 assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL);
394 }
395
Steve Paik388d7772018-02-12 10:54:51 -0800396 public static void assertPowerPermission(Context context) {
397 assertPermission(context, Car.PERMISSION_CAR_POWER);
398 }
399
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800400 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700401 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
402 }
403
Pavel Maltsev079873b2019-02-25 12:15:09 -0800404 /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */
405 public static void assertProjectionStatusPermission(Context context) {
406 assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS);
407 }
408
Enrico Granata3c7a6662017-02-23 18:07:59 -0800409 public static void assertAnyDiagnosticPermission(Context context) {
410 assertAnyPermission(context,
Enrico Granataae25b922017-07-07 11:28:15 -0700411 Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL,
Enrico Granata3c7a6662017-02-23 18:07:59 -0800412 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
413 }
414
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800415 public static void assertDrivingStatePermission(Context context) {
416 assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE);
417 }
418
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800419 public static void assertVmsPublisherPermission(Context context) {
420 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
421 }
422
Antonio Cortese4619c72017-02-02 07:53:27 -0800423 public static void assertVmsSubscriberPermission(Context context) {
424 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
425 }
426
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800427 /**
428 * Ensures the caller has the permission to enroll a Trust Agent.
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800429 */
430 public static void assertTrustAgentEnrollmentPermission(Context context) {
431 assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST);
432 }
433
Steve Paik461ecc62016-06-08 15:28:32 -0700434 public static void assertPermission(Context context, String permission) {
435 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
436 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800437 }
438 }
439
Steve Paik9ec53d72018-04-27 13:28:31 -0700440 /**
441 * Checks to see if the caller has a permission.
Steve Paik9ec53d72018-04-27 13:28:31 -0700442 *
443 * @return boolean TRUE if caller has the permission.
444 */
445 public static boolean hasPermission(Context context, String permission) {
446 return context.checkCallingOrSelfPermission(permission)
447 == PackageManager.PERMISSION_GRANTED;
448 }
449
Enrico Granata3c7a6662017-02-23 18:07:59 -0800450 public static void assertAnyPermission(Context context, String... permissions) {
451 for (String permission : permissions) {
452 if (context.checkCallingOrSelfPermission(permission) ==
453 PackageManager.PERMISSION_GRANTED) {
454 return;
455 }
456 }
457 throw new SecurityException("requires any of " + Arrays.toString(permissions));
458 }
459
Enrico Granatae8056ca2018-04-03 13:19:52 -0700460 @Override
461 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
462 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Anthony Chen12aec302018-04-25 16:41:48 -0700463 != PackageManager.PERMISSION_GRANTED) {
Enrico Granatae8056ca2018-04-03 13:19:52 -0700464 writer.println("Permission Denial: can't dump CarService from from pid="
Anthony Chen12aec302018-04-25 16:41:48 -0700465 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
466 + " without permission " + android.Manifest.permission.DUMP);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700467 return;
keunyounga3b28d82015-08-25 13:05:15 -0700468 }
Enrico Granatae8056ca2018-04-03 13:19:52 -0700469
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700470 if (args == null || args.length == 0 || (args.length > 0 && "-a".equals(args[0]))) {
471 writer.println("*Dump car service*");
Enrico Granatae8056ca2018-04-03 13:19:52 -0700472 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
473 writer.println("*Dump all services*");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700474
475 dumpAllServices(writer, false);
476
Enrico Granatae8056ca2018-04-03 13:19:52 -0700477 writer.println("*Dump Vehicle HAL*");
478 writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName);
479 try {
480 // TODO dump all feature flags by creating a dumpable interface
481 mHal.dump(writer);
482 } catch (Exception e) {
483 writer.println("Failed dumping: " + mHal.getClass().getName());
484 e.printStackTrace(writer);
485 }
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700486 } else if ("--metrics".equals(args[0])) {
487 writer.println("*Dump car service metrics*");
488 dumpAllServices(writer, true);
Mark Tabryb588d2e2019-09-12 10:50:11 -0700489 } else if ("--vms-hal".equals(args[0])) {
490 mHal.getVmsHal().dumpMetrics(fd);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700491 } else if (Build.IS_USERDEBUG || Build.IS_ENG) {
492 execShellCmd(args, writer);
493 } else {
494 writer.println("Commands not supported in " + Build.TYPE);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800495 }
496 }
497
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700498 private void dumpAllServices(PrintWriter writer, boolean dumpMetricsOnly) {
499 for (CarServiceBase service : mAllServices) {
500 dumpService(service, writer, dumpMetricsOnly);
501 }
502 if (mCarTestService != null) {
503 dumpService(mCarTestService, writer, dumpMetricsOnly);
504 }
505
506 }
507
508 private void dumpService(CarServiceBase service, PrintWriter writer, boolean dumpMetricsOnly) {
Brad Stenninged3d59b2017-11-09 16:15:17 -0800509 try {
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700510 if (dumpMetricsOnly) {
511 service.dumpMetrics(writer);
512 } else {
513 service.dump(writer);
514 }
Brad Stenninged3d59b2017-11-09 16:15:17 -0800515 } catch (Exception e) {
516 writer.println("Failed dumping: " + service.getClass().getName());
517 e.printStackTrace(writer);
518 }
keunyoungcc449f72015-08-12 10:46:27 -0700519 }
Yao Chene33f07e2016-07-26 12:02:51 -0700520
521 void execShellCmd(String[] args, PrintWriter writer) {
522 new CarShellCommand().exec(args, writer);
523 }
524
Pavel Maltsevabd47232017-10-10 16:54:57 -0700525 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700526 private void traceBegin(String name) {
Steve Paikc302c7c2017-08-04 14:01:58 -0700527 Slog.i(TAG, name);
528 mBootTiming.traceBegin(name);
529 }
530
Pavel Maltsevabd47232017-10-10 16:54:57 -0700531 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700532 private void traceEnd() {
Steve Paikc302c7c2017-08-04 14:01:58 -0700533 mBootTiming.traceEnd();
534 }
535
Yao Chene33f07e2016-07-26 12:02:51 -0700536 private class CarShellCommand {
537 private static final String COMMAND_HELP = "-h";
538 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800539 private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event";
Kai4b098cf2019-06-05 15:03:28 -0700540 private static final String COMMAND_INJECT_ERROR_EVENT = "inject-error-event";
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800541 private static final String COMMAND_ENABLE_UXR = "enable-uxr";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800542 private static final String COMMAND_GARAGE_MODE = "garage-mode";
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800543 private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities";
Kaidd4ef5a2019-03-04 14:07:26 -0800544 private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig";
Kai29fba112019-04-22 18:37:38 -0700545 private static final String COMMAND_GET_PROPERTY_VALUE = "get-property-value";
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700546 private static final String COMMAND_PROJECTION_AP_TETHERING = "projection-tethering";
Pavel Maltsev48a31942019-03-03 22:08:28 -0800547 private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode";
Jim Kayed76c2742019-04-02 11:33:27 -0700548 private static final String COMMAND_RESUME = "resume";
549 private static final String COMMAND_SUSPEND = "suspend";
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700550 private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device";
551 private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices";
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700552 private static final String COMMAND_SET_UID_TO_ZONE = "set-zoneid-for-uid";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800553
Yao Chene33f07e2016-07-26 12:02:51 -0700554 private static final String PARAM_DAY_MODE = "day";
555 private static final String PARAM_NIGHT_MODE = "night";
556 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800557 private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800558 private static final String PARAM_ON_MODE = "on";
559 private static final String PARAM_OFF_MODE = "off";
560 private static final String PARAM_QUERY_MODE = "query";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800561
Yao Chene33f07e2016-07-26 12:02:51 -0700562
563 private void dumpHelp(PrintWriter pw) {
564 pw.println("Car service commands:");
565 pw.println("\t-h");
566 pw.println("\t Print this help text.");
567 pw.println("\tday-night-mode [day|night|sensor]");
568 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800569 pw.println("\tinject-vhal-event property [zone] data(can be comma separated list)");
Jim Kayef10b7d82019-02-26 12:53:22 -0800570 pw.println("\t Inject a vehicle property for testing.");
Kai4b098cf2019-06-05 15:03:28 -0700571 pw.println("\tinject-error-event property zone errorCode");
572 pw.println("\t Inject an error event from VHAL for testing.");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700573 pw.println("\tenable-uxr true|false");
574 pw.println("\t Enable/Disable UX restrictions and App blocking.");
Bryan Eylera32a7c12018-02-27 15:40:00 -0800575 pw.println("\tgarage-mode [on|off|query]");
576 pw.println("\t Force into garage mode or check status.");
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800577 pw.println("\tget-do-activities pkgname");
Jim Kayef10b7d82019-02-26 12:53:22 -0800578 pw.println("\t Get Distraction Optimized activities in given package.");
Kaidd4ef5a2019-03-04 14:07:26 -0800579 pw.println("\tget-carpropertyconfig [propertyId]");
580 pw.println("\t Get a CarPropertyConfig by Id in Hex or list all CarPropertyConfigs");
Kai29fba112019-04-22 18:37:38 -0700581 pw.println("\tget-property-value [propertyId] [areaId]");
582 pw.println("\t Get a vehicle property value by property id in Hex and areaId");
583 pw.println("\t or list all property values for all areaId");
Jim Kayed76c2742019-04-02 11:33:27 -0700584 pw.println("\tsuspend");
585 pw.println("\t Suspend the system to Deep Sleep.");
586 pw.println("\tresume");
587 pw.println("\t Wake the system up after a 'suspend.'");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700588 pw.println("\tenable-trusted-device true|false");
589 pw.println("\t Enable/Disable Trusted device feature.");
590 pw.println("\tremove-trusted-devices");
591 pw.println("\t Remove all trusted devices for the current foreground user.");
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700592 pw.println("\tprojection-tethering [true|false]");
593 pw.println("\t Whether tethering should be used when creating access point for"
594 + " wireless projection");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700595 pw.println("\t--metrics");
596 pw.println("\t When used with dumpsys, only metrics will be in the dumpsys output.");
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700597 pw.println("\tset-zoneid-for-uid [zoneid] [uid]");
598 pw.println("\t Maps the audio zoneid to uid.");
599 }
600
601 private String runSetZoneIdForUid(String zoneString, String uidString) {
602 int uid = Integer.parseInt(uidString);
603 int zoneId = Integer.parseInt(zoneString);
604 if (!ArrayUtils.contains(mCarAudioService.getAudioZoneIds(), zoneId)) {
605 return "zoneid " + zoneId + " not found";
606 }
607 mCarAudioService.setZoneIdForUid(zoneId, uid);
608 return null;
Yao Chene33f07e2016-07-26 12:02:51 -0700609 }
610
611 public void exec(String[] args, PrintWriter writer) {
612 String arg = args[0];
613 switch (arg) {
614 case COMMAND_HELP:
615 dumpHelp(writer);
616 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800617 case COMMAND_DAY_NIGHT_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800618 String value = args.length < 2 ? "" : args[1];
Yao Chene33f07e2016-07-26 12:02:51 -0700619 forceDayNightMode(value, writer);
620 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800621 }
622 case COMMAND_GARAGE_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800623 String value = args.length < 2 ? "" : args[1];
Bryan Eylera32a7c12018-02-27 15:40:00 -0800624 forceGarageMode(value, writer);
625 break;
626 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800627 case COMMAND_INJECT_VHAL_EVENT:
628 String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL;
629 String data;
Jim Kayef10b7d82019-02-26 12:53:22 -0800630 if (args.length != 3 && args.length != 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800631 writer.println("Incorrect number of arguments.");
632 dumpHelp(writer);
633 break;
Jim Kayef10b7d82019-02-26 12:53:22 -0800634 } else if (args.length == 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800635 // Zoned
636 zone = args[2];
637 data = args[3];
638 } else {
639 // Global
640 data = args[2];
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800641 }
Kai4b098cf2019-06-05 15:03:28 -0700642 injectVhalEvent(args[1], zone, data, false, writer);
643 break;
644 case COMMAND_INJECT_ERROR_EVENT:
645 if (args.length != 4) {
646 writer.println("Incorrect number of arguments");
647 dumpHelp(writer);
648 break;
649 }
650 String errorAreaId = args[2];
651 String errorCode = args[3];
652 injectVhalEvent(args[1], errorAreaId, errorCode, true, writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800653 break;
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800654 case COMMAND_ENABLE_UXR:
Jim Kayef10b7d82019-02-26 12:53:22 -0800655 if (args.length != 2) {
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800656 writer.println("Incorrect number of arguments");
657 dumpHelp(writer);
658 break;
659 }
660 boolean enableBlocking = Boolean.valueOf(args[1]);
661 if (mCarPackageManagerService != null) {
662 mCarPackageManagerService.setEnableActivityBlocking(enableBlocking);
663 }
664 break;
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800665 case COMMAND_GET_DO_ACTIVITIES:
Jim Kayef10b7d82019-02-26 12:53:22 -0800666 if (args.length != 2) {
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800667 writer.println("Incorrect number of arguments");
668 dumpHelp(writer);
669 break;
670 }
671 String pkgName = args[1].toLowerCase();
672 if (mCarPackageManagerService != null) {
673 String[] doActivities =
674 mCarPackageManagerService.getDistractionOptimizedActivities(
675 pkgName);
676 if (doActivities != null) {
677 writer.println("DO Activities for " + pkgName);
678 for (String a : doActivities) {
679 writer.println(a);
680 }
681 } else {
682 writer.println("No DO Activities for " + pkgName);
683 }
684 }
685 break;
Kaidd4ef5a2019-03-04 14:07:26 -0800686 case COMMAND_GET_CARPROPERTYCONFIG:
687 String propertyId = args.length < 2 ? "" : args[1];
688 mHal.dumpPropertyConfigs(writer, propertyId);
689 break;
Kai29fba112019-04-22 18:37:38 -0700690 case COMMAND_GET_PROPERTY_VALUE:
691 String propId = args.length < 2 ? "" : args[1];
692 String areaId = args.length < 3 ? "" : args[2];
693 mHal.dumpPropertyValueByCommend(writer, propId, areaId);
694 break;
Pavel Maltsev48a31942019-03-03 22:08:28 -0800695 case COMMAND_PROJECTION_UI_MODE:
696 if (args.length != 2) {
697 writer.println("Incorrect number of arguments");
698 dumpHelp(writer);
699 break;
700 }
701 mCarProjectionService.setUiMode(Integer.valueOf(args[1]));
Pavel Maltsevd6961f62019-03-26 10:22:31 -0700702 break;
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700703 case COMMAND_PROJECTION_AP_TETHERING:
704 if (args.length != 2) {
705 writer.println("Incorrect number of arguments");
706 dumpHelp(writer);
707 break;
708 }
709 mCarProjectionService.setAccessPointTethering(Boolean.valueOf(args[1]));
710 break;
Jim Kayed76c2742019-04-02 11:33:27 -0700711 case COMMAND_RESUME:
712 mCarPowerManagementService.forceSimulatedResume();
713 writer.println("Resume: Simulating resuming from Deep Sleep");
714 break;
715 case COMMAND_SUSPEND:
716 mCarPowerManagementService.forceSimulatedSuspend();
717 writer.println("Resume: Simulating powering down to Deep Sleep");
718 break;
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700719 case COMMAND_ENABLE_TRUSTED_DEVICE:
720 if (args.length != 2) {
721 writer.println("Incorrect number of arguments");
722 dumpHelp(writer);
723 break;
724 }
725 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
726 .setTrustedDeviceEnrollmentEnabled(Boolean.valueOf(args[1]));
727 mCarTrustedDeviceService.getCarTrustAgentUnlockService()
728 .setTrustedDeviceUnlockEnabled(Boolean.valueOf(args[1]));
729 break;
730 case COMMAND_REMOVE_TRUSTED_DEVICES:
731 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
732 .removeAllTrustedDevices(
733 mUserManagerHelper.getCurrentForegroundUserId());
734 break;
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700735 case COMMAND_SET_UID_TO_ZONE:
736 if (args.length != 3) {
737 writer.println("Incorrect number of arguments");
738 dumpHelp(writer);
739 break;
740 }
741 String results = runSetZoneIdForUid(args[1], args[2]);
742 if (results != null) {
743 writer.println(results);
744 dumpHelp(writer);
745 }
746 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700747 default:
Jim Kayef10b7d82019-02-26 12:53:22 -0800748 writer.println("Unknown command: \"" + arg + "\"");
Yao Chene33f07e2016-07-26 12:02:51 -0700749 dumpHelp(writer);
750 }
751 }
752
753 private void forceDayNightMode(String arg, PrintWriter writer) {
754 int mode;
755 switch (arg) {
756 case PARAM_DAY_MODE:
757 mode = CarNightService.FORCED_DAY_MODE;
758 break;
759 case PARAM_NIGHT_MODE:
760 mode = CarNightService.FORCED_NIGHT_MODE;
761 break;
762 case PARAM_SENSOR_MODE:
763 mode = CarNightService.FORCED_SENSOR_MODE;
764 break;
765 default:
766 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
767 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
768 return;
769 }
770 int current = mCarNightService.forceDayNightMode(mode);
771 String currentMode = null;
772 switch (current) {
773 case UiModeManager.MODE_NIGHT_AUTO:
774 currentMode = PARAM_SENSOR_MODE;
775 break;
776 case UiModeManager.MODE_NIGHT_YES:
777 currentMode = PARAM_NIGHT_MODE;
778 break;
779 case UiModeManager.MODE_NIGHT_NO:
780 currentMode = PARAM_DAY_MODE;
781 break;
782 }
783 writer.println("DayNightMode changed to: " + currentMode);
784 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800785
Bryan Eylera32a7c12018-02-27 15:40:00 -0800786 private void forceGarageMode(String arg, PrintWriter writer) {
787 switch (arg) {
788 case PARAM_ON_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700789 mGarageModeService.forceStartGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -0700790 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -0800791 break;
792 case PARAM_OFF_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700793 mGarageModeService.stopAndResetGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -0700794 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -0800795 break;
796 case PARAM_QUERY_MODE:
Jim Kaye1b5e6182019-05-24 15:48:32 -0700797 mGarageModeService.dump(writer);
Bryan Eylera32a7c12018-02-27 15:40:00 -0800798 break;
799 default:
800 writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|"
801 + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE);
Bryan Eylera32a7c12018-02-27 15:40:00 -0800802 }
Bryan Eylera32a7c12018-02-27 15:40:00 -0800803 }
804
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800805 /**
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800806 * Inject a fake VHAL event
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800807 *
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800808 * @param property the Vehicle property Id as defined in the HAL
809 * @param zone Zone that this event services
Kai4b098cf2019-06-05 15:03:28 -0700810 * @param isErrorEvent indicates the type of event
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800811 * @param value Data value of the event
812 * @param writer PrintWriter
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800813 */
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800814 private void injectVhalEvent(String property, String zone, String value,
Kai4b098cf2019-06-05 15:03:28 -0700815 boolean isErrorEvent, PrintWriter writer) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800816 if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) {
817 if (!isPropertyAreaTypeGlobal(property)) {
818 writer.println("Property area type inconsistent with given zone");
819 return;
820 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800821 }
822 try {
Kai4b098cf2019-06-05 15:03:28 -0700823 if (isErrorEvent) {
824 mHal.injectOnPropertySetError(property, zone, value);
825 } else {
826 mHal.injectVhalEvent(property, zone, value);
827 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800828 } catch (NumberFormatException e) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800829 writer.println("Invalid property Id zone Id or value" + e);
830 dumpHelp(writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800831 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800832 }
833
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800834 // Check if the given property is global
835 private boolean isPropertyAreaTypeGlobal(String property) {
836 if (property == null) {
837 return false;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800838 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800839 return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800840 }
Yao Chene33f07e2016-07-26 12:02:51 -0700841 }
kevinjm55822c42018-08-15 11:26:00 -0700842}