blob: 61aae916109b3d4402dc19587763e418ac56d18b [file] [log] [blame]
keunyoungca515072015-07-10 12:21:47 -07001/*
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
17package com.android.car;
18
Yao Chene33f07e2016-07-26 12:02:51 -070019import android.app.UiModeManager;
Keun-young Parke54ac272016-02-16 19:02:18 -080020import android.car.Car;
21import android.car.ICar;
Antonio Cortese4619c72017-02-02 07:53:27 -080022import android.car.annotation.FutureFeature;
Pavel Maltsev0477e292016-05-27 12:22:36 -070023import android.car.cluster.renderer.IInstrumentClusterNavigation;
keunyoungca515072015-07-10 12:21:47 -070024import android.content.Context;
keunyoung1ab8e182015-09-24 09:25:22 -070025import android.content.pm.PackageManager;
Pavel Maltsevcfe93102017-02-02 12:38:08 -080026import android.hardware.automotive.vehicle.V2_0.IVehicle;
Ram Periathiruvadiee28c002017-02-07 21:35:01 -080027import android.hardware.automotive.vehicle.V2_0.VehicleAreaDoor;
28import android.hardware.automotive.vehicle.V2_0.VehicleProperty;
keunyoungca515072015-07-10 12:21:47 -070029import android.os.IBinder;
keunyoungca515072015-07-10 12:21:47 -070030import android.util.Log;
31
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080032import com.android.car.cluster.InstrumentClusterService;
keunyoungcc449f72015-08-12 10:46:27 -070033import com.android.car.hal.VehicleHal;
Antonio Cortesc52d5f92017-02-06 08:47:38 -080034import com.android.car.internal.FeatureConfiguration;
35import com.android.car.internal.FeatureUtil;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080036import com.android.car.pm.CarPackageManagerService;
keunyoungca515072015-07-10 12:21:47 -070037import com.android.internal.annotations.GuardedBy;
38
keunyounga3b28d82015-08-25 13:05:15 -070039import java.io.PrintWriter;
Antonio Cortese4619c72017-02-02 07:53:27 -080040import java.util.ArrayList;
41import java.util.Arrays;
42import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070043
keunyoungca515072015-07-10 12:21:47 -070044public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070045
Keun-young Parka28d7b22016-02-29 16:54:29 -080046 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070047 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
48 "system_activity_monitoring";
Keun-young Parka28d7b22016-02-29 16:54:29 -080049
50 // load jni for all services here
51 static {
Pavel Maltsev0d07c762016-11-03 16:40:15 -070052 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 Parka28d7b22016-02-29 16:54:29 -080058 }
59
keunyoungca515072015-07-10 12:21:47 -070060 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080061 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070062
Keun-young Park4727da32016-05-31 10:00:51 -070063 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070064 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080065 private final CarPackageManagerService mCarPackageManagerService;
66 private final CarInputService mCarInputService;
keunyoungca515072015-07-10 12:21:47 -070067 private final CarSensorService mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -070068 private final CarInfoService mCarInfoService;
keunyoungd32f4e62015-09-21 11:33:06 -070069 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080070 private final CarProjectionService mCarProjectionService;
Steve Paik43c04a72016-07-08 19:12:09 -070071 private final CarCabinService mCarCabinService;
Steve Paik875616c2016-02-05 10:55:59 -080072 private final CarCameraService mCarCameraService;
Steve Paik66481982015-10-27 15:22:38 -070073 private final CarHvacService mCarHvacService;
Sanket Agarwal3cf096a2015-10-13 14:46:31 -070074 private final CarRadioService mCarRadioService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080075 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070076 private final AppFocusService mAppFocusService;
Yao Chen3a7976d2016-01-20 17:27:08 -080077 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080078 private final InstrumentClusterService mInstrumentClusterService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070079 private final SystemStateControllerService mSystemStateControllerService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -070080 private final CarVendorExtensionService mCarVendorExtensionService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080081 private final CarBluetoothService mCarBluetoothService;
Antonio Cortese4619c72017-02-02 07:53:27 -080082 @FutureFeature
Enrico Granata5c56d2a2017-02-07 15:38:12 -080083 private CarDiagnosticService mCarDiagnosticService;
84 @FutureFeature
Antonio Cortese4619c72017-02-02 07:53:27 -080085 private VmsSubscriberService mVmsSubscriberService;
Antonio Cortes6b3544c2017-02-06 16:54:58 -080086 @FutureFeature
87 private VmsPublisherService mVmsPublisherService;
keunyounga74b9ca2015-10-21 13:33:58 -070088
Pavel Maltsev0d07c762016-11-03 16:40:15 -070089 private final CarServiceBase[] mAllServices;
90
keunyoung1ab8e182015-09-24 09:25:22 -070091 /** Test only service. Populate it only when necessary. */
92 @GuardedBy("this")
93 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -070094
Pavel Maltsevec83b632017-01-05 15:10:55 -080095 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
96 CanBusErrorNotifier errorNotifier) {
keunyoungca515072015-07-10 12:21:47 -070097 mContext = serviceContext;
Pavel Maltsev0d07c762016-11-03 16:40:15 -070098 mHal = new VehicleHal(vehicle);
Keun-young Park4727da32016-05-31 10:00:51 -070099 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700100 mCarPowerManagementService = new CarPowerManagementService(
101 mHal.getPowerHal(), systemInterface);
102 mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal());
Keun-young Park4727da32016-05-31 10:00:51 -0700103 mCarPackageManagerService = new CarPackageManagerService(serviceContext, mCarSensorService,
104 mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700105 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800106 mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService);
Yao Chen3a7976d2016-01-20 17:27:08 -0800107 mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700108 mCarInfoService = new CarInfoService(serviceContext, mHal.getInfoHal());
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700109 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700110 mCarAudioService = new CarAudioService(serviceContext, mHal.getAudioHal(),
Pavel Maltsevec83b632017-01-05 15:10:55 -0800111 mCarInputService, errorNotifier);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700112 mCarCabinService = new CarCabinService(serviceContext, mHal.getCabinHal());
113 mCarHvacService = new CarHvacService(serviceContext, mHal.getHvacHal());
114 mCarRadioService = new CarRadioService(serviceContext, mHal.getRadioHal());
Steve Paik875616c2016-02-05 10:55:59 -0800115 mCarCameraService = new CarCameraService(serviceContext);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700116 mCarNightService = new CarNightService(serviceContext, mCarSensorService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700117 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700118 mAppFocusService, mCarInputService);
Keun-young Parkd73afae2016-04-08 20:03:32 -0700119 mSystemStateControllerService = new SystemStateControllerService(serviceContext,
Keun-young Park3cb89102016-05-05 13:16:03 -0700120 mCarPowerManagementService, mCarAudioService, this);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700121 mCarVendorExtensionService = new CarVendorExtensionService(serviceContext,
122 mHal.getVendorExtensionHal());
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800123 mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService);
Antonio Cortese4619c72017-02-02 07:53:27 -0800124 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
125 mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal());
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800126 mVmsPublisherService = new VmsPublisherService(serviceContext, mHal.getVmsHal());
Antonio Cortese4619c72017-02-02 07:53:27 -0800127 }
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800128 if (FeatureConfiguration.ENABLE_DIAGNOSTIC) {
129 mCarDiagnosticService = new CarDiagnosticService(serviceContext,
130 mHal.getDiagnosticHal());
131 }
keunyounga74b9ca2015-10-21 13:33:58 -0700132
keunyounga3b28d82015-08-25 13:05:15 -0700133 // Be careful with order. Service depending on other service should be inited later.
Antonio Cortese4619c72017-02-02 07:53:27 -0800134 List<CarServiceBase> allServices = new ArrayList<>(Arrays.asList(
Keun-young Park4727da32016-05-31 10:00:51 -0700135 mSystemActivityMonitoringService,
keunyoung4b0212c2015-10-29 17:11:57 -0700136 mCarPowerManagementService,
Keun-young Park4727da32016-05-31 10:00:51 -0700137 mCarSensorService,
Keun-young Park45fdcba2015-12-08 11:38:58 -0800138 mCarPackageManagerService,
Keun-young Parka28d7b22016-02-29 16:54:29 -0800139 mCarInputService,
140 mGarageModeService,
keunyounga3b28d82015-08-25 13:05:15 -0700141 mCarInfoService,
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700142 mAppFocusService,
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700143 mCarAudioService,
Steve Paik43c04a72016-07-08 19:12:09 -0700144 mCarCabinService,
Steve Paik66481982015-10-27 15:22:38 -0700145 mCarHvacService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800146 mCarRadioService,
147 mCarCameraService,
Joseph Pirozzo317343d2016-01-25 10:22:37 -0800148 mCarNightService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800149 mInstrumentClusterService,
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800150 mCarProjectionService,
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700151 mSystemStateControllerService,
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800152 mCarVendorExtensionService,
153 mCarBluetoothService
Antonio Cortese4619c72017-02-02 07:53:27 -0800154 ));
155 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
156 allServices.add(mVmsSubscriberService);
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800157 allServices.add(mVmsPublisherService);
Antonio Cortese4619c72017-02-02 07:53:27 -0800158 }
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800159 if (FeatureConfiguration.ENABLE_DIAGNOSTIC) {
160 allServices.add(mCarDiagnosticService);
161 }
Antonio Cortese4619c72017-02-02 07:53:27 -0800162 mAllServices = allServices.toArray(new CarServiceBase[0]);
keunyoungca515072015-07-10 12:21:47 -0700163 }
164
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700165 public void init() {
166 mHal.init();
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800167 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700168 service.init();
169 }
keunyoungca515072015-07-10 12:21:47 -0700170 }
171
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700172 public void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700173 // release done in opposite order from init
174 for (int i = mAllServices.length - 1; i >= 0; i--) {
175 mAllServices[i].release();
176 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700177 mHal.release();
keunyoung1ab8e182015-09-24 09:25:22 -0700178 }
179
Pavel Maltsevec83b632017-01-05 15:10:55 -0800180 public void vehicleHalReconnected(IVehicle vehicle) {
181 mHal.vehicleHalReconnected(vehicle);
182 for (CarServiceBase service : mAllServices) {
183 service.vehicleHalReconnected();
184 }
185 }
186
keunyoungca515072015-07-10 12:21:47 -0700187 @Override
keunyoungca515072015-07-10 12:21:47 -0700188 public IBinder getCarService(String serviceName) {
189 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800190 case Car.AUDIO_SERVICE:
191 return mCarAudioService;
keunyoungca515072015-07-10 12:21:47 -0700192 case Car.SENSOR_SERVICE:
193 return mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -0700194 case Car.INFO_SERVICE:
195 return mCarInfoService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700196 case Car.APP_FOCUS_SERVICE:
197 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800198 case Car.PACKAGE_SERVICE:
199 return mCarPackageManagerService;
Steve Paik43c04a72016-07-08 19:12:09 -0700200 case Car.CABIN_SERVICE:
201 assertCabinPermission(mContext);
202 return mCarCabinService;
Steve Paik875616c2016-02-05 10:55:59 -0800203 case Car.CAMERA_SERVICE:
204 assertCameraPermission(mContext);
205 return mCarCameraService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800206 case Car.DIAGNOSTIC_SERVICE:
Enrico Granata34010ed2017-02-16 11:51:47 -0800207 FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_DIAGNOSTIC);
208 if (FeatureConfiguration.ENABLE_DIAGNOSTIC) {
Enrico Granata3c7a6662017-02-23 18:07:59 -0800209 assertAnyDiagnosticPermission(mContext);
Enrico Granata34010ed2017-02-16 11:51:47 -0800210 return mCarDiagnosticService;
211 }
Keun-young Parke54ac272016-02-16 19:02:18 -0800212 case Car.HVAC_SERVICE:
Steve Paik66481982015-10-27 15:22:38 -0700213 assertHvacPermission(mContext);
214 return mCarHvacService;
Keun-young Parke54ac272016-02-16 19:02:18 -0800215 case Car.RADIO_SERVICE:
keunyoung6b197692015-11-16 13:54:38 -0800216 assertRadioPermission(mContext);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700217 return mCarRadioService;
Pavel Maltsev7a948e52016-02-02 23:30:14 -0800218 case Car.CAR_NAVIGATION_SERVICE:
Keun-young Parke31a8b22016-03-16 17:34:08 -0700219 assertNavigationManagerPermission(mContext);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700220 IInstrumentClusterNavigation navService =
221 mInstrumentClusterService.getNavigationService();
222 return navService == null ? null : navService.asBinder();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800223 case Car.PROJECTION_SERVICE:
224 assertProjectionPermission(mContext);
225 return mCarProjectionService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700226 case Car.VENDOR_EXTENSION_SERVICE:
227 assertVendorExtensionPermission(mContext);
228 return mCarVendorExtensionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800229 case Car.VMS_SUBSCRIBER_SERVICE:
230 FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE);
231 if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) {
232 assertVmsSubscriberPermission(mContext);
233 return mVmsSubscriberService;
234 }
Keun-young Parke54ac272016-02-16 19:02:18 -0800235 case Car.TEST_SERVICE: {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700236 assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
keunyoung1ab8e182015-09-24 09:25:22 -0700237 synchronized (this) {
238 if (mCarTestService == null) {
239 mCarTestService = new CarTestService(mContext, this);
240 }
241 return mCarTestService;
242 }
243 }
keunyoungca515072015-07-10 12:21:47 -0700244 default:
245 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
246 return null;
247 }
248 }
249
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800250 @Override
251 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700252 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800253 }
254
Keun-young Parka28d7b22016-02-29 16:54:29 -0800255 public CarServiceBase getCarInternalService(String serviceName) {
256 switch (serviceName) {
257 case INTERNAL_INPUT_SERVICE:
258 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700259 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
260 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800261 default:
262 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
263 serviceName);
264 return null;
265 }
266 }
267
keunyoung1ab8e182015-09-24 09:25:22 -0700268 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700269 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700270 }
271
Steve Paik43c04a72016-07-08 19:12:09 -0700272 public static void assertCabinPermission(Context context) {
273 assertPermission(context, Car.PERMISSION_CAR_CABIN);
274 }
275
Steve Paik875616c2016-02-05 10:55:59 -0800276 public static void assertCameraPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700277 assertPermission(context, Car.PERMISSION_CAR_CAMERA);
Steve Paik875616c2016-02-05 10:55:59 -0800278 }
279
Keun-young Parke31a8b22016-03-16 17:34:08 -0700280 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700281 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800282 }
283
Steve Paik66481982015-10-27 15:22:38 -0700284 public static void assertHvacPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700285 assertPermission(context, Car.PERMISSION_CAR_HVAC);
Steve Paik66481982015-10-27 15:22:38 -0700286 }
287
keunyoung6b197692015-11-16 13:54:38 -0800288 private static void assertRadioPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700289 assertPermission(context, Car.PERMISSION_CAR_RADIO);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700290 }
291
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800292 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700293 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
294 }
295
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700296 public static void assertVendorExtensionPermission(Context context) {
297 assertPermission(context, Car.PERMISSION_VENDOR_EXTENSION);
298 }
299
Antonio Cortese4619c72017-02-02 07:53:27 -0800300 @FutureFeature
Enrico Granata3c7a6662017-02-23 18:07:59 -0800301 public static void assertAnyDiagnosticPermission(Context context) {
302 assertAnyPermission(context,
303 Car.PERMISSION_CAR_DIAGNOSTIC_READ,
304 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
305 }
306
307 @FutureFeature
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800308 public static void assertVmsPublisherPermission(Context context) {
309 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
310 }
311
312 @FutureFeature
Antonio Cortese4619c72017-02-02 07:53:27 -0800313 public static void assertVmsSubscriberPermission(Context context) {
314 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
315 }
316
Steve Paik461ecc62016-06-08 15:28:32 -0700317 public static void assertPermission(Context context, String permission) {
318 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
319 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800320 }
321 }
322
Enrico Granata3c7a6662017-02-23 18:07:59 -0800323 public static void assertAnyPermission(Context context, String... permissions) {
324 for (String permission : permissions) {
325 if (context.checkCallingOrSelfPermission(permission) ==
326 PackageManager.PERMISSION_GRANTED) {
327 return;
328 }
329 }
330 throw new SecurityException("requires any of " + Arrays.toString(permissions));
331 }
332
keunyoungcc449f72015-08-12 10:46:27 -0700333 void dump(PrintWriter writer) {
Keun-young Parkbae6e252017-01-25 12:30:15 -0800334 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
335 //TODO dump all feature flags by reflection
keunyounga3b28d82015-08-25 13:05:15 -0700336 writer.println("*Dump all services*");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800337 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700338 service.dump(writer);
339 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700340 if (mCarTestService != null) {
341 mCarTestService.dump(writer);
keunyoung1ab8e182015-09-24 09:25:22 -0700342 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700343 writer.println("*Dump Vehicle HAL*");
344 mHal.dump(writer);
keunyoungcc449f72015-08-12 10:46:27 -0700345 }
Yao Chene33f07e2016-07-26 12:02:51 -0700346
347 void execShellCmd(String[] args, PrintWriter writer) {
348 new CarShellCommand().exec(args, writer);
349 }
350
351 private class CarShellCommand {
352 private static final String COMMAND_HELP = "-h";
353 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800354 private static final String COMMAND_INJECT_EVENT = "inject-event";
355
Yao Chene33f07e2016-07-26 12:02:51 -0700356 private static final String PARAM_DAY_MODE = "day";
357 private static final String PARAM_NIGHT_MODE = "night";
358 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800359 private static final String PARAM_ZONED_BOOLEAN = "zoned-boolean";
Yao Chene33f07e2016-07-26 12:02:51 -0700360
361 private void dumpHelp(PrintWriter pw) {
362 pw.println("Car service commands:");
363 pw.println("\t-h");
364 pw.println("\t Print this help text.");
365 pw.println("\tday-night-mode [day|night|sensor]");
366 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800367 pw.println("\tinject-event zoned-boolean propertyType zone [true|false]");
368 pw.println("\t Inject a Boolean HAL Event. ");
Yao Chene33f07e2016-07-26 12:02:51 -0700369 }
370
371 public void exec(String[] args, PrintWriter writer) {
372 String arg = args[0];
373 switch (arg) {
374 case COMMAND_HELP:
375 dumpHelp(writer);
376 break;
377 case COMMAND_DAY_NIGHT_MODE:
378 String value = args.length < 1 ? "" : args[1];
379 forceDayNightMode(value, writer);
380 break;
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800381 case COMMAND_INJECT_EVENT:
382 String eventType;
383 if(args.length > 1) {
384 eventType = args[1];
385 // Zoned boolean event
386 if(eventType.equalsIgnoreCase(PARAM_ZONED_BOOLEAN)) {
387 if(args.length < 5) {
388 writer.println("Incorrect number of arguments.");
389 dumpHelp(writer);
390 break;
391 }
392 inject_zoned_boolean_event(args[2], args[3], args[4], writer);
393 }
394 }
395 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700396 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 Periathiruvadiee28c002017-02-07 21:35:01 -0800434
435 /**
436 * Inject a fake boolean HAL event to help testing.
437 * Currently supporting Door Unlock/Lock
438 * @param property - Vehicle Property
439 * @param value - boolean value for the property
440 * @param writer - Printwriter
441 */
442 private void inject_zoned_boolean_event(String property, String zone, String value, PrintWriter writer) {
443 Log.d(CarLog.TAG_SERVICE, "Injecting Boolean event");
444 boolean event;
445 int propId;
446 int zoneId;
447 if (value.equalsIgnoreCase("true")) {
448 event = true;
449 } else {
450 event = false;
451 }
452 try {
453 propId = Integer.decode(property);
454 zoneId = Integer.decode(zone);
455 } catch (NumberFormatException e) {
456 writer.println("Invalid property Id or Zone Id. Prefix hex values with 0x");
457 return;
458 }
459 mHal.injectBooleanEvent(propId, zoneId, event);
460 }
461
Yao Chene33f07e2016-07-26 12:02:51 -0700462 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800463}