• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import static android.car.builtin.content.pm.PackageManagerHelper.PROPERTY_CAR_SERVICE_PACKAGE_NAME;
20 
21 import static com.android.car.CarServiceImpl.CAR_SERVICE_INIT_TIMING_MIN_DURATION_MS;
22 import static com.android.car.CarServiceImpl.CAR_SERVICE_INIT_TIMING_TAG;
23 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.DEPRECATED_CODE;
24 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.DUMP_INFO;
25 import static com.android.car.internal.SystemConstants.ICAR_SYSTEM_SERVER_CLIENT;
26 
27 import android.annotation.MainThread;
28 import android.annotation.NonNull;
29 import android.annotation.Nullable;
30 import android.app.ActivityManager;
31 import android.car.Car;
32 import android.car.CarFeatures;
33 import android.car.ICar;
34 import android.car.ICarResultReceiver;
35 import android.car.builtin.CarBuiltin;
36 import android.car.builtin.os.BinderHelper;
37 import android.car.builtin.os.BuildHelper;
38 import android.car.builtin.os.TraceHelper;
39 import android.car.builtin.os.UserManagerHelper;
40 import android.car.builtin.util.EventLogHelper;
41 import android.car.builtin.util.Slogf;
42 import android.car.user.CarUserManager;
43 import android.content.Context;
44 import android.content.om.OverlayInfo;
45 import android.content.om.OverlayManager;
46 import android.content.pm.PackageManager;
47 import android.content.res.Resources;
48 import android.frameworks.automotive.powerpolicy.internal.ICarPowerPolicySystemNotification;
49 import android.hardware.automotive.vehicle.VehicleProperty;
50 import android.os.Binder;
51 import android.os.Build;
52 import android.os.Bundle;
53 import android.os.IBinder;
54 import android.os.Parcel;
55 import android.os.ParcelFileDescriptor;
56 import android.os.Process;
57 import android.os.RemoteException;
58 import android.os.SystemProperties;
59 import android.os.UserHandle;
60 import android.os.UserManager;
61 
62 import com.android.car.admin.CarDevicePolicyService;
63 import com.android.car.am.CarActivityService;
64 import com.android.car.am.FixedActivityService;
65 import com.android.car.audio.CarAudioService;
66 import com.android.car.bluetooth.CarBluetoothService;
67 import com.android.car.cluster.ClusterHomeService;
68 import com.android.car.cluster.ClusterNavigationService;
69 import com.android.car.cluster.InstrumentClusterService;
70 import com.android.car.evs.CarEvsService;
71 import com.android.car.garagemode.GarageModeService;
72 import com.android.car.hal.HalPropValue;
73 import com.android.car.hal.VehicleHal;
74 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
75 import com.android.car.internal.ICarServiceHelper;
76 import com.android.car.internal.ICarSystemServerClient;
77 import com.android.car.internal.util.IndentingPrintWriter;
78 import com.android.car.occupantconnection.CarOccupantConnectionService;
79 import com.android.car.occupantconnection.CarRemoteDeviceService;
80 import com.android.car.oem.CarOemProxyService;
81 import com.android.car.os.CarPerformanceService;
82 import com.android.car.pm.CarPackageManagerService;
83 import com.android.car.power.CarPowerManagementService;
84 import com.android.car.remoteaccess.CarRemoteAccessService;
85 import com.android.car.stats.CarStatsService;
86 import com.android.car.systeminterface.SystemInterface;
87 import com.android.car.systemui.keyguard.ExperimentalCarKeyguardService;
88 import com.android.car.telemetry.CarTelemetryService;
89 import com.android.car.user.CarUserNoticeService;
90 import com.android.car.user.CarUserService;
91 import com.android.car.user.ExperimentalCarUserService;
92 import com.android.car.util.LimitedTimingsTraceLog;
93 import com.android.car.vms.VmsBrokerService;
94 import com.android.car.watchdog.CarWatchdogService;
95 import com.android.internal.annotations.GuardedBy;
96 import com.android.internal.annotations.VisibleForTesting;
97 
98 import java.io.File;
99 import java.io.FileDescriptor;
100 import java.io.PrintWriter;
101 import java.util.ArrayList;
102 import java.util.Arrays;
103 import java.util.List;
104 import java.util.concurrent.Callable;
105 
106 public class ICarImpl extends ICar.Stub {
107 
108     public static final String INTERNAL_INPUT_SERVICE = "internal_input";
109     public static final String INTERNAL_SYSTEM_ACTIVITY_MONITORING_SERVICE =
110             "system_activity_monitoring";
111 
112     @VisibleForTesting
113     static final String TAG = CarLog.tagFor(ICarImpl.class);
114 
115     private static final int INITIAL_VHAL_GET_RETRY = 2;
116 
117     private final Context mContext;
118     private final Context mCarServiceBuiltinPackageContext;
119     private final VehicleHal mHal;
120 
121     private final CarServiceHelperWrapper mCarServiceHelperWrapper;
122 
123     private final CarFeatureController mFeatureController;
124 
125     private final SystemInterface mSystemInterface;
126 
127     private final CarOemProxyService mCarOemService;
128     private final SystemActivityMonitoringService mSystemActivityMonitoringService;
129     private final CarPowerManagementService mCarPowerManagementService;
130     private final CarPackageManagerService mCarPackageManagerService;
131     private final CarInputService mCarInputService;
132     private final CarDrivingStateService mCarDrivingStateService;
133     private final CarUxRestrictionsManagerService mCarUXRestrictionsService;
134     private final OccupantAwarenessService mOccupantAwarenessService;
135     private final CarAudioService mCarAudioService;
136     private final CarProjectionService mCarProjectionService;
137     private final CarPropertyService mCarPropertyService;
138     private final CarNightService mCarNightService;
139     private final AppFocusService mAppFocusService;
140     private final FixedActivityService mFixedActivityService;
141     private final GarageModeService mGarageModeService;
142     private final ClusterNavigationService mClusterNavigationService;
143     private final InstrumentClusterService mInstrumentClusterService;
144     private final CarLocationService mCarLocationService;
145     private final CarBluetoothService mCarBluetoothService;
146     private final CarPerUserServiceHelper mCarPerUserServiceHelper;
147     private final CarDiagnosticService mCarDiagnosticService;
148     private final CarStorageMonitoringService mCarStorageMonitoringService;
149     private final CarMediaService mCarMediaService;
150     private final CarUserService mCarUserService;
151     @Nullable
152     private final ExperimentalCarUserService mExperimentalCarUserService;
153     @Nullable
154     private final ExperimentalCarKeyguardService mExperimentalCarKeyguardService;
155     private final CarOccupantZoneService mCarOccupantZoneService;
156     private final CarUserNoticeService mCarUserNoticeService;
157     private final VmsBrokerService mVmsBrokerService;
158     private final CarBugreportManagerService mCarBugreportManagerService;
159     private final CarStatsService mCarStatsService;
160     private final CarExperimentalFeatureServiceController mCarExperimentalFeatureServiceController;
161     private final CarWatchdogService mCarWatchdogService;
162     private final CarPerformanceService mCarPerformanceService;
163     private final CarDevicePolicyService mCarDevicePolicyService;
164     private final ClusterHomeService mClusterHomeService;
165     private final CarEvsService mCarEvsService;
166     private final CarTelemetryService mCarTelemetryService;
167     private final CarActivityService mCarActivityService;
168     private final CarOccupantConnectionService mCarOccupantConnectionService;
169     private final CarRemoteDeviceService mCarRemoteDeviceService;
170     // Only modified at setCarRemoteAccessService for testing.
171     @Nullable
172     private CarRemoteAccessService mCarRemoteAccessService;
173 
174     private final CarSystemService[] mAllServices;
175 
176     private static final boolean DBG = true; // TODO(b/154033860): STOPSHIP if true
177 
178     private final Object mLock = new Object();
179 
180     // This flag indicates whether priorityInit() should be called in the constructor or
181     // will be deferred to CarImpl.init(). With the new boot user code flow, the boot user is set
182     // in initialUserSetter as early as possible. The earliest it can be done is in the ICarImpl
183     // constructor. In priorityInit() HAL and UserService are initialized which sets boot user.
184     private final boolean mDoPriorityInitInConstruction;
185 
186     /** Test only service. Populate it only when necessary. */
187     @GuardedBy("mLock")
188     private CarTestService mCarTestService;
189 
190     private final String mVehicleInterfaceName;
191 
192     private final ICarSystemServerClientImpl mICarSystemServerClientImpl;
193 
194     private final BinderHelper.ShellCommandListener mCmdListener =
195             (FileDescriptor in, FileDescriptor out, FileDescriptor err, String[] args) ->
196                     newCarShellCommand().exec(ICarImpl.this, in, out, err, args);
197 
ICarImpl(Context serviceContext, Context builtinContext, VehicleStub vehicle, SystemInterface systemInterface, String vehicleInterfaceName)198     public ICarImpl(Context serviceContext, Context builtinContext, VehicleStub vehicle,
199             SystemInterface systemInterface, String vehicleInterfaceName) {
200         this(serviceContext, builtinContext, vehicle, systemInterface, vehicleInterfaceName,
201                 /* carUserService= */ null, /* carWatchdogService= */ null,
202                 /* carPerformanceService= */ null, /* garageModeService= */ null,
203                 /* powerPolicyDaemon= */ null, /* carTelemetryService= */ null,
204                 /* carRemoteAccessService= */ null, /* doPriorityInitInConstruction= */ true);
205     }
206 
207     @VisibleForTesting
ICarImpl(Context serviceContext, @Nullable Context builtinContext, VehicleStub vehicle, SystemInterface systemInterface, String vehicleInterfaceName, @Nullable CarUserService carUserService, @Nullable CarWatchdogService carWatchdogService, @Nullable CarPerformanceService carPerformanceService, @Nullable GarageModeService garageModeService, @Nullable ICarPowerPolicySystemNotification powerPolicyDaemon, @Nullable CarTelemetryService carTelemetryService, @Nullable CarRemoteAccessService carRemoteAccessService, boolean doPriorityInitInConstruction)208     ICarImpl(Context serviceContext, @Nullable Context builtinContext, VehicleStub vehicle,
209             SystemInterface systemInterface, String vehicleInterfaceName,
210             @Nullable CarUserService carUserService,
211             @Nullable CarWatchdogService carWatchdogService,
212             @Nullable CarPerformanceService carPerformanceService,
213             @Nullable GarageModeService garageModeService,
214             @Nullable ICarPowerPolicySystemNotification powerPolicyDaemon,
215             @Nullable CarTelemetryService carTelemetryService,
216             @Nullable CarRemoteAccessService carRemoteAccessService,
217             boolean doPriorityInitInConstruction) {
218         LimitedTimingsTraceLog t = new LimitedTimingsTraceLog(
219                 CAR_SERVICE_INIT_TIMING_TAG, TraceHelper.TRACE_TAG_CAR_SERVICE,
220                 CAR_SERVICE_INIT_TIMING_MIN_DURATION_MS);
221         t.traceBegin("ICarImpl.constructor");
222 
223         mDoPriorityInitInConstruction = doPriorityInitInConstruction;
224 
225         mContext = serviceContext;
226         if (builtinContext == null) {
227             mCarServiceBuiltinPackageContext = serviceContext;
228         } else {
229             mCarServiceBuiltinPackageContext = builtinContext;
230         }
231 
232         mCarServiceHelperWrapper = CarServiceHelperWrapper.create();
233 
234         // Currently there are ~36 services, hence using 40 as the initial capacity.
235         List<CarSystemService> allServices = new ArrayList<>(40);
236         mCarOemService = constructWithTrace(t, CarOemProxyService.class,
237                 () -> new CarOemProxyService(serviceContext), allServices);
238 
239         mSystemInterface = systemInterface;
240         CarLocalServices.addService(SystemInterface.class, mSystemInterface);
241 
242         mHal = constructWithTrace(t, VehicleHal.class,
243                 () -> new VehicleHal(serviceContext, vehicle), allServices);
244 
245         HalPropValue disabledOptionalFeatureValue = mHal.getIfSupportedOrFailForEarlyStage(
246                 VehicleProperty.DISABLED_OPTIONAL_FEATURES, INITIAL_VHAL_GET_RETRY);
247 
248         String[] disabledFeaturesFromVhal = null;
249         if (disabledOptionalFeatureValue != null) {
250             String disabledFeatures = disabledOptionalFeatureValue.getStringValue();
251             if (disabledFeatures != null && !disabledFeatures.isEmpty()) {
252                 disabledFeaturesFromVhal = disabledFeatures.split(",");
253             }
254         }
255         if (disabledFeaturesFromVhal == null) {
256             disabledFeaturesFromVhal = new String[0];
257         }
258         Resources res = mContext.getResources();
259         String[] defaultEnabledFeatures = res.getStringArray(
260                 R.array.config_allowed_optional_car_features);
261         final String[] disabledFromVhal = disabledFeaturesFromVhal;
262         mFeatureController = constructWithTrace(t, CarFeatureController.class,
263                 () -> new CarFeatureController(serviceContext, defaultEnabledFeatures,
264                         disabledFromVhal, mSystemInterface.getSystemCarDir()), allServices);
265         mVehicleInterfaceName = vehicleInterfaceName;
266         mCarPropertyService = constructWithTrace(
267                 t, CarPropertyService.class,
268                 () -> new CarPropertyService(serviceContext, mHal.getPropertyHal()), allServices);
269         mCarDrivingStateService = constructWithTrace(
270                 t, CarDrivingStateService.class,
271                 () -> new CarDrivingStateService(serviceContext, mCarPropertyService), allServices);
272         mCarOccupantZoneService = constructWithTrace(t, CarOccupantZoneService.class,
273                 () -> new CarOccupantZoneService(serviceContext), allServices);
274         mCarUXRestrictionsService = constructWithTrace(t, CarUxRestrictionsManagerService.class,
275                 () -> new CarUxRestrictionsManagerService(serviceContext, mCarDrivingStateService,
276                         mCarPropertyService, mCarOccupantZoneService), allServices);
277         mCarActivityService = constructWithTrace(t, CarActivityService.class,
278                 () -> new CarActivityService(serviceContext), allServices);
279         mCarPackageManagerService = constructWithTrace(t, CarPackageManagerService.class,
280                 () -> new CarPackageManagerService(serviceContext, mCarUXRestrictionsService,
281                         mCarActivityService, mCarOccupantZoneService), allServices);
282         UserManager userManager = serviceContext.getSystemService(UserManager.class);
283         if (carUserService != null) {
284             mCarUserService = carUserService;
285             CarLocalServices.addService(CarUserService.class, carUserService);
286             allServices.add(mCarUserService);
287         } else {
288             int maxRunningUsers = UserManagerHelper.getMaxRunningUsers(serviceContext);
289             mCarUserService = constructWithTrace(t, CarUserService.class,
290                     () -> new CarUserService(serviceContext, mHal.getUserHal(), userManager,
291                             maxRunningUsers, mCarUXRestrictionsService, mCarPackageManagerService,
292                             mCarOccupantZoneService),
293                     allServices);
294         }
295         if (mDoPriorityInitInConstruction) {
296             Slogf.i(TAG, "VHAL Priority Init Enabled");
297             Slogf.i(TAG, "Car User Service Priority Init Enabled");
298             priorityInit();
299         }
300 
301         if (mFeatureController.isFeatureEnabled(Car.EXPERIMENTAL_CAR_USER_SERVICE)) {
302             mExperimentalCarUserService = constructWithTrace(t, ExperimentalCarUserService.class,
303                     () -> new ExperimentalCarUserService(serviceContext, mCarUserService,
304                             userManager), allServices);
305         } else {
306             mExperimentalCarUserService = null;
307         }
308         if (mFeatureController.isFeatureEnabled(Car.EXPERIMENTAL_CAR_KEYGUARD_SERVICE)) {
309             mExperimentalCarKeyguardService = constructWithTrace(t,
310                         ExperimentalCarKeyguardService.class,
311                     () -> new ExperimentalCarKeyguardService(serviceContext, mCarUserService,
312                             mCarOccupantZoneService), allServices);
313         } else {
314             mExperimentalCarKeyguardService = null;
315         }
316         mSystemActivityMonitoringService = constructWithTrace(
317                 t, SystemActivityMonitoringService.class,
318                 () -> new SystemActivityMonitoringService(serviceContext), allServices);
319         mCarPowerManagementService = constructWithTrace(
320                 t, CarPowerManagementService.class,
321                 () -> new CarPowerManagementService(mContext, mHal.getPowerHal(),
322                         systemInterface, mCarUserService, powerPolicyDaemon), allServices);
323         if (mFeatureController.isFeatureEnabled(CarFeatures.FEATURE_CAR_USER_NOTICE_SERVICE)) {
324             mCarUserNoticeService = constructWithTrace(
325                     t, CarUserNoticeService.class, () -> new CarUserNoticeService(serviceContext),
326                     allServices);
327         } else {
328             mCarUserNoticeService = null;
329         }
330         if (mFeatureController.isFeatureEnabled(Car.OCCUPANT_AWARENESS_SERVICE)) {
331             mOccupantAwarenessService = constructWithTrace(t, OccupantAwarenessService.class,
332                     () -> new OccupantAwarenessService(serviceContext), allServices);
333         } else {
334             mOccupantAwarenessService = null;
335         }
336         mCarPerUserServiceHelper = constructWithTrace(
337                 t, CarPerUserServiceHelper.class,
338                 () -> new CarPerUserServiceHelper(serviceContext, mCarUserService), allServices);
339         mCarBluetoothService = constructWithTrace(t, CarBluetoothService.class,
340                 () -> new CarBluetoothService(serviceContext, mCarPerUserServiceHelper),
341                 allServices);
342         mCarInputService = constructWithTrace(t, CarInputService.class,
343                 () -> new CarInputService(serviceContext, mHal.getInputHal(), mCarUserService,
344                         mCarOccupantZoneService, mCarBluetoothService, mCarPowerManagementService,
345                         mSystemInterface, userManager), allServices);
346         mCarProjectionService = constructWithTrace(t, CarProjectionService.class,
347                 () -> new CarProjectionService(serviceContext, null /* handler */, mCarInputService,
348                         mCarBluetoothService), allServices);
349         if (garageModeService == null) {
350             mGarageModeService = constructWithTrace(t, GarageModeService.class,
351                     () -> new GarageModeService(serviceContext), allServices);
352         } else {
353             mGarageModeService = garageModeService;
354             allServices.add(mGarageModeService);
355         }
356         mAppFocusService = constructWithTrace(t, AppFocusService.class,
357                 () -> new AppFocusService(serviceContext, mSystemActivityMonitoringService),
358                 allServices);
359         mCarAudioService = constructWithTrace(t, CarAudioService.class,
360                 () -> new CarAudioService(serviceContext), allServices);
361         mCarNightService = constructWithTrace(t, CarNightService.class,
362                 () -> new CarNightService(serviceContext, mCarPropertyService), allServices);
363         mFixedActivityService = constructWithTrace(t, FixedActivityService.class,
364                 () -> new FixedActivityService(serviceContext, mCarActivityService), allServices);
365         mClusterNavigationService = constructWithTrace(
366                 t, ClusterNavigationService.class,
367                 () -> new ClusterNavigationService(serviceContext, mAppFocusService), allServices);
368         if (mFeatureController.isFeatureEnabled(Car.CAR_INSTRUMENT_CLUSTER_SERVICE)) {
369             mInstrumentClusterService = constructWithTrace(t, InstrumentClusterService.class,
370                     () -> new InstrumentClusterService(serviceContext,
371                             mClusterNavigationService, mCarInputService), allServices);
372         } else {
373             mInstrumentClusterService = null;
374         }
375 
376         mCarStatsService = constructWithTrace(t, CarStatsService.class,
377                 () -> new CarStatsService(serviceContext), allServices);
378 
379         if (mFeatureController.isFeatureEnabled(Car.VEHICLE_MAP_SERVICE)) {
380             mVmsBrokerService = constructWithTrace(t, VmsBrokerService.class,
381                     () -> new VmsBrokerService(mContext, mCarStatsService), allServices);
382         } else {
383             mVmsBrokerService = null;
384         }
385         if (mFeatureController.isFeatureEnabled(Car.DIAGNOSTIC_SERVICE)) {
386             mCarDiagnosticService = constructWithTrace(t, CarDiagnosticService.class,
387                     () -> new CarDiagnosticService(serviceContext,
388                             mHal.getDiagnosticHal()), allServices);
389         } else {
390             mCarDiagnosticService = null;
391         }
392         if (mFeatureController.isFeatureEnabled(Car.STORAGE_MONITORING_SERVICE)) {
393             mCarStorageMonitoringService = constructWithTrace(
394                     t, CarStorageMonitoringService.class,
395                     () -> new CarStorageMonitoringService(serviceContext,
396                             systemInterface), allServices);
397         } else {
398             mCarStorageMonitoringService = null;
399         }
400         mCarLocationService = constructWithTrace(t, CarLocationService.class,
401                 () -> new CarLocationService(serviceContext), allServices);
402         mCarMediaService = constructWithTrace(t, CarMediaService.class,
403                 () -> new CarMediaService(serviceContext, mCarOccupantZoneService, mCarUserService),
404                 allServices);
405         mCarBugreportManagerService = constructWithTrace(t, CarBugreportManagerService.class,
406                 () -> new CarBugreportManagerService(serviceContext), allServices);
407         if (carWatchdogService == null) {
408             mCarWatchdogService = constructWithTrace(t, CarWatchdogService.class,
409                     () -> new CarWatchdogService(serviceContext, mCarServiceBuiltinPackageContext),
410                     allServices);
411         } else {
412             mCarWatchdogService = carWatchdogService;
413             allServices.add(mCarWatchdogService);
414             CarLocalServices.addService(CarWatchdogService.class, mCarWatchdogService);
415         }
416         if (carPerformanceService == null) {
417             mCarPerformanceService = constructWithTrace(t, CarPerformanceService.class,
418                     () -> new CarPerformanceService(serviceContext), allServices);
419         } else {
420             mCarPerformanceService = carPerformanceService;
421             allServices.add(mCarPerformanceService);
422             CarLocalServices.addService(CarPerformanceService.class, mCarPerformanceService);
423         }
424         mCarDevicePolicyService = constructWithTrace(
425                 t, CarDevicePolicyService.class, () -> new CarDevicePolicyService(mContext,
426                         mCarServiceBuiltinPackageContext, mCarUserService), allServices);
427         if (mFeatureController.isFeatureEnabled(Car.CLUSTER_HOME_SERVICE)) {
428             if (!mFeatureController.isFeatureEnabled(Car.CAR_INSTRUMENT_CLUSTER_SERVICE)) {
429                 mClusterHomeService = constructWithTrace(
430                         t, ClusterHomeService.class,
431                         () -> new ClusterHomeService(serviceContext, mHal.getClusterHal(),
432                                 mClusterNavigationService, mCarOccupantZoneService,
433                                 mFixedActivityService), allServices);
434             } else {
435                 Slogf.w(TAG, "Can't init ClusterHomeService, since Old cluster service is running");
436                 mClusterHomeService = null;
437             }
438         } else {
439             mClusterHomeService = null;
440         }
441 
442         if (mFeatureController.isFeatureEnabled(Car.CAR_EVS_SERVICE)) {
443             mCarEvsService = constructWithTrace(t, CarEvsService.class,
444                     () -> new CarEvsService(serviceContext, mCarServiceBuiltinPackageContext,
445                             mHal.getEvsHal(), mCarPropertyService), allServices);
446         } else {
447             mCarEvsService = null;
448         }
449 
450         if (mFeatureController.isFeatureEnabled(Car.CAR_TELEMETRY_SERVICE)) {
451             if (carTelemetryService == null) {
452                 mCarTelemetryService = constructWithTrace(t, CarTelemetryService.class,
453                         () -> new CarTelemetryService(
454                                 serviceContext, mCarPowerManagementService, mCarPropertyService),
455                         allServices);
456             } else {
457                 mCarTelemetryService = carTelemetryService;
458                 allServices.add(mCarTelemetryService);
459             }
460         } else {
461             mCarTelemetryService = null;
462         }
463 
464         if (mFeatureController.isFeatureEnabled((Car.CAR_REMOTE_ACCESS_SERVICE))) {
465             if (carRemoteAccessService == null) {
466                 mCarRemoteAccessService = constructWithTrace(t, CarRemoteAccessService.class,
467                         () -> new CarRemoteAccessService(
468                                 serviceContext, systemInterface, mHal.getPowerHal()), allServices);
469             } else {
470                 mCarRemoteAccessService = carRemoteAccessService;
471                 mCarRemoteAccessService.setPowerHal(mHal.getPowerHal());
472                 allServices.add(mCarRemoteAccessService);
473             }
474         } else {
475             mCarRemoteAccessService = null;
476         }
477 
478         // Always put mCarExperimentalFeatureServiceController in last.
479         if (!BuildHelper.isUserBuild()) {
480             mCarExperimentalFeatureServiceController = constructWithTrace(
481                     t, CarExperimentalFeatureServiceController.class,
482                     () -> new CarExperimentalFeatureServiceController(serviceContext),
483                     allServices);
484         } else {
485             mCarExperimentalFeatureServiceController = null;
486         }
487 
488         if (mFeatureController.isFeatureEnabled(Car.CAR_OCCUPANT_CONNECTION_SERVICE)
489                 || mFeatureController.isFeatureEnabled(Car.CAR_REMOTE_DEVICE_SERVICE)) {
490             mCarRemoteDeviceService = constructWithTrace(
491                     t, CarRemoteDeviceService.class,
492                     () -> new CarRemoteDeviceService(serviceContext, mCarOccupantZoneService,
493                             mCarPowerManagementService, mSystemActivityMonitoringService),
494                     allServices);
495             mCarOccupantConnectionService = constructWithTrace(
496                     t, CarOccupantConnectionService.class,
497                     () -> new CarOccupantConnectionService(serviceContext, mCarOccupantZoneService,
498                             mCarRemoteDeviceService),
499                     allServices);
500 
501         } else {
502             mCarOccupantConnectionService = null;
503             mCarRemoteDeviceService = null;
504         }
505 
506         mAllServices = allServices.toArray(new CarSystemService[allServices.size()]);
507 
508         mICarSystemServerClientImpl = new ICarSystemServerClientImpl();
509 
510         t.traceEnd(); // "ICarImpl.constructor"
511     }
512 
513     @MainThread
init()514     void init() {
515         LimitedTimingsTraceLog t = new LimitedTimingsTraceLog(CAR_SERVICE_INIT_TIMING_TAG,
516                 TraceHelper.TRACE_TAG_CAR_SERVICE, CAR_SERVICE_INIT_TIMING_MIN_DURATION_MS);
517 
518         t.traceBegin("ICarImpl.init");
519         if (!mDoPriorityInitInConstruction) {
520             priorityInit();
521         }
522 
523         t.traceBegin("CarService.initAllServices");
524         for (CarSystemService service : mAllServices) {
525             t.traceBegin(service.getClass().getSimpleName());
526             service.init();
527             t.traceEnd();
528         }
529         t.traceBegin("CarOemService.initComplete");
530         mCarOemService.onInitComplete();
531         t.traceEnd();
532         t.traceEnd(); // "CarService.initAllServices"
533         t.traceEnd(); // "ICarImpl.init"
534     }
535 
release()536     void release() {
537         // release done in opposite order from init
538         for (int i = mAllServices.length - 1; i >= 0; i--) {
539             mAllServices[i].release();
540         }
541     }
542 
543     @Override
setSystemServerConnections(ICarServiceHelper carServiceHelper, ICarResultReceiver resultReceiver)544     public void setSystemServerConnections(ICarServiceHelper carServiceHelper,
545             ICarResultReceiver resultReceiver) {
546         Bundle bundle;
547         try {
548             EventLogHelper.writeCarServiceSetCarServiceHelper(Binder.getCallingPid());
549             assertCallingFromSystemProcess();
550 
551             mCarServiceHelperWrapper.setCarServiceHelper(carServiceHelper);
552 
553             bundle = new Bundle();
554             bundle.putBinder(ICAR_SYSTEM_SERVER_CLIENT, mICarSystemServerClientImpl.asBinder());
555         } catch (Exception e) {
556             // send back a null response
557             Slogf.w(TAG, "Exception in setSystemServerConnections", e);
558             bundle = null;
559         }
560 
561         try {
562             resultReceiver.send(/* unused */ 0, bundle);
563         } catch (RemoteException e) {
564             Slogf.w(TAG, "RemoteException from CarServiceHelperService", e);
565         }
566     }
567 
568     @Override
isFeatureEnabled(String featureName)569     public boolean isFeatureEnabled(String featureName) {
570         return mFeatureController.isFeatureEnabled(featureName);
571     }
572 
573     @Override
enableFeature(String featureName)574     public int enableFeature(String featureName) {
575         // permission check inside the controller
576         return mFeatureController.enableFeature(featureName);
577     }
578 
579     @Override
disableFeature(String featureName)580     public int disableFeature(String featureName) {
581         // permission check inside the controller
582         return mFeatureController.disableFeature(featureName);
583     }
584 
585     @Override
getAllEnabledFeatures()586     public List<String> getAllEnabledFeatures() {
587         // permission check inside the controller
588         return mFeatureController.getAllEnabledFeatures();
589     }
590 
591     @Override
getAllPendingDisabledFeatures()592     public List<String> getAllPendingDisabledFeatures() {
593         // permission check inside the controller
594         return mFeatureController.getAllPendingDisabledFeatures();
595     }
596 
597     @Override
getAllPendingEnabledFeatures()598     public List<String> getAllPendingEnabledFeatures() {
599         // permission check inside the controller
600         return mFeatureController.getAllPendingEnabledFeatures();
601     }
602 
603     @Override
604     @Nullable
getCarManagerClassForFeature(String featureName)605     public String getCarManagerClassForFeature(String featureName) {
606         if (mCarExperimentalFeatureServiceController == null) {
607             return null;
608         }
609         return mCarExperimentalFeatureServiceController.getCarManagerClassForFeature(featureName);
610     }
611 
assertCallingFromSystemProcess()612     static void assertCallingFromSystemProcess() {
613         int uid = Binder.getCallingUid();
614         if (uid != Process.SYSTEM_UID) {
615             throw new SecurityException("Only allowed from system");
616         }
617     }
618 
619     @Override
620     @Nullable
getCarService(String serviceName)621     public IBinder getCarService(String serviceName) {
622         if (!mFeatureController.isFeatureEnabled(serviceName)) {
623             Slogf.w(CarLog.TAG_SERVICE, "getCarService for disabled service:" + serviceName);
624             return null;
625         }
626         switch (serviceName) {
627             case Car.AUDIO_SERVICE:
628                 return mCarAudioService;
629             case Car.APP_FOCUS_SERVICE:
630                 return mAppFocusService;
631             case Car.PACKAGE_SERVICE:
632                 return mCarPackageManagerService;
633             case Car.DIAGNOSTIC_SERVICE:
634                 CarServiceUtils.assertAnyDiagnosticPermission(mContext);
635                 return mCarDiagnosticService;
636             case Car.POWER_SERVICE:
637                 return mCarPowerManagementService;
638             case Car.CABIN_SERVICE:
639             case Car.HVAC_SERVICE:
640             case Car.INFO_SERVICE:
641             case Car.PROPERTY_SERVICE:
642             case Car.SENSOR_SERVICE:
643             case Car.VENDOR_EXTENSION_SERVICE:
644                 return mCarPropertyService;
645             case Car.CAR_NAVIGATION_SERVICE:
646                 CarServiceUtils.assertNavigationManagerPermission(mContext);
647                 return mClusterNavigationService;
648             case Car.CAR_INSTRUMENT_CLUSTER_SERVICE:
649                 CarServiceUtils.assertClusterManagerPermission(mContext);
650                 return mInstrumentClusterService.getManagerService();
651             case Car.PROJECTION_SERVICE:
652                 return mCarProjectionService;
653             case Car.VEHICLE_MAP_SERVICE:
654                 CarServiceUtils.assertAnyVmsPermission(mContext);
655                 return mVmsBrokerService;
656             case Car.VMS_SUBSCRIBER_SERVICE:
657                 CarServiceUtils.assertVmsSubscriberPermission(mContext);
658                 return mVmsBrokerService;
659             case Car.TEST_SERVICE: {
660                 CarServiceUtils.assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE);
661                 synchronized (mLock) {
662                     if (mCarTestService == null) {
663                         mCarTestService = new CarTestService(mContext, this);
664                     }
665                     return mCarTestService;
666                 }
667             }
668             case Car.STORAGE_MONITORING_SERVICE:
669                 CarServiceUtils.assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING);
670                 return mCarStorageMonitoringService;
671             case Car.CAR_DRIVING_STATE_SERVICE:
672                 CarServiceUtils.assertDrivingStatePermission(mContext);
673                 return mCarDrivingStateService;
674             case Car.CAR_UX_RESTRICTION_SERVICE:
675                 return mCarUXRestrictionsService;
676             case Car.OCCUPANT_AWARENESS_SERVICE:
677                 return mOccupantAwarenessService;
678             case Car.CAR_MEDIA_SERVICE:
679                 return mCarMediaService;
680             case Car.CAR_OCCUPANT_ZONE_SERVICE:
681                 return mCarOccupantZoneService;
682             case Car.CAR_BUGREPORT_SERVICE:
683                 return mCarBugreportManagerService;
684             case Car.CAR_USER_SERVICE:
685                 return mCarUserService;
686             case Car.EXPERIMENTAL_CAR_USER_SERVICE:
687                 return mExperimentalCarUserService;
688             case Car.EXPERIMENTAL_CAR_KEYGUARD_SERVICE:
689                 return mExperimentalCarKeyguardService;
690             case Car.CAR_WATCHDOG_SERVICE:
691                 return mCarWatchdogService;
692             case Car.CAR_PERFORMANCE_SERVICE:
693                 return mCarPerformanceService;
694             case Car.CAR_INPUT_SERVICE:
695                 return mCarInputService;
696             case Car.CAR_DEVICE_POLICY_SERVICE:
697                 return mCarDevicePolicyService;
698             case Car.CLUSTER_HOME_SERVICE:
699                 return mClusterHomeService;
700             case Car.CAR_EVS_SERVICE:
701                 return mCarEvsService;
702             case Car.CAR_TELEMETRY_SERVICE:
703                 return mCarTelemetryService;
704             case Car.CAR_ACTIVITY_SERVICE:
705                 return mCarActivityService;
706             case Car.CAR_OCCUPANT_CONNECTION_SERVICE:
707                 return mCarOccupantConnectionService;
708             case Car.CAR_REMOTE_DEVICE_SERVICE:
709                 return mCarRemoteDeviceService;
710             case Car.CAR_REMOTE_ACCESS_SERVICE:
711                 return mCarRemoteAccessService;
712             default:
713                 IBinder service = null;
714                 if (mCarExperimentalFeatureServiceController != null) {
715                     service = mCarExperimentalFeatureServiceController.getCarService(serviceName);
716                 }
717                 if (service == null) {
718                     Slogf.w(CarLog.TAG_SERVICE, "getCarService for unknown service:"
719                             + serviceName);
720                 }
721                 return service;
722         }
723     }
724 
725     @Override
726     @ExcludeFromCodeCoverageGeneratedReport(reason = DEPRECATED_CODE)
getCarConnectionType()727     public int getCarConnectionType() {
728         return Car.CONNECTION_TYPE_EMBEDDED;
729     }
730 
731     @Override
732     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dump(FileDescriptor fd, PrintWriter writer, String[] args)733     protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
734         if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
735                 != PackageManager.PERMISSION_GRANTED) {
736             writer.println("Permission Denial: can't dump CarService from from pid="
737                     + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
738                     + " without permission " + android.Manifest.permission.DUMP);
739             return;
740         }
741 
742         try (IndentingPrintWriter pw = new IndentingPrintWriter(writer)) {
743             dumpIndenting(fd, pw, args);
744         }
745     }
746 
747     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dumpIndenting(FileDescriptor fd, IndentingPrintWriter writer, String[] args)748     private void dumpIndenting(FileDescriptor fd, IndentingPrintWriter writer, String[] args) {
749         if (args == null || args.length == 0) {
750             dumpAll(writer);
751             return;
752         }
753         switch (args[0]) {
754             case "-a":
755                 dumpAll(writer);
756                 return;
757             case "--list":
758                 dumpListOfServices(writer);
759                 return;
760             case "--version":
761                 dumpVersions(writer);
762                 return;
763             case "--services": {
764                 if (args.length < 2) {
765                     writer.println("Must pass services to dump when using --services");
766                     return;
767                 }
768                 int length = args.length - 1;
769                 String[] services = new String[length];
770                 System.arraycopy(args, 1, services, 0, length);
771                 dumpIndividualServices(writer, services);
772                 return;
773             }
774             case "--metrics":
775                 // Strip the --metrics flag when passing dumpsys arguments to CarStatsService
776                 // allowing for nested flag selection.
777                 if (args.length == 1 || Arrays.asList(args).contains("--vms-client")) {
778                     mCarStatsService.dump(writer);
779                 }
780                 return;
781             case "--vms-hal":
782                 mHal.getVmsHal().dumpMetrics(fd);
783                 return;
784             case "--hal": {
785                 if (args.length == 1) {
786                     dumpAllHals(writer);
787                     return;
788                 }
789                 int length = args.length - 1;
790                 String[] halNames = new String[length];
791                 System.arraycopy(args, 1, halNames, 0, length);
792                 mHal.dumpSpecificHals(writer, halNames);
793                 return;
794             }
795             case "--list-hals":
796                 mHal.dumpListHals(writer);
797                 return;
798             case "--data-dir":
799                 dumpDataDir(writer);
800                 return;
801             case "--help":
802                 showDumpHelp(writer);
803                 return;
804             case "--rro":
805                 dumpRROs(writer);
806                 return;
807             case "--oem-service":
808                 if (args.length > 1 && args[1].equalsIgnoreCase("--name-only")) {
809                     writer.println(getOemServiceName());
810                 } else {
811                     dumpOemService(writer);
812                 }
813                 return;
814             default:
815                 execShellCmd(args, writer);
816         }
817     }
818 
dumpOemService(IndentingPrintWriter writer)819     private void dumpOemService(IndentingPrintWriter writer) {
820         mCarOemService.dump(writer);
821     }
822 
getOemServiceName()823     public String getOemServiceName() {
824         return mCarOemService.getOemServiceName();
825     }
826 
dumpAll(IndentingPrintWriter writer)827     private void dumpAll(IndentingPrintWriter writer) {
828         writer.println("*Dump car service*");
829         dumpVersions(writer);
830         dumpAllServices(writer);
831         dumpAllHals(writer);
832         dumpRROs(writer);
833     }
834 
dumpRROs(IndentingPrintWriter writer)835     private void dumpRROs(IndentingPrintWriter writer) {
836         writer.println("*Dump Car Service RROs*");
837 
838         String packageName = SystemProperties.get(
839                 PROPERTY_CAR_SERVICE_PACKAGE_NAME, /*def= */null);
840         if (packageName == null) {
841             writer.println("Car Service updatable package name is null.");
842             return;
843         }
844 
845         OverlayManager manager = mContext.getSystemService(OverlayManager.class);
846 
847         List<OverlayInfo> installedOverlaysForSystem = manager.getOverlayInfosForTarget(packageName,
848                 UserHandle.SYSTEM);
849         writer.println("RROs for System User");
850         for (int i = 0; i < installedOverlaysForSystem.size(); i++) {
851             OverlayInfo overlayInfo = installedOverlaysForSystem.get(i);
852             writer.printf("Overlay: %s, Enabled: %b \n", overlayInfo.getPackageName(),
853                     overlayInfo.isEnabled());
854         }
855 
856         int currentUser = ActivityManager.getCurrentUser();
857         writer.printf("RROs for Current User: %d\n", currentUser);
858         List<OverlayInfo> installedOverlaysForCurrentUser = manager.getOverlayInfosForTarget(
859                 packageName, UserHandle.of(currentUser));
860         for (int i = 0; i < installedOverlaysForCurrentUser.size(); i++) {
861             OverlayInfo overlayInfo = installedOverlaysForCurrentUser.get(i);
862             writer.printf("Overlay: %s, Enabled: %b \n", overlayInfo.getPackageName(),
863                     overlayInfo.isEnabled());
864         }
865     }
866 
867     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dumpVersions(IndentingPrintWriter writer)868     private void dumpVersions(IndentingPrintWriter writer) {
869         writer.println("*Dump versions*");
870         writer.println("Android SDK_INT: " + Build.VERSION.SDK_INT);
871         writer.println("Car Version: " + Car.getCarVersion());
872         writer.println("Platform Version: " + Car.getPlatformVersion());
873         writer.println("CarBuiltin Platform minor: " + CarBuiltin.PLATFORM_VERSION_MINOR_INT);
874         writer.println("Legacy versions (might differ from above as they can't be emulated)");
875         writer.increaseIndent();
876         writer.println("Car API major: " + Car.API_VERSION_MAJOR_INT);
877         writer.println("Car API minor: " + Car.API_VERSION_MINOR_INT);
878         writer.println("Car Platform minor: " + Car.PLATFORM_VERSION_MINOR_INT);
879         writer.println("VHAL and Car User Service Priority Init: " + mDoPriorityInitInConstruction);
880         writer.decreaseIndent();
881     }
882 
883     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dumpAllHals(IndentingPrintWriter writer)884     private void dumpAllHals(IndentingPrintWriter writer) {
885         writer.println("*Dump Vehicle HAL*");
886         writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName);
887         try {
888             // TODO dump all feature flags by creating a dumpable interface
889             mHal.dump(writer);
890         } catch (Exception e) {
891             writer.println("Failed dumping: " + mHal.getClass().getName());
892             e.printStackTrace(writer);
893         }
894     }
895 
896     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
showDumpHelp(IndentingPrintWriter writer)897     private void showDumpHelp(IndentingPrintWriter writer) {
898         writer.println("Car service dump usage:");
899         writer.println("[NO ARG]");
900         writer.println("\t  dumps everything (all services and HALs)");
901         writer.println("--help");
902         writer.println("\t  shows this help");
903         writer.println("--version");
904         writer.println("\t  shows the version of all car components");
905         writer.println("--list");
906         writer.println("\t  lists the name of all services");
907         writer.println("--list-hals");
908         writer.println("\t  lists the name of all HALs");
909         writer.println("--services <SVC1> [SVC2] [SVCN]");
910         writer.println("\t  dumps just the specific services, where SVC is just the service class");
911         writer.println("\t  name (like CarUserService)");
912         writer.println("--vms-hal");
913         writer.println("\t  dumps the VMS HAL metrics");
914         writer.println("--hal [HAL1] [HAL2] [HALN]");
915         writer.println("\t  dumps just the specified HALs (or all of them if none specified),");
916         writer.println("\t  where HAL is just the class name (like UserHalService)");
917         writer.println("--user-metrics");
918         writer.println("\t  dumps user switching and stopping metrics");
919         writer.println("--first-user-metrics");
920         writer.println("\t  dumps how long it took to unlock first user since Android started\n");
921         writer.println("\t  (or -1 if not unlocked)");
922         writer.println("--data-dir");
923         writer.println("\t  dumps CarService data dir (and whether it exists)");
924         writer.println("--rro");
925         writer.println("\t  dumps only the RROs");
926         writer.println("-h");
927         writer.println("\t  shows commands usage (NOTE: commands are not available on USER builds");
928         writer.println("[ANYTHING ELSE]");
929         writer.println("\t  runs the given command (use --h to see the available commands)");
930     }
931 
932     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dumpDataDir(IndentingPrintWriter writer)933     private void dumpDataDir(IndentingPrintWriter writer) {
934         File dataDir = mContext.getDataDir();
935         writer.printf("Data dir: %s Exists: %b\n", dataDir.getAbsolutePath(), dataDir.exists());
936     }
937 
938     @Override
onTransact(int code, @NonNull Parcel data, @Nullable Parcel reply, int flags)939     public boolean onTransact(int code, @NonNull Parcel data, @Nullable Parcel reply,
940             int flags) throws RemoteException {
941         // Shell cmd is handled specially.
942         if (BinderHelper.onTransactForCmd(code, data, reply, flags, mCmdListener)) {
943             return true;
944         }
945         return super.onTransact(code, data, reply, flags);
946     }
947 
newCarShellCommand()948     private CarShellCommand newCarShellCommand() {
949         return new CarShellCommand(mContext, mHal, mCarAudioService, mCarPackageManagerService,
950                 mCarProjectionService, mCarPowerManagementService, mFixedActivityService,
951                 mFeatureController, mCarInputService, mCarNightService, mSystemInterface,
952                 mGarageModeService, mCarUserService, mCarOccupantZoneService, mCarEvsService,
953                 mCarWatchdogService, mCarTelemetryService);
954     }
955 
956     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dumpListOfServices(IndentingPrintWriter writer)957     private void dumpListOfServices(IndentingPrintWriter writer) {
958         for (CarSystemService service : mAllServices) {
959             writer.println(service.getClass().getName());
960         }
961     }
962 
963     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dumpAllServices(IndentingPrintWriter writer)964     private void dumpAllServices(IndentingPrintWriter writer) {
965         writer.println("*Dump all services*");
966         for (CarSystemService service : mAllServices) {
967             if (service instanceof CarServiceBase) {
968                 dumpService(service, writer);
969             }
970         }
971         if (mCarTestService != null) {
972             dumpService(mCarTestService, writer);
973         }
974     }
975 
976     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dumpIndividualServices(IndentingPrintWriter writer, String... serviceNames)977     private void dumpIndividualServices(IndentingPrintWriter writer, String... serviceNames) {
978         for (String serviceName : serviceNames) {
979             writer.printf("** Dumping %s\n\n", serviceName);
980             CarSystemService service = getCarServiceBySubstring(serviceName);
981             if (service == null) {
982                 writer.println("No such service!");
983             } else {
984                 dumpService(service, writer);
985             }
986             writer.println();
987         }
988     }
989 
990     @Nullable
getCarServiceBySubstring(String className)991     private CarSystemService getCarServiceBySubstring(String className) {
992         return Arrays.asList(mAllServices).stream()
993                 .filter(s -> s.getClass().getSimpleName().equals(className))
994                 .findFirst().orElse(null);
995     }
996 
997     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dumpService(CarSystemService service, IndentingPrintWriter writer)998     private void dumpService(CarSystemService service, IndentingPrintWriter writer) {
999         try {
1000             service.dump(writer);
1001         } catch (Exception e) {
1002             writer.println("Failed dumping: " + service.getClass().getName());
1003             e.printStackTrace(writer);
1004         }
1005     }
1006 
execShellCmd(String[] args, IndentingPrintWriter writer)1007     void execShellCmd(String[] args, IndentingPrintWriter writer) {
1008         newCarShellCommand().exec(args, writer);
1009     }
1010 
constructWithTrace(LimitedTimingsTraceLog t, Class<T> cls, Callable<T> callable, List<CarSystemService> allServices)1011     private <T extends CarSystemService> T constructWithTrace(LimitedTimingsTraceLog t,
1012             Class<T> cls, Callable<T> callable, List<CarSystemService> allServices) {
1013         t.traceBegin(cls.getSimpleName());
1014         T constructed;
1015         try {
1016             constructed = callable.call();
1017             CarLocalServices.addService(cls, constructed);
1018         } catch (Exception e) {
1019             throw new RuntimeException("Crash while constructing:" + cls.getSimpleName(), e);
1020         } finally {
1021             t.traceEnd();
1022         }
1023         allServices.add(constructed);
1024         return constructed;
1025     }
1026 
1027     private final class ICarSystemServerClientImpl extends ICarSystemServerClient.Stub {
1028         @Override
onUserLifecycleEvent(int eventType, int fromUserId, int toUserId)1029         public void onUserLifecycleEvent(int eventType, int fromUserId, int toUserId)
1030                 throws RemoteException {
1031             assertCallingFromSystemProcess();
1032             EventLogHelper.writeCarServiceOnUserLifecycle(eventType, fromUserId, toUserId);
1033             if (DBG) {
1034                 Slogf.d(TAG,
1035                         "onUserLifecycleEvent("
1036                                 + CarUserManager.lifecycleEventTypeToString(eventType) + ", "
1037                                 + toUserId + ")");
1038             }
1039             mCarUserService.onUserLifecycleEvent(eventType, fromUserId, toUserId);
1040         }
1041 
1042         @Override
initBootUser()1043         public void initBootUser() throws RemoteException {
1044             assertCallingFromSystemProcess();
1045             EventLogHelper.writeCarServiceInitBootUser();
1046             if (DBG) Slogf.d(TAG, "initBootUser(): ");
1047             mCarUserService.initBootUser();
1048         }
1049 
1050         // TODO(235524989): Remove this method as on user removed will now go through
1051         // onUserLifecycleEvent due to changes in CarServiceProxy and CarUserService.
1052         @Override
onUserRemoved(UserHandle user)1053         public void onUserRemoved(UserHandle user) throws RemoteException {
1054             assertCallingFromSystemProcess();
1055             EventLogHelper.writeCarServiceOnUserRemoved(user.getIdentifier());
1056             if (DBG) Slogf.d(TAG, "onUserRemoved(): " + user);
1057             mCarUserService.onUserRemoved(user);
1058         }
1059 
1060         @Override
onFactoryReset(ICarResultReceiver callback)1061         public void onFactoryReset(ICarResultReceiver callback) {
1062             assertCallingFromSystemProcess();
1063 
1064             mCarPowerManagementService.setFactoryResetCallback(callback);
1065             BuiltinPackageDependency.createNotificationHelper(mCarServiceBuiltinPackageContext)
1066                     .showFactoryResetNotification(callback);
1067         }
1068 
1069         @Override
setInitialUser(UserHandle user)1070         public void setInitialUser(UserHandle user) {
1071             mCarUserService.setInitialUserFromSystemServer(user);
1072         }
1073     }
1074 
dumpVhal(ParcelFileDescriptor fd, List<String> options)1075     /* package */ void dumpVhal(ParcelFileDescriptor fd, List<String> options)
1076             throws RemoteException {
1077         mHal.dumpVhal(fd, options);
1078     }
1079 
hasAidlVhal()1080     /* package */ boolean hasAidlVhal() {
1081         return mHal.isAidlVhal();
1082     }
1083 
priorityInit()1084     /* package */ void priorityInit() {
1085         mHal.priorityInit();
1086         mCarUserService.priorityInit();
1087     }
1088 }
1089