appspawn Module for the Standard System
Overview
After being started by the init process, the appspawn process waits for inter-process communication (IPC) messages. Upon receiving a message, the appspawn process starts an application service based on the message content, and grants the corresponding permission to the application service.
Introduction
-
Security control
Support for setting of SELinux tags for applications -
Application process control
- Support for setting of AccessToken for applications
- Support for simultaneous stopping of all spawn application processes (after stopping of the appspawn process and before a restart)
-
Cold start
Support for cold start of applications by using the aa commandparam set appspawn.cold.boot true // Enable cold start. aa start -d 12345 -a $name -b $package -C Example: aa start -d 12345 -a ohos.acts.startup.sysparam.function.MainAbility -b ohos.acts.startup.sysparam.function -C
Basic Concepts
appspawn is a registered service name. The appspawn process receives requests from the client by listening to messages over the local socket. The message type is an AppProperty structure. It is defined in base/startup/appspawn_standard/interfaces/innerkits/include/sclient_socket.h.
Table 1 Field description
Development Guidelines
The API definitions are provided in base/startup/appspawn_standard/interfaces/innerkits/include/client_socket.h. Table 2 is a list of available APIs.
Available APIs
Table 2 API description
Development Example
The following is an example of using related APIs:
std::shared_ptr<AppSpawn::ClientSocket> clientSocket = std::make_unique<AppSpawn::ClientSocket>("AppSpawn");
if (clientSocket == nullptr) {
return -1;
}
if (clientSocket->CreateClient() != ERR_OK) {
return -1;
}
if (clientSocket->ConnectSocket() != ERR_OK) {
return -1;;
}
// Construct AppProperty based on the specified property.
clientSocket->WriteSocketMessage((void *)&property, sizeof(AppSpawn::AppProperty));
// Read the result.
int pid;
clientSocket->ReadSocketMessage((void *)&pid, sizeof(pid));
// Normally, the process ID of the application is returned. If the PID is less than or equal to 0, an error has occurred.
FAQ
Cold Start Failure
Symptom
Cold start failed because of a command execution failure.
Solution
1. Check whether cold start is enabled.
2. Check whether the cold start command is correct.