diff --git a/common/BUILD.gn b/common/BUILD.gn index 5eb2ebcf5957b55b6d78a86d4bc852dd34c8609c..9a201da31568af6c0a68481ee193fc913b68c449 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -29,7 +29,6 @@ ohos_shared_library("distributed_screen_utils") { "src/dscreen_hisysevent.cpp", "src/dscreen_json_util.cpp", "src/dscreen_log.cpp", - "src/dscreen_sa_process_state.cpp", "src/dscreen_util.cpp", ] diff --git a/common/include/dscreen_sa_process_state.h b/common/include/dscreen_sa_process_state.h deleted file mode 100644 index 95e560cc74503b0212bf86bb25b2ccf53ecc8cde..0000000000000000000000000000000000000000 --- a/common/include/dscreen_sa_process_state.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 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 - * - * 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 DSCREEN_SA_PROCESS_STATE_H -#define DSCREEN_SA_PROCESS_STATE_H - -namespace OHOS { -namespace DistributedHardware { -void SetSinkProcessExit(); -void SetSourceProcessExit(); -} // namespace DistributedHardware -} // namespace OHOS -#endif // DSCREEN_SA_PROCESS_STATE_H diff --git a/common/src/dscreen_sa_process_state.cpp b/common/src/dscreen_sa_process_state.cpp deleted file mode 100644 index e0377fce69dcf37bd6effe9c8d9e1b7ab5c5ec11..0000000000000000000000000000000000000000 --- a/common/src/dscreen_sa_process_state.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 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 - * - * 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 "dscreen_sa_process_state.h" - -#include -#include -#include - -#include "dscreen_constants.h" -#include "dscreen_hisysevent.h" -#include "dscreen_log.h" - -namespace OHOS { -namespace DistributedHardware { -enum DScreenSAState : uint32_t { - DSCREEN_SA_EXIT_STATE_START = 0, - DSCREEN_SA_EXIT_STATE_STOP = 1 -}; -DScreenSAState g_sinkSAState = DSCREEN_SA_EXIT_STATE_START; -DScreenSAState g_sourceSAState = DSCREEN_SA_EXIT_STATE_START; -std::mutex g_saProcessState; - -void SetSinkProcessExit() -{ - DHLOGI("set sink process exit."); - std::lock_guard autoLock(g_saProcessState); - g_sinkSAState = DSCREEN_SA_EXIT_STATE_STOP; - DHLOGI("g_sourceSAState = %" PRId32 ", g_sinkSAState = %" PRId32, g_sourceSAState, g_sinkSAState); - if (g_sourceSAState == DSCREEN_SA_EXIT_STATE_START || g_sinkSAState == DSCREEN_SA_EXIT_STATE_START) { - return; - } - DHLOGI("exit sa process success."); - ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, "dscreen sink sa exit success."); - _Exit(0); -} - -void SetSourceProcessExit() -{ - DHLOGI("set sources process exit."); - std::lock_guard autoLock(g_saProcessState); - g_sourceSAState = DSCREEN_SA_EXIT_STATE_STOP; - DHLOGI("g_sourceSAState = %" PRId32 ", g_sinkSAState = %" PRId32, g_sourceSAState, g_sinkSAState); - if (g_sourceSAState == DSCREEN_SA_EXIT_STATE_START || g_sinkSAState == DSCREEN_SA_EXIT_STATE_START) { - return; - } - DHLOGI("exit sa process success."); - ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, "dscreen source sa exit success."); - _Exit(0); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/common/test/unittest/BUILD.gn b/common/test/unittest/BUILD.gn index b755584924b372d6ae4ac86b2de60bf4d348e252..033dd19f2d1addb108d143d726fed4ca0afdf593 100644 --- a/common/test/unittest/BUILD.gn +++ b/common/test/unittest/BUILD.gn @@ -34,7 +34,6 @@ ohos_unittest("ScreenCommonTest") { sources = [ "${common_path}/src/dscreen_hisysevent.cpp", "${common_path}/src/dscreen_log.cpp", - "${common_path}/src/dscreen_sa_process_state.cpp", "${common_path}/src/dscreen_util.cpp", "${common_path}/test/unittest/src/screen_common_test.cpp", ] diff --git a/common/test/unittest/src/screen_common_test.cpp b/common/test/unittest/src/screen_common_test.cpp index bbb50342cf98c44b719155f6b3d0847b7658cc46..2a01870b91b4273bb81cc3c9eabb5573592661fc 100644 --- a/common/test/unittest/src/screen_common_test.cpp +++ b/common/test/unittest/src/screen_common_test.cpp @@ -16,7 +16,6 @@ #include "dscreen_errcode.h" #include "dscreen_hisysevent.h" -#include "dscreen_sa_process_state.h" #include "dscreen_log.h" #include "dscreen_util.h" using namespace testing::ext; @@ -40,7 +39,6 @@ void ScreenCommonTest::TearDown() {} HWTEST_F(ScreenCommonTest, common_001, TestSize.Level1) { DHLOGW("common_001."); - SetSourceProcessExit(); std::string networkId = "networkId"; int32_t ret = GetLocalDeviceNetworkId(networkId); EXPECT_NE(DH_SUCCESS, ret); diff --git a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp index ed2e0d6ac8d7329d4d0faf8df546e19d2dd34b2e..830e1553ba91e1f54f6057b02445a8add31d14af 100644 --- a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp +++ b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp @@ -25,7 +25,6 @@ #include "dscreen_constants.h" #include "dscreen_errcode.h" #include "dscreen_log.h" -#include "dscreen_sa_process_state.h" #include "dscreen_util.h" namespace OHOS { @@ -80,7 +79,17 @@ int32_t DScreenSinkService::ReleaseSink() DHLOGI("ReleaseSink"); ScreenRegionManager::GetInstance().ReleaseAllRegions(); DHLOGI("exit sink sa process"); - SetSinkProcessExit(); + auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityMgr == nullptr) { + DHLOGE("systemAbilityMgr is null"); + return DSCREEN_INIT_ERR; + } + int32_t ret = systemAbilityMgr->UnloadSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID); + if (ret != DH_SUCCESS) { + DHLOGE("sink systemAbilityMgr UnLoadSystemAbility failed, ret: %" PRId32, ret); + return DSCREEN_BAD_VALUE; + } + DHLOGI("sink systemAbilityMgr UnLoadSystemAbility success"); return DH_SUCCESS; } diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp index 2b7528f5fd46b2f902d648c43507163b55104a1d..421c4aedbf1e86821f0bff5f5b4e3488e6455bc9 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp @@ -199,6 +199,10 @@ void DScreen::HandleEnable(const std::string ¶m, const std::string &taskId) } json attrJson = json::parse(param, nullptr, false); + if (attrJson.is_discarded()) { + DHLOGE("HandleEnable attrJson is invalid"); + return; + } int32_t ret = CheckJsonData(attrJson); if (ret != DH_SUCCESS) { DHLOGE("check json data failed."); diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index 80ac3caaf7700afff49f4ad3d05c69c7f777030c..0ff9d570cbe96d626b6695fe9c5ec5f4ef7ef1bb 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -26,7 +26,6 @@ #include "dscreen_errcode.h" #include "dscreen_hisysevent.h" #include "dscreen_log.h" -#include "dscreen_sa_process_state.h" #include "dscreen_util.h" namespace OHOS { @@ -95,7 +94,17 @@ int32_t DScreenSourceService::ReleaseSource() return ret; } DHLOGI("exit source sa process"); - SetSourceProcessExit(); + auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityMgr == nullptr) { + DHLOGE("systemAbilityMgr is null"); + return DSCREEN_INIT_ERR; + } + ret = systemAbilityMgr->UnloadSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID); + if (ret != DH_SUCCESS) { + DHLOGE("source systemAbilityMgr UnLoadSystemAbility failed, ret: %" PRId32, ret); + return DSCREEN_BAD_VALUE; + } + DHLOGI("source systemAbilityMgr UnLoadSystemAbility success"); return DH_SUCCESS; }