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; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 24 | import android.car.internal.FeatureUtil; |
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; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 28 | import android.os.IBinder; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 29 | import android.util.Log; |
| 30 | |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 31 | import com.android.car.cluster.InstrumentClusterService; |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 32 | import com.android.car.hal.VehicleHal; |
Keun-young Park | 4aeb4bf | 2015-12-08 18:31:33 -0800 | [diff] [blame] | 33 | import com.android.car.pm.CarPackageManagerService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 34 | import com.android.internal.annotations.GuardedBy; |
| 35 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 36 | import java.io.PrintWriter; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 37 | import java.util.ArrayList; |
| 38 | import java.util.Arrays; |
| 39 | import java.util.List; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 40 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 41 | public class ICarImpl extends ICar.Stub { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 42 | |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 43 | public static final String INTERNAL_INPUT_SERVICE = "internal_input"; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 44 | public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE = |
| 45 | "system_activity_monitoring"; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 46 | |
| 47 | // load jni for all services here |
| 48 | static { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 49 | try { |
| 50 | System.loadLibrary("jni_car_service"); |
| 51 | } catch (UnsatisfiedLinkError ex) { |
| 52 | // Unable to load native library when loaded from the testing framework. |
| 53 | Log.e(CarLog.TAG_SERVICE, "Failed to load jni_car_service library: " + ex.getMessage()); |
| 54 | } |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 55 | } |
| 56 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 57 | private final Context mContext; |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 58 | private final VehicleHal mHal; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 59 | |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 60 | private final SystemActivityMonitoringService mSystemActivityMonitoringService; |
keunyoung | 4b0212c | 2015-10-29 17:11:57 -0700 | [diff] [blame] | 61 | private final CarPowerManagementService mCarPowerManagementService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 62 | private final CarPackageManagerService mCarPackageManagerService; |
| 63 | private final CarInputService mCarInputService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 64 | private final CarSensorService mCarSensorService; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 65 | private final CarInfoService mCarInfoService; |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 66 | private final CarAudioService mCarAudioService; |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 67 | private final CarProjectionService mCarProjectionService; |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 68 | private final CarCabinService mCarCabinService; |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 69 | private final CarCameraService mCarCameraService; |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 70 | private final CarHvacService mCarHvacService; |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 71 | private final CarRadioService mCarRadioService; |
Joseph Pirozzo | 317343d | 2016-01-25 10:22:37 -0800 | [diff] [blame] | 72 | private final CarNightService mCarNightService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 73 | private final AppFocusService mAppFocusService; |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 74 | private final GarageModeService mGarageModeService; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 75 | private final InstrumentClusterService mInstrumentClusterService; |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 76 | private final SystemStateControllerService mSystemStateControllerService; |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 77 | private final CarVendorExtensionService mCarVendorExtensionService; |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 78 | private final CarBluetoothService mCarBluetoothService; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 79 | @FutureFeature |
| 80 | private VmsSubscriberService mVmsSubscriberService; |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 81 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 82 | private final CarServiceBase[] mAllServices; |
| 83 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 84 | /** Test only service. Populate it only when necessary. */ |
| 85 | @GuardedBy("this") |
| 86 | private CarTestService mCarTestService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 87 | |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 88 | public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface, |
| 89 | CanBusErrorNotifier errorNotifier) { |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 90 | mContext = serviceContext; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 91 | mHal = new VehicleHal(vehicle); |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 92 | mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 93 | mCarPowerManagementService = new CarPowerManagementService( |
| 94 | mHal.getPowerHal(), systemInterface); |
| 95 | mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal()); |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 96 | mCarPackageManagerService = new CarPackageManagerService(serviceContext, mCarSensorService, |
| 97 | mSystemActivityMonitoringService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 98 | mCarInputService = new CarInputService(serviceContext, mHal.getInputHal()); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 99 | mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService); |
Yao Chen | 3a7976d | 2016-01-20 17:27:08 -0800 | [diff] [blame] | 100 | mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 101 | mCarInfoService = new CarInfoService(serviceContext, mHal.getInfoHal()); |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 102 | mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 103 | mCarAudioService = new CarAudioService(serviceContext, mHal.getAudioHal(), |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 104 | mCarInputService, errorNotifier); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 105 | mCarCabinService = new CarCabinService(serviceContext, mHal.getCabinHal()); |
| 106 | mCarHvacService = new CarHvacService(serviceContext, mHal.getHvacHal()); |
| 107 | mCarRadioService = new CarRadioService(serviceContext, mHal.getRadioHal()); |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 108 | mCarCameraService = new CarCameraService(serviceContext); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 109 | mCarNightService = new CarNightService(serviceContext, mCarSensorService); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 110 | mInstrumentClusterService = new InstrumentClusterService(serviceContext, |
Pavel Maltsev | 03cf60c | 2016-06-27 15:11:51 -0700 | [diff] [blame] | 111 | mAppFocusService, mCarInputService); |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 112 | mSystemStateControllerService = new SystemStateControllerService(serviceContext, |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 113 | mCarPowerManagementService, mCarAudioService, this); |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 114 | mCarVendorExtensionService = new CarVendorExtensionService(serviceContext, |
| 115 | mHal.getVendorExtensionHal()); |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 116 | mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService); |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 117 | if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { |
| 118 | mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal()); |
| 119 | } |
keunyoung | a74b9ca | 2015-10-21 13:33:58 -0700 | [diff] [blame] | 120 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 121 | // 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] | 122 | List<CarServiceBase> allServices = new ArrayList<>(Arrays.asList( |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 123 | mSystemActivityMonitoringService, |
keunyoung | 4b0212c | 2015-10-29 17:11:57 -0700 | [diff] [blame] | 124 | mCarPowerManagementService, |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 125 | mCarSensorService, |
Keun-young Park | 45fdcba | 2015-12-08 11:38:58 -0800 | [diff] [blame] | 126 | mCarPackageManagerService, |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 127 | mCarInputService, |
| 128 | mGarageModeService, |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 129 | mCarInfoService, |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 130 | mAppFocusService, |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 131 | mCarAudioService, |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 132 | mCarCabinService, |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 133 | mCarHvacService, |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 134 | mCarRadioService, |
| 135 | mCarCameraService, |
Joseph Pirozzo | 317343d | 2016-01-25 10:22:37 -0800 | [diff] [blame] | 136 | mCarNightService, |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 137 | mInstrumentClusterService, |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 138 | mCarProjectionService, |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 139 | mSystemStateControllerService, |
Ram Periathiruvadi | 7ed8418 | 2017-01-20 15:18:08 -0800 | [diff] [blame] | 140 | mCarVendorExtensionService, |
| 141 | mCarBluetoothService |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 142 | )); |
| 143 | if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { |
| 144 | allServices.add(mVmsSubscriberService); |
| 145 | } |
| 146 | mAllServices = allServices.toArray(new CarServiceBase[0]); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 149 | public void init() { |
| 150 | mHal.init(); |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 151 | for (CarServiceBase service: mAllServices) { |
| 152 | service.init(); |
| 153 | } |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 156 | public void release() { |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 157 | // release done in opposite order from init |
| 158 | for (int i = mAllServices.length - 1; i >= 0; i--) { |
| 159 | mAllServices[i].release(); |
| 160 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 161 | mHal.release(); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Pavel Maltsev | ec83b63 | 2017-01-05 15:10:55 -0800 | [diff] [blame] | 164 | public void vehicleHalReconnected(IVehicle vehicle) { |
| 165 | mHal.vehicleHalReconnected(vehicle); |
| 166 | for (CarServiceBase service : mAllServices) { |
| 167 | service.vehicleHalReconnected(); |
| 168 | } |
| 169 | } |
| 170 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 171 | @Override |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 172 | public IBinder getCarService(String serviceName) { |
| 173 | switch (serviceName) { |
Keun-young Park | 5672e85 | 2016-02-09 19:53:48 -0800 | [diff] [blame] | 174 | case Car.AUDIO_SERVICE: |
| 175 | return mCarAudioService; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 176 | case Car.SENSOR_SERVICE: |
| 177 | return mCarSensorService; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 178 | case Car.INFO_SERVICE: |
| 179 | return mCarInfoService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 180 | case Car.APP_FOCUS_SERVICE: |
| 181 | return mAppFocusService; |
Keun-young Park | 45fdcba | 2015-12-08 11:38:58 -0800 | [diff] [blame] | 182 | case Car.PACKAGE_SERVICE: |
| 183 | return mCarPackageManagerService; |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 184 | case Car.CABIN_SERVICE: |
| 185 | assertCabinPermission(mContext); |
| 186 | return mCarCabinService; |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 187 | case Car.CAMERA_SERVICE: |
| 188 | assertCameraPermission(mContext); |
| 189 | return mCarCameraService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 190 | case Car.HVAC_SERVICE: |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 191 | assertHvacPermission(mContext); |
| 192 | return mCarHvacService; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 193 | case Car.RADIO_SERVICE: |
keunyoung | 6b19769 | 2015-11-16 13:54:38 -0800 | [diff] [blame] | 194 | assertRadioPermission(mContext); |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 195 | return mCarRadioService; |
Pavel Maltsev | 7a948e5 | 2016-02-02 23:30:14 -0800 | [diff] [blame] | 196 | case Car.CAR_NAVIGATION_SERVICE: |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 197 | assertNavigationManagerPermission(mContext); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 198 | IInstrumentClusterNavigation navService = |
| 199 | mInstrumentClusterService.getNavigationService(); |
| 200 | return navService == null ? null : navService.asBinder(); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 201 | case Car.PROJECTION_SERVICE: |
| 202 | assertProjectionPermission(mContext); |
| 203 | return mCarProjectionService; |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 204 | case Car.VENDOR_EXTENSION_SERVICE: |
| 205 | assertVendorExtensionPermission(mContext); |
| 206 | return mCarVendorExtensionService; |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 207 | case Car.VMS_SUBSCRIBER_SERVICE: |
| 208 | FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE); |
| 209 | if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { |
| 210 | assertVmsSubscriberPermission(mContext); |
| 211 | return mVmsSubscriberService; |
| 212 | } |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 213 | case Car.TEST_SERVICE: { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 214 | assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 215 | synchronized (this) { |
| 216 | if (mCarTestService == null) { |
| 217 | mCarTestService = new CarTestService(mContext, this); |
| 218 | } |
| 219 | return mCarTestService; |
| 220 | } |
| 221 | } |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 222 | default: |
| 223 | Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName); |
| 224 | return null; |
| 225 | } |
| 226 | } |
| 227 | |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 228 | @Override |
| 229 | public int getCarConnectionType() { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 230 | return Car.CONNECTION_TYPE_EMBEDDED; |
Pavel Maltsev | 1ecdd6c | 2016-03-02 16:33:44 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 233 | public CarServiceBase getCarInternalService(String serviceName) { |
| 234 | switch (serviceName) { |
| 235 | case INTERNAL_INPUT_SERVICE: |
| 236 | return mCarInputService; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 237 | case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE: |
| 238 | return mSystemActivityMonitoringService; |
Keun-young Park | a28d7b2 | 2016-02-29 16:54:29 -0800 | [diff] [blame] | 239 | default: |
| 240 | Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" + |
| 241 | serviceName); |
| 242 | return null; |
| 243 | } |
| 244 | } |
| 245 | |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 246 | public static void assertVehicleHalMockPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 247 | assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Steve Paik | 43c04a7 | 2016-07-08 19:12:09 -0700 | [diff] [blame] | 250 | public static void assertCabinPermission(Context context) { |
| 251 | assertPermission(context, Car.PERMISSION_CAR_CABIN); |
| 252 | } |
| 253 | |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 254 | public static void assertCameraPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 255 | assertPermission(context, Car.PERMISSION_CAR_CAMERA); |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Keun-young Park | e31a8b2 | 2016-03-16 17:34:08 -0700 | [diff] [blame] | 258 | public static void assertNavigationManagerPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 259 | assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER); |
Pavel Maltsev | ce4ffd9 | 2016-03-09 10:56:23 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 262 | public static void assertHvacPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 263 | assertPermission(context, Car.PERMISSION_CAR_HVAC); |
Steve Paik | 6648198 | 2015-10-27 15:22:38 -0700 | [diff] [blame] | 264 | } |
| 265 | |
keunyoung | 6b19769 | 2015-11-16 13:54:38 -0800 | [diff] [blame] | 266 | private static void assertRadioPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 267 | assertPermission(context, Car.PERMISSION_CAR_RADIO); |
Sanket Agarwal | 3cf096a | 2015-10-13 14:46:31 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 270 | public static void assertProjectionPermission(Context context) { |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 271 | assertPermission(context, Car.PERMISSION_CAR_PROJECTION); |
| 272 | } |
| 273 | |
Pavel Maltsev | 634e1ff | 2016-07-14 15:41:26 -0700 | [diff] [blame] | 274 | public static void assertVendorExtensionPermission(Context context) { |
| 275 | assertPermission(context, Car.PERMISSION_VENDOR_EXTENSION); |
| 276 | } |
| 277 | |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 278 | @FutureFeature |
| 279 | public static void assertVmsSubscriberPermission(Context context) { |
| 280 | assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER); |
| 281 | } |
| 282 | |
Steve Paik | 461ecc6 | 2016-06-08 15:28:32 -0700 | [diff] [blame] | 283 | public static void assertPermission(Context context, String permission) { |
| 284 | if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { |
| 285 | throw new SecurityException("requires " + permission); |
Vitalii Tomkiv | 6e5ee61 | 2016-03-09 14:57:32 -0800 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 289 | void dump(PrintWriter writer) { |
Keun-young Park | bae6e25 | 2017-01-25 12:30:15 -0800 | [diff] [blame] | 290 | writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT); |
| 291 | //TODO dump all feature flags by reflection |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 292 | writer.println("*Dump all services*"); |
| 293 | for (CarServiceBase service: mAllServices) { |
| 294 | service.dump(writer); |
| 295 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 296 | if (mCarTestService != null) { |
| 297 | mCarTestService.dump(writer); |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 298 | } |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 299 | writer.println("*Dump Vehicle HAL*"); |
| 300 | mHal.dump(writer); |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 301 | } |
Yao Chen | e33f07e | 2016-07-26 12:02:51 -0700 | [diff] [blame] | 302 | |
| 303 | void execShellCmd(String[] args, PrintWriter writer) { |
| 304 | new CarShellCommand().exec(args, writer); |
| 305 | } |
| 306 | |
| 307 | private class CarShellCommand { |
| 308 | private static final String COMMAND_HELP = "-h"; |
| 309 | private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode"; |
| 310 | private static final String PARAM_DAY_MODE = "day"; |
| 311 | private static final String PARAM_NIGHT_MODE = "night"; |
| 312 | private static final String PARAM_SENSOR_MODE = "sensor"; |
| 313 | |
| 314 | private void dumpHelp(PrintWriter pw) { |
| 315 | pw.println("Car service commands:"); |
| 316 | pw.println("\t-h"); |
| 317 | pw.println("\t Print this help text."); |
| 318 | pw.println("\tday-night-mode [day|night|sensor]"); |
| 319 | pw.println("\t Force into day/night mode or restore to auto."); |
| 320 | } |
| 321 | |
| 322 | public void exec(String[] args, PrintWriter writer) { |
| 323 | String arg = args[0]; |
| 324 | switch (arg) { |
| 325 | case COMMAND_HELP: |
| 326 | dumpHelp(writer); |
| 327 | break; |
| 328 | case COMMAND_DAY_NIGHT_MODE: |
| 329 | String value = args.length < 1 ? "" : args[1]; |
| 330 | forceDayNightMode(value, writer); |
| 331 | break; |
| 332 | default: |
| 333 | writer.println("Unknown command."); |
| 334 | dumpHelp(writer); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | private void forceDayNightMode(String arg, PrintWriter writer) { |
| 339 | int mode; |
| 340 | switch (arg) { |
| 341 | case PARAM_DAY_MODE: |
| 342 | mode = CarNightService.FORCED_DAY_MODE; |
| 343 | break; |
| 344 | case PARAM_NIGHT_MODE: |
| 345 | mode = CarNightService.FORCED_NIGHT_MODE; |
| 346 | break; |
| 347 | case PARAM_SENSOR_MODE: |
| 348 | mode = CarNightService.FORCED_SENSOR_MODE; |
| 349 | break; |
| 350 | default: |
| 351 | writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|" |
| 352 | + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE); |
| 353 | return; |
| 354 | } |
| 355 | int current = mCarNightService.forceDayNightMode(mode); |
| 356 | String currentMode = null; |
| 357 | switch (current) { |
| 358 | case UiModeManager.MODE_NIGHT_AUTO: |
| 359 | currentMode = PARAM_SENSOR_MODE; |
| 360 | break; |
| 361 | case UiModeManager.MODE_NIGHT_YES: |
| 362 | currentMode = PARAM_NIGHT_MODE; |
| 363 | break; |
| 364 | case UiModeManager.MODE_NIGHT_NO: |
| 365 | currentMode = PARAM_DAY_MODE; |
| 366 | break; |
| 367 | } |
| 368 | writer.println("DayNightMode changed to: " + currentMode); |
| 369 | } |
| 370 | } |
Antonio Cortes | e4619c7 | 2017-02-02 07:53:27 -0800 | [diff] [blame] | 371 | } |