blob: 69a0560dc1302a0021d581152929e15fb9efa617 [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;
Keun young Park69a21042019-10-15 10:34:11 -070021import android.app.ActivityOptions;
Yao Chene33f07e2016-07-26 12:02:51 -070022import android.app.UiModeManager;
Keun-young Parke54ac272016-02-16 19:02:18 -080023import android.car.Car;
24import android.car.ICar;
Pavel Maltsev0477e292016-05-27 12:22:36 -070025import android.car.cluster.renderer.IInstrumentClusterNavigation;
Ying Zheng9fc99402018-09-19 14:23:59 -070026import android.car.userlib.CarUserManagerHelper;
Keun young Park69a21042019-10-15 10:34:11 -070027import android.content.ComponentName;
keunyoungca515072015-07-10 12:21:47 -070028import android.content.Context;
Keun young Park69a21042019-10-15 10:34:11 -070029import android.content.Intent;
keunyoung1ab8e182015-09-24 09:25:22 -070030import android.content.pm.PackageManager;
Keun young Parkf3523cd2019-04-08 10:09:17 -070031import android.content.res.Resources;
Pavel Maltsevcfe93102017-02-02 12:38:08 -080032import android.hardware.automotive.vehicle.V2_0.IVehicle;
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -080033import android.hardware.automotive.vehicle.V2_0.VehicleArea;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070034import android.os.Binder;
Enrico Granatae8056ca2018-04-03 13:19:52 -070035import android.os.Build;
keunyoungca515072015-07-10 12:21:47 -070036import android.os.IBinder;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070037import android.os.Process;
Steve Paikc302c7c2017-08-04 14:01:58 -070038import android.os.Trace;
keunyoungca515072015-07-10 12:21:47 -070039import android.util.Log;
Steve Paikc302c7c2017-08-04 14:01:58 -070040import android.util.Slog;
Keun-young Park4a79a382017-08-10 18:19:14 -070041import android.util.TimingsTraceLog;
Gregory Clark26fa6012018-03-14 18:38:56 -070042
Keun young Parkb5fab732019-10-03 10:51:12 -070043import com.android.car.am.FixedActivityService;
Hongwei Wang38549092018-08-22 12:32:42 -070044import com.android.car.audio.CarAudioService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080045import com.android.car.cluster.InstrumentClusterService;
Serik Beketayev06a66682018-06-12 16:54:29 -070046import com.android.car.garagemode.GarageModeService;
keunyoungcc449f72015-08-12 10:46:27 -070047import com.android.car.hal.VehicleHal;
Antonio Cortesc52d5f92017-02-06 08:47:38 -080048import com.android.car.internal.FeatureConfiguration;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080049import com.android.car.pm.CarPackageManagerService;
Mark Tabryc87043b2019-10-17 10:18:32 -070050import com.android.car.stats.CarStatsService;
Enrico Granatab19bc322017-10-12 12:25:06 -070051import com.android.car.systeminterface.SystemInterface;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070052import com.android.car.trust.CarTrustedDeviceService;
Keun young Park2bf014e2019-09-12 10:31:48 -070053import com.android.car.user.CarUserNoticeService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070054import com.android.car.user.CarUserService;
Mark Tabry76cfaaa2019-02-01 14:28:30 -080055import com.android.car.vms.VmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -080056import com.android.car.vms.VmsClientManager;
keunyoungca515072015-07-10 12:21:47 -070057import com.android.internal.annotations.GuardedBy;
Steve Paik1d8bea22018-02-03 01:54:06 +000058import com.android.internal.car.ICarServiceHelper;
Gregory Clark26fa6012018-03-14 18:38:56 -070059
Enrico Granatae8056ca2018-04-03 13:19:52 -070060import java.io.FileDescriptor;
keunyounga3b28d82015-08-25 13:05:15 -070061import java.io.PrintWriter;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070062import java.util.ArrayList;
Antonio Cortese4619c72017-02-02 07:53:27 -080063import java.util.Arrays;
Ying Zheng86d1c3e2018-05-11 11:42:48 -070064import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070065
keunyoungca515072015-07-10 12:21:47 -070066public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070067
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -080068 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070069 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
70 "system_activity_monitoring";
Mark Tabryccf43dc2019-11-21 15:07:36 -080071 public static final String INTERNAL_VMS_MANAGER = "vms_manager";
Keun-young Parka28d7b22016-02-29 16:54:29 -080072
keunyoungca515072015-07-10 12:21:47 -070073 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080074 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070075
Anthony Chen12aec302018-04-25 16:41:48 -070076 private final SystemInterface mSystemInterface;
77
Keun-young Park4727da32016-05-31 10:00:51 -070078 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070079 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080080 private final CarPackageManagerService mCarPackageManagerService;
81 private final CarInputService mCarInputService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -080082 private final CarDrivingStateService mCarDrivingStateService;
Ram Periathiruvadi4526a432018-01-24 13:00:54 -080083 private final CarUxRestrictionsManagerService mCarUXRestrictionsService;
keunyoungd32f4e62015-09-21 11:33:06 -070084 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080085 private final CarProjectionService mCarProjectionService;
Steve Paik9ec53d72018-04-27 13:28:31 -070086 private final CarPropertyService mCarPropertyService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080087 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070088 private final AppFocusService mAppFocusService;
Keun young Parkb5fab732019-10-03 10:51:12 -070089 private final FixedActivityService mFixedActivityService;
Yao Chen3a7976d2016-01-20 17:27:08 -080090 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080091 private final InstrumentClusterService mInstrumentClusterService;
Gregory Clarkd8136062017-12-11 14:27:53 -080092 private final CarLocationService mCarLocationService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070093 private final SystemStateControllerService mSystemStateControllerService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080094 private final CarBluetoothService mCarBluetoothService;
Ram Periathiruvadiacb60242017-04-13 16:19:09 -070095 private final PerUserCarServiceHelper mPerUserCarServiceHelper;
Enrico Granata9a916d72017-09-19 14:33:08 -070096 private final CarDiagnosticService mCarDiagnosticService;
97 private final CarStorageMonitoringService mCarStorageMonitoringService;
Anthony Chen12aec302018-04-25 16:41:48 -070098 private final CarConfigurationService mCarConfigurationService;
Ram Periathiruvadide0ca082019-03-20 11:16:44 -070099 private final CarTrustedDeviceService mCarTrustedDeviceService;
Simon Dai527eb552019-02-12 13:06:15 -0800100 private final CarMediaService mCarMediaService;
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700101 private final CarUserManagerHelper mUserManagerHelper;
Keun-young Parkd462a912019-02-11 08:53:42 -0800102 private final CarUserService mCarUserService;
Keun young Park2bf014e2019-09-12 10:31:48 -0700103 private final CarUserNoticeService mCarUserNoticeService;
Mark Tabrya8fce562019-01-16 16:24:01 -0800104 private final VmsClientManager mVmsClientManager;
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800105 private final VmsBrokerService mVmsBrokerService;
Mark Tabrya8fce562019-01-16 16:24:01 -0800106 private final VmsSubscriberService mVmsSubscriberService;
107 private final VmsPublisherService mVmsPublisherService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700108 private final CarBugreportManagerService mCarBugreportManagerService;
Mark Tabryc87043b2019-10-17 10:18:32 -0700109 private final CarStatsService mCarStatsService;
keunyounga74b9ca2015-10-21 13:33:58 -0700110
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700111 private final CarServiceBase[] mAllServices;
112
Steve Paikc302c7c2017-08-04 14:01:58 -0700113 private static final String TAG = "ICarImpl";
114 private static final String VHAL_TIMING_TAG = "VehicleHalTiming";
Serik Beketayev74debf22018-10-04 12:18:09 -0700115
116 private TimingsTraceLog mBootTiming;
Steve Paikc302c7c2017-08-04 14:01:58 -0700117
keunyoung1ab8e182015-09-24 09:25:22 -0700118 /** Test only service. Populate it only when necessary. */
119 @GuardedBy("this")
120 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -0700121
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700122 @GuardedBy("this")
123 private ICarServiceHelper mICarServiceHelper;
124
Enrico Granatae8056ca2018-04-03 13:19:52 -0700125 private final String mVehicleInterfaceName;
126
Pavel Maltsevec83b632017-01-05 15:10:55 -0800127 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
Enrico Granatae8056ca2018-04-03 13:19:52 -0700128 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) {
keunyoungca515072015-07-10 12:21:47 -0700129 mContext = serviceContext;
Steve Paik0f9fc002018-02-09 17:42:00 -0800130 mSystemInterface = systemInterface;
Mark Tabryb588d2e2019-09-12 10:50:11 -0700131 mHal = new VehicleHal(serviceContext, vehicle);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700132 mVehicleInterfaceName = vehicleInterfaceName;
Yao, Yuxing0811d5a2018-11-29 16:18:53 -0800133 mUserManagerHelper = new CarUserManagerHelper(serviceContext);
Keun young Parkf3523cd2019-04-08 10:09:17 -0700134 final Resources res = mContext.getResources();
135 final int maxRunningUsers = res.getInteger(
136 com.android.internal.R.integer.config_multiuserMaxRunningUsers);
137 mCarUserService = new CarUserService(serviceContext, mUserManagerHelper,
138 ActivityManager.getService(), maxRunningUsers);
Keun-young Park4727da32016-05-31 10:00:51 -0700139 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Steve Paik388d7772018-02-12 10:54:51 -0800140 mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(),
Keun young Park9b3f2662019-03-19 10:30:25 -0700141 systemInterface, mUserManagerHelper);
Keun young Park2bf014e2019-09-12 10:31:48 -0700142 mCarUserNoticeService = new CarUserNoticeService(serviceContext);
Steve Paik9ec53d72018-04-27 13:28:31 -0700143 mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal());
144 mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService);
Ram Periathiruvadi4526a432018-01-24 13:00:54 -0800145 mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext,
Yao, Yuxing9bfb7492019-02-15 11:53:34 -0800146 mCarDrivingStateService, mCarPropertyService);
Ram Periathiruvadi2da6d0e2018-01-26 18:02:10 -0800147 mCarPackageManagerService = new CarPackageManagerService(serviceContext,
148 mCarUXRestrictionsService,
Pavel Maltsev38da4312019-04-08 10:38:38 -0700149 mSystemActivityMonitoringService,
150 mUserManagerHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800151 mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext);
Sal Savage703c46f2019-04-15 08:39:25 -0700152 mCarBluetoothService = new CarBluetoothService(serviceContext, mPerUserCarServiceHelper);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700153 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Justin Paupore44985ba2019-01-30 18:53:41 -0800154 mCarProjectionService = new CarProjectionService(
Pavel Maltsev079873b2019-02-25 12:15:09 -0800155 serviceContext, null /* handler */, mCarInputService, mCarBluetoothService);
Serik Beketayevc6ab8be2018-08-28 21:20:53 -0700156 mGarageModeService = new GarageModeService(mContext);
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700157 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Hongwei Wang30557232018-01-02 10:25:08 -0800158 mCarAudioService = new CarAudioService(serviceContext);
Steve Paik9ec53d72018-04-27 13:28:31 -0700159 mCarNightService = new CarNightService(serviceContext, mCarPropertyService);
Keun young Parkb5fab732019-10-03 10:51:12 -0700160 mFixedActivityService = new FixedActivityService(serviceContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700161 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700162 mAppFocusService, mCarInputService);
Serik Beketayevf9f2ef02018-09-06 12:37:02 -0700163 mSystemStateControllerService = new SystemStateControllerService(
164 serviceContext, mCarAudioService, this);
Mark Tabryc87043b2019-10-17 10:18:32 -0700165 mCarStatsService = new CarStatsService(serviceContext);
Mark Tabry3f3ae3d2019-09-09 13:21:46 -0700166 mVmsBrokerService = new VmsBrokerService();
Mark Tabry1534c062019-03-29 01:30:49 -0700167 mVmsClientManager = new VmsClientManager(
Mark Tabryc87043b2019-10-17 10:18:32 -0700168 // CarStatsService needs to be passed to the constructor due to HAL init order
Mark Tabryccf43dc2019-11-21 15:07:36 -0800169 serviceContext, mCarStatsService, mCarUserService, mVmsBrokerService,
170 mHal.getVmsHal());
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800171 mVmsSubscriberService = new VmsSubscriberService(
Mark Tabry3f3ae3d2019-09-09 13:21:46 -0700172 serviceContext, mVmsBrokerService, mVmsClientManager, mHal.getVmsHal());
Mark Tabry76cfaaa2019-02-01 14:28:30 -0800173 mVmsPublisherService = new VmsPublisherService(
Mark Tabryc87043b2019-10-17 10:18:32 -0700174 serviceContext, mCarStatsService, mVmsBrokerService, mVmsClientManager);
Enrico Granatab3634e22017-05-05 18:02:31 -0700175 mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal());
Enrico Granata517a1e02017-09-20 16:15:50 -0700176 mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext,
177 systemInterface);
Anthony Chen12aec302018-04-25 16:41:48 -0700178 mCarConfigurationService =
179 new CarConfigurationService(serviceContext, new JsonReaderImpl());
Gregory Clarke1519532019-05-10 16:25:57 -0700180 mCarLocationService = new CarLocationService(mContext, mUserManagerHelper);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700181 mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext);
Simon Dai527eb552019-02-12 13:06:15 -0800182 mCarMediaService = new CarMediaService(serviceContext);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700183 mCarBugreportManagerService = new CarBugreportManagerService(serviceContext);
keunyounga74b9ca2015-10-21 13:33:58 -0700184
Keun young Parka5fa4782019-04-16 18:56:27 -0700185 CarLocalServices.addService(CarPowerManagementService.class, mCarPowerManagementService);
Keun-young Parkd462a912019-02-11 08:53:42 -0800186 CarLocalServices.addService(CarUserService.class, mCarUserService);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700187 CarLocalServices.addService(CarTrustedDeviceService.class, mCarTrustedDeviceService);
Mayank Gargfc24d572020-02-14 11:32:34 -0800188 CarLocalServices.addService(CarUserNoticeService.class, mCarUserNoticeService);
Gregory Clarka440e812019-02-14 16:05:51 -0800189 CarLocalServices.addService(SystemInterface.class, mSystemInterface);
Gregory Clark18a0ef92019-05-23 20:00:49 -0700190 CarLocalServices.addService(CarDrivingStateService.class, mCarDrivingStateService);
Gregory Clark55620c12019-06-03 17:42:58 -0700191 CarLocalServices.addService(PerUserCarServiceHelper.class, mPerUserCarServiceHelper);
Keun young Parkb5fab732019-10-03 10:51:12 -0700192 CarLocalServices.addService(FixedActivityService.class, mFixedActivityService);
Keun-young Parkd462a912019-02-11 08:53:42 -0800193
keunyounga3b28d82015-08-25 13:05:15 -0700194 // Be careful with order. Service depending on other service should be inited later.
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700195 List<CarServiceBase> allServices = new ArrayList<>();
Keun-young Parkd462a912019-02-11 08:53:42 -0800196 allServices.add(mCarUserService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700197 allServices.add(mSystemActivityMonitoringService);
198 allServices.add(mCarPowerManagementService);
199 allServices.add(mCarPropertyService);
200 allServices.add(mCarDrivingStateService);
201 allServices.add(mCarUXRestrictionsService);
202 allServices.add(mCarPackageManagerService);
203 allServices.add(mCarInputService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700204 allServices.add(mGarageModeService);
Keun young Park2bf014e2019-09-12 10:31:48 -0700205 allServices.add(mCarUserNoticeService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700206 allServices.add(mAppFocusService);
207 allServices.add(mCarAudioService);
208 allServices.add(mCarNightService);
Keun young Parkb5fab732019-10-03 10:51:12 -0700209 allServices.add(mFixedActivityService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700210 allServices.add(mInstrumentClusterService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700211 allServices.add(mSystemStateControllerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700212 allServices.add(mPerUserCarServiceHelper);
Justin Paupore44985ba2019-01-30 18:53:41 -0800213 allServices.add(mCarBluetoothService);
214 allServices.add(mCarProjectionService);
215 allServices.add(mCarDiagnosticService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700216 allServices.add(mCarStorageMonitoringService);
217 allServices.add(mCarConfigurationService);
Mark Tabrya8fce562019-01-16 16:24:01 -0800218 allServices.add(mVmsClientManager);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700219 allServices.add(mVmsSubscriberService);
220 allServices.add(mVmsPublisherService);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700221 allServices.add(mCarTrustedDeviceService);
Simon Dai527eb552019-02-12 13:06:15 -0800222 allServices.add(mCarMediaService);
Gregory Clarka63ba022018-06-07 16:42:12 -0700223 allServices.add(mCarLocationService);
Selim Gurunc8c82f62019-04-17 14:07:30 -0700224 allServices.add(mCarBugreportManagerService);
Ying Zheng86d1c3e2018-05-11 11:42:48 -0700225 mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]);
keunyoungca515072015-07-10 12:21:47 -0700226 }
227
Pavel Maltsevabd47232017-10-10 16:54:57 -0700228 @MainThread
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700229 void init() {
Serik Beketayev74debf22018-10-04 12:18:09 -0700230 mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL);
Steve Paikc302c7c2017-08-04 14:01:58 -0700231 traceBegin("VehicleHal.init");
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700232 mHal.init();
Steve Paikc302c7c2017-08-04 14:01:58 -0700233 traceEnd();
234 traceBegin("CarService.initAllServices");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800235 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700236 service.init();
237 }
Steve Paikc302c7c2017-08-04 14:01:58 -0700238 traceEnd();
Keun young Parkfd2afc92019-06-07 14:55:20 -0700239 mSystemInterface.reconfigureSecondaryDisplays();
keunyoungca515072015-07-10 12:21:47 -0700240 }
241
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700242 void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700243 // release done in opposite order from init
244 for (int i = mAllServices.length - 1; i >= 0; i--) {
245 mAllServices[i].release();
246 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700247 mHal.release();
keunyoung1ab8e182015-09-24 09:25:22 -0700248 }
249
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700250 void vehicleHalReconnected(IVehicle vehicle) {
Pavel Maltsevec83b632017-01-05 15:10:55 -0800251 mHal.vehicleHalReconnected(vehicle);
252 for (CarServiceBase service : mAllServices) {
253 service.vehicleHalReconnected();
254 }
255 }
256
keunyoungca515072015-07-10 12:21:47 -0700257 @Override
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700258 public void setCarServiceHelper(IBinder helper) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700259 assertCallingFromSystemProcess();
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700260 synchronized (this) {
261 mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper);
Steve Paik0f9fc002018-02-09 17:42:00 -0800262 mSystemInterface.setCarServiceHelper(mICarServiceHelper);
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700263 }
264 }
265
266 @Override
Keun-young Parkd462a912019-02-11 08:53:42 -0800267 public void setUserLockStatus(int userHandle, int unlocked) {
Pavel Maltsev17e81832019-04-04 14:38:41 -0700268 assertCallingFromSystemProcess();
269 mCarUserService.setUserLockStatus(userHandle, unlocked == 1);
Yabin Huang27712d72019-06-26 12:46:30 -0700270 mCarMediaService.setUserLockStatus(userHandle, unlocked == 1);
Pavel Maltsev17e81832019-04-04 14:38:41 -0700271 }
272
273 @Override
274 public void onSwitchUser(int userHandle) {
275 assertCallingFromSystemProcess();
276
277 Log.i(TAG, "Foreground user switched to " + userHandle);
278 mCarUserService.onSwitchUser(userHandle);
279 }
280
Jim Kayee5133162019-04-22 12:50:27 -0700281 static void assertCallingFromSystemProcess() {
Keun-young Parkd462a912019-02-11 08:53:42 -0800282 int uid = Binder.getCallingUid();
283 if (uid != Process.SYSTEM_UID) {
284 throw new SecurityException("Only allowed from system");
285 }
Keun-young Parkd462a912019-02-11 08:53:42 -0800286 }
287
Keun young Parkaabecd92019-05-03 17:31:27 -0700288 /**
289 * Assert if binder call is coming from system process like system server or if it is called
290 * from its own process even if it is not system. The latter can happen in test environment.
291 * Note that car service runs as system user but test like car service test will not.
292 */
293 static void assertCallingFromSystemProcessOrSelf() {
294 int uid = Binder.getCallingUid();
295 int pid = Binder.getCallingPid();
296 if (uid != Process.SYSTEM_UID && pid != Process.myPid()) {
297 throw new SecurityException("Only allowed from system or self");
298 }
299 }
300
Keun-young Parkd462a912019-02-11 08:53:42 -0800301 @Override
keunyoungca515072015-07-10 12:21:47 -0700302 public IBinder getCarService(String serviceName) {
303 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800304 case Car.AUDIO_SERVICE:
305 return mCarAudioService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700306 case Car.APP_FOCUS_SERVICE:
307 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800308 case Car.PACKAGE_SERVICE:
309 return mCarPackageManagerService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800310 case Car.DIAGNOSTIC_SERVICE:
Enrico Granatab3634e22017-05-05 18:02:31 -0700311 assertAnyDiagnosticPermission(mContext);
312 return mCarDiagnosticService;
Steve Paik388d7772018-02-12 10:54:51 -0800313 case Car.POWER_SERVICE:
314 assertPowerPermission(mContext);
315 return mCarPowerManagementService;
Steve Paik9ec53d72018-04-27 13:28:31 -0700316 case Car.CABIN_SERVICE:
317 case Car.HVAC_SERVICE:
318 case Car.INFO_SERVICE:
319 case Car.PROPERTY_SERVICE:
320 case Car.SENSOR_SERVICE:
321 case Car.VENDOR_EXTENSION_SERVICE:
322 return mCarPropertyService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800323 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700324 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700325 IInstrumentClusterNavigation navService =
326 mInstrumentClusterService.getNavigationService();
327 return navService == null ? null : navService.asBinder();
Pavel Maltsev905968c2017-07-16 19:48:57 -0700328 case Car.CAR_INSTRUMENT_CLUSTER_SERVICE:
329 assertClusterManagerPermission(mContext);
330 return mInstrumentClusterService.getManagerService();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800331 case Car.PROJECTION_SERVICE:
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800332 return mCarProjectionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800333 case Car.VMS_SUBSCRIBER_SERVICE:
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700334 assertVmsSubscriberPermission(mContext);
335 return mVmsSubscriberService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800336 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700337 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700338 synchronized (this) {
339 if (mCarTestService == null) {
340 mCarTestService = new CarTestService(mContext, this);
341 }
342 return mCarTestService;
343 }
344 }
Ram Periathiruvadi76a84892017-07-27 18:10:35 -0700345 case Car.BLUETOOTH_SERVICE:
346 return mCarBluetoothService;
Enrico Granata9a916d72017-09-19 14:33:08 -0700347 case Car.STORAGE_MONITORING_SERVICE:
Enrico Granata1172f882017-09-21 14:51:30 -0700348 assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING);
Enrico Granata9a916d72017-09-19 14:33:08 -0700349 return mCarStorageMonitoringService;
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800350 case Car.CAR_DRIVING_STATE_SERVICE:
351 assertDrivingStatePermission(mContext);
352 return mCarDrivingStateService;
353 case Car.CAR_UX_RESTRICTION_SERVICE:
354 return mCarUXRestrictionsService;
Anthony Chend4203d82018-05-16 16:21:52 -0700355 case Car.CAR_CONFIGURATION_SERVICE:
356 return mCarConfigurationService;
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800357 case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE:
358 assertTrustAgentEnrollmentPermission(mContext);
Ram Periathiruvadide0ca082019-03-20 11:16:44 -0700359 return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService();
Simon Dai527eb552019-02-12 13:06:15 -0800360 case Car.CAR_MEDIA_SERVICE:
361 return mCarMediaService;
Selim Gurunc8c82f62019-04-17 14:07:30 -0700362 case Car.CAR_BUGREPORT_SERVICE:
363 return mCarBugreportManagerService;
keunyoungca515072015-07-10 12:21:47 -0700364 default:
365 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
366 return null;
367 }
368 }
369
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800370 @Override
371 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700372 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800373 }
374
Keun-young Parka28d7b22016-02-29 16:54:29 -0800375 public CarServiceBase getCarInternalService(String serviceName) {
376 switch (serviceName) {
377 case INTERNAL_INPUT_SERVICE:
378 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700379 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
380 return mSystemActivityMonitoringService;
Mark Tabryccf43dc2019-11-21 15:07:36 -0800381 case INTERNAL_VMS_MANAGER:
382 return mVmsClientManager;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800383 default:
384 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
385 serviceName);
386 return null;
387 }
388 }
389
Mark Tabry8f5a5f72019-11-07 11:26:35 -0800390 CarStatsService getStatsService() {
391 return mCarStatsService;
392 }
393
keunyoung1ab8e182015-09-24 09:25:22 -0700394 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700395 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700396 }
397
Keun-young Parke31a8b22016-03-16 17:34:08 -0700398 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700399 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800400 }
401
Pavel Maltsev905968c2017-07-16 19:48:57 -0700402 public static void assertClusterManagerPermission(Context context) {
403 assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL);
404 }
405
Steve Paik388d7772018-02-12 10:54:51 -0800406 public static void assertPowerPermission(Context context) {
407 assertPermission(context, Car.PERMISSION_CAR_POWER);
408 }
409
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800410 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700411 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
412 }
413
Pavel Maltsev079873b2019-02-25 12:15:09 -0800414 /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */
415 public static void assertProjectionStatusPermission(Context context) {
416 assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS);
417 }
418
Enrico Granata3c7a6662017-02-23 18:07:59 -0800419 public static void assertAnyDiagnosticPermission(Context context) {
420 assertAnyPermission(context,
Enrico Granataae25b922017-07-07 11:28:15 -0700421 Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL,
Enrico Granata3c7a6662017-02-23 18:07:59 -0800422 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
423 }
424
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -0800425 public static void assertDrivingStatePermission(Context context) {
426 assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE);
427 }
428
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800429 public static void assertVmsPublisherPermission(Context context) {
430 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
431 }
432
Antonio Cortese4619c72017-02-02 07:53:27 -0800433 public static void assertVmsSubscriberPermission(Context context) {
434 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
435 }
436
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800437 /**
438 * Ensures the caller has the permission to enroll a Trust Agent.
Ram Periathiruvadi194ce1b2019-01-14 09:42:12 -0800439 */
440 public static void assertTrustAgentEnrollmentPermission(Context context) {
441 assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST);
442 }
443
Steve Paik461ecc62016-06-08 15:28:32 -0700444 public static void assertPermission(Context context, String permission) {
445 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
446 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800447 }
448 }
449
Steve Paik9ec53d72018-04-27 13:28:31 -0700450 /**
451 * Checks to see if the caller has a permission.
Steve Paik9ec53d72018-04-27 13:28:31 -0700452 *
453 * @return boolean TRUE if caller has the permission.
454 */
455 public static boolean hasPermission(Context context, String permission) {
456 return context.checkCallingOrSelfPermission(permission)
457 == PackageManager.PERMISSION_GRANTED;
458 }
459
Enrico Granata3c7a6662017-02-23 18:07:59 -0800460 public static void assertAnyPermission(Context context, String... permissions) {
461 for (String permission : permissions) {
462 if (context.checkCallingOrSelfPermission(permission) ==
463 PackageManager.PERMISSION_GRANTED) {
464 return;
465 }
466 }
467 throw new SecurityException("requires any of " + Arrays.toString(permissions));
468 }
469
Enrico Granatae8056ca2018-04-03 13:19:52 -0700470 @Override
471 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
472 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Anthony Chen12aec302018-04-25 16:41:48 -0700473 != PackageManager.PERMISSION_GRANTED) {
Enrico Granatae8056ca2018-04-03 13:19:52 -0700474 writer.println("Permission Denial: can't dump CarService from from pid="
Anthony Chen12aec302018-04-25 16:41:48 -0700475 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
476 + " without permission " + android.Manifest.permission.DUMP);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700477 return;
keunyounga3b28d82015-08-25 13:05:15 -0700478 }
Enrico Granatae8056ca2018-04-03 13:19:52 -0700479
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700480 if (args == null || args.length == 0 || (args.length > 0 && "-a".equals(args[0]))) {
481 writer.println("*Dump car service*");
Enrico Granatae8056ca2018-04-03 13:19:52 -0700482 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
483 writer.println("*Dump all services*");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700484
Mark Tabryc87043b2019-10-17 10:18:32 -0700485 dumpAllServices(writer);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700486
Enrico Granatae8056ca2018-04-03 13:19:52 -0700487 writer.println("*Dump Vehicle HAL*");
488 writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName);
489 try {
490 // TODO dump all feature flags by creating a dumpable interface
491 mHal.dump(writer);
492 } catch (Exception e) {
493 writer.println("Failed dumping: " + mHal.getClass().getName());
494 e.printStackTrace(writer);
495 }
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700496 } else if ("--metrics".equals(args[0])) {
Mark Tabryc87043b2019-10-17 10:18:32 -0700497 // Strip the --metrics flag when passing dumpsys arguments to CarStatsService
Mark Tabry7c9c0222019-12-03 11:03:48 -0800498 // allowing for nested flag selection
Mark Tabryc87043b2019-10-17 10:18:32 -0700499 mCarStatsService.dump(fd, writer, Arrays.copyOfRange(args, 1, args.length));
Mark Tabryb588d2e2019-09-12 10:50:11 -0700500 } else if ("--vms-hal".equals(args[0])) {
501 mHal.getVmsHal().dumpMetrics(fd);
Enrico Granatae8056ca2018-04-03 13:19:52 -0700502 } else if (Build.IS_USERDEBUG || Build.IS_ENG) {
503 execShellCmd(args, writer);
504 } else {
505 writer.println("Commands not supported in " + Build.TYPE);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800506 }
507 }
508
Mark Tabryc87043b2019-10-17 10:18:32 -0700509 private void dumpAllServices(PrintWriter writer) {
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700510 for (CarServiceBase service : mAllServices) {
Mark Tabryc87043b2019-10-17 10:18:32 -0700511 dumpService(service, writer);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700512 }
513 if (mCarTestService != null) {
Mark Tabryc87043b2019-10-17 10:18:32 -0700514 dumpService(mCarTestService, writer);
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700515 }
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700516 }
517
Mark Tabryc87043b2019-10-17 10:18:32 -0700518 private void dumpService(CarServiceBase service, PrintWriter writer) {
Brad Stenninged3d59b2017-11-09 16:15:17 -0800519 try {
Mark Tabryc87043b2019-10-17 10:18:32 -0700520 service.dump(writer);
Brad Stenninged3d59b2017-11-09 16:15:17 -0800521 } catch (Exception e) {
522 writer.println("Failed dumping: " + service.getClass().getName());
523 e.printStackTrace(writer);
524 }
keunyoungcc449f72015-08-12 10:46:27 -0700525 }
Yao Chene33f07e2016-07-26 12:02:51 -0700526
527 void execShellCmd(String[] args, PrintWriter writer) {
528 new CarShellCommand().exec(args, writer);
529 }
530
Pavel Maltsevabd47232017-10-10 16:54:57 -0700531 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700532 private void traceBegin(String name) {
Steve Paikc302c7c2017-08-04 14:01:58 -0700533 Slog.i(TAG, name);
534 mBootTiming.traceBegin(name);
535 }
536
Pavel Maltsevabd47232017-10-10 16:54:57 -0700537 @MainThread
Serik Beketayev74debf22018-10-04 12:18:09 -0700538 private void traceEnd() {
Steve Paikc302c7c2017-08-04 14:01:58 -0700539 mBootTiming.traceEnd();
540 }
541
Yao Chene33f07e2016-07-26 12:02:51 -0700542 private class CarShellCommand {
543 private static final String COMMAND_HELP = "-h";
544 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800545 private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event";
Kai4b098cf2019-06-05 15:03:28 -0700546 private static final String COMMAND_INJECT_ERROR_EVENT = "inject-error-event";
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800547 private static final String COMMAND_ENABLE_UXR = "enable-uxr";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800548 private static final String COMMAND_GARAGE_MODE = "garage-mode";
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800549 private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities";
Kaidd4ef5a2019-03-04 14:07:26 -0800550 private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig";
Kai29fba112019-04-22 18:37:38 -0700551 private static final String COMMAND_GET_PROPERTY_VALUE = "get-property-value";
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700552 private static final String COMMAND_PROJECTION_AP_TETHERING = "projection-tethering";
Pavel Maltsev48a31942019-03-03 22:08:28 -0800553 private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode";
Jim Kayed76c2742019-04-02 11:33:27 -0700554 private static final String COMMAND_RESUME = "resume";
555 private static final String COMMAND_SUSPEND = "suspend";
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700556 private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device";
557 private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices";
Keun young Park69a21042019-10-15 10:34:11 -0700558 private static final String COMMAND_START_FIXED_ACTIVITY_MODE = "start-fixed-activity-mode";
559 private static final String COMMAND_STOP_FIXED_ACTIVITY_MODE = "stop-fixed-activity-mode";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800560
Yao Chene33f07e2016-07-26 12:02:51 -0700561 private static final String PARAM_DAY_MODE = "day";
562 private static final String PARAM_NIGHT_MODE = "night";
563 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800564 private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0";
Bryan Eylera32a7c12018-02-27 15:40:00 -0800565 private static final String PARAM_ON_MODE = "on";
566 private static final String PARAM_OFF_MODE = "off";
567 private static final String PARAM_QUERY_MODE = "query";
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800568
Yao Chene33f07e2016-07-26 12:02:51 -0700569
570 private void dumpHelp(PrintWriter pw) {
571 pw.println("Car service commands:");
572 pw.println("\t-h");
573 pw.println("\t Print this help text.");
574 pw.println("\tday-night-mode [day|night|sensor]");
575 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800576 pw.println("\tinject-vhal-event property [zone] data(can be comma separated list)");
Jim Kayef10b7d82019-02-26 12:53:22 -0800577 pw.println("\t Inject a vehicle property for testing.");
Kai4b098cf2019-06-05 15:03:28 -0700578 pw.println("\tinject-error-event property zone errorCode");
579 pw.println("\t Inject an error event from VHAL for testing.");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700580 pw.println("\tenable-uxr true|false");
581 pw.println("\t Enable/Disable UX restrictions and App blocking.");
Bryan Eylera32a7c12018-02-27 15:40:00 -0800582 pw.println("\tgarage-mode [on|off|query]");
583 pw.println("\t Force into garage mode or check status.");
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800584 pw.println("\tget-do-activities pkgname");
Jim Kayef10b7d82019-02-26 12:53:22 -0800585 pw.println("\t Get Distraction Optimized activities in given package.");
Kaidd4ef5a2019-03-04 14:07:26 -0800586 pw.println("\tget-carpropertyconfig [propertyId]");
587 pw.println("\t Get a CarPropertyConfig by Id in Hex or list all CarPropertyConfigs");
Kai29fba112019-04-22 18:37:38 -0700588 pw.println("\tget-property-value [propertyId] [areaId]");
589 pw.println("\t Get a vehicle property value by property id in Hex and areaId");
590 pw.println("\t or list all property values for all areaId");
Jim Kayed76c2742019-04-02 11:33:27 -0700591 pw.println("\tsuspend");
592 pw.println("\t Suspend the system to Deep Sleep.");
593 pw.println("\tresume");
594 pw.println("\t Wake the system up after a 'suspend.'");
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700595 pw.println("\tenable-trusted-device true|false");
596 pw.println("\t Enable/Disable Trusted device feature.");
597 pw.println("\tremove-trusted-devices");
598 pw.println("\t Remove all trusted devices for the current foreground user.");
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700599 pw.println("\tprojection-tethering [true|false]");
600 pw.println("\t Whether tethering should be used when creating access point for"
601 + " wireless projection");
Andrew T Nguyena9228c72019-06-12 11:28:42 -0700602 pw.println("\t--metrics");
603 pw.println("\t When used with dumpsys, only metrics will be in the dumpsys output.");
Keun young Park69a21042019-10-15 10:34:11 -0700604 pw.println("\tstart-fixed-activity displayId packageName activityName");
605 pw.println("\t Start an Activity the specified display as fixed mode");
606 pw.println("\tstop-fixed-mode displayId");
607 pw.println("\t Stop fixed Activity mode for the given display. "
608 + "The Activity will not be restarted upon crash.");
Yao Chene33f07e2016-07-26 12:02:51 -0700609 }
610
611 public void exec(String[] args, PrintWriter writer) {
612 String arg = args[0];
613 switch (arg) {
614 case COMMAND_HELP:
615 dumpHelp(writer);
616 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800617 case COMMAND_DAY_NIGHT_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800618 String value = args.length < 2 ? "" : args[1];
Yao Chene33f07e2016-07-26 12:02:51 -0700619 forceDayNightMode(value, writer);
620 break;
Bryan Eylera32a7c12018-02-27 15:40:00 -0800621 }
622 case COMMAND_GARAGE_MODE: {
Jim Kayef10b7d82019-02-26 12:53:22 -0800623 String value = args.length < 2 ? "" : args[1];
Bryan Eylera32a7c12018-02-27 15:40:00 -0800624 forceGarageMode(value, writer);
625 break;
626 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800627 case COMMAND_INJECT_VHAL_EVENT:
628 String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL;
629 String data;
Jim Kayef10b7d82019-02-26 12:53:22 -0800630 if (args.length != 3 && args.length != 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800631 writer.println("Incorrect number of arguments.");
632 dumpHelp(writer);
633 break;
Jim Kayef10b7d82019-02-26 12:53:22 -0800634 } else if (args.length == 4) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800635 // Zoned
636 zone = args[2];
637 data = args[3];
638 } else {
639 // Global
640 data = args[2];
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800641 }
Kai4b098cf2019-06-05 15:03:28 -0700642 injectVhalEvent(args[1], zone, data, false, writer);
643 break;
644 case COMMAND_INJECT_ERROR_EVENT:
645 if (args.length != 4) {
646 writer.println("Incorrect number of arguments");
647 dumpHelp(writer);
648 break;
649 }
650 String errorAreaId = args[2];
651 String errorCode = args[3];
652 injectVhalEvent(args[1], errorAreaId, errorCode, true, writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800653 break;
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800654 case COMMAND_ENABLE_UXR:
Jim Kayef10b7d82019-02-26 12:53:22 -0800655 if (args.length != 2) {
Ram Periathiruvadibf0eab72018-02-06 12:32:43 -0800656 writer.println("Incorrect number of arguments");
657 dumpHelp(writer);
658 break;
659 }
660 boolean enableBlocking = Boolean.valueOf(args[1]);
661 if (mCarPackageManagerService != null) {
662 mCarPackageManagerService.setEnableActivityBlocking(enableBlocking);
663 }
664 break;
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800665 case COMMAND_GET_DO_ACTIVITIES:
Jim Kayef10b7d82019-02-26 12:53:22 -0800666 if (args.length != 2) {
Ram Periathiruvadi38388302018-02-22 16:42:49 -0800667 writer.println("Incorrect number of arguments");
668 dumpHelp(writer);
669 break;
670 }
671 String pkgName = args[1].toLowerCase();
672 if (mCarPackageManagerService != null) {
673 String[] doActivities =
674 mCarPackageManagerService.getDistractionOptimizedActivities(
675 pkgName);
676 if (doActivities != null) {
677 writer.println("DO Activities for " + pkgName);
678 for (String a : doActivities) {
679 writer.println(a);
680 }
681 } else {
682 writer.println("No DO Activities for " + pkgName);
683 }
684 }
685 break;
Kaidd4ef5a2019-03-04 14:07:26 -0800686 case COMMAND_GET_CARPROPERTYCONFIG:
687 String propertyId = args.length < 2 ? "" : args[1];
688 mHal.dumpPropertyConfigs(writer, propertyId);
689 break;
Kai29fba112019-04-22 18:37:38 -0700690 case COMMAND_GET_PROPERTY_VALUE:
691 String propId = args.length < 2 ? "" : args[1];
692 String areaId = args.length < 3 ? "" : args[2];
693 mHal.dumpPropertyValueByCommend(writer, propId, areaId);
694 break;
Pavel Maltsev48a31942019-03-03 22:08:28 -0800695 case COMMAND_PROJECTION_UI_MODE:
696 if (args.length != 2) {
697 writer.println("Incorrect number of arguments");
698 dumpHelp(writer);
699 break;
700 }
701 mCarProjectionService.setUiMode(Integer.valueOf(args[1]));
Pavel Maltsevd6961f62019-03-26 10:22:31 -0700702 break;
Pavel Maltsev371d97f2019-05-20 14:51:31 -0700703 case COMMAND_PROJECTION_AP_TETHERING:
704 if (args.length != 2) {
705 writer.println("Incorrect number of arguments");
706 dumpHelp(writer);
707 break;
708 }
709 mCarProjectionService.setAccessPointTethering(Boolean.valueOf(args[1]));
710 break;
Jim Kayed76c2742019-04-02 11:33:27 -0700711 case COMMAND_RESUME:
712 mCarPowerManagementService.forceSimulatedResume();
713 writer.println("Resume: Simulating resuming from Deep Sleep");
714 break;
715 case COMMAND_SUSPEND:
716 mCarPowerManagementService.forceSimulatedSuspend();
717 writer.println("Resume: Simulating powering down to Deep Sleep");
718 break;
Ram Periathiruvadid26a3fb2019-04-15 14:48:23 -0700719 case COMMAND_ENABLE_TRUSTED_DEVICE:
720 if (args.length != 2) {
721 writer.println("Incorrect number of arguments");
722 dumpHelp(writer);
723 break;
724 }
725 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
726 .setTrustedDeviceEnrollmentEnabled(Boolean.valueOf(args[1]));
727 mCarTrustedDeviceService.getCarTrustAgentUnlockService()
728 .setTrustedDeviceUnlockEnabled(Boolean.valueOf(args[1]));
729 break;
730 case COMMAND_REMOVE_TRUSTED_DEVICES:
731 mCarTrustedDeviceService.getCarTrustAgentEnrollmentService()
732 .removeAllTrustedDevices(
733 mUserManagerHelper.getCurrentForegroundUserId());
734 break;
Keun young Park69a21042019-10-15 10:34:11 -0700735 case COMMAND_START_FIXED_ACTIVITY_MODE:
736 handleStartFixedActivity(args, writer);
737 break;
738 case COMMAND_STOP_FIXED_ACTIVITY_MODE:
739 handleStopFixedMode(args, writer);
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
Keun young Park69a21042019-10-15 10:34:11 -0700747 private void handleStartFixedActivity(String[] args, PrintWriter writer) {
748 if (args.length != 4) {
749 writer.println("Incorrect number of arguments");
750 dumpHelp(writer);
751 return;
752 }
753 int displayId;
754 try {
755 displayId = Integer.parseInt(args[1]);
756 } catch (NumberFormatException e) {
757 writer.println("Wrong display id:" + args[1]);
758 return;
759 }
760 String packageName = args[2];
761 String activityName = args[3];
762 Intent intent = new Intent();
763 intent.setComponent(new ComponentName(packageName, activityName));
764 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
765 ActivityOptions options = ActivityOptions.makeBasic();
766 options.setLaunchDisplayId(displayId);
767 if (!mFixedActivityService.startFixedActivityModeForDisplayAndUser(intent, options,
768 displayId, ActivityManager.getCurrentUser())) {
769 writer.println("Failed to start");
770 return;
771 }
772 writer.println("Succeeded");
773 }
774
775 private void handleStopFixedMode(String[] args, PrintWriter writer) {
776 if (args.length != 2) {
777 writer.println("Incorrect number of arguments");
778 dumpHelp(writer);
779 return;
780 }
781 int displayId;
782 try {
783 displayId = Integer.parseInt(args[1]);
784 } catch (NumberFormatException e) {
785 writer.println("Wrong display id:" + args[1]);
786 return;
787 }
788 mFixedActivityService.stopFixedActivityMode(displayId);
789 }
790
Yao Chene33f07e2016-07-26 12:02:51 -0700791 private void forceDayNightMode(String arg, PrintWriter writer) {
792 int mode;
793 switch (arg) {
794 case PARAM_DAY_MODE:
795 mode = CarNightService.FORCED_DAY_MODE;
796 break;
797 case PARAM_NIGHT_MODE:
798 mode = CarNightService.FORCED_NIGHT_MODE;
799 break;
800 case PARAM_SENSOR_MODE:
801 mode = CarNightService.FORCED_SENSOR_MODE;
802 break;
803 default:
804 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
805 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
806 return;
807 }
808 int current = mCarNightService.forceDayNightMode(mode);
809 String currentMode = null;
810 switch (current) {
811 case UiModeManager.MODE_NIGHT_AUTO:
812 currentMode = PARAM_SENSOR_MODE;
813 break;
814 case UiModeManager.MODE_NIGHT_YES:
815 currentMode = PARAM_NIGHT_MODE;
816 break;
817 case UiModeManager.MODE_NIGHT_NO:
818 currentMode = PARAM_DAY_MODE;
819 break;
820 }
821 writer.println("DayNightMode changed to: " + currentMode);
822 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800823
Bryan Eylera32a7c12018-02-27 15:40:00 -0800824 private void forceGarageMode(String arg, PrintWriter writer) {
825 switch (arg) {
826 case PARAM_ON_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700827 mGarageModeService.forceStartGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -0700828 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -0800829 break;
830 case PARAM_OFF_MODE:
Serik Beketayeve0e7ff22018-07-31 21:04:12 -0700831 mGarageModeService.stopAndResetGarageMode();
Jim Kaye1b5e6182019-05-24 15:48:32 -0700832 writer.println("Garage mode: " + mGarageModeService.isGarageModeActive());
Bryan Eylera32a7c12018-02-27 15:40:00 -0800833 break;
834 case PARAM_QUERY_MODE:
Jim Kaye1b5e6182019-05-24 15:48:32 -0700835 mGarageModeService.dump(writer);
Bryan Eylera32a7c12018-02-27 15:40:00 -0800836 break;
837 default:
838 writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|"
839 + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE);
Bryan Eylera32a7c12018-02-27 15:40:00 -0800840 }
Bryan Eylera32a7c12018-02-27 15:40:00 -0800841 }
842
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800843 /**
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800844 * Inject a fake VHAL event
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800845 *
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800846 * @param property the Vehicle property Id as defined in the HAL
847 * @param zone Zone that this event services
Kai4b098cf2019-06-05 15:03:28 -0700848 * @param isErrorEvent indicates the type of event
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800849 * @param value Data value of the event
850 * @param writer PrintWriter
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800851 */
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800852 private void injectVhalEvent(String property, String zone, String value,
Kai4b098cf2019-06-05 15:03:28 -0700853 boolean isErrorEvent, PrintWriter writer) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800854 if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) {
855 if (!isPropertyAreaTypeGlobal(property)) {
856 writer.println("Property area type inconsistent with given zone");
857 return;
858 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800859 }
860 try {
Kai4b098cf2019-06-05 15:03:28 -0700861 if (isErrorEvent) {
862 mHal.injectOnPropertySetError(property, zone, value);
863 } else {
864 mHal.injectVhalEvent(property, zone, value);
865 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800866 } catch (NumberFormatException e) {
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800867 writer.println("Invalid property Id zone Id or value" + e);
868 dumpHelp(writer);
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800869 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800870 }
871
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800872 // Check if the given property is global
873 private boolean isPropertyAreaTypeGlobal(String property) {
874 if (property == null) {
875 return false;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800876 }
Ram Periathiruvadi5cd00cb2018-02-12 13:49:50 -0800877 return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800878 }
Yao Chene33f07e2016-07-26 12:02:51 -0700879 }
kevinjm55822c42018-08-15 11:26:00 -0700880}