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 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 19 | import android.app.UiModeManager; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 20 | import android.car.Car; |
| 21 | import android.car.ICar; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 22 | import android.car.annotation.FutureFeature; |
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; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 27 | import android.hardware.automotive.vehicle.V2_0.VehicleAreaDoor; |
| 28 | import android.hardware.automotive.vehicle.V2_0.VehicleProperty; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 29 | import android.os.IBinder; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 30 | import android.util.Log; |
| 31 | |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 32 | import com.android.car.cluster.InstrumentClusterService; |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 33 | import com.android.car.hal.VehicleHal; |
Antonio Cortes | c52d5f9 | 2017-02-06 08:47:38 -0800 | [diff] [blame] | 34 | import com.android.car.internal.FeatureConfiguration; |
| 35 | import com.android.car.internal.FeatureUtil; |
Keun-young Park | 4aeb4bf | 2015-12-08 18:31:33 -0800 | [diff] [blame] | 36 | import com.android.car.pm.CarPackageManagerService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 37 | import com.android.internal.annotations.GuardedBy; |
| 38 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 39 | import java.io.PrintWriter; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 40 | import java.util.ArrayList; |
| 41 | import java.util.Arrays; |
| 42 | import java.util.List; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 43 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 44 | public class ICarImpl extends ICar.Stub { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 45 | |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame^] | 46 | public static final String INTERNAL_INPUT_SERVICE = "internal_input"; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 47 | public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE = |
| 48 | "system_activity_monitoring"; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 49 | |
| 50 | // load jni for all services here |
| 51 | static { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 52 | try { |
| 53 | System.loadLibrary("jni_car_service"); |
| 54 | } catch (UnsatisfiedLinkError ex) { |
| 55 | // Unable to load native library when loaded from the testing framework. |
| 56 | Log.e(CarLog.TAG_SERVICE, "Failed to load jni_car_service library: " + ex.getMessage()); |
| 57 | } |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 58 | } |
| 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 | |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 63 | private final SystemActivityMonitoringService mSystemActivityMonitoringService; |
keunyoung | 4b0212c | 2015-10-29 17:11:57 -0700 | [diff] [blame] | 64 | private final CarPowerManagementService mCarPowerManagementService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 65 | private final CarPackageManagerService mCarPackageManagerService; |
| 66 | private final CarInputService mCarInputService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 67 | private final CarSensorService mCarSensorService; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 68 | private final CarInfoService mCarInfoService; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 69 | private final CarAudioService mCarAudioService; |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 70 | private final CarProjectionService mCarProjectionService; |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 71 | private final CarCabinService mCarCabinService; |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 72 | private final CarCameraService mCarCameraService; |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 73 | private final CarHvacService mCarHvacService; |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 74 | private final CarRadioService mCarRadioService; |
Joseph Pirozzo | 317343d | 2016-01-25 10:22:37 -0800 | [diff] [blame] | 75 | private final CarNightService mCarNightService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 76 | private final AppFocusService mAppFocusService; |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 77 | private final GarageModeService mGarageModeService; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 78 | private final InstrumentClusterService mInstrumentClusterService; |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 79 | private final SystemStateControllerService mSystemStateControllerService; |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 80 | private final CarVendorExtensionService mCarVendorExtensionService; |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 81 | private final CarBluetoothService mCarBluetoothService; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 82 | @FutureFeature |
Enrico Granata | 5c56d2a | 2017-02-07 15:38:12 -0800 | [diff] [blame] | 83 | private CarDiagnosticService mCarDiagnosticService; |
| 84 | @FutureFeature |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 85 | private VmsSubscriberService mVmsSubscriberService; |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 86 | @FutureFeature |
| 87 | private VmsPublisherService mVmsPublisherService; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 88 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 89 | private final CarServiceBase[] mAllServices; |
| 90 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 91 | /** Test only service. Populate it only when necessary. */ |
| 92 | @GuardedBy("this") |
| 93 | private CarTestService mCarTestService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 94 | |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 95 | public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface, |
| 96 | CanBusErrorNotifier errorNotifier) { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 97 | mContext = serviceContext; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 98 | mHal = new VehicleHal(vehicle); |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 99 | mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 100 | mCarPowerManagementService = new CarPowerManagementService( |
| 101 | mHal.getPowerHal(), systemInterface); |
| 102 | mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal()); |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 103 | mCarPackageManagerService = new CarPackageManagerService(serviceContext, mCarSensorService, |
| 104 | mSystemActivityMonitoringService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 105 | mCarInputService = new CarInputService(serviceContext, mHal.getInputHal()); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 106 | mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService); |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 107 | mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 108 | mCarInfoService = new CarInfoService(serviceContext, mHal.getInfoHal()); |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 109 | mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 110 | mCarAudioService = new CarAudioService(serviceContext, mHal.getAudioHal(), |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 111 | mCarInputService, errorNotifier); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 112 | mCarCabinService = new CarCabinService(serviceContext, mHal.getCabinHal()); |
| 113 | mCarHvacService = new CarHvacService(serviceContext, mHal.getHvacHal()); |
| 114 | mCarRadioService = new CarRadioService(serviceContext, mHal.getRadioHal()); |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 115 | mCarCameraService = new CarCameraService(serviceContext); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 116 | mCarNightService = new CarNightService(serviceContext, mCarSensorService); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 117 | mInstrumentClusterService = new InstrumentClusterService(serviceContext, |
Pavel Maltsev | 03cf60c | 2016-06-27 15:11:51 -0700 | [diff] [blame] | 118 | mAppFocusService, mCarInputService); |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 119 | mSystemStateControllerService = new SystemStateControllerService(serviceContext, |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 120 | mCarPowerManagementService, mCarAudioService, this); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 121 | mCarVendorExtensionService = new CarVendorExtensionService(serviceContext, |
| 122 | mHal.getVendorExtensionHal()); |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame^] | 123 | mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService, |
| 124 | mCarSensorService); |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 125 | if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { |
| 126 | mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal()); |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 127 | mVmsPublisherService = new VmsPublisherService(serviceContext, mHal.getVmsHal()); |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 128 | } |
Enrico Granata | 5c56d2a | 2017-02-07 15:38:12 -0800 | [diff] [blame] | 129 | if (FeatureConfiguration.ENABLE_DIAGNOSTIC) { |
| 130 | mCarDiagnosticService = new CarDiagnosticService(serviceContext, |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame^] | 131 | mHal.getDiagnosticHal()); |
Enrico Granata | 5c56d2a | 2017-02-07 15:38:12 -0800 | [diff] [blame] | 132 | } |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 133 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 134 | // 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] | 135 | List<CarServiceBase> allServices = new ArrayList<>(Arrays.asList( |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 136 | mSystemActivityMonitoringService, |
keunyoung | 4b0212c | 2015-10-29 17:11:57 -0700 | [diff] [blame] | 137 | mCarPowerManagementService, |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 138 | mCarSensorService, |
Keun-young Park | 45fdcba | 2015-12-08 11:38:58 -0800 | [diff] [blame] | 139 | mCarPackageManagerService, |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 140 | mCarInputService, |
| 141 | mGarageModeService, |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 142 | mCarInfoService, |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 143 | mAppFocusService, |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 144 | mCarAudioService, |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 145 | mCarCabinService, |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 146 | mCarHvacService, |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 147 | mCarRadioService, |
| 148 | mCarCameraService, |
Joseph Pirozzo | 317343d | 2016-01-25 10:22:37 -0800 | [diff] [blame] | 149 | mCarNightService, |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 150 | mInstrumentClusterService, |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 151 | mCarProjectionService, |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 152 | mSystemStateControllerService, |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 153 | mCarVendorExtensionService, |
| 154 | mCarBluetoothService |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 155 | )); |
| 156 | if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { |
| 157 | allServices.add(mVmsSubscriberService); |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 158 | allServices.add(mVmsPublisherService); |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 159 | } |
Enrico Granata | 5c56d2a | 2017-02-07 15:38:12 -0800 | [diff] [blame] | 160 | if (FeatureConfiguration.ENABLE_DIAGNOSTIC) { |
| 161 | allServices.add(mCarDiagnosticService); |
| 162 | } |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 163 | mAllServices = allServices.toArray(new CarServiceBase[0]); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 166 | public void init() { |
| 167 | mHal.init(); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 168 | for (CarServiceBase service : mAllServices) { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 169 | service.init(); |
| 170 | } |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 173 | public void release() { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 174 | // release done in opposite order from init |
| 175 | for (int i = mAllServices.length - 1; i >= 0; i--) { |
| 176 | mAllServices[i].release(); |
| 177 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 178 | mHal.release(); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 181 | public void vehicleHalReconnected(IVehicle vehicle) { |
| 182 | mHal.vehicleHalReconnected(vehicle); |
| 183 | for (CarServiceBase service : mAllServices) { |
| 184 | service.vehicleHalReconnected(); |
| 185 | } |
| 186 | } |
| 187 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 188 | @Override |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 189 | public IBinder getCarService(String serviceName) { |
| 190 | switch (serviceName) { |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 191 | case Car.AUDIO_SERVICE: |
| 192 | return mCarAudioService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 193 | case Car.SENSOR_SERVICE: |
| 194 | return mCarSensorService; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 195 | case Car.INFO_SERVICE: |
| 196 | return mCarInfoService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 197 | case Car.APP_FOCUS_SERVICE: |
| 198 | return mAppFocusService; |
Keun-young Park | 45fdcba | 2015-12-08 11:38:58 -0800 | [diff] [blame] | 199 | case Car.PACKAGE_SERVICE: |
| 200 | return mCarPackageManagerService; |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 201 | case Car.CABIN_SERVICE: |
| 202 | assertCabinPermission(mContext); |
| 203 | return mCarCabinService; |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 204 | case Car.CAMERA_SERVICE: |
| 205 | assertCameraPermission(mContext); |
| 206 | return mCarCameraService; |
Enrico Granata | 5c56d2a | 2017-02-07 15:38:12 -0800 | [diff] [blame] | 207 | case Car.DIAGNOSTIC_SERVICE: |
Enrico Granata | 34010ed | 2017-02-16 11:51:47 -0800 | [diff] [blame] | 208 | FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_DIAGNOSTIC); |
| 209 | if (FeatureConfiguration.ENABLE_DIAGNOSTIC) { |
| 210 | //TODO(egranata): handle permissions |
| 211 | return mCarDiagnosticService; |
| 212 | } |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 213 | case Car.HVAC_SERVICE: |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 214 | assertHvacPermission(mContext); |
| 215 | return mCarHvacService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 216 | case Car.RADIO_SERVICE: |
keunyoung | 6b19769 | 2015-11-16 13:54:38 -0800 | [diff] [blame] | 217 | assertRadioPermission(mContext); |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 218 | return mCarRadioService; |
Pavel Maltsev | 7a948e5 | 2016-02-02 23:30:14 -0800 | [diff] [blame] | 219 | case Car.CAR_NAVIGATION_SERVICE: |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 220 | assertNavigationManagerPermission(mContext); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 221 | IInstrumentClusterNavigation navService = |
| 222 | mInstrumentClusterService.getNavigationService(); |
| 223 | return navService == null ? null : navService.asBinder(); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 224 | case Car.PROJECTION_SERVICE: |
| 225 | assertProjectionPermission(mContext); |
| 226 | return mCarProjectionService; |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 227 | case Car.VENDOR_EXTENSION_SERVICE: |
| 228 | assertVendorExtensionPermission(mContext); |
| 229 | return mCarVendorExtensionService; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 230 | case Car.VMS_SUBSCRIBER_SERVICE: |
| 231 | FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE); |
| 232 | if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { |
| 233 | assertVmsSubscriberPermission(mContext); |
| 234 | return mVmsSubscriberService; |
| 235 | } |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 236 | case Car.TEST_SERVICE: { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 237 | assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 238 | synchronized (this) { |
| 239 | if (mCarTestService == null) { |
| 240 | mCarTestService = new CarTestService(mContext, this); |
| 241 | } |
| 242 | return mCarTestService; |
| 243 | } |
| 244 | } |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 245 | default: |
| 246 | Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName); |
| 247 | return null; |
| 248 | } |
| 249 | } |
| 250 | |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 251 | @Override |
| 252 | public int getCarConnectionType() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 253 | return Car.CONNECTION_TYPE_EMBEDDED; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 254 | } |
| 255 | |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 256 | public CarServiceBase getCarInternalService(String serviceName) { |
| 257 | switch (serviceName) { |
| 258 | case INTERNAL_INPUT_SERVICE: |
| 259 | return mCarInputService; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 260 | case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE: |
| 261 | return mSystemActivityMonitoringService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 262 | default: |
| 263 | Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" + |
| 264 | serviceName); |
| 265 | return null; |
| 266 | } |
| 267 | } |
| 268 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 269 | public static void assertVehicleHalMockPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 270 | assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 273 | public static void assertCabinPermission(Context context) { |
| 274 | assertPermission(context, Car.PERMISSION_CAR_CABIN); |
| 275 | } |
| 276 | |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 277 | public static void assertCameraPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 278 | assertPermission(context, Car.PERMISSION_CAR_CAMERA); |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 279 | } |
| 280 | |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 281 | public static void assertNavigationManagerPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 282 | assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER); |
Pavel Maltsev | ce4ffd9 | 2016-03-09 10:56:23 -0800 | [diff] [blame] | 283 | } |
| 284 | |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 285 | public static void assertHvacPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 286 | assertPermission(context, Car.PERMISSION_CAR_HVAC); |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 287 | } |
| 288 | |
keunyoung | 6b19769 | 2015-11-16 13:54:38 -0800 | [diff] [blame] | 289 | private static void assertRadioPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 290 | assertPermission(context, Car.PERMISSION_CAR_RADIO); |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 293 | public static void assertProjectionPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 294 | assertPermission(context, Car.PERMISSION_CAR_PROJECTION); |
| 295 | } |
| 296 | |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 297 | public static void assertVendorExtensionPermission(Context context) { |
| 298 | assertPermission(context, Car.PERMISSION_VENDOR_EXTENSION); |
| 299 | } |
| 300 | |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 301 | @FutureFeature |
Antonio Cortes | 6b3544c | 2017-02-06 16:54:58 -0800 | [diff] [blame] | 302 | public static void assertVmsPublisherPermission(Context context) { |
| 303 | assertPermission(context, Car.PERMISSION_VMS_PUBLISHER); |
| 304 | } |
| 305 | |
| 306 | @FutureFeature |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 307 | public static void assertVmsSubscriberPermission(Context context) { |
| 308 | assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER); |
| 309 | } |
| 310 | |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 311 | public static void assertPermission(Context context, String permission) { |
| 312 | if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { |
| 313 | throw new SecurityException("requires " + permission); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 317 | void dump(PrintWriter writer) { |
Keun-young Park | bae6e25 | 2017-01-25 12:30:15 -0800 | [diff] [blame] | 318 | writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT); |
| 319 | //TODO dump all feature flags by reflection |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 320 | writer.println("*Dump all services*"); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 321 | for (CarServiceBase service : mAllServices) { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 322 | service.dump(writer); |
| 323 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 324 | if (mCarTestService != null) { |
| 325 | mCarTestService.dump(writer); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 326 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 327 | writer.println("*Dump Vehicle HAL*"); |
| 328 | mHal.dump(writer); |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 329 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 330 | |
| 331 | void execShellCmd(String[] args, PrintWriter writer) { |
| 332 | new CarShellCommand().exec(args, writer); |
| 333 | } |
| 334 | |
| 335 | private class CarShellCommand { |
| 336 | private static final String COMMAND_HELP = "-h"; |
| 337 | private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode"; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 338 | private static final String COMMAND_INJECT_EVENT = "inject-event"; |
| 339 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 340 | private static final String PARAM_DAY_MODE = "day"; |
| 341 | private static final String PARAM_NIGHT_MODE = "night"; |
| 342 | private static final String PARAM_SENSOR_MODE = "sensor"; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 343 | private static final String PARAM_ZONED_BOOLEAN = "zoned-boolean"; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame^] | 344 | private static final String PARAM_GLOBAL_INT = "global-integer"; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 345 | |
| 346 | private void dumpHelp(PrintWriter pw) { |
| 347 | pw.println("Car service commands:"); |
| 348 | pw.println("\t-h"); |
| 349 | pw.println("\t Print this help text."); |
| 350 | pw.println("\tday-night-mode [day|night|sensor]"); |
| 351 | pw.println("\t Force into day/night mode or restore to auto."); |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 352 | pw.println("\tinject-event zoned-boolean propertyType zone [true|false]"); |
| 353 | pw.println("\t Inject a Boolean HAL Event. "); |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | public void exec(String[] args, PrintWriter writer) { |
| 357 | String arg = args[0]; |
| 358 | switch (arg) { |
| 359 | case COMMAND_HELP: |
| 360 | dumpHelp(writer); |
| 361 | break; |
| 362 | case COMMAND_DAY_NIGHT_MODE: |
| 363 | String value = args.length < 1 ? "" : args[1]; |
| 364 | forceDayNightMode(value, writer); |
| 365 | break; |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 366 | case COMMAND_INJECT_EVENT: |
| 367 | String eventType; |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame^] | 368 | if (args.length > 1) { |
| 369 | eventType = args[1].toLowerCase(); |
| 370 | switch (eventType) { |
| 371 | case PARAM_ZONED_BOOLEAN: |
| 372 | if (args.length < 5) { |
| 373 | writer.println("Incorrect number of arguments."); |
| 374 | dumpHelp(writer); |
| 375 | break; |
| 376 | } |
| 377 | inject_zoned_boolean_event(args[2], args[3], args[4], writer); |
| 378 | break; |
| 379 | |
| 380 | case PARAM_GLOBAL_INT: |
| 381 | if (args.length < 4) { |
| 382 | writer.println("Incorrect number of Arguments"); |
| 383 | dumpHelp(writer); |
| 384 | break; |
| 385 | } |
| 386 | inject_global_integer_event(args[2], args[3], writer); |
| 387 | break; |
| 388 | |
| 389 | default: |
| 390 | writer.println("Unsupported event type"); |
| 391 | dumpHelp(writer); |
| 392 | break; |
| 393 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 394 | } |
| 395 | break; |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 396 | default: |
| 397 | writer.println("Unknown command."); |
| 398 | dumpHelp(writer); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | private void forceDayNightMode(String arg, PrintWriter writer) { |
| 403 | int mode; |
| 404 | switch (arg) { |
| 405 | case PARAM_DAY_MODE: |
| 406 | mode = CarNightService.FORCED_DAY_MODE; |
| 407 | break; |
| 408 | case PARAM_NIGHT_MODE: |
| 409 | mode = CarNightService.FORCED_NIGHT_MODE; |
| 410 | break; |
| 411 | case PARAM_SENSOR_MODE: |
| 412 | mode = CarNightService.FORCED_SENSOR_MODE; |
| 413 | break; |
| 414 | default: |
| 415 | writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|" |
| 416 | + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE); |
| 417 | return; |
| 418 | } |
| 419 | int current = mCarNightService.forceDayNightMode(mode); |
| 420 | String currentMode = null; |
| 421 | switch (current) { |
| 422 | case UiModeManager.MODE_NIGHT_AUTO: |
| 423 | currentMode = PARAM_SENSOR_MODE; |
| 424 | break; |
| 425 | case UiModeManager.MODE_NIGHT_YES: |
| 426 | currentMode = PARAM_NIGHT_MODE; |
| 427 | break; |
| 428 | case UiModeManager.MODE_NIGHT_NO: |
| 429 | currentMode = PARAM_DAY_MODE; |
| 430 | break; |
| 431 | } |
| 432 | writer.println("DayNightMode changed to: " + currentMode); |
| 433 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 434 | |
| 435 | /** |
| 436 | * Inject a fake boolean HAL event to help testing. |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame^] | 437 | * |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 438 | * @param property - Vehicle Property |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame^] | 439 | * @param value - boolean value for the property |
| 440 | * @param writer - Printwriter |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 441 | */ |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame^] | 442 | private void inject_zoned_boolean_event(String property, String zone, String value, |
| 443 | PrintWriter writer) { |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 444 | Log.d(CarLog.TAG_SERVICE, "Injecting Boolean event"); |
| 445 | boolean event; |
| 446 | int propId; |
| 447 | int zoneId; |
| 448 | if (value.equalsIgnoreCase("true")) { |
| 449 | event = true; |
| 450 | } else { |
| 451 | event = false; |
| 452 | } |
| 453 | try { |
| 454 | propId = Integer.decode(property); |
| 455 | zoneId = Integer.decode(zone); |
| 456 | } catch (NumberFormatException e) { |
| 457 | writer.println("Invalid property Id or Zone Id. Prefix hex values with 0x"); |
| 458 | return; |
| 459 | } |
| 460 | mHal.injectBooleanEvent(propId, zoneId, event); |
| 461 | } |
| 462 | |
Ram Periathiruvadi | 49d5a5a | 2017-02-17 18:50:09 -0800 | [diff] [blame^] | 463 | /** |
| 464 | * Inject a fake Integer HAL event to help testing. |
| 465 | * |
| 466 | * @param property - Vehicle Property |
| 467 | * @param value - Integer value to inject |
| 468 | * @param writer - PrintWriter |
| 469 | */ |
| 470 | private void inject_global_integer_event(String property, String value, |
| 471 | PrintWriter writer) { |
| 472 | Log.d(CarLog.TAG_SERVICE, "Injecting integer event"); |
| 473 | int propId; |
| 474 | int eventValue; |
| 475 | try { |
| 476 | propId = Integer.decode(property); |
| 477 | eventValue = Integer.decode(value); |
| 478 | } catch (NumberFormatException e) { |
| 479 | writer.println("Invalid property Id or event value. Prefix hex values with 0x"); |
| 480 | return; |
| 481 | } |
| 482 | mHal.injectIntegerEvent(propId, eventValue); |
| 483 | } |
| 484 | |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 485 | } |
Ram Periathiruvadi | ee28c00 | 2017-02-07 21:35:01 -0800 | [diff] [blame] | 486 | } |