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 command

    param 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

Field

Description

processName

Name of the service process to be started. The value contains a maximum of 256 bytes.

bundleName

Bundle name of the application to be started. The value contains a maximum of 256 bytes.

soPath

Path of the dynamic library specified by the application. The value contains a maximum of 256 bytes.

uid

UID of the application process to be started. The value must be a positive number.

gid

GID of the application process to be started. The value must be a positive number.

gidTable

Information about the application process group to be started. Its length is specified by gidCount. A maximum of 64 process groups are supported. The value must be a positive number.

gidCount

Number of application process groups to be started.

accessTokenId

Token ID for application process permission control.

apl

APL for application process permission control. The value contains a maximum of 32 bytes.

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

API

Description

CreateClient

Creates a client.

CloseClient

Closes a client.

ConnectSocket

Sends a connection request to the appspawn service.

WriteSocketMessage

Sends a message to the appspawn service.

ReadSocketMessage

Receives a message from the appspawn service.

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.