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