blob: a5137063d2aeb6d0819e2711e852c8de54a34d40 [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;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070027import android.os.Binder;
keunyoungca515072015-07-10 12:21:47 -070028import android.os.IBinder;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070029import android.os.Process;
Steve Paikc302c7c2017-08-04 14:01:58 -070030import android.os.Trace;
keunyoungca515072015-07-10 12:21:47 -070031import android.util.Log;
Steve Paikc302c7c2017-08-04 14:01:58 -070032import android.util.Slog;
Keun-young Park4a79a382017-08-10 18:19:14 -070033import android.util.TimingsTraceLog;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080034import com.android.car.cluster.InstrumentClusterService;
keunyoungcc449f72015-08-12 10:46:27 -070035import com.android.car.hal.VehicleHal;
Antonio Cortesc52d5f92017-02-06 08:47:38 -080036import com.android.car.internal.FeatureConfiguration;
37import com.android.car.internal.FeatureUtil;
Keun-young Park4aeb4bf2015-12-08 18:31:33 -080038import com.android.car.pm.CarPackageManagerService;
keunyoungca515072015-07-10 12:21:47 -070039import com.android.internal.annotations.GuardedBy;
Keun-young Parkaab47cd2017-06-05 11:04:50 -070040import com.android.internal.car.ICarServiceHelper;
keunyounga3b28d82015-08-25 13:05:15 -070041import java.io.PrintWriter;
Antonio Cortese4619c72017-02-02 07:53:27 -080042import java.util.ArrayList;
43import java.util.Arrays;
44import java.util.List;
keunyounga3b28d82015-08-25 13:05:15 -070045
keunyoungca515072015-07-10 12:21:47 -070046public class ICarImpl extends ICar.Stub {
keunyoungca515072015-07-10 12:21:47 -070047
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -080048 public static final String INTERNAL_INPUT_SERVICE = "internal_input";
Keun-young Park4727da32016-05-31 10:00:51 -070049 public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
50 "system_activity_monitoring";
Keun-young Parka28d7b22016-02-29 16:54:29 -080051
keunyoungca515072015-07-10 12:21:47 -070052 private final Context mContext;
Pavel Maltsevec83b632017-01-05 15:10:55 -080053 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070054
Keun-young Park4727da32016-05-31 10:00:51 -070055 private final SystemActivityMonitoringService mSystemActivityMonitoringService;
keunyoung4b0212c2015-10-29 17:11:57 -070056 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Parka28d7b22016-02-29 16:54:29 -080057 private final CarPackageManagerService mCarPackageManagerService;
58 private final CarInputService mCarInputService;
keunyoungca515072015-07-10 12:21:47 -070059 private final CarSensorService mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -070060 private final CarInfoService mCarInfoService;
keunyoungd32f4e62015-09-21 11:33:06 -070061 private final CarAudioService mCarAudioService;
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -080062 private final CarProjectionService mCarProjectionService;
Steve Paik43c04a72016-07-08 19:12:09 -070063 private final CarCabinService mCarCabinService;
Steve Paik66481982015-10-27 15:22:38 -070064 private final CarHvacService mCarHvacService;
Sanket Agarwal3cf096a2015-10-13 14:46:31 -070065 private final CarRadioService mCarRadioService;
Joseph Pirozzo317343d2016-01-25 10:22:37 -080066 private final CarNightService mCarNightService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -070067 private final AppFocusService mAppFocusService;
Yao Chen3a7976d2016-01-20 17:27:08 -080068 private final GarageModeService mGarageModeService;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -080069 private final InstrumentClusterService mInstrumentClusterService;
Keun-young Parkd73afae2016-04-08 20:03:32 -070070 private final SystemStateControllerService mSystemStateControllerService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -070071 private final CarVendorExtensionService mCarVendorExtensionService;
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -080072 private final CarBluetoothService mCarBluetoothService;
Ram Periathiruvadiacb60242017-04-13 16:19:09 -070073 private final PerUserCarServiceHelper mPerUserCarServiceHelper;
Enrico Granata5c56d2a2017-02-07 15:38:12 -080074 private CarDiagnosticService mCarDiagnosticService;
75 @FutureFeature
Antonio Cortese4619c72017-02-02 07:53:27 -080076 private VmsSubscriberService mVmsSubscriberService;
Antonio Cortes6b3544c2017-02-06 16:54:58 -080077 @FutureFeature
78 private VmsPublisherService mVmsPublisherService;
keunyounga74b9ca2015-10-21 13:33:58 -070079
Pavel Maltsev0d07c762016-11-03 16:40:15 -070080 private final CarServiceBase[] mAllServices;
81
Steve Paikc302c7c2017-08-04 14:01:58 -070082 private static final String TAG = "ICarImpl";
83 private static final String VHAL_TIMING_TAG = "VehicleHalTiming";
Keun-young Park4a79a382017-08-10 18:19:14 -070084 private static final TimingsTraceLog mBootTiming = new TimingsTraceLog(VHAL_TIMING_TAG,
Steve Paikc302c7c2017-08-04 14:01:58 -070085 Trace.TRACE_TAG_HAL);
86
keunyoung1ab8e182015-09-24 09:25:22 -070087 /** Test only service. Populate it only when necessary. */
88 @GuardedBy("this")
89 private CarTestService mCarTestService;
keunyoungca515072015-07-10 12:21:47 -070090
Keun-young Parkaab47cd2017-06-05 11:04:50 -070091 @GuardedBy("this")
92 private ICarServiceHelper mICarServiceHelper;
93
Pavel Maltsevec83b632017-01-05 15:10:55 -080094 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
95 CanBusErrorNotifier errorNotifier) {
keunyoungca515072015-07-10 12:21:47 -070096 mContext = serviceContext;
Pavel Maltsev0d07c762016-11-03 16:40:15 -070097 mHal = new VehicleHal(vehicle);
Keun-young Park4727da32016-05-31 10:00:51 -070098 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
Pavel Maltsev0d07c762016-11-03 16:40:15 -070099 mCarPowerManagementService = new CarPowerManagementService(
100 mHal.getPowerHal(), systemInterface);
101 mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal());
Keun-young Park4727da32016-05-31 10:00:51 -0700102 mCarPackageManagerService = new CarPackageManagerService(serviceContext, mCarSensorService,
103 mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700104 mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800105 mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService);
Yao Chen3a7976d2016-01-20 17:27:08 -0800106 mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700107 mCarInfoService = new CarInfoService(serviceContext, mHal.getInfoHal());
Vitalii Tomkiv8c7f2972016-07-11 15:42:04 -0700108 mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700109 mCarAudioService = new CarAudioService(serviceContext, mHal.getAudioHal(),
Pavel Maltsevec83b632017-01-05 15:10:55 -0800110 mCarInputService, errorNotifier);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700111 mCarCabinService = new CarCabinService(serviceContext, mHal.getCabinHal());
112 mCarHvacService = new CarHvacService(serviceContext, mHal.getHvacHal());
113 mCarRadioService = new CarRadioService(serviceContext, mHal.getRadioHal());
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700114 mCarNightService = new CarNightService(serviceContext, mCarSensorService);
Pavel Maltsev0477e292016-05-27 12:22:36 -0700115 mInstrumentClusterService = new InstrumentClusterService(serviceContext,
Pavel Maltsev03cf60c2016-06-27 15:11:51 -0700116 mAppFocusService, mCarInputService);
Keun-young Parkd73afae2016-04-08 20:03:32 -0700117 mSystemStateControllerService = new SystemStateControllerService(serviceContext,
Keun-young Park3cb89102016-05-05 13:16:03 -0700118 mCarPowerManagementService, mCarAudioService, this);
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700119 mCarVendorExtensionService = new CarVendorExtensionService(serviceContext,
120 mHal.getVendorExtensionHal());
Ram Periathiruvadiacb60242017-04-13 16:19:09 -0700121 mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext);
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800122 mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService,
Ram Periathiruvadiacb60242017-04-13 16:19:09 -0700123 mCarSensorService, mPerUserCarServiceHelper);
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700124 mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal());
125 mVmsPublisherService = new VmsPublisherService(serviceContext, mHal.getVmsHal());
Enrico Granatab3634e22017-05-05 18:02:31 -0700126 mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal());
keunyounga74b9ca2015-10-21 13:33:58 -0700127
keunyounga3b28d82015-08-25 13:05:15 -0700128 // Be careful with order. Service depending on other service should be inited later.
Antonio Cortese4619c72017-02-02 07:53:27 -0800129 List<CarServiceBase> allServices = new ArrayList<>(Arrays.asList(
Keun-young Park4727da32016-05-31 10:00:51 -0700130 mSystemActivityMonitoringService,
keunyoung4b0212c2015-10-29 17:11:57 -0700131 mCarPowerManagementService,
Keun-young Park4727da32016-05-31 10:00:51 -0700132 mCarSensorService,
Keun-young Park45fdcba2015-12-08 11:38:58 -0800133 mCarPackageManagerService,
Keun-young Parka28d7b22016-02-29 16:54:29 -0800134 mCarInputService,
135 mGarageModeService,
keunyounga3b28d82015-08-25 13:05:15 -0700136 mCarInfoService,
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700137 mAppFocusService,
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700138 mCarAudioService,
Steve Paik43c04a72016-07-08 19:12:09 -0700139 mCarCabinService,
Steve Paik66481982015-10-27 15:22:38 -0700140 mCarHvacService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800141 mCarRadioService,
Joseph Pirozzo317343d2016-01-25 10:22:37 -0800142 mCarNightService,
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800143 mInstrumentClusterService,
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800144 mCarProjectionService,
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700145 mSystemStateControllerService,
Ram Periathiruvadi7ed84182017-01-20 15:18:08 -0800146 mCarVendorExtensionService,
Enrico Granatab3634e22017-05-05 18:02:31 -0700147 mCarBluetoothService,
Ram Periathiruvadia048c0a2017-05-09 07:35:03 -0700148 mCarDiagnosticService,
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700149 mPerUserCarServiceHelper,
150 mVmsSubscriberService,
151 mVmsPublisherService
Antonio Cortese4619c72017-02-02 07:53:27 -0800152 ));
Antonio Cortese4619c72017-02-02 07:53:27 -0800153 mAllServices = allServices.toArray(new CarServiceBase[0]);
keunyoungca515072015-07-10 12:21:47 -0700154 }
155
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700156 void init() {
Steve Paikc302c7c2017-08-04 14:01:58 -0700157 traceBegin("VehicleHal.init");
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700158 mHal.init();
Steve Paikc302c7c2017-08-04 14:01:58 -0700159 traceEnd();
160 traceBegin("CarService.initAllServices");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800161 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700162 service.init();
163 }
Steve Paikc302c7c2017-08-04 14:01:58 -0700164 traceEnd();
keunyoungca515072015-07-10 12:21:47 -0700165 }
166
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700167 void release() {
keunyounga3b28d82015-08-25 13:05:15 -0700168 // release done in opposite order from init
169 for (int i = mAllServices.length - 1; i >= 0; i--) {
170 mAllServices[i].release();
171 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700172 mHal.release();
keunyoung1ab8e182015-09-24 09:25:22 -0700173 }
174
Pavel Maltsev8edd2552017-09-18 14:52:16 -0700175 void vehicleHalReconnected(IVehicle vehicle) {
Pavel Maltsevec83b632017-01-05 15:10:55 -0800176 mHal.vehicleHalReconnected(vehicle);
177 for (CarServiceBase service : mAllServices) {
178 service.vehicleHalReconnected();
179 }
180 }
181
keunyoungca515072015-07-10 12:21:47 -0700182 @Override
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700183 public void setCarServiceHelper(IBinder helper) {
184 int uid = Binder.getCallingUid();
185 if (uid != Process.SYSTEM_UID) {
186 throw new SecurityException("Only allowed from system");
187 }
188 synchronized (this) {
189 mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper);
190 }
191 }
192
193 @Override
keunyoungca515072015-07-10 12:21:47 -0700194 public IBinder getCarService(String serviceName) {
195 switch (serviceName) {
Keun-young Park5672e852016-02-09 19:53:48 -0800196 case Car.AUDIO_SERVICE:
197 return mCarAudioService;
keunyoungca515072015-07-10 12:21:47 -0700198 case Car.SENSOR_SERVICE:
199 return mCarSensorService;
keunyounga3b28d82015-08-25 13:05:15 -0700200 case Car.INFO_SERVICE:
201 return mCarInfoService;
Vitalii Tomkiv46371472016-05-23 16:55:22 -0700202 case Car.APP_FOCUS_SERVICE:
203 return mAppFocusService;
Keun-young Park45fdcba2015-12-08 11:38:58 -0800204 case Car.PACKAGE_SERVICE:
205 return mCarPackageManagerService;
Steve Paik43c04a72016-07-08 19:12:09 -0700206 case Car.CABIN_SERVICE:
207 assertCabinPermission(mContext);
208 return mCarCabinService;
Enrico Granata5c56d2a2017-02-07 15:38:12 -0800209 case Car.DIAGNOSTIC_SERVICE:
Enrico Granatab3634e22017-05-05 18:02:31 -0700210 assertAnyDiagnosticPermission(mContext);
211 return mCarDiagnosticService;
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();
Pavel Maltsev905968c2017-07-16 19:48:57 -0700223 case Car.CAR_INSTRUMENT_CLUSTER_SERVICE:
224 assertClusterManagerPermission(mContext);
225 return mInstrumentClusterService.getManagerService();
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800226 case Car.PROJECTION_SERVICE:
227 assertProjectionPermission(mContext);
228 return mCarProjectionService;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700229 case Car.VENDOR_EXTENSION_SERVICE:
230 assertVendorExtensionPermission(mContext);
231 return mCarVendorExtensionService;
Antonio Cortese4619c72017-02-02 07:53:27 -0800232 case Car.VMS_SUBSCRIBER_SERVICE:
Asaf Rosenfeld39e4f032017-09-16 11:33:50 -0700233 assertVmsSubscriberPermission(mContext);
234 return mVmsSubscriberService;
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 }
Ram Periathiruvadi76a84892017-07-27 18:10:35 -0700244 case Car.BLUETOOTH_SERVICE:
245 return mCarBluetoothService;
keunyoungca515072015-07-10 12:21:47 -0700246 default:
247 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
248 return null;
249 }
250 }
251
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800252 @Override
253 public int getCarConnectionType() {
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700254 return Car.CONNECTION_TYPE_EMBEDDED;
Pavel Maltsev1ecdd6c2016-03-02 16:33:44 -0800255 }
256
Keun-young Parka28d7b22016-02-29 16:54:29 -0800257 public CarServiceBase getCarInternalService(String serviceName) {
258 switch (serviceName) {
259 case INTERNAL_INPUT_SERVICE:
260 return mCarInputService;
Keun-young Park4727da32016-05-31 10:00:51 -0700261 case INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE:
262 return mSystemActivityMonitoringService;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800263 default:
264 Log.w(CarLog.TAG_SERVICE, "getCarInternalService for unknown service:" +
265 serviceName);
266 return null;
267 }
268 }
269
keunyoung1ab8e182015-09-24 09:25:22 -0700270 public static void assertVehicleHalMockPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700271 assertPermission(context, Car.PERMISSION_MOCK_VEHICLE_HAL);
keunyoung1ab8e182015-09-24 09:25:22 -0700272 }
273
Steve Paik43c04a72016-07-08 19:12:09 -0700274 public static void assertCabinPermission(Context context) {
275 assertPermission(context, Car.PERMISSION_CAR_CABIN);
276 }
277
Keun-young Parke31a8b22016-03-16 17:34:08 -0700278 public static void assertNavigationManagerPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700279 assertPermission(context, Car.PERMISSION_CAR_NAVIGATION_MANAGER);
Pavel Maltsevce4ffd92016-03-09 10:56:23 -0800280 }
281
Pavel Maltsev905968c2017-07-16 19:48:57 -0700282 public static void assertClusterManagerPermission(Context context) {
283 assertPermission(context, Car.PERMISSION_CAR_INSTRUMENT_CLUSTER_CONTROL);
284 }
285
Steve Paik66481982015-10-27 15:22:38 -0700286 public static void assertHvacPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700287 assertPermission(context, Car.PERMISSION_CAR_HVAC);
Steve Paik66481982015-10-27 15:22:38 -0700288 }
289
keunyoung6b197692015-11-16 13:54:38 -0800290 private static void assertRadioPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700291 assertPermission(context, Car.PERMISSION_CAR_RADIO);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700292 }
293
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800294 public static void assertProjectionPermission(Context context) {
Steve Paik461ecc62016-06-08 15:28:32 -0700295 assertPermission(context, Car.PERMISSION_CAR_PROJECTION);
296 }
297
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700298 public static void assertVendorExtensionPermission(Context context) {
299 assertPermission(context, Car.PERMISSION_VENDOR_EXTENSION);
300 }
301
Enrico Granata3c7a6662017-02-23 18:07:59 -0800302 public static void assertAnyDiagnosticPermission(Context context) {
303 assertAnyPermission(context,
Enrico Granataae25b922017-07-07 11:28:15 -0700304 Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL,
Enrico Granata3c7a6662017-02-23 18:07:59 -0800305 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
306 }
307
308 @FutureFeature
Antonio Cortes6b3544c2017-02-06 16:54:58 -0800309 public static void assertVmsPublisherPermission(Context context) {
310 assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
311 }
312
313 @FutureFeature
Antonio Cortese4619c72017-02-02 07:53:27 -0800314 public static void assertVmsSubscriberPermission(Context context) {
315 assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER);
316 }
317
Steve Paik461ecc62016-06-08 15:28:32 -0700318 public static void assertPermission(Context context, String permission) {
319 if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
320 throw new SecurityException("requires " + permission);
Vitalii Tomkiv6e5ee612016-03-09 14:57:32 -0800321 }
322 }
323
Enrico Granata3c7a6662017-02-23 18:07:59 -0800324 public static void assertAnyPermission(Context context, String... permissions) {
325 for (String permission : permissions) {
326 if (context.checkCallingOrSelfPermission(permission) ==
327 PackageManager.PERMISSION_GRANTED) {
328 return;
329 }
330 }
331 throw new SecurityException("requires any of " + Arrays.toString(permissions));
332 }
333
keunyoungcc449f72015-08-12 10:46:27 -0700334 void dump(PrintWriter writer) {
Keun-young Parkbae6e252017-01-25 12:30:15 -0800335 writer.println("*FutureConfig, DEFAULT:" + FeatureConfiguration.DEFAULT);
336 //TODO dump all feature flags by reflection
keunyounga3b28d82015-08-25 13:05:15 -0700337 writer.println("*Dump all services*");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800338 for (CarServiceBase service : mAllServices) {
keunyounga3b28d82015-08-25 13:05:15 -0700339 service.dump(writer);
340 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700341 if (mCarTestService != null) {
342 mCarTestService.dump(writer);
keunyoung1ab8e182015-09-24 09:25:22 -0700343 }
Pavel Maltsev0d07c762016-11-03 16:40:15 -0700344 writer.println("*Dump Vehicle HAL*");
345 mHal.dump(writer);
keunyoungcc449f72015-08-12 10:46:27 -0700346 }
Yao Chene33f07e2016-07-26 12:02:51 -0700347
348 void execShellCmd(String[] args, PrintWriter writer) {
349 new CarShellCommand().exec(args, writer);
350 }
351
Steve Paikc302c7c2017-08-04 14:01:58 -0700352 private static void traceBegin(String name) {
353 Slog.i(TAG, name);
354 mBootTiming.traceBegin(name);
355 }
356
357 private static void traceEnd() {
358 mBootTiming.traceEnd();
359 }
360
Yao Chene33f07e2016-07-26 12:02:51 -0700361 private class CarShellCommand {
362 private static final String COMMAND_HELP = "-h";
363 private static final String COMMAND_DAY_NIGHT_MODE = "day-night-mode";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800364 private static final String COMMAND_INJECT_EVENT = "inject-event";
365
Yao Chene33f07e2016-07-26 12:02:51 -0700366 private static final String PARAM_DAY_MODE = "day";
367 private static final String PARAM_NIGHT_MODE = "night";
368 private static final String PARAM_SENSOR_MODE = "sensor";
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800369 private static final String PARAM_ZONED_BOOLEAN = "zoned-boolean";
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800370 private static final String PARAM_GLOBAL_INT = "global-integer";
Yao Chene33f07e2016-07-26 12:02:51 -0700371
372 private void dumpHelp(PrintWriter pw) {
373 pw.println("Car service commands:");
374 pw.println("\t-h");
375 pw.println("\t Print this help text.");
376 pw.println("\tday-night-mode [day|night|sensor]");
377 pw.println("\t Force into day/night mode or restore to auto.");
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800378 pw.println("\tinject-event zoned-boolean propertyType zone [true|false]");
379 pw.println("\t Inject a Boolean HAL Event. ");
Yao Chene33f07e2016-07-26 12:02:51 -0700380 }
381
382 public void exec(String[] args, PrintWriter writer) {
383 String arg = args[0];
384 switch (arg) {
385 case COMMAND_HELP:
386 dumpHelp(writer);
387 break;
388 case COMMAND_DAY_NIGHT_MODE:
389 String value = args.length < 1 ? "" : args[1];
390 forceDayNightMode(value, writer);
391 break;
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800392 case COMMAND_INJECT_EVENT:
393 String eventType;
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800394 if (args.length > 1) {
395 eventType = args[1].toLowerCase();
396 switch (eventType) {
397 case PARAM_ZONED_BOOLEAN:
398 if (args.length < 5) {
399 writer.println("Incorrect number of arguments.");
400 dumpHelp(writer);
401 break;
402 }
403 inject_zoned_boolean_event(args[2], args[3], args[4], writer);
404 break;
405
406 case PARAM_GLOBAL_INT:
407 if (args.length < 4) {
408 writer.println("Incorrect number of Arguments");
409 dumpHelp(writer);
410 break;
411 }
412 inject_global_integer_event(args[2], args[3], writer);
413 break;
414
415 default:
416 writer.println("Unsupported event type");
417 dumpHelp(writer);
418 break;
419 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800420 }
421 break;
Yao Chene33f07e2016-07-26 12:02:51 -0700422 default:
423 writer.println("Unknown command.");
424 dumpHelp(writer);
425 }
426 }
427
428 private void forceDayNightMode(String arg, PrintWriter writer) {
429 int mode;
430 switch (arg) {
431 case PARAM_DAY_MODE:
432 mode = CarNightService.FORCED_DAY_MODE;
433 break;
434 case PARAM_NIGHT_MODE:
435 mode = CarNightService.FORCED_NIGHT_MODE;
436 break;
437 case PARAM_SENSOR_MODE:
438 mode = CarNightService.FORCED_SENSOR_MODE;
439 break;
440 default:
441 writer.println("Unknown value. Valid argument: " + PARAM_DAY_MODE + "|"
442 + PARAM_NIGHT_MODE + "|" + PARAM_SENSOR_MODE);
443 return;
444 }
445 int current = mCarNightService.forceDayNightMode(mode);
446 String currentMode = null;
447 switch (current) {
448 case UiModeManager.MODE_NIGHT_AUTO:
449 currentMode = PARAM_SENSOR_MODE;
450 break;
451 case UiModeManager.MODE_NIGHT_YES:
452 currentMode = PARAM_NIGHT_MODE;
453 break;
454 case UiModeManager.MODE_NIGHT_NO:
455 currentMode = PARAM_DAY_MODE;
456 break;
457 }
458 writer.println("DayNightMode changed to: " + currentMode);
459 }
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800460
461 /**
462 * Inject a fake boolean HAL event to help testing.
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800463 *
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800464 * @param property - Vehicle Property
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800465 * @param value - boolean value for the property
466 * @param writer - Printwriter
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800467 */
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800468 private void inject_zoned_boolean_event(String property, String zone, String value,
469 PrintWriter writer) {
Ram Periathiruvadiee28c002017-02-07 21:35:01 -0800470 Log.d(CarLog.TAG_SERVICE, "Injecting Boolean event");
471 boolean event;
472 int propId;
473 int zoneId;
474 if (value.equalsIgnoreCase("true")) {
475 event = true;
476 } else {
477 event = false;
478 }
479 try {
480 propId = Integer.decode(property);
481 zoneId = Integer.decode(zone);
482 } catch (NumberFormatException e) {
483 writer.println("Invalid property Id or Zone Id. Prefix hex values with 0x");
484 return;
485 }
486 mHal.injectBooleanEvent(propId, zoneId, event);
487 }
488
Ram Periathiruvadi49d5a5a2017-02-17 18:50:09 -0800489 /**
490 * Inject a fake Integer HAL event to help testing.
491 *
492 * @param property - Vehicle Property
493 * @param value - Integer value to inject
494 * @param writer - PrintWriter
495 */
496 private void inject_global_integer_event(String property, String value,
497 PrintWriter writer) {
498 Log.d(CarLog.TAG_SERVICE, "Injecting integer event");
499 int propId;
500 int eventValue;
501 try {
502 propId = Integer.decode(property);
503 eventValue = Integer.decode(value);
504 } catch (NumberFormatException e) {
505 writer.println("Invalid property Id or event value. Prefix hex values with 0x");
506 return;
507 }
508 mHal.injectIntegerEvent(propId, eventValue);
509 }
510
Yao Chene33f07e2016-07-26 12:02:51 -0700511 }
Keun-young Parkaab47cd2017-06-05 11:04:50 -0700512}