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