diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md index 4d478ebc0011ca9e29f537318377b48366c0a649..25dbe4da7bf83ad06c7b841d2b4e2a0d82389751 100644 --- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md +++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -60,7 +60,7 @@ - 是否同步合入interface仓的相关d.ts(需求合入用同一个issue) - [ ] 已同步 - [ ] 不涉及 -### L0新增用例自检结果 -- [ ] 是,有新增L0用例,且完成自检 -- [ ] 否 +### 是否已执行L0用例 +- [ ] 已验证 +- [ ] 不涉及。如不涉及,请写明理由 ## 六:将上述测试的截图贴到下面 diff --git a/base_sdk/BUILD.gn b/base_sdk/BUILD.gn index df8ace62c86c25713f52d53c81f895bf3b29f113..4beb42070368b0a3389aeb1a00e53bf5015467c0 100644 --- a/base_sdk/BUILD.gn +++ b/base_sdk/BUILD.gn @@ -30,3 +30,33 @@ ohos_prebuilt_etc("base_sdk_ets") { subsystem_name = "commonlibrary" part_name = "ets_utils" } + +generate_static_abc("base_transfer") { + base_url = "./transfer" + files = [ + "./transfer/@ohos.transfer.ets", + "./transfer/register.ets", + "./transfer/kitRegister/abilitykit.ets", + "./transfer/kitRegister/arkui.ets", + "./transfer/kitRegister/arkts.ets", + "./transfer/kitRegister/arkweb.ets", + "./transfer/kitRegister/registerMain.ets", + "./transfer/kitRegister/resourceManager.ets", + "./transfer/kitRegister/basicServicesKit.ets", + "./transfer/kitRegister/osAccount.ets", + "./transfer/kitRegister/rpc.ets", + "./transfer/kitRegister/window.ets", + "./transfer/kitRegister/scene3d.ets", + "./transfer/kitRegister/imageKit.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/base_transfer.abc" +} + +ohos_prebuilt_etc("base_transfer_ets") { + source = "$target_out_dir/base_transfer.abc" + module_install_dir = "framework" + subsystem_name = "commonlibrary" + part_name = "ets_utils" + deps = [ ":base_transfer" ] +} diff --git a/base_sdk/ets/@ohos.base.ets b/base_sdk/ets/@ohos.base.ets index cd88297a2bb5eb641f65f50050883e26dab32dd2..b2576542b01fa093254c89b63eb0cccc41c4956e 100644 --- a/base_sdk/ets/@ohos.base.ets +++ b/base_sdk/ets/@ohos.base.ets @@ -14,7 +14,7 @@ */ export class BusinessError extends Error { - code: number; + code: int; data?: T; constructor() { @@ -22,12 +22,12 @@ export class BusinessError extends Error { this.code = 0; } - constructor(code: number, error: Error) { + constructor(code: int, error: Error) { super(error.name, error.message, new ErrorOptions(error.cause)); this.code = code; } - constructor(code: number, data: T, error: Error) { + constructor(code: int, data: T, error: Error) { super(error.name, error.message, new ErrorOptions(error.cause)); this.code = code; this.data = data; diff --git a/base_sdk/transfer/@ohos.transfer.ets b/base_sdk/transfer/@ohos.transfer.ets new file mode 100644 index 0000000000000000000000000000000000000000..2bd36cfbbce60a3933bcabbaeaab7a00d661c87a --- /dev/null +++ b/base_sdk/transfer/@ohos.transfer.ets @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { staticRegisterMap, dynamicRegisterMap, CallbackUrl } from './register.ets'; +import { BusinessError } from '@ohos.base'; +import { registerMain } from './kitRegister/registerMain.ets'; + +registerMain(); + +const transferErrorCodeId = 10200067; + +const staticCBCache = new Map(); +const dynamicCBCache = new Map(); +const staticRegisterMapRef = staticRegisterMap; +const dynamicRegisterMapRef = dynamicRegisterMap; + +export namespace transfer { + + export function transferStatic(input: Any, inputName: string): Object { + + if (!staticRegisterMapRef.has(inputName)) { + throw new BusinessError(transferErrorCodeId, + new Error(`Transfer Error. The input name is not supported!`)); + } + let cb: CallbackUrl = staticRegisterMapRef.get(inputName)!; + if (cb.filePath === '') { + return cb.staticMethod!(input); + } + + let method: Method | undefined; + if (staticCBCache.has(inputName)) { + method = staticCBCache.get(inputName); + } else { + method = getMethod(cb.filePath, cb.className, cb.methodName); + staticCBCache.set(inputName, method); + } + return method!.invoke(null, [input]) as Object; + } + + export function transferDynamic(input: Object, inputName: string): Any { + if (!dynamicRegisterMapRef.has(inputName)) { + throw new BusinessError(transferErrorCodeId, + new Error(`Transfer Error. The input name is not supported!`)); + } + let cb: CallbackUrl = dynamicRegisterMapRef.get(inputName)!; + if (cb.filePath === '') { + return cb.dynamicMethod!(input) ; + } + + let method: Method | undefined; + if (dynamicCBCache.has(inputName)) { + method = dynamicCBCache.get(inputName); + } else { + method = getMethod(cb.filePath, cb.className, cb.methodName); + dynamicCBCache.set(inputName, method); + } + return method!.invoke(null, [input]) as Any; + } + + function getMethod(filePath: string, className: string, methodName: string): Method { + className = filePath + '.' + className; + let linker = Class.ofCaller()!.getLinker(); + let classType: ClassType | undefined = linker.getType(className) as ClassType; + if (!classType) { + throw new BusinessError(transferErrorCodeId, + new Error(`Transfer Error. The class ${className} is not found!`)); + } + for (let i = 0; i < classType!.getMethodsNum(); i++) { + if (methodName === classType!.getMethod(i).getName()) { + return classType!.getMethod(i); + } + } + throw new BusinessError(transferErrorCodeId, + new Error(`Transfer Error. The method ${methodName} is not found!`)); + } +} diff --git a/base_sdk/transfer/kitRegister/abilitykit.ets b/base_sdk/transfer/kitRegister/abilitykit.ets new file mode 100644 index 0000000000000000000000000000000000000000..d51e6bb087f3aabab9aed96a092f4d324d27aea3 --- /dev/null +++ b/base_sdk/transfer/kitRegister/abilitykit.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerAbilityKit() { + registerStaticCB('AbilityKit.UIAbilityContext', 'application.UIAbilityContext', 'UIAbilityContext', 'transferStatic'); + registerDynamicCB('AbilityKit.UIAbilityContext', 'application.UIAbilityContext', 'UIAbilityContext', 'transferDynamic'); + + registerStaticCB('AbilityKit.Context', 'application.Context', 'Context', 'transferStatic'); + registerDynamicCB('AbilityKit.Context', 'application.Context', 'Context', 'transferDynamic'); + + registerStaticCB('AbilityKit.ApplicationContext', 'application.ApplicationContext', 'ApplicationContext', 'transferStatic'); + registerDynamicCB('AbilityKit.ApplicationContext', 'application.ApplicationContext', 'ApplicationContext', 'transferDynamic'); + + registerStaticCB('AbilityKit.AbilityStageContext', 'application.AbilityStageContext', 'AbilityStageContext', 'transferStatic'); + registerDynamicCB('AbilityKit.AbilityStageContext', 'application.AbilityStageContext', 'AbilityStageContext', 'transferDynamic'); + + registerStaticCB('AbilityKit.Caller', 'application.Caller', 'CallerImpl', 'transferStatic'); + registerDynamicCB('AbilityKit.Caller', 'application.Caller', 'CallerImpl', 'transferDynamic'); + + registerStaticCB('AbilityKit.Callee', 'application.Callee', 'CalleeImpl', 'transferStatic'); + registerDynamicCB('AbilityKit.Callee', 'application.Callee', 'CalleeImpl', 'transferDynamic'); +} diff --git a/base_sdk/transfer/kitRegister/arkts.ets b/base_sdk/transfer/kitRegister/arkts.ets new file mode 100644 index 0000000000000000000000000000000000000000..9e492bf612e664b1c18c001d7603fe6cd2b950f8 --- /dev/null +++ b/base_sdk/transfer/kitRegister/arkts.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerArkTS() { + registerStaticCB('InteropTransferHelper', InteropTransferHelper.transferArrayBufferToStatic); + registerDynamicCB('InteropTransferHelper', InteropTransferHelper.transferArrayBufferToDynamic); +} diff --git a/base_sdk/transfer/kitRegister/arkui.ets b/base_sdk/transfer/kitRegister/arkui.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a557d921cb578eec61b8e84063b4ca9bc923af6 --- /dev/null +++ b/base_sdk/transfer/kitRegister/arkui.ets @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerArkUI() { + registerStaticCB('ArkUI.NavDestinationInfo', '@ohos.arkui.observer', 'uiObserver.NavDestinationInfoImpl', 'transferStatic'); + registerDynamicCB('ArkUI.NavDestinationInfo', '@ohos.arkui.observer', 'uiObserver.NavDestinationInfoImpl', 'transferDynamic'); + + registerStaticCB('ArkUI.NavigationInfo', '@ohos.arkui.observer', 'uiObserver.NavigationInfoImpl', 'transferStatic'); + registerDynamicCB('ArkUI.NavigationInfo', '@ohos.arkui.observer', 'uiObserver.NavigationInfoImpl', 'transferDynamic'); + + registerStaticCB('ArkUI.RouterPageInfo', '@ohos.arkui.observer', 'uiObserver.RouterPageInfo', 'transferStatic'); + registerDynamicCB('ArkUI.RouterPageInfo', '@ohos.arkui.observer', 'uiObserver.RouterPageInfo', 'transferDynamic'); + + registerStaticCB('ArkUI.Matrix4', '@ohos.matrix4', 'matrix4.Matrix4TransitInner', 'matrixTransferStatic'); + registerDynamicCB('ArkUI.Matrix4', '@ohos.matrix4', 'matrix4.Matrix4TransitInner', 'matrixTransferDynamic'); + + registerStaticCB('ArkUI.Animator', '@ohos.animator', 'AnimatorResultInner', 'animatorTransferStatic'); + registerDynamicCB('ArkUI.Animator', '@ohos.animator', 'AnimatorResultInner', 'animatorTransferDynamic'); + + registerStaticCB('ArkUI.FrameNode', 'arkui.handwritten.transfer.FrameNodeTransfer', 'FrameNodeTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.FrameNode', 'arkui.handwritten.transfer.FrameNodeTransfer', 'FrameNodeTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.UIContext', 'arkui.handwritten.transfer.UIContextTransfer', 'UIContextTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.UIContext', 'arkui.handwritten.transfer.UIContextTransfer', 'UIContextTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.LengthMetrics', 'arkui.handwritten.transfer.LengthMetricsTransfer', 'LengthMetricsTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.LengthMetrics', 'arkui.handwritten.transfer.LengthMetricsTransfer', 'LengthMetricsTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.ShapeClip', 'arkui.handwritten.transfer.ShapeClipTransfer', 'ShapeClipTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.ShapeClip', 'arkui.handwritten.transfer.ShapeClipTransfer', 'ShapeClipTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.ColorMetrics', 'arkui.handwritten.transfer.ColorMetricsTransfer', 'ColorMetricsTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.ColorMetrics', 'arkui.handwritten.transfer.ColorMetricsTransfer', 'ColorMetricsTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.ShapeMask', 'arkui.handwritten.transfer.ShapeMaskTransfer', 'ShapeMaskTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.ShapeMask', 'arkui.handwritten.transfer.ShapeMaskTransfer', 'ShapeMaskTransfer', 'transferDynamic'); + + registerStaticCB('Global.Resource', 'arkui.handwritten.transfer.ResourceTransfer', 'ResourceTransfer', 'transferStatic'); + registerDynamicCB('Global.Resource', 'arkui.handwritten.transfer.ResourceTransfer', 'ResourceTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.RenderNode', 'arkui.handwritten.transfer.RenderNodeTransfer', 'RenderNodeTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.RenderNode', 'arkui.handwritten.transfer.RenderNodeTransfer', 'RenderNodeTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.TouchEvent', 'arkui.component.common', 'TouchEventTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.TouchEvent', 'arkui.component.common', 'TouchEventTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.MouseEvent', 'arkui.component.common', 'MouseEventTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.MouseEvent', 'arkui.component.common', 'MouseEventTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.AxisEvent', 'arkui.component.common', 'AxisEventTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.AxisEvent', 'arkui.component.common', 'AxisEventTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.ClickEvent', 'arkui.component.common', 'ClickEventTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.ClickEvent', 'arkui.component.common', 'ClickEventTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.HoverEvent', 'arkui.component.common', 'HoverEventTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.HoverEvent', 'arkui.component.common', 'HoverEventTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.DragEvent', 'arkui.component.common', 'DragEventTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.DragEvent', 'arkui.component.common', 'DragEventTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.KeyEvent', 'arkui.component.common', 'KeyEventTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.KeyEvent', 'arkui.component.common', 'KeyEventTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.TouchTestInfo', 'arkui.component.common', 'TouchTestInfoTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.TouchTestInfo', 'arkui.component.common', 'TouchTestInfoTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.EventTargetInfo', 'arkui.component.gesture', 'EventTargetInfoTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.EventTargetInfo', 'arkui.component.gesture', 'EventTargetInfoTransfer', 'transferDynamic'); + + registerStaticCB('ArkUI.ScrollableTargetInfo', 'arkui.component.gesture', 'ScrollableTargetInfoTransfer', 'transferStatic'); + registerDynamicCB('ArkUI.ScrollableTargetInfo', 'arkui.component.gesture', 'ScrollableTargetInfoTransfer', 'transferDynamic'); +} \ No newline at end of file diff --git a/base_sdk/transfer/kitRegister/arkweb.ets b/base_sdk/transfer/kitRegister/arkweb.ets new file mode 100644 index 0000000000000000000000000000000000000000..2339b2804552d710ceb2ef4a5adec669e0ff22d3 --- /dev/null +++ b/base_sdk/transfer/kitRegister/arkweb.ets @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerArkWeb() { + registerStaticCB('ArkWeb.ScreenCaptureHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferScreenCaptureHandlerStatic'); + registerDynamicCB('ArkWeb.ScreenCaptureHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferScreenCaptureHandlerDynamic'); + + registerStaticCB('ArkWeb.FileSelectorParam', 'arkui.component.web', 'ArkWebTransfer', 'transferFileSelectorParamStatic'); + registerDynamicCB('ArkWeb.FileSelectorParam', 'arkui.component.web', 'ArkWebTransfer', 'transferFileSelectorParamDynamic'); + + registerStaticCB('ArkWeb.JsGeolocation', 'arkui.component.web', 'ArkWebTransfer', 'transferJsGeolocationStatic'); + registerDynamicCB('ArkWeb.JsGeolocation', 'arkui.component.web', 'ArkWebTransfer', 'transferJsGeolocationDynamic'); + + registerStaticCB('ArkWeb.JsResult', 'arkui.component.web', 'ArkWebTransfer', 'transferJsResultStatic'); + registerDynamicCB('ArkWeb.JsResult', 'arkui.component.web', 'ArkWebTransfer', 'transferJsResultDynamic'); + + registerStaticCB('ArkWeb.EventResult', 'arkui.component.web', 'ArkWebTransfer', 'transferEventResultStatic'); + registerDynamicCB('ArkWeb.EventResult', 'arkui.component.web', 'ArkWebTransfer', 'transferEventResultDynamic'); + + registerStaticCB('ArkWeb.FileSelectorResult', 'arkui.component.web', 'ArkWebTransfer', 'transferFileSelectorResultStatic'); + registerDynamicCB('ArkWeb.FileSelectorResult', 'arkui.component.web', 'ArkWebTransfer', 'transferFileSelectorResultDynamic'); + + registerStaticCB('ArkWeb.WebContextMenuParam', 'arkui.component.web', 'ArkWebTransfer', 'transferWebContextMenuParamStatic'); + registerDynamicCB('ArkWeb.WebContextMenuParam', 'arkui.component.web', 'ArkWebTransfer', 'transferWebContextMenuParamDynamic'); + + registerStaticCB('ArkWeb.WebContextMenuResult', 'arkui.component.web', 'ArkWebTransfer', 'transferWebContextMenuResultStatic'); + registerDynamicCB('ArkWeb.WebContextMenuResult', 'arkui.component.web', 'ArkWebTransfer', 'transferWebContextMenuResultDynamic'); + + registerStaticCB('ArkWeb.HttpAuthHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferHttpAuthHandlerToStatic'); + registerDynamicCB('ArkWeb.HttpAuthHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferHttpAuthHandlerToDynamic'); + + registerStaticCB('ArkWeb.WebResourceResponse', 'arkui.component.web', 'ArkWebTransfer', 'transferWebResourceReponseToStatic'); + registerDynamicCB('ArkWeb.WebResourceResponse', 'arkui.component.web', 'ArkWebTransfer', 'transferWebResourceReponseToDynamic'); + + registerStaticCB('ArkWeb.WebResourceRequest', 'arkui.component.web', 'ArkWebTransfer', 'transferWebResourceRequestToStatic'); + registerDynamicCB('ArkWeb.WebResourceRequest', 'arkui.component.web', 'ArkWebTransfer', 'transferWebResourceRequestToDynamic'); + + registerStaticCB('ArkWeb.ConsoleMessage', 'arkui.component.web', 'ArkWebTransfer', 'transferConsoleMessageToStatic'); + registerDynamicCB('ArkWeb.ConsoleMessage', 'arkui.component.web', 'ArkWebTransfer', 'transferConsoleMessageToDynamic'); + + registerStaticCB('ArkWeb.DataResubmissionHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferDataResubmissionHandlerToStatic'); + registerDynamicCB('ArkWeb.DataResubmissionHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferDataResubmissionHandlerToDynamic'); + + registerStaticCB('ArkWeb.ClientAuthenticationHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferClientAuthenticationHandlerToStatic'); + registerDynamicCB('ArkWeb.ClientAuthenticationHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferClientAuthenticationHandlerToDynamic'); + + registerStaticCB('ArkWeb.SslErrorHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferSslErrorHandlerToStatic'); + registerDynamicCB('ArkWeb.SslErrorHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferSslErrorHandlerToDynamic'); + + registerStaticCB('ArkWeb.PermissionRequest', 'arkui.component.web', 'ArkWebTransfer', 'transferPermissionRequestStatic'); + registerDynamicCB('ArkWeb.PermissionRequest', 'arkui.component.web', 'ArkWebTransfer', 'transferPermissionRequestDynamic'); + + registerStaticCB('ArkWeb.WebKeyboardController', 'arkui.component.web', 'ArkWebTransfer', 'transferWebKeyboardControllerStatic'); + registerDynamicCB('ArkWeb.WebKeyboardController', 'arkui.component.web', 'ArkWebTransfer', 'transferWebKeyboardControllerDynamic'); + + registerStaticCB('ArkWeb.ControllerHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferControllerHandlerStatic'); + registerDynamicCB('ArkWeb.ControllerHandler', 'arkui.component.web', 'ArkWebTransfer', 'transferControllerHandlerDynamic'); + + registerStaticCB('ArkWeb.BackForwardList', '@ohos.web.webview', 'webview.BackForwardListinner', 'transferBackForwardListToStatic'); + registerDynamicCB('ArkWeb.BackForwardList', '@ohos.web.webview', 'webview.BackForwardListinner', 'transferBackForwardListToDynamic'); + + registerStaticCB('ArkWeb.WebMessagePort', '@ohos.web.webview', 'webview.WebMessagePortInner', 'transferWebMessagePortToStatic'); + registerDynamicCB('ArkWeb.WebMessagePort', '@ohos.web.webview', 'webview.WebMessagePortInner', 'transferWebMessagePortToDynamic'); + + registerStaticCB('ArkWeb.NativeMediaPlayerHandler', '@ohos.web.webview', 'webview.NativeMediaPlayerHandlerinner', 'transferNativeMediaPlayerHandlerToStatic'); + registerDynamicCB('ArkWeb.NativeMediaPlayerHandler', '@ohos.web.webview', 'webview.NativeMediaPlayerHandlerinner', 'transferNativeMediaPlayerHandlerToDynamic'); +} diff --git a/base_sdk/transfer/kitRegister/basicServicesKit.ets b/base_sdk/transfer/kitRegister/basicServicesKit.ets new file mode 100644 index 0000000000000000000000000000000000000000..d589f846d04851bbc8efaf4444cfbeee5009f177 --- /dev/null +++ b/base_sdk/transfer/kitRegister/basicServicesKit.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerCommonEventManager() { + registerStaticCB('CommonEventManager.CommonEventSubscriber', 'commonEvent/commonEventSubscriber', 'CommonEventSubscriberInner', 'transferStatic'); + registerDynamicCB('CommonEventManager.CommonEventSubscriber', 'commonEvent/commonEventSubscriber', 'CommonEventSubscriberInner', 'transferDynamic'); + + registerStaticCB('StaticSubscriberExtensionContext', '@ohos.application.StaticSubscriberExtensionContext', 'StaticSubscriberExtensionContext', 'transferStatic'); + registerDynamicCB('StaticSubscriberExtensionContext', '@ohos.application.StaticSubscriberExtensionContext', 'StaticSubscriberExtensionContext', 'transferDynamic'); +} diff --git a/base_sdk/transfer/kitRegister/imageKit.ets b/base_sdk/transfer/kitRegister/imageKit.ets new file mode 100644 index 0000000000000000000000000000000000000000..9789dcdbf3b9869c480ca62c83b2f62955c02ce5 --- /dev/null +++ b/base_sdk/transfer/kitRegister/imageKit.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerImageKit() { + registerStaticCB('ImageKit.ImageSource', '@ohos.multimedia.image', 'image', 'imageSourceTransferStatic'); + registerDynamicCB('ImageKit.ImageSource', '@ohos.multimedia.image', 'image', 'imageSourceTransferDynamic'); + + registerStaticCB('ImageKit.ImagePacker', '@ohos.multimedia.image', 'image', 'imagePackerTransferStatic'); + registerDynamicCB('ImageKit.ImagePacker', '@ohos.multimedia.image', 'image', 'imagePackerTransferDynamic'); + + registerStaticCB('ImageKit.Picture', '@ohos.multimedia.image', 'image', 'pictureTransferStatic'); + registerDynamicCB('ImageKit.Picture', '@ohos.multimedia.image', 'image', 'pictureTransferDynamic'); + + registerStaticCB('ImageKit.AuxiliaryPicture', '@ohos.multimedia.image', 'image', 'auxiliaryPictureTransferStatic'); + registerDynamicCB('ImageKit.AuxiliaryPicture', '@ohos.multimedia.image', 'image', 'auxiliaryPictureTransferDynamic'); + + registerStaticCB('ImageKit.ImageReceiver', '@ohos.multimedia.image', 'image', 'imageReceiverTransferStatic'); + registerDynamicCB('ImageKit.ImageReceiver', '@ohos.multimedia.image', 'image', 'imageReceiverTransferDynamic'); + + registerStaticCB('ImageKit.ImageCreator', '@ohos.multimedia.image', 'image', 'imageCreatorTransferStatic'); + registerDynamicCB('ImageKit.ImageCreator', '@ohos.multimedia.image', 'image', 'imageCreatorTransferDynamic'); +} diff --git a/base_sdk/transfer/kitRegister/osAccount.ets b/base_sdk/transfer/kitRegister/osAccount.ets new file mode 100644 index 0000000000000000000000000000000000000000..425aa0e35de737178a32d45dd3428db0c21dcb48 --- /dev/null +++ b/base_sdk/transfer/kitRegister/osAccount.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerOsAccount() { + registerStaticCB('BasicServicesKit.IInputData', '@ohos.account.transfer.osAccount', 'Transfer', 'iInputDataTransferStatic'); + registerDynamicCB('BasicServicesKit.IInputData', '@ohos.account.transfer.osAccount', 'Transfer', 'iInputDataTransferDynamic'); +} diff --git a/base_sdk/transfer/kitRegister/registerMain.ets b/base_sdk/transfer/kitRegister/registerMain.ets new file mode 100644 index 0000000000000000000000000000000000000000..66a39d9f98257c11a54afc6592c05a810214e41d --- /dev/null +++ b/base_sdk/transfer/kitRegister/registerMain.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerArkTS } from './arkts.ets'; +import { registerArkUI } from './arkui.ets'; +import { registerWindow } from './window.ets'; +import { registerAbilityKit } from './abilitykit.ets'; +import { registerOsAccount } from './osAccount.ets'; +import { registerArkWeb } from './arkweb.ets'; +import { registerCommonEventManager } from './basicServicesKit.ets' +import { registerResourceManager } from './resourceManager.ets'; +import { registerRpc } from './rpc.ets'; +import { registerScene3D } from './scene3d.ets'; +import { registerImageKit } from './imageKit.ets'; + +export function registerMain(){ + registerArkTS(); + registerArkUI(); + registerWindow(); + registerAbilityKit(); + registerOsAccount(); + registerArkWeb(); + registerCommonEventManager(); + registerResourceManager(); + registerRpc(); + registerScene3D(); + registerImageKit(); +} \ No newline at end of file diff --git a/base_sdk/transfer/kitRegister/resourceManager.ets b/base_sdk/transfer/kitRegister/resourceManager.ets new file mode 100644 index 0000000000000000000000000000000000000000..fd4b947e709c91030e0976902800df584151048f --- /dev/null +++ b/base_sdk/transfer/kitRegister/resourceManager.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerResourceManager() { + registerStaticCB('LocalizationKit.ResourceManager', '@ohos.resourceManager', 'resourceManager', 'transferToStaticResource'); + registerDynamicCB('LocalizationKit.ResourceManager', '@ohos.resourceManager', 'resourceManager', 'transferToDynamicResource'); +} diff --git a/base_sdk/transfer/kitRegister/rpc.ets b/base_sdk/transfer/kitRegister/rpc.ets new file mode 100644 index 0000000000000000000000000000000000000000..e9e731a9f8d310ca05426a3aa5a91b008239dfb7 --- /dev/null +++ b/base_sdk/transfer/kitRegister/rpc.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerRpc() { + registerStaticCB('rpc.MessageSequence', '@ohos.rpc', 'rpc.MessageSequence', 'transferStatic'); + registerDynamicCB('rpc.MessageSequence', '@ohos.rpc', 'rpc.MessageSequence', 'transferDynamic'); +} \ No newline at end of file diff --git a/base_sdk/transfer/kitRegister/scene3d.ets b/base_sdk/transfer/kitRegister/scene3d.ets new file mode 100644 index 0000000000000000000000000000000000000000..c67ed7885cf84a46b73b598b1dc72f5c51e0fa98 --- /dev/null +++ b/base_sdk/transfer/kitRegister/scene3d.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerScene3D() { + registerStaticCB('ArkGraphics3D.Scene', 'graphics3d.Scene', 'Transfer', 'sceneTransferStatic'); + registerDynamicCB('ArkGraphics3D.Scene', 'graphics3d.Scene', 'Transfer', 'sceneTransferDynamic'); + registerStaticCB('ArkGraphics3D.SceneResourceFactory', 'graphics3d.Scene', 'Transfer', 'sceneResourceFactoryTransferStatic'); + registerDynamicCB('ArkGraphics3D.SceneResourceFactory', 'graphics3d.Scene', 'Transfer', 'sceneResourceFactoryTransferDynamic'); + registerStaticCB('ArkGraphics3D.Camera', 'graphics3d.SceneNodes', 'Transfer', 'cameraTransferStatic'); + registerDynamicCB('ArkGraphics3D.Camera', 'graphics3d.SceneNodes', 'Transfer', 'cameraTransferDynamic'); + registerStaticCB('ArkGraphics3D.Node', 'graphics3d.SceneNodes', 'Transfer', 'nodeTransferStatic'); + registerDynamicCB('ArkGraphics3D.Node', 'graphics3d.SceneNodes', 'Transfer', 'nodeTransferDynamic'); + registerStaticCB('ArkGraphics3D.Animation', 'graphics3d.SceneResources', 'Transfer', 'animationTransferStatic'); + registerDynamicCB('ArkGraphics3D.Animation', 'graphics3d.SceneResources', 'Transfer', 'animationTransferDynamic'); + registerStaticCB('ArkGraphics3D.Environment', 'graphics3d.SceneResources', 'Transfer', 'environmentTransferStatic'); + registerDynamicCB('ArkGraphics3D.Environment', 'graphics3d.SceneResources', 'Transfer', 'environmentTransferDynamic'); +} diff --git a/base_sdk/transfer/kitRegister/window.ets b/base_sdk/transfer/kitRegister/window.ets new file mode 100644 index 0000000000000000000000000000000000000000..55e42e8760ae1bcdd08eeca8f4724591397cf6ab --- /dev/null +++ b/base_sdk/transfer/kitRegister/window.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device 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 { registerStaticCB, registerDynamicCB } from '../register.ets'; + +export function registerWindow() { + registerStaticCB('window.WindowStage', '@ohos.window', 'window.WindowStageInternal', 'transferStatic'); + registerDynamicCB('window.WindowStage', '@ohos.window', 'window.WindowStageInternal', 'transferDynamic'); + registerStaticCB('window.Window', '@ohos.window', 'window.WindowInternal', 'transferStatic'); + registerDynamicCB('window.Window', '@ohos.window', 'window.WindowInternal', 'transferDynamic'); +} diff --git a/base_sdk/transfer/register.ets b/base_sdk/transfer/register.ets new file mode 100644 index 0000000000000000000000000000000000000000..09ba267ba88ba9947c39d74cb72de2fb1942abd8 --- /dev/null +++ b/base_sdk/transfer/register.ets @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 Huawei Device 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. + */ + +export interface CallbackUrl { + key: string; + filePath: string; + className: string; + methodName: string; + staticMethod?: (input: Any) => Object; + dynamicMethod?: (input: Object) => Any; +} + +export const staticRegisterMap = new Map(); +export const dynamicRegisterMap = new Map(); + +export function registerStaticCB(key: string, filePath: string, className: string, methodName: string) { + let callbackUrl: CallbackUrl = { + key: key, + filePath: filePath, + className: className, + methodName: methodName + }; + staticRegisterMap.set(key, callbackUrl); +} + +export function registerDynamicCB(key: string, filePath: string, className: string, methodName: string) { + let callbackUrl: CallbackUrl = { + key: key, + filePath: filePath, + className: className, + methodName: methodName + }; + dynamicRegisterMap.set(key, callbackUrl); +} + +export function registerStaticCB(key: string, staticMethod: (input: Any) => Object) { + let callbackUrl: CallbackUrl = { + key: key, + filePath: '', + className: '', + methodName: '', + staticMethod: staticMethod + }; + staticRegisterMap.set(key, callbackUrl); +} + +export function registerDynamicCB(key: string, dynamicMethod: (input: Object) => Any) { + let callbackUrl: CallbackUrl = { + key: key, + filePath: '', + className: '', + methodName: '', + dynamicMethod: dynamicMethod + }; + dynamicRegisterMap.set(key, callbackUrl); +} + + diff --git a/bundle.json b/bundle.json index 77f5f349db98089986cd583a4d6c30621042e993..21129c8a27160a803c28cf6e76c50667c5b46179 100644 --- a/bundle.json +++ b/bundle.json @@ -66,13 +66,15 @@ "icu", "openssl", "libxml2", - "typescript" + "typescript", + "runtime_core" ], "third_party": [] }, "build": { "sub_component": [ "//commonlibrary/ets_utils/base_sdk:base_sdk_ets", + "//commonlibrary/ets_utils/base_sdk:base_transfer_ets", "//commonlibrary/ets_utils/js_api_module/uri:uri_packages", "//commonlibrary/ets_utils/js_api_module/url:url_packages", "//commonlibrary/ets_utils/js_api_module/convertxml:convertxml_packages", diff --git a/js_concurrent_module/common/helper/concurrent_helper.cpp b/js_concurrent_module/common/helper/concurrent_helper.cpp index 3eef1990199088c278215488606099ade770e28e..151dacc6b029b402ac6467fa97eae285bc6159d2 100644 --- a/js_concurrent_module/common/helper/concurrent_helper.cpp +++ b/js_concurrent_module/common/helper/concurrent_helper.cpp @@ -95,4 +95,4 @@ bool ConcurrentHelper::IsModerateMemory() return false; #endif } -} // namespace Commonlibrary::Concurrent::TaskPoolModule \ No newline at end of file +} // namespace Commonlibrary::Concurrent::Common::Helper \ No newline at end of file diff --git a/js_concurrent_module/common/helper/hybrid_concurrent_helper.cpp b/js_concurrent_module/common/helper/hybrid_concurrent_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..41e51ef3936d1f299b8a4ac5b7ef66a1bd7b85b8 --- /dev/null +++ b/js_concurrent_module/common/helper/hybrid_concurrent_helper.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device 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. + */ + +#include "hybrid_concurrent_helper.h" +#include "tools/log.h" +#include "parameters.h" + +namespace Commonlibrary::Concurrent::Common::Helper { +std::atomic_bool globalEnableConcurrencyInteropFlag = false; +ani_vm* globalAniVm = nullptr; +std::once_flag g_globalAniVmInitFlag; + +ani_vm* ANIHelper::GetAniVm() +{ + std::call_once(g_globalAniVmInitFlag, &InitializeAniVm); + return globalAniVm; +} + +void ANIHelper::InitializeAniVm() +{ + const int flag = OHOS::system::GetIntParameter("persist.commonlibrary.concurrencysupportinterop", 0); + globalEnableConcurrencyInteropFlag = (flag != 0); + const std::string logMsg = globalEnableConcurrencyInteropFlag + ? "worker and taskpool support interop." + : "worker and taskpool do not support interop."; + HILOG_INFO("ANIHelper:: %{public}s", logMsg.c_str()); + if (!globalEnableConcurrencyInteropFlag) { + return; + } + ani_size res = 0; + ani_status status = ANI_GetCreatedVMs(&globalAniVm, 1, &res); + if (status != ANI_OK) { + HILOG_ERROR("ANIHelper:: ANI_GetCreatedVMs failed."); + globalAniVm = nullptr; + } +} + +bool ANIHelper::IsConcurrencySupportInterop() +{ + return globalEnableConcurrencyInteropFlag; +} +} // Commonlibrary::Concurrent::Common::Helper \ No newline at end of file diff --git a/js_concurrent_module/common/helper/hybrid_concurrent_helper.h b/js_concurrent_module/common/helper/hybrid_concurrent_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..32171a426bdd3f4f3e7ee4ff3608410588aa5632 --- /dev/null +++ b/js_concurrent_module/common/helper/hybrid_concurrent_helper.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device 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. + */ + +#ifndef JS_CONCURRENT_MODULE_COMMON_HELPER_HYBRID_CONCURRENT_HELPER_H +#define JS_CONCURRENT_MODULE_COMMON_HELPER_HYBRID_CONCURRENT_HELPER_H + +#include +#include "ani.h" + +namespace Commonlibrary::Concurrent::Common::Helper { +extern std::atomic_bool globalEnableConcurrencyInteropFlag; +extern ani_vm* globalAniVm; +extern std::once_flag g_globalAniVmInitFlag; + +class ANIHelper { +public: + ANIHelper() = delete; + ~ANIHelper() = delete; + + static ani_vm* GetAniVm(); + static void InitializeAniVm(); + static bool IsConcurrencySupportInterop(); +}; +} // namespace Commonlibrary::Concurrent::Common::Helper +#endif // JS_CONCURRENT_MODULE_COMMON_HELPER_HYBRID_CONCURRENT_HELPER_H \ No newline at end of file diff --git a/js_concurrent_module/taskpool/BUILD.gn b/js_concurrent_module/taskpool/BUILD.gn index 04007d066bb00a200fcbbb299f1a6e2b701a5353..36a709f7cab23676e49383d6693b8f621f2687de 100644 --- a/js_concurrent_module/taskpool/BUILD.gn +++ b/js_concurrent_module/taskpool/BUILD.gn @@ -96,6 +96,7 @@ ohos_shared_library("taskpool") { "ENABLE_TASKPOOL_EVENTHANDLER", "ENABLE_TASKPOOL_FFRT", "ENABLE_TASKPOOL_HISYSEVENT", + "ENABLE_CONCURRENCY_INTEROP", ] external_deps += [ "bundle_framework:appexecfwk_base", @@ -107,7 +108,10 @@ ohos_shared_library("taskpool") { "init:libbegetutil", "ipc:ipc_core", "samgr:samgr_proxy", + "runtime_core:ani", + "runtime_core:libarkruntime", ] + sources += [ "../common/helper/hybrid_concurrent_helper.cpp" ] } if (is_ohos && is_standard_system && !is_arkui_x && @@ -163,6 +167,7 @@ ohos_source_set("taskpool_static") { "ENABLE_TASKPOOL_EVENTHANDLER", "ENABLE_TASKPOOL_FFRT", "ENABLE_TASKPOOL_HISYSEVENT", + "ENABLE_CONCURRENCY_INTEROP", ] external_deps += [ "bundle_framework:appexecfwk_base", @@ -174,7 +179,10 @@ ohos_source_set("taskpool_static") { "init:libbegetutil", "ipc:ipc_core", "samgr:samgr_proxy", + "runtime_core:ani", + "runtime_core:libarkruntime", ] + sources += [ "../common/helper/hybrid_concurrent_helper.cpp" ] } if (is_arkui_x) { diff --git a/js_concurrent_module/taskpool/task_manager.cpp b/js_concurrent_module/taskpool/task_manager.cpp index 90f72b9664e59b83e8bc6b855aa5ba634242ed09..fc7c9c5f05a339043cb5714da95a6d2bcdd04b52 100644 --- a/js_concurrent_module/taskpool/task_manager.cpp +++ b/js_concurrent_module/taskpool/task_manager.cpp @@ -922,6 +922,11 @@ void TaskManager::InitTaskManager(napi_env env) #if defined(ENABLE_TASKPOOL_EVENTHANDLER) mainThreadHandler_ = std::make_shared( OHOS::AppExecFwk::EventRunner::GetMainEventRunner()); +#endif +#if defined(ENABLE_CONCURRENCY_INTEROP) + if (reinterpret_cast(env)->IsMainThread() && ANIHelper::GetAniVm() == nullptr) { + HILOG_INFO("taskpool:: get aniVm is null in main thread."); + } #endif auto mainThreadEngine = NativeEngine::GetMainThreadEngine(); if (mainThreadEngine == nullptr) { @@ -1697,4 +1702,46 @@ bool TaskManager::IsPerformIdle() const { return isPerformIdle_; } + +#if defined(ENABLE_CONCURRENCY_INTEROP) +void TaskManager::AttachWorkerToAniVm(Worker* worker) +{ + if (!ANIHelper::IsConcurrencySupportInterop()) { + return; + } + // attach worker env to 1.2vm + std::string interop = "--interop=enable"; + ani_option interopEnabled {interop.data(), (void *)worker->workerEnv_}; + ani_options aniArgs {1, &interopEnabled}; + auto* aniVm = ANIHelper::GetAniVm(); + if (aniVm == nullptr) { + HILOG_ERROR("taskpool:: aviVm is null."); + return; + } + ani_status status = aniVm->AttachCurrentThread(&aniArgs, ANI_VERSION_1, &worker->aniEnv_); + if (status != ANI_OK || worker->aniEnv_ == nullptr) { + HILOG_ERROR("taskpool:: AttachCurrentThread failed."); + } +} + +void TaskManager::DetachWorkerFromAniVm(Worker* worker) +{ + if (!ANIHelper::IsConcurrencySupportInterop()) { + return; + } + // detach worker from 1.2vm + auto* aniVm = ANIHelper::GetAniVm(); + if (aniVm == nullptr) { + HILOG_ERROR("taskpool:: DetachWorkerFromAniVm aviVm is null."); + return; + } + ani_status status = aniVm->DetachCurrentThread(); + if (status != ANI_OK) { + HILOG_ERROR("taskpool:: DetachCurrentThread failed."); + } + delete worker->aniEnv_; + worker->aniEnv_ = nullptr; +} +#endif + } // namespace Commonlibrary::Concurrent::TaskPoolModule \ No newline at end of file diff --git a/js_concurrent_module/taskpool/task_manager.h b/js_concurrent_module/taskpool/task_manager.h index 2d8eb173d268055dce2fdfa05712fbb5cbbb7e10..0c6d13d6250d704b5fd1bfd8be0a854955e3ffde 100644 --- a/js_concurrent_module/taskpool/task_manager.h +++ b/js_concurrent_module/taskpool/task_manager.h @@ -156,6 +156,10 @@ public: void SetIsPerformIdle(bool performIdle); bool IsPerformIdle() const; + // for taskpool support interop + void AttachWorkerToAniVm(Worker* worker); + void DetachWorkerFromAniVm(Worker* worker); + private: TaskManager(); ~TaskManager(); diff --git a/js_concurrent_module/taskpool/test/BUILD.gn b/js_concurrent_module/taskpool/test/BUILD.gn index 2bbb5248320f5fe88c9106442d172f0623c0d890..50a8bd4c0dcf19be59239a0860b0b02368097d26 100644 --- a/js_concurrent_module/taskpool/test/BUILD.gn +++ b/js_concurrent_module/taskpool/test/BUILD.gn @@ -56,10 +56,13 @@ ohos_unittest("test_taskpool_unittest") { defines = [ "ENABLE_TASKPOOL_FFRT", "ENABLE_TASKPOOL_HISYSEVENT", + "ENABLE_CONCURRENCY_INTEROP", ] external_deps += [ "ffrt:libffrt", "hisysevent:libhisysevent", + "runtime_core:ani", + "runtime_core:libarkruntime", ] } } diff --git a/js_concurrent_module/taskpool/worker.cpp b/js_concurrent_module/taskpool/worker.cpp index cc1a19b5369c38acac6520e6a01f719b0efebbe7..2425cdfabe6b70922aa7a757187a80712e0857aa 100644 --- a/js_concurrent_module/taskpool/worker.cpp +++ b/js_concurrent_module/taskpool/worker.cpp @@ -102,6 +102,10 @@ void Worker::ReleaseWorkerHandles(const uv_async_t* req) if (loop != nullptr) { uv_stop(loop); } + +#if defined(ENABLE_CONCURRENCY_INTEROP) + TaskManager::GetInstance().DetachWorkerFromAniVm(worker); +#endif } bool Worker::CheckFreeConditions() @@ -226,6 +230,9 @@ void Worker::ExecuteInThread(const void* data) HILOG_ERROR("taskpool:: worker create runtime failed"); return; } +#if defined(ENABLE_CONCURRENCY_INTEROP) + TaskManager::GetInstance().AttachWorkerToAniVm(worker); +#endif auto workerEngine = reinterpret_cast(worker->workerEnv_); // mark worker env is taskpoolThread workerEngine->MarkTaskPoolThread(); diff --git a/js_concurrent_module/taskpool/worker.h b/js_concurrent_module/taskpool/worker.h index 97850b34316b7a55cc6304548dc32592088bff50..51ee15d49ad4b037a32ef680a22771eb51a7487b 100644 --- a/js_concurrent_module/taskpool/worker.h +++ b/js_concurrent_module/taskpool/worker.h @@ -21,6 +21,9 @@ #if defined(ENABLE_TASKPOOL_FFRT) #include "cpp/task.h" #endif +#if defined(ENABLE_CONCURRENCY_INTEROP) +#include "helper/hybrid_concurrent_helper.h" +#endif #include "helper/concurrent_helper.h" #include "helper/error_helper.h" #include "helper/napi_helper.h" @@ -226,6 +229,9 @@ private: #if defined(ENABLE_TASKPOOL_HISYSEVENT) std::atomic reportCount_ = 0; #endif +#if defined(ENABLE_CONCURRENCY_INTEROP) + ani_env* aniEnv_ = nullptr; +#endif }; } // namespace Commonlibrary::Concurrent::TaskPoolModule #endif // JS_CONCURRENT_MODULE_TASKPOOL_WORKER_H \ No newline at end of file diff --git a/js_concurrent_module/worker/BUILD.gn b/js_concurrent_module/worker/BUILD.gn index 4fe2a072cdf1d18d3d2bab379ccc3d801a3598bf..d4b300025cb083ae4e92eb64f30c7c229b010742 100644 --- a/js_concurrent_module/worker/BUILD.gn +++ b/js_concurrent_module/worker/BUILD.gn @@ -83,8 +83,16 @@ ohos_shared_library("worker") { } if (is_ohos && is_standard_system && !is_arkui_x) { - defines += [ "ENABLE_WORKER_EVENTHANDLER" ] - external_deps += [ "eventhandler:libeventhandler" ] + defines += [ + "ENABLE_WORKER_EVENTHANDLER", + "ENABLE_CONCURRENCY_INTEROP", + ] + external_deps += [ + "eventhandler:libeventhandler", + "runtime_core:ani", + "runtime_core:libarkruntime", + ] + sources += [ "../common/helper/hybrid_concurrent_helper.cpp" ] } if (is_ohos && is_standard_system && defined(global_parts_info) && @@ -171,8 +179,16 @@ ohos_source_set("worker_static") { } if (is_ohos && is_standard_system && !is_arkui_x) { - defines += [ "ENABLE_WORKER_EVENTHANDLER" ] - external_deps += [ "eventhandler:libeventhandler" ] + defines += [ + "ENABLE_WORKER_EVENTHANDLER", + "ENABLE_CONCURRENCY_INTEROP" + ] + external_deps += [ + "eventhandler:libeventhandler", + "runtime_core:ani", + "runtime_core:libarkruntime", + ] + sources += [ "../common/helper/hybrid_concurrent_helper.cpp" ] } if (is_ohos && is_standard_system && defined(global_parts_info) && diff --git a/js_concurrent_module/worker/test/BUILD.gn b/js_concurrent_module/worker/test/BUILD.gn index b23476f7f87a353d2f60d3289b88f178386334f3..fa895ff5a5fd3d7b5506bc70950f9cede02931da 100644 --- a/js_concurrent_module/worker/test/BUILD.gn +++ b/js_concurrent_module/worker/test/BUILD.gn @@ -47,6 +47,14 @@ ohos_unittest("test_worker_unittest") { "libuv:uv", "napi:ace_napi", ] + + if (is_ohos && is_standard_system && !is_arkui_x) { + defines = [ "ENABLE_CONCURRENCY_INTEROP" ] + external_deps += [ + "runtime_core:ani", + "runtime_core:libarkruntime", + ] + } } group("unittest") { diff --git a/js_concurrent_module/worker/worker.cpp b/js_concurrent_module/worker/worker.cpp index b7317e31d80ae6d703ec47283a496f1f23d2b8a6..c66b4d850b39dc121819645323d4c3b1ce12e828 100644 --- a/js_concurrent_module/worker/worker.cpp +++ b/js_concurrent_module/worker/worker.cpp @@ -119,6 +119,12 @@ napi_value Worker::InitWorker(napi_env env, napi_value exports) InitPriorityObject(env, exports); +#if defined(ENABLE_CONCURRENCY_INTEROP) + if (reinterpret_cast(env)->IsMainThread() && ANIHelper::GetAniVm() == nullptr) { + HILOG_INFO("worker:: get aniVm is null in main thread."); + } +#endif + return InitPort(env, exports); } @@ -358,6 +364,13 @@ napi_value Worker::Constructor(napi_env env, napi_callback_info cbinfo, bool lim CloseHelp::DeletePointer(script, true); return nullptr; } + +#if defined(ENABLE_CONCURRENCY_INTEROP) + if (reinterpret_cast(env)->IsMainThread() && ANIHelper::GetAniVm() == nullptr) { + HILOG_ERROR("worker:: get aniVm is null in main thread."); + } +#endif + worker->StartExecuteInThread(env, script); return thisVar; } @@ -1464,6 +1477,11 @@ void Worker::ExecuteInThread(const void* data) worker->EraseWorker(); return; } + +#if defined(ENABLE_CONCURRENCY_INTEROP) + worker->AttachWorkerEnvToAniVm(); +#endif + reinterpret_cast(workerEnv)->RegisterNapiUncaughtExceptionHandler( [workerEnv, worker] (napi_value exception) -> void { if (!NativeEngine::IsAlive(reinterpret_cast(workerEnv))) { @@ -2500,6 +2518,11 @@ void Worker::ReleaseWorkerThreadContent() // 3. clear message send to worker thread workerMessageQueue_.Clear(workerEnv_); workerGlobalCallQueue_.Clear(workerEnv_); + +#if defined(ENABLE_CONCURRENCY_INTEROP) + DetachWorkerFromAniVm(); +#endif + CloseHelp::DeletePointer(reinterpret_cast(workerEnv_), false); workerEnv_ = nullptr; } @@ -2809,4 +2832,44 @@ void Worker::HostOnAllErrorsInner() HandleHostException(); } } + +#if defined(ENABLE_CONCURRENCY_INTEROP) +void Worker::AttachWorkerEnvToAniVm() +{ + if (!ANIHelper::IsConcurrencySupportInterop()) { + return; + } + std::string interop = "--interop=enable"; + ani_option interopEnabled {interop.data(), (void *)workerEnv_}; + ani_options aniArgs {1, &interopEnabled}; + auto* aniVm = ANIHelper::GetAniVm(); + if (aniVm == nullptr) { + HILOG_ERROR("worker:: AttachWorkerEnvToAniVm aviVm is null"); + return; + } + ani_status status = aniVm->AttachCurrentThread(&aniArgs, ANI_VERSION_1, &aniEnv_); + if (status != ANI_OK || aniEnv_ == nullptr) { + HILOG_ERROR("worker:: AttachCurrentThread failed."); + } +} + +void Worker::DetachWorkerFromAniVm() +{ + if (!ANIHelper::IsConcurrencySupportInterop()) { + return; + } + auto* aniVm = ANIHelper::GetAniVm(); + if (aniVm == nullptr) { + HILOG_ERROR("worker:: aviVm is null when DetachWorkerFromAniVm."); + return; + } + ani_status status = aniVm->DetachCurrentThread(); + if (status != ANI_OK) { + HILOG_ERROR("worker:: DetachCurrentThread failed."); + } + delete aniEnv_; + aniEnv_ = nullptr; +} +#endif + } // namespace Commonlibrary::Concurrent::WorkerModule diff --git a/js_concurrent_module/worker/worker.h b/js_concurrent_module/worker/worker.h index d769450035a2bb600d47e583a11faab8a43aec95..edfb7af2f4c962e02e5716aa5c3466f39683f937 100644 --- a/js_concurrent_module/worker/worker.h +++ b/js_concurrent_module/worker/worker.h @@ -21,6 +21,9 @@ #include #include +#if defined(ENABLE_CONCURRENCY_INTEROP) +#include "helper/hybrid_concurrent_helper.h" +#endif #include "helper/napi_helper.h" #include "helper/object_helper.h" #include "message_queue.h" @@ -587,6 +590,9 @@ private: void ClearHostMessage(napi_env env); + void AttachWorkerEnvToAniVm(); + void DetachWorkerFromAniVm(); + #if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) static void HandleDebuggerTask(const uv_async_t* req); void DebuggerOnPostTask(std::function&& task); @@ -661,6 +667,10 @@ private: WorkerPriority workerPriority_ = WorkerPriority::INVALID; std::function qosUpdatedCallback_; +#if defined(ENABLE_CONCURRENCY_INTEROP) + ani_env* aniEnv_ = nullptr; +#endif + friend class WorkersTest; };