From 999ebc84303d8b6e4536f54adb005af2918f84e8 Mon Sep 17 00:00:00 2001 From: hyiso Date: Tue, 27 Aug 2024 11:09:35 +0800 Subject: [PATCH 1/4] =?UTF-8?q?Fix=20setApplicationSwitcherDescription=20?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hyiso --- .../embedding/engine/systemchannels/PlatformChannel.ets | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets index 8afbc92223..caf39c4916 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets @@ -321,7 +321,8 @@ class PlatformMethodCallback implements MethodCallHandler { case "SystemChrome.setApplicationSwitcherDescription": Log.d(PlatformMethodCallback.TAG, "setApplicationSwitcherDescription: " + JSON.stringify(args)); try { - this.platform.platformMessageHandler.setApplicationSwitcherDescription(args); + let description: AppSwitcherDescription = this.decodeAppSwitcherDescription(args); + this.platform.platformMessageHandler.setApplicationSwitcherDescription(description); result.success(null); } catch (err) { Log.e(PlatformMethodCallback.TAG, "setApplicationSwitcherDescription err:" + JSON.stringify(err)); @@ -398,6 +399,12 @@ class PlatformMethodCallback implements MethodCallHandler { } } + private decodeAppSwitcherDescription(encodedDescription: Map): AppSwitcherDescription { + let color: number = encodedDescription.get('color') as number; + let label: string = encodedDescription.get('label') as string; + return new AppSwitcherDescription(color, label); + } + private decodeSystemUiOverlays(encodedSystemUiOverlay: string[]): SystemUiOverlay[] { let overlays: SystemUiOverlay[] = []; for(let i = 0; i < encodedSystemUiOverlay.length; i++) { -- Gitee From f085f791d7c629811a24b5b0704d7c6c8886c0b3 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Mon, 9 Sep 2024 16:08:51 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0flutter.har=E4=B8=AD?= =?UTF-8?q?=E7=9A=84oh-package.json5=E7=9A=84name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../platform/ohos/flutter_embedding/flutter/oh-package.json5 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/oh-package.json5 b/shell/platform/ohos/flutter_embedding/flutter/oh-package.json5 index 8c53bcea95..39bbaa64c0 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/oh-package.json5 +++ b/shell/platform/ohos/flutter_embedding/flutter/oh-package.json5 @@ -16,8 +16,8 @@ { "license": "Apache-2.0", "author": "", - "name": "flutter", - "description": "Please describe the basic information.", + "name": "@ohos/flutter_ohos", + "description": "The embedder of flutter in ohos.", "main": "index.ets", "version": "1.0.0", "dependencies": {}, -- Gitee From 1b16f6fb9cac7df15869427d0d1e6c4d3fc3f222 Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Mon, 9 Sep 2024 17:52:04 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9flutterEntry=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E9=94=AE=E7=9B=98=E4=B8=8D=E6=94=B6=E8=B5=B7=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: huangxiaoyao <976125628@qq.com> --- .../flutter/src/main/ets/embedding/ohos/FlutterEntry.ets | 1 + 1 file changed, 1 insertion(+) 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 7f5ccfc251..8055aefa4f 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 @@ -127,6 +127,7 @@ export default class FlutterEntry implements Host { onBackPress() { Log.d(TAG, "FlutterEntry onBackPress==="); this?.delegate?.flutterEngine?.getNavigationChannel()?.popRoute(); + this?.delegate?.flutterEngine?.getTextInputChannel()?.textInputMethodHandler?.hide(); } shouldDispatchAppLifecycleState(): boolean { -- Gitee From b14601bc0f46c96e43653750a8eb39b616f86eca Mon Sep 17 00:00:00 2001 From: zhuzhengjun Date: Tue, 10 Sep 2024 17:51:22 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0LookupCallbackInformation?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuzhengjun --- .../src/main/cpp/types/libflutter/index.d.ets | 3 ++ .../main/ets/embedding/engine/FlutterNapi.ets | 9 +++- .../ets/view/FlutterCallbackInformation.ets | 14 +++-- shell/platform/ohos/library_loader.cpp | 4 +- .../ohos/napi/platform_view_ohos_napi.cpp | 53 +++++++++++++++++++ .../ohos/napi/platform_view_ohos_napi.h | 3 ++ 6 files changed, 79 insertions(+), 7 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets index 45a76fdda8..53a5eabeca 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets @@ -17,6 +17,7 @@ import common from '@ohos.app.ability.common'; import resourceManager from '@ohos.resourceManager'; import image from '@ohos.multimedia.image'; import FlutterNapi from '../../../ets/embedding/engine/FlutterNapi'; +import { FlutterCallbackInformation } from '../../../ets/view/FlutterCallbackInformation'; export const getContext: (a: number) => napiContext; @@ -132,3 +133,5 @@ export const nativeEncodeUtf8: (str: string) => Uint8Array; export const nativeDecodeUtf8: (array: Uint8Array) => string; export const nativeSetTextureBufferSize: (nativeShellHolderId: number, textureId: number, width: number, height: number) => void; + +export const nativeLookupCallbackInformation: (callback: FlutterCallbackInformation, handler: number) => number; \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets index 75f4a58b45..78f1a520e7 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets @@ -101,8 +101,8 @@ export default class FlutterNapi { runBundleAndSnapshotFromLibrary( bundlePath: string, - entrypointFunctionName: string, - pathToEntrypointFunction: string, + entrypointFunctionName: string | undefined, + pathToEntrypointFunction: string | undefined, assetManager: resourceManager.ResourceManager, entrypointArgs: Array) { if (!FlutterNapi.hasInit) { @@ -138,6 +138,11 @@ export default class FlutterNapi { } static nativeLookupCallbackInformation(handle: number): FlutterCallbackInformation | null { + let callbackInformation = new FlutterCallbackInformation(); + let ret : number = flutter.nativeLookupCallbackInformation(callbackInformation, handle); + if (ret == 0) { + return callbackInformation; + } return null; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterCallbackInformation.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterCallbackInformation.ets index 26202727fa..7f9111e95f 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterCallbackInformation.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterCallbackInformation.ets @@ -16,9 +16,9 @@ import FlutterNapi from '../embedding/engine/FlutterNapi'; export class FlutterCallbackInformation { - callbackName: string; - callbackClassName: string; - callbackLibraryPath: string; + callbackName?: string; + callbackClassName?: string; + callbackLibraryPath?: string; /** * Get callback information for a given handle. @@ -31,7 +31,13 @@ export class FlutterCallbackInformation { return FlutterNapi.nativeLookupCallbackInformation(handle); } - constructor(callbackName: string, callbackClassName: string, callbackLibraryPath: string) { + constructor(callbackName?: string, callbackClassName?: string, callbackLibraryPath?: string) { + this.callbackName = callbackName; + this.callbackClassName = callbackClassName; + this.callbackLibraryPath = callbackLibraryPath; + } + + init(callbackName: string, callbackClassName: string, callbackLibraryPath: string) { this.callbackName = callbackName; this.callbackClassName = callbackClassName; this.callbackLibraryPath = callbackLibraryPath; diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index 390b300b20..473feb562e 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -138,7 +138,9 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_FUNCTION( "nativeDecodeUtf8", flutter::PlatformViewOHOSNapi::nativeDecodeUtf8), - + DECLARE_NAPI_FUNCTION( + "nativeLookupCallbackInformation", + flutter::PlatformViewOHOSNapi::nativeLookupCallbackInformation), }; FML_DLOG(INFO) << "Init NAPI size=" << sizeof(desc) / sizeof(desc[0]); diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 9ac9dfafd2..d46617ef3a 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -29,6 +29,7 @@ #include "flutter/shell/platform/ohos/ohos_shell_holder.h" #include "flutter/shell/platform/ohos/surface/ohos_native_window.h" #include "flutter/shell/platform/ohos/types.h" +#include "flutter/lib/ui/plugins/callback_cache.h" #include "unicode/uchar.h" #include "flutter/shell/platform/ohos/ohos_xcomponent_adapter.h" #include "flutter/shell/platform/ohos/ohos_logging.h" @@ -1797,4 +1798,56 @@ napi_value PlatformViewOHOSNapi::nativeDecodeUtf8(napi_env env, napi_callback_in return result; } +napi_value PlatformViewOHOSNapi::nativeLookupCallbackInformation(napi_env env, napi_callback_info info) +{ + napi_value result; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_status ret = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + if (ret != napi_ok) { + LOGE("nativeLookupCallbackInformation napi_get_cb_info error"); + napi_create_int32(env, -1, &result); + return result; + } + + int64_t handle; + bool lossless; + ret = napi_get_value_bigint_int64(env, args[1], &handle, &lossless); + if (ret != napi_ok) { + LOGE("nativeLookupCallbackInformation napi_get_value_int64 error"); + napi_create_int32(env, -1, &result); + return result; + } + + LOGD("nativeLookupCallbackInformation::handle : %{public}ld", handle); + auto cbInfo = flutter::DartCallbackCache::GetCallbackInformation(handle); + if (cbInfo == nullptr) { + LOGE("nativeLookupCallbackInformation DartCallbackCache GetCallbackInformation nullptr"); + napi_create_int32(env, -1, &result); + return result; + } + + napi_ref callbck_napi_obj; + ret = napi_create_reference(env, args[0], 1, &callbck_napi_obj); + if (ret != napi_ok) { + LOGE("nativeLookupCallbackInformation napi_create_reference error"); + napi_create_int32(env, -1, &result); + return result; + } + + napi_value callbackParam[3]; + napi_create_string_utf8(env, cbInfo->name.c_str(), NAPI_AUTO_LENGTH, &callbackParam[0]); + napi_create_string_utf8(env, cbInfo->class_name.c_str(), NAPI_AUTO_LENGTH, &callbackParam[1]); + napi_create_string_utf8(env, cbInfo->library_path.c_str(), NAPI_AUTO_LENGTH, &callbackParam[2]); + + ret = fml::napi::InvokeJsMethod(env, callbck_napi_obj, "init", 3, callbackParam); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "nativeLookupCallbackInformation init fail "; + napi_create_int32(env, -1, &result); + return result; + } + napi_delete_reference(env, callbck_napi_obj); + napi_create_int32(env, 0, &result); + return result; +} } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 2c9cc19fb5..9ca6b6f90b 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -208,6 +208,9 @@ class PlatformViewOHOSNapi { static napi_value nativeDecodeUtf8( napi_env env, napi_callback_info info); + static napi_value nativeLookupCallbackInformation( + napi_env env, + napi_callback_info info); private: static napi_env env_; -- Gitee