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; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 20 | import android.app.UiModeManager; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 21 | import android.car.Car; |
| 22 | import android.car.ICar; |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 23 | import android.car.cluster.renderer.IInstrumentClusterNavigation; |
Ying Zheng | d3cb98e | 2018-05-11 11:42:48 -0700 | [diff] [blame^] | 24 | import android.car.user.CarUserManagerHelper; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 25 | import android.content.Context; |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 26 | import android.content.pm.PackageManager; |
Pavel Maltsev | cfe9310 | 2017-02-02 12:38:08 -0800 | [diff] [blame] | 27 | import android.hardware.automotive.vehicle.V2_0.IVehicle; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 28 | import android.hardware.automotive.vehicle.V2_0.VehicleArea; |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 29 | import android.os.Binder; |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 30 | import android.os.Build; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 31 | import android.os.IBinder; |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 32 | import android.os.Process; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 33 | import android.os.Trace; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 34 | import android.util.Log; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 35 | import android.util.Slog; |
Keun-young Park | 4a79a38 | 2017-08-10 18:19:14 -0700 | [diff] [blame] | 36 | import android.util.TimingsTraceLog; |
Gregory Clark | 26fa601 | 2018-03-14 18:38:56 -0700 | [diff] [blame] | 37 | |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 38 | import com.android.car.cluster.InstrumentClusterService; |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 39 | import com.android.car.hal.VehicleHal; |
Antonio Cortes | c52d5f9 | 2017-02-06 08:47:38 -0800 | [diff] [blame] | 40 | import com.android.car.internal.FeatureConfiguration; |
Keun-young Park | 4aeb4bf | 2015-12-08 18:31:33 -0800 | [diff] [blame] | 41 | import com.android.car.pm.CarPackageManagerService; |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 42 | import com.android.car.systeminterface.SystemInterface; |
Ying Zheng | d3cb98e | 2018-05-11 11:42:48 -0700 | [diff] [blame^] | 43 | import com.android.car.user.CarUserService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 44 | import com.android.internal.annotations.GuardedBy; |
Steve Paik | 1d8bea2 | 2018-02-03 01:54:06 +0000 | [diff] [blame] | 45 | import com.android.internal.car.ICarServiceHelper; |
Gregory Clark | 26fa601 | 2018-03-14 18:38:56 -0700 | [diff] [blame] | 46 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 47 | import java.io.FileDescriptor; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 48 | import java.io.PrintWriter; |
Ying Zheng | d3cb98e | 2018-05-11 11:42:48 -0700 | [diff] [blame^] | 49 | import java.util.ArrayList; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 50 | import java.util.Arrays; |
Ying Zheng | d3cb98e | 2018-05-11 11:42:48 -0700 | [diff] [blame^] | 51 | import java.util.List; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 52 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 53 | public class ICarImpl extends ICar.Stub { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 54 | |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 55 | public static final String INTERNAL_INPUT_SERVICE = "internal_input"; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 56 | public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE = |
| 57 | "system_activity_monitoring"; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 58 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 59 | private final Context mContext; |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 60 | private final VehicleHal mHal; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 61 | |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 62 | private final SystemInterface mSystemInterface; |
| 63 | |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 64 | private final SystemActivityMonitoringService mSystemActivityMonitoringService; |
keunyoung | 4b0212c | 2015-10-29 17:11:57 -0700 | [diff] [blame] | 65 | private final CarPowerManagementService mCarPowerManagementService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 66 | private final CarPackageManagerService mCarPackageManagerService; |
| 67 | private final CarInputService mCarInputService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 68 | private final CarSensorService mCarSensorService; |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 69 | private final CarDrivingStateService mCarDrivingStateService; |
Ram Periathiruvadi | 4526a43 | 2018-01-24 13:00:54 -0800 | [diff] [blame] | 70 | private final CarUxRestrictionsManagerService mCarUXRestrictionsService; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 71 | private final CarInfoService mCarInfoService; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 72 | private final CarAudioService mCarAudioService; |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 73 | private final CarProjectionService mCarProjectionService; |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 74 | private final CarCabinService mCarCabinService; |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 75 | private final CarHvacService mCarHvacService; |
Joseph Pirozzo | 317343d | 2016-01-25 10:22:37 -0800 | [diff] [blame] | 76 | private final CarNightService mCarNightService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 77 | private final AppFocusService mAppFocusService; |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 78 | private final GarageModeService mGarageModeService; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 79 | private final InstrumentClusterService mInstrumentClusterService; |
Gregory Clark | d813606 | 2017-12-11 14:27:53 -0800 | [diff] [blame] | 80 | private final CarLocationService mCarLocationService; |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 81 | private final SystemStateControllerService mSystemStateControllerService; |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 82 | private final CarVendorExtensionService mCarVendorExtensionService; |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 83 | private final CarBluetoothService mCarBluetoothService; |
Ram Periathiruvadi | acb6024 | 2017-04-13 16:19:09 -0700 | [diff] [blame] | 84 | private final PerUserCarServiceHelper mPerUserCarServiceHelper; |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 85 | private final CarDiagnosticService mCarDiagnosticService; |
| 86 | private final CarStorageMonitoringService mCarStorageMonitoringService; |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 87 | private final CarConfigurationService mCarConfigurationService; |
| 88 | |
Ying Zheng | d3cb98e | 2018-05-11 11:42:48 -0700 | [diff] [blame^] | 89 | private final CarUserManagerHelper mUserManagerHelper; |
| 90 | private CarUserService mCarUserService; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 91 | private VmsSubscriberService mVmsSubscriberService; |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 92 | private VmsPublisherService mVmsPublisherService; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 93 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 94 | private final CarServiceBase[] mAllServices; |
| 95 | |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 96 | private static final String TAG = "ICarImpl"; |
| 97 | private static final String VHAL_TIMING_TAG = "VehicleHalTiming"; |
Keun-young Park | 4a79a38 | 2017-08-10 18:19:14 -0700 | [diff] [blame] | 98 | private static final TimingsTraceLog mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, |
Gregory Clark | d813606 | 2017-12-11 14:27:53 -0800 | [diff] [blame] | 99 | Trace.TRACE_TAG_HAL); |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 100 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 101 | /** Test only service. Populate it only when necessary. */ |
| 102 | @GuardedBy("this") |
| 103 | private CarTestService mCarTestService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 104 | |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 105 | @GuardedBy("this") |
| 106 | private ICarServiceHelper mICarServiceHelper; |
| 107 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 108 | private final String mVehicleInterfaceName; |
| 109 | |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 110 | public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface, |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 111 | CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 112 | mContext = serviceContext; |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame] | 113 | mSystemInterface = systemInterface; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 114 | mHal = new VehicleHal(vehicle); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 115 | mVehicleInterfaceName = vehicleInterfaceName; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 116 | mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext); |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 117 | mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(), |
| 118 | systemInterface); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 119 | mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal()); |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 120 | mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarSensorService); |
Ram Periathiruvadi | 4526a43 | 2018-01-24 13:00:54 -0800 | [diff] [blame] | 121 | mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext, |
Ram Periathiruvadi | ed9e8f8 | 2018-03-07 11:50:49 -0800 | [diff] [blame] | 122 | mCarDrivingStateService, mCarSensorService); |
Ram Periathiruvadi | 2da6d0e | 2018-01-26 18:02:10 -0800 | [diff] [blame] | 123 | mCarPackageManagerService = new CarPackageManagerService(serviceContext, |
| 124 | mCarUXRestrictionsService, |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 125 | mSystemActivityMonitoringService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 126 | mCarInputService = new CarInputService(serviceContext, mHal.getInputHal()); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 127 | mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService); |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 128 | mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService); |
Gregory Clark | 26fa601 | 2018-03-14 18:38:56 -0700 | [diff] [blame] | 129 | mCarLocationService = new CarLocationService(mContext, mCarPowerManagementService, |
| 130 | mCarSensorService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 131 | mCarInfoService = new CarInfoService(serviceContext, mHal.getInfoHal()); |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 132 | mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService); |
Hongwei Wang | 3055723 | 2018-01-02 10:25:08 -0800 | [diff] [blame] | 133 | mCarAudioService = new CarAudioService(serviceContext); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 134 | mCarCabinService = new CarCabinService(serviceContext, mHal.getCabinHal()); |
| 135 | mCarHvacService = new CarHvacService(serviceContext, mHal.getHvacHal()); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 136 | mCarNightService = new CarNightService(serviceContext, mCarSensorService); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 137 | mInstrumentClusterService = new InstrumentClusterService(serviceContext, |
Pavel Maltsev | 03cf60c | 2016-06-27 15:11:51 -0700 | [diff] [blame] | 138 | mAppFocusService, mCarInputService); |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 139 | mSystemStateControllerService = new SystemStateControllerService(serviceContext, |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 140 | mCarPowerManagementService, mCarAudioService, this); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 141 | mCarVendorExtensionService = new CarVendorExtensionService(serviceContext, |
| 142 | mHal.getVendorExtensionHal()); |
Ram Periathiruvadi | acb6024 | 2017-04-13 16:19:09 -0700 | [diff] [blame] | 143 | mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext); |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 144 | mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService, |
Ram Periathiruvadi | e011a40 | 2018-03-22 18:54:33 -0700 | [diff] [blame] | 145 | mCarSensorService, mPerUserCarServiceHelper, mCarUXRestrictionsService); |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 146 | mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal()); |
| 147 | mVmsPublisherService = new VmsPublisherService(serviceContext, mHal.getVmsHal()); |
Enrico Granata | b3634e2 | 2017-05-05 18:02:31 -0700 | [diff] [blame] | 148 | mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal()); |
Enrico Granata | 517a1e0 | 2017-09-20 16:15:50 -0700 | [diff] [blame] | 149 | mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext, |
| 150 | systemInterface); |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 151 | mCarConfigurationService = |
| 152 | new CarConfigurationService(serviceContext, new JsonReaderImpl()); |
Ying Zheng | d3cb98e | 2018-05-11 11:42:48 -0700 | [diff] [blame^] | 153 | mUserManagerHelper = new CarUserManagerHelper(serviceContext); |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 154 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 155 | // Be careful with order. Service depending on other service should be inited later. |
Ying Zheng | d3cb98e | 2018-05-11 11:42:48 -0700 | [diff] [blame^] | 156 | List<CarServiceBase> allServices = new ArrayList<>(); |
| 157 | allServices.add(mSystemActivityMonitoringService); |
| 158 | allServices.add(mCarPowerManagementService); |
| 159 | allServices.add(mCarSensorService); |
| 160 | allServices.add(mCarDrivingStateService); |
| 161 | allServices.add(mCarUXRestrictionsService); |
| 162 | allServices.add(mCarPackageManagerService); |
| 163 | allServices.add(mCarInputService); |
| 164 | allServices.add(mCarLocationService); |
| 165 | allServices.add(mGarageModeService); |
| 166 | allServices.add(mCarInfoService); |
| 167 | allServices.add(mAppFocusService); |
| 168 | allServices.add(mCarAudioService); |
| 169 | allServices.add(mCarCabinService); |
| 170 | allServices.add(mCarHvacService); |
| 171 | allServices.add(mCarNightService); |
| 172 | allServices.add(mInstrumentClusterService); |
| 173 | allServices.add(mCarProjectionService); |
| 174 | allServices.add(mSystemStateControllerService); |
| 175 | allServices.add(mCarVendorExtensionService); |
| 176 | allServices.add(mCarBluetoothService); |
| 177 | allServices.add(mCarDiagnosticService); |
| 178 | allServices.add(mPerUserCarServiceHelper); |
| 179 | allServices.add(mCarStorageMonitoringService); |
| 180 | allServices.add(mCarConfigurationService); |
| 181 | allServices.add(mVmsSubscriberService); |
| 182 | allServices.add(mVmsPublisherService); |
| 183 | |
| 184 | if (mUserManagerHelper.isHeadlessSystemUser()) { |
| 185 | mCarUserService = new CarUserService(serviceContext, mUserManagerHelper); |
| 186 | allServices.add(mCarUserService); |
| 187 | } |
| 188 | |
| 189 | mAllServices = allServices.toArray(new CarServiceBase[allServices.size()]); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 192 | @MainThread |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 193 | void init() { |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 194 | traceBegin("VehicleHal.init"); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 195 | mHal.init(); |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 196 | traceEnd(); |
| 197 | traceBegin("CarService.initAllServices"); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 198 | for (CarServiceBase service : mAllServices) { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 199 | service.init(); |
| 200 | } |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 201 | traceEnd(); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 204 | void release() { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 205 | // release done in opposite order from init |
| 206 | for (int i = mAllServices.length - 1; i >= 0; i--) { |
| 207 | mAllServices[i].release(); |
| 208 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 209 | mHal.release(); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 212 | void vehicleHalReconnected(IVehicle vehicle) { |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 213 | mHal.vehicleHalReconnected(vehicle); |
| 214 | for (CarServiceBase service : mAllServices) { |
| 215 | service.vehicleHalReconnected(); |
| 216 | } |
| 217 | } |
| 218 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 219 | @Override |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 220 | public void setCarServiceHelper(IBinder helper) { |
| 221 | int uid = Binder.getCallingUid(); |
| 222 | if (uid != Process.SYSTEM_UID) { |
| 223 | throw new SecurityException("Only allowed from system"); |
| 224 | } |
| 225 | synchronized (this) { |
| 226 | mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper); |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame] | 227 | mSystemInterface.setCarServiceHelper(mICarServiceHelper); |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
| 231 | @Override |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 232 | public IBinder getCarService(String serviceName) { |
| 233 | switch (serviceName) { |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 234 | case Car.AUDIO_SERVICE: |
| 235 | return mCarAudioService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 236 | case Car.SENSOR_SERVICE: |
| 237 | return mCarSensorService; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 238 | case Car.INFO_SERVICE: |
| 239 | return mCarInfoService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 240 | case Car.APP_FOCUS_SERVICE: |
| 241 | return mAppFocusService; |
Keun-young Park | 45fdcba | 2015-12-08 11:38:58 -0800 | [diff] [blame] | 242 | case Car.PACKAGE_SERVICE: |
| 243 | return mCarPackageManagerService; |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 244 | case Car.CABIN_SERVICE: |
| 245 | assertCabinPermission(mContext); |
| 246 | return mCarCabinService; |
Enrico Granata | 5c56d2a | 2017-02-07 15:38:12 -0800 | [diff] [blame] | 247 | case Car.DIAGNOSTIC_SERVICE: |
Enrico Granata | b3634e2 | 2017-05-05 18:02:31 -0700 | [diff] [blame] | 248 | assertAnyDiagnosticPermission(mContext); |
| 249 | return mCarDiagnosticService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 250 | case Car.HVAC_SERVICE: |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 251 | assertHvacPermission(mContext); |
| 252 | return mCarHvacService; |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 253 | case Car.POWER_SERVICE: |
| 254 | assertPowerPermission(mContext); |
| 255 | return mCarPowerManagementService; |
Pavel Maltsev | 7a948e5 | 2016-02-02 23:30:14 -0800 | [diff] [blame] | 256 | case Car.CAR_NAVIGATION_SERVICE: |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 257 | assertNavigationManagerPermission(mContext); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 258 | IInstrumentClusterNavigation navService = |
| 259 | mInstrumentClusterService.getNavigationService(); |
| 260 | return navService == null ? null : navService.asBinder(); |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 261 | case Car.CAR_INSTRUMENT_CLUSTER_SERVICE: |
| 262 | assertClusterManagerPermission(mContext); |
| 263 | return mInstrumentClusterService.getManagerService(); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 264 | case Car.PROJECTION_SERVICE: |
| 265 | assertProjectionPermission(mContext); |
| 266 | return mCarProjectionService; |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 267 | case Car.VENDOR_EXTENSION_SERVICE: |
| 268 | assertVendorExtensionPermission(mContext); |
| 269 | return mCarVendorExtensionService; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 270 | case Car.VMS_SUBSCRIBER_SERVICE: |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 271 | assertVmsSubscriberPermission(mContext); |
| 272 | return mVmsSubscriberService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 273 | case Car.TEST_SERVICE: { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 274 | assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 275 | synchronized (this) { |
| 276 | if (mCarTestService == null) { |
| 277 | mCarTestService = new CarTestService(mContext, this); |
| 278 | } |
| 279 | return mCarTestService; |
| 280 | } |
| 281 | } |
Ram Periathiruvadi | 76a8489 | 2017-07-27 18:10:35 -0700 | [diff] [blame] | 282 | case Car.BLUETOOTH_SERVICE: |
| 283 | return mCarBluetoothService; |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 284 | case Car.STORAGE_MONITORING_SERVICE: |
Enrico Granata | 1172f88 | 2017-09-21 14:51:30 -0700 | [diff] [blame] | 285 | assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING); |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 286 | return mCarStorageMonitoringService; |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 287 | case Car.CAR_DRIVING_STATE_SERVICE: |
| 288 | assertDrivingStatePermission(mContext); |
| 289 | return mCarDrivingStateService; |
| 290 | case Car.CAR_UX_RESTRICTION_SERVICE: |
| 291 | return mCarUXRestrictionsService; |
Anthony Chen | d4203d8 | 2018-05-16 16:21:52 -0700 | [diff] [blame] | 292 | case Car.CAR_CONFIGURATION_SERVICE: |
| 293 | return mCarConfigurationService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 294 | default: |
| 295 | Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName); |
| 296 | return null; |
| 297 | } |
| 298 | } |
| 299 | |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 300 | @Override |
| 301 | public int getCarConnectionType() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 302 | return Car.CONNECTION_TYPE_EMBEDDED; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 305 | public CarServiceBase getCarInternalService(String serviceName) { |
| 306 | switch (serviceName) { |
| 307 | case INTERNAL_INPUT_SERVICE: |
| 308 | return mCarInputService; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 309 | case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE: |
| 310 | return mSystemActivityMonitoringService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 311 | default: |
| 312 | Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" + |
| 313 | serviceName); |
| 314 | return null; |
| 315 | } |
| 316 | } |
| 317 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 318 | public static void assertVehicleHalMockPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 319 | assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 322 | public static void assertCabinPermission(Context context) { |
Kai | 25c0b85 | 2018-03-01 11:52:31 -0800 | [diff] [blame] | 323 | assertPermission(context, Car.PERMISSION_ADJUST_CAR_CABIN); |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 326 | public static void assertNavigationManagerPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 327 | assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER); |
Pavel Maltsev | ce4ffd9 | 2016-03-09 10:56:23 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 330 | public static void assertClusterManagerPermission(Context context) { |
| 331 | assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL); |
| 332 | } |
| 333 | |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 334 | public static void assertHvacPermission(Context context) { |
Kai | 68ee16b | 2018-03-22 11:57:37 -0700 | [diff] [blame] | 335 | assertPermission(context, Car.PERMISSION_CONTROL_CAR_CLIMATE); |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Steve Paik | 388d777 | 2018-02-12 10:54:51 -0800 | [diff] [blame] | 338 | public static void assertPowerPermission(Context context) { |
| 339 | assertPermission(context, Car.PERMISSION_CAR_POWER); |
| 340 | } |
| 341 | |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 342 | public static void assertProjectionPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 343 | assertPermission(context, Car.PERMISSION_CAR_PROJECTION); |
| 344 | } |
| 345 | |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 346 | public static void assertVendorExtensionPermission(Context context) { |
| 347 | assertPermission(context, Car.PERMISSION_VENDOR_EXTENSION); |
| 348 | } |
| 349 | |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 350 | public static void assertAnyDiagnosticPermission(Context context) { |
| 351 | assertAnyPermission(context, |
Enrico Granata | ae25b92 | 2017-07-07 11:28:15 -0700 | [diff] [blame] | 352 | Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL, |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 353 | Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR); |
| 354 | } |
| 355 | |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 356 | public static void assertDrivingStatePermission(Context context) { |
| 357 | assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE); |
| 358 | } |
| 359 | |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 360 | public static void assertVmsPublisherPermission(Context context) { |
| 361 | assertPermission(context, Car.PERMISSION_VMS_PUBLISHER); |
| 362 | } |
| 363 | |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 364 | public static void assertVmsSubscriberPermission(Context context) { |
| 365 | assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER); |
| 366 | } |
| 367 | |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 368 | public static void assertPermission(Context context, String permission) { |
| 369 | if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { |
| 370 | throw new SecurityException("requires " + permission); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 374 | public static void assertAnyPermission(Context context, String... permissions) { |
| 375 | for (String permission : permissions) { |
| 376 | if (context.checkCallingOrSelfPermission(permission) == |
| 377 | PackageManager.PERMISSION_GRANTED) { |
| 378 | return; |
| 379 | } |
| 380 | } |
| 381 | throw new SecurityException("requires any of " + Arrays.toString(permissions)); |
| 382 | } |
| 383 | |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 384 | @Override |
| 385 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| 386 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 387 | != PackageManager.PERMISSION_GRANTED) { |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 388 | writer.println("Permission Denial: can't dump CarService from from pid=" |
Anthony Chen | 12aec30 | 2018-04-25 16:41:48 -0700 | [diff] [blame] | 389 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() |
| 390 | + " without permission " + android.Manifest.permission.DUMP); |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 391 | return; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 392 | } |
Enrico Granata | e8056ca | 2018-04-03 13:19:52 -0700 | [diff] [blame] | 393 | if (args == null || args.length == 0) { |
| 394 | writer.println("*dump car service*"); |
| 395 | |
| 396 | writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT); |
| 397 | writer.println("*Dump all services*"); |
| 398 | for (CarServiceBase service : mAllServices) { |
| 399 | dumpService(service, writer); |
| 400 | } |
| 401 | if (mCarTestService != null) { |
| 402 | dumpService(mCarTestService, writer); |
| 403 | } |
| 404 | writer.println("*Dump Vehicle HAL*"); |
| 405 | writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName); |
| 406 | try { |
| 407 | // TODO dump all feature flags by creating a dumpable interface |
| 408 | mHal.dump(writer); |
| 409 | } catch (Exception e) { |
| 410 | writer.println("Failed dumping: " + mHal.getClass().getName()); |
| 411 | e.printStackTrace(writer); |
| 412 | } |
| 413 | } else if (Build.IS_USERDEBUG || Build.IS_ENG) { |
| 414 | execShellCmd(args, writer); |
| 415 | } else { |
| 416 | writer.println("Commands not supported in " + Build.TYPE); |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
| 420 | private void dumpService(CarServiceBase service, PrintWriter writer) { |
| 421 | try { |
| 422 | service.dump(writer); |
| 423 | } catch (Exception e) { |
| 424 | writer.println("Failed dumping: " + service.getClass().getName()); |
| 425 | e.printStackTrace(writer); |
| 426 | } |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 427 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 428 | |
| 429 | void execShellCmd(String[] args, PrintWriter writer) { |
| 430 | new CarShellCommand().exec(args, writer); |
| 431 | } |
| 432 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 433 | @MainThread |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 434 | private static void traceBegin(String name) { |
| 435 | Slog.i(TAG, name); |
| 436 | mBootTiming.traceBegin(name); |
| 437 | } |
| 438 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 439 | @MainThread |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 440 | private static void traceEnd() { |
| 441 | mBootTiming.traceEnd(); |
| 442 | } |
| 443 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 444 | private class CarShellCommand { |
| 445 | private static final String COMMAND_HELP = "-h"; |
| 446 | private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 447 | private static final String COMMAND_INJECT_VHAL_EVENT = "inject-vhal-event"; |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 448 | private static final String COMMAND_ENABLE_UXR = "enable-uxr"; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 449 | private static final String COMMAND_GARAGE_MODE = "garage-mode"; |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 450 | private static final String COMMAND_GET_DO_ACTIVITIES = "get-do-activities"; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 451 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 452 | private static final String PARAM_DAY_MODE = "day"; |
| 453 | private static final String PARAM_NIGHT_MODE = "night"; |
| 454 | private static final String PARAM_SENSOR_MODE = "sensor"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 455 | private static final String PARAM_VEHICLE_PROPERTY_AREA_GLOBAL = "0"; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 456 | private static final String PARAM_ON_MODE = "on"; |
| 457 | private static final String PARAM_OFF_MODE = "off"; |
| 458 | private static final String PARAM_QUERY_MODE = "query"; |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 459 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 460 | |
| 461 | private void dumpHelp(PrintWriter pw) { |
| 462 | pw.println("Car service commands:"); |
| 463 | pw.println("\t-h"); |
| 464 | pw.println("\t Print this help text."); |
| 465 | pw.println("\tday-night-mode [day|night|sensor]"); |
| 466 | pw.println("\t Force into day/night mode or restore to auto."); |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 467 | pw.println("\tinject-vhal-event property [zone] data(can be comma separated list)"); |
| 468 | pw.println("\t Inject a vehicle property for testing"); |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 469 | pw.println("\tdisable-uxr true|false"); |
| 470 | pw.println("\t Disable UX restrictions and App blocking."); |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 471 | pw.println("\tgarage-mode [on|off|query]"); |
| 472 | pw.println("\t Force into garage mode or check status."); |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 473 | pw.println("\tget-do-activities pkgname"); |
| 474 | pw.println("\t Get Distraction Optimized activities in given package"); |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | public void exec(String[] args, PrintWriter writer) { |
| 478 | String arg = args[0]; |
| 479 | switch (arg) { |
| 480 | case COMMAND_HELP: |
| 481 | dumpHelp(writer); |
| 482 | break; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 483 | case COMMAND_DAY_NIGHT_MODE: { |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 484 | String value = args.length < 1 ? "" : args[1]; |
| 485 | forceDayNightMode(value, writer); |
| 486 | break; |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 487 | } |
| 488 | case COMMAND_GARAGE_MODE: { |
| 489 | String value = args.length < 1 ? "" : args[1]; |
| 490 | forceGarageMode(value, writer); |
| 491 | break; |
| 492 | } |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 493 | case COMMAND_INJECT_VHAL_EVENT: |
| 494 | String zone = PARAM_VEHICLE_PROPERTY_AREA_GLOBAL; |
| 495 | String data; |
| 496 | if (args.length < 3) { |
| 497 | writer.println("Incorrect number of arguments."); |
| 498 | dumpHelp(writer); |
| 499 | break; |
| 500 | } else if (args.length > 3) { |
| 501 | // Zoned |
| 502 | zone = args[2]; |
| 503 | data = args[3]; |
| 504 | } else { |
| 505 | // Global |
| 506 | data = args[2]; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 507 | } |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 508 | injectVhalEvent(args[1], zone, data, writer); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 509 | break; |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 510 | case COMMAND_ENABLE_UXR: |
| 511 | if (args.length < 2) { |
| 512 | writer.println("Incorrect number of arguments"); |
| 513 | dumpHelp(writer); |
| 514 | break; |
| 515 | } |
| 516 | boolean enableBlocking = Boolean.valueOf(args[1]); |
| 517 | if (mCarPackageManagerService != null) { |
| 518 | mCarPackageManagerService.setEnableActivityBlocking(enableBlocking); |
| 519 | } |
| 520 | break; |
Ram Periathiruvadi | 3838830 | 2018-02-22 16:42:49 -0800 | [diff] [blame] | 521 | case COMMAND_GET_DO_ACTIVITIES: |
| 522 | if (args.length < 2) { |
| 523 | writer.println("Incorrect number of arguments"); |
| 524 | dumpHelp(writer); |
| 525 | break; |
| 526 | } |
| 527 | String pkgName = args[1].toLowerCase(); |
| 528 | if (mCarPackageManagerService != null) { |
| 529 | String[] doActivities = |
| 530 | mCarPackageManagerService.getDistractionOptimizedActivities( |
| 531 | pkgName); |
| 532 | if (doActivities != null) { |
| 533 | writer.println("DO Activities for " + pkgName); |
| 534 | for (String a : doActivities) { |
| 535 | writer.println(a); |
| 536 | } |
| 537 | } else { |
| 538 | writer.println("No DO Activities for " + pkgName); |
| 539 | } |
| 540 | } |
| 541 | break; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 542 | default: |
| 543 | writer.println("Unknown command."); |
| 544 | dumpHelp(writer); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | private void forceDayNightMode(String arg, PrintWriter writer) { |
| 549 | int mode; |
| 550 | switch (arg) { |
| 551 | case PARAM_DAY_MODE: |
| 552 | mode = CarNightService.FORCED_DAY_MODE; |
| 553 | break; |
| 554 | case PARAM_NIGHT_MODE: |
| 555 | mode = CarNightService.FORCED_NIGHT_MODE; |
| 556 | break; |
| 557 | case PARAM_SENSOR_MODE: |
| 558 | mode = CarNightService.FORCED_SENSOR_MODE; |
| 559 | break; |
| 560 | default: |
| 561 | writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|" |
| 562 | + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE); |
| 563 | return; |
| 564 | } |
| 565 | int current = mCarNightService.forceDayNightMode(mode); |
| 566 | String currentMode = null; |
| 567 | switch (current) { |
| 568 | case UiModeManager.MODE_NIGHT_AUTO: |
| 569 | currentMode = PARAM_SENSOR_MODE; |
| 570 | break; |
| 571 | case UiModeManager.MODE_NIGHT_YES: |
| 572 | currentMode = PARAM_NIGHT_MODE; |
| 573 | break; |
| 574 | case UiModeManager.MODE_NIGHT_NO: |
| 575 | currentMode = PARAM_DAY_MODE; |
| 576 | break; |
| 577 | } |
| 578 | writer.println("DayNightMode changed to: " + currentMode); |
| 579 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 580 | |
Bryan Eyler | a32a7c1 | 2018-02-27 15:40:00 -0800 | [diff] [blame] | 581 | private void forceGarageMode(String arg, PrintWriter writer) { |
| 582 | switch (arg) { |
| 583 | case PARAM_ON_MODE: |
| 584 | mGarageModeService.onPrepareShutdown(false); |
| 585 | break; |
| 586 | case PARAM_OFF_MODE: |
| 587 | mGarageModeService.onSleepEntry(); |
| 588 | break; |
| 589 | case PARAM_QUERY_MODE: |
| 590 | // Nothing to do. Always query at the end anyway. |
| 591 | break; |
| 592 | default: |
| 593 | writer.println("Unknown value. Valid argument: " + PARAM_ON_MODE + "|" |
| 594 | + PARAM_OFF_MODE + "|" + PARAM_QUERY_MODE); |
| 595 | return; |
| 596 | } |
| 597 | writer.println("Garage mode: " + mGarageModeService.isInGarageMode()); |
| 598 | } |
| 599 | |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 600 | /** |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 601 | * Inject a fake VHAL event |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 602 | * |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 603 | * @param property the Vehicle property Id as defined in the HAL |
| 604 | * @param zone Zone that this event services |
| 605 | * @param value Data value of the event |
| 606 | * @param writer PrintWriter |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 607 | */ |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 608 | private void injectVhalEvent(String property, String zone, String value, |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 609 | PrintWriter writer) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 610 | if (zone != null && (zone.equalsIgnoreCase(PARAM_VEHICLE_PROPERTY_AREA_GLOBAL))) { |
| 611 | if (!isPropertyAreaTypeGlobal(property)) { |
| 612 | writer.println("Property area type inconsistent with given zone"); |
| 613 | return; |
| 614 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 615 | } |
| 616 | try { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 617 | mHal.injectVhalEvent(property, zone, value); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 618 | } catch (NumberFormatException e) { |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 619 | writer.println("Invalid property Id zone Id or value" + e); |
| 620 | dumpHelp(writer); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 621 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 622 | } |
| 623 | |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 624 | // Check if the given property is global |
| 625 | private boolean isPropertyAreaTypeGlobal(String property) { |
| 626 | if (property == null) { |
| 627 | return false; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 628 | } |
Ram Periathiruvadi | 5cd00cb | 2018-02-12 13:49:50 -0800 | [diff] [blame] | 629 | return (Integer.decode(property) & VehicleArea.MASK) == VehicleArea.GLOBAL; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 630 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 631 | } |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 632 | } |