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; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 24 | import android.content.Context; |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 25 | import android.content.pm.PackageManager; |
Pavel Maltsev | cfe9310 | 2017-02-02 12:38:08 -0800 | [diff] [blame] | 26 | import android.hardware.automotive.vehicle.V2_0.IVehicle; |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 27 | import android.os.Binder; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 28 | import android.os.IBinder; |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 29 | import android.os.Process; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 30 | import android.os.Trace; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 31 | import android.util.Log; |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 32 | import android.util.Slog; |
Keun-young Park | 4a79a38 | 2017-08-10 18:19:14 -0700 | [diff] [blame] | 33 | import android.util.TimingsTraceLog; |
Hongwei Wang | 3055723 | 2018-01-02 10:25:08 -0800 | [diff] [blame] | 34 | |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 35 | import com.android.car.cluster.InstrumentClusterService; |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 36 | import com.android.car.hal.VehicleHal; |
Antonio Cortes | c52d5f9 | 2017-02-06 08:47:38 -0800 | [diff] [blame] | 37 | import com.android.car.internal.FeatureConfiguration; |
Keun-young Park | 4aeb4bf | 2015-12-08 18:31:33 -0800 | [diff] [blame] | 38 | import com.android.car.pm.CarPackageManagerService; |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 39 | import com.android.car.systeminterface.SystemInterface; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 40 | import com.android.internal.annotations.GuardedBy; |
Steve Paik | 1d8bea2 | 2018-02-03 01:54:06 +0000 | [diff] [blame] | 41 | import com.android.internal.car.ICarServiceHelper; |
Hongwei Wang | 3055723 | 2018-01-02 10:25:08 -0800 | [diff] [blame] | 42 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 43 | import java.io.PrintWriter; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 44 | import java.util.ArrayList; |
| 45 | import java.util.Arrays; |
| 46 | import java.util.List; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 47 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 48 | public class ICarImpl extends ICar.Stub { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 49 | |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 50 | public static final String INTERNAL_INPUT_SERVICE = "internal_input"; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 51 | public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE = |
| 52 | "system_activity_monitoring"; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 53 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 54 | private final Context mContext; |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 55 | private final VehicleHal mHal; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 56 | |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 57 | private final SystemActivityMonitoringService mSystemActivityMonitoringService; |
keunyoung | 4b0212c | 2015-10-29 17:11:57 -0700 | [diff] [blame] | 58 | private final CarPowerManagementService mCarPowerManagementService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 59 | private final CarPackageManagerService mCarPackageManagerService; |
| 60 | private final CarInputService mCarInputService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 61 | private final CarSensorService mCarSensorService; |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 62 | private final CarDrivingStateService mCarDrivingStateService; |
Ram Periathiruvadi | 4526a43 | 2018-01-24 13:00:54 -0800 | [diff] [blame] | 63 | private final CarUxRestrictionsManagerService mCarUXRestrictionsService; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 64 | private final CarInfoService mCarInfoService; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 65 | private final CarAudioService mCarAudioService; |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 66 | private final CarProjectionService mCarProjectionService; |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 67 | private final CarCabinService mCarCabinService; |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 68 | private final CarHvacService mCarHvacService; |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 69 | private final CarRadioService mCarRadioService; |
Joseph Pirozzo | 317343d | 2016-01-25 10:22:37 -0800 | [diff] [blame] | 70 | private final CarNightService mCarNightService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 71 | private final AppFocusService mAppFocusService; |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 72 | private final GarageModeService mGarageModeService; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 73 | private final InstrumentClusterService mInstrumentClusterService; |
Gregory Clark | d813606 | 2017-12-11 14:27:53 -0800 | [diff] [blame] | 74 | private final CarLocationService mCarLocationService; |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 75 | private final SystemStateControllerService mSystemStateControllerService; |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 76 | private final CarVendorExtensionService mCarVendorExtensionService; |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 77 | private final CarBluetoothService mCarBluetoothService; |
Ram Periathiruvadi | acb6024 | 2017-04-13 16:19:09 -0700 | [diff] [blame] | 78 | private final PerUserCarServiceHelper mPerUserCarServiceHelper; |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 79 | private final CarDiagnosticService mCarDiagnosticService; |
| 80 | private final CarStorageMonitoringService mCarStorageMonitoringService; |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame^] | 81 | private final SystemInterface mSystemInterface; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 82 | private VmsSubscriberService mVmsSubscriberService; |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 83 | private VmsPublisherService mVmsPublisherService; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 84 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 85 | private final CarServiceBase[] mAllServices; |
| 86 | |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 87 | private static final String TAG = "ICarImpl"; |
| 88 | private static final String VHAL_TIMING_TAG = "VehicleHalTiming"; |
Keun-young Park | 4a79a38 | 2017-08-10 18:19:14 -0700 | [diff] [blame] | 89 | private static final TimingsTraceLog mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG, |
Gregory Clark | d813606 | 2017-12-11 14:27:53 -0800 | [diff] [blame] | 90 | Trace.TRACE_TAG_HAL); |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 91 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 92 | /** Test only service. Populate it only when necessary. */ |
| 93 | @GuardedBy("this") |
| 94 | private CarTestService mCarTestService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 95 | |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 96 | @GuardedBy("this") |
| 97 | private ICarServiceHelper mICarServiceHelper; |
| 98 | |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 99 | public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface, |
| 100 | CanBusErrorNotifier errorNotifier) { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 101 | mContext = serviceContext; |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame^] | 102 | mSystemInterface = systemInterface; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 103 | mHal = new VehicleHal(vehicle); |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 104 | mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 105 | mCarPowerManagementService = new CarPowerManagementService( |
| 106 | mHal.getPowerHal(), systemInterface); |
| 107 | mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal()); |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 108 | mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarSensorService); |
Ram Periathiruvadi | 4526a43 | 2018-01-24 13:00:54 -0800 | [diff] [blame] | 109 | mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext, |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 110 | mCarDrivingStateService); |
Ram Periathiruvadi | 2da6d0e | 2018-01-26 18:02:10 -0800 | [diff] [blame] | 111 | mCarPackageManagerService = new CarPackageManagerService(serviceContext, |
| 112 | mCarUXRestrictionsService, |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 113 | mSystemActivityMonitoringService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 114 | mCarInputService = new CarInputService(serviceContext, mHal.getInputHal()); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 115 | mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService); |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 116 | mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService); |
Gregory Clark | d813606 | 2017-12-11 14:27:53 -0800 | [diff] [blame] | 117 | mCarLocationService = new CarLocationService(mContext, mCarPowerManagementService, |
| 118 | mCarSensorService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 119 | mCarInfoService = new CarInfoService(serviceContext, mHal.getInfoHal()); |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 120 | mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService); |
Hongwei Wang | 3055723 | 2018-01-02 10:25:08 -0800 | [diff] [blame] | 121 | mCarAudioService = new CarAudioService(serviceContext); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 122 | mCarCabinService = new CarCabinService(serviceContext, mHal.getCabinHal()); |
| 123 | mCarHvacService = new CarHvacService(serviceContext, mHal.getHvacHal()); |
| 124 | mCarRadioService = new CarRadioService(serviceContext, mHal.getRadioHal()); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 125 | mCarNightService = new CarNightService(serviceContext, mCarSensorService); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 126 | mInstrumentClusterService = new InstrumentClusterService(serviceContext, |
Pavel Maltsev | 03cf60c | 2016-06-27 15:11:51 -0700 | [diff] [blame] | 127 | mAppFocusService, mCarInputService); |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 128 | mSystemStateControllerService = new SystemStateControllerService(serviceContext, |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 129 | mCarPowerManagementService, mCarAudioService, this); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 130 | mCarVendorExtensionService = new CarVendorExtensionService(serviceContext, |
| 131 | mHal.getVendorExtensionHal()); |
Ram Periathiruvadi | acb6024 | 2017-04-13 16:19:09 -0700 | [diff] [blame] | 132 | mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext); |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 133 | mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService, |
Ram Periathiruvadi | acb6024 | 2017-04-13 16:19:09 -0700 | [diff] [blame] | 134 | mCarSensorService, mPerUserCarServiceHelper); |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 135 | mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal()); |
| 136 | mVmsPublisherService = new VmsPublisherService(serviceContext, mHal.getVmsHal()); |
Enrico Granata | b3634e2 | 2017-05-05 18:02:31 -0700 | [diff] [blame] | 137 | mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal()); |
Enrico Granata | 517a1e0 | 2017-09-20 16:15:50 -0700 | [diff] [blame] | 138 | mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext, |
| 139 | systemInterface); |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 140 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 141 | // Be careful with order. Service depending on other service should be inited later. |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 142 | List<CarServiceBase> allServices = new ArrayList<>(Arrays.asList( |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 143 | mSystemActivityMonitoringService, |
keunyoung | 4b0212c | 2015-10-29 17:11:57 -0700 | [diff] [blame] | 144 | mCarPowerManagementService, |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 145 | mCarSensorService, |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 146 | mCarDrivingStateService, |
| 147 | mCarUXRestrictionsService, |
Keun-young Park | 45fdcba | 2015-12-08 11:38:58 -0800 | [diff] [blame] | 148 | mCarPackageManagerService, |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 149 | mCarInputService, |
Gregory Clark | d813606 | 2017-12-11 14:27:53 -0800 | [diff] [blame] | 150 | mCarLocationService, |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 151 | mGarageModeService, |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 152 | mCarInfoService, |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 153 | mAppFocusService, |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 154 | mCarAudioService, |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 155 | mCarCabinService, |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 156 | mCarHvacService, |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 157 | mCarRadioService, |
Joseph Pirozzo | 317343d | 2016-01-25 10:22:37 -0800 | [diff] [blame] | 158 | mCarNightService, |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 159 | mInstrumentClusterService, |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 160 | mCarProjectionService, |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 161 | mSystemStateControllerService, |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 162 | mCarVendorExtensionService, |
Enrico Granata | b3634e2 | 2017-05-05 18:02:31 -0700 | [diff] [blame] | 163 | mCarBluetoothService, |
Ram Periathiruvadi | a048c0a | 2017-05-09 07:35:03 -0700 | [diff] [blame] | 164 | mCarDiagnosticService, |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 165 | mPerUserCarServiceHelper, |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 166 | mCarStorageMonitoringService, |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 167 | mVmsSubscriberService, |
| 168 | mVmsPublisherService |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 169 | )); |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 170 | mAllServices = allServices.toArray(new CarServiceBase[0]); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 173 | @MainThread |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 174 | void init() { |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 175 | traceBegin("VehicleHal.init"); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 176 | mHal.init(); |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 177 | traceEnd(); |
| 178 | traceBegin("CarService.initAllServices"); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 179 | for (CarServiceBase service : mAllServices) { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 180 | service.init(); |
| 181 | } |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 182 | traceEnd(); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 185 | void release() { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 186 | // release done in opposite order from init |
| 187 | for (int i = mAllServices.length - 1; i >= 0; i--) { |
| 188 | mAllServices[i].release(); |
| 189 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 190 | mHal.release(); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Pavel Maltsev | 8edd255 | 2017-09-18 14:52:16 -0700 | [diff] [blame] | 193 | void vehicleHalReconnected(IVehicle vehicle) { |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 194 | mHal.vehicleHalReconnected(vehicle); |
| 195 | for (CarServiceBase service : mAllServices) { |
| 196 | service.vehicleHalReconnected(); |
| 197 | } |
| 198 | } |
| 199 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 200 | @Override |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 201 | public void setCarServiceHelper(IBinder helper) { |
| 202 | int uid = Binder.getCallingUid(); |
| 203 | if (uid != Process.SYSTEM_UID) { |
| 204 | throw new SecurityException("Only allowed from system"); |
| 205 | } |
| 206 | synchronized (this) { |
| 207 | mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper); |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame^] | 208 | mSystemInterface.setCarServiceHelper(mICarServiceHelper); |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
| 212 | @Override |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 213 | public IBinder getCarService(String serviceName) { |
| 214 | switch (serviceName) { |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 215 | case Car.AUDIO_SERVICE: |
| 216 | return mCarAudioService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 217 | case Car.SENSOR_SERVICE: |
| 218 | return mCarSensorService; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 219 | case Car.INFO_SERVICE: |
| 220 | return mCarInfoService; |
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; |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 225 | case Car.CABIN_SERVICE: |
| 226 | assertCabinPermission(mContext); |
| 227 | return mCarCabinService; |
Enrico Granata | 5c56d2a | 2017-02-07 15:38:12 -0800 | [diff] [blame] | 228 | case Car.DIAGNOSTIC_SERVICE: |
Enrico Granata | b3634e2 | 2017-05-05 18:02:31 -0700 | [diff] [blame] | 229 | assertAnyDiagnosticPermission(mContext); |
| 230 | return mCarDiagnosticService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 231 | case Car.HVAC_SERVICE: |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 232 | assertHvacPermission(mContext); |
| 233 | return mCarHvacService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 234 | case Car.RADIO_SERVICE: |
keunyoung | 6b19769 | 2015-11-16 13:54:38 -0800 | [diff] [blame] | 235 | assertRadioPermission(mContext); |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 236 | return mCarRadioService; |
Pavel Maltsev | 7a948e5 | 2016-02-02 23:30:14 -0800 | [diff] [blame] | 237 | case Car.CAR_NAVIGATION_SERVICE: |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 238 | assertNavigationManagerPermission(mContext); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 239 | IInstrumentClusterNavigation navService = |
| 240 | mInstrumentClusterService.getNavigationService(); |
| 241 | return navService == null ? null : navService.asBinder(); |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 242 | case Car.CAR_INSTRUMENT_CLUSTER_SERVICE: |
| 243 | assertClusterManagerPermission(mContext); |
| 244 | return mInstrumentClusterService.getManagerService(); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 245 | case Car.PROJECTION_SERVICE: |
| 246 | assertProjectionPermission(mContext); |
| 247 | return mCarProjectionService; |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 248 | case Car.VENDOR_EXTENSION_SERVICE: |
| 249 | assertVendorExtensionPermission(mContext); |
| 250 | return mCarVendorExtensionService; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 251 | case Car.VMS_SUBSCRIBER_SERVICE: |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 252 | assertVmsSubscriberPermission(mContext); |
| 253 | return mVmsSubscriberService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 254 | case Car.TEST_SERVICE: { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 255 | assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 256 | synchronized (this) { |
| 257 | if (mCarTestService == null) { |
| 258 | mCarTestService = new CarTestService(mContext, this); |
| 259 | } |
| 260 | return mCarTestService; |
| 261 | } |
| 262 | } |
Ram Periathiruvadi | 76a8489 | 2017-07-27 18:10:35 -0700 | [diff] [blame] | 263 | case Car.BLUETOOTH_SERVICE: |
| 264 | return mCarBluetoothService; |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 265 | case Car.STORAGE_MONITORING_SERVICE: |
Enrico Granata | 1172f88 | 2017-09-21 14:51:30 -0700 | [diff] [blame] | 266 | assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING); |
Enrico Granata | 9a916d7 | 2017-09-19 14:33:08 -0700 | [diff] [blame] | 267 | return mCarStorageMonitoringService; |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 268 | case Car.CAR_DRIVING_STATE_SERVICE: |
| 269 | assertDrivingStatePermission(mContext); |
| 270 | return mCarDrivingStateService; |
| 271 | case Car.CAR_UX_RESTRICTION_SERVICE: |
| 272 | return mCarUXRestrictionsService; |
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 | |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 301 | public static void assertCabinPermission(Context context) { |
| 302 | assertPermission(context, Car.PERMISSION_CAR_CABIN); |
| 303 | } |
| 304 | |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 305 | public static void assertNavigationManagerPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 306 | assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER); |
Pavel Maltsev | ce4ffd9 | 2016-03-09 10:56:23 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 309 | public static void assertClusterManagerPermission(Context context) { |
| 310 | assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL); |
| 311 | } |
| 312 | |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 313 | public static void assertHvacPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 314 | assertPermission(context, Car.PERMISSION_CAR_HVAC); |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 315 | } |
| 316 | |
keunyoung | 6b19769 | 2015-11-16 13:54:38 -0800 | [diff] [blame] | 317 | private static void assertRadioPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 318 | assertPermission(context, Car.PERMISSION_CAR_RADIO); |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 321 | public static void assertProjectionPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 322 | assertPermission(context, Car.PERMISSION_CAR_PROJECTION); |
| 323 | } |
| 324 | |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 325 | public static void assertVendorExtensionPermission(Context context) { |
| 326 | assertPermission(context, Car.PERMISSION_VENDOR_EXTENSION); |
| 327 | } |
| 328 | |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 329 | public static void assertAnyDiagnosticPermission(Context context) { |
| 330 | assertAnyPermission(context, |
Enrico Granata | ae25b92 | 2017-07-07 11:28:15 -0700 | [diff] [blame] | 331 | Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL, |
Enrico Granata | 3c7a666 | 2017-02-23 18:07:59 -0800 | [diff] [blame] | 332 | Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR); |
| 333 | } |
| 334 | |
Ram Periathiruvadi | 25c16f1 | 2017-11-17 16:48:37 -0800 | [diff] [blame] | 335 | public static void assertDrivingStatePermission(Context context) { |
| 336 | assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE); |
| 337 | } |
| 338 | |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 339 | public static void assertVmsPublisherPermission(Context context) { |
| 340 | assertPermission(context, Car.PERMISSION_VMS_PUBLISHER); |
| 341 | } |
| 342 | |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 343 | public static void assertVmsSubscriberPermission(Context context) { |
| 344 | assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER); |
| 345 | } |
| 346 | |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 347 | public static void assertPermission(Context context, String permission) { |
| 348 | if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { |
| 349 | throw new SecurityException("requires " + permission); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 350 | } |
| 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 | |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 363 | void dump(PrintWriter writer) { |
Keun-young Park | bae6e25 | 2017-01-25 12:30:15 -0800 | [diff] [blame] | 364 | writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT); |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 365 | writer.println("*Dump all services*"); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 366 | for (CarServiceBase service : mAllServices) { |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 367 | dumpService(service, writer); |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 368 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 369 | if (mCarTestService != null) { |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 370 | dumpService(mCarTestService, writer); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 371 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 372 | writer.println("*Dump Vehicle HAL*"); |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 373 | try { |
Gregory Clark | d813606 | 2017-12-11 14:27:53 -0800 | [diff] [blame] | 374 | // TODO dump all feature flags by creating a dumpable interface |
Brad Stenning | ed3d59b | 2017-11-09 16:15:17 -0800 | [diff] [blame] | 375 | mHal.dump(writer); |
| 376 | } catch (Exception e) { |
| 377 | writer.println("Failed dumping: " + mHal.getClass().getName()); |
| 378 | e.printStackTrace(writer); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | private void dumpService(CarServiceBase service, PrintWriter writer) { |
| 383 | try { |
| 384 | service.dump(writer); |
| 385 | } catch (Exception e) { |
| 386 | writer.println("Failed dumping: " + service.getClass().getName()); |
| 387 | e.printStackTrace(writer); |
| 388 | } |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 389 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 390 | |
| 391 | void execShellCmd(String[] args, PrintWriter writer) { |
| 392 | new CarShellCommand().exec(args, writer); |
| 393 | } |
| 394 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 395 | @MainThread |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 396 | private static void traceBegin(String name) { |
| 397 | Slog.i(TAG, name); |
| 398 | mBootTiming.traceBegin(name); |
| 399 | } |
| 400 | |
Pavel Maltsev | abd4723 | 2017-10-10 16:54:57 -0700 | [diff] [blame] | 401 | @MainThread |
Steve Paik | c302c7c | 2017-08-04 14:01:58 -0700 | [diff] [blame] | 402 | private static void traceEnd() { |
| 403 | mBootTiming.traceEnd(); |
| 404 | } |
| 405 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 406 | private class CarShellCommand { |
| 407 | private static final String COMMAND_HELP = "-h"; |
| 408 | private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode"; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 409 | private static final String COMMAND_INJECT_EVENT = "inject-event"; |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 410 | private static final String COMMAND_ENABLE_UXR = "enable-uxr"; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 411 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 412 | private static final String PARAM_DAY_MODE = "day"; |
| 413 | private static final String PARAM_NIGHT_MODE = "night"; |
| 414 | private static final String PARAM_SENSOR_MODE = "sensor"; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 415 | private static final String PARAM_ZONED_BOOLEAN = "zoned-boolean"; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 416 | private static final String PARAM_GLOBAL_INT = "global-integer"; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 417 | |
| 418 | private void dumpHelp(PrintWriter pw) { |
| 419 | pw.println("Car service commands:"); |
| 420 | pw.println("\t-h"); |
| 421 | pw.println("\t Print this help text."); |
| 422 | pw.println("\tday-night-mode [day|night|sensor]"); |
| 423 | pw.println("\t Force into day/night mode or restore to auto."); |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 424 | pw.println("\tinject-event zoned-boolean|global-integer property [zone] value"); |
| 425 | pw.println("\t Inject a vehicle property - zoned boolean or global integer."); |
| 426 | pw.println("\tdisable-uxr true|false"); |
| 427 | pw.println("\t Disable UX restrictions and App blocking."); |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | public void exec(String[] args, PrintWriter writer) { |
| 431 | String arg = args[0]; |
| 432 | switch (arg) { |
| 433 | case COMMAND_HELP: |
| 434 | dumpHelp(writer); |
| 435 | break; |
| 436 | case COMMAND_DAY_NIGHT_MODE: |
| 437 | String value = args.length < 1 ? "" : args[1]; |
| 438 | forceDayNightMode(value, writer); |
| 439 | break; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 440 | case COMMAND_INJECT_EVENT: |
| 441 | String eventType; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 442 | if (args.length > 1) { |
| 443 | eventType = args[1].toLowerCase(); |
| 444 | switch (eventType) { |
| 445 | case PARAM_ZONED_BOOLEAN: |
| 446 | if (args.length < 5) { |
| 447 | writer.println("Incorrect number of arguments."); |
| 448 | dumpHelp(writer); |
| 449 | break; |
| 450 | } |
| 451 | inject_zoned_boolean_event(args[2], args[3], args[4], writer); |
| 452 | break; |
| 453 | |
| 454 | case PARAM_GLOBAL_INT: |
| 455 | if (args.length < 4) { |
| 456 | writer.println("Incorrect number of Arguments"); |
| 457 | dumpHelp(writer); |
| 458 | break; |
| 459 | } |
| 460 | inject_global_integer_event(args[2], args[3], writer); |
| 461 | break; |
| 462 | |
| 463 | default: |
| 464 | writer.println("Unsupported event type"); |
| 465 | dumpHelp(writer); |
| 466 | break; |
| 467 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 468 | } |
| 469 | break; |
Ram Periathiruvadi | bf0eab7 | 2018-02-06 12:32:43 -0800 | [diff] [blame] | 470 | case COMMAND_ENABLE_UXR: |
| 471 | if (args.length < 2) { |
| 472 | writer.println("Incorrect number of arguments"); |
| 473 | dumpHelp(writer); |
| 474 | break; |
| 475 | } |
| 476 | boolean enableBlocking = Boolean.valueOf(args[1]); |
| 477 | if (mCarPackageManagerService != null) { |
| 478 | mCarPackageManagerService.setEnableActivityBlocking(enableBlocking); |
| 479 | } |
| 480 | break; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 481 | default: |
| 482 | writer.println("Unknown command."); |
| 483 | dumpHelp(writer); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | private void forceDayNightMode(String arg, PrintWriter writer) { |
| 488 | int mode; |
| 489 | switch (arg) { |
| 490 | case PARAM_DAY_MODE: |
| 491 | mode = CarNightService.FORCED_DAY_MODE; |
| 492 | break; |
| 493 | case PARAM_NIGHT_MODE: |
| 494 | mode = CarNightService.FORCED_NIGHT_MODE; |
| 495 | break; |
| 496 | case PARAM_SENSOR_MODE: |
| 497 | mode = CarNightService.FORCED_SENSOR_MODE; |
| 498 | break; |
| 499 | default: |
| 500 | writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|" |
| 501 | + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE); |
| 502 | return; |
| 503 | } |
| 504 | int current = mCarNightService.forceDayNightMode(mode); |
| 505 | String currentMode = null; |
| 506 | switch (current) { |
| 507 | case UiModeManager.MODE_NIGHT_AUTO: |
| 508 | currentMode = PARAM_SENSOR_MODE; |
| 509 | break; |
| 510 | case UiModeManager.MODE_NIGHT_YES: |
| 511 | currentMode = PARAM_NIGHT_MODE; |
| 512 | break; |
| 513 | case UiModeManager.MODE_NIGHT_NO: |
| 514 | currentMode = PARAM_DAY_MODE; |
| 515 | break; |
| 516 | } |
| 517 | writer.println("DayNightMode changed to: " + currentMode); |
| 518 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 519 | |
| 520 | /** |
| 521 | * Inject a fake boolean HAL event to help testing. |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 522 | * |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 523 | * @param property - Vehicle Property |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 524 | * @param value - boolean value for the property |
| 525 | * @param writer - Printwriter |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 526 | */ |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 527 | private void inject_zoned_boolean_event(String property, String zone, String value, |
| 528 | PrintWriter writer) { |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 529 | Log.d(CarLog.TAG_SERVICE, "Injecting Boolean event"); |
| 530 | boolean event; |
| 531 | int propId; |
| 532 | int zoneId; |
| 533 | if (value.equalsIgnoreCase("true")) { |
| 534 | event = true; |
| 535 | } else { |
| 536 | event = false; |
| 537 | } |
| 538 | try { |
| 539 | propId = Integer.decode(property); |
| 540 | zoneId = Integer.decode(zone); |
| 541 | } catch (NumberFormatException e) { |
| 542 | writer.println("Invalid property Id or Zone Id. Prefix hex values with 0x"); |
| 543 | return; |
| 544 | } |
| 545 | mHal.injectBooleanEvent(propId, zoneId, event); |
| 546 | } |
| 547 | |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame] | 548 | /** |
| 549 | * Inject a fake Integer HAL event to help testing. |
| 550 | * |
| 551 | * @param property - Vehicle Property |
| 552 | * @param value - Integer value to inject |
| 553 | * @param writer - PrintWriter |
| 554 | */ |
| 555 | private void inject_global_integer_event(String property, String value, |
| 556 | PrintWriter writer) { |
| 557 | Log.d(CarLog.TAG_SERVICE, "Injecting integer event"); |
| 558 | int propId; |
| 559 | int eventValue; |
| 560 | try { |
| 561 | propId = Integer.decode(property); |
| 562 | eventValue = Integer.decode(value); |
| 563 | } catch (NumberFormatException e) { |
| 564 | writer.println("Invalid property Id or event value. Prefix hex values with 0x"); |
| 565 | return; |
| 566 | } |
| 567 | mHal.injectIntegerEvent(propId, eventValue); |
| 568 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 569 | } |
Keun-young Park | aab47cd | 2017-06-05 11:04:50 -0700 | [diff] [blame] | 570 | } |