mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 22:39:58 +00:00
!827 continue switch change active
Merge pull request !827 from 仝月姣/master
This commit is contained in:
commit
1563e0890d
@ -32,6 +32,7 @@ ohos_shared_library("distributed_sched_utils") {
|
||||
deps = []
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:ability_manager",
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"config_policy:configpolicy_util",
|
||||
|
@ -20,10 +20,13 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
constexpr static int32_t INVALID_MISSION_ID = -1;
|
||||
|
||||
bool IsValidPath(const std::string &inFilePath, std::string &realFilePath);
|
||||
bool UpdateAllowAppList(const std::string &cfgJsonStr);
|
||||
int32_t LoadContinueConfig();
|
||||
bool CheckBundleContinueConfig(const std::string &bundleName);
|
||||
int32_t GetCurrentMissionId();
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_SERVICE_H
|
@ -23,6 +23,7 @@
|
||||
#include <vector>
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "config_policy_utils.h"
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
@ -170,5 +171,19 @@ bool CheckBundleContinueConfig(const std::string &bundleName)
|
||||
bundleName.c_str(), g_continueCfgFullPath.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t GetCurrentMissionId()
|
||||
{
|
||||
HILOGI("GetCurrentMission begin");
|
||||
sptr<IRemoteObject> token;
|
||||
int ret = AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility(token);
|
||||
if (ret != ERR_OK || token == nullptr) {
|
||||
HILOGE("GetTopAbility failed, ret: %{public}d", ret);
|
||||
return INVALID_MISSION_ID;
|
||||
}
|
||||
int32_t missionId = INVALID_MISSION_ID;
|
||||
AAFwk::AbilityManagerClient::GetInstance()->GetMissionIdByToken(token, missionId);
|
||||
return missionId;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -68,6 +68,7 @@ public:
|
||||
void NotifyDied(const sptr<IRemoteObject>& obj);
|
||||
void NotifyDeviceOffline(const std::string& networkId);
|
||||
void OnDeviceScreenOff();
|
||||
void OnContinueSwitchOff();
|
||||
|
||||
private:
|
||||
void StartEvent();
|
||||
|
@ -14,7 +14,11 @@
|
||||
*/
|
||||
|
||||
#include "datashare_manager.h"
|
||||
|
||||
#include "distributed_sched_utils.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/dms_continue_recv_manager.h"
|
||||
#include "mission/dms_continue_send_manager.h"
|
||||
#include "switch_status_dependency.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -68,6 +72,18 @@ void DataShareRegisterObserver::OnChange(const ChangeInfo &changeInfo)
|
||||
HILOGI("DataShareRegisterObserver OnChange start");
|
||||
bool IsContinueSwitchOn = SwitchStatusDependency::GetInstance().IsContinueSwitchOn();
|
||||
HILOGI("IsContinueSwitchOn : %{public}d", IsContinueSwitchOn);
|
||||
int32_t missionId = GetCurrentMissionId();
|
||||
if (missionId <= 0) {
|
||||
HILOGW("GetCurrentMissionId failed, init end. ret: %{public}d", missionId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsContinueSwitchOn) {
|
||||
DMSContinueSendMgr::GetInstance().NotifyMissionFocused(missionId, FocusedReason::INIT);
|
||||
} else {
|
||||
DMSContinueSendMgr::GetInstance().NotifyMissionUnfocused(missionId, UnfocusedReason::NORMAL);
|
||||
DMSContinueRecvMgr::GetInstance().OnContinueSwitchOff();
|
||||
}
|
||||
HILOGI("DataShareRegisterObserver OnChange done");
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
|
@ -378,6 +378,44 @@ void DMSContinueRecvMgr::OnDeviceScreenOff()
|
||||
}
|
||||
#endif
|
||||
|
||||
void DMSContinueRecvMgr::OnContinueSwitchOff()
|
||||
{
|
||||
auto func = [this]() {
|
||||
std::string senderNetworkId;
|
||||
std::string bundleName;
|
||||
{
|
||||
std::lock_guard<std::mutex> currentIconLock(iconMutex_);
|
||||
if (iconInfo_.isEmpty()) {
|
||||
HILOGW("Saved iconInfo has already been cleared, task abort.");
|
||||
return;
|
||||
}
|
||||
senderNetworkId = iconInfo_.senderNetworkId;
|
||||
bundleName = iconInfo_.bundleName;
|
||||
iconInfo_.senderNetworkId = "";
|
||||
iconInfo_.bundleName = "";
|
||||
}
|
||||
HILOGI("Saved iconInfo cleared, networkId = %{public}s, bundleName = %{public}s",
|
||||
DnetworkAdapter::AnonymizeNetworkId(senderNetworkId).c_str(), bundleName.c_str());
|
||||
{
|
||||
std::lock_guard<std::mutex> registerOnListenerMapLock(eventMutex_);
|
||||
auto iterItem = registerOnListener_.find(onType_);
|
||||
if (iterItem == registerOnListener_.end()) {
|
||||
HILOGI("Get iterItem failed from registerOnListener_, nobody registed");
|
||||
return;
|
||||
}
|
||||
std::vector<sptr<IRemoteObject>> objs = iterItem->second;
|
||||
for (auto iter : objs) {
|
||||
NotifyRecvBroadcast(iter, senderNetworkId, bundleName, INACTIVE);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (eventHandler_ == nullptr) {
|
||||
HILOGE("eventHandler_ is nullptr");
|
||||
return;
|
||||
}
|
||||
eventHandler_->PostTask(func);
|
||||
}
|
||||
|
||||
void DMSContinueRecvMgr::NotifyDeviceOffline(const std::string& networkId)
|
||||
{
|
||||
if (networkId.empty()) {
|
||||
|
@ -72,8 +72,8 @@ void DMSContinueSendMgr::Init()
|
||||
return;
|
||||
}
|
||||
DmsRadar::GetInstance().DmsFocused("Init", INIT);
|
||||
NotifyMissionFocused(missionId, FocusedReason::INIT);
|
||||
DataShareManager::GetInstance().RegisterObserver(SETTINGS_DATA_URI);
|
||||
NotifyMissionFocused(missionId, FocusedReason::INIT);
|
||||
HILOGI("Init end");
|
||||
}
|
||||
|
||||
@ -373,6 +373,11 @@ int32_t DMSContinueSendMgr::SendScreenOffEvent(uint8_t type)
|
||||
|
||||
HILOGI("start, type: %{public}d, missionId: %{public}d, bundleName: %{public}s, accessTokenId: %{public}u",
|
||||
type, missionId, bundleName.c_str(), accessTokenId);
|
||||
if (!CheckBundleContinueConfig(bundleName)) {
|
||||
HILOGI("App does not allow continue in config file, bundle name %{public}s, missionId: %{public}d",
|
||||
bundleName.c_str(), missionId);
|
||||
return REMOTE_DEVICE_BIND_ABILITY_ERR;
|
||||
}
|
||||
|
||||
bool IsContinueSwitchOn = SwitchStatusDependency::GetInstance().IsContinueSwitchOn();
|
||||
HILOGI("IsContinueSwitchOn : %{public}d", IsContinueSwitchOn);
|
||||
|
Loading…
Reference in New Issue
Block a user