blob: a3090a24b3ab5eaf5744e73ebd4ab1f481365069 [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;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070049import com.android.car.user.CarUserService;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080050import com.android.car.vms.VmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -080051import com.android.car.vms.VmsClientManager;
keunyoungca515072015-07-10 12:21:47 -070052import com.android.internal.annotations.GuardedBy;
Steve Paik1d8bea22018-02-03 01:54:06 +000053import com.android.internal.car.ICarServiceHelper;
Oscar Azucena3f3a25e2019-07-12 14:28:24 -070054import com.android.internal.util.ArrayUtils;
Gregory Clark26fa6012018-03-14 18:38:56 -070055
Enrico Granatae8056ca2018-04-03 13:19:52 -070056import java.io.FileDescriptor;
keunyounga3b28d82015-08-25 13:05:15 -070057import java.io.PrintWriter;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070058import java.util.ArrayList;
Antonio Cortese4619c72017-02-02 07:53:27 -080059import java.util.Arrays;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070060import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070061
keunyoungca515072015-07-10 12:21:47 -070062public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070063
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -080064 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070065 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
66 "system_activity_monitoring";
Keun-young Parka28d7b22016-02-29 16:54:29 -080067
keunyoungca515072015-07-10 12:21:47 -070068 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080069 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070070
Anthony Chen12aec302018-04-25 16:41:48 -070071 private final SystemInterface mSystemInterface;
72
Keun-young Park4727da32016-05-31 10:00:51 -070073 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070074 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080075 private final CarPackageManagerService mCarPackageManagerService;
76 private final CarInputService mCarInputService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -080077 private final CarDrivingStateService mCarDrivingStateService;
Ram Periathiruvadi4526a432018-01-24 13:00:54 -080078 private final CarUxRestrictionsManagerService mCarUXRestrictionsService;
keunyoungd32f4e62015-09-21 11:33:06 -070079 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080080 private final CarProjectionService mCarProjectionService;
Steve Paik9ec53d72018-04-27 13:28:31 -070081 private final CarPropertyService mCarPropertyService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080082 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070083 private final AppFocusService mAppFocusService;
Yao Chen3a7976d2016-01-20 17:27:08 -080084 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080085 private final InstrumentClusterService mInstrumentClusterService;
Gregory Clarkd8136062017-12-11 14:27:53 -080086 private final CarLocationService mCarLocationService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070087 private final SystemStateControllerService mSystemStateControllerService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080088 private final CarBluetoothService mCarBluetoothService;
Ram Periathiruvadiacb60242017-04-13 16:19:09 -070089 private final PerUserCarServiceHelper mPerUserCarServiceHelper;
Enrico Granata9a916d72017-09-19 14:33:08 -070090 private final CarDiagnosticService mCarDiagnosticService;
91 private final CarStorageMonitoringService mCarStorageMonitoringService;
Anthony Chen12aec302018-04-25 16:41:48 -070092 private final CarConfigurationService mCarConfigurationService;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070093 private final CarTrustedDeviceService mCarTrustedDeviceService;
Simon Dai527eb552019-02-12 13:06:15 -080094 private final CarMediaService mCarMediaService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070095 private final CarUserManagerHelper mUserManagerHelper;
Keun-young Parkd462a912019-02-11 08:53:42 -080096 private final CarUserService mCarUserService;
Keun young Parkbb877e22019-08-02 10:38:01 -070097 private final CarOccupantZoneService mCarOccupantZoneService;
Mark Tabrya8fce562019-01-16 16:24:01 -080098 private final VmsClientManager mVmsClientManager;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080099 private final VmsBrokerService mVmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -0800100 private final VmsSubscriberService mVmsSubscriberService;
101 private final VmsPublisherService mVmsPublisherService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700102 private final CarBugreportManagerService mCarBugreportManagerService;
keunyounga74b9ca2015-10-21 13:33:58 -0700103
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700104 private final CarServiceBase[] mAllServices;
105
Steve Paikc302c7c2017-08-04 14:01:58 -0700106 private static final String TAG = "ICarImpl";
107 private static final String VHAL_TIMING_TAG = "VehicleHalTiming";
Serik Beketayev74debf22018-10-04 12:18:09 -0700108
109 private TimingsTraceLog mBootTiming;
Steve Paikc302c7c2017-08-04 14:01:58 -0700110
keunyoung1ab8e182015-09-24 09:25:22 -0700111 /** Test only service. Populate it only when necessary. */
112 @GuardedBy("this")
113 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -0700114
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700115 @GuardedBy("this")
116 private ICarServiceHelper mICarServiceHelper;
117
Enrico Granatae8056ca2018-04-03 13:19:52 -0700118 private final String mVehicleInterfaceName;
119
Pavel Maltsevec83b632017-01-05 15:10:55 -0800120 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
Enrico Granatae8056ca2018-04-03 13:19:52 -0700121 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) {
keunyoungca515072015-07-10 12:21:47 -0700122 mContext = serviceContext;
Steve Paik0f9fc002018-02-09 17:42:00 -0800123 mSystemInterface = systemInterface;
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700124 mHal = new VehicleHal(vehicle);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700125 mVehicleInterfaceName = vehicleInterfaceName;
Yao, Yuxing0811d5a2018-11-29 16:18:53 -0800126 mUserManagerHelper = new CarUserManagerHelper(serviceContext);
Anthony Hugh9932a252019-06-12 16:19:56 -0700127 UserManager userManager =
128 (UserManager) serviceContext.getSystemService(Context.USER_SERVICE);
Keun young Parkf3523cd2019-04-08 10:09:17 -0700129 final Resources res = mContext.getResources();
130 final int maxRunningUsers = res.getInteger(
131 com.android.internal.R.integer.config_multiuserMaxRunningUsers);
Anthony Hugh9932a252019-06-12 16:19:56 -0700132 mCarUserService = new CarUserService(serviceContext, mUserManagerHelper, userManager,
Keun young Parkf3523cd2019-04-08 10:09:17 -0700133 ActivityManager.getService(), maxRunningUsers);
Keun young Parkbb877e22019-08-02 10:38:01 -0700134 mCarOccupantZoneService = new CarOccupantZoneService(serviceContext);
Keun-young Park4727da32016-05-31 10:00:51 -0700135 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Steve Paik388d7772018-02-12 10:54:51 -0800136 mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(),
Keun young Park9b3f2662019-03-19 10:30:25 -0700137 systemInterface, mUserManagerHelper);
Steve Paik9ec53d72018-04-27 13:28:31 -0700138 mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal());
139 mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService);
Ram Periathiruvadi4526a432018-01-24 13:00:54 -0800140 mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext,
Yao, Yuxing9bfb7492019-02-15 11:53:34 -0800141 mCarDrivingStateService, mCarPropertyService);
Ram Periathiruvadi2da6d0e2018-01-26 18:02:10 -0800142 mCarPackageManagerService = new CarPackageManagerService(serviceContext,
143 mCarUXRestrictionsService,
Pavel Maltsev38da4312019-04-08 10:38:38 -0700144 mSystemActivityMonitoringService,
145 mUserManagerHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800146 mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext);
Sal Savage703c46f2019-04-15 08:39:25 -0700147 mCarBluetoothService = new CarBluetoothService(serviceContext, mPerUserCarServiceHelper);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700148 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Justin Paupore44985ba2019-01-30 18:53:41 -0800149 mCarProjectionService = new CarProjectionService(
Pavel Maltsev079873b2019-02-25 12:15:09 -0800150 serviceContext, null /* handler */, mCarInputService, mCarBluetoothService);
Serik Beketayevc6ab8be2018-08-28 21:20:53 -0700151 mGarageModeService = new GarageModeService(mContext);
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700152 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Hongwei Wang30557232018-01-02 10:25:08 -0800153 mCarAudioService = new CarAudioService(serviceContext);
Steve Paik9ec53d72018-04-27 13:28:31 -0700154 mCarNightService = new CarNightService(serviceContext, mCarPropertyService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700155 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700156 mAppFocusService, mCarInputService);
Serik Beketayevf9f2ef02018-09-06 12:37:02 -0700157 mSystemStateControllerService = new SystemStateControllerService(
158 serviceContext, mCarAudioService, this);
Andrew T Nguyen0d4a36f2019-05-03 15:41:23 -0700159 mVmsBrokerService = new VmsBrokerService(mContext.getPackageManager());
Mark Tabry1534c062019-03-29 01:30:49 -0700160 mVmsClientManager = new VmsClientManager(
Mark Tabry41437562019-04-04 10:37:33 -0700161 serviceContext, mCarUserService, mUserManagerHelper, mHal.getVmsHal());
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800162 mVmsSubscriberService = new VmsSubscriberService(
163 serviceContext, mVmsBrokerService, mHal.getVmsHal());
164 mVmsPublisherService = new VmsPublisherService(
Mark Tabry1534c062019-03-29 01:30:49 -0700165 serviceContext, mVmsBrokerService, mVmsClientManager);
Enrico Granatab3634e22017-05-05 18:02:31 -0700166 mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal());
Enrico Granata517a1e02017-09-20 16:15:50 -0700167 mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext,
168 systemInterface);
Anthony Chen12aec302018-04-25 16:41:48 -0700169 mCarConfigurationService =
170 new CarConfigurationService(serviceContext, new JsonReaderImpl());
Gregory Clarke1519532019-05-10 16:25:57 -0700171 mCarLocationService = new CarLocationService(mContext, mUserManagerHelper);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700172 mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext);
Simon Dai527eb552019-02-12 13:06:15 -0800173 mCarMediaService = new CarMediaService(serviceContext);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700174 mCarBugreportManagerService = new CarBugreportManagerService(serviceContext);
keunyounga74b9ca2015-10-21 13:33:58 -0700175
Keun young Parka5fa4782019-04-16 18:56:27 -0700176 CarLocalServices.addService(CarPowerManagementService.class, mCarPowerManagementService);
Keun young Parkbb877e22019-08-02 10:38:01 -0700177 CarLocalServices.addService(CarPropertyService.class, mCarPropertyService);
Keun-young Parkd462a912019-02-11 08:53:42 -0800178 CarLocalServices.addService(CarUserService.class, mCarUserService);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700179 CarLocalServices.addService(CarTrustedDeviceService.class, mCarTrustedDeviceService);
Gregory Clarka440e812019-02-14 16:05:51 -0800180 CarLocalServices.addService(SystemInterface.class, mSystemInterface);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700181 CarLocalServices.addService(CarDrivingStateService.class, mCarDrivingStateService);
Gregory Clark55620c12019-06-03 17:42:58 -0700182 CarLocalServices.addService(PerUserCarServiceHelper.class, mPerUserCarServiceHelper);
Keun-young Parkd462a912019-02-11 08:53:42 -0800183
keunyounga3b28d82015-08-25 13:05:15 -0700184 // Be careful with order. Service depending on other service should be inited later.
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700185 List<CarServiceBase> allServices = new ArrayList<>();
Keun-young Parkd462a912019-02-11 08:53:42 -0800186 allServices.add(mCarUserService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700187 allServices.add(mSystemActivityMonitoringService);
188 allServices.add(mCarPowerManagementService);
189 allServices.add(mCarPropertyService);
190 allServices.add(mCarDrivingStateService);
Keun young Parkbb877e22019-08-02 10:38:01 -0700191 allServices.add(mCarOccupantZoneService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700192 allServices.add(mCarUXRestrictionsService);
193 allServices.add(mCarPackageManagerService);
194 allServices.add(mCarInputService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700195 allServices.add(mGarageModeService);
196 allServices.add(mAppFocusService);
197 allServices.add(mCarAudioService);
198 allServices.add(mCarNightService);
199 allServices.add(mInstrumentClusterService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700200 allServices.add(mSystemStateControllerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700201 allServices.add(mPerUserCarServiceHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800202 allServices.add(mCarBluetoothService);
203 allServices.add(mCarProjectionService);
204 allServices.add(mCarDiagnosticService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700205 allServices.add(mCarStorageMonitoringService);
206 allServices.add(mCarConfigurationService);
Mark Tabrya8fce562019-01-16 16:24:01 -0800207 allServices.add(mVmsClientManager);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700208 allServices.add(mVmsSubscriberService);
209 allServices.add(mVmsPublisherService);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700210 allServices.add(mCarTrustedDeviceService);
Simon Dai527eb552019-02-12 13:06:15 -0800211 allServices.add(mCarMediaService);
Gregory Clarka63ba022018-06-07 16:42:12 -0700212 allServices.add(mCarLocationService);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700213 allServices.add(mCarBugreportManagerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700214 mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]);
keunyoungca515072015-07-10 12:21:47 -0700215 }
216
Pavel Maltsevabd47232017-10-10 16:54:57 -0700217 @MainThread
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700218 void init() {
Serik Beketayev74debf22018-10-04 12:18:09 -0700219 mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL);
Steve Paikc302c7c2017-08-04 14:01:58 -0700220 traceBegin("VehicleHal.init");
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700221 mHal.init();
Steve Paikc302c7c2017-08-04 14:01:58 -0700222 traceEnd();
223 traceBegin("CarService.initAllServices");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800224 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700225 service.init();
226 }
Steve Paikc302c7c2017-08-04 14:01:58 -0700227 traceEnd();
Keun young Parkfd2afc92019-06-07 14:55:20 -0700228 mSystemInterface.reconfigureSecondaryDisplays();
keunyoungca515072015-07-10 12:21:47 -0700229 }
230
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700231 void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700232 // release done in opposite order from init
233 for (int i = mAllServices.length - 1; i >= 0; i--) {
234 mAllServices[i].release();
235 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700236 mHal.release();
Keun-young Parkd462a912019-02-11 08:53:42 -0800237 CarLocalServices.removeAllServices();
keunyoung1ab8e182015-09-24 09:25:22 -0700238 }
239
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700240 void vehicleHalReconnected(IVehicle vehicle) {
Pavel Maltsevec83b632017-01-05 15:10:55 -0800241 mHal.vehicleHalReconnected(vehicle);
242 for (CarServiceBase service : mAllServices) {
243 service.vehicleHalReconnected();
244 }
245 }
246
keunyoungca515072015-07-10 12:21:47 -0700247 @Override
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700248 public void setCarServiceHelper(IBinder helper) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700249 assertCallingFromSystemProcess();
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700250 synchronized (this) {
251 mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper);
Steve Paik0f9fc002018-02-09 17:42:00 -0800252 mSystemInterface.setCarServiceHelper(mICarServiceHelper);
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700253 }
254 }
255
256 @Override
Keun-young Parkd462a912019-02-11 08:53:42 -0800257 public void setUserLockStatus(int userHandle, int unlocked) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700258 assertCallingFromSystemProcess();
259 mCarUserService.setUserLockStatus(userHandle, unlocked == 1);
Yabin Huang27712d72019-06-26 12:46:30 -0700260 mCarMediaService.setUserLockStatus(userHandle, unlocked == 1);
Pavel Maltsev17e81832019-04-04 14:38:41 -0700261 }
262
263 @Override
264 public void onSwitchUser(int userHandle) {
265 assertCallingFromSystemProcess();
266
267 Log.i(TAG, "Foreground user switched to " + userHandle);
268 mCarUserService.onSwitchUser(userHandle);
269 }
270
Jim Kayee5133162019-04-22 12:50:27 -0700271 static void assertCallingFromSystemProcess() {
Keun-young Parkd462a912019-02-11 08:53:42 -0800272 int uid = Binder.getCallingUid();
273 if (uid != Process.SYSTEM_UID) {
274 throw new SecurityException("Only allowed from system");
275 }
Keun-young Parkd462a912019-02-11 08:53:42 -0800276 }
277
Keun young Parkaabecd92019-05-03 17:31:27 -0700278 /**
279 * Assert if binder call is coming from system process like system server or if it is called
280 * from its own process even if it is not system. The latter can happen in test environment.
281 * Note that car service runs as system user but test like car service test will not.
282 */
283 static void assertCallingFromSystemProcessOrSelf() {
284 int uid = Binder.getCallingUid();
285 int pid = Binder.getCallingPid();
286 if (uid != Process.SYSTEM_UID && pid != Process.myPid()) {
287 throw new SecurityException("Only allowed from system or self");
288 }
289 }
290
Keun-young Parkd462a912019-02-11 08:53:42 -0800291 @Override
keunyoungca515072015-07-10 12:21:47 -0700292 public IBinder getCarService(String serviceName) {
293 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800294 case Car.AUDIO_SERVICE:
295 return mCarAudioService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700296 case Car.APP_FOCUS_SERVICE:
297 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800298 case Car.PACKAGE_SERVICE:
299 return mCarPackageManagerService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800300 case Car.DIAGNOSTIC_SERVICE:
Enrico Granatab3634e22017-05-05 18:02:31 -0700301 assertAnyDiagnosticPermission(mContext);
302 return mCarDiagnosticService;
Steve Paik388d7772018-02-12 10:54:51 -0800303 case Car.POWER_SERVICE:
304 assertPowerPermission(mContext);
305 return mCarPowerManagementService;
Steve Paik9ec53d72018-04-27 13:28:31 -0700306 case Car.CABIN_SERVICE:
307 case Car.HVAC_SERVICE:
308 case Car.INFO_SERVICE:
309 case Car.PROPERTY_SERVICE:
310 case Car.SENSOR_SERVICE:
311 case Car.VENDOR_EXTENSION_SERVICE:
312 return mCarPropertyService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800313 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700314 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700315 IInstrumentClusterNavigation navService =
316 mInstrumentClusterService.getNavigationService();
317 return navService == null ? null : navService.asBinder();
Pavel Maltsev905968c2017-07-16 19:48:57 -0700318 case Car.CAR_INSTRUMENT_CLUSTER_SERVICE:
319 assertClusterManagerPermission(mContext);
320 return mInstrumentClusterService.getManagerService();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800321 case Car.PROJECTION_SERVICE:
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800322 return mCarProjectionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800323 case Car.VMS_SUBSCRIBER_SERVICE:
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700324 assertVmsSubscriberPermission(mContext);
325 return mVmsSubscriberService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800326 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700327 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700328 synchronized (this) {
329 if (mCarTestService == null) {
330 mCarTestService = new CarTestService(mContext, this);
331 }
332 return mCarTestService;
333 }
334 }
Ram Periathiruvadi76a84892017-07-27 18:10:35 -0700335 case Car.BLUETOOTH_SERVICE:
336 return mCarBluetoothService;
Enrico Granata9a916d72017-09-19 14:33:08 -0700337 case Car.STORAGE_MONITORING_SERVICE:
Enrico Granata1172f882017-09-21 14:51:30 -0700338 assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING);
Enrico Granata9a916d72017-09-19 14:33:08 -0700339 return mCarStorageMonitoringService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800340 case Car.CAR_DRIVING_STATE_SERVICE:
341 assertDrivingStatePermission(mContext);
342 return mCarDrivingStateService;
343 case Car.CAR_UX_RESTRICTION_SERVICE:
344 return mCarUXRestrictionsService;
Anthony Chend4203d82018-05-16 16:21:52 -0700345 case Car.CAR_CONFIGURATION_SERVICE:
346 return mCarConfigurationService;
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800347 case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE:
348 assertTrustAgentEnrollmentPermission(mContext);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700349 return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService();
Simon Dai527eb552019-02-12 13:06:15 -0800350 case Car.CAR_MEDIA_SERVICE:
351 return mCarMediaService;
Keun young Parkbb877e22019-08-02 10:38:01 -0700352 case Car.CAR_OCCUPANT_ZONE_SERVICE:
353 return mCarOccupantZoneService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700354 case Car.CAR_BUGREPORT_SERVICE:
355 return mCarBugreportManagerService;
keunyoungca515072015-07-10 12:21:47 -0700356 default:
357 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
358 return null;
359 }
360 }
361
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800362 @Override
363 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700364 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800365 }
366
Keun-young Parka28d7b22016-02-29 16:54:29 -0800367 public CarServiceBase getCarInternalService(String serviceName) {
368 switch (serviceName) {
369 case INTERNAL_INPUT_SERVICE:
370 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700371 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
372 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800373 default:
374 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
375 serviceName);
376 return null;
377 }
378 }
379
keunyoung1ab8e182015-09-24 09:25:22 -0700380 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700381 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700382 }
383
Keun-young Parke31a8b22016-03-16 17:34:08 -0700384 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700385 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800386 }
387
Pavel Maltsev905968c2017-07-16 19:48:57 -0700388 public static void assertClusterManagerPermission(Context context) {
389 assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL);
390 }
391
Steve Paik388d7772018-02-12 10:54:51 -0800392 public static void assertPowerPermission(Context context) {
393 assertPermission(context, Car.PERMISSION_CAR_POWER);
394 }
395
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800396 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700397 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
398 }
399
Pavel Maltsev079873b2019-02-25 12:15:09 -0800400 /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */
401 public static void assertProjectionStatusPermission(Context context) {
402 assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS);
403 }
404
Enrico Granata3c7a6662017-02-23 18:07:59 -0800405 public static void assertAnyDiagnosticPermission(Context context) {
406 assertAnyPermission(context,
Enrico Granataae25b922017-07-07 11:28:15 -0700407 Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL,
Enrico Granata3c7a6662017-02-23 18:07:59 -0800408 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
409 }
410
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800411 public static void assertDrivingStatePermission(Context context) {
412 assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE);
413 }
414
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800415 public static void assertVmsPublisherPermission(Context context) {
416 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
417 }
418
Antonio Cortese4619c72017-02-02 07:53:27 -0800419 public static void assertVmsSubscriberPermission(Context context) {
420 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
421 }
422
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800423 /**
424 * Ensures the caller has the permission to enroll a Trust Agent.
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800425 */
426 public static void assertTrustAgentEnrollmentPermission(Context context) {
427 assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST);
428 }
429
Steve Paik461ecc62016-06-08 15:28:32 -0700430 public static void assertPermission(Context context, String permission) {
431 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
432 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800433 }
434 }
435
Steve Paik9ec53d72018-04-27 13:28:31 -0700436 /**
437 * Checks to see if the caller has a permission.
Steve Paik9ec53d72018-04-27 13:28:31 -0700438 *
439 * @return boolean TRUE if caller has the permission.
440 */
441 public static boolean hasPermission(Context context, String permission) {
442 return context.checkCallingOrSelfPermission(permission)
443 == PackageManager.PERMISSION_GRANTED;
444 }
445
Enrico Granata3c7a6662017-02-23 18:07:59 -0800446 public static void assertAnyPermission(Context context, String... permissions) {
447 for (String permission : permissions) {
448 if (context.checkCallingOrSelfPermission(permission) ==
449 PackageManager.PERMISSION_GRANTED) {
450 return;
451 }
452 }
453 throw new SecurityException("requires any of " + Arrays.toString(permissions));
454 }
455
Enrico Granatae8056ca2018-04-03 13:19:52 -0700456 @Override
457 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
458 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Anthony Chen12aec302018-04-25 16:41:48 -0700459 != PackageManager.PERMISSION_GRANTED) {
Enrico Granatae8056ca2018-04-03 13:19:52 -0700460 writer.println("Permission Denial: can't dump CarService from from pid="
Anthony Chen12aec302018-04-25 16:41:48 -0700461 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
462 + " without permission " + android.Manifest.permission.DUMP);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700463 return;
keunyounga3b28d82015-08-25 13:05:15 -0700464 }
Enrico Granatae8056ca2018-04-03 13:19:52 -0700465
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700466 if (args == null || args.length == 0 || (args.length > 0 && "-a".equals(args[0]))) {
467 writer.println("*Dump car service*");
Enrico Granatae8056ca2018-04-03 13:19:52 -0700468 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
469 writer.println("*Dump all services*");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700470
471 dumpAllServices(writer, false);
472
Enrico Granatae8056ca2018-04-03 13:19:52 -0700473 writer.println("*Dump Vehicle HAL*");
474 writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName);
475 try {
476 // TODO dump all feature flags by creating a dumpable interface
477 mHal.dump(writer);
478 } catch (Exception e) {
479 writer.println("Failed dumping: " + mHal.getClass().getName());
480 e.printStackTrace(writer);
481 }
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700482 } else if ("--metrics".equals(args[0])) {
483 writer.println("*Dump car service metrics*");
484 dumpAllServices(writer, true);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700485 } else if (Build.IS_USERDEBUG || Build.IS_ENG) {
486 execShellCmd(args, writer);
487 } else {
488 writer.println("Commands not supported in " + Build.TYPE);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800489 }
490 }
491
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700492 private void dumpAllServices(PrintWriter writer, boolean dumpMetricsOnly) {
493 for (CarServiceBase service : mAllServices) {
494 dumpService(service, writer, dumpMetricsOnly);
495 }
496 if (mCarTestService != null) {
497 dumpService(mCarTestService, writer, dumpMetricsOnly);
498 }
499
500 }
501
502 private void dumpService(CarServiceBase service, PrintWriter writer, boolean dumpMetricsOnly) {
Brad Stenninged3d59b2017-11-09 16:15:17 -0800503 try {
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700504 if (dumpMetricsOnly) {
505 service.dumpMetrics(writer);
506 } else {
507 service.dump(writer);
508 }
Brad Stenninged3d59b2017-11-09 16:15:17 -0800509 } catch (Exception e) {
510 writer.println("Failed dumping: " + service.getClass().getName());
511 e.printStackTrace(writer);
512 }
keunyoungcc449f72015-08-12 10:46:27 -0700513 }
Yao Chene33f07e2016-07-26 12:02:51 -0700514
515 void execShellCmd(String[] args, PrintWriter writer) {
516 new CarShellCommand().exec(args, writer);
517 }
518
Pavel Maltsevabd47232017-10-10 16:54:57 -0700519 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700520 private void traceBegin(String name) {
Steve Paikc302c7c2017-08-04 14:01:58 -0700521 Slog.i(TAG, name);
522 mBootTiming.traceBegin(name);
523 }
524
Pavel Maltsevabd47232017-10-10 16:54:57 -0700525 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700526 private void traceEnd() {
Steve Paikc302c7c2017-08-04 14:01:58 -0700527 mBootTiming.traceEnd();
528 }
529
Yao Chene33f07e2016-07-26 12:02:51 -0700530 private class CarShellCommand {
531 private static final String COMMAND_HELP = "-h";
532 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800533 private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event";
Kai4b098cf2019-06-05 15:03:28 -0700534 private static final String COMMAND_INJECT_ERROR_EVENT = "inject-error-event";
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800535 private static final String COMMAND_ENABLE_UXR = "enable-uxr";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800536 private static final String COMMAND_GARAGE_MODE = "garage-mode";
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800537 private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities";
Kaidd4ef5a2019-03-04 14:07:26 -0800538 private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig";
Kai29fba112019-04-22 18:37:38 -0700539 private static final String COMMAND_GET_PROPERTY_VALUE = "get-property-value";
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700540 private static final String COMMAND_PROJECTION_AP_TETHERING = "projection-tethering";
Pavel Maltsev48a31942019-03-03 22:08:28 -0800541 private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode";
Jim Kayed76c2742019-04-02 11:33:27 -0700542 private static final String COMMAND_RESUME = "resume";
543 private static final String COMMAND_SUSPEND = "suspend";
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700544 private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device";
545 private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices";
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700546 private static final String COMMAND_SET_UID_TO_ZONE = "set-zoneid-for-uid";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800547
Yao Chene33f07e2016-07-26 12:02:51 -0700548 private static final String PARAM_DAY_MODE = "day";
549 private static final String PARAM_NIGHT_MODE = "night";
550 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800551 private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800552 private static final String PARAM_ON_MODE = "on";
553 private static final String PARAM_OFF_MODE = "off";
554 private static final String PARAM_QUERY_MODE = "query";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800555
Yao Chene33f07e2016-07-26 12:02:51 -0700556
557 private void dumpHelp(PrintWriter pw) {
558 pw.println("Car service commands:");
559 pw.println("\t-h");
560 pw.println("\t Print this help text.");
561 pw.println("\tday-night-mode [day|night|sensor]");
562 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800563 pw.println("\tinject-vhal-event property [zone] data(can be comma separated list)");
Jim Kayef10b7d82019-02-26 12:53:22 -0800564 pw.println("\t Inject a vehicle property for testing.");
Kai4b098cf2019-06-05 15:03:28 -0700565 pw.println("\tinject-error-event property zone errorCode");
566 pw.println("\t Inject an error event from VHAL for testing.");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700567 pw.println("\tenable-uxr true|false");
568 pw.println("\t Enable/Disable UX restrictions and App blocking.");
Bryan Eylera32a7c12018-02-27 15:40:00 -0800569 pw.println("\tgarage-mode [on|off|query]");
570 pw.println("\t Force into garage mode or check status.");
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800571 pw.println("\tget-do-activities pkgname");
Jim Kayef10b7d82019-02-26 12:53:22 -0800572 pw.println("\t Get Distraction Optimized activities in given package.");
Kaidd4ef5a2019-03-04 14:07:26 -0800573 pw.println("\tget-carpropertyconfig [propertyId]");
574 pw.println("\t Get a CarPropertyConfig by Id in Hex or list all CarPropertyConfigs");
Kai29fba112019-04-22 18:37:38 -0700575 pw.println("\tget-property-value [propertyId] [areaId]");
576 pw.println("\t Get a vehicle property value by property id in Hex and areaId");
577 pw.println("\t or list all property values for all areaId");
Jim Kayed76c2742019-04-02 11:33:27 -0700578 pw.println("\tsuspend");
579 pw.println("\t Suspend the system to Deep Sleep.");
580 pw.println("\tresume");
581 pw.println("\t Wake the system up after a 'suspend.'");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700582 pw.println("\tenable-trusted-device true|false");
583 pw.println("\t Enable/Disable Trusted device feature.");
584 pw.println("\tremove-trusted-devices");
585 pw.println("\t Remove all trusted devices for the current foreground user.");
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700586 pw.println("\tprojection-tethering [true|false]");
587 pw.println("\t Whether tethering should be used when creating access point for"
588 + " wireless projection");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700589 pw.println("\t--metrics");
590 pw.println("\t When used with dumpsys, only metrics will be in the dumpsys output.");
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700591 pw.println("\tset-zoneid-for-uid [zoneid] [uid]");
592 pw.println("\t Maps the audio zoneid to uid.");
593 }
594
595 private String runSetZoneIdForUid(String zoneString, String uidString) {
596 int uid = Integer.parseInt(uidString);
597 int zoneId = Integer.parseInt(zoneString);
598 if (!ArrayUtils.contains(mCarAudioService.getAudioZoneIds(), zoneId)) {
599 return "zoneid " + zoneId + " not found";
600 }
601 mCarAudioService.setZoneIdForUid(zoneId, uid);
602 return null;
Yao Chene33f07e2016-07-26 12:02:51 -0700603 }
604
605 public void exec(String[] args, PrintWriter writer) {
606 String arg = args[0];
607 switch (arg) {
608 case COMMAND_HELP:
609 dumpHelp(writer);
610 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800611 case COMMAND_DAY_NIGHT_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800612 String value = args.length < 2 ? "" : args[1];
Yao Chene33f07e2016-07-26 12:02:51 -0700613 forceDayNightMode(value, writer);
614 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800615 }
616 case COMMAND_GARAGE_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800617 String value = args.length < 2 ? "" : args[1];
Bryan Eylera32a7c12018-02-27 15:40:00 -0800618 forceGarageMode(value, writer);
619 break;
620 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800621 case COMMAND_INJECT_VHAL_EVENT:
622 String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL;
623 String data;
Jim Kayef10b7d82019-02-26 12:53:22 -0800624 if (args.length != 3 && args.length != 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800625 writer.println("Incorrect number of arguments.");
626 dumpHelp(writer);
627 break;
Jim Kayef10b7d82019-02-26 12:53:22 -0800628 } else if (args.length == 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800629 // Zoned
630 zone = args[2];
631 data = args[3];
632 } else {
633 // Global
634 data = args[2];
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800635 }
Kai4b098cf2019-06-05 15:03:28 -0700636 injectVhalEvent(args[1], zone, data, false, writer);
637 break;
638 case COMMAND_INJECT_ERROR_EVENT:
639 if (args.length != 4) {
640 writer.println("Incorrect number of arguments");
641 dumpHelp(writer);
642 break;
643 }
644 String errorAreaId = args[2];
645 String errorCode = args[3];
646 injectVhalEvent(args[1], errorAreaId, errorCode, true, writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800647 break;
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800648 case COMMAND_ENABLE_UXR:
Jim Kayef10b7d82019-02-26 12:53:22 -0800649 if (args.length != 2) {
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800650 writer.println("Incorrect number of arguments");
651 dumpHelp(writer);
652 break;
653 }
654 boolean enableBlocking = Boolean.valueOf(args[1]);
655 if (mCarPackageManagerService != null) {
656 mCarPackageManagerService.setEnableActivityBlocking(enableBlocking);
657 }
658 break;
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800659 case COMMAND_GET_DO_ACTIVITIES:
Jim Kayef10b7d82019-02-26 12:53:22 -0800660 if (args.length != 2) {
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800661 writer.println("Incorrect number of arguments");
662 dumpHelp(writer);
663 break;
664 }
665 String pkgName = args[1].toLowerCase();
666 if (mCarPackageManagerService != null) {
667 String[] doActivities =
668 mCarPackageManagerService.getDistractionOptimizedActivities(
669 pkgName);
670 if (doActivities != null) {
671 writer.println("DO Activities for " + pkgName);
672 for (String a : doActivities) {
673 writer.println(a);
674 }
675 } else {
676 writer.println("No DO Activities for " + pkgName);
677 }
678 }
679 break;
Kaidd4ef5a2019-03-04 14:07:26 -0800680 case COMMAND_GET_CARPROPERTYCONFIG:
681 String propertyId = args.length < 2 ? "" : args[1];
682 mHal.dumpPropertyConfigs(writer, propertyId);
683 break;
Kai29fba112019-04-22 18:37:38 -0700684 case COMMAND_GET_PROPERTY_VALUE:
685 String propId = args.length < 2 ? "" : args[1];
686 String areaId = args.length < 3 ? "" : args[2];
687 mHal.dumpPropertyValueByCommend(writer, propId, areaId);
688 break;
Pavel Maltsev48a31942019-03-03 22:08:28 -0800689 case COMMAND_PROJECTION_UI_MODE:
690 if (args.length != 2) {
691 writer.println("Incorrect number of arguments");
692 dumpHelp(writer);
693 break;
694 }
695 mCarProjectionService.setUiMode(Integer.valueOf(args[1]));
Pavel Maltsevd6961f62019-03-26 10:22:31 -0700696 break;
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700697 case COMMAND_PROJECTION_AP_TETHERING:
698 if (args.length != 2) {
699 writer.println("Incorrect number of arguments");
700 dumpHelp(writer);
701 break;
702 }
703 mCarProjectionService.setAccessPointTethering(Boolean.valueOf(args[1]));
704 break;
Jim Kayed76c2742019-04-02 11:33:27 -0700705 case COMMAND_RESUME:
706 mCarPowerManagementService.forceSimulatedResume();
707 writer.println("Resume: Simulating resuming from Deep Sleep");
708 break;
709 case COMMAND_SUSPEND:
710 mCarPowerManagementService.forceSimulatedSuspend();
711 writer.println("Resume: Simulating powering down to Deep Sleep");
712 break;
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700713 case COMMAND_ENABLE_TRUSTED_DEVICE:
714 if (args.length != 2) {
715 writer.println("Incorrect number of arguments");
716 dumpHelp(writer);
717 break;
718 }
719 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
720 .setTrustedDeviceEnrollmentEnabled(Boolean.valueOf(args[1]));
721 mCarTrustedDeviceService.getCarTrustAgentUnlockService()
722 .setTrustedDeviceUnlockEnabled(Boolean.valueOf(args[1]));
723 break;
724 case COMMAND_REMOVE_TRUSTED_DEVICES:
725 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
726 .removeAllTrustedDevices(
727 mUserManagerHelper.getCurrentForegroundUserId());
728 break;
Oscar Azucena3f3a25e2019-07-12 14:28:24 -0700729 case COMMAND_SET_UID_TO_ZONE:
730 if (args.length != 3) {
731 writer.println("Incorrect number of arguments");
732 dumpHelp(writer);
733 break;
734 }
735 String results = runSetZoneIdForUid(args[1], args[2]);
736 if (results != null) {
737 writer.println(results);
738 dumpHelp(writer);
739 }
740 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700741 default:
Jim Kayef10b7d82019-02-26 12:53:22 -0800742 writer.println("Unknown command: \"" + arg + "\"");
Yao Chene33f07e2016-07-26 12:02:51 -0700743 dumpHelp(writer);
744 }
745 }
746
747 private void forceDayNightMode(String arg, PrintWriter writer) {
748 int mode;
749 switch (arg) {
750 case PARAM_DAY_MODE:
751 mode = CarNightService.FORCED_DAY_MODE;
752 break;
753 case PARAM_NIGHT_MODE:
754 mode = CarNightService.FORCED_NIGHT_MODE;
755 break;
756 case PARAM_SENSOR_MODE:
757 mode = CarNightService.FORCED_SENSOR_MODE;
758 break;
759 default:
760 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
761 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
762 return;
763 }
764 int current = mCarNightService.forceDayNightMode(mode);
765 String currentMode = null;
766 switch (current) {
767 case UiModeManager.MODE_NIGHT_AUTO:
768 currentMode = PARAM_SENSOR_MODE;
769 break;
770 case UiModeManager.MODE_NIGHT_YES:
771 currentMode = PARAM_NIGHT_MODE;
772 break;
773 case UiModeManager.MODE_NIGHT_NO:
774 currentMode = PARAM_DAY_MODE;
775 break;
776 }
777 writer.println("DayNightMode changed to: " + currentMode);
778 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800779
Bryan Eylera32a7c12018-02-27 15:40:00 -0800780 private void forceGarageMode(String arg, PrintWriter writer) {
781 switch (arg) {
782 case PARAM_ON_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700783 mGarageModeService.forceStartGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -0700784 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -0800785 break;
786 case PARAM_OFF_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700787 mGarageModeService.stopAndResetGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -0700788 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -0800789 break;
790 case PARAM_QUERY_MODE:
Jim Kaye1b5e6182019-05-24 15:48:32 -0700791 mGarageModeService.dump(writer);
Bryan Eylera32a7c12018-02-27 15:40:00 -0800792 break;
793 default:
794 writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|"
795 + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE);
Bryan Eylera32a7c12018-02-27 15:40:00 -0800796 }
Bryan Eylera32a7c12018-02-27 15:40:00 -0800797 }
798
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800799 /**
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800800 * Inject a fake VHAL event
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800801 *
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800802 * @param property the Vehicle property Id as defined in the HAL
803 * @param zone Zone that this event services
Kai4b098cf2019-06-05 15:03:28 -0700804 * @param isErrorEvent indicates the type of event
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800805 * @param value Data value of the event
806 * @param writer PrintWriter
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800807 */
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800808 private void injectVhalEvent(String property, String zone, String value,
Kai4b098cf2019-06-05 15:03:28 -0700809 boolean isErrorEvent, PrintWriter writer) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800810 if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) {
811 if (!isPropertyAreaTypeGlobal(property)) {
812 writer.println("Property area type inconsistent with given zone");
813 return;
814 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800815 }
816 try {
Kai4b098cf2019-06-05 15:03:28 -0700817 if (isErrorEvent) {
818 mHal.injectOnPropertySetError(property, zone, value);
819 } else {
820 mHal.injectVhalEvent(property, zone, value);
821 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800822 } catch (NumberFormatException e) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800823 writer.println("Invalid property Id zone Id or value" + e);
824 dumpHelp(writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800825 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800826 }
827
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800828 // Check if the given property is global
829 private boolean isPropertyAreaTypeGlobal(String property) {
830 if (property == null) {
831 return false;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800832 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800833 return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800834 }
Yao Chene33f07e2016-07-26 12:02:51 -0700835 }
kevinjm55822c42018-08-15 11:26:00 -0700836}