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