• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Overview of Cross-Application Data Sharing
2
3## Introduction
4
5OpenHarmony provides APIs for an application to manage its own data and share data with other applications.
6
7Data needs to be shared in a wealth of scenarios. For example, the Contacts, short message service (SMS), and Gallery data always needs to be shared with other applications. However, certain data, such as accounts and passwords, cannot be shared. Some data, such as SMS messages, can be queried but not modified by other applications. Therefore, a secure and efficient cross-application data sharing mechanism for different data sharing scenarios and data privacy protection is very important.
8
9Currently, OpenHarmony supports one-to-many and many-to-many cross-application data sharing, based on the number of the data provider applications involved.
10
11## Basic Concepts
12
13Before you start, understand the following concepts:
14
15- **Data provider**: an application that provides data and implements related services. It is also called the producer or server.
16
17- **Data consumer**: an application that accesses the data or services provided by the data provider. It is also called the client.
18
19- **ValuesBucket**: a set of data to be inserted. It can be one or more data records in key-value (KV) pairs. In each KV pair, the key must be of the string type, and the value can be a number, a string, a Boolean value, or an unsigned integer array.
20
21- **ResultSet**: a set of query results. It provides flexible modes for users to obtain various data.
22
23- **Predicates**: an object that specifies the conditions for updating, deleting, or querying data in a database.
24
25## One-to-Many Cross-Application Data Sharing
26
27You can use **DataShare** to implement one-to-many data sharing across applications. **DataShare** implements data sharing between data providers and data consumers. The following describes the implementation modes.
28
29### Implementation
30
31The data provider can directly use **DataShare** to share data with other applications without complex encapsulation. The data consumer only needs to use a set of APIs because the **DataShare** access mode does not vary with the data provision mode. This greatly reduces the learning time and development difficulty.
32
33**DataShare** implements cross-application data sharing in either of the following ways:
34
35<!--RP1-->
36- [Using DataShareExtensionAbility](share-data-by-datashareextensionability.md)
37
38  You need to implement an ExtensionAbility with callbacks in the HAP. When the data consumer calls an API, the ExtensionAbility of the data provider will be automatically started to invoke the registered callback.
39
40  You can use **DataShareExtensionAbility** when the cross-application data access involves service operations other than mere addition, deletion, modification, and query of data in databases.
41
42- [Using Silent Access via the DatamgrService](share-data-by-silent-access.md)
43
44  You need to configure database access rules in the HAP. When the data consumer calls an API, the system ability automatically obtains the access rules in the HAP and returns data without starting the data provider.
45
46  You can use this mode when the cross-application data access involves only database operations (data addition, deletion, modification, and query) or data hosted to the DatamgrService.
47<!--RP1End-->
48
49- [Sharing Configurations Between Applications](share-config.md)
50
51  You need to manage common configuration information in a centralized manner and share the configurations between different applications to improve collaboration efficiency.
52
53### Constraints
54
55- Currently, **dataShare** supports development based on the stage model only.
56<!--Del-->
57- **DataShare** is subject to the limitations on the database used by the data provider. For example, the supported data models, length of the keys and values, and maximum number of databases that can be accessed at a time by each application vary with the database in use.
58
59- The payloads of **ValuesBucket**, **Predicates**, and **ResultSet** are restricted by IPC.
60<!--DelEnd-->
61
62## Many-to-Many Cross-Application Data Sharing
63
64In one-to-many cross-application data sharing, there is only one data provider. In many-to-many cross-application data sharing, you need to consider data definition, data exchange, and permission management. The UDMF provides a new data sharing and interaction mode to implement many-to-many cross-application data sharing.
65
66### Implementation
67
68[Sharing Data via Unified Data Channels](unified-data-channels.md)
69
70Applications can call the APIs provided by the UDMF to write data that complies with the unified data definition to different data sharing channels of the UDMF. The data in these channels can be read by other applications. The data written into the UDMF is managed based on the permissions of the application, permissions of the data channels, and the permission management logic of the UDMF. Lifecycle management is also performed on the data written into the channels in the same way. In this way, the data scattered in each application is aggregated via different channels of the UDMF, improving the development efficiency and data experience of users.
71