Android car service (1) CarService
broadview_java Modified on 2023-03-28 22:24:56 3.7k reads Collection 24 Likes 3
Classification column: Android Automotive Article tags: Vehicle development CarServiceCarService
Android Automotive The column contains this content 32 Subscribe 7 articles S
1. Introduction
Android Automotive OS, as a vehicle operating system, needs to be interconnected with other subsystems on the vehicle.
Android Automotive OS defines a standard hardware abstraction layer HAL (Hardware Abstraction Layer) to standardize the calling interface
subsystem and Framework, and provides standard programming interfaces to upper-layer applications through CarService and related Car APIs.
Below we refer to Android Automotive OS as AAOS.
AAOS has not drastically changed the original overall architecture of Android. Almost all core services ( AMS , WMS, PKMS) are no differen
mobile phones and use the same source code, so we can understand AAOS as Android OS + Android Automotive Services is more appropriate.
The traditional mobile phone system plus related car services constitute the current AAOS, and CarService is the most important module that p
car-related functions.
This article focuses on introducing CarService, which is Android car service.
2. Composition of CarService
For applications, the relevant functions will not be called directly through the instances of the above services, but the calls to the services will b
completed through the corresponding Car API. Anyone who has done Android development must know that the communication mode of Android is b
the C/S mode. There are clients and servers, and each service has a corresponding proxy object (for example, ActivityManager is the client relative
service AMS, and PackageManager is the client relative to the service PKMS).
As the core process of AAOS, Google has implemented many services closely related to cars in CarService. We will briefly list the services. S
each car service will also have its own corresponding client. The table is as follows (not complete):
Service side Function Client
Service to manage the focus of
AppFocusService CarAppFocusManager
similar applications
CarAudioService car audio services CarAudioManager
car package management
CarPackageManagerService CarPackageManager
services
CarDiagnosticService Automotive Diagnostic Services CarDiagnosticManager
Automotive power management
CarPowerManagerService CarPowerManager
services
IInstrumentClusterNavigaiton Instrument navigation service
IInstrumentClusterManagerServcie instrument service IInstrumentClusterManager
CarProjecitonService Screen casting service CarProjecitonManager
VmsSubscriberService Vehicle map service VmsSubscriberManager
CarBluetoothService Car Bluetooth service CarBluetoothManager
CarStorageMonitoringService Car Storage Monitoring Service CarStorageMonitoringManager
CarDrivingStateService Car driving status service CarDrivingStateManager
Automotive User Experience Think it’s One-clic
CarUXRestrictionsService CarUXRestrictionsManager
Limitation Services pretty good? collectio
broadview_java focus on 3 twenty
CarConfigurationService Car configuration service CarConfigurationManager
CarTrustedDeviceService Credit equipment management CarTrustAgentEnrollmentManager
CarMediaService media management services CarMediaManager
CarBugreportManagerService Error reporting service CarBugreportManager
[Remarks]: The version of aosp has been updated, and there are more and more services. The author has only listed some of them. For reference
In terms of naming, it is relatively easy to associate the above objects with related services. The more special one is CarInfoManager.
CarSensorManager, CarHvacManager, CarCabinManager, CarVendor-ExtensionManager and CarPropertyManager all correspond to CarPropertyS
service will be introduced in detail later in the article.
3. CarService startup process
After understanding the main components of CarService, let's take a look at the startup process of CarService and see what it does during the
process. As the core service of AAOS, CarService needs to always run in the background and early in the system startup. Create. Timing diagram:
The detailed code is as follows:
/frameworks/base/services/java/com/android/server/SystemServer.java
1 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {
2 traceBeginAndSlog("StartCarServiceHelperService");
3 mSystemServiceManager.startService(CAR_SERVICE_HELPER_SERVICE_CLASS);
4 traceEnd();
5 }
Then jump to the startService method in the SystemServiceManager.java file
frameworks/base/services/core/java/com/android/server/SystemServiceManager.java
1 public SystemService startService(String className) {
2 final Class<SystemService> serviceClass;
3 try {
4 serviceClass = (Class<SystemService>)Class.forName(className);
5 } catch (ClassNotFoundException ex) {
6 Slog.i(TAG, "Starting " + className); Think it’s One-clic
7 throw new RuntimeException("Failed to create service " + className pretty good? collectio
8 + ": service class not found, usually indicates that the caller should "
broadview_java focus on 3 twenty
9 + "have called PackageManager.hasSystemFeature() to check whether the "
10 + "feature is available on this device before trying to start the "
11
+ "services that implement it", ex);12 }
13 return startService(serviceClass);
14 }
15
16 public <T extends SystemService> T startService(Class<T> serviceClass) {
17
18 final String name = serviceClass.getName();
19 ....
20 try { // 注释1
21 Constructor<T> constructor = serviceClass.getConstructor(Context.class);
22 service = constructor.newInstance(mContext);
23 ....
24 startService(service);
25 return service;
26 ...
27 }
28
29 public void startService(@NonNull final SystemService service) {
30 // Register it.
31 mServices.add(service);
32 // Start it.
33 long time = SystemClock.elapsedRealtime();
34 try {
35 // 注释2 启动CarService
36 service.onStart();
37 .....
38 }
Note 1, the service is created through the method encapsulated by SystemServiceManager. Here SystemServiceManager creates the
CarServiceHelperService object through reflection, calls its onStart method, and enters the CarServiceHelperService.java file.
1 public void onStart() {
2 Intent intent = new Intent();
3 intent.setPackage("com.android.car");
4 intent.setAction(CAR_SERVICE_INTERFACE);
5 if (!getContext().bindServiceAsUser(intent, mCarServiceConnection, Context.BIND_AUTO_CREATE,
6 UserHandle.SYSTEM)) {
7 Slog.wtf(TAG, "cannot start car service");
8 }
9 System.loadLibrary("car-framework-service-jni");
10 }
Note 2: In the onStart method, an Intent is created, the package name and Action are set, and bindServiceAsUser is called to create and bind the as
CarService. At the same time, the relevant JNI library (car-framework-service-jni) is loaded.
Through the above source code snippets, we know that the target package name of the Intent is "com.android.car", the action is "android.car.ICar",
source code is globally searched for a matching Service.
packages/services/Car/service/src/com/android/car/CarService.java
1 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
3 package="com.android.car"
4 coreApp="true"
5 android:sharedUserId="android.uid.system">
6
7
8
9 <service android:name=".CarService"
10 android:singleUser="true">
11 <intent-filter>
12 <action android:name="android.car.ICar" />
13 </intent-filter> Think it’s One-clic
14 </service> pretty good? collectio
15
broadview_java focus on 3 twenty
Through the above process, CarService will be started together with other services in the early stage of system startup, and its startup timing is con
LocationManagerService/NotificationManagerService/WallpaperManagerService.
From this point of view, CarService has the same status as other main system services. The difference is that CarService runs in an independen
while other services run in the SystemServer process.
On the other hand, it can be seen from the manifest file of CarService that CarService uses the system UID to run, which also ensures that CarServ
characteristics and permissions of system services.
In addition, the main functional implementation of AAOS car service is concentrated in CarService, and the coupling with the original Android Frame
source code is relatively small. In terms of source code management, the source code of CarService is managed in a separate warehouse.
The following is a simple architectural diagram to illustrate the relationship between CarService and Android's original system services: CarService r
independent process. As a supplement to the original Android service, it runs on the car device
AAOS architecture diagram
4. CarService source code analysis
When the service is started, its onCreate method is first called. The onCreate method of CarService is implemented as follows:
1 @Override
2 public void onCreate() {
3 Log.i(CarLog.TAG_SERVICE, "Service onCreate");
4 // 获取通知管理NotificationManager对象
5 mCanBusErrorNotifier = new CanBusErrorNotifier(this /* context */);
6 mVehicle = getVehicle();
7
8 if (mVehicle == null) {
9 throw new IllegalStateException("Vehicle HAL service is not available.");
10 }
11 try {
12 mVehicleInterfaceName = mVehicle.interfaceDescriptor();
13 } catch (RemoteException e) {
14 throw new IllegalStateException("Unable to get Vehicle HAL interface descriptor", e);
15 }
16
17 Log.i(CarLog.TAG_SERVICE, "Connected to " + mVehicleInterfaceName);
18
19 mICarImpl = new ICarImpl(this,
20 mVehicle,
21 SystemInterface.Builder.defaultSystemInterface(this).build(),
22 mCanBusErrorNotifier,
23 mVehicleInterfaceName);
24 mICarImpl.init();
25
26 linkToDeath(mVehicle, mVehicleDeathRecipient);
27
28 ServiceManager.addService("car_service", mICarImpl);
29 // 设置SystemProperty属性 carService 已创建 Think it’s One-clic
30 SystemProperties.set("boot.car_service_created", "1"); pretty good? collectio
31 super.onCreate(); broadview_java focus on 3 twenty
32 }
Mainly did two things:
1. Obtain the HIDL Binder remote object related to the mVehicle vehicle;
2. Created the mICarImpl object and added it to the service list managed by ServiceManager.
The ICarImpl here plays the role of creating and managing each service. In its constructor, instances of each service are created and added to the s
The source code is as follows:
packages/services/Car/service/src/com/android/car/ICarImpl.java
1 public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,
2 CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) {
3 mContext = serviceContext;
4 mSystemInterface = systemInterface;
5 mHal = new VehicleHal(vehicle);
6 mVehicleInterfaceName = vehicleInterfaceName;
7 // 创建各种重要的服务
8 mUserManagerHelper = new CarUserManagerHelper(serviceContext);
9 final Resources res = mContext.getResources();
10 final int maxRunningUsers = res.getInteger(
11 com.android.internal.R.integer.config_multiuserMaxRunningUsers);
12 mCarUserService = new CarUserService(serviceContext, mUserManagerHelper,
13 ActivityManager.getService(), maxRunningUsers);
14 mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);
15 mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(),
16 systemInterface, mUserManagerHelper);
17 mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal());
18 ....
19
20 // 将重要的服务缓存到 CarLocalServices
21 CarLocalServices.addService(CarPowerManagementService.class, mCarPowerManagementService);
22 CarLocalServices.addService(CarUserService.class, mCarUserService);
23 CarLocalServices.addService(CarTrustedDeviceService.class, mCarTrustedDeviceService);
24
25
26 // 将创建的服务对象依次添加到⼀个list中保存起来
27 List<CarServiceBase> allServices = new ArrayList<>();
28 allServices.add(mFeatureController);
29 allServices.add(mCarUserService);
30
31 .....
32 }
These created services are the car services introduced above.
5. How to use Car API
In the above introduction, CarServiceeach service we mentioned is essentially an implementation class of the AIDL interface, which belongs
server side, and the corresponding client side needs an IBinderobject to access the server side methods. These IBinderobjects are encapsulate
API in a XXXManagercategory.
5.1 Compile Car API
Before using the Car API, we need to compile the Car API into a jar, which is CarLib, so that it can be used by other system applications. The c
as follows:
make android.car android.car-system-stubs android.car-stubs
The output path of android.car.jar after successful compilation is:
Think it’s One-clic
pretty good? collectio
/out/soong/.intermediates/packages/services/Car/car-lib/android.car/android_common/javac/android.car.jar
broadview_java focus on 3 twenty
5.2 Using Car API
The use of Car API is not complicated, and there are roughly the following steps:
1. First, create the Car object through Car.createCar
1 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {
2 Car carClient = Car.createCar(context, mCarServiceConnection);
3 }
Determine whether the system supports specific module functions through getPackageManager().hasSystemFeature(String string)
The ServiceConnection object needs to be passed in. After CarService is successfully connected, the corresponding callback is received. If
onServiceConnected of ServiceConnection is called back, it means that the connection is successful and the corresponding service can be obtained
1 private final ServiceConnection mCarServiceConnection = new ServiceConnection() {
2 @Override
3 public void onServiceConnected(ComponentName name, IBinder service) {
4 try {
5 CarInfoManager manager = (CarInfoManager) carClient.getCarManager(Car.INFO_SERVICE);
6 } catch (CarNotConnectedException e) {
7 Log.e(TAG, "Car not connected in onServiceConnected");
8 }
9 }
10
11 @Override
12 public void onServiceDisconnected(ComponentName name) {
13 }
14 };
2. After constructing the Car object, you still need to call it connect()to connect CarServiceto it.
carClient.connect();
[注意事项]connect()It can only be called once. If it is currently connected, connect()an exception will be thrown if called again. If the client doe
the exception, it will cause the client program to crash.
1 @Deprecated
2 public void connect() throws IllegalStateException {
3 synchronized (mLock) {
4 if (mConnectionState != STATE_DISCONNECTED) {
5 throw new IllegalStateException("already connected or connecting");
6 }
7 mConnectionState = STATE_CONNECTING;
8 startCarService();
9 }
10 }
3. In addition to connecting to the service, you also need to unbind the service when not using CarService and release resources through the discon
method:
carClient.disconnect();
The above three steps were used before (<=Android9). After Android10, the method of obtaining the Car object has been greatly simplified.
An application does not have to connect and accept callbacks before it can use the Car API, which means that methods to obtain a Car Manager ob
executed synchronously rather than asynchronously.
How to get the Car object in android10 and later:
1 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {
2 Car carClient = Car.createCar(context); Think it’s One-clic
3 CarHvacManager manager = (CarHvacManager) carClient.getCarManager(Car.HVAC_SERVICE); pretty good? collectio
4 } broadview_java focus on 3 twenty
6. Summary
This article mainly explains the startup process of the CarService system service, as well as the creation and initialization process of some key
At the same time, we briefly introduce how the client obtains and uses the CarService object. As mentioned above, the CarService object is on
for obtaining each Manager. It itself does not undertake specific tasks such as managing sensors and air conditioners.
If you want to obtain vehicle-related information, such as vehicle speed, interior air-conditioning temperature, diagnostic information, or perform
controls on the vehicle, such as raising and lowering the air-conditioning temperature, controlling seats and windows, adjusting the volume, etc., you
specific The API and corresponding services in the Manager are implemented.
Car- Service : Providing car services
Car Quote Car Quote Service Directory Basic Information Car Service Quote. CRUD application for holding car purchase offers. Screenshot Technology Area Java - Vers
Car Service : car service _
Getting Started with Create React App This project is bootstrapped. The available scripts are in the project directory and can be run: npm start to run the application in de
Android AutoMotive module Car Service _automotive service csdn -CSDN...
Car Service defines access rights to attribute values for some special attribute reading and writing. The definition method is in the Android Manifest . Service maps attribu
An in-depth introduction to the composition and links of Android car core Car Service_ android occupantzo...
When Car Service Helper Service executes onStart () , it will hand over subsequent work to Car Service Helper Service UpdatableImpl to handle. In its onStart(), bind Se
Android car service ( 4 ) CarAudio Service u012514113's colu
In vehicles , the number and usage scenarios of audio devices are very different from those on mobile phones. The original audio service of Android cannot meet the nee
STR android implementation introduction kill150's co
Source: You need to climb over the wall. If you can’t climb over, look at the picture below:
Android O Car Service _ car service android _ _
Mainly introduces Android 's Car Service . Architecture The overall architecture of Android Automative is shown in the figure below: From this figure we can see that Andr
Android 9.0 Car Service Analysis _
1. Car Service startup process: 1. Startup flow chart 2. SystemServer -> Car Service Helper Service - > Car Service finally starts Car Service frameworks /base/ service s
【Android R 】Car Android core service CarProperty Service xiaokangss's
Comparing the development of car Android and mobile phone Android applications, the biggest difference should be that many car applications need to consider the over
[ Android Car Series] Chapter 1 Overall Introduction to the Car System Yv
Automotive operating systems have evolved from traditional automotive electronics. Traditional automotive electronic products can be divided into two categories: one is
Thousands of words interpret the core of Android cars: the composition and links of Car Service ~ allisonchen's co
Regarding Android cars, I have previously analyzed the input mechanism of custom buttons on the side control and the input principle of the knob on the center control, b
Car Service of Android 9.0 AutoMotive module Cha
The previous article summarized the Vhal of the Automotive module. This article mainly analyzes the functions provided by Automotive from the implementation of the up
Android Automotive (5 ) Car Service Jun_P's b
Android Automotive (5 ) Car Service
[ Android Car Series] Chapter 2 Car System Startup and Car Service Yv
..default:= null) { The functions implemented by Car Service almost cover the core of the entire vehicle-mounted Framework. However, in reality, in order to ensure the sta
【Android R 】Car Android core service - Car Service analysis linkwj's b
In the previous article, discussing the vehicle Android system from the perspective of an application engineer, it was mentioned that " Car Service is one of the core servi
Android 12 system source code_ Car Service (1) Basic architecture of Car Service AfinalStone's colu
Introducing the architecture of Car Service through Android 12 system source code
car - service : car service
hey ca r - Backend Challenge Task: Create a platform that can receive listings from resellers through different providers and make them available in the platform. Out of s
PSK - Car Service
PSK - Car Service
Think it’s One-clic
front - car Service
pretty good? collectio
Front service
broadview_java focus on 3 twenty
oxit - car Service
oxit - car Service
A neurofeedback training system based on MATLAB
matlab experiment
Responsive Web Development Project Tutorial (HTML5+CSS3+Bootstrap) Version 2 Example 2-4 Font Icon Application Latest releases
Responsive Web Development Project Tutorial (HTML5+CSS3+Bootstrap) 2nd Edition Chapter 2 CSS3 Text and Icon Example 2-4 Font Icon Application
LiuMo.html
LiuMo.html
PowerPolicy android
According to the quote provided, PowerPolicy is a feature in Android that manages the power policy of a device. According to the quote…
Is "Related Recommendations" helpful to you?
Very unhelpful Not helpful generally helpful very helpful
about Business seeking 400-660- online Working hours
Recruitment kefu@csdn.net
Us Cooperation coverage 0108 service 8:30-22:00
Public Security Registration Number 11010502030143 Beijing ICP No. 19004658 Beijing Net Article [2020] No. 1039-165
Commercial website registration information Beijing Internet Illegal and Bad Information Reporting Center Parental supervision
Network 110 alarm service China Internet Reporting Center Chrome store download Account management specifications
Copyright and Disclaimer Copyright complaint Publication license business license
©1999-2024Beijing Innovation Lezhi Network Technology Co., Ltd.
broadview_java
10 years of coding No certifi…
132 20,000+ 10,000+ 420,000+
Original Weekly Overall access grade
ranking ranking
1777 122 332 59 1307
integral fan Liked Comment collect
Private letter focus on
Search blogger articles
Think it’s One-clic
pretty good? collectio
broadview_java focus on 3 twenty