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