mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 22:39:58 +00:00
commit
07e2897996
@ -71,6 +71,7 @@ private:
|
||||
bool CheckCallingUid();
|
||||
bool EnforceInterfaceToken(MessageParcel& data);
|
||||
bool CallerInfoUnmarshalling(CallerInfo& callerInfo, MessageParcel& data);
|
||||
void SaveExtraInfo(const nlohmann::json& extraInfoJson, CallerInfo& callerInfo);
|
||||
|
||||
using DistributedSchedFunc = int32_t(DistributedSchedStub::*)(MessageParcel& data, MessageParcel& reply);
|
||||
std::map<uint32_t, DistributedSchedFunc> remoteFuncsMap_;
|
||||
|
@ -35,6 +35,7 @@ const std::string FOUNDATION_PROCESS_NAME = "foundation";
|
||||
const std::string DMS_API_VERSION = "dmsApiVersion";
|
||||
const std::string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround";
|
||||
const std::string DMS_MISSION_ID = "dmsMissionId";
|
||||
const std::string DMS_VERSION_ID = "dmsVersion";
|
||||
const std::string PERMISSION_START_ABILIIES_FROM_BACKGROUND = "ohos.permission.START_ABILIIES_FROM_BACKGROUND";
|
||||
const std::string PERMISSION_START_ABILITIES_FROM_BACKGROUND = "ohos.permission.START_ABILITIES_FROM_BACKGROUND";
|
||||
const std::string PERMISSION_START_INVISIBLE_ABILITY = "ohos.permission.START_INVISIBLE_ABILITY";
|
||||
@ -380,6 +381,11 @@ bool DistributedSchedPermission::CheckCustomPermission(const AppExecFwk::Ability
|
||||
bool DistributedSchedPermission::CheckBackgroundPermission(const AppExecFwk::AbilityInfo& targetAbility,
|
||||
const CallerInfo& callerInfo, const AAFwk::Want& want, bool needCheckApiVersion) const
|
||||
{
|
||||
if (callerInfo.extraInfoJson.empty() ||
|
||||
callerInfo.extraInfoJson.find(DMS_VERSION_ID) == callerInfo.extraInfoJson.end()) {
|
||||
HILOGD("the version is low");
|
||||
return true;
|
||||
}
|
||||
AAFwk::Want* remoteWant = const_cast<Want*>(&want);
|
||||
bool isCallerBackGround = remoteWant->GetBoolParam(DMS_IS_CALLER_BACKGROUND, true);
|
||||
remoteWant->RemoveParam(DMS_IS_CALLER_BACKGROUND);
|
||||
|
@ -36,6 +36,7 @@ const std::u16string DMS_PROXY_INTERFACE_TOKEN = u"ohos.distributedschedule.acce
|
||||
const std::string EXTRO_INFO_JSON_KEY_ACCESS_TOKEN = "accessTokenID";
|
||||
const std::string EXTRO_INFO_JSON_KEY_REQUEST_CODE = "requestCode";
|
||||
const std::string CMPT_PARAM_FREEINSTALL_BUNDLENAMES = "ohos.extra.param.key.allowedBundles";
|
||||
const std::string DMS_VERSION_ID = "dmsVersion";
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
constexpr int32_t WAIT_TIME = 15;
|
||||
#endif
|
||||
@ -85,6 +86,9 @@ int32_t DistributedSchedProxy::StartAbilityFromRemote(const OHOS::AAFwk::Want& w
|
||||
PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
|
||||
nlohmann::json extraInfoJson;
|
||||
extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
|
||||
if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
|
||||
extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
|
||||
}
|
||||
std::string extraInfo = extraInfoJson.dump();
|
||||
PARCEL_WRITE_HELPER(data, String, extraInfo);
|
||||
MessageParcel reply;
|
||||
@ -280,6 +284,9 @@ int32_t DistributedSchedProxy::ConnectAbilityFromRemote(const OHOS::AAFwk::Want&
|
||||
PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
|
||||
nlohmann::json extraInfoJson;
|
||||
extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
|
||||
if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
|
||||
extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
|
||||
}
|
||||
std::string extraInfo = extraInfoJson.dump();
|
||||
PARCEL_WRITE_HELPER(data, String, extraInfo);
|
||||
MessageParcel reply;
|
||||
@ -645,6 +652,9 @@ int32_t DistributedSchedProxy::StartAbilityByCallFromRemote(const OHOS::AAFwk::W
|
||||
PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
|
||||
nlohmann::json extraInfoJson;
|
||||
extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
|
||||
if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
|
||||
extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
|
||||
}
|
||||
std::string extraInfo = extraInfoJson.dump();
|
||||
PARCEL_WRITE_HELPER(data, String, extraInfo);
|
||||
PARCEL_WRITE_HELPER(data, Parcelable, &want);
|
||||
@ -741,6 +751,9 @@ int32_t DistributedSchedProxy::StartFreeInstallFromRemote(const FreeInstallInfo&
|
||||
nlohmann::json extraInfoJson;
|
||||
extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = info.callerInfo.accessToken;
|
||||
extraInfoJson[EXTRO_INFO_JSON_KEY_REQUEST_CODE] = info.requestCode;
|
||||
if (info.callerInfo.extraInfoJson.find(DMS_VERSION_ID) != info.callerInfo.extraInfoJson.end()) {
|
||||
extraInfoJson[DMS_VERSION_ID] = info.callerInfo.extraInfoJson[DMS_VERSION_ID];
|
||||
}
|
||||
std::string extraInfo = extraInfoJson.dump();
|
||||
PARCEL_WRITE_HELPER(data, String, extraInfo);
|
||||
MessageParcel reply;
|
||||
|
@ -80,6 +80,8 @@ const std::string COMPONENT_TYPE_KEY = "componentType";
|
||||
const std::string DEVICE_TYPE_KEY = "deviceType";
|
||||
const std::string CHANGE_TYPE_KEY = "changeType";
|
||||
const std::string DMS_HIPLAY_ACTION = "ohos.ability.action.deviceSelect";
|
||||
const std::string DMS_VERSION_ID = "dmsVersion";
|
||||
const std::string DMS_VERSION = "4.0.0";
|
||||
constexpr int32_t BIND_CONNECT_RETRY_TIMES = 3;
|
||||
constexpr int32_t BIND_CONNECT_TIMEOUT = 500; // 500ms
|
||||
constexpr int32_t MAX_DISTRIBUTED_CONNECT_NUM = 600;
|
||||
@ -213,6 +215,7 @@ int32_t DistributedSchedService::StartRemoteAbility(const OHOS::AAFwk::Want& wan
|
||||
HILOGE("GetBundleNameListFromBms failed");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
AccountInfo accountInfo;
|
||||
int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(deviceId, callerInfo, accountInfo);
|
||||
if (ret != ERR_OK) {
|
||||
@ -681,7 +684,7 @@ int32_t DistributedSchedService::ConnectRemoteAbility(const OHOS::AAFwk::Want& w
|
||||
HILOGE("GetBundleNameListFromBms failed");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
HILOGD("[PerformanceTest] ConnectRemoteAbility begin");
|
||||
int32_t result = TryConnectRemoteAbility(want, connect, callerInfo);
|
||||
if (result != ERR_OK) {
|
||||
@ -916,6 +919,7 @@ int32_t DistributedSchedService::StartRemoteAbilityByCall(const OHOS::AAFwk::Wan
|
||||
HILOGE("GetBundleNameListFromBms failed");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
int32_t ret = TryStartRemoteAbilityByCall(want, connect, callerInfo);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("StartRemoteAbilityByCall result is %{public}d", ret);
|
||||
@ -1793,6 +1797,7 @@ int32_t DistributedSchedService::SetCallerInfo(
|
||||
HILOGE("GetBundleNameListFromBms failed");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ const std::string PERMISSION_DISTRIBUTED_DATASYNC = "ohos.permission.DISTRIBUTED
|
||||
const std::string PARAM_FREEINSTALL_APPID = "ohos.freeinstall.params.callingAppId";
|
||||
const std::string PARAM_FREEINSTALL_BUNDLENAMES = "ohos.freeinstall.params.callingBundleNames";
|
||||
const std::string CMPT_PARAM_FREEINSTALL_BUNDLENAMES = "ohos.extra.param.key.allowedBundles";
|
||||
const std::string DMS_VERSION_ID = "dmsVersion";
|
||||
const int DEFAULT_REQUEST_CODE = -1;
|
||||
}
|
||||
|
||||
@ -204,9 +205,8 @@ int32_t DistributedSchedStub::StartAbilityFromRemoteInner(MessageParcel& data, M
|
||||
}
|
||||
nlohmann::json extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
|
||||
if (!extraInfoJson.is_discarded()) {
|
||||
uint32_t accessToken = extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN];
|
||||
callerInfo.accessToken = accessToken;
|
||||
HILOGD("parse extra info, accessTokenID = %u", accessToken);
|
||||
SaveExtraInfo(extraInfoJson, callerInfo);
|
||||
HILOGD("parse extra info");
|
||||
}
|
||||
int32_t result = StartAbilityFromRemote(*want, abilityInfo, requestCode, callerInfo, accountInfo);
|
||||
BehaviorEventParam eventParam = { EventCallingType::REMOTE, BehaviorEvent::START_REMOTE_ABILITY, result,
|
||||
@ -221,6 +221,18 @@ int32_t DistributedSchedStub::StartAbilityFromRemoteInner(MessageParcel& data, M
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
void DistributedSchedStub::SaveExtraInfo(const nlohmann::json& extraInfoJson, CallerInfo& callerInfo)
|
||||
{
|
||||
uint32_t accessToken = extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN];
|
||||
callerInfo.accessToken = accessToken;
|
||||
HILOGD("parse extra info, accessTokenID = %u", accessToken);
|
||||
if (extraInfoJson.find(DMS_VERSION_ID) != extraInfoJson.end()) {
|
||||
std::string dmsVersion = extraInfoJson[DMS_VERSION_ID];
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = dmsVersion;
|
||||
HILOGD("save dms version");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedSchedStub::SendResultFromRemoteInner(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
if (!CheckCallingUid()) {
|
||||
@ -449,9 +461,8 @@ int32_t DistributedSchedStub::ConnectAbilityFromRemoteInner(MessageParcel& data,
|
||||
}
|
||||
nlohmann::json extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
|
||||
if (!extraInfoJson.is_discarded()) {
|
||||
uint32_t accessToken = extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN];
|
||||
callerInfo.accessToken = accessToken;
|
||||
HILOGD("parse extra info, accessTokenID = %u", accessToken);
|
||||
SaveExtraInfo(extraInfoJson, callerInfo);
|
||||
HILOGD("parse extra info");
|
||||
}
|
||||
std::string package = abilityInfo.bundleName;
|
||||
std::string deviceId = abilityInfo.deviceId;
|
||||
@ -819,9 +830,8 @@ int32_t DistributedSchedStub::StartAbilityByCallFromRemoteInner(MessageParcel& d
|
||||
}
|
||||
nlohmann::json extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
|
||||
if (!extraInfoJson.is_discarded()) {
|
||||
uint32_t accessToken = extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN];
|
||||
callerInfo.accessToken = accessToken;
|
||||
HILOGD("parse extra info, accessToken = %u", accessToken);
|
||||
SaveExtraInfo(extraInfoJson, callerInfo);
|
||||
HILOGD("parse extra info");
|
||||
}
|
||||
shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
|
||||
if (want == nullptr) {
|
||||
@ -986,9 +996,7 @@ int32_t DistributedSchedStub::StartFreeInstallFromRemoteInner(MessageParcel& dat
|
||||
nlohmann::json extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
|
||||
int32_t requestCode = DEFAULT_REQUEST_CODE;
|
||||
if (!extraInfoJson.is_discarded()) {
|
||||
uint32_t accessToken = extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN];
|
||||
callerInfo.accessToken = accessToken;
|
||||
HILOGD("parse extra info, accessTokenID = %u", accessToken);
|
||||
SaveExtraInfo(extraInfoJson, callerInfo);
|
||||
if (extraInfoJson.contains(EXTRO_INFO_JSON_KEY_REQUEST_CODE)) {
|
||||
requestCode = extraInfoJson[EXTRO_INFO_JSON_KEY_REQUEST_CODE];
|
||||
HILOGD("parse extra info, requestCode = %d", requestCode);
|
||||
|
@ -54,6 +54,8 @@ const string INVALID_PERMISSION_NAME = "ohos.permission.TEST";
|
||||
const string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround";
|
||||
const string DMS_API_VERSION = "dmsApiVersion";
|
||||
const string DMS_MISSION_ID = "dmsMissionId";
|
||||
const string DMS_VERSION_ID = "dmsVersion";
|
||||
const string DMS_VERSION = "4.0.0";
|
||||
const int API_VERSION = 9;
|
||||
const int FA_MODULE_ALLOW_MIN_API_VERSION = 8;
|
||||
|
||||
@ -559,6 +561,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_003, TestSize.
|
||||
CallerInfo callerInfo;
|
||||
bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
|
||||
EXPECT_EQ(result, true);
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
IDistributedSched::AccountInfo accountInfo;
|
||||
accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
|
||||
AppExecFwk::AbilityInfo targetAbility;
|
||||
@ -583,6 +586,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_004, TestSize.
|
||||
CallerInfo callerInfo;
|
||||
bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
|
||||
EXPECT_EQ(result, true);
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
IDistributedSched::AccountInfo accountInfo;
|
||||
accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
|
||||
AppExecFwk::AbilityInfo targetAbility;
|
||||
@ -608,6 +612,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_005, TestSize.
|
||||
CallerInfo callerInfo;
|
||||
bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
|
||||
EXPECT_EQ(result, true);
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
IDistributedSched::AccountInfo accountInfo;
|
||||
accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
|
||||
AppExecFwk::AbilityInfo targetAbility;
|
||||
@ -854,6 +859,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_001, TestSize
|
||||
DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_001 begin" << std::endl;
|
||||
AppExecFwk::AbilityInfo targetAbility;
|
||||
CallerInfo callerInfo;
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
AAFwk::Want want;
|
||||
want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
|
||||
bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
|
||||
@ -873,6 +879,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_002, TestSize
|
||||
DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_002 begin" << std::endl;
|
||||
AppExecFwk::AbilityInfo targetAbility;
|
||||
CallerInfo callerInfo;
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
AAFwk::Want want;
|
||||
bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
|
||||
false);
|
||||
@ -892,6 +899,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_003, TestSize
|
||||
AppExecFwk::AbilityInfo targetAbility;
|
||||
targetAbility.isStageBasedModel = true;
|
||||
CallerInfo callerInfo;
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
AAFwk::Want want;
|
||||
bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
|
||||
true);
|
||||
@ -911,6 +919,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_004, TestSize
|
||||
AppExecFwk::AbilityInfo targetAbility;
|
||||
targetAbility.type = AppExecFwk::AbilityType::SERVICE;
|
||||
CallerInfo callerInfo;
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
AAFwk::Want want;
|
||||
want.SetParam(DMS_API_VERSION, FA_MODULE_ALLOW_MIN_API_VERSION);
|
||||
bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
|
||||
@ -930,6 +939,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_005, TestSize
|
||||
DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_005 begin" << std::endl;
|
||||
AppExecFwk::AbilityInfo targetAbility;
|
||||
CallerInfo callerInfo;
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
callerInfo.sourceDeviceId = "";
|
||||
callerInfo.accessToken = GetSelfTokenID();
|
||||
AAFwk::Want want;
|
||||
@ -950,6 +960,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_006, TestSize
|
||||
DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_006 begin" << std::endl;
|
||||
AppExecFwk::AbilityInfo targetAbility;
|
||||
CallerInfo callerInfo;
|
||||
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
|
||||
callerInfo.sourceDeviceId = deviceId_;
|
||||
uint64_t tokenId = GetSelfTokenID();
|
||||
callerInfo.accessToken = tokenId;
|
||||
|
Loading…
Reference in New Issue
Block a user