Architecture and Design Considerations of Distributed Capabilities in HarmonyOS Next
In the HarmonyOS Next system, distributed capabilities are undoubtedly one of its core highlights. They enable efficient collaboration between different devices, bringing users a seamless cross-device experience. An in-depth analysis of this capability from the perspective of architecture design helps us better understand how it integrates with the existing system and how to fully leverage its advantages in application development.
Technical Architecture of Distributed Capabilities in HarmonyOS Next (How to Support Capabilities Such as Clipboard, Dragging, and Continuation)
The distributed capabilities of HarmonyOS Next rely on a carefully designed technical architecture, which mainly consists of key components such as the distributed framework, the soft bus, and device virtualization.
Distributed Framework
The distributed framework is the core component for implementing distributed capabilities. It provides unified management and scheduling for cross-device operations. In functions such as cross-device clipboard, dragging, and continuation, the distributed framework is responsible for coordinating data interaction and task scheduling between devices. For example, in the scenario of a cross-device clipboard, when a user copies data on device A, the distributed framework will assign the tasks of data processing and synchronization to the corresponding modules, ensuring that the data can be accurately transmitted to device B and correctly displayed in the clipboard of device B. In the scenario of application continuation, the distributed framework will manage the saving and restoration of the application state, ensuring that the user's operation state and data can be seamlessly connected when the application migrates between different devices.
Soft Bus
The soft bus is a bridge for communication between devices, providing a high-speed and stable data transmission channel. Whether it is the data synchronization of the cross-device clipboard, the file transfer in cross-device dragging, or the migration of the application state during application continuation, all rely on the soft bus to achieve. Through a unified interface, the soft bus masks the network differences and hardware characteristics between different devices, making the communication between devices simple and efficient. It adopts a series of optimization technologies, such as intelligent routing, data compression, and encryption, to ensure the speed and security of data transmission.
Device Virtualization
Device virtualization technology abstracts and integrates the resources of different devices, enabling developers to call the resources of other devices just like calling local resources. In cross-device dragging, through device virtualization, the source device can operate the dragged file or text as if it were a local resource, and the target device can receive these resources just like receiving local data, achieving seamless connection of cross-device operations. In application continuation, device virtualization enables the application to easily obtain the resources of the target device when it migrates between different devices, ensuring the normal operation of the application.
Underlying Implementations and Interaction Methods of Different Distributed Capabilities (API Call Chains, Data Transmission Protocols)
API Call Chains
-
Cross-device Clipboard: The application calls the APIs in the
@ohos.pasteboardmodule, such asgetSystemPasteboard()to obtain the system clipboard object, and then uses thesetData()andgetData()methods of this object to write and read data. In a cross-device scenario, these API calls will trigger the relevant logic of the distributed framework, and the distributed framework will interact with the soft bus to complete the data transmission between different devices. For example, whensetData()is called on device A, the distributed framework will encapsulate the data and send it to device B through the soft bus. After the distributed framework of device B receives the data, it will call the local clipboard API to write the data into the clipboard of device B. -
Cross-device Dragging: Developers enable the dragging function of a component by setting its
draggableproperty totrue. When the component is dragged, theonDragStartevent will be triggered, and developers can set the data to be transmitted in this event. During the data transmission process, the involved APIs will work in coordination with the distributed framework. The distributed framework uses the soft bus to transmit the data to the target device, and the target device processes the data through theonDropevent after receiving it. -
Application Continuation: In application continuation, the source-side UIAbility saves the data required for migration by implementing the
onContinue()interface, and the target-side UIAbility restores the data through theonCreate()oronNewWant()interface. The calls to these interfaces will trigger the application continuation logic in the distributed framework, and the distributed framework is responsible for managing the migration of the application state and the transmission of data, ensuring the seamless switching of the application between different devices.
Data Transmission Protocols
HarmonyOS Next adopts a self-developed data transmission protocol, which is optimized for distributed scenarios. During the data transmission process, the protocol will perform serialization and deserialization operations on the data, converting the data into a format suitable for network transmission and restoring the data on the target device. At the same time, in order to ensure the integrity and security of the data, the protocol also adopts checksum and encryption mechanisms. For example, in the data transmission of the cross-device clipboard, the data will be encapsulated into a specific format, including the data content, data type, and check information, etc. During the transmission process, the soft bus will send and receive the data according to the protocol. After the target device receives the data, it will perform verification and unpacking according to the protocol to ensure the accuracy of the data.
Optimizing the Distributed Experience from the Application Design Perspective (How to Improve the Flow Speed, Reduce Energy Consumption, and Enhance the User Experience)
Improving the Flow Speed
- Data Prefetching: In application design, data that may need to flow can be prefetched in advance according to the user's usage habits and scenarios. For example, in an email application, when it is detected that the user may transfer an email from a mobile phone to a tablet, the email attachments can be downloaded in advance to reduce the waiting time on the tablet.
- Optimizing Network Requests: Reasonably design the network request strategy of the application to reduce unnecessary network overhead. A caching mechanism can be adopted. For data that has already been flowed, when it is used again within a certain period of time, it is preferred to obtain it from the local cache to avoid repeatedly obtaining data from the network, thereby improving the flow speed.
Reducing Energy Consumption
- Intelligent Hibernation: When the device is in an idle state or low-power mode, the application can automatically adjust the running state of the distributed function, reducing unnecessary communication and data transmission between devices and reducing energy consumption. For example, when the device screen is turned off, the data synchronization function of the cross-device clipboard can be paused until the screen is turned on again.
- Optimizing Data Transmission Volume: Before data transmission, compress the data to reduce the data transmission volume. For example, when dragging a file across devices, appropriately compress the file, which can not only improve the transmission speed but also reduce energy consumption.
Enhancing the User Experience
- Real-time Feedback: During the distributed operation process, provide the user with operation feedback in a timely manner so that the user can understand the progress and status of the operation. For example, during application continuation, display a loading animation to inform the user that the application is migrating, avoiding the user's confusion and anxiety.
- Seamless Switch Design: In terms of interface design and interaction logic, ensure that the user can transition naturally when the application switches between different devices. For example, maintain the same interface style and operation habits of the application on different devices, so that the user does not feel the device switch during use.
The distributed capabilities of HarmonyOS Next provide developers with powerful cross-device development capabilities through a carefully designed technical architecture and underlying implementation. From the perspective of application design, we can give full play to the advantages of distributed capabilities by optimizing the flow speed, reducing energy consumption, and enhancing the user experience, bringing users a more convenient and efficient cross-device usage experience.
Top comments (0)