Android CarService - Android Carservice-CSDN Blog-Part1
Android CarService - Android Carservice-CSDN Blog-Part1
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.
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.
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):
[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.
/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 }
frameworks/base/services/core/java/com/android/server/SystemServiceManager.java
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.
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
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 }
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 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
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.
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.
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
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
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 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
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
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…
broadview_java
10 years of coding No certifi…