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