# OpenHarmony **Repository Path**: miracle__cc/open-harmony ## Basic Information - **Project Name**: OpenHarmony - **Description**: 了解OpenHarmony并移植再使用的记录 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: develop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-11-17 - **Last Updated**: 2022-06-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OpenHarmony ## 介绍 了解OpenHarmony并移植再使用的记录 ## OpenHarmony官方 Gitee仓库:https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/OpenHarmony-v3.0-LTS.md HarmonyOS Device站点:https://device.harmonyos.com/cn/home 全量代码下载:(HarmonyOS Device站点 文档-入门-源码获取:"获取方式3:从镜像站点获取") https://repo.huaweicloud.com/harmonyos/os/3.0/code-v3.0-LTS.tar.gz ## 了解 ## NOTICE: 修改自 OpenHarmonyOS Standard(Linux) ## NOTICE: "不能愉快地玩 !!!(看这种代码是很痛苦的事情,特别是好的框架下却是烂代码的情况)" ### 5. launcher运行 foundation/aafwk/standard/services/abilitymgr/include/ability_config.h:47:const std::string LAUNCHER_ABILITY_NAME = "com.ohos.launcher.MainAbility"; foundation/aafwk/standard/services/abilitymgr/include/ability_config.h:48:const std::string LAUNCHER_BUNDLE_NAME = "com.ohos.launcher"; AbilityManagerService::StartingLauncherAbility() want.SetElementName(AbilityConfig::LAUNCHER_BUNDLE_NAME, AbilityConfig::LAUNCHER_ABILITY_NAME); <-- AbilityManagerService::StartSystemApplication() <-- AbilityManagerService::Init() auto startLauncherAbilityTask = [aams = shared_from_this()]() { aams->StartSystemApplication(); }; <-- AbilityManagerService::OnStart() override SystemAbility::OnStart() <-- SystemAbility::Start() ... <-- load and start ams AmsConfigurationParameter read /system/etc/ams_service_config.json AMS connect BMS APPMS foundation/aafwk/standard/README_zh.md: Ability是系统调度应用的最小单元,是能够完成一个独立功能的组件,一个应用可以包含一个或多个Ability。 Ability分为FA(Feature Ability)和PA(Particle Ability)两种类,其中FA支持Page Ability,PA支持Service Ability和Data Ability。 - Ability管理服务(AbilityManagerServicei)用于协调各Ability运行关系、及对生命周期进行调度的系统服务。 - Ability栈管理模块(AbilityStackManager)负责维护各个Ability之间跳转的先后关系。 - 连接管理模块(AbilityConnectManager)是Ability管理服务对Service类型Ability连接管理的模块。 - 数据管理模块(DataAbilityManager)是Ability管理服务对Data类型Ability管理的模块。 - App管理服务调度模块(AppScheduler)提供Ability管理服务对用户程序管理服务进行调度管理的能力。 - Ability调度模块(AbilityScheduler)提供对Ability进行调度管理的能力。 - 生命周期调度模块(LifecycleDeal)是Ability管理服务对Ability的生命周期事件进行管理调度的模块。 BundleManagerService BMS (Bundle Data Mgr) (BMSEventHandler::BUNDLE_SCAN_START) === design location (自己定义) (1) rootfs(inc system) + user + data rootfs mount at / user mount at /user data mount at /data (2) rootfs + system + user + data rootfs mount at / system mount at /system user mount at /user data mount at /data system app at /system/app system app data at /data/system user app at /user/app user app data at /data/user APP_INSTALL_PATH /data/accounts write into base/foundation/bms/base_bundle_installer.h nlohmann/json.hpp 单个头文件的c++ json库使用 Whenever you want to convert a type T to/from JSON, you need to define in the namespace of T a to_json/from_json function. The conversions work recursively. So if T contains a member of type U, and a conversion is defined for U, then in the conversion for T you can just write something like j["my_U_member"] = t.u;. You do not need to care about STL containers - you get std::vector or std::set for free. If you want to access private members, you need to make the conversion functions friend. 使用OpenSSL PEM_read_bio_X509 解析 出现 free(): invalid next size (fast): 0x0000007fa401b140 *** 使用官方openssl3.0重新编译 MetaData 在AbilityInfo中时,使用 AbilityInfo 的from_json,在configJson中时,为区分才添加了 namespace ProfileReader { from_json( MetaData) } BMS connect Installd, Installd 需要chown等操作,只能设置为root:root,因此,Install功能需要单独拿出,不能合并进BMS launcher.hap 安装后 /data/system/accounts/account_0/applications/com.ohos.launcher/com.ohos.launcher .hap的内容 /data/system/accounts/account_0/appdata/com.ohos.launcher/下 drwxr-xr-x 2 19192484 root 0 Jan 1 12:48 cache drwxr-xr-x 4 root root 0 Jan 1 12:48 com.ohos.launcher drwxr-xr-x 2 19192484 root 0 Jan 1 12:48 database drwxr-xr-x 2 19192484 root 0 Jan 1 12:48 files drwxr-xr-x 2 19192484 root 0 Jan 1 12:48 sharedPreference /data/system/accounts/account_0/appdata/com.ohos.launcher/com.ohos.launcher/com.ohos.launcher.MainAbility/下 drwxr-xr-x 2 2100 2100 0 Jan 1 12:48 cache drwxr-xr-x 2 2100 2100 0 Jan 1 12:48 database drwxr-xr-x 2 2100 2100 0 Jan 1 12:48 files drwxr-xr-x 2 2100 2100 0 Jan 1 12:48 sharedPreference IPC通信 非数据类型 如何传输 ? Android 实现了Parcelable来二进制序列化 OpenHarmony也是Parcelable,可能是相同的实现(这里参考,实现简易的序列化) utils/native/base/include/parcel.h utils/native/base/src/parcel.cpp AMS connect APPMGR, APPMGR connect AppSpawn .hap中包含描述文件config.json { "app": { "apiVersion": { "compatible": 4,"releaseType": "Beta1","target": 7 }, "vendor": "ohos", "bundleName": "com.ohos.launcher", "version": {"code": 1000000,"name": "1.0.0"} }, "deviceConfig": {}, "module": { "abilities": [{ "iconId": 83886092, "visible": true, "icon": "$media:icon", "description": "$string:mainability_description", "label": "$string:entry_MainAbility", "type": "page", "homeAbility": true, "skills": [{ "entities": [ "entity.system.home", "flag.home.intent.from.system" ], "actions": [ "action.system.home", "com.ohos.action.main" ] }], "metaData": { "customizeData": [{ "name": "hwc-theme" }] }, "descriptionId": 83886088, "labelId": 83886083, "name": "com.ohos.launcher.MainAbility", "launchType": "singleton" }], "deviceType": ["phone"], "distro": {"moduleType": "entry","installationFree": true,"deliveryWithInstall": true,"moduleName": "phone"}, "package": "com.ohos.launcher", "name": ".MyApplication", "js": [{ "mode": { "syntax": "ets", "type": "pageAbility" }, "pages": ["pages/EntryView"], "name": "default", "window": {"designWidth": 720,"autoDesignWidth": false} }] } } start Launcher --> AppSpawn fork a child, child use MainThread::Start(), call ConnectToAppMgr() {AttachApplication} [now use myipc, mainthread is service(use appid), APPMGR is its client], APPMGR AttachApplication -> app_running_record -> app_lifecycle_deal -> call child ScheduleLaunchApplication child do ScheduleLaunchApplication ScheduleLaunchApplication, then ScheduleLaunchAbility, AbilityLoader PAGE need AceAbility(libace.z.so) start launcher ability, (abilitythread) attach() call AbilityMgr.AttachAbilityThread [now use myipc, ability is service(use threadid), AbilityMgr is its client] call APPMGR do Foreground -> -> app_running_record -> app_lifecycle_deal -> call child ScheduleForegroundRunning ## 错综复杂的关系还在继续。。。。。。 ![输入图片说明](%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE%202021-12-16%20072841.jpg)