适配异ability需求

Signed-off-by: m30043719 <maxiaodong25@huawei.com>
This commit is contained in:
m30043719 2024-04-28 09:39:27 +08:00
parent 218b419682
commit a5dbb4bf2d
11 changed files with 171 additions and 25 deletions

View File

@ -52,6 +52,9 @@ public:
static int32_t GetBundleNameId(const std::string& bundleName, uint16_t& accessTokenId); static int32_t GetBundleNameId(const std::string& bundleName, uint16_t& accessTokenId);
static std::string GetContinueType(const std::string &networkId, static std::string GetContinueType(const std::string &networkId,
std::string &bundleName, uint8_t continueTypeId); 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, static int32_t GetBundleNameFromDbms(const std::string& networkId,
const uint16_t accessTokenId, std::string& bundleName); const uint16_t accessTokenId, std::string& bundleName);
static int32_t GetApplicationInfoFromBms(const std::string& bundleName, const AppExecFwk::BundleFlag flag, static int32_t GetApplicationInfoFromBms(const std::string& bundleName, const AppExecFwk::BundleFlag flag,

View File

@ -35,6 +35,8 @@ namespace {
// distributed bm // distributed bm
static std::string DMS_BM_APP_ID = "DistributedSchedule"; static std::string DMS_BM_APP_ID = "DistributedSchedule";
static std::string DISTRIBUTE_BM_STORE_ID = "dms_bundle_datas"; 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 { class DmsBmStorage {
public: public:
@ -50,6 +52,8 @@ public:
std::string &bundleName); std::string &bundleName);
bool GetBundleNameId(std::string bundleName, uint16_t &accessTokenId); bool GetBundleNameId(std::string bundleName, uint16_t &accessTokenId);
std::string GetContinueType(const std::string &networkId, std::string &bundleName, uint8_t continueTypeId); 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(); void UpdateDistributedData();
int32_t PullOtherDistributedData(); int32_t PullOtherDistributedData();
int32_t PushOtherDistributedData(); int32_t PushOtherDistributedData();

View File

@ -48,8 +48,8 @@ class DMSContinueRecvMgr {
DECLARE_SINGLE_INSTANCE(DMSContinueRecvMgr); DECLARE_SINGLE_INSTANCE(DMSContinueRecvMgr);
public: public:
constexpr static uint8_t DMS_DATA_LEN = 6; // Dms data Length constexpr static uint8_t DMS_DATA_LEN = 3; // Dms data Length
constexpr static int32_t DMS_SEND_LEN = 1024 * 1024 * 10; // Maximum Broadcast Length constexpr static int32_t DMS_SEND_LEN = 4; // Maximum Broadcast Length
constexpr static uint8_t DMS_0XF0 = 0xf0; constexpr static uint8_t DMS_0XF0 = 0xf0;
constexpr static uint8_t DMS_0X0F = 0x0f; constexpr static uint8_t DMS_0X0F = 0x0f;
constexpr static uint8_t DMS_0XFF = 0xff; constexpr static uint8_t DMS_0XFF = 0xff;

View File

@ -69,8 +69,8 @@ class DMSContinueSendMgr {
DECLARE_SINGLE_INSTANCE(DMSContinueSendMgr); DECLARE_SINGLE_INSTANCE(DMSContinueSendMgr);
public: public:
constexpr static uint8_t DMS_DATA_LEN = 6; // Dms data Length constexpr static uint8_t DMS_DATA_LEN = 3; // Dms data Length
constexpr static int32_t DMS_SEND_LEN = 7; // Maximum broadcast length constexpr static int32_t DMS_SEND_LEN = 4; // Maximum broadcast length
constexpr static uint8_t DMS_0XF0 = 0xf0; constexpr static uint8_t DMS_0XF0 = 0xf0;
constexpr static uint8_t DMS_0X0F = 0x0f; constexpr static uint8_t DMS_0X0F = 0x0f;
constexpr static uint8_t DMS_0XFF = 0xff; constexpr static uint8_t DMS_0XFF = 0xff;

View File

@ -345,6 +345,33 @@ std::string BundleManagerInternal::GetContinueType(const std::string &networkId,
return continueType; 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, int32_t BundleManagerInternal::GetBundleNameFromDbms(const std::string& networkId,
const uint16_t accessTokenId, std::string& bundleName) const uint16_t accessTokenId, std::string& bundleName)
{ {

View File

@ -2339,8 +2339,8 @@ int32_t DistributedSchedService::GetContinueInfo(std::string& dstNetworkId, std:
} }
dstNetworkId = dschedContinuation_->continueInfo_.dstNetworkId; dstNetworkId = dschedContinuation_->continueInfo_.dstNetworkId;
srcNetworkId = dschedContinuation_->continueInfo_.srcNetworkId; srcNetworkId = dschedContinuation_->continueInfo_.srcNetworkId;
HILOGI("dstNetworkId: %{public}s", dstNetworkId.c_str()); HILOGI("dstNetworkId: %{public}s", DnetworkAdapter::AnonymizeNetworkId(dstNetworkId).c_str());
HILOGI("srcNetworkId: %{public}s", srcNetworkId.c_str()); HILOGI("srcNetworkId: %{public}s", DnetworkAdapter::AnonymizeNetworkId(srcNetworkId).c_str());
return 0; return 0;
} }

View File

@ -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 EL1 = 1;
const int32_t MAX_TIMES = 600; // 1min const int32_t MAX_TIMES = 600; // 1min
const int32_t SLEEP_INTERVAL = 100 * 1000; // 100ms const int32_t SLEEP_INTERVAL = 100 * 1000; // 100ms
const int32_t FLAGS = AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES; const int32_t FLAGS = AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES |
const uint16_t MAX_BUNDLEID = 65535; // size of uint16_t AppExecFwk::ApplicationFlag::GET_APPLICATION_INFO_WITH_DISABLE |
AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_DISABLE;
} // namespace } // namespace
std::shared_ptr<DmsBmStorage> DmsBmStorage::instance_ = nullptr; std::shared_ptr<DmsBmStorage> DmsBmStorage::instance_ = nullptr;
@ -147,7 +148,7 @@ bool DmsBmStorage::DeleteStorageDistributeInfo(const std::string &bundleName)
} }
uint16_t accessTokenId = 0; uint16_t accessTokenId = 0;
GetBundleNameId(bundleName, accessTokenId); GetBundleNameId(bundleName, accessTokenId);
if (bundleNameIdTables_.size() >= accessTokenId) { if (bundleNameIdTables_.size() > accessTokenId) {
bundleNameIdTables_[accessTokenId] = false; bundleNameIdTables_[accessTokenId] = false;
} }
std::string keyOfData = DeviceAndNameToKey(udid, bundleName); 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, bool DmsBmStorage::DealGetBundleName(const std::string &networkId, uint16_t accessTokenId,
std::string &bundleName) 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()) { if (!CheckKvStore()) {
HILOGE("kvStore is nullptr"); 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, bool DmsBmStorage::GetDistributedBundleName(const std::string &networkId, uint16_t accessTokenId,
std::string &bundleName) 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); bool ret = DealGetBundleName(networkId, accessTokenId, bundleName);
if (!ret) { if (!ret) {
HILOGW("GetDistributedBundleName error and try to call again"); HILOGW("GetDistributedBundleName error and try to call again");
@ -383,12 +386,14 @@ DmsBundleInfo DmsBmStorage::ConvertToDistributedBundleInfo(const AppExecFwk::Bun
distributedBundleInfo.enabled = bundleInfo.applicationInfo.enabled; distributedBundleInfo.enabled = bundleInfo.applicationInfo.enabled;
distributedBundleInfo.accessTokenId = CreateBundleNameId(); distributedBundleInfo.accessTokenId = CreateBundleNameId();
distributedBundleInfo.updateTime = bundleInfo.updateTime; distributedBundleInfo.updateTime = bundleInfo.updateTime;
int32_t pos = 0; uint8_t pos = 0;
for (const auto &abilityInfo : bundleInfo.abilityInfos) { for (const auto &abilityInfo : bundleInfo.abilityInfos) {
DmsAbilityInfo dmsAbilityInfo; DmsAbilityInfo dmsAbilityInfo;
dmsAbilityInfo.abilityName = abilityInfo.name; dmsAbilityInfo.abilityName = abilityInfo.name;
dmsAbilityInfo.continueType.push_back(abilityInfo.name); for (const auto &continueType : abilityInfo.continueType) {
dmsAbilityInfo.continueTypeId.push_back(pos++); dmsAbilityInfo.continueType.push_back(continueType);
dmsAbilityInfo.continueTypeId.push_back(pos++);
}
distributedBundleInfo.dmsAbilityInfos.push_back(dmsAbilityInfo); distributedBundleInfo.dmsAbilityInfos.push_back(dmsAbilityInfo);
} }
return distributedBundleInfo; return distributedBundleInfo;
@ -493,7 +498,6 @@ void DmsBmStorage::UpdateDistributedData()
if (oldDistributedBundleInfos.find(bundleInfo.name) != oldDistributedBundleInfos.end()) { if (oldDistributedBundleInfos.find(bundleInfo.name) != oldDistributedBundleInfos.end()) {
int32_t updateTime = oldDistributedBundleInfos[bundleInfo.name].updateTime; int32_t updateTime = oldDistributedBundleInfos[bundleInfo.name].updateTime;
if (updateTime == bundleInfo.updateTime) { if (updateTime == bundleInfo.updateTime) {
HILOGW("bundleName:%{public}s no need to update", bundleInfo.name.c_str());
continue; continue;
} }
} }
@ -567,8 +571,8 @@ std::string FindContinueType(const DmsBundleInfo& distributedBundleInfo, uint8_t
std::string DmsBmStorage::GetContinueType(const std::string &networkId, std::string &bundleName, std::string DmsBmStorage::GetContinueType(const std::string &networkId, std::string &bundleName,
uint8_t continueTypeId) uint8_t continueTypeId)
{ {
HILOGD("networkId: %{public}s, bundleName: %{public}s, continueTypeId: %{public}d", networkId.c_str(), HILOGD("networkId: %{public}s, bundleName: %{public}s, continueTypeId: %{public}d",
bundleName.c_str(), continueTypeId); DnetworkAdapter::AnonymizeNetworkId(networkId).c_str(), bundleName.c_str(), continueTypeId);
{ {
if (!CheckKvStore()) { if (!CheckKvStore()) {
HILOGE("kvStore is nullptr"); 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 ""; 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 DistributedSchedule
} // namespace OHOS } // namespace OHOS

View File

@ -91,7 +91,7 @@ void DMSContinueRecvMgr::NotifyDataRecv(std::string& senderNetworkId,
HILOGE("ContinueSwitch status is off"); HILOGE("ContinueSwitch status is off");
return; return;
} }
if (dataLen > DMS_SEND_LEN) { if (dataLen < DMS_SEND_LEN) {
HILOGE("dataLen error, dataLen: %{public}u", dataLen); HILOGE("dataLen error, dataLen: %{public}u", dataLen);
return; return;
} }
@ -102,8 +102,8 @@ void DMSContinueRecvMgr::NotifyDataRecv(std::string& senderNetworkId,
return; return;
} }
uint16_t bundleNameId = (payload[1] << CONTINUE_SHIFT_08) | payload[INDEX_2]; uint16_t bundleNameId = (payload[1] << CONTINUE_SHIFT_08) | payload[INDEX_2];
uint16_t continueTypeId = payload[INDEX_3]; uint8_t continueTypeId = payload[INDEX_3];
HILOGD("bundleNameId: %{public}u, continueTypeId: %{public}u", bundleNameId, continueTypeId); HILOGI("bundleNameId: %{public}u, continueTypeId: %{public}u", bundleNameId, continueTypeId);
int32_t state = ACTIVE; int32_t state = ACTIVE;
if (type == DMS_UNFOCUSED_TYPE) { if (type == DMS_UNFOCUSED_TYPE) {
state = INACTIVE; state = INACTIVE;

View File

@ -282,7 +282,7 @@ int32_t DMSContinueSendMgr::DealFocusedBusiness(const int32_t missionId)
AddMMIListener(); AddMMIListener();
#endif #endif
uint16_t accessTokenId = 0; uint16_t accessTokenId = 0;
uint16_t contineTypeId = 0; uint8_t continueTypeId = 0;
ret = BundleManagerInternal::GetBundleNameId(bundleName, accessTokenId); ret = BundleManagerInternal::GetBundleNameId(bundleName, accessTokenId);
DmsRadar::GetInstance().NormalFocusedGetAccessTokenIdRes("GetBundleNameId", ret); DmsRadar::GetInstance().NormalFocusedGetAccessTokenIdRes("GetBundleNameId", ret);
if (ret != ERR_OK) { if (ret != ERR_OK) {
@ -290,7 +290,7 @@ int32_t DMSContinueSendMgr::DealFocusedBusiness(const int32_t missionId)
return ret; return ret;
} }
if (!SwitchStatusDependency::GetInstance().IsContinueSwitchOn()) { return DMS_PERMISSION_DENIED;} 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); DmsRadar::GetInstance().NormalFocusedSendEventRes("SendSoftbusEvent", ret);
if (ret != ERR_OK) { if (ret != ERR_OK) {
HILOGE("SendSoftbusEvent focused failed, ret: %{public}d", ret); HILOGE("SendSoftbusEvent focused failed, ret: %{public}d", ret);

View File

@ -63,7 +63,7 @@ void DMSContinueManagerTest::TearDown()
} }
void RemoteOnListenerStubTest::OnCallback(const uint32_t ContinueState, const std::string& srcDeviceId, 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)
{ {
} }

View File

@ -33,7 +33,7 @@ public:
class RemoteOnListenerStubTest : public AAFwk::RemoteOnListenerStub { class RemoteOnListenerStubTest : public AAFwk::RemoteOnListenerStub {
public: public:
void OnCallback(const uint32_t ContinueState, const std::string& srcDeviceId, 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 DistributedSchedule
} // namespace OHOS } // namespace OHOS