diff --git a/README.en.md b/README.en.md index 1b57e89b92d73492261975d2ceeef0cfe3262632..3fdf8e6498e23241deefdf81bfa409ec12b5a564 100644 --- a/README.en.md +++ b/README.en.md @@ -92,5 +92,3 @@ export OHOS_SDK_HOME= 3. The har file output path is: shell/platform/ohos/flutter_embedding/flutter/build ps: If you are using the Beta version of DevEco Studio and encounter the error "must have required property 'compatibleSdkVersion', location: build-profile.json5:17:11" when compiling the project, please refer to the "DevEco Studio Environment Configuration Guide." docx》Chapter '6 Creating Projects and Running Hello World' [Configuration Plugin] Modify the shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 file. - -[hvigor-dependencies-config](shell/platform/ohos/flutter_embedding/dependencies/hvigor-dependencies-config.md) diff --git a/README.md b/README.md index 5cb27d599c6e68ef28d28da501eef57e066c26d8..e19e793031e61cc34fabd0d8f19e20f7b4315c8f 100644 --- a/README.md +++ b/README.md @@ -94,5 +94,3 @@ export OHOS_SDK_HOME= 3. har文件输出路径为:shell/platform/ohos/flutter_embedding/flutter/build ps:如果你使用的是DevEco Studio的Beta版本,编译工程时遇到“must have required property 'compatibleSdkVersion', location: build-profile.json5:17:11"错误,请参考《DevEco Studio环境配置指导.docx》中的‘6 创建工程和运行Hello World’【配置插件】章节修改 shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5文件。 - -[hvigor本地依赖配置](shell/platform/ohos/flutter_embedding/dependencies/hvigor-dependencies-config.md) diff --git a/attachment/repos/bootstrap/ohos.py b/attachment/repos/bootstrap/ohos.py index 21022e045442452b15fc086c37bfb8571471c03e..f59d783c8f207ffc1e786e32be9df2112d955091 100644 --- a/attachment/repos/bootstrap/ohos.py +++ b/attachment/repos/bootstrap/ohos.py @@ -315,17 +315,9 @@ def zipFiles(buildInfo, useZip2=False): TIME_STR, ) prefixInZip = os.path.join("src", "out", outputName) + excludes = ["obj", "exe.unstripped", "so.unstripped"] if IS_WINDOWS: - excludes = [ - ".*\.ilk", - ".*\.pdb", - ] - else: - excludes = [ - "obj", - "exe.unstripped", - "so.unstripped", - ] + excludes.extend([".*\.ilk", ".*\.pdb"]) zipFileDir(fileIn, fileName, prefixInZip, excludes=excludes, useZip2=useZip2) diff --git a/attachment/repos/build.patch b/attachment/repos/build.patch index c3df91e35fb66e5af9b41004b66ad0e6af1f644f..7dd52e5b16332809ddd85dcf3a179af9737c7778 100644 --- a/attachment/repos/build.patch +++ b/attachment/repos/build.patch @@ -12,18 +12,10 @@ index 4e62965..ea49a53 100644 libs = [ "dl" ] } diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn -index b8d0f47..d789796 100644 +index b8d0f47..a3d1ed9 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn -@@ -34,6 +34,7 @@ - # When writing build files, to do something only for the host: - # if (current_toolchain == host_toolchain) { ... - -+ - if (target_os == "") { - target_os = host_os - } -@@ -190,6 +191,7 @@ if (current_os == "win") { +@@ -190,6 +190,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -31,7 +23,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = false is_win = true -@@ -198,6 +200,7 @@ if (current_os == "win") { +@@ -198,6 +199,7 @@ if (current_os == "win") { is_android = false is_chromeos = false is_fuchsia = false @@ -39,7 +31,7 @@ index b8d0f47..d789796 100644 is_fuchsia_host = false is_ios = false is_linux = false -@@ -212,6 +215,7 @@ if (current_os == "win") { +@@ -212,6 +214,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -47,7 +39,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -223,6 +227,7 @@ if (current_os == "win") { +@@ -223,6 +226,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = true @@ -55,7 +47,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -237,6 +242,7 @@ if (current_os == "win") { +@@ -237,6 +241,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -63,7 +55,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -248,6 +254,19 @@ if (current_os == "win") { +@@ -248,6 +253,19 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = true is_linux = false @@ -83,7 +75,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -259,6 +278,7 @@ if (current_os == "win") { +@@ -259,6 +277,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = true @@ -91,7 +83,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -270,6 +290,7 @@ if (current_os == "win") { +@@ -270,6 +289,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -99,7 +91,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -281,6 +302,7 @@ if (current_os == "win") { +@@ -281,6 +301,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -107,7 +99,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = false is_win = false -@@ -313,7 +335,7 @@ if (!is_clang && using_sanitizer) { +@@ -313,7 +334,7 @@ if (!is_clang && using_sanitizer) { is_clang = true } @@ -116,18 +108,18 @@ index b8d0f47..d789796 100644 if (is_msan && !is_linux) { assert(false, "Memory sanitizer is only available on Linux.") -@@ -365,7 +387,9 @@ if (is_posix) { +@@ -365,7 +386,9 @@ if (is_posix) { ] } -if (is_linux) { -+if(is_ohos || (is_linux && host_os == "mac")){ ++if (is_ohos || (is_linux && host_os == "mac")) { + _native_compiler_configs += [ "//build/config/ohos:sdk" ] -+ }else if (is_linux) { ++} else if (is_linux) { _native_compiler_configs += [ "//build/config/linux:sdk" ] } else if (is_mac) { _native_compiler_configs += [ "//build/config/mac:sdk" ] -@@ -510,8 +534,18 @@ shlib_toolchain = false +@@ -510,8 +533,18 @@ shlib_toolchain = false if (custom_toolchain != "") { assert(custom_sysroot != "") assert(custom_target_triple != "") @@ -147,22 +139,20 @@ index b8d0f47..d789796 100644 } else if (is_win) { if (is_clang) { host_toolchain = "//build/toolchain/win:clang_$host_cpu" -@@ -544,6 +578,21 @@ if (custom_toolchain != "") { +@@ -544,6 +577,19 @@ if (custom_toolchain != "") { } else { set_default_toolchain("//build/toolchain/android:$current_cpu") } +} else if (is_ohos) { ++ set_default_toolchain("//build/toolchain/custom") + if (host_os == "linux") { + if (is_clang) { + host_toolchain = "//build/toolchain/linux:clang_$host_cpu" -+ set_default_toolchain("//build/toolchain/linux:clang_$current_cpu") + } else { + host_toolchain = "//build/toolchain/linux:$host_cpu" -+ set_default_toolchain("//build/toolchain/linux:$current_cpu") + } + } else if (host_os == "mac") { + host_toolchain = "//build/toolchain/mac:clang_$host_cpu" -+ set_default_toolchain("//build/toolchain/ohos:clang_$current_cpu") + } else { + assert(false, "Unknown host for ohos cross compile") + } @@ -170,10 +160,10 @@ index b8d0f47..d789796 100644 if (is_clang) { host_toolchain = "//build/toolchain/linux:clang_$host_cpu" diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn -index ba20010..24a7d4e 100644 +index ba20010..67371f5 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn -@@ -191,11 +191,18 @@ config("compiler") { +@@ -191,10 +191,16 @@ config("compiler") { # CPU architecture. We may or may not be doing a cross compile now, so for # simplicity we always explicitly set the architecture. if (current_cpu == "x64") { @@ -181,61 +171,64 @@ index ba20010..24a7d4e 100644 - "-m64", - "-march=x86-64", - ] -+ if ( is_ohos ){ ++ if (is_ohos) { + cflags += [ + "-m64", + ] -+ }else { ++ } else { + cflags += [ + "-m64", + "-march=x86-64", + ] + } ldflags += [ "-m64" ] -+ } else if (current_cpu == "x86") { cflags += [ "-m32" ] - ldflags += [ "-m32" ] -@@ -315,7 +322,7 @@ config("compiler") { +@@ -315,7 +321,7 @@ config("compiler") { # Linux/Android common flags setup. # --------------------------------- - if (is_linux || is_android) { -+ if (is_linux || is_android || is_ohos ) { ++ if (is_linux || is_android || is_ohos) { cflags += [ "-fPIC", "-pipe", # Use pipes for communicating between sub-processes. Faster. -@@ -334,7 +341,16 @@ config("compiler") { +@@ -334,7 +340,16 @@ config("compiler") { # Linux-specific compiler flags setup. # ------------------------------------ - if (is_linux) { -+ if (is_ohos ) { ++ if (is_ohos) { + cflags += [ "-pthread" ] + ldflags += [ "-pthread" ] + + if (current_cpu == "arm64") { -+ cflags += [ "--target=aarch64-linux-ohos" ] -+ ldflags += [ "--target=aarch64-linux-ohos" ] ++ cflags += [ "--target=aarch64-linux-ohos" ] ++ ldflags += [ "--target=aarch64-linux-ohos" ] + cflags += [ "-DBORINGSSL_CLANG_SUPPORTS_DOT_ARCH" ] + } -+ }else if (is_linux ) { ++ } else if (is_linux) { cflags += [ "-pthread" ] ldflags += [ "-pthread" ] -@@ -521,8 +537,8 @@ config("runtime_library") { +@@ -521,9 +536,13 @@ config("runtime_library") { ldflags += [ "-nostdlib++" ] } include_dirs = [ - "//third_party/libcxx/include", "//third_party/libcxxabi/include", -+ "$custom_toolchain/include/c++/v1", ] ++ if (custom_toolchain != "") { ++ include_dirs += [ "$custom_toolchain/include/c++/v1" ] ++ } else { ++ include_dirs += [ "//third_party/libcxx/include" ] ++ } } + # Android standard library setup. diff --git a/build/config/ohos/BUILD.gn b/build/config/ohos/BUILD.gn new file mode 100644 -index 0000000..1d29b40 +index 0000000..b2675d2 --- /dev/null +++ b/build/config/ohos/BUILD.gn @@ -0,0 +1,29 @@ @@ -243,6 +236,7 @@ index 0000000..1d29b40 +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + ++import("//build/config/ohos/config.gni") +import("//build/config/ohos/pkg_config.gni") +import("//build/config/features.gni") +import("//build/config/sysroot.gni") @@ -267,7 +261,25 @@ index 0000000..1d29b40 +config("fontconfig") { + libs = [ ] +} +diff --git a/build/config/ohos/config.gni b/build/config/ohos/config.gni +new file mode 100644 +index 0000000..0022d70 +--- /dev/null ++++ b/build/config/ohos/config.gni +@@ -0,0 +1,13 @@ ++# Copyright 2014 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + ++# This file contains common system config stuff for the Ohos build. ++ ++if (is_ohos) { ++ if (current_cpu == "arm64") { ++ ohos_app_abi = "arm64-v8a" ++ } else { ++ assert(false, "Unknown Ohos ABI: " + current_cpu) ++ } ++} diff --git a/build/config/ohos/pkg-config.py b/build/config/ohos/pkg-config.py new file mode 100644 index 0000000..b4a6aff @@ -703,6 +715,145 @@ index 7987e51..cd7b060 100644 if (current_cpu == "x64") { sysroot = rebase_path("//build/linux/debian_sid_amd64-sysroot") } else { +diff --git a/build/ohos/ohos_create_flutter_har.py b/build/ohos/ohos_create_flutter_har.py +new file mode 100644 +index 0000000..fc46359 +--- /dev/null ++++ b/build/ohos/ohos_create_flutter_har.py +@@ -0,0 +1,133 @@ ++#!/usr/bin/env python3 ++# ++# Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++ ++"""Create a HAR incorporating all the components required to build a Flutter application""" ++ ++import argparse ++import logging ++import os ++import re ++import shutil ++import subprocess ++import sys ++ ++ ++HAR_CONFIG_TEMPLATE = """ ++{ ++ "app": { ++ "signingConfigs": [], ++ "products": [ ++ { ++ "name": "default", ++ "signingConfig": "default", ++ "compileSdkVersion": "%s", ++ "compatibleSdkVersion": "%s", ++ "runtimeOS": "HarmonyOS", ++ } ++ ], ++ "buildModeSet": [ ++ { ++ "name": "debug", ++ }, ++ { ++ "name": "release" ++ }, ++ { ++ "name": "profile" ++ }, ++ ] ++ }, ++ "modules": [ ++ { ++ "name": "flutter", ++ "srcPath": "./flutter" ++ } ++ ] ++} ++""" ++ ++ ++# 更新har的配置文件,指定编译使用的api版本 ++def updateConfig(buildDir, apiInt): ++ apiStr = "4.1.0(11)" if apiInt == 11 else "4.0.0(10)" ++ jsonFile = os.path.join(buildDir, "build-profile.json5") ++ with open(jsonFile, "w", encoding="utf-8") as file: ++ file.write(HAR_CONFIG_TEMPLATE % (apiStr, apiStr)) ++ ++ ++# 执行命令 ++def runCommand(command, checkCode=True, timeout=None): ++ logging.info("runCommand start, command = %s" % (command)) ++ code = subprocess.Popen(command, shell=True).wait(timeout) ++ if code != 0: ++ logging.error("runCommand error, code = %s, command = %s" % (code, command)) ++ if checkCode: ++ exit(code) ++ else: ++ logging.info("runCommand finish, code = %s, command = %s" % (code, command)) ++ ++ ++# 编译har文件,通过hvigorw的命令行参数指定编译类型(debug/release/profile) ++def buildHar(buildDir, apiInt, buildType): ++ updateConfig(buildDir, apiInt) ++ runCommand( ++ "cd %s && .%shvigorw clean --mode module " % (buildDir, os.sep) ++ + "-p module=flutter@default -p product=default -p buildMode=%s " % buildType ++ + "assembleHar --no-daemon" ++ ) ++ ++ ++def main(): ++ parser = argparse.ArgumentParser() ++ parser.add_argument("--embedding_src", help="Path of embedding source code.") ++ parser.add_argument("--build_dir", help="Path to build.") ++ parser.add_argument( ++ "--build_type", ++ choices=["debug", "release", "profile"], ++ help="Type to build har.", ++ ) ++ parser.add_argument("--output", help="Path to output har.") ++ parser.add_argument("--native_lib", action="append", help="Native code library.") ++ parser.add_argument("--ohos_abi", help="Native code ABI.") ++ parser.add_argument( ++ "--ohos_api_int", type=int, choices=[10, 11], help="Ohos api int." ++ ) ++ options = parser.parse_args() ++ # copy source code ++ if os.path.exists(options.build_dir): ++ shutil.rmtree(options.build_dir) ++ shutil.copytree(options.embedding_src, options.build_dir) ++ ++ # copy so files ++ for file in options.native_lib: ++ dir_name, full_file_name = os.path.split(file) ++ targetDir = os.path.join(options.build_dir, "flutter/libs", options.ohos_abi) ++ if not os.path.exists(targetDir): ++ os.makedirs(targetDir) ++ shutil.copyfile( ++ file, ++ os.path.join(targetDir, full_file_name), ++ ) ++ buildHar(options.build_dir, options.ohos_api_int, options.build_type) ++ shutil.copyfile( ++ os.path.join( ++ options.build_dir, "flutter/build/default/outputs/default/flutter.har" ++ ), ++ options.output, ++ ) ++ ++ ++if __name__ == "__main__": ++ sys.exit(main()) diff --git a/build/ohos/sysroot_ld_path.sh b/build/ohos/sysroot_ld_path.sh new file mode 100755 index 0000000..4b8bf73 diff --git a/attachment/repos/skia.patch b/attachment/repos/skia.patch index 455594c1ba654eb1d776fe23ed272fe9cdcd9a1d..d993bdffa7bae8ef54f07c45fbb2824284ef191c 100644 --- a/attachment/repos/skia.patch +++ b/attachment/repos/skia.patch @@ -327,59 +327,6 @@ index b43526fe1f..fb34289da7 100644 ldflags = [ "-rdynamic", "-Wl,-rpath,\$ORIGIN", -diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp -index ab23b24edd..c5f714712b 100644 ---- a/src/core/SkCanvas.cpp -+++ b/src/core/SkCanvas.cpp -@@ -82,6 +82,16 @@ static_assert(std::max(3,4) == 4); - - using Slug = sktext::gpu::Slug; - -+#ifdef TARGET_OS_OHOS -+#include -+#define SKIA_LOG_INFO LOG_INFO -+#define SKIA_TAG "XComSkia" -+//int OH_LOG_Print(int type, HiLog_LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) ; -+#define OHOS_LOG_DEBUG(...) (void) OH_LOG_Print(LOG_APP,SKIA_LOG_INFO,LOG_DOMAIN,SKIA_TAG,__VA_ARGS__) -+#else -+#define OHOS_LOG_DEBUG(...) -+#endif -+ - /////////////////////////////////////////////////////////////////////////////////////////////////// - - /* -@@ -2044,7 +2054,7 @@ void SkCanvas::onDrawPaint(const SkPaint& paint) { - } - - void SkCanvas::internalDrawPaint(const SkPaint& paint) { -- // drawPaint does not call internalQuickReject() because computing its geometry is not free -+ // drawPaint does not call exitinternalQuickReject() because computing its geometry is not free - // (see getLocalClipBounds(), and the two conditions below are sufficient. - if (paint.nothingToDraw() || this->isClipEmpty()) { - return; -@@ -2358,16 +2368,22 @@ void SkCanvas::onDrawImageRect2(const SkImage* image, const SkRect& src, const S - SkPaint realPaint = clean_paint_for_drawImage(paint); - SkSamplingOptions realSampling = clean_sampling_for_constraint(sampling, constraint); - -+ OHOS_LOG_DEBUG("SkCanvas::onDrawImageRect2 ...enter "); - if (this->internalQuickReject(dst, realPaint)) { -+ OHOS_LOG_DEBUG("SkCanvas::onDrawImageRect2 ...internalQuickReject rejected"); - return; - } - -+ OHOS_LOG_DEBUG("SkCanvas::onDrawImageRect2 ...aboutToDraw"); - auto layer = this->aboutToDraw(this, realPaint, &dst, CheckForOverwrite::kYes, - image->isOpaque() ? kOpaque_ShaderOverrideOpacity - : kNotOpaque_ShaderOverrideOpacity); -+ - if (layer) { -+ OHOS_LOG_DEBUG("SkCanvas::onDrawImageRect2 ...topDevice->drawImageRect"); - this->topDevice()->drawImageRect(image, &src, dst, realSampling, layer->paint(), constraint); - } -+ OHOS_LOG_DEBUG("SkCanvas::onDrawImageRect2 ...exit"); - } - - void SkCanvas::onDrawImageLattice2(const SkImage* image, const Lattice& lattice, const SkRect& dst, diff --git a/src/gpu/ganesh/gl/egl/GrGLMakeEGLInterface.cpp b/src/gpu/ganesh/gl/egl/GrGLMakeEGLInterface.cpp index 78225b4610..c2105852b1 100644 --- a/src/gpu/ganesh/gl/egl/GrGLMakeEGLInterface.cpp diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 90993ddb427930aab584a484190c10e702028f19..dd4fbdc66517078e684b9062cc3b0a526219a797 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -20,7 +20,7 @@ generated_file("artifacts_entitlement_config") { } } -if (build_engine_artifacts && !is_android) { +if (build_engine_artifacts && !is_android && !is_ohos) { zip_bundle("artifacts") { deps = [ "//flutter/flutter_frontend_server:frontend_server", @@ -129,6 +129,12 @@ if (build_engine_artifacts && !is_android) { } } +if (is_ohos) { + group("artifacts") { + deps = [ "//flutter/shell/platform/ohos:flutter_har_zip" ] + } +} + if (host_os == "linux" || host_os == "win") { group("embedder") { deps = [ "//flutter/shell/platform/embedder:embedder-archive" ] diff --git a/build/dart/rules.gni b/build/dart/rules.gni index c239d536c13fbaf70b242396b5543ae0c2ec3886..d92acff60e6fc61214addbdd9089046f7dd3c281 100644 --- a/build/dart/rules.gni +++ b/build/dart/rules.gni @@ -155,7 +155,7 @@ template("flutter_snapshot") { } else { output_aot_lib = "libapp.so" } - libapp = "$target_gen_dir/ohos/libs/$output_aot_lib" + libapp = "$target_gen_dir/ohos/libs/$ohos_app_abi/$output_aot_lib" outputs += [ libapp ] args += [ "--snapshot_kind=app-aot-elf", diff --git a/common/config.gni b/common/config.gni index 21a43ba4f89a36eeb0ed60772bc9d3b05fb2ca62..d74f2c9bc20c612c9b8e7fb48876a73d3c971e6f 100644 --- a/common/config.gni +++ b/common/config.gni @@ -6,6 +6,10 @@ if (is_android) { import("//build/config/android/config.gni") } +if (is_ohos) { + import("//build/config/ohos/config.gni") +} + if (target_cpu == "arm" || target_cpu == "arm64") { import("//build/config/arm.gni") } diff --git a/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc index db5574ce4ff941691548b3d3178294ce24f7b2fb..0427f9fdf0d928231b574473adf2a442d27ba442 100644 --- a/impeller/renderer/backend/vulkan/context_vk.cc +++ b/impeller/renderer/backend/vulkan/context_vk.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. // FLUTTER_NOLINT: https://github.com/flutter/flutter/issues/68331 +#pragma clang diagnostic ignored "-Wc++11-narrowing" #include "impeller/renderer/backend/vulkan/context_vk.h" diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index 8d18085468e772ad3fbb9ab6c40482c61e7fb387..f60b29c347c85214613db491658de12937233482 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -13,17 +13,25 @@ assert(is_ohos) +import("//build/config/ohos/config.gni") +import("//build/toolchain/clang.gni") import("//flutter/build/zip_bundle.gni") -import("//flutter/shell/platform/glfw/config.gni") -import("//flutter/testing/testing.gni") -import("//build/config/ohos/pkg_config.gni") +import("//flutter/common/config.gni") import("//flutter/shell/gpu/gpu.gni") +import("//flutter/shell/version/version.gni") +import("//flutter/testing/testing.gni") group("ohos") { deps = [ - ":flutter", + ":flutter_shell_native", #":publish_headers_ohos", + #":ohos_har", + ":flutter_har_zip", + ":ohos_symbols", ] + if (target_cpu != "x86") { + deps += [ ":gen_snapshot" ] + } } shell_gpu_configuration("ohos_gpu_configuration") { enable_software = true @@ -192,13 +200,10 @@ executable("flutter_ohos_unittests") { ] } -shared_library("flutter") { +shared_library("flutter_shell_native") { + output_name = "flutter" deps = [ ":flutter_ohos_src" ] - if (flutter_runtime_mode == "profile") { - deps += [ "//flutter/shell/vmservice:vmservice_snapshot" ] - } - ldflags = ["--rtlib=compiler-rt", "-fuse-ld=lld", "-static-libstdc++", @@ -268,3 +273,232 @@ shared_library("flutter") { # ] # files = tmp_files #} + +declare_args() { + embedding_artifact_id = "flutter_embedding_$flutter_runtime_mode" + embedding_har_filename = "$embedding_artifact_id.har" + embedding_har_path = "$root_out_dir/$embedding_har_filename" + engine_artifact_id = + string_replace(ohos_app_abi, "-", "_") + "_" + flutter_runtime_mode + engine_har_filename = "$engine_artifact_id.har" + + ohos_zip_archive_dir = "ohos-$target_cpu" + if (flutter_runtime_mode != "debug") { + ohos_zip_archive_dir += "-$flutter_runtime_mode" + } + ohos_api_int = 11 +} + +action("ohos_har") { + script = "//build/ohos/ohos_create_flutter_har.py" + + if (stripped_symbols) { + engine_library = "libflutter.so" + } else { + engine_library = "so.unstripped/libflutter.so" + } + + inputs = [ + # "$root_build_dir/$embedding_har_filename", + "$root_build_dir/$engine_library", + ] + + outputs = [ + "$root_build_dir/flutter.har", + # "$root_build_dir/$engine_har_filename", + ] + + args = [ + "--embedding_src", + "../../flutter/shell/platform/ohos/flutter_embedding", + "--build_dir", + "./obj/ohos/flutter_embedding", + "--build_type", + flutter_runtime_mode, + "--output", + rebase_path("flutter.har", root_build_dir, root_build_dir), + "--native_lib", + rebase_path("$engine_library", root_build_dir, root_build_dir), + "--ohos_abi", + ohos_app_abi, + "--ohos_api_int", + ohos_api_int + ] + + deps = [ + ":flutter_shell_native" + ] + + if (flutter_runtime_mode == "profile") { + deps += [ "//flutter/shell/vmservice:vmservice_snapshot" ] + args += [ + "--native_lib", + rebase_path( + "$root_gen_dir/flutter/shell/vmservice/ohos/libs/$ohos_app_abi/libvmservice_snapshot.so", + root_build_dir, + root_build_dir), + ] + } +} + +zip_bundle("flutter_har_zip") { + output = "$ohos_zip_archive_dir/artifacts.zip" + files = [ + { + source = "$root_build_dir/flutter.har" + destination = "flutter.har" + } + ] + + deps = [ ":ohos_har" ] +} + +zip_bundle("ohos_symbols") { + output = "$ohos_zip_archive_dir/symbols.zip" + files = [ + { + source = "$root_build_dir/so.unstripped/libflutter.so" + destination = "libflutter.so" + }, + ] + + deps = [ ":flutter_shell_native" ] +} + +generated_file("ohos_entitlement_config") { + outputs = [ "$target_gen_dir/ohos_entitlements.txt" ] + contents = [ "gen_snapshot" ] + deps = [] +} + +if (target_cpu != "x86") { + zip_bundle("gen_snapshot") { + gen_snapshot_bin = "gen_snapshot" + gen_snapshot_out_dir = get_label_info( + "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)", + "root_out_dir") + gen_snapshot_path = rebase_path("$gen_snapshot_out_dir/$gen_snapshot_bin") + + if (host_os == "linux") { + output = "$ohos_zip_archive_dir/linux-x64.zip" + } else if (host_os == "mac") { + output = "$ohos_zip_archive_dir/darwin-x64.zip" + } else if (host_os == "win") { + output = "$ohos_zip_archive_dir/windows-x64.zip" + gen_snapshot_bin = "gen_snapshot.exe" + gen_snapshot_path = rebase_path("$root_out_dir/$gen_snapshot_bin") + } + + files = [ + { + source = gen_snapshot_path + destination = gen_snapshot_bin + }, + ] + + deps = [ "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)" ] + } + + # TODO(godofredoc): Remove gen_snapshot and rename new_gen_snapshot when v2 migration is complete. + # BUG: https://github.com/flutter/flutter/issues/105351 + zip_bundle("new_gen_snapshot") { + gen_snapshot_bin = "gen_snapshot" + gen_snapshot_out_dir = get_label_info( + "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)", + "root_out_dir") + gen_snapshot_path = rebase_path("$gen_snapshot_out_dir/$gen_snapshot_bin") + + if (host_os == "linux") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/linux-x64.zip" + } else if (host_os == "mac") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/darwin-x64.zip" + } else if (host_os == "win") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/windows-x64.zip" + gen_snapshot_bin = "gen_snapshot.exe" + gen_snapshot_path = rebase_path("$root_out_dir/$gen_snapshot_bin") + } + + files = [ + { + source = gen_snapshot_path + destination = gen_snapshot_bin + }, + ] + + deps = [ "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)" ] + + if (host_os == "mac") { + deps += [ ":ohos_entitlement_config" ] + files += [ + { + source = "$target_gen_dir/ohos_entitlements.txt" + destination = "entitlements.txt" + }, + ] + } + } +} + +if (target_cpu == "x64" || target_cpu == "arm64") { + zip_bundle("analyze_snapshot") { + deps = + [ "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)" ] + + analyze_snapshot_bin = "analyze_snapshot" + analyze_snapshot_out_dir = + get_label_info( + "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)", + "root_out_dir") + analyze_snapshot_path = + rebase_path("$analyze_snapshot_out_dir/$analyze_snapshot_bin") + + if (host_os == "linux") { + output = "$ohos_zip_archive_dir/analyze-snapshot-linux-x64.zip" + } else if (host_os == "mac") { + output = "$ohos_zip_archive_dir/analyze-snapshot-darwin-x64.zip" + } else if (host_os == "win") { + output = "$ohos_zip_archive_dir/analyze-snapshot-windows-x64.zip" + analyze_snapshot_bin = "analyze-snapshot.exe" + analyze_snapshot_path = rebase_path("$root_out_dir/$analyze_snapshot_bin") + } + + files = [ + { + source = analyze_snapshot_path + destination = analyze_snapshot_bin + }, + ] + } + + # TODO(godofredoc): Remove analyze_snapshot and rename new_analyze_snapshot when v2 migration is complete. + # BUG: https://github.com/flutter/flutter/issues/105351 + zip_bundle("new_analyze_snapshot") { + deps = + [ "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)" ] + + analyze_snapshot_bin = "analyze_snapshot" + analyze_snapshot_out_dir = + get_label_info( + "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)", + "root_out_dir") + analyze_snapshot_path = + rebase_path("$analyze_snapshot_out_dir/$analyze_snapshot_bin") + + if (host_os == "linux") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/analyze-snapshot-linux-x64.zip" + } else if (host_os == "mac") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/analyze-snapshot-darwin-x64.zip" + } else if (host_os == "win") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/analyze-snapshot-windows-x64.zip" + analyze_snapshot_bin = "analyze-snapshot.exe" + analyze_snapshot_path = rebase_path("$root_out_dir/$analyze_snapshot_bin") + } + + files = [ + { + source = analyze_snapshot_path + destination = analyze_snapshot_bin + }, + ] + } +} diff --git a/shell/platform/ohos/flutter_embedding/.gitignore b/shell/platform/ohos/flutter_embedding/.gitignore index 4510e76666c8541e4a1195a0ed2850754c9fc243..969cec852a5aba0b1c35703eb108a5e6097bd818 100644 --- a/shell/platform/ohos/flutter_embedding/.gitignore +++ b/shell/platform/ohos/flutter_embedding/.gitignore @@ -8,3 +8,4 @@ /.clang-format /.clang-tidy **/.test +flutter/BuildProfile.ets diff --git a/shell/platform/ohos/flutter_embedding/build-profile.json5 b/shell/platform/ohos/flutter_embedding/build-profile.json5 index ae4533ee39e5c2954b75b7b19fe2ea1ef2b4ea82..2d2ee025698136d74f0a9ec4e9472bb263df8834 100755 --- a/shell/platform/ohos/flutter_embedding/build-profile.json5 +++ b/shell/platform/ohos/flutter_embedding/build-profile.json5 @@ -24,6 +24,17 @@ "compatibleSdkVersion": "4.1.0(11)", "runtimeOS": "HarmonyOS", } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + }, + { + "name": "profile" + }, ] }, "modules": [ diff --git a/shell/platform/ohos/flutter_embedding/flutter/index.ets b/shell/platform/ohos/flutter_embedding/flutter/index.ets index 3c96b70703b57d3e53a171aabf07727db248e94b..a9e43723cbf3971e9eb7e4a29aad5145731dff10 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/index.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/index.ets @@ -13,6 +13,193 @@ * limitations under the License. */ -export { FlutterAbility } from './src/main/ets/embedding/ohos/FlutterAbility' +import FlutterInjector from './src/main/ets/FlutterInjector'; +import FlutterPluginRegistry from './src/main/ets/app/FlutterPluginRegistry'; +import FlutterComponent from './src/main/ets/component/FlutterComponent'; +import FlutterEngine from './src/main/ets/embedding/engine/FlutterEngine'; +import FlutterEngineCache from './src/main/ets/embedding/engine/FlutterEngineCache'; +import FlutterEngineConnectionRegistry from './src/main/ets/embedding/engine/FlutterEngineConnectionRegistry'; +import FlutterEngineGroup from './src/main/ets/embedding/engine/FlutterEngineGroup'; +import FlutterEngineGroupCache from './src/main/ets/embedding/engine/FlutterEngineGroupCache'; +import FlutterNapi from './src/main/ets/embedding/engine/FlutterNapi'; +import { FlutterOverlaySurface } from './src/main/ets/embedding/engine/FlutterOverlaySurface'; +import FlutterShellArgs from './src/main/ets/embedding/engine/FlutterShellArgs'; +import DartExecutor from './src/main/ets/embedding/engine/dart/DartExecutor'; +import { DartMessenger } from './src/main/ets/embedding/engine/dart/DartMessenger'; +import { PlatformMessageHandler } from './src/main/ets/embedding/engine/dart/PlatformMessageHandler'; +import ApplicationInfoLoader from './src/main/ets/embedding/engine/loader/ApplicationInfoLoader'; +import FlutterApplicationInfo from './src/main/ets/embedding/engine/loader/FlutterApplicationInfo'; +import FlutterLoader from './src/main/ets/embedding/engine/loader/FlutterLoader'; +import { FlutterMutatorView } from './src/main/ets/embedding/engine/mutatorsstack/FlutterMutatorView'; +import { FlutterMutatorsStack } from './src/main/ets/embedding/engine/mutatorsstack/FlutterMutatorsStack'; +import { FlutterPlugin } from './src/main/ets/embedding/engine/plugins/FlutterPlugin'; +import AbilityAware from './src/main/ets/embedding/engine/plugins/ability/AbilityAware'; +import AbilityControlSurface from './src/main/ets/embedding/engine/plugins/ability/AbilityControlSurface'; +import { AbilityPluginBinding } from './src/main/ets/embedding/engine/plugins/ability/AbilityPluginBinding'; +import GeneratedPluginRegister from './src/main/ets/embedding/engine/plugins/util/GeneratedPluginRegister'; +import { FlutterUiDisplayListener } from './src/main/ets/embedding/engine/renderer/FlutterUiDisplayListener'; +import AccessibilityChannel from './src/main/ets/embedding/engine/systemchannels/AccessibilityChannel'; +import KeyEventChannel from './src/main/ets/embedding/engine/systemchannels/KeyEventChannel'; +import LifecycleChannel from './src/main/ets/embedding/engine/systemchannels/LifecycleChannel'; +import LocalizationChannel from './src/main/ets/embedding/engine/systemchannels/LocalizationChannel'; +import MouseCursorChannel from './src/main/ets/embedding/engine/systemchannels/MouseCursorChannel'; +import NavigationChannel from './src/main/ets/embedding/engine/systemchannels/NavigationChannel'; +import PlatformChannel from './src/main/ets/embedding/engine/systemchannels/PlatformChannel'; +import PlatformViewsChannel from './src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel'; +import RestorationChannel from './src/main/ets/embedding/engine/systemchannels/RestorationChannel'; +import SettingsChannel from './src/main/ets/embedding/engine/systemchannels/SettingsChannel'; +import SystemChannel from './src/main/ets/embedding/engine/systemchannels/SystemChannel'; +import TestChannel from './src/main/ets/embedding/engine/systemchannels/TestChannel'; +import TextInputChannel from './src/main/ets/embedding/engine/systemchannels/TextInputChannel'; +import ExclusiveAppComponent from './src/main/ets/embedding/ohos/ExclusiveAppComponent'; +import { FlutterAbility } from './src/main/ets/embedding/ohos/FlutterAbility'; +import { FlutterAbilityAndEntryDelegate } from './src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate'; +import FlutterAbilityLaunchConfigs from './src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs'; +import FlutterEngineConfigurator from './src/main/ets/embedding/ohos/FlutterEngineConfigurator'; +import FlutterEngineProvider from './src/main/ets/embedding/ohos/FlutterEngineProvider'; +import FlutterEntry from './src/main/ets/embedding/ohos/FlutterEntry'; +import FlutterManager from './src/main/ets/embedding/ohos/FlutterManager'; +import { FlutterPage } from './src/main/ets/embedding/ohos/FlutterPage'; +import KeyboardManager from './src/main/ets/embedding/ohos/KeyboardManager'; +import OhosTouchProcessor from './src/main/ets/embedding/ohos/OhosTouchProcessor'; +import Settings from './src/main/ets/embedding/ohos/Settings'; +import { TouchEventTracker } from './src/main/ets/embedding/ohos/TouchEventTracker'; +import WindowInfoRepositoryCallbackAdapterWrapper + from './src/main/ets/embedding/ohos/WindowInfoRepositoryCallbackAdapterWrapper'; +import PlatformPlugin from './src/main/ets/plugin/PlatformPlugin'; +import BasicMessageChannel from './src/main/ets/plugin/common/BasicMessageChannel'; +import BinaryCodec from './src/main/ets/plugin/common/BinaryCodec'; +import { BinaryMessenger } from './src/main/ets/plugin/common/BinaryMessenger'; +import EventChannel from './src/main/ets/plugin/common/EventChannel'; +import FlutterException from './src/main/ets/plugin/common/FlutterException'; +import JSONMessageCodec from './src/main/ets/plugin/common/JSONMessageCodec'; +import JSONMethodCodec from './src/main/ets/plugin/common/JSONMethodCodec'; +import MessageCodec from './src/main/ets/plugin/common/MessageCodec'; +import MethodCall from './src/main/ets/plugin/common/MethodCall'; +import MethodChannel from './src/main/ets/plugin/common/MethodChannel'; +import MethodCodec from './src/main/ets/plugin/common/MethodCodec'; +import StandardMessageCodec from './src/main/ets/plugin/common/StandardMessageCodec'; +import StandardMethodCodec from './src/main/ets/plugin/common/StandardMethodCodec'; +import StringCodec from './src/main/ets/plugin/common/StringCodec'; +import { ListenableEditingState } from './src/main/ets/plugin/editing/ListenableEditingState'; +import { TextEditingDelta } from './src/main/ets/plugin/editing/TextEditingDelta'; +import TextInputPlugin from './src/main/ets/plugin/editing/TextInputPlugin'; +import LocalizationPlugin from './src/main/ets/plugin/localization/LocalizationPlugin'; +import MouseCursorPlugin from './src/main/ets/plugin/mouse/MouseCursorPlugin'; +import { AccessibilityEventsDelegate } from './src/main/ets/plugin/platform/AccessibilityEventsDelegate'; +import { PlatformOverlayView } from './src/main/ets/plugin/platform/PlatformOverlayView'; +import PlatformView from './src/main/ets/plugin/platform/PlatformView'; +import PlatformViewFactory from './src/main/ets/plugin/platform/PlatformViewFactory'; +import PlatformViewRegistry from './src/main/ets/plugin/platform/PlatformViewRegistry'; +import PlatformViewRegistryImpl from './src/main/ets/plugin/platform/PlatformViewRegistryImpl'; +import { PlatformViewWrapper } from './src/main/ets/plugin/platform/PlatformViewWrapper'; +import { PlatformViewsAccessibilityDelegate } from './src/main/ets/plugin/platform/PlatformViewsAccessibilityDelegate'; +import PlatformViewsController from './src/main/ets/plugin/platform/PlatformViewsController'; +import AccessibilityBridge from './src/main/ets/view/AccessibilityBridge'; +import { FlutterCallbackInformation } from './src/main/ets/view/FlutterCallbackInformation'; +import FlutterRunArguments from './src/main/ets/view/FlutterRunArguments'; +import { FlutterView } from './src/main/ets/view/FlutterView'; +import { TextureRegistry } from './src/main/ets/view/TextureRegistry'; +import { ByteBuffer } from './src/main/ets/util/ByteBuffer'; +import Log from './src/main/ets/util/Log'; +import MessageChannelUtils from './src/main/ets/util/MessageChannelUtils'; +import PathUtils from './src/main/ets/util/PathUtils'; +import StringUtils from './src/main/ets/util/StringUtils'; +import ToolUtils from './src/main/ets/util/ToolUtils'; +import { TraceSection } from './src/main/ets/util/TraceSection'; -export { FlutterPage } from './src/main/ets/embedding/ohos/FlutterPage' +export { + FlutterInjector, + FlutterPluginRegistry, + FlutterComponent, + FlutterEngine, + FlutterEngineCache, + FlutterEngineConnectionRegistry, + FlutterEngineGroup, + FlutterEngineGroupCache, + FlutterNapi, + FlutterOverlaySurface, + FlutterShellArgs, + DartExecutor, + DartMessenger, + PlatformMessageHandler, + ApplicationInfoLoader, + FlutterApplicationInfo, + FlutterLoader, + FlutterMutatorView, + FlutterMutatorsStack, + FlutterPlugin, + AbilityAware, + AbilityControlSurface, + AbilityPluginBinding, + GeneratedPluginRegister, + FlutterUiDisplayListener, + AccessibilityChannel, + KeyEventChannel, + LifecycleChannel, + LocalizationChannel, + MouseCursorChannel, + NavigationChannel, + PlatformChannel, + PlatformViewsChannel, + RestorationChannel, + SettingsChannel, + SystemChannel, + TestChannel, + TextInputChannel, + ExclusiveAppComponent, + FlutterAbility, + FlutterAbilityAndEntryDelegate, + FlutterAbilityLaunchConfigs, + FlutterEngineConfigurator, + FlutterEngineProvider, + FlutterEntry, + FlutterManager, + FlutterPage, + KeyboardManager, + OhosTouchProcessor, + Settings, + TouchEventTracker, + WindowInfoRepositoryCallbackAdapterWrapper, + PlatformPlugin, + BasicMessageChannel, + BinaryCodec, + BinaryMessenger, + EventChannel, + FlutterException, + JSONMessageCodec, + JSONMethodCodec, + MessageCodec, + MethodCall, + MethodChannel, + MethodCodec, + StandardMessageCodec, + StandardMethodCodec, + StringCodec, + ListenableEditingState, + TextEditingDelta, + TextInputPlugin, + LocalizationPlugin, + MouseCursorPlugin, + AccessibilityEventsDelegate, + PlatformOverlayView, + PlatformView, + PlatformViewFactory, + PlatformViewRegistry, + PlatformViewRegistryImpl, + PlatformViewWrapper, + PlatformViewsAccessibilityDelegate, + PlatformViewsController, + AccessibilityBridge, + FlutterCallbackInformation, + FlutterRunArguments, + FlutterView, + TextureRegistry, + ByteBuffer, + Log, + MessageChannelUtils, + PathUtils, + StringUtils, + ToolUtils, + TraceSection, +} diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets index 2a2a44964d3903c884f533e2bed115a4b624b745..758b5f6e1ce5fd7c97312ab4cc0cfe76954fc422 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets @@ -18,11 +18,13 @@ import PlatformViewController from '../plugin/platform/PlatformViewsController' export default class FlutterPluginRegistry { private mPlatformViewsController: PlatformViewController; - private mFlutterView: FlutterView; - private mContext: common.Context; + private mFlutterView: FlutterView | null = null; + private mContext: common.Context | null = null; constructor() { this.mPlatformViewsController = new PlatformViewController(); + this.mFlutterView = null; + this.mContext = null; } attach(flutterView: FlutterView, context: common.Context): void { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets index e9d66ef987b8c8f070bb6279a2035fc06fc8c054..d8198a8b32cddbc18ae63f0dbcf2cefbf6935939 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets @@ -21,7 +21,7 @@ struct XComponentStruct { dvModelParams: DVModelParameters = new DVModelParameters(); build() { - XComponent({ id: (this.dvModelParams as Record)["xComponentId"], type: 'texture', libraryname: 'flutter'}) + XComponent({ id: (this.dvModelParams as Record)["xComponentId"], type: XComponentType.TEXTURE, libraryname: 'flutter'}) .onLoad((context) => { this.context = context; }) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartExecutor.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartExecutor.ets index 46d08cd458b5795d1daaa1f4379a088b129d5dc7..383927204c7bc83df203d2e779430c3969762a20 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartExecutor.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartExecutor.ets @@ -172,7 +172,7 @@ export default class DartExecutor implements BinaryMessenger { this.getBinaryMessenger().send(channel, message, callback); } - setMessageHandler(channel: String, handler: BinaryMessageHandler, taskQueue?: TaskQueue): void { + setMessageHandler(channel: String, handler: BinaryMessageHandler | null, taskQueue?: TaskQueue): void { this.getBinaryMessenger().setMessageHandler(channel, handler, taskQueue); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartMessenger.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartMessenger.ets index 6e9bfab834fbdc2b0929e774ecd94c78d4683e7a..3567d610f4ddafb1e845baf55a0d7d8028e878a5 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartMessenger.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartMessenger.ets @@ -68,7 +68,7 @@ export class DartMessenger implements BinaryMessenger, PlatformMessageHandler { } - setMessageHandler(channel: String, handler: BinaryMessageHandler, taskQueue?: TaskQueue): void { + setMessageHandler(channel: String, handler: BinaryMessageHandler | null, taskQueue?: TaskQueue): void { if (handler == null) { Log.d(TAG, "Removing handler for channel '" + channel + "'"); this.messageHandlers.delete(channel); @@ -255,7 +255,7 @@ class Reply implements BinaryReply { this.replyId = replyId; } - reply(reply: ArrayBuffer) { + reply(reply: ArrayBuffer | null) { if (this.done) { throw new Error("Reply already submitted"); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets index 272615d612c8d056fb3a58c280f9f2e69b02d502..8ff3aec5b8e0a72c4427b0cfab711d62e266a9b3 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +import BuildProfile from "../../../../../../BuildProfile.ets"; + const DEFAULT_AOT_SHARED_LIBRARY_NAME = "libapp.so"; const DEFAULT_VM_SNAPSHOT_DATA = "vm_snapshot_data"; const DEFAULT_ISOLATE_SNAPSHOT_DATA = "isolate_snapshot_data"; @@ -49,7 +51,7 @@ export default class FlutterApplicationInfo { this.domainNetworkPolicy = domainNetworkPolicy == null ? "" : domainNetworkPolicy; this.nativeLibraryDir = nativeLibraryDir; this.automaticallyRegisterPlugins = automaticallyRegisterPlugins; - this.isDebugMode = false; - this.isProfile = false; + this.isDebugMode = "debug" == String(BuildProfile.BUILD_MODE_NAME); + this.isProfile = "profile" == String(BuildProfile.BUILD_MODE_NAME); } } \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets index c02c3ad005371a98e50fed4d23ca2b3852c89cd6..315a433f8491dd40e4f533287dfa5de49a49302f 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets @@ -20,6 +20,8 @@ import TextInputPlugin from '../../../plugin/editing/TextInputPlugin'; import Log from '../../../util/Log'; import DartExecutor from '../dart/DartExecutor'; import inputMethod from '@ohos.inputMethod'; +import ArrayList from '@ohos.util.ArrayList'; +import { TextEditingDelta, TextEditingDeltaJson } from '../../../plugin/editing/TextEditingDelta'; const TAG = "TextInputChannel"; @@ -56,6 +58,18 @@ export default class TextInputChannel { return state; } + createEditingDeltaJSON(batchDeltas: ArrayList): EditingDelta { + let deltas: Array = []; + batchDeltas.forEach((val, idx, array) => { + deltas.push(val.toJSON()); + }) + + let state: EditingDelta = { + deltas: deltas, + }; + return state; + } + /** * Instructs Flutter to update its text input editing state to reflect the given configuration. */ @@ -72,6 +86,12 @@ export default class TextInputChannel { this.channel.invokeMethod('TextInputClient.updateEditingState', [inputClientId, state]); } + updateEditingStateWithDeltas(inputClientId: number, batchDeltas: ArrayList): void { + Log.d(TAG, "updateEditingStateWithDeltas:" + "batchDeltas length: " + batchDeltas.length); + const state: ESObject = this.createEditingDeltaJSON(batchDeltas); + this.channel.invokeMethod('TextInputClient.updateEditingStateWithDeltas', [inputClientId, state]); + } + newline(inputClientId: number): void { Log.d(TAG, "Sending 'newline' message."); this.channel.invokeMethod("TextInputClient.performAction", [inputClientId, "TextInputAction.newline"]); @@ -124,7 +144,6 @@ export default class TextInputChannel { performPrivateCommand(inputClientId: number, action: string, data: ESObject) { } - } interface EditingState { @@ -135,6 +154,12 @@ interface EditingState { composingExtent: number; } + +interface EditingDelta { + deltas: Array; +} + + export interface TextInputMethodHandler { show(): void; @@ -175,12 +200,12 @@ export class Configuration { enableSuggestions: boolean, enableIMEPersonalizedLearning: boolean, enableDeltaModel: boolean, - textCapitalization:TextCapitalization, + textCapitalization: TextCapitalization, inputType: InputType, inputAction: Number, actionLabel: String, - autofill :boolean, - contentListString:[], + autofill: boolean, + contentListString: [], fields: Configuration[] ) { this.obscureText = obscureText; @@ -197,8 +222,9 @@ export class Configuration { this.fields = fields } + static getTextCapitalizationFromValue(encodedName: string): TextCapitalization { - let textKeys= ["CHARACTERS", "WORDS","SENTENCES", "NONE"]; + let textKeys = ["CHARACTERS", "WORDS", "SENTENCES", "NONE"]; for (let textKey of textKeys) { if (TextCapitalization[textKey] === encodedName) { return textKey as TextCapitalization; @@ -206,8 +232,9 @@ export class Configuration { } throw new Error("No such TextCapitalization: " + encodedName); } - private static inputActionFromTextInputAction(inputActionName:string):number{ - switch(inputActionName){ + + private static inputActionFromTextInputAction(inputActionName: string): number { + switch (inputActionName) { case "TextInputAction.previous": return inputMethod.EnterKeyType.PREVIOUS case "TextInputAction.unspecified": @@ -228,23 +255,24 @@ export class Configuration { } } - static fromJson(json:ESObject) { - const inputActionName:string = json.inputAction; + + static fromJson(json: ESObject) { + const inputActionName: string = json.inputAction; if (!inputActionName) { throw new Error("Configuration JSON missing 'inputAction' property."); } - let fields:Array = new Array(); + let fields: Array = new Array(); if (json.fields !== null && json.fields !== undefined) { - fields = json.fields.map((field:ESObject):ESObject => Configuration.fromJson(field)); + fields = json.fields.map((field: ESObject): ESObject => Configuration.fromJson(field)); } - const inputAction:number = Configuration.inputActionFromTextInputAction(inputActionName); + const inputAction: number = Configuration.inputActionFromTextInputAction(inputActionName); // Build list of content commit mime types from the data in the JSON list. - const contentList:Array = []; + const contentList: Array = []; if (json.contentCommitMimeTypes !== null && json.contentCommitMimeTypes !== undefined) { - json.contentCommitMimeTypes.forEach((type:ESObject) => { + json.contentCommitMimeTypes.forEach((type: ESObject) => { contentList.push(type); }); } @@ -263,7 +291,6 @@ export class Configuration { fields ); } - } enum TextCapitalization { @@ -304,7 +331,7 @@ export class InputType { } static getTextInputTypeFromValue(encodedName: string): TextInputType { - let textKeys = [ "TEXT", "DATETIME","NAME" , "POSTAL_ADDRESS", "NUMBER", "PHONE", "MULTILINE", "EMAIL_ADDRESS", "URL", "VISIBLE_PASSWORD", "NONE" ,]; + let textKeys = ["TEXT", "DATETIME", "NAME", "POSTAL_ADDRESS", "NUMBER", "PHONE", "MULTILINE", "EMAIL_ADDRESS", "URL", "VISIBLE_PASSWORD", "NONE",]; for (let textKey of textKeys) { if (TextInputType[textKey] === encodedName) { return textKey as TextInputType; @@ -403,7 +430,7 @@ class TextInputCallback implements MethodCallHandler { break; case "TextInput.setClient": const textInputClientId: number = args[0] as number; - const jsonConfiguration :string = args[1] ; + const jsonConfiguration: string = args[1]; const config: Configuration | null = Configuration.fromJson(jsonConfiguration); this.textInputMethodHandler.setClient(textInputClientId, config); @@ -442,5 +469,4 @@ class TextInputCallback implements MethodCallHandler { break; } } - } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets index 056d8c0b5cad796975b3121ef57848fa606cd23b..df276bd2e5ce35b8b53f76d6aaf80c1f1e014689 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets @@ -39,6 +39,7 @@ import GeneratedPluginRegister from '../engine/plugins/util/GeneratedPluginRegis import { UIContext } from '@ohos.arkui.UIContext'; import { FlutterView } from '../../view/FlutterView'; import FlutterManager from './FlutterManager'; +import router from '@ohos.router'; const TAG = "FlutterAbilityDelegate"; const PLUGINS_RESTORATION_BUNDLE_KEY = "plugins"; @@ -97,7 +98,7 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent } if (this.flutterEngine) { this.textInputPlugin = new TextInputPlugin(this.flutterEngine.getTextInputChannel()!); - this.platformPlugin = new PlatformPlugin(this.flutterEngine.getPlatformChannel()!, this.context); + this.platformPlugin = new PlatformPlugin(this.flutterEngine.getPlatformChannel()!, this.context, this); this.settings = new Settings(this.flutterEngine.getSettingsChannel()!); this.flutterEngine.getSystemLanguages(); } @@ -107,6 +108,11 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent this.host?.configureFlutterEngine(this.flutterEngine!!); } + popSystemNavigator(): boolean { + router.back(); + return true; + } + /** * 加载app.so资源或者snapshot */ diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets index e995319b549201eb1dfa72ce972df8d64d53138f..2d5a4a0ef800ce96b6f33f2507762f97c592bfef 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets @@ -38,26 +38,31 @@ export default class FlutterEntry implements Host { private flutterView: FlutterView | null = null private context: Context; private windowStage: window.WindowStage | null = null - private parameters: ESObject = {}; + private parameters: Record = {}; private engineConfigurator: FlutterEngineConfigurator | null = null + private hasInit: boolean = false; - constructor(context: Context, params: ESObject = {}) { + constructor(context: Context, params: Record = {}) { this.context = context; this.uiAbility = FlutterManager.getInstance().getUIAbility(context); this.parameters = params; this.windowStage = FlutterManager.getInstance().getWindowStage(this.uiAbility); + this.hasInit = false; } async aboutToAppear() { Log.i(TAG, 'aboutToAppear'); - this.delegate = new FlutterAbilityAndEntryDelegate(this); - this.flutterView = this.delegate?.createView(this.context); - await this?.delegate?.onAttach(this.context); - Log.i(TAG, 'onAttach end'); - this?.delegate?.platformPlugin?.setUIAbilityContext(this.uiAbility!!.context); - this.delegate?.onCreate(); - this.delegate?.onWindowStageCreate() - this.windowStage?.on('windowStageEvent', this.windowStageEventCallback); + if (this.hasInit == false) { + this.delegate = new FlutterAbilityAndEntryDelegate(this); + this.flutterView = this.delegate?.createView(this.context); + await this?.delegate?.onAttach(this.context); + Log.i(TAG, 'onAttach end'); + this?.delegate?.platformPlugin?.setUIAbilityContext(this.uiAbility!!.context); + this.delegate?.onCreate(); + this.delegate?.onWindowStageCreate() + this.windowStage?.on('windowStageEvent', this.windowStageEventCallback); + this.hasInit = true; + } } private windowStageEventCallback = (data: window.WindowStageEventType) => { @@ -119,6 +124,11 @@ export default class FlutterEntry implements Host { this?.delegate?.onBackground(); } + onBackPress() { + Log.d(TAG, "FlutterEntry onBackPress==="); + this?.delegate?.flutterEngine?.getNavigationChannel()?.popRoute(); + } + shouldDispatchAppLifecycleState(): boolean { return true; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 483813fa6ae5e97b4b79abf9c8748ecdac90eebb..e29e877c56c919d1c3249469efb1b3fb1c3bf0fd 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -35,18 +35,18 @@ const TAG = "FlutterPage"; */ @Component export struct FlutterPage { - @State rootDvModel: DVModel | undefined = undefined + @State rootDvModel: DVModelChildren | undefined = undefined @Prop viewId: string = "" private flutterView?: FlutterView | null aboutToAppear() { this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.rootDvModel = this.flutterView!!.getDVModel() + this.rootDvModel = this.flutterView!!.getDVModel().children } build() { Stack() { - XComponent({ id: this.viewId, type: 'texture', libraryname: 'flutter' }) + XComponent({ id: this.viewId, type: XComponentType.TEXTURE, libraryname: 'flutter' }) .focusable(true) .onLoad((context) => { this.flutterView?.onSurfaceCreated() @@ -56,13 +56,14 @@ export struct FlutterPage { Log.d(TAG, "XComponent onDestroy "); this.flutterView?.onSurfaceDestroyed() }) - DynamicView({ - model: this.rootDvModel, - params: this.rootDvModel!!.params as DVModelParameters, - events: this.rootDvModel!!.events as DVModelEvents, - children: this.rootDvModel!!.children as DVModelChildren, - customBuilder: this.rootDvModel!!.builder as ($$: Record<"params", DVModelParameters>) => void - //customBuilder: this.rootDvModel.model.builder as ($$: { params: DVModelParameters }) => void + ForEach(this.rootDvModel!!, (child:ESObject) =>{ + DynamicView({ + model: child as DVModel, + params:child.params, + events:child.events, + children:child.children, + customBuilder:child.builder + }) }) } .onAreaChange((oldValue: Area, newValue: Area) => { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets index 796f8edb8936927b11819282e8721b41da55a103..5a58b8c3ca0daa6bd51f0281aa968904b1e68411 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets @@ -74,7 +74,7 @@ export default class BasicMessageChannel { * * @param handler a {@link MessageHandler}, or null to deregister. */ - setMessageHandler(handler: MessageHandler): void { + setMessageHandler(handler: MessageHandler | null): void { // We call the 2 parameter variant specifically to avoid breaking changes in // mock verify calls. // See https://github.com/flutter/flutter/issues/92582. @@ -136,7 +136,7 @@ class IncomingReplyHandler implements BinaryReply { this.codec = codec } - reply(reply: ArrayBuffer) { + reply(reply: ArrayBuffer | null) { try { this.callback(this.codec.decodeMessage(reply)); } catch (e) { @@ -146,17 +146,17 @@ class IncomingReplyHandler implements BinaryReply { } class IncomingMessageHandler implements BinaryMessageHandler { - private handler: MessageHandler + private handler: MessageHandler | null private codec: MessageCodec - constructor(handler: MessageHandler, codec: MessageCodec) { + constructor(handler: MessageHandler | null, codec: MessageCodec) { this.handler = handler; this.codec = codec } onMessage(message: ArrayBuffer, callback: BinaryReply) { try { - this.handler.onMessage( + this.handler?.onMessage( this.codec.decodeMessage(message), { reply: (reply: T): void => { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryCodec.ets index 578436417dc4a23cfaf2c5adbb9c8340efa5795d..1c15c762108efc389aef0b9d2bf3ff8b07b01991 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryCodec.ets @@ -37,9 +37,9 @@ export default class BinaryCodec implements MessageCodec { return message } - decodeMessage(message: ArrayBuffer): ArrayBuffer { + decodeMessage(message: ArrayBuffer | null): ArrayBuffer { if (message == null) { - return message; + return new ArrayBuffer(0); } else if (this.returnsDirectByteBufferFromDecoding) { return message; } else { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets index e0b55276beb3893f0347d9893ecaab9d2754174c..68925a8b1abcaf1f99964f67e52da6e99cc8ba8c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets @@ -49,7 +49,7 @@ export interface BinaryReply { * outgoing replies must place the reply bytes between position zero and current position. * Reply receivers can read from the buffer directly. */ - reply(reply: ArrayBuffer): void; + reply(reply: ArrayBuffer | null): void; } /** Handler for incoming binary messages from Flutter. */ @@ -96,7 +96,7 @@ export interface BinaryMessenger { * @param message the message payload, a direct-allocated {@link ByteBuffer} with the message * bytes between position zero and current position, or null. */ - send(channel: String, message: ArrayBuffer): void; + send(channel: String, message: ArrayBuffer | null): void; /** * Sends a binary message to the Flutter application, optionally expecting a reply. @@ -127,7 +127,7 @@ export interface BinaryMessenger { * the handler. Specifying null means execute on the platform thread. */ //setMessageHandler(channel: String, handler: BinaryMessageHandler) - setMessageHandler(channel: String, handler: BinaryMessageHandler, taskQueue?: TaskQueue): void; + setMessageHandler(channel: String, handler: BinaryMessageHandler | null, taskQueue?: TaskQueue): void; // { // if (taskQueue != null) { // throw new Error("setMessageHandler called with nonnull taskQueue is not supported.") diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets index 166659a32e819580f2d433886f763dc453d8a597..0c2ee0884cd3ee114ef244fda91631d4bbc71407 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets @@ -40,13 +40,13 @@ export default class EventChannel { private messenger: BinaryMessenger; private name: string; private codec: MethodCodec; - private taskQueue: TaskQueue; + private taskQueue: TaskQueue | null; constructor(messenger: BinaryMessenger, name: string, codec?: MethodCodec, taskQueue?: TaskQueue) { this.messenger = messenger this.name = name this.codec = codec ? codec : StandardMethodCodec.INSTANCE - this.taskQueue = taskQueue + this.taskQueue = taskQueue ?? null } @@ -236,26 +236,26 @@ class EventSinkImplementation implements EventSink { return; } this.hasEnded = true; - this.messenger.send(this.name, null); + this.messenger.send(this.name, new ArrayBuffer(0)); } } class AtomicReference { - private value: T; + private value: T | null; - constructor(value: T) { + constructor(value: T | null) { this.value = value } - get(): T { + get(): T | null { return this.value; } - set(newValue: T): void { + set(newValue: T | null): void { this.value = newValue; } - getAndSet(newValue: T) { + getAndSet(newValue: T | null) { const oldValue = this.value; this.value = newValue; return oldValue; diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets index e766db57fc08160e21e5061e525a2c03e986621f..e37a3d27e51b0ad6e3b50c4a80d5760ffac28901 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets @@ -44,9 +44,9 @@ export default class JSONMessageCodec implements MessageCodec { return StringCodec.INSTANCE.encodeMessage(JSON.stringify(this.toBaseData(message))); } - decodeMessage(message: ArrayBuffer): ESObject { + decodeMessage(message: ArrayBuffer | null): ESObject { if (message == null) { - return null; + return StringUtils.stringToArrayBuffer(""); } try { const jsonStr = StringCodec.INSTANCE.decodeMessage(message); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MessageCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MessageCodec.ets index 663d57af19c70523e44a5f48cc61e22ab0dc5b33..6cb2c033b63e20323e89aaecec9893bdfbadb92e 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MessageCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MessageCodec.ets @@ -26,5 +26,5 @@ export default interface MessageCodec { * Decodes the specified message from binary. * */ - decodeMessage(message: ArrayBuffer): T; + decodeMessage(message: ArrayBuffer | null): T; } \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets index f42df11830d1a0eab1adc73acc30bde2d09406e1..e9c3a7cc150e82b69b9b0b488a4920924a6ea98f 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets @@ -165,7 +165,7 @@ export class IncomingResultHandler implements BinaryReply { this.codec = codec } - reply(reply: ArrayBuffer): void { + reply(reply: ArrayBuffer | null): void { try { if (reply == null) { this.callback.notImplemented(); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets index 2ee2ef39b25336d660cf74425d99f5477f11032e..df27a1232865d2882f9474fabf0c7aaf23712c1b 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets @@ -76,7 +76,7 @@ export default class StandardMessageCodec implements MessageCodec { return stream.buffer } - decodeMessage(message: ArrayBuffer): ESObject { + decodeMessage(message: ArrayBuffer | null): ESObject { if (message == null) { return null } @@ -233,7 +233,7 @@ export default class StandardMessageCodec implements MessageCodec { } readValue(buffer: ByteBuffer): ESObject { - let type = buffer.readInt8() + let type = buffer.readUint8() return this.readValueOfType(type, buffer); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StringCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StringCodec.ets index b824ac1f901b1dc9d1ae36f49e7fc74954595f4f..3ce96e365ce74d7e82bbf2f742c1bdb3800afb27 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StringCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StringCodec.ets @@ -33,7 +33,7 @@ export default class StringCodec implements MessageCodec { return StringUtils.stringToArrayBuffer(message); } - decodeMessage(message: ArrayBuffer): string { + decodeMessage(message: ArrayBuffer | null): string { if (message == null) { return ""; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets index 953f7cad09b96e97f5bbc45ee519cf70358d2eed..0726ab0fb43398a1d60062f472484c3f6b3601d5 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets @@ -19,10 +19,11 @@ import inputMethod from '@ohos.inputMethod'; import ArrayList from '@ohos.util.ArrayList'; import { TextEditingDelta } from './TextEditingDelta'; import TextInputChannel from '../../embedding/engine/systemchannels/TextInputChannel'; -const TAG = "ListenableEditingState"; -export class ListenableEditingState { - private TextInputChannel: TextInputChannel | null = null ; +const TAG = "ListenableEditingState"; + +export class ListenableEditingState { + private TextInputChannel: TextInputChannel | null = null; private client: number = 0 //Cache used to storage software keyboard input action private mStringCache: string; @@ -56,6 +57,34 @@ export class ListenableEditingState { this.mComposingEndCache = -1; } + extractBatchTextEditingDeltas(): ArrayList { + let currentBatchDeltas = new ArrayList(); + this.mBatchTextEditingDeltas.forEach((data) => { + currentBatchDeltas.add(data); + }) + this.mBatchTextEditingDeltas.clear(); + return currentBatchDeltas; + } + + clearBatchDeltas(): void { + this.mBatchTextEditingDeltas.clear(); + } + + replace(start: number, end: number, tb: String, tbStart: number, tbEnd: number): void { + const placeIndex = this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + + this.mBatchTextEditingDeltas.add( + new TextEditingDelta( + this.mStringCache.toString(), + placeIndex + tbEnd, + placeIndex + tbEnd, + this.getComposingStart(), + this.getComposingEnd(), + start, + end + tbStart, + tb.toString() + )); + } getSelectionStart(): number { return this.mSelectionStartCache; @@ -116,20 +145,26 @@ export class ListenableEditingState { } handleInsertTextEvent(text: string): void { - if(this.mStringCache.length == this.mSelectionStartCache) { + let start = this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + let end = this.mSelectionStartCache > this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + const length = text.length; + this.replace(start, end, text, 0, length); + + if (this.mStringCache.length == this.mSelectionStartCache) { //Insert text one by one - this.mStringCache += text; + let tempStr: string = this.mStringCache.substring(0, start) + text + this.mStringCache.substring(end); + this.mStringCache = tempStr; this.setSelectionStart(this.mStringCache.length); this.setSelectionEnd(this.mStringCache.length); - } else if(this.mStringCache.length > this.mSelectionStartCache) { + } else if (this.mStringCache.length > this.mSelectionStartCache) { //Insert text in the middle of string - let tempStr: string = this.mStringCache.substring(0, this.mSelectionStartCache) + text + this.mStringCache.substring(this.mSelectionStartCache); + let tempStr: string = this.mStringCache.substring(0, start) + text + this.mStringCache.substring(end); this.mStringCache = tempStr; - this.mSelectionStartCache += text.length; + this.mSelectionStartCache = start + text.length; this.mSelectionEndCache = this.mSelectionStartCache; } - if(this.mListeners == null) { + if (this.mListeners == null) { Log.e(TAG, "mListeners is null"); return; } @@ -139,7 +174,7 @@ export class ListenableEditingState { updateTextInputState(state: TextEditState): void { this.beginBatchEdit(); this.setStringCache(state.text); - if(state.hasSelection()) { + if (state.hasSelection()) { this.setSelectionStart(state.selectionStart); this.setSelectionEnd(state.selectionEnd); } else { @@ -217,22 +252,30 @@ export class ListenableEditingState { } handleDeleteEvent(leftOrRight: boolean, length: number): void { - if(leftOrRight == false) { + let start = this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + let end = this.mSelectionStartCache > this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + + if (leftOrRight == false) { //delete left - if(this.mSelectionStartCache == 0) { + if (start == 0 && end == 0) { return; } - this.mSelectionStartCache -= length; - let tempStr: string = this.mStringCache.slice(0, this.mSelectionStartCache) + this.mStringCache.slice(this.mSelectionStartCache + length); + const startData = start == end ? start - 1 : start; + const tbEnd = start == end ? -1 : 0; + this.replace(startData, end, "", 0, tbEnd); + this.mSelectionStartCache = startData; + let tempStr: string = this.mStringCache.slice(0, startData) + this.mStringCache.slice(end); this.mStringCache = tempStr; this.mSelectionEndCache = this.mSelectionStartCache; - } else if(leftOrRight == true) { + } else if (leftOrRight == true) { //delete right - if(this.mSelectionStartCache == this.mStringCache.length) { + if (start == this.mStringCache.length) { return; } - this.mSelectionEndCache += length; - let tempStr: string = this.mStringCache.slice(0,this.mSelectionStartCache) + this.mStringCache.slice(this.mSelectionEndCache); + const tbStart = start == end ? 1 : 0; + this.replace(start, end, "", tbStart, 0); + this.mSelectionEndCache = start; + let tempStr: string = this.mStringCache.slice(0, start) + (end + 1 >= this.mStringCache.length ? "" : this.mStringCache.slice(end + 1)); this.mStringCache = tempStr; this.mSelectionStartCache = this.mSelectionEndCache; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextEditingDelta.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextEditingDelta.ets index 1aa1b2d87245f029c1b8a630fecf02bceb41ea8d..495c4a51821d5b9279c56dc134138e5ccb17b41f 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextEditingDelta.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextEditingDelta.ets @@ -38,11 +38,11 @@ export class TextEditingDelta { this.newSelectionEnd = selectionEnd; this.newComposingStart = composingStart; this.newComposingEnd = composingEnd; - if(replacementDestinationStart === undefined || + if (replacementDestinationStart === undefined || replacementDestinationEnd === undefined || replacementSource === undefined) { this.setDeltas(oldEditable, "", -1, -1); - } else { + } else { this.setDeltas( oldEditable, replacementSource, @@ -58,4 +58,30 @@ export class TextEditingDelta { this.deltaStart = newStart; this.deltaEnd = newExtent; } + + toJSON(): TextEditingDeltaJson { + let state: TextEditingDeltaJson = { + oldText: this.oldText.toString(), + deltaText: this.deltaText.toString(), + deltaStart: this.deltaStart, + deltaEnd: this.deltaEnd, + selectionBase: this.newSelectionStart, + selectionExtent: this.newSelectionEnd, + composingBase: this.newComposingStart, + composingExtent: this.newComposingEnd, + }; + return state; + } +} + + +export interface TextEditingDeltaJson { + oldText: string; + deltaText: string; + deltaStart: number; + deltaEnd: number; + selectionBase: number; + selectionExtent: number; + composingBase: number; + composingExtent: number; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index ca7f22a339dd13c6b6fcf4c06a1a1b4f40604e16..9252bf0b0242a9e09e579d883b4546f25e36bf6d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -13,14 +13,17 @@ * limitations under the License. */ -import TextInputChannel, { Configuration, TextEditState, +import TextInputChannel, { + Configuration, + TextEditState, TextInputMethodHandler, - TextInputType } from '../../embedding/engine/systemchannels/TextInputChannel'; + TextInputType +} from '../../embedding/engine/systemchannels/TextInputChannel'; import inputMethod from '@ohos.inputMethod'; import Log from '../../util/Log'; import { EditingStateWatcher, ListenableEditingState } from './ListenableEditingState'; -export default class TextInputPlugin implements EditingStateWatcher{ +export default class TextInputPlugin implements EditingStateWatcher { private static TAG = "TextInputPlugin"; private textInputChannel: TextInputChannel; private mTextInputHandler: TextInputMethodHandlerImpl; @@ -42,19 +45,25 @@ export default class TextInputPlugin implements EditingStateWatcher{ didChangeEditingState(textChanged: boolean, selectionChanged: boolean, composingRegionChanged: boolean): void { let editable = this.mTextInputHandler.mEditable; let inputTarget = this.mTextInputHandler.inputTarget; - this.textInputChannel.updateEditingState(inputTarget.id, editable.getStringCache(), - editable.getSelectionStart(), editable.getSelectionEnd(), - editable.getComposingStart(), editable.getComposingEnd()) + let configuration = this.mTextInputHandler.configuration; + if (configuration!= null && configuration.enableDeltaModel) { + this.textInputChannel.updateEditingStateWithDeltas(inputTarget.id,editable.extractBatchTextEditingDeltas()); + editable.clearBatchDeltas(); + } else { + this.textInputChannel.updateEditingState(inputTarget.id, editable.getStringCache(), + editable.getSelectionStart(), editable.getSelectionEnd(), + editable.getComposingStart(), editable.getComposingEnd()) + } + } detach(): void { this.mTextInputHandler.inputMethodController.detach((err) => { - if(err) { + if (err) { Log.e(TextInputPlugin.TAG, "Failed to detach: " + JSON.stringify(err)); } }) } - } class TextInputMethodHandlerImpl implements TextInputMethodHandler { @@ -62,7 +71,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { private textConfig: inputMethod.TextConfig; inputMethodController: inputMethod.InputMethodController; inputTarget: InputTarget; - private configuration: Configuration | null = null; + public configuration: Configuration | null = null; mEditable: ListenableEditingState; private mRestartInputPending: boolean = false; private plugin: EditingStateWatcher | ESObject; @@ -74,7 +83,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { inputAttribute: { textInputType: 0, enterKeyType: 1 - }}; + } }; this.plugin = plugin; this.mEditable = new ListenableEditingState(null, 0); this.inputMethodController = inputMethod.getController(); @@ -82,7 +91,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } show(): void { - if(this.keyboardStatus == KeyboardStatus.SHOW){ + if (this.keyboardStatus == KeyboardStatus.SHOW) { return; } this.showTextInput(); @@ -103,7 +112,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } setClient(textInputClientId: number, configuration: Configuration | null): void { - Log.d(TextInputMethodHandlerImpl.TAG,"textInputClientId: " + textInputClientId); + Log.d(TextInputMethodHandlerImpl.TAG, "textInputClientId: " + textInputClientId); this.setTextInputClient(textInputClientId, configuration); } @@ -116,7 +125,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } setEditingState(editingState: TextEditState): void { - Log.d(TextInputMethodHandlerImpl.TAG, "text:" + editingState.text +" selectionStart:" + editingState.selectionStart + " selectionEnd:" + Log.d(TextInputMethodHandlerImpl.TAG, "text:" + editingState.text + " selectionStart:" + editingState.selectionStart + " selectionEnd:" + editingState.selectionEnd + " composingStart:" + editingState.composingStart + " composingEnd" + editingState.composingEnd); this.mEditable.updateTextInputState(editingState); } @@ -127,10 +136,10 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { private async showTextInput(): Promise { await this.attach(true); - if(this.imcFlag != true) { + if (this.imcFlag != true) { this.listenKeyBoardEvent(); } - this.inputMethodController.showTextInput().then(()=> { + this.inputMethodController.showTextInput().then(() => { Log.d(TextInputMethodHandlerImpl.TAG, "Succeeded in showing softKeyboard"); }).catch((err: ESObject) => { Log.e(TextInputMethodHandlerImpl.TAG, "Failed to show softKeyboard:" + JSON.stringify(err)); @@ -145,7 +154,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { }) } - async attach(showKeyboard: boolean): Promise { + async attach(showKeyboard: boolean): Promise { try { await this.inputMethodController.attach(showKeyboard, this.textConfig); } catch (err) { @@ -154,17 +163,15 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } setTextInputClient(client: number, configuration: Configuration | null): void { - const INPUT_TYPE_NAME = ['NONE', 'TEXT', 'MULTILINE', 'NUMBER', 'PHONE','DATETIME','EMAIL_ADDRESS','URL','VISIBLE_PASSWORD'] - if(configuration) - { + const INPUT_TYPE_NAME = ['NONE', 'TEXT', 'MULTILINE', 'NUMBER', 'PHONE', 'DATETIME', 'EMAIL_ADDRESS', 'URL', 'VISIBLE_PASSWORD'] + if (configuration) { this.configuration = configuration; - if(configuration.inputType) - { - this.textConfig.inputAttribute.textInputType =INPUT_TYPE_NAME.indexOf(configuration.inputType.type) + if (configuration.inputType) { + this.textConfig.inputAttribute.textInputType = INPUT_TYPE_NAME.indexOf(configuration.inputType.type) this.textConfig.inputAttribute.enterKeyType = configuration.inputAction as ESObject; } } - if(this.canShowTextInput()) { + if (this.canShowTextInput()) { this.inputTarget = new InputTarget(Type.FRAMEWORK_CLIENT, client); } else { this.inputTarget = new InputTarget(Type.NO_TARGET, client); @@ -178,7 +185,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } canShowTextInput(): boolean { - if(this.configuration == null || this.configuration.inputType == null) { + if (this.configuration == null || this.configuration.inputType == null) { return true; } return this.configuration.inputType.type != TextInputType.NONE; @@ -228,7 +235,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { try { this.inputMethodController.on('sendKeyboardStatus', (state) => { - if(state == KeyboardStatus.HIDE) { + if (state == KeyboardStatus.HIDE) { this.keyboardStatus = KeyboardStatus.HIDE; this.plugin.textInputChannel.onConnectionClosed(this.inputTarget.id); } @@ -261,7 +268,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } public clearTextInputClient(): void { - if(this.inputTarget.type == Type.VIRTUAL_DISPLAY_PLATFORM_VIEW) { + if (this.inputTarget.type == Type.VIRTUAL_DISPLAY_PLATFORM_VIEW) { return; } this.mEditable.removeEditingStateListener(this.plugin); @@ -295,5 +302,4 @@ export class InputTarget { this.type = type; this.id = id; } - } \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets index 437b52f18049b9ba77e47350033482a06368c5c4..33796b25fe8d344ceb1f83eeefc36b210f5f5711 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets @@ -91,6 +91,12 @@ export default class Log { */ static e(tag: string, format: string, ...args: ESObject[]) { if (Log.isLoggable(HiLog.LogLevel.ERROR)) { + args.forEach((item: ESObject, index: number) => { + if (item instanceof Error) { + args[index] = item.message + item.stack; + } + format+="%{public}s"; + }) HiLog.error(DOMAIN, TAG, tag + SYMBOL + format, args); } } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/PathUtils.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/PathUtils.ets index 691ea0f360b40adb266bde566c2f66292a2aa0ff..f47bcb68b0755dba14200d8a44db899528119191 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/PathUtils.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/PathUtils.ets @@ -30,7 +30,7 @@ export default class PathUtils { return context.cacheDir; } - static getDataDirectory(context: common.Context): string { + static getDataDirectory(context: common.Context): string | null { const name = "flutter"; const flutterDir = context.filesDir + "/" + name; if (!fs.accessSync(flutterDir)) { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterNativeView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterNativeView.ets deleted file mode 100644 index 9138ad728502e49e675e69e1fd533d80ad7016bc..0000000000000000000000000000000000000000 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterNativeView.ets +++ /dev/null @@ -1,137 +0,0 @@ -/* -* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import common from '@ohos.app.ability.common'; -import DartExecutor from '../embedding/engine/dart/DartExecutor'; -import { EngineLifecycleListener } from '../embedding/engine/FlutterEngine'; -import FlutterNapi from '../embedding/engine/FlutterNapi'; -import Log from '../util/Log'; -import FlutterPluginRegistry from '../app/FlutterPluginRegistry'; -import FlutterRunArguments from './FlutterRunArguments'; -import { FlutterView } from './FlutterView'; - -const TAG: string = "FlutterNativeView"; - -export default class FlutterNativeView { - private mContext: common.Context; - private mPluginRegistry: FlutterPluginRegistry; - private mFlutterNapi: FlutterNapi; - private dartExecutor: DartExecutor; - private mFlutterView: FlutterView; - private applicationIsRunning: boolean; - - constructor(context: common.Context, isBackgroundView?: boolean) { - if (isBackgroundView) { - Log.i(TAG, "isBackgroundView is no longer supported and will be ignored"); - } - this.mContext = context; - this.mPluginRegistry = new FlutterPluginRegistry(); - this.mFlutterNapi = new FlutterNapi(); - //this.mFlutterNapi.addIsDisplayingFlutterUiListener(this.flutterUiDisplayListener); - this.dartExecutor = new DartExecutor(this.mFlutterNapi, this.mContext.resourceManager); - this.mFlutterNapi.addEngineLifecycleListener(new EngineLifecycleListenerImpl(this.mFlutterView, this.mPluginRegistry)); - this.attach(this.mFlutterNapi, this.dartExecutor); - this.assertAttached(this.mFlutterNapi); - } - - attach(flutterNapi: FlutterNapi, dartExecutor: DartExecutor): void { - flutterNapi.attachToNative(); - dartExecutor.onAttachedToNAPI(); - } - - assertAttached(flutterNapi: FlutterNapi): void { - if (!this.isAttached(flutterNapi)) { - throw new Error('Platform View is not attached'); - } - } - - isAttached(flutterNapi: FlutterNapi): boolean { - return flutterNapi.isAttached(); - } - - detachFromFlutterView(): void { - this.mPluginRegistry.detach(); - this.mFlutterView = null; - } - - destroy(): void { - this.mPluginRegistry.destroy(); - this.dartExecutor.onDetachedFromNAPI(); - this.mFlutterView = null; - //this.mFlutterNapi.removeIsDisplayingFlutterUiListener(this.flutterUiDisplayListener); - this.applicationIsRunning = false; - } - - getDartExecutor(): DartExecutor { - return this.dartExecutor; - } - - getPluginRegistry(): FlutterPluginRegistry { - return this.mPluginRegistry; - } - - attachViewAndAbility(flutterView: FlutterView, context: common.Context): void { - this.mFlutterView = flutterView; - this.mPluginRegistry.attach(flutterView, context); - } - - runFromBundle(args: FlutterRunArguments): void { - if (args.entrypoint == null) { - throw new Error("an entrypoint must be specific"); - } - this.assertAttached(this.mFlutterNapi); - if (this.applicationIsRunning) { - throw new Error("this flutter engine instance is already running an application"); - } - this.mFlutterNapi.runBundleAndSnapshotFromLibrary(args.bundlePath, args.entrypoint, args.libraryPath, this.mContext.resourceManager, null); - this.applicationIsRunning = true; - } - - isApplicationRunning(): boolean { - return this.applicationIsRunning; - } - - // getObservatoryUri(): string { - // return this.mFlutterNapi.getObservatoryUri(); - // } -} - -class EngineLifecycleListenerImpl implements EngineLifecycleListener { - private flutterView: FlutterView; - private pluginRegistry: FlutterPluginRegistry; - - onPreEngineRestart(): void { - if (this.flutterView != null) { - //this.flutterView.resetAccessibilityTree(); - } - - if (this.pluginRegistry == null) { - return; - } - - this.pluginRegistry.onPreEngineRestart(); - } - - onEngineWillDestroy(): void { - - } - - constructor(flutterView: FlutterView, pluginRegistry: FlutterPluginRegistry) { - this.flutterView = flutterView; - this.pluginRegistry = pluginRegistry; - } -} - - diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterRunArguments.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterRunArguments.ets index d17ec28d1fdc6237ee486362751ee25e58590887..c81e33f381f06662a8b881df3452d76038837361 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterRunArguments.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterRunArguments.ets @@ -17,4 +17,10 @@ export default class FlutterRunArguments { public bundlePath: string; public entrypoint: string; public libraryPath: string; + + constructor(bundlePath: string, entrypoint: string, libraryPath: string) { + this.bundlePath = bundlePath; + this.entrypoint = entrypoint; + this.libraryPath = libraryPath; + } } \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 b/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 index 3496547c0bf7facd5ffce8a2ee7ff8ea64fd5ef8..5c4892a18d34742a191e72c3729f168444966edc 100755 --- a/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 +++ b/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 @@ -12,9 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2", - } + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2", + } } diff --git a/shell/platform/ohos/flutter_embedding/hvigorfile.ts b/shell/platform/ohos/flutter_embedding/hvigorfile.ts index 5a172b770e3b15f67c12152d00f38f2084d3915b..8f2d2aafe6d6a3a71a9944ebd0c91fbc308ac9d1 100755 --- a/shell/platform/ohos/flutter_embedding/hvigorfile.ts +++ b/shell/platform/ohos/flutter_embedding/hvigorfile.ts @@ -13,5 +13,9 @@ * limitations under the License. */ -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -export { appTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/local.properties b/shell/platform/ohos/flutter_embedding/local.properties index 42b3cf913edcd8d66de22dd116909893a09e7550..bc8cf2a57b8e2c4cb07ed1fa172df80a8f546f81 100755 --- a/shell/platform/ohos/flutter_embedding/local.properties +++ b/shell/platform/ohos/flutter_embedding/local.properties @@ -1,23 +1,22 @@ -# Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This file is automatically generated by DevEco Studio. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file should *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# For customization when using a Version Control System, please read the header note. -sdk.dir= -nodejs.dir= - +# Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This file is automatically generated by DevEco Studio. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file should *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# For customization when using a Version Control System, please read the header note. +sdk.dir= +nodejs.dir= diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index f592b7e0dfcaf661d8c3e14d4100f2191a1e3dff..a657f6b949fecfd0af46467abe5b3852a0fe8f0f 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -268,10 +268,9 @@ void XComponentBase::DetachFlutterEngine() { if (window_ != nullptr) { PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); } else { - LOGE("OnSurfaceCreated XComponentBase is not attached"); + LOGE("DetachFlutterEngine XComponentBase is not attached"); } shellholderId_ = ""; - window_ = nullptr; isEngineAttached_ = false; } diff --git a/tools/gn b/tools/gn index a5efe0f75d58748cd6047a78e22dc9735d7e7eb5..8f6f1fef7d6346dcf6478081013f85cf8be81c76 100755 --- a/tools/gn +++ b/tools/gn @@ -303,6 +303,9 @@ def to_gn_args(args): gn_args['is_official_build'] = True # Disable Skia test utilities. gn_args['android_full_debug' ] = args.target_os == 'android' and args.unoptimized + + gn_args['ohos_api_int'] = args.ohos_api_int + if args.clang is None: gn_args['is_clang'] = True else: @@ -761,6 +764,9 @@ def parse_args(args): parser.add_argument( '--ohos-cpu', type=str, choices=['x64', 'x86', 'arm64', 'arm'] ) + parser.add_argument( + '--ohos-api-int', type=int, choices=[10, 11], default=11 + ) parser.add_argument( '--fuchsia-cpu', type=str, choices=['x64', 'arm64'], default='x64' ) @@ -1047,10 +1053,10 @@ def main(argv): print('XX target_os:%s' % args.target_os) if args.target_os == 'ohos': - if args.ohos_cpu is not None: - args.linux_cpu = args.ohos_cpu - elif args.linux_cpu is not None : - args.ohos_cpu = args.linux_cpu + if args.ohos_cpu is not None: + args.linux_cpu = args.ohos_cpu + elif args.linux_cpu is not None : + args.ohos_cpu = args.linux_cpu if not args.web: if args.ide != '':