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; |
felipeal | 080e565 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Keun young Park | f3523cd | 2019-04-08 10:09:17 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Keun young Park | 09ca849 | 2019-10-15 10:34:11 -0700 | [diff] [blame] | 22 | import android.app.ActivityOptions; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 23 | import android.app.UiModeManager; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 24 | import android.car.Car; |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 25 | import android.car.CarFeatures; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 26 | import android.car.ICar; |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 27 | import android.car.cluster.renderer.IInstrumentClusterNavigation; |
Felipe Leme | e93218b | 2020-02-13 14:10:52 -0800 | [diff] [blame] | 28 | import android.car.user.CarUserManager; |
Ying Zheng | 9fc9940 | 2018-09-19 14:23:59 -0700 | [diff] [blame] | 29 | import android.car.userlib.CarUserManagerHelper; |
Keun young Park | 09ca849 | 2019-10-15 10:34:11 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 31 | import android.content.Context; |
Keun young Park | 09ca849 | 2019-10-15 10:34:11 -0700 | [diff] [blame] | 32 | import android.content.Intent; |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Keun young Park | f3523cd | 2019-04-08 10:09:17 -0700 | [diff] [blame] | 34 | import android.content.res.Resources; |
Pavel Maltsev | cfe9310 | 2017-02-02 12:38:08 -0800 | [diff] [blame] | 35 | import android.hardware.automotive.vehicle.V2_0.IVehicle; |
Felipe Leme | a5e6938 | 2020-02-11 17:53:20 -0800 | [diff] [blame] | 36 | import android.hardware.automotive.vehicle.V2_0.InitialUserInfoResponseAction; |
| 37 | import android.hardware.automotive.vehicle.V2_0.UsersInfo; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 38 | import android.hardware.automotive.vehicle.V2_0.VehicleArea; |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 39 | import android.os.Binder; |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 40 | import android.os.Build; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 41 | import android.os.IBinder; |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 42 | import android.os.Process; |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 43 | import android.os.RemoteException; |
| 44 | import android.os.ResultReceiver; |
| 45 | import android.os.ShellCallback; |
| 46 | import android.os.ShellCommand; |
Keun young Park | 313dfaf | 2019-12-19 11:32:38 -0800 | [diff] [blame] | 47 | import android.os.SystemClock; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 48 | import android.os.Trace; |
Anthony Hugh | 9932a25 | 2019-06-12 16:19:56 -0700 | [diff] [blame] | 49 | import android.os.UserManager; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 50 | import android.util.Log; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 51 | import android.util.Slog; |
Keun-young Park | 4a79a38 | 2017-08-10 18:19:14 -0700 | [diff] [blame] | 52 | import android.util.TimingsTraceLog; |
Keun young Park | 313dfaf | 2019-12-19 11:32:38 -0800 | [diff] [blame] | 53 | import android.view.KeyEvent; |
Gregory Clark | 26fa601 | 2018-03-14 18:38:56 -0700 | [diff] [blame] | 54 | |
Keun young Park | a4d1220 | 2019-10-03 10:51:12 -0700 | [diff] [blame] | 55 | import com.android.car.am.FixedActivityService; |
Hongwei Wang | 3854909 | 2018-08-22 12:32:42 -0700 | [diff] [blame] | 56 | import com.android.car.audio.CarAudioService; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 57 | import com.android.car.cluster.InstrumentClusterService; |
Serik Beketayev | 06a6668 | 2018-06-12 16:54:29 -0700 | [diff] [blame] | 58 | import com.android.car.garagemode.GarageModeService; |
Keun young Park | 313dfaf | 2019-12-19 11:32:38 -0800 | [diff] [blame] | 59 | import com.android.car.hal.InputHalService; |
Felipe Leme | a5e6938 | 2020-02-11 17:53:20 -0800 | [diff] [blame] | 60 | import com.android.car.hal.UserHalHelper; |
| 61 | import com.android.car.hal.UserHalService; |
| 62 | import com.android.car.hal.UserHalService.HalCallback; |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 63 | import com.android.car.hal.VehicleHal; |
Keun-young Park | 4aeb4bf | 2015-12-08 18:31:33 -0800 | [diff] [blame] | 64 | import com.android.car.pm.CarPackageManagerService; |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 65 | import com.android.car.stats.CarStatsService; |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 66 | import com.android.car.systeminterface.SystemInterface; |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 67 | import com.android.car.trust.CarTrustedDeviceService; |
Keun young Park | 7af7d6c | 2019-09-12 10:31:48 -0700 | [diff] [blame] | 68 | import com.android.car.user.CarUserNoticeService; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 69 | import com.android.car.user.CarUserService; |
Felipe Leme | e93218b | 2020-02-13 14:10:52 -0800 | [diff] [blame] | 70 | import com.android.car.user.UserMetrics; |
Mark Tabry | 6fa123d | 2020-01-10 19:52:59 -0800 | [diff] [blame] | 71 | import com.android.car.vms.VmsNewBrokerService; |
Eric Jeong | ae2c04c | 2020-02-21 09:18:31 -0800 | [diff] [blame] | 72 | import com.android.car.watchdog.CarWatchdogService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 73 | import com.android.internal.annotations.GuardedBy; |
Felipe Leme | 6ef8965 | 2019-12-19 16:47:14 -0800 | [diff] [blame] | 74 | import com.android.internal.annotations.VisibleForTesting; |
Steve Paik | 1d8bea2 | 2018-02-03 01:54:06 +0000 | [diff] [blame] | 75 | import com.android.internal.car.ICarServiceHelper; |
Felipe Leme | e2600fc | 2020-02-26 11:06:04 -0800 | [diff] [blame] | 76 | import com.android.internal.os.IResultReceiver; |
Oscar Azucena | 3f3a25e | 2019-07-12 14:28:24 -0700 | [diff] [blame] | 77 | import com.android.internal.util.ArrayUtils; |
Gregory Clark | 26fa601 | 2018-03-14 18:38:56 -0700 | [diff] [blame] | 78 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 79 | import java.io.FileDescriptor; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 80 | import java.io.PrintWriter; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 81 | import java.util.ArrayList; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 82 | import java.util.Arrays; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 83 | import java.util.List; |
Felipe Leme | a5e6938 | 2020-02-11 17:53:20 -0800 | [diff] [blame] | 84 | import java.util.concurrent.CountDownLatch; |
| 85 | import java.util.concurrent.TimeUnit; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 86 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 87 | public class ICarImpl extends ICar.Stub { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 88 | |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 89 | public static final String INTERNAL_INPUT_SERVICE = "internal_input"; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 90 | public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE = |
| 91 | "system_activity_monitoring"; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 92 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 93 | private final Context mContext; |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 94 | private final VehicleHal mHal; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 95 | |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 96 | private final CarFeatureController mFeatureController; |
| 97 | |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 98 | private final SystemInterface mSystemInterface; |
| 99 | |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 100 | private final SystemActivityMonitoringService mSystemActivityMonitoringService; |
keunyoung | 4b0212c | 2015-10-29 17:11:57 -0700 | [diff] [blame] | 101 | private final CarPowerManagementService mCarPowerManagementService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 102 | private final CarPackageManagerService mCarPackageManagerService; |
| 103 | private final CarInputService mCarInputService; |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 104 | private final CarDrivingStateService mCarDrivingStateService; |
Ram Periathiruvadi | 4526a43 | 2018-01-24 13:00:54 -0800 | [diff] [blame] | 105 | private final CarUxRestrictionsManagerService mCarUXRestrictionsService; |
Michael Keller | c0f0bdb | 2019-12-11 14:58:19 -0800 | [diff] [blame] | 106 | private final OccupantAwarenessService mOccupantAwarenessService; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 107 | private final CarAudioService mCarAudioService; |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 108 | private final CarProjectionService mCarProjectionService; |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 109 | private final CarPropertyService mCarPropertyService; |
Joseph Pirozzo | 317343d | 2016-01-25 10:22:37 -0800 | [diff] [blame] | 110 | private final CarNightService mCarNightService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 111 | private final AppFocusService mAppFocusService; |
Keun young Park | a4d1220 | 2019-10-03 10:51:12 -0700 | [diff] [blame] | 112 | private final FixedActivityService mFixedActivityService; |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 113 | private final GarageModeService mGarageModeService; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 114 | private final InstrumentClusterService mInstrumentClusterService; |
Gregory Clark | d813606 | 2017-12-11 14:27:53 -0800 | [diff] [blame] | 115 | private final CarLocationService mCarLocationService; |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 116 | private final SystemStateControllerService mSystemStateControllerService; |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 117 | private final CarBluetoothService mCarBluetoothService; |
Ram Periathiruvadi | acb6024 | 2017-04-13 16:19:09 -0700 | [diff] [blame] | 118 | private final PerUserCarServiceHelper mPerUserCarServiceHelper; |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 119 | private final CarDiagnosticService mCarDiagnosticService; |
| 120 | private final CarStorageMonitoringService mCarStorageMonitoringService; |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 121 | private final CarConfigurationService mCarConfigurationService; |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 122 | private final CarTrustedDeviceService mCarTrustedDeviceService; |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 123 | private final CarMediaService mCarMediaService; |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 124 | private final CarUserManagerHelper mUserManagerHelper; |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 125 | private final CarUserService mCarUserService; |
Keun young Park | bb877e2 | 2019-08-02 10:38:01 -0700 | [diff] [blame] | 126 | private final CarOccupantZoneService mCarOccupantZoneService; |
Keun young Park | 7af7d6c | 2019-09-12 10:31:48 -0700 | [diff] [blame] | 127 | private final CarUserNoticeService mCarUserNoticeService; |
Mark Tabry | 6fa123d | 2020-01-10 19:52:59 -0800 | [diff] [blame] | 128 | private final VmsNewBrokerService mVmsBrokerService; |
Selim Gurun | c8c82f6 | 2019-04-17 14:07:30 -0700 | [diff] [blame] | 129 | private final CarBugreportManagerService mCarBugreportManagerService; |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 130 | private final CarStatsService mCarStatsService; |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 131 | private final CarExperimentalFeatureServiceController mCarExperimentalFeatureServiceController; |
Eric Jeong | ae2c04c | 2020-02-21 09:18:31 -0800 | [diff] [blame] | 132 | private final CarWatchdogService mCarWatchdogService; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 133 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 134 | private final CarServiceBase[] mAllServices; |
| 135 | |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 136 | private static final String TAG = "ICarImpl"; |
| 137 | private static final String VHAL_TIMING_TAG = "VehicleHalTiming"; |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 138 | |
| 139 | private TimingsTraceLog mBootTiming; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 140 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 141 | /** Test only service. Populate it only when necessary. */ |
| 142 | @GuardedBy("this") |
| 143 | private CarTestService mCarTestService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 144 | |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 145 | @GuardedBy("this") |
| 146 | private ICarServiceHelper mICarServiceHelper; |
| 147 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 148 | private final String mVehicleInterfaceName; |
| 149 | |
Felipe Leme | e93218b | 2020-02-13 14:10:52 -0800 | [diff] [blame] | 150 | private final UserMetrics mUserMetrics = new UserMetrics(); |
| 151 | |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 152 | public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface, |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 153 | CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) { |
Felipe Leme | 6ef8965 | 2019-12-19 16:47:14 -0800 | [diff] [blame] | 154 | this(serviceContext, vehicle, systemInterface, errorNotifier, vehicleInterfaceName, |
Eric Jeong | ae2c04c | 2020-02-21 09:18:31 -0800 | [diff] [blame] | 155 | /* carUserService= */ null, /* carWatchdogService= */ null); |
Felipe Leme | 6ef8965 | 2019-12-19 16:47:14 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | @VisibleForTesting |
| 159 | ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface, |
| 160 | CanBusErrorNotifier errorNotifier, String vehicleInterfaceName, |
Eric Jeong | ae2c04c | 2020-02-21 09:18:31 -0800 | [diff] [blame] | 161 | @Nullable CarUserService carUserService, |
| 162 | @Nullable CarWatchdogService carWatchdogService) { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 163 | mContext = serviceContext; |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame] | 164 | mSystemInterface = systemInterface; |
Mark Tabry | b588d2e | 2019-09-12 10:50:11 -0700 | [diff] [blame] | 165 | mHal = new VehicleHal(serviceContext, vehicle); |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 166 | Resources res = mContext.getResources(); |
| 167 | String[] defaultEnabledFeatures = res.getStringArray( |
| 168 | R.array.config_allowed_optional_car_features); |
| 169 | // Do this before any other service components to allow feature check. It should work |
| 170 | // even without init. |
| 171 | // TODO (b/144504820) Add vhal plumbing |
| 172 | mFeatureController = new CarFeatureController(serviceContext, defaultEnabledFeatures, |
| 173 | /* disabledFeaturesFromVhal= */ new String[0], mSystemInterface.getSystemCarDir()); |
| 174 | CarLocalServices.addService(CarFeatureController.class, mFeatureController); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 175 | mVehicleInterfaceName = vehicleInterfaceName; |
Yao, Yuxing | 0811d5a | 2018-11-29 16:18:53 -0800 | [diff] [blame] | 176 | mUserManagerHelper = new CarUserManagerHelper(serviceContext); |
Felipe Leme | 6ef8965 | 2019-12-19 16:47:14 -0800 | [diff] [blame] | 177 | if (carUserService != null) { |
| 178 | mCarUserService = carUserService; |
| 179 | } else { |
| 180 | UserManager userManager = |
| 181 | (UserManager) serviceContext.getSystemService(Context.USER_SERVICE); |
| 182 | int maxRunningUsers = res.getInteger( |
| 183 | com.android.internal.R.integer.config_multiuserMaxRunningUsers); |
Felipe Leme | 5841220 | 2020-01-09 13:45:33 -0800 | [diff] [blame] | 184 | mCarUserService = new CarUserService(serviceContext, mHal.getUserHal(), |
| 185 | mUserManagerHelper, userManager, ActivityManager.getService(), maxRunningUsers); |
Felipe Leme | 6ef8965 | 2019-12-19 16:47:14 -0800 | [diff] [blame] | 186 | } |
Keun young Park | bb877e2 | 2019-08-02 10:38:01 -0700 | [diff] [blame] | 187 | mCarOccupantZoneService = new CarOccupantZoneService(serviceContext); |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 188 | mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext); |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 189 | mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(), |
Felipe Leme | e3cab98 | 2020-03-12 11:39:29 -0700 | [diff] [blame] | 190 | systemInterface, mUserManagerHelper, mCarUserService); |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 191 | if (mFeatureController.isFeatureEnabled(CarFeatures.FEATURE_CAR_USER_NOTICE_SERVICE)) { |
| 192 | mCarUserNoticeService = new CarUserNoticeService(serviceContext); |
| 193 | } else { |
| 194 | mCarUserNoticeService = null; |
| 195 | } |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 196 | mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal()); |
| 197 | mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService); |
Ram Periathiruvadi | 4526a43 | 2018-01-24 13:00:54 -0800 | [diff] [blame] | 198 | mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext, |
Yao, Yuxing | 9bfb749 | 2019-02-15 11:53:34 -0800 | [diff] [blame] | 199 | mCarDrivingStateService, mCarPropertyService); |
Michael Keller | c0f0bdb | 2019-12-11 14:58:19 -0800 | [diff] [blame] | 200 | if (mFeatureController.isFeatureEnabled(Car.OCCUPANT_AWARENESS_SERVICE)) { |
| 201 | mOccupantAwarenessService = new OccupantAwarenessService(serviceContext); |
| 202 | } else { |
| 203 | mOccupantAwarenessService = null; |
| 204 | } |
Ram Periathiruvadi | 2da6d0e | 2018-01-26 18:02:10 -0800 | [diff] [blame] | 205 | mCarPackageManagerService = new CarPackageManagerService(serviceContext, |
| 206 | mCarUXRestrictionsService, |
Mayank Garg | 31e7304 | 2020-01-23 00:10:38 -0800 | [diff] [blame] | 207 | mSystemActivityMonitoringService, |
| 208 | mCarUserService); |
| 209 | mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext, mCarUserService); |
Sal Savage | 703c46f | 2019-04-15 08:39:25 -0700 | [diff] [blame] | 210 | mCarBluetoothService = new CarBluetoothService(serviceContext, mPerUserCarServiceHelper); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 211 | mCarInputService = new CarInputService(serviceContext, mHal.getInputHal()); |
Justin Paupore | 44985ba | 2019-01-30 18:53:41 -0800 | [diff] [blame] | 212 | mCarProjectionService = new CarProjectionService( |
Pavel Maltsev | 079873b | 2019-02-25 12:15:09 -0800 | [diff] [blame] | 213 | serviceContext, null /* handler */, mCarInputService, mCarBluetoothService); |
Serik Beketayev | c6ab8be | 2018-08-28 21:20:53 -0700 | [diff] [blame] | 214 | mGarageModeService = new GarageModeService(mContext); |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 215 | mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService); |
Hongwei Wang | 3055723 | 2018-01-02 10:25:08 -0800 | [diff] [blame] | 216 | mCarAudioService = new CarAudioService(serviceContext); |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 217 | mCarNightService = new CarNightService(serviceContext, mCarPropertyService); |
Keun young Park | a4d1220 | 2019-10-03 10:51:12 -0700 | [diff] [blame] | 218 | mFixedActivityService = new FixedActivityService(serviceContext); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 219 | mInstrumentClusterService = new InstrumentClusterService(serviceContext, |
Pavel Maltsev | 03cf60c | 2016-06-27 15:11:51 -0700 | [diff] [blame] | 220 | mAppFocusService, mCarInputService); |
Serik Beketayev | f9f2ef0 | 2018-09-06 12:37:02 -0700 | [diff] [blame] | 221 | mSystemStateControllerService = new SystemStateControllerService( |
| 222 | serviceContext, mCarAudioService, this); |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 223 | mCarStatsService = new CarStatsService(serviceContext); |
Ruchir Rastogi | a683d74 | 2020-01-22 00:17:51 -0800 | [diff] [blame] | 224 | mCarStatsService.init(); |
Mark Tabry | 62e749c | 2020-01-10 19:52:59 -0800 | [diff] [blame] | 225 | if (mFeatureController.isFeatureEnabled(Car.VEHICLE_MAP_SERVICE) |
| 226 | || mFeatureController.isFeatureEnabled(Car.VMS_SUBSCRIBER_SERVICE)) { |
Mark Tabry | 6fa123d | 2020-01-10 19:52:59 -0800 | [diff] [blame] | 227 | mVmsBrokerService = new VmsNewBrokerService(mContext, mCarStatsService); |
Keun young Park | c6d80af | 2020-01-17 18:14:28 -0800 | [diff] [blame] | 228 | } else { |
| 229 | mVmsBrokerService = null; |
Mark Tabry | 6fa123d | 2020-01-10 19:52:59 -0800 | [diff] [blame] | 230 | } |
Keun young Park | c6d80af | 2020-01-17 18:14:28 -0800 | [diff] [blame] | 231 | if (mFeatureController.isFeatureEnabled(Car.DIAGNOSTIC_SERVICE)) { |
| 232 | mCarDiagnosticService = new CarDiagnosticService(serviceContext, |
| 233 | mHal.getDiagnosticHal()); |
| 234 | } else { |
| 235 | mCarDiagnosticService = null; |
| 236 | } |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 237 | if (mFeatureController.isFeatureEnabled(Car.STORAGE_MONITORING_SERVICE)) { |
| 238 | mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext, |
| 239 | systemInterface); |
| 240 | } else { |
| 241 | mCarStorageMonitoringService = null; |
| 242 | } |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 243 | mCarConfigurationService = |
| 244 | new CarConfigurationService(serviceContext, new JsonReaderImpl()); |
Anthony Hugh | 5f2465e | 2019-10-08 15:07:01 -0700 | [diff] [blame] | 245 | mCarLocationService = new CarLocationService(serviceContext); |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 246 | mCarTrustedDeviceService = new CarTrustedDeviceService(serviceContext); |
Mayank Garg | 31e7304 | 2020-01-23 00:10:38 -0800 | [diff] [blame] | 247 | mCarMediaService = new CarMediaService(serviceContext, mCarUserService); |
Selim Gurun | c8c82f6 | 2019-04-17 14:07:30 -0700 | [diff] [blame] | 248 | mCarBugreportManagerService = new CarBugreportManagerService(serviceContext); |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 249 | if (!Build.IS_USER) { |
| 250 | mCarExperimentalFeatureServiceController = new CarExperimentalFeatureServiceController( |
| 251 | serviceContext); |
| 252 | } else { |
| 253 | mCarExperimentalFeatureServiceController = null; |
| 254 | } |
Eric Jeong | ae2c04c | 2020-02-21 09:18:31 -0800 | [diff] [blame] | 255 | if (carWatchdogService == null) { |
| 256 | mCarWatchdogService = new CarWatchdogService(serviceContext); |
| 257 | } else { |
| 258 | mCarWatchdogService = carWatchdogService; |
| 259 | } |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 260 | |
Keun young Park | a5fa478 | 2019-04-16 18:56:27 -0700 | [diff] [blame] | 261 | CarLocalServices.addService(CarPowerManagementService.class, mCarPowerManagementService); |
Keun young Park | bb877e2 | 2019-08-02 10:38:01 -0700 | [diff] [blame] | 262 | CarLocalServices.addService(CarPropertyService.class, mCarPropertyService); |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 263 | CarLocalServices.addService(CarUserService.class, mCarUserService); |
Gregory Clark | 18a0ef9 | 2019-05-23 20:00:49 -0700 | [diff] [blame] | 264 | CarLocalServices.addService(CarTrustedDeviceService.class, mCarTrustedDeviceService); |
Mayank Garg | fc24d57 | 2020-02-14 11:32:34 -0800 | [diff] [blame] | 265 | CarLocalServices.addService(CarUserNoticeService.class, mCarUserNoticeService); |
Gregory Clark | a440e81 | 2019-02-14 16:05:51 -0800 | [diff] [blame] | 266 | CarLocalServices.addService(SystemInterface.class, mSystemInterface); |
Gregory Clark | 18a0ef9 | 2019-05-23 20:00:49 -0700 | [diff] [blame] | 267 | CarLocalServices.addService(CarDrivingStateService.class, mCarDrivingStateService); |
Gregory Clark | 55620c1 | 2019-06-03 17:42:58 -0700 | [diff] [blame] | 268 | CarLocalServices.addService(PerUserCarServiceHelper.class, mPerUserCarServiceHelper); |
Keun young Park | a4d1220 | 2019-10-03 10:51:12 -0700 | [diff] [blame] | 269 | CarLocalServices.addService(FixedActivityService.class, mFixedActivityService); |
Mark Tabry | 62e749c | 2020-01-10 19:52:59 -0800 | [diff] [blame] | 270 | CarLocalServices.addService(VmsNewBrokerService.class, mVmsBrokerService); |
Oscar Azucena | a48a118 | 2020-02-20 16:43:15 -0800 | [diff] [blame] | 271 | CarLocalServices.addService(CarOccupantZoneService.class, mCarOccupantZoneService); |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 272 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 273 | // 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] | 274 | List<CarServiceBase> allServices = new ArrayList<>(); |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 275 | allServices.add(mFeatureController); |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 276 | allServices.add(mCarUserService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 277 | allServices.add(mSystemActivityMonitoringService); |
| 278 | allServices.add(mCarPowerManagementService); |
| 279 | allServices.add(mCarPropertyService); |
| 280 | allServices.add(mCarDrivingStateService); |
Keun young Park | bb877e2 | 2019-08-02 10:38:01 -0700 | [diff] [blame] | 281 | allServices.add(mCarOccupantZoneService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 282 | allServices.add(mCarUXRestrictionsService); |
Michael Keller | c0f0bdb | 2019-12-11 14:58:19 -0800 | [diff] [blame] | 283 | addServiceIfNonNull(allServices, mOccupantAwarenessService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 284 | allServices.add(mCarPackageManagerService); |
| 285 | allServices.add(mCarInputService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 286 | allServices.add(mGarageModeService); |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 287 | addServiceIfNonNull(allServices, mCarUserNoticeService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 288 | allServices.add(mAppFocusService); |
| 289 | allServices.add(mCarAudioService); |
| 290 | allServices.add(mCarNightService); |
Keun young Park | a4d1220 | 2019-10-03 10:51:12 -0700 | [diff] [blame] | 291 | allServices.add(mFixedActivityService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 292 | allServices.add(mInstrumentClusterService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 293 | allServices.add(mSystemStateControllerService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 294 | allServices.add(mPerUserCarServiceHelper); |
Justin Paupore | 44985ba | 2019-01-30 18:53:41 -0800 | [diff] [blame] | 295 | allServices.add(mCarBluetoothService); |
| 296 | allServices.add(mCarProjectionService); |
Keun young Park | c6d80af | 2020-01-17 18:14:28 -0800 | [diff] [blame] | 297 | addServiceIfNonNull(allServices, mCarDiagnosticService); |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 298 | addServiceIfNonNull(allServices, mCarStorageMonitoringService); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 299 | allServices.add(mCarConfigurationService); |
Mark Tabry | 6fa123d | 2020-01-10 19:52:59 -0800 | [diff] [blame] | 300 | addServiceIfNonNull(allServices, mVmsBrokerService); |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 301 | allServices.add(mCarTrustedDeviceService); |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 302 | allServices.add(mCarMediaService); |
Gregory Clark | a63ba02 | 2018-06-07 16:42:12 -0700 | [diff] [blame] | 303 | allServices.add(mCarLocationService); |
Selim Gurun | c8c82f6 | 2019-04-17 14:07:30 -0700 | [diff] [blame] | 304 | allServices.add(mCarBugreportManagerService); |
Eric Jeong | ae2c04c | 2020-02-21 09:18:31 -0800 | [diff] [blame] | 305 | allServices.add(mCarWatchdogService); |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 306 | // Always put mCarExperimentalFeatureServiceController in last. |
| 307 | addServiceIfNonNull(allServices, mCarExperimentalFeatureServiceController); |
Ying Zheng | 86d1c3e | 2018-05-11 11:42:48 -0700 | [diff] [blame] | 308 | mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 311 | private void addServiceIfNonNull(List<CarServiceBase> services, CarServiceBase service) { |
| 312 | if (service != null) { |
| 313 | services.add(service); |
| 314 | } |
| 315 | } |
| 316 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 317 | @MainThread |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 318 | void init() { |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 319 | mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, Trace.TRACE_TAG_HAL); |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 320 | traceBegin("VehicleHal.init"); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 321 | mHal.init(); |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 322 | traceEnd(); |
| 323 | traceBegin("CarService.initAllServices"); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 324 | for (CarServiceBase service : mAllServices) { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 325 | service.init(); |
| 326 | } |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 327 | traceEnd(); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 330 | void release() { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 331 | // release done in opposite order from init |
| 332 | for (int i = mAllServices.length - 1; i >= 0; i--) { |
| 333 | mAllServices[i].release(); |
| 334 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 335 | mHal.release(); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 338 | void vehicleHalReconnected(IVehicle vehicle) { |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 339 | mHal.vehicleHalReconnected(vehicle); |
| 340 | for (CarServiceBase service : mAllServices) { |
| 341 | service.vehicleHalReconnected(); |
| 342 | } |
| 343 | } |
| 344 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 345 | @Override |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 346 | public void setCarServiceHelper(IBinder helper) { |
Pavel Maltsev | 17e8183 | 2019-04-04 14:38:41 -0700 | [diff] [blame] | 347 | assertCallingFromSystemProcess(); |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 348 | synchronized (this) { |
| 349 | mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper); |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame] | 350 | mSystemInterface.setCarServiceHelper(mICarServiceHelper); |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | @Override |
Felipe Leme | e93218b | 2020-02-13 14:10:52 -0800 | [diff] [blame] | 355 | public void onUserLifecycleEvent(int eventType, long timestampMs, int fromUserId, |
| 356 | int toUserId) { |
| 357 | assertCallingFromSystemProcess(); |
| 358 | Log.i(TAG, "onUserLifecycleEvent(" + CarUserManager.lifecycleEventTypeToString(eventType) |
Felipe Leme | e2600fc | 2020-02-26 11:06:04 -0800 | [diff] [blame] | 359 | + ", " + toUserId + ")"); |
Felipe Leme | e93218b | 2020-02-13 14:10:52 -0800 | [diff] [blame] | 360 | mUserMetrics.onEvent(eventType, timestampMs, fromUserId, toUserId); |
Antonio Kantek | 991ba0b | 2020-03-12 14:28:21 -0700 | [diff] [blame] | 361 | if (eventType == CarUserManager.USER_LIFECYCLE_EVENT_TYPE_UNLOCKING) { |
| 362 | setUserLockStatus(toUserId); |
| 363 | } else if (eventType == CarUserManager.USER_LIFECYCLE_EVENT_TYPE_SWITCHING) { |
| 364 | onSwitchUser(toUserId); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | private void setUserLockStatus(int userId) { |
| 369 | mCarUserService.setUserLockStatus(userId, /* unlocked= */ true); |
| 370 | mCarMediaService.setUserLockStatus(userId, /* unlocked= */ true); |
| 371 | } |
| 372 | |
| 373 | private void onSwitchUser(int userId) { |
| 374 | Log.i(TAG, "Foreground user switched to " + userId); |
| 375 | mCarUserService.onSwitchUser(userId); |
Felipe Leme | e93218b | 2020-02-13 14:10:52 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 378 | @Override |
Felipe Leme | 30b4e1e | 2020-02-25 10:26:07 -0800 | [diff] [blame] | 379 | public void onFirstUserUnlocked(int userId, long timestampMs, long duration) { |
| 380 | mUserMetrics.logFirstUnlockedUser(userId, timestampMs, duration); |
| 381 | } |
| 382 | |
| 383 | @Override |
Felipe Leme | e2600fc | 2020-02-26 11:06:04 -0800 | [diff] [blame] | 384 | public void getInitialUserInfo(int requestType, int timeoutMs, IBinder binder) { |
| 385 | IResultReceiver receiver = IResultReceiver.Stub.asInterface(binder); |
| 386 | mCarUserService.getInitialUserInfo(requestType, timeoutMs, receiver); |
| 387 | } |
| 388 | |
| 389 | @Override |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 390 | public boolean isFeatureEnabled(String featureName) { |
| 391 | return mFeatureController.isFeatureEnabled(featureName); |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public int enableFeature(String featureName) { |
| 396 | // permission check inside the controller |
| 397 | return mFeatureController.enableFeature(featureName); |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public int disableFeature(String featureName) { |
| 402 | // permission check inside the controller |
| 403 | return mFeatureController.disableFeature(featureName); |
| 404 | } |
| 405 | |
| 406 | @Override |
| 407 | public List<String> getAllEnabledFeatures() { |
| 408 | // permission check inside the controller |
| 409 | return mFeatureController.getAllEnabledFeatures(); |
| 410 | } |
| 411 | |
| 412 | @Override |
| 413 | public List<String> getAllPendingDisabledFeatures() { |
| 414 | // permission check inside the controller |
| 415 | return mFeatureController.getAllPendingDisabledFeatures(); |
| 416 | } |
| 417 | |
| 418 | @Override |
| 419 | public List<String> getAllPendingEnabledFeatures() { |
| 420 | // permission check inside the controller |
| 421 | return mFeatureController.getAllPendingEnabledFeatures(); |
| 422 | } |
| 423 | |
| 424 | @Override |
| 425 | public String getCarManagerClassForFeature(String featureName) { |
| 426 | if (mCarExperimentalFeatureServiceController == null) { |
| 427 | return null; |
| 428 | } |
| 429 | return mCarExperimentalFeatureServiceController.getCarManagerClassForFeature(featureName); |
| 430 | } |
| 431 | |
Jim Kaye | e513316 | 2019-04-22 12:50:27 -0700 | [diff] [blame] | 432 | static void assertCallingFromSystemProcess() { |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 433 | int uid = Binder.getCallingUid(); |
| 434 | if (uid != Process.SYSTEM_UID) { |
| 435 | throw new SecurityException("Only allowed from system"); |
| 436 | } |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Keun young Park | aabecd9 | 2019-05-03 17:31:27 -0700 | [diff] [blame] | 439 | /** |
| 440 | * Assert if binder call is coming from system process like system server or if it is called |
| 441 | * from its own process even if it is not system. The latter can happen in test environment. |
| 442 | * Note that car service runs as system user but test like car service test will not. |
| 443 | */ |
| 444 | static void assertCallingFromSystemProcessOrSelf() { |
| 445 | int uid = Binder.getCallingUid(); |
| 446 | int pid = Binder.getCallingPid(); |
| 447 | if (uid != Process.SYSTEM_UID && pid != Process.myPid()) { |
| 448 | throw new SecurityException("Only allowed from system or self"); |
| 449 | } |
| 450 | } |
| 451 | |
Keun-young Park | d462a91 | 2019-02-11 08:53:42 -0800 | [diff] [blame] | 452 | @Override |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 453 | public IBinder getCarService(String serviceName) { |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 454 | if (!mFeatureController.isFeatureEnabled(serviceName)) { |
| 455 | Log.w(CarLog.TAG_SERVICE, "getCarService for disabled service:" + serviceName); |
| 456 | return null; |
| 457 | } |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 458 | switch (serviceName) { |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 459 | case Car.AUDIO_SERVICE: |
| 460 | return mCarAudioService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 461 | case Car.APP_FOCUS_SERVICE: |
| 462 | return mAppFocusService; |
Keun-young Park | 45fdcba | 2015-12-08 11:38:58 -0800 | [diff] [blame] | 463 | case Car.PACKAGE_SERVICE: |
| 464 | return mCarPackageManagerService; |
Enrico Granata | 5c56d2a | 2017-02-07 15:38:12 -0800 | [diff] [blame] | 465 | case Car.DIAGNOSTIC_SERVICE: |
Enrico Granata | b3634e2 | 2017-05-05 18:02:31 -0700 | [diff] [blame] | 466 | assertAnyDiagnosticPermission(mContext); |
| 467 | return mCarDiagnosticService; |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 468 | case Car.POWER_SERVICE: |
| 469 | assertPowerPermission(mContext); |
| 470 | return mCarPowerManagementService; |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 471 | case Car.CABIN_SERVICE: |
| 472 | case Car.HVAC_SERVICE: |
| 473 | case Car.INFO_SERVICE: |
| 474 | case Car.PROPERTY_SERVICE: |
| 475 | case Car.SENSOR_SERVICE: |
| 476 | case Car.VENDOR_EXTENSION_SERVICE: |
| 477 | return mCarPropertyService; |
Pavel Maltsev | 7a948e5 | 2016-02-02 23:30:14 -0800 | [diff] [blame] | 478 | case Car.CAR_NAVIGATION_SERVICE: |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 479 | assertNavigationManagerPermission(mContext); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 480 | IInstrumentClusterNavigation navService = |
| 481 | mInstrumentClusterService.getNavigationService(); |
| 482 | return navService == null ? null : navService.asBinder(); |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 483 | case Car.CAR_INSTRUMENT_CLUSTER_SERVICE: |
| 484 | assertClusterManagerPermission(mContext); |
| 485 | return mInstrumentClusterService.getManagerService(); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 486 | case Car.PROJECTION_SERVICE: |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 487 | return mCarProjectionService; |
Mark Tabry | 6fa123d | 2020-01-10 19:52:59 -0800 | [diff] [blame] | 488 | case Car.VEHICLE_MAP_SERVICE: |
| 489 | assertAnyVmsPermission(mContext); |
| 490 | return mVmsBrokerService; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 491 | case Car.VMS_SUBSCRIBER_SERVICE: |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 492 | assertVmsSubscriberPermission(mContext); |
Mark Tabry | 62e749c | 2020-01-10 19:52:59 -0800 | [diff] [blame] | 493 | return mVmsBrokerService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 494 | case Car.TEST_SERVICE: { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 495 | assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 496 | synchronized (this) { |
| 497 | if (mCarTestService == null) { |
| 498 | mCarTestService = new CarTestService(mContext, this); |
| 499 | } |
| 500 | return mCarTestService; |
| 501 | } |
| 502 | } |
Ram Periathiruvadi | 76a8489 | 2017-07-27 18:10:35 -0700 | [diff] [blame] | 503 | case Car.BLUETOOTH_SERVICE: |
| 504 | return mCarBluetoothService; |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 505 | case Car.STORAGE_MONITORING_SERVICE: |
Enrico Granata | 1172f88 | 2017-09-21 14:51:30 -0700 | [diff] [blame] | 506 | assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING); |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 507 | return mCarStorageMonitoringService; |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 508 | case Car.CAR_DRIVING_STATE_SERVICE: |
| 509 | assertDrivingStatePermission(mContext); |
| 510 | return mCarDrivingStateService; |
| 511 | case Car.CAR_UX_RESTRICTION_SERVICE: |
| 512 | return mCarUXRestrictionsService; |
Michael Keller | ac2ed20 | 2020-01-30 14:11:16 -0800 | [diff] [blame] | 513 | case Car.OCCUPANT_AWARENESS_SERVICE: |
| 514 | return mOccupantAwarenessService; |
Anthony Chen | d4203d8 | 2018-05-16 16:21:52 -0700 | [diff] [blame] | 515 | case Car.CAR_CONFIGURATION_SERVICE: |
| 516 | return mCarConfigurationService; |
Ram Periathiruvadi | 194ce1b | 2019-01-14 09:42:12 -0800 | [diff] [blame] | 517 | case Car.CAR_TRUST_AGENT_ENROLLMENT_SERVICE: |
| 518 | assertTrustAgentEnrollmentPermission(mContext); |
Ram Periathiruvadi | de0ca08 | 2019-03-20 11:16:44 -0700 | [diff] [blame] | 519 | return mCarTrustedDeviceService.getCarTrustAgentEnrollmentService(); |
Simon Dai | 527eb55 | 2019-02-12 13:06:15 -0800 | [diff] [blame] | 520 | case Car.CAR_MEDIA_SERVICE: |
| 521 | return mCarMediaService; |
Keun young Park | bb877e2 | 2019-08-02 10:38:01 -0700 | [diff] [blame] | 522 | case Car.CAR_OCCUPANT_ZONE_SERVICE: |
| 523 | return mCarOccupantZoneService; |
Selim Gurun | c8c82f6 | 2019-04-17 14:07:30 -0700 | [diff] [blame] | 524 | case Car.CAR_BUGREPORT_SERVICE: |
| 525 | return mCarBugreportManagerService; |
Eric Jeong | 1545f3b | 2019-09-16 13:56:52 -0700 | [diff] [blame] | 526 | case Car.CAR_USER_SERVICE: |
| 527 | return mCarUserService; |
Eric Jeong | ae2c04c | 2020-02-21 09:18:31 -0800 | [diff] [blame] | 528 | case Car.CAR_WATCHDOG_SERVICE: |
| 529 | return mCarWatchdogService; |
Keun young Park | 401479c | 2020-02-19 14:15:51 -0800 | [diff] [blame] | 530 | case Car.CAR_INPUT_SERVICE: |
| 531 | return mCarInputService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 532 | default: |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 533 | IBinder service = null; |
| 534 | if (mCarExperimentalFeatureServiceController != null) { |
| 535 | service = mCarExperimentalFeatureServiceController.getCarService(serviceName); |
| 536 | } |
| 537 | if (service == null) { |
| 538 | Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" |
| 539 | + serviceName); |
| 540 | } |
| 541 | return service; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 545 | @Override |
| 546 | public int getCarConnectionType() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 547 | return Car.CONNECTION_TYPE_EMBEDDED; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 550 | public CarServiceBase getCarInternalService(String serviceName) { |
| 551 | switch (serviceName) { |
| 552 | case INTERNAL_INPUT_SERVICE: |
| 553 | return mCarInputService; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 554 | case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE: |
| 555 | return mSystemActivityMonitoringService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 556 | default: |
| 557 | Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" + |
| 558 | serviceName); |
| 559 | return null; |
| 560 | } |
| 561 | } |
| 562 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 563 | public static void assertVehicleHalMockPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 564 | assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 567 | public static void assertNavigationManagerPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 568 | assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER); |
Pavel Maltsev | ce4ffd9 | 2016-03-09 10:56:23 -0800 | [diff] [blame] | 569 | } |
| 570 | |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 571 | public static void assertClusterManagerPermission(Context context) { |
| 572 | assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL); |
| 573 | } |
| 574 | |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 575 | public static void assertPowerPermission(Context context) { |
| 576 | assertPermission(context, Car.PERMISSION_CAR_POWER); |
| 577 | } |
| 578 | |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 579 | public static void assertProjectionPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 580 | assertPermission(context, Car.PERMISSION_CAR_PROJECTION); |
| 581 | } |
| 582 | |
Pavel Maltsev | 079873b | 2019-02-25 12:15:09 -0800 | [diff] [blame] | 583 | /** Verify the calling context has the {@link Car#PERMISSION_CAR_PROJECTION_STATUS} */ |
| 584 | public static void assertProjectionStatusPermission(Context context) { |
| 585 | assertPermission(context, Car.PERMISSION_CAR_PROJECTION_STATUS); |
| 586 | } |
| 587 | |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 588 | public static void assertAnyDiagnosticPermission(Context context) { |
| 589 | assertAnyPermission(context, |
Enrico Granata | ae25b92 | 2017-07-07 11:28:15 -0700 | [diff] [blame] | 590 | Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL, |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 591 | Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR); |
| 592 | } |
| 593 | |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 594 | public static void assertDrivingStatePermission(Context context) { |
| 595 | assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE); |
| 596 | } |
| 597 | |
Mark Tabry | 6fa123d | 2020-01-10 19:52:59 -0800 | [diff] [blame] | 598 | /** |
| 599 | * Verify the calling context has either {@link Car#PERMISSION_VMS_SUBSCRIBER} or |
| 600 | * {@link Car#PERMISSION_VMS_PUBLISHER} |
| 601 | */ |
| 602 | public static void assertAnyVmsPermission(Context context) { |
| 603 | assertAnyPermission(context, |
| 604 | Car.PERMISSION_VMS_SUBSCRIBER, |
| 605 | Car.PERMISSION_VMS_PUBLISHER); |
| 606 | } |
| 607 | |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 608 | public static void assertVmsPublisherPermission(Context context) { |
| 609 | assertPermission(context, Car.PERMISSION_VMS_PUBLISHER); |
| 610 | } |
| 611 | |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 612 | public static void assertVmsSubscriberPermission(Context context) { |
| 613 | assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER); |
| 614 | } |
| 615 | |
Ram Periathiruvadi | 194ce1b | 2019-01-14 09:42:12 -0800 | [diff] [blame] | 616 | /** |
| 617 | * Ensures the caller has the permission to enroll a Trust Agent. |
Ram Periathiruvadi | 194ce1b | 2019-01-14 09:42:12 -0800 | [diff] [blame] | 618 | */ |
| 619 | public static void assertTrustAgentEnrollmentPermission(Context context) { |
| 620 | assertPermission(context, Car.PERMISSION_CAR_ENROLL_TRUST); |
| 621 | } |
| 622 | |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 623 | public static void assertPermission(Context context, String permission) { |
| 624 | if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { |
| 625 | throw new SecurityException("requires " + permission); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 629 | /** |
| 630 | * Checks to see if the caller has a permission. |
Steve Paik | 9ec53d7 | 2018-04-27 13:28:31 -0700 | [diff] [blame] | 631 | * |
| 632 | * @return boolean TRUE if caller has the permission. |
| 633 | */ |
| 634 | public static boolean hasPermission(Context context, String permission) { |
| 635 | return context.checkCallingOrSelfPermission(permission) |
| 636 | == PackageManager.PERMISSION_GRANTED; |
| 637 | } |
| 638 | |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 639 | public static void assertAnyPermission(Context context, String... permissions) { |
| 640 | for (String permission : permissions) { |
Antonio Kantek | 991ba0b | 2020-03-12 14:28:21 -0700 | [diff] [blame] | 641 | if (context.checkCallingOrSelfPermission(permission) |
| 642 | == PackageManager.PERMISSION_GRANTED) { |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 643 | return; |
| 644 | } |
| 645 | } |
| 646 | throw new SecurityException("requires any of " + Arrays.toString(permissions)); |
| 647 | } |
| 648 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 649 | @Override |
| 650 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| 651 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 652 | != PackageManager.PERMISSION_GRANTED) { |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 653 | writer.println("Permission Denial: can't dump CarService from from pid=" |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 654 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() |
| 655 | + " without permission " + android.Manifest.permission.DUMP); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 656 | return; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 657 | } |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 658 | |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 659 | if (args == null || args.length == 0 || (args.length > 0 && "-a".equals(args[0]))) { |
| 660 | writer.println("*Dump car service*"); |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 661 | dumpAllServices(writer); |
Felipe Leme | f07c3f9 | 2020-02-12 14:26:33 -0800 | [diff] [blame] | 662 | dumpAllHals(writer); |
Felipe Leme | e93218b | 2020-02-13 14:10:52 -0800 | [diff] [blame] | 663 | mUserMetrics.dump(writer); |
felipeal | 080e565 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 664 | } else if ("--list".equals(args[0])) { |
| 665 | dumpListOfServices(writer); |
| 666 | return; |
| 667 | } else if ("--services".equals(args[0])) { |
| 668 | if (args.length < 2) { |
Felipe Leme | 177464b | 2020-03-11 17:32:21 -0700 | [diff] [blame] | 669 | writer.println("Must pass services to dump when using --services"); |
felipeal | 080e565 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 670 | return; |
| 671 | } |
| 672 | int length = args.length - 1; |
| 673 | String[] services = new String[length]; |
| 674 | System.arraycopy(args, 1, services, 0, length); |
| 675 | dumpIndividualServices(writer, services); |
| 676 | return; |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 677 | } else if ("--metrics".equals(args[0])) { |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 678 | // Strip the --metrics flag when passing dumpsys arguments to CarStatsService |
Mark Tabry | c98f995 | 2019-12-03 11:03:48 -0800 | [diff] [blame] | 679 | // allowing for nested flag selection |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 680 | mCarStatsService.dump(fd, writer, Arrays.copyOfRange(args, 1, args.length)); |
Mark Tabry | b588d2e | 2019-09-12 10:50:11 -0700 | [diff] [blame] | 681 | } else if ("--vms-hal".equals(args[0])) { |
| 682 | mHal.getVmsHal().dumpMetrics(fd); |
Felipe Leme | f07c3f9 | 2020-02-12 14:26:33 -0800 | [diff] [blame] | 683 | } else if ("--hal".equals(args[0])) { |
| 684 | if (args.length == 1) { |
| 685 | dumpAllHals(writer); |
| 686 | return; |
| 687 | } |
| 688 | int length = args.length - 1; |
| 689 | String[] halNames = new String[length]; |
| 690 | System.arraycopy(args, 1, halNames, 0, length); |
| 691 | mHal.dumpSpecificHals(writer, halNames); |
| 692 | |
| 693 | } else if ("--list-hals".equals(args[0])) { |
| 694 | mHal.dumpListHals(writer); |
| 695 | return; |
Felipe Leme | e93218b | 2020-02-13 14:10:52 -0800 | [diff] [blame] | 696 | } else if ("--user-metrics".equals(args[0])) { |
| 697 | mUserMetrics.dump(writer); |
Felipe Leme | 30b4e1e | 2020-02-25 10:26:07 -0800 | [diff] [blame] | 698 | } else if ("--first-user-metrics".equals(args[0])) { |
| 699 | mUserMetrics.dumpFirstUserUnlockDuration(writer); |
Felipe Leme | f07c3f9 | 2020-02-12 14:26:33 -0800 | [diff] [blame] | 700 | } else if ("--help".equals(args[0])) { |
| 701 | showDumpHelp(writer); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 702 | } else if (Build.IS_USERDEBUG || Build.IS_ENG) { |
| 703 | execShellCmd(args, writer); |
| 704 | } else { |
| 705 | writer.println("Commands not supported in " + Build.TYPE); |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
Felipe Leme | f07c3f9 | 2020-02-12 14:26:33 -0800 | [diff] [blame] | 709 | private void dumpAllHals(PrintWriter writer) { |
| 710 | writer.println("*Dump Vehicle HAL*"); |
| 711 | writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName); |
| 712 | try { |
| 713 | // TODO dump all feature flags by creating a dumpable interface |
| 714 | mHal.dump(writer); |
| 715 | } catch (Exception e) { |
| 716 | writer.println("Failed dumping: " + mHal.getClass().getName()); |
| 717 | e.printStackTrace(writer); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | private void showDumpHelp(PrintWriter writer) { |
| 722 | writer.println("Car service dump usage:"); |
| 723 | writer.println("[NO ARG]"); |
| 724 | writer.println("\t dumps everything (all services and HALs)"); |
| 725 | writer.println("--help"); |
| 726 | writer.println("\t shows this help"); |
| 727 | writer.println("--list"); |
| 728 | writer.println("\t lists the name of all services"); |
Oscar Azucena | a350a2e | 2020-02-21 20:08:02 -0800 | [diff] [blame] | 729 | writer.println("--list-hals"); |
| 730 | writer.println("\t lists the name of all HALs"); |
Felipe Leme | f07c3f9 | 2020-02-12 14:26:33 -0800 | [diff] [blame] | 731 | writer.println("--services <SVC1> [SVC2] [SVCN]"); |
| 732 | writer.println("\t dumps just the specific services, where SVC is just the service class"); |
| 733 | writer.println("\t name (like CarUserService)"); |
| 734 | writer.println("--vms-hal"); |
| 735 | writer.println("\t dumps the VMS HAL metrics"); |
| 736 | writer.println("--hal [HAL1] [HAL2] [HALN]"); |
| 737 | writer.println("\t dumps just the specified HALs (or all of them if none specified),"); |
| 738 | writer.println("\t where HAL is just the class name (like UserHalService)"); |
Felipe Leme | e93218b | 2020-02-13 14:10:52 -0800 | [diff] [blame] | 739 | writer.println("--user-metrics"); |
| 740 | writer.println("\t dumps user switching and stopping metrics "); |
Felipe Leme | 30b4e1e | 2020-02-25 10:26:07 -0800 | [diff] [blame] | 741 | writer.println("--first-user-metrics"); |
| 742 | writer.println("\t dumps how long it took to unlock first user since Android started\n"); |
| 743 | writer.println("\t (or -1 if not unlocked)"); |
Felipe Leme | f07c3f9 | 2020-02-12 14:26:33 -0800 | [diff] [blame] | 744 | writer.println("-h"); |
| 745 | writer.println("\t shows commands usage (NOTE: commands are not available on USER builds"); |
| 746 | writer.println("[ANYTHING ELSE]"); |
| 747 | writer.println("\t runs the given command (use --h to see the available commands)"); |
| 748 | } |
| 749 | |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 750 | @Override |
| 751 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 752 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 753 | throws RemoteException { |
| 754 | new CarShellCommand().exec(this, in, out, err, args, callback, resultReceiver); |
| 755 | } |
| 756 | |
felipeal | 080e565 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 757 | private void dumpListOfServices(PrintWriter writer) { |
| 758 | for (CarServiceBase service : mAllServices) { |
| 759 | writer.println(service.getClass().getName()); |
| 760 | } |
| 761 | } |
| 762 | |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 763 | private void dumpAllServices(PrintWriter writer) { |
Felipe Leme | f07c3f9 | 2020-02-12 14:26:33 -0800 | [diff] [blame] | 764 | writer.println("*Dump all services*"); |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 765 | for (CarServiceBase service : mAllServices) { |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 766 | dumpService(service, writer); |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 767 | } |
| 768 | if (mCarTestService != null) { |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 769 | dumpService(mCarTestService, writer); |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 770 | } |
felipeal | 080e565 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 771 | } |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 772 | |
felipeal | 080e565 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 773 | private void dumpIndividualServices(PrintWriter writer, String... serviceNames) { |
| 774 | for (String serviceName : serviceNames) { |
| 775 | writer.println("** Dumping " + serviceName + "\n"); |
| 776 | CarServiceBase service = getCarServiceBySubstring(serviceName); |
| 777 | if (service == null) { |
| 778 | writer.println("No such service!"); |
| 779 | } else { |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 780 | dumpService(service, writer); |
felipeal | 080e565 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 781 | } |
| 782 | writer.println(); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | @Nullable |
| 787 | private CarServiceBase getCarServiceBySubstring(String className) { |
| 788 | return Arrays.asList(mAllServices).stream() |
| 789 | .filter(s -> s.getClass().getSimpleName().equals(className)) |
| 790 | .findFirst().orElse(null); |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 793 | private void dumpService(CarServiceBase service, PrintWriter writer) { |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 794 | try { |
Mark Tabry | 7e2a782 | 2019-10-17 10:18:32 -0700 | [diff] [blame] | 795 | service.dump(writer); |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 796 | } catch (Exception e) { |
| 797 | writer.println("Failed dumping: " + service.getClass().getName()); |
| 798 | e.printStackTrace(writer); |
| 799 | } |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 800 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 801 | |
| 802 | void execShellCmd(String[] args, PrintWriter writer) { |
| 803 | new CarShellCommand().exec(args, writer); |
| 804 | } |
| 805 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 806 | @MainThread |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 807 | private void traceBegin(String name) { |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 808 | Slog.i(TAG, name); |
| 809 | mBootTiming.traceBegin(name); |
| 810 | } |
| 811 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 812 | @MainThread |
Serik Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 813 | private void traceEnd() { |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 814 | mBootTiming.traceEnd(); |
| 815 | } |
| 816 | |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 817 | private final class CarShellCommand extends ShellCommand { |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 818 | private static final String COMMAND_HELP = "-h"; |
| 819 | private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 820 | private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event"; |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 821 | private static final String COMMAND_INJECT_ERROR_EVENT = "inject-error-event"; |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 822 | private static final String COMMAND_ENABLE_UXR = "enable-uxr"; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 823 | private static final String COMMAND_GARAGE_MODE = "garage-mode"; |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 824 | private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities"; |
Kai | dd4ef5a | 2019-03-04 14:07:26 -0800 | [diff] [blame] | 825 | private static final String COMMAND_GET_CARPROPERTYCONFIG = "get-carpropertyconfig"; |
Kai | 29fba11 | 2019-04-22 18:37:38 -0700 | [diff] [blame] | 826 | private static final String COMMAND_GET_PROPERTY_VALUE = "get-property-value"; |
Pavel Maltsev | 371d97f | 2019-05-20 14:51:31 -0700 | [diff] [blame] | 827 | private static final String COMMAND_PROJECTION_AP_TETHERING = "projection-tethering"; |
Pavel Maltsev | 48a3194 | 2019-03-03 22:08:28 -0800 | [diff] [blame] | 828 | private static final String COMMAND_PROJECTION_UI_MODE = "projection-ui-mode"; |
Jim Kaye | d76c274 | 2019-04-02 11:33:27 -0700 | [diff] [blame] | 829 | private static final String COMMAND_RESUME = "resume"; |
| 830 | private static final String COMMAND_SUSPEND = "suspend"; |
Ram Periathiruvadi | d26a3fb | 2019-04-15 14:48:23 -0700 | [diff] [blame] | 831 | private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device"; |
| 832 | private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices"; |
Oscar Azucena | 3f3a25e | 2019-07-12 14:28:24 -0700 | [diff] [blame] | 833 | private static final String COMMAND_SET_UID_TO_ZONE = "set-zoneid-for-uid"; |
Keun young Park | 09ca849 | 2019-10-15 10:34:11 -0700 | [diff] [blame] | 834 | private static final String COMMAND_START_FIXED_ACTIVITY_MODE = "start-fixed-activity-mode"; |
| 835 | private static final String COMMAND_STOP_FIXED_ACTIVITY_MODE = "stop-fixed-activity-mode"; |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 836 | private static final String COMMAND_ENABLE_FEATURE = "enable-feature"; |
| 837 | private static final String COMMAND_DISABLE_FEATURE = "disable-feature"; |
Keun young Park | 313dfaf | 2019-12-19 11:32:38 -0800 | [diff] [blame] | 838 | private static final String COMMAND_INJECT_KEY = "inject-key"; |
Felipe Leme | a5e6938 | 2020-02-11 17:53:20 -0800 | [diff] [blame] | 839 | private static final String COMMAND_GET_INITIAL_USER_INFO = "get-initial-user-info"; |
Felipe Leme | 5bf135b | 2020-02-07 12:22:14 -0800 | [diff] [blame] | 840 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 841 | private static final String PARAM_DAY_MODE = "day"; |
| 842 | private static final String PARAM_NIGHT_MODE = "night"; |
| 843 | private static final String PARAM_SENSOR_MODE = "sensor"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 844 | private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0"; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 845 | private static final String PARAM_ON_MODE = "on"; |
| 846 | private static final String PARAM_OFF_MODE = "off"; |
| 847 | private static final String PARAM_QUERY_MODE = "query"; |
Jim Kaye | 9a834ea | 2020-02-07 15:50:53 -0800 | [diff] [blame] | 848 | private static final String PARAM_REBOOT = "reboot"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 849 | |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 850 | private static final int RESULT_OK = 0; |
| 851 | private static final int RESULT_ERROR = -1; // Arbitrary value, any non-0 is fine |
| 852 | |
| 853 | |
| 854 | @Override |
| 855 | public int onCommand(String cmd) { |
| 856 | if (cmd == null) { |
| 857 | onHelp(); |
| 858 | return RESULT_ERROR; |
| 859 | } |
| 860 | ArrayList<String> argsList = new ArrayList<>(); |
| 861 | argsList.add(cmd); |
| 862 | String arg = null; |
| 863 | do { |
| 864 | arg = getNextArg(); |
| 865 | if (arg != null) { |
| 866 | argsList.add(arg); |
| 867 | } |
| 868 | } while (arg != null); |
| 869 | String[] args = new String[argsList.size()]; |
| 870 | argsList.toArray(args); |
| 871 | return exec(args, getOutPrintWriter()); |
| 872 | } |
| 873 | |
| 874 | @Override |
| 875 | public void onHelp() { |
| 876 | dumpHelp(getOutPrintWriter()); |
| 877 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 878 | |
| 879 | private void dumpHelp(PrintWriter pw) { |
| 880 | pw.println("Car service commands:"); |
| 881 | pw.println("\t-h"); |
| 882 | pw.println("\t Print this help text."); |
| 883 | pw.println("\tday-night-mode [day|night|sensor]"); |
| 884 | pw.println("\t Force into day/night mode or restore to auto."); |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 885 | 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] | 886 | pw.println("\t Inject a vehicle property for testing."); |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 887 | pw.println("\tinject-error-event property zone errorCode"); |
| 888 | pw.println("\t Inject an error event from VHAL for testing."); |
Ram Periathiruvadi | d26a3fb | 2019-04-15 14:48:23 -0700 | [diff] [blame] | 889 | pw.println("\tenable-uxr true|false"); |
| 890 | pw.println("\t Enable/Disable UX restrictions and App blocking."); |
Jim Kaye | 9a834ea | 2020-02-07 15:50:53 -0800 | [diff] [blame] | 891 | pw.println("\tgarage-mode [on|off|query|reboot]"); |
| 892 | pw.println("\t Force into or out of garage mode, or check status."); |
| 893 | pw.println("\t With 'reboot', enter garage mode, then reboot when it completes."); |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 894 | pw.println("\tget-do-activities pkgname"); |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 895 | pw.println("\t Get Distraction Optimized activities in given package."); |
Kai | dd4ef5a | 2019-03-04 14:07:26 -0800 | [diff] [blame] | 896 | pw.println("\tget-carpropertyconfig [propertyId]"); |
| 897 | 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] | 898 | pw.println("\tget-property-value [propertyId] [areaId]"); |
| 899 | pw.println("\t Get a vehicle property value by property id in Hex and areaId"); |
| 900 | pw.println("\t or list all property values for all areaId"); |
Jim Kaye | d76c274 | 2019-04-02 11:33:27 -0700 | [diff] [blame] | 901 | pw.println("\tsuspend"); |
| 902 | pw.println("\t Suspend the system to Deep Sleep."); |
| 903 | pw.println("\tresume"); |
| 904 | pw.println("\t Wake the system up after a 'suspend.'"); |
Ram Periathiruvadi | d26a3fb | 2019-04-15 14:48:23 -0700 | [diff] [blame] | 905 | pw.println("\tenable-trusted-device true|false"); |
| 906 | pw.println("\t Enable/Disable Trusted device feature."); |
| 907 | pw.println("\tremove-trusted-devices"); |
| 908 | pw.println("\t Remove all trusted devices for the current foreground user."); |
Pavel Maltsev | 371d97f | 2019-05-20 14:51:31 -0700 | [diff] [blame] | 909 | pw.println("\tprojection-tethering [true|false]"); |
| 910 | pw.println("\t Whether tethering should be used when creating access point for" |
| 911 | + " wireless projection"); |
Andrew T Nguyen | a9228c7 | 2019-06-12 11:28:42 -0700 | [diff] [blame] | 912 | pw.println("\t--metrics"); |
| 913 | 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] | 914 | pw.println("\tset-zoneid-for-uid [zoneid] [uid]"); |
Jim Kaye | 9a834ea | 2020-02-07 15:50:53 -0800 | [diff] [blame] | 915 | pw.println("\t Maps the audio zoneid to uid."); |
Keun young Park | 09ca849 | 2019-10-15 10:34:11 -0700 | [diff] [blame] | 916 | pw.println("\tstart-fixed-activity displayId packageName activityName"); |
| 917 | pw.println("\t Start an Activity the specified display as fixed mode"); |
| 918 | pw.println("\tstop-fixed-mode displayId"); |
| 919 | pw.println("\t Stop fixed Activity mode for the given display. " |
| 920 | + "The Activity will not be restarted upon crash."); |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 921 | pw.println("\tenable-feature featureName"); |
| 922 | pw.println("\t Enable the requested feature. Change will happen after reboot."); |
| 923 | pw.println("\t This requires root/su."); |
| 924 | pw.println("\tdisable-feature featureName"); |
| 925 | pw.println("\t Disable the requested feature. Change will happen after reboot"); |
| 926 | pw.println("\t This requires root/su."); |
Keun young Park | 313dfaf | 2019-12-19 11:32:38 -0800 | [diff] [blame] | 927 | pw.println("\tinject-key [-d display] [-t down_delay_ms] key_code"); |
| 928 | pw.println("\t inject key down / up event to car service"); |
| 929 | pw.println("\t display: 0 for main, 1 for cluster. If not specified, it will be 0."); |
| 930 | pw.println("\t down_delay_ms: delay from down to up key event. If not specified,"); |
| 931 | pw.println("\t it will be 0"); |
| 932 | pw.println("\t key_code: int key code defined in android KeyEvent"); |
Felipe Leme | a5e6938 | 2020-02-11 17:53:20 -0800 | [diff] [blame] | 933 | pw.printf("\t%s <REQ_TYPE> [--timeout TIMEOUT_MS]\n", COMMAND_GET_INITIAL_USER_INFO); |
| 934 | pw.println("\t Calls the Vehicle HAL to get the initial boot info, passing the given"); |
| 935 | pw.println("\t REQ_TYPE (which could be either FIRST_BOOT, FIRST_BOOT_AFTER_OTA, "); |
| 936 | pw.println("\t COLD_BOOT, RESUME, or any numeric value that would be passed 'as-is')"); |
| 937 | pw.println("\t and an optional TIMEOUT_MS to wait for the HAL response (if not set,"); |
| 938 | pw.println("\t it will use a default value)."); |
Oscar Azucena | 3f3a25e | 2019-07-12 14:28:24 -0700 | [diff] [blame] | 939 | } |
| 940 | |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 941 | private int dumpInvalidArguments(PrintWriter pw) { |
| 942 | pw.println("Incorrect number of arguments."); |
| 943 | dumpHelp(pw); |
| 944 | return RESULT_ERROR; |
| 945 | } |
| 946 | |
Oscar Azucena | 3f3a25e | 2019-07-12 14:28:24 -0700 | [diff] [blame] | 947 | private String runSetZoneIdForUid(String zoneString, String uidString) { |
| 948 | int uid = Integer.parseInt(uidString); |
| 949 | int zoneId = Integer.parseInt(zoneString); |
| 950 | if (!ArrayUtils.contains(mCarAudioService.getAudioZoneIds(), zoneId)) { |
| 951 | return "zoneid " + zoneId + " not found"; |
| 952 | } |
| 953 | mCarAudioService.setZoneIdForUid(zoneId, uid); |
| 954 | return null; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 955 | } |
| 956 | |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 957 | public int exec(String[] args, PrintWriter writer) { |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 958 | String arg = args[0]; |
| 959 | switch (arg) { |
| 960 | case COMMAND_HELP: |
| 961 | dumpHelp(writer); |
| 962 | break; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 963 | case COMMAND_DAY_NIGHT_MODE: { |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 964 | String value = args.length < 2 ? "" : args[1]; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 965 | forceDayNightMode(value, writer); |
| 966 | break; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 967 | } |
| 968 | case COMMAND_GARAGE_MODE: { |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 969 | String value = args.length < 2 ? "" : args[1]; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 970 | forceGarageMode(value, writer); |
| 971 | break; |
| 972 | } |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 973 | case COMMAND_INJECT_VHAL_EVENT: |
| 974 | String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL; |
| 975 | String data; |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 976 | if (args.length != 3 && args.length != 4) { |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 977 | return dumpInvalidArguments(writer); |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 978 | } else if (args.length == 4) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 979 | // Zoned |
| 980 | zone = args[2]; |
| 981 | data = args[3]; |
| 982 | } else { |
| 983 | // Global |
| 984 | data = args[2]; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 985 | } |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 986 | injectVhalEvent(args[1], zone, data, false, writer); |
| 987 | break; |
| 988 | case COMMAND_INJECT_ERROR_EVENT: |
| 989 | if (args.length != 4) { |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 990 | return dumpInvalidArguments(writer); |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 991 | } |
| 992 | String errorAreaId = args[2]; |
| 993 | String errorCode = args[3]; |
| 994 | injectVhalEvent(args[1], errorAreaId, errorCode, true, writer); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 995 | break; |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 996 | case COMMAND_ENABLE_UXR: |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 997 | if (args.length != 2) { |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 998 | return dumpInvalidArguments(writer); |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 999 | } |
| 1000 | boolean enableBlocking = Boolean.valueOf(args[1]); |
| 1001 | if (mCarPackageManagerService != null) { |
| 1002 | mCarPackageManagerService.setEnableActivityBlocking(enableBlocking); |
| 1003 | } |
| 1004 | break; |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 1005 | case COMMAND_GET_DO_ACTIVITIES: |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 1006 | if (args.length != 2) { |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 1007 | return dumpInvalidArguments(writer); |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 1008 | } |
| 1009 | String pkgName = args[1].toLowerCase(); |
| 1010 | if (mCarPackageManagerService != null) { |
| 1011 | String[] doActivities = |
| 1012 | mCarPackageManagerService.getDistractionOptimizedActivities( |
| 1013 | pkgName); |
| 1014 | if (doActivities != null) { |
| 1015 | writer.println("DO Activities for " + pkgName); |
| 1016 | for (String a : doActivities) { |
| 1017 | writer.println(a); |
| 1018 | } |
| 1019 | } else { |
| 1020 | writer.println("No DO Activities for " + pkgName); |
| 1021 | } |
| 1022 | } |
| 1023 | break; |
Kai | dd4ef5a | 2019-03-04 14:07:26 -0800 | [diff] [blame] | 1024 | case COMMAND_GET_CARPROPERTYCONFIG: |
| 1025 | String propertyId = args.length < 2 ? "" : args[1]; |
| 1026 | mHal.dumpPropertyConfigs(writer, propertyId); |
| 1027 | break; |
Kai | 29fba11 | 2019-04-22 18:37:38 -0700 | [diff] [blame] | 1028 | case COMMAND_GET_PROPERTY_VALUE: |
| 1029 | String propId = args.length < 2 ? "" : args[1]; |
| 1030 | String areaId = args.length < 3 ? "" : args[2]; |
| 1031 | mHal.dumpPropertyValueByCommend(writer, propId, areaId); |
| 1032 | break; |
Pavel Maltsev | 48a3194 | 2019-03-03 22:08:28 -0800 | [diff] [blame] | 1033 | case COMMAND_PROJECTION_UI_MODE: |
| 1034 | if (args.length != 2) { |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 1035 | return dumpInvalidArguments(writer); |
Pavel Maltsev | 48a3194 | 2019-03-03 22:08:28 -0800 | [diff] [blame] | 1036 | } |
| 1037 | mCarProjectionService.setUiMode(Integer.valueOf(args[1])); |
Pavel Maltsev | d6961f6 | 2019-03-26 10:22:31 -0700 | [diff] [blame] | 1038 | break; |
Pavel Maltsev | 371d97f | 2019-05-20 14:51:31 -0700 | [diff] [blame] | 1039 | case COMMAND_PROJECTION_AP_TETHERING: |
| 1040 | if (args.length != 2) { |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 1041 | return dumpInvalidArguments(writer); |
Pavel Maltsev | 371d97f | 2019-05-20 14:51:31 -0700 | [diff] [blame] | 1042 | } |
| 1043 | mCarProjectionService.setAccessPointTethering(Boolean.valueOf(args[1])); |
| 1044 | break; |
Jim Kaye | d76c274 | 2019-04-02 11:33:27 -0700 | [diff] [blame] | 1045 | case COMMAND_RESUME: |
| 1046 | mCarPowerManagementService.forceSimulatedResume(); |
| 1047 | writer.println("Resume: Simulating resuming from Deep Sleep"); |
| 1048 | break; |
| 1049 | case COMMAND_SUSPEND: |
Jim Kaye | 9a834ea | 2020-02-07 15:50:53 -0800 | [diff] [blame] | 1050 | mCarPowerManagementService.forceSuspendAndMaybeReboot(false); |
Jim Kaye | d76c274 | 2019-04-02 11:33:27 -0700 | [diff] [blame] | 1051 | writer.println("Resume: Simulating powering down to Deep Sleep"); |
| 1052 | break; |
Ram Periathiruvadi | d26a3fb | 2019-04-15 14:48:23 -0700 | [diff] [blame] | 1053 | case COMMAND_ENABLE_TRUSTED_DEVICE: |
| 1054 | if (args.length != 2) { |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 1055 | return dumpInvalidArguments(writer); |
Ram Periathiruvadi | d26a3fb | 2019-04-15 14:48:23 -0700 | [diff] [blame] | 1056 | } |
| 1057 | mCarTrustedDeviceService.getCarTrustAgentEnrollmentService() |
| 1058 | .setTrustedDeviceEnrollmentEnabled(Boolean.valueOf(args[1])); |
| 1059 | mCarTrustedDeviceService.getCarTrustAgentUnlockService() |
| 1060 | .setTrustedDeviceUnlockEnabled(Boolean.valueOf(args[1])); |
| 1061 | break; |
| 1062 | case COMMAND_REMOVE_TRUSTED_DEVICES: |
| 1063 | mCarTrustedDeviceService.getCarTrustAgentEnrollmentService() |
Anthony Hugh | fbb6776 | 2019-10-15 12:54:54 -0700 | [diff] [blame] | 1064 | .removeAllTrustedDevices(ActivityManager.getCurrentUser()); |
Ram Periathiruvadi | d26a3fb | 2019-04-15 14:48:23 -0700 | [diff] [blame] | 1065 | break; |
Oscar Azucena | 3f3a25e | 2019-07-12 14:28:24 -0700 | [diff] [blame] | 1066 | case COMMAND_SET_UID_TO_ZONE: |
| 1067 | if (args.length != 3) { |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 1068 | return dumpInvalidArguments(writer); |
Oscar Azucena | 3f3a25e | 2019-07-12 14:28:24 -0700 | [diff] [blame] | 1069 | } |
| 1070 | String results = runSetZoneIdForUid(args[1], args[2]); |
| 1071 | if (results != null) { |
| 1072 | writer.println(results); |
| 1073 | dumpHelp(writer); |
| 1074 | } |
| 1075 | break; |
Keun young Park | 09ca849 | 2019-10-15 10:34:11 -0700 | [diff] [blame] | 1076 | case COMMAND_START_FIXED_ACTIVITY_MODE: |
| 1077 | handleStartFixedActivity(args, writer); |
| 1078 | break; |
| 1079 | case COMMAND_STOP_FIXED_ACTIVITY_MODE: |
| 1080 | handleStopFixedMode(args, writer); |
| 1081 | break; |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 1082 | case COMMAND_ENABLE_FEATURE: |
| 1083 | if (args.length != 2) { |
| 1084 | return dumpInvalidArguments(writer); |
| 1085 | } |
| 1086 | handleEnableDisableFeature(args, writer, /* enable= */ true); |
| 1087 | break; |
| 1088 | case COMMAND_DISABLE_FEATURE: |
| 1089 | if (args.length != 2) { |
| 1090 | return dumpInvalidArguments(writer); |
| 1091 | } |
| 1092 | handleEnableDisableFeature(args, writer, /* enable= */ false); |
| 1093 | break; |
Keun young Park | 313dfaf | 2019-12-19 11:32:38 -0800 | [diff] [blame] | 1094 | case COMMAND_INJECT_KEY: |
| 1095 | if (args.length < 2) { |
| 1096 | return dumpInvalidArguments(writer); |
| 1097 | } |
| 1098 | handleInjectKey(args, writer); |
| 1099 | break; |
Felipe Leme | a5e6938 | 2020-02-11 17:53:20 -0800 | [diff] [blame] | 1100 | case COMMAND_GET_INITIAL_USER_INFO: |
| 1101 | handleGetInitialUserInfo(args, writer); |
| 1102 | break; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 1103 | default: |
Jim Kaye | f10b7d8 | 2019-02-26 12:53:22 -0800 | [diff] [blame] | 1104 | writer.println("Unknown command: \"" + arg + "\""); |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 1105 | dumpHelp(writer); |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 1106 | return RESULT_ERROR; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 1107 | } |
felipeal | 72bf642 | 2019-11-02 17:04:04 -0700 | [diff] [blame] | 1108 | return RESULT_OK; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Keun young Park | 09ca849 | 2019-10-15 10:34:11 -0700 | [diff] [blame] | 1111 | private void handleStartFixedActivity(String[] args, PrintWriter writer) { |
| 1112 | if (args.length != 4) { |
| 1113 | writer.println("Incorrect number of arguments"); |
| 1114 | dumpHelp(writer); |
| 1115 | return; |
| 1116 | } |
| 1117 | int displayId; |
| 1118 | try { |
| 1119 | displayId = Integer.parseInt(args[1]); |
| 1120 | } catch (NumberFormatException e) { |
| 1121 | writer.println("Wrong display id:" + args[1]); |
| 1122 | return; |
| 1123 | } |
| 1124 | String packageName = args[2]; |
| 1125 | String activityName = args[3]; |
| 1126 | Intent intent = new Intent(); |
| 1127 | intent.setComponent(new ComponentName(packageName, activityName)); |
| 1128 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 1129 | ActivityOptions options = ActivityOptions.makeBasic(); |
| 1130 | options.setLaunchDisplayId(displayId); |
| 1131 | if (!mFixedActivityService.startFixedActivityModeForDisplayAndUser(intent, options, |
| 1132 | displayId, ActivityManager.getCurrentUser())) { |
| 1133 | writer.println("Failed to start"); |
| 1134 | return; |
| 1135 | } |
| 1136 | writer.println("Succeeded"); |
| 1137 | } |
| 1138 | |
| 1139 | private void handleStopFixedMode(String[] args, PrintWriter writer) { |
| 1140 | if (args.length != 2) { |
| 1141 | writer.println("Incorrect number of arguments"); |
| 1142 | dumpHelp(writer); |
| 1143 | return; |
| 1144 | } |
| 1145 | int displayId; |
| 1146 | try { |
| 1147 | displayId = Integer.parseInt(args[1]); |
| 1148 | } catch (NumberFormatException e) { |
| 1149 | writer.println("Wrong display id:" + args[1]); |
| 1150 | return; |
| 1151 | } |
| 1152 | mFixedActivityService.stopFixedActivityMode(displayId); |
| 1153 | } |
| 1154 | |
Keun young Park | 9a91efb | 2019-11-15 18:10:47 -0800 | [diff] [blame] | 1155 | private void handleEnableDisableFeature(String[] args, PrintWriter writer, boolean enable) { |
| 1156 | if (Binder.getCallingUid() != Process.ROOT_UID) { |
| 1157 | writer.println("Only allowed to root/su"); |
| 1158 | return; |
| 1159 | } |
| 1160 | String featureName = args[1]; |
| 1161 | long id = Binder.clearCallingIdentity(); |
| 1162 | // no permission check here |
| 1163 | int r; |
| 1164 | if (enable) { |
| 1165 | r = mFeatureController.enableFeature(featureName); |
| 1166 | } else { |
| 1167 | r = mFeatureController.disableFeature(featureName); |
| 1168 | } |
| 1169 | switch (r) { |
| 1170 | case Car.FEATURE_REQUEST_SUCCESS: |
| 1171 | if (enable) { |
| 1172 | writer.println("Enabled feature:" + featureName); |
| 1173 | } else { |
| 1174 | writer.println("Disabled feature:" + featureName); |
| 1175 | } |
| 1176 | break; |
| 1177 | case Car.FEATURE_REQUEST_ALREADY_IN_THE_STATE: |
| 1178 | if (enable) { |
| 1179 | writer.println("Already enabled:" + featureName); |
| 1180 | } else { |
| 1181 | writer.println("Already disabled:" + featureName); |
| 1182 | } |
| 1183 | break; |
| 1184 | case Car.FEATURE_REQUEST_MANDATORY: |
| 1185 | writer.println("Cannot change mandatory feature:" + featureName); |
| 1186 | break; |
| 1187 | case Car.FEATURE_REQUEST_NOT_EXISTING: |
| 1188 | writer.println("Non-existing feature:" + featureName); |
| 1189 | break; |
| 1190 | default: |
| 1191 | writer.println("Unknown error:" + r); |
| 1192 | break; |
| 1193 | } |
| 1194 | Binder.restoreCallingIdentity(id); |
| 1195 | } |
| 1196 | |
Keun young Park | 313dfaf | 2019-12-19 11:32:38 -0800 | [diff] [blame] | 1197 | private void handleInjectKey(String[] args, PrintWriter writer) { |
| 1198 | int i = 1; // 0 is command itself |
| 1199 | int display = InputHalService.DISPLAY_MAIN; |
| 1200 | int delayMs = 0; |
| 1201 | int keyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 1202 | try { |
| 1203 | while (i < args.length) { |
| 1204 | switch (args[i]) { |
| 1205 | case "-d": |
| 1206 | i++; |
| 1207 | display = Integer.parseInt(args[i]); |
| 1208 | break; |
| 1209 | case "-t": |
| 1210 | i++; |
| 1211 | delayMs = Integer.parseInt(args[i]); |
| 1212 | break; |
| 1213 | default: |
| 1214 | if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 1215 | throw new IllegalArgumentException("key_code already set:" |
| 1216 | + keyCode); |
| 1217 | } |
| 1218 | keyCode = Integer.parseInt(args[i]); |
| 1219 | } |
| 1220 | i++; |
| 1221 | } |
| 1222 | } catch (Exception e) { |
| 1223 | writer.println("Invalid args:" + e); |
| 1224 | dumpHelp(writer); |
| 1225 | return; |
| 1226 | } |
| 1227 | if (keyCode == KeyEvent.KEYCODE_UNKNOWN) { |
| 1228 | writer.println("Missing key code or invalid keycode"); |
| 1229 | dumpHelp(writer); |
| 1230 | return; |
| 1231 | } |
| 1232 | if (display != InputHalService.DISPLAY_MAIN |
| 1233 | && display != InputHalService.DISPLAY_INSTRUMENT_CLUSTER) { |
| 1234 | writer.println("Invalid display:" + display); |
| 1235 | dumpHelp(writer); |
| 1236 | return; |
| 1237 | } |
| 1238 | if (delayMs < 0) { |
| 1239 | writer.println("Invalid delay:" + delayMs); |
| 1240 | dumpHelp(writer); |
| 1241 | return; |
| 1242 | } |
| 1243 | KeyEvent keyDown = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); |
| 1244 | mCarInputService.onKeyEvent(keyDown, display); |
| 1245 | SystemClock.sleep(delayMs); |
| 1246 | KeyEvent keyUp = new KeyEvent(KeyEvent.ACTION_UP, keyCode); |
| 1247 | mCarInputService.onKeyEvent(keyUp, display); |
| 1248 | writer.println("Succeeded"); |
| 1249 | } |
| 1250 | |
Felipe Leme | a5e6938 | 2020-02-11 17:53:20 -0800 | [diff] [blame] | 1251 | private void handleGetInitialUserInfo(String[] args, PrintWriter writer) { |
| 1252 | if (args.length < 2) { |
| 1253 | writer.println("Insufficient number of args"); |
| 1254 | return; |
| 1255 | } |
| 1256 | |
| 1257 | // Gets the request type |
| 1258 | String typeArg = args[1]; |
| 1259 | int requestType = UserHalHelper.parseInitialUserInfoRequestType(typeArg); |
| 1260 | |
| 1261 | int timeout = 1_000; |
| 1262 | for (int i = 2; i < args.length; i++) { |
| 1263 | String arg = args[i]; |
| 1264 | switch (arg) { |
| 1265 | case "--timeout": |
| 1266 | timeout = Integer.parseInt(args[++i]); |
| 1267 | break; |
| 1268 | default: |
| 1269 | writer.println("Invalid option at index " + i + ": " + arg); |
| 1270 | return; |
| 1271 | |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | Log.d(TAG, "handleGetInitialUserInfo(): type=" + requestType + " (" + typeArg |
| 1276 | + "), timeout=" + timeout); |
| 1277 | |
| 1278 | UserHalService userHal = mHal.getUserHal(); |
Felipe Leme | 8f30b31 | 2020-02-28 18:01:25 -0800 | [diff] [blame] | 1279 | // TODO(b/150413515): use UserHalHelper to populate it with current users |
Felipe Leme | a5e6938 | 2020-02-11 17:53:20 -0800 | [diff] [blame] | 1280 | UsersInfo usersInfo = new UsersInfo(); |
| 1281 | CountDownLatch latch = new CountDownLatch(1); |
| 1282 | |
| 1283 | userHal.getInitialUserInfo(requestType, timeout, usersInfo, (status, resp) -> { |
| 1284 | try { |
| 1285 | Log.d(TAG, "GetUserInfoResponse: status=" + status + ", resp=" + resp); |
| 1286 | writer.printf("Status: %s\n", UserHalHelper.halCallbackStatusToString(status)); |
| 1287 | if (status != HalCallback.STATUS_OK) { |
| 1288 | return; |
| 1289 | } |
| 1290 | writer.printf("Request id: %d\n", resp.requestId); |
| 1291 | writer.printf("Action: "); |
| 1292 | switch (resp.action) { |
| 1293 | case InitialUserInfoResponseAction.DEFAULT: |
| 1294 | writer.println("default"); |
| 1295 | break; |
| 1296 | case InitialUserInfoResponseAction.SWITCH: |
| 1297 | writer.printf("switch to user %d\n", resp.userToSwitchOrCreate.userId); |
| 1298 | break; |
| 1299 | case InitialUserInfoResponseAction.CREATE: |
| 1300 | writer.printf("create user: name=%s, flags=%d\n", resp.userNameToCreate, |
| 1301 | resp.userToSwitchOrCreate.flags); |
| 1302 | break; |
| 1303 | default: |
| 1304 | writer.printf("unknown (%d)\n", resp.action); |
| 1305 | break; |
| 1306 | } |
| 1307 | } finally { |
| 1308 | latch.countDown(); |
| 1309 | } |
| 1310 | }); |
| 1311 | |
| 1312 | try { |
| 1313 | if (!latch.await(timeout, TimeUnit.MILLISECONDS)) { |
| 1314 | writer.printf("HAL didn't respond in %dms\n", timeout); |
| 1315 | } |
| 1316 | } catch (InterruptedException e) { |
| 1317 | Thread.currentThread().interrupt(); |
| 1318 | writer.println("Interrupted waiting for HAL"); |
| 1319 | } |
| 1320 | return; |
| 1321 | } |
| 1322 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 1323 | private void forceDayNightMode(String arg, PrintWriter writer) { |
| 1324 | int mode; |
| 1325 | switch (arg) { |
| 1326 | case PARAM_DAY_MODE: |
| 1327 | mode = CarNightService.FORCED_DAY_MODE; |
| 1328 | break; |
| 1329 | case PARAM_NIGHT_MODE: |
| 1330 | mode = CarNightService.FORCED_NIGHT_MODE; |
| 1331 | break; |
| 1332 | case PARAM_SENSOR_MODE: |
| 1333 | mode = CarNightService.FORCED_SENSOR_MODE; |
| 1334 | break; |
| 1335 | default: |
| 1336 | writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|" |
| 1337 | + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE); |
| 1338 | return; |
| 1339 | } |
| 1340 | int current = mCarNightService.forceDayNightMode(mode); |
| 1341 | String currentMode = null; |
| 1342 | switch (current) { |
| 1343 | case UiModeManager.MODE_NIGHT_AUTO: |
| 1344 | currentMode = PARAM_SENSOR_MODE; |
| 1345 | break; |
| 1346 | case UiModeManager.MODE_NIGHT_YES: |
| 1347 | currentMode = PARAM_NIGHT_MODE; |
| 1348 | break; |
| 1349 | case UiModeManager.MODE_NIGHT_NO: |
| 1350 | currentMode = PARAM_DAY_MODE; |
| 1351 | break; |
| 1352 | } |
| 1353 | writer.println("DayNightMode changed to: " + currentMode); |
| 1354 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 1355 | |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 1356 | private void forceGarageMode(String arg, PrintWriter writer) { |
| 1357 | switch (arg) { |
| 1358 | case PARAM_ON_MODE: |
Jim Kaye | 26fc7da | 2019-10-23 10:46:28 -0700 | [diff] [blame] | 1359 | mSystemInterface.setDisplayState(false); |
Serik Beketayev | e0e7ff2 | 2018-07-31 21:04:12 -0700 | [diff] [blame] | 1360 | mGarageModeService.forceStartGarageMode(); |
Jim Kaye | 1b5e618 | 2019-05-24 15:48:32 -0700 | [diff] [blame] | 1361 | writer.println("Garage mode: " + mGarageModeService.isGarageModeActive()); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 1362 | break; |
| 1363 | case PARAM_OFF_MODE: |
Jim Kaye | 26fc7da | 2019-10-23 10:46:28 -0700 | [diff] [blame] | 1364 | mSystemInterface.setDisplayState(true); |
Serik Beketayev | e0e7ff2 | 2018-07-31 21:04:12 -0700 | [diff] [blame] | 1365 | mGarageModeService.stopAndResetGarageMode(); |
Jim Kaye | 1b5e618 | 2019-05-24 15:48:32 -0700 | [diff] [blame] | 1366 | writer.println("Garage mode: " + mGarageModeService.isGarageModeActive()); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 1367 | break; |
| 1368 | case PARAM_QUERY_MODE: |
Jim Kaye | 1b5e618 | 2019-05-24 15:48:32 -0700 | [diff] [blame] | 1369 | mGarageModeService.dump(writer); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 1370 | break; |
Jim Kaye | 9a834ea | 2020-02-07 15:50:53 -0800 | [diff] [blame] | 1371 | case PARAM_REBOOT: |
| 1372 | mCarPowerManagementService.forceSuspendAndMaybeReboot(true); |
| 1373 | writer.println("Entering Garage Mode. Will reboot when it completes."); |
| 1374 | break; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 1375 | default: |
| 1376 | writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|" |
Jim Kaye | 9a834ea | 2020-02-07 15:50:53 -0800 | [diff] [blame] | 1377 | + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE + "|" + PARAM_REBOOT); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 1378 | } |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 1381 | /** |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 1382 | * Inject a fake VHAL event |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 1383 | * |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 1384 | * @param property the Vehicle property Id as defined in the HAL |
| 1385 | * @param zone Zone that this event services |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 1386 | * @param isErrorEvent indicates the type of event |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 1387 | * @param value Data value of the event |
| 1388 | * @param writer PrintWriter |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 1389 | */ |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 1390 | private void injectVhalEvent(String property, String zone, String value, |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 1391 | boolean isErrorEvent, PrintWriter writer) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 1392 | if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) { |
| 1393 | if (!isPropertyAreaTypeGlobal(property)) { |
| 1394 | writer.println("Property area type inconsistent with given zone"); |
| 1395 | return; |
| 1396 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 1397 | } |
| 1398 | try { |
Kai | 4b098cf | 2019-06-05 15:03:28 -0700 | [diff] [blame] | 1399 | if (isErrorEvent) { |
| 1400 | mHal.injectOnPropertySetError(property, zone, value); |
| 1401 | } else { |
| 1402 | mHal.injectVhalEvent(property, zone, value); |
| 1403 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 1404 | } catch (NumberFormatException e) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 1405 | writer.println("Invalid property Id zone Id or value" + e); |
| 1406 | dumpHelp(writer); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 1407 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 1408 | } |
| 1409 | |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 1410 | // Check if the given property is global |
| 1411 | private boolean isPropertyAreaTypeGlobal(String property) { |
| 1412 | if (property == null) { |
| 1413 | return false; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 1414 | } |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 1415 | return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 1416 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 1417 | } |
kevinjm | 55822c4 | 2018-08-15 11:26:00 -0700 | [diff] [blame] | 1418 | } |