mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 14:30:21 +00:00
适配异ability需求
Signed-off-by: m30043719 <maxiaodong25@huawei.com>
This commit is contained in:
parent
218b419682
commit
a5dbb4bf2d
@ -52,6 +52,9 @@ public:
|
||||
static int32_t GetBundleNameId(const std::string& bundleName, uint16_t& accessTokenId);
|
||||
static std::string GetContinueType(const std::string &networkId,
|
||||
std::string &bundleName, uint8_t continueTypeId);
|
||||
static int32_t GetContinueTypeId(std::string &bundleName,
|
||||
const std::string &abilityName, uint8_t &continueTypeId);
|
||||
static std::string GetAbilityName(const std::string &networkId, std::string &bundleName, std::string &continueType);
|
||||
static int32_t GetBundleNameFromDbms(const std::string& networkId,
|
||||
const uint16_t accessTokenId, std::string& bundleName);
|
||||
static int32_t GetApplicationInfoFromBms(const std::string& bundleName, const AppExecFwk::BundleFlag flag,
|
||||
|
@ -35,6 +35,8 @@ namespace {
|
||||
// distributed bm
|
||||
static std::string DMS_BM_APP_ID = "DistributedSchedule";
|
||||
static std::string DISTRIBUTE_BM_STORE_ID = "dms_bundle_datas";
|
||||
const uint16_t MAX_BUNDLEID = 65535; // size of uint16_t
|
||||
const uint8_t MAX_CONTINUETYPEID = 255; // size of uint8_t
|
||||
}
|
||||
class DmsBmStorage {
|
||||
public:
|
||||
@ -50,6 +52,8 @@ public:
|
||||
std::string &bundleName);
|
||||
bool GetBundleNameId(std::string bundleName, uint16_t &accessTokenId);
|
||||
std::string GetContinueType(const std::string &networkId, std::string &bundleName, uint8_t continueTypeId);
|
||||
std::string GetAbilityName(const std::string &networkId, std::string &bundleName, std::string &continueType);
|
||||
bool GetContinueTypeId(const std::string bundleName, const std::string &abilityName, uint8_t &continueTypeId);
|
||||
void UpdateDistributedData();
|
||||
int32_t PullOtherDistributedData();
|
||||
int32_t PushOtherDistributedData();
|
||||
|
@ -48,8 +48,8 @@ class DMSContinueRecvMgr {
|
||||
DECLARE_SINGLE_INSTANCE(DMSContinueRecvMgr);
|
||||
|
||||
public:
|
||||
constexpr static uint8_t DMS_DATA_LEN = 6; // Dms data Length
|
||||
constexpr static int32_t DMS_SEND_LEN = 1024 * 1024 * 10; // Maximum Broadcast Length
|
||||
constexpr static uint8_t DMS_DATA_LEN = 3; // Dms data Length
|
||||
constexpr static int32_t DMS_SEND_LEN = 4; // Maximum Broadcast Length
|
||||
constexpr static uint8_t DMS_0XF0 = 0xf0;
|
||||
constexpr static uint8_t DMS_0X0F = 0x0f;
|
||||
constexpr static uint8_t DMS_0XFF = 0xff;
|
||||
|
@ -69,8 +69,8 @@ class DMSContinueSendMgr {
|
||||
DECLARE_SINGLE_INSTANCE(DMSContinueSendMgr);
|
||||
|
||||
public:
|
||||
constexpr static uint8_t DMS_DATA_LEN = 6; // Dms data Length
|
||||
constexpr static int32_t DMS_SEND_LEN = 7; // Maximum broadcast length
|
||||
constexpr static uint8_t DMS_DATA_LEN = 3; // Dms data Length
|
||||
constexpr static int32_t DMS_SEND_LEN = 4; // Maximum broadcast length
|
||||
constexpr static uint8_t DMS_0XF0 = 0xf0;
|
||||
constexpr static uint8_t DMS_0X0F = 0x0f;
|
||||
constexpr static uint8_t DMS_0XFF = 0xff;
|
||||
|
@ -345,6 +345,33 @@ std::string BundleManagerInternal::GetContinueType(const std::string &networkId,
|
||||
return continueType;
|
||||
}
|
||||
|
||||
int32_t BundleManagerInternal::GetContinueTypeId(std::string &bundleName,
|
||||
const std::string &abilityName, uint8_t &continueTypeId)
|
||||
{
|
||||
HILOGD("called.");
|
||||
bool ret = DmsBmStorage::GetInstance()->GetContinueTypeId(bundleName, abilityName, continueTypeId);
|
||||
HILOGI("ContinueTypeId: %{public}d ", continueTypeId);
|
||||
if (!ret) {
|
||||
HILOGE("can not get ContinueTypeId!");
|
||||
return CAN_NOT_FOUND_ABILITY_ERR;
|
||||
}
|
||||
HILOGD("end.");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
std::string BundleManagerInternal::GetAbilityName(const std::string &networkId,
|
||||
std::string &bundleName, std::string &continueType)
|
||||
{
|
||||
HILOGD("called.");
|
||||
std::string abilityName = DmsBmStorage::GetInstance()->GetAbilityName(networkId, bundleName, continueType);
|
||||
HILOGI("continueType: %{public}s ", abilityName.c_str());
|
||||
if (abilityName == "") {
|
||||
HILOGE("can not get abilityName!");
|
||||
}
|
||||
HILOGD("end.");
|
||||
return abilityName;
|
||||
}
|
||||
|
||||
int32_t BundleManagerInternal::GetBundleNameFromDbms(const std::string& networkId,
|
||||
const uint16_t accessTokenId, std::string& bundleName)
|
||||
{
|
||||
|
@ -2339,8 +2339,8 @@ int32_t DistributedSchedService::GetContinueInfo(std::string& dstNetworkId, std:
|
||||
}
|
||||
dstNetworkId = dschedContinuation_->continueInfo_.dstNetworkId;
|
||||
srcNetworkId = dschedContinuation_->continueInfo_.srcNetworkId;
|
||||
HILOGI("dstNetworkId: %{public}s", dstNetworkId.c_str());
|
||||
HILOGI("srcNetworkId: %{public}s", srcNetworkId.c_str());
|
||||
HILOGI("dstNetworkId: %{public}s", DnetworkAdapter::AnonymizeNetworkId(dstNetworkId).c_str());
|
||||
HILOGI("srcNetworkId: %{public}s", DnetworkAdapter::AnonymizeNetworkId(srcNetworkId).c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,9 @@ const std::string BMS_KV_BASE_DIR = "/data/service/el1/public/database/Distribut
|
||||
const int32_t EL1 = 1;
|
||||
const int32_t MAX_TIMES = 600; // 1min
|
||||
const int32_t SLEEP_INTERVAL = 100 * 1000; // 100ms
|
||||
const int32_t FLAGS = AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES;
|
||||
const uint16_t MAX_BUNDLEID = 65535; // size of uint16_t
|
||||
const int32_t FLAGS = AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES |
|
||||
AppExecFwk::ApplicationFlag::GET_APPLICATION_INFO_WITH_DISABLE |
|
||||
AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_DISABLE;
|
||||
} // namespace
|
||||
|
||||
std::shared_ptr<DmsBmStorage> DmsBmStorage::instance_ = nullptr;
|
||||
@ -147,7 +148,7 @@ bool DmsBmStorage::DeleteStorageDistributeInfo(const std::string &bundleName)
|
||||
}
|
||||
uint16_t accessTokenId = 0;
|
||||
GetBundleNameId(bundleName, accessTokenId);
|
||||
if (bundleNameIdTables_.size() >= accessTokenId) {
|
||||
if (bundleNameIdTables_.size() > accessTokenId) {
|
||||
bundleNameIdTables_[accessTokenId] = false;
|
||||
}
|
||||
std::string keyOfData = DeviceAndNameToKey(udid, bundleName);
|
||||
@ -199,7 +200,8 @@ bool DmsBmStorage::GetStorageDistributeInfo(const std::string &networkId,
|
||||
bool DmsBmStorage::DealGetBundleName(const std::string &networkId, uint16_t accessTokenId,
|
||||
std::string &bundleName)
|
||||
{
|
||||
HILOGD("networkId: %{public}s accessTokenId: %{public}d", networkId.c_str(), accessTokenId);
|
||||
HILOGD("networkId: %{public}s accessTokenId: %{public}d",
|
||||
DnetworkAdapter::AnonymizeNetworkId(networkId).c_str(), accessTokenId);
|
||||
{
|
||||
if (!CheckKvStore()) {
|
||||
HILOGE("kvStore is nullptr");
|
||||
@ -238,7 +240,8 @@ bool DmsBmStorage::DealGetBundleName(const std::string &networkId, uint16_t acce
|
||||
bool DmsBmStorage::GetDistributedBundleName(const std::string &networkId, uint16_t accessTokenId,
|
||||
std::string &bundleName)
|
||||
{
|
||||
HILOGD("networkId: %{public}s accessTokenId: %{public}d", networkId.c_str(), accessTokenId);
|
||||
HILOGD("networkId: %{public}s accessTokenId: %{public}d",
|
||||
DnetworkAdapter::AnonymizeNetworkId(networkId).c_str(), accessTokenId);
|
||||
bool ret = DealGetBundleName(networkId, accessTokenId, bundleName);
|
||||
if (!ret) {
|
||||
HILOGW("GetDistributedBundleName error and try to call again");
|
||||
@ -383,12 +386,14 @@ DmsBundleInfo DmsBmStorage::ConvertToDistributedBundleInfo(const AppExecFwk::Bun
|
||||
distributedBundleInfo.enabled = bundleInfo.applicationInfo.enabled;
|
||||
distributedBundleInfo.accessTokenId = CreateBundleNameId();
|
||||
distributedBundleInfo.updateTime = bundleInfo.updateTime;
|
||||
int32_t pos = 0;
|
||||
uint8_t pos = 0;
|
||||
for (const auto &abilityInfo : bundleInfo.abilityInfos) {
|
||||
DmsAbilityInfo dmsAbilityInfo;
|
||||
dmsAbilityInfo.abilityName = abilityInfo.name;
|
||||
dmsAbilityInfo.continueType.push_back(abilityInfo.name);
|
||||
dmsAbilityInfo.continueTypeId.push_back(pos++);
|
||||
for (const auto &continueType : abilityInfo.continueType) {
|
||||
dmsAbilityInfo.continueType.push_back(continueType);
|
||||
dmsAbilityInfo.continueTypeId.push_back(pos++);
|
||||
}
|
||||
distributedBundleInfo.dmsAbilityInfos.push_back(dmsAbilityInfo);
|
||||
}
|
||||
return distributedBundleInfo;
|
||||
@ -493,7 +498,6 @@ void DmsBmStorage::UpdateDistributedData()
|
||||
if (oldDistributedBundleInfos.find(bundleInfo.name) != oldDistributedBundleInfos.end()) {
|
||||
int32_t updateTime = oldDistributedBundleInfos[bundleInfo.name].updateTime;
|
||||
if (updateTime == bundleInfo.updateTime) {
|
||||
HILOGW("bundleName:%{public}s no need to update", bundleInfo.name.c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -567,8 +571,8 @@ std::string FindContinueType(const DmsBundleInfo& distributedBundleInfo, uint8_t
|
||||
std::string DmsBmStorage::GetContinueType(const std::string &networkId, std::string &bundleName,
|
||||
uint8_t continueTypeId)
|
||||
{
|
||||
HILOGD("networkId: %{public}s, bundleName: %{public}s, continueTypeId: %{public}d", networkId.c_str(),
|
||||
bundleName.c_str(), continueTypeId);
|
||||
HILOGD("networkId: %{public}s, bundleName: %{public}s, continueTypeId: %{public}d",
|
||||
DnetworkAdapter::AnonymizeNetworkId(networkId).c_str(), bundleName.c_str(), continueTypeId);
|
||||
{
|
||||
if (!CheckKvStore()) {
|
||||
HILOGE("kvStore is nullptr");
|
||||
@ -601,8 +605,116 @@ std::string DmsBmStorage::GetContinueType(const std::string &networkId, std::str
|
||||
}
|
||||
}
|
||||
}
|
||||
HILOGE("Failed to discover continueType");
|
||||
HILOGW("Can't find continueType");
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string FindAbilityName(const DmsBundleInfo& distributedBundleInfo, std::string continueType)
|
||||
{
|
||||
for (auto dmsAbilityInfo : distributedBundleInfo.dmsAbilityInfos) {
|
||||
for (auto ele : dmsAbilityInfo.continueType) {
|
||||
if (ele == continueType) {
|
||||
return dmsAbilityInfo.abilityName;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string DmsBmStorage::GetAbilityName(const std::string &networkId, std::string &bundleName,
|
||||
std::string &continueType)
|
||||
{
|
||||
HILOGD("networkId: %{public}s, bundleName: %{public}s, continueTypeId: %{public}s",
|
||||
DnetworkAdapter::AnonymizeNetworkId(networkId).c_str(), bundleName.c_str(), continueType.c_str());
|
||||
{
|
||||
if (!CheckKvStore()) {
|
||||
HILOGE("kvStore is nullptr");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
std::string udid = DtbschedmgrDeviceInfoStorage::GetInstance().GetUdidByNetworkId(networkId);
|
||||
if (udid == "") {
|
||||
HILOGE("can not get udid by networkId");
|
||||
return "";
|
||||
}
|
||||
Key allEntryKeyPrefix("");
|
||||
std::vector<Entry> allEntries;
|
||||
Status status = kvStorePtr_->GetEntries(allEntryKeyPrefix, allEntries);
|
||||
if (status != Status::SUCCESS) {
|
||||
HILOGE("GetEntries error: %{public}d", status);
|
||||
return "";
|
||||
}
|
||||
for (auto entry : allEntries) {
|
||||
std::string key = entry.key.ToString();
|
||||
std::string value = entry.value.ToString();
|
||||
if (key.find(udid) == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
DmsBundleInfo distributedBundleInfo;
|
||||
if (distributedBundleInfo.FromJsonString(value) && distributedBundleInfo.bundleName == bundleName) {
|
||||
std::string abilityName = FindAbilityName(distributedBundleInfo, continueType);
|
||||
if (abilityName != "") {
|
||||
return abilityName;
|
||||
}
|
||||
}
|
||||
}
|
||||
HILOGW("Can't find abilityName");
|
||||
return "";
|
||||
}
|
||||
|
||||
uint8_t FindContinueTypeId(const DmsBundleInfo& distributedBundleInfo, std::string abilityName)
|
||||
{
|
||||
HILOGD("called.");
|
||||
uint8_t pos = 0;
|
||||
for (auto dmsAbilityInfo : distributedBundleInfo.dmsAbilityInfos) {
|
||||
if (dmsAbilityInfo.abilityName == abilityName) {
|
||||
return pos;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
return MAX_CONTINUETYPEID;
|
||||
}
|
||||
|
||||
bool DmsBmStorage::GetContinueTypeId(const std::string bundleName, const std::string &abilityName,
|
||||
uint8_t &continueTypeId)
|
||||
{
|
||||
HILOGD("called.");
|
||||
{
|
||||
if (!CheckKvStore()) {
|
||||
HILOGE("kvStore is nullptr");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
std::string udid;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalUdid(udid);
|
||||
if (udid == "") {
|
||||
HILOGE("can not get udid by networkId");
|
||||
return false;
|
||||
}
|
||||
Key allEntryKeyPrefix("");
|
||||
std::vector<Entry> allEntries;
|
||||
Status status = kvStorePtr_->GetEntries(allEntryKeyPrefix, allEntries);
|
||||
if (status != Status::SUCCESS) {
|
||||
HILOGE("GetEntries error: %{public}d", status);
|
||||
return false;
|
||||
}
|
||||
for (auto entry : allEntries) {
|
||||
std::string key = entry.key.ToString();
|
||||
std::string value = entry.value.ToString();
|
||||
if (key.find(udid) == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
DmsBundleInfo distributedBundleInfo;
|
||||
if (distributedBundleInfo.FromJsonString(value) && distributedBundleInfo.bundleName == bundleName) {
|
||||
continueTypeId = FindContinueTypeId(distributedBundleInfo, abilityName);
|
||||
if (continueTypeId != MAX_CONTINUETYPEID) {
|
||||
HILOGD("end.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
HILOGW("Can't find continueTypeId");
|
||||
return false;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -91,7 +91,7 @@ void DMSContinueRecvMgr::NotifyDataRecv(std::string& senderNetworkId,
|
||||
HILOGE("ContinueSwitch status is off");
|
||||
return;
|
||||
}
|
||||
if (dataLen > DMS_SEND_LEN) {
|
||||
if (dataLen < DMS_SEND_LEN) {
|
||||
HILOGE("dataLen error, dataLen: %{public}u", dataLen);
|
||||
return;
|
||||
}
|
||||
@ -102,8 +102,8 @@ void DMSContinueRecvMgr::NotifyDataRecv(std::string& senderNetworkId,
|
||||
return;
|
||||
}
|
||||
uint16_t bundleNameId = (payload[1] << CONTINUE_SHIFT_08) | payload[INDEX_2];
|
||||
uint16_t continueTypeId = payload[INDEX_3];
|
||||
HILOGD("bundleNameId: %{public}u, continueTypeId: %{public}u", bundleNameId, continueTypeId);
|
||||
uint8_t continueTypeId = payload[INDEX_3];
|
||||
HILOGI("bundleNameId: %{public}u, continueTypeId: %{public}u", bundleNameId, continueTypeId);
|
||||
int32_t state = ACTIVE;
|
||||
if (type == DMS_UNFOCUSED_TYPE) {
|
||||
state = INACTIVE;
|
||||
|
@ -282,7 +282,7 @@ int32_t DMSContinueSendMgr::DealFocusedBusiness(const int32_t missionId)
|
||||
AddMMIListener();
|
||||
#endif
|
||||
uint16_t accessTokenId = 0;
|
||||
uint16_t contineTypeId = 0;
|
||||
uint8_t continueTypeId = 0;
|
||||
ret = BundleManagerInternal::GetBundleNameId(bundleName, accessTokenId);
|
||||
DmsRadar::GetInstance().NormalFocusedGetAccessTokenIdRes("GetBundleNameId", ret);
|
||||
if (ret != ERR_OK) {
|
||||
@ -290,7 +290,7 @@ int32_t DMSContinueSendMgr::DealFocusedBusiness(const int32_t missionId)
|
||||
return ret;
|
||||
}
|
||||
if (!SwitchStatusDependency::GetInstance().IsContinueSwitchOn()) { return DMS_PERMISSION_DENIED;}
|
||||
ret = SendSoftbusEvent(accessTokenId, contineTypeId, DMS_FOCUSED_TYPE);
|
||||
ret = SendSoftbusEvent(accessTokenId, continueTypeId, DMS_FOCUSED_TYPE);
|
||||
DmsRadar::GetInstance().NormalFocusedSendEventRes("SendSoftbusEvent", ret);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("SendSoftbusEvent focused failed, ret: %{public}d", ret);
|
||||
|
@ -63,7 +63,7 @@ void DMSContinueManagerTest::TearDown()
|
||||
}
|
||||
|
||||
void RemoteOnListenerStubTest::OnCallback(const uint32_t ContinueState, const std::string& srcDeviceId,
|
||||
const std::string& bundleName)
|
||||
const std::string &bundleName, const std::string &continueType, const std::string &srcBundleName)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
class RemoteOnListenerStubTest : public AAFwk::RemoteOnListenerStub {
|
||||
public:
|
||||
void OnCallback(const uint32_t ContinueState, const std::string& srcDeviceId,
|
||||
const std::string& bundleName) override;
|
||||
const std::string &bundleName, const std::string &continueType, const std::string &srcBundleName) override;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user