From a64c4822d685c00cf261d52156dbcaf34c7a5033 Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Wed, 17 Jan 2024 16:03:50 +0800 Subject: [PATCH 01/26] IssueNo: zhan-linlin 17301907374@163.com Sig: OpenHarmony-SIG/flutter-engine Feature or Bugfix: Bugfix Binary Source: No Signed-off-by: zhan-linlin <17301907374@163.com> --- .../flutter_embedding/flutter/src/main/ets/util/Log.ets | 6 ++++++ 1 file changed, 6 insertions(+) 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 437b52f180..8dcfb79903 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.format((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); } } -- Gitee From a2b02ef02e3a06212d1cbbcfab7c201f9ca5f1bf Mon Sep 17 00:00:00 2001 From: zmf <279822581@qq.com> Date: Thu, 18 Jan 2024 16:00:38 +0800 Subject: [PATCH 02/26] =?UTF-8?q?=E7=A7=BB=E9=99=A4skia=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E5=A4=9A=E4=BD=99=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zmf <279822581@qq.com> --- attachment/repos/skia.patch | 53 ------------------- .../renderer/backend/vulkan/context_vk.cc | 1 + 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/attachment/repos/skia.patch b/attachment/repos/skia.patch index 455594c1ba..d993bdffa7 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/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc index db5574ce4f..0427f9fdf0 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" -- Gitee From f183262964b0c4e636e1d36e25e680bc990e26f1 Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Mon, 22 Jan 2024 16:05:22 +0800 Subject: [PATCH 03/26] =?UTF-8?q?DetachFlutterEngine=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=B0=86window=E8=AE=BE=E7=BD=AE=E4=B8=BAnullptr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiang --- shell/platform/ohos/ohos_xcomponent_adapter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index f592b7e0df..a657f6b949 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; } -- Gitee From ab1485441047a3226d41d7ab38059342cbde7213 Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Tue, 23 Jan 2024 16:04:40 +0800 Subject: [PATCH 04/26] =?UTF-8?q?=E7=A1=AE=E8=AE=A4aboutToAppear=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=8F=AA=E4=BC=9A=E8=BF=9B=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiang --- .../ohos/flutter_embedding/flutter/index.ets | 20 ++++++++++++++++-- .../main/ets/embedding/ohos/FlutterEntry.ets | 21 ++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/index.ets b/shell/platform/ohos/flutter_embedding/flutter/index.ets index 3c96b70703..a69f1c32bb 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/index.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/index.ets @@ -13,6 +13,22 @@ * limitations under the License. */ -export { FlutterAbility } from './src/main/ets/embedding/ohos/FlutterAbility' +import FlutterManager from './src/main/ets/embedding/ohos/FlutterManager'; +import { FlutterAbility } from './src/main/ets/embedding/ohos/FlutterAbility' +import { FlutterPage } from './src/main/ets/embedding/ohos/FlutterPage' +import { FlutterPlugin } from './src/main/ets/embedding/engine/plugins/FlutterPlugin' +import { FlutterView } from './src/main/ets/view/FlutterView'; +import FlutterEntry from './src/main/ets/embedding/ohos/FlutterEntry'; +import FlutterEngine from './src/main/ets/embedding/engine/FlutterEngine'; +import PlatformPlugin from './src/main/ets/plugin/PlatformPlugin'; -export { FlutterPage } from './src/main/ets/embedding/ohos/FlutterPage' +export { + PlatformPlugin, + FlutterPlugin, + FlutterView, + FlutterEntry, + FlutterEngine, + FlutterAbility, + FlutterManager, + FlutterPage +} \ No newline at end of file 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 e995319b54..e66095a173 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 @@ -40,24 +40,29 @@ export default class FlutterEntry implements Host { private windowStage: window.WindowStage | null = null private parameters: ESObject = {}; private engineConfigurator: FlutterEngineConfigurator | null = null + private hasInit: boolean = false; constructor(context: Context, params: ESObject = {}) { 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) => { -- Gitee From 746e9759805deea8229f1fc76201b80573b1a94b Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Tue, 23 Jan 2024 16:39:50 +0800 Subject: [PATCH 05/26] =?UTF-8?q?index.d.ets=E6=9A=B4=E9=9C=B2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiang --- .../ohos/flutter_embedding/flutter/index.ets | 183 ++++++++++++++++-- 1 file changed, 171 insertions(+), 12 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/index.ets b/shell/platform/ohos/flutter_embedding/flutter/index.ets index a69f1c32bb..21cb665ac4 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/index.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/index.ets @@ -13,22 +13,181 @@ * limitations under the License. */ -import FlutterManager from './src/main/ets/embedding/ohos/FlutterManager'; -import { FlutterAbility } from './src/main/ets/embedding/ohos/FlutterAbility' -import { FlutterPage } from './src/main/ets/embedding/ohos/FlutterPage' -import { FlutterPlugin } from './src/main/ets/embedding/engine/plugins/FlutterPlugin' -import { FlutterView } from './src/main/ets/view/FlutterView'; -import FlutterEntry from './src/main/ets/embedding/ohos/FlutterEntry'; +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 FlutterNativeView from './src/main/ets/view/FlutterNativeView'; +import FlutterRunArguments from './src/main/ets/view/FlutterRunArguments'; +import { FlutterView } from './src/main/ets/view/FlutterView'; +import { TextureRegistry } from './src/main/ets/view/TextureRegistry'; export { - PlatformPlugin, - FlutterPlugin, - FlutterView, - FlutterEntry, + 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 -} \ No newline at end of file + 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, + FlutterNativeView, + FlutterRunArguments, + FlutterView, + TextureRegistry, +} -- Gitee From 49921622ebe4be0f44dbc3585d976cc41168c0a0 Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Wed, 24 Jan 2024 12:59:51 +0800 Subject: [PATCH 06/26] lint Signed-off-by: xiaoxiang --- .../ohos/flutter_embedding/flutter/index.ets | 2 - .../main/ets/app/FlutterPluginRegistry.ets | 6 +- .../ets/plugin/common/BinaryMessenger.ets | 6 +- .../main/ets/plugin/common/EventChannel.ets | 14 +- .../src/main/ets/view/FlutterNativeView.ets | 137 ------------------ .../src/main/ets/view/FlutterRunArguments.ets | 6 + 6 files changed, 20 insertions(+), 151 deletions(-) delete mode 100644 shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterNativeView.ets diff --git a/shell/platform/ohos/flutter_embedding/flutter/index.ets b/shell/platform/ohos/flutter_embedding/flutter/index.ets index 21cb665ac4..c146ae457d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/index.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/index.ets @@ -97,7 +97,6 @@ import { PlatformViewsAccessibilityDelegate } from './src/main/ets/plugin/platfo 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 FlutterNativeView from './src/main/ets/view/FlutterNativeView'; import FlutterRunArguments from './src/main/ets/view/FlutterRunArguments'; import { FlutterView } from './src/main/ets/view/FlutterView'; import { TextureRegistry } from './src/main/ets/view/TextureRegistry'; @@ -186,7 +185,6 @@ export { PlatformViewsController, AccessibilityBridge, FlutterCallbackInformation, - FlutterNativeView, FlutterRunArguments, FlutterView, TextureRegistry, 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 2a2a44964d..4eabe6ad35 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; + private mContext: common.Context | 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/plugin/common/BinaryMessenger.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets index e0b55276be..68925a8b1a 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 166659a32e..cc792fbb52 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,7 +40,7 @@ export default class EventChannel { private messenger: BinaryMessenger; private name: string; private codec: MethodCodec; - private taskQueue: TaskQueue; + private taskQueue: TaskQueue | undefined; constructor(messenger: BinaryMessenger, name: string, codec?: MethodCodec, taskQueue?: TaskQueue) { this.messenger = messenger @@ -240,22 +240,22 @@ class EventSinkImplementation implements EventSink { } } -class AtomicReference { - private value: T; +class AtomicReference { + 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): T | null { const oldValue = this.value; this.value = newValue; return oldValue; 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 9138ad7285..0000000000 --- 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 d17ec28d1f..c81e33f381 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 -- Gitee From f1fcec04102e24d44f08f4a9084637b9be04ea94 Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Fri, 26 Jan 2024 17:29:51 +0800 Subject: [PATCH 07/26] =?UTF-8?q?=E8=A7=A3=E5=86=B3XComponent=20type?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=94=99=E8=AF=AF=E5=BC=95=E8=B5=B7=E7=9A=84?= =?UTF-8?q?flutterpage=E5=88=87=E6=8D=A2=E6=97=B6=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E9=BB=91=E5=B1=8F=E5=92=8Cflutterpage=E5=8D=8A=E5=B1=8F?= =?UTF-8?q?=E9=80=8F=E6=98=8E=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwyang <137208408@qq.com> --- .../flutter/src/main/ets/component/XComponentStruct.ets | 2 +- .../flutter/src/main/ets/embedding/ohos/FlutterPage.ets | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 e9d66ef987..d8198a8b32 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/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 483813fa6a..53e7ef62d1 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 @@ -46,7 +46,7 @@ export struct FlutterPage { 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() -- Gitee From 330b1673786ee314a521d40625b488bfb50884ed Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Mon, 29 Jan 2024 15:26:30 +0800 Subject: [PATCH 08/26] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhan-linlin <17301907374@163.com> --- .../ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8dcfb79903..33796b25fe 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,7 +91,7 @@ export default class Log { */ static e(tag: string, format: string, ...args: ESObject[]) { if (Log.isLoggable(HiLog.LogLevel.ERROR)) { - args.format((item: ESObject, index: number) => { + args.forEach((item: ESObject, index: number) => { if (item instanceof Error) { args[index] = item.message + item.stack; } -- Gitee From 4bfbf9b80e295b87c921f15811bf057f0fa40e56 Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Tue, 30 Jan 2024 16:03:31 +0800 Subject: [PATCH 09/26] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A2=9E=E9=87=8F?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=89=A7=E8=A1=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhan-linlin <17301907374@163.com> --- .../systemchannels/TextInputChannel.ets | 62 ++++++++++++----- .../plugin/editing/ListenableEditingState.ets | 67 +++++++++++++++---- .../ets/plugin/editing/TextEditingDelta.ets | 30 ++++++++- .../ets/plugin/editing/TextInputPlugin.ets | 60 +++++++++-------- 4 files changed, 160 insertions(+), 59 deletions(-) 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 c02c3ad005..315a433f84 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/plugin/editing/ListenableEditingState.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets index 953f7cad09..4c215d195d 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,17 +145,23 @@ export class ListenableEditingState { } handleInsertTextEvent(text: string): void { + 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) { //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) { @@ -217,22 +252,30 @@ export class ListenableEditingState { } handleDeleteEvent(leftOrRight: boolean, length: number): void { + 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) { //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 1aa1b2d872..495c4a5182 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 ca7f22a339..9252bf0b02 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 -- Gitee From 349d7ce4ff04fe0d720407c6879a8b8a3cac4833 Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Tue, 30 Jan 2024 16:34:39 +0800 Subject: [PATCH 10/26] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A2=9E=E9=87=8F?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=89=A7=E8=A1=8C=E9=80=BB=E8=BE=91=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhan-linlin <17301907374@163.com> --- .../plugin/editing/ListenableEditingState.ets | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) 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 4c215d195d..0726ab0fb4 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 @@ -66,7 +66,7 @@ export class ListenableEditingState { return currentBatchDeltas; } - clearBatchDeltas():void { + clearBatchDeltas(): void { this.mBatchTextEditingDeltas.clear(); } @@ -145,26 +145,26 @@ export class ListenableEditingState { } handleInsertTextEvent(text: string): void { - let start = this.mSelectionStartCache < this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; - let end = this.mSelectionStartCache > this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; + 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); + this.replace(start, end, text, 0, length); - if(this.mStringCache.length == this.mSelectionStartCache) { + if (this.mStringCache.length == this.mSelectionStartCache) { //Insert text one by one - let tempStr: string = this.mStringCache.substring(0,start) + text + this.mStringCache.substring(end); + 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, start) + text + this.mStringCache.substring(end); this.mStringCache = tempStr; - this.mSelectionStartCache = start+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; } @@ -174,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 { @@ -252,30 +252,30 @@ export class ListenableEditingState { } handleDeleteEvent(leftOrRight: boolean, length: number): void { - let start = this.mSelectionStartCache < this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; - let end = this.mSelectionStartCache > this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; + let start = this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + let end = this.mSelectionStartCache > this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; - if(leftOrRight == false) { + if (leftOrRight == false) { //delete left - if(start == 0 && end == 0) { + if (start == 0 && end == 0) { return; } - const startData = start== end ?start-1:start; - const tbEnd = start== end ?-1:0; - this.replace(startData,end,"",0,tbEnd); + 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(start == this.mStringCache.length) { + if (start == this.mStringCache.length) { return; } - const tbStart= start== end ?1:0; - this.replace(start,end,"",tbStart,0); + 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 )); + 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; } -- Gitee From 26f1d5d00880b0522fe21ce88676f0f20aa8132c Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Tue, 30 Jan 2024 17:03:35 +0800 Subject: [PATCH 11/26] =?UTF-8?q?=E6=9A=B4=E9=9C=B2util=E7=9A=84=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiang --- .../ohos/flutter_embedding/flutter/index.ets | 14 ++++++++++++++ .../flutter/src/main/ets/util/PathUtils.ets | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/index.ets b/shell/platform/ohos/flutter_embedding/flutter/index.ets index c146ae457d..a9e43723cb 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/index.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/index.ets @@ -100,6 +100,13 @@ import { FlutterCallbackInformation } from './src/main/ets/view/FlutterCallbackI 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 { FlutterInjector, @@ -188,4 +195,11 @@ export { FlutterRunArguments, FlutterView, TextureRegistry, + ByteBuffer, + Log, + MessageChannelUtils, + PathUtils, + StringUtils, + ToolUtils, + TraceSection, } 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 691ea0f360..f47bcb68b0 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)) { -- Gitee From 25142f9038c258accacbfd1aac86c39ad9a367f2 Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Wed, 31 Jan 2024 01:16:03 +0800 Subject: [PATCH 12/26] =?UTF-8?q?=E4=BF=AE=E5=A4=8DStandardMessageCodec?= =?UTF-8?q?=E8=A7=A3=E7=A0=81type=E7=B1=BB=E5=9E=8B=E6=97=B6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8readint8=E4=B8=8D=E5=8C=B9=E9=85=8D=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiang --- .../flutter/src/main/ets/plugin/common/StandardMessageCodec.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2ee2ef39b2..88de0fc5de 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 @@ -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); } -- Gitee From f2eba99d185ea437db160f2f185d046f59503069 Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Thu, 1 Feb 2024 20:21:26 +0800 Subject: [PATCH 13/26] =?UTF-8?q?=E4=BF=AE=E5=A4=8DFlutterEntry=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=8F=82=E6=95=B0=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangxiaoyao <976125628@qq.com> --- .../ohos/FlutterAbilityLaunchConfigs.ets | 11 ++++++- .../main/ets/embedding/ohos/FlutterEntry.ets | 30 +++++++++---------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets index 996f455b9d..a1ae4bdb86 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets @@ -43,4 +43,13 @@ export default class FlutterAbilityLaunchConfigs { static DEFAULT_DART_ENTRYPOINT = "main"; static DEFAULT_INITIAL_ROUTE = "/"; static DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque -} \ No newline at end of file +} + +export interface ParamsConfigs { + should_attach_engine_to_ability?: boolean; + dart_entrypoint?: string; + route?: string; + cached_engine_id?: string; + dart_entrypoint_args?: Array; + cached_engine_group_id?: string | null; +} 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 e66095a173..a9984b3f9e 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 @@ -21,7 +21,7 @@ import ExclusiveAppComponent from './ExclusiveAppComponent'; import { FlutterPlugin } from '../engine/plugins/FlutterPlugin'; import List from '@ohos.util.List'; import { FlutterAbilityAndEntryDelegate, Host } from './FlutterAbilityAndEntryDelegate'; -import FlutterAbilityLaunchConfigs from './FlutterAbilityLaunchConfigs'; +import FlutterAbilityLaunchConfigs, { ParamsConfigs } from './FlutterAbilityLaunchConfigs'; import Log from '../../util/Log'; import { FlutterView } from '../../view/FlutterView'; import FlutterManager from './FlutterManager'; @@ -38,11 +38,11 @@ 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: ParamsConfigs; private engineConfigurator: FlutterEngineConfigurator | null = null private hasInit: boolean = false; - - constructor(context: Context, params: ESObject = {}) { + + constructor(context: Context, params: ParamsConfigs) { this.context = context; this.uiAbility = FlutterManager.getInstance().getUIAbility(context); this.parameters = params; @@ -143,15 +143,15 @@ export default class FlutterEntry implements Host { } shouldAttachEngineToAbility(): boolean { - return this.parameters![FlutterEntry.ARG_SHOULD_ATTACH_ENGINE_TO_ABILITY] as boolean + return this.parameters!.should_attach_engine_to_ability as boolean } getCachedEngineId(): string { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as string + return this.parameters!.cached_engine_id as string } getCachedEngineGroupId(): string | null { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_GROUP_ID] as string + return this.parameters!.cached_engine_group_id as string } shouldDestroyEngineWithHost(): boolean { @@ -167,8 +167,8 @@ export default class FlutterEntry implements Host { } getDartEntrypointArgs(): string[] { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS] as Array; + if (this.parameters!.dart_entrypoint_args) { + return this.parameters!.dart_entrypoint_args as Array; } return new Array() } @@ -182,15 +182,15 @@ export default class FlutterEntry implements Host { } getDartEntrypointFunctionName(): string { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT] as string; + if (this.parameters!.dart_entrypoint) { + return this.parameters!.dart_entrypoint as string; } return FlutterAbilityLaunchConfigs.DEFAULT_DART_ENTRYPOINT } getInitialRoute(): string { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE] as string + if (this.parameters!.route) { + return this.parameters!.route as string } return ""; } @@ -200,8 +200,8 @@ export default class FlutterEntry implements Host { } shouldRestoreAndSaveState(): boolean { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] != undefined) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as boolean; + if (this.parameters!.cached_engine_id != undefined) { + return true; } if (this.getCachedEngineId() != null && this.getCachedEngineId().length > 0) { // Prevent overwriting the existing state in a cached engine with restoration state. -- Gitee From e34b1ca4e603fffbe18d5c5c8062f0c7a311dc63 Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Fri, 2 Feb 2024 12:43:36 +0800 Subject: [PATCH 14/26] =?UTF-8?q?=E4=BF=AE=E5=A4=8DFlutterEntry=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=8F=82=E6=95=B0=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangxiaoyao <976125628@qq.com> --- .../ohos/FlutterAbilityLaunchConfigs.ets | 11 +------ .../main/ets/embedding/ohos/FlutterEntry.ets | 30 +++++++++---------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets index a1ae4bdb86..996f455b9d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets @@ -43,13 +43,4 @@ export default class FlutterAbilityLaunchConfigs { static DEFAULT_DART_ENTRYPOINT = "main"; static DEFAULT_INITIAL_ROUTE = "/"; static DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque -} - -export interface ParamsConfigs { - should_attach_engine_to_ability?: boolean; - dart_entrypoint?: string; - route?: string; - cached_engine_id?: string; - dart_entrypoint_args?: Array; - cached_engine_group_id?: string | null; -} +} \ No newline at end of file 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 a9984b3f9e..d90be8a48b 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 @@ -21,7 +21,7 @@ import ExclusiveAppComponent from './ExclusiveAppComponent'; import { FlutterPlugin } from '../engine/plugins/FlutterPlugin'; import List from '@ohos.util.List'; import { FlutterAbilityAndEntryDelegate, Host } from './FlutterAbilityAndEntryDelegate'; -import FlutterAbilityLaunchConfigs, { ParamsConfigs } from './FlutterAbilityLaunchConfigs'; +import FlutterAbilityLaunchConfigs from './FlutterAbilityLaunchConfigs'; import Log from '../../util/Log'; import { FlutterView } from '../../view/FlutterView'; import FlutterManager from './FlutterManager'; @@ -38,11 +38,11 @@ export default class FlutterEntry implements Host { private flutterView: FlutterView | null = null private context: Context; private windowStage: window.WindowStage | null = null - private parameters: ParamsConfigs; + private parameters: Record = {}; private engineConfigurator: FlutterEngineConfigurator | null = null private hasInit: boolean = false; - - constructor(context: Context, params: ParamsConfigs) { + + constructor(context: Context, params: Record = {}) { this.context = context; this.uiAbility = FlutterManager.getInstance().getUIAbility(context); this.parameters = params; @@ -143,15 +143,15 @@ export default class FlutterEntry implements Host { } shouldAttachEngineToAbility(): boolean { - return this.parameters!.should_attach_engine_to_ability as boolean + return this.parameters![FlutterEntry.ARG_SHOULD_ATTACH_ENGINE_TO_ABILITY] as boolean } getCachedEngineId(): string { - return this.parameters!.cached_engine_id as string + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as string } getCachedEngineGroupId(): string | null { - return this.parameters!.cached_engine_group_id as string + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_GROUP_ID] as string } shouldDestroyEngineWithHost(): boolean { @@ -167,8 +167,8 @@ export default class FlutterEntry implements Host { } getDartEntrypointArgs(): string[] { - if (this.parameters!.dart_entrypoint_args) { - return this.parameters!.dart_entrypoint_args as Array; + if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS]) { + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS] as Array; } return new Array() } @@ -182,15 +182,15 @@ export default class FlutterEntry implements Host { } getDartEntrypointFunctionName(): string { - if (this.parameters!.dart_entrypoint) { - return this.parameters!.dart_entrypoint as string; + if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT]) { + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT] as string; } return FlutterAbilityLaunchConfigs.DEFAULT_DART_ENTRYPOINT } getInitialRoute(): string { - if (this.parameters!.route) { - return this.parameters!.route as string + if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE]) { + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE] as string } return ""; } @@ -200,8 +200,8 @@ export default class FlutterEntry implements Host { } shouldRestoreAndSaveState(): boolean { - if (this.parameters!.cached_engine_id != undefined) { - return true; + if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] != undefined) { + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as boolean; } if (this.getCachedEngineId() != null && this.getCachedEngineId().length > 0) { // Prevent overwriting the existing state in a cached engine with restoration state. -- Gitee From 9c767ce6c012d44308856bed73f548877a433bc1 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:00 +0800 Subject: [PATCH 15/26] =?UTF-8?q?=E6=9B=B4=E6=96=B0hvigor=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=89=88=E6=9C=AC=E4=B8=BA3.2.1-s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- README.en.md | 2 -- README.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/README.en.md b/README.en.md index 1b57e89b92..3fdf8e6498 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 5cb27d599c..e19e793031 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) -- Gitee From d67dc5395271bbc0d7a9ff4ea22d71d4eb3e165b Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:00 +0800 Subject: [PATCH 16/26] =?UTF-8?q?so=E6=96=87=E4=BB=B6=E6=89=93=E5=8C=85?= =?UTF-8?q?=E5=88=B0flutter=5Fembedding.har=E6=96=87=E4=BB=B6=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/build.patch | 245 +++++++++++++++++++++++++++++------ shell/platform/ohos/BUILD.gn | 79 ++++++++++- 2 files changed, 274 insertions(+), 50 deletions(-) diff --git a/attachment/repos/build.patch b/attachment/repos/build.patch index c3df91e35f..d1bf7b82e2 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,153 @@ 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..4e052ed +--- /dev/null ++++ b/build/ohos/ohos_create_flutter_har.py +@@ -0,0 +1,141 @@ ++#!/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", ++ } ++ ] ++ }, ++ "modules": [ ++ { ++ "name": "flutter", ++ "srcPath": "./flutter" ++ } ++ ] ++} ++""" ++ ++ ++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)) ++ ++ ++# 替换文件中的字符串 ++def replaceStr(file, regex, newstr): ++ with open(file, "r", encoding="utf-8") as f1: ++ lines = f1.readlines() ++ with open(file, "w+", encoding="utf-8") as f2: ++ for line in lines: ++ a = re.sub(regex, newstr, line) ++ f2.writelines(a) ++ ++ ++# 编译har文件 ++def buildHar(buildDir, apiInt, buildType): ++ updateConfig(buildDir, apiInt) ++ isDebug = "true" if buildType == "debug" else "false" ++ isProfile = "true" if buildType == "profile" else "false" ++ dirEmbedding = buildDir ++ targetFile = os.path.join( ++ buildDir, ++ "flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets", ++ ) ++ logging.info("isDebugMode=%s, isProfile=%s" % (isDebug, isProfile)) ++ replaceStr(targetFile, "isDebugMode = .*", "isDebugMode = %s;" % isDebug) ++ replaceStr(targetFile, "isProfile = .*", "isProfile = %s;" % isProfile) ++ runCommand( ++ ("cd %s && " % dirEmbedding) ++ + (".%s" % os.sep) ++ + "hvigorw --mode module -p module=flutter@default -p product=default 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/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index 8d18085468..aa2f620ed7 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -13,16 +13,19 @@ 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", #":publish_headers_ohos", + ":ohos_har" ] } shell_gpu_configuration("ohos_gpu_configuration") { @@ -195,10 +198,6 @@ executable("flutter_ohos_unittests") { shared_library("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 +267,69 @@ 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" + } +} + +action("ohos_har") { + script = "//build/ohos/ohos_create_flutter_har.py" + + if (stripped_symbols) { + engine_library = "so.unstripped/libflutter.so" + } else { + engine_library = "libflutter.so" + } + #engine_library = "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", + "./ohos/flutter_embedding", + "--build_type", + flutter_runtime_mode, + "--output", + rebase_path("flutter_embedding.har", root_build_dir, root_build_dir), + "--native_lib", + rebase_path("$engine_library", root_build_dir, root_build_dir), + "--ohos_abi", + ohos_app_abi, + ] + + deps = [ + ":flutter" + ] + + 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), + ] + } +} + -- Gitee From 2361c3a63beb16270b2b9fdf5fea5c8123a14467 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:00 +0800 Subject: [PATCH 17/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9ets=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../flutter/src/main/ets/app/FlutterPluginRegistry.ets | 4 ++-- .../main/ets/embedding/engine/dart/DartExecutor.ets | 2 +- .../main/ets/embedding/engine/dart/DartMessenger.ets | 4 ++-- .../src/main/ets/plugin/common/BasicMessageChannel.ets | 2 +- .../flutter/src/main/ets/plugin/common/BinaryCodec.ets | 4 ++-- .../src/main/ets/plugin/common/EventChannel.ets | 10 +++++----- .../src/main/ets/plugin/common/JSONMessageCodec.ets | 4 ++-- .../src/main/ets/plugin/common/MessageCodec.ets | 2 +- .../src/main/ets/plugin/common/MethodChannel.ets | 2 +- .../main/ets/plugin/common/StandardMessageCodec.ets | 2 +- .../flutter/src/main/ets/plugin/common/StringCodec.ets | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) 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 4eabe6ad35..758b5f6e1c 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,8 +18,8 @@ import PlatformViewController from '../plugin/platform/PlatformViewsController' export default class FlutterPluginRegistry { private mPlatformViewsController: PlatformViewController; - private mFlutterView: FlutterView | null; - private mContext: common.Context | null; + private mFlutterView: FlutterView | null = null; + private mContext: common.Context | null = null; constructor() { this.mPlatformViewsController = new PlatformViewController(); 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 46d08cd458..383927204c 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 6e9bfab834..3567d610f4 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/plugin/common/BasicMessageChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets index 796f8edb89..4b627aea9e 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 @@ -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) { 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 578436417d..1c15c76210 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/EventChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets index cc792fbb52..0c2ee0884c 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 | undefined; + 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,11 +236,11 @@ class EventSinkImplementation implements EventSink { return; } this.hasEnded = true; - this.messenger.send(this.name, null); + this.messenger.send(this.name, new ArrayBuffer(0)); } } -class AtomicReference { +class AtomicReference { private value: T | null; constructor(value: T | null) { @@ -255,7 +255,7 @@ class AtomicReference { this.value = newValue; } - getAndSet(newValue: T | null): T | null { + 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 e766db57fc..e37a3d27e5 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 663d57af19..6cb2c033b6 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 f42df11830..e9c3a7cc15 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 88de0fc5de..df27a12328 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 } 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 b824ac1f90..3ce96e365c 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 ""; } -- Gitee From b5f0fe4f6b1210326c122095b133c1e64687374e Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:00 +0800 Subject: [PATCH 18/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9engine=E4=BA=A7?= =?UTF-8?q?=E7=89=A9=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/bootstrap/ohos.py | 12 +- build/archives/BUILD.gn | 8 +- build/dart/rules.gni | 2 +- common/config.gni | 4 + shell/platform/ohos/BUILD.gn | 187 +++++++++++++++++++++++++++-- tools/gn | 14 ++- 6 files changed, 202 insertions(+), 25 deletions(-) diff --git a/attachment/repos/bootstrap/ohos.py b/attachment/repos/bootstrap/ohos.py index 21022e0454..f59d783c8f 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/build/archives/BUILD.gn b/build/archives/BUILD.gn index 90993ddb42..dd4fbdc665 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 c239d536c1..d92acff60e 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 21a43ba4f8..d74f2c9bc2 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/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index aa2f620ed7..f60b29c347 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -23,10 +23,15 @@ import("//flutter/testing/testing.gni") group("ohos") { deps = [ - ":flutter", + ":flutter_shell_native", #":publish_headers_ohos", - ":ohos_har" + #":ohos_har", + ":flutter_har_zip", + ":ohos_symbols", ] + if (target_cpu != "x86") { + deps += [ ":gen_snapshot" ] + } } shell_gpu_configuration("ohos_gpu_configuration") { enable_software = true @@ -195,7 +200,8 @@ executable("flutter_ohos_unittests") { ] } -shared_library("flutter") { +shared_library("flutter_shell_native") { + output_name = "flutter" deps = [ ":flutter_ohos_src" ] ldflags = ["--rtlib=compiler-rt", @@ -280,17 +286,17 @@ declare_args() { 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 = "so.unstripped/libflutter.so" - } else { engine_library = "libflutter.so" + } else { + engine_library = "so.unstripped/libflutter.so" } - #engine_library = "libflutter.so" inputs = [ # "$root_build_dir/$embedding_har_filename", @@ -306,19 +312,21 @@ action("ohos_har") { "--embedding_src", "../../flutter/shell/platform/ohos/flutter_embedding", "--build_dir", - "./ohos/flutter_embedding", + "./obj/ohos/flutter_embedding", "--build_type", flutter_runtime_mode, "--output", - rebase_path("flutter_embedding.har", root_build_dir, root_build_dir), + 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" + ":flutter_shell_native" ] if (flutter_runtime_mode == "profile") { @@ -333,3 +341,164 @@ action("ohos_har") { } } +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/tools/gn b/tools/gn index a5efe0f75d..98a207a1be 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=10 + ) 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 != '': -- Gitee From bc849c310715f58bf51f342d30e563a00b681fa3 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:40 +0800 Subject: [PATCH 19/26] =?UTF-8?q?=E6=9B=B4=E6=96=B0hvigor=E5=88=B04.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../ohos/flutter_embedding/hvigor/hvigor-config.json5 | 11 ++++++----- shell/platform/ohos/flutter_embedding/hvigorfile.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 b/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 index 3496547c0b..5c4892a18d 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 5a172b770e..8f2d2aafe6 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 -- Gitee From c684e30a8533f6b080a3bec26850e750286f6754 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:40 +0800 Subject: [PATCH 20/26] =?UTF-8?q?hvigor=E6=89=93=E5=8C=85=E5=8A=A0?= =?UTF-8?q?=E4=B8=8Aclean=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/build.patch | 4 ++-- shell/platform/ohos/flutter_embedding/.gitignore | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/attachment/repos/build.patch b/attachment/repos/build.patch index d1bf7b82e2..c9f4260f96 100644 --- a/attachment/repos/build.patch +++ b/attachment/repos/build.patch @@ -717,7 +717,7 @@ index 7987e51..cd7b060 100644 } 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..4e052ed +index 0000000..12fb407 --- /dev/null +++ b/build/ohos/ohos_create_flutter_har.py @@ -0,0 +1,141 @@ @@ -816,7 +816,7 @@ index 0000000..4e052ed + runCommand( + ("cd %s && " % dirEmbedding) + + (".%s" % os.sep) -+ + "hvigorw --mode module -p module=flutter@default -p product=default assembleHar --no-daemon" ++ + "hvigorw clean --mode module -p module=flutter@default -p product=default assembleHar --no-daemon" + ) + + diff --git a/shell/platform/ohos/flutter_embedding/.gitignore b/shell/platform/ohos/flutter_embedding/.gitignore index 4510e76666..969cec852a 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 -- Gitee From bedbee328aaed3664da8a5444f2e715a01c9c529 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:40 +0800 Subject: [PATCH 21/26] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8hvigo?= =?UTF-8?q?rw=E7=9A=84=E5=8F=82=E6=95=B0=E6=8C=87=E5=AE=9A=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/build.patch | 44 ++++++++----------- .../flutter_embedding/build-profile.json5 | 11 +++++ .../engine/loader/FlutterApplicationInfo.ets | 6 ++- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/attachment/repos/build.patch b/attachment/repos/build.patch index c9f4260f96..7dd52e5b16 100644 --- a/attachment/repos/build.patch +++ b/attachment/repos/build.patch @@ -717,10 +717,10 @@ index 7987e51..cd7b060 100644 } 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..12fb407 +index 0000000..fc46359 --- /dev/null +++ b/build/ohos/ohos_create_flutter_har.py -@@ -0,0 +1,141 @@ +@@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. @@ -759,6 +759,17 @@ index 0000000..12fb407 + "compatibleSdkVersion": "%s", + "runtimeOS": "HarmonyOS", + } ++ ], ++ "buildModeSet": [ ++ { ++ "name": "debug", ++ }, ++ { ++ "name": "release" ++ }, ++ { ++ "name": "profile" ++ }, + ] + }, + "modules": [ @@ -771,6 +782,7 @@ index 0000000..12fb407 +""" + + ++# 更新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") @@ -790,33 +802,13 @@ index 0000000..12fb407 + logging.info("runCommand finish, code = %s, command = %s" % (code, command)) + + -+# 替换文件中的字符串 -+def replaceStr(file, regex, newstr): -+ with open(file, "r", encoding="utf-8") as f1: -+ lines = f1.readlines() -+ with open(file, "w+", encoding="utf-8") as f2: -+ for line in lines: -+ a = re.sub(regex, newstr, line) -+ f2.writelines(a) -+ -+ -+# 编译har文件 ++# 编译har文件,通过hvigorw的命令行参数指定编译类型(debug/release/profile) +def buildHar(buildDir, apiInt, buildType): + updateConfig(buildDir, apiInt) -+ isDebug = "true" if buildType == "debug" else "false" -+ isProfile = "true" if buildType == "profile" else "false" -+ dirEmbedding = buildDir -+ targetFile = os.path.join( -+ buildDir, -+ "flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets", -+ ) -+ logging.info("isDebugMode=%s, isProfile=%s" % (isDebug, isProfile)) -+ replaceStr(targetFile, "isDebugMode = .*", "isDebugMode = %s;" % isDebug) -+ replaceStr(targetFile, "isProfile = .*", "isProfile = %s;" % isProfile) + runCommand( -+ ("cd %s && " % dirEmbedding) -+ + (".%s" % os.sep) -+ + "hvigorw clean --mode module -p module=flutter@default -p product=default assembleHar --no-daemon" ++ "cd %s && .%shvigorw clean --mode module " % (buildDir, os.sep) ++ + "-p module=flutter@default -p product=default -p buildMode=%s " % buildType ++ + "assembleHar --no-daemon" + ) + + diff --git a/shell/platform/ohos/flutter_embedding/build-profile.json5 b/shell/platform/ohos/flutter_embedding/build-profile.json5 index ae4533ee39..2d2ee02569 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/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets index 272615d612..8ff3aec5b8 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 -- Gitee From bbbf42ce63ff07263bb6d8d99247081ecd12302b Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Tue, 20 Feb 2024 16:45:55 +0800 Subject: [PATCH 22/26] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=89=93=E5=BC=80flutter=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=BF=94=E5=9B=9E=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangxiaoyao <976125628@qq.com> --- .../ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets | 8 +++++++- .../flutter/src/main/ets/embedding/ohos/FlutterEntry.ets | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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 056d8c0b5c..df276bd2e5 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 d90be8a48b..2d5a4a0ef8 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 @@ -124,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; } -- Gitee From 06c916d33621c783dfaf062c89884e38f8d22148 Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Wed, 21 Feb 2024 18:06:57 +0800 Subject: [PATCH 23/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../ets/plugin/common/BasicMessageChannel.ets | 8 +++--- .../ohos/flutter_embedding/local.properties | 27 +++++-------------- 2 files changed, 11 insertions(+), 24 deletions(-) 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 4b627aea9e..5a58b8c3ca 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. @@ -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/local.properties b/shell/platform/ohos/flutter_embedding/local.properties index 42b3cf913e..127b42ca13 100755 --- a/shell/platform/ohos/flutter_embedding/local.properties +++ b/shell/platform/ohos/flutter_embedding/local.properties @@ -1,23 +1,10 @@ -# 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. -# +# 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= - +hwsdk.dir=D:/env/sdk \ No newline at end of file -- Gitee From ece184fd8a6640304f067439e6285f0771451aff Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Thu, 22 Feb 2024 10:12:28 +0800 Subject: [PATCH 24/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../ohos/flutter_embedding/local.properties | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/local.properties b/shell/platform/ohos/flutter_embedding/local.properties index 127b42ca13..bc8cf2a57b 100755 --- a/shell/platform/ohos/flutter_embedding/local.properties +++ b/shell/platform/ohos/flutter_embedding/local.properties @@ -1,10 +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= -hwsdk.dir=D:/env/sdk \ No newline at end of file +# For customization when using a Version Control System, please read the header note. +sdk.dir= +nodejs.dir= -- Gitee From 4cf54877c0f7fd677a45f6fc6454679c7c976d4d Mon Sep 17 00:00:00 2001 From: SimpleLove520 <1960997571@qq.com> Date: Thu, 22 Feb 2024 10:13:13 +0800 Subject: [PATCH 25/26] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebview=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E4=BC=9A=E8=A6=86=E7=9B=96=E9=A1=B6=E9=83=A8=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E6=A0=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SimpleLove520 <1960997571@qq.com> --- .../main/ets/embedding/ohos/FlutterPage.ets | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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 53e7ef62d1..e29e877c56 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,13 +35,13 @@ 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() { @@ -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) => { -- Gitee From f9e335d544e7bee445831183534e88980b19f9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Fri, 23 Feb 2024 19:28:21 +0800 Subject: [PATCH 26/26] Fix compiler error. See https://gitee.com/openharmony-sig/flutter_engine/issues/I93DI6 for more details. --- tools/gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/gn b/tools/gn index 98a207a1be..8f6f1fef7d 100755 --- a/tools/gn +++ b/tools/gn @@ -765,7 +765,7 @@ def parse_args(args): '--ohos-cpu', type=str, choices=['x64', 'x86', 'arm64', 'arm'] ) parser.add_argument( - '--ohos-api-int', type=int, choices=[10, 11], default=10 + '--ohos-api-int', type=int, choices=[10, 11], default=11 ) parser.add_argument( '--fuchsia-cpu', type=str, choices=['x64', 'arm64'], default='x64' -- Gitee