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