diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 5944f68acd7541bba058c655f1214abd55431116..02cc8cdf6c2adb640c4b468e67adfd370bdd3d40 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -99,8 +99,27 @@ ohos_shared_library("commonlib_ets_ani") { output_extension = "so" } +ohos_prebuilt_etc("commonlib_ets_transfer_etc") { + source = "$target_out_dir/commonlib_ets_transfer.abc" + module_install_dir = "framework" + subsystem_name = "commonlibrary" + part_name = "ets_transfer" + deps = [ ":commonlib_ets_transfer" ] +} + +generate_static_abc("commonlib_ets_transfer") { + base_url = "./transfer" + files = [ + "./transfer/@ohos.DemoTransfer.ets", + "./transfer/@ohos.transfer.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/commonlib_ets_transfer.abc" +} + group("commonlib_sdk") { deps = [ + ":commonlib_ets_transfer_etc", #":commonlib_ets_ani", #":commonlib_ets_utils_api", #":commonsdk_arkts_etc", diff --git a/sdk/transfer/@ohos.DemoTransfer.ets b/sdk/transfer/@ohos.DemoTransfer.ets new file mode 100644 index 0000000000000000000000000000000000000000..ccaaa1cb1286e4dfdc027f319fe579b36aa921f5 --- /dev/null +++ b/sdk/transfer/@ohos.DemoTransfer.ets @@ -0,0 +1,34 @@ +/* + * 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. + */ + +class Demo { + x: string; + constructor(x: string) { + this.x = x; + } +} + +export class DemoTransfer { + static transferStatic(input: ESObject): Object { + let inputx = input.toString(); + let result: Demo = new Demo(inputx) + return result; + } + + static transferDynamic(input: Demo): ESObject { + let result: ESObject = new ESObject(); + return result; + } +} \ No newline at end of file diff --git a/sdk/transfer/@ohos.transfer.ets b/sdk/transfer/@ohos.transfer.ets new file mode 100644 index 0000000000000000000000000000000000000000..a871c916a7a764bd2e15f1a3f6927135bdf620ee --- /dev/null +++ b/sdk/transfer/@ohos.transfer.ets @@ -0,0 +1,32 @@ +/* + * 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 function transferStatic(input: ESObject, clazz: ClassType): Object { + let method = getMethod('transferStatic', clazz); + return method.invoke(null, [input]); +} + +export function transferDynamic(input: Object, clazz: ClassType): ESObject { + let method = getMethod('transferDynamic', clazz); + return method.invoke(null, [input]); +} + +function getMethod(methodName: string, clazz: ClassType): Method { + for (let i = 0; i < clazz.getMethodsNum().length; i++) { + if (methodName === clazz.getMethod(i).getName()) { + return clazz.getMethod(i); + } + } + throw new Error('Method ' + methodName + ' not found!'); +}