From 0013a2caac0f94eed82ba3297a9e5a9761c4052e Mon Sep 17 00:00:00 2001 From: zhongjianfei Date: Fri, 11 Mar 2022 10:26:13 +0800 Subject: [PATCH] sync aafwk to release3.1 Signed-off-by: zhongjianfei Change-Id: I0436a3a061297b02b50bef0861d66e8243419b5e --- aafwk.gni | 8 + common/BUILD.gn | 2 +- common/task_dispatcher/BUILD.gn | 2 +- .../include/dispatcher/base_task_dispatcher.h | 7 +- .../include/dispatcher/blocking_queue.h | 3 +- .../dispatcher/global_task_dispatcher.h | 2 +- .../include/dispatcher/group_impl.h | 2 +- .../dispatcher/parallel_task_dispatcher.h | 2 +- .../parallel_task_dispatcher_base.h | 2 +- .../dispatcher/serial_task_dispatcher.h | 3 +- .../dispatcher/spec_dispatcher_config.h | 2 +- .../include/dispatcher/spec_task_dispatcher.h | 2 +- .../dispatcher/task_dispatcher_context.h | 2 +- .../include/task/barrier_handler.h | 2 +- .../task_dispatcher/include/task/sync_task.h | 2 +- common/task_dispatcher/include/task/task.h | 2 +- .../task/task_handler_libevent_adapter.h | 2 +- .../include/task/task_listener.h | 2 +- .../task_dispatcher/include/task/task_stage.h | 2 +- .../include/threading/concurrent_queue.h | 2 +- .../threading/default_thread_factory.h | 2 +- .../threading/default_worker_pool_config.h | 2 +- .../include/threading/delay_execute_service.h | 2 +- .../include/threading/delay_queue.h | 2 +- .../include/threading/runnable.h | 2 +- .../threading/task_execute_interceptor.h | 2 +- .../include/threading/task_executor.h | 2 +- .../include/threading/thread_factory.h | 2 +- .../include/threading/work_thread.h | 2 +- .../include/threading/worker_pool.h | 2 +- .../include/threading/worker_pool_config.h | 2 +- .../src/dispatcher/global_task_dispatcher.cpp | 2 +- .../src/dispatcher/group_impl.cpp | 2 +- .../src/dispatcher/serial_task_dispatcher.cpp | 2 +- .../src/dispatcher/spec_task_dispatcher.cpp | 2 +- .../dispatcher/task_dispatcher_context.cpp | 2 +- .../src/task/barrier_handler.cpp | 2 +- common/task_dispatcher/src/task/sync_task.cpp | 2 +- common/task_dispatcher/src/task/task.cpp | 9 +- .../src/threading/default_thread_factory.cpp | 2 +- .../threading/default_worker_pool_config.cpp | 2 +- .../src/threading/work_thread.cpp | 2 +- .../src/threading/worker_pool.cpp | 2 +- common/task_dispatcher/test/BUILD.gn | 2 +- .../unittest/barrier_handler_test/BUILD.gn | 2 +- .../barrier_handler_test.cpp | 2 +- .../base_task_dispatcher_test/BUILD.gn | 2 +- .../base_task_dispatcher_test.cpp | 2 +- .../global_task_dispatcher_test/BUILD.gn | 2 +- .../global_task_dispatcher_test.cpp | 2 +- .../test/unittest/groupImpl_test/BUILD.gn | 2 +- .../groupImpl_test/groupImpl_test.cpp | 2 +- .../BUILD.gn | 2 +- .../parallel_task_dispatcher_base_test.cpp | 2 +- .../parallel_task_dispatcher_test/BUILD.gn | 2 +- .../parallel_task_dispatcher_test.cpp | 2 +- .../serial_task_dispatcher_test/BUILD.gn | 2 +- .../spec_dispatcher_config_test/BUILD.gn | 2 +- .../spec_dispatcher_config_test.cpp | 2 +- .../test/unittest/sync_task_test/BUILD.gn | 2 +- .../task_dispatcher_context_test/BUILD.gn | 2 +- .../task_dispatcher_context_test.cpp | 2 +- .../test/unittest/task_executor_test/BUILD.gn | 2 +- .../task_executor_test/task_executor_test.cpp | 2 +- .../BUILD.gn | 2 +- .../task_handler_libevent_adapter_test.cpp | 2 +- .../test/unittest/task_test/BUILD.gn | 2 +- .../test/unittest/task_test/task_test.cpp | 2 +- .../test/unittest/work_thread_test/BUILD.gn | 2 +- .../test/unittest/worker_pool_test/BUILD.gn | 2 +- .../worker_pool_test/worker_pool_test.cpp | 2 +- common/test/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../parallel_task_dispatcher_module_test.cpp | 10 +- .../BUILD.gn | 2 +- .../serial_task_dispatcher_module_test.cpp | 2 +- .../spec_task_dispatcher_module_test/BUILD.gn | 2 +- .../spec_task_dispatcher_module_test.cpp | 2 +- .../src/ability_connection.cpp | 2 + .../src/ability_context_impl.cpp | 2 +- .../mock_serviceability_manager_service.cpp | 8 +- .../AMS/mock_serviceability_manager_service.h | 4 +- .../ability_caller_fw_module_test.cpp | 2 +- frameworks/kits/ability/native/BUILD.gn | 11 +- .../kits/ability/native/include/ability.h | 26 + .../ability/native/include/ability_context.h | 49 +- .../ability/native/include/ability_impl.h | 18 +- .../ability/native/include/form_extension.h | 10 + .../native/include/form_provider_client.h | 12 + .../form_extension_provider_client.h | 10 + .../kits/ability/native/src/ability.cpp | 123 ++- .../ability/native/src/ability_context.cpp | 129 +-- .../ability/native/src/ability_window.cpp | 4 +- ...se_continuation_scheduler_replica_stub.cpp | 2 +- .../native/src/data_ability_helper.cpp | 35 +- .../native/src/data_ability_operation.cpp | 2 +- .../ability/native/src/form_extension.cpp | 6 + .../native/src/form_provider_client.cpp | 50 ++ .../form_extension_provider_client.cpp | 43 + .../js_form_extension_context.cpp | 2 +- .../native/src/js_datashare_ext_ability.cpp | 1 + .../ability/native/src/new_ability_impl.cpp | 2 +- .../ability/native/src/page_ability_impl.cpp | 2 +- .../include/mock_ability_manager_service.cpp | 14 +- .../include/mock_ability_manager_service.h | 7 +- .../mock/include/mock_bundle_manager_form.h | 8 +- .../include/mock_form_supply_callback.cpp | 12 + .../mock/include/mock_form_supply_callback.h | 8 + .../test/unittest/ability_context_test.cpp | 2 +- .../test/unittest/ability_permission_test.cpp | 54 +- .../include/ability_delegator.h | 5 +- .../include/ability_delegator_args.h | 7 + .../include/iability_monitor.h | 4 +- .../include/runner_runtime/js_test_runner.h | 1 + .../src/ability_delegator.cpp | 39 +- .../src/ability_delegator_args.cpp | 34 +- .../src/iability_monitor.cpp | 6 +- .../src/runner_runtime/js_test_runner.cpp | 40 +- .../ability_runtime/context/context_impl.cpp | 2 +- .../context/js_context_utils.cpp | 2 +- .../kits/appkit/native/app/include/context.h | 35 - .../native/app/include/context_container.h | 37 +- .../appkit/native/app/include/context_deal.h | 35 - .../appkit/native/app/include/main_thread.h | 26 +- .../native/app/src/context_container.cpp | 59 -- .../appkit/native/app/src/context_deal.cpp | 44 - .../appkit/native/app/src/main_thread.cpp | 97 +- .../mock_ability_manager_client_interface1.h | 15 +- .../mock_resourceManager_interface1.cpp | 3 +- .../Mock/include/mock_ability_mgr_service.h | 3 +- .../Mock/include/mock_bundle_mgr_service.h | 6 +- .../src/ohos/aafwk/content/extra_params.cpp | 1 + .../cpp/src/ohos/aafwk/content/want.cpp | 4 +- .../src/ohos/aafwk/content/want_params.cpp | 2 +- .../kits/fmskit/native/include/form_mgr.h | 20 + .../kits/fmskit/native/src/form_mgr.cpp | 37 + .../native/js_data_struct_converter.cpp | 1 - frameworks/kits/runtime/native/js_runtime.cpp | 6 +- .../mock/AMS/mock_ability_manager_service.cpp | 8 +- .../mock/AMS/mock_ability_manager_service.h | 6 +- .../mock_serviceability_manager_service.cpp | 8 +- .../AMS/mock_serviceability_manager_service.h | 6 +- .../mock_ability_thread_for_data_observer.h | 3 + .../cpp/abilitytest/ability_context_test.cpp | 2 +- .../kits/wantagent/src/pending_want.cpp | 6 +- .../kits/wantagent/src/want_agent_helper.cpp | 4 +- .../include/ability_manager_client.h | 11 +- .../include/ability_manager_interface.h | 28 +- .../include/ability_scheduler_interface.h | 4 +- .../include/appmgr/ams_mgr_interface.h | 13 - .../include/appmgr/ams_mgr_proxy.h | 12 - .../app_manager/include/appmgr/ams_mgr_stub.h | 3 +- .../include/appmgr/app_mgr_client.h | 19 +- .../include/appmgr/app_mgr_interface.h | 8 + .../include/appmgr/app_mgr_proxy.h | 7 + .../app_manager/include/appmgr/app_mgr_stub.h | 1 + .../include/appmgr/app_scheduler_host.h | 1 + .../include/appmgr/app_scheduler_interface.h | 10 + .../include/appmgr/app_scheduler_proxy.h | 9 + .../src/appmgr/ability_controller_stub.cpp | 2 +- .../app_manager/src/appmgr/ams_mgr_proxy.cpp | 28 - .../app_manager/src/appmgr/ams_mgr_stub.cpp | 17 +- .../app_manager/src/appmgr/app_mgr_client.cpp | 28 +- .../app_manager/src/appmgr/app_mgr_proxy.cpp | 26 + .../app_manager/src/appmgr/app_mgr_stub.cpp | 11 +- .../src/appmgr/app_scheduler_host.cpp | 11 +- .../src/appmgr/app_scheduler_proxy.cpp | 20 + .../src/appmgr/app_state_callback_host.cpp | 2 +- .../application_state_observer_stub.cpp | 2 +- .../src/appmgr/render_scheduler_host.cpp | 2 +- .../start_specified_ability_response_stub.cpp | 2 +- interfaces/innerkits/form_manager/BUILD.gn | 5 + .../form_manager/include/form_constants.h | 2 + .../form_manager/include/form_mgr_interface.h | 24 +- .../form_manager/include/form_mgr_proxy.h | 21 + .../form_manager/include/form_mgr_stub.h | 14 + .../include/form_provider_interface.h | 12 + .../include/form_provider_proxy.h | 8 + .../form_manager/include/form_provider_stub.h | 7 + .../include/form_supply_interface.h | 10 + .../form_manager/include/form_supply_proxy.h | 8 + .../form_manager/include/form_supply_stub.h | 7 + .../form_manager/src/form_host_stub.cpp | 2 +- .../form_manager/src/form_mgr_proxy.cpp | 92 ++ .../form_manager/src/form_mgr_stub.cpp | 70 +- .../form_manager/src/form_provider_proxy.cpp | 44 + .../form_manager/src/form_provider_stub.cpp | 35 +- .../form_manager/src/form_supply_proxy.cpp | 36 + .../form_manager/src/form_supply_stub.cpp | 24 +- .../innerkits/runtime/include/runtime.h | 1 + .../want/include/ohos/aafwk/content/want.h | 4 +- .../napi/aafwk/app/ability_delegator/BUILD.gn | 1 + .../js_ability_delegator.cpp | 137 ++- .../ability_delegator/js_ability_delegator.h | 6 +- .../js_ability_delegator_utils.cpp | 1 + interfaces/kits/napi/aafwk/dataShare/BUILD.gn | 1 + .../kits/napi/aafwk/featureAbility/BUILD.gn | 6 +- .../aafwk/featureAbility/napi_context.cpp | 229 +---- .../napi_data_ability_operation.cpp | 8 +- interfaces/kits/napi/aafwk/formHost/BUILD.gn | 3 + .../napi/aafwk/formHost/napi_form_host.cpp | 830 ++++++++++++++++++ .../kits/napi/aafwk/formHost/napi_form_host.h | 59 ++ .../napi/aafwk/formHost/native_module.cpp | 6 + .../kits/napi/aafwk/formManager/BUILD.gn | 11 +- .../aafwk/formManager/napi_form_manager.cpp | 830 ++++++++++++++++++ .../aafwk/formManager/napi_form_manager.h | 60 ++ .../napi/aafwk/formManager/native_module.cpp | 6 + .../napi/aafwk/inner/napi_common/BUILD.gn | 5 +- .../inner/napi_common/napi_common_ability.cpp | 8 +- .../napi_common/napi_common_configuration.cpp | 2 +- .../inner/napi_common/napi_common_util.cpp | 4 +- .../kits/napi/aafwk/particleAbility/BUILD.gn | 4 +- .../kits/napi/aafwk/wantConstant/BUILD.gn | 3 +- .../include/ability_connect_manager.h | 2 + .../include/ability_manager_proxy.h | 25 +- .../include/ability_manager_service.h | 22 +- .../abilitymgr/include/ability_manager_stub.h | 4 +- services/abilitymgr/include/app_scheduler.h | 30 +- .../abilitymgr/include/inner_mission_info.h | 2 + .../abilitymgr/include/mission_info_mgr.h | 5 + services/abilitymgr/include/mission_list.h | 9 + .../abilitymgr/include/mission_list_manager.h | 4 + .../include/mission_listener_controller.h | 2 + .../abilitymgr/include/pending_want_manager.h | 4 +- services/abilitymgr/include/user_controller.h | 2 +- .../src/ability_connect_callback_stub.cpp | 1 + .../src/ability_connect_manager.cpp | 19 + .../abilitymgr/src/ability_manager_client.cpp | 29 +- .../abilitymgr/src/ability_manager_proxy.cpp | 62 +- .../src/ability_manager_service.cpp | 136 ++- .../abilitymgr/src/ability_manager_stub.cpp | 30 +- .../src/ams_configuration_parameter.cpp | 4 +- services/abilitymgr/src/app_scheduler.cpp | 33 +- .../abilitymgr/src/data_ability_manager.cpp | 3 +- .../abilitymgr/src/inner_mission_info.cpp | 90 +- services/abilitymgr/src/mission_info_mgr.cpp | 35 +- services/abilitymgr/src/mission_list.cpp | 35 + .../abilitymgr/src/mission_list_manager.cpp | 60 +- .../src/mission_listener_controller.cpp | 25 + .../abilitymgr/src/pending_want_manager.cpp | 8 +- services/abilitymgr/src/shared_memory.cpp | 5 +- .../src/appmgr_test_service.cpp | 4 +- .../mock/include/mock_app_manager_client.h | 3 +- .../include/appmgr/app_mgr_client.h | 14 +- .../src/appmgr/app_mgr_client.cpp | 5 - .../src/appmgr/mock_app_scheduler.cpp | 8 +- .../ability_connect_manage_test/BUILD.gn | 3 +- .../ability_manager_stub_mock_test.h | 14 +- .../ability_manager_stub_mock.h | 14 +- .../ability_manager_service_test.cpp | 22 +- .../ability_manager_stub_impl_mock.h | 13 +- .../ability_manager_stub_mock.h | 6 +- .../ability_stack_manager_test.cpp | 8 +- .../phone/data_ability_manager_test/BUILD.gn | 3 +- .../pending_want_manager_test.cpp | 6 +- services/appmgr/include/ams_mgr_scheduler.h | 12 - services/appmgr/include/app_mgr_service.h | 8 + .../appmgr/include/app_mgr_service_inner.h | 12 - services/appmgr/include/app_running_record.h | 1 + .../appmgr/include/module_running_record.h | 4 +- services/appmgr/src/ams_mgr_scheduler.cpp | 8 - services/appmgr/src/app_death_recipient.cpp | 3 +- services/appmgr/src/app_mgr_service.cpp | 20 + services/appmgr/src/app_mgr_service_inner.cpp | 70 +- services/appmgr/src/app_running_record.cpp | 13 + .../src/system_environment_information.cpp | 2 +- .../mock/include/mock_ams_mgr_scheduler.h | 3 +- .../test/mock/include/mock_app_mgr_service.h | 1 + .../test/mock/include/mock_app_scheduler.h | 1 + .../test/mock/include/mock_application.h | 1 + .../ams_workflow_test.cpp | 6 +- .../common/include/permission_constants.h | 9 +- .../common/include/permission_verification.h | 2 + .../common/src/permission_verification.cpp | 14 + .../src/data_ability_observer_proxy.cpp | 7 +- .../mock_dataobs_mgr_client.h | 10 +- services/formmgr/BUILD.gn | 1 + .../include/form_acquire_state_connection.h | 56 ++ services/formmgr/include/form_mgr_adapter.h | 24 +- services/formmgr/include/form_mgr_service.h | 20 + services/formmgr/include/form_provider_mgr.h | 6 + .../formmgr/include/form_supply_callback.h | 8 + services/formmgr/include/form_task_mgr.h | 16 + services/formmgr/include/form_timer.h | 2 +- services/formmgr/include/form_timer_mgr.h | 12 +- .../src/form_acquire_state_connection.cpp | 58 ++ services/formmgr/src/form_mgr_adapter.cpp | 94 ++ services/formmgr/src/form_mgr_service.cpp | 37 + services/formmgr/src/form_supply_callback.cpp | 18 + services/formmgr/src/form_task_mgr.cpp | 42 + services/formmgr/src/form_timer_mgr.cpp | 49 +- .../test/mock/include/mock_ability_manager.h | 46 +- .../test/mock/include/mock_bundle_manager.h | 6 +- .../test/mock/include/mock_form_host_client.h | 7 +- .../mock/include/mock_form_provider_client.h | 9 + .../mock/src/mock_form_provider_client.cpp | 14 + .../unittest/fms_form_data_mgr_test/BUILD.gn | 4 +- .../fms_form_data_mgr_test.cpp | 4 +- .../unittest/fms_form_db_record_test/BUILD.gn | 4 +- .../fms_form_mgr_add_form_test/BUILD.gn | 4 +- .../fms_form_mgr_death_callback_test/BUILD.gn | 4 +- .../include/appmgr/mock_ability_mgr_host.h | 9 +- .../mock/include/mock_ability_manager_proxy.h | 7 +- .../mock/include/mock_ability_mgr_service.h | 6 +- .../test/mock/include/mock_app_mgr_client.h | 3 +- .../test/mock/include/mock_app_scheduler.h | 1 + .../ability_mgr_module_test.cpp | 31 +- .../ability_stack_module_test.cpp | 12 +- ...ams_ability_running_record_module_test.cpp | 3 + .../ams_app_mgr_service_module_test.cpp | 2 + .../ams/app_running_record_test/BUILD.gn | 3 +- .../ams_app_service_flow_module_test.cpp | 4 +- .../specified_ability_service_test/BUILD.gn | 3 +- .../static_start_ability_test/BUILD.gn | 3 +- .../amsKitSystemTest/src/second_ability.cpp | 8 +- .../src/ams_st_service_ability_b3.cpp | 17 +- .../src/ams_st_service_ability_c4.cpp | 15 +- .../src/ams_st_service_ability_d1.cpp | 15 +- .../src/ams_st_service_ability_e2.cpp | 19 +- .../src/ams_st_service_ability_f3.cpp | 10 +- .../src/ams_st_service_ability_g1.cpp | 19 +- .../src/ams_st_service_ability_h1.cpp | 19 +- .../serviceAbilityA/src/service_ability_a.cpp | 12 +- .../src/verify_act_first_ability.cpp | 8 +- .../abilitySrc/taskDispatcherTestB/BUILD.gn | 3 +- .../src/form_ability_commona.cpp | 12 +- .../src/form_ability_commonb.cpp | 12 +- .../src/form_ability_no_perm.cpp | 8 +- .../src/form_ability_a.cpp | 35 +- .../src/form_ability_deleteform.cpp | 28 +- .../src/form_ability_releaseform.cpp | 17 +- .../src/form_ability_b.cpp | 14 +- .../ams_service_ability_test.cpp | 4 +- tools/aa/include/ability_command.h | 6 +- tools/aa/include/itest_observer.h | 2 +- tools/aa/include/test_observer.h | 4 +- tools/aa/include/test_observer_proxy.h | 2 +- tools/aa/src/ability_command.cpp | 13 +- tools/aa/src/test_observer.cpp | 6 +- tools/aa/src/test_observer_proxy.cpp | 6 +- tools/aa/src/test_observer_stub.cpp | 4 +- tools/test/mock/mock_ability_manager_stub.h | 6 +- tools/test/moduletest/aa/BUILD.gn | 3 +- zidl/test/native/src/test_client.cpp | 1 - 345 files changed, 4604 insertions(+), 1755 deletions(-) create mode 100644 services/formmgr/include/form_acquire_state_connection.h create mode 100644 services/formmgr/src/form_acquire_state_connection.cpp diff --git a/aafwk.gni b/aafwk.gni index 0e00cbd507b..9e1a559076f 100644 --- a/aafwk.gni +++ b/aafwk.gni @@ -24,3 +24,11 @@ dispatcher_path = "${aafwk_path}/common/task_dispatcher" system_test_app_path = "${aafwk_path}/test/resource/amssystemtestability/abilitySrc" + +declare_args() { + background_task_mgr_continuous_task_enable = true + + if (!defined(global_parts_info.resourceschedule_background_task_mgr)) { + background_task_mgr_continuous_task_enable = false + } +} diff --git a/common/BUILD.gn b/common/BUILD.gn index b58b035353d..39040c9b8c0 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/BUILD.gn b/common/task_dispatcher/BUILD.gn index ceba1aafa69..8fa9150d0fe 100644 --- a/common/task_dispatcher/BUILD.gn +++ b/common/task_dispatcher/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/dispatcher/base_task_dispatcher.h b/common/task_dispatcher/include/dispatcher/base_task_dispatcher.h index f55a2b6f081..f1cce7186b2 100644 --- a/common/task_dispatcher/include/dispatcher/base_task_dispatcher.h +++ b/common/task_dispatcher/include/dispatcher/base_task_dispatcher.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -30,7 +30,6 @@ namespace AppExecFwk { /** * Base implementation for interface of TaskDispatcher. */ - class BaseTaskDispatcher : public TaskDispatcher { public: BaseTaskDispatcher(const std::string &dispatcherName, const TaskPriority priority); @@ -90,7 +89,7 @@ public: /** * Synchronously waiting all tasks in the group to be done. - * @param group contains a serial of jobs. + * @param group contains a serial of jobs. * @param timeout is the max waiting time for jobs in group execute, in ms. * @return true if all jobs in group has finished or false if timeout occurs. * @@ -110,7 +109,7 @@ public: /** * Called to dispatch |task| |iterations| times and wait. * - * @param task is the job to execute multi times. + * @param task is the job to execute multi times. * @param iterations indicates times the task should be executed. * */ diff --git a/common/task_dispatcher/include/dispatcher/blocking_queue.h b/common/task_dispatcher/include/dispatcher/blocking_queue.h index 305c8614227..05d2fd2e1b4 100644 --- a/common/task_dispatcher/include/dispatcher/blocking_queue.h +++ b/common/task_dispatcher/include/dispatcher/blocking_queue.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -55,6 +55,7 @@ struct PriorityTaskWrapper { static constexpr int DEFAULT_PRIORITY_WEIGHT = 1; static constexpr int LOW_PRIORITY_WEIGHT = 0; }; + struct CompareTaskPriority { bool operator()(const std::shared_ptr &wrapper1, const std::shared_ptr &wrapper2) const diff --git a/common/task_dispatcher/include/dispatcher/global_task_dispatcher.h b/common/task_dispatcher/include/dispatcher/global_task_dispatcher.h index 3af52cc747f..f0416a1824e 100644 --- a/common/task_dispatcher/include/dispatcher/global_task_dispatcher.h +++ b/common/task_dispatcher/include/dispatcher/global_task_dispatcher.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/dispatcher/group_impl.h b/common/task_dispatcher/include/dispatcher/group_impl.h index 4075ee5f59e..388942ad7ff 100644 --- a/common/task_dispatcher/include/dispatcher/group_impl.h +++ b/common/task_dispatcher/include/dispatcher/group_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/dispatcher/parallel_task_dispatcher.h b/common/task_dispatcher/include/dispatcher/parallel_task_dispatcher.h index 8c429313a59..8f85c544b0e 100644 --- a/common/task_dispatcher/include/dispatcher/parallel_task_dispatcher.h +++ b/common/task_dispatcher/include/dispatcher/parallel_task_dispatcher.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/dispatcher/parallel_task_dispatcher_base.h b/common/task_dispatcher/include/dispatcher/parallel_task_dispatcher_base.h index 87381bd557b..39a5fcf4ab1 100644 --- a/common/task_dispatcher/include/dispatcher/parallel_task_dispatcher_base.h +++ b/common/task_dispatcher/include/dispatcher/parallel_task_dispatcher_base.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/dispatcher/serial_task_dispatcher.h b/common/task_dispatcher/include/dispatcher/serial_task_dispatcher.h index 0777833e7ae..3348ad1a0bb 100644 --- a/common/task_dispatcher/include/dispatcher/serial_task_dispatcher.h +++ b/common/task_dispatcher/include/dispatcher/serial_task_dispatcher.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #ifndef OHOS_APP_DISPATCHER_SERIAL_TASK_DISPATCHER_H #define OHOS_APP_DISPATCHER_SERIAL_TASK_DISPATCHER_H diff --git a/common/task_dispatcher/include/dispatcher/spec_dispatcher_config.h b/common/task_dispatcher/include/dispatcher/spec_dispatcher_config.h index 64ecdb2e320..8a5ecab5dfa 100644 --- a/common/task_dispatcher/include/dispatcher/spec_dispatcher_config.h +++ b/common/task_dispatcher/include/dispatcher/spec_dispatcher_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/dispatcher/spec_task_dispatcher.h b/common/task_dispatcher/include/dispatcher/spec_task_dispatcher.h index 138f78aa768..377ccd5e413 100644 --- a/common/task_dispatcher/include/dispatcher/spec_task_dispatcher.h +++ b/common/task_dispatcher/include/dispatcher/spec_task_dispatcher.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/dispatcher/task_dispatcher_context.h b/common/task_dispatcher/include/dispatcher/task_dispatcher_context.h index f289bec7e59..ffb0cc90dcd 100644 --- a/common/task_dispatcher/include/dispatcher/task_dispatcher_context.h +++ b/common/task_dispatcher/include/dispatcher/task_dispatcher_context.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/task/barrier_handler.h b/common/task_dispatcher/include/task/barrier_handler.h index c2c52234bec..7bf29df1d27 100644 --- a/common/task_dispatcher/include/task/barrier_handler.h +++ b/common/task_dispatcher/include/task/barrier_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/task/sync_task.h b/common/task_dispatcher/include/task/sync_task.h index 5901e6bbc27..4c5c57a38a0 100644 --- a/common/task_dispatcher/include/task/sync_task.h +++ b/common/task_dispatcher/include/task/sync_task.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/task/task.h b/common/task_dispatcher/include/task/task.h index b73c09578cf..e43309c5ba8 100644 --- a/common/task_dispatcher/include/task/task.h +++ b/common/task_dispatcher/include/task/task.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/task/task_handler_libevent_adapter.h b/common/task_dispatcher/include/task/task_handler_libevent_adapter.h index 84d9973e046..df1c5cd4ceb 100644 --- a/common/task_dispatcher/include/task/task_handler_libevent_adapter.h +++ b/common/task_dispatcher/include/task/task_handler_libevent_adapter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/task/task_listener.h b/common/task_dispatcher/include/task/task_listener.h index b1891899515..f0b6e46494b 100644 --- a/common/task_dispatcher/include/task/task_listener.h +++ b/common/task_dispatcher/include/task/task_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/task/task_stage.h b/common/task_dispatcher/include/task/task_stage.h index e0244d0fbee..8c2da3aebeb 100644 --- a/common/task_dispatcher/include/task/task_stage.h +++ b/common/task_dispatcher/include/task/task_stage.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/concurrent_queue.h b/common/task_dispatcher/include/threading/concurrent_queue.h index 7e9286e0fbe..9c6c53d085b 100644 --- a/common/task_dispatcher/include/threading/concurrent_queue.h +++ b/common/task_dispatcher/include/threading/concurrent_queue.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/default_thread_factory.h b/common/task_dispatcher/include/threading/default_thread_factory.h index 6ee8ef91d81..1c457d94a62 100644 --- a/common/task_dispatcher/include/threading/default_thread_factory.h +++ b/common/task_dispatcher/include/threading/default_thread_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/default_worker_pool_config.h b/common/task_dispatcher/include/threading/default_worker_pool_config.h index 8ec371262e2..45e19983389 100644 --- a/common/task_dispatcher/include/threading/default_worker_pool_config.h +++ b/common/task_dispatcher/include/threading/default_worker_pool_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/delay_execute_service.h b/common/task_dispatcher/include/threading/delay_execute_service.h index 4b62e2cd3cf..5f218ddfcc3 100644 --- a/common/task_dispatcher/include/threading/delay_execute_service.h +++ b/common/task_dispatcher/include/threading/delay_execute_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/delay_queue.h b/common/task_dispatcher/include/threading/delay_queue.h index d010f661a29..5938064c5a2 100644 --- a/common/task_dispatcher/include/threading/delay_queue.h +++ b/common/task_dispatcher/include/threading/delay_queue.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/runnable.h b/common/task_dispatcher/include/threading/runnable.h index af541d17cae..fd84ab2a566 100644 --- a/common/task_dispatcher/include/threading/runnable.h +++ b/common/task_dispatcher/include/threading/runnable.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/task_execute_interceptor.h b/common/task_dispatcher/include/threading/task_execute_interceptor.h index 51794fc3495..4c3e6acd846 100644 --- a/common/task_dispatcher/include/threading/task_execute_interceptor.h +++ b/common/task_dispatcher/include/threading/task_execute_interceptor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/task_executor.h b/common/task_dispatcher/include/threading/task_executor.h index 7c6294c036a..5e4509a6162 100644 --- a/common/task_dispatcher/include/threading/task_executor.h +++ b/common/task_dispatcher/include/threading/task_executor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/thread_factory.h b/common/task_dispatcher/include/threading/thread_factory.h index f1d685ed0f2..3e1c25baee9 100644 --- a/common/task_dispatcher/include/threading/thread_factory.h +++ b/common/task_dispatcher/include/threading/thread_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/work_thread.h b/common/task_dispatcher/include/threading/work_thread.h index 6aca9c78c3d..02b27834174 100644 --- a/common/task_dispatcher/include/threading/work_thread.h +++ b/common/task_dispatcher/include/threading/work_thread.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/worker_pool.h b/common/task_dispatcher/include/threading/worker_pool.h index 5b5b3cc5ce6..6ce8fdda977 100644 --- a/common/task_dispatcher/include/threading/worker_pool.h +++ b/common/task_dispatcher/include/threading/worker_pool.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/include/threading/worker_pool_config.h b/common/task_dispatcher/include/threading/worker_pool_config.h index 83f1fd9d943..0e5066bb9c9 100644 --- a/common/task_dispatcher/include/threading/worker_pool_config.h +++ b/common/task_dispatcher/include/threading/worker_pool_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/src/dispatcher/global_task_dispatcher.cpp b/common/task_dispatcher/src/dispatcher/global_task_dispatcher.cpp index 6a794d8eafd..e816dc455d8 100644 --- a/common/task_dispatcher/src/dispatcher/global_task_dispatcher.cpp +++ b/common/task_dispatcher/src/dispatcher/global_task_dispatcher.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/src/dispatcher/group_impl.cpp b/common/task_dispatcher/src/dispatcher/group_impl.cpp index ff4ceee648f..4be1ec7b1cf 100644 --- a/common/task_dispatcher/src/dispatcher/group_impl.cpp +++ b/common/task_dispatcher/src/dispatcher/group_impl.cpp @@ -95,7 +95,7 @@ bool GroupImpl::AddNotification(const std::shared_ptr ¬ification) if (count_.load() != 0) { std::unique_lock lock(dataMutex_); if (notifications_.size() == MAX_TASK) { - HILOG_WARN("GroupImpl::AddNotification called maximun number of tasks exceeded"); + HILOG_WARN("GroupImpl::AddNotification called maximum number of tasks exceeded"); return false; } if (count_.load() != 0) { diff --git a/common/task_dispatcher/src/dispatcher/serial_task_dispatcher.cpp b/common/task_dispatcher/src/dispatcher/serial_task_dispatcher.cpp index 676fd491749..f7d96a688bb 100644 --- a/common/task_dispatcher/src/dispatcher/serial_task_dispatcher.cpp +++ b/common/task_dispatcher/src/dispatcher/serial_task_dispatcher.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/src/dispatcher/spec_task_dispatcher.cpp b/common/task_dispatcher/src/dispatcher/spec_task_dispatcher.cpp index 63fe1a334d9..41f3dce63cb 100644 --- a/common/task_dispatcher/src/dispatcher/spec_task_dispatcher.cpp +++ b/common/task_dispatcher/src/dispatcher/spec_task_dispatcher.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/src/dispatcher/task_dispatcher_context.cpp b/common/task_dispatcher/src/dispatcher/task_dispatcher_context.cpp index 528180e67cc..a760c32b9e0 100644 --- a/common/task_dispatcher/src/dispatcher/task_dispatcher_context.cpp +++ b/common/task_dispatcher/src/dispatcher/task_dispatcher_context.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/src/task/barrier_handler.cpp b/common/task_dispatcher/src/task/barrier_handler.cpp index 971b042e407..0e18d9cc8fb 100644 --- a/common/task_dispatcher/src/task/barrier_handler.cpp +++ b/common/task_dispatcher/src/task/barrier_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/src/task/sync_task.cpp b/common/task_dispatcher/src/task/sync_task.cpp index e2c12b62e40..065df40d3f0 100644 --- a/common/task_dispatcher/src/task/sync_task.cpp +++ b/common/task_dispatcher/src/task/sync_task.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/src/task/task.cpp b/common/task_dispatcher/src/task/task.cpp index d14616124df..8fd7976ed71 100644 --- a/common/task_dispatcher/src/task/task.cpp +++ b/common/task_dispatcher/src/task/task.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -208,9 +208,10 @@ void Task::ConcurrentQueueStatusUpdate(const TaskStage::TASKSTAGE taskstage) bool Task::operator==(std::shared_ptr &rec) const { - return this->sequence_ == rec->sequence_ && this->state_ == rec->state_ && this->priority_ == rec->priority_ && - this->revocable_ == rec->revocable_ && this->runnable_ == rec->runnable_ && - this->baseTaskDispatcher_ == rec->baseTaskDispatcher_; + return ((this->sequence_ == rec->sequence_) && (this->state_ == rec->state_) && + (this->priority_ == rec->priority_) && + (this->revocable_ == rec->revocable_) && (this->runnable_ == rec->runnable_) && + (this->baseTaskDispatcher_ == rec->baseTaskDispatcher_)); } } // namespace AppExecFwk } // namespace OHOS diff --git a/common/task_dispatcher/src/threading/default_thread_factory.cpp b/common/task_dispatcher/src/threading/default_thread_factory.cpp index 0e8eedaa47d..5dbf3147e33 100644 --- a/common/task_dispatcher/src/threading/default_thread_factory.cpp +++ b/common/task_dispatcher/src/threading/default_thread_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/src/threading/default_worker_pool_config.cpp b/common/task_dispatcher/src/threading/default_worker_pool_config.cpp index a42d13a2d5b..404567290f8 100644 --- a/common/task_dispatcher/src/threading/default_worker_pool_config.cpp +++ b/common/task_dispatcher/src/threading/default_worker_pool_config.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/src/threading/work_thread.cpp b/common/task_dispatcher/src/threading/work_thread.cpp index dc049bd9463..9f840d7badf 100644 --- a/common/task_dispatcher/src/threading/work_thread.cpp +++ b/common/task_dispatcher/src/threading/work_thread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/src/threading/worker_pool.cpp b/common/task_dispatcher/src/threading/worker_pool.cpp index 7a9672fc29e..117fc41bb8d 100644 --- a/common/task_dispatcher/src/threading/worker_pool.cpp +++ b/common/task_dispatcher/src/threading/worker_pool.cpp @@ -49,7 +49,7 @@ WorkerPool::~WorkerPool() bool WorkerPool::Init(const std::shared_ptr &config) { - if (CheckConfigParams(config) == false) { + if (!CheckConfigParams(config)) { HILOG_ERROR("WorkerPool::checkConfigParams parameters are illegal"); return false; } diff --git a/common/task_dispatcher/test/BUILD.gn b/common/task_dispatcher/test/BUILD.gn index 1c43d56c4b1..c27637c77d8 100644 --- a/common/task_dispatcher/test/BUILD.gn +++ b/common/task_dispatcher/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/barrier_handler_test/BUILD.gn b/common/task_dispatcher/test/unittest/barrier_handler_test/BUILD.gn index f4d1aeae48b..e9fd2c2940f 100644 --- a/common/task_dispatcher/test/unittest/barrier_handler_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/barrier_handler_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/barrier_handler_test/barrier_handler_test.cpp b/common/task_dispatcher/test/unittest/barrier_handler_test/barrier_handler_test.cpp index 57eedb0cf96..9c705156c44 100644 --- a/common/task_dispatcher/test/unittest/barrier_handler_test/barrier_handler_test.cpp +++ b/common/task_dispatcher/test/unittest/barrier_handler_test/barrier_handler_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/base_task_dispatcher_test/BUILD.gn b/common/task_dispatcher/test/unittest/base_task_dispatcher_test/BUILD.gn index 125246d8aef..58c6730325a 100644 --- a/common/task_dispatcher/test/unittest/base_task_dispatcher_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/base_task_dispatcher_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/base_task_dispatcher_test/base_task_dispatcher_test.cpp b/common/task_dispatcher/test/unittest/base_task_dispatcher_test/base_task_dispatcher_test.cpp index b86f345d621..10eb4715a95 100644 --- a/common/task_dispatcher/test/unittest/base_task_dispatcher_test/base_task_dispatcher_test.cpp +++ b/common/task_dispatcher/test/unittest/base_task_dispatcher_test/base_task_dispatcher_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/global_task_dispatcher_test/BUILD.gn b/common/task_dispatcher/test/unittest/global_task_dispatcher_test/BUILD.gn index fb64f1340f3..7ab2580ed98 100644 --- a/common/task_dispatcher/test/unittest/global_task_dispatcher_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/global_task_dispatcher_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/global_task_dispatcher_test/global_task_dispatcher_test.cpp b/common/task_dispatcher/test/unittest/global_task_dispatcher_test/global_task_dispatcher_test.cpp index 636b8e1059e..58c204fbd6e 100644 --- a/common/task_dispatcher/test/unittest/global_task_dispatcher_test/global_task_dispatcher_test.cpp +++ b/common/task_dispatcher/test/unittest/global_task_dispatcher_test/global_task_dispatcher_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/groupImpl_test/BUILD.gn b/common/task_dispatcher/test/unittest/groupImpl_test/BUILD.gn index 3ce7d0beb41..fd04fe6fd7c 100644 --- a/common/task_dispatcher/test/unittest/groupImpl_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/groupImpl_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/groupImpl_test/groupImpl_test.cpp b/common/task_dispatcher/test/unittest/groupImpl_test/groupImpl_test.cpp index 344cfbc9267..72f3a9228c2 100644 --- a/common/task_dispatcher/test/unittest/groupImpl_test/groupImpl_test.cpp +++ b/common/task_dispatcher/test/unittest/groupImpl_test/groupImpl_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/BUILD.gn b/common/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/BUILD.gn index 034e2735ffe..72f51bd87eb 100644 --- a/common/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/parallel_task_dispatcher_base_test.cpp b/common/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/parallel_task_dispatcher_base_test.cpp index a7e924cf023..38c25387f13 100644 --- a/common/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/parallel_task_dispatcher_base_test.cpp +++ b/common/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/parallel_task_dispatcher_base_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/parallel_task_dispatcher_test/BUILD.gn b/common/task_dispatcher/test/unittest/parallel_task_dispatcher_test/BUILD.gn index 2d806681b24..e32d1db4542 100644 --- a/common/task_dispatcher/test/unittest/parallel_task_dispatcher_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/parallel_task_dispatcher_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/parallel_task_dispatcher_test/parallel_task_dispatcher_test.cpp b/common/task_dispatcher/test/unittest/parallel_task_dispatcher_test/parallel_task_dispatcher_test.cpp index 0fa744cf871..c861e62bbbd 100644 --- a/common/task_dispatcher/test/unittest/parallel_task_dispatcher_test/parallel_task_dispatcher_test.cpp +++ b/common/task_dispatcher/test/unittest/parallel_task_dispatcher_test/parallel_task_dispatcher_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/serial_task_dispatcher_test/BUILD.gn b/common/task_dispatcher/test/unittest/serial_task_dispatcher_test/BUILD.gn index 0c5f1598c3e..70660016a4f 100644 --- a/common/task_dispatcher/test/unittest/serial_task_dispatcher_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/serial_task_dispatcher_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/spec_dispatcher_config_test/BUILD.gn b/common/task_dispatcher/test/unittest/spec_dispatcher_config_test/BUILD.gn index 44da5792008..383b08f4977 100644 --- a/common/task_dispatcher/test/unittest/spec_dispatcher_config_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/spec_dispatcher_config_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/spec_dispatcher_config_test/spec_dispatcher_config_test.cpp b/common/task_dispatcher/test/unittest/spec_dispatcher_config_test/spec_dispatcher_config_test.cpp index 0292695e797..c008fcccd14 100644 --- a/common/task_dispatcher/test/unittest/spec_dispatcher_config_test/spec_dispatcher_config_test.cpp +++ b/common/task_dispatcher/test/unittest/spec_dispatcher_config_test/spec_dispatcher_config_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/sync_task_test/BUILD.gn b/common/task_dispatcher/test/unittest/sync_task_test/BUILD.gn index c72beab2a9e..57009126a2b 100644 --- a/common/task_dispatcher/test/unittest/sync_task_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/sync_task_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/task_dispatcher_context_test/BUILD.gn b/common/task_dispatcher/test/unittest/task_dispatcher_context_test/BUILD.gn index 9118bf33c64..0c96d0037f5 100644 --- a/common/task_dispatcher/test/unittest/task_dispatcher_context_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/task_dispatcher_context_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/task_dispatcher_context_test/task_dispatcher_context_test.cpp b/common/task_dispatcher/test/unittest/task_dispatcher_context_test/task_dispatcher_context_test.cpp index ae5fd1d92be..dfca77d5fa3 100644 --- a/common/task_dispatcher/test/unittest/task_dispatcher_context_test/task_dispatcher_context_test.cpp +++ b/common/task_dispatcher/test/unittest/task_dispatcher_context_test/task_dispatcher_context_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/task_executor_test/BUILD.gn b/common/task_dispatcher/test/unittest/task_executor_test/BUILD.gn index 273b89ce879..13c94fb8a77 100644 --- a/common/task_dispatcher/test/unittest/task_executor_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/task_executor_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/task_executor_test/task_executor_test.cpp b/common/task_dispatcher/test/unittest/task_executor_test/task_executor_test.cpp index 47f70eb1da1..5069a2279ca 100644 --- a/common/task_dispatcher/test/unittest/task_executor_test/task_executor_test.cpp +++ b/common/task_dispatcher/test/unittest/task_executor_test/task_executor_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/task_handler_libevent_adapter_test/BUILD.gn b/common/task_dispatcher/test/unittest/task_handler_libevent_adapter_test/BUILD.gn index 87822b59359..ae5d9ec39d6 100644 --- a/common/task_dispatcher/test/unittest/task_handler_libevent_adapter_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/task_handler_libevent_adapter_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/task_handler_libevent_adapter_test/task_handler_libevent_adapter_test.cpp b/common/task_dispatcher/test/unittest/task_handler_libevent_adapter_test/task_handler_libevent_adapter_test.cpp index 5146ec09942..bedbc6e2b6f 100644 --- a/common/task_dispatcher/test/unittest/task_handler_libevent_adapter_test/task_handler_libevent_adapter_test.cpp +++ b/common/task_dispatcher/test/unittest/task_handler_libevent_adapter_test/task_handler_libevent_adapter_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/task_test/BUILD.gn b/common/task_dispatcher/test/unittest/task_test/BUILD.gn index 3cc8ee274b3..91a6ee6eac2 100644 --- a/common/task_dispatcher/test/unittest/task_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/task_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/task_test/task_test.cpp b/common/task_dispatcher/test/unittest/task_test/task_test.cpp index 0fa06c0642c..1fdc4299941 100644 --- a/common/task_dispatcher/test/unittest/task_test/task_test.cpp +++ b/common/task_dispatcher/test/unittest/task_test/task_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/work_thread_test/BUILD.gn b/common/task_dispatcher/test/unittest/work_thread_test/BUILD.gn index e6b418d7801..e5899e7892d 100644 --- a/common/task_dispatcher/test/unittest/work_thread_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/work_thread_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/worker_pool_test/BUILD.gn b/common/task_dispatcher/test/unittest/worker_pool_test/BUILD.gn index 0bd65420cf0..6784b7f6ded 100644 --- a/common/task_dispatcher/test/unittest/worker_pool_test/BUILD.gn +++ b/common/task_dispatcher/test/unittest/worker_pool_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/task_dispatcher/test/unittest/worker_pool_test/worker_pool_test.cpp b/common/task_dispatcher/test/unittest/worker_pool_test/worker_pool_test.cpp index 594fcb73c94..dc460e18a43 100644 --- a/common/task_dispatcher/test/unittest/worker_pool_test/worker_pool_test.cpp +++ b/common/task_dispatcher/test/unittest/worker_pool_test/worker_pool_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/test/BUILD.gn b/common/test/BUILD.gn index c2f769c0c60..a837c31baae 100644 --- a/common/test/BUILD.gn +++ b/common/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/test/moduletest/task_dispatcher/global_task_dispatcher_module_test/BUILD.gn b/common/test/moduletest/task_dispatcher/global_task_dispatcher_module_test/BUILD.gn index fd7cc87971d..86300bfbf18 100644 --- a/common/test/moduletest/task_dispatcher/global_task_dispatcher_module_test/BUILD.gn +++ b/common/test/moduletest/task_dispatcher/global_task_dispatcher_module_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/test/moduletest/task_dispatcher/parallel_task_dispatcher_module_test/BUILD.gn b/common/test/moduletest/task_dispatcher/parallel_task_dispatcher_module_test/BUILD.gn index 9796fb4748b..8d0afe32e47 100644 --- a/common/test/moduletest/task_dispatcher/parallel_task_dispatcher_module_test/BUILD.gn +++ b/common/test/moduletest/task_dispatcher/parallel_task_dispatcher_module_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/test/moduletest/task_dispatcher/parallel_task_dispatcher_module_test/parallel_task_dispatcher_module_test.cpp b/common/test/moduletest/task_dispatcher/parallel_task_dispatcher_module_test/parallel_task_dispatcher_module_test.cpp index 63a2cac60af..7dbcd3070ae 100644 --- a/common/test/moduletest/task_dispatcher/parallel_task_dispatcher_module_test/parallel_task_dispatcher_module_test.cpp +++ b/common/test/moduletest/task_dispatcher/parallel_task_dispatcher_module_test/parallel_task_dispatcher_module_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -64,7 +64,7 @@ std::shared_ptr ParallelTaskDispatcherModuleTest::Create HWTEST_F(ParallelTaskDispatcherModuleTest, ParallelTaskDispatcher_LifeCycleTest_001, TestSize.Level1) { auto name = std::string("ParallelTaskDispatcher_LifeCycleTest_001"); - GTEST_LOG_(INFO) << name + " start"; + GTEST_LOG_(INFO) << (name + " start"); std::shared_ptr ptr = CreateMtParallelTaskDispatcher(name, TaskPriority::DEFAULT); std::atomic count(0); std::shared_ptr runnable = std::make_shared([&]() { @@ -161,7 +161,7 @@ HWTEST_F(ParallelTaskDispatcherModuleTest, ParallelTaskDispatcher_AsyncDispatchT HWTEST_F(ParallelTaskDispatcherModuleTest, ParallelTaskDispatcher_AsyncGroupDispatchTest_001, TestSize.Level1) { auto name = std::string("ParallelTaskDispatcher_AsyncGroupDispatchTest_001"); - GTEST_LOG_(INFO) << name + " start"; + GTEST_LOG_(INFO) << (name + " start"); std::shared_ptr ptr = CreateMtParallelTaskDispatcher(name, TaskPriority::DEFAULT); std::atomic count(0); long sleep1 = 200; @@ -205,7 +205,7 @@ HWTEST_F(ParallelTaskDispatcherModuleTest, ParallelTaskDispatcher_AsyncGroupDisp HWTEST_F(ParallelTaskDispatcherModuleTest, ParallelTaskDispatcher_AsyncGroupDispatchTest_002, TestSize.Level1) { auto name = std::string("ParallelTaskDispatcher_AsyncGroupDispatchTest_002"); - GTEST_LOG_(INFO) << name + " start"; + GTEST_LOG_(INFO) << (name + " start"); std::shared_ptr ptr = CreateMtParallelTaskDispatcher(name, TaskPriority::DEFAULT); std::shared_ptr group = ptr->CreateDispatchGroup(); ptr->AsyncGroupDispatch(group, std::make_shared([&]() { @@ -246,7 +246,7 @@ HWTEST_F(ParallelTaskDispatcherModuleTest, ParallelTaskDispatcher_ApplyDispatchT int index = count.fetch_add(1); EXPECT_TRUE(index >= repeatCount); EXPECT_TRUE(index < repeatCount * 2); - GTEST_LOG_(INFO) << name + " repeats1"; + GTEST_LOG_(INFO) << (name + " repeats1"); }); ptr->ApplyDispatch(repeats1, repeatCount); diff --git a/common/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/BUILD.gn b/common/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/BUILD.gn index cb7313d728c..0be1fa9d00b 100644 --- a/common/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/BUILD.gn +++ b/common/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/serial_task_dispatcher_module_test.cpp b/common/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/serial_task_dispatcher_module_test.cpp index 603077fff5e..1fd76d728ad 100644 --- a/common/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/serial_task_dispatcher_module_test.cpp +++ b/common/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/serial_task_dispatcher_module_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/common/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/BUILD.gn b/common/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/BUILD.gn index 551b443ff04..1d5740c3416 100644 --- a/common/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/BUILD.gn +++ b/common/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/common/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/spec_task_dispatcher_module_test.cpp b/common/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/spec_task_dispatcher_module_test.cpp index 528c9af9cff..9de8ea35361 100644 --- a/common/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/spec_task_dispatcher_module_test.cpp +++ b/common/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/spec_task_dispatcher_module_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/frameworks/kits/ability/ability_runtime/src/ability_connection.cpp b/frameworks/kits/ability/ability_runtime/src/ability_connection.cpp index d9ca5ee0f40..81d87f96fd3 100755 --- a/frameworks/kits/ability/ability_runtime/src/ability_connection.cpp +++ b/frameworks/kits/ability/ability_runtime/src/ability_connection.cpp @@ -34,6 +34,7 @@ void AbilityConnection::OnAbilityConnectDone( HILOG_DEBUG("%{public}s begin.", __func__); if (abilityConnectCallback_ == nullptr) { HILOG_ERROR("%{public}s abilityConnectCallback is nullptr.", __func__); + return; } SetRemoteObject(remoteObject); SetResultCode(resultCode); @@ -47,6 +48,7 @@ void AbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &e HILOG_DEBUG("%{public}s begin, resultCode:%{public}d.", __func__, resultCode); if (abilityConnectCallback_ == nullptr) { HILOG_ERROR("%{public}s abilityConnectCallback is nullptr.", __func__); + return; } // if resultCode < 0 that means the connectReceiver is died if (resultCode == DIED) { diff --git a/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp b/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp index e8591266b9c..27e44039eb6 100644 --- a/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp +++ b/frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp @@ -344,7 +344,7 @@ ErrCode AbilityContextImpl::RestoreWindowStage(NativeEngine& engine, NativeValue ErrCode AbilityContextImpl::StartAbility( const AAFwk::Want& want, const std::shared_ptr &callback) { - if (!localCallContainer_) { + if (localCallContainer_ == nullptr) { localCallContainer_ = new (std::nothrow)LocalCallContainer(); } diff --git a/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.cpp b/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.cpp index 01e0d174911..89d93be8c6a 100644 --- a/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.cpp +++ b/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -158,12 +158,6 @@ bool MockServiceAbilityManagerService::IsFirstInMission(const sptr(const WantSenderInfo &wantSenderInfo, const sptr &callerToken)); MOCK_METHOD2(SendWantSender, int(const sptr &target, const SenderInfo &senderInfo)); @@ -140,12 +140,12 @@ public: MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); + MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); MOCK_METHOD2(GetWantSenderInfo, int(const sptr &target, std::shared_ptr &info)); int MoveMissionToEnd(const sptr &token, const bool nonFirst) override; bool IsFirstInMission(const sptr &token) override; - int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override; int RemoveMission(int id) override; diff --git a/frameworks/kits/ability/ability_runtime/test/moduletest/ability_caller_fw_module_test.cpp b/frameworks/kits/ability/ability_runtime/test/moduletest/ability_caller_fw_module_test.cpp index 79bf37ab2f6..ebd9437fcea 100644 --- a/frameworks/kits/ability/ability_runtime/test/moduletest/ability_caller_fw_module_test.cpp +++ b/frameworks/kits/ability/ability_runtime/test/moduletest/ability_caller_fw_module_test.cpp @@ -55,7 +55,7 @@ void AbilityCallerTest::SetUpTestCase(void) OHOS::sptr abilityObject = new (std::nothrow) MockServiceAbilityManagerService(); auto sysMgr = OHOS::DelayedSingleton::GetInstance(); - if (sysMgr == NULL) { + if (sysMgr == nullptr) { GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager"; return; } diff --git a/frameworks/kits/ability/native/BUILD.gn b/frameworks/kits/ability/native/BUILD.gn index 89547165049..6e72186b902 100644 --- a/frameworks/kits/ability/native/BUILD.gn +++ b/frameworks/kits/ability/native/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") +import("//foundation/aafwk/standard/aafwk.gni") import("//foundation/aafwk/standard/feature.gni") SUBSYSTEM_DIR = "//foundation/aafwk/standard/frameworks/kits/ability/native" INNERKITS_PATH = "//foundation/aafwk/standard/interfaces/innerkits" @@ -253,7 +254,6 @@ ohos_shared_library("abilitykit_native") { "ability_runtime:task_dispatcher", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", - "background_task_mgr:bgtaskmgr_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "bytrace_standard:bytrace_core", @@ -264,12 +264,19 @@ ohos_shared_library("abilitykit_native") { "native_appdatamgr:native_appdatafwk", "native_appdatamgr:native_dataability", "native_appdatamgr:native_rdb", + "os_account_standard:os_account_innerkits", "permission_standard:libpermissionsdk_standard", "resmgr_standard:global_resmgr", "samgr_standard:samgr_proxy", "utils_base:utils", ] + defines = [] + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ] + } + public_deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr", "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", diff --git a/frameworks/kits/ability/native/include/ability.h b/frameworks/kits/ability/native/include/ability.h index 438d85d9ab1..cf239a805da 100755 --- a/frameworks/kits/ability/native/include/ability.h +++ b/frameworks/kits/ability/native/include/ability.h @@ -45,6 +45,7 @@ #include "form_death_callback.h" #include "form_info.h" #include "form_provider_info.h" +#include "form_state_info.h" #include "foundation/multimodalinput/input/interfaces/native/innerkits/event/include/key_event.h" #include "foundation/multimodalinput/input/interfaces/native/innerkits/event/include/pointer_event.h" #endif @@ -1281,6 +1282,13 @@ public: * @param message Form event message. */ virtual void OnTriggerEvent(const int64_t formId, const std::string &message); + /** + * @brief Called to notify the form supplier to acquire form state. + * + * @param want Indicates the detailed information about the form to be obtained, including + * the bundle name, module name, ability name, form name and form dimension. + */ + virtual FormState OnAcquireFormState(const Want &want); /** * @brief Requests for form data update. * @@ -1328,6 +1336,24 @@ public: */ bool CheckFMSReady(); + /** + * @brief Delete the given invalid forms. + * + * @param formIds Indicates the ID of the forms to delete. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns true if the request is successfully initiated; returns false otherwise. + */ + ErrCode DeleteInvalidForms(const std::vector &formIds, int32_t &numFormsDeleted); + + /** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns true if the request is successfully initiated; returns false otherwise. + */ + ErrCode AcquireFormState(const Want &want, FormStateInfo &stateInfo); + /** * @brief Get All FormsInfo. * diff --git a/frameworks/kits/ability/native/include/ability_context.h b/frameworks/kits/ability/native/include/ability_context.h index c916da960fb..c305fc1d84c 100644 --- a/frameworks/kits/ability/native/include/ability_context.h +++ b/frameworks/kits/ability/native/include/ability_context.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -398,53 +398,6 @@ public: */ std::shared_ptr GetResourceManager() const override; - /** - * @brief Checks whether the current process has the given permission. - * You need to call requestPermissionsFromUser(java.lang.std::string[],int) to request a permission only - * if the current process does not have the specific permission. - * - * @param permission Indicates the permission to check. This parameter cannot be null. - * - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the current process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ - virtual int VerifySelfPermission(const std::string &permission) override; - - /** - * @brief Checks whether the calling process for inter-process communication has the given permission. - * The calling process is not the current process. - * - * @param permission Indicates the permission to check. This parameter cannot be null. - * - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the calling process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ - virtual int VerifyCallingPermission(const std::string &permission) override; - - /** - * @brief Confirms with the permission management module to check whether a request prompt is required for granting - * a certain permission. You need to call the current method to check whether a prompt is required before calling - * requestPermissionsFromUser(java.lang.String[],int) to request a permission. If a prompt is not required, - * permission request will not be initiated. - * - * @param requestCode Indicates the permission to be queried. This parameter cannot be null. - * - * @return Returns true if the current application does not have the permission and the user does not turn off - * further requests; returns false if the current application already has the permission, the permission is rejected - * by the system, or the permission is denied by the user and the user has turned off further requests. - */ - virtual bool CanRequestPermission(const std::string &permission) override; - - /** - * @brief When there is a remote call to check whether the remote has permission, otherwise check whether it has - * permission - * - * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null. - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the current process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ - virtual int VerifyCallingOrSelfPermission(const std::string &permission) override; - /** * @brief Query whether the application of the specified PID and UID has been granted a certain permission * diff --git a/frameworks/kits/ability/native/include/ability_impl.h b/frameworks/kits/ability/native/include/ability_impl.h index c994331a2a9..c870115cf24 100755 --- a/frameworks/kits/ability/native/include/ability_impl.h +++ b/frameworks/kits/ability/native/include/ability_impl.h @@ -49,17 +49,17 @@ public: std::shared_ptr &contextDeal); /** - * @brief Set if use new mission. - * - * @param useNewMission new mission flag. - */ + * @brief Set if use new mission. + * + * @param useNewMission new mission flag. + */ static void SetUseNewMission(bool useNewMission); - /** - * @brief Get if use new mission. - * - * @return return true if use new mission. - */ + /** + * @brief Get if use new mission. + * + * @return return true if use new mission. + */ static bool IsUseNewMission(); /** diff --git a/frameworks/kits/ability/native/include/form_extension.h b/frameworks/kits/ability/native/include/form_extension.h index 615f4927dac..eec5c11ee7b 100644 --- a/frameworks/kits/ability/native/include/form_extension.h +++ b/frameworks/kits/ability/native/include/form_extension.h @@ -18,6 +18,7 @@ #include "extension_base.h" #include "form_provider_info.h" +#include "form_state_info.h" namespace OHOS { namespace AbilityRuntime { @@ -128,6 +129,15 @@ public: * @return none. */ virtual void OnVisibilityChange(const std::map& formEventsMap); + + /** + * @brief Called to notify the form provider to acquire form state. + * + * @param want Indicates the detailed information about the form to be obtained, including + * the bundle name, module name, ability name, form name and form dimension. + * @return none. + */ + virtual FormState OnAcquireFormState(const Want &want); }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/kits/ability/native/include/form_provider_client.h b/frameworks/kits/ability/native/include/form_provider_client.h index baa25d0c503..07d8e39656a 100644 --- a/frameworks/kits/ability/native/include/form_provider_client.h +++ b/frameworks/kits/ability/native/include/form_provider_client.h @@ -123,6 +123,16 @@ public: const std::string &message, const Want &want, const sptr &callerToken) override; + + /** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param callerToken Form provider proxy object. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int AcquireState(const Want &wantArg, const Want &want, const sptr &callerToken) override; + /** * @brief Set the owner ability of the form provider client. * @@ -144,6 +154,8 @@ protected: int HandleDisconnect(const Want &want, const sptr &callerToken); int HandleAcquire(const FormProviderInfo &formProviderInfo, const Want &newWant, const sptr &callerToken); + int HandleAcquireStateResult(FormState state, int errorCode, const Want &want, + const sptr &callerToken); private: std::shared_ptr GetOwner(); diff --git a/frameworks/kits/ability/native/include/form_runtime/form_extension_provider_client.h b/frameworks/kits/ability/native/include/form_runtime/form_extension_provider_client.h index 2f6180a2a30..d719968b6dc 100644 --- a/frameworks/kits/ability/native/include/form_runtime/form_extension_provider_client.h +++ b/frameworks/kits/ability/native/include/form_runtime/form_extension_provider_client.h @@ -107,6 +107,15 @@ public: virtual int FireFormEvent(const int64_t formId, const std::string &message, const Want &want, const sptr &callerToken) override; + /** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param callerToken Form provider proxy object. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int AcquireState(const Want &wantArg, const Want &want, const sptr &callerToken) override; + /** * @brief Set the owner form extension of the form provider client. * @@ -141,6 +150,7 @@ private: const sptr &callerToken); void FireFormExtensionEvent(const int64_t formId, const std::string &message, const Want &want, const sptr &callerToken); + void NotifyFormExtensionAcquireState(const Want &wantArg, const Want &want, const sptr &callerToken); private: mutable std::mutex formExtensionMutex_; diff --git a/frameworks/kits/ability/native/src/ability.cpp b/frameworks/kits/ability/native/src/ability.cpp index 62cd57c035e..0179f25175e 100755 --- a/frameworks/kits/ability/native/src/ability.cpp +++ b/frameworks/kits/ability/native/src/ability.cpp @@ -23,7 +23,9 @@ #include "ability_post_event_timeout.h" #include "ability_runtime/js_ability.h" #include "abs_shared_result_set.h" +#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE #include "background_task_mgr_helper.h" +#endif #include "bytrace.h" #include "configuration_convertor.h" #include "connection_manager.h" @@ -31,7 +33,9 @@ #include "continuation_manager.h" #include "continuation_register_manager.h" #include "continuation_register_manager_proxy.h" +#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE #include "continuous_task_param.h" +#endif #include "data_ability_operation.h" #include "data_ability_predicates.h" #include "data_ability_result.h" @@ -291,12 +295,14 @@ void Ability::OnStart(const Want &want) HILOG_ERROR("%{public}s error, resConfig is nullptr.", __func__); return; } - resConfig->SetScreenDensity(ConvertDensity(density)); - resConfig->SetDirection(ConvertDirection(height, width)); auto resourceManager = GetResourceManager(); if (resourceManager != nullptr) { + resourceManager->GetResConfig(*resConfig); + resConfig->SetScreenDensity(ConvertDensity(density)); + resConfig->SetDirection(ConvertDirection(height, width)); resourceManager->UpdateResConfig(*resConfig); - HILOG_INFO("%{public}s Notify ResourceManager.", __func__); + HILOG_INFO("%{public}s Notify ResourceManager, Density: %{public}d, Direction: %{public}d.", __func__, + resConfig->GetScreenDensity(), resConfig->GetDirection()); } } } @@ -1012,8 +1018,13 @@ void Ability::OnConfigurationUpdatedNotify(const Configuration &changeConfigurat // Notify ResourceManager std::unique_ptr resConfig(Global::Resource::CreateResConfig()); - if (resConfig != nullptr) { - HILOG_INFO("make resource mgr data"); + if (resConfig == nullptr) { + HILOG_ERROR("Create res config failed."); + return; + } + auto resourceManager = GetResourceManager(); + if (resourceManager != nullptr) { + resourceManager->GetResConfig(*resConfig); #ifdef SUPPORT_GRAPHICS if (!language.empty()) { UErrorCode status = U_ZERO_ERROR; @@ -1025,13 +1036,10 @@ void Ability::OnConfigurationUpdatedNotify(const Configuration &changeConfigurat } #endif resConfig->SetColorMode(ConvertColorMode(colormode)); - - auto resourceManager = GetResourceManager(); - if (resourceManager != nullptr) { - resourceManager->UpdateResConfig(*resConfig); - HILOG_INFO("%{public}s Notify ResourceManager.", __func__); - } + resourceManager->UpdateResConfig(*resConfig); + HILOG_INFO("Notify ResourceManager, colorMode: %{public}d.", resConfig->GetColorMode()); } + #ifdef SUPPORT_GRAPHICS // Notify WindowScene if (scene_ != nullptr && !language.empty()) { @@ -2116,10 +2124,14 @@ ErrCode Ability::DeleteForm(const int64_t formId) */ int Ability::StartBackgroundRunning(const AbilityRuntime::WantAgent::WantAgent &wantAgent) { +#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE uint32_t defaultBgMode = 0; BackgroundTaskMgr::ContinuousTaskParam taskParam = BackgroundTaskMgr::ContinuousTaskParam(false, defaultBgMode, std::make_shared(wantAgent), abilityInfo_->name, GetToken()); return BackgroundTaskMgr::BackgroundTaskMgrHelper::RequestStartBackgroundRunning(taskParam); +#else + return ERR_INVALID_OPERATION; +#endif } /** @@ -2129,7 +2141,11 @@ int Ability::StartBackgroundRunning(const AbilityRuntime::WantAgent::WantAgent & */ int Ability::StopBackgroundRunning() { +#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE return BackgroundTaskMgr::BackgroundTaskMgrHelper::RequestStopBackgroundRunning(abilityInfo_->name, GetToken()); +#else + return ERR_INVALID_OPERATION; +#endif } #ifdef SUPPORT_GRAPHICS @@ -2478,6 +2494,17 @@ void Ability::OnVisibilityChanged(const std::map &formEventsMa */ void Ability::OnTriggerEvent(const int64_t formId, const std::string &message) {} + +/** + * @brief Called to notify the form supplier to acquire form state. + * + * @param want Indicates the detailed information about the form to be obtained, including + * the bundle name, module name, ability name, form name and form dimension. + */ +FormState Ability::OnAcquireFormState(const Want &want) +{ + return FormState::DEFAULT; +} /** * @brief Delete or release form with formId. * @@ -2915,6 +2942,54 @@ bool Ability::CheckFMSReady() return true; } +/** + * @brief Delete the given invalid forms. + * + * @param formIds Indicates the ID of the forms to delete. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns true if the request is successfully initiated; returns false otherwise. + */ +ErrCode Ability::DeleteInvalidForms(const std::vector &formIds, int32_t &numFormsDeleted) +{ + HILOG_INFO("%{public}s called.", __func__); + + if (FormMgr::GetRecoverStatus() == Constants::IN_RECOVERING) { + HILOG_ERROR("%{public}s error, form is in recover status, can't do action on form.", __func__); + return ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR; + } + + // DeleteInvalidForms request to fms + int resultCode = FormMgr::GetInstance().DeleteInvalidForms(formIds, FormHostClient::GetInstance(), numFormsDeleted); + if (resultCode != ERR_OK) { + HILOG_ERROR("%{public}s error, failed to DeleteInvalidForms, error code is %{public}d.", __func__, resultCode); + } + return resultCode; +} + +/** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns true if the request is successfully initiated; returns false otherwise. + */ +ErrCode Ability::AcquireFormState(const Want &want, FormStateInfo &stateInfo) +{ + HILOG_INFO("%{public}s called.", __func__); + + if (FormMgr::GetRecoverStatus() == Constants::IN_RECOVERING) { + HILOG_ERROR("%{public}s error, form is in recover status, can't do action on form.", __func__); + return ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR; + } + + // AcquireFormState request to fms + int resultCode = FormMgr::GetInstance().AcquireFormState(want, FormHostClient::GetInstance(), stateInfo); + if (resultCode != ERR_OK) { + HILOG_ERROR("%{public}s error, failed to AcquireFormState, error code is %{public}d.", __func__, resultCode); + } + return resultCode; +} + /** * @brief Get All FormsInfo. * @@ -3235,7 +3310,9 @@ std::shared_ptr Ability::ParsePredictionArgsRe HILOG_INFO("Ability::ParsePredictionArgsReference push_back done"); } - predicates->SetWhereArgs(strPredicatesList); + if (predicates) { + predicates->SetWhereArgs(strPredicatesList); + } return predicates; } @@ -3523,13 +3600,14 @@ void Ability::OnChange(Rosen::DisplayId displayId) int32_t height = display->GetHeight(); std::unique_ptr resConfig(Global::Resource::CreateResConfig()); if (resConfig != nullptr) { - resConfig->SetScreenDensity(ConvertDensity(density)); - resConfig->SetDirection(ConvertDirection(height, width)); - auto resourceManager = GetResourceManager(); if (resourceManager != nullptr) { + resourceManager->GetResConfig(*resConfig); + resConfig->SetScreenDensity(ConvertDensity(density)); + resConfig->SetDirection(ConvertDirection(height, width)); resourceManager->UpdateResConfig(*resConfig); - HILOG_INFO("%{public}s Notify ResourceManager.", __func__); + HILOG_INFO("%{public}s Notify ResourceManager, Density: %{public}d, Direction: %{public}d.", __func__, + resConfig->GetScreenDensity(), resConfig->GetDirection()); } } @@ -3570,6 +3648,19 @@ void Ability::OnDisplayMove(Rosen::DisplayId from, Rosen::DisplayId to) float density = display->GetVirtualPixelRatio(); int32_t width = display->GetWidth(); int32_t height = display->GetHeight(); + std::unique_ptr resConfig(Global::Resource::CreateResConfig()); + if (resConfig != nullptr) { + auto resourceManager = GetResourceManager(); + if (resourceManager != nullptr) { + resourceManager->GetResConfig(*resConfig); + resConfig->SetScreenDensity(ConvertDensity(density)); + resConfig->SetDirection(ConvertDirection(height, width)); + resourceManager->UpdateResConfig(*resConfig); + HILOG_INFO("%{public}s Notify ResourceManager, Density: %{public}d, Direction: %{public}d.", __func__, + resConfig->GetScreenDensity(), resConfig->GetDirection()); + } + } + Configuration newConfig; newConfig.AddItem(ConfigurationInner::APPLICATION_DISPLAYID, std::to_string(to)); newConfig.AddItem(to, ConfigurationInner::APPLICATION_DIRECTION, GetDirectionStr(height, width)); diff --git a/frameworks/kits/ability/native/src/ability_context.cpp b/frameworks/kits/ability/native/src/ability_context.cpp index c0295104cce..0dd3ac43101 100644 --- a/frameworks/kits/ability/native/src/ability_context.cpp +++ b/frameworks/kits/ability/native/src/ability_context.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -16,9 +16,11 @@ #include "ability_context.h" #include "ability_manager_client.h" +#include "accesstoken_kit.h" #include "bundle_constants.h" #include "hilog_wrapper.h" #include "iservice_registry.h" +#include "os_account_manager.h" #include "resource_manager.h" #include "sys_mgr_client.h" #include "system_ability_definition.h" @@ -349,92 +351,6 @@ std::shared_ptr AbilityContext::GetResourceMa return resourceManager; } -int AbilityContext::VerifySelfPermission(const std::string &permission) -{ - HILOG_INFO("%{public}s begin. permission=%{public}s", __func__, permission.c_str()); - if (permission.empty()) { - HILOG_ERROR("VerifySelfPermission permission invalid"); - return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; - } - - std::string bundle_name = GetBundleName(); - if (bundle_name.empty()) { - HILOG_ERROR("VerifySelfPermission failed to get bundle name error"); - return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; - } - - sptr ptr = GetBundleManager(); - if (ptr == nullptr) { - HILOG_ERROR("VerifySelfPermission failed to get bundle manager service"); - return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; - } - - HILOG_INFO("%{public}s start bms->CheckPermission. bundle_name=%{public}s", __func__, bundle_name.c_str()); - int ret = ptr->CheckPermission(bundle_name, permission); - HILOG_INFO("%{public}s end bms->CheckPermission, ret=%{public}d", __func__, ret); - HILOG_INFO("%{public}s end.", __func__); - return ret; -} - -int AbilityContext::VerifyCallingPermission(const std::string &permission) -{ - HILOG_INFO("%{public}s begin. permission=%{public}s", __func__, permission.c_str()); - if (permission.empty()) { - HILOG_ERROR("VerifyCallingPermission permission invalid"); - return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; - } - - std::string bundle_name = GetCallingBundle(); - if (bundle_name.empty()) { - HILOG_ERROR("VerifyCallingPermission failed to get bundle name by uid"); - return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; - } - - sptr ptr = GetBundleManager(); - if (ptr == nullptr) { - HILOG_ERROR("VerifyCallingPermission failed to get bundle manager service"); - return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; - } - - HILOG_INFO("%{public}s start bms->CheckPermission. bundle_name=%{public}s", __func__, bundle_name.c_str()); - int ret = ptr->CheckPermission(bundle_name, permission); - HILOG_INFO("%{public}s end bms->CheckPermission, ret=%{public}d", __func__, ret); - HILOG_INFO("%{public}s end.", __func__); - return ret; -} - -bool AbilityContext::CanRequestPermission(const std::string &permission) -{ - HILOG_INFO("%{public}s begin. permission=%{public}s", __func__, permission.c_str()); - if (permission.empty()) { - HILOG_ERROR("CanRequestPermission permission invalid"); - return true; - } - - std::string bundle_name = GetBundleName(); - if (bundle_name.empty()) { - HILOG_ERROR("CanRequestPermission failed to get bundle name error"); - return true; - } - - sptr ptr = GetBundleManager(); - if (ptr == nullptr) { - HILOG_ERROR("CanRequestPermission failed to get bundle manager service"); - return true; - } - - HILOG_INFO("%{public}s start bms->CanRequestPermission. bundle_name=%{public}s", __func__, bundle_name.c_str()); - bool ret = ptr->CanRequestPermission(bundle_name, permission, 0); - HILOG_INFO("%{public}s end bms->CanRequestPermission, ret=%{public}s", __func__, ret ? "true" : "false"); - HILOG_INFO("%{public}s end.", __func__); - return ret; -} - -int AbilityContext::VerifyCallingOrSelfPermission(const std::string &permission) -{ - return VerifySelfPermission(permission); -} - int AbilityContext::VerifyPermission(const std::string &permission, int pid, int uid) { HILOG_INFO("%{public}s begin. permission=%{public}s, pid=%{public}d, uid=%{public}d", @@ -459,27 +375,36 @@ int AbilityContext::VerifyPermission(const std::string &permission, int pid, int return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; } - HILOG_INFO("%{public}s start bms->CheckPermission. bundle_name=%{public}s", __func__, bundle_name.c_str()); - int ret = ptr->CheckPermission(bundle_name, permission); - HILOG_INFO("%{public}s end bms->CheckPermission, ret=%{public}d", __func__, ret); - HILOG_INFO("%{public}s end.", __func__); - return ret; + int account = -1; + if (AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, account) != 0) { + HILOG_ERROR("VerifyPermission failed to get account by uid"); + return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; + } + + AppExecFwk::ApplicationInfo appInfo; + if (!ptr->GetApplicationInfo(bundle_name, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, account, appInfo)) { + HILOG_ERROR("VerifyPermission failed to get application info"); + return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; + } + + int32_t ret = Security::AccessToken::AccessTokenKit::VerifyAccessToken(appInfo.accessTokenId, permission); + if (ret == Security::AccessToken::PermissionState::PERMISSION_DENIED) { + HILOG_ERROR("VerifyPermission %{public}d: PERMISSION_DENIED", appInfo.accessTokenId); + return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; + } + + return 0; } void AbilityContext::GetPermissionDes(const std::string &permissionName, std::string &des) { - sptr ptr = GetBundleManager(); - if (ptr == nullptr) { - HILOG_ERROR("GetPermissionDes failed to get bundle manager service"); - return; - } - - PermissionDef permissionDef; - HILOG_INFO("%{public}s start bms->GetPermissionDef. permissionName=%{public}s", __func__, permissionName.c_str()); - if (ptr->GetPermissionDef(permissionName, permissionDef)) { + Security::AccessToken::PermissionDef permissionDef; + int32_t ret = Security::AccessToken::AccessTokenKit::GetDefPermission(permissionName, permissionDef); + if (ret == Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) { + HILOG_DEBUG("GetPermissionDes %{public}s: RET_SUCCESS", permissionName.c_str()); des = permissionDef.description; } - HILOG_INFO("%{public}s end bms->GetPermissionDef.", __func__); + HILOG_DEBUG("%{public}s end GetPermissionDef.", __func__); } void AbilityContext::RequestPermissionsFromUser(std::vector &permissions, int requestCode) diff --git a/frameworks/kits/ability/native/src/ability_window.cpp b/frameworks/kits/ability/native/src/ability_window.cpp index 722ecce9d0d..6040330a5f0 100644 --- a/frameworks/kits/ability/native/src/ability_window.cpp +++ b/frameworks/kits/ability/native/src/ability_window.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -195,7 +195,7 @@ void AbilityWindow::OnPostAbilityStop() if (windowScene_) { windowScene_ = nullptr; - HILOG_INFO("AbilityWindow::widow windowScene_ release end."); + HILOG_INFO("AbilityWindow::window windowScene_ release end."); } isWindowAttached = false; diff --git a/frameworks/kits/ability/native/src/continuation/distributed/reverse_continuation_scheduler_replica_stub.cpp b/frameworks/kits/ability/native/src/continuation/distributed/reverse_continuation_scheduler_replica_stub.cpp index 63a3a10f0e6..db6e9504bc2 100644 --- a/frameworks/kits/ability/native/src/continuation/distributed/reverse_continuation_scheduler_replica_stub.cpp +++ b/frameworks/kits/ability/native/src/continuation/distributed/reverse_continuation_scheduler_replica_stub.cpp @@ -58,7 +58,7 @@ int32_t ReverseContinuationSchedulerReplicaStub::NotifyReverseResultInner(Messag int ReverseContinuationSchedulerReplicaStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("%{public}s called begin, code = %{public}d, flags= %{public}d.", __func__, code, option.GetFlags()); + HILOG_INFO("%{public}s called begin, code = %{public}u, flags= %{public}d.", __func__, code, option.GetFlags()); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (remoteDescriptor != ReverseContinuationSchedulerReplicaStub::GetDescriptor()) { HILOG_ERROR("ReverseContinuationSchedulerReplicaStub::OnRemoteRequest token is invalid"); diff --git a/frameworks/kits/ability/native/src/data_ability_helper.cpp b/frameworks/kits/ability/native/src/data_ability_helper.cpp index 4a516be3cea..571894a5a7d 100644 --- a/frameworks/kits/ability/native/src/data_ability_helper.cpp +++ b/frameworks/kits/ability/native/src/data_ability_helper.cpp @@ -250,8 +250,7 @@ std::shared_ptr DataAbilityHelper::Creator( if (uri->GetScheme() != SchemeOhos) { HILOG_ERROR("DataAbilityHelper::Creator (context, uri, tryBind) failed, the Scheme is not dataability, Scheme: " - "%{public}s", - uri->GetScheme().c_str()); + "%{public}s", uri->GetScheme().c_str()); return nullptr; } @@ -855,25 +854,31 @@ bool DataAbilityHelper::CheckUriParam(const Uri &uri) return false; } - auto uriSp = uri_; // do not directly use uri_ here, otherwise, it will crash. - if (uriSp != nullptr) { - if (!CheckOhosUri(*uriSp)) { - HILOG_ERROR("DataAbilityHelper::CheckUriParam failed. CheckOhosUri uriSp failed"); + // do not directly use uri_ here, otherwise, it will probably crash. + std::vector segments; + { + std::lock_guard guard(lock_); + if (!uri_) { + HILOG_INFO("DataAbilityHelper::CheckUriParam uri_ is nullptr, no need check"); + return true; + } + + if (!CheckOhosUri(*uri_)) { + HILOG_ERROR("DataAbilityHelper::CheckUriParam failed. CheckOhosUri uri_ failed"); return false; } - std::vector checkSegments; - checkUri.GetPathSegments(checkSegments); + uri_->GetPathSegments(segments); + } - std::vector segments; - uriSp->GetPathSegments(segments); + std::vector checkSegments; + checkUri.GetPathSegments(checkSegments); - if (checkSegments.empty() || segments.empty() || checkSegments[0] != segments[0]) { - HILOG_ERROR( - "DataAbilityHelper::CheckUriParam failed. the dataability in uri doesn't equal the one in uriSp."); - return false; - } + if (checkSegments.empty() || segments.empty() || checkSegments[0] != segments[0]) { + HILOG_ERROR("DataAbilityHelper::CheckUriParam failed. dataability in uri doesn't equal the one in uri_."); + return false; } + HILOG_INFO("DataAbilityHelper::CheckUriParam end."); return true; } diff --git a/frameworks/kits/ability/native/src/data_ability_operation.cpp b/frameworks/kits/ability/native/src/data_ability_operation.cpp index 13d8f44d518..8f67c0c7dd5 100644 --- a/frameworks/kits/ability/native/src/data_ability_operation.cpp +++ b/frameworks/kits/ability/native/src/data_ability_operation.cpp @@ -374,7 +374,7 @@ DataAbilityOperation *DataAbilityOperation::Unmarshalling(Parcel &in) HILOG_DEBUG("DataAbilityOperation::Unmarshalling start"); DataAbilityOperation *dataAbilityOperation = new (std::nothrow) DataAbilityOperation(); if (dataAbilityOperation != nullptr && !dataAbilityOperation->ReadFromParcel(in)) { - HILOG_ERROR("DataAbilityOperation::Unmarshalling dataAbilityOperation(%p) error", dataAbilityOperation); + HILOG_ERROR("DataAbilityOperation::Unmarshalling dataAbilityOperation error"); delete dataAbilityOperation; dataAbilityOperation = nullptr; } diff --git a/frameworks/kits/ability/native/src/form_extension.cpp b/frameworks/kits/ability/native/src/form_extension.cpp index 4761f4e06d8..f32d5798a28 100644 --- a/frameworks/kits/ability/native/src/form_extension.cpp +++ b/frameworks/kits/ability/native/src/form_extension.cpp @@ -94,5 +94,11 @@ void FormExtension::OnVisibilityChange(const std::map& formEve { HILOG_INFO("%{public}s called.", __func__); } + +FormState FormExtension::OnAcquireFormState(const Want &want) +{ + HILOG_INFO("%{public}s called.", __func__); + return FormState::DEFAULT; +} } } \ No newline at end of file diff --git a/frameworks/kits/ability/native/src/form_provider_client.cpp b/frameworks/kits/ability/native/src/form_provider_client.cpp index b2e433148a8..37aa2957c62 100755 --- a/frameworks/kits/ability/native/src/form_provider_client.cpp +++ b/frameworks/kits/ability/native/src/form_provider_client.cpp @@ -368,6 +368,41 @@ int FormProviderClient::FireFormEvent( return disconnectErrorCode; } } + +/** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param callerToken Form provider proxy object. + * @return Returns ERR_OK on success, others on failure. + */ +int FormProviderClient::AcquireState(const Want &wantArg, const Want &want, const sptr &callerToken) +{ + HILOG_INFO("%{public}s called.", __func__); + // The error code for business operation. + int errorCode = ERR_OK; + FormState state = FormState::UNKNOWN; + do { + std::shared_ptr ownerAbility = GetOwner(); + if (ownerAbility == nullptr) { + HILOG_ERROR("%{public}s error, ownerAbility is nullptr.", __func__); + errorCode = ERR_APPEXECFWK_FORM_NO_SUCH_ABILITY; + break; + } + if (!CheckIsSystemApp()) { + HILOG_ERROR("%{public}s caller permission denied", __func__); + errorCode = ERR_APPEXECFWK_FORM_PERMISSION_DENY; + break; + } + + HILOG_INFO("%{public}s come, %{public}s", __func__, ownerAbility->GetAbilityName().c_str()); + state = ownerAbility->OnAcquireFormState(wantArg); + } while (false); + + HandleAcquireStateResult(state, errorCode, want, callerToken); + return errorCode; +} + /** * @brief Set the owner ability of the form provider client. * @@ -466,5 +501,20 @@ int FormProviderClient::HandleDisconnect(const Want &want, const sptrOnEventHandle(want); return ERR_OK; } + +int FormProviderClient::HandleAcquireStateResult(FormState state, int errorCode, const Want &want, + const sptr &callerToken) +{ + HILOG_INFO("%{public}s start, form state is %{public}d", __func__, state); + + sptr formSupplyClient = iface_cast(callerToken); + if (formSupplyClient == nullptr) { + HILOG_ERROR("%{public}s warn, IFormSupply is nullptr", __func__); + return ERR_APPEXECFWK_FORM_BIND_PROVIDER_FAILED; + } + formSupplyClient->OnAcquireStateResult(state, want); + HILOG_INFO("%{public}s end", __func__); + return errorCode; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/kits/ability/native/src/form_runtime/form_extension_provider_client.cpp b/frameworks/kits/ability/native/src/form_runtime/form_extension_provider_client.cpp index 9f6333788c3..35ac48f1bdc 100644 --- a/frameworks/kits/ability/native/src/form_runtime/form_extension_provider_client.cpp +++ b/frameworks/kits/ability/native/src/form_runtime/form_extension_provider_client.cpp @@ -378,6 +378,49 @@ void FormExtensionProviderClient::FireFormExtensionEvent(const int64_t formId, c HILOG_INFO("%{public}s called end.", __func__); } +/** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param callerToken Form provider proxy object. + * @return Returns ERR_OK on success, others on failure. + */ +int FormExtensionProviderClient::AcquireState(const Want &wantArg, const Want &want, + const sptr &callerToken) +{ + HILOG_INFO("%{public}s called.", __func__); + std::pair errorCode = CheckParam(want, callerToken); + if (errorCode.first != ERR_OK) { + HILOG_ERROR("%{public}s CheckParam failed", __func__); + return errorCode.second; + } + + std::shared_ptr mainHandler = std::make_shared(EventRunner::GetMainEventRunner()); + std::function notifyFormExtensionAcquireStateFunc = [client = sptr(this), + wantArg, want, callerToken]() { + client->NotifyFormExtensionAcquireState(wantArg, want, callerToken); + }; + mainHandler->PostSyncTask(notifyFormExtensionAcquireStateFunc); + return ERR_OK; +} + +void FormExtensionProviderClient::NotifyFormExtensionAcquireState(const Want &wantArg, const Want &want, + const sptr &callerToken) +{ + HILOG_INFO("%{public}s called.", __func__); + int errorCode = ERR_OK; + FormState state = FormState::UNKNOWN; + std::shared_ptr ownerFormExtension = GetOwner(); + if (ownerFormExtension == nullptr) { + HILOG_ERROR("%{public}s error, ownerFormExtension is nullptr.", __func__); + errorCode = ERR_APPEXECFWK_FORM_NO_SUCH_ABILITY; + } else { + state = ownerFormExtension->OnAcquireFormState(wantArg); + } + HandleAcquireStateResult(state, errorCode, want, callerToken); + HILOG_INFO("%{public}s called end.", __func__); +} + /** * @brief Set the owner form extension of the form provider client. * diff --git a/frameworks/kits/ability/native/src/form_runtime/js_form_extension_context.cpp b/frameworks/kits/ability/native/src/form_runtime/js_form_extension_context.cpp index 28cd18d18b9..1b14d3818cb 100644 --- a/frameworks/kits/ability/native/src/form_runtime/js_form_extension_context.cpp +++ b/frameworks/kits/ability/native/src/form_runtime/js_form_extension_context.cpp @@ -116,7 +116,7 @@ private: }; NativeValue* lastParam = - (info.argc == UPDATE_FORM_PARAMS_SIZE) ? nullptr : info.argv[UPDATE_FORM_PARAMS_SIZE]; + (info.argc == UPDATE_FORM_PARAMS_SIZE) ? nullptr : info.argv[UPDATE_FORM_PARAMS_SIZE - 1]; NativeValue* result = nullptr; AsyncTask::Schedule( engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); diff --git a/frameworks/kits/ability/native/src/js_datashare_ext_ability.cpp b/frameworks/kits/ability/native/src/js_datashare_ext_ability.cpp index cd75d025206..abca98562d5 100644 --- a/frameworks/kits/ability/native/src/js_datashare_ext_ability.cpp +++ b/frameworks/kits/ability/native/src/js_datashare_ext_ability.cpp @@ -452,6 +452,7 @@ std::shared_ptr JsDataShareExtAbility::Query(cons HILOG_INFO("%{public}s begin.", __func__); std::shared_ptr ret; if (!CheckCallingPermission(abilityInfo_->readPermission)) { + HILOG_ERROR("%{public}s Check calling permission failed.", __func__); return ret; } diff --git a/frameworks/kits/ability/native/src/new_ability_impl.cpp b/frameworks/kits/ability/native/src/new_ability_impl.cpp index a890ba24e62..b7fa9fd453d 100644 --- a/frameworks/kits/ability/native/src/new_ability_impl.cpp +++ b/frameworks/kits/ability/native/src/new_ability_impl.cpp @@ -46,7 +46,7 @@ void NewAbilityImpl::HandleAbilityTransaction(const Want &want, const AAFwk::Lif #endif SetLifeCycleStateInfo(targetState); - if (lifecycleState_ == AAFwk::ABILITY_STATE_INITIAL) { + if (ability_ && lifecycleState_ == AAFwk::ABILITY_STATE_INITIAL) { ability_->SetStartAbilitySetting(targetState.setting); ability_->SetLaunchParam(targetState.launchParam); Start(want); diff --git a/frameworks/kits/ability/native/src/page_ability_impl.cpp b/frameworks/kits/ability/native/src/page_ability_impl.cpp index 594c105c238..c2622d6689d 100644 --- a/frameworks/kits/ability/native/src/page_ability_impl.cpp +++ b/frameworks/kits/ability/native/src/page_ability_impl.cpp @@ -45,7 +45,7 @@ void PageAbilityImpl::HandleAbilityTransaction(const Want &want, const AAFwk::Li SetLifeCycleStateInfo(targetState); - if (lifecycleState_ == AAFwk::ABILITY_STATE_INITIAL) { + if (ability_ && lifecycleState_ == AAFwk::ABILITY_STATE_INITIAL) { ability_->SetStartAbilitySetting(targetState.setting); Start(want); CheckAndRestore(); diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.cpp b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.cpp index afac3de2feb..d40a91e86cd 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.cpp +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -26,9 +26,7 @@ using OHOS::AppExecFwk::ElementName; namespace OHOS { namespace AAFwk { MockAbilityManagerService::MockAbilityManagerService() : abilityScheduler_(nullptr) -{ - abilityScheduler_ = nullptr; -} +{} MockAbilityManagerService::~MockAbilityManagerService() {} @@ -173,7 +171,7 @@ int MockAbilityManagerService::KillProcess(const std::string &bundleName) return 0; } -int MockAbilityManagerService::UninstallApp(const std::string &bundleName) +int MockAbilityManagerService::UninstallApp(const std::string &bundleName, int32_t uid) { return 0; } @@ -188,12 +186,6 @@ bool MockAbilityManagerService::IsFirstInMission(const sptr &toke return true; } -int MockAbilityManagerService::CompelVerifyPermission( - const std::string &permission, int pid, int uid, std::string &message) -{ - return 0; -} - int MockAbilityManagerService::PowerOff() { return 0; diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h index 21f571f8d06..b52b1b1867e 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -160,6 +160,7 @@ public: MOCK_METHOD2(SetMissionLabel, int(const sptr &token, const std::string &label)); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); + MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector &info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector &info)); @@ -198,7 +199,7 @@ public: int KillProcess(const std::string &bundleName) override; - int UninstallApp(const std::string &bundleName) override; + int UninstallApp(const std::string &bundleName, int32_t uid) override; int TerminateAbilityByCaller(const sptr &callerToken, int requestCode) override { @@ -209,8 +210,6 @@ public: virtual bool IsFirstInMission(const sptr &token); - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message); - virtual int SetShowOnLockScreen(bool isAllow) override { return 0; diff --git a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager_form.h b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager_form.h index 340a7b37c24..f54074c1d9a 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager_form.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager_form.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -241,10 +241,6 @@ public: MOCK_METHOD2(GetBundlesForUid, bool(const int uid, std::vector &)); MOCK_METHOD1(IsAbilityEnabled, bool(const AbilityInfo &)); MOCK_METHOD2(GetAbilityIcon, std::string(const std::string &bundleName, const std::string &className)); - MOCK_METHOD1(RegisterAllPermissionsChanged, bool(const sptr &callback)); - MOCK_METHOD2(RegisterPermissionsChanged, - bool(const std::vector &uids, const sptr &callback)); - MOCK_METHOD1(UnregisterPermissionsChanged, bool(const sptr &callback)); bool QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo) override; bool QueryAbilityInfoByUri(const std::string &uri, AbilityInfo &abilityInfo) override; @@ -287,7 +283,7 @@ public: { return ""; }; - // obtains information about an application bundle contained in a ohos Ability Package (HAP). + // obtains information about an application bundle contained in an ohos Ability Package (HAP). virtual bool GetBundleArchiveInfo( const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) override { diff --git a/frameworks/kits/ability/native/test/mock/include/mock_form_supply_callback.cpp b/frameworks/kits/ability/native/test/mock/include/mock_form_supply_callback.cpp index a3df27f2461..eb5fd927fc0 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_form_supply_callback.cpp +++ b/frameworks/kits/ability/native/test/mock/include/mock_form_supply_callback.cpp @@ -55,5 +55,17 @@ int MockFormSupplyCallback::OnEventHandle(const Want& want) HILOG_INFO("MockFormSupplyCallback::OnEventHandle called."); return 1; } + +/** + * OnAcquireStateResult + * + * @param state Form state + * @param want input data + */ +int MockFormSupplyCallback::OnAcquireStateResult(FormState state, const Want &want) +{ + HILOG_INFO("MockFormSupplyCallback::OnAcquireStateResult called."); + return 1; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/kits/ability/native/test/mock/include/mock_form_supply_callback.h b/frameworks/kits/ability/native/test/mock/include/mock_form_supply_callback.h index d21007196b3..0449c271a12 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_form_supply_callback.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_form_supply_callback.h @@ -45,6 +45,14 @@ public: */ virtual int OnEventHandle(const Want& want) override; + /** + * OnAcquireStateResult + * + * @param state Form state + * @param want input data + */ + virtual int OnAcquireStateResult(FormState state, const Want &want) override; + private: static std::mutex mutex; static sptr instance; diff --git a/frameworks/kits/ability/native/test/unittest/ability_context_test.cpp b/frameworks/kits/ability/native/test/unittest/ability_context_test.cpp index c705e2aa06c..6eba768327b 100644 --- a/frameworks/kits/ability/native/test/unittest/ability_context_test.cpp +++ b/frameworks/kits/ability/native/test/unittest/ability_context_test.cpp @@ -59,7 +59,7 @@ void AbilityContextTest::SetUpTestCase(void) GTEST_LOG_(INFO) << "AppExecFwk_AbilityContext_SetUpTestCase abilityObject->" << abilityObject.GetRefPtr(); auto sysMgr = OHOS::DelayedSingleton::GetInstance(); - if (sysMgr == NULL) { + if (sysMgr == nullptr) { GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager"; return; } diff --git a/frameworks/kits/ability/native/test/unittest/ability_permission_test.cpp b/frameworks/kits/ability/native/test/unittest/ability_permission_test.cpp index 06f9bd1c321..d79244ecffa 100644 --- a/frameworks/kits/ability/native/test/unittest/ability_permission_test.cpp +++ b/frameworks/kits/ability/native/test/unittest/ability_permission_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -51,7 +51,7 @@ void AbilityPermissionTest::SetUpTestCase(void) auto sysMgr = OHOS::DelayedSingleton::GetInstance(); - if (sysMgr == NULL) { + if (sysMgr == nullptr) { GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager"; return; } @@ -95,32 +95,6 @@ HWTEST_F(AbilityPermissionTest, AaFwk_AbilityPermissionTest_VerifySelfPermission context_->VerifySelfPermission(permission_name); } -/** - * @tc.number: AaFwk_AbilityPermissionTest_VerifyCallingOrSelfPermission_0100 - * @tc.name: VerifyCallingOrSelfPermission - * @tc.desc: Verify that the VerifyCallingOrSelfPermission return value is correct. - */ -HWTEST_F(AbilityPermissionTest, AaFwk_AbilityPermissionTest_VerifyCallingOrSelfPermission_0100, - Function | MediumTest | Level1) -{ - if (context_ == nullptr) { - EXPECT_EQ(true, context_ != nullptr); - return; - } - - std::string permission_name("permission_VerifyCallingOrSelfPermission"); - std::shared_ptr appInfo = std::make_shared(); - std::string name = "hello"; - appInfo->bundleName = name; - - std::shared_ptr deal = std::make_shared(); - deal->SetApplicationInfo(appInfo); - - context_->AttachBaseContext(deal); - - context_->VerifyCallingOrSelfPermission(permission_name); -} - /** * @tc.number: AaFwk_AbilityPermissionTest_VerifyPermission_0100 * @tc.name: VerifyPermission @@ -146,30 +120,6 @@ HWTEST_F(AbilityPermissionTest, AaFwk_AbilityPermissionTest_VerifyPermission_010 context_->VerifyPermission(permission_name, 0, 10); } -/** - * @tc.number: AaFwk_AbilityPermissionTest_CanRequestPermission_0100 - * @tc.name: CanRequestPermission - * @tc.desc: Verify that the CanRequestPermission return value is correct. - */ -HWTEST_F(AbilityPermissionTest, AaFwk_AbilityPermissionTest_CanRequestPermission_0100, Function | MediumTest | Level1) -{ - if (context_ == nullptr) { - EXPECT_EQ(true, context_ != nullptr); - return; - } - - std::string permission_name("permission_CanRequestPermission"); - std::shared_ptr appInfo = std::make_shared(); - std::string name = "hello"; - appInfo->bundleName = name; - - std::shared_ptr deal = std::make_shared(); - deal->SetApplicationInfo(appInfo); - - context_->AttachBaseContext(deal); - context_->CanRequestPermission(permission_name); -} - /** * @tc.number: AaFwk_AbilityPermissionTest_RequestPermissionsFromUser_0100 * @tc.name: RequestPermissionsFromUser diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h index cd500e65f76..de671bcbcc1 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h @@ -30,6 +30,7 @@ #include "ability_lifecycle_executor.h" #include "ability_runtime/context/context.h" +#include "want.h" namespace OHOS { namespace AppExecFwk { @@ -65,10 +66,12 @@ public: void Prepare(); void OnRun(); + ErrCode StartAbility(const AAFwk::Want &want); + bool DoAbilityForeground(const sptr &token); bool DoAbilityBackground(const sptr &token); - std::unique_ptr ExecuteShellCommand(const std::string &cmd, const int64_t timeoutMs); + std::unique_ptr ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec); void Print(const std::string &msg); diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h index 8544f749a71..443ccedc640 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h @@ -26,6 +26,8 @@ namespace AppExecFwk { class AbilityDelegatorArgs { public: static const std::string KEY_TEST_BUNDLE_NAME; + static const std::string KEY_TEST_PACKAGE_NAME; + static const std::string KEY_TEST_MODULE_NAME; static const std::string KEY_TEST_RUNNER_CLASS; static const std::string KEY_TEST_CASE; static const std::string KEY_TEST_WAIT_TIMEOUT; @@ -39,12 +41,17 @@ public: void SetTestBundleName(const std::string &bundleName); std::string GetTestBundleName() const; + std::string GetTestPackageName() const; + std::string GetTestModuleName() const; std::string GetTestRunnerClassName() const; std::string GetTestCaseName() const; void SetTestParam(const std::map ¶ms); std::map GetTestParam() const; +private: + std::string GetParamValue(const std::string &key) const; + private: std::string bundleName_; std::map params_; diff --git a/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h b/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h index 337ab360567..c064f89d9f9 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h @@ -35,8 +35,8 @@ public: virtual bool Match(const std::shared_ptr &ability, bool isNotify = false); - virtual std::shared_ptr waitForAbility(); - virtual std::shared_ptr waitForAbility(const int64_t timeoutMs); + virtual std::shared_ptr WaitForAbility(); + virtual std::shared_ptr WaitForAbility(const int64_t timeoutMs); virtual void OnAbilityStart(); virtual void OnAbilityForeground(); diff --git a/frameworks/kits/appkit/native/ability_delegator/include/runner_runtime/js_test_runner.h b/frameworks/kits/appkit/native/ability_delegator/include/runner_runtime/js_test_runner.h index 9fed6bd1446..fbacead0c97 100755 --- a/frameworks/kits/appkit/native/ability_delegator/include/runner_runtime/js_test_runner.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/runner_runtime/js_test_runner.h @@ -48,6 +48,7 @@ private: JsRuntime &jsRuntime_; std::unique_ptr jsTestRunnerObj_; + std::string srcPath_; }; } // namespace RunnerRuntime } // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp index 4412ac8c882..4c3f48b2f33 100644 --- a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp +++ b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp @@ -83,7 +83,7 @@ sptr AbilityDelegator::WaitAbilityMonitor(const std::shared_ptrwaitForAbility(); + auto obtainedAbility = monitor->WaitForAbility(); if (!obtainedAbility) { HILOG_WARN("Invalid obtained ability"); return {}; @@ -102,7 +102,7 @@ sptr AbilityDelegator::WaitAbilityMonitor( AddAbilityMonitor(monitor); - auto obtainedAbility = monitor->waitForAbility(timeoutMs); + auto obtainedAbility = monitor->WaitForAbility(timeoutMs); if (!obtainedAbility) { HILOG_WARN("Invalid obtained ability"); return {}; @@ -187,8 +187,17 @@ void AbilityDelegator::OnRun() HILOG_INFO("Run finished"); } +ErrCode AbilityDelegator::StartAbility(const AAFwk::Want &want) +{ + HILOG_INFO("Enter"); + + return AbilityManagerClient::GetInstance()->StartAbility(want); +} + bool AbilityDelegator::DoAbilityForeground(const sptr &token) { + HILOG_INFO("Enter"); + if (!token) { HILOG_WARN("Invalid input parameter"); return false; @@ -205,6 +214,8 @@ bool AbilityDelegator::DoAbilityForeground(const sptr &token) bool AbilityDelegator::DoAbilityBackground(const sptr &token) { + HILOG_INFO("Enter"); + if (!token) { HILOG_WARN("Invalid input parameter"); return false; @@ -219,9 +230,9 @@ bool AbilityDelegator::DoAbilityBackground(const sptr &token) return true; } -std::unique_ptr AbilityDelegator::ExecuteShellCommand(const std::string &cmd, const int64_t timeoutMs) +std::unique_ptr AbilityDelegator::ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec) { - HILOG_INFO("command : %{public}s, timeout : %{public}" PRId64, cmd.data(), timeoutMs); + HILOG_INFO("command : %{public}s, timeout : %{public}" PRId64, cmd.data(), timeoutSec); if (cmd.empty()) { HILOG_ERROR("Invalid cmd"); @@ -234,7 +245,7 @@ std::unique_ptr AbilityDelegator::ExecuteShellCommand(const std: return {}; } - auto result = testObserver->ExecuteShellCommand(cmd, timeoutMs); + auto result = testObserver->ExecuteShellCommand(cmd, timeoutSec); return std::make_unique(result); } @@ -252,6 +263,8 @@ void AbilityDelegator::Print(const std::string &msg) void AbilityDelegator::PostPerformStart(const std::shared_ptr &ability) { + HILOG_INFO("Enter"); + if (!ability) { HILOG_WARN("Invalid input parameter"); return; @@ -278,6 +291,8 @@ void AbilityDelegator::PostPerformStart(const std::shared_ptr &ability) { + HILOG_INFO("Enter"); + if (!ability) { HILOG_WARN("Invalid input parameter"); return; @@ -304,6 +319,8 @@ void AbilityDelegator::PostPerformScenceCreated(const std::shared_ptr &ability) { + HILOG_INFO("Enter"); + if (!ability) { HILOG_WARN("Invalid input parameter"); return; @@ -330,6 +347,8 @@ void AbilityDelegator::PostPerformScenceRestored(const std::shared_ptr &ability) { + HILOG_INFO("Enter"); + if (!ability) { HILOG_WARN("Invalid input parameter"); return; @@ -356,6 +375,8 @@ void AbilityDelegator::PostPerformScenceDestroyed(const std::shared_ptr &ability) { + HILOG_INFO("Enter"); + if (!ability) { HILOG_WARN("Invalid input parameter"); return; @@ -382,6 +403,8 @@ void AbilityDelegator::PostPerformForeground(const std::shared_ptr &ability) { + HILOG_INFO("Enter"); + if (!ability) { HILOG_WARN("Invalid input parameter"); return; @@ -408,6 +431,8 @@ void AbilityDelegator::PostPerformBackground(const std::shared_ptr &ability) { + HILOG_INFO("Enter"); + if (!ability) { HILOG_WARN("Invalid input parameter"); return; @@ -459,6 +484,8 @@ AbilityDelegator::AbilityState AbilityDelegator::ConvertAbilityState( void AbilityDelegator::ProcessAbilityProperties(const std::shared_ptr &ability) { + HILOG_INFO("Enter"); + if (!ability) { HILOG_WARN("Invalid ability property"); return; @@ -480,6 +507,8 @@ void AbilityDelegator::ProcessAbilityProperties(const std::shared_ptr AbilityDelegator::DoesPropertyExist(const sptr &token) { + HILOG_INFO("Enter"); + if (!token) { HILOG_WARN("Invalid input parameter"); return {}; diff --git a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp index 0b7fe770d7a..c317d1702d4 100644 --- a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp +++ b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp @@ -17,7 +17,9 @@ namespace OHOS { namespace AppExecFwk { -const std::string AbilityDelegatorArgs::KEY_TEST_BUNDLE_NAME {"-p"}; +const std::string AbilityDelegatorArgs::KEY_TEST_BUNDLE_NAME {"-b"}; +const std::string AbilityDelegatorArgs::KEY_TEST_PACKAGE_NAME {"-p"}; +const std::string AbilityDelegatorArgs::KEY_TEST_MODULE_NAME {"-m"}; const std::string AbilityDelegatorArgs::KEY_TEST_RUNNER_CLASS {"-s unittest"}; const std::string AbilityDelegatorArgs::KEY_TEST_CASE {"-s class"}; const std::string AbilityDelegatorArgs::KEY_TEST_WAIT_TIMEOUT {"-w"}; @@ -48,24 +50,24 @@ std::string AbilityDelegatorArgs::GetTestBundleName() const return bundleName_; } -std::string AbilityDelegatorArgs::GetTestRunnerClassName() const +std::string AbilityDelegatorArgs::GetTestPackageName() const { - auto target = params_.find(AbilityDelegatorArgs::KEY_TEST_RUNNER_CLASS); - if (target != params_.end()) { - return target->second; - } + return GetParamValue(AbilityDelegatorArgs::KEY_TEST_PACKAGE_NAME); +} - return {}; +std::string AbilityDelegatorArgs::GetTestModuleName() const +{ + return GetParamValue(AbilityDelegatorArgs::KEY_TEST_MODULE_NAME); } -std::string AbilityDelegatorArgs::GetTestCaseName() const +std::string AbilityDelegatorArgs::GetTestRunnerClassName() const { - auto target = params_.find(AbilityDelegatorArgs::KEY_TEST_CASE); - if (target != params_.end()) { - return target->second; - } + return GetParamValue(AbilityDelegatorArgs::KEY_TEST_RUNNER_CLASS); +} - return {}; +std::string AbilityDelegatorArgs::GetTestCaseName() const +{ + return GetParamValue(AbilityDelegatorArgs::KEY_TEST_CASE); } void AbilityDelegatorArgs::SetTestParam(const std::map ¶ms) @@ -77,5 +79,11 @@ std::map AbilityDelegatorArgs::GetTestParam() const { return params_; } + +std::string AbilityDelegatorArgs::GetParamValue(const std::string &key) const +{ + auto target = params_.find(key); + return (target != params_.end()) ? target->second : std::string(); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp b/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp index 394c5548e64..dc93e135799 100644 --- a/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp +++ b/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp @@ -57,12 +57,12 @@ bool IAbilityMonitor::Match(const std::shared_ptr &ab return true; } -std::shared_ptr IAbilityMonitor::waitForAbility() +std::shared_ptr IAbilityMonitor::WaitForAbility() { - return waitForAbility(MAX_TIME_OUT); + return WaitForAbility(MAX_TIME_OUT); } -std::shared_ptr IAbilityMonitor::waitForAbility(const int64_t timeoutMs) +std::shared_ptr IAbilityMonitor::WaitForAbility(const int64_t timeoutMs) { auto realTime = timeoutMs; if (timeoutMs <= 0) { diff --git a/frameworks/kits/appkit/native/ability_delegator/src/runner_runtime/js_test_runner.cpp b/frameworks/kits/appkit/native/ability_delegator/src/runner_runtime/js_test_runner.cpp index 03546804dae..3cebabeeca2 100755 --- a/frameworks/kits/appkit/native/ability_delegator/src/runner_runtime/js_test_runner.cpp +++ b/frameworks/kits/appkit/native/ability_delegator/src/runner_runtime/js_test_runner.cpp @@ -41,31 +41,23 @@ JsTestRunner::JsTestRunner( JsRuntime &jsRuntime, const std::shared_ptr &args, const AppExecFwk::BundleInfo &bundleInfo) : jsRuntime_(jsRuntime) { - std::string prefix; - std::string tempTestRunnerName = args->GetTestRunnerClassName(); - auto testRunnerName = tempTestRunnerName; - - auto pos = tempTestRunnerName.find(":"); - if (pos != std::string::npos) { - prefix = tempTestRunnerName.substr(0, pos); - testRunnerName = tempTestRunnerName.substr(pos + 1); + if (args) { + std::string srcPath; + if (bundleInfo.hapModuleInfos.back().isModuleJson) { + srcPath.append(args->GetTestModuleName()); + srcPath.append("/ets/TestRunner/"); + } else { + srcPath.append(args->GetTestPackageName()); + srcPath.append("/assets/js/TestRunner/"); + } + srcPath.append(args->GetTestRunnerClassName()); + srcPath.append(".abc"); + srcPath_ = srcPath; } - - std::string srcPath; - if (bundleInfo.hapModuleInfos.back().isModuleJson) { - srcPath.append(prefix); - srcPath.append("/ets/TestRunner/"); - } else { - srcPath.append(args->GetTestBundleName()); - srcPath.append("/assets/js/TestRunner/"); - } - srcPath.append(testRunnerName); - srcPath.append(".abc"); - - HILOG_INFO("JsTestRunner srcPath is %{public}s", srcPath.c_str()); + HILOG_INFO("JsTestRunner srcPath is %{public}s", srcPath_.c_str()); std::string moduleName; - jsTestRunnerObj_ = jsRuntime_.LoadModule(moduleName, srcPath); + jsTestRunnerObj_ = jsRuntime_.LoadModule(moduleName, srcPath_); } JsTestRunner::~JsTestRunner() = default; @@ -91,8 +83,8 @@ void JsTestRunner::CallObjectMethod(const char *name, NativeValue *const *argv, HILOG_INFO("JsTestRunner::CallObjectMethod(%{public}s)", name); if (!jsTestRunnerObj_) { - HILOG_ERROR("Not found test_runner.js"); - ReportFinished("Not found test_runner.js"); + HILOG_ERROR("Not found %{public}s", srcPath_.c_str()); + ReportFinished("Not found " + srcPath_); return; } diff --git a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp index be24cd79b68..029c9df2244 100644 --- a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp +++ b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp @@ -73,7 +73,7 @@ std::string ContextImpl::GetBundleCodeDir() if (IsCreateBySystemApp()) { dir = std::regex_replace(appInfo->codePath, std::regex(ABS_CODE_PATH), LOCAL_BUNDLES); } else { - dir = CONTEXT_DATA_STORAGE + CONTEXT_ELS[0] + CONTEXT_BUNDLE; + dir = LOCAL_CODE_PATH; } CreateDirIfNotExist(dir); HILOG_DEBUG("ContextImpl::GetBundleCodeDir:%{public}s", dir.c_str()); diff --git a/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp b/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp index 627c34d3a95..983ffe9ac68 100755 --- a/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp +++ b/frameworks/kits/appkit/native/ability_runtime/context/js_context_utils.cpp @@ -43,7 +43,7 @@ public: NativeValue* OnGetDatabaseDir(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetStorageDir(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetBundleCodeDir(NativeEngine& engine, NativeCallbackInfo& info); - + static NativeValue* GetCacheDir(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* GetTempDir(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* GetFilesDir(NativeEngine* engine, NativeCallbackInfo* info); diff --git a/frameworks/kits/appkit/native/app/include/context.h b/frameworks/kits/appkit/native/app/include/context.h index 03687a8663d..5f9ad4bd4c6 100644 --- a/frameworks/kits/appkit/native/app/include/context.h +++ b/frameworks/kits/appkit/native/app/include/context.h @@ -266,17 +266,6 @@ public: */ virtual std::string GetNoBackupFilesDir() = 0; - /** - * @brief Checks whether the calling process for inter-process communication has the given permission. - * The calling process is not the current process. - * - * @param permission Indicates the permission to check. This parameter cannot be null. - * - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the calling process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ - virtual int VerifyCallingPermission(const std::string &permission) = 0; - /** * @brief Checks whether the current process has the given permission. * You need to call requestPermissionsFromUser(java.lang.std::string[],int) to request a permission only @@ -366,30 +355,6 @@ public: */ virtual ErrCode TerminateAbility() = 0; - /** - * @brief Confirms with the permission management module to check whether a request prompt is required for granting - * a certain permission. You need to call the current method to check whether a prompt is required before calling - * requestPermissionsFromUser(java.lang.String[],int) to request a permission. If a prompt is not required, - * permission request will not be initiated. - * - * @param requestCode Indicates the permission to be queried. This parameter cannot be null. - * - * @return Returns true if the current application does not have the permission and the user does not turn off - * further requests; returns false if the current application already has the permission, the permission is rejected - * by the system, or the permission is denied by the user and the user has turned off further requests. - */ - virtual bool CanRequestPermission(const std::string &permission) = 0; - - /** - * @brief When there is a remote call to check whether the remote has permission, otherwise check whether it has - * permission - * - * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null. - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the current process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ - virtual int VerifyCallingOrSelfPermission(const std::string &permission) = 0; - /** * @brief Query whether the application of the specified PID and UID has been granted a certain permission * diff --git a/frameworks/kits/appkit/native/app/include/context_container.h b/frameworks/kits/appkit/native/app/include/context_container.h index 3dfc6e05b70..833e8743b81 100755 --- a/frameworks/kits/appkit/native/app/include/context_container.h +++ b/frameworks/kits/appkit/native/app/include/context_container.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -199,17 +199,6 @@ public: */ std::string GetNoBackupFilesDir() override; - /** - * @brief Checks whether the calling process for inter-process communication has the given permission. - * The calling process is not the current process. - * - * @param permission Indicates the permission to check. This parameter cannot be null. - * - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the calling process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ - int VerifyCallingPermission(const std::string &permission) override; - /** * @brief Checks whether the current process has the given permission. * You need to call requestPermissionsFromUser(java.lang.std::string[],int) to request a permission only @@ -264,30 +253,6 @@ public: */ std::string GetAppType() override; - /** - * @brief Confirms with the permission management module to check whether a request prompt is required for granting - * a certain permission. You need to call the current method to check whether a prompt is required before calling - * requestPermissionsFromUser(java.lang.String[],int) to request a permission. If a prompt is not required, - * permission request will not be initiated. - * - * @param requestCode Indicates the permission to be queried. This parameter cannot be null. - * - * @return Returns true if the current application does not have the permission and the user does not turn off - * further requests; returns false if the current application already has the permission, the permission is rejected - * by the system, or the permission is denied by the user and the user has turned off further requests. - */ - bool CanRequestPermission(const std::string &permission) override; - - /** - * @brief When there is a remote call to check whether the remote has permission, otherwise check whether it has - * permission - * - * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null. - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the current process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ - int VerifyCallingOrSelfPermission(const std::string &permission) override; - /** * @brief Query whether the application of the specified PID and UID has been granted a certain permission * diff --git a/frameworks/kits/appkit/native/app/include/context_deal.h b/frameworks/kits/appkit/native/app/include/context_deal.h index 6e721b91e35..77152de25ee 100755 --- a/frameworks/kits/appkit/native/app/include/context_deal.h +++ b/frameworks/kits/appkit/native/app/include/context_deal.h @@ -261,17 +261,6 @@ public: */ std::string GetNoBackupFilesDir() override; - /** - * @brief Checks whether the calling process for inter-process communication has the given permission. - * The calling process is not the current process. - * - * @param permission Indicates the permission to check. This parameter cannot be null. - * - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the calling process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ - int VerifyCallingPermission(const std::string &permission) override; - /** * @brief Checks whether the current process has the given permission. * You need to call requestPermissionsFromUser(java.lang.std::string[],int) to request a permission only @@ -354,30 +343,6 @@ public: */ ErrCode TerminateAbility(int requestCode) override; - /** - * @brief Confirms with the permission management module to check whether a request prompt is required for granting - * a certain permission. You need to call the current method to check whether a prompt is required before calling - * requestPermissionsFromUser(java.lang.String[],int) to request a permission. If a prompt is not required, - * permission request will not be initiated. - * - * @param requestCode Indicates the permission to be queried. This parameter cannot be null. - * - * @return Returns true if the current application does not have the permission and the user does not turn off - * further requests; returns false if the current application already has the permission, the permission is rejected - * by the system, or the permission is denied by the user and the user has turned off further requests. - */ - bool CanRequestPermission(const std::string &permission) override; - - /** - * @brief When there is a remote call to check whether the remote has permission, otherwise check whether it has - * permission - * - * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null. - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the current process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ - virtual int VerifyCallingOrSelfPermission(const std::string &permission) override; - /** * @brief Query whether the application of the specified PID and UID has been granted a certain permission * diff --git a/frameworks/kits/appkit/native/app/include/main_thread.h b/frameworks/kits/appkit/native/app/include/main_thread.h index 4d8427212f1..973a6169616 100644 --- a/frameworks/kits/appkit/native/app/include/main_thread.h +++ b/frameworks/kits/appkit/native/app/include/main_thread.h @@ -210,6 +210,13 @@ public: void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override; + /** + * + * @brief The handle of application not response process. + * + */ + void ScheduleANRProcess() override; + private: /** * @@ -378,15 +385,6 @@ private: */ void TaskTimeoutDetected(const std::shared_ptr& runner); - /** - * - * @brief The handle of application not response process. - * - * @param sigMessage Receive the sig message. - * - */ - static void HandleANRProcess(int sigMessage); - /** * * @brief Check whether the OHOSApplication is ready. @@ -408,6 +406,15 @@ private: */ bool PrepareAbilityDelegator(const std::shared_ptr &record); + /** + * + * @brief The handle of application not response process. + * + * @param sigMessage Recieve the sig message. + * + */ + void HandleScheduleANRProcess(); + class MainHandler : public EventHandler { public: MainHandler(const std::shared_ptr &runner, const sptr &thread); @@ -435,6 +442,7 @@ private: std::shared_ptr applicationImpl_ = nullptr; std::shared_ptr mainHandler_ = nullptr; std::shared_ptr watchDogHandler_ = nullptr; + std::shared_ptr handleANRThread_ = nullptr; std::shared_ptr abilityRecordMgr_ = nullptr; MainThreadState mainThreadState_ = MainThreadState::INIT; sptr appMgr_ = nullptr; // appMgrService Handler diff --git a/frameworks/kits/appkit/native/app/src/context_container.cpp b/frameworks/kits/appkit/native/app/src/context_container.cpp index 715b11a8f59..58ef2de10ad 100644 --- a/frameworks/kits/appkit/native/app/src/context_container.cpp +++ b/frameworks/kits/appkit/native/app/src/context_container.cpp @@ -335,25 +335,6 @@ std::string ContextContainer::GetNoBackupFilesDir() } } -/** - * @brief Checks whether the calling process for inter-process communication has the given permission. - * The calling process is not the current process. - * - * @param permission Indicates the permission to check. This parameter cannot be null. - * - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the calling process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ -int ContextContainer::VerifyCallingPermission(const std::string &permission) -{ - if (baseContext_ != nullptr) { - return baseContext_->VerifyCallingPermission(permission); - } else { - HILOG_ERROR("ContextContainer::VerifyCallingPermission baseContext_ is nullptr"); - return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; - } -} - /** * @brief Checks whether the current process has the given permission. * You need to call requestPermissionsFromUser(java.lang.std::string[],int) to request a permission only @@ -455,46 +436,6 @@ std::string ContextContainer::GetAppType() } } -/** - * @brief Confirms with the permission management module to check whether a request prompt is required for granting a - * certain permission. You need to call the current method to check whether a prompt is required before calling - * requestPermissionsFromUser(java.lang.String[],int) to request a permission. If a prompt is not required, permission - * request will not be initiated. - * - * @param requestCode Indicates the permission to be queried. This parameter cannot be null. - * - * @return Returns true if the current application does not have the permission and the user does not turn off further - * requests; returns false if the current application already has the permission, the permission is rejected by the - * system, or the permission is denied by the user and the user has turned off further requests. - */ -bool ContextContainer::CanRequestPermission(const std::string &permission) -{ - if (baseContext_ != nullptr) { - return baseContext_->CanRequestPermission(permission); - } else { - HILOG_ERROR("ContextContainer::CanRequestPermission baseContext_ is nullptr"); - return true; - } -} - -/** - * @brief When there is a remote call to check whether the remote has permission, otherwise check whether it has - * permission - * - * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null. - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the current process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ -int ContextContainer::VerifyCallingOrSelfPermission(const std::string &permission) -{ - if (baseContext_ != nullptr) { - return baseContext_->VerifyCallingOrSelfPermission(permission); - } else { - HILOG_ERROR("ContextContainer::VerifyCallingOrSelfPermission baseContext_ is nullptr"); - return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; - } -} - /** * @brief Query whether the application of the specified PID and UID has been granted a certain permission * diff --git a/frameworks/kits/appkit/native/app/src/context_deal.cpp b/frameworks/kits/appkit/native/app/src/context_deal.cpp index 837825cdfaa..097e62dc7e2 100644 --- a/frameworks/kits/appkit/native/app/src/context_deal.cpp +++ b/frameworks/kits/appkit/native/app/src/context_deal.cpp @@ -448,20 +448,6 @@ std::string ContextDeal::GetNoBackupFilesDir() return dir; } -/** - * @brief Checks whether the calling process for inter-process communication has the given permission. - * The calling process is not the current process. - * - * @param permission Indicates the permission to check. This parameter cannot be null. - * - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the calling process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ -int ContextDeal::VerifyCallingPermission(const std::string &permission) -{ - return 0; -} - /** * @brief Checks whether the current process has the given permission. * You need to call requestPermissionsFromUser(java.lang.std::string[],int) to request a permission only @@ -595,36 +581,6 @@ ErrCode ContextDeal::TerminateAbility(int requestCode) return ERR_INVALID_VALUE; } -/** - * @brief Confirms with the permission management module to check whether a request prompt is required for granting a - * certain permission. You need to call the current method to check whether a prompt is required before calling - * requestPermissionsFromUser(java.lang.String[],int) to request a permission. If a prompt is not required, permission - * request will not be initiated. - * - * @param requestCode Indicates the permission to be queried. This parameter cannot be null. - * - * @return Returns true if the current application does not have the permission and the user does not turn off further - * requests; returns false if the current application already has the permission, the permission is rejected by the - * system, or the permission is denied by the user and the user has turned off further requests. - */ -bool ContextDeal::CanRequestPermission(const std::string &permission) -{ - return false; -} - -/** - * @brief When there is a remote call to check whether the remote has permission, otherwise check whether it has - * permission - * - * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null. - * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the current process has the permission; - * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise. - */ -int ContextDeal::VerifyCallingOrSelfPermission(const std::string &permission) -{ - return 0; -} - /** * @brief Query whether the application of the specified PID and UID has been granted a certain permission * diff --git a/frameworks/kits/appkit/native/app/src/main_thread.cpp b/frameworks/kits/appkit/native/app/src/main_thread.cpp index 10a61b102a1..9673f944702 100644 --- a/frameworks/kits/appkit/native/app/src/main_thread.cpp +++ b/frameworks/kits/appkit/native/app/src/main_thread.cpp @@ -623,6 +623,11 @@ void MainThread::HandleTerminateApplicationLocal() if (watchDogHandler_ != nullptr) { watchDogHandler_->Stop(); } + if (handleANRThread_ != nullptr && handleANRThread_->joinable()) { + handleANRThread_->join(); + handleANRThread_ = nullptr; + } + int ret = runner->Stop(); if (ret != ERR_OK) { HILOG_ERROR("MainThread::HandleTerminateApplicationLocal failed. runner->Run failed ret = %{public}d", ret); @@ -870,6 +875,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con AbilityRuntime::Runtime::Options options; options.codePath = LOCAL_CODE_PATH; options.eventRunner = mainHandler_->GetEventRunner(); + options.loadAce = true; std::string nativeLibraryPath = appInfo.nativeLibraryPath; if (!nativeLibraryPath.empty()) { if (nativeLibraryPath.back() == '/') { @@ -885,7 +891,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con HILOG_ERROR("OHOSApplication::OHOSApplication: Failed to create runtime"); return; } - // auto& jsEngine = (static_cast(*runtime)).GetNativeEngine(); + auto& jsEngine = (static_cast(*runtime)).GetNativeEngine(); auto bundleName = appInfo.bundleName; auto uid = appInfo.uid; auto processName = processInfo.GetProcessName(); @@ -942,7 +948,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con appThread->ScheduleProcessSecurityExit(); HILOG_INFO("RegisterUncaughtExceptionHandler End ret = %{public}d", ret); }; - // jsEngine.RegisterUncaughtExceptionHandler(uncaughtTask); + jsEngine.RegisterUncaughtExceptionHandler(uncaughtTask); application_->SetRuntime(std::move(runtime)); AbilityLoader::GetInstance().RegisterAbility("Ability", [application = application_]() { @@ -1032,10 +1038,6 @@ void MainThread::HandleAbilityStage(const HapModuleInfo &abilityStage) return; } - if (!appMgr_ || !applicationImpl_) { - HILOG_ERROR("appMgr_ is nullptr"); - return; - } appMgr_->AddAbilityStageDone(applicationImpl_->GetRecordId()); } @@ -1071,6 +1073,7 @@ bool MainThread::PrepareAbilityDelegator(const std::shared_ptr & AbilityRuntime::Runtime::Options options; options.codePath = LOCAL_CODE_PATH; options.eventRunner = mainHandler_->GetEventRunner(); + options.loadAce = false; static auto runtime = AbilityRuntime::Runtime::Create(options); auto testRunner = TestRunner::Create(runtime, args); auto delegator = std::make_shared( @@ -1337,6 +1340,11 @@ void MainThread::HandleTerminateApplication() if (watchDogHandler_ != nullptr) { watchDogHandler_->Stop(); } + if (handleANRThread_ != nullptr && handleANRThread_->joinable()) { + handleANRThread_->join(); + handleANRThread_ = nullptr; + } + HILOG_INFO("MainThread::handleTerminateApplication before stop runner"); int ret = runner->Stop(); HILOG_INFO("MainThread::handleTerminateApplication after stop runner"); @@ -1346,9 +1354,9 @@ void MainThread::HandleTerminateApplication() SetRunnerStarted(false); #ifdef ABILITY_LIBRARY_LOADER - HILOG_INFO("MainThread::handleTerminateApplication. Start callint CloseAbilityLibrary."); + HILOG_INFO("MainThread::handleTerminateApplication. Start calling CloseAbilityLibrary."); CloseAbilityLibrary(); - HILOG_INFO("MainThread::handleTerminateApplication. End callint CloseAbilityLibrary."); + HILOG_INFO("MainThread::handleTerminateApplication. End calling CloseAbilityLibrary."); #endif // ABILITY_LIBRARY_LOADER #ifdef APPLICATION_LIBRARY_LOADER if (handleAppLib_ != nullptr) { @@ -1457,35 +1465,48 @@ void MainThread::Init(const std::shared_ptr &runner, const std::sha HILOG_INFO("MainThread:Init end."); } -void MainThread::HandleANRProcess(int sigMessage) +void MainThread::ScheduleANRProcess() { - if (sigMessage == SIGUSR1) { - HILOG_INFO("MainThread:HandleANRProcess start."); - int rFD = -1; - std::string mainThreadStackInfo; - if ((rFD = RequestFileDescriptor(int32_t(FaultLoggerType::CPP_STACKTRACE))) < 0) { - HILOG_ERROR("MainThread::HandleANRProcess request file eescriptor failed"); - return; - } - auto jsRuntime = std::move((std::unique_ptr&)applicationForAnr_->GetRuntime()); - if (jsRuntime != nullptr) { - mainThreadStackInfo= jsRuntime->BuildNativeAndJsBackStackTrace(); - if (write(rFD, mainThreadStackInfo.c_str(), mainThreadStackInfo.size()) != mainThreadStackInfo.size()) { - HILOG_ERROR("MainThread::HandleANRProcess write main thread stack info failed"); - } - } - OHOS::HiviewDFX::DfxDumpCatcher dumplog; - std::string proStackInfo; - if (dumplog.DumpCatch(getpid(), 0, proStackInfo) == false) { - HILOG_ERROR("MainThread::HandleANRProcess get process stack info failed"); - } - if (write(rFD, proStackInfo.c_str(), proStackInfo.size()) != proStackInfo.size()) { - HILOG_ERROR("MainThread::HandleANRProcess write process stack info failed"); - } - if (rFD != -1) { - close(rFD); + HILOG_INFO("MainThread::ScheduleANRProcess called begin"); + if (handleANRThread_ == nullptr) { + handleANRThread_ = std::make_shared(&MainThread::HandleScheduleANRProcess, this); + } + HILOG_INFO("MainThread::ScheduleANRProcess called end."); +} + +void MainThread::HandleScheduleANRProcess() +{ + HILOG_INFO("MainThread:HandleScheduleANRProcess start."); + int rFD = -1; + std::string mainThreadStackInfo; + if ((rFD = RequestFileDescriptor(int32_t(FaultLoggerType::CPP_STACKTRACE))) < 0) { + HILOG_ERROR("MainThread::HandleScheduleANRProcess request file eescriptor failed"); + return; + } + HILOG_INFO("MainThread:HandleScheduleANRProcess RequestFileDescriptor end."); + auto jsRuntime = std::move((std::unique_ptr&)applicationForAnr_->GetRuntime()); + if (jsRuntime != nullptr) { + mainThreadStackInfo= jsRuntime->BuildNativeAndJsBackStackTrace(); + if (write(rFD, mainThreadStackInfo.c_str(), mainThreadStackInfo.size()) != mainThreadStackInfo.size()) { + HILOG_ERROR("MainThread::HandleScheduleANRProcess write main thread stack info failed"); } } + HILOG_INFO("HandleScheduleANRProcess write main thread stack info size: %{public}d", mainThreadStackInfo.size()); + HILOG_INFO("MainThread:HandleScheduleANRProcess BuildNativeAndJsBackStackTrace end."); + OHOS::HiviewDFX::DfxDumpCatcher dumplog; + std::string proStackInfo; + if (dumplog.DumpCatch(getpid(), 0, proStackInfo) == false) { + HILOG_ERROR("MainThread::HandleScheduleANRProcess get process stack info failed"); + } + HILOG_INFO("MainThread:HandleScheduleANRProcess DumpCatch end."); + if (write(rFD, proStackInfo.c_str(), proStackInfo.size()) != proStackInfo.size()) { + HILOG_ERROR("MainThread::HandleScheduleANRProcess write process stack info failed"); + } + HILOG_INFO("HandleScheduleANRProcess DumpCatch write process stack info size: %{public}d", proStackInfo.size()); + if (rFD != -1) { + close(rFD); + } + HILOG_INFO("MainThread:HandleScheduleANRProcess end."); } void MainThread::Start() @@ -1508,14 +1529,6 @@ void MainThread::Start() return; } - HILOG_INFO("MainThread::main Register sig handle start"); - struct sigaction sigAct; - sigemptyset(&sigAct.sa_mask); - sigAct.sa_flags = 0; - sigAct.sa_handler = &MainThread::HandleANRProcess; - sigaction(SIGUSR1, &sigAct, NULL); - HILOG_INFO("MainThread::main Register sig handle end"); - HILOG_INFO("MainThread::main called start Init"); thread->Init(runner, runnerWatchDog); HILOG_INFO("MainThread::main called end Init"); diff --git a/frameworks/kits/appkit/native/test/mock/include/mock_ability_manager_client_interface1.h b/frameworks/kits/appkit/native/test/mock/include/mock_ability_manager_client_interface1.h index a82f685e6a3..7fbfcfce052 100644 --- a/frameworks/kits/appkit/native/test/mock/include/mock_ability_manager_client_interface1.h +++ b/frameworks/kits/appkit/native/test/mock/include/mock_ability_manager_client_interface1.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -239,19 +239,6 @@ public: { return true; }; - virtual bool RegisterAllPermissionsChanged(const sptr &callback) - { - return true; - }; - virtual bool RegisterPermissionsChanged( - const std::vector &uids, const sptr &callback) - { - return true; - }; - virtual bool UnregisterPermissionsChanged(const sptr &callback) - { - return true; - }; virtual bool GetAllFormsInfo(std::vector &formInfos) { return true; diff --git a/frameworks/kits/appkit/native/test/mock/include/mock_resourceManager_interface1.cpp b/frameworks/kits/appkit/native/test/mock/include/mock_resourceManager_interface1.cpp index a57281033d9..e1bcd3c2eeb 100644 --- a/frameworks/kits/appkit/native/test/mock/include/mock_resourceManager_interface1.cpp +++ b/frameworks/kits/appkit/native/test/mock/include/mock_resourceManager_interface1.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -265,7 +265,6 @@ public: std::map> IntArrayById_; std::map ColorById_; - // static ResourceManagerTestInstance* instance; static std::shared_ptr instance; }; diff --git a/frameworks/kits/appkit/test/Mock/include/mock_ability_mgr_service.h b/frameworks/kits/appkit/test/Mock/include/mock_ability_mgr_service.h index 936f084101c..d6588ed87ac 100644 --- a/frameworks/kits/appkit/test/Mock/include/mock_ability_mgr_service.h +++ b/frameworks/kits/appkit/test/Mock/include/mock_ability_mgr_service.h @@ -60,7 +60,7 @@ public: MOCK_METHOD1(MoveMissionToTop, int(int32_t)); MOCK_METHOD1(KillProcess, int(const std::string &bundleName)); - MOCK_METHOD2(UninstallApp, int(const std::string &bundleName, const int userId)); + MOCK_METHOD2(UninstallApp, int(const std::string &bundleName, int32_t uid)); MOCK_METHOD1(TerminateAbilityByRecordId, int(const int64_t recordId)); MOCK_METHOD1(LockMissionForCleanup, int(int32_t missionId)); @@ -74,6 +74,7 @@ public: MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); + MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector &info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector &info)); diff --git a/frameworks/kits/appkit/test/Mock/include/mock_bundle_mgr_service.h b/frameworks/kits/appkit/test/Mock/include/mock_bundle_mgr_service.h index 3154fb4edce..94ba137c0c7 100644 --- a/frameworks/kits/appkit/test/Mock/include/mock_bundle_mgr_service.h +++ b/frameworks/kits/appkit/test/Mock/include/mock_bundle_mgr_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -114,10 +114,6 @@ public: MOCK_METHOD2(GetBundlesForUid, bool(const int uid, std::vector &)); MOCK_METHOD1(IsAbilityEnabled, bool(const AbilityInfo &)); MOCK_METHOD2(GetAbilityIcon, std::string(const std::string &bundleName, const std::string &className)); - MOCK_METHOD1(RegisterAllPermissionsChanged, bool(const sptr &callback)); - MOCK_METHOD2(RegisterPermissionsChanged, - bool(const std::vector &uids, const sptr &callback)); - MOCK_METHOD1(UnregisterPermissionsChanged, bool(const sptr &callback)); void Wait() { sem_.Wait(); diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/extra_params.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/extra_params.cpp index 9433ead0d14..f4358176681 100644 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/extra_params.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/extra_params.cpp @@ -156,6 +156,7 @@ string ExtraParams::GetTargetBundleName() const { return targetBundleName_; } + /** * @brief Sets the description used for device filtering. * diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp index 2641b5e684d..ce30c18c1fb 100644 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -1341,7 +1341,7 @@ Want &Want::SetUriAndType(const Uri &uri, const std::string &type) /** * @description: Converts a Want into a URI string containing a representation of it. * @param want Indicates the want description.--Want. - * @return Returns a encoding URI string describing the Want object. + * @return Returns an encoding URI string describing the Want object. */ std::string Want::WantToUri(Want &want) { diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp index ecb52051305..8a2a1ec8cd9 100644 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp @@ -1350,7 +1350,7 @@ void WantParams::DumpInfo(int level) const if (typeId != VALUE_TYPE_NULL) { std::string value = WantParams::GetStringByType(it.second, typeId); ABILITYBASE_LOGI( - "=WantParams::params_[%{public}s] : %{public}s =============", it.first.c_str(), value.c_str()); + "=WantParams::params_[%{public}s] : %{private}s =============", it.first.c_str(), value.c_str()); } else { ABILITYBASE_LOGI("=WantParams::params_[%{public}s] : type error =============", it.first.c_str()); } diff --git a/frameworks/kits/fmskit/native/include/form_mgr.h b/frameworks/kits/fmskit/native/include/form_mgr.h index 203a61d2912..d576baf74ff 100644 --- a/frameworks/kits/fmskit/native/include/form_mgr.h +++ b/frameworks/kits/fmskit/native/include/form_mgr.h @@ -26,6 +26,7 @@ #include "form_js_info.h" #include "form_mgr_interface.h" #include "form_provider_data.h" +#include "form_state_info.h" #include "iremote_object.h" #include "want.h" @@ -240,6 +241,25 @@ public: */ int DistributedDataDeleteForm(const std::string &formId); + /** + * @brief Delete the given invalid forms. + * @param formIds Indicates the ID of the forms to delete. + * @param callerToken Host client. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns ERR_OK on success, others on failure. + */ + int DeleteInvalidForms(const std::vector &formIds, const sptr &callerToken, + int32_t &numFormsDeleted); + + /** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param callerToken Host client. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns ERR_OK on success, others on failure. + */ + int AcquireFormState(const Want &want, const sptr &callerToken, FormStateInfo &stateInfo); + /** * @brief Get All FormsInfo. * @param formInfos Return the forms' information of all forms provided. diff --git a/frameworks/kits/fmskit/native/src/form_mgr.cpp b/frameworks/kits/fmskit/native/src/form_mgr.cpp index ce95771d8db..a6c6f828eac 100644 --- a/frameworks/kits/fmskit/native/src/form_mgr.cpp +++ b/frameworks/kits/fmskit/native/src/form_mgr.cpp @@ -555,6 +555,43 @@ int FormMgr::DistributedDataDeleteForm(const std::string &formId) return remoteProxy_->DistributedDataDeleteForm(formId); } +/** + * @brief Delete the given invalid forms. + * @param formIds Indicates the ID of the forms to delete. + * @param callerToken Host client. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgr::DeleteInvalidForms(const std::vector &formIds, const sptr &callerToken, + int32_t &numFormsDeleted) +{ + HILOG_INFO("%{public}s start.", __func__); + int errCode = Connect(); + if (errCode != ERR_OK) { + HILOG_ERROR("%{public}s failed, errCode: %{public}d.", __func__, errCode); + return errCode; + } + return remoteProxy_->DeleteInvalidForms(formIds, callerToken, numFormsDeleted); +} + +/** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param callerToken Host client. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgr::AcquireFormState(const Want &want, const sptr &callerToken, FormStateInfo &stateInfo) +{ + HILOG_INFO("%{public}s start.", __func__); + int errCode = Connect(); + if (errCode != ERR_OK) { + HILOG_ERROR("%{public}s failed, errCode: %{public}d.", __func__, errCode); + return errCode; + } + return remoteProxy_->AcquireFormState(want, callerToken, stateInfo); +} + /** * @brief Get All FormsInfo. * @param formInfos Return the forms' information of all forms provided. diff --git a/frameworks/kits/runtime/native/js_data_struct_converter.cpp b/frameworks/kits/runtime/native/js_data_struct_converter.cpp index 161a6454c21..80641366805 100644 --- a/frameworks/kits/runtime/native/js_data_struct_converter.cpp +++ b/frameworks/kits/runtime/native/js_data_struct_converter.cpp @@ -171,7 +171,6 @@ NativeValue* CreateJsApplicationInfo(NativeEngine& engine, const AppExecFwk::App } } object->SetProperty("moduleInfo", arrayValue); - // metaData: Map>; for (auto &item : applicationInfo.metaData) { object->SetProperty(item.first.c_str(), CreateJsCustomizeDataArray(engine, item.second)); } diff --git a/frameworks/kits/runtime/native/js_runtime.cpp b/frameworks/kits/runtime/native/js_runtime.cpp index baef798a1f1..e8f0ac8af71 100644 --- a/frameworks/kits/runtime/native/js_runtime.cpp +++ b/frameworks/kits/runtime/native/js_runtime.cpp @@ -323,7 +323,9 @@ bool JsRuntime::Initialize(const Options& options) return false; } - OHOS::Ace::DeclarativeModulePreloader::Preload(*nativeEngine_); + if (options.loadAce) { + OHOS::Ace::DeclarativeModulePreloader::Preload(*nativeEngine_); + } codePath_ = options.codePath; auto moduleManager = NativeModuleManager::GetInstance(); @@ -524,7 +526,7 @@ NativeValue* JsRuntime::ClearCallbackTimer(NativeEngine& engine, NativeCallbackI std::string JsRuntime::BuildNativeAndJsBackStackTrace() { std::string straceStr = ""; - // [[maybe_unused]]bool temp = nativeEngine_->BuildNativeAndJsBackStackTrace(straceStr); + // [[maybe_unused]]bool temp = nativeEngine_->BuildNativeAndJsBackStackTrace(straceStr) return straceStr; } } // namespace AbilityRuntime diff --git a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.cpp b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.cpp index e80a4082fa9..38e407f46f1 100644 --- a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.cpp +++ b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -224,12 +224,6 @@ bool MockAbilityManagerService::IsFirstInMission(const sptr &toke return true; } -int MockAbilityManagerService::CompelVerifyPermission( - const std::string &permission, int pid, int uid, std::string &message) -{ - return 0; -} - int MockAbilityManagerService::PowerOff() { return 0; diff --git a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h index 5f7106cf5b4..f6b37411010 100644 --- a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -91,7 +91,7 @@ public: MOCK_METHOD1(MoveMissionToTop, int(int32_t missionId)); MOCK_METHOD1(KillProcess, int(const std::string &bundleName)); - MOCK_METHOD1(UninstallApp, int(const std::string &bundleName)); + MOCK_METHOD2(UninstallApp, int(const std::string &bundleName, int32_t uid)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo &wantSenderInfo, const sptr &callerToken)); MOCK_METHOD2(SendWantSender, int(const sptr &target, const SenderInfo &senderInfo)); @@ -142,10 +142,10 @@ public: MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector &info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector &info)); MOCK_METHOD3(StartAbilityByCall, int(const Want &, const sptr &, const sptr &)); + MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); int MoveMissionToEnd(const sptr &token, const bool nonFirst) override; bool IsFirstInMission(const sptr &token) override; - int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override; int GetRecentMissions( const int32_t numMax, const int32_t flags, std::vector &recentList) override; diff --git a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.cpp b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.cpp index 0cb934af7d6..d45b1c8c003 100644 --- a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.cpp +++ b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -196,12 +196,6 @@ bool MockServiceAbilityManagerService::IsFirstInMission(const sptr(const WantSenderInfo &wantSenderInfo, const sptr &callerToken)); MOCK_METHOD2(SendWantSender, int(const sptr &target, const SenderInfo &senderInfo)); @@ -131,6 +131,7 @@ public: MOCK_METHOD3( GetMissionInfos, int(const std::string& deviceId, int32_t numMax, std::vector &missionInfos)); MOCK_METHOD3(GetMissionInfo, int(const std::string& deviceId, int32_t missionId, MissionInfo &missionInfo)); + MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); MOCK_METHOD1(CleanMission, int(int32_t missionId)); MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); @@ -144,7 +145,6 @@ public: int MoveMissionToEnd(const sptr &token, const bool nonFirst) override; bool IsFirstInMission(const sptr &token) override; - int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override; int RemoveMission(int id) override; diff --git a/frameworks/kits/test/mock/DemoObServer/mock_ability_thread_for_data_observer.h b/frameworks/kits/test/mock/DemoObServer/mock_ability_thread_for_data_observer.h index 8a3e95caa16..8db35922a30 100644 --- a/frameworks/kits/test/mock/DemoObServer/mock_ability_thread_for_data_observer.h +++ b/frameworks/kits/test/mock/DemoObServer/mock_ability_thread_for_data_observer.h @@ -36,16 +36,19 @@ sptr MockCreateAbilityThread() sptr abilitythread(new (std::nothrow) AppExecFwk::AbilityThread()); if (abilitythread == nullptr) { GTEST_LOG_(INFO) << "mock_ability_thread_for_data_observer:mock abilityhreadptr is nullptr called"; + return nullptr; } std::shared_ptr application = std::make_shared(); if (application == nullptr) { GTEST_LOG_(INFO) << "mock_ability_thread_for_data_observer:mock applicationptr is nullptr called"; + return nullptr; } std::shared_ptr info = std::make_shared(); if (info == nullptr) { GTEST_LOG_(INFO) << "mock_ability_thread_for_data_observer:mock AbilityInfo::info is nullptr called"; + return nullptr; } info->name = std::string("MockAbilityTest"); diff --git a/frameworks/kits/test/moduletest/cpp/abilitytest/ability_context_test.cpp b/frameworks/kits/test/moduletest/cpp/abilitytest/ability_context_test.cpp index c198d37047c..e86f616a2cd 100644 --- a/frameworks/kits/test/moduletest/cpp/abilitytest/ability_context_test.cpp +++ b/frameworks/kits/test/moduletest/cpp/abilitytest/ability_context_test.cpp @@ -50,7 +50,7 @@ void AbilityContextTest::SetUpTestCase(void) OHOS::sptr abilityObject = new (std::nothrow) MockServiceAbilityManagerService(); auto sysMgr = OHOS::DelayedSingleton::GetInstance(); - if (sysMgr == NULL) { + if (sysMgr == nullptr) { GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager"; return; } diff --git a/frameworks/kits/wantagent/src/pending_want.cpp b/frameworks/kits/wantagent/src/pending_want.cpp index 262e56d0a7c..b18bd56d754 100644 --- a/frameworks/kits/wantagent/src/pending_want.cpp +++ b/frameworks/kits/wantagent/src/pending_want.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -265,10 +265,10 @@ int PendingWant::SendAndReturnResult(int resultCode, const std::shared_ptr bool PendingWant::Equals( const std::shared_ptr &targetPendingWant, const std::shared_ptr &otherPendingWant) { - if (targetPendingWant == nullptr && otherPendingWant == nullptr) { + if ((targetPendingWant == nullptr) && (otherPendingWant == nullptr)) { return true; } - if (targetPendingWant == nullptr || otherPendingWant == nullptr) { + if ((targetPendingWant == nullptr) || (otherPendingWant == nullptr)) { return false; } return targetPendingWant->GetHashCode(targetPendingWant->GetTarget()) == diff --git a/frameworks/kits/wantagent/src/want_agent_helper.cpp b/frameworks/kits/wantagent/src/want_agent_helper.cpp index 14e9c459a20..00a98755f58 100644 --- a/frameworks/kits/wantagent/src/want_agent_helper.cpp +++ b/frameworks/kits/wantagent/src/want_agent_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -169,7 +169,7 @@ std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo &pa WantAgentConstant::OperationType WantAgentHelper::GetType(const std::shared_ptr &agent) { - if (agent == nullptr || agent->GetPendingWant() == nullptr) { + if ((agent == nullptr) || (agent->GetPendingWant() == nullptr)) { return WantAgentConstant::OperationType::UNKNOWN_TYPE; } diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_client.h b/interfaces/innerkits/ability_manager/include/ability_manager_client.h index e8bd70cb0b1..ab936d74dcf 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_client.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_client.h @@ -359,8 +359,6 @@ public: */ ErrCode IsFirstInMission(const sptr &token); - ErrCode CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message); - /** * Save the top ability States and move them to the background * @return Returns ERR_OK on success, others on failure. @@ -636,6 +634,15 @@ public: ErrCode MoveMissionToFront(int32_t missionId); ErrCode MoveMissionToFront(int32_t missionId, const StartOptions &startOptions); + /** + * @brief Get mission id by ability token. + * + * @param token ability token. + * @param missionId output mission id. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetMissionIdByToken(const sptr &token, int32_t &missionId); + /** * Start Ability, connect session with common ability. * diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h index c1e73ed03a6..191d3d96360 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h @@ -394,10 +394,11 @@ public: /** * Uninstall app * - * @param bundleName. + * @param bundleName bundle name of uninstalling app. + * @param uid uid of bundle. * @return Returns ERR_OK on success, others on failure. */ - virtual int UninstallApp(const std::string &bundleName) = 0; + virtual int UninstallApp(const std::string &bundleName, int32_t uid) = 0; /** * Moving mission to the specified stack by mission option(Enter floating window mode). @@ -464,18 +465,6 @@ public: */ virtual bool IsFirstInMission(const sptr &token) = 0; - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) = 0; - /** * Save the top ability States and move them to the background * @return Returns ERR_OK on success, others on failure. @@ -727,6 +716,14 @@ public: */ virtual int SendANRProcessID(int pid) = 0; + /** + * Get mission id by ability token. + * + * @param token The token of ability. + * @return Returns -1 if do not find mission, otherwise return mission id. + */ + virtual int32_t GetMissionIdByToken(const sptr &token) = 0; + enum { // ipc id 1-1000 for kit // ipc id for terminating ability (1) @@ -897,6 +894,9 @@ public: // ipc id for move mission to front by options (56) MOVE_MISSION_TO_FRONT_BY_OPTIONS, + // ipc for get mission id by ability token (57) + GET_MISSION_ID_BY_ABILITY_TOKEN, + // ipc id 1001-2000 for DMS // ipc id for starting ability (1001) START_ABILITY = 1001, diff --git a/interfaces/innerkits/ability_manager/include/ability_scheduler_interface.h b/interfaces/innerkits/ability_manager/include/ability_scheduler_interface.h index 7696ce30911..14bbfb31f6e 100644 --- a/interfaces/innerkits/ability_manager/include/ability_scheduler_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_scheduler_interface.h @@ -368,8 +368,8 @@ public: // ipc id for continue ability CONTINUE_ABILITY, - - // ipc id for dump ability runner + + // ipc id for dump ability runner DUMP_ABILITY_RUNNER_INNER }; }; diff --git a/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_interface.h index 28d20995083..b834d7a3897 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_interface.h @@ -143,18 +143,6 @@ public: virtual void PrepareTerminate(const sptr &token) = 0; - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) = 0; - virtual void GetRunningProcessInfoByToken( const sptr &token, OHOS::AppExecFwk::RunningProcessInfo &info) = 0; @@ -184,7 +172,6 @@ public: KILL_PROCESS_WITH_ACCOUNT, KILL_APPLICATION, ABILITY_ATTACH_TIMEOUT, - COMPEL_VERIFY_PERMISSION, PREPARE_TERMINATE_ABILITY, KILL_APPLICATION_BYUID, GET_RUNNING_PROCESS_INFO_BY_TOKEN, diff --git a/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_proxy.h index 4be57ed5e91..e4b54c68350 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_proxy.h @@ -137,18 +137,6 @@ public: virtual void PrepareTerminate(const sptr &token) override; - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override; - void GetRunningProcessInfoByToken(const sptr &token, AppExecFwk::RunningProcessInfo &info) override; virtual void StartSpecifiedAbility( diff --git a/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_stub.h b/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_stub.h index 982f5a5a86e..8ba49bef091 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_stub.h +++ b/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -54,7 +54,6 @@ private: int32_t HandleKillProcessWithAccount(MessageParcel &data, MessageParcel &reply); int32_t HandleKillApplication(MessageParcel &data, MessageParcel &reply); int32_t HandleAbilityAttachTimeOut(MessageParcel &data, MessageParcel &reply); - int32_t HandleCompelVerifyPermission(MessageParcel &data, MessageParcel &reply); int32_t HandlePrepareTerminate(MessageParcel &data, MessageParcel &reply); int32_t HandleKillApplicationByUid(MessageParcel &data, MessageParcel &reply); int32_t HandleGetRunningProcessInfoByToken(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h index 9626b64b112..453dcb1e4d4 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h @@ -173,18 +173,6 @@ public: virtual void PrepareTerminate(const sptr &token); - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message); - /** * Get system memory information. * @param SystemMemoryAttr, memory information. @@ -264,6 +252,13 @@ public: */ virtual void AttachRenderProcess(const sptr &renderScheduler); + /** + * Post a task to the not response process. + * + * @param pid, the not response process id. + */ + virtual void PostANRTaskByProcessID(const pid_t pid); + private: void SetServiceManager(std::unique_ptr serviceMgr); diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h index c05c45c6544..5fb8ffff4bf 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h @@ -214,6 +214,13 @@ public: */ virtual void AttachRenderProcess(const sptr &renderScheduler) = 0; + /** + * Post a task to the not response process. + * + * @param pid, the not response process id. + */ + virtual void PostANRTaskByProcessID(const pid_t pid) = 0; + enum class Message { APP_ATTACH_APPLICATION = 0, APP_APPLICATION_FOREGROUNDED, @@ -237,6 +244,7 @@ public: APP_GET_ABILITY_RECORDS_BY_PROCESS_ID, START_RENDER_PROCESS, ATTACH_RENDER_PROCESS, + POST_ANR_TASK_BY_PID, }; }; } // namespace AppExecFwk diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h index cb1bb6f8bfb..845f139539c 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h @@ -207,6 +207,13 @@ public: */ virtual void AttachRenderProcess(const sptr &renderApp) override; + /** + * Post a task to the not response process. + * + * @param pid, the not response process id. + */ + virtual void PostANRTaskByProcessID(const pid_t pid) override; + private: bool SendTransactCmd(IAppMgr::Message code, MessageParcel &data, MessageParcel &reply); bool WriteInterfaceToken(MessageParcel &data); diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h index 36c330d19d6..e9513f2fb14 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h @@ -77,6 +77,7 @@ private: int32_t HandleGetAbilityRecordsByProcessID(MessageParcel &data, MessageParcel &reply); int32_t HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply); + int32_t HandlePostANRTaskByProcessID(MessageParcel &data, MessageParcel &reply); using AppMgrFunc = int32_t (AppMgrStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_host.h b/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_host.h index 5d5c9e4bc5d..6c07b1963df 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_host.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_host.h @@ -48,6 +48,7 @@ private: int32_t HandleScheduleConfigurationUpdated(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleProcessSecurityExit(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleAcceptWant(MessageParcel &data, MessageParcel &reply); + int32_t HandleScheduleANRProcess(MessageParcel &data, MessageParcel &reply); using AppSchedulerFunc = int32_t (AppSchedulerHost::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_interface.h b/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_interface.h index d80f7d2166e..334ec2bc93b 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_interface.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_interface.h @@ -131,6 +131,15 @@ public: virtual void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) = 0; + /** + * + * @brief The handle of application not response process. + * + * @param sigMessage Recieve the sig message. + * + */ + virtual void ScheduleANRProcess() = 0; + enum class Message { SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION = 0, SCHEDULE_BACKGROUND_APPLICATION_TRANSACTION, @@ -145,6 +154,7 @@ public: SCHEDULE_PROCESS_SECURITY_EXIT_TRANSACTION, SCHEDULE_ABILITY_STAGE_INFO, SCHEDULE_ACCEPT_WANT, + SCHEDULE_ANR_PROCESS, }; }; } // namespace AppExecFwk diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_proxy.h b/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_proxy.h index 74462aaadee..f72e8b35708 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_proxy.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_scheduler_proxy.h @@ -134,6 +134,15 @@ public: virtual void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override; + /** + * + * @brief The handle of application not response process. + * + * @param sigMessage Recieve the sig message. + * + */ + virtual void ScheduleANRProcess() override; + private: bool WriteInterfaceToken(MessageParcel &data); static inline BrokerDelegator delegator_; diff --git a/interfaces/innerkits/app_manager/src/appmgr/ability_controller_stub.cpp b/interfaces/innerkits/app_manager/src/appmgr/ability_controller_stub.cpp index e9b3a04d80b..58d345f4867 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/ability_controller_stub.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/ability_controller_stub.cpp @@ -39,7 +39,7 @@ AbilityControllerStub::~AbilityControllerStub() int AbilityControllerStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("AbilityControllerStub::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("AbilityControllerStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = AbilityControllerStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { diff --git a/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_proxy.cpp index 850d6777cc0..13082b503bc 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -391,34 +391,6 @@ void AmsMgrProxy::PrepareTerminate(const sptr &token) HILOG_DEBUG("end"); } -int AmsMgrProxy::CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) -{ - HILOG_DEBUG("start"); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - if (!WriteInterfaceToken(data)) { - return ERR_INVALID_DATA; - } - if (!data.WriteString16(Str8ToStr16(permission)) || !data.WriteInt32(pid) || !data.WriteInt32(uid)) { - HILOG_ERROR("%{public}s, write failed", __func__); - return ERR_INVALID_DATA; - } - sptr remote = Remote(); - if (remote == nullptr) { - HILOG_ERROR("Remote() is NULL"); - return ERR_NULL_OBJECT; - } - auto ret = - remote->SendRequest(static_cast(IAmsMgr::Message::COMPEL_VERIFY_PERMISSION), data, reply, option); - if (ret != NO_ERROR) { - HILOG_WARN("SendRequest is failed, error code: %{public}d", ret); - return ERR_INVALID_DATA; - } - message = Str16ToStr8(reply.ReadString16()); - return reply.ReadInt32(); -} - void AmsMgrProxy::GetRunningProcessInfoByToken( const sptr &token, AppExecFwk::RunningProcessInfo &info) { diff --git a/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_stub.cpp index 71d298be2e6..5fa46f9c13a 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -51,8 +51,6 @@ AmsMgrStub::AmsMgrStub() memberFuncMap_[static_cast(IAmsMgr::Message::KILL_APPLICATION)] = &AmsMgrStub::HandleKillApplication; memberFuncMap_[static_cast(IAmsMgr::Message::ABILITY_ATTACH_TIMEOUT)] = &AmsMgrStub::HandleAbilityAttachTimeOut; - memberFuncMap_[static_cast(IAmsMgr::Message::COMPEL_VERIFY_PERMISSION)] = - &AmsMgrStub::HandleCompelVerifyPermission; memberFuncMap_[static_cast(IAmsMgr::Message::PREPARE_TERMINATE_ABILITY)] = &AmsMgrStub::HandlePrepareTerminate; memberFuncMap_[static_cast(IAmsMgr::Message::KILL_APPLICATION_BYUID)] = @@ -76,7 +74,7 @@ AmsMgrStub::~AmsMgrStub() int AmsMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("AmsMgrStub::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("AmsMgrStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = AmsMgrStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { @@ -232,19 +230,6 @@ int32_t AmsMgrStub::HandleAbilityAttachTimeOut(MessageParcel &data, MessageParce return NO_ERROR; } -int32_t AmsMgrStub::HandleCompelVerifyPermission(MessageParcel &data, MessageParcel &reply) -{ - BYTRACE(BYTRACE_TAG_APP); - auto permission = Str16ToStr8(data.ReadString16()); - auto pid = data.ReadInt32(); - auto uid = data.ReadInt32(); - std::string message; - auto result = CompelVerifyPermission(permission, pid, uid, message); - reply.WriteString16(Str8ToStr16(message)); - reply.WriteInt32(result); - return NO_ERROR; -} - int32_t AmsMgrStub::HandlePrepareTerminate(MessageParcel &data, MessageParcel &reply) { sptr token = data.ReadParcelable(); diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp index ce9ece8a858..7b292e14c6e 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp @@ -277,23 +277,6 @@ void AppMgrClient::PrepareTerminate(const sptr &token) amsService->PrepareTerminate(token); } -int AppMgrClient::CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) -{ - sptr service = iface_cast(remote_); - if (service == nullptr) { - return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; - } - sptr amsService = service->GetAmsMgr(); - if (amsService == nullptr) { - return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; - } - auto result = amsService->CompelVerifyPermission(permission, pid, uid, message); - if (result != ERR_OK) { - return AppMgrResultCode::ERROR_SERVICE_NOT_READY; - } - return AppMgrResultCode::RESULT_OK; -} - /** * Get system memory information. * @param SystemMemoryAttr, memory information. @@ -457,5 +440,16 @@ void AppMgrClient::AttachRenderProcess(const sptr &renderSched service->AttachRenderProcess(renderScheduler->AsObject()); } } + +void AppMgrClient::PostANRTaskByProcessID(const pid_t pid) +{ + sptr service = iface_cast(remote_); + if (service == nullptr) { + HILOG_ERROR("service is nullptr"); + return; + } + + service->PostANRTaskByProcessID(pid); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp index b5726463380..5a00a9768f8 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -651,5 +651,31 @@ void AppMgrProxy::AttachRenderProcess(const sptr &renderScheduler return; } } + +void AppMgrProxy::PostANRTaskByProcessID(const pid_t pid) +{ + HILOG_DEBUG("start"); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteInt32(pid)) { + HILOG_ERROR("parcel WriteInt32 failed"); + return; + } + sptr remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("Remote() is NULL"); + return; + } + int32_t ret = + remote->SendRequest(static_cast(IAppMgr::Message::POST_ANR_TASK_BY_PID), data, reply, option); + if (ret != NO_ERROR) { + HILOG_WARN("SendRequest is failed, error code: %{public}d", ret); + } + HILOG_DEBUG("end"); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp index bad33a92ec4..68361bcd002 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp @@ -76,6 +76,8 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleStartRenderProcess; memberFuncMap_[static_cast(IAppMgr::Message::ATTACH_RENDER_PROCESS)] = &AppMgrStub::HandleAttachRenderProcess; + memberFuncMap_[static_cast(IAppMgr::Message::POST_ANR_TASK_BY_PID)] = + &AppMgrStub::HandlePostANRTaskByProcessID; } AppMgrStub::~AppMgrStub() @@ -85,7 +87,7 @@ AppMgrStub::~AppMgrStub() int AppMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("AppMgrStub::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("AppMgrStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = AppMgrStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { @@ -385,5 +387,12 @@ int32_t AppMgrStub::HandleAttachRenderProcess(MessageParcel &data, MessageParcel AttachRenderProcess(scheduler); return NO_ERROR; } + +int32_t AppMgrStub::HandlePostANRTaskByProcessID(MessageParcel &data, MessageParcel &reply) +{ + auto pid = data.ReadInt32(); + PostANRTaskByProcessID(pid); + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_scheduler_host.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_scheduler_host.cpp index a2aa882fcec..4a9a096ed95 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_scheduler_host.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_scheduler_host.cpp @@ -50,6 +50,8 @@ AppSchedulerHost::AppSchedulerHost() &AppSchedulerHost::HandleScheduleAbilityStage; memberFuncMap_[static_cast(IAppScheduler::Message::SCHEDULE_ACCEPT_WANT)] = &AppSchedulerHost::HandleScheduleAcceptWant; + memberFuncMap_[static_cast(IAppScheduler::Message::SCHEDULE_ANR_PROCESS)] = + &AppSchedulerHost::HandleScheduleANRProcess; } AppSchedulerHost::~AppSchedulerHost() @@ -59,7 +61,7 @@ AppSchedulerHost::~AppSchedulerHost() int AppSchedulerHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("AppSchedulerHost::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("AppSchedulerHost::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = AppSchedulerHost::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { @@ -211,5 +213,12 @@ int32_t AppSchedulerHost::HandleScheduleAcceptWant(MessageParcel &data, MessageP ScheduleAcceptWant(*want, moduleName); return NO_ERROR; } + +int32_t AppSchedulerHost::HandleScheduleANRProcess(MessageParcel &data, MessageParcel &reply) +{ + BYTRACE(BYTRACE_TAG_APP); + ScheduleANRProcess(); + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_scheduler_proxy.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_scheduler_proxy.cpp index 1305571339d..005c8f4e45c 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_scheduler_proxy.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_scheduler_proxy.cpp @@ -337,5 +337,25 @@ void AppSchedulerProxy::ScheduleAcceptWant(const AAFwk::Want &want, const std::s HILOG_WARN("SendRequest is failed, error code: %{public}d", ret); } } + +void AppSchedulerProxy::ScheduleANRProcess() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + return; + } + sptr remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("Remote() is NULL"); + return; + } + int32_t ret = remote->SendRequest( + static_cast(IAppScheduler::Message::SCHEDULE_ANR_PROCESS), data, reply, option); + if (ret != NO_ERROR) { + HILOG_WARN("SendRequest is failed, error code: %{public}d", ret); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_state_callback_host.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_state_callback_host.cpp index 9636dbaf4a2..53187150543 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_state_callback_host.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_state_callback_host.cpp @@ -41,7 +41,7 @@ AppStateCallbackHost::~AppStateCallbackHost() int AppStateCallbackHost::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("AppStateCallbackHost::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("AppStateCallbackHost::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = AppStateCallbackHost::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { diff --git a/interfaces/innerkits/app_manager/src/appmgr/application_state_observer_stub.cpp b/interfaces/innerkits/app_manager/src/appmgr/application_state_observer_stub.cpp index 3bf6e6e6bc6..f2a5ede0472 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/application_state_observer_stub.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/application_state_observer_stub.cpp @@ -52,7 +52,7 @@ ApplicationStateObserverStub::~ApplicationStateObserverStub() int ApplicationStateObserverStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("ApplicationStateObserverStub::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("ApplicationStateObserverStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = ApplicationStateObserverStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { diff --git a/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp b/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp index d2118654f74..018c0291acd 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp @@ -34,7 +34,7 @@ RenderSchedulerHost::~RenderSchedulerHost() int RenderSchedulerHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("RenderSchedulerHost::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("RenderSchedulerHost::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = RenderSchedulerHost::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { diff --git a/interfaces/innerkits/app_manager/src/appmgr/start_specified_ability_response_stub.cpp b/interfaces/innerkits/app_manager/src/appmgr/start_specified_ability_response_stub.cpp index 94ce53749bd..a39e5498890 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/start_specified_ability_response_stub.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/start_specified_ability_response_stub.cpp @@ -65,7 +65,7 @@ int32_t StartSpecifiedAbilityResponseStub::HandleOnTimeoutResponse(MessageParcel int StartSpecifiedAbilityResponseStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("StartSpecifiedAbilityResponseStub::OnReceived, code = %{public}d, flags= %{public}d.", + HILOG_INFO("StartSpecifiedAbilityResponseStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = StartSpecifiedAbilityResponseStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); diff --git a/interfaces/innerkits/form_manager/BUILD.gn b/interfaces/innerkits/form_manager/BUILD.gn index c7e99326ca2..f51ce663afb 100644 --- a/interfaces/innerkits/form_manager/BUILD.gn +++ b/interfaces/innerkits/form_manager/BUILD.gn @@ -49,6 +49,11 @@ ohos_shared_library("form_manager") { "src/provider_connect_stub.cpp", ] + defines = [ + "APP_LOG_TAG = \"FormMgrService\"", + "LOG_DOMAIN = 0xD001120", + ] + public_configs = [ ":formmgr_sdk_config", "${services_path}/formmgr:formmgr_config", diff --git a/interfaces/innerkits/form_manager/include/form_constants.h b/interfaces/innerkits/form_manager/include/form_constants.h index f0e2178af28..fe474794aa6 100644 --- a/interfaces/innerkits/form_manager/include/form_constants.h +++ b/interfaces/innerkits/form_manager/include/form_constants.h @@ -43,6 +43,8 @@ namespace Constants { const std::string SYSTEM_PARAM_FORM_REFRESH_MIN_TIME = "persist.sys.fms.form.refresh.min.time"; const std::string ACTION_UPDATEATTIMER = "form_update_at_timer"; const std::string KEY_WAKEUP_TIME = "wakeUpTime"; + const std::string KEY_WAKEUP_TIME_LEFT = "wakeUpTimeLeft"; + const std::string KEY_WAKEUP_TIME_RIGHT = "wakeUpTimeRight"; const std::string KEY_ACTION_TYPE = "form_update_action_type"; const std::string ABS_CODE_PATH = "/data/app/el1/bundle/public"; const std::string LOCAL_CODE_PATH = "/data/storage/el1/bundle"; diff --git a/interfaces/innerkits/form_manager/include/form_mgr_interface.h b/interfaces/innerkits/form_manager/include/form_mgr_interface.h index f48099b5342..ff805a734f1 100644 --- a/interfaces/innerkits/form_manager/include/form_mgr_interface.h +++ b/interfaces/innerkits/form_manager/include/form_mgr_interface.h @@ -20,6 +20,7 @@ #include "form_info.h" #include "form_js_info.h" #include "form_provider_data.h" +#include "form_state_info.h" #include "ipc_types.h" #include "iremote_broker.h" @@ -182,6 +183,26 @@ public: */ virtual int DistributedDataDeleteForm(const std::string &formId) = 0; + /** + * @brief Delete the given invalid forms. + * @param formIds Indicates the ID of the forms to delete. + * @param callerToken Caller ability token. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int DeleteInvalidForms(const std::vector &formIds, const sptr &callerToken, + int32_t &numFormsDeleted) = 0; + + /** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param callerToken Caller ability token. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int AcquireFormState(const Want &want, const sptr &callerToken, + FormStateInfo &stateInfo) = 0; + /** * @brief Get All FormsInfo. * @param formInfos Return the forms' information of all forms provided. @@ -224,7 +245,6 @@ public: FORM_MGR_EVENT_NOTIFY, FORM_MGR_CHECK_AND_DELETE_INVALID_FORMS, FORM_MGR_SET_NEXT_REFRESH_TIME, - FORM_MGR_ACQUIRE_FORM_STATE, FORM_MGR_NOTIFY_FORM_WHETHER_VISIBLE, FORM_MGR_STORAGE_FORM_INFOS, FORM_MGR_FORM_INFOS_BY_NAME, @@ -235,6 +255,8 @@ public: FORM_MGR_CLEAR_FORM_RECORDS_ST, FORM_MGR_DISTRIBUTED_DATA_ADD_FORM__ST, FORM_MGR_DISTRIBUTED_DATA_DELETE_FORM__ST, + FORM_MGR_DELETE_INVALID_FORMS, + FORM_MGR_ACQUIRE_FORM_STATE, FORM_MGR_GET_ALL_FORMS_INFO, FORM_MGR_GET_FORMS_INFO_BY_APP, FORM_MGR_GET_FORMS_INFO_BY_MODULE, diff --git a/interfaces/innerkits/form_manager/include/form_mgr_proxy.h b/interfaces/innerkits/form_manager/include/form_mgr_proxy.h index f4e48460c2c..3076ea7c723 100644 --- a/interfaces/innerkits/form_manager/include/form_mgr_proxy.h +++ b/interfaces/innerkits/form_manager/include/form_mgr_proxy.h @@ -19,6 +19,7 @@ #include "form_db_info.h" #include "form_info.h" #include "form_mgr_interface.h" +#include "form_state_info.h" #include "iremote_proxy.h" namespace OHOS { @@ -176,6 +177,26 @@ public: */ virtual int DistributedDataDeleteForm(const std::string &formId) override; + /** + * @brief Delete the given invalid forms. + * @param formIds Indicates the ID of the forms to delete. + * @param callerToken Caller ability token. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int DeleteInvalidForms(const std::vector &formIds, const sptr &callerToken, + int32_t &numFormsDeleted) override; + + /** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param callerToken Caller ability token. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int AcquireFormState(const Want &want, const sptr &callerToken, + FormStateInfo &stateInfo) override; + /** * @brief Get All FormsInfo. * @param formInfos Return the forms' information of all forms provided. diff --git a/interfaces/innerkits/form_manager/include/form_mgr_stub.h b/interfaces/innerkits/form_manager/include/form_mgr_stub.h index f2f7bca7e9b..3920bad47ac 100644 --- a/interfaces/innerkits/form_manager/include/form_mgr_stub.h +++ b/interfaces/innerkits/form_manager/include/form_mgr_stub.h @@ -171,6 +171,20 @@ private: * @return Returns ERR_OK on success, others on failure. */ int32_t HandleDistributedDataDeleteForm(MessageParcel &data, MessageParcel &reply); + /** + * @brief Handle DeleteInvalidForms message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t HandleDeleteInvalidForms(MessageParcel &data, MessageParcel &reply); + /** + * @brief Handle AcquireFormState message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t HandleAcquireFormState(MessageParcel &data, MessageParcel &reply); /** * @brief Handle GetAllFormsInfo message. * @param data input param. diff --git a/interfaces/innerkits/form_manager/include/form_provider_interface.h b/interfaces/innerkits/form_manager/include/form_provider_interface.h index 5594a23a0f6..3c304fe5724 100644 --- a/interfaces/innerkits/form_manager/include/form_provider_interface.h +++ b/interfaces/innerkits/form_manager/include/form_provider_interface.h @@ -103,6 +103,15 @@ public: virtual int FireFormEvent(const int64_t formId, const std::string &message, const Want &want, const sptr &callerToken) = 0; + /** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param callerToken Form provider proxy object. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int AcquireState(const Want &wantArg, const Want &want, const sptr &callerToken) = 0; + enum class Message { // ipc id 1-1000 for kit // ipc id 1001-2000 for DMS @@ -127,6 +136,9 @@ public: // ipc id for event notify (3057) FORM_PROVIDER_EVENT_MESSAGE, + + // ipc id for acquiring form state (3058) + FORM_PROVIDER_NOTIFY_STATE_ACQUIRE, }; }; } // namespace AppExecFwk diff --git a/interfaces/innerkits/form_manager/include/form_provider_proxy.h b/interfaces/innerkits/form_manager/include/form_provider_proxy.h index 547aa3295a8..599636bec83 100644 --- a/interfaces/innerkits/form_manager/include/form_provider_proxy.h +++ b/interfaces/innerkits/form_manager/include/form_provider_proxy.h @@ -104,6 +104,14 @@ public: */ virtual int FireFormEvent(const int64_t formId, const std::string &message, const Want &want, const sptr &callerToken) override; + /** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param callerToken Form provider proxy object. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int AcquireState(const Want &wantArg, const Want &want, const sptr &callerToken) override; private: template diff --git a/interfaces/innerkits/form_manager/include/form_provider_stub.h b/interfaces/innerkits/form_manager/include/form_provider_stub.h index 5c0751e96db..4eaabfeaf92 100644 --- a/interfaces/innerkits/form_manager/include/form_provider_stub.h +++ b/interfaces/innerkits/form_manager/include/form_provider_stub.h @@ -94,6 +94,13 @@ private: * @return Returns ERR_OK on success, others on failure. */ int HandleFireFormEvent(MessageParcel &data, MessageParcel &reply); + /** + * @brief handle AcquireState message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int HandleAcquireState(MessageParcel &data, MessageParcel &reply); private: using FormProviderFunc = int32_t (FormProviderStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/innerkits/form_manager/include/form_supply_interface.h b/interfaces/innerkits/form_manager/include/form_supply_interface.h index 9e8ec1562ee..4e3017c4f7b 100644 --- a/interfaces/innerkits/form_manager/include/form_supply_interface.h +++ b/interfaces/innerkits/form_manager/include/form_supply_interface.h @@ -19,6 +19,7 @@ #include #include "form_provider_info.h" +#include "form_state_info.h" #include "ipc_types.h" #include "iremote_broker.h" @@ -51,6 +52,14 @@ public: */ virtual int OnEventHandle(const Want &want) = 0; + /** + * @brief Accept form state from form provider. + * @param state Form state. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int OnAcquireStateResult(FormState state, const Want &want) = 0; + enum class Message { // ipc id 1-1000 for kit // ipc id 1001-2000 for DMS @@ -58,6 +67,7 @@ public: // ipc id for create (3201) TRANSACTION_FORM_ACQUIRED = 3201, TRANSACTION_EVENT_HANDLE, + TRANSACTION_FORM_STATE_ACQUIRED, }; }; } // namespace AppExecFwk diff --git a/interfaces/innerkits/form_manager/include/form_supply_proxy.h b/interfaces/innerkits/form_manager/include/form_supply_proxy.h index e6654a7badd..05c2b7d6486 100644 --- a/interfaces/innerkits/form_manager/include/form_supply_proxy.h +++ b/interfaces/innerkits/form_manager/include/form_supply_proxy.h @@ -48,6 +48,14 @@ public: */ virtual int OnEventHandle(const Want &want) override; + /** + * @brief Accept form state from form provider. + * @param state Form state. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int OnAcquireStateResult(FormState state, const Want &want) override; + private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/interfaces/innerkits/form_manager/include/form_supply_stub.h b/interfaces/innerkits/form_manager/include/form_supply_stub.h index 796012eb146..bf1352c7cb9 100644 --- a/interfaces/innerkits/form_manager/include/form_supply_stub.h +++ b/interfaces/innerkits/form_manager/include/form_supply_stub.h @@ -56,6 +56,13 @@ private: * @return Returns ERR_OK on success, others on failure. */ int HandleOnEventHandle(MessageParcel &data, MessageParcel &reply); + /** + * @brief handle OnAcquireStateResult message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int HandleOnAcquireStateResult(MessageParcel &data, MessageParcel &reply); private: using FormSupplyFunc = int32_t (FormSupplyStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/innerkits/form_manager/src/form_host_stub.cpp b/interfaces/innerkits/form_manager/src/form_host_stub.cpp index fcbcfa72e52..e7ddc4da67f 100644 --- a/interfaces/innerkits/form_manager/src/form_host_stub.cpp +++ b/interfaces/innerkits/form_manager/src/form_host_stub.cpp @@ -47,7 +47,7 @@ FormHostStub::~FormHostStub() */ int FormHostStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("FormHostStub::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("FormHostStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = FormHostStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { diff --git a/interfaces/innerkits/form_manager/src/form_mgr_proxy.cpp b/interfaces/innerkits/form_manager/src/form_mgr_proxy.cpp index ba46c343a8b..4a2b2db18e6 100644 --- a/interfaces/innerkits/form_manager/src/form_mgr_proxy.cpp +++ b/interfaces/innerkits/form_manager/src/form_mgr_proxy.cpp @@ -717,6 +717,98 @@ int FormMgrProxy::DistributedDataDeleteForm(const std::string &formId) return reply.ReadInt32(); } +/** + * @brief Delete the given invalid forms. + * @param formIds Indicates the ID of the forms to delete. + * @param callerToken Caller ability token. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrProxy::DeleteInvalidForms(const std::vector &formIds, const sptr &callerToken, + int32_t &numFormsDeleted) +{ + MessageParcel data; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s, failed to write interface token", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteInt64Vector(formIds)) { + HILOG_ERROR("%{public}s, failed to write vector formIds", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteParcelable(callerToken)) { + HILOG_ERROR("%{public}s, failed to write callerToken", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + MessageParcel reply; + MessageOption option; + int error = Remote()->SendRequest( + static_cast( + IFormMgr::Message::FORM_MGR_DELETE_INVALID_FORMS), + data, + reply, + option); + if (error != ERR_OK) { + HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + return ERR_APPEXECFWK_FORM_SEND_FMS_MSG; + } + + int32_t result = reply.ReadInt32(); + if (result != ERR_OK) { + HILOG_ERROR("%{public}s, failed to read reply result", __func__); + return result; + } + numFormsDeleted = reply.ReadInt32(); + return result; +} + +/** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param callerToken Caller ability token. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrProxy::AcquireFormState(const Want &want, const sptr &callerToken, FormStateInfo &stateInfo) +{ + MessageParcel data; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s, failed to write interface token", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteParcelable(&want)) { + HILOG_ERROR("%{public}s, failed to write want", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteParcelable(callerToken)) { + HILOG_ERROR("%{public}s, failed to write callerToken", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + MessageParcel reply; + MessageOption option; + int error = Remote()->SendRequest( + static_cast( + IFormMgr::Message::FORM_MGR_ACQUIRE_FORM_STATE), + data, + reply, + option); + if (error != ERR_OK) { + HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + return ERR_APPEXECFWK_FORM_SEND_FMS_MSG; + } + + int32_t result = reply.ReadInt32(); + if (result != ERR_OK) { + HILOG_ERROR("%{public}s, failed to read reply result", __func__); + return result; + } + stateInfo.state = (FormState)reply.ReadInt32(); + stateInfo.want = want; + return result; +} + /** * @brief Get All FormsInfo. * @param formInfos Return the forms' information of all forms provided. diff --git a/interfaces/innerkits/form_manager/src/form_mgr_stub.cpp b/interfaces/innerkits/form_manager/src/form_mgr_stub.cpp index 9c02fe52f6f..843aa33716b 100644 --- a/interfaces/innerkits/form_manager/src/form_mgr_stub.cpp +++ b/interfaces/innerkits/form_manager/src/form_mgr_stub.cpp @@ -76,6 +76,10 @@ FormMgrStub::FormMgrStub() &FormMgrStub::HandleDistributedDataAddForm; memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_DISTRIBUTED_DATA_DELETE_FORM__ST)] = &FormMgrStub::HandleDistributedDataDeleteForm; + memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_DELETE_INVALID_FORMS)] = + &FormMgrStub::HandleDeleteInvalidForms; + memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_ACQUIRE_FORM_STATE)] = + &FormMgrStub::HandleAcquireFormState; memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_GET_ALL_FORMS_INFO)] = &FormMgrStub::HandleGetAllFormsInfo; memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_APP)] = @@ -98,7 +102,7 @@ FormMgrStub::~FormMgrStub() */ int FormMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("FormMgrStub::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("FormMgrStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = FormMgrStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { @@ -496,6 +500,70 @@ int32_t FormMgrStub::HandleDistributedDataDeleteForm(MessageParcel &data, Messag return result; } +/** + * @brief Handle DeleteInvalidForms message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ +int32_t FormMgrStub::HandleDeleteInvalidForms(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("%{public}s called.", __func__); + std::vector formIds; + if (!data.ReadInt64Vector(&formIds)) { + HILOG_ERROR("%{public}s, failed to ReadInt64Vector", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + sptr callerToken = data.ReadParcelable(); + if (callerToken == nullptr) { + HILOG_ERROR("%{public}s, failed to ReadParcelable", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + int32_t numFormsDeleted = 0; + int32_t result = DeleteInvalidForms(formIds, callerToken, numFormsDeleted); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("%{public}s, failed to write result", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!reply.WriteInt32(numFormsDeleted)) { + HILOG_ERROR("%{public}s, failed to write numFormsDeleted", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + return result; +} + +/** + * @brief Handle AcquireFormState message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ +int32_t FormMgrStub::HandleAcquireFormState(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("%{public}s called.", __func__); + FormStateInfo stateInfo {}; + std::unique_ptr want(data.ReadParcelable()); + if (want == nullptr) { + HILOG_ERROR("%{public}s, failed to ReadParcelable want", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + sptr callerToken = data.ReadParcelable(); + if (callerToken == nullptr) { + HILOG_ERROR("%{public}s, failed to ReadParcelable", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + int32_t result = AcquireFormState(*want, callerToken, stateInfo); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("%{public}s, failed to write result", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!reply.WriteInt32((int32_t)stateInfo.state)) { + HILOG_ERROR("%{public}s, failed to write state", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + return result; +} + /** * @brief Handle GetAllFormsInfo message. * @param data input param. diff --git a/interfaces/innerkits/form_manager/src/form_provider_proxy.cpp b/interfaces/innerkits/form_manager/src/form_provider_proxy.cpp index 5dc73b84992..58731c6d076 100644 --- a/interfaces/innerkits/form_manager/src/form_provider_proxy.cpp +++ b/interfaces/innerkits/form_manager/src/form_provider_proxy.cpp @@ -348,6 +348,50 @@ int FormProviderProxy::FireFormEvent( return ERR_OK; } +/** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param callerToken Form provider proxy object. + * @return Returns ERR_OK on success, others on failure. + */ +int FormProviderProxy::AcquireState(const Want &wantArg, const Want &want, const sptr &callerToken) +{ + int error; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s, failed to write interface token", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + if (!data.WriteParcelable(&wantArg)) { + HILOG_ERROR("%{public}s, failed to write wantArg", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteParcelable(&want)) { + HILOG_ERROR("%{public}s, failed to write want", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteParcelable(callerToken)) { + HILOG_ERROR("%{public}s, failed to write callerToken", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + error = Remote()->SendRequest( + static_cast(IFormProvider::Message::FORM_PROVIDER_NOTIFY_STATE_ACQUIRE), + data, + reply, + option); + if (error != ERR_OK) { + HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + return error; + } + return ERR_OK; +} + template int FormProviderProxy::GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos) { diff --git a/interfaces/innerkits/form_manager/src/form_provider_stub.cpp b/interfaces/innerkits/form_manager/src/form_provider_stub.cpp index aae547f49c4..0a5f5c24568 100644 --- a/interfaces/innerkits/form_manager/src/form_provider_stub.cpp +++ b/interfaces/innerkits/form_manager/src/form_provider_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "form_provider_stub.h" #include "appexecfwk_errors.h" #include "app_scheduler_interface.h" #include "errors.h" -#include "form_provider_stub.h" #include "hilog_wrapper.h" #include "ipc_skeleton.h" #include "ipc_types.h" @@ -39,6 +39,8 @@ FormProviderStub::FormProviderStub() &FormProviderStub::HandleNotifyFormCastTempForm; memberFuncMap_[static_cast(IFormProvider::Message::FORM_PROVIDER_EVENT_MESSAGE)] = &FormProviderStub::HandleFireFormEvent; + memberFuncMap_[static_cast(IFormProvider::Message::FORM_PROVIDER_NOTIFY_STATE_ACQUIRE)] = + &FormProviderStub::HandleAcquireState; } FormProviderStub::~FormProviderStub() @@ -54,7 +56,7 @@ FormProviderStub::~FormProviderStub() */ int FormProviderStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("FormProviderStub::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("FormProviderStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = FormProviderStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { @@ -264,5 +266,32 @@ int FormProviderStub::HandleFireFormEvent(MessageParcel &data, MessageParcel &re reply.WriteInt32(result); return result; } +/** + * @brief handle AcquireState message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ +int FormProviderStub::HandleAcquireState(MessageParcel &data, MessageParcel &reply) +{ + std::unique_ptr wantArg(data.ReadParcelable()); + if (!wantArg) { + HILOG_ERROR("%{public}s fail, ReadParcelable failed", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + std::unique_ptr want(data.ReadParcelable()); + if (!want) { + HILOG_ERROR("%{public}s fail, ReadParcelable failed", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + sptr client = data.ReadParcelable(); + if (client == nullptr) { + HILOG_ERROR("%{public}s, failed to ReadParcelable", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + int32_t result = AcquireState(*wantArg, *want, client); + reply.WriteInt32(result); + return result; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/form_manager/src/form_supply_proxy.cpp b/interfaces/innerkits/form_manager/src/form_supply_proxy.cpp index 5993db4b6e9..5ddddca5d93 100644 --- a/interfaces/innerkits/form_manager/src/form_supply_proxy.cpp +++ b/interfaces/innerkits/form_manager/src/form_supply_proxy.cpp @@ -91,6 +91,42 @@ int FormSupplyProxy::OnEventHandle(const Want& want) return error; } +/** + * @brief Accept form state from form provider. + * @param state Form state. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ +int FormSupplyProxy::OnAcquireStateResult(FormState state, const Want &want) +{ + MessageParcel data; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s, failed to WriteInterfaceToken", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteParcelable(&want)) { + HILOG_ERROR("%{public}s, failed to write want", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteInt32((int32_t) state)) { + HILOG_ERROR("%{public}s, failed to write form state", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + MessageParcel reply; + MessageOption option; + int error = Remote()->SendRequest( + static_cast(IFormSupply::Message::TRANSACTION_FORM_STATE_ACQUIRED), + data, + reply, + option); + if (error != ERR_OK) { + HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + } + return error; +} + + template int FormSupplyProxy::GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos) { diff --git a/interfaces/innerkits/form_manager/src/form_supply_stub.cpp b/interfaces/innerkits/form_manager/src/form_supply_stub.cpp index fbebe28689e..7e9cf0eb02a 100644 --- a/interfaces/innerkits/form_manager/src/form_supply_stub.cpp +++ b/interfaces/innerkits/form_manager/src/form_supply_stub.cpp @@ -29,6 +29,8 @@ FormSupplyStub::FormSupplyStub() &FormSupplyStub::HandleOnAcquire; memberFuncMap_[static_cast(IFormSupply::Message::TRANSACTION_EVENT_HANDLE)] = &FormSupplyStub::HandleOnEventHandle; + memberFuncMap_[static_cast(IFormSupply::Message::TRANSACTION_FORM_STATE_ACQUIRED)] = + &FormSupplyStub::HandleOnAcquireStateResult; } FormSupplyStub::~FormSupplyStub() @@ -44,7 +46,7 @@ FormSupplyStub::~FormSupplyStub() */ int FormSupplyStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("FormSupplyStub::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + HILOG_INFO("FormSupplyStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = FormSupplyStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { @@ -120,5 +122,25 @@ int FormSupplyStub::HandleOnEventHandle(MessageParcel &data, MessageParcel &repl reply.WriteInt32(result); return result; } + +/** + * @brief handle OnAcquireStateResult message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ +int FormSupplyStub::HandleOnAcquireStateResult(MessageParcel &data, MessageParcel &reply) +{ + std::unique_ptr want(data.ReadParcelable()); + if (!want) { + HILOG_ERROR("%{public}s, failed to ReadParcelable", __func__); + reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + auto state = (FormState) data.ReadInt32(); + int32_t result = OnAcquireStateResult(state, *want); + reply.WriteInt32(result); + return result; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/runtime/include/runtime.h b/interfaces/innerkits/runtime/include/runtime.h index 3c63341403d..506791c09b0 100644 --- a/interfaces/innerkits/runtime/include/runtime.h +++ b/interfaces/innerkits/runtime/include/runtime.h @@ -34,6 +34,7 @@ public: std::string codePath; std::string packagePath; std::shared_ptr eventRunner; + bool loadAce = true; }; static std::unique_ptr Create(const Options& options); diff --git a/interfaces/innerkits/want/include/ohos/aafwk/content/want.h b/interfaces/innerkits/want/include/ohos/aafwk/content/want.h index 8cbea1e7b33..7ce18829cb9 100644 --- a/interfaces/innerkits/want/include/ohos/aafwk/content/want.h +++ b/interfaces/innerkits/want/include/ohos/aafwk/content/want.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -234,7 +234,7 @@ public: /** * @description: Converts a Want into a URI string containing a representation of it. * @param want Indicates the want description.--Want. - * @return Returns a encoding URI string describing the Want object. + * @return Returns an encoding URI string describing the Want object. */ std::string WantToUri(Want &want); diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/BUILD.gn b/interfaces/kits/napi/aafwk/app/ability_delegator/BUILD.gn index 78ba8c79bbe..a54f4a3bd87 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/BUILD.gn +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/BUILD.gn @@ -38,6 +38,7 @@ ohos_shared_library("abilitydelegatorregistry") { external_deps = [ "ability_base:base", + "ability_base:want", "ability_runtime:ability_manager", "ability_runtime:abilitykit_native", "ability_runtime:runtime", diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp index bd308b1c061..df8f11b7cb6 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp @@ -21,11 +21,20 @@ #include "js_ability_delegator_utils.h" #include "js_context_utils.h" #include "js_runtime_utils.h" +#include "napi_common_want.h" #include "napi_remote_object.h" #include "shell_cmd_result.h" namespace OHOS { namespace AbilityDelegatorJs { +struct AbilityTokenBox { + sptr token_; +}; + +struct ShellCmdResultBox { + std::unique_ptr shellCmdResult_; +}; + constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; constexpr size_t INDEX_ZERO = 0; @@ -79,6 +88,12 @@ NativeValue *JSAbilityDelegator::GetCurrentTopAbility(NativeEngine *engine, Nati return (me != nullptr) ? me->OnGetCurrentTopAbility(*engine, *info) : nullptr; } +NativeValue *JSAbilityDelegator::StartAbility(NativeEngine *engine, NativeCallbackInfo *info) +{ + JSAbilityDelegator *me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnStartAbility(*engine, *info) : nullptr; +} + NativeValue *JSAbilityDelegator::DoAbilityForeground(NativeEngine *engine, NativeCallbackInfo *info) { JSAbilityDelegator *me = CheckParamsAndGetThis(engine, info); @@ -188,21 +203,26 @@ NativeValue *JSAbilityDelegator::OnWaitAbilityMonitor(NativeEngine &engine, Nati return engine.CreateUndefined(); } + auto abilityTokenBox = std::make_shared(); + AsyncTask::ExecuteCallback execute = [monitor, timeout, opt, abilityTokenBox]() { + HILOG_INFO("OnWaitAbilityMonitor AsyncTask ExecuteCallback is called"); + auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); + if (!delegator) { + HILOG_ERROR("OnWaitAbilityMonitor AsyncTask ExecuteCallback, Invalid delegator"); + return; + } + + if (opt.hasTimeoutPara) { + abilityTokenBox->token_ = delegator->WaitAbilityMonitor(monitor, timeout); + } else { + abilityTokenBox->token_ = delegator->WaitAbilityMonitor(monitor); + } + }; + AsyncTask::CompleteCallback complete = - [monitor, timeout, opt, this](NativeEngine &engine, AsyncTask &task, int32_t status) { - HILOG_INFO("OnWaitAbilityMonitor AsyncTask is called"); - auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); - if (!delegator) { - task.Reject(engine, CreateJsError(engine, ERROR, "waitAbilityMonitor failed.")); - return; - } - sptr remoteObject = nullptr; - if (opt.hasTimeoutPara) { - remoteObject = delegator->WaitAbilityMonitor(monitor, timeout); - } else { - remoteObject = delegator->WaitAbilityMonitor(monitor); - } - NativeValue *ability = CreateAbilityObject(engine, remoteObject); + [abilityTokenBox, this](NativeEngine &engine, AsyncTask &task, int32_t status) { + HILOG_INFO("OnWaitAbilityMonitor AsyncTask CompleteCallback is called"); + NativeValue *ability = CreateAbilityObject(engine, abilityTokenBox->token_); if (ability) { task.Resolve(engine, ability); } else { @@ -219,7 +239,7 @@ NativeValue *JSAbilityDelegator::OnWaitAbilityMonitor(NativeEngine &engine, Nati NativeValue *result = nullptr; AsyncTask::Schedule( - engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + engine, CreateAsyncTaskWithLastParam(engine, lastParam, std::move(execute), std::move(complete), &result)); return result; } @@ -263,16 +283,21 @@ NativeValue *JSAbilityDelegator::OnExecuteShellCommand(NativeEngine &engine, Nat return engine.CreateUndefined(); } - AsyncTask::CompleteCallback complete = [cmd, timeoutSecs](NativeEngine &engine, AsyncTask &task, int32_t status) { - HILOG_INFO("OnExecuteShellCommand AsyncTask is called"); + auto shellCmdResultBox = std::make_shared(); + AsyncTask::ExecuteCallback execute = [cmd, timeoutSecs, shellCmdResultBox]() { + HILOG_INFO("OnExecuteShellCommand AsyncTask ExecuteCallback is called"); auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); if (!delegator) { - task.Reject(engine, CreateJsError(engine, ERROR, "executeShellCommand failed.")); + HILOG_ERROR("OnExecuteShellCommand AsyncTask ExecuteCallback, Invalid delegator"); return; } - std::unique_ptr shellResult = - delegator->ExecuteShellCommand(cmd, timeoutSecs); - NativeValue *result = CreateJsShellCmdResult(engine, shellResult); + + shellCmdResultBox->shellCmdResult_ = delegator->ExecuteShellCommand(cmd, timeoutSecs); + }; + + AsyncTask::CompleteCallback complete = [shellCmdResultBox](NativeEngine &engine, AsyncTask &task, int32_t status) { + HILOG_INFO("OnExecuteShellCommand AsyncTask CompleteCallback is called"); + NativeValue *result = CreateJsShellCmdResult(engine, shellCmdResultBox->shellCmdResult_); if (result) { task.Resolve(engine, result); } else { @@ -289,7 +314,7 @@ NativeValue *JSAbilityDelegator::OnExecuteShellCommand(NativeEngine &engine, Nat NativeValue *result = nullptr; AsyncTask::Schedule( - engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + engine, CreateAsyncTaskWithLastParam(engine, lastParam, std::move(execute), std::move(complete), &result)); return result; } @@ -370,6 +395,38 @@ NativeValue *JSAbilityDelegator::OnGetCurrentTopAbility(NativeEngine &engine, Na return result; } +NativeValue *JSAbilityDelegator::OnStartAbility(NativeEngine &engine, NativeCallbackInfo &info) +{ + HILOG_INFO("enter, argc = %{public}d", static_cast(info.argc)); + + AAFwk::Want want; + if (!ParseStartAbilityPara(engine, info, want)) { + HILOG_ERROR("Parse startAbility parameters failed"); + return engine.CreateUndefined(); + } + + AsyncTask::CompleteCallback complete = [want](NativeEngine &engine, AsyncTask &task, int32_t status) { + HILOG_INFO("OnStartAbility AsyncTask is called"); + auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); + if (!delegator) { + task.Reject(engine, CreateJsError(engine, ERROR, "startAbility failed.")); + return; + } + int result = delegator->StartAbility(want); + if (result) { + task.Reject(engine, CreateJsError(engine, result, "startAbility failed.")); + } else { + task.Resolve(engine, engine.CreateNull()); + } + }; + + NativeValue *lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr; + NativeValue *result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + NativeValue *JSAbilityDelegator::OnDoAbilityForeground(NativeEngine &engine, NativeCallbackInfo &info) { HILOG_INFO("enter, argc = %{public}d", static_cast(info.argc)); @@ -539,8 +596,8 @@ NativeValue *JSAbilityDelegator::CreateAbilityObject(NativeEngine &engine, const return objValue; } -void JSAbilityDelegator::AbilityLifecycleStateToJs(const AbilityDelegator::AbilityState &lifeState, - AbilityLifecycleState &abilityLifeState) +void JSAbilityDelegator::AbilityLifecycleStateToJs( + const AbilityDelegator::AbilityState &lifeState, AbilityLifecycleState &abilityLifeState) { HILOG_INFO("enter and lifeState = %{public}d", (int32_t)lifeState); switch (lifeState) { @@ -678,8 +735,8 @@ NativeValue *JSAbilityDelegator::ParseExecuteShellCommandPara( return engine.CreateNull(); } -NativeValue *JSAbilityDelegator::ParseAbilityCommonPara(NativeEngine &engine, NativeCallbackInfo &info, - sptr &remoteObject) +NativeValue *JSAbilityDelegator::ParseAbilityCommonPara( + NativeEngine &engine, NativeCallbackInfo &info, sptr &remoteObject) { HILOG_INFO("enter"); if (info.argc < ARGC_ONE) { @@ -701,8 +758,32 @@ NativeValue *JSAbilityDelegator::ParseAbilityCommonPara(NativeEngine &engine, Na return engine.CreateNull(); } -NativeValue *JSAbilityDelegator::ParseFinishTestPara(NativeEngine &engine, - NativeCallbackInfo &info, std::string &msg, int64_t &code) +NativeValue *JSAbilityDelegator::ParseStartAbilityPara( + NativeEngine &engine, NativeCallbackInfo &info, AAFwk::Want &want) +{ + HILOG_INFO("enter"); + if (info.argc < ARGC_ONE) { + HILOG_ERROR("Incorrect number of parameters"); + return nullptr; + } + + if (!OHOS::AppExecFwk::UnwrapWant( + reinterpret_cast(&engine), reinterpret_cast(info.argv[INDEX_ZERO]), want)) { + HILOG_ERROR("Parse want parameter failed"); + return nullptr; + } + + if (info.argc > ARGC_ONE) { + if (info.argv[INDEX_ONE]->TypeOf() != NativeValueType::NATIVE_FUNCTION) { + HILOG_ERROR("Parse StartAbility callback parameters failed"); + return nullptr; + } + } + return engine.CreateNull(); +} + +NativeValue *JSAbilityDelegator::ParseFinishTestPara( + NativeEngine &engine, NativeCallbackInfo &info, std::string &msg, int64_t &code) { HILOG_INFO("enter"); if (info.argc < ARGC_TWO) { diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h index 80e9c9a2b66..27523675812 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h @@ -21,6 +21,7 @@ #include "ability_monitor.h" #include "js_ability_delegator_registry.h" #include "js_ability_monitor.h" +#include "want.h" namespace OHOS { namespace AbilityDelegatorJs { @@ -43,6 +44,7 @@ public: static NativeValue *GetAppContext(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue *GetAbilityState(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue *GetCurrentTopAbility(NativeEngine *engine, NativeCallbackInfo *info); + static NativeValue *StartAbility(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue *DoAbilityForeground(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue *DoAbilityBackground(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue *FinishTest(NativeEngine *engine, NativeCallbackInfo *info); @@ -56,6 +58,7 @@ private: NativeValue *OnGetAppContext(NativeEngine &engine, NativeCallbackInfo &info); NativeValue *OnGetAbilityState(NativeEngine &engine, NativeCallbackInfo &info); NativeValue *OnGetCurrentTopAbility(NativeEngine &engine, NativeCallbackInfo &info); + NativeValue *OnStartAbility(NativeEngine &engine, NativeCallbackInfo &info); NativeValue *OnDoAbilityForeground(NativeEngine &engine, NativeCallbackInfo &info); NativeValue *OnDoAbilityBackground(NativeEngine &engine, NativeCallbackInfo &info); NativeValue *OnFinishTest(NativeEngine &engine, NativeCallbackInfo &info); @@ -77,7 +80,8 @@ private: NativeEngine &engine, NativeCallbackInfo &info, std::string &cmd, TimeoutCallback &opt, int64_t &timeout); NativeValue *ParseAbilityCommonPara( NativeEngine &engine, NativeCallbackInfo &info, sptr &remoteObject); - NativeValue *ParseAbilityCommonRemainingPara(NativeEngine &engine, NativeCallbackInfo &info); + NativeValue *ParseStartAbilityPara( + NativeEngine &engine, NativeCallbackInfo &info, AAFwk::Want &want); NativeValue *ParseFinishTestPara(NativeEngine &engine, NativeCallbackInfo &info, std::string &msg, int64_t &code); }; } // namespace AbilityDelegatorJs diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_utils.cpp b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_utils.cpp index 8675af78628..548a179ab30 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_utils.cpp +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_utils.cpp @@ -44,6 +44,7 @@ NativeValue *CreateJsAbilityDelegator(NativeEngine &engine) BindNativeFunction(engine, *object, "getAppContext", JSAbilityDelegator::GetAppContext); BindNativeFunction(engine, *object, "getAbilityState", JSAbilityDelegator::GetAbilityState); BindNativeFunction(engine, *object, "getCurrentTopAbility", JSAbilityDelegator::GetCurrentTopAbility); + BindNativeFunction(engine, *object, "startAbility", JSAbilityDelegator::StartAbility); BindNativeFunction(engine, *object, "doAbilityForeground", JSAbilityDelegator::DoAbilityForeground); BindNativeFunction(engine, *object, "doAbilityBackground", JSAbilityDelegator::DoAbilityBackground); BindNativeFunction(engine, *object, "print", JSAbilityDelegator::Print); diff --git a/interfaces/kits/napi/aafwk/dataShare/BUILD.gn b/interfaces/kits/napi/aafwk/dataShare/BUILD.gn index 7a198f290fb..91055a5981b 100644 --- a/interfaces/kits/napi/aafwk/dataShare/BUILD.gn +++ b/interfaces/kits/napi/aafwk/dataShare/BUILD.gn @@ -20,6 +20,7 @@ ohos_shared_library("datashare") { "//foundation/aafwk/standard/frameworks/kits/ability/native/include", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/dataShare", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common", + "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_rdb/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_dataability/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_rdb/include", diff --git a/interfaces/kits/napi/aafwk/featureAbility/BUILD.gn b/interfaces/kits/napi/aafwk/featureAbility/BUILD.gn index 55b5667da00..059c975da36 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/BUILD.gn +++ b/interfaces/kits/napi/aafwk/featureAbility/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -11,12 +11,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -# import("//build/config/ohos/rules.gni") import("//build/ohos.gni") ohos_shared_library("featureability") { include_dirs = [ "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/featureAbility", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common", + "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_rdb/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_dataability/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_rdb/include", @@ -26,8 +26,6 @@ ohos_shared_library("featureability") { sources = [ "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/src/js_utils.cpp", - - #"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_resultset/napi_resultset_predicates.cpp", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_dataability/src/napi_data_ability_predicates.cpp", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_rdb/src/napi_result_set.cpp", "feature_ability.cpp", diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_context.cpp b/interfaces/kits/napi/aafwk/featureAbility/napi_context.cpp index abcd15a5d77..8a28940ada6 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_context.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_context.cpp @@ -609,80 +609,6 @@ napi_value NAPI_GetCtxAbilityInfo(napi_env env, napi_callback_info info) return NAPI_GetAbilityInfoCommon(env, info, AbilityType::PAGE); } -void CanRequestPermissionExecuteCallback(napi_env env, void *data) -{ - HILOG_INFO("%{public}s called.", __func__); - - AsyncJSCallbackInfo *asyncCallbackInfo = (AsyncJSCallbackInfo *)data; - if (asyncCallbackInfo == nullptr) { - HILOG_INFO("%{public}s called. asyncCallbackInfo is null", __func__); - return; - } - - asyncCallbackInfo->error_code = NAPI_ERR_NO_ERROR; - asyncCallbackInfo->native_data.data_type = NVT_NONE; - - if (asyncCallbackInfo->ability == nullptr) { - asyncCallbackInfo->error_code = NAPI_ERR_ACE_ABILITY; - return; - } - - std::string permission(asyncCallbackInfo->param.paramArgs.GetStringValue("permission")); - asyncCallbackInfo->native_data.data_type = NVT_BOOL; - asyncCallbackInfo->native_data.bool_value = asyncCallbackInfo->ability->CanRequestPermission(permission); -} - -napi_value NAPI_CanRequestPermissionWrap(napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo) -{ - HILOG_INFO("%{public}s called.", __func__); - size_t argc = ARGS_MAX_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value jsthis = 0; - void *data = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data)); - - if (!UnwrapParamVerifySelfPermission(env, argc, args, asyncCallbackInfo)) { - HILOG_INFO("%{public}s called. Invoke UnwrapParamVerifySelfPermission fail", __func__); - return nullptr; - } - - AsyncParamEx asyncParamEx; - if (asyncCallbackInfo->cbInfo.callback != nullptr) { - HILOG_INFO("%{public}s called. asyncCallback.", __func__); - asyncParamEx.resource = "NAPI_CanRequestPermissionCallback"; - asyncParamEx.execute = CanRequestPermissionExecuteCallback; - asyncParamEx.complete = CompleteAsyncCallbackWork; - - return ExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx); - } else { - HILOG_INFO("%{public}s called. promise.", __func__); - asyncParamEx.resource = "NAPI_CanRequestPermissionPromise"; - asyncParamEx.execute = CanRequestPermissionExecuteCallback; - asyncParamEx.complete = CompletePromiseCallbackWork; - - return ExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx); - } -} - -napi_value NAPI_CanRequestPermission(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - - AsyncJSCallbackInfo *asyncCallbackInfo = CreateAsyncJSCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - HILOG_INFO("%{public}s called. Invoke CreateAsyncJSCallbackInfo failed.", __func__); - return WrapVoidToJS(env); - } - - napi_value rev = NAPI_CanRequestPermissionWrap(env, info, asyncCallbackInfo); - if (rev == nullptr) { - FreeAsyncJSCallbackInfo(&asyncCallbackInfo); - rev = WrapVoidToJS(env); - } - return rev; -} - bool UnwrapVerifyPermissionOptions(napi_env env, napi_value argv, AsyncJSCallbackInfo *asyncCallbackInfo) { HILOG_INFO("%{public}s called", __func__); @@ -833,156 +759,6 @@ napi_value NAPI_VerifyPermission(napi_env env, napi_callback_info info) return rev; } -void VerifyCallingPermissionExecuteCallback(napi_env env, void *data) -{ - HILOG_INFO("%{public}s called.", __func__); - - AsyncJSCallbackInfo *asyncCallbackInfo = (AsyncJSCallbackInfo *)data; - if (asyncCallbackInfo == nullptr) { - HILOG_INFO("%{public}s called. asyncCallbackInfo is null", __func__); - return; - } - - asyncCallbackInfo->error_code = NAPI_ERR_NO_ERROR; - asyncCallbackInfo->native_data.data_type = NVT_NONE; - - if (asyncCallbackInfo->ability == nullptr) { - asyncCallbackInfo->error_code = NAPI_ERR_ACE_ABILITY; - return; - } - - asyncCallbackInfo->native_data.data_type = NVT_INT32; - std::string permission(asyncCallbackInfo->param.paramArgs.GetStringValue("permission").c_str()); - asyncCallbackInfo->native_data.int32_value = asyncCallbackInfo->ability->VerifyCallingPermission(permission); -} - -napi_value NAPI_VerifyCallingPermissionWrap( - napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo) -{ - HILOG_INFO("%{public}s called.", __func__); - size_t argc = ARGS_MAX_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value jsthis = 0; - void *data = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data)); - - if (!UnwrapParamVerifySelfPermission(env, argc, args, asyncCallbackInfo)) { - HILOG_INFO("%{public}s called. Invoke UnwrapParamVerifySelfPermission fail", __func__); - return nullptr; - } - - AsyncParamEx asyncParamEx; - if (asyncCallbackInfo->cbInfo.callback != nullptr) { - HILOG_INFO("%{public}s called. asyncCallback.", __func__); - asyncParamEx.resource = "NAPI_VerifyCallingPermissionCallback"; - asyncParamEx.execute = VerifyCallingPermissionExecuteCallback; - asyncParamEx.complete = CompleteAsyncCallbackWork; - - return ExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx); - } else { - HILOG_INFO("%{public}s called. promise.", __func__); - asyncParamEx.resource = "NAPI_VerifyCallingPermissionPromise"; - asyncParamEx.execute = VerifyCallingPermissionExecuteCallback; - asyncParamEx.complete = CompletePromiseCallbackWork; - - return ExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx); - } -} - -napi_value NAPI_VerifyCallingPermission(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - - AsyncJSCallbackInfo *asyncCallbackInfo = CreateAsyncJSCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - HILOG_INFO("%{public}s called. Invoke CreateAsyncJSCallbackInfo failed.", __func__); - return WrapVoidToJS(env); - } - - napi_value rev = NAPI_VerifyCallingPermissionWrap(env, info, asyncCallbackInfo); - if (rev == nullptr) { - FreeAsyncJSCallbackInfo(&asyncCallbackInfo); - rev = WrapVoidToJS(env); - } - return rev; -} - -void VerifyCallingOrSelfPermissionExecuteCallback(napi_env env, void *data) -{ - HILOG_INFO("%{public}s called.", __func__); - - AsyncJSCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_INFO("%{public}s called. asyncCallbackInfo is null", __func__); - return; - } - - asyncCallbackInfo->error_code = NAPI_ERR_NO_ERROR; - asyncCallbackInfo->native_data.data_type = NVT_NONE; - - if (asyncCallbackInfo->ability == nullptr) { - asyncCallbackInfo->error_code = NAPI_ERR_ACE_ABILITY; - return; - } - - asyncCallbackInfo->native_data.data_type = NVT_INT32; - std::string permission(asyncCallbackInfo->param.paramArgs.GetStringValue("permission").c_str()); - asyncCallbackInfo->native_data.int32_value = asyncCallbackInfo->ability->VerifyCallingOrSelfPermission(permission); -} - -napi_value NAPI_VerifyCallingOrSelfPermissionWrap( - napi_env env, napi_callback_info info, AsyncJSCallbackInfo *asyncCallbackInfo) -{ - HILOG_INFO("%{public}s called.", __func__); - size_t argc = ARGS_MAX_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value jsthis = 0; - void *data = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data)); - - if (!UnwrapParamVerifySelfPermission(env, argc, args, asyncCallbackInfo)) { - HILOG_INFO("%{public}s called. Invoke UnwrapParamVerifySelfPermission fail", __func__); - return nullptr; - } - - AsyncParamEx asyncParamEx; - if (asyncCallbackInfo->cbInfo.callback != nullptr) { - HILOG_INFO("%{public}s called. asyncCallback.", __func__); - asyncParamEx.resource = "NAPI_VerifyCallingOrSelfPermissionCallback"; - asyncParamEx.execute = VerifyCallingOrSelfPermissionExecuteCallback; - asyncParamEx.complete = CompleteAsyncCallbackWork; - - return ExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx); - } else { - HILOG_INFO("%{public}s called. promise.", __func__); - asyncParamEx.resource = "NAPI_VerifyCallingOrSelfPermissionPromise"; - asyncParamEx.execute = VerifyCallingOrSelfPermissionExecuteCallback; - asyncParamEx.complete = CompletePromiseCallbackWork; - - return ExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx); - } -} - -napi_value NAPI_VerifyCallingOrSelfPermission(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - - AsyncJSCallbackInfo *asyncCallbackInfo = CreateAsyncJSCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - HILOG_INFO("%{public}s called. Invoke CreateAsyncJSCallbackInfo failed.", __func__); - return WrapVoidToJS(env); - } - - napi_value rev = NAPI_VerifyCallingOrSelfPermissionWrap(env, info, asyncCallbackInfo); - if (rev == nullptr) { - FreeAsyncJSCallbackInfo(&asyncCallbackInfo); - rev = WrapVoidToJS(env); - } - return rev; -} - /** * @brief GetApplicationInfo asynchronous processing function. * @@ -1640,7 +1416,7 @@ void GetElementNameExecuteCB(napi_env env, void *data) } std::shared_ptr elementName = elementNameCB->cbBase.ability->GetElementName(); - if (elementNameCB != nullptr) { + if (elementName != nullptr) { elementNameCB->deviceId = elementName->GetDeviceID(); elementNameCB->bundleName = elementName->GetBundleName(); elementNameCB->abilityName = elementName->GetAbilityName(); @@ -3069,10 +2845,7 @@ napi_value ContextPermissionInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("verifySelfPermission", NAPI_VerifySelfPermission), DECLARE_NAPI_FUNCTION("requestPermissionsFromUser", NAPI_RequestPermissionsFromUser), DECLARE_NAPI_FUNCTION("getBundleName", NAPI_GetBundleName), - DECLARE_NAPI_FUNCTION("canRequestPermission", NAPI_CanRequestPermission), DECLARE_NAPI_FUNCTION("verifyPermission", NAPI_VerifyPermission), - DECLARE_NAPI_FUNCTION("verifyCallingPermission", NAPI_VerifyCallingPermission), - DECLARE_NAPI_FUNCTION("verifyCallingOrSelfPermission", NAPI_VerifyCallingOrSelfPermission), DECLARE_NAPI_FUNCTION("getApplicationInfo", NAPI_GetApplicationInfo), DECLARE_NAPI_FUNCTION("getProcessInfo", NAPI_GetProcessInfo), DECLARE_NAPI_FUNCTION("getElementName", NAPI_GetElementName), diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_operation.cpp b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_operation.cpp index 8174f23870f..98945710552 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_operation.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_operation.cpp @@ -94,17 +94,13 @@ napi_value BuildDataAbilityOperation( valuesBucket->Clear(); napi_value jsValueBucket = GetPropertyValueByPropertyName(env, param, "valuesBucket", napi_object); UnwrapValuesBucket(valuesBucket, env, jsValueBucket); - if (valuesBucket != nullptr) { - builder->WithValuesBucket(valuesBucket); - } + builder->WithValuesBucket(valuesBucket); // get dataAbilityPredicates property std::shared_ptr predicates = std::make_shared(); napi_value jsPredicates = GetPropertyValueByPropertyName(env, param, "predicates", napi_object); UnwrapDataAbilityPredicates(*predicates, env, jsPredicates); - if (predicates != nullptr) { - builder->WithPredicates(predicates); - } + builder->WithPredicates(predicates); // get expectedcount property int expectedCount = 0; diff --git a/interfaces/kits/napi/aafwk/formHost/BUILD.gn b/interfaces/kits/napi/aafwk/formHost/BUILD.gn index 4420134c137..519f48499f5 100644 --- a/interfaces/kits/napi/aafwk/formHost/BUILD.gn +++ b/interfaces/kits/napi/aafwk/formHost/BUILD.gn @@ -19,6 +19,7 @@ ohos_shared_library("formhost_napi") { "//foundation/aafwk/standard/frameworks/kits/ability/native/include", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/formHost", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/formUtil", + "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", ] @@ -32,11 +33,13 @@ ohos_shared_library("formhost_napi") { "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/formUtil:formutil_napi", + "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", "//foundation/ace/napi:ace_napi", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", ] external_deps = [ + "ability_base:want", "ability_runtime:ability_manager", "ability_runtime:runtime", "hiviewdfx_hilog_native:libhilog", diff --git a/interfaces/kits/napi/aafwk/formHost/napi_form_host.cpp b/interfaces/kits/napi/aafwk/formHost/napi_form_host.cpp index 27651243cee..dfe84e55b07 100644 --- a/interfaces/kits/napi/aafwk/formHost/napi_form_host.cpp +++ b/interfaces/kits/napi/aafwk/formHost/napi_form_host.cpp @@ -25,6 +25,8 @@ #include "napi_form_util.h" #include "napi/native_api.h" #include "napi/native_node_api.h" +#include "napi_common_util.h" +#include "napi_common_want.h" #include "runtime.h" using namespace OHOS; @@ -1943,6 +1945,834 @@ napi_value NAPI_CheckFMSReady(napi_env env, napi_callback_info info) } } +static void InnerDeleteInvalidForms(napi_env env, AsyncDeleteInvalidFormsCallbackInfo *const asyncCallbackInfo) +{ + HILOG_DEBUG("%{public}s called.", __func__); + OHOS::AppExecFwk::Ability *ability = asyncCallbackInfo->ability; + ErrCode ret = ability->DeleteInvalidForms(asyncCallbackInfo->formIds, asyncCallbackInfo->numFormsDeleted); + asyncCallbackInfo->result = ret; + if (ret != ERR_OK) { + asyncCallbackInfo->numFormsDeleted = 0; + } + HILOG_DEBUG("%{public}s, end", __func__); +} + +napi_value DeleteInvalidFormsCallback(napi_env env, AsyncDeleteInvalidFormsCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncDeleteInvalidFormsCallbackInfo *) data; + InnerDeleteInvalidForms(env, asyncCallbackInfo); + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncDeleteInvalidFormsCallbackInfo *) data; + + if (asyncCallbackInfo->callback != nullptr) { + napi_value callback; + napi_value callbackValues[ARGS_SIZE_TWO] = {nullptr}; + napi_create_int32(env, asyncCallbackInfo->result, &callbackValues[0]); + napi_create_int32(env, asyncCallbackInfo->numFormsDeleted, &callbackValues[1]); + + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_TWO, callbackValues, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value DeleteInvalidFormsPromise(napi_env env, AsyncDeleteInvalidFormsCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncDeleteInvalidFormsCallbackInfo *) data; + InnerDeleteInvalidForms(env, asyncCallbackInfo); + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncDeleteInvalidFormsCallbackInfo *) data; + napi_value result; + napi_create_int32(env, asyncCallbackInfo->numFormsDeleted, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: deleteInvalidForms + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_DeleteInvalidForms(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_TWO) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); + + uint32_t numForms = 0; + NAPI_CALL(env, napi_get_array_length(env, argv[0], &numForms)); + NAPI_ASSERT(env, numForms > 0, "The arguments[0] value of deleteInvalidForms is incorrect, this array is empty."); + + std::vector formIds {}; + napi_valuetype valueType; + for (size_t i = 0; i < numForms; i++) { + napi_value napiFormId; + napi_get_element(env, argv[0], i, &napiFormId); + + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, napiFormId, &valueType)); + NAPI_ASSERT(env, valueType == napi_string, "The arguments[0] value type of deleteInvalidForms \ + is incorrect, expected type is string."); + + std::string strFormId = GetStringFromNAPI(env, napiFormId); + int64_t formIdValue; + bool isConversionSucceeded = ConvertStringToInt64(strFormId, formIdValue); + NAPI_ASSERT(env, isConversionSucceeded, "The arguments[0] type of deleteInvalidForms is incorrect,\ + expected type is string and the content must be numeric,\ + value range is: 0x8000000000000000~0x7FFFFFFFFFFFFFFF."); + formIds.push_back(formIdValue); + } + + auto *asyncCallbackInfo = new AsyncDeleteInvalidFormsCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .formIds = formIds, + .numFormsDeleted = 0, + }; + + if (argc == ARGS_SIZE_TWO) { + // Check the value type of the arguments + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The arguments[1] type of deleteInvalidForms \ + is incorrect, expected type is function."); + napi_create_reference(env, argv[1], REF_COUNT, &asyncCallbackInfo->callback); + return DeleteInvalidFormsCallback(env, asyncCallbackInfo); + } else { + return DeleteInvalidFormsPromise(env, asyncCallbackInfo); + } +} + +static void InnerAcquireFormState(napi_env env, AsyncAcquireFormStateCallbackInfo *const asyncCallbackInfo) +{ + HILOG_DEBUG("%{public}s called.", __func__); + OHOS::AppExecFwk::Ability *ability = asyncCallbackInfo->ability; + ErrCode ret = ability->AcquireFormState(asyncCallbackInfo->want, asyncCallbackInfo->stateInfo); + asyncCallbackInfo->result = ret; + HILOG_DEBUG("%{public}s, end", __func__); +} + +napi_value ParseFormStateInfo(napi_env env, FormStateInfo &stateInfo) +{ + napi_value formStateInfoObject = nullptr; + napi_create_object(env, &formStateInfoObject); + napi_value jsValue = WrapWant(env, stateInfo.want); + SetPropertyValueByPropertyName(env, formStateInfoObject, "want", jsValue); + napi_value formState = nullptr; + napi_create_int32(env, (int32_t) stateInfo.state, &formState); + SetPropertyValueByPropertyName(env, formStateInfoObject, "formState", formState); + + return formStateInfoObject; +} + +napi_value AcquireFormStateCallback(napi_env env, AsyncAcquireFormStateCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncAcquireFormStateCallbackInfo *) data; + InnerAcquireFormState(env, asyncCallbackInfo); + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncAcquireFormStateCallbackInfo *) data; + if (asyncCallbackInfo->callback != nullptr) { + napi_value callback; + napi_value callbackValues[ARGS_SIZE_TWO] = {nullptr}; + napi_create_int32(env, asyncCallbackInfo->result, &callbackValues[0]); + callbackValues[1] = ParseFormStateInfo(env, asyncCallbackInfo->stateInfo); + + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_TWO, callbackValues, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value AcquireFormStatePromise(napi_env env, AsyncAcquireFormStateCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncAcquireFormStateCallbackInfo *) data; + InnerAcquireFormState(env, asyncCallbackInfo); + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncAcquireFormStateCallbackInfo *) data; + napi_value result = ParseFormStateInfo(env, asyncCallbackInfo->stateInfo); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: acquireFormState + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_AcquireFormState(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_TWO) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[0], &valueType)); + NAPI_ASSERT(env, valueType == napi_object, + "The arguments[0] type of acquireFormState is incorrect, expected type is object."); + + auto *asyncCallbackInfo = new AsyncAcquireFormStateCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .want = {}, + .stateInfo = {}, + }; + + bool parseResult = UnwrapWant(env, argv[0], asyncCallbackInfo->want); + if (!parseResult) { + HILOG_ERROR("%{public}s, failed to parse want.", __func__); + delete asyncCallbackInfo; + return nullptr; + } + + if (argc == ARGS_SIZE_TWO) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The arguments[1] type of acquireFormState \ + is incorrect, expected type is function."); + napi_create_reference(env, argv[1], REF_COUNT, &asyncCallbackInfo->callback); + return AcquireFormStateCallback(env, asyncCallbackInfo); + } else { + return AcquireFormStatePromise(env, asyncCallbackInfo); + } +} + +napi_value RegisterFormUninstallObserverCallback(napi_env env, + AsyncFormUninstallObserverCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + + if (asyncCallbackInfo->callback != nullptr) { + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_value callback; + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_ONE, &result, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value RegisterFormUninstallObserverPromise(napi_env env, + AsyncFormUninstallObserverCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: on + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_RegisterFormUninstallObserver(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_TWO) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[0], &valueType)); + NAPI_ASSERT(env, valueType == napi_string, + "The arguments[0] type of on is incorrect, expected type is string."); + + auto *asyncCallbackInfo = new AsyncFormUninstallObserverCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .result = 0, + }; + + if (argc == ARGS_SIZE_TWO) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The arguments[1] type of on \ + is incorrect, expected type is function."); + napi_create_reference(env, argv[1], REF_COUNT, &asyncCallbackInfo->callback); + return RegisterFormUninstallObserverCallback(env, asyncCallbackInfo); + } else { + return RegisterFormUninstallObserverPromise(env, asyncCallbackInfo); + } +} + + +napi_value UnregisterFormUninstallObserverCallback(napi_env env, + AsyncFormUninstallObserverCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + + if (asyncCallbackInfo->callback != nullptr) { + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_value callback; + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_ONE, &result, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value UnregisterFormUninstallObserverPromise(napi_env env, + AsyncFormUninstallObserverCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: off + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_UnregisterFormUninstallObserver(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_TWO) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[0], &valueType)); + NAPI_ASSERT(env, valueType == napi_string, + "The arguments[0] type of off is incorrect, expected type is string."); + + auto *asyncCallbackInfo = new AsyncFormUninstallObserverCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .result = 0, + }; + + if (argc == ARGS_SIZE_TWO) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The arguments[1] type of off \ + is incorrect, expected type is function."); + napi_create_reference(env, argv[1], REF_COUNT, &asyncCallbackInfo->callback); + return UnregisterFormUninstallObserverCallback(env, asyncCallbackInfo); + } else { + return UnregisterFormUninstallObserverPromise(env, asyncCallbackInfo); + } +} + +napi_value NotifyFormsVisibleCallback(napi_env env, AsyncNotifyFormsVisibleCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsVisibleCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsVisibleCallbackInfo *) data; + + if (asyncCallbackInfo->callback != nullptr) { + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_value callback; + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_ONE, &result, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value NotifyFormsVisiblePromise(napi_env env, AsyncNotifyFormsVisibleCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsVisibleCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsVisibleCallbackInfo *) data; + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: notifyFormsVisible + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_NotifyFormsVisible(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_THREE; + napi_value argv[ARGS_SIZE_THREE] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_THREE) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + + uint32_t numForms = 0; + NAPI_CALL(env, napi_get_array_length(env, argv[0], &numForms)); + NAPI_ASSERT(env, numForms > 0, "The type of arg 0 is incorrect, this array is empty."); + + std::vector formIds {}; + napi_valuetype valueType; + for (size_t i = 0; i < numForms; i++) { + napi_value napiFormId; + napi_get_element(env, argv[0], i, &napiFormId); + + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, napiFormId, &valueType)); + NAPI_ASSERT(env, valueType == napi_string, "The type of arg 0 is incorrect, expected type is string."); + + std::string strFormId = GetStringFromNAPI(env, napiFormId); + int64_t formIdValue; + bool isConversionSucceeded = ConvertStringToInt64(strFormId, formIdValue); + NAPI_ASSERT(env, isConversionSucceeded, "The arguments[0] type of notifyFormsVisible is incorrect, expected " + "type is string and the content must be numeric,value range is: 0x8000000000000000~0x7FFFFFFFFFFFFFFF."); + formIds.push_back(formIdValue); + } + + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_boolean, "The type of arg 1 is incorrect, expected type is boolean."); + auto *asyncCallbackInfo = new AsyncNotifyFormsVisibleCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .formIds = formIds, + .isVisible = false, + }; + napi_get_value_bool(env, argv[1], &asyncCallbackInfo->isVisible); + + if (argc == ARGS_SIZE_THREE) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_TWO], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The type of arg 2 is incorrect, expected type is function."); + napi_create_reference(env, argv[ARGS_SIZE_TWO], REF_COUNT, &asyncCallbackInfo->callback); + return NotifyFormsVisibleCallback(env, asyncCallbackInfo); + } else { + return NotifyFormsVisiblePromise(env, asyncCallbackInfo); + } +} + +napi_value NotifyFormsEnableUpdateCallback(napi_env env, + AsyncNotifyFormsEnableUpdateCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsEnableUpdateCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsEnableUpdateCallbackInfo *) data; + + if (asyncCallbackInfo->callback != nullptr) { + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_value callback; + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_ONE, &result, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value NotifyFormsEnableUpdatePromise(napi_env env, + AsyncNotifyFormsEnableUpdateCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsEnableUpdateCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsEnableUpdateCallbackInfo *) data; + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: notifyFormsEnableUpdate + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_NotifyFormsEnableUpdate(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_THREE; + napi_value argv[ARGS_SIZE_THREE] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_THREE) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + + uint32_t numForms = 0; + NAPI_CALL(env, napi_get_array_length(env, argv[0], &numForms)); + NAPI_ASSERT(env, numForms > 0, "The type of arg 0 is incorrect, this array is empty."); + + std::vector formIds {}; + napi_valuetype valueType; + for (size_t i = 0; i < numForms; i++) { + napi_value napiFormId; + napi_get_element(env, argv[0], i, &napiFormId); + + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, napiFormId, &valueType)); + NAPI_ASSERT(env, valueType == napi_string, "The type of arg 0 is incorrect, expected type is string."); + + std::string strFormId = GetStringFromNAPI(env, napiFormId); + int64_t formIdValue; + bool isConversionSucceeded = ConvertStringToInt64(strFormId, formIdValue); + NAPI_ASSERT(env, isConversionSucceeded, "The type of arg 0 is incorrect, expected type is string and " + "the content must be numeric, value range is: 0x8000000000000000~0x7FFFFFFFFFFFFFFF."); + formIds.push_back(formIdValue); + } + + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_boolean, "The type of arg 1 is incorrect, expected type is boolean."); + auto *asyncCallbackInfo = new AsyncNotifyFormsEnableUpdateCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .formIds = formIds, + .isEnableUpdate = false, + }; + napi_get_value_bool(env, argv[1], &asyncCallbackInfo->isEnableUpdate); + + if (argc == ARGS_SIZE_THREE) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_TWO], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The type of arg 2 is incorrect, expected type is function."); + napi_create_reference(env, argv[ARGS_SIZE_TWO], REF_COUNT, &asyncCallbackInfo->callback); + return NotifyFormsEnableUpdateCallback(env, asyncCallbackInfo); + } else { + return NotifyFormsEnableUpdatePromise(env, asyncCallbackInfo); + } +} + /** * @brief Call native kit function: GetAllFormsInfo * diff --git a/interfaces/kits/napi/aafwk/formHost/napi_form_host.h b/interfaces/kits/napi/aafwk/formHost/napi_form_host.h index ff8c627e79a..a369afa3bbb 100644 --- a/interfaces/kits/napi/aafwk/formHost/napi_form_host.h +++ b/interfaces/kits/napi/aafwk/formHost/napi_form_host.h @@ -112,6 +112,59 @@ struct AsyncCheckFMSReadyCallbackInfo { bool isFMSReady; }; +struct AsyncDeleteInvalidFormsCallbackInfo { + napi_env env; + OHOS::AppExecFwk::Ability *ability; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + std::vector formIds; + int numFormsDeleted; + int result; +}; + +struct AsyncAcquireFormStateCallbackInfo { + napi_env env; + OHOS::AppExecFwk::Ability *ability; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + OHOS::AAFwk::Want want; + OHOS::AppExecFwk::FormStateInfo stateInfo; + int result; +}; + +struct AsyncFormUninstallObserverCallbackInfo { + napi_env env; + OHOS::AppExecFwk::Ability *ability; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + int result; +}; + +struct AsyncNotifyFormsVisibleCallbackInfo { + napi_env env; + OHOS::AppExecFwk::Ability *ability; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + std::vector formIds; + bool isVisible; + int result; +}; + +struct AsyncNotifyFormsEnableUpdateCallbackInfo { + napi_env env; + OHOS::AppExecFwk::Ability *ability; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + std::vector formIds; + bool isEnableUpdate; + int result; +}; + struct AsyncGetFormsInfoCallbackInfo { napi_env env; OHOS::AppExecFwk::Ability *ability; @@ -133,6 +186,12 @@ napi_value NAPI_NotifyInvisibleForms(napi_env env, napi_callback_info info); napi_value NAPI_EnableFormsUpdate(napi_env env, napi_callback_info info); napi_value NAPI_DisableFormsUpdate(napi_env env, napi_callback_info info); napi_value NAPI_CheckFMSReady(napi_env env, napi_callback_info info); +napi_value NAPI_DeleteInvalidForms(napi_env env, napi_callback_info info); +napi_value NAPI_AcquireFormState(napi_env env, napi_callback_info info); +napi_value NAPI_RegisterFormUninstallObserver(napi_env env, napi_callback_info info); +napi_value NAPI_UnregisterFormUninstallObserver(napi_env env, napi_callback_info info); +napi_value NAPI_NotifyFormsVisible(napi_env env, napi_callback_info info); +napi_value NAPI_NotifyFormsEnableUpdate(napi_env env, napi_callback_info info); napi_value NAPI_GetAllFormsInfo(napi_env env, napi_callback_info info); napi_value NAPI_GetFormsInfo(napi_env env, napi_callback_info info); diff --git a/interfaces/kits/napi/aafwk/formHost/native_module.cpp b/interfaces/kits/napi/aafwk/formHost/native_module.cpp index 6a971acc4ed..4c9213c4a91 100644 --- a/interfaces/kits/napi/aafwk/formHost/native_module.cpp +++ b/interfaces/kits/napi/aafwk/formHost/native_module.cpp @@ -46,6 +46,12 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("enableFormsUpdate", NAPI_EnableFormsUpdate), DECLARE_NAPI_FUNCTION("disableFormsUpdate", NAPI_DisableFormsUpdate), DECLARE_NAPI_FUNCTION("isSystemReady", NAPI_CheckFMSReady), + DECLARE_NAPI_FUNCTION("deleteInvalidForms", NAPI_DeleteInvalidForms), + DECLARE_NAPI_FUNCTION("acquireFormState", NAPI_AcquireFormState), + DECLARE_NAPI_FUNCTION("on", NAPI_RegisterFormUninstallObserver), + DECLARE_NAPI_FUNCTION("off", NAPI_UnregisterFormUninstallObserver), + DECLARE_NAPI_FUNCTION("notifyFormsVisible", NAPI_NotifyFormsVisible), + DECLARE_NAPI_FUNCTION("notifyFormsEnableUpdate", NAPI_NotifyFormsEnableUpdate), DECLARE_NAPI_FUNCTION("getAllFormsInfo", NAPI_GetAllFormsInfo), DECLARE_NAPI_FUNCTION("getFormsInfo", NAPI_GetFormsInfo), }; diff --git a/interfaces/kits/napi/aafwk/formManager/BUILD.gn b/interfaces/kits/napi/aafwk/formManager/BUILD.gn index ced9913d691..194c8aefa62 100644 --- a/interfaces/kits/napi/aafwk/formManager/BUILD.gn +++ b/interfaces/kits/napi/aafwk/formManager/BUILD.gn @@ -13,15 +13,20 @@ import("//build/ohos.gni") ohos_shared_library("formmanager") { - include_dirs = - [ "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/formManager" ] + include_dirs = [ + "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/formManager", + "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common", + ] sources = [ "napi_form_manager.cpp", "native_module.cpp", ] - deps = [ "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native" ] + deps = [ + "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", + "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", + ] external_deps = [ "ability_base:base", diff --git a/interfaces/kits/napi/aafwk/formManager/napi_form_manager.cpp b/interfaces/kits/napi/aafwk/formManager/napi_form_manager.cpp index 6432c26697d..d3834fdf5e9 100644 --- a/interfaces/kits/napi/aafwk/formManager/napi_form_manager.cpp +++ b/interfaces/kits/napi/aafwk/formManager/napi_form_manager.cpp @@ -22,6 +22,8 @@ #include "napi/native_api.h" #include "napi/native_node_api.h" +#include "napi_common_util.h" +#include "napi_common_want.h" #include "runtime.h" using namespace OHOS; @@ -2638,6 +2640,834 @@ napi_value NAPI_CheckFMSReady(napi_env env, napi_callback_info info) } } +static void InnerDeleteInvalidForms(napi_env env, AsyncDeleteInvalidFormsCallbackInfo *const asyncCallbackInfo) +{ + HILOG_DEBUG("%{public}s called.", __func__); + OHOS::AppExecFwk::Ability *ability = asyncCallbackInfo->ability; + ErrCode ret = ability->DeleteInvalidForms(asyncCallbackInfo->formIds, asyncCallbackInfo->numFormsDeleted); + asyncCallbackInfo->result = ret; + if (ret != ERR_OK) { + asyncCallbackInfo->numFormsDeleted = 0; + } + HILOG_DEBUG("%{public}s, end", __func__); +} + +napi_value DeleteInvalidFormsCallback(napi_env env, AsyncDeleteInvalidFormsCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncDeleteInvalidFormsCallbackInfo *) data; + InnerDeleteInvalidForms(env, asyncCallbackInfo); + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncDeleteInvalidFormsCallbackInfo *) data; + + if (asyncCallbackInfo->callback != nullptr) { + napi_value callback; + napi_value callbackValues[ARGS_SIZE_TWO] = {nullptr}; + napi_create_int32(env, asyncCallbackInfo->result, &callbackValues[0]); + napi_create_int32(env, asyncCallbackInfo->numFormsDeleted, &callbackValues[1]); + + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_TWO, callbackValues, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value DeleteInvalidFormsPromise(napi_env env, AsyncDeleteInvalidFormsCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncDeleteInvalidFormsCallbackInfo *) data; + InnerDeleteInvalidForms(env, asyncCallbackInfo); + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncDeleteInvalidFormsCallbackInfo *) data; + napi_value result; + napi_create_int32(env, asyncCallbackInfo->numFormsDeleted, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: deleteInvalidForms + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_DeleteInvalidForms(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_TWO) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); + + uint32_t numForms = 0; + NAPI_CALL(env, napi_get_array_length(env, argv[0], &numForms)); + NAPI_ASSERT(env, numForms > 0, "The arguments[0] value of deleteInvalidForms is incorrect, this array is empty."); + + std::vector formIds {}; + napi_valuetype valueType; + for (size_t i = 0; i < numForms; i++) { + napi_value napiFormId; + napi_get_element(env, argv[0], i, &napiFormId); + + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, napiFormId, &valueType)); + NAPI_ASSERT(env, valueType == napi_string, "The arguments[0] value type of deleteInvalidForms \ + is incorrect, expected type is string."); + + std::string strFormId = GetStringFromNAPI(env, napiFormId); + int64_t formIdValue; + bool isConversionSucceeded = ConvertStringToInt64(strFormId, formIdValue); + NAPI_ASSERT(env, isConversionSucceeded, "The arguments[0] type of deleteInvalidForms is incorrect,\ + expected type is string and the content must be numeric,\ + value range is: 0x8000000000000000~0x7FFFFFFFFFFFFFFF."); + formIds.push_back(formIdValue); + } + + auto *asyncCallbackInfo = new AsyncDeleteInvalidFormsCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .formIds = formIds, + .numFormsDeleted = 0, + }; + + if (argc == ARGS_SIZE_TWO) { + // Check the value type of the arguments + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The arguments[1] type of deleteInvalidForms \ + is incorrect, expected type is function."); + napi_create_reference(env, argv[1], REF_COUNT, &asyncCallbackInfo->callback); + return DeleteInvalidFormsCallback(env, asyncCallbackInfo); + } else { + return DeleteInvalidFormsPromise(env, asyncCallbackInfo); + } +} + +static void InnerAcquireFormState(napi_env env, AsyncAcquireFormStateCallbackInfo *const asyncCallbackInfo) +{ + HILOG_DEBUG("%{public}s called.", __func__); + OHOS::AppExecFwk::Ability *ability = asyncCallbackInfo->ability; + ErrCode ret = ability->AcquireFormState(asyncCallbackInfo->want, asyncCallbackInfo->stateInfo); + asyncCallbackInfo->result = ret; + HILOG_DEBUG("%{public}s, end", __func__); +} + +napi_value ParseFormStateInfo(napi_env env, FormStateInfo &stateInfo) +{ + napi_value formStateInfoObject = nullptr; + napi_create_object(env, &formStateInfoObject); + napi_value jsValue = WrapWant(env, stateInfo.want); + SetPropertyValueByPropertyName(env, formStateInfoObject, "want", jsValue); + napi_value formState = nullptr; + napi_create_int32(env, (int32_t) stateInfo.state, &formState); + SetPropertyValueByPropertyName(env, formStateInfoObject, "formState", formState); + + return formStateInfoObject; +} + +napi_value AcquireFormStateCallback(napi_env env, AsyncAcquireFormStateCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncAcquireFormStateCallbackInfo *) data; + InnerAcquireFormState(env, asyncCallbackInfo); + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncAcquireFormStateCallbackInfo *) data; + if (asyncCallbackInfo->callback != nullptr) { + napi_value callback; + napi_value callbackValues[ARGS_SIZE_TWO] = {nullptr}; + napi_create_int32(env, asyncCallbackInfo->result, &callbackValues[0]); + callbackValues[1] = ParseFormStateInfo(env, asyncCallbackInfo->stateInfo); + + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_TWO, callbackValues, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value AcquireFormStatePromise(napi_env env, AsyncAcquireFormStateCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncAcquireFormStateCallbackInfo *) data; + InnerAcquireFormState(env, asyncCallbackInfo); + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncAcquireFormStateCallbackInfo *) data; + napi_value result = ParseFormStateInfo(env, asyncCallbackInfo->stateInfo); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: acquireFormState + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_AcquireFormState(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_TWO) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[0], &valueType)); + NAPI_ASSERT(env, valueType == napi_object, + "The arguments[0] type of acquireFormState is incorrect, expected type is object."); + + auto *asyncCallbackInfo = new AsyncAcquireFormStateCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .want = {}, + .stateInfo = {}, + }; + + bool parseResult = UnwrapWant(env, argv[0], asyncCallbackInfo->want); + if (!parseResult) { + HILOG_ERROR("%{public}s, failed to parse want.", __func__); + delete asyncCallbackInfo; + return nullptr; + } + + if (argc == ARGS_SIZE_TWO) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The arguments[1] type of acquireFormState \ + is incorrect, expected type is function."); + napi_create_reference(env, argv[1], REF_COUNT, &asyncCallbackInfo->callback); + return AcquireFormStateCallback(env, asyncCallbackInfo); + } else { + return AcquireFormStatePromise(env, asyncCallbackInfo); + } +} + +napi_value RegisterFormUninstallObserverCallback(napi_env env, + AsyncFormUninstallObserverCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + + if (asyncCallbackInfo->callback != nullptr) { + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_value callback; + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_ONE, &result, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value RegisterFormUninstallObserverPromise(napi_env env, + AsyncFormUninstallObserverCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: on + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_RegisterFormUninstallObserver(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_TWO) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[0], &valueType)); + NAPI_ASSERT(env, valueType == napi_string, + "The arguments[0] type of on is incorrect, expected type is string."); + + auto *asyncCallbackInfo = new AsyncFormUninstallObserverCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .result = 0, + }; + + if (argc == ARGS_SIZE_TWO) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The arguments[1] type of on \ + is incorrect, expected type is function."); + napi_create_reference(env, argv[1], REF_COUNT, &asyncCallbackInfo->callback); + return RegisterFormUninstallObserverCallback(env, asyncCallbackInfo); + } else { + return RegisterFormUninstallObserverPromise(env, asyncCallbackInfo); + } +} + + +napi_value UnregisterFormUninstallObserverCallback(napi_env env, + AsyncFormUninstallObserverCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + + if (asyncCallbackInfo->callback != nullptr) { + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_value callback; + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_ONE, &result, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value UnregisterFormUninstallObserverPromise(napi_env env, + AsyncFormUninstallObserverCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncFormUninstallObserverCallbackInfo *) data; + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: off + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_UnregisterFormUninstallObserver(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_TWO) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[0], &valueType)); + NAPI_ASSERT(env, valueType == napi_string, + "The arguments[0] type of off is incorrect, expected type is string."); + + auto *asyncCallbackInfo = new AsyncFormUninstallObserverCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .result = 0, + }; + + if (argc == ARGS_SIZE_TWO) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The arguments[1] type of off \ + is incorrect, expected type is function."); + napi_create_reference(env, argv[1], REF_COUNT, &asyncCallbackInfo->callback); + return UnregisterFormUninstallObserverCallback(env, asyncCallbackInfo); + } else { + return UnregisterFormUninstallObserverPromise(env, asyncCallbackInfo); + } +} + +napi_value NotifyFormsVisibleCallback(napi_env env, AsyncNotifyFormsVisibleCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsVisibleCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsVisibleCallbackInfo *) data; + + if (asyncCallbackInfo->callback != nullptr) { + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_value callback; + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_ONE, &result, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value NotifyFormsVisiblePromise(napi_env env, AsyncNotifyFormsVisibleCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsVisibleCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsVisibleCallbackInfo *) data; + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: notifyFormsVisible + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_NotifyFormsVisible(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_THREE; + napi_value argv[ARGS_SIZE_THREE] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_THREE) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + + uint32_t numForms = 0; + NAPI_CALL(env, napi_get_array_length(env, argv[0], &numForms)); + NAPI_ASSERT(env, numForms > 0, "The type of arg 0 is incorrect, this array is empty."); + + std::vector formIds {}; + napi_valuetype valueType; + for (size_t i = 0; i < numForms; i++) { + napi_value napiFormId; + napi_get_element(env, argv[0], i, &napiFormId); + + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, napiFormId, &valueType)); + NAPI_ASSERT(env, valueType == napi_string, "The type of arg 0 is incorrect, expected type is string."); + + std::string strFormId = GetStringFromNAPI(env, napiFormId); + int64_t formIdValue; + bool isConversionSucceeded = ConvertStringToInt64(strFormId, formIdValue); + NAPI_ASSERT(env, isConversionSucceeded, "The arguments[0] type of notifyFormsVisible is incorrect, expected " + "type is string and the content must be numeric,value range is: 0x8000000000000000~0x7FFFFFFFFFFFFFFF."); + formIds.push_back(formIdValue); + } + + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_boolean, "The type of arg 1 is incorrect, expected type is boolean."); + auto *asyncCallbackInfo = new AsyncNotifyFormsVisibleCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .formIds = formIds, + .isVisible = false, + }; + napi_get_value_bool(env, argv[1], &asyncCallbackInfo->isVisible); + + if (argc == ARGS_SIZE_THREE) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_TWO], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The type of arg 2 is incorrect, expected type is function."); + napi_create_reference(env, argv[ARGS_SIZE_TWO], REF_COUNT, &asyncCallbackInfo->callback); + return NotifyFormsVisibleCallback(env, asyncCallbackInfo); + } else { + return NotifyFormsVisiblePromise(env, asyncCallbackInfo); + } +} + +napi_value NotifyFormsEnableUpdateCallback(napi_env env, + AsyncNotifyFormsEnableUpdateCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, asyncCallback.", __func__); + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsEnableUpdateCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsEnableUpdateCallbackInfo *) data; + + if (asyncCallbackInfo->callback != nullptr) { + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_value callback; + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_SIZE_ONE, &result, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResut(env, 1); +} + +napi_value NotifyFormsEnableUpdatePromise(napi_env env, + AsyncNotifyFormsEnableUpdateCallbackInfo *const asyncCallbackInfo) +{ + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise runnning", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsEnableUpdateCallbackInfo *) data; + asyncCallbackInfo->result = 0; + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + auto *asyncCallbackInfo = (AsyncNotifyFormsEnableUpdateCallbackInfo *) data; + napi_value result; + napi_create_int32(env, asyncCallbackInfo->result, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *) asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; +} + +/** + * @brief The implementation of Node-API interface: notifyFormsEnableUpdate + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_NotifyFormsEnableUpdate(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_THREE; + napi_value argv[ARGS_SIZE_THREE] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc > ARGS_SIZE_THREE) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + + uint32_t numForms = 0; + NAPI_CALL(env, napi_get_array_length(env, argv[0], &numForms)); + NAPI_ASSERT(env, numForms > 0, "The type of arg 0 is incorrect, this array is empty."); + + std::vector formIds {}; + napi_valuetype valueType; + for (size_t i = 0; i < numForms; i++) { + napi_value napiFormId; + napi_get_element(env, argv[0], i, &napiFormId); + + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, napiFormId, &valueType)); + NAPI_ASSERT(env, valueType == napi_string, "The type of arg 0 is incorrect, expected type is string."); + + std::string strFormId = GetStringFromNAPI(env, napiFormId); + int64_t formIdValue; + bool isConversionSucceeded = ConvertStringToInt64(strFormId, formIdValue); + NAPI_ASSERT(env, isConversionSucceeded, "The type of arg 0 is incorrect, expected type is string and " + "the content must be numeric, value range is: 0x8000000000000000~0x7FFFFFFFFFFFFFFF."); + formIds.push_back(formIdValue); + } + + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); + NAPI_ASSERT(env, valueType == napi_boolean, "The type of arg 1 is incorrect, expected type is boolean."); + auto *asyncCallbackInfo = new AsyncNotifyFormsEnableUpdateCallbackInfo { + .env = env, + .ability = GetGlobalAbility(env), + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .formIds = formIds, + .isEnableUpdate = false, + }; + napi_get_value_bool(env, argv[1], &asyncCallbackInfo->isEnableUpdate); + + if (argc == ARGS_SIZE_THREE) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_TWO], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The type of arg 2 is incorrect, expected type is function."); + napi_create_reference(env, argv[ARGS_SIZE_TWO], REF_COUNT, &asyncCallbackInfo->callback); + return NotifyFormsEnableUpdateCallback(env, asyncCallbackInfo); + } else { + return NotifyFormsEnableUpdatePromise(env, asyncCallbackInfo); + } +} + /** * @brief Call native kit function: GetAllFormsInfo * diff --git a/interfaces/kits/napi/aafwk/formManager/napi_form_manager.h b/interfaces/kits/napi/aafwk/formManager/napi_form_manager.h index cc394da4600..456f87bbed9 100644 --- a/interfaces/kits/napi/aafwk/formManager/napi_form_manager.h +++ b/interfaces/kits/napi/aafwk/formManager/napi_form_manager.h @@ -21,6 +21,7 @@ #include "form_info.h" #include "form_js_info.h" #include "form_provider_info.h" +#include "form_state_info.h" #include "hilog_wrapper.h" #include "napi/native_api.h" #include "napi/native_common.h" @@ -140,6 +141,59 @@ struct AsyncCheckFMSReadyCallbackInfo { bool isFMSReady; }; +struct AsyncDeleteInvalidFormsCallbackInfo { + napi_env env; + OHOS::AppExecFwk::Ability *ability; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + std::vector formIds; + int numFormsDeleted; + int result; +}; + +struct AsyncAcquireFormStateCallbackInfo { + napi_env env; + OHOS::AppExecFwk::Ability *ability; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + OHOS::AAFwk::Want want; + OHOS::AppExecFwk::FormStateInfo stateInfo; + int result; +}; + +struct AsyncFormUninstallObserverCallbackInfo { + napi_env env; + OHOS::AppExecFwk::Ability *ability; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + int result; +}; + +struct AsyncNotifyFormsVisibleCallbackInfo { + napi_env env; + OHOS::AppExecFwk::Ability *ability; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + std::vector formIds; + bool isVisible; + int result; +}; + +struct AsyncNotifyFormsEnableUpdateCallbackInfo { + napi_env env; + OHOS::AppExecFwk::Ability *ability; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + std::vector formIds; + bool isEnableUpdate; + int result; +}; + struct AsyncGetFormsInfoCallbackInfo { napi_env env; OHOS::AppExecFwk::Ability *ability; @@ -173,6 +227,12 @@ napi_value NAPI_NotifyInvisibleForms(napi_env env, napi_callback_info info); napi_value NAPI_EnableFormsUpdate(napi_env env, napi_callback_info info); napi_value NAPI_DisableFormsUpdate(napi_env env, napi_callback_info info); napi_value NAPI_CheckFMSReady(napi_env env, napi_callback_info info); +napi_value NAPI_DeleteInvalidForms(napi_env env, napi_callback_info info); +napi_value NAPI_AcquireFormState(napi_env env, napi_callback_info info); +napi_value NAPI_RegisterFormUninstallObserver(napi_env env, napi_callback_info info); +napi_value NAPI_UnregisterFormUninstallObserver(napi_env env, napi_callback_info info); +napi_value NAPI_NotifyFormsVisible(napi_env env, napi_callback_info info); +napi_value NAPI_NotifyFormsEnableUpdate(napi_env env, napi_callback_info info); napi_value NAPI_GetAllFormsInfo(napi_env env, napi_callback_info info); napi_value NAPI_GetFormsInfo(napi_env env, napi_callback_info info); diff --git a/interfaces/kits/napi/aafwk/formManager/native_module.cpp b/interfaces/kits/napi/aafwk/formManager/native_module.cpp index 3983804a177..3d9eec7b165 100644 --- a/interfaces/kits/napi/aafwk/formManager/native_module.cpp +++ b/interfaces/kits/napi/aafwk/formManager/native_module.cpp @@ -47,6 +47,12 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("enableFormsUpdate", NAPI_EnableFormsUpdate), DECLARE_NAPI_FUNCTION("disableFormsUpdate", NAPI_DisableFormsUpdate), DECLARE_NAPI_FUNCTION("isSystemReady", NAPI_CheckFMSReady), + DECLARE_NAPI_FUNCTION("deleteInvalidForms", NAPI_DeleteInvalidForms), + DECLARE_NAPI_FUNCTION("acquireFormState", NAPI_AcquireFormState), + DECLARE_NAPI_FUNCTION("on", NAPI_RegisterFormUninstallObserver), + DECLARE_NAPI_FUNCTION("off", NAPI_UnregisterFormUninstallObserver), + DECLARE_NAPI_FUNCTION("notifyFormsVisible", NAPI_NotifyFormsVisible), + DECLARE_NAPI_FUNCTION("notifyFormsEnableUpdate", NAPI_NotifyFormsEnableUpdate), DECLARE_NAPI_FUNCTION("getAllFormsInfo", NAPI_GetAllFormsInfo), DECLARE_NAPI_FUNCTION("getFormsInfo", NAPI_GetFormsInfo), }; diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn b/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn index 5a4d4d0e0e4..972cbdf0abd 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn +++ b/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -11,7 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# import("//build/config/ohos/rules.gni") import("//build/ohos.gni") import("//foundation/aafwk/standard/feature.gni") ohos_shared_library("napi_common") { @@ -57,8 +56,6 @@ ohos_shared_library("napi_common") { "native_appdatamgr:native_dataability", "native_appdatamgr:native_rdb", "utils_base:utils", - - #"samgr_standard:samgr_proxy", ] if (ability_runtime_graphics) { diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp index bffb159ba84..225d8d6c61b 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp @@ -694,7 +694,7 @@ void GetExternalCacheDirExecuteCallback(napi_env env, void *data) asyncCallbackInfo->native_data.data_type = NVT_STRING; asyncCallbackInfo->native_data.str_value = asyncCallbackInfo->ability->GetExternalCacheDir(); HILOG_INFO( - "%{public}s end. ExternalCacheDir=%{public}s", __func__, asyncCallbackInfo->native_data.str_value.c_str()); + "%{public}s end. ExternalCacheDir=%{private}s", __func__, asyncCallbackInfo->native_data.str_value.c_str()); } /** @@ -2952,12 +2952,12 @@ void UnwrapAbilityStartSettingForNumber( bool isReadValue32 = false; bool isReadDouble = false; if (napi_get_value_int32(env, param, &natValue32) == napi_ok) { - HILOG_INFO("%{public}s called. Property value=%{public}d.", __func__, natValue32); + HILOG_INFO("%{public}s called. Property value=%{private}d.", __func__, natValue32); isReadValue32 = true; } if (napi_get_value_double(env, param, &natValueDouble) == napi_ok) { - HILOG_INFO("%{public}s called. Property value=%{public}lf.", __func__, natValueDouble); + HILOG_INFO("%{public}s called. Property value=%{private}lf.", __func__, natValueDouble); isReadDouble = true; } @@ -3003,7 +3003,7 @@ bool UnwrapAbilityStartSetting(napi_env env, napi_value param, AAFwk::AbilitySta switch (jsValueType) { case napi_string: { std::string natValue = UnwrapStringFromJS(env, jsProValue); - HILOG_INFO("%{public}s called. Property value=%{public}s.", __func__, natValue.c_str()); + HILOG_INFO("%{public}s called. Property value=%{private}s.", __func__, natValue.c_str()); setting.AddProperty(strProName, natValue); break; } diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_configuration.cpp b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_configuration.cpp index ba2c69a9e06..e8c37750251 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_configuration.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_configuration.cpp @@ -27,7 +27,7 @@ bool InnerWrapConfigurationString( napi_env env, napi_value jsObject, const std::string &key, const std::string &value) { if (!value.empty()) { - HILOG_INFO("%{public}s called. key=%{public}s, value=%{public}s", __func__, key.c_str(), value.c_str()); + HILOG_INFO("%{public}s called. key=%{public}s, value=%{private}s", __func__, key.c_str(), value.c_str()); napi_value jsValue = WrapStringToJS(env, value); if (jsValue != nullptr) { NAPI_CALL_BASE(env, napi_set_named_property(env, jsObject, key.c_str(), jsValue), false); diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp index 903cd9e6a95..4d724479b32 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp @@ -230,7 +230,7 @@ std::string UnwrapStringFromJS(napi_env env, napi_value param, const std::string if (buf == nullptr) { return value; } - memset_s(buf, size + 1, 0, size + 1); + (void)memset_s(buf, size + 1, 0, size + 1); bool rev = napi_get_value_string_utf8(env, param, buf, size + 1, &size) == napi_ok; if (rev) { @@ -260,7 +260,7 @@ bool UnwrapStringFromJS2(napi_env env, napi_value param, std::string &value) if (buf == nullptr) { return false; } - memset_s(buf, (size + 1), 0, (size + 1)); + (void)memset_s(buf, (size + 1), 0, (size + 1)); bool rev = napi_get_value_string_utf8(env, param, buf, size + 1, &size) == napi_ok; if (rev) { diff --git a/interfaces/kits/napi/aafwk/particleAbility/BUILD.gn b/interfaces/kits/napi/aafwk/particleAbility/BUILD.gn index 6e2cf8ce3f2..bbbb31acd16 100644 --- a/interfaces/kits/napi/aafwk/particleAbility/BUILD.gn +++ b/interfaces/kits/napi/aafwk/particleAbility/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -11,7 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# import("//build/config/ohos/rules.gni") import("//build/ohos.gni") ohos_shared_library("particleability") { include_dirs = [ @@ -21,6 +20,7 @@ ohos_shared_library("particleability") { "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/featureAbility", "//foundation/aafwk/standard/services/common/include", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_rdb/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_dataability/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_rdb/include", diff --git a/interfaces/kits/napi/aafwk/wantConstant/BUILD.gn b/interfaces/kits/napi/aafwk/wantConstant/BUILD.gn index 554f9c249ea..5facb27a223 100644 --- a/interfaces/kits/napi/aafwk/wantConstant/BUILD.gn +++ b/interfaces/kits/napi/aafwk/wantConstant/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -11,7 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# import("//build/config/ohos/rules.gni") import("//build/ohos.gni") ohos_shared_library("wantconstant") { include_dirs = [ diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index 166c225ae19..12b1324ec3c 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -230,6 +230,8 @@ public: void DumpState(std::vector &info, bool isClient, const std::string &args = "") const; + void StopAllExtensions(); + // MSG 0 - 20 represents timeout message static constexpr uint32_t LOAD_TIMEOUT_MSG = 0; static constexpr uint32_t CONNECT_TIMEOUT_MSG = 1; diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 737b3f193dc..634ac10a388 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -357,10 +357,11 @@ public: /** * Uninstall app * - * @param bundleName. + * @param bundleName bundle name of uninstalling app. + * @param uid uid of bundle. * @return Returns ERR_OK on success, others on failure. */ - virtual int UninstallApp(const std::string &bundleName) override; + virtual int UninstallApp(const std::string &bundleName, int32_t uid) override; /** * Moving mission to the specified stack by mission option(Enter floating window mode). @@ -428,18 +429,6 @@ public: */ virtual bool IsFirstInMission(const sptr &token) override; - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override; - /** * Save the top ability States and move them to the background * @return Returns ERR_OK on success, others on failure. @@ -681,6 +670,14 @@ public: */ virtual int SendANRProcessID(int pid) override; + /** + * Get mission id by ability token. + * + * @param token The token of ability. + * @return Returns -1 if do not find mission, otherwise return mission id. + */ + virtual int32_t GetMissionIdByToken(const sptr &token) override; + private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 7bbd8160257..6899170bc2b 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -475,10 +475,11 @@ public: /** * Uninstall app * - * @param bundleName. + * @param bundleName bundle name of uninstalling app. + * @param uid uid of bundle. * @return Returns ERR_OK on success, others on failure. */ - virtual int UninstallApp(const std::string &bundleName) override; + virtual int UninstallApp(const std::string &bundleName, int32_t uid) override; /** * Moving mission to the specified stack by mission option(Enter floating window mode). @@ -546,18 +547,6 @@ public: */ virtual bool IsFirstInMission(const sptr &token) override; - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override; - /** * Save the top ability States and move them to the background * @return Returns ERR_OK on success, others on failure. @@ -678,6 +667,8 @@ public: virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override; + virtual int32_t GetMissionIdByToken(const sptr &token) override; + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; virtual int StopSyncRemoteMissions(const std::string& devId) override; @@ -860,6 +851,8 @@ public: bool IsAbilityControllerForeground(const std::string &bundleName); + bool IsAbilityControllerStartById(int32_t missionId); + void GrantUriPermission(const Want &want, int32_t validUserId, uint32_t targetTokenId); /** @@ -1115,6 +1108,7 @@ private: void PauseOldUser(int32_t userId); void PauseOldStackManager(int32_t userId); void PauseOldMissionListManager(int32_t userId); + void PauseOldConnectManager(int32_t userId); bool IsSystemUI(const std::string &bundleName) const; bool VerificationAllToken(const sptr &token); diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 402f451790d..76bc7812ecf 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -96,7 +96,6 @@ private: int CloseMultiWindowInner(MessageParcel &data, MessageParcel &reply); int SetMissionStackSettingInner(MessageParcel &data, MessageParcel &reply); int IsFirstInMissionInner(MessageParcel &data, MessageParcel &reply); - int CompelVerifyPermissionInner(MessageParcel &data, MessageParcel &reply); int PowerOffInner(MessageParcel &data, MessageParcel &reply); int PowerOnInner(MessageParcel &data, MessageParcel &reply); int LockMissionInner(MessageParcel &data, MessageParcel &reply); @@ -144,6 +143,7 @@ private: int CleanMissionInner(MessageParcel &data, MessageParcel &reply); int CleanAllMissionsInner(MessageParcel &data, MessageParcel &reply); int MoveMissionToFrontInner(MessageParcel &data, MessageParcel &reply); + int GetMissionIdByTokenInner(MessageParcel &data, MessageParcel &reply); // for new version ability (call ability) int StartAbilityByCallInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index dbf3c483d02..c967cedd119 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -210,6 +210,15 @@ public: */ int KillApplication(const std::string &bundleName); + /** + * kill the application by uid + * + * @param bundleName name of bundle. + * @param uid uid of bundle. + * @return 0 if success. + */ + int KillApplicationByUid(const std::string &bundleName, int32_t uid); + /** * clear the application data * @@ -221,18 +230,6 @@ public: void PrepareTerminate(const sptr &token); - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message); - /** * Get system memory information. * @param SystemMemoryAttr, memory information. @@ -286,6 +283,13 @@ public: */ int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens); + /** + * Post a task to the not response process. + * + * @param pid, the not response process id. + */ + void PostANRTaskByProcessID(const pid_t pid); + protected: /** * OnAbilityRequestDone, app manager service call this interface after ability request done. diff --git a/services/abilitymgr/include/inner_mission_info.h b/services/abilitymgr/include/inner_mission_info.h index af13a48e350..0b811ec6bd3 100644 --- a/services/abilitymgr/include/inner_mission_info.h +++ b/services/abilitymgr/include/inner_mission_info.h @@ -45,6 +45,8 @@ struct InnerMissionInfo { std::string missionName; bool isSingletonMode; int32_t startMethod; + std::string bundleName; + int32_t uid; std::string ToJsonStr() const; bool FromJsonStr(const std::string &jsonStr); diff --git a/services/abilitymgr/include/mission_info_mgr.h b/services/abilitymgr/include/mission_info_mgr.h index f3757a4e462..5289421796e 100644 --- a/services/abilitymgr/include/mission_info_mgr.h +++ b/services/abilitymgr/include/mission_info_mgr.h @@ -157,6 +157,8 @@ public: * @param handler the snapshotHandler */ void RegisterSnapshotHandler(const sptr& handler); + + void HandleUnInstallApp(const std::string &bundleName, int32_t uid, std::list &missions); private: /** * @brief Boot query mission info. @@ -164,7 +166,10 @@ private: */ bool LoadAllMissionInfo(); + void GetMatchedMission(const std::string &bundleName, int32_t uid, std::list &missions); + private: + int32_t currentMisionId_ = MIN_MISSION_ID; std::unordered_map missionIdMap_; // key:distributed misisonid, vaule: has been saved std::list missionInfoList_; std::shared_ptr taskDataPersistenceMgr_; diff --git a/services/abilitymgr/include/mission_list.h b/services/abilitymgr/include/mission_list.h index 93c74aad320..34de25fd73d 100644 --- a/services/abilitymgr/include/mission_list.h +++ b/services/abilitymgr/include/mission_list.h @@ -161,6 +161,14 @@ public: */ sptr GetAbilityTokenByMissionId(int32_t missionId); + /** + * Handle uninstall bundle. + * + * @param bundleName name of bundle. + * @param uid the uid of bundle. + */ + void HandleUnInstallApp(const std::string &bundleName, int32_t uid); + /** * @brief dump mission * @@ -181,6 +189,7 @@ public: std::shared_ptr GetMissionBySpecifiedFlag(const AAFwk::Want &want, const std::string &flag) const; private: std::string GetTypeName(); + bool MatchedInitialMission(const std::shared_ptr& mission, const std::string &bundleName, int32_t uid); MissionListType type_; std::list> missions_ {}; diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index 5f25a748703..b6e3b5b2c65 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -339,6 +339,8 @@ public: */ std::shared_ptr GetCurrentTopAbility(const std::string &bundleName); + void UninstallApp(const std::string &bundleName, int32_t uid); + bool IsStarted(); void PauseManager(); void ResumeManager(); @@ -407,6 +409,8 @@ private: int CallAbilityLocked(const AbilityRequest &abilityRequest); void UpdateMissionSnapshot(const std::shared_ptr& abilityRecord); + void AddUninstallTags(const std::string &bundleName, int32_t uid); + private: int userId_; std::recursive_mutex managerLock_; diff --git a/services/abilitymgr/include/mission_listener_controller.h b/services/abilitymgr/include/mission_listener_controller.h index 7a20272afc1..ee003f2b378 100644 --- a/services/abilitymgr/include/mission_listener_controller.h +++ b/services/abilitymgr/include/mission_listener_controller.h @@ -82,6 +82,8 @@ public: */ void NotifyMissionMovedToFront(int32_t missionId); + void HandleUnInstallApp(const std::list &missions); + private: void NotifyListeners(int32_t missionId, IMissionListener::MissionListenerCmd cmd); void OnListenerDied(const wptr &remote); diff --git a/services/abilitymgr/include/pending_want_manager.h b/services/abilitymgr/include/pending_want_manager.h index 55852046f41..7c5d2c38bed 100644 --- a/services/abilitymgr/include/pending_want_manager.h +++ b/services/abilitymgr/include/pending_want_manager.h @@ -156,7 +156,7 @@ public: int32_t DeviceIdDetermine( const Want &want, const sptr &callerToken, int32_t requestCode, const int32_t callerUid); int32_t PendingWantPublishCommonEvent(const Want &want, const SenderInfo &senderInfo, int32_t callerUid); - void ClearPendingWantRecord(const std::string &bundleName); + void ClearPendingWantRecord(const std::string &bundleName, int32_t uid); void Dump(std::vector &info); void DumpByRecordId(std::vector &info, const std::string &args); @@ -172,7 +172,7 @@ private: sptr GetPendingWantRecordByCode(int32_t code); static int32_t PendingRecordIdCreate(); - void ClearPendingWantRecordTask(const std::string &bundleName); + void ClearPendingWantRecordTask(const std::string &bundleName, int32_t uid); private: std::map, sptr> wantRecords_; diff --git a/services/abilitymgr/include/user_controller.h b/services/abilitymgr/include/user_controller.h index de5adfbcd73..17c55e4eb5a 100644 --- a/services/abilitymgr/include/user_controller.h +++ b/services/abilitymgr/include/user_controller.h @@ -119,7 +119,7 @@ private: private: std::recursive_mutex userLock_; - int32_t currentUserId_ = USER_ID_NO_HEAD; + int32_t currentUserId_ = USER_ID_DEFAULT; std::unordered_map> userItems_; std::shared_ptr eventHandler_; }; diff --git a/services/abilitymgr/src/ability_connect_callback_stub.cpp b/services/abilitymgr/src/ability_connect_callback_stub.cpp index 783df6ab6e9..49c2e203eab 100644 --- a/services/abilitymgr/src/ability_connect_callback_stub.cpp +++ b/services/abilitymgr/src/ability_connect_callback_stub.cpp @@ -116,6 +116,7 @@ int AbilityConnectionStub::OnRemoteRequest( auto remoteObject = data.ReadRemoteObject(); if (remoteObject == nullptr) { HILOG_ERROR("callback stub receive remoteObject is nullptr"); + delete element; return ERR_INVALID_VALUE; } auto resultCode = data.ReadInt32(); diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index b8836846642..b4e8cf3202c 100755 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -559,6 +559,9 @@ std::shared_ptr AbilityConnectManager::GetServiceRecordByToken(co { std::lock_guard guard(Lock_); auto IsMatch = [token](auto service) { + if (!service.second) { + return false; + } sptr srcToken = service.second->GetToken(); return srcToken == token; }; @@ -1107,5 +1110,21 @@ void AbilityConnectManager::GetExtensionRunningInfo(std::shared_ptr guard(Lock_); + auto mgr = shared_from_this(); + auto task = [mgr](ServiceMapType::reference service) { + auto abilityRecord = service.second; + CHECK_POINTER(abilityRecord); + if (abilityRecord->GetAbilityInfo().type == AbilityType::EXTENSION) { + mgr->TerminateAbilityLocked(abilityRecord->GetToken()); + } + }; + std::for_each(serviceMap_.begin(), serviceMap_.end(), task); + HILOG_INFO("StopAllExtensions end."); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 486f96063e7..b3cabdb149b 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -389,17 +389,7 @@ ErrCode AbilityManagerClient::IsFirstInMission(const sptr &token) } return ERR_OK; } -#endif -ErrCode AbilityManagerClient::CompelVerifyPermission( - const std::string &permission, int pid, int uid, std::string &message) -{ - CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); - sptr abms = iface_cast(remoteObject_); - return abms->CompelVerifyPermission(permission, pid, uid, message); -} - -#ifdef SUPPORT_GRAPHICS ErrCode AbilityManagerClient::MoveMissionToFloatingStack(const MissionOption &missionOption) { CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); @@ -811,6 +801,23 @@ ErrCode AbilityManagerClient::MoveMissionToFront(int32_t missionId, const StartO sptr abms = iface_cast(remoteObject_); return abms->MoveMissionToFront(missionId, startOptions); } + +ErrCode AbilityManagerClient::GetMissionIdByToken(const sptr &token, int32_t &missionId) +{ + CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); + sptr abms = iface_cast(remoteObject_); + if (!abms) { + HILOG_ERROR("ability manager service connect failed!"); + return ABILITY_SERVICE_NOT_CONNECTED; + } + + missionId = abms->GetMissionIdByToken(token); + if (missionId <= 0) { + HILOG_ERROR("get missionid by token failed!"); + return MISSION_NOT_FOUND; + } + return ERR_OK; +} #endif ErrCode AbilityManagerClient::StartAbilityByCall( diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index f713cac88f2..12120c09917 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -503,7 +503,7 @@ void AbilityManagerProxy::AddWindowInfo(const sptr &token, int32_ } void AbilityManagerProxy::DumpSysState( - const std::string& args, std::vector& state, bool isClient, bool isUserID, int UserID) + const std::string& args, std::vector& state, bool isClient, bool isUserId, int UserId) { int error; MessageParcel data; @@ -519,11 +519,11 @@ void AbilityManagerProxy::DumpSysState( HILOG_ERROR("data write failed."); return ; } - if (!data.WriteBool(isUserID)) { + if (!data.WriteBool(isUserId)) { HILOG_ERROR("data write failed."); return ; } - if (!data.WriteInt32(UserID)) { + if (!data.WriteInt32(UserId)) { HILOG_ERROR("data write failed."); return ; } @@ -931,7 +931,7 @@ int AbilityManagerProxy::ClearUpApplicationData(const std::string &bundleName) return reply.ReadInt32(); } -int AbilityManagerProxy::UninstallApp(const std::string &bundleName) +int AbilityManagerProxy::UninstallApp(const std::string &bundleName, int32_t uid) { MessageParcel data; MessageParcel reply; @@ -944,6 +944,10 @@ int AbilityManagerProxy::UninstallApp(const std::string &bundleName) HILOG_ERROR("bundleName write failed."); return ERR_INVALID_VALUE; } + if (!data.WriteInt32(uid)) { + HILOG_ERROR("uid write failed."); + return ERR_INVALID_VALUE; + } int error = Remote()->SendRequest(IAbilityManager::UNINSTALL_APP, data, reply, option); if (error != NO_ERROR) { HILOG_ERROR("Send request error: %{public}d", error); @@ -1142,27 +1146,6 @@ bool AbilityManagerProxy::IsFirstInMission(const sptr &token) return reply.ReadBool(); } -int AbilityManagerProxy::CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return INNER_ERR; - } - if (!data.WriteString16(Str8ToStr16(permission)) || !data.WriteInt32(pid) || !data.WriteInt32(uid)) { - HILOG_ERROR("data write failed."); - return INNER_ERR; - } - auto error = Remote()->SendRequest(IAbilityManager::COMPEL_VERIFY_PERMISSION, data, reply, option); - if (error != NO_ERROR) { - HILOG_ERROR("Send request error: %{public}d", error); - return error; - } - message = Str16ToStr8(reply.ReadString16()); - return reply.ReadInt32(); -} - int AbilityManagerProxy::PowerOff() { MessageParcel data; @@ -2666,5 +2649,34 @@ int AbilityManagerProxy::SendANRProcessID(int pid) } return reply.ReadInt32(); } + +int32_t AbilityManagerProxy::GetMissionIdByToken(const sptr &token) +{ + if (!token) { + HILOG_ERROR("token is nullptr."); + return -1; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("data interface token failed."); + return -1; + } + + if (!data.WriteParcelable(token)) { + HILOG_ERROR("data write failed."); + return -1; + } + + auto error = Remote()->SendRequest(IAbilityManager::GET_MISSION_ID_BY_ABILITY_TOKEN, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return -1; + } + + return reply.ReadInt32(); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index a17f04b500a..f2ab866fd5a 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -84,7 +84,6 @@ const std::string APP_MEMORY_MAX_SIZE_PARAMETER = "const.product.dalvikheaplimit const std::string RAM_CONSTRAINED_DEVICE_SIGN = "const.product.islowram"; const std::string PKG_NAME = "ohos.distributedhardware.devicemanager"; const std::string ACTION_CHOOSE = "ohos.want.action.select"; -const std::string PERMISSION_SET_ABILITY_CONTROLLER = "ohos.permission.SET_ABILITY_CONTROLLER"; const std::map AbilityManagerService::dumpMap = { std::map::value_type("--all", KEY_DUMP_ALL), std::map::value_type("-a", KEY_DUMP_ALL), @@ -192,14 +191,10 @@ bool AbilityManagerService::Init() systemDataAbilityManager_ = std::make_shared(); amsConfigResolver_ = std::make_shared(); - if (amsConfigResolver_) { - amsConfigResolver_->Parse(); - HILOG_INFO("ams config parse"); - } + amsConfigResolver_->Parse(); + HILOG_INFO("ams config parse"); useNewMission_ = amsConfigResolver_->IsUseNewMission(); #ifdef SUPPORT_GRAPHICS - SetStackManager(userId, true); - InitMissionListManager(userId, true); #endif SwitchManagers(U0_USER_ID, false); @@ -1512,6 +1507,13 @@ int AbilityManagerService::CleanAllMissions() return CHECK_PERMISSION_FAILED; } + Want want; + want.SetElementName(AbilityConfig::LAUNCHER_BUNDLE_NAME, AbilityConfig::LAUNCHER_ABILITY_NAME); + if (!IsAbilityControllerStart(want, AbilityConfig::LAUNCHER_BUNDLE_NAME)) { + HILOG_ERROR("IsAbilityControllerStart failed: %{public}s", want.GetBundle().c_str()); + return ERR_WOULD_BLOCK; + } + return currentMissionListManager_->ClearAllMissions(); } @@ -1525,6 +1527,11 @@ int AbilityManagerService::MoveMissionToFront(int32_t missionId) return CHECK_PERMISSION_FAILED; } + if (!IsAbilityControllerStartById(missionId)) { + HILOG_ERROR("IsAbilityControllerStart false"); + return ERR_WOULD_BLOCK; + } + return currentMissionListManager_->MoveMissionToFront(missionId); } @@ -1538,11 +1545,49 @@ int AbilityManagerService::MoveMissionToFront(int32_t missionId, const StartOpti return CHECK_PERMISSION_FAILED; } + if (!IsAbilityControllerStartById(missionId)) { + HILOG_ERROR("IsAbilityControllerStart false"); + return ERR_WOULD_BLOCK; + } + auto options = std::make_shared(startOptions); return currentMissionListManager_->MoveMissionToFront(missionId, options); } + +int32_t AbilityManagerService::GetMissionIdByToken(const sptr &token) +{ + HILOG_INFO("request GetMissionIdByToken."); + if (!token) { + HILOG_ERROR("token is invalid."); + return -1; + } + + if (IPCSkeleton::GetCallingPid() != getpid()) { + HILOG_ERROR("%{public}s: Only support same process call.", __func__); + return -1; + } + + return GetMissionIdByAbilityToken(token); +} #endif +bool AbilityManagerService::IsAbilityControllerStartById(int32_t missionId) +{ + InnerMissionInfo innerMissionInfo; + int getMission = DelayedSingleton::GetInstance()->GetInnerMissionInfoById( + missionId, innerMissionInfo); + if (getMission != ERR_OK) { + HILOG_ERROR("cannot find mission info from MissionInfoList by missionId: %{public}d", missionId); + return true; + } + if (!IsAbilityControllerStart(innerMissionInfo.missionInfo.want, innerMissionInfo.missionInfo.want.GetBundle())) { + HILOG_ERROR("IsAbilityControllerStart failed: %{public}s", + innerMissionInfo.missionInfo.want.GetBundle().c_str()); + return false; + } + return true; +} + std::shared_ptr AbilityManagerService::GetServiceRecordByElementName(const std::string &element) { return connectManager_->GetServiceRecordByElementName(element); @@ -1639,6 +1684,11 @@ int AbilityManagerService::ReleaseDataAbility( sptr dataAbilityScheduler, const sptr &callerToken) { HILOG_INFO("%{public}s, called.", __func__); + if (!dataAbilityScheduler || !callerToken) { + HILOG_ERROR("dataAbilitySchedule or callerToken is nullptr"); + return ERR_INVALID_VALUE; + } + bool isSystem = (IPCSkeleton::GetCallingUid() <= AppExecFwk::Constants::BASE_SYS_UID); if (!isSystem) { HILOG_INFO("callerToken not system %{public}s", __func__); @@ -2735,7 +2785,7 @@ int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName) return ERR_OK; } -int AbilityManagerService::UninstallApp(const std::string &bundleName) +int AbilityManagerService::UninstallApp(const std::string &bundleName, int32_t uid) { HILOG_DEBUG("Uninstall app, bundleName: %{public}s", bundleName.c_str()); pid_t callingPid = IPCSkeleton::GetCallingPid(); @@ -2745,11 +2795,13 @@ int AbilityManagerService::UninstallApp(const std::string &bundleName) return CHECK_PERMISSION_FAILED; } - CHECK_POINTER_AND_RETURN(currentStackManager_, ERR_NO_INIT); - currentStackManager_->UninstallApp(bundleName); + int32_t targetUserId = uid / BASE_USER_RANGE; + auto listManager = GetListManagerByUserId(targetUserId); + CHECK_POINTER_AND_RETURN(listManager, ERR_NO_INIT); + listManager->UninstallApp(bundleName, uid); CHECK_POINTER_AND_RETURN(pendingWantManager_, ERR_NO_INIT); - pendingWantManager_->ClearPendingWantRecord(bundleName); - int ret = DelayedSingleton::GetInstance()->KillApplication(bundleName); + pendingWantManager_->ClearPendingWantRecord(bundleName, uid); + int ret = DelayedSingleton::GetInstance()->KillApplicationByUid(bundleName, uid); if (ret != ERR_OK) { return UNINSTALL_APP_FAILED; } @@ -3157,15 +3209,7 @@ bool AbilityManagerService::IsFirstInMission(const sptr &token) } return stackManager->IsFirstInMission(token); } -#endif - -int AbilityManagerService::CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) -{ - HILOG_INFO("Compel verify permission."); - return DelayedSingleton::GetInstance()->CompelVerifyPermission(permission, pid, uid, message); -} -#ifdef SUPPORT_GRAPHICS int AbilityManagerService::PowerOff() { HILOG_INFO("Power off."); @@ -3806,6 +3850,7 @@ void AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId) isBoot = true; } StartUserApps(userId, isBoot); + PauseOldConnectManager(oldUserId); } void AbilityManagerService::SwitchManagers(int32_t userId, bool switchUser) @@ -3847,6 +3892,29 @@ void AbilityManagerService::PauseOldMissionListManager(int32_t userId) HILOG_INFO("%{public}s, PauseOldMissionListManager:%{public}d-----end", __func__, userId); } +void AbilityManagerService::PauseOldConnectManager(int32_t userId) +{ + HILOG_INFO("%{public}s, PauseOldConnectManager:%{public}d-----begin", __func__, userId); + if (userId == U0_USER_ID) { + HILOG_INFO("%{public}s, u0 not stop, id:%{public}d-----nullptr", __func__, userId); + return; + } + + std::shared_lock lock(managersMutex_); + auto it = connectManagers_.find(userId); + if (it == connectManagers_.end()) { + HILOG_INFO("%{public}s, PauseOldConnectManager:%{public}d-----no user", __func__, userId); + return; + } + auto manager = it->second; + if (!manager) { + HILOG_INFO("%{public}s, PauseOldConnectManager:%{public}d-----nullptr", __func__, userId); + return; + } + manager->StopAllExtensions(); + HILOG_INFO("%{public}s, PauseOldConnectManager:%{public}d-----end", __func__, userId); +} + void AbilityManagerService::PauseOldStackManager(int32_t userId) { auto it = stackManagers_.find(userId); @@ -4005,16 +4073,12 @@ int AbilityManagerService::SetAbilityController(const sptr & bool imAStabilityTest) { HILOG_DEBUG("%{public}s, imAStabilityTest: %{public}d", __func__, imAStabilityTest); - auto bms = GetBundleManager(); - CHECK_POINTER_AND_RETURN(bms, ERR_INVALID_VALUE); - std::string bundleName; - int uid = IPCSkeleton::GetCallingUid(); - IN_PROCESS_CALL_WITHOUT_RET(bms->GetBundleNameForUid(uid, bundleName)); - HILOG_INFO("%{public}s, bundleName: %{public}s, uid = %{public}d", __func__, bundleName.c_str(), uid); - if (IN_PROCESS_CALL(bms->CheckPermission(bundleName, PERMISSION_SET_ABILITY_CONTROLLER)) == 0) { - HILOG_ERROR("PERMISSION_SET_ABILITY_CONTROLLER check failed"); + auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyControllerPerm(); + if (!isPerm) { + HILOG_ERROR("%{public}s: Permission verification failed", __func__); return CHECK_PERMISSION_FAILED; } + std::lock_guard guard(globalLock_); abilityController_ = abilityController; controllerIsAStabilityTest_ = imAStabilityTest; @@ -4043,10 +4107,7 @@ int AbilityManagerService::SendANRProcessID(int pid) } #endif handler_->PostTask(timeoutTask, "TIME_OUT_TASK", anrTimeOut); - if (kill(pid, SIGUSR1) != ERR_OK) { - HILOG_ERROR("Send sig to app not response process failed"); - return SEND_USR1_SIG_FAIL; - } + appScheduler_->PostANRTaskByProcessID(pid); return ERR_OK; } @@ -4124,7 +4185,7 @@ int AbilityManagerService::StartUserTest(const Want &want, const sptr &token, uint32_t flag) { - HILOG_DEBUG("DoAbilityForeground, sceneFlag:%{public}d", flag); + HILOG_DEBUG("DoAbilityForeground, sceneFlag:%{public}u", flag); CHECK_POINTER_AND_RETURN(token, ERR_INVALID_VALUE); if (!VerificationToken(token) && !VerificationAllToken(token)) { HILOG_ERROR("%{public}s token error.", __func__); @@ -4251,7 +4312,7 @@ int AbilityManagerService::DoAbilityForeground(const sptr &token, int AbilityManagerService::DoAbilityBackground(const sptr &token, uint32_t flag) { - HILOG_DEBUG("DoAbilityBackground, sceneFlag:%{public}d", flag); + HILOG_DEBUG("DoAbilityBackground, sceneFlag:%{public}u", flag); CHECK_POINTER_AND_RETURN(token, ERR_INVALID_VALUE); auto abilityRecord = Token::GetAbilityRecordByToken(token); @@ -4269,6 +4330,11 @@ int AbilityManagerService::DelegatorMoveMissionToFront(int32_t missionId) HILOG_INFO("enter missionId : %{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + if (!IsAbilityControllerStartById(missionId)) { + HILOG_ERROR("IsAbilityControllerStart false"); + return ERR_WOULD_BLOCK; + } + return currentMissionListManager_->MoveMissionToFront(missionId); } diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 54580c6b32b..9ad749d60d2 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -94,7 +94,6 @@ void AbilityManagerStub::SecondStepInit() requestFuncMap_[CLOSE_MULTI_WINDOW] = &AbilityManagerStub::CloseMultiWindowInner; requestFuncMap_[SET_STACK_SETTING] = &AbilityManagerStub::SetMissionStackSettingInner; requestFuncMap_[IS_FIRST_IN_MISSION] = &AbilityManagerStub::IsFirstInMissionInner; - requestFuncMap_[COMPEL_VERIFY_PERMISSION] = &AbilityManagerStub::CompelVerifyPermissionInner; requestFuncMap_[POWER_OFF] = &AbilityManagerStub::PowerOffInner; requestFuncMap_[POWER_ON] = &AbilityManagerStub::PowerOnInner; requestFuncMap_[LUCK_MISSION] = &AbilityManagerStub::LockMissionInner; @@ -152,6 +151,7 @@ void AbilityManagerStub::ThirdStepInit() requestFuncMap_[DELEGATOR_DO_ABILITY_BACKGROUND] = &AbilityManagerStub::DelegatorDoAbilityBackgroundInner; requestFuncMap_[DO_ABILITY_FOREGROUND] = &AbilityManagerStub::DoAbilityForegroundInner; requestFuncMap_[DO_ABILITY_BACKGROUND] = &AbilityManagerStub::DoAbilityBackgroundInner; + requestFuncMap_[GET_MISSION_ID_BY_ABILITY_TOKEN] = &AbilityManagerStub::GetMissionIdByTokenInner; } int AbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -422,7 +422,8 @@ int AbilityManagerStub::ClearUpApplicationDataInner(MessageParcel &data, Message int AbilityManagerStub::UninstallAppInner(MessageParcel &data, MessageParcel &reply) { std::string bundleName = Str16ToStr8(data.ReadString16()); - int result = UninstallApp(bundleName); + int32_t uid = data.ReadInt32(); + int result = UninstallApp(bundleName, uid); if (!reply.WriteInt32(result)) { HILOG_ERROR("remove stack error"); return ERR_INVALID_VALUE; @@ -691,18 +692,6 @@ int AbilityManagerStub::IsFirstInMissionInner(MessageParcel &data, MessageParcel return NO_ERROR; } -int AbilityManagerStub::CompelVerifyPermissionInner(MessageParcel &data, MessageParcel &reply) -{ - auto permission = Str16ToStr8(data.ReadString16()); - auto pid = data.ReadInt32(); - auto uid = data.ReadInt32(); - std::string message; - auto result = CompelVerifyPermission(permission, pid, uid, message); - reply.WriteString16(Str8ToStr16(message)); - reply.WriteInt32(result); - return NO_ERROR; -} - int AbilityManagerStub::PowerOffInner(MessageParcel &data, MessageParcel &reply) { auto result = PowerOff(); @@ -1179,6 +1168,17 @@ int AbilityManagerStub::MoveMissionToFrontInner(MessageParcel &data, MessageParc return NO_ERROR; } +int AbilityManagerStub::GetMissionIdByTokenInner(MessageParcel &data, MessageParcel &reply) +{ + sptr token = data.ReadParcelable(); + int32_t missionId = GetMissionIdByToken(token); + if (!reply.WriteInt32(missionId)) { + HILOG_ERROR("GetMissionIdByToken write missionId failed."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int AbilityManagerStub::MoveMissionToFrontByOptionsInner(MessageParcel &data, MessageParcel &reply) { int32_t missionId = data.ReadInt32(); diff --git a/services/abilitymgr/src/ams_configuration_parameter.cpp b/services/abilitymgr/src/ams_configuration_parameter.cpp index 889dbc03af8..1eee7ad008d 100644 --- a/services/abilitymgr/src/ams_configuration_parameter.cpp +++ b/services/abilitymgr/src/ams_configuration_parameter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -144,7 +144,7 @@ int AmsConfigurationParameter::LoadAmsConfiguration(const std::string &filePath) } } - HILOG_INFO("read ams config succes!"); + HILOG_INFO("read ams config success!"); return READ_OK; } diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 6cd186b67c9..f519cca0e8c 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -198,6 +198,19 @@ int AppScheduler::KillApplication(const std::string &bundleName) return ERR_OK; } +int AppScheduler::KillApplicationByUid(const std::string &bundleName, int32_t uid) +{ + HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); + CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); + int ret = (int)appMgrClient_->KillApplicationByUid(bundleName, uid); + if (ret != ERR_OK) { + HILOG_ERROR("Fail to kill application by uid."); + return INNER_ERR; + } + + return ERR_OK; +} + int AppScheduler::ClearUpApplicationData(const std::string &bundleName) { CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); @@ -221,18 +234,6 @@ void AppScheduler::PrepareTerminate(const sptr &token) appMgrClient_->PrepareTerminate(token); } -int AppScheduler::CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) -{ - CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); - auto ret = static_cast(appMgrClient_->CompelVerifyPermission(permission, pid, uid, message)); - if (ret != ERR_OK) { - HILOG_ERROR("Compel verify permission failed."); - return INNER_ERR; - } - - return ERR_OK; -} - void AppScheduler::OnAppStateChanged(const AppExecFwk::AppProcessData &appData) { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -364,5 +365,11 @@ int AppScheduler::GetAbilityRecordsByProcessID(const int pid, std::vectorPostANRTaskByProcessID(pid); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/data_ability_manager.cpp b/services/abilitymgr/src/data_ability_manager.cpp index c930a6d0de3..221497a6492 100644 --- a/services/abilitymgr/src/data_ability_manager.cpp +++ b/services/abilitymgr/src/data_ability_manager.cpp @@ -135,7 +135,8 @@ int DataAbilityManager::Release( DataAbilityRecordPtr dataAbilityRecord; for (it = dataAbilityRecordsLoaded_.begin(); it != dataAbilityRecordsLoaded_.end(); ++it) { - if (it->second->GetScheduler() != nullptr && it->second->GetScheduler()->AsObject() == scheduler->AsObject()) { + if (it->second && it->second->GetScheduler() && + it->second->GetScheduler()->AsObject() == scheduler->AsObject()) { dataAbilityRecord = it->second; break; } diff --git a/services/abilitymgr/src/inner_mission_info.cpp b/services/abilitymgr/src/inner_mission_info.cpp index 2198f0df7ed..9902f6d3c4f 100644 --- a/services/abilitymgr/src/inner_mission_info.cpp +++ b/services/abilitymgr/src/inner_mission_info.cpp @@ -20,20 +20,36 @@ namespace OHOS { namespace AAFwk { +namespace { +const std::string KEY_MISSION_NAME = "MissionName"; +const std::string KEY_IS_SINGLETON = "IsSingleton"; +const std::string KEY_MISSION_ID = "MissionId"; +const std::string KEY_RUNNING_STATE = "RunningState"; +const std::string KEY_LOCKED_STATE = "LockedState"; +const std::string KEY_CONTINUABLE = "Continuable"; +const std::string KEY_TIME = "Time"; +const std::string KEY_LABEL = "Label"; +const std::string KEY_ICON_PATH = "IconPath"; +const std::string KEY_WANT = "Want"; +const std::string KEY_START_METHOD = "StartMethod"; +const std::string KEY_BUNDLE_NAME = "BundleName"; +const std::string KEY_UID = "Uid"; +} std::string InnerMissionInfo::ToJsonStr() const { nlohmann::json value; - value["MissionName"] = missionName; - value["IsSingleton"] = isSingletonMode; - value["StartMethod"] = startMethod; - value["MissionId"] = missionInfo.id; - value["RunningState"] = missionInfo.runningState; - value["LockedState"] = missionInfo.lockedState; - value["Continuable"] = missionInfo.continuable; - value["Time"] = missionInfo.time; - value["Label"] = missionInfo.label; - value["IconPath"] = missionInfo.iconPath; - value["Want"] = missionInfo.want.ToUri(); + value[KEY_MISSION_NAME] = missionName; + value[KEY_IS_SINGLETON] = isSingletonMode; + value[KEY_BUNDLE_NAME] = bundleName; + value[KEY_UID] = uid; + value[KEY_MISSION_ID] = missionInfo.id; + value[KEY_RUNNING_STATE] = missionInfo.runningState; + value[KEY_LOCKED_STATE] = missionInfo.lockedState; + value[KEY_CONTINUABLE] = missionInfo.continuable; + value[KEY_TIME] = missionInfo.time; + value[KEY_LABEL] = missionInfo.label; + value[KEY_ICON_PATH] = missionInfo.iconPath; + value[KEY_WANT] = missionInfo.want.ToUri(); return value.dump(); } @@ -64,50 +80,58 @@ bool InnerMissionInfo::FromJsonStr(const std::string &jsonStr) } return false; }; - if (!CheckJsonNode("MissionName", JsonType::STRING)) { + if (!CheckJsonNode(KEY_MISSION_NAME, JsonType::STRING)) { + return false; + } + missionName = value[KEY_MISSION_NAME].get(); + if (!CheckJsonNode(KEY_IS_SINGLETON, JsonType::BOOLEAN)) { + return false; + } + isSingletonMode = value[KEY_IS_SINGLETON].get(); + if (!CheckJsonNode(KEY_START_METHOD, JsonType::NUMBER)) { return false; } - missionName = value["MissionName"].get(); - if (!CheckJsonNode("IsSingleton", JsonType::BOOLEAN)) { + startMethod = value[KEY_START_METHOD].get(); + if (!CheckJsonNode(KEY_BUNDLE_NAME, JsonType::STRING)) { return false; } - isSingletonMode = value["IsSingleton"].get(); - if (!CheckJsonNode("StartMethod", JsonType::NUMBER)) { + bundleName = value[KEY_BUNDLE_NAME].get(); + if (!CheckJsonNode(KEY_UID, JsonType::NUMBER)) { return false; } - startMethod = value["StartMethod"].get(); - if (!CheckJsonNode("MissionId", JsonType::NUMBER)) { + uid = value[KEY_UID].get(); + if (!CheckJsonNode(KEY_MISSION_ID, JsonType::NUMBER)) { return false; } - missionInfo.id = value["MissionId"].get(); - if (!CheckJsonNode("RunningState", JsonType::NUMBER)) { + missionInfo.id = value[KEY_MISSION_ID].get(); + if (!CheckJsonNode(KEY_RUNNING_STATE, JsonType::NUMBER)) { return false; } - missionInfo.runningState = value["RunningState"].get(); - if (!CheckJsonNode("LockedState", JsonType::BOOLEAN)) { + missionInfo.runningState = value[KEY_RUNNING_STATE].get(); + if (!CheckJsonNode(KEY_LOCKED_STATE, JsonType::BOOLEAN)) { return false; } - missionInfo.lockedState = value["LockedState"].get(); - if (!CheckJsonNode("Continuable", JsonType::BOOLEAN)) { + missionInfo.lockedState = value[KEY_LOCKED_STATE].get(); + if (!CheckJsonNode(KEY_CONTINUABLE, JsonType::BOOLEAN)) { return false; } - missionInfo.continuable = value["Continuable"].get(); - if (!CheckJsonNode("Time", JsonType::STRING)) { + missionInfo.continuable = value[KEY_CONTINUABLE].get(); + if (!CheckJsonNode(KEY_TIME, JsonType::STRING)) { return false; } - missionInfo.time = value["Time"].get(); - if (!CheckJsonNode("Label", JsonType::STRING)) { + missionInfo.time = value[KEY_TIME].get(); + if (!CheckJsonNode(KEY_LABEL, JsonType::STRING)) { return false; } - missionInfo.label = value["Label"].get(); - if (!CheckJsonNode("IconPath", JsonType::STRING)) { + missionInfo.label = value[KEY_LABEL].get(); + if (!CheckJsonNode(KEY_ICON_PATH, JsonType::STRING)) { return false; } - missionInfo.iconPath = value["IconPath"].get(); - if (!CheckJsonNode("Want", JsonType::STRING)) { + missionInfo.iconPath = value[KEY_ICON_PATH].get(); + if (!CheckJsonNode(KEY_WANT, JsonType::STRING)) { return false; } - Want* want = Want::ParseUri(value["Want"].get()); + Want* want = Want::ParseUri(value[KEY_WANT].get()); if (want) { missionInfo.want = *want; } diff --git a/services/abilitymgr/src/mission_info_mgr.cpp b/services/abilitymgr/src/mission_info_mgr.cpp index 224364b1b2c..aeaa0e3207a 100644 --- a/services/abilitymgr/src/mission_info_mgr.cpp +++ b/services/abilitymgr/src/mission_info_mgr.cpp @@ -29,12 +29,17 @@ MissionInfoMgr::~MissionInfoMgr() HILOG_INFO("MissionInfoMgr instance is destroyed"); } -bool MissionInfoMgr::GenerateMissionId(int32_t &misisonId) +bool MissionInfoMgr::GenerateMissionId(int32_t &missionId) { - for (int32_t index = MIN_MISSION_ID; index <= MAX_MISSION_ID; index++) { + if (currentMisionId_ == MAX_MISSION_ID) { + currentMisionId_ = MIN_MISSION_ID; + } + + for (int32_t index = currentMisionId_; index < MAX_MISSION_ID; index++) { if (missionIdMap_.find(index) == missionIdMap_.end()) { - misisonId = index; - missionIdMap_[misisonId] = false; + missionId = index; + missionIdMap_[missionId] = false; + currentMisionId_ = missionId + 1; return true; } } @@ -351,6 +356,28 @@ bool MissionInfoMgr::LoadAllMissionInfo() return true; } +void MissionInfoMgr::HandleUnInstallApp(const std::string &bundleName, int32_t uid, std::list &missions) +{ + HILOG_INFO("HandleUnInstallApp, bundleName:%{public}s, uid:%{public}d", bundleName.c_str(), uid); + GetMatchedMission(bundleName, uid, missions); + if (missions.empty()) { + return; + } + + for (auto missionId : missions) { + DeleteMissionInfo(missionId); + } +} + +void MissionInfoMgr::GetMatchedMission(const std::string &bundleName, int32_t uid, std::list &missions) +{ + for (const auto& innerMissionInfo : missionInfoList_) { + if (innerMissionInfo.bundleName == bundleName && innerMissionInfo.uid == uid) { + missions.push_back(innerMissionInfo.missionInfo.id); + } + } +} + void MissionInfoMgr::Dump(std::vector &info) { for (const auto& innerMissionInfo : missionInfoList_) { diff --git a/services/abilitymgr/src/mission_list.cpp b/services/abilitymgr/src/mission_list.cpp index b127d033804..742dfa0b070 100644 --- a/services/abilitymgr/src/mission_list.cpp +++ b/services/abilitymgr/src/mission_list.cpp @@ -259,6 +259,41 @@ std::string MissionList::GetTypeName() } } +void MissionList::HandleUnInstallApp(const std::string &bundleName, int32_t uid) +{ + for (auto it = missions_.begin(); it != missions_.end();) { + auto mission = *it; + if (MatchedInitialMission(mission, bundleName, uid)) { + missions_.erase(it++); + } else { + it++; + } + } +} + +bool MissionList::MatchedInitialMission(const std::shared_ptr& mission, + const std::string &bundleName, int32_t uid) +{ + if (!mission) { + return false; + } + + auto abilityRecord = mission->GetAbilityRecord(); + if (!abilityRecord) { + return false; + } + + if (abilityRecord->GetAbilityInfo().bundleName == bundleName && abilityRecord->GetUid() == uid) { + abilityRecord->SetIsUninstallAbility(); + if (abilityRecord->IsAbilityState(AbilityState::INITIAL)) { + return true; + } + } + + return false; +} + + void MissionList::Dump(std::vector& info) { std::string dumpInfo = " MissionList Type #" + GetTypeName(); diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index c1fb9290a48..17f1166cd8a 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -351,6 +351,8 @@ void MissionListManager::GetTargetMissionAndAbility(const AbilityRequest &abilit info.missionName = missionName; info.isSingletonMode = isSingleton; info.startMethod = startMethod; + info.bundleName = abilityRequest.abilityInfo.bundleName; + info.uid = abilityRequest.uid; info.missionInfo.runningState = 0; info.missionInfo.continuable = abilityRequest.abilityInfo.continuable; info.missionInfo.time = Time2str(time(0)); @@ -931,7 +933,7 @@ void MissionListManager::CompleteBackground(const std::shared_ptr // new version. started by caller, sdheduler call request if (abilityRecord->IsStartedByCall() && abilityRecord->IsStartToBackground() && abilityRecord->IsReady()) { - HILOG_DEBUG("call request after completing backgroud state"); + HILOG_DEBUG("call request after completing background state"); abilityRecord->CallRequest(); abilityRecord->SetStartToBackground(false); } @@ -1177,10 +1179,15 @@ void MissionListManager::CompleteTerminateAndUpdateMission(const std::shared_ptr std::shared_ptr MissionListManager::GetAbilityFromTerminateList(const sptr &token) { + if (!token) { + return nullptr; + } + std::lock_guard guard(managerLock_); for (auto abilityRecord : terminateAbilityList_) { // token is type of IRemoteObject, abilityRecord->GetToken() is type of Token extending from IRemoteObject. - if (abilityRecord && token == abilityRecord->GetToken()->AsObject()) { + if (abilityRecord && abilityRecord->GetToken() && + abilityRecord->GetToken() && token == abilityRecord->GetToken()->AsObject()) { return abilityRecord; } } @@ -1793,10 +1800,13 @@ void MissionListManager::HandleAbilityDiedByDefault(std::shared_ptr::GetInstance()->GetInnerMissionInfoById(mission->GetMissionId(), info) == 0) { - info.missionInfo.runningState = -1; - DelayedSingleton::GetInstance()->UpdateMissionInfo(info); + if (!ability->IsUninstallAbility()) { + InnerMissionInfo info; + if (DelayedSingleton::GetInstance()->GetInnerMissionInfoById( + mission->GetMissionId(), info) == 0) { + info.missionInfo.runningState = -1; + DelayedSingleton::GetInstance()->UpdateMissionInfo(info); + } } // start launcher @@ -2308,6 +2318,44 @@ std::shared_ptr MissionListManager::GetCurrentTopAbility(const st return {}; } +void MissionListManager::UninstallApp(const std::string &bundleName, int32_t uid) +{ + HILOG_INFO("Uninstall app, bundleName: %{public}s, uid:%{public}d", bundleName.c_str(), uid); + auto abilityManagerService = DelayedSingleton::GetInstance(); + CHECK_POINTER(abilityManagerService); + auto handler = abilityManagerService->GetEventHandler(); + CHECK_POINTER(handler); + std::weak_ptr wpMgr = shared_from_this(); + auto task = [wpMgr, bundleName, uid]() { + HILOG_INFO("Handle Uninstall app, bundleName: %{public}s, uid:%{public}d", bundleName.c_str(), uid); + auto mgr = wpMgr.lock(); + if (mgr) { + mgr->AddUninstallTags(bundleName, uid); + } + }; + handler->PostTask(task); +} + +void MissionListManager::AddUninstallTags(const std::string &bundleName, int32_t uid) +{ + HILOG_INFO("AddUninstallTags, bundleName: %{public}s, uid:%{public}d", bundleName.c_str(), uid); + for (auto& missionList : currentMissionLists_) { + if (missionList) { + missionList->HandleUnInstallApp(bundleName, uid); // add tag here. + if (missionList->IsEmpty()) { + currentMissionLists_.remove(missionList); + } + } + } + defaultSingleList_->HandleUnInstallApp(bundleName, uid); + defaultStandardList_->HandleUnInstallApp(bundleName, uid); + std::list matchedMissions; + DelayedSingleton::GetInstance()->HandleUnInstallApp(bundleName, uid, matchedMissions); + if (listenerController_) { + listenerController_->HandleUnInstallApp(matchedMissions); + } +} + bool MissionListManager::IsStarted() { std::lock_guard guard(managerLock_); diff --git a/services/abilitymgr/src/mission_listener_controller.cpp b/services/abilitymgr/src/mission_listener_controller.cpp index fc3b6753b82..c53591d8e05 100644 --- a/services/abilitymgr/src/mission_listener_controller.cpp +++ b/services/abilitymgr/src/mission_listener_controller.cpp @@ -133,6 +133,31 @@ void MissionListenerController::NotifyMissionDestroyed(int32_t missionId) handler_->PostTask(task); } +void MissionListenerController::HandleUnInstallApp(const std::list &missions) +{ + if (!handler_) { + HILOG_ERROR("handler not init"); + return; + } + + if (missions.empty()) { + return; + } + + auto task = [weak = weak_from_this(), missions]() { + auto self = weak.lock(); + if (self == nullptr) { + HILOG_ERROR("self is nullptr, NotifyMissionDestroyed failed."); + return; + } + for (auto id : missions) { + self->NotifyListeners(id, Cmd::ON_MISSION_DESTROYED); + } + }; + handler_->PostTask(task); + +} + void MissionListenerController::NotifyMissionSnapshotChanged(int32_t missionId) { if (!handler_) { diff --git a/services/abilitymgr/src/pending_want_manager.cpp b/services/abilitymgr/src/pending_want_manager.cpp index 0f4c522e1bf..665e4dcafc0 100644 --- a/services/abilitymgr/src/pending_want_manager.cpp +++ b/services/abilitymgr/src/pending_want_manager.cpp @@ -481,18 +481,18 @@ int32_t PendingWantManager::GetWantSenderInfo(const sptr &target, s return NO_ERROR; } -void PendingWantManager::ClearPendingWantRecord(const std::string &bundleName) +void PendingWantManager::ClearPendingWantRecord(const std::string &bundleName, int32_t uid) { HILOG_INFO("ClearPendingWantRecord, bundleName: %{public}s", bundleName.c_str()); auto abilityManagerService = DelayedSingleton::GetInstance(); CHECK_POINTER(abilityManagerService); auto handler = abilityManagerService->GetEventHandler(); CHECK_POINTER(handler); - auto task = [bundleName, self = shared_from_this()]() { self->ClearPendingWantRecordTask(bundleName); }; + auto task = [bundleName, uid, self = shared_from_this()]() { self->ClearPendingWantRecordTask(bundleName, uid); }; handler->PostTask(task); } -void PendingWantManager::ClearPendingWantRecordTask(const std::string &bundleName) +void PendingWantManager::ClearPendingWantRecordTask(const std::string &bundleName, int32_t uid) { HILOG_INFO("ClearPendingWantRecordTask, bundleName: %{public}s", bundleName.c_str()); std::lock_guard locker(mutex_); @@ -503,7 +503,7 @@ void PendingWantManager::ClearPendingWantRecordTask(const std::string &bundleNam if ((pendingRecord != nullptr)) { auto wantInfos = pendingRecord->GetKey()->GetAllWantsInfos(); for (const auto &wantInfo: wantInfos) { - if (wantInfo.want.GetBundle() == bundleName) { + if (wantInfo.want.GetBundle() == bundleName && uid == pendingRecord->GetUid()) { hasBundle = true; break; } diff --git a/services/abilitymgr/src/shared_memory.cpp b/services/abilitymgr/src/shared_memory.cpp index 621209f63bd..d73188b7a85 100644 --- a/services/abilitymgr/src/shared_memory.cpp +++ b/services/abilitymgr/src/shared_memory.cpp @@ -93,7 +93,7 @@ void* SharedMemory::PopSharedMemory(int shmKey, int size) HILOG_ERROR("size is invalid: %{public}d.", size); return nullptr; } - void *data = reinterpret_cast(malloc(size)); + int shmId = shmget(shmKey, 0, 0 | SHM_READ_WRITE_PERMISSIONS); if (shmId == -1) { HILOG_ERROR("shmId is invalid: %{public}d, %{public}d.", shmId, errno); @@ -107,17 +107,20 @@ void* SharedMemory::PopSharedMemory(int shmKey, int size) return nullptr; } + void *data = reinterpret_cast(malloc(size)); int retCode = memcpy_s(data, size, shared, size); if (retCode != EOK) { shmdt(shared); ReleaseShmId(shmId); HILOG_ERROR("Failed to memory copy, retCode[%{public}d].", retCode); + free(data); return nullptr; } if (shmdt(shared) == -1) { ReleaseShmId(shmId); HILOG_ERROR("shmdt failed: %{public}d.", errno); + free(data); return nullptr; } diff --git a/services/abilitymgr/test/mock/appmgr_test_service/src/appmgr_test_service.cpp b/services/abilitymgr/test/mock/appmgr_test_service/src/appmgr_test_service.cpp index 0be423eb874..e7a725cadbb 100644 --- a/services/abilitymgr/test/mock/appmgr_test_service/src/appmgr_test_service.cpp +++ b/services/abilitymgr/test/mock/appmgr_test_service/src/appmgr_test_service.cpp @@ -96,7 +96,7 @@ void AppMgrEventHandler::ScheduleAbilityTransaction(const AppExecFwk::InnerEvent auto abilityToken = tokenMap_[abilitySched]; if (abilityToken == nullptr) { - HILOG_ERROR("abilityToken unavailable. object: %p", object.get()); + HILOG_ERROR("abilityToken unavailable."); return; } @@ -139,7 +139,7 @@ void AppMgrEventHandler::ScheduleDisconnectAbilityTransaction(const AppExecFwk:: auto abilityToken = tokenMap_[abilitySched]; if (abilityToken == nullptr) { - HILOG_ERROR("abilityToken unavailable. object: %p", object.get()); + HILOG_ERROR("abilityToken unavailable."); return; } diff --git a/services/abilitymgr/test/mock/include/mock_app_manager_client.h b/services/abilitymgr/test/mock/include/mock_app_manager_client.h index c6620b266d0..7956f6d3713 100644 --- a/services/abilitymgr/test/mock/include/mock_app_manager_client.h +++ b/services/abilitymgr/test/mock/include/mock_app_manager_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -41,7 +41,6 @@ public: const int32_t visibility, const int32_t perceptibility, const int32_t connectionState)); MOCK_METHOD1(KillProcessByAbilityToken, AppMgrResultCode(const sptr &token)); MOCK_METHOD1(KillProcessesByUserId, AppMgrResultCode(int32_t userId)); - MOCK_METHOD4(CompelVerifyPermission, int(const std::string &permission, int pid, int uid, std::string &message)); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h index f46e167b051..7ad8cb18e2a 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -164,18 +164,6 @@ public: virtual void PrepareTerminate(const sptr &token); - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message); - private: void SetServiceManager(std::unique_ptr serviceMgr); diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp index 8b67084fd6b..3c730865e4d 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp @@ -101,11 +101,6 @@ void AppMgrClient::AbilityAttachTimeOut(const sptr &token) void AppMgrClient::PrepareTerminate(const sptr &token) {} -int AppMgrClient::CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) -{ - return AppMgrResultCode::RESULT_OK; -} - void AppMgrClient::GetSystemMemoryAttr(SystemMemoryAttr &memoryInfo, std::string &strConfig) {} diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp index d70ce17557a..a16078df5cb 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -126,12 +126,6 @@ void AppScheduler::PrepareTerminate(const sptr &token) HILOG_INFO("Test AppScheduler::PrepareTerminate()"); } -int AppScheduler::CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) -{ - HILOG_INFO("Test AppScheduler::CompelVerifyPermission()"); - return ERR_OK; -} - void AppScheduler::OnAppStateChanged(const AppExecFwk::AppProcessData &appData) { HILOG_INFO("Test AppScheduler::OnAppStateChanged()"); diff --git a/services/abilitymgr/test/unittest/phone/ability_connect_manage_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_connect_manage_test/BUILD.gn index a22b1865f31..1a82cb08819 100755 --- a/services/abilitymgr/test/unittest/phone/ability_connect_manage_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_connect_manage_test/BUILD.gn @@ -66,6 +66,5 @@ ohos_unittest("ability_connect_manage_test") { group("unittest") { testonly = true - - deps = [ ":ability_connect_manage_test" ] + # deps = [ ":ability_connect_manage_test" ] } diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h b/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h index 2d4167321ee..f064283b3ab 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -212,24 +212,24 @@ public: return 0; } - virtual int UninstallApp(const std::string &bundleName) + virtual int UninstallApp(const std::string &bundleName, int32_t uid) { return 0; } - virtual int MoveMissionToTop(int32_t missionId) + virtual int32_t GetMissionIdByToken(const sptr &token) override { return 0; } - bool IsFirstInMission(const sptr &token) override + virtual int MoveMissionToTop(int32_t missionId) { - return true; + return 0; } - int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override + bool IsFirstInMission(const sptr &token) override { - return 0; + return true; } int MoveMissionToEnd(const sptr &token, const bool nonFirst) override diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h index 3c2a6b1714f..11cb38f66b7 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -212,24 +212,24 @@ public: return 0; } - virtual int UninstallApp(const std::string &bundleName) + virtual int UninstallApp(const std::string &bundleName, int32_t uid) { return 0; } - virtual int MoveMissionToTop(int32_t missionId) + virtual int32_t GetMissionIdByToken(const sptr &token) override { return 0; } - bool IsFirstInMission(const sptr &token) override + virtual int MoveMissionToTop(int32_t missionId) { - return true; + return 0; } - int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override + bool IsFirstInMission(const sptr &token) override { - return 0; + return true; } int MoveMissionToEnd(const sptr &token, const bool nonFirst) override diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp index c75b01ef44c..ae0b36b1d0f 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -1262,7 +1262,7 @@ HWTEST_F(AbilityManagerServiceTest, Interface_029, TestSize.Level1) HWTEST_F(AbilityManagerServiceTest, Interface_030, TestSize.Level1) { abilityMs_->currentStackManager_ = nullptr; - auto result = abilityMs_->UninstallApp("bundle"); + auto result = abilityMs_->UninstallApp("bundle", -1); EXPECT_EQ(ERR_NO_INIT, result); } @@ -2797,24 +2797,6 @@ HWTEST_F(AbilityManagerServiceTest, movemissiontoend_012, TestSize.Level1) EXPECT_EQ(resultFunction, MOVE_MISSION_FAILED); } -/* - * Feature: AbilityManagerService - * Function: CompelVerifyPermission - * SubFunction: NA - * FunctionPoints: AbilityManagerService CompelVerifyPermission - * EnvConditions: NA - * CaseDescription: Verify function CompelVerifyPermission - */ -HWTEST_F(AbilityManagerServiceTest, compelverifypermission_001, TestSize.Level1) -{ - const std::string permission = "permission"; - int pid = 100; - int uid = 1000; - std::string message; - auto resultFunction = abilityMs_->CompelVerifyPermission(permission, pid, uid, message); - EXPECT_EQ(resultFunction, ERR_OK); -} - /* * Feature: AbilityManagerService * Function: AmsConfigurationParameter diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 9a128f97072..1da93ac68b2 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -225,7 +225,7 @@ public: return 0; } - virtual int UninstallApp(const std::string &bundleName) + virtual int UninstallApp(const std::string &bundleName, int32_t uid) { return 0; } @@ -240,11 +240,6 @@ public: return true; } - int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override - { - return 0; - } - int MoveMissionToEnd(const sptr &token, const bool nonFirst) override { return 0; @@ -365,6 +360,10 @@ public: { return 0; } + virtual int32_t GetMissionIdByToken(const sptr &token) override + { + return 0; + } virtual int GetMissionInfos(const std::string& deviceId, int32_t numMax, std::vector &missionInfos) override { diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h index 86e8505154f..ebae85c6f74 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -65,12 +65,12 @@ public: MOCK_METHOD1(RemoveStack, int(int)); MOCK_METHOD1(MoveMissionToTop, int(int32_t)); MOCK_METHOD1(KillProcess, int(const std::string &)); - MOCK_METHOD1(UninstallApp, int(const std::string &)); + MOCK_METHOD2(UninstallApp, int(const std::string &, int32_t)); + MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr &callerToken, int requestCode)); MOCK_METHOD3(StartAbility, int(const Want &want, const sptr &callerToken, int requestCode)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr &token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr &token)); - MOCK_METHOD4(CompelVerifyPermission, int(const std::string &permission, int pid, int uid, std::string &message)); MOCK_METHOD0(PowerOff, int()); MOCK_METHOD0(PowerOn, int()); MOCK_METHOD1(LockMission, int(int)); diff --git a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp index b16d19871ed..05d94121bd2 100644 --- a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -2199,7 +2199,7 @@ HWTEST_F(AbilityStackManagerTest, ability_stack_manager_operating_061, TestSize. stackManager_->Init(); auto abilityStartSetting = AbilityStartSetting::GetEmptySetting(); - // defult mission id + // default mission id abilityStartSetting->AddProperty(AbilityStartSetting::WINDOW_MODE_KEY, std::to_string(AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FULLSCREEN)); EXPECT_TRUE(abilityStartSetting); @@ -2289,7 +2289,7 @@ HWTEST_F(AbilityStackManagerTest, ability_stack_manager_operating_062, TestSize. * SubFunction: NA * FunctionPoints: Start the floating window according to the parameters * EnvConditions: NA - * CaseDescription: a defult ability + Start a floating window application + * CaseDescription: a default ability + Start a floating window application */ HWTEST_F(AbilityStackManagerTest, ability_stack_manager_operating_063, TestSize.Level1) { @@ -2414,7 +2414,7 @@ HWTEST_F(AbilityStackManagerTest, ability_stack_manager_operating_065, TestSize. EXPECT_TRUE(stact); EXPECT_EQ(stact->GetMissionStackId(), FLOATING_MISSION_STACK_ID); - // radioAbility in the defult stack + // radioAbility in the default stack EXPECT_EQ(redioMissionRecord->GetMissionStack()->GetMissionStackId(), DEFAULT_MISSION_STACK_ID); } diff --git a/services/abilitymgr/test/unittest/phone/data_ability_manager_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/data_ability_manager_test/BUILD.gn index f88bd33be43..3bf6449c2e3 100755 --- a/services/abilitymgr/test/unittest/phone/data_ability_manager_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/data_ability_manager_test/BUILD.gn @@ -76,6 +76,5 @@ ohos_unittest("data_ability_manager_test") { group("unittest") { testonly = true - - deps = [ ":data_ability_manager_test" ] + # deps = [ ":data_ability_manager_test" ] } diff --git a/services/abilitymgr/test/unittest/phone/pending_want_manager_test/pending_want_manager_test.cpp b/services/abilitymgr/test/unittest/phone/pending_want_manager_test/pending_want_manager_test.cpp index 3007f1aed71..38d97defaae 100644 --- a/services/abilitymgr/test/unittest/phone/pending_want_manager_test/pending_want_manager_test.cpp +++ b/services/abilitymgr/test/unittest/phone/pending_want_manager_test/pending_want_manager_test.cpp @@ -928,7 +928,7 @@ HWTEST_F(PendingWantManagerTest, PendingWantManagerTest_3500, TestSize.Level1) pendingManager_->GetWantSenderLocked(1, 1, wantSenderInfo1.userId, wantSenderInfo1, nullptr)->AsObject()); EXPECT_NE(pendingRecord1, nullptr); EXPECT_EQ((int)pendingManager_->wantRecords_.size(), 2); - pendingManager_->ClearPendingWantRecordTask("bundleName2"); + pendingManager_->ClearPendingWantRecordTask("bundleName2", 1); EXPECT_EQ((int)pendingManager_->wantRecords_.size(), 0); } @@ -965,7 +965,7 @@ HWTEST_F(PendingWantManagerTest, PendingWantManagerTest_3600, TestSize.Level1) pendingManager_->GetWantSenderLocked(1, 1, wantSenderInfo1.userId, wantSenderInfo1, nullptr)->AsObject()); EXPECT_NE(pendingRecord1, nullptr); EXPECT_EQ((int)pendingManager_->wantRecords_.size(), 2); - pendingManager_->ClearPendingWantRecordTask("bundleName1"); + pendingManager_->ClearPendingWantRecordTask("bundleName1", 1); EXPECT_EQ((int)pendingManager_->wantRecords_.size(), 1); } @@ -1002,7 +1002,7 @@ HWTEST_F(PendingWantManagerTest, PendingWantManagerTest_3700, TestSize.Level1) pendingManager_->GetWantSenderLocked(1, 1, wantSenderInfo1.userId, wantSenderInfo1, nullptr)->AsObject()); EXPECT_NE(pendingRecord1, nullptr); EXPECT_EQ((int)pendingManager_->wantRecords_.size(), 2); - pendingManager_->ClearPendingWantRecordTask("bundleName3"); + pendingManager_->ClearPendingWantRecordTask("bundleName3", 1); EXPECT_EQ((int)pendingManager_->wantRecords_.size(), 2); } diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index 990f6c59776..faf7b386d04 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -150,18 +150,6 @@ public: virtual void PrepareTerminate(const sptr &token) override; - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override; - virtual void GetRunningProcessInfoByToken( const sptr &token, AppExecFwk::RunningProcessInfo &info) override; diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 7c9d8f8cfda..c53f4049b63 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -36,6 +36,7 @@ #include "app_running_record.h" #include "app_scheduler_proxy.h" #include "ams_mgr_scheduler.h" +#include "ams_mgr_scheduler.h" namespace OHOS { namespace AppExecFwk { @@ -214,6 +215,13 @@ public: virtual void AttachRenderProcess(const sptr &shceduler) override; + /** + * Post a task to the not response process. + * + * @param pid, the not response process id. + */ + virtual void PostANRTaskByProcessID(const pid_t pid) override; + private: /** * Init, Initialize application services. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 9aed583b74f..e0bf702209b 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -412,18 +412,6 @@ public: void PrepareTerminate(const sptr &token); - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message); - /** * OnAppStateChanged, Application state changed. * diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 7782b001111..a82e44c9037 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -485,6 +485,7 @@ public: bool IsStartSpecifiedAbility() const; void ScheduleAcceptWant(const std::string &moduleName); void ScheduleAcceptWantDone(); + void ApplicationTerminated(); const AAFwk::Want &GetSpecifiedWant() const; void SetDebugApp(bool isDebugApp); void SetRenderRecord(const std::shared_ptr &record); diff --git a/services/appmgr/include/module_running_record.h b/services/appmgr/include/module_running_record.h index 8d45bb39837..a877f3d63a0 100644 --- a/services/appmgr/include/module_running_record.h +++ b/services/appmgr/include/module_running_record.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -174,7 +174,7 @@ private: void SendEvent(uint32_t msg, int64_t timeOut, const std::shared_ptr &abilityRecord); ModuleRecordState GetState() const; - + private: std::map, std::shared_ptr> abilities_; std::map, std::shared_ptr> terminateAbilitys_; diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 8726441dfcf..eb061a3fb58 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -223,14 +223,6 @@ bool AmsMgrScheduler::IsReady() const return true; } -int AmsMgrScheduler::CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) -{ - if (!IsReady()) { - return ERR_INVALID_OPERATION; - } - return amsMgrServiceInner_->CompelVerifyPermission(permission, pid, uid, message); -} - void AmsMgrScheduler::GetRunningProcessInfoByToken( const sptr &token, AppExecFwk::RunningProcessInfo &info) { diff --git a/services/appmgr/src/app_death_recipient.cpp b/services/appmgr/src/app_death_recipient.cpp index 64112141172..9dde4a875d8 100644 --- a/services/appmgr/src/app_death_recipient.cpp +++ b/services/appmgr/src/app_death_recipient.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -14,7 +14,6 @@ */ #include "app_death_recipient.h" - #include "app_mgr_service_inner.h" #include "hilog_wrapper.h" diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 72426c43a66..2c191af31fb 100755 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -435,5 +435,25 @@ void AppMgrService::AttachRenderProcess(const sptr &scheduler) appMgrServiceInner_, pid, iface_cast(scheduler)); handler_->PostTask(fun, TASK_ATTACH_RENDER_PROCESS); } + +void AppMgrService::PostANRTaskByProcessID(const pid_t pid) +{ + HILOG_DEBUG("PostANRTaskByProcessID called."); + if (!IsReady()) { + HILOG_ERROR("AttachRenderProcess failed, not ready."); + return; + } + auto appRecord = appMgrServiceInner_->GetAppRunningRecordByPid(pid); + if (!appRecord) { + HILOG_ERROR("no such appRecord"); + return; + } + auto object = appRecord->GetApplicationClient(); + if (!object) { + HILOG_ERROR("GetApplicationClient failed."); + return; + } + object->ScheduleANRProcess(); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index c5f8a27088d..88280259cb4 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -66,8 +66,6 @@ const std::string FUNC_NAME = "main"; const std::string SO_PATH = "system/lib64/libmapleappkit.z.so"; const std::string RENDER_PARAM = "invalidparam"; const int32_t SIGNAL_KILL = 9; -const std::string REQ_PERMISSION = "ohos.permission.LOCATION_IN_BACKGROUND"; -constexpr int32_t SYSTEM_UID = 1000; constexpr int32_t USER_SCALE = 200000; #define ENUM_TO_STRING(s) #s @@ -365,6 +363,7 @@ void AppMgrServiceInner::ApplicationTerminated(const int32_t recordId) HILOG_ERROR("get app record failed"); return; } + appRecord->ApplicationTerminated(); // Maybe can't get in here if (appRecord->IsKeepAliveApp()) { return; @@ -919,7 +918,7 @@ void AppMgrServiceInner::KillProcessByAbilityToken(const sptr &to return; } - // befor exec ScheduleProcessSecurityExit return + // before exec ScheduleProcessSecurityExit return // The resident process won't let him die if (appRecord->IsKeepAliveApp()) { return; @@ -1483,12 +1482,6 @@ void AppMgrServiceInner::HandleTerminateApplicationTimeOut(const int64_t eventId HILOG_ERROR("appRecord is nullptr"); return; } - - auto abilityRecord = appRecord->GetAbilityRunningRecord(eventId); - if (!abilityRecord) { - HILOG_ERROR("abilityRecord is nullptr"); - return; - } appRecord->SetState(ApplicationState::APP_STATE_TERMINATED); appRecord->RemoveAppDeathRecipient(); OnAppStateChanged(appRecord, ApplicationState::APP_STATE_TERMINATED); @@ -1525,57 +1518,6 @@ void AppMgrServiceInner::HandleAddAbilityStageTimeOut(const int64_t eventId) KillApplicationByRecord(appRecord); } -int AppMgrServiceInner::CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) -{ - HILOG_INFO("compel verify permission"); - message = ENUM_TO_STRING(PERMISSION_NOT_GRANTED); - if (!remoteClientManager_) { - HILOG_ERROR("remoteClientManager_ is nullptr"); - return ERR_NO_INIT; - } - if (permission.empty()) { - HILOG_INFO("permission is empty, PERMISSION_GRANTED"); - message = ENUM_TO_STRING(PERMISSION_GRANTED); - return ERR_OK; - } - if (pid == getpid()) { - HILOG_INFO("pid is my pid, PERMISSION_GRANTED"); - message = ENUM_TO_STRING(PERMISSION_GRANTED); - return ERR_OK; - } - int userId = Constants::DEFAULT_USERID; - auto appRecord = GetAppRunningRecordByPid(pid); - if (!appRecord) { - HILOG_ERROR("app record is nullptr"); - return PERMISSION_NOT_GRANTED; - } - auto bundleName = appRecord->GetBundleName(); - if (appRecord->GetCloneInfo()) { - userId = Constants::C_UESRID; - } - auto bundleMgr = remoteClientManager_->GetBundleManager(); - if (bundleMgr == nullptr) { - HILOG_ERROR("GetBundleManager fail"); - return ERR_NO_INIT; - } - auto bmsUid = IN_PROCESS_CALL(bundleMgr->GetUidByBundleName(bundleName, userId)); - if (bmsUid == ROOT_UID || bmsUid == SYSTEM_UID) { - HILOG_INFO("uid is root or system, PERMISSION_GRANTED"); - message = ENUM_TO_STRING(PERMISSION_GRANTED); - return ERR_OK; - } - if (bmsUid != uid) { - HILOG_INFO("check uid != bms uid, PERMISSION_NOT_GRANTED"); - return PERMISSION_NOT_GRANTED; - } - auto result = IN_PROCESS_CALL(bundleMgr->CheckPermissionByUid(bundleName, permission, userId)); - if (result != PERMISSION_GRANTED) { - return PERMISSION_NOT_GRANTED; - } - message = ENUM_TO_STRING(PERMISSION_GRANTED); - return ERR_OK; -} - void AppMgrServiceInner::GetRunningProcessInfoByToken( const sptr &token, AppExecFwk::RunningProcessInfo &info) { @@ -1932,12 +1874,8 @@ int AppMgrServiceInner::GetHapModuleInfoForTestRunner(const AAFwk::Want &want, c moduelJson = bundleInfo.hapModuleInfos.back().isModuleJson; } if (moduelJson) { - std::string moudleName; - auto testRunnerName = want.GetStringParam("-s unittest"); - auto pos = testRunnerName.find(":"); - if (pos != std::string::npos) { - moudleName = testRunnerName.substr(0, pos); - } else { + std::string moudleName = want.GetStringParam("-m"); + if (moudleName.empty()) { UserTestAbnormalFinish(observer, "No module name isn't unspecified."); return ERR_INVALID_VALUE; } diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 01822e7c72f..51b73361f80 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -1009,6 +1009,19 @@ void AppRunningRecord::ScheduleAcceptWantDone() eventHandler_->RemoveEvent(AMSEventHandler::START_SPECIFIED_ABILITY_TIMEOUT_MSG, eventId_); } +void AppRunningRecord::ApplicationTerminated() +{ + HILOG_DEBUG("Application terminated bundle %{public}s and eventId %{public}d", mainBundleName_.c_str(), + static_cast(eventId_)); + + if (!eventHandler_) { + HILOG_ERROR("eventHandler_ is nullptr"); + return; + } + + eventHandler_->RemoveEvent(AMSEventHandler::TERMINATE_APPLICATION_TIMEOUT_MSG, eventId_); +} + const AAFwk::Want &AppRunningRecord::GetSpecifiedWant() const { return SpecifiedWant_; diff --git a/services/appmgr/src/system_environment_information.cpp b/services/appmgr/src/system_environment_information.cpp index 38a1ef322cd..5f316aeec95 100644 --- a/services/appmgr/src/system_environment_information.cpp +++ b/services/appmgr/src/system_environment_information.cpp @@ -98,7 +98,7 @@ static void RequestSystemMemoryInfo(std::map &memInfo) while (fgets(buff, sizeof(buff), fp) != nullptr) { std::string strbuf(buff); - memset_s(buff, sizeof(buff), 0x00, sizeof(buff)); + (void)memset_s(buff, sizeof(buff), 0x00, sizeof(buff)); std::smatch sm; std::smatch smData; bool flag = false; diff --git a/services/appmgr/test/mock/include/mock_ams_mgr_scheduler.h b/services/appmgr/test/mock/include/mock_ams_mgr_scheduler.h index 504630addd4..746a0a89dc1 100644 --- a/services/appmgr/test/mock/include/mock_ams_mgr_scheduler.h +++ b/services/appmgr/test/mock/include/mock_ams_mgr_scheduler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -41,7 +41,6 @@ public: MOCK_METHOD0(IsReady, bool()); MOCK_METHOD1(AbilityAttachTimeOut, void(const sptr &token)); MOCK_METHOD1(PrepareTerminate, void(const sptr &token)); - MOCK_METHOD4(CompelVerifyPermission, int(const std::string &permission, int pid, int uid, std::string &message)); MOCK_METHOD2(GetRunningProcessInfoByToken, void(const sptr &token, OHOS::AppExecFwk::RunningProcessInfo &info)); MOCK_METHOD2(StartSpecifiedAbility, void(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo)); diff --git a/services/appmgr/test/mock/include/mock_app_mgr_service.h b/services/appmgr/test/mock/include/mock_app_mgr_service.h index d90d4bcea8d..aa60310a252 100644 --- a/services/appmgr/test/mock/include/mock_app_mgr_service.h +++ b/services/appmgr/test/mock/include/mock_app_mgr_service.h @@ -55,6 +55,7 @@ public: MOCK_METHOD3(ScheduleAcceptWantDone, void(const int32_t recordId, const AAFwk::Want &want, const std::string &flag)); MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector> &tokens)); + MOCK_METHOD1(PostANRTaskByProcessID, void(const pid_t pid)); virtual int StartUserTestProcess( const AAFwk::Want &want, const sptr &observer, const BundleInfo &bundleInfo) diff --git a/services/appmgr/test/mock/include/mock_app_scheduler.h b/services/appmgr/test/mock/include/mock_app_scheduler.h index 1b45cb5e141..f17c4be3a43 100644 --- a/services/appmgr/test/mock/include/mock_app_scheduler.h +++ b/services/appmgr/test/mock/include/mock_app_scheduler.h @@ -42,6 +42,7 @@ public: MOCK_METHOD0(ScheduleProcessSecurityExit, void()); MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo &)); MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want &want, const std::string &moduleName)); + MOCK_METHOD0(ScheduleANRProcess, void()); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/test/mock/include/mock_application.h b/services/appmgr/test/mock/include/mock_application.h index b537cb26e26..b8a99828852 100644 --- a/services/appmgr/test/mock/include/mock_application.h +++ b/services/appmgr/test/mock/include/mock_application.h @@ -37,6 +37,7 @@ public: MOCK_METHOD0(ScheduleProcessSecurityExit, void()); MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo &)); MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want &want, const std::string &moduleName)); + MOCK_METHOD0(ScheduleANRProcess, void()); void Post() { diff --git a/services/appmgr/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp b/services/appmgr/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp index 9432cf07206..7ce5889de8c 100644 --- a/services/appmgr/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp +++ b/services/appmgr/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -639,7 +639,7 @@ HWTEST_F(AmsWorkFlowTest, ScreenOn_001, TestSize.Level1) * Function: AppLifeCycle * SubFunction: WorkFlow * FunctionPoints: ScreenOn - * CaseDescription: when multiple abilities on backgroud, previous is one ability, simulate screen on + * CaseDescription: when multiple abilities on background, previous is one ability, simulate screen on */ HWTEST_F(AmsWorkFlowTest, ScreenOn_002, TestSize.Level1) { @@ -666,7 +666,7 @@ HWTEST_F(AmsWorkFlowTest, ScreenOn_002, TestSize.Level1) * Function: AppLifeCycle * SubFunction: WorkFlow * FunctionPoints: ScreenOn - * CaseDescription: when multiple abilities on backgroud, all abilities are previous, simulate screen on + * CaseDescription: when multiple abilities on background, all abilities are previous, simulate screen on */ HWTEST_F(AmsWorkFlowTest, ScreenOn_003, TestSize.Level1) { diff --git a/services/common/include/permission_constants.h b/services/common/include/permission_constants.h index fce13bd70ba..e63a3643b17 100644 --- a/services/common/include/permission_constants.h +++ b/services/common/include/permission_constants.h @@ -19,13 +19,14 @@ namespace OHOS { namespace AAFwk { namespace PermissionConstants { +const std::string PERMISSION_CLEAN_APPLICATION_DATA = "ohos.permission.CLEAN_APPLICATION_DATA"; const std::string PERMISSION_CLEAN_BACKGROUND_PROCESSES = "ohos.permission.CLEAN_BACKGROUND_PROCESSES"; -const std::string PERMISSION_INTERACT_ACROSS_LOCAL_ACCOUNTS = "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS"; const std::string PERMISSION_GET_RUNNING_INFO = "ohos.permission.GET_RUNNING_INFO"; -const std::string PERMISSION_UPDATE_CONFIGURATION = "ohos.permission.UPDATE_CONFIGURATION"; -const std::string PERMISSION_CLEAN_APPLICATION_DATA = "ohos.permission.CLEAN_APPLICATION_DATA"; -const std::string PERMISSION_RUNNING_STATE_OBSERVER = "ohos.permission.RUNNING_STATE_OBSERVER"; +const std::string PERMISSION_INTERACT_ACROSS_LOCAL_ACCOUNTS = "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS"; const std::string PERMISSION_MANAGE_MISSION = "ohos.permission.MANAGE_MISSIONS"; +const std::string PERMISSION_RUNNING_STATE_OBSERVER = "ohos.permission.RUNNING_STATE_OBSERVER"; +const std::string PERMISSION_SET_ABILITY_CONTROLLER = "ohos.permission.SET_ABILITY_CONTROLLER"; +const std::string PERMISSION_UPDATE_CONFIGURATION = "ohos.permission.UPDATE_CONFIGURATION"; } // namespace PermissionConstants } // namespace AAFwk } // namespace OHOS diff --git a/services/common/include/permission_verification.h b/services/common/include/permission_verification.h index 89e6fd773ae..f5d8c2e6b2d 100644 --- a/services/common/include/permission_verification.h +++ b/services/common/include/permission_verification.h @@ -33,6 +33,8 @@ public: bool VerifyRunningInfoPerm(); + bool VerifyControllerPerm(); + private: DISALLOW_COPY_AND_MOVE(PermissionVerification); unsigned int GetCallingTokenID(); diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index 10d186be7c3..ebc8368e47a 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -62,6 +62,20 @@ bool PermissionVerification::VerifyRunningInfoPerm() return false; } +bool PermissionVerification::VerifyControllerPerm() +{ + if (IsSACall()) { + HILOG_DEBUG("%{public}s: the interface called by SA.", __func__); + return true; + } + if (VerifyCallingPermission(PermissionConstants::PERMISSION_SET_ABILITY_CONTROLLER)) { + HILOG_DEBUG("%{public}s: Permission verification succeeded.", __func__); + return true; + } + HILOG_ERROR("%{public}s: Permission verification failed.", __func__); + return false; +} + unsigned int PermissionVerification::GetCallingTokenID() { auto callerToken = IPCSkeleton::GetCallingTokenID(); diff --git a/services/dataobsmgr/src/data_ability_observer_proxy.cpp b/services/dataobsmgr/src/data_ability_observer_proxy.cpp index 2d4b0cc6491..157fb562f4b 100644 --- a/services/dataobsmgr/src/data_ability_observer_proxy.cpp +++ b/services/dataobsmgr/src/data_ability_observer_proxy.cpp @@ -48,14 +48,9 @@ void DataAbilityObserverProxy::OnChange() } int result = remote->SendRequest(IDataAbilityObserver::DATA_ABILITY_OBSERVER_CHANGE, data, reply, option); - if (result == ERR_NONE) { - HILOG_INFO("%{public}s SendRequest ok, retval is %d", __func__, reply.ReadInt32()); - return; - } else { + if (result != ERR_NONE) { HILOG_ERROR("%{public}s SendRequest error, result=%{public}d", __func__, result); - return; } } - } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/dataobsmgr/test/unittest/phone/dataobs_mgr_client_test/mock_dataobs_mgr_client.h b/services/dataobsmgr/test/unittest/phone/dataobs_mgr_client_test/mock_dataobs_mgr_client.h index 8d0b9dfd45e..07d51498d99 100644 --- a/services/dataobsmgr/test/unittest/phone/dataobs_mgr_client_test/mock_dataobs_mgr_client.h +++ b/services/dataobsmgr/test/unittest/phone/dataobs_mgr_client_test/mock_dataobs_mgr_client.h @@ -40,13 +40,11 @@ public: std::shared_ptr MockDataObsMgrClient::GetInstance() { if (instance_ == nullptr) { - if (instance_ == nullptr) { - std::shared_ptr client {new (std::nothrow) MockDataObsMgrClient()}; - if (client != nullptr) { - ((MockDataObsMgrClient *)client.get())->Connect(); - } - instance_ = client; + std::shared_ptr client {new (std::nothrow) MockDataObsMgrClient()}; + if (client != nullptr) { + ((MockDataObsMgrClient *)client.get())->Connect(); } + instance_ = client; } return instance_; } diff --git a/services/formmgr/BUILD.gn b/services/formmgr/BUILD.gn index 2ea626ec79d..b7c89cb5791 100644 --- a/services/formmgr/BUILD.gn +++ b/services/formmgr/BUILD.gn @@ -39,6 +39,7 @@ ohos_shared_library("libfms") { sources = [ "src/form_ability_connection.cpp", "src/form_acquire_connection.cpp", + "src/form_acquire_state_connection.cpp", "src/form_ams_helper.cpp", "src/form_batch_delete_connection.cpp", "src/form_bms_helper.cpp", diff --git a/services/formmgr/include/form_acquire_state_connection.h b/services/formmgr/include/form_acquire_state_connection.h new file mode 100644 index 00000000000..3422995e303 --- /dev/null +++ b/services/formmgr/include/form_acquire_state_connection.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_ACQUIRE_STATE_CONNECTION_H +#define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_ACQUIRE_STATE_CONNECTION_H + +#include + +#include "event_handler.h" +#include "form_ability_connection.h" +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +using WantParams = OHOS::AAFwk::WantParams; +using Want = OHOS::AAFwk::Want; + +/** + * @class FormAcquireStateConnection + * Form acquire form state connection stub. + */ +class FormAcquireStateConnection : public FormAbilityConnection { +public: + FormAcquireStateConnection(const std::string &bundleName, const std::string &abilityName, const Want &want); + + virtual ~FormAcquireStateConnection() = default; + + /** + * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. + * @param element service ability's ElementName. + * @param remoteObject the session proxy of service ability. + * @param resultCode ERR_OK on success, others on failure. + */ + void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; + +private: + Want want_; + DISALLOW_COPY_AND_MOVE(FormAcquireStateConnection); +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_ACQUIRE_STATE_CONNECTION_H diff --git a/services/formmgr/include/form_mgr_adapter.h b/services/formmgr/include/form_mgr_adapter.h index cc66dc131df..847e101dd8d 100644 --- a/services/formmgr/include/form_mgr_adapter.h +++ b/services/formmgr/include/form_mgr_adapter.h @@ -21,12 +21,13 @@ #include "bundle_info.h" #include "bundle_mgr_interface.h" -#include "form_info.h" +#include "form_db_info.h" #include "form_host_record.h" +#include "form_info.h" #include "form_item_info.h" #include "form_js_info.h" #include "form_provider_data.h" -#include "form_db_info.h" +#include "form_state_info.h" #include "ipc_types.h" #include "iremote_object.h" #include "want.h" @@ -212,6 +213,25 @@ public: */ int DistributedDataDeleteForm(const std::string &formId); + /** + * @brief Delete the given invalid forms. + * @param formIds Indicates the ID of the forms to delete. + * @param callerToken Caller ability token. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns ERR_OK on success, others on failure. + */ + int DeleteInvalidForms(const std::vector &formIds, const sptr &callerToken, + int32_t &numFormsDeleted); + + /** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param callerToken Caller ability token. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns ERR_OK on success, others on failure. + */ + int AcquireFormState(const Want &want, const sptr &callerToken, FormStateInfo &stateInfo); + /** * @brief Get All FormsInfo. * @param formInfos Return the forms' information of all forms provided. diff --git a/services/formmgr/include/form_mgr_service.h b/services/formmgr/include/form_mgr_service.h index 64ffde7049a..953e04e8102 100644 --- a/services/formmgr/include/form_mgr_service.h +++ b/services/formmgr/include/form_mgr_service.h @@ -202,6 +202,26 @@ public: */ int DistributedDataDeleteForm(const std::string &formId) override; + /** + * @brief Delete the given invalid forms. + * @param formIds Indicates the ID of the forms to delete. + * @param callerToken Caller ability token. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int DeleteInvalidForms(const std::vector &formIds, const sptr &callerToken, + int32_t &numFormsDeleted) override; + + /** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param callerToken Caller ability token. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int AcquireFormState(const Want &want, const sptr &callerToken, + FormStateInfo &stateInfo) override; + /** * @brief Get All FormsInfo. * @param formInfos Return the forms' information of all forms provided. diff --git a/services/formmgr/include/form_provider_mgr.h b/services/formmgr/include/form_provider_mgr.h index 2cee0158a38..4163e70f417 100644 --- a/services/formmgr/include/form_provider_mgr.h +++ b/services/formmgr/include/form_provider_mgr.h @@ -91,6 +91,12 @@ public: */ ErrCode NotifyProviderFormsBatchDelete(const std::string &bundleName, const std::string &abilityName, const std::set &formIds); + /** + * @brief Acquire form state. + * @param want Want. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AcquireFormState(const Want &want); /** * @brief Process js message event. * @param formId Indicates the unique id of form. diff --git a/services/formmgr/include/form_supply_callback.h b/services/formmgr/include/form_supply_callback.h index 244721cffcb..6bb15b9b6ab 100644 --- a/services/formmgr/include/form_supply_callback.h +++ b/services/formmgr/include/form_supply_callback.h @@ -46,6 +46,14 @@ public: */ int OnEventHandle(const Want &want) override; + /** + * @brief Accept form state from form provider. + * @param state Form state. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ + int OnAcquireStateResult(FormState state, const Want &want) override; + /** * @brief Save ability Connection for the callback. * @param connection ability connection. diff --git a/services/formmgr/include/form_task_mgr.h b/services/formmgr/include/form_task_mgr.h index 7403f50a0d0..908b1f3445f 100644 --- a/services/formmgr/include/form_task_mgr.h +++ b/services/formmgr/include/form_task_mgr.h @@ -144,6 +144,14 @@ public: void PostFormEventTask(const int64_t formId, const std::string &message, const Want &want, const sptr &remoteObject); + /** + * @brief Post acquire state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param remoteObject Form provider proxy object. + */ + void PostAcquireStateTask(const Want &wantArg, const Want &want, const sptr &remoteObject); + /** * @brief Post uninstall message to form host(task). * @param formIds The Id list of the forms. @@ -241,6 +249,14 @@ private: void FireFormEvent(const int64_t formId, const std::string &message, const Want &want, const sptr &remoteObject); + /** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param remoteObject Form provider proxy object. + */ + void AcquireState(const Want &wantArg, const Want &want, const sptr &remoteObject); + /** * @brief Handle uninstall message. * @param formIds The Id list of the forms. diff --git a/services/formmgr/include/form_timer.h b/services/formmgr/include/form_timer.h index cffaeb9bdb0..97fccd2e1ad 100644 --- a/services/formmgr/include/form_timer.h +++ b/services/formmgr/include/form_timer.h @@ -115,7 +115,7 @@ public: class DynamicRefreshItem { public: int64_t formId = 0L; - int64_t settedTime = LONG_MAX; + int64_t settedTime = INT64_MAX; int32_t userId = -1; DynamicRefreshItem(){} diff --git a/services/formmgr/include/form_timer_mgr.h b/services/formmgr/include/form_timer_mgr.h index 14f4d14a191..c6541e1f459 100644 --- a/services/formmgr/include/form_timer_mgr.h +++ b/services/formmgr/include/form_timer_mgr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -138,7 +138,7 @@ public: * @param updateTime Update time. * @return Returns true on success, false on failure. */ - bool OnDynamicTimeTrigger(long updateTime); + bool OnDynamicTimeTrigger(int64_t updateTime); /** * @brief Get interval timer task. * @param formId The Id of the form. @@ -266,7 +266,7 @@ private: * @param updateAtItem Next at timer item. * @return Returns true on success, false on failure. */ - bool FindNextAtTimerItem(const int nowTime, UpdateAtItem &updateAtItem); + bool FindNextAtTimerItem(const long nowTime, UpdateAtItem &updateAtItem); /** * @brief Clear update at timer resource. */ @@ -316,7 +316,7 @@ private: * @param nextTime The next update time. * @return Returns WantAgent. */ - std::shared_ptr GetDynamicWantAgent(long nextTime, int32_t userId); + std::shared_ptr GetDynamicWantAgent(int64_t nextTime, int32_t userId); /** * @brief check if user is active or not. @@ -362,13 +362,13 @@ private: std::shared_ptr intervalTimer_ = nullptr; uint64_t updateAtTimerId_ = 0L; uint64_t dynamicAlarmTimerId_ = 0L; - uint64_t limiterTimerId_= 0L; + uint64_t limiterTimerId_ = 0L; std::shared_ptr currentUpdateAtWantAgent = nullptr; std::shared_ptr currentDynamicWantAgent = nullptr; std::shared_ptr currentLimiterWantAgent = nullptr; - long dynamicWakeUpTime_ = LONG_MAX; + int64_t dynamicWakeUpTime_ = INT64_MAX; long atTimerWakeUpTime_ = LONG_MAX; }; } // namespace AppExecFwk diff --git a/services/formmgr/src/form_acquire_state_connection.cpp b/services/formmgr/src/form_acquire_state_connection.cpp new file mode 100644 index 00000000000..63eeefe6a93 --- /dev/null +++ b/services/formmgr/src/form_acquire_state_connection.cpp @@ -0,0 +1,58 @@ + +/* + * Copyright (c) 2021 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 "form_acquire_state_connection.h" + +#include "appexecfwk_errors.h" +#include "form_constants.h" +#include "form_supply_callback.h" +#include "form_task_mgr.h" +#include "form_util.h" +#include "hilog_wrapper.h" +#include "message_parcel.h" +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +FormAcquireStateConnection::FormAcquireStateConnection(const std::string &bundleName, const std::string &abilityName, + const Want &want) + : want_(want) +{ + SetProviderKey(bundleName, abilityName); +} + +/** + * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. + * @param element service ability's ElementName. + * @param remoteObject the session proxy of service ability. + * @param resultCode ERR_OK on success, others on failure. + */ +void FormAcquireStateConnection::OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) +{ + HILOG_INFO("%{public}s called.", __func__); + if (resultCode != ERR_OK) { + HILOG_ERROR("%{public}s, abilityName:%{public}s, resultCode:%{public}d", + __func__, element.GetAbilityName().c_str(), resultCode); + return; + } + FormSupplyCallback::GetInstance()->AddConnection(this); + Want want; + want.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId()); + FormTaskMgr::GetInstance().PostAcquireStateTask(want_, want, remoteObject); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/formmgr/src/form_mgr_adapter.cpp b/services/formmgr/src/form_mgr_adapter.cpp index cbc287c2482..2591efe2f3f 100644 --- a/services/formmgr/src/form_mgr_adapter.cpp +++ b/services/formmgr/src/form_mgr_adapter.cpp @@ -18,6 +18,7 @@ #include "appexecfwk_errors.h" #include "form_acquire_connection.h" +#include "form_acquire_state_connection.h" #include "form_ams_helper.h" #include "form_bms_helper.h" #include "form_cache_mgr.h" @@ -1712,6 +1713,99 @@ int32_t FormMgrAdapter::GetCurrentUserId(const int callingUid) int32_t userId = callingUid / UID_CALLINGUID_TRANSFORM_DIVISOR; return userId; } + +/** + * @brief Delete the given invalid forms. + * @param formIds Indicates the ID of the forms to delete. + * @param callerToken Caller ability token. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrAdapter::DeleteInvalidForms(const std::vector &formIds, const sptr &callerToken, + int32_t &numFormsDeleted) +{ + HILOG_INFO("%{public}s called.", __func__); + if (callerToken == nullptr) { + HILOG_ERROR("%{public}s, deleteForm invalid param", __func__); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; + } + numFormsDeleted = 0; + + for (int64_t formId: formIds) { + HILOG_DEBUG("check formId: %{public}" PRId64 "", formId); + if (formId <= 0) { + continue; + } + int64_t matchedFormId = FormDataMgr::GetInstance().FindMatchedFormId(formId); + if (FormDataMgr::GetInstance().ExistTempForm(matchedFormId)) { + HILOG_INFO("delete temp form, formId: %{public}" PRId64 "", formId); + int ret = HandleDeleteTempForm(matchedFormId, callerToken); + if (ret == ERR_OK) { + numFormsDeleted++; + } else { + HILOG_ERROR("failed to delete the temp form, formId: %{public}" PRId64 "", formId); + } + continue; + } + + if (!FormDataMgr::GetInstance().ExistFormRecord(matchedFormId)) { + HILOG_ERROR("%{public}s, not exist such form:%{public}" PRId64 "", __func__, matchedFormId); + continue; + } + + HILOG_INFO("delete form, formId: %{public}" PRId64 "", formId); + int ret = HandleDeleteForm(matchedFormId, callerToken); + if (ret == ERR_OK) { + numFormsDeleted++; + } else { + HILOG_ERROR("failed to delete the form, formId: %{public}" PRId64 "", formId); + } + } + HILOG_INFO("%{public}s done, %{public}d forms deleted.", __func__, numFormsDeleted); + return ERR_OK; +} + +/** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param callerToken Caller ability token. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrAdapter::AcquireFormState(const Want &want, const sptr &callerToken, + FormStateInfo &stateInfo) +{ + if (callerToken == nullptr) { + HILOG_ERROR("%{public}s, deleteForm invalid param", __func__); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; + } + std::string bundleName = want.GetElement().GetBundleName(); + std::string abilityName = want.GetElement().GetAbilityName(); + + if (bundleName.empty()) { + HILOG_ERROR("%{public}s error, bundleName is empty.", __func__); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; + } + if (abilityName.empty()) { + HILOG_ERROR("%{public}s error, abilityName is empty.", __func__); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; + } + + HILOG_DEBUG("bundleName:%{public}s, abilityName:%{public}s", bundleName.c_str(), abilityName.c_str()); + sptr acquireFormStateConnection = new FormAcquireStateConnection(bundleName, abilityName, want); + + Want targetWant; + targetWant.AddFlags(Want::FLAG_ABILITY_FORM_ENABLED); + targetWant.SetElementName(bundleName, abilityName); + ErrCode errorCode = FormAmsHelper::GetInstance().ConnectServiceAbility(targetWant, acquireFormStateConnection); + if (errorCode != ERR_OK) { + HILOG_ERROR("%{public}s, ConnectServiceAbility failed.", __func__); + return ERR_APPEXECFWK_FORM_BIND_PROVIDER_FAILED; + } + stateInfo.state = FormState::DEFAULT; + return ERR_OK; +} + /** * @brief Get All FormsInfo. * @param formInfos Return the forms' information of all forms provided. diff --git a/services/formmgr/src/form_mgr_service.cpp b/services/formmgr/src/form_mgr_service.cpp index 67468747a8b..a67af87f802 100644 --- a/services/formmgr/src/form_mgr_service.cpp +++ b/services/formmgr/src/form_mgr_service.cpp @@ -451,6 +451,43 @@ int FormMgrService::DistributedDataDeleteForm(const std::string &formId) return FormMgrAdapter::GetInstance().DistributedDataDeleteForm(formId); } +/** + * @brief Delete the given invalid forms. + * @param formIds Indicates the ID of the forms to delete. + * @param callerToken Caller ability token. + * @param numFormsDeleted Returns the number of the deleted forms. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrService::DeleteInvalidForms(const std::vector &formIds, const sptr &callerToken, + int32_t &numFormsDeleted) +{ + HILOG_INFO("%{public}s called.", __func__); + ErrCode ret = CheckFormPermission(); + if (ret != ERR_OK) { + HILOG_ERROR("%{public}s fail, delete form permission denied", __func__); + return ret; + } + return FormMgrAdapter::GetInstance().DeleteInvalidForms(formIds, callerToken, numFormsDeleted); +} + +/** + * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. + * @param want Indicates a set of parameters to be transparently passed to the form provider. + * @param callerToken Caller ability token. + * @param stateInfo Returns the form's state info of the specify. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrService::AcquireFormState(const Want &want, const sptr &callerToken, FormStateInfo &stateInfo) +{ + HILOG_INFO("%{public}s called.", __func__); + ErrCode ret = CheckFormPermission(); + if (ret != ERR_OK) { + HILOG_ERROR("%{public}s fail, delete form permission denied", __func__); + return ret; + } + return FormMgrAdapter::GetInstance().AcquireFormState(want, callerToken, stateInfo); +} + /** * @brief Get All FormsInfo. * @param formInfos Return the forms' information of all forms provided. diff --git a/services/formmgr/src/form_supply_callback.cpp b/services/formmgr/src/form_supply_callback.cpp index e5aeac03624..11cc256761e 100644 --- a/services/formmgr/src/form_supply_callback.cpp +++ b/services/formmgr/src/form_supply_callback.cpp @@ -95,6 +95,24 @@ int FormSupplyCallback::OnEventHandle(const Want &want) HILOG_INFO("%{public}s end.", __func__); return ERR_OK; } + +/** + * @brief Accept form state from form provider. + * @param state Form state. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ +int FormSupplyCallback::OnAcquireStateResult(FormState state, const Want &want) +{ + HILOG_INFO("%{public}s called.", __func__); + long connectId = want.GetLongParam(Constants::FORM_CONNECT_ID, 0); + std::string supplyInfo = want.GetStringParam(Constants::FORM_SUPPLY_INFO); + HILOG_DEBUG("%{public}s come: %{public}ld, %{public}s", __func__, connectId, supplyInfo.c_str()); + RemoveConnection(connectId); + HILOG_INFO("%{public}s end.", __func__); + return ERR_OK; +} + /** * @brief Save ability Connection for the callback. * @param connection ability connection. diff --git a/services/formmgr/src/form_task_mgr.cpp b/services/formmgr/src/form_task_mgr.cpp index 4899c6715b0..1cfb88e4fae 100644 --- a/services/formmgr/src/form_task_mgr.cpp +++ b/services/formmgr/src/form_task_mgr.cpp @@ -224,6 +224,23 @@ void FormTaskMgr::PostFormEventTask(const int64_t formId, const std::string &mes eventHandler_->PostTask(formEventFunc, FORM_TASK_DELAY_TIME); } +/** +* @brief Post acquire state to form provider. +* @param wantArg The want of onAcquireFormState. +* @param want The want of the request. +* @param remoteObject Form provider proxy object. +*/ +void FormTaskMgr::PostAcquireStateTask(const Want &wantArg, const Want &want, const sptr &remoteObject) +{ + if (eventHandler_ == nullptr) { + HILOG_ERROR("%{public}s fail, eventhandler invalidate.", __func__); + return; + } + std::function acquireStateFunc = std::bind(&FormTaskMgr::AcquireState, + this, wantArg, want, remoteObject); + eventHandler_->PostTask(acquireStateFunc, FORM_TASK_DELAY_TIME); +} + /** * @brief Post uninstall message to form host(task). * @param formIds The Id list of the forms. @@ -462,6 +479,31 @@ void FormTaskMgr::FireFormEvent(const int64_t formId, const std::string &message HILOG_INFO("%{public}s end", __func__); } +/** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param remoteObject Form provider proxy object. + */ +void FormTaskMgr::AcquireState(const Want &wantArg, const Want &want, const sptr &remoteObject) +{ + HILOG_INFO("%{public}s start", __func__); + long connectId = want.GetLongParam(Constants::FORM_CONNECT_ID, 0); + sptr formProviderProxy = iface_cast(remoteObject); + if (formProviderProxy == nullptr) { + FormSupplyCallback::GetInstance()->RemoveConnection(connectId); + HILOG_ERROR("%{public}s, Failed to get formProviderProxy", __func__); + return; + } + + int error = formProviderProxy->AcquireState(wantArg, want, FormSupplyCallback::GetInstance()); + if (error != ERR_OK) { + FormSupplyCallback::GetInstance()->RemoveConnection(connectId); + HILOG_ERROR("%{public}s, Failed to acquire form state to form provider", __func__); + } + HILOG_INFO("%{public}s end", __func__); +} + /** * @brief Handle uninstall message. * @param formIds The Id list of the forms. diff --git a/services/formmgr/src/form_timer_mgr.cpp b/services/formmgr/src/form_timer_mgr.cpp index b751267e6a1..541502ab31f 100644 --- a/services/formmgr/src/form_timer_mgr.cpp +++ b/services/formmgr/src/form_timer_mgr.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -36,6 +36,7 @@ namespace AppExecFwk { const int REQUEST_UPDATE_AT_CODE = 1; const int REQUEST_LIMITER_CODE = 2; const int REQUEST_DYNAMIC_CODE = 3; +const int SHIFT_BIT_LENGTH = 32; FormTimerMgr::FormTimerMgr() { @@ -291,7 +292,7 @@ bool FormTimerMgr::AtTimerToIntervalTimer(const int64_t formId, const FormTimerC } targetItem.refreshTask.isUpdateAt = false; targetItem.refreshTask.period = timerCfg.updateDuration; - targetItem.refreshTask.refreshTime = LONG_MAX; + targetItem.refreshTask.refreshTime = INT64_MAX; if (!AddIntervalTimer(targetItem.refreshTask)) { HILOG_ERROR("%{public}s, failed to add interval timer", __func__); return false; @@ -548,15 +549,15 @@ bool FormTimerMgr::OnUpdateAtTrigger(long updateTime) * @param updateTime Update time. * @return Returns true on success, false on failure. */ -bool FormTimerMgr::OnDynamicTimeTrigger(long updateTime) +bool FormTimerMgr::OnDynamicTimeTrigger(int64_t updateTime) { - HILOG_INFO("%{public}s start, updateTime:%{public}ld", __func__, updateTime); + HILOG_INFO("%{public}s start, updateTime:%{public}" PRId64 "", __func__, updateTime); std::vector updateList; { std::lock_guard lock(dynamicMutex_); auto timeSinceEpoch = std::chrono::steady_clock::now().time_since_epoch(); auto timeInSec = std::chrono::duration_cast(timeSinceEpoch).count(); - long markedTime = timeInSec + Constants::ABS_REFRESH_MS; + int64_t markedTime = timeInSec + Constants::ABS_REFRESH_MS; std::vector::iterator itItem; for (itItem = dynamicRefreshTasks_.begin(); itItem != dynamicRefreshTasks_.end();) { if (itItem->settedTime <= updateTime || itItem->settedTime <= markedTime) { @@ -581,7 +582,7 @@ bool FormTimerMgr::OnDynamicTimeTrigger(long updateTime) } if (!updateList.empty()) { - HILOG_INFO("%{public}s triggered, trigged time: %{public}ld", __func__, updateTime); + HILOG_INFO("%{public}s triggered, trigged time: %{public}" PRId64 "", __func__, updateTime); for (auto &task : updateList) { ExecTimerTask(task); } @@ -741,8 +742,8 @@ bool FormTimerMgr::DeleteUpdateAtTimer(const int64_t formId) HILOG_ERROR("%{public}s, failed to update attimer alarm.", __func__); return false; } - return true; HILOG_INFO("%{public}s end", __func__); + return true; } /** * @brief Delete dynamic refresh item. @@ -768,8 +769,8 @@ bool FormTimerMgr::DeleteDynamicItem(const int64_t formId) HILOG_ERROR("%{public}s, failed to UpdateDynamicAlarm", __func__); return false; } - return true; HILOG_INFO("%{public}s end", __func__); + return true; } /** * @brief interval timer task timeout. @@ -813,8 +814,8 @@ bool FormTimerMgr::UpdateAtTimerAlarm() return false; } - int nowAtTime = tmAtTime.tm_hour * Constants::MIN_PER_HOUR + tmAtTime.tm_min; - long currentTime = FormUtil::GetCurrentMillisecond(); + long nowAtTime = tmAtTime.tm_hour * Constants::MIN_PER_HOUR + tmAtTime.tm_min; + int64_t currentTime = FormUtil::GetCurrentMillisecond(); UpdateAtItem findedItem; bool bFinded = FindNextAtTimerItem(nowAtTime, findedItem); if (!bFinded) { @@ -832,7 +833,7 @@ bool FormTimerMgr::UpdateAtTimerAlarm() tmAtTime.tm_sec = 0; tmAtTime.tm_hour = findedItem.refreshTask.hour; tmAtTime.tm_min = findedItem.refreshTask.min; - long selectTime = FormUtil::GetMillisecondFromTm(tmAtTime); + int64_t selectTime = FormUtil::GetMillisecondFromTm(tmAtTime); if (selectTime < currentTime) { tmAtTime.tm_mday += 1; nextWakeUpTime += (Constants::HOUR_PER_DAY * Constants::MIN_PER_HOUR); @@ -939,7 +940,7 @@ bool FormTimerMgr::UpdateLimiterAlarm() tmAtTime.tm_sec = Constants::MAX_SECOND; // max value can be 61 tmAtTime.tm_hour = Constants::MAX_HOUR; tmAtTime.tm_min = Constants::MAX_MININUTE; - uint64_t limiterWakeUpTime = FormUtil::GetMillisecondFromTm(tmAtTime); + int64_t limiterWakeUpTime = FormUtil::GetMillisecondFromTm(tmAtTime); auto timerOption = std::make_shared(); timerOption->SetType(timerOption->TIMER_TYPE_WAKEUP); @@ -1015,7 +1016,7 @@ bool FormTimerMgr::UpdateDynamicAlarm() HILOG_INFO("%{public}s start", __func__); if (dynamicRefreshTasks_.empty()) { ClearDynamicResource(); - dynamicWakeUpTime_ = LONG_MAX; + dynamicWakeUpTime_ = INT64_MAX; return true; } @@ -1053,9 +1054,7 @@ bool FormTimerMgr::UpdateDynamicAlarm() if (!bRet) { HILOG_ERROR("%{public}s failed, init dynamic timer task error", __func__); } - - HILOG_INFO("%{public}s end, dynamicWakeUpTime_ : %{pubilc}ld.", __func__, dynamicWakeUpTime_); - + HILOG_INFO("%{public}s end, dynamicWakeUpTime_ : %{public}" PRId64 ".", __func__, dynamicWakeUpTime_); return true; } /** @@ -1063,14 +1062,18 @@ bool FormTimerMgr::UpdateDynamicAlarm() * @param nextTime The next update time. * @return Returns WantAgent. */ -std::shared_ptr FormTimerMgr::GetDynamicWantAgent(long nextTime, int32_t userId) +std::shared_ptr FormTimerMgr::GetDynamicWantAgent(int64_t nextTime, int32_t userId) { std::shared_ptr want = std::make_shared(); ElementName element("", "", ""); want->SetElement(element); want->SetAction(Constants::ACTION_UPDATEATTIMER); want->SetParam(Constants::KEY_ACTION_TYPE, Constants::TYPE_DYNAMIC_UPDATE); - want->SetParam(Constants::KEY_WAKEUP_TIME, nextTime); + int nextTimeRight = static_cast(nextTime); + int nextTimLeft = static_cast(nextTime >> SHIFT_BIT_LENGTH); + + want->SetParam(Constants::KEY_WAKEUP_TIME_LEFT, nextTimLeft); + want->SetParam(Constants::KEY_WAKEUP_TIME_RIGHT, nextTimeRight); std::vector> wants; wants.emplace_back(want); WantAgentInfo wantAgentInfo(REQUEST_DYNAMIC_CODE, WantAgentConstant::OperationType::SEND_COMMON_EVENT, @@ -1104,7 +1107,7 @@ void FormTimerMgr::ClearDynamicResource() * @param updateAtItem Next at timer item. * @return Returns true on success, false on failure. */ -bool FormTimerMgr::FindNextAtTimerItem(const int nowTime, UpdateAtItem &updateAtItem) +bool FormTimerMgr::FindNextAtTimerItem(const long nowTime, UpdateAtItem &updateAtItem) { HILOG_INFO("%{public}s start", __func__); if (updateAtTimerTasks_.empty()) { @@ -1257,9 +1260,13 @@ void FormTimerMgr::TimerReceiver::OnReceiveEvent(const EventFwk::CommonEventData } FormTimerMgr::GetInstance().OnUpdateAtTrigger(updateTime); } else if (type == Constants::TYPE_DYNAMIC_UPDATE) { - long updateTime = want.GetLongParam(Constants::KEY_WAKEUP_TIME, 0); + int updateTimeLeft = want.GetIntParam(Constants::KEY_WAKEUP_TIME_LEFT, -1); + int updateTimeRight = want.GetIntParam(Constants::KEY_WAKEUP_TIME_RIGHT, -1); + int64_t updateTime = static_cast(updateTimeLeft); + updateTime = updateTime << SHIFT_BIT_LENGTH; + updateTime |= updateTimeRight; if (updateTime <= 0) { - HILOG_ERROR("%{public}s failed, invalid updateTime:%{public}ld.", __func__, updateTime); + HILOG_ERROR("%{public}s failed, invalid updateTime:%{public}" PRId64 "", __func__, updateTime); return; } FormTimerMgr::GetInstance().OnDynamicTimeTrigger(updateTime); diff --git a/services/formmgr/test/mock/include/mock_ability_manager.h b/services/formmgr/test/mock/include/mock_ability_manager.h index 1f8ee784e80..5a773d2479e 100644 --- a/services/formmgr/test/mock/include/mock_ability_manager.h +++ b/services/formmgr/test/mock/include/mock_ability_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -213,6 +213,12 @@ public: { return 0; } + + virtual int32_t GetMissionIdByToken(const sptr &token) override + { + return 0; + } + virtual int RemoveMission(int id) { return 0; @@ -225,7 +231,7 @@ public: { return 0; } - virtual int UninstallApp(const std::string &bundleName) + virtual int UninstallApp(const std::string &bundleName, int32_t uid) { return 0; } @@ -245,20 +251,6 @@ public: { return 0; } - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) - { - return 0; - } virtual int SetShowOnLockScreen(bool isAllow) override { @@ -604,6 +596,12 @@ public: { return 0; } + + virtual int32_t GetMissionIdByToken(const sptr &token) override + { + return 0; + } + virtual int RemoveMission(int id) { return 0; @@ -616,7 +614,7 @@ public: { return 0; } - virtual int UninstallApp(const std::string &bundleName) + virtual int UninstallApp(const std::string &bundleName, int32_t uid) { return 0; } @@ -682,20 +680,6 @@ public: { return 0; } - /** - * Checks whether a specified permission has been granted to the process identified by pid and uid - * - * @param permission Indicates the permission to check. - * @param pid Indicates the ID of the process to check. - * @param uid Indicates the UID of the process to check. - * @param message Describe success or failure - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) - { - return 0; - } virtual void GetSystemMemoryAttr(AppExecFwk::SystemMemoryAttr &memoryInfo) {} diff --git a/services/formmgr/test/mock/include/mock_bundle_manager.h b/services/formmgr/test/mock/include/mock_bundle_manager.h index b833123f9a4..b01f66ef6c8 100755 --- a/services/formmgr/test/mock/include/mock_bundle_manager.h +++ b/services/formmgr/test/mock/include/mock_bundle_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -200,7 +200,7 @@ public: } /** - * @brief Obtains the CommonEventInfo objects provided by a event key on the device. + * @brief Obtains the CommonEventInfo objects provided by an event key on the device. * @param eventKey Indicates the event of the subscribe. * @param commonEventInfos List of CommonEventInfo objects if obtained. * @return Returns true if this function is successfully called; returns false otherwise. @@ -427,7 +427,7 @@ public: } /** - * @brief Obtains the CommonEventInfo objects provided by a event key on the device. + * @brief Obtains the CommonEventInfo objects provided by an event key on the device. * @param eventKey Indicates the event of the subscribe. * @param commonEventInfos List of CommonEventInfo objects if obtained. * @return Returns true if this function is successfully called; returns false otherwise. diff --git a/services/formmgr/test/mock/include/mock_form_host_client.h b/services/formmgr/test/mock/include/mock_form_host_client.h index b242c4080ac..1c4c4fce1a7 100644 --- a/services/formmgr/test/mock/include/mock_form_host_client.h +++ b/services/formmgr/test/mock/include/mock_form_host_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -50,11 +50,6 @@ public: sem_.Post(); } - // void AddForm(const Ability& slice, int64_t formId); - - // void RemoveForm(const Ability& slice, int64_t formId); - - // bool ContainsForm(int64_t formId); /** * Request to give back a Form. * diff --git a/services/formmgr/test/mock/include/mock_form_provider_client.h b/services/formmgr/test/mock/include/mock_form_provider_client.h index 8f8a6857d37..5b5915cdf96 100644 --- a/services/formmgr/test/mock/include/mock_form_provider_client.h +++ b/services/formmgr/test/mock/include/mock_form_provider_client.h @@ -106,6 +106,15 @@ private: */ virtual int FireFormEvent(const int64_t formId, const std::string &message, const Want &want, const sptr &callerToken) override; + + /** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param callerToken Form provider proxy object. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int AcquireState(const Want &wantArg, const Want &want, const sptr &callerToken) override; private: DISALLOW_COPY_AND_MOVE(MockFormProviderClient); }; diff --git a/services/formmgr/test/mock/src/mock_form_provider_client.cpp b/services/formmgr/test/mock/src/mock_form_provider_client.cpp index e582ddb0ce1..7ac777fb966 100644 --- a/services/formmgr/test/mock/src/mock_form_provider_client.cpp +++ b/services/formmgr/test/mock/src/mock_form_provider_client.cpp @@ -39,6 +39,7 @@ int MockFormProviderClient::AcquireProviderFormInfo(const int64_t formId, const sptr formSupply = iface_cast(callerToken); if (formSupply == nullptr) { HILOG_ERROR("failed to get formSupplyProxy"); + return ERR_OK; } FormProviderInfo formProviderInfo; @@ -136,5 +137,18 @@ int MockFormProviderClient::FireFormEvent(const int64_t formId, const std::strin HILOG_DEBUG("Fire form event"); return ERR_OK; } + +/** + * @brief Acquire form state to form provider. + * @param wantArg The want of onAcquireFormState. + * @param want The want of the request. + * @param callerToken Form provider proxy object. + * @return Returns ERR_OK on success, others on failure. + */ +int MockFormProviderClient::AcquireState(const Want &wantArg, const Want &want, const sptr &callerToken) +{ + HILOG_DEBUG("Acquire state"); + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/formmgr/test/unittest/fms_form_data_mgr_test/BUILD.gn b/services/formmgr/test/unittest/fms_form_data_mgr_test/BUILD.gn index 7ad8fc83d98..46cdf6ed868 100644 --- a/services/formmgr/test/unittest/fms_form_data_mgr_test/BUILD.gn +++ b/services/formmgr/test/unittest/fms_form_data_mgr_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -29,8 +29,6 @@ ohos_unittest("FmsFormDataMgrTest") { "//foundation/appexecfwk/standard/common/log/include/", "//foundation/aafwk/standard/services/formmgr/include", - #"//foundation/appexecfwk/standard/services/bundlemgr/include", - #"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include/", "//foundation/aafwk/standard/interfaces/innerkits/form_manager/include", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr/", diff --git a/services/formmgr/test/unittest/fms_form_data_mgr_test/fms_form_data_mgr_test.cpp b/services/formmgr/test/unittest/fms_form_data_mgr_test/fms_form_data_mgr_test.cpp index e82ef5566e8..4f656ee0a77 100644 --- a/services/formmgr/test/unittest/fms_form_data_mgr_test/fms_form_data_mgr_test.cpp +++ b/services/formmgr/test/unittest/fms_form_data_mgr_test/fms_form_data_mgr_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -259,7 +259,7 @@ HWTEST_F(FmsFormDataMgrTest, FmsFormDataMgrTest_AllotFormRecord_006, TestSize.Le * @tc.desc: Verify that the return value is correct. * @tc.details: * SetUpdateDuration is 0.(call ParseAtTimerConfig) - * 获取配置项scheduledUpdateTime_为无效值 + * Gets the configuration item scheduledUpdateTime_ an invalid value. */ HWTEST_F(FmsFormDataMgrTest, FmsFormDataMgrTest_AllotFormRecord_007, TestSize.Level0) { diff --git a/services/formmgr/test/unittest/fms_form_db_record_test/BUILD.gn b/services/formmgr/test/unittest/fms_form_db_record_test/BUILD.gn index f3cde572b1d..0fb84ce4175 100644 --- a/services/formmgr/test/unittest/fms_form_db_record_test/BUILD.gn +++ b/services/formmgr/test/unittest/fms_form_db_record_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -26,8 +26,6 @@ ohos_unittest("FmsFormDbRecordTest") { "//foundation/appexecfwk/standard/common/log/include/", "//foundation/aafwk/standard/services/formmgr/include", - #"//foundation/appexecfwk/standard/services/bundlemgr/include", - #"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include/", "//foundation/aafwk/standard/interfaces/innerkits/form_manager/include", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr/", diff --git a/services/formmgr/test/unittest/fms_form_mgr_add_form_test/BUILD.gn b/services/formmgr/test/unittest/fms_form_mgr_add_form_test/BUILD.gn index 7a480b2f0a7..1d01331d618 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_add_form_test/BUILD.gn +++ b/services/formmgr/test/unittest/fms_form_mgr_add_form_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -63,8 +63,6 @@ ohos_unittest("FmsFormMgrAddFormTest") { "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/innerkits/want:want", - - #"${appexecfwk_path}/services/bundlemgr:bms_target", "//foundation/aafwk/standard/services/abilitymgr:abilityms_target", "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", diff --git a/services/formmgr/test/unittest/fms_form_mgr_death_callback_test/BUILD.gn b/services/formmgr/test/unittest/fms_form_mgr_death_callback_test/BUILD.gn index 9c20fdb068f..f1efa22d431 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_death_callback_test/BUILD.gn +++ b/services/formmgr/test/unittest/fms_form_mgr_death_callback_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -48,8 +48,6 @@ ohos_unittest("FmsFormMgrDeathCallbackTest") { configs = [ "${services_path}/formmgr/test:formmgr_test_config", "//foundation/aafwk/standard/services/abilitymgr:abilityms_config", - - # "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:bundlemgr_sdk_config", ] cflags = [] if (target_cpu == "arm") { diff --git a/services/test/mock/include/appmgr/mock_ability_mgr_host.h b/services/test/mock/include/appmgr/mock_ability_mgr_host.h index f0f005064d2..8101cdcc27a 100644 --- a/services/test/mock/include/appmgr/mock_ability_mgr_host.h +++ b/services/test/mock/include/appmgr/mock_ability_mgr_host.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -150,7 +150,7 @@ public: { return 0; } - virtual int UninstallApp(const std::string &bundleName) override + virtual int UninstallApp(const std::string &bundleName, int32_t uid) override { return 0; } @@ -169,11 +169,6 @@ public: return true; } - virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override - { - return 0; - } - virtual int PowerOff() override { return 0; diff --git a/services/test/mock/include/mock_ability_manager_proxy.h b/services/test/mock/include/mock_ability_manager_proxy.h index c65309aabf5..869639d68d4 100644 --- a/services/test/mock/include/mock_ability_manager_proxy.h +++ b/services/test/mock/include/mock_ability_manager_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -55,14 +55,14 @@ public: MOCK_METHOD1(RemoveMission, int(int)); MOCK_METHOD1(RemoveStack, int(int)); MOCK_METHOD1(MoveMissionToTop, int(int32_t)); + MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); MOCK_METHOD1(KillProcess, int(const std::string &)); - MOCK_METHOD1(UninstallApp, int(const std::string &)); + MOCK_METHOD2(UninstallApp, int(const std::string &, int32_t)); MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr &callerToken, int requestCode)); MOCK_METHOD3(StartAbility, int(const Want &want, const sptr &callerToken, int requestCode)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr &token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr &token)); - MOCK_METHOD4(CompelVerifyPermission, int(const std::string &permission, int pid, int uid, std::string &message)); MOCK_METHOD0(PowerOff, int()); MOCK_METHOD0(PowerOn, int()); MOCK_METHOD1(LockMission, int(int)); @@ -84,7 +84,6 @@ public: MOCK_METHOD2(MoveMissionToEnd, int(const sptr &token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr &token)); - MOCK_METHOD4(CompelVerifyPermission, int(const std::string &permission, int pid, int uid, std::string &message)); MOCK_METHOD0(PowerOff, int()); MOCK_METHOD0(PowerOn, int()); MOCK_METHOD1(GetPendingWantUserId, int(const sptr &target)); diff --git a/services/test/mock/include/mock_ability_mgr_service.h b/services/test/mock/include/mock_ability_mgr_service.h index ad54fb74ae0..c4609ad5c5a 100644 --- a/services/test/mock/include/mock_ability_mgr_service.h +++ b/services/test/mock/include/mock_ability_mgr_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -63,12 +63,12 @@ public: MOCK_METHOD1(RemoveMission, int(int)); MOCK_METHOD1(RemoveStack, int(int)); MOCK_METHOD1(MoveMissionToTop, int(int32_t)); + MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); MOCK_METHOD1(KillProcess, int(const std::string &)); - MOCK_METHOD1(UninstallApp, int(const std::string &)); + MOCK_METHOD2(UninstallApp, int(const std::string &, int32_t)); MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr &token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr &token)); - MOCK_METHOD4(CompelVerifyPermission, int(const std::string &permission, int pid, int uid, std::string &message)); MOCK_METHOD0(PowerOff, int()); MOCK_METHOD0(PowerOn, int()); MOCK_METHOD1(LockMission, int(int)); diff --git a/services/test/mock/include/mock_app_mgr_client.h b/services/test/mock/include/mock_app_mgr_client.h index 2e0bb4001d0..0bf79cc17b6 100644 --- a/services/test/mock/include/mock_app_mgr_client.h +++ b/services/test/mock/include/mock_app_mgr_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -32,7 +32,6 @@ public: MOCK_METHOD1(KillApplication, AppMgrResultCode(const std::string &)); MOCK_METHOD1(KillProcessByAbilityToken, AppMgrResultCode(const sptr &token)); MOCK_METHOD1(KillProcessesByUserId, AppMgrResultCode(int32_t userId)); - MOCK_METHOD4(CompelVerifyPermission, int(const std::string &permission, int pid, int uid, std::string &message)); MOCK_METHOD1(AbilityAttachTimeOut, void(const sptr &token)); MOCK_METHOD2(GetRunningProcessInfoByToken, void((const sptr &token, AppExecFwk::RunningProcessInfo &info))); diff --git a/services/test/mock/include/mock_app_scheduler.h b/services/test/mock/include/mock_app_scheduler.h index df33e11b7a9..e1960e809e0 100644 --- a/services/test/mock/include/mock_app_scheduler.h +++ b/services/test/mock/include/mock_app_scheduler.h @@ -41,6 +41,7 @@ public: MOCK_METHOD1(ScheduleConfigurationUpdated, void(const AppExecFwk::Configuration &config)); MOCK_METHOD1(ScheduleShrinkMemory, void(const int)); MOCK_METHOD0(ScheduleLowMemory, void()); + MOCK_METHOD0(ScheduleANRProcess, void()); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp index 12e14d6aecf..6e0c1c742bd 100644 --- a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp +++ b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -1140,27 +1140,6 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_018, TestSize.Level1) testing::Mock::AllowLeak(callback); } -/* - * Feature: AbilityManagerService - * Function: CompelVerifyPermission - * SubFunction: NA - * FunctionPoints: AbilityManagerService CompelVerifyPermission - * EnvConditions: NA - * CaseDescription: Verify function CompelVerifyPermission - */ -HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_025, TestSize.Level1) -{ - EXPECT_TRUE(abilityMgrServ_); - EXPECT_TRUE(mockAppMgrClient_); - const std::string permission = "permission"; - int pid = 100; - int uid = 1000; - std::string message; - int runTimes = 1; - EXPECT_CALL(*mockAppMgrClient_, CompelVerifyPermission(_, _, _, _)).Times(runTimes); - auto resultFunction = abilityMgrServ_->CompelVerifyPermission(permission, pid, uid, message); - EXPECT_EQ(resultFunction, 0); -} /* * Feature: AbilityManagerService * Function: AmsConfigurationParameter @@ -1245,7 +1224,7 @@ HWTEST_F(AbilityMgrModuleTest, UninstallApp_001, TestSize.Level1) wantSenderInfo1, nullptr)->AsObject()); EXPECT_NE(pendingRecord1, nullptr); EXPECT_EQ((int)abilityMgrServ_->pendingWantManager_->wantRecords_.size(), 2); - abilityMgrServ_->UninstallApp("bundleName3"); + abilityMgrServ_->UninstallApp("bundleName3", 1); WaitAMS(); EXPECT_EQ((int)abilityMgrServ_->pendingWantManager_->wantRecords_.size(), 2); } @@ -1288,7 +1267,7 @@ HWTEST_F(AbilityMgrModuleTest, UninstallApp_002, TestSize.Level1) wantSenderInfo1, nullptr)->AsObject()); EXPECT_NE(pendingRecord1, nullptr); EXPECT_EQ((int)abilityMgrServ_->pendingWantManager_->wantRecords_.size(), 2); - abilityMgrServ_->UninstallApp("bundleName2"); + abilityMgrServ_->UninstallApp("bundleName2", 1); WaitAMS(); EXPECT_EQ((int)abilityMgrServ_->pendingWantManager_->wantRecords_.size(), 0); } @@ -1331,7 +1310,7 @@ HWTEST_F(AbilityMgrModuleTest, UninstallApp_003, TestSize.Level1) wantSenderInfo1, nullptr)->AsObject()); EXPECT_NE(pendingRecord1, nullptr); EXPECT_EQ((int)abilityMgrServ_->pendingWantManager_->wantRecords_.size(), 2); - abilityMgrServ_->UninstallApp("bundleName1"); + abilityMgrServ_->UninstallApp("bundleName1", 1); WaitAMS(); EXPECT_EQ((int)abilityMgrServ_->pendingWantManager_->wantRecords_.size(), 1); } @@ -1374,7 +1353,7 @@ HWTEST_F(AbilityMgrModuleTest, UninstallApp_004, TestSize.Level1) wantSenderInfo1, nullptr)->AsObject()); EXPECT_NE(pendingRecord1, nullptr); EXPECT_EQ((int)abilityMgrServ_->pendingWantManager_->wantRecords_.size(), 2); - abilityMgrServ_->UninstallApp("bundleName3"); + abilityMgrServ_->UninstallApp("bundleName3", 1); WaitAMS(); EXPECT_EQ((int)abilityMgrServ_->pendingWantManager_->wantRecords_.size(), 1); } diff --git a/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp b/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp index 92a14dbb7a8..268565fdf0a 100644 --- a/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp +++ b/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp @@ -1831,7 +1831,7 @@ HWTEST_F(AbilityStackModuleTest, ability_stack_test_035, TestSize.Level1) EXPECT_TRUE(topAbilityRecordRadio); topAbilityRecordRadio->SetAbilityState(OHOS::AAFwk::ACTIVE); - // start defult ability, put in float stack + // start default ability, put in float stack auto musicAbilityRequest = GenerateAbilityRequest("device", "MusicAbility", "music", "com.ix.hiMusic"); ref = stackManager_->StartAbility(musicAbilityRequest); EXPECT_EQ(ERR_OK, ref); @@ -1877,7 +1877,7 @@ HWTEST_F(AbilityStackModuleTest, ability_stack_test_036, TestSize.Level1) EXPECT_TRUE(topAbilityRecordRadio); topAbilityRecordRadio->SetAbilityState(OHOS::AAFwk::ACTIVE); - // start defult singleton ability, put in float stack + // start default singleton ability, put in float stack auto musicTonAbilityRequest = GenerateAbilityRequest("device", "MusicSAbility", "music", "com.ix.hiMusic"); ref = stackManager_->StartAbility(musicTonAbilityRequest); EXPECT_EQ(ERR_OK, ref); @@ -1906,7 +1906,7 @@ HWTEST_F(AbilityStackModuleTest, ability_stack_test_037, TestSize.Level1) auto topAbilityRecord1 = stackManager_->GetCurrentTopAbility(); topAbilityRecord1->SetAbilityState(OHOS::AAFwk::ACTIVE); - // start defult singleton ability, put in float stack + // start default singleton ability, put in float stack auto musicTonAbilityRequest = GenerateAbilityRequest("device", "MusicSAbility", "music", "com.ix.hiMusic"); ref = stackManager_->StartAbility(musicTonAbilityRequest); EXPECT_EQ(ERR_OK, ref); @@ -1971,7 +1971,7 @@ HWTEST_F(AbilityStackModuleTest, ability_stack_test_038, TestSize.Level1) * SubFunction: Try moving other applications to the floating window stack * FunctionPoints: * EnvConditions: NA - * CaseDescription: Move the defult ability to the floating window stack + * CaseDescription: Move the default ability to the floating window stack */ HWTEST_F(AbilityStackModuleTest, ability_stack_test_039, TestSize.Level1) { @@ -2166,7 +2166,7 @@ HWTEST_F(AbilityStackModuleTest, ability_stack_test_043, TestSize.Level1) * SubFunction: moving other applications to the floating window stack or Full screen stack * FunctionPoints: * EnvConditions: NA - * CaseDescription: Move the float ability to the defult stack + * CaseDescription: Move the float ability to the default stack */ HWTEST_F(AbilityStackModuleTest, ability_stack_test_044, TestSize.Level1) { @@ -2250,7 +2250,7 @@ HWTEST_F(AbilityStackModuleTest, ability_stack_test_045, TestSize.Level1) EXPECT_CALL(*scheduler, AsObject()).WillRepeatedly(Return(nullptr)); radioAbilityRecord->SetScheduler(scheduler); - // top float ability move to defult stack + // top float ability move to default stack ref = stackManager_->MaximizeMultiWindow(radioAbilityRecord->GetMissionRecordId()); EXPECT_EQ(ERR_OK, ref); diff --git a/services/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp b/services/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp index 70ef4d43d1a..39d2bf5df2f 100644 --- a/services/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp +++ b/services/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp @@ -136,6 +136,9 @@ public: appLaunchTime = 0; } + void ScheduleANRProcess() override + {} + private: int abilityLaunchTime = 0; int appLaunchTime = 0; diff --git a/services/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp b/services/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp index c590912c289..394f93d1368 100644 --- a/services/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp +++ b/services/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp @@ -68,6 +68,8 @@ public: {} void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override {} + void ScheduleANRProcess() override + {} }; class AppMgrServiceModuleTest : public testing::Test { public: diff --git a/services/test/moduletest/common/ams/app_running_record_test/BUILD.gn b/services/test/moduletest/common/ams/app_running_record_test/BUILD.gn index 174ccbfebca..ea863f61668 100755 --- a/services/test/moduletest/common/ams/app_running_record_test/BUILD.gn +++ b/services/test/moduletest/common/ams/app_running_record_test/BUILD.gn @@ -38,6 +38,5 @@ ohos_moduletest("AmsAppRunningRecordModuleTest") { group("moduletest") { testonly = true - - deps = [ ":AmsAppRunningRecordModuleTest" ] + # deps = [ ":AmsAppRunningRecordModuleTest" ] } diff --git a/services/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp b/services/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp index a7ddbf433ee..01cab016ef3 100644 --- a/services/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp +++ b/services/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -355,7 +355,7 @@ HWTEST_F(AmsAppServiceFlowModuleTest, ServiceFlow_BackKey_005, TestSize.Level1) EXPECT_CALL(*(testAppA.mockAppScheduler_), ScheduleBackgroundApplication()).Times(1); EXPECT_CALL(*(testAppA.mockAppScheduler_), ScheduleCleanAbility(_)).Times(1); - // simulate press back key, AppA to backgroud and exit. + // simulate press back key, AppA to background and exit. serviceInner_->UpdateAbilityState(testAppB.GetToken("abilityB1"), AbilityState::ABILITY_STATE_FOREGROUND); serviceInner_->ApplicationForegrounded(testAppB.appRecord_->GetRecordId()); serviceInner_->UpdateAbilityState(testAppA.GetToken("abilityA1"), AbilityState::ABILITY_STATE_BACKGROUND); diff --git a/services/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn b/services/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn index 9d27752489f..423c213955d 100644 --- a/services/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn +++ b/services/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn @@ -90,6 +90,5 @@ ohos_moduletest("specified_ability_service_test") { group("moduletest") { testonly = true - - deps = [ ":specified_ability_service_test" ] + # deps = [ ":specified_ability_service_test" ] } diff --git a/services/test/moduletest/static_start_ability_test/BUILD.gn b/services/test/moduletest/static_start_ability_test/BUILD.gn index cba78198677..bda339be0fe 100644 --- a/services/test/moduletest/static_start_ability_test/BUILD.gn +++ b/services/test/moduletest/static_start_ability_test/BUILD.gn @@ -128,6 +128,5 @@ ohos_moduletest("static_start_ability_test") { group("moduletest") { testonly = true - - deps = [ ":static_start_ability_test" ] + # deps = [ ":static_start_ability_test" ] } diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/src/second_ability.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/src/second_ability.cpp index 2616d1b8992..a4348b7d5e5 100755 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/src/second_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/src/second_ability.cpp @@ -4601,7 +4601,7 @@ void SecondAbility::WantSetParamShortCase3(int code) { std::string key = "key"; short value = 999; - int size = 5; + short size = 5; Want want; for (short i = 0; i < size; i++) { want.SetParam(key, static_cast(i * value)); @@ -4615,7 +4615,7 @@ void SecondAbility::WantSetParamShortCase4(int code) { std::string key = "key"; short value = 999; - int size = 5; + short size = 5; Want want; for (short i = 0; i < size; i++) { want.SetParam(key + std::to_string(i), static_cast(i * value)); @@ -4667,7 +4667,7 @@ void SecondAbility::WantSetParamShortArrayCase2(int code) void SecondAbility::WantSetParamShortArrayCase3(int code) { std::string key = "key"; - int size = 5; + short size = 5; short sValue = 999; std::vector value(size, sValue * size); Want want; @@ -4683,7 +4683,7 @@ void SecondAbility::WantSetParamShortArrayCase3(int code) void SecondAbility::WantSetParamShortArrayCase4(int code) { std::string key = "key"; - int size = 5; + short size = 5; short value = 999; Want want; for (short i = 1; i <= size; i++) { diff --git a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceB/src/ams_st_service_ability_b3.cpp b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceB/src/ams_st_service_ability_b3.cpp index f5e3129610a..b051dfe4482 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceB/src/ams_st_service_ability_b3.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceB/src/ams_st_service_ability_b3.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -54,6 +54,7 @@ std::vector AmsStServiceAbilityB3::Split(std::string str, const std } return splitString; } + void AmsStServiceAbilityB3::StartOtherAbility() { HILOG_INFO("AmsStServiceAbilityB3::StartOtherAbility begin targetBundle=%{public}s, targetAbility=%{public}s", @@ -80,6 +81,7 @@ void AmsStServiceAbilityB3::StartOtherAbility() } } } + void AmsStServiceAbilityB3::ConnectOtherAbility() { HILOG_INFO( @@ -141,6 +143,7 @@ void AmsStServiceAbilityB3::OnStart(const Want &want) PublishEvent(APP_B3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); SubscribeEvent(); } + void AmsStServiceAbilityB3::OnNewWant(const Want &want) { HILOG_INFO("AmsStServiceAbilityB3::OnNewWant"); @@ -148,6 +151,7 @@ void AmsStServiceAbilityB3::OnNewWant(const Want &want) GetWantInfo(want); Ability::OnNewWant(want); } + void AmsStServiceAbilityB3::OnCommand(const AAFwk::Want &want, bool restart, int startId) { HILOG_INFO("AmsStServiceAbilityB3::OnCommand"); @@ -156,6 +160,7 @@ void AmsStServiceAbilityB3::OnCommand(const AAFwk::Want &want, bool restart, int Ability::OnCommand(want, restart, startId); PublishEvent(APP_B3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); } + void AmsStServiceAbilityB3::OnStop() { HILOG_INFO("AmsStServiceAbilityB3::onStop"); @@ -163,6 +168,7 @@ void AmsStServiceAbilityB3::OnStop() Ability::OnStop(); PublishEvent(APP_B3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); } + void AmsStServiceAbilityB3::OnActive() { HILOG_INFO("AmsStServiceAbilityB3::OnActive"); @@ -170,6 +176,7 @@ void AmsStServiceAbilityB3::OnActive() Ability::OnActive(); PublishEvent(APP_B3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); } + void AmsStServiceAbilityB3::OnInactive() { HILOG_INFO("AmsStServiceAbilityB3::OnInactive"); @@ -177,6 +184,7 @@ void AmsStServiceAbilityB3::OnInactive() Ability::OnInactive(); PublishEvent(APP_B3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); } + void AmsStServiceAbilityB3::OnBackground() { HILOG_INFO("AmsStServiceAbilityB3::OnBackground"); @@ -184,6 +192,7 @@ void AmsStServiceAbilityB3::OnBackground() Ability::OnBackground(); PublishEvent(APP_B3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnBackground"); } + sptr AmsStServiceAbilityB3::OnConnect(const Want &want) { HILOG_INFO("AmsStServiceAbilityB3::OnConnect"); @@ -192,6 +201,7 @@ sptr AmsStServiceAbilityB3::OnConnect(const Want &want) PublishEvent(APP_B3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnConnect"); return remote; } + void AmsStServiceAbilityB3::OnDisconnect(const Want &want) { HILOG_INFO("AmsStServiceAbilityB3::OnDisconnect"); @@ -199,6 +209,7 @@ void AmsStServiceAbilityB3::OnDisconnect(const Want &want) Ability::OnDisconnect(want); PublishEvent(APP_B3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); } + void AmsStServiceAbilityB3::Clear() { shouldReturn_ = ""; @@ -212,6 +223,7 @@ void AmsStServiceAbilityB3::Clear() nextTargetAbilityConn_ = ""; AmsStServiceAbilityB3::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } + void AmsStServiceAbilityB3::GetWantInfo(const Want &want) { Want mWant(want); @@ -226,6 +238,7 @@ void AmsStServiceAbilityB3::GetWantInfo(const Want &want) nextTargetAbilityConn_ = mWant.GetStringParam("nextTargetAbilityConn"); AmsStServiceAbilityB3::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } + bool AmsStServiceAbilityB3::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { HILOG_INFO("AmsStServiceAbilityB3::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", @@ -241,6 +254,7 @@ bool AmsStServiceAbilityB3::PublishEvent(const std::string &eventName, const int commonData.SetData(data); return CommonEventManager::PublishCommonEvent(commonData); } + bool AmsStServiceAbilityB3::SubscribeEvent() { HILOG_INFO("AmsStServiceAbilityB3::SubscribeEvent"); @@ -253,6 +267,7 @@ bool AmsStServiceAbilityB3::SubscribeEvent() subscriber_->mainAbility_ = this; return CommonEventManager::SubscribeCommonEvent(subscriber_); } + void AmsStServiceAbilityB3::AppEventSubscriber::OnReceiveEvent(const CommonEventData &data) { auto eventName = data.GetWant().GetAction(); diff --git a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceC/src/ams_st_service_ability_c4.cpp b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceC/src/ams_st_service_ability_c4.cpp index 8c9308a6265..8dbbc988f3f 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceC/src/ams_st_service_ability_c4.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceC/src/ams_st_service_ability_c4.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -43,6 +43,7 @@ void AmsStServiceAbilityC4::OnStart(const Want &want) PublishEvent(APP_C4_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); SubscribeEvent(); } + void AmsStServiceAbilityC4::OnCommand(const AAFwk::Want &want, bool restart, int startId) { HILOG_INFO("AmsStServiceAbilityC4::OnCommand"); @@ -51,6 +52,7 @@ void AmsStServiceAbilityC4::OnCommand(const AAFwk::Want &want, bool restart, int Ability::OnCommand(want, restart, startId); PublishEvent(APP_C4_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); } + void AmsStServiceAbilityC4::OnNewWant(const Want &want) { HILOG_INFO("AmsStServiceAbilityC4::OnNewWant"); @@ -58,6 +60,7 @@ void AmsStServiceAbilityC4::OnNewWant(const Want &want) GetWantInfo(want); Ability::OnNewWant(want); } + void AmsStServiceAbilityC4::OnStop() { HILOG_INFO("AmsStServiceAbilityC4::OnStop"); @@ -65,6 +68,7 @@ void AmsStServiceAbilityC4::OnStop() Ability::OnStop(); PublishEvent(APP_C4_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); } + void AmsStServiceAbilityC4::OnActive() { HILOG_INFO("AmsStServiceAbilityC4::OnActive"); @@ -72,6 +76,7 @@ void AmsStServiceAbilityC4::OnActive() Ability::OnActive(); PublishEvent(APP_C4_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); } + void AmsStServiceAbilityC4::OnInactive() { HILOG_INFO("AmsStServiceAbilityC4::OnInactive"); @@ -79,6 +84,7 @@ void AmsStServiceAbilityC4::OnInactive() Ability::OnInactive(); PublishEvent(APP_C4_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); } + void AmsStServiceAbilityC4::OnBackground() { HILOG_INFO("AmsStServiceAbilityC4::OnBackground"); @@ -86,6 +92,7 @@ void AmsStServiceAbilityC4::OnBackground() Ability::OnBackground(); PublishEvent(APP_C4_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnBackground"); } + sptr AmsStServiceAbilityC4::OnConnect(const Want &want) { HILOG_INFO("AmsStServiceAbilityC4::OnConnect"); @@ -94,6 +101,7 @@ sptr AmsStServiceAbilityC4::OnConnect(const Want &want) PublishEvent(APP_C4_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnConnect"); return ret; } + void AmsStServiceAbilityC4::OnDisconnect(const Want &want) { HILOG_INFO("AmsStServiceAbilityC4::OnDisconnect"); @@ -101,24 +109,28 @@ void AmsStServiceAbilityC4::OnDisconnect(const Want &want) Ability::OnDisconnect(want); PublishEvent(APP_C4_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); } + void AmsStServiceAbilityC4::StopSelfAbility() { HILOG_INFO("AmsStServiceAbilityC4::StopSelfAbility"); TerminateAbility(); } + void AmsStServiceAbilityC4::DisConnectOtherAbility() { HILOG_INFO("AmsStServiceAbilityC4::DisConnectOtherAbility begin"); HILOG_INFO("AmsStServiceAbilityB3::DisConnectOtherAbility end"); } + void AmsStServiceAbilityC4::Clear() { shouldReturn_ = ""; targetBundle_ = ""; targetAbility_ = ""; } + void AmsStServiceAbilityC4::GetWantInfo(const Want &want) { Want mWant(want); @@ -126,6 +138,7 @@ void AmsStServiceAbilityC4::GetWantInfo(const Want &want) targetBundle_ = mWant.GetStringParam("targetBundle"); targetAbility_ = mWant.GetStringParam("targetAbility"); } + bool AmsStServiceAbilityC4::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { HILOG_INFO("AmsStServiceAbilityC4::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", diff --git a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceD/src/ams_st_service_ability_d1.cpp b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceD/src/ams_st_service_ability_d1.cpp index 28580675bfa..9d7f87929e3 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceD/src/ams_st_service_ability_d1.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceD/src/ams_st_service_ability_d1.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -55,6 +55,7 @@ std::vector AmsStServiceAbilityD1::Split(std::string str, const std } return splitString; } + void AmsStServiceAbilityD1::StartOtherAbility() { HILOG_INFO("AmsStServiceAbilityD1::StartOtherAbility begin targetBundle=%{public}s, targetAbility=%{public}s", @@ -81,6 +82,7 @@ void AmsStServiceAbilityD1::StartOtherAbility() } } } + void AmsStServiceAbilityD1::ConnectOtherAbility() { HILOG_INFO( @@ -143,6 +145,7 @@ void AmsStServiceAbilityD1::OnStart(const Want &want) PublishEvent(APP_D1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); SubscribeEvent(); } + void AmsStServiceAbilityD1::OnNewWant(const Want &want) { HILOG_INFO("AmsStServiceAbilityD1::OnNewWant"); @@ -150,6 +153,7 @@ void AmsStServiceAbilityD1::OnNewWant(const Want &want) GetWantInfo(want); Ability::OnNewWant(want); } + void AmsStServiceAbilityD1::OnCommand(const AAFwk::Want &want, bool restart, int startId) { HILOG_INFO("AmsStServiceAbilityD1::OnCommand"); @@ -158,6 +162,7 @@ void AmsStServiceAbilityD1::OnCommand(const AAFwk::Want &want, bool restart, int Ability::OnCommand(want, restart, startId); PublishEvent(APP_D1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); } + void AmsStServiceAbilityD1::OnStop() { HILOG_INFO("AmsStServiceAbilityD1::OnStop"); @@ -165,6 +170,7 @@ void AmsStServiceAbilityD1::OnStop() Ability::OnStop(); PublishEvent(APP_D1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); } + void AmsStServiceAbilityD1::GetDataByDataAbility() { HILOG_INFO("AmsStServiceAbilityD1::GetDataByDataAbility"); @@ -188,6 +194,7 @@ void AmsStServiceAbilityD1::GetDataByDataAbility() PublishEvent(APP_D1_RESP_EVENT_NAME, 0, "GetDataByDataAbility"); } } + void AmsStServiceAbilityD1::OnActive() { HILOG_INFO("AmsStServiceAbilityD1::OnActive"); @@ -195,6 +202,7 @@ void AmsStServiceAbilityD1::OnActive() Ability::OnActive(); PublishEvent(APP_D1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); } + void AmsStServiceAbilityD1::OnInactive() { HILOG_INFO("AmsStServiceAbilityD1::OnInactive"); @@ -202,6 +210,7 @@ void AmsStServiceAbilityD1::OnInactive() Ability::OnInactive(); PublishEvent(APP_D1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); } + void AmsStServiceAbilityD1::OnBackground() { HILOG_INFO("AmsStServiceAbilityD1::OnBackground"); @@ -223,6 +232,7 @@ void AmsStServiceAbilityD1::Clear() nextTargetAbilityConn_ = ""; AmsStServiceAbilityD1::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } + void AmsStServiceAbilityD1::GetWantInfo(const Want &want) { Want mWant(want); @@ -237,6 +247,7 @@ void AmsStServiceAbilityD1::GetWantInfo(const Want &want) nextTargetAbilityConn_ = mWant.GetStringParam("nextTargetAbilityConn"); AmsStServiceAbilityD1::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } + bool AmsStServiceAbilityD1::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { HILOG_INFO("AmsStServiceAbilityD1::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", @@ -252,6 +263,7 @@ bool AmsStServiceAbilityD1::PublishEvent(const std::string &eventName, const int commonData.SetData(data); return CommonEventManager::PublishCommonEvent(commonData); } + bool AmsStServiceAbilityD1::SubscribeEvent() { MatchingSkills matchingSkills; @@ -262,6 +274,7 @@ bool AmsStServiceAbilityD1::SubscribeEvent() subscriber_->mainAbility_ = this; return CommonEventManager::SubscribeCommonEvent(subscriber_); } + void AmsStServiceAbilityD1::AppEventSubscriber::OnReceiveEvent(const CommonEventData &data) { auto eventName = data.GetWant().GetAction(); diff --git a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceE/src/ams_st_service_ability_e2.cpp b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceE/src/ams_st_service_ability_e2.cpp index b77b1876175..88917ef087d 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceE/src/ams_st_service_ability_e2.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceE/src/ams_st_service_ability_e2.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -54,6 +54,7 @@ std::vector AmsStServiceAbilityE2::Split(std::string str, const std } return splitString; } + void AmsStServiceAbilityE2::StartOtherAbility() { HILOG_INFO("AmsStServiceAbilityE2::StartOtherAbility begin targetBundle=%{public}s, targetAbility=%{public}s", @@ -80,6 +81,7 @@ void AmsStServiceAbilityE2::StartOtherAbility() } } } + void AmsStServiceAbilityE2::ConnectOtherAbility() { HILOG_INFO( @@ -115,6 +117,7 @@ void AmsStServiceAbilityE2::ConnectOtherAbility() } HILOG_INFO("AmsStServiceAbilityE2::ConnectOtherAbility end"); } + void AmsStServiceAbilityE2::OnStart(const Want &want) { HILOG_INFO("AmsStServiceAbilityE2::OnStart"); @@ -124,6 +127,7 @@ void AmsStServiceAbilityE2::OnStart(const Want &want) PublishEvent(APP_E2_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); SubscribeEvent(); } + void AmsStServiceAbilityE2::OnCommand(const AAFwk::Want &want, bool restart, int startId) { HILOG_INFO("AmsStServiceAbilityE2::OnCommand"); @@ -132,6 +136,7 @@ void AmsStServiceAbilityE2::OnCommand(const AAFwk::Want &want, bool restart, int Ability::OnCommand(want, restart, startId); PublishEvent(APP_E2_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); } + void AmsStServiceAbilityE2::OnNewWant(const Want &want) { HILOG_INFO("AmsStServiceAbilityE2::OnNewWant"); @@ -139,6 +144,7 @@ void AmsStServiceAbilityE2::OnNewWant(const Want &want) GetWantInfo(want); Ability::OnNewWant(want); } + void AmsStServiceAbilityE2::DisConnectOtherAbility() { HILOG_INFO("AmsStServiceAbilityE2::DisConnectOtherAbility begin"); @@ -156,6 +162,7 @@ void AmsStServiceAbilityE2::OnStop() Ability::OnStop(); PublishEvent(APP_E2_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); } + void AmsStServiceAbilityE2::GetDataByDataAbility() { std::shared_ptr helper = DataAbilityHelper::Creator(GetContext()); @@ -177,6 +184,7 @@ void AmsStServiceAbilityE2::GetDataByDataAbility() PublishEvent(APP_E2_RESP_EVENT_NAME, 0, "GetDataByDataAbility"); } } + void AmsStServiceAbilityE2::OnActive() { HILOG_INFO("AmsStServiceAbilityE2::OnActive"); @@ -184,6 +192,7 @@ void AmsStServiceAbilityE2::OnActive() Ability::OnActive(); PublishEvent(APP_E2_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); } + void AmsStServiceAbilityE2::OnInactive() { HILOG_INFO("AmsStServiceAbilityE2::OnInactive"); @@ -191,6 +200,7 @@ void AmsStServiceAbilityE2::OnInactive() Ability::OnInactive(); PublishEvent(APP_E2_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); } + void AmsStServiceAbilityE2::OnBackground() { HILOG_INFO("AmsStServiceAbilityE2::OnBackground"); @@ -198,6 +208,7 @@ void AmsStServiceAbilityE2::OnBackground() Ability::OnBackground(); PublishEvent(APP_E2_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnBackground"); } + sptr AmsStServiceAbilityE2::OnConnect(const Want &want) { HILOG_INFO("AmsStServiceAbilityE2::OnConnect"); @@ -206,6 +217,7 @@ sptr AmsStServiceAbilityE2::OnConnect(const Want &want) PublishEvent(APP_E2_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnConnect"); return nullptr; } + void AmsStServiceAbilityE2::OnDisconnect(const Want &want) { HILOG_INFO("AmsStServiceAbilityE2::OnDisconnect"); @@ -213,6 +225,7 @@ void AmsStServiceAbilityE2::OnDisconnect(const Want &want) Ability::OnDisconnect(want); PublishEvent(APP_E2_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); } + void AmsStServiceAbilityE2::Clear() { shouldReturn_ = ""; @@ -226,6 +239,7 @@ void AmsStServiceAbilityE2::Clear() nextTargetAbilityConn_ = ""; AmsStServiceAbilityE2::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } + void AmsStServiceAbilityE2::GetWantInfo(const Want &want) { Want mWant(want); @@ -240,6 +254,7 @@ void AmsStServiceAbilityE2::GetWantInfo(const Want &want) nextTargetAbilityConn_ = mWant.GetStringParam("nextTargetAbilityConn"); AmsStServiceAbilityE2::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } + bool AmsStServiceAbilityE2::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { HILOG_INFO("AmsStServiceAbilityE2::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", @@ -255,6 +270,7 @@ bool AmsStServiceAbilityE2::PublishEvent(const std::string &eventName, const int commonData.SetData(data); return CommonEventManager::PublishCommonEvent(commonData); } + bool AmsStServiceAbilityE2::SubscribeEvent() { MatchingSkills matchingSkills; @@ -265,6 +281,7 @@ bool AmsStServiceAbilityE2::SubscribeEvent() subscriber_->mainAbility_ = this; return CommonEventManager::SubscribeCommonEvent(subscriber_); } + void AmsStServiceAbilityE2::AppEventSubscriber::OnReceiveEvent(const CommonEventData &data) { auto eventName = data.GetWant().GetAction(); diff --git a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceF/src/ams_st_service_ability_f3.cpp b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceF/src/ams_st_service_ability_f3.cpp index 5ad88c511e9..a9c7577fe6a 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceF/src/ams_st_service_ability_f3.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceF/src/ams_st_service_ability_f3.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -39,6 +39,7 @@ void AmsStServiceAbilityF3::OnStart(const Want &want) Ability::OnStart(want); PublishEvent(APP_F3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); } + void AmsStServiceAbilityF3::OnNewWant(const Want &want) { HILOG_INFO("AmsStServiceAbilityF3::OnNewWant"); @@ -46,6 +47,7 @@ void AmsStServiceAbilityF3::OnNewWant(const Want &want) GetWantInfo(want); Ability::OnNewWant(want); } + void AmsStServiceAbilityF3::OnCommand(const AAFwk::Want &want, bool restart, int startId) { HILOG_INFO("AmsStServiceAbilityF3::OnCommand"); @@ -54,6 +56,7 @@ void AmsStServiceAbilityF3::OnCommand(const AAFwk::Want &want, bool restart, int Ability::OnCommand(want, restart, startId); PublishEvent(APP_F3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); } + void AmsStServiceAbilityF3::OnStop() { HILOG_INFO("AmsStServiceAbilityF3::onStop"); @@ -61,6 +64,7 @@ void AmsStServiceAbilityF3::OnStop() Ability::OnStop(); PublishEvent(APP_F3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); } + void AmsStServiceAbilityF3::OnActive() { HILOG_INFO("AmsStServiceAbilityF3::OnActive"); @@ -68,6 +72,7 @@ void AmsStServiceAbilityF3::OnActive() Ability::OnActive(); PublishEvent(APP_F3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); } + void AmsStServiceAbilityF3::OnInactive() { HILOG_INFO("AmsStServiceAbilityF3::OnInactive"); @@ -75,6 +80,7 @@ void AmsStServiceAbilityF3::OnInactive() Ability::OnInactive(); PublishEvent(APP_F3_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); } + void AmsStServiceAbilityF3::OnBackground() { HILOG_INFO("AmsStServiceAbilityF3::OnBackground"); @@ -89,6 +95,7 @@ void AmsStServiceAbilityF3::Clear() targetBundle_ = ""; targetAbility_ = ""; } + void AmsStServiceAbilityF3::GetWantInfo(const Want &want) { Want mWant(want); @@ -96,6 +103,7 @@ void AmsStServiceAbilityF3::GetWantInfo(const Want &want) targetBundle_ = mWant.GetStringParam("targetBundle"); targetAbility_ = mWant.GetStringParam("targetAbility"); } + bool AmsStServiceAbilityF3::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { HILOG_INFO("AmsStServiceAbilityF3::PublishEvent eventName = %s, code = %d, data = %s", diff --git a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceG/src/ams_st_service_ability_g1.cpp b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceG/src/ams_st_service_ability_g1.cpp index 44b5651ab18..4c0039dbc09 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceG/src/ams_st_service_ability_g1.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceG/src/ams_st_service_ability_g1.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -54,6 +54,7 @@ std::vector AmsStServiceAbilityG1::Split(std::string str, const std } return splitString; } + void AmsStServiceAbilityG1::StartOtherAbility() { HILOG_INFO("AmsStServiceAbilityG1::StartOtherAbility begin targetBundle=%{public}s, targetAbility=%{public}s", @@ -80,6 +81,7 @@ void AmsStServiceAbilityG1::StartOtherAbility() } } } + void AmsStServiceAbilityG1::ConnectOtherAbility() { HILOG_INFO( @@ -115,6 +117,7 @@ void AmsStServiceAbilityG1::ConnectOtherAbility() } HILOG_INFO("AmsStServiceAbilityG1::ConnectOtherAbility end"); } + void AmsStServiceAbilityG1::OnStart(const Want &want) { HILOG_INFO("AmsStServiceAbilityG1::OnStart"); @@ -124,6 +127,7 @@ void AmsStServiceAbilityG1::OnStart(const Want &want) PublishEvent(APP_G1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); SubscribeEvent(); } + void AmsStServiceAbilityG1::OnCommand(const AAFwk::Want &want, bool restart, int startId) { HILOG_INFO("AmsStServiceAbilityG1::OnCommand"); @@ -132,6 +136,7 @@ void AmsStServiceAbilityG1::OnCommand(const AAFwk::Want &want, bool restart, int Ability::OnCommand(want, restart, startId); PublishEvent(APP_G1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); } + void AmsStServiceAbilityG1::OnNewWant(const Want &want) { HILOG_INFO("AmsStServiceAbilityG1::OnNewWant"); @@ -139,6 +144,7 @@ void AmsStServiceAbilityG1::OnNewWant(const Want &want) GetWantInfo(want); Ability::OnNewWant(want); } + void AmsStServiceAbilityG1::DisConnectOtherAbility() { HILOG_INFO("AmsStServiceAbilityG1::DisConnectOtherAbility begin"); @@ -156,6 +162,7 @@ void AmsStServiceAbilityG1::OnStop() Ability::OnStop(); PublishEvent(APP_G1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); } + void AmsStServiceAbilityG1::GetDataByDataAbility() { std::shared_ptr helper = DataAbilityHelper::Creator(std::shared_ptr(this)); @@ -177,6 +184,7 @@ void AmsStServiceAbilityG1::GetDataByDataAbility() PublishEvent(APP_G1_RESP_EVENT_NAME, 0, "GetDataByDataAbility"); } } + void AmsStServiceAbilityG1::OnActive() { HILOG_INFO("AmsStServiceAbilityG1::OnActive"); @@ -184,6 +192,7 @@ void AmsStServiceAbilityG1::OnActive() Ability::OnActive(); PublishEvent(APP_G1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); } + void AmsStServiceAbilityG1::OnInactive() { HILOG_INFO("AmsStServiceAbilityG1::OnInactive"); @@ -191,6 +200,7 @@ void AmsStServiceAbilityG1::OnInactive() Ability::OnInactive(); PublishEvent(APP_G1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); } + void AmsStServiceAbilityG1::OnBackground() { HILOG_INFO("AmsStServiceAbilityG1::OnBackground"); @@ -198,6 +208,7 @@ void AmsStServiceAbilityG1::OnBackground() Ability::OnBackground(); PublishEvent(APP_G1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnBackground"); } + sptr AmsStServiceAbilityG1::OnConnect(const Want &want) { HILOG_INFO("AmsStServiceAbilityG1::OnConnect"); @@ -206,6 +217,7 @@ sptr AmsStServiceAbilityG1::OnConnect(const Want &want) PublishEvent(APP_G1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnConnect"); return nullptr; } + void AmsStServiceAbilityG1::OnDisconnect(const Want &want) { HILOG_INFO("AmsStServiceAbilityG1::OnDisconnect"); @@ -213,6 +225,7 @@ void AmsStServiceAbilityG1::OnDisconnect(const Want &want) Ability::OnDisconnect(want); PublishEvent(APP_G1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); } + void AmsStServiceAbilityG1::Clear() { shouldReturn_ = ""; @@ -226,6 +239,7 @@ void AmsStServiceAbilityG1::Clear() nextTargetAbilityConn_ = ""; AmsStServiceAbilityG1::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } + void AmsStServiceAbilityG1::GetWantInfo(const Want &want) { Want mWant(want); @@ -240,6 +254,7 @@ void AmsStServiceAbilityG1::GetWantInfo(const Want &want) nextTargetAbilityConn_ = mWant.GetStringParam("nextTargetAbilityConn"); AmsStServiceAbilityG1::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } + bool AmsStServiceAbilityG1::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { HILOG_INFO("AmsStServiceAbilityG1::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", @@ -255,6 +270,7 @@ bool AmsStServiceAbilityG1::PublishEvent(const std::string &eventName, const int commonData.SetData(data); return CommonEventManager::PublishCommonEvent(commonData); } + bool AmsStServiceAbilityG1::SubscribeEvent() { MatchingSkills matchingSkills; @@ -265,6 +281,7 @@ bool AmsStServiceAbilityG1::SubscribeEvent() subscriber_->mainAbility_ = this; return CommonEventManager::SubscribeCommonEvent(subscriber_); } + void AmsStServiceAbilityG1::AppEventSubscriber::OnReceiveEvent(const CommonEventData &data) { auto eventName = data.GetWant().GetAction(); diff --git a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceH/src/ams_st_service_ability_h1.cpp b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceH/src/ams_st_service_ability_h1.cpp index 80d609c5e0a..7293ba61811 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceH/src/ams_st_service_ability_h1.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsSystemTestServiceH/src/ams_st_service_ability_h1.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -54,6 +54,7 @@ std::vector AmsStServiceAbilityH1::Split(std::string str, const std } return splitString; } + void AmsStServiceAbilityH1::StartOtherAbility() { HILOG_INFO("AmsStServiceAbilityH1::StartOtherAbility begin targetBundle=%{public}s, targetAbility=%{public}s", @@ -80,6 +81,7 @@ void AmsStServiceAbilityH1::StartOtherAbility() } } } + void AmsStServiceAbilityH1::ConnectOtherAbility() { HILOG_INFO( @@ -115,6 +117,7 @@ void AmsStServiceAbilityH1::ConnectOtherAbility() } HILOG_INFO("AmsStServiceAbilityH1::ConnectOtherAbility end"); } + void AmsStServiceAbilityH1::OnStart(const Want &want) { HILOG_INFO("AmsStServiceAbilityH1::OnStart"); @@ -124,6 +127,7 @@ void AmsStServiceAbilityH1::OnStart(const Want &want) PublishEvent(APP_H1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); SubscribeEvent(); } + void AmsStServiceAbilityH1::OnCommand(const AAFwk::Want &want, bool restart, int startId) { HILOG_INFO("AmsStServiceAbilityH1::OnCommand"); @@ -132,6 +136,7 @@ void AmsStServiceAbilityH1::OnCommand(const AAFwk::Want &want, bool restart, int Ability::OnCommand(want, restart, startId); PublishEvent(APP_H1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); } + void AmsStServiceAbilityH1::OnNewWant(const Want &want) { HILOG_INFO("AmsStServiceAbilityH1::OnNewWant"); @@ -139,6 +144,7 @@ void AmsStServiceAbilityH1::OnNewWant(const Want &want) GetWantInfo(want); Ability::OnNewWant(want); } + void AmsStServiceAbilityH1::DisConnectOtherAbility() { HILOG_INFO("AmsStServiceAbilityH1::DisConnectOtherAbility begin"); @@ -156,6 +162,7 @@ void AmsStServiceAbilityH1::OnStop() Ability::OnStop(); PublishEvent(APP_H1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); } + void AmsStServiceAbilityH1::GetDataByDataAbility() { std::shared_ptr helper = DataAbilityHelper::Creator(std::shared_ptr(this)); @@ -177,6 +184,7 @@ void AmsStServiceAbilityH1::GetDataByDataAbility() PublishEvent(APP_H1_RESP_EVENT_NAME, 0, "GetDataByDataAbility"); } } + void AmsStServiceAbilityH1::OnActive() { HILOG_INFO("AmsStServiceAbilityH1::OnActive"); @@ -184,6 +192,7 @@ void AmsStServiceAbilityH1::OnActive() Ability::OnActive(); PublishEvent(APP_H1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); } + void AmsStServiceAbilityH1::OnInactive() { HILOG_INFO("AmsStServiceAbilityH1::OnInactive"); @@ -191,6 +200,7 @@ void AmsStServiceAbilityH1::OnInactive() Ability::OnInactive(); PublishEvent(APP_H1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); } + void AmsStServiceAbilityH1::OnBackground() { HILOG_INFO("AmsStServiceAbilityH1::OnBackground"); @@ -198,6 +208,7 @@ void AmsStServiceAbilityH1::OnBackground() Ability::OnBackground(); PublishEvent(APP_H1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnBackground"); } + sptr AmsStServiceAbilityH1::OnConnect(const Want &want) { HILOG_INFO("AmsStServiceAbilityH1::OnConnect"); @@ -206,6 +217,7 @@ sptr AmsStServiceAbilityH1::OnConnect(const Want &want) PublishEvent(APP_H1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnConnect"); return nullptr; } + void AmsStServiceAbilityH1::OnDisconnect(const Want &want) { HILOG_INFO("AmsStServiceAbilityH1::OnDisconnect"); @@ -213,6 +225,7 @@ void AmsStServiceAbilityH1::OnDisconnect(const Want &want) Ability::OnDisconnect(want); PublishEvent(APP_H1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); } + void AmsStServiceAbilityH1::Clear() { shouldReturn_ = ""; @@ -226,6 +239,7 @@ void AmsStServiceAbilityH1::Clear() nextTargetAbilityConn_ = ""; AmsStServiceAbilityH1::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } + void AmsStServiceAbilityH1::GetWantInfo(const Want &want) { Want mWant(want); @@ -240,6 +254,7 @@ void AmsStServiceAbilityH1::GetWantInfo(const Want &want) nextTargetAbilityConn_ = mWant.GetStringParam("nextTargetAbilityConn"); AmsStServiceAbilityH1::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } + bool AmsStServiceAbilityH1::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { HILOG_INFO("AmsStServiceAbilityH1::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", @@ -255,6 +270,7 @@ bool AmsStServiceAbilityH1::PublishEvent(const std::string &eventName, const int commonData.SetData(data); return CommonEventManager::PublishCommonEvent(commonData); } + bool AmsStServiceAbilityH1::SubscribeEvent() { MatchingSkills matchingSkills; @@ -265,6 +281,7 @@ bool AmsStServiceAbilityH1::SubscribeEvent() subscriber_->mainAbility_ = this; return CommonEventManager::SubscribeCommonEvent(subscriber_); } + void AmsStServiceAbilityH1::AppEventSubscriber::OnReceiveEvent(const CommonEventData &data) { auto eventName = data.GetWant().GetAction(); diff --git a/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/src/service_ability_a.cpp b/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/src/service_ability_a.cpp index 123e907fada..df7d2410864 100644 --- a/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/src/service_ability_a.cpp +++ b/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/src/service_ability_a.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -13,12 +13,6 @@ * limitations under the License. */ #include "service_ability_a.h" -// #include "hilog_wrapper.h" -// #include "iremote_broker.h" -// #include "iremote_object.h" -// #include "iremote_proxy.h" -// #include "iremote_stub.h" -// #include "main_service_ability.h" #include "test_ability_connection.h" namespace OHOS { @@ -28,11 +22,13 @@ void ServiceAbilityA::OnStart(const Want &want) HILOG_INFO("ServiceAbilityA OnStart"); Ability::OnStart(want); } + void ServiceAbilityA::OnCommand(const AAFwk::Want &want, bool restart, int startId) { HILOG_INFO("ServiceAbilityA::OnCommand"); Ability::OnCommand(want, restart, startId); } + sptr ServiceAbilityA::OnConnect(const Want &want) { HILOG_INFO("ServiceAbilityA::OnConnect"); @@ -41,11 +37,13 @@ sptr ServiceAbilityA::OnConnect(const Want &want) Ability::OnConnect(want); return remoteObject->AsObject(); } + void ServiceAbilityA::OnDisconnect(const Want &want) { HILOG_INFO("ServiceAbilityA::OnDisconnect"); Ability::OnDisconnect(want); } + void ServiceAbilityA::OnStop() { HILOG_INFO("ServiceAbilityA::OnStop"); diff --git a/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/src/verify_act_first_ability.cpp b/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/src/verify_act_first_ability.cpp index f47ad90b8ad..e4ec061d522 100644 --- a/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/src/verify_act_first_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/src/verify_act_first_ability.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -31,6 +31,7 @@ void AbilityConnectionActFirst::OnAbilityDisconnectDone(const AppExecFwk::Elemen HILOG_INFO("AbilityConnectionActFirst OnAbilityDisconnectDone resultCode: %{public}d", resultCode); HILOG_INFO("AbilityConnectionActFirst OnAbilityDisconnectDone : %{public}s", element.GetAbilityName().c_str()); } + void VerifyIOAbilityLifecycleCallbacks::OnAbilityStart(const std::shared_ptr &ability) { HILOG_INFO("----------VerifyIOAbilityLifecycleCallbacks::OnAbilityStart called. AbilityName is %{public}s", @@ -69,6 +70,7 @@ void VerifyIOAbilityLifecycleCallbacks::OnAbilityStop(const std::shared_ptrGetAbilityName().c_str()); } + void VerifyIOAbilityLifecycleCallbacks::OnAbilitySaveState(const PacMap &outState) { HILOG_INFO("----------VerifyIOAbilityLifecycleCallbacks::OnAbilitySaveState called.----------"); @@ -98,24 +100,28 @@ void VerifyActFirstAbility::OnStart(const Want &want) Ability::OnStart(want); } + void VerifyActFirstAbility::OnStop() { HILOG_INFO("----------VerifyActFirstAbility::onStop begin----------"); HILOG_INFO("----------VerifyActFirstAbility::onStop end----------"); Ability::OnStop(); } + void VerifyActFirstAbility::OnActive() { HILOG_INFO("----------VerifyActFirstAbility::OnActive begin----------"); HILOG_INFO("----------VerifyActFirstAbility::OnActive end----------"); Ability::OnActive(); } + void VerifyActFirstAbility::OnInactive() { HILOG_INFO("----------VerifyActFirstAbility::OnInactive begin----------"); HILOG_INFO("----------VerifyActFirstAbility::OnInactive end----------"); Ability::OnInactive(); } + void VerifyActFirstAbility::OnBackground() { HILOG_INFO("----------VerifyActFirstAbility::OnBackground begin----------"); diff --git a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/BUILD.gn index 4557c046ecf..faba4c317db 100755 --- a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -40,6 +40,7 @@ config("taskDispatcherTestBConfig") { cflags += [ "-DBINDER_IPC_32BIT" ] } } + ohos_shared_library("taskDispatcherTestB") { sources = [ "${SUBDEMOSYSTEM_DIR}/src/main_ability.cpp", diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp index 10b06b93123..f17b9f9ff9b 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -35,6 +35,7 @@ void FormAbilityCommonA::AcquireFormCallback::OnAcquired(const int32_t result, c { HILOG_INFO("%{public}s called[%{public}s]", __func__, std::to_string(formJsInfo.formId).c_str()); } + void FormAbilityCommonA::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const { HILOG_INFO("%{public}s called", __func__); @@ -71,6 +72,7 @@ void FormAbilityCommonA::FMS_acquireForm(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100, ""); } } + void FormAbilityCommonA::FMS_deleteForm(std::string data) { HILOG_INFO("%{public}s formId: %{public}s", __func__, data.c_str()); @@ -83,6 +85,7 @@ void FormAbilityCommonA::FMS_deleteForm(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, "false"); } } + void FormAbilityCommonA::FMS_acquireForm_batch(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -107,6 +110,7 @@ void FormAbilityCommonA::FMS_acquireForm_batch(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "false"); } } + void FormAbilityCommonA::FMS_deleteFormBatch(std::string strFormId) { HILOG_INFO("%{public}s called", __func__); @@ -119,15 +123,18 @@ void FormAbilityCommonA::FMS_deleteFormBatch(std::string strFormId) FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "false"); } } + FormAbilityCommonA::~FormAbilityCommonA() { CommonEventManager::UnSubscribeCommonEvent(subscriber_); } + void FormAbilityCommonA::OnStart(const Want &want) { HILOG_INFO("FormAbilityCommonA::onStart"); Ability::OnStart(want); } + void FormAbilityCommonA::OnActive() { HILOG_INFO("FormAbilityCommonA::OnActive"); @@ -142,18 +149,21 @@ void FormAbilityCommonA::OnStop() Ability::OnStop(); } + void FormAbilityCommonA::OnInactive() { HILOG_INFO("FormAbilityCommonA::OnInactive"); Ability::OnInactive(); } + void FormAbilityCommonA::OnBackground() { HILOG_INFO("FormAbilityCommonA::OnBackground"); Ability::OnBackground(); } + void FormAbilityCommonA::SubscribeEvent() { HILOG_INFO("FormAbilityCommonA::SubscribeEvent"); diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonB/src/form_ability_commonb.cpp b/test/resource/formsystemtestability/fmsSystemTestHostCommonB/src/form_ability_commonb.cpp index fb5e9f5641c..7ee493ced51 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostCommonB/src/form_ability_commonb.cpp +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonB/src/form_ability_commonb.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -35,6 +35,7 @@ void FormAbilityCommonB::AcquireFormCallback::OnAcquired(const int32_t result, c { HILOG_INFO("%{public}s called[%{public}s]", __func__, std::to_string(formJsInfo.formId).c_str()); } + void FormAbilityCommonB::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const { HILOG_INFO("%{public}s called", __func__); @@ -71,6 +72,7 @@ void FormAbilityCommonB::FMS_acquireForm(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_B, EVENT_CODE_100, ""); } } + void FormAbilityCommonB::FMS_acquireForm_batch(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -95,6 +97,7 @@ void FormAbilityCommonB::FMS_acquireForm_batch(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "false"); } } + void FormAbilityCommonB::FMS_deleteFormBatch(std::string strFormId) { HILOG_INFO("%{public}s called", __func__); @@ -107,6 +110,7 @@ void FormAbilityCommonB::FMS_deleteFormBatch(std::string strFormId) FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "false"); } } + void FormAbilityCommonB::FMS_deleteForm(std::string data) { HILOG_INFO("%{public}s formId: %{public}s", __func__, data.c_str()); @@ -119,15 +123,18 @@ void FormAbilityCommonB::FMS_deleteForm(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_B_DEL, EVENT_CODE_101, "false"); } } + FormAbilityCommonB::~FormAbilityCommonB() { CommonEventManager::UnSubscribeCommonEvent(subscriber_); } + void FormAbilityCommonB::OnStart(const Want &want) { HILOG_INFO("FormAbilityCommonB::onStart"); Ability::OnStart(want); } + void FormAbilityCommonB::OnActive() { HILOG_INFO("FormAbilityCommonB::OnActive"); @@ -142,18 +149,21 @@ void FormAbilityCommonB::OnStop() Ability::OnStop(); } + void FormAbilityCommonB::OnInactive() { HILOG_INFO("FormAbilityCommonB::OnInactive"); Ability::OnInactive(); } + void FormAbilityCommonB::OnBackground() { HILOG_INFO("FormAbilityCommonB::OnBackground"); Ability::OnBackground(); } + void FormAbilityCommonB::SubscribeEvent() { HILOG_INFO("FormAbilityCommonB::SubscribeEvent"); diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/src/form_ability_no_perm.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/src/form_ability_no_perm.cpp index 3ff4f626934..2cdc006a909 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/src/form_ability_no_perm.cpp +++ b/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/src/form_ability_no_perm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -28,10 +28,12 @@ void FormAbilityNoPerm::AcquireFormCallback::OnAcquired(const int32_t result, co { HILOG_INFO("%{public}s called", __func__); } + void FormAbilityNoPerm::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const { HILOG_INFO("%{public}s called", __func__); } + void FormAbilityNoPerm::AcquireFormCallback::OnFormUninstall(const int64_t formId) const { HILOG_INFO("%{public}s called", __func__); @@ -95,6 +97,7 @@ void FormAbilityNoPerm::OnStart(const Want &want) }; SubscribeEvent(eventList); } + void FormAbilityNoPerm::OnActive() { HILOG_INFO("FormAbilityNoPerm::OnActive"); @@ -109,18 +112,21 @@ void FormAbilityNoPerm::OnStop() Ability::OnStop(); } + void FormAbilityNoPerm::OnInactive() { HILOG_INFO("FormAbilityNoPerm::OnInactive"); Ability::OnInactive(); } + void FormAbilityNoPerm::OnBackground() { HILOG_INFO("FormAbilityNoPerm::OnBackground"); Ability::OnBackground(); } + void FormAbilityNoPerm::SubscribeEvent(const std::vector &eventList) { MatchingSkills matchingSkills; diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp index dc5b9b0ce36..ab5f9dc1e3e 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -44,6 +44,7 @@ void FormAbilityA::AcquireFormCallback::OnAcquired(const int32_t result, const F HILOG_INFO("%{public}s called", __func__); FormTestUtils::PublishEvent(this->caseName_, this->code_, std::to_string(formJsInfo.formId)); } + void FormAbilityA::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const { HILOG_INFO("%{public}s called", __func__); @@ -65,6 +66,7 @@ void FormAbilityA::AcquireFormCallback::OnFormUninstall(const int64_t formId) co { HILOG_INFO("%{public}s called", __func__); } + void FormAbilityA::FMS_deleteFormCommon(std::string strFormId) { HILOG_INFO("%{public}s called, formId: %{public}s", __func__, strFormId.c_str()); @@ -107,6 +109,7 @@ void FormAbilityA::FMS_acquireForm_0300(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0300, EVENT_CODE_300, "false"); } } + void FormAbilityA::FMS_acquireForm_0400(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -128,6 +131,7 @@ void FormAbilityA::FMS_acquireForm_0400(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0400, EVENT_CODE_400, "false"); } } + void FormAbilityA::FMS_acquireForm_0500(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -150,6 +154,7 @@ void FormAbilityA::FMS_acquireForm_0500(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0500, EVENT_CODE_500, "false"); } } + void FormAbilityA::FMS_acquireForm_0600(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -172,6 +177,7 @@ void FormAbilityA::FMS_acquireForm_0600(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0600, EVENT_CODE_600, "false"); } } + void FormAbilityA::FMS_acquireForm_0700(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -193,6 +199,7 @@ void FormAbilityA::FMS_acquireForm_0700(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0700, EVENT_CODE_700, "false"); } } + void FormAbilityA::FMS_acquireForm_1000(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -214,6 +221,7 @@ void FormAbilityA::FMS_acquireForm_1000(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1000, EVENT_CODE_1000, "false"); } } + void FormAbilityA::FMS_acquireForm_1100(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -236,6 +244,7 @@ void FormAbilityA::FMS_acquireForm_1100(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1100, EVENT_CODE_1100, ""); } } + void FormAbilityA::FMS_acquireForm_1200(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -304,6 +313,7 @@ void FormAbilityA::FMS_acquireForm_1600(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1600, EVENT_CODE_1600, ""); } } + void FormAbilityA::FMS_acquireForm_1600_1(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -326,6 +336,7 @@ void FormAbilityA::FMS_acquireForm_1600_1(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1600_1, EVENT_CODE_1610, ""); } } + void FormAbilityA::FMS_acquireForm_1800(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -348,6 +359,7 @@ void FormAbilityA::FMS_acquireForm_1800(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1800, EVENT_CODE_1800, ""); } } + void FormAbilityA::FMS_acquireForm_1800_1(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -370,6 +382,7 @@ void FormAbilityA::FMS_acquireForm_1800_1(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1800_1, EVENT_CODE_1810, ""); } } + void FormAbilityA::FMS_acquireForm_1900(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -392,6 +405,7 @@ void FormAbilityA::FMS_acquireForm_1900(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1900, EVENT_CODE_1900, ""); } } + void FormAbilityA::FMS_acquireForm_2100(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -415,6 +429,7 @@ void FormAbilityA::FMS_acquireForm_2100(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2100, EVENT_CODE_2100, "false"); } } + void FormAbilityA::FMS_acquireForm_2200(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -430,6 +445,7 @@ void FormAbilityA::FMS_acquireForm_2200(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2200, EVENT_CODE_2200, "false"); } } + void FormAbilityA::FMS_acquireForm_2300(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -445,6 +461,7 @@ void FormAbilityA::FMS_acquireForm_2300(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2300, EVENT_CODE_2300, "false"); } } + void FormAbilityA::FMS_acquireForm_2400(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -483,6 +500,7 @@ void FormAbilityA::FMS_acquireForm_2500(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2500, EVENT_CODE_2500, "false"); } } + void FormAbilityA::FMS_acquireForm_2600_1(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -544,6 +562,7 @@ void FormAbilityA::FMS_acquireForm_2700(std::string data) FMS_deleteFormCommon(data); } + void FormAbilityA::FMS_acquireForm_2800(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -562,6 +581,7 @@ void FormAbilityA::FMS_acquireForm_2800(std::string data) FMS_deleteFormCommon(data); } + void FormAbilityA::FMS_acquireForm_2900(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -607,6 +627,7 @@ void FormAbilityA::FMS_acquireForm_2900_1(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2900_1, EVENT_CODE_2910, ""); } } + void FormAbilityA::FMS_acquireForm_3000(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -628,6 +649,7 @@ void FormAbilityA::FMS_acquireForm_3000(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_3000, EVENT_CODE_3000, "false"); } } + void FormAbilityA::FMS_acquireForm_3100(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -654,9 +676,11 @@ void FormAbilityA::FMS_acquireForm_3100(std::string data) void FormAbilityA::FMS_acquireForm_3300(std::string data) { } + void FormAbilityA::FMS_acquireForm_3400(std::string data) { } + void FormAbilityA::FMS_acquireForm_3500(std::string data) { } @@ -683,6 +707,7 @@ void FormAbilityA::FMS_acquireForm_tempForm(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP, ""); } } + void FormAbilityA::FMS_acquireFormBatch(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -732,6 +757,7 @@ void FormAbilityA::FMS_acquireFormBatchB(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH_B, EVENT_CODE_BATCH_B, "false"); } } + void FormAbilityA::FMS_acquireFormTempBatch(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -757,6 +783,7 @@ void FormAbilityA::FMS_acquireFormTempBatch(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "false"); } } + void FormAbilityA::FMS_deleteFormBatch(std::string strFormId) { HILOG_INFO("%{public}s called", __func__); @@ -769,15 +796,18 @@ void FormAbilityA::FMS_deleteFormBatch(std::string strFormId) FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "false"); } } + FormAbilityA::~FormAbilityA() { CommonEventManager::UnSubscribeCommonEvent(subscriber_); } + void FormAbilityA::OnStart(const Want &want) { HILOG_INFO("FormAbilityA::onStart"); Ability::OnStart(want); } + void FormAbilityA::OnActive() { HILOG_INFO("FormAbilityA::OnActive"); @@ -792,18 +822,21 @@ void FormAbilityA::OnStop() Ability::OnStop(); } + void FormAbilityA::OnInactive() { HILOG_INFO("FormAbilityA::OnInactive"); Ability::OnInactive(); } + void FormAbilityA::OnBackground() { HILOG_INFO("FormAbilityA::OnBackground"); Ability::OnBackground(); } + void FormAbilityA::SubscribeEvent() { HILOG_INFO("FormAbilityA::SubscribeEvent"); diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp index 1f8de799d4e..cfc5bb42ca0 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -33,6 +33,7 @@ void FormAbilityDeleteForm::AcquireFormCallback::OnAcquired(const int32_t result ability_->FMS_deleteForm_common(formJsInfo.formId, this->caseName_); } } + void FormAbilityDeleteForm::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const { HILOG_INFO("%{public}s called", __func__); @@ -116,6 +117,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_0300(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0300, EVENT_CODE_300, ""); } } + void FormAbilityDeleteForm::FMS_deleteForm_0400(std::string data) { std::shared_ptr callback = @@ -217,6 +219,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_0800(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800, ""); } } + void FormAbilityDeleteForm::FMS_deleteForm_0900(std::string data) { std::shared_ptr callback = @@ -347,6 +350,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1400(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1400, EVENT_CODE_1400, ""); } } + void FormAbilityDeleteForm::FMS_deleteForm_1401(std::string data) { HILOG_INFO("%{public}s formId: %{public}s", __func__, data.c_str()); @@ -411,6 +415,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1501(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1501, EVENT_CODE_1510, "deleteError"); } } + void FormAbilityDeleteForm::FMS_deleteForm_1502(std::string data) { HILOG_INFO("%{public}s formId: %{public}s", __func__, data.c_str()); @@ -423,6 +428,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1502(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1502, EVENT_CODE_1511, "false"); } } + void FormAbilityDeleteForm::FMS_deleteForm_1600(std::string data) { std::shared_ptr callback = @@ -444,6 +450,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1600(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1600, EVENT_CODE_1600, ""); } } + void FormAbilityDeleteForm::FMS_deleteForm_1601(std::string data) { HILOG_INFO("%{public}s formId: %{public}s", __func__, data.c_str()); @@ -473,6 +480,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1601(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1601, EVENT_CODE_1610, "deleteError"); } } + void FormAbilityDeleteForm::FMS_deleteForm_1602(std::string data) { HILOG_INFO("%{public}s formId: %{public}s", __func__, data.c_str()); @@ -537,6 +545,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1701(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1701, EVENT_CODE_1701, "deleteError"); } } + void FormAbilityDeleteForm::FMS_deleteForm_1702(std::string data) { HILOG_INFO("%{public}s formId: %{public}s", __func__, data.c_str()); @@ -549,6 +558,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1702(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1702, EVENT_CODE_1702, "false"); } } + void FormAbilityDeleteForm::FMS_acquire_tempForm_batch(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -573,6 +583,7 @@ void FormAbilityDeleteForm::FMS_acquire_tempForm_batch(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "false"); } } + void FormAbilityDeleteForm::FMS_acquireForm_batch(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -597,6 +608,7 @@ void FormAbilityDeleteForm::FMS_acquireForm_batch(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "false"); } } + void FormAbilityDeleteForm::FMS_deleteFormBatch(std::string strFormId) { HILOG_INFO("%{public}s called", __func__); @@ -712,6 +724,7 @@ void FormAbilityDeleteForm::DeleteForm_1000(int64_t form_id) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, ""); } } + void FormAbilityDeleteForm::DeleteForm_1100(int64_t form_id) { bool bResult = DeleteForm(form_id); @@ -723,38 +736,47 @@ void FormAbilityDeleteForm::DeleteForm_1100(int64_t form_id) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100, "false"); } } + void FormAbilityDeleteForm::DeleteForm_1200(int64_t form_id) { FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1200, EVENT_CODE_1200, std::to_string(form_id)); } + void FormAbilityDeleteForm::DeleteForm_1400(int64_t form_id) { FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1400, EVENT_CODE_1400, std::to_string(form_id)); } + void FormAbilityDeleteForm::DeleteForm_1500(int64_t form_id) { FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1500, EVENT_CODE_1500, std::to_string(form_id)); } + void FormAbilityDeleteForm::DeleteForm_1501(int64_t form_id) { FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1501, EVENT_CODE_1510, std::to_string(form_id)); } + void FormAbilityDeleteForm::DeleteForm_1600(int64_t form_id) { FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1600, EVENT_CODE_1600, std::to_string(form_id)); } + void FormAbilityDeleteForm::DeleteForm_1601(int64_t form_id) { FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1601, EVENT_CODE_1610, std::to_string(form_id)); } + void FormAbilityDeleteForm::DeleteForm_1700(int64_t form_id) { FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1700, EVENT_CODE_1700, std::to_string(form_id)); } + void FormAbilityDeleteForm::DeleteForm_1701(int64_t form_id) { FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1701, EVENT_CODE_1701, std::to_string(form_id)); } + void FormAbilityDeleteForm::OnStart(const Want &want) { HILOG_INFO("FormAbilityDeleteForm::onStart"); @@ -789,6 +811,7 @@ void FormAbilityDeleteForm::OnStart(const Want &want) }; SubscribeEvent(eventList); } + void FormAbilityDeleteForm::OnActive() { HILOG_INFO("FormAbilityDeleteForm::OnActive"); @@ -803,18 +826,21 @@ void FormAbilityDeleteForm::OnStop() Ability::OnStop(); } + void FormAbilityDeleteForm::OnInactive() { HILOG_INFO("FormAbilityDeleteForm::OnInactive"); Ability::OnInactive(); } + void FormAbilityDeleteForm::OnBackground() { HILOG_INFO("FormAbilityDeleteForm::OnBackground"); Ability::OnBackground(); } + void FormAbilityDeleteForm::SubscribeEvent(const std::vector &eventList) { MatchingSkills matchingSkills; diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_releaseform.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_releaseform.cpp index 5361faddace..c4ca6576424 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_releaseform.cpp +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_releaseform.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -32,6 +32,7 @@ void FormAbilityReleaseForm::AcquireFormCallback::OnAcquired(const int32_t resul ability_->FMS_releaseForm_common(formJsInfo.formId, this->caseName_, this->lastformId_); } } + void FormAbilityReleaseForm::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const { HILOG_INFO("%{public}s called", __func__); @@ -102,6 +103,7 @@ void FormAbilityReleaseForm::FMS_releaseForm_0300(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0300, EVENT_CODE_300, ""); } } + void FormAbilityReleaseForm::FMS_releaseForm_0400(std::string data) { std::shared_ptr callback = @@ -202,6 +204,7 @@ void FormAbilityReleaseForm::FMS_releaseForm_0800(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0800, EVENT_CODE_800, ""); } } + void FormAbilityReleaseForm::FMS_releaseForm_0900(std::string data) { std::shared_ptr callback = @@ -333,6 +336,7 @@ void FormAbilityReleaseForm::FMS_releaseForm_1400(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1400, EVENT_CODE_1400, ""); } } + void FormAbilityReleaseForm::FMS_releaseForm_common_del(std::string data) { HILOG_INFO("%{public}s formId: %{public}s", __func__, data.c_str()); @@ -410,6 +414,7 @@ void FormAbilityReleaseForm::ReleaseForm_0700(int64_t form_id) FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0700, EVENT_CODE_700, "false"); } } + void FormAbilityReleaseForm::ReleaseForm_0800(int64_t form_id) { bool isReleaseCache = false; @@ -422,6 +427,7 @@ void FormAbilityReleaseForm::ReleaseForm_0800(int64_t form_id) FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0800, EVENT_CODE_800, "false"); } } + void FormAbilityReleaseForm::ReleaseForm_0900(int64_t form_id) { bool isReleaseCache = false; @@ -434,6 +440,7 @@ void FormAbilityReleaseForm::ReleaseForm_0900(int64_t form_id) FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0900, EVENT_CODE_900, "false"); } } + void FormAbilityReleaseForm::ReleaseForm_1000(int64_t form_id) { bool isReleaseCache = true; @@ -446,6 +453,7 @@ void FormAbilityReleaseForm::ReleaseForm_1000(int64_t form_id) FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1000, EVENT_CODE_1000, "false"); } } + void FormAbilityReleaseForm::ReleaseForm_1100(int64_t form_id) { bool isReleaseCache = true; @@ -458,6 +466,7 @@ void FormAbilityReleaseForm::ReleaseForm_1100(int64_t form_id) FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1100, EVENT_CODE_1100, "false"); } } + void FormAbilityReleaseForm::ReleaseForm_1200(int64_t form_id) { bool isReleaseCache = true; @@ -470,6 +479,7 @@ void FormAbilityReleaseForm::ReleaseForm_1200(int64_t form_id) FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1200, EVENT_CODE_1200, "false"); } } + void FormAbilityReleaseForm::ReleaseForm_1300(int64_t form_id, std::string lastFormId) { if (lastFormId == "") { @@ -489,6 +499,7 @@ void FormAbilityReleaseForm::ReleaseForm_1300(int64_t form_id, std::string lastF } } } + void FormAbilityReleaseForm::ReleaseForm_1400(int64_t form_id) { bool isReleaseCache = true; @@ -525,6 +536,7 @@ void FormAbilityReleaseForm::OnStart(const Want &want) }; SubscribeEvent(eventList); } + void FormAbilityReleaseForm::OnActive() { HILOG_INFO("FormAbilityReleaseForm::OnActive"); @@ -539,18 +551,21 @@ void FormAbilityReleaseForm::OnStop() Ability::OnStop(); } + void FormAbilityReleaseForm::OnInactive() { HILOG_INFO("FormAbilityReleaseForm::OnInactive"); Ability::OnInactive(); } + void FormAbilityReleaseForm::OnBackground() { HILOG_INFO("FormAbilityReleaseForm::OnBackground"); Ability::OnBackground(); } + void FormAbilityReleaseForm::SubscribeEvent(const std::vector &eventList) { MatchingSkills matchingSkills; diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormalB/src/form_ability_b.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/src/form_ability_b.cpp index f903327b92b..8d88015a429 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostNormalB/src/form_ability_b.cpp +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/src/form_ability_b.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -41,6 +41,7 @@ void FormAbilityB::AcquireFormCallback::OnAcquired(const int32_t result, const F ability_->FMS_deleteFormCommon(strFormId); } } + void FormAbilityB::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const { HILOG_INFO("%{public}s called", __func__); @@ -57,6 +58,7 @@ void FormAbilityB::AcquireFormCallback::OnFormUninstall(const int64_t formId) co { HILOG_INFO("%{public}s called", __func__); } + void FormAbilityB::FMS_deleteFormCommon(std::string strFormId) { HILOG_INFO("%{public}s called, formId: %{public}s", __func__, strFormId.c_str()); @@ -101,6 +103,7 @@ void FormAbilityB::FMS_acquireForm_1400(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1400, EVENT_CODE_1400, "false"); } } + void FormAbilityB::FMS_acquireForm_1500(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -147,6 +150,7 @@ void FormAbilityB::FMS_acquireForm_1800_2(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1800_2, EVENT_CODE_1820, ""); } } + void FormAbilityB::FMS_acquireForm_1800_3(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -186,6 +190,7 @@ void FormAbilityB::FMS_acquireForm_2400_1(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2400_1, EVENT_CODE_2410, "false"); } } + void FormAbilityB::FMS_acquireForm_3100(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -208,6 +213,7 @@ void FormAbilityB::FMS_acquireForm_3100(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3100, ""); } } + void FormAbilityB::FMS_acquireForm_tempForm(std::string data) { HILOG_INFO("%{public}s called", __func__); @@ -281,15 +287,18 @@ void FormAbilityB::FMS_acquireFormTempBatch(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "false"); } } + FormAbilityB::~FormAbilityB() { CommonEventManager::UnSubscribeCommonEvent(subscriber_); } + void FormAbilityB::OnStart(const Want &want) { HILOG_INFO("FormAbilityB::onStart"); Ability::OnStart(want); } + void FormAbilityB::OnActive() { HILOG_INFO("FormAbilityB::OnActive"); @@ -304,18 +313,21 @@ void FormAbilityB::OnStop() Ability::OnStop(); } + void FormAbilityB::OnInactive() { HILOG_INFO("FormAbilityB::OnInactive"); Ability::OnInactive(); } + void FormAbilityB::OnBackground() { HILOG_INFO("FormAbilityB::OnBackground"); Ability::OnBackground(); } + void FormAbilityB::SubscribeEvent() { HILOG_INFO("FormAbilityB::SubscribeEvent"); diff --git a/test/systemtest/common/ams/ams_service_ability_test/ams_service_ability_test.cpp b/test/systemtest/common/ams/ams_service_ability_test/ams_service_ability_test.cpp index 6b7f40d9da4..2317c98bd76 100644 --- a/test/systemtest/common/ams/ams_service_ability_test/ams_service_ability_test.cpp +++ b/test/systemtest/common/ams/ams_service_ability_test/ams_service_ability_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -123,7 +123,7 @@ public: result.clear(); char bufPs[BUFFER_SIZE]; FILE *ptr; - if (!cmd.empty() && (ptr = popen(cmd.c_str(), "r")) != NULL) { + if (!cmd.empty() && (ptr = popen(cmd.c_str(), "r")) != nullptr) { while (fgets(bufPs, BUFFER_SIZE, ptr) != nullptr) { result.append(bufPs); } diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index 94f64e84e45..fe626a12347 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -89,7 +89,11 @@ const std::string HELP_MSG_TEST = "usage: aa test \n" "options list:\n" " -h, --help list available commands\n" - " -p -s unittest start the test framework with options\n" + " -b -s unittest start the test framework with options\n" + " [-p ] the name of package with test-runner, " + "required for the FA model\n" + " [-m ] the name of module with test-runner, " + "required for the STAGE model\n" " [-s class ]\n" " [-s level ]\n" " [-s size ]\n" diff --git a/tools/aa/include/itest_observer.h b/tools/aa/include/itest_observer.h index 8d617010c80..9944096af43 100644 --- a/tools/aa/include/itest_observer.h +++ b/tools/aa/include/itest_observer.h @@ -28,7 +28,7 @@ public: virtual void TestStatus(const std::string &msg, const int &resultCode) = 0; virtual void TestFinished(const std::string &msg, const int &resultCode) = 0; virtual ShellCommandResult ExecuteShellCommand( - const std::string &cmd, const int64_t timeoutMs) = 0; + const std::string &cmd, const int64_t timeoutSec) = 0; enum class Message { AA_TEST_STATUS = 1, diff --git a/tools/aa/include/test_observer.h b/tools/aa/include/test_observer.h index ca4d8253791..9001415cf79 100644 --- a/tools/aa/include/test_observer.h +++ b/tools/aa/include/test_observer.h @@ -30,12 +30,12 @@ public: virtual void TestStatus(const std::string &msg, const int &resultCode) override; virtual void TestFinished(const std::string &msg, const int &resultCode) override; virtual ShellCommandResult ExecuteShellCommand( - const std::string &cmd, const int64_t timeoutMs) override; + const std::string &cmd, const int64_t timeoutSec) override; bool WaitForFinish(const int64_t &timeoutMs); private: bool isFinished_; - static constexpr int64_t SHELL_COMMAND_TIMEOUT_MAX = 5000; + static constexpr int64_t SHELL_COMMAND_TIMEOUT_MAX = 5; }; } // namespace AAFwk } // namespace OHOS diff --git a/tools/aa/include/test_observer_proxy.h b/tools/aa/include/test_observer_proxy.h index 62be09d3eb0..ac6dd5826a8 100644 --- a/tools/aa/include/test_observer_proxy.h +++ b/tools/aa/include/test_observer_proxy.h @@ -28,7 +28,7 @@ public: virtual void TestStatus(const std::string &msg, const int &resultCode) override; virtual void TestFinished(const std::string &msg, const int &resultCode) override; virtual ShellCommandResult ExecuteShellCommand( - const std::string &cmd, const int64_t timeoutMs) override; + const std::string &cmd, const int64_t timeoutSec) override; private: static inline BrokerDelegator delegator_; diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index a20c095ff83..468a054292d 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -353,9 +353,7 @@ ErrCode AbilityManagerShellCommand::CreateMessageMap() ErrCode AbilityManagerShellCommand::init() { - ErrCode result = AbilityManagerClient::GetInstance()->Connect(); - - return result; + return AbilityManagerClient::GetInstance()->Connect(); } ErrCode AbilityManagerShellCommand::RunAsHelpCommand() @@ -566,7 +564,6 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() int userID = DEFAULT_INVAL_VALUE; bool isfirstCommand = false; std::string args; - for (auto it = argList_.begin(); it != argList_.end(); it++) { if (*it == "-c" || *it == "--client") { if (isClient == false) { @@ -640,7 +637,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() break; } case 'l': { - if (isfirstCommand == false && optarg == nullptr) { + if (isfirstCommand == false) { isfirstCommand = true; } else { // 'aa dumpsys -i 10 -element -lastpage' @@ -1230,7 +1227,7 @@ ErrCode AbilityManagerShellCommand::RunAsTestCommand() if (opt == "-h" || opt == "--help") { resultReceiver_.append(HELP_MSG_TEST); return OHOS::ERR_OK; - } else if (opt == "-p" || opt == "-w") { + } else if (opt == "-b" || opt == "-w" || opt == "-p" || opt == "-m") { if (i >= argc_ - 1) { return TestCommandError("error: option [" + opt + "] requires a value.\n"); } @@ -1259,7 +1256,7 @@ bool AbilityManagerShellCommand::IsTestCommandIntegrity(const std::map opts = {"-p", "-s unittest"}; + std::vector opts = {"-b", "-s unittest"}; for (auto opt : opts) { auto it = params.find(opt); if (it == params.end()) { diff --git a/tools/aa/src/test_observer.cpp b/tools/aa/src/test_observer.cpp index b6020a1c2ba..cbd1a1acf5c 100644 --- a/tools/aa/src/test_observer.cpp +++ b/tools/aa/src/test_observer.cpp @@ -45,7 +45,7 @@ void TestObserver::TestFinished(const std::string &msg, const int &resultCode) isFinished_ = true; } -ShellCommandResult TestObserver::ExecuteShellCommand(const std::string &cmd, const int64_t timeoutMs) +ShellCommandResult TestObserver::ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec) { HILOG_INFO("enter"); ShellCommandResult result; @@ -57,8 +57,8 @@ ShellCommandResult TestObserver::ExecuteShellCommand(const std::string &cmd, con return result; } - int64_t timeout = (timeoutMs <= 0) ? SHELL_COMMAND_TIMEOUT_MAX : timeoutMs; - std::this_thread::sleep_for(std::chrono::microseconds(timeout)); + int64_t timeout = (timeoutSec <= 0) ? SHELL_COMMAND_TIMEOUT_MAX : timeoutSec; + std::this_thread::sleep_for(std::chrono::seconds(timeout)); char commandResult[1024] = {0}; while ((fgets(commandResult, sizeof(commandResult), file)) != nullptr) { diff --git a/tools/aa/src/test_observer_proxy.cpp b/tools/aa/src/test_observer_proxy.cpp index 1721a9e7ad2..bb5cdbce0fe 100644 --- a/tools/aa/src/test_observer_proxy.cpp +++ b/tools/aa/src/test_observer_proxy.cpp @@ -101,7 +101,7 @@ void TestObserverProxy::TestFinished(const std::string &msg, const int &resultCo } ShellCommandResult TestObserverProxy::ExecuteShellCommand( - const std::string &cmd, const int64_t timeoutMs) + const std::string &cmd, const int64_t timeoutSec) { HILOG_INFO("start"); @@ -125,8 +125,8 @@ ShellCommandResult TestObserverProxy::ExecuteShellCommand( return result; } - if (!data.WriteInt64(timeoutMs)) { - HILOG_ERROR("Failed to write timeoutMs"); + if (!data.WriteInt64(timeoutSec)) { + HILOG_ERROR("Failed to write timeoutSec"); return result; } diff --git a/tools/aa/src/test_observer_stub.cpp b/tools/aa/src/test_observer_stub.cpp index 20b1908c922..fd783d34ee1 100644 --- a/tools/aa/src/test_observer_stub.cpp +++ b/tools/aa/src/test_observer_stub.cpp @@ -49,8 +49,8 @@ int TestObserverStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messag } case static_cast(ITestObserver::Message::AA_EXECUTE_SHELL_COMMAND): { std::string cmd = data.ReadString(); - int64_t timeoutMs = data.ReadInt64(); - ShellCommandResult result = ExecuteShellCommand(cmd, timeoutMs); + int64_t timeoutSecs = data.ReadInt64(); + ShellCommandResult result = ExecuteShellCommand(cmd, timeoutSecs); if (!reply.WriteParcelable(&result)) { HILOG_ERROR("Failed to write reply ShellCommandResult!"); return ERR_INVALID_VALUE; diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 6e99eac731d..e900d080e28 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -85,11 +85,10 @@ public: MOCK_METHOD1(RemoveMission, int(int id)); MOCK_METHOD1(RemoveStack, int(int id)); MOCK_METHOD1(KillProcess, int(const std::string &bundleName)); - MOCK_METHOD1(UninstallApp, int(const std::string &bundleName)); + MOCK_METHOD2(UninstallApp, int(const std::string &bundleName, int32_t uid)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr &token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr &token)); - MOCK_METHOD4(CompelVerifyPermission, int(const std::string &permission, int pid, int uid, std::string &message)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo &wantSenderInfo, const sptr &callerToken)); MOCK_METHOD2(SendWantSender, int(const sptr &target, const SenderInfo &senderInfo)); @@ -117,6 +116,7 @@ public: ChangeFocusAbility, int(const sptr &lostFocusToken, const sptr &getFocusToken)); MOCK_METHOD1(MinimizeMultiWindow, int(int missionId)); MOCK_METHOD1(MaximizeMultiWindow, int(int missionId)); + MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); MOCK_METHOD1(GetFloatingMissions, int(std::vector &list)); MOCK_METHOD1(CloseMultiWindow, int(int missionId)); MOCK_METHOD1(SetMissionStackSetting, int(const StackSetting &stackSetting)); diff --git a/tools/test/moduletest/aa/BUILD.gn b/tools/test/moduletest/aa/BUILD.gn index 5d9ed8f0f1b..da4b3291b1f 100644 --- a/tools/test/moduletest/aa/BUILD.gn +++ b/tools/test/moduletest/aa/BUILD.gn @@ -136,7 +136,8 @@ group("moduletest") { deps = [ ":aa_command_dump_module_test", - ":aa_command_dumpsys_module_test", + + # ":aa_command_dumpsys_module_test", ":aa_command_start_module_test", ":aa_command_stop_service_module_test", ] diff --git a/zidl/test/native/src/test_client.cpp b/zidl/test/native/src/test_client.cpp index b732b598ba2..d2670709a25 100644 --- a/zidl/test/native/src/test_client.cpp +++ b/zidl/test/native/src/test_client.cpp @@ -31,7 +31,6 @@ int TestClient::ConnectService() } sptr object = saMgr->GetSystemAbility(IPC_TEST_SERVICE); - if (object != nullptr) { ZLOGE(LABEL, "Got test Service object"); testService_ = (new (std::nothrow) ZidlTestServiceProxy(object)); -- Gitee