!848 [新需求]:点击接续图标后应用能够立即启动

Merge pull request !848 from liuhongjie/master_0416_1613
This commit is contained in:
openharmony_ci 2024-04-17 07:43:44 +00:00 committed by Gitee
commit dc0de73dce
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 347 additions and 3 deletions

View File

@ -95,6 +95,7 @@ ohos_shared_library("distributedschedsvr") {
"src/continue/state/source_state/dsched_continue_source_end_state.cpp",
"src/continue/state/source_state/dsched_continue_source_start_state.cpp",
"src/continue/state/source_state/dsched_continue_source_wait_end_state.cpp",
"src/continue_scene_session_handler.cpp",
"src/datashare_manager.cpp",
"src/deviceManager/dms_device_info.cpp",
"src/dfx/dms_continue_time_dumper.cpp",
@ -171,6 +172,8 @@ ohos_shared_library("distributedschedsvr") {
"kv_store:distributeddata_inner",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"window_manager:scene_session",
"window_manager:session_manager_lite",
]
if (os_account_part) {
external_deps += [ "os_account:os_account_innerkits" ]

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2024 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 OHOS_DISTRIBUTED_CONTINUE_SCENE_SESSION_HANDLER_H
#define OHOS_DISTRIBUTED_CONTINUE_SCENE_SESSION_HANDLER_H
#include <string>
#include "single_instance.h"
namespace OHOS {
namespace DistributedSchedule {
class ContinueSceneSessionHandler {
public:
DECLARE_SINGLE_INSTANCE_BASE(ContinueSceneSessionHandler);
public:
ContinueSceneSessionHandler() = default;
virtual ~ContinueSceneSessionHandler() = default;
void UpdateContinueSessionId(const std::string& bundleName, const std::string& abilityName);
std::string GetContinueSessionId() const;
void ClearContinueSessionId();
int32_t GetPersistentId(int32_t& persistentId);
private:
std::string continueSessionId_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_CONTINUE_SCENE_SESSION_HANDLER_H

View File

@ -125,7 +125,7 @@ enum class RecvUnfocused : int32_t {
enum class ClickIcon : int32_t {
DMS_CONTINUE = 4,
DMS_STARTABILITY = 5,
DMS_RECV_OVER = 8,
DMS_RECV_OVER = 10,
};
enum class SaveData : int32_t {

View File

@ -255,6 +255,7 @@ private:
void SetCleanMissionFlag(const OHOS::AAFwk::Want& want, int32_t missionId);
void RemoveConnectAbilityInfo(const std::string& deviceId);
ErrCode QueryOsAccount(int32_t& activeAccountId);
int32_t QuickStartAbility(const std::string& bundleName);
std::shared_ptr<DSchedContinuation> dschedContinuation_;
std::map<sptr<IRemoteObject>, std::list<ConnectAbilitySession>> distributedConnectAbilityMap_;

View File

@ -180,7 +180,7 @@ int32_t BundleManagerInternal::GetLocalBundleInfo(const std::string& bundleName,
if (err != ERR_OK) {
return err;
}
if (!bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT,
if (!bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES,
localBundleInfo, activeAccountId)) {
HILOGE("get local bundle info failed");
return INVALID_PARAMETERS_ERR;

View File

@ -0,0 +1,95 @@
/*
* Copyright (c) 2024 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 "continue_scene_session_handler.h"
#include <chrono>
#include <thread>
#include "dtbschedmgr_log.h"
#include "scene_board_judgement.h"
#include "session_manager_lite.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "ContinueSceneSessionHandler";
constexpr int32_t RETRY_TIMES = 2;
constexpr int32_t SLEEP_TIME = 50;
}
IMPLEMENT_SINGLE_INSTANCE(ContinueSceneSessionHandler);
using OHOS::Rosen::SessionManagerLite;
using OHOS::Rosen::WSError;
void ContinueSceneSessionHandler::UpdateContinueSessionId(const std::string& bundleName, const std::string& abilityName)
{
HILOGD("Update continueSessionId, bundleName: %{public}s, abilityName: %{public}s",
bundleName.c_str(), abilityName.c_str());
auto now = std::chrono::system_clock::now();
int64_t timeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
std::size_t hash = std::hash<std::string>()(bundleName + abilityName + std::to_string(timeStamp));
continueSessionId_ = std::to_string(hash);
}
std::string ContinueSceneSessionHandler::GetContinueSessionId() const
{
return continueSessionId_;
}
void ContinueSceneSessionHandler::ClearContinueSessionId()
{
HILOGI("%{public}s called", __func__);
continueSessionId_.clear();
}
int32_t ContinueSceneSessionHandler::GetPersistentId(int32_t& persistentId)
{
HILOGI("%{public}s called", __func__);
if (continueSessionId_.empty()) {
HILOGE("continueSessionId is empty.");
return INVALID_PARAMETERS_ERR;
}
if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
HILOGE("sceneBoard not available.");
return INVALID_PARAMETERS_ERR;
}
auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy();
if (!sceneSessionManager) {
HILOGE("proxy is nullptr.");
return INVALID_PARAMETERS_ERR;
}
int32_t retryTimeout = RETRY_TIMES;
AAFwk::MissionInfo missionInfo;
do {
auto err = sceneSessionManager->GetSessionInfoByContinueSessionId(continueSessionId_, missionInfo);
if (err == WSError::WS_OK) {
continueSessionId_.clear();
persistentId = missionInfo.id;
return ERR_OK;
}
HILOGE("Get sessionInfo failed, continueSessionId: %{public}s, errorCode: %{public}d",
continueSessionId_.c_str(), err);
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
} while (--retryTimeout >= 0);
continueSessionId_.clear();
return INVALID_PARAMETERS_ERR;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -42,6 +42,7 @@
#include "adapter/dnetwork_adapter.h"
#include "bundle/bundle_manager_internal.h"
#include "connect_death_recipient.h"
#include "continue_scene_session_handler.h"
#include "dfx/dms_continue_time_dumper.h"
#include "distributed_radar.h"
#include "distributed_sched_adapter.h"
@ -55,6 +56,7 @@
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "parcel_helper.h"
#include "scene_board_judgement.h"
#include "switch_status_dependency.h"
#ifdef SUPPORT_COMMON_EVENT_SERVICE
#include "common_event_listener.h"
@ -100,6 +102,8 @@ const std::string SUPPORT_CONTINUE_SOURCE_EXIT_KEY = "ohos.extra.param.key.suppo
const std::string SUPPORT_CONTINUE_MODULE_NAME_UPDATE_KEY = "ohos.extra.param.key.supportContinueModuleNameUpdate";
const std::string DSCHED_EVENT_KEY = "IDSchedEventListener";
const std::string DMSDURATION_SAVETIME = "ohos.dschedule.SaveDataTime";
const std::string DMS_CONTINUE_SESSION_ID = "ohos.dms.continueSessionId";
const std::string DMS_PERSISTENT_ID = "ohos.dms.persistentId";
constexpr int32_t DEFAULT_DMS_MISSION_ID = -1;
constexpr int32_t DEFAULT_DMS_CONNECT_TOKEN = -1;
constexpr int32_t BIND_CONNECT_RETRY_TIMES = 3;
@ -329,7 +333,15 @@ int32_t DistributedSchedService::StartAbilityFromRemote(const OHOS::AAFwk::Want&
HILOGE("CheckTargetPermission failed!!");
return result;
}
return StartAbility(want, requestCode);
int32_t persistentId;
AAFwk::Want newWant = want;
int32_t err = ContinueSceneSessionHandler::GetInstance().GetPersistentId(persistentId);
if (err == ERR_OK) {
HILOGI("get persistentId success, persistentId: %{public}d", persistentId);
newWant.SetParam(DMS_PERSISTENT_ID, persistentId);
}
return StartAbility(newWant, requestCode);
}
int32_t DistributedSchedService::SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode,
@ -535,6 +547,8 @@ int32_t DistributedSchedService::ContinueRemoteMission(const std::string& srcDev
DmsContinueTime::GetInstance().SetDurationBegin(DMSDURATION_DSTTOSRCRPCTIME, begin);
DmsContinueTime::GetInstance().SetDurationBegin(DMSDURATION_TOTALTIME, begin);
}
QuickStartAbility(bundleName);
sptr<IDistributedSched> remoteDms = GetRemoteDms(srcDeviceId);
if (remoteDms == nullptr) {
HILOGE("get remote dms null!");
@ -542,6 +556,7 @@ int32_t DistributedSchedService::ContinueRemoteMission(const std::string& srcDev
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
ContinueSceneSessionHandler::GetInstance().ClearContinueSessionId();
int32_t dSchedEventresult = dschedContinuation_->NotifyDSchedEventResult(DSCHED_EVENT_KEY,
INVALID_REMOTE_PARAMETERS_ERR);
HILOGD("NotifyDSchedEventResult result:%{public}d", dSchedEventresult);
@ -559,12 +574,43 @@ int32_t DistributedSchedService::ContinueRemoteMission(const std::string& srcDev
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
ContinueSceneSessionHandler::GetInstance().ClearContinueSessionId();
int32_t dSchedEventresult = dschedContinuation_->NotifyDSchedEventResult(DSCHED_EVENT_KEY, result);
HILOGD("NotifyDSchedEventResult result:%{public}d", dSchedEventresult);
}
return result;
}
int32_t DistributedSchedService::QuickStartAbility(const std::string& bundleName)
{
HILOGI("%{public}s called", __func__);
if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
HILOGE("sceneBoard not available.");
return INVALID_PARAMETERS_ERR;
}
BundleInfo localBundleInfo;
if (BundleManagerInternal::GetLocalBundleInfo(bundleName, localBundleInfo) != ERR_OK) {
HILOGE("get local bundle info failed.");
return INVALID_PARAMETERS_ERR;
}
if (localBundleInfo.abilityInfos.empty() || localBundleInfo.abilityInfos.size() > 1) {
HILOGE("quick start is not supported, abilityInfos size: %{public}d",
static_cast<int32_t>(localBundleInfo.abilityInfos.size()));
return INVALID_PARAMETERS_ERR;
}
auto abilityInfo = localBundleInfo.abilityInfos.front();
ContinueSceneSessionHandler::GetInstance().UpdateContinueSessionId(bundleName, abilityInfo.name);
std::string continueSessionId = ContinueSceneSessionHandler::GetInstance().GetContinueSessionId();
HILOGI("continueSessionId is %{public}s", continueSessionId.c_str());
AAFwk::Want want;
want.SetElementName(bundleName, abilityInfo.name);
want.SetParam(DMS_CONTINUE_SESSION_ID, continueSessionId);
return StartAbility(want, DEFAULT_REQUEST_CODE);
}
int32_t DistributedSchedService::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
{

View File

@ -65,6 +65,8 @@ dsched_external_deps = [
"kv_store:distributeddata_inner",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"window_manager:scene_session",
"window_manager:session_manager_lite",
]
if (os_account_part) {
dsched_external_deps += [ "os_account:os_account_innerkits" ]
@ -112,6 +114,7 @@ dtbschedmgr_sources = [
"${distributed_service}/dtbschedmgr/src/bundle/bundle_manager_callback_stub.cpp",
"${distributed_service}/dtbschedmgr/src/bundle/bundle_manager_internal.cpp",
"${distributed_service}/dtbschedmgr/src/connect_death_recipient.cpp",
"${distributed_service}/dtbschedmgr/src/continue_scene_session_handler.cpp",
"${distributed_service}/dtbschedmgr/src/datashare_manager.cpp",
"${distributed_service}/dtbschedmgr/src/deviceManager/dms_device_info.cpp",
"${distributed_service}/dtbschedmgr/src/dfx/dms_continue_time_dumper.cpp",
@ -197,6 +200,7 @@ ohos_unittest("distributedschedsvrtest") {
]
sources = [
"unittest/continue_scene_session_handler_test.cpp",
"unittest/distributed_radar_test.cpp",
"unittest/distributed_sched_adapter_test.cpp",
"unittest/distributed_sched_dumper_test.cpp",

View File

@ -0,0 +1,108 @@
/*
* Copyright (c) 2024 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 "continue_scene_session_handler_test.h"
#include "dtbschedmgr_log.h"
#include "test_log.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace DistributedSchedule {
void ContinueSceneSessionHandlerTest::SetUpTestCase()
{
DTEST_LOG << "ContinueSceneSessionHandlerTest::SetUpTestCase" << std::endl;
}
void ContinueSceneSessionHandlerTest::TearDownTestCase()
{
DTEST_LOG << "ContinueSceneSessionHandlerTest::TearDownTestCase" << std::endl;
}
void ContinueSceneSessionHandlerTest::TearDown()
{
DTEST_LOG << "ContinueSceneSessionHandlerTest::TearDown" << std::endl;
}
void ContinueSceneSessionHandlerTest::SetUp()
{
DTEST_LOG << "ContinueSceneSessionHandlerTest::SetUp" << std::endl;
}
/**
* @tc.name: UpdateContinueSessionId_001
* @tc.desc: generated continueSessionId by bundleName and abilityName
* @tc.type: FUNC
* @tc.require: SR20240116512594
*/
HWTEST_F(ContinueSceneSessionHandlerTest, UpdateContinueSessionId_001, TestSize.Level3)
{
DTEST_LOG << "ContinueSceneSessionHandlerTest UpdateContinueSessionId_001 begin" << std::endl;
std::string bundleName = "ohos.dms.bundleName_001";
std::string abilityName = "ohos.dms.abilityName_001";
ContinueSceneSessionHandler::GetInstance().UpdateContinueSessionId(bundleName, abilityName);
std::string continueSessionId = ContinueSceneSessionHandler::GetInstance().GetContinueSessionId();
EXPECT_FALSE(continueSessionId.empty());
DTEST_LOG << "ContinueSceneSessionHandlerTest UpdateContinueSessionId_001 end" << std::endl;
}
/**
* @tc.name: GetContinueSessionId_001
* @tc.desc: get continueSessionId test
* @tc.type: FUNC
* @tc.require: SR20240116512594
*/
HWTEST_F(ContinueSceneSessionHandlerTest, GetContinueSessionId_001, TestSize.Level3)
{
DTEST_LOG << "ContinueSceneSessionHandlerTest GetContinueSessionId_001 begin" << std::endl;
std::string continueSessionId = ContinueSceneSessionHandler::GetInstance().GetContinueSessionId();
EXPECT_FALSE(continueSessionId.empty());
DTEST_LOG << "ContinueSceneSessionHandlerTest GetContinueSessionId_001 end" << std::endl;
}
/**
* @tc.name: GetPersistentId_001
* @tc.desc: get persistentId by continueSessionId
* @tc.type: FUNC
* @tc.require: SR20240116512594
*/
HWTEST_F(ContinueSceneSessionHandlerTest, GetPersistentId_001, TestSize.Level3)
{
DTEST_LOG << "ContinueSceneSessionHandlerTest GetPersistentId_001 begin" << std::endl;
int32_t persistentId;
int32_t err = ContinueSceneSessionHandler::GetInstance().GetPersistentId(persistentId);
EXPECT_EQ(static_cast<int32_t>(INVALID_PARAMETERS_ERR), err);
DTEST_LOG << "ContinueSceneSessionHandlerTest GetPersistentId_001 end" << std::endl;
}
/**
* @tc.name: ClearContinueSessionId_001
* @tc.desc: clear continueSessionId test
* @tc.type: FUNC
* @tc.require: SR20240116512594
*/
HWTEST_F(ContinueSceneSessionHandlerTest, ClearContinueSessionId_001, TestSize.Level3)
{
DTEST_LOG << "ContinueSceneSessionHandlerTest ClearContinueSessionId_001 begin" << std::endl;
ContinueSceneSessionHandler::GetInstance().ClearContinueSessionId();
std::string continueSessionId = ContinueSceneSessionHandler::GetInstance().GetContinueSessionId();
EXPECT_TRUE(continueSessionId.empty());
DTEST_LOG << "ContinueSceneSessionHandlerTest ClearContinueSessionId_001 end" << std::endl;
}
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 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 ABILITY_CONTINUE_SESSION_TEST_H
#define ABILITY_CONTINUE_SESSION_TEST_H
#include <gtest/gtest.h>
#include "continue_scene_session_handler.h"
namespace OHOS {
namespace DistributedSchedule {
class ContinueSceneSessionHandlerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // ABILITY_CONTINUE_SESSION_TEST_H

View File

@ -1430,5 +1430,18 @@ HWTEST_F(DistributedSchedServiceSecondTest, ContinueMissionBundleName_002, TestS
EXPECT_EQ(static_cast<int>(OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET), result);
DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_002 end" << std::endl;
}
/**
* @tc.name: QuickStartAbility_001
* @tc.desc: quick start ability test
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedServiceSecondTest, QuickStartAbility_001, TestSize.Level3)
{
DTEST_LOG << "DSchedContinuationTest QuickStartAbility_001 start" << std::endl;
auto ret = DistributedSchedService::GetInstance().QuickStartAbility("bundleName");
EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
DTEST_LOG << "DSchedContinuationTest QuickStartAbility_001 end" << std::endl;
}
}
}