blob: 5b7de86e3660d8bfe384adc4e94853efb4f8d259 [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;
Gregory Clark26fa6012018-03-14 18:38:56 -070054
Enrico Granatae8056ca2018-04-03 13:19:52 -070055import java.io.FileDescriptor;
keunyounga3b28d82015-08-25 13:05:15 -070056import java.io.PrintWriter;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070057import java.util.ArrayList;
Antonio Cortese4619c72017-02-02 07:53:27 -080058import java.util.Arrays;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070059import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070060
keunyoungca515072015-07-10 12:21:47 -070061public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070062
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -080063 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070064 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
65 "system_activity_monitoring";
Keun-young Parka28d7b22016-02-29 16:54:29 -080066
keunyoungca515072015-07-10 12:21:47 -070067 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080068 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070069
Anthony Chen12aec302018-04-25 16:41:48 -070070 private final SystemInterface mSystemInterface;
71
Keun-young Park4727da32016-05-31 10:00:51 -070072 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070073 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080074 private final CarPackageManagerService mCarPackageManagerService;
75 private final CarInputService mCarInputService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -080076 private final CarDrivingStateService mCarDrivingStateService;
Ram Periathiruvadi4526a432018-01-24 13:00:54 -080077 private final CarUxRestrictionsManagerService mCarUXRestrictionsService;
keunyoungd32f4e62015-09-21 11:33:06 -070078 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080079 private final CarProjectionService mCarProjectionService;
Steve Paik9ec53d72018-04-27 13:28:31 -070080 private final CarPropertyService mCarPropertyService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080081 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070082 private final AppFocusService mAppFocusService;
Yao Chen3a7976d2016-01-20 17:27:08 -080083 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080084 private final InstrumentClusterService mInstrumentClusterService;
Gregory Clarkd8136062017-12-11 14:27:53 -080085 private final CarLocationService mCarLocationService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070086 private final SystemStateControllerService mSystemStateControllerService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080087 private final CarBluetoothService mCarBluetoothService;
Ram Periathiruvadiacb60242017-04-13 16:19:09 -070088 private final PerUserCarServiceHelper mPerUserCarServiceHelper;
Enrico Granata9a916d72017-09-19 14:33:08 -070089 private final CarDiagnosticService mCarDiagnosticService;
90 private final CarStorageMonitoringService mCarStorageMonitoringService;
Anthony Chen12aec302018-04-25 16:41:48 -070091 private final CarConfigurationService mCarConfigurationService;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070092 private final CarTrustedDeviceService mCarTrustedDeviceService;
Simon Dai527eb552019-02-12 13:06:15 -080093 private final CarMediaService mCarMediaService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070094 private final CarUserManagerHelper mUserManagerHelper;
Keun-young Parkd462a912019-02-11 08:53:42 -080095 private final CarUserService mCarUserService;
Mark Tabrya8fce562019-01-16 16:24:01 -080096 private final VmsClientManager mVmsClientManager;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080097 private final VmsBrokerService mVmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -080098 private final VmsSubscriberService mVmsSubscriberService;
99 private final VmsPublisherService mVmsPublisherService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700100 private final CarBugreportManagerService mCarBugreportManagerService;
keunyounga74b9ca2015-10-21 13:33:58 -0700101
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700102 private final CarServiceBase[] mAllServices;
103
Steve Paikc302c7c2017-08-04 14:01:58 -0700104 private static final String TAG = "ICarImpl";
105 private static final String VHAL_TIMING_TAG = "VehicleHalTiming";
Serik Beketayev74debf22018-10-04 12:18:09 -0700106
107 private TimingsTraceLog mBootTiming;
Steve Paikc302c7c2017-08-04 14:01:58 -0700108
keunyoung1ab8e182015-09-24 09:25:22 -0700109 /** Test only service. Populate it only when necessary. */
110 @GuardedBy("this")
111 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -0700112
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700113 @GuardedBy("this")
114 private ICarServiceHelper mICarServiceHelper;
115
Enrico Granatae8056ca2018-04-03 13:19:52 -0700116 private final String mVehicleInterfaceName;
117
Pavel Maltsevec83b632017-01-05 15:10:55 -0800118 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
Enrico Granatae8056ca2018-04-03 13:19:52 -0700119 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) {
keunyoungca515072015-07-10 12:21:47 -0700120 mContext = serviceContext;
Steve Paik0f9fc002018-02-09 17:42:00 -0800121 mSystemInterface = systemInterface;
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700122 mHal = new VehicleHal(vehicle);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700123 mVehicleInterfaceName = vehicleInterfaceName;
Yao, Yuxing0811d5a2018-11-29 16:18:53 -0800124 mUserManagerHelper = new CarUserManagerHelper(serviceContext);
Anthony Hugh9932a252019-06-12 16:19:56 -0700125 UserManager userManager =
126 (UserManager) serviceContext.getSystemService(Context.USER_SERVICE);
Keun young Parkf3523cd2019-04-08 10:09:17 -0700127 final Resources res = mContext.getResources();
128 final int maxRunningUsers = res.getInteger(
129 com.android.internal.R.integer.config_multiuserMaxRunningUsers);
Anthony Hugh9932a252019-06-12 16:19:56 -0700130 mCarUserService = new CarUserService(serviceContext, mUserManagerHelper, userManager,
Keun young Parkf3523cd2019-04-08 10:09:17 -0700131 ActivityManager.getService(), maxRunningUsers);
Keun-young Park4727da32016-05-31 10:00:51 -0700132 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Steve Paik388d7772018-02-12 10:54:51 -0800133 mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(),
Keun young Park9b3f2662019-03-19 10:30:25 -0700134 systemInterface, mUserManagerHelper);
Steve Paik9ec53d72018-04-27 13:28:31 -0700135 mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal());
136 mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService);
Ram Periathiruvadi4526a432018-01-24 13:00:54 -0800137 mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext,
Yao, Yuxing9bfb7492019-02-15 11:53:34 -0800138 mCarDrivingStateService, mCarPropertyService);
Ram Periathiruvadi2da6d0e2018-01-26 18:02:10 -0800139 mCarPackageManagerService = new CarPackageManagerService(serviceContext,
140 mCarUXRestrictionsService,
Pavel Maltsev38da4312019-04-08 10:38:38 -0700141 mSystemActivityMonitoringService,
142 mUserManagerHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800143 mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext);
Sal Savage703c46f2019-04-15 08:39:25 -0700144 mCarBluetoothService = new CarBluetoothService(serviceContext, mPerUserCarServiceHelper);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700145 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Justin Paupore44985ba2019-01-30 18:53:41 -0800146 mCarProjectionService = new CarProjectionService(
Pavel Maltsev079873b2019-02-25 12:15:09 -0800147 serviceContext, null /* handler */, mCarInputService, mCarBluetoothService);
Serik Beketayevc6ab8be2018-08-28 21:20:53 -0700148 mGarageModeService = new GarageModeService(mContext);
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700149 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Hongwei Wang30557232018-01-02 10:25:08 -0800150 mCarAudioService = new CarAudioService(serviceContext);
Steve Paik9ec53d72018-04-27 13:28:31 -0700151 mCarNightService = new CarNightService(serviceContext, mCarPropertyService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700152 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700153 mAppFocusService, mCarInputService);
Serik Beketayevf9f2ef02018-09-06 12:37:02 -0700154 mSystemStateControllerService = new SystemStateControllerService(
155 serviceContext, mCarAudioService, this);
Andrew T Nguyen0d4a36f2019-05-03 15:41:23 -0700156 mVmsBrokerService = new VmsBrokerService(mContext.getPackageManager());
Mark Tabry1534c062019-03-29 01:30:49 -0700157 mVmsClientManager = new VmsClientManager(
Mark Tabry41437562019-04-04 10:37:33 -0700158 serviceContext, mCarUserService, mUserManagerHelper, mHal.getVmsHal());
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800159 mVmsSubscriberService = new VmsSubscriberService(
160 serviceContext, mVmsBrokerService, mHal.getVmsHal());
161 mVmsPublisherService = new VmsPublisherService(
Mark Tabry1534c062019-03-29 01:30:49 -0700162 serviceContext, mVmsBrokerService, mVmsClientManager);
Enrico Granatab3634e22017-05-05 18:02:31 -0700163 mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal());
Enrico Granata517a1e02017-09-20 16:15:50 -0700164 mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext,
165 systemInterface);
Anthony Chen12aec302018-04-25 16:41:48 -0700166 mCarConfigurationService =
167 new CarConfigurationService(serviceContext, new JsonReaderImpl());
Gregory Clarke1519532019-05-10 16:25:57 -0700168 mCarLocationService = new CarLocationService(mContext, mUserManagerHelper);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700169 mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext);
Simon Dai527eb552019-02-12 13:06:15 -0800170 mCarMediaService = new CarMediaService(serviceContext);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700171 mCarBugreportManagerService = new CarBugreportManagerService(serviceContext);
keunyounga74b9ca2015-10-21 13:33:58 -0700172
Keun young Parka5fa4782019-04-16 18:56:27 -0700173 CarLocalServices.addService(CarPowerManagementService.class, mCarPowerManagementService);
Keun-young Parkd462a912019-02-11 08:53:42 -0800174 CarLocalServices.addService(CarUserService.class, mCarUserService);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700175 CarLocalServices.addService(CarTrustedDeviceService.class, mCarTrustedDeviceService);
Gregory Clarka440e812019-02-14 16:05:51 -0800176 CarLocalServices.addService(SystemInterface.class, mSystemInterface);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700177 CarLocalServices.addService(CarDrivingStateService.class, mCarDrivingStateService);
Gregory Clark55620c12019-06-03 17:42:58 -0700178 CarLocalServices.addService(PerUserCarServiceHelper.class, mPerUserCarServiceHelper);
Keun-young Parkd462a912019-02-11 08:53:42 -0800179
keunyounga3b28d82015-08-25 13:05:15 -0700180 // Be careful with order. Service depending on other service should be inited later.
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700181 List<CarServiceBase> allServices = new ArrayList<>();
Keun-young Parkd462a912019-02-11 08:53:42 -0800182 allServices.add(mCarUserService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700183 allServices.add(mSystemActivityMonitoringService);
184 allServices.add(mCarPowerManagementService);
185 allServices.add(mCarPropertyService);
186 allServices.add(mCarDrivingStateService);
187 allServices.add(mCarUXRestrictionsService);
188 allServices.add(mCarPackageManagerService);
189 allServices.add(mCarInputService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700190 allServices.add(mGarageModeService);
191 allServices.add(mAppFocusService);
192 allServices.add(mCarAudioService);
193 allServices.add(mCarNightService);
194 allServices.add(mInstrumentClusterService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700195 allServices.add(mSystemStateControllerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700196 allServices.add(mPerUserCarServiceHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800197 allServices.add(mCarBluetoothService);
198 allServices.add(mCarProjectionService);
199 allServices.add(mCarDiagnosticService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700200 allServices.add(mCarStorageMonitoringService);
201 allServices.add(mCarConfigurationService);
Mark Tabrya8fce562019-01-16 16:24:01 -0800202 allServices.add(mVmsClientManager);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700203 allServices.add(mVmsSubscriberService);
204 allServices.add(mVmsPublisherService);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700205 allServices.add(mCarTrustedDeviceService);
Simon Dai527eb552019-02-12 13:06:15 -0800206 allServices.add(mCarMediaService);
Gregory Clarka63ba022018-06-07 16:42:12 -0700207 allServices.add(mCarLocationService);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700208 allServices.add(mCarBugreportManagerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700209 mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]);
keunyoungca515072015-07-10 12:21:47 -0700210 }
211
Pavel Maltsevabd47232017-10-10 16:54:57 -0700212 @MainThread
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700213 void init() {
Serik Beketayev74debf22018-10-04 12:18:09 -0700214 mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL);
Steve Paikc302c7c2017-08-04 14:01:58 -0700215 traceBegin("VehicleHal.init");
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700216 mHal.init();
Steve Paikc302c7c2017-08-04 14:01:58 -0700217 traceEnd();
218 traceBegin("CarService.initAllServices");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800219 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700220 service.init();
221 }
Steve Paikc302c7c2017-08-04 14:01:58 -0700222 traceEnd();
Keun young Parkfd2afc92019-06-07 14:55:20 -0700223 mSystemInterface.reconfigureSecondaryDisplays();
keunyoungca515072015-07-10 12:21:47 -0700224 }
225
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700226 void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700227 // release done in opposite order from init
228 for (int i = mAllServices.length - 1; i >= 0; i--) {
229 mAllServices[i].release();
230 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700231 mHal.release();
Keun-young Parkd462a912019-02-11 08:53:42 -0800232 CarLocalServices.removeAllServices();
keunyoung1ab8e182015-09-24 09:25:22 -0700233 }
234
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700235 void vehicleHalReconnected(IVehicle vehicle) {
Pavel Maltsevec83b632017-01-05 15:10:55 -0800236 mHal.vehicleHalReconnected(vehicle);
237 for (CarServiceBase service : mAllServices) {
238 service.vehicleHalReconnected();
239 }
240 }
241
keunyoungca515072015-07-10 12:21:47 -0700242 @Override
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700243 public void setCarServiceHelper(IBinder helper) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700244 assertCallingFromSystemProcess();
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700245 synchronized (this) {
246 mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper);
Steve Paik0f9fc002018-02-09 17:42:00 -0800247 mSystemInterface.setCarServiceHelper(mICarServiceHelper);
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700248 }
249 }
250
251 @Override
Keun-young Parkd462a912019-02-11 08:53:42 -0800252 public void setUserLockStatus(int userHandle, int unlocked) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700253 assertCallingFromSystemProcess();
254 mCarUserService.setUserLockStatus(userHandle, unlocked == 1);
255 }
256
257 @Override
258 public void onSwitchUser(int userHandle) {
259 assertCallingFromSystemProcess();
260
261 Log.i(TAG, "Foreground user switched to " + userHandle);
262 mCarUserService.onSwitchUser(userHandle);
263 }
264
Jim Kayee5133162019-04-22 12:50:27 -0700265 static void assertCallingFromSystemProcess() {
Keun-young Parkd462a912019-02-11 08:53:42 -0800266 int uid = Binder.getCallingUid();
267 if (uid != Process.SYSTEM_UID) {
268 throw new SecurityException("Only allowed from system");
269 }
Keun-young Parkd462a912019-02-11 08:53:42 -0800270 }
271
Keun young Parkaabecd92019-05-03 17:31:27 -0700272 /**
273 * Assert if binder call is coming from system process like system server or if it is called
274 * from its own process even if it is not system. The latter can happen in test environment.
275 * Note that car service runs as system user but test like car service test will not.
276 */
277 static void assertCallingFromSystemProcessOrSelf() {
278 int uid = Binder.getCallingUid();
279 int pid = Binder.getCallingPid();
280 if (uid != Process.SYSTEM_UID && pid != Process.myPid()) {
281 throw new SecurityException("Only allowed from system or self");
282 }
283 }
284
Keun-young Parkd462a912019-02-11 08:53:42 -0800285 @Override
keunyoungca515072015-07-10 12:21:47 -0700286 public IBinder getCarService(String serviceName) {
287 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800288 case Car.AUDIO_SERVICE:
289 return mCarAudioService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700290 case Car.APP_FOCUS_SERVICE:
291 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800292 case Car.PACKAGE_SERVICE:
293 return mCarPackageManagerService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800294 case Car.DIAGNOSTIC_SERVICE:
Enrico Granatab3634e22017-05-05 18:02:31 -0700295 assertAnyDiagnosticPermission(mContext);
296 return mCarDiagnosticService;
Steve Paik388d7772018-02-12 10:54:51 -0800297 case Car.POWER_SERVICE:
298 assertPowerPermission(mContext);
299 return mCarPowerManagementService;
Steve Paik9ec53d72018-04-27 13:28:31 -0700300 case Car.CABIN_SERVICE:
301 case Car.HVAC_SERVICE:
302 case Car.INFO_SERVICE:
303 case Car.PROPERTY_SERVICE:
304 case Car.SENSOR_SERVICE:
305 case Car.VENDOR_EXTENSION_SERVICE:
306 return mCarPropertyService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800307 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700308 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700309 IInstrumentClusterNavigation navService =
310 mInstrumentClusterService.getNavigationService();
311 return navService == null ? null : navService.asBinder();
Pavel Maltsev905968c2017-07-16 19:48:57 -0700312 case Car.CAR_INSTRUMENT_CLUSTER_SERVICE:
313 assertClusterManagerPermission(mContext);
314 return mInstrumentClusterService.getManagerService();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800315 case Car.PROJECTION_SERVICE:
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800316 return mCarProjectionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800317 case Car.VMS_SUBSCRIBER_SERVICE:
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700318 assertVmsSubscriberPermission(mContext);
319 return mVmsSubscriberService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800320 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700321 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700322 synchronized (this) {
323 if (mCarTestService == null) {
324 mCarTestService = new CarTestService(mContext, this);
325 }
326 return mCarTestService;
327 }
328 }
Ram Periathiruvadi76a84892017-07-27 18:10:35 -0700329 case Car.BLUETOOTH_SERVICE:
330 return mCarBluetoothService;
Enrico Granata9a916d72017-09-19 14:33:08 -0700331 case Car.STORAGE_MONITORING_SERVICE:
Enrico Granata1172f882017-09-21 14:51:30 -0700332 assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING);
Enrico Granata9a916d72017-09-19 14:33:08 -0700333 return mCarStorageMonitoringService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800334 case Car.CAR_DRIVING_STATE_SERVICE:
335 assertDrivingStatePermission(mContext);
336 return mCarDrivingStateService;
337 case Car.CAR_UX_RESTRICTION_SERVICE:
338 return mCarUXRestrictionsService;
Anthony Chend4203d82018-05-16 16:21:52 -0700339 case Car.CAR_CONFIGURATION_SERVICE:
340 return mCarConfigurationService;
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800341 case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE:
342 assertTrustAgentEnrollmentPermission(mContext);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700343 return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService();
Simon Dai527eb552019-02-12 13:06:15 -0800344 case Car.CAR_MEDIA_SERVICE:
345 return mCarMediaService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700346 case Car.CAR_BUGREPORT_SERVICE:
347 return mCarBugreportManagerService;
keunyoungca515072015-07-10 12:21:47 -0700348 default:
349 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
350 return null;
351 }
352 }
353
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800354 @Override
355 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700356 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800357 }
358
Keun-young Parka28d7b22016-02-29 16:54:29 -0800359 public CarServiceBase getCarInternalService(String serviceName) {
360 switch (serviceName) {
361 case INTERNAL_INPUT_SERVICE:
362 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700363 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
364 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800365 default:
366 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
367 serviceName);
368 return null;
369 }
370 }
371
keunyoung1ab8e182015-09-24 09:25:22 -0700372 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700373 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700374 }
375
Keun-young Parke31a8b22016-03-16 17:34:08 -0700376 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700377 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800378 }
379
Pavel Maltsev905968c2017-07-16 19:48:57 -0700380 public static void assertClusterManagerPermission(Context context) {
381 assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL);
382 }
383
Steve Paik388d7772018-02-12 10:54:51 -0800384 public static void assertPowerPermission(Context context) {
385 assertPermission(context, Car.PERMISSION_CAR_POWER);
386 }
387
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800388 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700389 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
390 }
391
Pavel Maltsev079873b2019-02-25 12:15:09 -0800392 /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */
393 public static void assertProjectionStatusPermission(Context context) {
394 assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS);
395 }
396
Enrico Granata3c7a6662017-02-23 18:07:59 -0800397 public static void assertAnyDiagnosticPermission(Context context) {
398 assertAnyPermission(context,
Enrico Granataae25b922017-07-07 11:28:15 -0700399 Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL,
Enrico Granata3c7a6662017-02-23 18:07:59 -0800400 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
401 }
402
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800403 public static void assertDrivingStatePermission(Context context) {
404 assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE);
405 }
406
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800407 public static void assertVmsPublisherPermission(Context context) {
408 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
409 }
410
Antonio Cortese4619c72017-02-02 07:53:27 -0800411 public static void assertVmsSubscriberPermission(Context context) {
412 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
413 }
414
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800415 /**
416 * Ensures the caller has the permission to enroll a Trust Agent.
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800417 */
418 public static void assertTrustAgentEnrollmentPermission(Context context) {
419 assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST);
420 }
421
Steve Paik461ecc62016-06-08 15:28:32 -0700422 public static void assertPermission(Context context, String permission) {
423 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
424 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800425 }
426 }
427
Steve Paik9ec53d72018-04-27 13:28:31 -0700428 /**
429 * Checks to see if the caller has a permission.
Steve Paik9ec53d72018-04-27 13:28:31 -0700430 *
431 * @return boolean TRUE if caller has the permission.
432 */
433 public static boolean hasPermission(Context context, String permission) {
434 return context.checkCallingOrSelfPermission(permission)
435 == PackageManager.PERMISSION_GRANTED;
436 }
437
Enrico Granata3c7a6662017-02-23 18:07:59 -0800438 public static void assertAnyPermission(Context context, String... permissions) {
439 for (String permission : permissions) {
440 if (context.checkCallingOrSelfPermission(permission) ==
441 PackageManager.PERMISSION_GRANTED) {
442 return;
443 }
444 }
445 throw new SecurityException("requires any of " + Arrays.toString(permissions));
446 }
447
Enrico Granatae8056ca2018-04-03 13:19:52 -0700448 @Override
449 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
450 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Anthony Chen12aec302018-04-25 16:41:48 -0700451 != PackageManager.PERMISSION_GRANTED) {
Enrico Granatae8056ca2018-04-03 13:19:52 -0700452 writer.println("Permission Denial: can't dump CarService from from pid="
Anthony Chen12aec302018-04-25 16:41:48 -0700453 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
454 + " without permission " + android.Manifest.permission.DUMP);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700455 return;
keunyounga3b28d82015-08-25 13:05:15 -0700456 }
Enrico Granatae8056ca2018-04-03 13:19:52 -0700457
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700458 if (args == null || args.length == 0 || (args.length > 0 && "-a".equals(args[0]))) {
459 writer.println("*Dump car service*");
Enrico Granatae8056ca2018-04-03 13:19:52 -0700460 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
461 writer.println("*Dump all services*");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700462
463 dumpAllServices(writer, false);
464
Enrico Granatae8056ca2018-04-03 13:19:52 -0700465 writer.println("*Dump Vehicle HAL*");
466 writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName);
467 try {
468 // TODO dump all feature flags by creating a dumpable interface
469 mHal.dump(writer);
470 } catch (Exception e) {
471 writer.println("Failed dumping: " + mHal.getClass().getName());
472 e.printStackTrace(writer);
473 }
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700474 } else if ("--metrics".equals(args[0])) {
475 writer.println("*Dump car service metrics*");
476 dumpAllServices(writer, true);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700477 } else if (Build.IS_USERDEBUG || Build.IS_ENG) {
478 execShellCmd(args, writer);
479 } else {
480 writer.println("Commands not supported in " + Build.TYPE);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800481 }
482 }
483
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700484 private void dumpAllServices(PrintWriter writer, boolean dumpMetricsOnly) {
485 for (CarServiceBase service : mAllServices) {
486 dumpService(service, writer, dumpMetricsOnly);
487 }
488 if (mCarTestService != null) {
489 dumpService(mCarTestService, writer, dumpMetricsOnly);
490 }
491
492 }
493
494 private void dumpService(CarServiceBase service, PrintWriter writer, boolean dumpMetricsOnly) {
Brad Stenninged3d59b2017-11-09 16:15:17 -0800495 try {
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700496 if (dumpMetricsOnly) {
497 service.dumpMetrics(writer);
498 } else {
499 service.dump(writer);
500 }
Brad Stenninged3d59b2017-11-09 16:15:17 -0800501 } catch (Exception e) {
502 writer.println("Failed dumping: " + service.getClass().getName());
503 e.printStackTrace(writer);
504 }
keunyoungcc449f72015-08-12 10:46:27 -0700505 }
Yao Chene33f07e2016-07-26 12:02:51 -0700506
507 void execShellCmd(String[] args, PrintWriter writer) {
508 new CarShellCommand().exec(args, writer);
509 }
510
Pavel Maltsevabd47232017-10-10 16:54:57 -0700511 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700512 private void traceBegin(String name) {
Steve Paikc302c7c2017-08-04 14:01:58 -0700513 Slog.i(TAG, name);
514 mBootTiming.traceBegin(name);
515 }
516
Pavel Maltsevabd47232017-10-10 16:54:57 -0700517 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700518 private void traceEnd() {
Steve Paikc302c7c2017-08-04 14:01:58 -0700519 mBootTiming.traceEnd();
520 }
521
Yao Chene33f07e2016-07-26 12:02:51 -0700522 private class CarShellCommand {
523 private static final String COMMAND_HELP = "-h";
524 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800525 private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event";
Kai4b098cf2019-06-05 15:03:28 -0700526 private static final String COMMAND_INJECT_ERROR_EVENT = "inject-error-event";
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800527 private static final String COMMAND_ENABLE_UXR = "enable-uxr";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800528 private static final String COMMAND_GARAGE_MODE = "garage-mode";
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800529 private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities";
Kaidd4ef5a2019-03-04 14:07:26 -0800530 private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig";
Kai29fba112019-04-22 18:37:38 -0700531 private static final String COMMAND_GET_PROPERTY_VALUE = "get-property-value";
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700532 private static final String COMMAND_PROJECTION_AP_TETHERING = "projection-tethering";
Pavel Maltsev48a31942019-03-03 22:08:28 -0800533 private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode";
Jim Kayed76c2742019-04-02 11:33:27 -0700534 private static final String COMMAND_RESUME = "resume";
535 private static final String COMMAND_SUSPEND = "suspend";
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700536 private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device";
537 private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800538
Yao Chene33f07e2016-07-26 12:02:51 -0700539 private static final String PARAM_DAY_MODE = "day";
540 private static final String PARAM_NIGHT_MODE = "night";
541 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800542 private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800543 private static final String PARAM_ON_MODE = "on";
544 private static final String PARAM_OFF_MODE = "off";
545 private static final String PARAM_QUERY_MODE = "query";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800546
Yao Chene33f07e2016-07-26 12:02:51 -0700547
548 private void dumpHelp(PrintWriter pw) {
549 pw.println("Car service commands:");
550 pw.println("\t-h");
551 pw.println("\t Print this help text.");
552 pw.println("\tday-night-mode [day|night|sensor]");
553 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800554 pw.println("\tinject-vhal-event property [zone] data(can be comma separated list)");
Jim Kayef10b7d82019-02-26 12:53:22 -0800555 pw.println("\t Inject a vehicle property for testing.");
Kai4b098cf2019-06-05 15:03:28 -0700556 pw.println("\tinject-error-event property zone errorCode");
557 pw.println("\t Inject an error event from VHAL for testing.");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700558 pw.println("\tenable-uxr true|false");
559 pw.println("\t Enable/Disable UX restrictions and App blocking.");
Bryan Eylera32a7c12018-02-27 15:40:00 -0800560 pw.println("\tgarage-mode [on|off|query]");
561 pw.println("\t Force into garage mode or check status.");
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800562 pw.println("\tget-do-activities pkgname");
Jim Kayef10b7d82019-02-26 12:53:22 -0800563 pw.println("\t Get Distraction Optimized activities in given package.");
Kaidd4ef5a2019-03-04 14:07:26 -0800564 pw.println("\tget-carpropertyconfig [propertyId]");
565 pw.println("\t Get a CarPropertyConfig by Id in Hex or list all CarPropertyConfigs");
Kai29fba112019-04-22 18:37:38 -0700566 pw.println("\tget-property-value [propertyId] [areaId]");
567 pw.println("\t Get a vehicle property value by property id in Hex and areaId");
568 pw.println("\t or list all property values for all areaId");
Jim Kayed76c2742019-04-02 11:33:27 -0700569 pw.println("\tsuspend");
570 pw.println("\t Suspend the system to Deep Sleep.");
571 pw.println("\tresume");
572 pw.println("\t Wake the system up after a 'suspend.'");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700573 pw.println("\tenable-trusted-device true|false");
574 pw.println("\t Enable/Disable Trusted device feature.");
575 pw.println("\tremove-trusted-devices");
576 pw.println("\t Remove all trusted devices for the current foreground user.");
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700577 pw.println("\tprojection-tethering [true|false]");
578 pw.println("\t Whether tethering should be used when creating access point for"
579 + " wireless projection");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700580 pw.println("\t--metrics");
581 pw.println("\t When used with dumpsys, only metrics will be in the dumpsys output.");
Yao Chene33f07e2016-07-26 12:02:51 -0700582 }
583
584 public void exec(String[] args, PrintWriter writer) {
585 String arg = args[0];
586 switch (arg) {
587 case COMMAND_HELP:
588 dumpHelp(writer);
589 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800590 case COMMAND_DAY_NIGHT_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800591 String value = args.length < 2 ? "" : args[1];
Yao Chene33f07e2016-07-26 12:02:51 -0700592 forceDayNightMode(value, writer);
593 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800594 }
595 case COMMAND_GARAGE_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800596 String value = args.length < 2 ? "" : args[1];
Bryan Eylera32a7c12018-02-27 15:40:00 -0800597 forceGarageMode(value, writer);
598 break;
599 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800600 case COMMAND_INJECT_VHAL_EVENT:
601 String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL;
602 String data;
Jim Kayef10b7d82019-02-26 12:53:22 -0800603 if (args.length != 3 && args.length != 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800604 writer.println("Incorrect number of arguments.");
605 dumpHelp(writer);
606 break;
Jim Kayef10b7d82019-02-26 12:53:22 -0800607 } else if (args.length == 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800608 // Zoned
609 zone = args[2];
610 data = args[3];
611 } else {
612 // Global
613 data = args[2];
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800614 }
Kai4b098cf2019-06-05 15:03:28 -0700615 injectVhalEvent(args[1], zone, data, false, writer);
616 break;
617 case COMMAND_INJECT_ERROR_EVENT:
618 if (args.length != 4) {
619 writer.println("Incorrect number of arguments");
620 dumpHelp(writer);
621 break;
622 }
623 String errorAreaId = args[2];
624 String errorCode = args[3];
625 injectVhalEvent(args[1], errorAreaId, errorCode, true, writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800626 break;
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800627 case COMMAND_ENABLE_UXR:
Jim Kayef10b7d82019-02-26 12:53:22 -0800628 if (args.length != 2) {
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800629 writer.println("Incorrect number of arguments");
630 dumpHelp(writer);
631 break;
632 }
633 boolean enableBlocking = Boolean.valueOf(args[1]);
634 if (mCarPackageManagerService != null) {
635 mCarPackageManagerService.setEnableActivityBlocking(enableBlocking);
636 }
637 break;
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800638 case COMMAND_GET_DO_ACTIVITIES:
Jim Kayef10b7d82019-02-26 12:53:22 -0800639 if (args.length != 2) {
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800640 writer.println("Incorrect number of arguments");
641 dumpHelp(writer);
642 break;
643 }
644 String pkgName = args[1].toLowerCase();
645 if (mCarPackageManagerService != null) {
646 String[] doActivities =
647 mCarPackageManagerService.getDistractionOptimizedActivities(
648 pkgName);
649 if (doActivities != null) {
650 writer.println("DO Activities for " + pkgName);
651 for (String a : doActivities) {
652 writer.println(a);
653 }
654 } else {
655 writer.println("No DO Activities for " + pkgName);
656 }
657 }
658 break;
Kaidd4ef5a2019-03-04 14:07:26 -0800659 case COMMAND_GET_CARPROPERTYCONFIG:
660 String propertyId = args.length < 2 ? "" : args[1];
661 mHal.dumpPropertyConfigs(writer, propertyId);
662 break;
Kai29fba112019-04-22 18:37:38 -0700663 case COMMAND_GET_PROPERTY_VALUE:
664 String propId = args.length < 2 ? "" : args[1];
665 String areaId = args.length < 3 ? "" : args[2];
666 mHal.dumpPropertyValueByCommend(writer, propId, areaId);
667 break;
Pavel Maltsev48a31942019-03-03 22:08:28 -0800668 case COMMAND_PROJECTION_UI_MODE:
669 if (args.length != 2) {
670 writer.println("Incorrect number of arguments");
671 dumpHelp(writer);
672 break;
673 }
674 mCarProjectionService.setUiMode(Integer.valueOf(args[1]));
Pavel Maltsevd6961f62019-03-26 10:22:31 -0700675 break;
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700676 case COMMAND_PROJECTION_AP_TETHERING:
677 if (args.length != 2) {
678 writer.println("Incorrect number of arguments");
679 dumpHelp(writer);
680 break;
681 }
682 mCarProjectionService.setAccessPointTethering(Boolean.valueOf(args[1]));
683 break;
Jim Kayed76c2742019-04-02 11:33:27 -0700684 case COMMAND_RESUME:
685 mCarPowerManagementService.forceSimulatedResume();
686 writer.println("Resume: Simulating resuming from Deep Sleep");
687 break;
688 case COMMAND_SUSPEND:
689 mCarPowerManagementService.forceSimulatedSuspend();
690 writer.println("Resume: Simulating powering down to Deep Sleep");
691 break;
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700692 case COMMAND_ENABLE_TRUSTED_DEVICE:
693 if (args.length != 2) {
694 writer.println("Incorrect number of arguments");
695 dumpHelp(writer);
696 break;
697 }
698 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
699 .setTrustedDeviceEnrollmentEnabled(Boolean.valueOf(args[1]));
700 mCarTrustedDeviceService.getCarTrustAgentUnlockService()
701 .setTrustedDeviceUnlockEnabled(Boolean.valueOf(args[1]));
702 break;
703 case COMMAND_REMOVE_TRUSTED_DEVICES:
704 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
705 .removeAllTrustedDevices(
706 mUserManagerHelper.getCurrentForegroundUserId());
707 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700708 default:
Jim Kayef10b7d82019-02-26 12:53:22 -0800709 writer.println("Unknown command: \"" + arg + "\"");
Yao Chene33f07e2016-07-26 12:02:51 -0700710 dumpHelp(writer);
711 }
712 }
713
714 private void forceDayNightMode(String arg, PrintWriter writer) {
715 int mode;
716 switch (arg) {
717 case PARAM_DAY_MODE:
718 mode = CarNightService.FORCED_DAY_MODE;
719 break;
720 case PARAM_NIGHT_MODE:
721 mode = CarNightService.FORCED_NIGHT_MODE;
722 break;
723 case PARAM_SENSOR_MODE:
724 mode = CarNightService.FORCED_SENSOR_MODE;
725 break;
726 default:
727 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
728 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
729 return;
730 }
731 int current = mCarNightService.forceDayNightMode(mode);
732 String currentMode = null;
733 switch (current) {
734 case UiModeManager.MODE_NIGHT_AUTO:
735 currentMode = PARAM_SENSOR_MODE;
736 break;
737 case UiModeManager.MODE_NIGHT_YES:
738 currentMode = PARAM_NIGHT_MODE;
739 break;
740 case UiModeManager.MODE_NIGHT_NO:
741 currentMode = PARAM_DAY_MODE;
742 break;
743 }
744 writer.println("DayNightMode changed to: " + currentMode);
745 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800746
Bryan Eylera32a7c12018-02-27 15:40:00 -0800747 private void forceGarageMode(String arg, PrintWriter writer) {
748 switch (arg) {
749 case PARAM_ON_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700750 mGarageModeService.forceStartGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -0700751 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -0800752 break;
753 case PARAM_OFF_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700754 mGarageModeService.stopAndResetGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -0700755 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -0800756 break;
757 case PARAM_QUERY_MODE:
Jim Kaye1b5e6182019-05-24 15:48:32 -0700758 mGarageModeService.dump(writer);
Bryan Eylera32a7c12018-02-27 15:40:00 -0800759 break;
760 default:
761 writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|"
762 + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE);
Bryan Eylera32a7c12018-02-27 15:40:00 -0800763 }
Bryan Eylera32a7c12018-02-27 15:40:00 -0800764 }
765
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800766 /**
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800767 * Inject a fake VHAL event
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800768 *
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800769 * @param property the Vehicle property Id as defined in the HAL
770 * @param zone Zone that this event services
Kai4b098cf2019-06-05 15:03:28 -0700771 * @param isErrorEvent indicates the type of event
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800772 * @param value Data value of the event
773 * @param writer PrintWriter
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800774 */
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800775 private void injectVhalEvent(String property, String zone, String value,
Kai4b098cf2019-06-05 15:03:28 -0700776 boolean isErrorEvent, PrintWriter writer) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800777 if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) {
778 if (!isPropertyAreaTypeGlobal(property)) {
779 writer.println("Property area type inconsistent with given zone");
780 return;
781 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800782 }
783 try {
Kai4b098cf2019-06-05 15:03:28 -0700784 if (isErrorEvent) {
785 mHal.injectOnPropertySetError(property, zone, value);
786 } else {
787 mHal.injectVhalEvent(property, zone, value);
788 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800789 } catch (NumberFormatException e) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800790 writer.println("Invalid property Id zone Id or value" + e);
791 dumpHelp(writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800792 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800793 }
794
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800795 // Check if the given property is global
796 private boolean isPropertyAreaTypeGlobal(String property) {
797 if (property == null) {
798 return false;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800799 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800800 return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800801 }
Yao Chene33f07e2016-07-26 12:02:51 -0700802 }
kevinjm55822c42018-08-15 11:26:00 -0700803}