In-depth interpretation of the HarmonyOS distributed application framework

As more and more devices become more intelligent, application development in multi-device scenarios faces the following challenges: from the morphological differences of multiple devices (screens of different sizes, resolutions, and shapes, and diverse interaction methods—buttons, touch screen, keyboard, voice, gestures, etc.), the ability of multiple devices (memory from 100 KB to GB devices).

In response to the above challenges, HarmonyOS, as a brand-new distributed operating system for the era of the Internet of Everything, will be able to solve it. Thanks to the distributed application framework of HarmonyOS, these multiple devices form a hyperterminal and give full play to the capabilities of each device. Realize multi-device collaboration and cross-device migration, laying the foundation for the Internet of Everything.

The distributed application framework for HarmonyOS will be explained in depth in the following chapters.

1. HarmonyOS user program

The applications on the HarmonyOS system are divided into: HarmonyOS applications and atomization services. HarmonyOS applications need to be downloaded and installed in the application store just like traditional applications. Atomization services have independent operation entry, installation-free, and specific functions, which are better than WeChat applet functions. More powerful, coupled with the cross-device, distributed capabilities and applications of HarmonyOS, the two have unlimited capabilities.

From the developer's point of view, the basic components on HarmonyOS are divided into 3+1, of which 3 represents three capabilities, namely: PageAbility: responsible for the display of the user interface, DataAbility: responsible for data management, providing a unified data access abstraction to the outside world , ServiceAbility: responsible for tasks running in the background. 1 represents the AbilityForm service card, where important information or operations can be placed in order to achieve direct service and reduce experience levels. 3+1 components are combined to develop applications on HarmonyOS. The packaging format is HAP (HarmonyOS Ability Package). According to whether HAP has an interface, it is divided into two types: FA (Feature Ability) and PA (Particle Ability).

  1. HarmonyOS distributed application framework overall frame

From the perspective of the application framework, the system is divided into 5 layers, which are as follows:

The underlying software layer: including the kernel, HAL, and soft bus. This layer is not used by developers, and generally serves developers and users silently.

Basic service layer: including distributed scheduling management, distributed data management, distributed hardware management, and distributed authority management.

Core service layer: including global package management, distributed operation management, and global package management: applications on HarmonyOS are no longer limited to a single device, and package management also includes all devices across virtual terminals. Distributed runtime management is responsible for application dynamic runtime management, including collaboration framework, migration framework, and service card framework.

Application interface layer: It is the interface layer provided by the system to developers to develop applications. No matter how complex the underlying implementation of the system is, the interface provided to developers is as simple as possible. This layer includes the basic components mentioned earlier, as well as the ACE (Ability Cross-platform Environment) framework. In the multi-device interaction model, consistency is very important. From the UI perspective, how to adapt the UI framework to large screens, small screens, Long screen, square screen, horizontal screen, etc. This consistency is largely supported by the ACE framework.

User program layer: This layer is the application developed by the majority of developers for users to use.

  1. HarmonyOS distributed application framework running view

This is the view of the application framework at runtime. At runtime, each application is in an independent sandbox, isolated from each other and does not affect each other, which ensures the security of the system. The system includes AppSpawn for process incubation, AppMS for process management, BMS (Bundle Manager Service) for package management, AMS (Ability Manager Service) for basic component management, and DMS (Distributed Manager Service) for distributed business management. , is a dedicated low-level service. Many of our upper-level services have distributed services. Through it, a connected business is unified. Its main responsibilities include distributed task management, cross-device status and data synchronization.

  1. HarmonyOS distributed operation: multi-terminal collaboration

Multi-terminal collaboration is to allow our application to complete a business on multiple terminals. At this time, the system framework provides three capabilities to the application. The first cross-device component starts, and with this capability, a concurrency can be accomplished. The second is cross-device data transfer, and business collaboration is performed via a connection channel. The third is that distributed shared objects allow you to automatically synchronize state between two or more devices.

The code snippet in the upper right corner emphasizes a connection. In fact, it seems natural to provide a connection at the system level, but it is very complicated behind it. The devices on HarmonyOS span various types of devices from small to medium to large. The types of their chips are different, and their connection methods are also different. There may be WI-FI, Bluetooth, etc. This connection is wireless and often interferes. This connection also needs to shake the underlying network. to filter out.

Based on the multi-terminal collaboration framework, developers can develop applications that span multiple devices. For example: You can develop an application for watching videos on the pad, so that you can use the mobile phone to comment and reply to the video, and conduct a cross-end business, so that you can achieve concurrency, collaboration, and complementarity.

  1. HarmonyOS Distributed Operations: Cross-End Migration

The task management center on HarmonyOS can manage all the tasks on the super terminal on one terminal. With this task management center, a task can be easily migrated from the mobile phone to the large screen. This process is a connection between the developer and the system. The system itself gets a state through the task management center and through the application, and the application itself passes the state to the system through callbacks. This state is passed between systems, and developers don’t need to care. With the help of the migration framework, a continuous and consistent system is created for users. Effect.

  1. HarmonyOS Basic Architecture: Distributed Window Management

Whether it is multi-terminal collaboration or cross-terminal migration, when the user drags in the task center, the system will pull the dragged task window into a virtual window for rendering, and pass the rendering result to the target proxy window to fill it, not only One of the video streams is transmitted, and the user's interaction events are sent back to the original application. There are existing multi-mode and unified interaction modules in the system, which are actually invisible to the application. It is unknown whether the event comes from the local end or another. one end.

  1. HarmonyOS Basic Architecture: Distributed Hardware

Today's devices contain a lot of hardware and peripherals, such as cameras and microphones, including various sensors, such as a watch that monitors sleep, daily walking, and other health status every day. If these devices are limited to only one device Using that is a huge limitation. Therefore, in the programming of the distributed environment, the system provides two capabilities from the perspective of hardware. The first is global virtualization, which pools all hardware peripherals connected to the HyperTerminal globally, which can be provided to developers. This is because hardware is often privacy-related, and the system has opened up these underlying capabilities through unified global virtualization. .

Then the second is the automatic follow-up of the hardware. Our software is not limited to one device. It may be migrated from one device to another device. For example, when a sound is playing at this time, for example, when we are video chatting with others at this time, then these The hardware is automatically migrated along with it, and the combination of the application framework and the underlying distributed hardware accomplishes such a thing, reducing the burden on developers.

——————

Original: Lao Wang丨[Public Account: Hongmeng Developer Laowang] Huawei Certified Instructor / Tencent Certified Instructor / Hongmeng Development Pioneer

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324360537&siteId=291194637