add share form code

Signed-off-by: xuchenghua09 <xuchenghua09@huawei.com>
This commit is contained in:
xuchenghua09 2022-08-03 14:52:21 +08:00
parent 9734a880c2
commit 601c4ec8c7
13 changed files with 555 additions and 296 deletions

View File

@ -16,6 +16,7 @@
"subsystem": "ability",
"adapted_system_type": [ "standard" ],
"features" : [
"dmsfwk_standard_form_share",
"dmsfwk_mission_manager"
],
"hisysevent_config": [
@ -33,6 +34,7 @@
"distributeddatamgr",
"dsoftbus",
"eventhandler",
"form_fwk",
"hisysevent_native",
"hitrace_native",
"hiviewdfx_hilog_native",

View File

@ -12,6 +12,7 @@
# limitations under the License.
declare_args() {
dmsfwk_standard_form_share = true
dmsfwk_mission_manager = true
if (defined(global_parts_info) &&
!defined(global_parts_info.multimedia_multimedia_image_standard)) {

View File

@ -29,6 +29,9 @@ config("distributed_sched_config") {
if (dmsfwk_mission_manager) {
defines = [ "SUPPORT_DISTRIBUTED_MISSION_MANAGER" ]
}
if (dmsfwk_standard_form_share) {
defines += [ "SUPPORT_DISTRIBUTED_FORM_SHARE" ]
}
}
ohos_shared_library("distributedschedsvr") {
@ -81,6 +84,10 @@ ohos_shared_library("distributedschedsvr") {
deps = [ "//foundation/ability/dmsfwk/services/base:dmsbaseinner" ]
if (dmsfwk_standard_form_share) {
external_deps += [ "form_fwk:form_manager" ]
}
if (dmsfwk_mission_manager) {
defines = [ "SUPPORT_DISTRIBUTED_MISSION_MANAGER" ]
sources += [

View File

@ -20,6 +20,9 @@
#include "ability_info.h"
#include "ability_manager_interface.h"
#include "caller_info.h"
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
#include "form_share_info.h"
#endif
#include "iremote_broker.h"
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
#include "mission_info.h"
@ -115,6 +118,12 @@ public:
{
return 0;
}
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
virtual int32_t StartRemoteShareForm(const std::string &remoteDeviceId,
const OHOS::AppExecFwk::FormShareInfo &formShareInfo) = 0;
virtual int32_t StartShareFormFromRemote(
const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) = 0;
#endif
virtual int32_t RegisterDistributedComponentListener(const sptr<IRemoteObject>& callback) = 0;
virtual int32_t GetDistributedComponentList(std::vector<std::string>& distributedComponents) = 0;
enum {
@ -170,6 +179,10 @@ public:
// request code for upload distributed component info
REGISTER_DISTRIBUTED_COMPONENT_LISTENER = 160,
GET_DISTRIBUTED_COMPONENT_LIST = 161,
// form share
START_REMOTE_SHARE_FORM = 220,
START_SHARE_FORM_FROM_REMOTE = 221,
};
};
} // namespace DistributedSchedule

View File

@ -79,7 +79,12 @@ public:
int32_t callerUid, int32_t requestCode, uint32_t accessToken, const sptr<IRemoteObject>& callback) override;
int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override;
int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override;
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
int32_t StartRemoteShareForm(const std::string &remoteDeviceId,
const AppExecFwk::FormShareInfo &formShareInfo) override;
int32_t StartShareFormFromRemote(
const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo) override;
#endif
int32_t RegisterDistributedComponentListener(const sptr<IRemoteObject>& callback) override;
int32_t GetDistributedComponentList(std::vector<std::string>& distributedComponents) override;
private:

View File

@ -121,6 +121,12 @@ public:
const CallerInfo& callerInfo, const AccountInfo& accountInfo) override;
int32_t ReleaseAbilityFromRemote(const sptr<IRemoteObject>& connect, const AppExecFwk::ElementName &element,
const CallerInfo& callerInfo) override;
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
int32_t StartRemoteShareForm(const std::string &remoteDeviceId,
const AppExecFwk::FormShareInfo &formShareInfo) override;
int32_t StartShareFormFromRemote(
const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo) override;
#endif
void ProcessCallerDied(const sptr<IRemoteObject>& connect, int32_t deviceType);
void ProcessCalleeDied(const sptr<IRemoteObject>& connect);
int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode,
@ -160,6 +166,9 @@ private:
static int32_t GetUidLocked(const std::list<ConnectAbilitySession>& sessionList);
int32_t TryConnectRemoteAbility(const OHOS::AAFwk::Want& want,
const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo);
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
sptr<IRemoteObject> GetFormMgrProxy();
#endif
int32_t CleanMission(int32_t missionId);
int32_t SetCallerInfo(int32_t callerUid, std::string localDeviceId, uint32_t accessToken, CallerInfo& callerInfo);
int32_t SetWantForContinuation(AAFwk::Want& newWant, int32_t missionId);
@ -193,6 +202,9 @@ private:
std::mutex distributedLock_;
std::mutex connectLock_;
sptr<IRemoteObject::DeathRecipient> connectDeathRecipient_;
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
sptr<IRemoteObject> formMgrProxy_;
#endif
std::mutex calleeLock_;
std::map<sptr<IRemoteObject>, ConnectInfo> calleeMap_;
sptr<IRemoteObject::DeathRecipient> callerDeathRecipient_;

View File

@ -62,6 +62,10 @@ private:
int32_t StartRemoteFreeInstallInner(MessageParcel& data, MessageParcel& reply);
int32_t StartFreeInstallFromRemoteInner(MessageParcel& data, MessageParcel& reply);
int32_t NotifyCompleteFreeInstallFromRemoteInner(MessageParcel& data, MessageParcel& reply);
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
int32_t StartRemoteShareFormInner(MessageParcel &data, MessageParcel &reply);
int32_t StartShareFormFromRemoteInner(MessageParcel &data, MessageParcel &reply);
#endif
int32_t RegisterDistributedComponentListenerInner(MessageParcel& data, MessageParcel& reply);
int32_t GetDistributedComponentListInner(MessageParcel& data, MessageParcel& reply);
bool CheckDmsRequestPermission();

View File

@ -769,6 +769,64 @@ int32_t DistributedSchedProxy::NotifyCompleteFreeInstallFromRemote(int64_t taskI
PARCEL_TRANSACT_SYNC_RET_INT(remote, NOTIFY_COMPLETE_FREE_INSTALL_FROM_REMOTE, data, reply);
}
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
int32_t DistributedSchedProxy::StartRemoteShareForm(
const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo)
{
HILOGD("SHAREFORM:: func call");
if (remoteDeviceId.empty()) {
HILOGE("input params deviceId is nullptr.");
return INVALID_PARAMETERS_ERR;
}
auto remote = Remote();
if (remote == nullptr) {
HILOGE("fail to get dms remote.");
return DMSPROXY_SERVICE_ERR;
}
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
HILOGE("WriteInterfaceToken failed");
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, String, remoteDeviceId);
PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo);
PARCEL_TRANSACT_SYNC_RET_INT(remote, START_REMOTE_SHARE_FORM, data, reply);
}
int32_t DistributedSchedProxy::StartShareFormFromRemote(
const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo)
{
HILOGD("SHAREFORM:: func call");
if (remoteDeviceId.empty()) {
HILOGE("input params deviceId is nullptr.");
return INVALID_PARAMETERS_ERR;
}
auto remote = Remote();
if (remote == nullptr) {
HILOGE("fail to get dms remote.");
return DMSPROXY_SERVICE_ERR;
}
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
HILOGE("WriteInterfaceToken failed");
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, String, remoteDeviceId);
PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo);
PARCEL_TRANSACT_SYNC_RET_INT(remote, START_SHARE_FORM_FROM_REMOTE, data, reply);
}
#endif
int32_t DistributedSchedProxy::RegisterDistributedComponentListener(const sptr<IRemoteObject>& callback)
{
if (callback == nullptr) {

View File

@ -36,6 +36,9 @@
#include "dtbschedmgr_log.h"
#include "element_name.h"
#include "file_ex.h"
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
#include "form_mgr_interface.h"
#endif
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
@ -488,6 +491,29 @@ int32_t DistributedSchedService::NotifyContinuationResultFromRemote(int32_t sess
return ERR_OK;
}
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
sptr<IRemoteObject> DistributedSchedService::GetFormMgrProxy()
{
HILOGD("%{public}s begin.", __func__);
if (formMgrProxy_ != nullptr) {
HILOGD("%{public}s fms proxy get success.", __func__);
return formMgrProxy_;
}
auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sm == nullptr) {
HILOGE("GetAbilityManagerProxy sm is nullptr");
return nullptr;
}
formMgrProxy_ = sm->GetSystemAbility(FORM_MGR_SERVICE_ID);
if (formMgrProxy_ == nullptr) {
HILOGE("failed to get ability manager service");
return nullptr;
}
return formMgrProxy_;
}
#endif
void DistributedSchedService::NotifyContinuationCallbackResult(int32_t missionId, int32_t isSuccess)
{
HILOGD("Continuation result is: %{public}d", isSuccess);
@ -967,6 +993,63 @@ int32_t DistributedSchedService::ReleaseAbilityFromRemote(const sptr<IRemoteObje
return result;
}
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
int32_t DistributedSchedService::StartRemoteShareForm(const std::string &remoteDeviceId,
const OHOS::AppExecFwk::FormShareInfo &formShareInfo)
{
HILOGD("SHAREFORM:: func call");
if (remoteDeviceId.empty()) {
HILOGE("StartRemoteShareForm input params error");
return INVALID_PARAMETERS_ERR;
}
sptr<IDistributedSched> remoteDms = GetRemoteDms(remoteDeviceId);
if (remoteDms == nullptr) {
HILOGE("StartRemoteShareForm get remote DMS failed, remoteDeviceId : %{public}s",
DnetworkAdapter::AnonymizeDeviceId(remoteDeviceId).c_str());
return GET_REMOTE_DMS_FAIL;
}
int32_t result = remoteDms->StartShareFormFromRemote(remoteDeviceId, formShareInfo);
HILOGD("[PerformanceTest] StartRemoteShareForm RPC end");
if (result != ERR_OK) {
HILOGE("StartRemoteShareForm failed, result : %{public}d", result);
}
return result;
}
int32_t DistributedSchedService::StartShareFormFromRemote(
const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo)
{
HILOGD("SHAREFORM:: func call begin");
std::string localDeviceId = "";
GetLocalDeviceId(localDeviceId);
if (CheckDeviceId(localDeviceId, remoteDeviceId)) {
HILOGE("localId is %{public}s != %{public}s",
DnetworkAdapter::AnonymizeDeviceId(localDeviceId).c_str(),
DnetworkAdapter::AnonymizeDeviceId(remoteDeviceId).c_str());
return INVALID_REMOTE_PARAMETERS_ERR;
}
auto remote = GetFormMgrProxy();
if (remote == nullptr) {
HILOGE("Get remote proxy failed");
return NOT_FIND_SERVICE_PROXY;
}
auto formMgr = iface_cast<IFormMgr>(remote);
if (formMgr == nullptr) {
HILOGE("FormMgr type conversion failed");
return NOT_FIND_SERVICE_PROXY;
}
auto result = formMgr->RecvFormShareInfoFromRemote(formShareInfo);
HILOGD("SHAREFORM:: func call end");
return result;
}
#endif
int32_t DistributedSchedService::RegisterDistributedComponentListener(const sptr<IRemoteObject>& callback)
{
if (callback == nullptr) {

View File

@ -92,6 +92,10 @@ DistributedSchedStub::DistributedSchedStub()
localFuncsMap_[RELEASE_REMOTE_ABILITY] = &DistributedSchedStub::ReleaseRemoteAbilityInner;
remoteFuncsMap_[START_ABILITY_BY_CALL_FROM_REMOTE] = &DistributedSchedStub::StartAbilityByCallFromRemoteInner;
remoteFuncsMap_[RELEASE_ABILITY_FROM_REMOTE] = &DistributedSchedStub::ReleaseAbilityFromRemoteInner;
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
localFuncsMap_[START_REMOTE_SHARE_FORM] = &DistributedSchedStub::StartRemoteShareFormInner;
remoteFuncsMap_[START_SHARE_FORM_FROM_REMOTE] = &DistributedSchedStub::StartShareFormFromRemoteInner;
#endif
localFuncsMap_[REGISTER_DISTRIBUTED_COMPONENT_LISTENER] =
&DistributedSchedStub::RegisterDistributedComponentListenerInner;
localFuncsMap_[GET_DISTRIBUTED_COMPONENT_LIST] = &DistributedSchedStub::GetDistributedComponentListInner;
@ -859,6 +863,48 @@ int32_t DistributedSchedStub::ReleaseAbilityFromRemoteInner(MessageParcel& data,
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
}
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
int32_t DistributedSchedStub::StartRemoteShareFormInner(MessageParcel &data, MessageParcel &reply)
{
HILOGD("SHAREFORM:: func call");
std::string deviceId = "";
PARCEL_READ_HELPER(data, String, deviceId);
shared_ptr<AppExecFwk::FormShareInfo> formShareInfo(data.ReadParcelable<AppExecFwk::FormShareInfo>());
if (formShareInfo == nullptr) {
HILOGW("SHARE_FORM readParcelable failed!");
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, static_cast<int32_t>(ERR_FLATTEN_OBJECT));
return ERR_FLATTEN_OBJECT;
}
int32_t result = StartRemoteShareForm(deviceId, *formShareInfo);
HILOGI("result = %{public}d", result);
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
}
int32_t DistributedSchedStub::StartShareFormFromRemoteInner(MessageParcel &data, MessageParcel &reply)
{
HILOGD("SHAREFORM:: func call");
if (!CheckCallingUid()) {
HILOGW("request DENIED!");
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, static_cast<int32_t>(DMS_PERMISSION_DENIED));
return DMS_PERMISSION_DENIED;
}
std::string deviceId = "";
PARCEL_READ_HELPER(data, String, deviceId);
shared_ptr<AppExecFwk::FormShareInfo> formShareInfo(data.ReadParcelable<AppExecFwk::FormShareInfo>());
if (formShareInfo == nullptr) {
HILOGW("SHARE_FORM readParcelable failed!");
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, static_cast<int32_t>(ERR_FLATTEN_OBJECT));
return ERR_FLATTEN_OBJECT;
}
int32_t result = StartShareFormFromRemote(deviceId, *formShareInfo);
HILOGI("result = %{public}d", result);
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
}
#endif
int32_t DistributedSchedStub::RegisterDistributedComponentListenerInner(MessageParcel& data, MessageParcel& reply)
{
if (!CheckCallingUid()) {

View File

@ -54,6 +54,10 @@ dsched_external_deps = [
"utils_base:utils",
]
if (dmsfwk_standard_form_share) {
dsched_external_deps += [ "form_fwk:form_manager" ]
}
if (dmsfwk_mission_manager) {
dsched_external_deps += [ "multimedia_image_standard:image_native" ]
}
@ -153,6 +157,10 @@ ohos_unittest("dschedcontinuetest") {
defines = [ "SUPPORT_DISTRIBUTED_MISSION_MANAGER" ]
}
if (dmsfwk_standard_form_share) {
defines += [ "SUPPORT_DISTRIBUTED_FORM_SHARE" ]
}
part_name = "dmsfwk"
subsystem_name = "ability"
}

View File

@ -203,5 +203,19 @@ int32_t MockDistributedSched::NotifyCompleteFreeInstall(
{
return ERR_NONE;
}
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
int32_t MockDistributedSched::StartRemoteShareForm(const std::string &remoteDeviceId,
const OHOS::AppExecFwk::FormShareInfo &formShareInfo)
{
return ERR_NONE;
}
int32_t MockDistributedSched::StartShareFormFromRemote(
const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo)
{
return ERR_NONE;
}
#endif
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -75,6 +75,12 @@ public:
const CallerInfo& callerInfo) override;
int32_t RegisterDistributedComponentListener(const sptr<IRemoteObject>& callback) override;
int32_t GetDistributedComponentList(std::vector<std::string>& distributedComponents) override;
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
int32_t StartRemoteShareForm(const std::string &remoteDeviceId,
const OHOS::AppExecFwk::FormShareInfo &formShareInfo) override;
int32_t StartShareFormFromRemote(
const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) override;
#endif
int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode,
uint32_t accessToken, const sptr<IRemoteObject>& callback) override;
int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override;