The Utils library stores common basic components of OpenHarmony. These basic components can be used by OpenHarmony service subsystems and upper-layer applications.
The Utils library provides the following capabilities on different platforms:
LiteOS Cortex-M \(Hi3861 platform\): KV store, file operations, IoT peripheral control, and system attribute dumping
LiteOS Cortex-A \(Hi3516 or Hi3518 platform\): KV store, timer, JavaScript APIs for data and file storage, and system attribute dumping
## 1. Failure in running the KV store on the LiteOS Cortex-A kernel \(Hi3516 or Hi3518\) due to incorrect path setting for the KV store<a name="section2041345718513"></a>
**Problem**
When the LiteOS Cortex-A kernel \(Hi3516 or Hi3518 platform\) directly calls the API provided by the KV store, the compiled executable program fails to run.
**Possible Causes**
The compiled executable program is run directly without being converted to an application using **AbilityKit** APIs. In this case, the Bundle Manager Service \(BMS\) cannot correctly set the path for storing application data during application installation. As a result, the KV store fails to run.
**Solution**
Call the **UtilsSetEnv** function of the KV store to set the data storage path.
<tbody><trid="row671818445506"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p871814441501"><aname="p871814441501"></a><aname="p871814441501"></a>int UtilsFileOpen(const char* path, int oflag, int mode)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p127181444165016"><aname="p127181444165016"></a><aname="p127181444165016"></a>Opens or creates a file.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p1071884416504"><aname="p1071884416504"></a><aname="p1071884416504"></a>Closes a file with a specified file descriptor.</p>
</td>
</tr>
<trid="row6718744105017"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p137181644145015"><aname="p137181644145015"></a><aname="p137181644145015"></a>int UtilsFileRead(int fd, char *buf, unsigned int len)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p1171854410509"><aname="p1171854410509"></a><aname="p1171854410509"></a>Reads a specified length of data from a file with the specified file descriptor and writes the data into the buffer.</p>
</td>
</tr>
<trid="row2071817440509"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p17718144465012"><aname="p17718144465012"></a><aname="p17718144465012"></a>int UtilsFileWrite(int fd, const char *buf, unsigned int len)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p67191444145012"><aname="p67191444145012"></a><aname="p67191444145012"></a>Writes a specified length of data into a file with the specified file descriptor.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p2071919446507"><aname="p2071919446507"></a><aname="p2071919446507"></a>Deletes a specified file.</p>
</td>
</tr>
<trid="row1071964425013"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p20719114405010"><aname="p20719114405010"></a><aname="p20719114405010"></a>int UtilsFileStat(const char *path, unsigned int *fileSize)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p8719144435015"><aname="p8719144435015"></a><aname="p8719144435015"></a>Obtains the file size.</p>
</td>
</tr>
<trid="row2071924417504"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p57193447501"><aname="p57193447501"></a><aname="p57193447501"></a>int UtilsFileSeek(int fd, int offset, unsigned int whence)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p1071934495014"><aname="p1071934495014"></a><aname="p1071934495014"></a>Adjusts the read and write position offset in a file.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p113501041155511"><aname="p113501041155511"></a><aname="p113501041155511"></a>Copies the source file to a target file.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p921744595517"><aname="p921744595517"></a><aname="p921744595517"></a>Moves the source file into a target file.</p>
<tbody><trid="row34145016535"><tdclass="cellrowborder"valign="top"width="57.38999999999999%"headers="mcps1.2.3.1.1 "><pid="p980953910190"><aname="p980953910190"></a><aname="p980953910190"></a>int UtilsGetValue(const char* key, char* value, unsigned int len)</p>
</td>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p13562171015712"><aname="p13562171015712"></a><aname="p13562171015712"></a>Obtains the value matching a specified key from the file system or cache.</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p2431455765"><aname="p2431455765"></a><aname="p2431455765"></a>Adds or updates the value matching a specified key in the file system or cache.</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p126575774517"><aname="p126575774517"></a><aname="p126575774517"></a>Deletes the value matching a specified key from the file system or cache.</p>
</td>
</tr>
</tbody>
</table>
Sample code for the KV store:
```
// Set the value matching the specified key.
char key[] = "rw.sys.version_100";
char value[] = "Hello kv operation implement!";
int ret = UtilsSetValue(key, value);
printf("UtilsSetValue set ret = %d\n", ret);
// Obtain the value matching the specified key.
char temp[128] = {0};
ret = UtilsGetValue(key, temp, 128);
printf("UtilsGetValue get ret = %d, temp = %s\n", ret, temp);
// Delete the value matching the specified key.
ret = UtilsDeleteValue(key);
printf("UtilsDeleteValue delete ret = %d\n", ret);
```
## How to Develop<a name="section17450172710292"></a>
### Developing a Native Application for the KV Store That Uses the LiteOS Cortex-A Kernel \(Hi3516 or Hi3518\)<a name="section258354119295"></a>
1. Develop the native application for the KV store using **AbilityKit** APIs.
- Write the user program by calling the APIs provided by the KV store and compile the **libLauncher.so** file.
```
// Set the value matching the specified key.
char key[] = "rw.sys.version_100";
char value[] = "Hello kv operation implement!";
int ret = UtilsSetValue(key, value);
printf("UtilsSetValue set ret = %d\n", ret);
// Obtain the value matching the specified key.
char temp[128] = {0};
ret = UtilsGetValue(key, temp, 128);
printf("UtilsGetValue get ret = %d, temp = %s\n", ret, temp);
// Delete the value matching the specified key.
ret = UtilsDeleteValue(key);
printf("UtilsDeleteValue delete ret = %d\n", ret);
- Add resource files in the **res/drawable** directory based on the following directory structure.

- Compress the **libLauncher.so**, **config.json**, and resource files into a ZIP package and change the file name extension to **.hap**, for example, **Launcher.hap**.
2. Connect the development board and send the command for installing the native KV store application to the board through the serial port.
This document provides development guidelines related to the telephony subsystem, including modem vendor library integration, initialization, service request responding, and modem event reporting. It is intended as a reference for developers of different modem chips, helping them efficiently develop telephony service-related functions.
## Basic Concepts<a name="section187mcpsimp"></a>
- Telephony Service: core service layer of the telephony subsystem. Its main functions are as follows:
- Initializes the RIL Manager module, SIM card module, and network search modules.
- Provides access to the RIL Adapter service, and implements communication with RIL Adapter by registering the callback service.
- Implements communication between modules, such as the call module and SMS module, by subscribing to callbacks.
- RIL Adapter: RIL adaptation layer of the Telephony subsystem. This layer provides functions such as vendor library loading and service API implementation. It shields the differences of modems supplied by different vendors to provide a unified API for the telephony service layer. It communicates with the telephony service layer by registering the Hardware Driver Foundation \(HDF\) service.
- HDF: Hardware Driver Foundation, which allows for unified access from peripheral devices and provides a framework for driver development and management.
- hdc\_std: OpenHarmony Device Connector, a command line tool provided by OpenHarmony for developers to debug device connectivity.
## Working Principles<a name="section194mcpsimp"></a>
As shown in the preceding figure, RIL Adapter is logically divided into three layers: **hril\_hdf**, **hril**, and **vendorlib**.
-**hril\_hdf**: unique entry of RIL Adapter. The main function of this layer is to load modem vendor library files. Wherein, **modem\_adapter** enables a single firmware to adapt to different modems.
Specifically, **hril\_hdf** obtains the modem type from the kernel and then loads the target modem vendor library based on the modem type.
-**hril**: OpenHarmony Radio Interface Layer, which provides APIs for communication between the **vendorlib** and various Telephony Service modules, including the SIM card, network search, cellular call, cellular data, and SMS/MMS modules.
-**vendorlib**: Modem vendor library file. Different modem vendor libraries are developed based on standard APIs or service request IDs provided by RIL Adapter. \(**vendorlib** is provided by modem vendors.\)
After **hril\_hdf** is executed, **vendorlib** is dynamically loaded so that it can obtain the pointers to the response processing and event reporting functions from **hril\_hdf**. After this process is complete, **hril\_hdf** can communicate with a modem through **vendorlib**.
## Constraints<a name="section205mcpsimp"></a>
**Specifications**
At least one modem must be supported by a device vendor. If no modem is supported, **vendorlib** APIs do not need to be implemented.