mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2025-02-21 15:01:20 +00:00
add continue switch
Signed-off-by: dengxiaoyu <dengxiaoyu6@huawei.com>
This commit is contained in:
parent
9609092176
commit
5db8cb044f
@ -124,6 +124,8 @@ ohos_shared_library("distributedschedsvr") {
|
||||
"src/softbus_adapter/transport/dsched_data_buffer.cpp",
|
||||
"src/softbus_adapter/transport/dsched_softbus_session.cpp",
|
||||
"src/softbus_adapter/transport/dsched_transport_softbus_adapter.cpp",
|
||||
"src/switch_status_dependency.cpp",
|
||||
"src/datashare_manager.cpp",
|
||||
]
|
||||
|
||||
if (!dmsfwk_softbus_adapter_common) {
|
||||
@ -168,6 +170,7 @@ ohos_shared_library("distributedschedsvr") {
|
||||
"kv_store:distributeddata_inner",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"data_share:datashare_consumer",
|
||||
]
|
||||
if (os_account_part) {
|
||||
external_deps += [ "os_account:os_account_innerkits" ]
|
||||
|
54
services/dtbschedmgr/include/datashare_manager.h
Normal file
54
services/dtbschedmgr/include/datashare_manager.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 DMS_DATASHARE_MANAGER_H
|
||||
#define DMS_DATASHARE_MANAGER_H
|
||||
|
||||
#include <shared_mutex>
|
||||
#include "datashare_helper.h"
|
||||
|
||||
namespace OHOS{
|
||||
namespace DistributedSchedule{
|
||||
using ChangeInfo = DataShare::DataShareObserver::ChangeInfo;
|
||||
const std::string SETTINGS_DATA_URI =
|
||||
"datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=Continue_Switch_Status";
|
||||
|
||||
class DataShareManager {
|
||||
public:
|
||||
static DataShareManager &GetInstance();
|
||||
std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
|
||||
bool IsCreateDataShareHelper(const std::string &datashareUri);
|
||||
void RegisterObserver(const std::string &datashareUri);
|
||||
|
||||
private:
|
||||
DataShareManager() = default;
|
||||
~DataShareManager() = default;
|
||||
DISALLOW_COPY_AND_MOVE(DataShareManager);
|
||||
|
||||
static DataShareManager instance_;
|
||||
std::shared_ptr<DataShare::DataShareHelper> helper_;
|
||||
std::string datashareUri_;
|
||||
};
|
||||
|
||||
class DataShareRegisterObserver : public DataShare::DataShareObserver{
|
||||
public:
|
||||
DataShareRegisterObserver(){}
|
||||
~DataShareRegisterObserver(){}
|
||||
void OnChange(const ChangeInfo &changeInfo) override;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DMS_DATASHARE_MANAGER_H
|
49
services/dtbschedmgr/include/switch_status_dependency.h
Normal file
49
services/dtbschedmgr/include/switch_status_dependency.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 DMS_SWITCH_STATUS_DEPENDENCY_H
|
||||
#define DMS_SWITCH_STATUS_DEPENDENCY_H
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include "json/json.h"
|
||||
#include "datashare_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule{
|
||||
|
||||
class SwitchStatusDependency {
|
||||
public:
|
||||
static SwitchStatusDependency &GetInstance();
|
||||
bool IsContinueSwitchOn();
|
||||
|
||||
private:
|
||||
std::string GetSwitchStatus(const std::string &key, const std::string &defaultValue);
|
||||
std::shared_ptr<DataShare::DataShareHelper> GetDataShareHelper();
|
||||
std::mutex dataShareMutex_;
|
||||
const std::string SETTINGS_DATA_URI_PREFIX =
|
||||
"datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true";
|
||||
const std::string SETTINGS_DATA_FIELD_KEY = "KEYWORD";
|
||||
const std::string SETTINGS_DATA_FIELD_VAL = "VALUE";
|
||||
const std::string CONTINUE_SWITCH_STATUS_KEY = "Continue_Switch_Status";
|
||||
const std::string CONTINUE_SWITCH_OFF = "continue_switch_off";
|
||||
const std::string CONTINUE_SWITCH_ON = "continue_switch_on";
|
||||
std::string switchStatus_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DMS_SWITCH_STATUS_DEPENDENCY_H
|
74
services/dtbschedmgr/src/datashare_manager.cpp
Normal file
74
services/dtbschedmgr/src/datashare_manager.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 "datashare_manager.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "switch_status_dependency.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "DMSDataShareManager";
|
||||
}
|
||||
|
||||
DataShareManager DataShareManager::instance_;
|
||||
DataShareManager &DataShareManager::GetInstance()
|
||||
{
|
||||
return instance_;
|
||||
}
|
||||
|
||||
std::shared_ptr<DataShare::DataShareHelper> DataShareManager::CreateDataShareHelper()
|
||||
{
|
||||
HILOGI("create DataShareHelper intance");
|
||||
DataShare::CreateOptions options;
|
||||
options.isProxy_ = true;
|
||||
datashareUri_ = SETTINGS_DATA_URI;
|
||||
helper_ = DataShare::DataShareHelper::Creator(datashareUri_, options);
|
||||
return helper_;
|
||||
}
|
||||
|
||||
bool DataShareManager::IsCreateDataShareHelper(const std::string &datashareUri)
|
||||
{
|
||||
HILOGI("DataShareManager IsCreateDataShareHelper start");
|
||||
if (CreateDataShareHelper() == nullptr){
|
||||
HILOGE("create helper failed for uri:%{public}s", datashareUri_.c_str());
|
||||
return false;
|
||||
}else {
|
||||
HILOGI("create new helper success for uri:%{public}s", datashareUri_.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void DataShareManager::RegisterObserver(const std::string &datashareUri)
|
||||
{
|
||||
HILOGI("DataShareManager RegisterObserver start");
|
||||
if (IsCreateDataShareHelper(datashareUri)){
|
||||
Uri uri(SETTINGS_DATA_URI);
|
||||
std::shared_ptr<DataShareRegisterObserver> dataObserver = std::make_shared<DataShareRegisterObserver>();
|
||||
helper_->RegisterObserverExt(uri, dataObserver, true);
|
||||
HILOGI("DataShareManager RegisterObserver uri:%{public}s success", datashareUri.c_str());
|
||||
}
|
||||
HILOGI("DataShareManager RegisterObserver done");
|
||||
}
|
||||
|
||||
void DataShareRegisterObserver::OnChange(const ChangeInfo &changeInfo)
|
||||
{
|
||||
HILOGI("DataShareRegisterObserver OnChange start");
|
||||
bool IsContinueSwitchOn = SwitchStatusDependency::GetInstance().IsContinueSwitchOn();
|
||||
HILOGI("IsContinueSwitchOn : %{public}s", IsContinueSwitchOn);
|
||||
HILOGI("DataShareRegisterObserver OnChange done");
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -431,6 +431,12 @@ int32_t DistributedSchedService::ContinueLocalMissionDealFreeInstall(OHOS::AAFwk
|
||||
int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDeviceId, int32_t missionId,
|
||||
const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
|
||||
{
|
||||
bool IsContinueSwitchOn = SwitchStatusDependency::GetInstance().IsContinueSwitchOn();
|
||||
HILOGI("IsContinueSwitchOn : %{public}s", IsContinueSwitchOn);
|
||||
if (!IsContinueSwitchOn) {
|
||||
HILOGE("continuation switch is off!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
if (dschedContinuation_ == nullptr) {
|
||||
HILOGE("continuation object null!");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "parcel_helper.h"
|
||||
#include "softbus_adapter/softbus_adapter.h"
|
||||
#include <sys/prctl.h>
|
||||
#include "switch_status_dependency.h"
|
||||
#include "datashare_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -60,6 +62,8 @@ void DMSContinueRecvMgr::Init()
|
||||
eventCon_.wait(lock, [this] {
|
||||
return eventHandler_ != nullptr;
|
||||
});
|
||||
|
||||
DataShareManager::GetInstance().RegisterObserver(SETTINGS_DATA_URI);
|
||||
}
|
||||
HILOGI("Init end");
|
||||
}
|
||||
@ -82,6 +86,12 @@ void DMSContinueRecvMgr::NotifyDataRecv(std::string& senderNetworkId,
|
||||
{
|
||||
HILOGI("NotifyDataRecv start, senderNetworkId: %{public}s, dataLen: %{public}u",
|
||||
DnetworkAdapter::AnonymizeNetworkId(senderNetworkId).c_str(), dataLen);
|
||||
bool IsContinueSwitchOn = SwitchStatusDependency::GetInstance().IsContinueSwitchOn();
|
||||
HILOGI("IsContinueSwitchOn : %{public}s", IsContinueSwitchOn);
|
||||
if (!IsContinueSwitchOn) {
|
||||
HILOGE("continuation switch is off!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
if (dataLen != DMS_SEND_LEN) {
|
||||
HILOGE("dataLen error, dataLen: %{public}u", dataLen);
|
||||
return;
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "parcel_helper.h"
|
||||
#include "softbus_adapter/softbus_adapter.h"
|
||||
#include "switch_status_dependency.h"
|
||||
#include "datashare_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -287,6 +289,12 @@ int32_t DMSContinueSendMgr::DealFocusedBusiness(const int32_t missionId)
|
||||
HILOGE("Get focused accessTokenId failed, accessTokenId: %{public}u, ret: %{public}d", accessTokenId, ret);
|
||||
return ret;
|
||||
}
|
||||
bool IsContinueSwitchOn = SwitchStatusDependency::GetInstance().IsContinueSwitchOn();
|
||||
HILOGI("IsContinueSwitchOn : %{public}s", IsContinueSwitchOn);
|
||||
if (!IsContinueSwitchOn) {
|
||||
HILOGE("continuation switch is off!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
HILOGI("Get focused accessTokenId success, accessTokenId: %{public}u", accessTokenId);
|
||||
ret = SendSoftbusEvent(accessTokenId, DMS_FOCUSED_TYPE);
|
||||
DmsRadar::GetInstance().NormalFocusedSendEventRes("SendSoftbusEvent", ret);
|
||||
@ -371,6 +379,13 @@ 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);
|
||||
|
||||
bool IsContinueSwitchOn = SwitchStatusDependency::GetInstance().IsContinueSwitchOn();
|
||||
HILOGI("IsContinueSwitchOn : %{public}s", IsContinueSwitchOn);
|
||||
if (!IsContinueSwitchOn) {
|
||||
HILOGE("continuation switch is off!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
int32_t ret = SendSoftbusEvent(accessTokenId, type);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("SendSoftbusEvent unfocused failed, ret: %{public}d", ret);
|
||||
@ -607,6 +622,13 @@ int32_t DMSContinueSendMgr::GetAccessTokenIdSendEvent(std::string bundleName,
|
||||
}
|
||||
|
||||
if (screenOffHandler_->IsDeviceScreenOn()) {
|
||||
bool IsContinueSwitchOn = SwitchStatusDependency::GetInstance().IsContinueSwitchOn();
|
||||
HILOGI("IsContinueSwitchOn : %{public}s", IsContinueSwitchOn);
|
||||
if (!IsContinueSwitchOn)
|
||||
{
|
||||
HILOGE("continuation switch is off!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
ret = SendSoftbusEvent(accessTokenId, DMS_UNFOCUSED_TYPE);
|
||||
bool res = (reason != UnfocusedReason::TIMEOUT)
|
||||
? DmsRadar::GetInstance().NormalUnfocusedSendEventRes("SendSoftbusEvent", ret)
|
||||
@ -631,6 +653,13 @@ int32_t DMSContinueSendMgr::SetStateSendEvent(const uint32_t accessTokenId, cons
|
||||
AddMMIListener();
|
||||
}
|
||||
|
||||
bool IsContinueSwitchOn = SwitchStatusDependency::GetInstance().IsContinueSwitchOn();
|
||||
HILOGI("IsContinueSwitchOn : %{public}s", IsContinueSwitchOn);
|
||||
if (!IsContinueSwitchOn) {
|
||||
HILOGE("continuation switch is off!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
uint8_t type = state == AAFwk::ContinueState::CONTINUESTATE_INACTIVE ? DMS_UNFOCUSED_TYPE : DMS_FOCUSED_TYPE;
|
||||
int32_t ret = SendSoftbusEvent(accessTokenId, type);
|
||||
bool res = (state == AAFwk::ContinueState::CONTINUESTATE_INACTIVE)
|
||||
|
101
services/dtbschedmgr/src/switch_status_dependency.cpp
Normal file
101
services/dtbschedmgr/src/switch_status_dependency.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 "switch_status_dependency.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "if_system_abilty_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "uri.h"
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "DMSSwitchStatusDep";
|
||||
const std::string SETTINGS_DATA_URI =
|
||||
"datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=Continue_Switch_Status";
|
||||
}
|
||||
SwitchStatusDependency &SwitchStatusDependency::GetInstance()
|
||||
{
|
||||
static SwitchStatusDependency instance;
|
||||
return instance;
|
||||
}
|
||||
bool SwitchStatusDependency::IsContinueSwitchOn()
|
||||
{
|
||||
HILOGI("IsContinueSwitchOn start");
|
||||
std::lock_guard<std::mutex> lock(dataShareMutex_);
|
||||
HILOGI("start query switch from dataShare");
|
||||
switchStatus_ = GetSwitchStatus(CONTINUE_SWITCH_STATUS_KEY, CONTINUE_SWITCH_ON);
|
||||
return switchStatus_ == CONTINUE_SWITCH_ON;
|
||||
}
|
||||
|
||||
std::string SwitchStatusDependency::GetSwitchStatus(const std::string &key, const std::string &defaultValue)
|
||||
{
|
||||
HILOGI("GetSwitchStatus start, key is %{public}s", key.c_str());
|
||||
std::shared_ptr<Datashare::DataShareHelper> dataShareHelper = GetDataShareHelper();
|
||||
if (dataShareHelper == nullptr) {
|
||||
HILOGE("dataShareHelper is null, key is %{public}s", key.c_str());
|
||||
return CONTINUE_SWITCH_OFF;
|
||||
}
|
||||
Uri uri = Uri(SETTINGS_DATA_URI);
|
||||
DataShare::DataSharePredicates dataSharePredicates;
|
||||
std::vector<std::string> columns;
|
||||
dataSharePredicates.EqualTo(SETTINGS_DATA_FILELD_KEY,key);
|
||||
columns.emplace_back(SETTINGS_DATA_FILELD_VAL);
|
||||
auto resultSet = dataShareHelper->Query(uri, dataSharePredicates, columns);
|
||||
if (result == nullptr) {
|
||||
HILOGE("get switch status, resultSet is nullptr with key is %{public}s", key.c_str());
|
||||
dataShareHelper->Release();
|
||||
return CONTINUE_SWITCH_OFF;
|
||||
}
|
||||
int32_t numRows = 0;
|
||||
resultSet->GetRowCount(numRows);
|
||||
if(numRows==0) {
|
||||
HILOGE("get switch status, resultSet is nullptr with key is %{public}s", key.c_str());
|
||||
resultSet->Close();
|
||||
dataShareHelper->Release();
|
||||
return CONTINUE_SWITCH_OFF;
|
||||
}
|
||||
int32_t columnIndex = 0;
|
||||
int32_t rowNumber = 0;
|
||||
resultSet->GoToRow(rowNumber);
|
||||
std::string valueResult;
|
||||
int32_t ret = resultSet->GetString(columnIndex,valueResult);
|
||||
if (ret != 0){
|
||||
HILOGE("get switch status, resultSet->GetString not ok with key is %{public}s", key.c_str());
|
||||
resultSet->Close();
|
||||
dataShareHelper->Release();
|
||||
return CONTINUE_SWITCH_OFF;
|
||||
}
|
||||
resultSet->Close();
|
||||
dataShareHelper->Release();
|
||||
HILOGI("get switch status, query end");
|
||||
HILOGI("GetSwitchStatus, setting value is %{public}s with key is %{public}s", valueResult.c_str(), key.c_str());
|
||||
return valueResult;
|
||||
}
|
||||
|
||||
std::shared_ptr<DataShare::DataShareHelper> SwitchStatusDependency::GetDataShareHelper()
|
||||
{
|
||||
HILOGI("create DataShareHelper instance");
|
||||
DataShare::CreateOptions options;
|
||||
options.isProxy_ = true;
|
||||
return DataShare::DataShareHelper::Creator(SETTINGS_DATA_URI_PREFIX, options);
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
Loading…
x
Reference in New Issue
Block a user