keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.car; |
| 18 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 19 | import android.annotation.MainThread; |
Keun young Park | f3523cd | 2019-04-08 10:09:17 -0700 | [diff] [blame^] | 20 | import android.app.ActivityManager; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 21 | import android.app.UiModeManager; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 22 | import android.car.Car; |
| 23 | import android.car.ICar; |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 24 | import android.car.cluster.renderer.IInstrumentClusterNavigation; |
Ying Zheng | 9fc9940 | 2018-09-19 14:23:59 -0700 | [diff] [blame] | 25 | import android.car.userlib.CarUserManagerHelper; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 26 | import android.content.Context; |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
Keun young Park | f3523cd | 2019-04-08 10:09:17 -0700 | [diff] [blame^] | 28 | import android.content.res.Resources; |
Pavel Maltsev | cfe9310 | 2017-02-02 12:38:08 -0800 | [diff] [blame] | 29 | import android.hardware.automotive.vehicle.V2_0.IVehicle; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 30 | import android.hardware.automotive.vehicle.V2_0.VehicleArea; |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 31 | import android.os.Binder; |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 32 | import android.os.Build; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 33 | import android.os.IBinder; |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 34 | import android.os.Process; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 35 | import android.os.Trace; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 36 | import android.util.Log; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 37 | import android.util.Slog; |
Keun-young Park | 4a79a38 | 2017-08-10 18:19:14 -0700 | [diff] [blame] | 38 | import android.util.TimingsTraceLog; |
Gregory Clark | 26fa601 | 2018-03-14 18:38:56 -0700 | [diff] [blame] | 39 | |
Hongwei Wang | 3854909 | 2018-08-22 12:32:42 -0700 | [diff] [blame] | 40 | import com.android.car.audio.CarAudioService; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 41 | import com.android.car.cluster.InstrumentClusterService; |
Serik Beketayev | 06a6668 | 2018-06-12 16:54:29 -0700 | [diff] [blame] | 42 | import com.android.car.garagemode.GarageModeService; |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 43 | import com.android.car.hal.VehicleHal; |
Antonio Cortes | c52d5f9 | 2017-02-06 08:47:38 -0800 | [diff] [blame] | 44 | import com.android.car.internal.FeatureConfiguration; |
Keun-young Park | 4aeb4bf | 2015-12-08 18:31:33 -0800 | [diff] [blame] | 45 | import com.android.car.pm.CarPackageManagerService; |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 46 | import com.android.car.systeminterface.SystemInterface; |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 47 | import com.android.car.trust.CarTrustedDeviceService; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 48 | import com.android.car.user.CarUserService; |
Mark Tabry | 76cfaaa | 2019-02-01 14:28:30 -0800 | [diff] [blame] | 49 | import com.android.car.vms.VmsBrokerService; |
Mark Tabry | a8fce56 | 2019-01-16 16:24:01 -0800 | [diff] [blame] | 50 | import com.android.car.vms.VmsClientManager; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 51 | import com.android.internal.annotations.GuardedBy; |
Steve Paik | 1d8bea2 | 2018-02-03 01:54:06 +0000 | [diff] [blame] | 52 | import com.android.internal.car.ICarServiceHelper; |
Gregory Clark | 26fa601 | 2018-03-14 18:38:56 -0700 | [diff] [blame] | 53 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 54 | import java.io.FileDescriptor; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 55 | import java.io.PrintWriter; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 56 | import java.util.ArrayList; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 57 | import java.util.Arrays; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 58 | import java.util.List; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 59 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 60 | public class ICarImpl extends ICar.Stub { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 61 | |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 62 | public static final String INTERNAL_INPUT_SERVICE = "internal_input"; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 63 | public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE = |
| 64 | "system_activity_monitoring"; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 65 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 66 | private final Context mContext; |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 67 | private final VehicleHal mHal; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 68 | |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 69 | private final SystemInterface mSystemInterface; |
| 70 | |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 71 | private final SystemActivityMonitoringService mSystemActivityMonitoringService; |
keunyoung | 4b0212c | 2015-10-29 17:11:57 -0700 | [diff] [blame] | 72 | private final CarPowerManagementService mCarPowerManagementService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 73 | private final CarPackageManagerService mCarPackageManagerService; |
| 74 | private final CarInputService mCarInputService; |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 75 | private final CarDrivingStateService mCarDrivingStateService; |
Ram Periathiruvadi | 4526a43 | 2018-01-24 13:00:54 -0800 | [diff] [blame] | 76 | private final CarUxRestrictionsManagerService mCarUXRestrictionsService; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 77 | private final CarAudioService mCarAudioService; |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 78 | private final CarProjectionService mCarProjectionService; |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 79 | private final CarPropertyService mCarPropertyService; |
Joseph Pirozzo | 317343d | 2016-01-25 10:22:37 -0800 | [diff] [blame] | 80 | private final CarNightService mCarNightService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 81 | private final AppFocusService mAppFocusService; |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 82 | private final GarageModeService mGarageModeService; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 83 | private final InstrumentClusterService mInstrumentClusterService; |
Gregory Clark | d813606 | 2017-12-11 14:27:53 -0800 | [diff] [blame] | 84 | private final CarLocationService mCarLocationService; |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 85 | private final SystemStateControllerService mSystemStateControllerService; |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 86 | private final CarBluetoothService mCarBluetoothService; |
Ram Periathiruvadi | acb6024 | 2017-04-13 16:19:09 -0700 | [diff] [blame] | 87 | private final PerUserCarServiceHelper mPerUserCarServiceHelper; |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 88 | private final CarDiagnosticService mCarDiagnosticService; |
| 89 | private final CarStorageMonitoringService mCarStorageMonitoringService; |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 90 | private final CarConfigurationService mCarConfigurationService; |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 91 | private final CarTrustedDeviceService mCarTrustedDeviceService; |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 92 | private final CarMediaService mCarMediaService; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 93 | private final CarUserManagerHelper mUserManagerHelper; |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 94 | private final CarUserService mCarUserService; |
Mark Tabry | a8fce56 | 2019-01-16 16:24:01 -0800 | [diff] [blame] | 95 | private final VmsClientManager mVmsClientManager; |
Mark Tabry | 76cfaaa | 2019-02-01 14:28:30 -0800 | [diff] [blame] | 96 | private final VmsBrokerService mVmsBrokerService; |
Mark Tabry | a8fce56 | 2019-01-16 16:24:01 -0800 | [diff] [blame] | 97 | private final VmsSubscriberService mVmsSubscriberService; |
| 98 | private final VmsPublisherService mVmsPublisherService; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 99 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 100 | private final CarServiceBase[] mAllServices; |
| 101 | |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 102 | private static final String TAG = "ICarImpl"; |
| 103 | private static final String VHAL_TIMING_TAG = "VehicleHalTiming"; |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 104 | |
| 105 | private TimingsTraceLog mBootTiming; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 106 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 107 | /** Test only service. Populate it only when necessary. */ |
| 108 | @GuardedBy("this") |
| 109 | private CarTestService mCarTestService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 110 | |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 111 | @GuardedBy("this") |
| 112 | private ICarServiceHelper mICarServiceHelper; |
| 113 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 114 | private final String mVehicleInterfaceName; |
| 115 | |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 116 | public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface, |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 117 | CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 118 | mContext = serviceContext; |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame] | 119 | mSystemInterface = systemInterface; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 120 | mHal = new VehicleHal(vehicle); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 121 | mVehicleInterfaceName = vehicleInterfaceName; |
Yao, Yuxing | 0811d5a | 2018-11-29 16:18:53 -0800 | [diff] [blame] | 122 | mUserManagerHelper = new CarUserManagerHelper(serviceContext); |
Keun young Park | f3523cd | 2019-04-08 10:09:17 -0700 | [diff] [blame^] | 123 | final Resources res = mContext.getResources(); |
| 124 | final int maxRunningUsers = res.getInteger( |
| 125 | com.android.internal.R.integer.config_multiuserMaxRunningUsers); |
| 126 | mCarUserService = new CarUserService(serviceContext, mUserManagerHelper, |
| 127 | ActivityManager.getService(), maxRunningUsers); |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 128 | mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext); |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 129 | mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(), |
Keun young Park | 9b3f266 | 2019-03-19 10:30:25 -0700 | [diff] [blame] | 130 | systemInterface, mUserManagerHelper); |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 131 | mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal()); |
| 132 | mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService); |
Ram Periathiruvadi | 4526a43 | 2018-01-24 13:00:54 -0800 | [diff] [blame] | 133 | mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext, |
Yao, Yuxing | 9bfb749 | 2019-02-15 11:53:34 -0800 | [diff] [blame] | 134 | mCarDrivingStateService, mCarPropertyService); |
Ram Periathiruvadi | 2da6d0e | 2018-01-26 18:02:10 -0800 | [diff] [blame] | 135 | mCarPackageManagerService = new CarPackageManagerService(serviceContext, |
| 136 | mCarUXRestrictionsService, |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 137 | mSystemActivityMonitoringService); |
Justin Paupore | 44985ba | 2019-01-30 18:53:41 -0800 | [diff] [blame] | 138 | mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext); |
| 139 | mCarBluetoothService = new CarBluetoothService(serviceContext, mCarPropertyService, |
| 140 | mPerUserCarServiceHelper, mCarUXRestrictionsService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 141 | mCarInputService = new CarInputService(serviceContext, mHal.getInputHal()); |
Justin Paupore | 44985ba | 2019-01-30 18:53:41 -0800 | [diff] [blame] | 142 | mCarProjectionService = new CarProjectionService( |
Pavel Maltsev | 079873b | 2019-02-25 12:15:09 -0800 | [diff] [blame] | 143 | serviceContext, null /* handler */, mCarInputService, mCarBluetoothService); |
Serik Beketayev | c6ab8be | 2018-08-28 21:20:53 -0700 | [diff] [blame] | 144 | mGarageModeService = new GarageModeService(mContext); |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 145 | mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService); |
Hongwei Wang | 3055723 | 2018-01-02 10:25:08 -0800 | [diff] [blame] | 146 | mCarAudioService = new CarAudioService(serviceContext); |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 147 | mCarNightService = new CarNightService(serviceContext, mCarPropertyService); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 148 | mInstrumentClusterService = new InstrumentClusterService(serviceContext, |
Pavel Maltsev | 03cf60c | 2016-06-27 15:11:51 -0700 | [diff] [blame] | 149 | mAppFocusService, mCarInputService); |
Serik Beketayev | f9f2ef0 | 2018-09-06 12:37:02 -0700 | [diff] [blame] | 150 | mSystemStateControllerService = new SystemStateControllerService( |
| 151 | serviceContext, mCarAudioService, this); |
Mark Tabry | 76cfaaa | 2019-02-01 14:28:30 -0800 | [diff] [blame] | 152 | mVmsBrokerService = new VmsBrokerService(); |
Mark Tabry | 1534c06 | 2019-03-29 01:30:49 -0700 | [diff] [blame] | 153 | mVmsClientManager = new VmsClientManager( |
Mark Tabry | 4143756 | 2019-04-04 10:37:33 -0700 | [diff] [blame] | 154 | serviceContext, mCarUserService, mUserManagerHelper, mHal.getVmsHal()); |
Mark Tabry | 76cfaaa | 2019-02-01 14:28:30 -0800 | [diff] [blame] | 155 | mVmsSubscriberService = new VmsSubscriberService( |
| 156 | serviceContext, mVmsBrokerService, mHal.getVmsHal()); |
| 157 | mVmsPublisherService = new VmsPublisherService( |
Mark Tabry | 1534c06 | 2019-03-29 01:30:49 -0700 | [diff] [blame] | 158 | serviceContext, mVmsBrokerService, mVmsClientManager); |
Enrico Granata | b3634e2 | 2017-05-05 18:02:31 -0700 | [diff] [blame] | 159 | mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal()); |
Enrico Granata | 517a1e0 | 2017-09-20 16:15:50 -0700 | [diff] [blame] | 160 | mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext, |
| 161 | systemInterface); |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 162 | mCarConfigurationService = |
| 163 | new CarConfigurationService(serviceContext, new JsonReaderImpl()); |
Gregory Clark | a440e81 | 2019-02-14 16:05:51 -0800 | [diff] [blame] | 164 | mCarLocationService = new CarLocationService(mContext, mCarPropertyService, |
| 165 | mUserManagerHelper); |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 166 | mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext); |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 167 | mCarMediaService = new CarMediaService(serviceContext); |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 168 | |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 169 | CarLocalServices.addService(CarUserService.class, mCarUserService); |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 170 | Log.d(TAG, "Adding CarTrustedDeviceService"); |
| 171 | CarLocalServices.addService(CarTrustedDeviceService.class, |
| 172 | mCarTrustedDeviceService); |
Gregory Clark | a440e81 | 2019-02-14 16:05:51 -0800 | [diff] [blame] | 173 | CarLocalServices.addService(SystemInterface.class, mSystemInterface); |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 174 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 175 | // Be careful with order. Service depending on other service should be inited later. |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 176 | List<CarServiceBase> allServices = new ArrayList<>(); |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 177 | allServices.add(mCarUserService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 178 | allServices.add(mSystemActivityMonitoringService); |
| 179 | allServices.add(mCarPowerManagementService); |
| 180 | allServices.add(mCarPropertyService); |
| 181 | allServices.add(mCarDrivingStateService); |
| 182 | allServices.add(mCarUXRestrictionsService); |
| 183 | allServices.add(mCarPackageManagerService); |
| 184 | allServices.add(mCarInputService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 185 | allServices.add(mGarageModeService); |
| 186 | allServices.add(mAppFocusService); |
| 187 | allServices.add(mCarAudioService); |
| 188 | allServices.add(mCarNightService); |
| 189 | allServices.add(mInstrumentClusterService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 190 | allServices.add(mSystemStateControllerService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 191 | allServices.add(mPerUserCarServiceHelper); |
Justin Paupore | 44985ba | 2019-01-30 18:53:41 -0800 | [diff] [blame] | 192 | allServices.add(mCarBluetoothService); |
| 193 | allServices.add(mCarProjectionService); |
| 194 | allServices.add(mCarDiagnosticService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 195 | allServices.add(mCarStorageMonitoringService); |
| 196 | allServices.add(mCarConfigurationService); |
Mark Tabry | a8fce56 | 2019-01-16 16:24:01 -0800 | [diff] [blame] | 197 | allServices.add(mVmsClientManager); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 198 | allServices.add(mVmsSubscriberService); |
| 199 | allServices.add(mVmsPublisherService); |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 200 | allServices.add(mCarTrustedDeviceService); |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 201 | allServices.add(mCarMediaService); |
Gregory Clark | a63ba02 | 2018-06-07 16:42:12 -0700 | [diff] [blame] | 202 | allServices.add(mCarLocationService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 203 | mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 206 | @MainThread |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 207 | void init() { |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 208 | mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL); |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 209 | traceBegin("VehicleHal.init"); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 210 | mHal.init(); |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 211 | traceEnd(); |
| 212 | traceBegin("CarService.initAllServices"); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 213 | for (CarServiceBase service : mAllServices) { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 214 | service.init(); |
| 215 | } |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 216 | traceEnd(); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 219 | void release() { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 220 | // release done in opposite order from init |
| 221 | for (int i = mAllServices.length - 1; i >= 0; i--) { |
| 222 | mAllServices[i].release(); |
| 223 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 224 | mHal.release(); |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 225 | CarLocalServices.removeAllServices(); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 228 | void vehicleHalReconnected(IVehicle vehicle) { |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 229 | mHal.vehicleHalReconnected(vehicle); |
| 230 | for (CarServiceBase service : mAllServices) { |
| 231 | service.vehicleHalReconnected(); |
| 232 | } |
| 233 | } |
| 234 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 235 | @Override |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 236 | public void setCarServiceHelper(IBinder helper) { |
Pavel Maltsev | 17e8183 | 2019-04-04 14:38:41 -0700 | [diff] [blame] | 237 | assertCallingFromSystemProcess(); |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 238 | synchronized (this) { |
| 239 | mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper); |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame] | 240 | mSystemInterface.setCarServiceHelper(mICarServiceHelper); |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
| 244 | @Override |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 245 | public void setUserLockStatus(int userHandle, int unlocked) { |
Pavel Maltsev | 17e8183 | 2019-04-04 14:38:41 -0700 | [diff] [blame] | 246 | assertCallingFromSystemProcess(); |
| 247 | mCarUserService.setUserLockStatus(userHandle, unlocked == 1); |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public void onSwitchUser(int userHandle) { |
| 252 | assertCallingFromSystemProcess(); |
| 253 | |
| 254 | Log.i(TAG, "Foreground user switched to " + userHandle); |
| 255 | mCarUserService.onSwitchUser(userHandle); |
| 256 | } |
| 257 | |
| 258 | private static void assertCallingFromSystemProcess() { |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 259 | int uid = Binder.getCallingUid(); |
| 260 | if (uid != Process.SYSTEM_UID) { |
| 261 | throw new SecurityException("Only allowed from system"); |
| 262 | } |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | @Override |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 266 | public IBinder getCarService(String serviceName) { |
| 267 | switch (serviceName) { |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 268 | case Car.AUDIO_SERVICE: |
| 269 | return mCarAudioService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 270 | case Car.APP_FOCUS_SERVICE: |
| 271 | return mAppFocusService; |
Keun-young Park | 45fdcba | 2015-12-08 11:38:58 -0800 | [diff] [blame] | 272 | case Car.PACKAGE_SERVICE: |
| 273 | return mCarPackageManagerService; |
Enrico Granata | 5c56d2a | 2017-02-07 15:38:12 -0800 | [diff] [blame] | 274 | case Car.DIAGNOSTIC_SERVICE: |
Enrico Granata | b3634e2 | 2017-05-05 18:02:31 -0700 | [diff] [blame] | 275 | assertAnyDiagnosticPermission(mContext); |
| 276 | return mCarDiagnosticService; |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 277 | case Car.POWER_SERVICE: |
| 278 | assertPowerPermission(mContext); |
| 279 | return mCarPowerManagementService; |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 280 | case Car.CABIN_SERVICE: |
| 281 | case Car.HVAC_SERVICE: |
| 282 | case Car.INFO_SERVICE: |
| 283 | case Car.PROPERTY_SERVICE: |
| 284 | case Car.SENSOR_SERVICE: |
| 285 | case Car.VENDOR_EXTENSION_SERVICE: |
| 286 | return mCarPropertyService; |
Pavel Maltsev | 7a948e5 | 2016-02-02 23:30:14 -0800 | [diff] [blame] | 287 | case Car.CAR_NAVIGATION_SERVICE: |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 288 | assertNavigationManagerPermission(mContext); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 289 | IInstrumentClusterNavigation navService = |
| 290 | mInstrumentClusterService.getNavigationService(); |
| 291 | return navService == null ? null : navService.asBinder(); |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 292 | case Car.CAR_INSTRUMENT_CLUSTER_SERVICE: |
| 293 | assertClusterManagerPermission(mContext); |
| 294 | return mInstrumentClusterService.getManagerService(); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 295 | case Car.PROJECTION_SERVICE: |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 296 | return mCarProjectionService; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 297 | case Car.VMS_SUBSCRIBER_SERVICE: |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 298 | assertVmsSubscriberPermission(mContext); |
| 299 | return mVmsSubscriberService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 300 | case Car.TEST_SERVICE: { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 301 | assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 302 | synchronized (this) { |
| 303 | if (mCarTestService == null) { |
| 304 | mCarTestService = new CarTestService(mContext, this); |
| 305 | } |
| 306 | return mCarTestService; |
| 307 | } |
| 308 | } |
Ram Periathiruvadi | 76a8489 | 2017-07-27 18:10:35 -0700 | [diff] [blame] | 309 | case Car.BLUETOOTH_SERVICE: |
| 310 | return mCarBluetoothService; |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 311 | case Car.STORAGE_MONITORING_SERVICE: |
Enrico Granata | 1172f88 | 2017-09-21 14:51:30 -0700 | [diff] [blame] | 312 | assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING); |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 313 | return mCarStorageMonitoringService; |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 314 | case Car.CAR_DRIVING_STATE_SERVICE: |
| 315 | assertDrivingStatePermission(mContext); |
| 316 | return mCarDrivingStateService; |
| 317 | case Car.CAR_UX_RESTRICTION_SERVICE: |
| 318 | return mCarUXRestrictionsService; |
Anthony Chen | d4203d8 | 2018-05-16 16:21:52 -0700 | [diff] [blame] | 319 | case Car.CAR_CONFIGURATION_SERVICE: |
| 320 | return mCarConfigurationService; |
Ram Periathiruvadi | 194ce1b | 2019-01-14 09:42:12 -0800 | [diff] [blame] | 321 | case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE: |
| 322 | assertTrustAgentEnrollmentPermission(mContext); |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 323 | return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService(); |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 324 | case Car.CAR_MEDIA_SERVICE: |
| 325 | return mCarMediaService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 326 | default: |
| 327 | Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName); |
| 328 | return null; |
| 329 | } |
| 330 | } |
| 331 | |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 332 | @Override |
| 333 | public int getCarConnectionType() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 334 | return Car.CONNECTION_TYPE_EMBEDDED; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 337 | public CarServiceBase getCarInternalService(String serviceName) { |
| 338 | switch (serviceName) { |
| 339 | case INTERNAL_INPUT_SERVICE: |
| 340 | return mCarInputService; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 341 | case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE: |
| 342 | return mSystemActivityMonitoringService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 343 | default: |
| 344 | Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" + |
| 345 | serviceName); |
| 346 | return null; |
| 347 | } |
| 348 | } |
| 349 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 350 | public static void assertVehicleHalMockPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 351 | assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 354 | public static void assertNavigationManagerPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 355 | assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER); |
Pavel Maltsev | ce4ffd9 | 2016-03-09 10:56:23 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 358 | public static void assertClusterManagerPermission(Context context) { |
| 359 | assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL); |
| 360 | } |
| 361 | |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 362 | public static void assertPowerPermission(Context context) { |
| 363 | assertPermission(context, Car.PERMISSION_CAR_POWER); |
| 364 | } |
| 365 | |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 366 | public static void assertProjectionPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 367 | assertPermission(context, Car.PERMISSION_CAR_PROJECTION); |
| 368 | } |
| 369 | |
Pavel Maltsev | 079873b | 2019-02-25 12:15:09 -0800 | [diff] [blame] | 370 | /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */ |
| 371 | public static void assertProjectionStatusPermission(Context context) { |
| 372 | assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS); |
| 373 | } |
| 374 | |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 375 | public static void assertAnyDiagnosticPermission(Context context) { |
| 376 | assertAnyPermission(context, |
Enrico Granata | ae25b92 | 2017-07-07 11:28:15 -0700 | [diff] [blame] | 377 | Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL, |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 378 | Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR); |
| 379 | } |
| 380 | |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 381 | public static void assertDrivingStatePermission(Context context) { |
| 382 | assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE); |
| 383 | } |
| 384 | |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 385 | public static void assertVmsPublisherPermission(Context context) { |
| 386 | assertPermission(context, Car.PERMISSION_VMS_PUBLISHER); |
| 387 | } |
| 388 | |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 389 | public static void assertVmsSubscriberPermission(Context context) { |
| 390 | assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER); |
| 391 | } |
| 392 | |
Ram Periathiruvadi | 194ce1b | 2019-01-14 09:42:12 -0800 | [diff] [blame] | 393 | /** |
| 394 | * Ensures the caller has the permission to enroll a Trust Agent. |
| 395 | * @param context |
| 396 | */ |
| 397 | public static void assertTrustAgentEnrollmentPermission(Context context) { |
| 398 | assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST); |
| 399 | } |
| 400 | |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 401 | public static void assertPermission(Context context, String permission) { |
| 402 | if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { |
| 403 | throw new SecurityException("requires " + permission); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 407 | /** |
| 408 | * Checks to see if the caller has a permission. |
| 409 | * @param context |
| 410 | * @param permission |
| 411 | * |
| 412 | * @return boolean TRUE if caller has the permission. |
| 413 | */ |
| 414 | public static boolean hasPermission(Context context, String permission) { |
| 415 | return context.checkCallingOrSelfPermission(permission) |
| 416 | == PackageManager.PERMISSION_GRANTED; |
| 417 | } |
| 418 | |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 419 | public static void assertAnyPermission(Context context, String... permissions) { |
| 420 | for (String permission : permissions) { |
| 421 | if (context.checkCallingOrSelfPermission(permission) == |
| 422 | PackageManager.PERMISSION_GRANTED) { |
| 423 | return; |
| 424 | } |
| 425 | } |
| 426 | throw new SecurityException("requires any of " + Arrays.toString(permissions)); |
| 427 | } |
| 428 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 429 | @Override |
| 430 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| 431 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 432 | != PackageManager.PERMISSION_GRANTED) { |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 433 | writer.println("Permission Denial: can't dump CarService from from pid=" |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 434 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() |
| 435 | + " without permission " + android.Manifest.permission.DUMP); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 436 | return; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 437 | } |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 438 | if (args == null || args.length == 0) { |
| 439 | writer.println("*dump car service*"); |
| 440 | |
| 441 | writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT); |
| 442 | writer.println("*Dump all services*"); |
| 443 | for (CarServiceBase service : mAllServices) { |
| 444 | dumpService(service, writer); |
| 445 | } |
| 446 | if (mCarTestService != null) { |
| 447 | dumpService(mCarTestService, writer); |
| 448 | } |
| 449 | writer.println("*Dump Vehicle HAL*"); |
| 450 | writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName); |
| 451 | try { |
| 452 | // TODO dump all feature flags by creating a dumpable interface |
| 453 | mHal.dump(writer); |
| 454 | } catch (Exception e) { |
| 455 | writer.println("Failed dumping: " + mHal.getClass().getName()); |
| 456 | e.printStackTrace(writer); |
| 457 | } |
| 458 | } else if (Build.IS_USERDEBUG || Build.IS_ENG) { |
| 459 | execShellCmd(args, writer); |
| 460 | } else { |
| 461 | writer.println("Commands not supported in " + Build.TYPE); |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
| 465 | private void dumpService(CarServiceBase service, PrintWriter writer) { |
| 466 | try { |
| 467 | service.dump(writer); |
| 468 | } catch (Exception e) { |
| 469 | writer.println("Failed dumping: " + service.getClass().getName()); |
| 470 | e.printStackTrace(writer); |
| 471 | } |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 472 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 473 | |
| 474 | void execShellCmd(String[] args, PrintWriter writer) { |
| 475 | new CarShellCommand().exec(args, writer); |
| 476 | } |
| 477 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 478 | @MainThread |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 479 | private void traceBegin(String name) { |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 480 | Slog.i(TAG, name); |
| 481 | mBootTiming.traceBegin(name); |
| 482 | } |
| 483 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 484 | @MainThread |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 485 | private void traceEnd() { |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 486 | mBootTiming.traceEnd(); |
| 487 | } |
| 488 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 489 | private class CarShellCommand { |
| 490 | private static final String COMMAND_HELP = "-h"; |
| 491 | private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 492 | private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event"; |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 493 | private static final String COMMAND_ENABLE_UXR = "enable-uxr"; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 494 | private static final String COMMAND_GARAGE_MODE = "garage-mode"; |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 495 | private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities"; |
Kai | dd4ef5a | 2019-03-04 14:07:26 -0800 | [diff] [blame] | 496 | private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig"; |
Pavel Maltsev | 48a3194 | 2019-03-03 22:08:28 -0800 | [diff] [blame] | 497 | private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode"; |
Jim Kaye | d76c274 | 2019-04-02 11:33:27 -0700 | [diff] [blame] | 498 | private static final String COMMAND_RESUME = "resume"; |
| 499 | private static final String COMMAND_SUSPEND = "suspend"; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 500 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 501 | private static final String PARAM_DAY_MODE = "day"; |
| 502 | private static final String PARAM_NIGHT_MODE = "night"; |
| 503 | private static final String PARAM_SENSOR_MODE = "sensor"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 504 | private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0"; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 505 | private static final String PARAM_ON_MODE = "on"; |
| 506 | private static final String PARAM_OFF_MODE = "off"; |
| 507 | private static final String PARAM_QUERY_MODE = "query"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 508 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 509 | |
| 510 | private void dumpHelp(PrintWriter pw) { |
| 511 | pw.println("Car service commands:"); |
| 512 | pw.println("\t-h"); |
| 513 | pw.println("\t Print this help text."); |
| 514 | pw.println("\tday-night-mode [day|night|sensor]"); |
| 515 | pw.println("\t Force into day/night mode or restore to auto."); |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 516 | pw.println("\tinject-vhal-event property [zone] data(can be comma separated list)"); |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 517 | pw.println("\t Inject a vehicle property for testing."); |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 518 | pw.println("\tdisable-uxr true|false"); |
| 519 | pw.println("\t Disable UX restrictions and App blocking."); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 520 | pw.println("\tgarage-mode [on|off|query]"); |
| 521 | pw.println("\t Force into garage mode or check status."); |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 522 | pw.println("\tget-do-activities pkgname"); |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 523 | pw.println("\t Get Distraction Optimized activities in given package."); |
Kai | dd4ef5a | 2019-03-04 14:07:26 -0800 | [diff] [blame] | 524 | pw.println("\tget-carpropertyconfig [propertyId]"); |
| 525 | pw.println("\t Get a CarPropertyConfig by Id in Hex or list all CarPropertyConfigs"); |
Jim Kaye | d76c274 | 2019-04-02 11:33:27 -0700 | [diff] [blame] | 526 | pw.println("\tsuspend"); |
| 527 | pw.println("\t Suspend the system to Deep Sleep."); |
| 528 | pw.println("\tresume"); |
| 529 | pw.println("\t Wake the system up after a 'suspend.'"); |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | public void exec(String[] args, PrintWriter writer) { |
| 533 | String arg = args[0]; |
| 534 | switch (arg) { |
| 535 | case COMMAND_HELP: |
| 536 | dumpHelp(writer); |
| 537 | break; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 538 | case COMMAND_DAY_NIGHT_MODE: { |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 539 | String value = args.length < 2 ? "" : args[1]; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 540 | forceDayNightMode(value, writer); |
| 541 | break; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 542 | } |
| 543 | case COMMAND_GARAGE_MODE: { |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 544 | String value = args.length < 2 ? "" : args[1]; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 545 | forceGarageMode(value, writer); |
| 546 | break; |
| 547 | } |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 548 | case COMMAND_INJECT_VHAL_EVENT: |
| 549 | String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL; |
| 550 | String data; |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 551 | if (args.length != 3 && args.length != 4) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 552 | writer.println("Incorrect number of arguments."); |
| 553 | dumpHelp(writer); |
| 554 | break; |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 555 | } else if (args.length == 4) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 556 | // Zoned |
| 557 | zone = args[2]; |
| 558 | data = args[3]; |
| 559 | } else { |
| 560 | // Global |
| 561 | data = args[2]; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 562 | } |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 563 | injectVhalEvent(args[1], zone, data, writer); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 564 | break; |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 565 | case COMMAND_ENABLE_UXR: |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 566 | if (args.length != 2) { |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 567 | writer.println("Incorrect number of arguments"); |
| 568 | dumpHelp(writer); |
| 569 | break; |
| 570 | } |
| 571 | boolean enableBlocking = Boolean.valueOf(args[1]); |
| 572 | if (mCarPackageManagerService != null) { |
| 573 | mCarPackageManagerService.setEnableActivityBlocking(enableBlocking); |
| 574 | } |
| 575 | break; |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 576 | case COMMAND_GET_DO_ACTIVITIES: |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 577 | if (args.length != 2) { |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 578 | writer.println("Incorrect number of arguments"); |
| 579 | dumpHelp(writer); |
| 580 | break; |
| 581 | } |
| 582 | String pkgName = args[1].toLowerCase(); |
| 583 | if (mCarPackageManagerService != null) { |
| 584 | String[] doActivities = |
| 585 | mCarPackageManagerService.getDistractionOptimizedActivities( |
| 586 | pkgName); |
| 587 | if (doActivities != null) { |
| 588 | writer.println("DO Activities for " + pkgName); |
| 589 | for (String a : doActivities) { |
| 590 | writer.println(a); |
| 591 | } |
| 592 | } else { |
| 593 | writer.println("No DO Activities for " + pkgName); |
| 594 | } |
| 595 | } |
| 596 | break; |
Kai | dd4ef5a | 2019-03-04 14:07:26 -0800 | [diff] [blame] | 597 | case COMMAND_GET_CARPROPERTYCONFIG: |
| 598 | String propertyId = args.length < 2 ? "" : args[1]; |
| 599 | mHal.dumpPropertyConfigs(writer, propertyId); |
| 600 | break; |
Pavel Maltsev | 48a3194 | 2019-03-03 22:08:28 -0800 | [diff] [blame] | 601 | case COMMAND_PROJECTION_UI_MODE: |
| 602 | if (args.length != 2) { |
| 603 | writer.println("Incorrect number of arguments"); |
| 604 | dumpHelp(writer); |
| 605 | break; |
| 606 | } |
| 607 | mCarProjectionService.setUiMode(Integer.valueOf(args[1])); |
Pavel Maltsev | d6961f6 | 2019-03-26 10:22:31 -0700 | [diff] [blame] | 608 | break; |
Jim Kaye | d76c274 | 2019-04-02 11:33:27 -0700 | [diff] [blame] | 609 | case COMMAND_RESUME: |
| 610 | mCarPowerManagementService.forceSimulatedResume(); |
| 611 | writer.println("Resume: Simulating resuming from Deep Sleep"); |
| 612 | break; |
| 613 | case COMMAND_SUSPEND: |
| 614 | mCarPowerManagementService.forceSimulatedSuspend(); |
| 615 | writer.println("Resume: Simulating powering down to Deep Sleep"); |
| 616 | break; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 617 | default: |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 618 | writer.println("Unknown command: \"" + arg + "\""); |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 619 | dumpHelp(writer); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | private void forceDayNightMode(String arg, PrintWriter writer) { |
| 624 | int mode; |
| 625 | switch (arg) { |
| 626 | case PARAM_DAY_MODE: |
| 627 | mode = CarNightService.FORCED_DAY_MODE; |
| 628 | break; |
| 629 | case PARAM_NIGHT_MODE: |
| 630 | mode = CarNightService.FORCED_NIGHT_MODE; |
| 631 | break; |
| 632 | case PARAM_SENSOR_MODE: |
| 633 | mode = CarNightService.FORCED_SENSOR_MODE; |
| 634 | break; |
| 635 | default: |
| 636 | writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|" |
| 637 | + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE); |
| 638 | return; |
| 639 | } |
| 640 | int current = mCarNightService.forceDayNightMode(mode); |
| 641 | String currentMode = null; |
| 642 | switch (current) { |
| 643 | case UiModeManager.MODE_NIGHT_AUTO: |
| 644 | currentMode = PARAM_SENSOR_MODE; |
| 645 | break; |
| 646 | case UiModeManager.MODE_NIGHT_YES: |
| 647 | currentMode = PARAM_NIGHT_MODE; |
| 648 | break; |
| 649 | case UiModeManager.MODE_NIGHT_NO: |
| 650 | currentMode = PARAM_DAY_MODE; |
| 651 | break; |
| 652 | } |
| 653 | writer.println("DayNightMode changed to: " + currentMode); |
| 654 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 655 | |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 656 | private void forceGarageMode(String arg, PrintWriter writer) { |
| 657 | switch (arg) { |
| 658 | case PARAM_ON_MODE: |
Serik Beketayev | e0e7ff2 | 2018-07-31 21:04:12 -0700 | [diff] [blame] | 659 | mGarageModeService.forceStartGarageMode(); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 660 | break; |
| 661 | case PARAM_OFF_MODE: |
Serik Beketayev | e0e7ff2 | 2018-07-31 21:04:12 -0700 | [diff] [blame] | 662 | mGarageModeService.stopAndResetGarageMode(); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 663 | break; |
| 664 | case PARAM_QUERY_MODE: |
| 665 | // Nothing to do. Always query at the end anyway. |
| 666 | break; |
| 667 | default: |
| 668 | writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|" |
| 669 | + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE); |
| 670 | return; |
| 671 | } |
Serik Beketayev | e0e7ff2 | 2018-07-31 21:04:12 -0700 | [diff] [blame] | 672 | writer.println("Garage mode: " + mGarageModeService.isGarageModeActive()); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 673 | } |
| 674 | |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 675 | /** |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 676 | * Inject a fake VHAL event |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 677 | * |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 678 | * @param property the Vehicle property Id as defined in the HAL |
| 679 | * @param zone Zone that this event services |
| 680 | * @param value Data value of the event |
| 681 | * @param writer PrintWriter |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 682 | */ |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 683 | private void injectVhalEvent(String property, String zone, String value, |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 684 | PrintWriter writer) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 685 | if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) { |
| 686 | if (!isPropertyAreaTypeGlobal(property)) { |
| 687 | writer.println("Property area type inconsistent with given zone"); |
| 688 | return; |
| 689 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 690 | } |
| 691 | try { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 692 | mHal.injectVhalEvent(property, zone, value); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 693 | } catch (NumberFormatException e) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 694 | writer.println("Invalid property Id zone Id or value" + e); |
| 695 | dumpHelp(writer); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 696 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 697 | } |
| 698 | |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 699 | // Check if the given property is global |
| 700 | private boolean isPropertyAreaTypeGlobal(String property) { |
| 701 | if (property == null) { |
| 702 | return false; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 703 | } |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 704 | return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 705 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 706 | } |
kevinjm | 55822c4 | 2018-08-15 11:26:00 -0700 | [diff] [blame] | 707 | } |