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