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; |
Anthony Hugh | 9932a25 | 2019-06-12 16:19:56 -0700 | [diff] [blame] | 36 | import android.os.UserManager; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 37 | import android.util.Log; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 38 | import android.util.Slog; |
Keun-young Park | 4a79a38 | 2017-08-10 18:19:14 -0700 | [diff] [blame] | 39 | import android.util.TimingsTraceLog; |
Gregory Clark | 26fa601 | 2018-03-14 18:38:56 -0700 | [diff] [blame] | 40 | |
Hongwei Wang | 3854909 | 2018-08-22 12:32:42 -0700 | [diff] [blame] | 41 | import com.android.car.audio.CarAudioService; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 42 | import com.android.car.cluster.InstrumentClusterService; |
Serik Beketayev | 06a6668 | 2018-06-12 16:54:29 -0700 | [diff] [blame] | 43 | import com.android.car.garagemode.GarageModeService; |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 44 | import com.android.car.hal.VehicleHal; |
Antonio Cortes | c52d5f9 | 2017-02-06 08:47:38 -0800 | [diff] [blame] | 45 | import com.android.car.internal.FeatureConfiguration; |
Keun-young Park | 4aeb4bf | 2015-12-08 18:31:33 -0800 | [diff] [blame] | 46 | import com.android.car.pm.CarPackageManagerService; |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 47 | import com.android.car.systeminterface.SystemInterface; |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 48 | import com.android.car.trust.CarTrustedDeviceService; |
Keun young Park | 7af7d6c | 2019-09-12 10:31:48 -0700 | [diff] [blame^] | 49 | import com.android.car.user.CarUserNoticeService; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 50 | import com.android.car.user.CarUserService; |
Mark Tabry | 76cfaaa | 2019-02-01 14:28:30 -0800 | [diff] [blame] | 51 | import com.android.car.vms.VmsBrokerService; |
Mark Tabry | a8fce56 | 2019-01-16 16:24:01 -0800 | [diff] [blame] | 52 | import com.android.car.vms.VmsClientManager; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 53 | import com.android.internal.annotations.GuardedBy; |
Steve Paik | 1d8bea2 | 2018-02-03 01:54:06 +0000 | [diff] [blame] | 54 | import com.android.internal.car.ICarServiceHelper; |
Oscar Azucena | 3f3a25e | 2019-07-12 14:28:24 -0700 | [diff] [blame] | 55 | import com.android.internal.util.ArrayUtils; |
Gregory Clark | 26fa601 | 2018-03-14 18:38:56 -0700 | [diff] [blame] | 56 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 57 | import java.io.FileDescriptor; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 58 | import java.io.PrintWriter; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 59 | import java.util.ArrayList; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 60 | import java.util.Arrays; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 61 | import java.util.List; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 62 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 63 | public class ICarImpl extends ICar.Stub { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 64 | |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 65 | public static final String INTERNAL_INPUT_SERVICE = "internal_input"; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 66 | public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE = |
| 67 | "system_activity_monitoring"; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 68 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 69 | private final Context mContext; |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 70 | private final VehicleHal mHal; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 71 | |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 72 | private final SystemInterface mSystemInterface; |
| 73 | |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 74 | private final SystemActivityMonitoringService mSystemActivityMonitoringService; |
keunyoung | 4b0212c | 2015-10-29 17:11:57 -0700 | [diff] [blame] | 75 | private final CarPowerManagementService mCarPowerManagementService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 76 | private final CarPackageManagerService mCarPackageManagerService; |
| 77 | private final CarInputService mCarInputService; |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 78 | private final CarDrivingStateService mCarDrivingStateService; |
Ram Periathiruvadi | 4526a43 | 2018-01-24 13:00:54 -0800 | [diff] [blame] | 79 | private final CarUxRestrictionsManagerService mCarUXRestrictionsService; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 80 | private final CarAudioService mCarAudioService; |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 81 | private final CarProjectionService mCarProjectionService; |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 82 | private final CarPropertyService mCarPropertyService; |
Joseph Pirozzo | 317343d | 2016-01-25 10:22:37 -0800 | [diff] [blame] | 83 | private final CarNightService mCarNightService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 84 | private final AppFocusService mAppFocusService; |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 85 | private final GarageModeService mGarageModeService; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 86 | private final InstrumentClusterService mInstrumentClusterService; |
Gregory Clark | d813606 | 2017-12-11 14:27:53 -0800 | [diff] [blame] | 87 | private final CarLocationService mCarLocationService; |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 88 | private final SystemStateControllerService mSystemStateControllerService; |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 89 | private final CarBluetoothService mCarBluetoothService; |
Ram Periathiruvadi | acb6024 | 2017-04-13 16:19:09 -0700 | [diff] [blame] | 90 | private final PerUserCarServiceHelper mPerUserCarServiceHelper; |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 91 | private final CarDiagnosticService mCarDiagnosticService; |
| 92 | private final CarStorageMonitoringService mCarStorageMonitoringService; |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 93 | private final CarConfigurationService mCarConfigurationService; |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 94 | private final CarTrustedDeviceService mCarTrustedDeviceService; |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 95 | private final CarMediaService mCarMediaService; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 96 | private final CarUserManagerHelper mUserManagerHelper; |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 97 | private final CarUserService mCarUserService; |
Keun young Park | bb877e2 | 2019-08-02 10:38:01 -0700 | [diff] [blame] | 98 | private final CarOccupantZoneService mCarOccupantZoneService; |
Keun young Park | 7af7d6c | 2019-09-12 10:31:48 -0700 | [diff] [blame^] | 99 | private final CarUserNoticeService mCarUserNoticeService; |
Mark Tabry | a8fce56 | 2019-01-16 16:24:01 -0800 | [diff] [blame] | 100 | private final VmsClientManager mVmsClientManager; |
Mark Tabry | 76cfaaa | 2019-02-01 14:28:30 -0800 | [diff] [blame] | 101 | private final VmsBrokerService mVmsBrokerService; |
Mark Tabry | a8fce56 | 2019-01-16 16:24:01 -0800 | [diff] [blame] | 102 | private final VmsSubscriberService mVmsSubscriberService; |
| 103 | private final VmsPublisherService mVmsPublisherService; |
Selim Gurun | c8c82f6 | 2019-04-17 14:07:30 -0700 | [diff] [blame] | 104 | private final CarBugreportManagerService mCarBugreportManagerService; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 105 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 106 | private final CarServiceBase[] mAllServices; |
| 107 | |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 108 | private static final String TAG = "ICarImpl"; |
| 109 | private static final String VHAL_TIMING_TAG = "VehicleHalTiming"; |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 110 | |
| 111 | private TimingsTraceLog mBootTiming; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 112 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 113 | /** Test only service. Populate it only when necessary. */ |
| 114 | @GuardedBy("this") |
| 115 | private CarTestService mCarTestService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 116 | |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 117 | @GuardedBy("this") |
| 118 | private ICarServiceHelper mICarServiceHelper; |
| 119 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 120 | private final String mVehicleInterfaceName; |
| 121 | |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 122 | public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface, |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 123 | CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 124 | mContext = serviceContext; |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame] | 125 | mSystemInterface = systemInterface; |
Mark Tabry | b588d2e | 2019-09-12 10:50:11 -0700 | [diff] [blame] | 126 | mHal = new VehicleHal(serviceContext, vehicle); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 127 | mVehicleInterfaceName = vehicleInterfaceName; |
Yao, Yuxing | 0811d5a | 2018-11-29 16:18:53 -0800 | [diff] [blame] | 128 | mUserManagerHelper = new CarUserManagerHelper(serviceContext); |
Anthony Hugh | 9932a25 | 2019-06-12 16:19:56 -0700 | [diff] [blame] | 129 | UserManager userManager = |
| 130 | (UserManager) serviceContext.getSystemService(Context.USER_SERVICE); |
Keun young Park | f3523cd | 2019-04-08 10:09:17 -0700 | [diff] [blame] | 131 | final Resources res = mContext.getResources(); |
| 132 | final int maxRunningUsers = res.getInteger( |
| 133 | com.android.internal.R.integer.config_multiuserMaxRunningUsers); |
Anthony Hugh | 9932a25 | 2019-06-12 16:19:56 -0700 | [diff] [blame] | 134 | mCarUserService = new CarUserService(serviceContext, mUserManagerHelper, userManager, |
Keun young Park | f3523cd | 2019-04-08 10:09:17 -0700 | [diff] [blame] | 135 | ActivityManager.getService(), maxRunningUsers); |
Keun young Park | bb877e2 | 2019-08-02 10:38:01 -0700 | [diff] [blame] | 136 | mCarOccupantZoneService = new CarOccupantZoneService(serviceContext); |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 137 | mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext); |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 138 | mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(), |
Keun young Park | 9b3f266 | 2019-03-19 10:30:25 -0700 | [diff] [blame] | 139 | systemInterface, mUserManagerHelper); |
Keun young Park | 7af7d6c | 2019-09-12 10:31:48 -0700 | [diff] [blame^] | 140 | mCarUserNoticeService = new CarUserNoticeService(serviceContext); |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 141 | mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal()); |
| 142 | mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService); |
Ram Periathiruvadi | 4526a43 | 2018-01-24 13:00:54 -0800 | [diff] [blame] | 143 | mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext, |
Yao, Yuxing | 9bfb749 | 2019-02-15 11:53:34 -0800 | [diff] [blame] | 144 | mCarDrivingStateService, mCarPropertyService); |
Ram Periathiruvadi | 2da6d0e | 2018-01-26 18:02:10 -0800 | [diff] [blame] | 145 | mCarPackageManagerService = new CarPackageManagerService(serviceContext, |
| 146 | mCarUXRestrictionsService, |
Pavel Maltsev | 38da431 | 2019-04-08 10:38:38 -0700 | [diff] [blame] | 147 | mSystemActivityMonitoringService, |
| 148 | mUserManagerHelper); |
Justin Paupore | 44985ba | 2019-01-30 18:53:41 -0800 | [diff] [blame] | 149 | mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext); |
Sal Savage | 703c46f | 2019-04-15 08:39:25 -0700 | [diff] [blame] | 150 | mCarBluetoothService = new CarBluetoothService(serviceContext, mPerUserCarServiceHelper); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 151 | mCarInputService = new CarInputService(serviceContext, mHal.getInputHal()); |
Justin Paupore | 44985ba | 2019-01-30 18:53:41 -0800 | [diff] [blame] | 152 | mCarProjectionService = new CarProjectionService( |
Pavel Maltsev | 079873b | 2019-02-25 12:15:09 -0800 | [diff] [blame] | 153 | serviceContext, null /* handler */, mCarInputService, mCarBluetoothService); |
Serik Beketayev | c6ab8be | 2018-08-28 21:20:53 -0700 | [diff] [blame] | 154 | mGarageModeService = new GarageModeService(mContext); |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 155 | mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService); |
Hongwei Wang | 3055723 | 2018-01-02 10:25:08 -0800 | [diff] [blame] | 156 | mCarAudioService = new CarAudioService(serviceContext); |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 157 | mCarNightService = new CarNightService(serviceContext, mCarPropertyService); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 158 | mInstrumentClusterService = new InstrumentClusterService(serviceContext, |
Pavel Maltsev | 03cf60c | 2016-06-27 15:11:51 -0700 | [diff] [blame] | 159 | mAppFocusService, mCarInputService); |
Serik Beketayev | f9f2ef0 | 2018-09-06 12:37:02 -0700 | [diff] [blame] | 160 | mSystemStateControllerService = new SystemStateControllerService( |
| 161 | serviceContext, mCarAudioService, this); |
Mark Tabry | 61a06c7 | 2019-06-17 10:37:49 -0700 | [diff] [blame] | 162 | mVmsBrokerService = new VmsBrokerService(); |
Mark Tabry | 1534c06 | 2019-03-29 01:30:49 -0700 | [diff] [blame] | 163 | mVmsClientManager = new VmsClientManager( |
Mark Tabry | 61a06c7 | 2019-06-17 10:37:49 -0700 | [diff] [blame] | 164 | serviceContext, mVmsBrokerService, mCarUserService, mUserManagerHelper, |
| 165 | mHal.getVmsHal()); |
Mark Tabry | 76cfaaa | 2019-02-01 14:28:30 -0800 | [diff] [blame] | 166 | mVmsSubscriberService = new VmsSubscriberService( |
Mark Tabry | 61a06c7 | 2019-06-17 10:37:49 -0700 | [diff] [blame] | 167 | serviceContext, mVmsBrokerService, mVmsClientManager, mHal.getVmsHal()); |
Mark Tabry | 76cfaaa | 2019-02-01 14:28:30 -0800 | [diff] [blame] | 168 | mVmsPublisherService = new VmsPublisherService( |
Mark Tabry | 1534c06 | 2019-03-29 01:30:49 -0700 | [diff] [blame] | 169 | serviceContext, mVmsBrokerService, mVmsClientManager); |
Enrico Granata | b3634e2 | 2017-05-05 18:02:31 -0700 | [diff] [blame] | 170 | mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal()); |
Enrico Granata | 517a1e0 | 2017-09-20 16:15:50 -0700 | [diff] [blame] | 171 | mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext, |
| 172 | systemInterface); |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 173 | mCarConfigurationService = |
| 174 | new CarConfigurationService(serviceContext, new JsonReaderImpl()); |
Gregory Clark | e151953 | 2019-05-10 16:25:57 -0700 | [diff] [blame] | 175 | mCarLocationService = new CarLocationService(mContext, mUserManagerHelper); |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 176 | mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext); |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 177 | mCarMediaService = new CarMediaService(serviceContext); |
Selim Gurun | c8c82f6 | 2019-04-17 14:07:30 -0700 | [diff] [blame] | 178 | mCarBugreportManagerService = new CarBugreportManagerService(serviceContext); |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 179 | |
Keun young Park | a5fa478 | 2019-04-16 18:56:27 -0700 | [diff] [blame] | 180 | CarLocalServices.addService(CarPowerManagementService.class, mCarPowerManagementService); |
Keun young Park | bb877e2 | 2019-08-02 10:38:01 -0700 | [diff] [blame] | 181 | CarLocalServices.addService(CarPropertyService.class, mCarPropertyService); |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 182 | CarLocalServices.addService(CarUserService.class, mCarUserService); |
Gregory Clark | 18a0ef9 | 2019-05-23 20:00:49 -0700 | [diff] [blame] | 183 | CarLocalServices.addService(CarTrustedDeviceService.class, mCarTrustedDeviceService); |
Gregory Clark | a440e81 | 2019-02-14 16:05:51 -0800 | [diff] [blame] | 184 | CarLocalServices.addService(SystemInterface.class, mSystemInterface); |
Gregory Clark | 18a0ef9 | 2019-05-23 20:00:49 -0700 | [diff] [blame] | 185 | CarLocalServices.addService(CarDrivingStateService.class, mCarDrivingStateService); |
Gregory Clark | 55620c1 | 2019-06-03 17:42:58 -0700 | [diff] [blame] | 186 | CarLocalServices.addService(PerUserCarServiceHelper.class, mPerUserCarServiceHelper); |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 187 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 188 | // 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] | 189 | List<CarServiceBase> allServices = new ArrayList<>(); |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 190 | allServices.add(mCarUserService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 191 | allServices.add(mSystemActivityMonitoringService); |
| 192 | allServices.add(mCarPowerManagementService); |
| 193 | allServices.add(mCarPropertyService); |
| 194 | allServices.add(mCarDrivingStateService); |
Keun young Park | bb877e2 | 2019-08-02 10:38:01 -0700 | [diff] [blame] | 195 | allServices.add(mCarOccupantZoneService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 196 | allServices.add(mCarUXRestrictionsService); |
| 197 | allServices.add(mCarPackageManagerService); |
| 198 | allServices.add(mCarInputService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 199 | allServices.add(mGarageModeService); |
Keun young Park | 7af7d6c | 2019-09-12 10:31:48 -0700 | [diff] [blame^] | 200 | allServices.add(mCarUserNoticeService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 201 | allServices.add(mAppFocusService); |
| 202 | allServices.add(mCarAudioService); |
| 203 | allServices.add(mCarNightService); |
| 204 | allServices.add(mInstrumentClusterService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 205 | allServices.add(mSystemStateControllerService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 206 | allServices.add(mPerUserCarServiceHelper); |
Justin Paupore | 44985ba | 2019-01-30 18:53:41 -0800 | [diff] [blame] | 207 | allServices.add(mCarBluetoothService); |
| 208 | allServices.add(mCarProjectionService); |
| 209 | allServices.add(mCarDiagnosticService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 210 | allServices.add(mCarStorageMonitoringService); |
| 211 | allServices.add(mCarConfigurationService); |
Mark Tabry | a8fce56 | 2019-01-16 16:24:01 -0800 | [diff] [blame] | 212 | allServices.add(mVmsClientManager); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 213 | allServices.add(mVmsSubscriberService); |
| 214 | allServices.add(mVmsPublisherService); |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 215 | allServices.add(mCarTrustedDeviceService); |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 216 | allServices.add(mCarMediaService); |
Gregory Clark | a63ba02 | 2018-06-07 16:42:12 -0700 | [diff] [blame] | 217 | allServices.add(mCarLocationService); |
Selim Gurun | c8c82f6 | 2019-04-17 14:07:30 -0700 | [diff] [blame] | 218 | allServices.add(mCarBugreportManagerService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 219 | mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 222 | @MainThread |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 223 | void init() { |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 224 | mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL); |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 225 | traceBegin("VehicleHal.init"); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 226 | mHal.init(); |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 227 | traceEnd(); |
| 228 | traceBegin("CarService.initAllServices"); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 229 | for (CarServiceBase service : mAllServices) { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 230 | service.init(); |
| 231 | } |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 232 | traceEnd(); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 235 | void release() { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 236 | // release done in opposite order from init |
| 237 | for (int i = mAllServices.length - 1; i >= 0; i--) { |
| 238 | mAllServices[i].release(); |
| 239 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 240 | mHal.release(); |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 241 | CarLocalServices.removeAllServices(); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 244 | void vehicleHalReconnected(IVehicle vehicle) { |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 245 | mHal.vehicleHalReconnected(vehicle); |
| 246 | for (CarServiceBase service : mAllServices) { |
| 247 | service.vehicleHalReconnected(); |
| 248 | } |
| 249 | } |
| 250 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 251 | @Override |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 252 | public void setCarServiceHelper(IBinder helper) { |
Pavel Maltsev | 17e8183 | 2019-04-04 14:38:41 -0700 | [diff] [blame] | 253 | assertCallingFromSystemProcess(); |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 254 | synchronized (this) { |
| 255 | mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper); |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame] | 256 | mSystemInterface.setCarServiceHelper(mICarServiceHelper); |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | @Override |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 261 | public void setUserLockStatus(int userHandle, int unlocked) { |
Pavel Maltsev | 17e8183 | 2019-04-04 14:38:41 -0700 | [diff] [blame] | 262 | assertCallingFromSystemProcess(); |
| 263 | mCarUserService.setUserLockStatus(userHandle, unlocked == 1); |
Yabin Huang | 27712d7 | 2019-06-26 12:46:30 -0700 | [diff] [blame] | 264 | mCarMediaService.setUserLockStatus(userHandle, unlocked == 1); |
Pavel Maltsev | 17e8183 | 2019-04-04 14:38:41 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | @Override |
| 268 | public void onSwitchUser(int userHandle) { |
| 269 | assertCallingFromSystemProcess(); |
| 270 | |
| 271 | Log.i(TAG, "Foreground user switched to " + userHandle); |
| 272 | mCarUserService.onSwitchUser(userHandle); |
| 273 | } |
| 274 | |
Jim Kaye | e513316 | 2019-04-22 12:50:27 -0700 | [diff] [blame] | 275 | static void assertCallingFromSystemProcess() { |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 276 | int uid = Binder.getCallingUid(); |
| 277 | if (uid != Process.SYSTEM_UID) { |
| 278 | throw new SecurityException("Only allowed from system"); |
| 279 | } |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Keun young Park | aabecd9 | 2019-05-03 17:31:27 -0700 | [diff] [blame] | 282 | /** |
| 283 | * Assert if binder call is coming from system process like system server or if it is called |
| 284 | * from its own process even if it is not system. The latter can happen in test environment. |
| 285 | * Note that car service runs as system user but test like car service test will not. |
| 286 | */ |
| 287 | static void assertCallingFromSystemProcessOrSelf() { |
| 288 | int uid = Binder.getCallingUid(); |
| 289 | int pid = Binder.getCallingPid(); |
| 290 | if (uid != Process.SYSTEM_UID && pid != Process.myPid()) { |
| 291 | throw new SecurityException("Only allowed from system or self"); |
| 292 | } |
| 293 | } |
| 294 | |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 295 | @Override |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 296 | public IBinder getCarService(String serviceName) { |
| 297 | switch (serviceName) { |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 298 | case Car.AUDIO_SERVICE: |
| 299 | return mCarAudioService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 300 | case Car.APP_FOCUS_SERVICE: |
| 301 | return mAppFocusService; |
Keun-young Park | 45fdcba | 2015-12-08 11:38:58 -0800 | [diff] [blame] | 302 | case Car.PACKAGE_SERVICE: |
| 303 | return mCarPackageManagerService; |
Enrico Granata | 5c56d2a | 2017-02-07 15:38:12 -0800 | [diff] [blame] | 304 | case Car.DIAGNOSTIC_SERVICE: |
Enrico Granata | b3634e2 | 2017-05-05 18:02:31 -0700 | [diff] [blame] | 305 | assertAnyDiagnosticPermission(mContext); |
| 306 | return mCarDiagnosticService; |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 307 | case Car.POWER_SERVICE: |
| 308 | assertPowerPermission(mContext); |
| 309 | return mCarPowerManagementService; |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 310 | case Car.CABIN_SERVICE: |
| 311 | case Car.HVAC_SERVICE: |
| 312 | case Car.INFO_SERVICE: |
| 313 | case Car.PROPERTY_SERVICE: |
| 314 | case Car.SENSOR_SERVICE: |
| 315 | case Car.VENDOR_EXTENSION_SERVICE: |
| 316 | return mCarPropertyService; |
Pavel Maltsev | 7a948e5 | 2016-02-02 23:30:14 -0800 | [diff] [blame] | 317 | case Car.CAR_NAVIGATION_SERVICE: |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 318 | assertNavigationManagerPermission(mContext); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 319 | IInstrumentClusterNavigation navService = |
| 320 | mInstrumentClusterService.getNavigationService(); |
| 321 | return navService == null ? null : navService.asBinder(); |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 322 | case Car.CAR_INSTRUMENT_CLUSTER_SERVICE: |
| 323 | assertClusterManagerPermission(mContext); |
| 324 | return mInstrumentClusterService.getManagerService(); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 325 | case Car.PROJECTION_SERVICE: |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 326 | return mCarProjectionService; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 327 | case Car.VMS_SUBSCRIBER_SERVICE: |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 328 | assertVmsSubscriberPermission(mContext); |
| 329 | return mVmsSubscriberService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 330 | case Car.TEST_SERVICE: { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 331 | assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 332 | synchronized (this) { |
| 333 | if (mCarTestService == null) { |
| 334 | mCarTestService = new CarTestService(mContext, this); |
| 335 | } |
| 336 | return mCarTestService; |
| 337 | } |
| 338 | } |
Ram Periathiruvadi | 76a8489 | 2017-07-27 18:10:35 -0700 | [diff] [blame] | 339 | case Car.BLUETOOTH_SERVICE: |
| 340 | return mCarBluetoothService; |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 341 | case Car.STORAGE_MONITORING_SERVICE: |
Enrico Granata | 1172f88 | 2017-09-21 14:51:30 -0700 | [diff] [blame] | 342 | assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING); |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 343 | return mCarStorageMonitoringService; |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 344 | case Car.CAR_DRIVING_STATE_SERVICE: |
| 345 | assertDrivingStatePermission(mContext); |
| 346 | return mCarDrivingStateService; |
| 347 | case Car.CAR_UX_RESTRICTION_SERVICE: |
| 348 | return mCarUXRestrictionsService; |
Anthony Chen | d4203d8 | 2018-05-16 16:21:52 -0700 | [diff] [blame] | 349 | case Car.CAR_CONFIGURATION_SERVICE: |
| 350 | return mCarConfigurationService; |
Ram Periathiruvadi | 194ce1b | 2019-01-14 09:42:12 -0800 | [diff] [blame] | 351 | case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE: |
| 352 | assertTrustAgentEnrollmentPermission(mContext); |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 353 | return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService(); |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 354 | case Car.CAR_MEDIA_SERVICE: |
| 355 | return mCarMediaService; |
Keun young Park | bb877e2 | 2019-08-02 10:38:01 -0700 | [diff] [blame] | 356 | case Car.CAR_OCCUPANT_ZONE_SERVICE: |
| 357 | return mCarOccupantZoneService; |
Selim Gurun | c8c82f6 | 2019-04-17 14:07:30 -0700 | [diff] [blame] | 358 | case Car.CAR_BUGREPORT_SERVICE: |
| 359 | return mCarBugreportManagerService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 360 | default: |
| 361 | Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName); |
| 362 | return null; |
| 363 | } |
| 364 | } |
| 365 | |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 366 | @Override |
| 367 | public int getCarConnectionType() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 368 | return Car.CONNECTION_TYPE_EMBEDDED; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 371 | public CarServiceBase getCarInternalService(String serviceName) { |
| 372 | switch (serviceName) { |
| 373 | case INTERNAL_INPUT_SERVICE: |
| 374 | return mCarInputService; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 375 | case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE: |
| 376 | return mSystemActivityMonitoringService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 377 | default: |
| 378 | Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" + |
| 379 | serviceName); |
| 380 | return null; |
| 381 | } |
| 382 | } |
| 383 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 384 | public static void assertVehicleHalMockPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 385 | assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 388 | public static void assertNavigationManagerPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 389 | assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER); |
Pavel Maltsev | ce4ffd9 | 2016-03-09 10:56:23 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 392 | public static void assertClusterManagerPermission(Context context) { |
| 393 | assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL); |
| 394 | } |
| 395 | |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 396 | public static void assertPowerPermission(Context context) { |
| 397 | assertPermission(context, Car.PERMISSION_CAR_POWER); |
| 398 | } |
| 399 | |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 400 | public static void assertProjectionPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 401 | assertPermission(context, Car.PERMISSION_CAR_PROJECTION); |
| 402 | } |
| 403 | |
Pavel Maltsev | 079873b | 2019-02-25 12:15:09 -0800 | [diff] [blame] | 404 | /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */ |
| 405 | public static void assertProjectionStatusPermission(Context context) { |
| 406 | assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS); |
| 407 | } |
| 408 | |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 409 | public static void assertAnyDiagnosticPermission(Context context) { |
| 410 | assertAnyPermission(context, |
Enrico Granata | ae25b92 | 2017-07-07 11:28:15 -0700 | [diff] [blame] | 411 | Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL, |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 412 | Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR); |
| 413 | } |
| 414 | |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 415 | public static void assertDrivingStatePermission(Context context) { |
| 416 | assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE); |
| 417 | } |
| 418 | |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 419 | public static void assertVmsPublisherPermission(Context context) { |
| 420 | assertPermission(context, Car.PERMISSION_VMS_PUBLISHER); |
| 421 | } |
| 422 | |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 423 | public static void assertVmsSubscriberPermission(Context context) { |
| 424 | assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER); |
| 425 | } |
| 426 | |
Ram Periathiruvadi | 194ce1b | 2019-01-14 09:42:12 -0800 | [diff] [blame] | 427 | /** |
| 428 | * Ensures the caller has the permission to enroll a Trust Agent. |
Ram Periathiruvadi | 194ce1b | 2019-01-14 09:42:12 -0800 | [diff] [blame] | 429 | */ |
| 430 | public static void assertTrustAgentEnrollmentPermission(Context context) { |
| 431 | assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST); |
| 432 | } |
| 433 | |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 434 | public static void assertPermission(Context context, String permission) { |
| 435 | if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { |
| 436 | throw new SecurityException("requires " + permission); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 440 | /** |
| 441 | * Checks to see if the caller has a permission. |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 442 | * |
| 443 | * @return boolean TRUE if caller has the permission. |
| 444 | */ |
| 445 | public static boolean hasPermission(Context context, String permission) { |
| 446 | return context.checkCallingOrSelfPermission(permission) |
| 447 | == PackageManager.PERMISSION_GRANTED; |
| 448 | } |
| 449 | |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 450 | public static void assertAnyPermission(Context context, String... permissions) { |
| 451 | for (String permission : permissions) { |
| 452 | if (context.checkCallingOrSelfPermission(permission) == |
| 453 | PackageManager.PERMISSION_GRANTED) { |
| 454 | return; |
| 455 | } |
| 456 | } |
| 457 | throw new SecurityException("requires any of " + Arrays.toString(permissions)); |
| 458 | } |
| 459 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 460 | @Override |
| 461 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| 462 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 463 | != PackageManager.PERMISSION_GRANTED) { |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 464 | writer.println("Permission Denial: can't dump CarService from from pid=" |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 465 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() |
| 466 | + " without permission " + android.Manifest.permission.DUMP); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 467 | return; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 468 | } |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 469 | |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 470 | if (args == null || args.length == 0 || (args.length > 0 && "-a".equals(args[0]))) { |
| 471 | writer.println("*Dump car service*"); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 472 | writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT); |
| 473 | writer.println("*Dump all services*"); |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 474 | |
| 475 | dumpAllServices(writer, false); |
| 476 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 477 | writer.println("*Dump Vehicle HAL*"); |
| 478 | writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName); |
| 479 | try { |
| 480 | // TODO dump all feature flags by creating a dumpable interface |
| 481 | mHal.dump(writer); |
| 482 | } catch (Exception e) { |
| 483 | writer.println("Failed dumping: " + mHal.getClass().getName()); |
| 484 | e.printStackTrace(writer); |
| 485 | } |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 486 | } else if ("--metrics".equals(args[0])) { |
| 487 | writer.println("*Dump car service metrics*"); |
| 488 | dumpAllServices(writer, true); |
Mark Tabry | b588d2e | 2019-09-12 10:50:11 -0700 | [diff] [blame] | 489 | } else if ("--vms-hal".equals(args[0])) { |
| 490 | mHal.getVmsHal().dumpMetrics(fd); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 491 | } else if (Build.IS_USERDEBUG || Build.IS_ENG) { |
| 492 | execShellCmd(args, writer); |
| 493 | } else { |
| 494 | writer.println("Commands not supported in " + Build.TYPE); |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 498 | private void dumpAllServices(PrintWriter writer, boolean dumpMetricsOnly) { |
| 499 | for (CarServiceBase service : mAllServices) { |
| 500 | dumpService(service, writer, dumpMetricsOnly); |
| 501 | } |
| 502 | if (mCarTestService != null) { |
| 503 | dumpService(mCarTestService, writer, dumpMetricsOnly); |
| 504 | } |
| 505 | |
| 506 | } |
| 507 | |
| 508 | private void dumpService(CarServiceBase service, PrintWriter writer, boolean dumpMetricsOnly) { |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 509 | try { |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 510 | if (dumpMetricsOnly) { |
| 511 | service.dumpMetrics(writer); |
| 512 | } else { |
| 513 | service.dump(writer); |
| 514 | } |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 515 | } catch (Exception e) { |
| 516 | writer.println("Failed dumping: " + service.getClass().getName()); |
| 517 | e.printStackTrace(writer); |
| 518 | } |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 519 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 520 | |
| 521 | void execShellCmd(String[] args, PrintWriter writer) { |
| 522 | new CarShellCommand().exec(args, writer); |
| 523 | } |
| 524 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 525 | @MainThread |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 526 | private void traceBegin(String name) { |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 527 | Slog.i(TAG, name); |
| 528 | mBootTiming.traceBegin(name); |
| 529 | } |
| 530 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 531 | @MainThread |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 532 | private void traceEnd() { |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 533 | mBootTiming.traceEnd(); |
| 534 | } |
| 535 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 536 | private class CarShellCommand { |
| 537 | private static final String COMMAND_HELP = "-h"; |
| 538 | private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 539 | private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event"; |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 540 | private static final String COMMAND_INJECT_ERROR_EVENT = "inject-error-event"; |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 541 | private static final String COMMAND_ENABLE_UXR = "enable-uxr"; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 542 | private static final String COMMAND_GARAGE_MODE = "garage-mode"; |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 543 | private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities"; |
Kai | dd4ef5a | 2019-03-04 14:07:26 -0800 | [diff] [blame] | 544 | private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig"; |
Kai | 29fba11 | 2019-04-22 18:37:38 -0700 | [diff] [blame] | 545 | private static final String COMMAND_GET_PROPERTY_VALUE = "get-property-value"; |
Pavel Maltsev | 371d97f | 2019-05-20 14:51:31 -0700 | [diff] [blame] | 546 | private static final String COMMAND_PROJECTION_AP_TETHERING = "projection-tethering"; |
Pavel Maltsev | 48a3194 | 2019-03-03 22:08:28 -0800 | [diff] [blame] | 547 | private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode"; |
Jim Kaye | d76c274 | 2019-04-02 11:33:27 -0700 | [diff] [blame] | 548 | private static final String COMMAND_RESUME = "resume"; |
| 549 | private static final String COMMAND_SUSPEND = "suspend"; |
Ram Periathiruvadi | d26a3fb | 2019-04-15 14:48:23 -0700 | [diff] [blame] | 550 | private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device"; |
| 551 | private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices"; |
Oscar Azucena | 3f3a25e | 2019-07-12 14:28:24 -0700 | [diff] [blame] | 552 | private static final String COMMAND_SET_UID_TO_ZONE = "set-zoneid-for-uid"; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 553 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 554 | private static final String PARAM_DAY_MODE = "day"; |
| 555 | private static final String PARAM_NIGHT_MODE = "night"; |
| 556 | private static final String PARAM_SENSOR_MODE = "sensor"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 557 | private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0"; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 558 | private static final String PARAM_ON_MODE = "on"; |
| 559 | private static final String PARAM_OFF_MODE = "off"; |
| 560 | private static final String PARAM_QUERY_MODE = "query"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 561 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 562 | |
| 563 | private void dumpHelp(PrintWriter pw) { |
| 564 | pw.println("Car service commands:"); |
| 565 | pw.println("\t-h"); |
| 566 | pw.println("\t Print this help text."); |
| 567 | pw.println("\tday-night-mode [day|night|sensor]"); |
| 568 | pw.println("\t Force into day/night mode or restore to auto."); |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 569 | 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] | 570 | pw.println("\t Inject a vehicle property for testing."); |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 571 | pw.println("\tinject-error-event property zone errorCode"); |
| 572 | pw.println("\t Inject an error event from VHAL for testing."); |
Ram Periathiruvadi | d26a3fb | 2019-04-15 14:48:23 -0700 | [diff] [blame] | 573 | pw.println("\tenable-uxr true|false"); |
| 574 | pw.println("\t Enable/Disable UX restrictions and App blocking."); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 575 | pw.println("\tgarage-mode [on|off|query]"); |
| 576 | pw.println("\t Force into garage mode or check status."); |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 577 | pw.println("\tget-do-activities pkgname"); |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 578 | pw.println("\t Get Distraction Optimized activities in given package."); |
Kai | dd4ef5a | 2019-03-04 14:07:26 -0800 | [diff] [blame] | 579 | pw.println("\tget-carpropertyconfig [propertyId]"); |
| 580 | pw.println("\t Get a CarPropertyConfig by Id in Hex or list all CarPropertyConfigs"); |
Kai | 29fba11 | 2019-04-22 18:37:38 -0700 | [diff] [blame] | 581 | pw.println("\tget-property-value [propertyId] [areaId]"); |
| 582 | pw.println("\t Get a vehicle property value by property id in Hex and areaId"); |
| 583 | pw.println("\t or list all property values for all areaId"); |
Jim Kaye | d76c274 | 2019-04-02 11:33:27 -0700 | [diff] [blame] | 584 | pw.println("\tsuspend"); |
| 585 | pw.println("\t Suspend the system to Deep Sleep."); |
| 586 | pw.println("\tresume"); |
| 587 | pw.println("\t Wake the system up after a 'suspend.'"); |
Ram Periathiruvadi | d26a3fb | 2019-04-15 14:48:23 -0700 | [diff] [blame] | 588 | pw.println("\tenable-trusted-device true|false"); |
| 589 | pw.println("\t Enable/Disable Trusted device feature."); |
| 590 | pw.println("\tremove-trusted-devices"); |
| 591 | pw.println("\t Remove all trusted devices for the current foreground user."); |
Pavel Maltsev | 371d97f | 2019-05-20 14:51:31 -0700 | [diff] [blame] | 592 | pw.println("\tprojection-tethering [true|false]"); |
| 593 | pw.println("\t Whether tethering should be used when creating access point for" |
| 594 | + " wireless projection"); |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 595 | pw.println("\t--metrics"); |
| 596 | pw.println("\t When used with dumpsys, only metrics will be in the dumpsys output."); |
Oscar Azucena | 3f3a25e | 2019-07-12 14:28:24 -0700 | [diff] [blame] | 597 | pw.println("\tset-zoneid-for-uid [zoneid] [uid]"); |
| 598 | pw.println("\t Maps the audio zoneid to uid."); |
| 599 | } |
| 600 | |
| 601 | private String runSetZoneIdForUid(String zoneString, String uidString) { |
| 602 | int uid = Integer.parseInt(uidString); |
| 603 | int zoneId = Integer.parseInt(zoneString); |
| 604 | if (!ArrayUtils.contains(mCarAudioService.getAudioZoneIds(), zoneId)) { |
| 605 | return "zoneid " + zoneId + " not found"; |
| 606 | } |
| 607 | mCarAudioService.setZoneIdForUid(zoneId, uid); |
| 608 | return null; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 609 | } |
| 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 Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 617 | case COMMAND_DAY_NIGHT_MODE: { |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 618 | String value = args.length < 2 ? "" : args[1]; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 619 | forceDayNightMode(value, writer); |
| 620 | break; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 621 | } |
| 622 | case COMMAND_GARAGE_MODE: { |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 623 | String value = args.length < 2 ? "" : args[1]; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 624 | forceGarageMode(value, writer); |
| 625 | break; |
| 626 | } |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 627 | case COMMAND_INJECT_VHAL_EVENT: |
| 628 | String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL; |
| 629 | String data; |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 630 | if (args.length != 3 && args.length != 4) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 631 | writer.println("Incorrect number of arguments."); |
| 632 | dumpHelp(writer); |
| 633 | break; |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 634 | } else if (args.length == 4) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 635 | // Zoned |
| 636 | zone = args[2]; |
| 637 | data = args[3]; |
| 638 | } else { |
| 639 | // Global |
| 640 | data = args[2]; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 641 | } |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 642 | 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 Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 653 | break; |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 654 | case COMMAND_ENABLE_UXR: |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 655 | if (args.length != 2) { |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 656 | 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 Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 665 | case COMMAND_GET_DO_ACTIVITIES: |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 666 | if (args.length != 2) { |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 667 | 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; |
Kai | dd4ef5a | 2019-03-04 14:07:26 -0800 | [diff] [blame] | 686 | case COMMAND_GET_CARPROPERTYCONFIG: |
| 687 | String propertyId = args.length < 2 ? "" : args[1]; |
| 688 | mHal.dumpPropertyConfigs(writer, propertyId); |
| 689 | break; |
Kai | 29fba11 | 2019-04-22 18:37:38 -0700 | [diff] [blame] | 690 | 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 Maltsev | 48a3194 | 2019-03-03 22:08:28 -0800 | [diff] [blame] | 695 | 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 Maltsev | d6961f6 | 2019-03-26 10:22:31 -0700 | [diff] [blame] | 702 | break; |
Pavel Maltsev | 371d97f | 2019-05-20 14:51:31 -0700 | [diff] [blame] | 703 | 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 Kaye | d76c274 | 2019-04-02 11:33:27 -0700 | [diff] [blame] | 711 | 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 Periathiruvadi | d26a3fb | 2019-04-15 14:48:23 -0700 | [diff] [blame] | 719 | case COMMAND_ENABLE_TRUSTED_DEVICE: |
| 720 | if (args.length != 2) { |
| 721 | writer.println("Incorrect number of arguments"); |
| 722 | dumpHelp(writer); |
| 723 | break; |
| 724 | } |
| 725 | mCarTrustedDeviceService.getCarTrustAgentEnrollmentService() |
| 726 | .setTrustedDeviceEnrollmentEnabled(Boolean.valueOf(args[1])); |
| 727 | mCarTrustedDeviceService.getCarTrustAgentUnlockService() |
| 728 | .setTrustedDeviceUnlockEnabled(Boolean.valueOf(args[1])); |
| 729 | break; |
| 730 | case COMMAND_REMOVE_TRUSTED_DEVICES: |
| 731 | mCarTrustedDeviceService.getCarTrustAgentEnrollmentService() |
| 732 | .removeAllTrustedDevices( |
| 733 | mUserManagerHelper.getCurrentForegroundUserId()); |
| 734 | break; |
Oscar Azucena | 3f3a25e | 2019-07-12 14:28:24 -0700 | [diff] [blame] | 735 | case COMMAND_SET_UID_TO_ZONE: |
| 736 | if (args.length != 3) { |
| 737 | writer.println("Incorrect number of arguments"); |
| 738 | dumpHelp(writer); |
| 739 | break; |
| 740 | } |
| 741 | String results = runSetZoneIdForUid(args[1], args[2]); |
| 742 | if (results != null) { |
| 743 | writer.println(results); |
| 744 | dumpHelp(writer); |
| 745 | } |
| 746 | break; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 747 | default: |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 748 | writer.println("Unknown command: \"" + arg + "\""); |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 749 | dumpHelp(writer); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | private void forceDayNightMode(String arg, PrintWriter writer) { |
| 754 | int mode; |
| 755 | switch (arg) { |
| 756 | case PARAM_DAY_MODE: |
| 757 | mode = CarNightService.FORCED_DAY_MODE; |
| 758 | break; |
| 759 | case PARAM_NIGHT_MODE: |
| 760 | mode = CarNightService.FORCED_NIGHT_MODE; |
| 761 | break; |
| 762 | case PARAM_SENSOR_MODE: |
| 763 | mode = CarNightService.FORCED_SENSOR_MODE; |
| 764 | break; |
| 765 | default: |
| 766 | writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|" |
| 767 | + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE); |
| 768 | return; |
| 769 | } |
| 770 | int current = mCarNightService.forceDayNightMode(mode); |
| 771 | String currentMode = null; |
| 772 | switch (current) { |
| 773 | case UiModeManager.MODE_NIGHT_AUTO: |
| 774 | currentMode = PARAM_SENSOR_MODE; |
| 775 | break; |
| 776 | case UiModeManager.MODE_NIGHT_YES: |
| 777 | currentMode = PARAM_NIGHT_MODE; |
| 778 | break; |
| 779 | case UiModeManager.MODE_NIGHT_NO: |
| 780 | currentMode = PARAM_DAY_MODE; |
| 781 | break; |
| 782 | } |
| 783 | writer.println("DayNightMode changed to: " + currentMode); |
| 784 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 785 | |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 786 | private void forceGarageMode(String arg, PrintWriter writer) { |
| 787 | switch (arg) { |
| 788 | case PARAM_ON_MODE: |
Serik Beketayev | e0e7ff2 | 2018-07-31 21:04:12 -0700 | [diff] [blame] | 789 | mGarageModeService.forceStartGarageMode(); |
Jim Kaye | 1b5e618 | 2019-05-24 15:48:32 -0700 | [diff] [blame] | 790 | writer.println("Garage mode: " + mGarageModeService.isGarageModeActive()); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 791 | break; |
| 792 | case PARAM_OFF_MODE: |
Serik Beketayev | e0e7ff2 | 2018-07-31 21:04:12 -0700 | [diff] [blame] | 793 | mGarageModeService.stopAndResetGarageMode(); |
Jim Kaye | 1b5e618 | 2019-05-24 15:48:32 -0700 | [diff] [blame] | 794 | writer.println("Garage mode: " + mGarageModeService.isGarageModeActive()); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 795 | break; |
| 796 | case PARAM_QUERY_MODE: |
Jim Kaye | 1b5e618 | 2019-05-24 15:48:32 -0700 | [diff] [blame] | 797 | mGarageModeService.dump(writer); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 798 | break; |
| 799 | default: |
| 800 | writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|" |
| 801 | + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 802 | } |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 803 | } |
| 804 | |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 805 | /** |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 806 | * Inject a fake VHAL event |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 807 | * |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 808 | * @param property the Vehicle property Id as defined in the HAL |
| 809 | * @param zone Zone that this event services |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 810 | * @param isErrorEvent indicates the type of event |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 811 | * @param value Data value of the event |
| 812 | * @param writer PrintWriter |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 813 | */ |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 814 | private void injectVhalEvent(String property, String zone, String value, |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 815 | boolean isErrorEvent, PrintWriter writer) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 816 | if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) { |
| 817 | if (!isPropertyAreaTypeGlobal(property)) { |
| 818 | writer.println("Property area type inconsistent with given zone"); |
| 819 | return; |
| 820 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 821 | } |
| 822 | try { |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 823 | if (isErrorEvent) { |
| 824 | mHal.injectOnPropertySetError(property, zone, value); |
| 825 | } else { |
| 826 | mHal.injectVhalEvent(property, zone, value); |
| 827 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 828 | } catch (NumberFormatException e) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 829 | writer.println("Invalid property Id zone Id or value" + e); |
| 830 | dumpHelp(writer); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 831 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 834 | // Check if the given property is global |
| 835 | private boolean isPropertyAreaTypeGlobal(String property) { |
| 836 | if (property == null) { |
| 837 | return false; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 838 | } |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 839 | return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 840 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 841 | } |
kevinjm | 55822c4 | 2018-08-15 11:26:00 -0700 | [diff] [blame] | 842 | } |