mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-10-07 16:33:53 +00:00
commit
3e0205e774
@ -2877,6 +2877,12 @@ FormProviderInfo Ability::OnCreate(const Want &want)
|
|||||||
return formProviderInfo;
|
return formProviderInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Ability::OnShare(int64_t formId, AAFwk::WantParams &wantParams)
|
||||||
|
{
|
||||||
|
HILOG_DEBUG("%{public}s called.", __func__);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called to notify the form provider that a specified form has been deleted. Override this method if
|
* @brief Called to notify the form provider that a specified form has been deleted. Override this method if
|
||||||
* you want your application, as the form provider, to be notified of form deletion.
|
* you want your application, as the form provider, to be notified of form deletion.
|
||||||
|
@ -100,5 +100,11 @@ FormState FormExtension::OnAcquireFormState(const Want &want)
|
|||||||
HILOG_INFO("%{public}s called.", __func__);
|
HILOG_INFO("%{public}s called.", __func__);
|
||||||
return FormState::DEFAULT;
|
return FormState::DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FormExtension::OnShare(int64_t formId, AAFwk::WantParams &wantParams)
|
||||||
|
{
|
||||||
|
HILOG_DEBUG("%{public}s called.", __func__);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -514,5 +514,41 @@ int FormProviderClient::HandleAcquireStateResult(FormState state, const std::str
|
|||||||
HILOG_INFO("%{public}s end", __func__);
|
HILOG_INFO("%{public}s end", __func__);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t FormProviderClient::AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId,
|
||||||
|
const sptr<IRemoteObject> &formSupplyCallback, int64_t requestCode)
|
||||||
|
{
|
||||||
|
HILOG_DEBUG("FormProviderClient::%{public}s called.", __func__);
|
||||||
|
if (formId <= 0 || remoteDeviceId.empty() || formSupplyCallback == nullptr || requestCode <= 0) {
|
||||||
|
HILOG_ERROR("%{public}s error, Abnormal parameters exist.", __func__);
|
||||||
|
return ERR_APPEXECFWK_FORM_NO_SUCH_ABILITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Ability> ownerAbility = GetOwner();
|
||||||
|
if (ownerAbility == nullptr) {
|
||||||
|
HILOG_ERROR("%{public}s error, ownerAbility is nullptr.", __func__);
|
||||||
|
return ERR_APPEXECFWK_FORM_NO_SUCH_ABILITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
HILOG_DEBUG("%{public}s come, %{public}s.", __func__, ownerAbility->GetAbilityName().c_str());
|
||||||
|
|
||||||
|
if (!CheckIsSystemApp()) {
|
||||||
|
HILOG_WARN("%{public}s warn, AcquireProviderFormInfo caller permission denied.", __func__);
|
||||||
|
return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto formCall = iface_cast<IFormSupply>(formSupplyCallback);
|
||||||
|
if (formCall == nullptr) {
|
||||||
|
HILOG_ERROR("%{public}s error, callback is nullptr.", __func__);
|
||||||
|
return ERR_APPEXECFWK_FORM_NO_SUCH_ABILITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
AAFwk::WantParams wantParams;
|
||||||
|
auto result = ownerAbility->OnShare(formId, wantParams);
|
||||||
|
formCall->OnShareAcquire(formId, remoteDeviceId, wantParams, requestCode, result);
|
||||||
|
|
||||||
|
HILOG_DEBUG("%{public}s, call over", __func__);
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
} // namespace AppExecFwk
|
} // namespace AppExecFwk
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
|
@ -500,5 +500,46 @@ std::pair<int, int> FormExtensionProviderClient::CheckParam(const Want &want, co
|
|||||||
}
|
}
|
||||||
return std::pair<int, int>(ERR_OK, ERR_OK);
|
return std::pair<int, int>(ERR_OK, ERR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t FormExtensionProviderClient::AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId,
|
||||||
|
const sptr<IRemoteObject> &formSupplyCallback, int64_t requestCode)
|
||||||
|
{
|
||||||
|
HILOG_DEBUG("%{public}s called.", __func__);
|
||||||
|
|
||||||
|
if (!FormProviderClient::CheckIsSystemApp()) {
|
||||||
|
HILOG_ERROR("%{public}s warn, AcquireProviderFormInfo caller permission denied.", __func__);
|
||||||
|
return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<EventHandler> mainHandler = std::make_shared<EventHandler>(EventRunner::GetMainEventRunner());
|
||||||
|
auto formCall = iface_cast<IFormSupply>(formSupplyCallback);
|
||||||
|
if (formCall == nullptr) {
|
||||||
|
HILOG_ERROR("%{public}s error, callback is nullptr.", __func__);
|
||||||
|
return ERR_APPEXECFWK_FORM_NO_SUCH_ABILITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
AAFwk::WantParams wantParams;
|
||||||
|
bool result = false;
|
||||||
|
auto taskProc = [client = sptr<FormExtensionProviderClient>(this), formId, &wantParams, &result]() {
|
||||||
|
result = client->AcquireFormExtensionProviderShareFormInfo(formId, wantParams);
|
||||||
|
};
|
||||||
|
mainHandler->PostSyncTask(taskProc);
|
||||||
|
formCall->OnShareAcquire(formId, remoteDeviceId, wantParams, requestCode, result);
|
||||||
|
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FormExtensionProviderClient::AcquireFormExtensionProviderShareFormInfo(
|
||||||
|
int64_t formId, AAFwk::WantParams &wantParams)
|
||||||
|
{
|
||||||
|
HILOG_DEBUG("%{public}s called.", __func__);
|
||||||
|
std::shared_ptr<FormExtension> ownerFormExtension = GetOwner();
|
||||||
|
if (ownerFormExtension == nullptr) {
|
||||||
|
HILOG_ERROR("%{public}s error, ownerFormExtension is nullptr.", __func__);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ownerFormExtension->OnShare(formId, wantParams);
|
||||||
|
}
|
||||||
} // namespace AbilityRuntime
|
} // namespace AbilityRuntime
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
|
@ -384,5 +384,39 @@ FormState JsFormExtension::OnAcquireFormState(const Want &want)
|
|||||||
return (AppExecFwk::FormState) state;
|
return (AppExecFwk::FormState) state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool JsFormExtension::OnShare(int64_t formId, AAFwk::WantParams &wantParams)
|
||||||
|
{
|
||||||
|
HILOG_DEBUG("%{public}s called.", __func__);
|
||||||
|
HandleScope handleScope(jsRuntime_);
|
||||||
|
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||||
|
if (nativeEngine == nullptr) {
|
||||||
|
HILOG_ERROR("%{public}s OnShare get NativeEngine is nullptr", __func__);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto formIdStr = std::to_string(formId);
|
||||||
|
NativeValue* argv[] = { nativeEngine->CreateString(formIdStr.c_str(), formIdStr.length()) };
|
||||||
|
NativeValue* nativeResult = CallObjectMethod("onShare", argv, 1);
|
||||||
|
if (nativeResult == nullptr) {
|
||||||
|
HILOG_ERROR("%{public}s OnShare return value is nullptr", __func__);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nativeResult->TypeOf() != NativeValueType::NATIVE_OBJECT) {
|
||||||
|
HILOG_ERROR("%{public}s OnShare return value`s type is %{public}d", __func__,
|
||||||
|
static_cast<int32_t>(nativeResult->TypeOf()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!OHOS::AppExecFwk::UnwrapWantParams(reinterpret_cast<napi_env>(nativeEngine),
|
||||||
|
reinterpret_cast<napi_value>(nativeResult), wantParams)) {
|
||||||
|
HILOG_ERROR("%{public}s OnShare UnwrapWantParams failed, return false", __func__);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
HILOG_DEBUG("%{public}s called end.", __func__);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} // namespace AbilityRuntime
|
} // namespace AbilityRuntime
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
|
@ -1347,6 +1347,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual FormProviderInfo OnCreate(const Want &want);
|
virtual FormProviderInfo OnCreate(const Want &want);
|
||||||
|
|
||||||
|
virtual bool OnShare(int64_t formId, AAFwk::WantParams &wantParams);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called to notify the form provider that a specified form has been deleted. Override this method if
|
* @brief Called to notify the form provider that a specified form has been deleted. Override this method if
|
||||||
* you want your application, as the form provider, to be notified of form deletion.
|
* you want your application, as the form provider, to be notified of form deletion.
|
||||||
|
@ -138,6 +138,15 @@ public:
|
|||||||
* @return none.
|
* @return none.
|
||||||
*/
|
*/
|
||||||
virtual FormState OnAcquireFormState(const Want &want);
|
virtual FormState OnAcquireFormState(const Want &want);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Request currently shared data
|
||||||
|
*
|
||||||
|
* @param wantParams Indicates the form share information data.
|
||||||
|
*
|
||||||
|
* @return none.
|
||||||
|
*/
|
||||||
|
virtual bool OnShare(int64_t formId, AAFwk::WantParams &wantParams);
|
||||||
};
|
};
|
||||||
} // namespace AbilityRuntime
|
} // namespace AbilityRuntime
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
|
@ -135,6 +135,17 @@ public:
|
|||||||
virtual int AcquireState(const Want &wantArg, const std::string &provider, const Want &want,
|
virtual int AcquireState(const Want &wantArg, const std::string &provider, const Want &want,
|
||||||
const sptr<IRemoteObject> &callerToken) override;
|
const sptr<IRemoteObject> &callerToken) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Acquire to share form information data. This is sync API.
|
||||||
|
* @param formId The Id of the from.
|
||||||
|
* @param remoteDeviceId Indicates the remote device ID.
|
||||||
|
* @param formSupplyCallback Indicates lifecycle callbacks.
|
||||||
|
* @param requestCode Indicates the request code of this share form.
|
||||||
|
* @return Returns ERR_OK on success, others on failure.
|
||||||
|
*/
|
||||||
|
virtual int32_t AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId,
|
||||||
|
const sptr<IRemoteObject> &formSupplyCallback, int64_t requestCode) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the owner ability of the form provider client.
|
* @brief Set the owner ability of the form provider client.
|
||||||
*
|
*
|
||||||
|
@ -134,6 +134,17 @@ public:
|
|||||||
*/
|
*/
|
||||||
void ClearOwner(const std::shared_ptr<FormExtension> formExtension);
|
void ClearOwner(const std::shared_ptr<FormExtension> formExtension);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Acquire to share form information data. This is sync API.
|
||||||
|
* @param formId The Id of the from.
|
||||||
|
* @param remoteDeviceId Indicates the remote device ID.
|
||||||
|
* @param formSupplyCallback Indicates lifecycle callbacks.
|
||||||
|
* @param requestCode Indicates the request code of this share form.
|
||||||
|
* @return Returns ERR_OK on success, others on failure.
|
||||||
|
*/
|
||||||
|
virtual int32_t AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId,
|
||||||
|
const sptr<IRemoteObject> &formSupplyCallback, int64_t requestCode) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<FormExtension> GetOwner();
|
std::shared_ptr<FormExtension> GetOwner();
|
||||||
std::pair<int, int> CheckParam(const Want &want, const sptr<IRemoteObject> &callerToken);
|
std::pair<int, int> CheckParam(const Want &want, const sptr<IRemoteObject> &callerToken);
|
||||||
@ -154,6 +165,7 @@ private:
|
|||||||
const sptr<IRemoteObject> &callerToken);
|
const sptr<IRemoteObject> &callerToken);
|
||||||
void NotifyFormExtensionAcquireState(const Want &wantArg, const std::string &provider, const Want &want,
|
void NotifyFormExtensionAcquireState(const Want &wantArg, const std::string &provider, const Want &want,
|
||||||
const sptr<IRemoteObject> &callerToken);
|
const sptr<IRemoteObject> &callerToken);
|
||||||
|
bool AcquireFormExtensionProviderShareFormInfo(int64_t formId, AAFwk::WantParams &wantParams);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable std::mutex formExtensionMutex_;
|
mutable std::mutex formExtensionMutex_;
|
||||||
|
@ -60,6 +60,8 @@ public:
|
|||||||
|
|
||||||
FormState OnAcquireFormState(const Want &want) override;
|
FormState OnAcquireFormState(const Want &want) override;
|
||||||
|
|
||||||
|
bool OnShare(int64_t formId, AAFwk::WantParams &wantParams) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NativeValue* CallObjectMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0);
|
NativeValue* CallObjectMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0);
|
||||||
|
|
||||||
|
@ -70,5 +70,11 @@ int MockFormSupplyCallback::OnAcquireStateResult(FormState state, const std::str
|
|||||||
HILOG_INFO("MockFormSupplyCallback::OnAcquireStateResult called.");
|
HILOG_INFO("MockFormSupplyCallback::OnAcquireStateResult called.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MockFormSupplyCallback::OnShareAcquire(int64_t formId, const std::string &remoteDeviceId,
|
||||||
|
const AAFwk::WantParams &wantParams, int64_t requestCode, const bool &result)
|
||||||
|
{
|
||||||
|
HILOG_INFO("MockFormSupplyCallback::OnShareAcquire called.");
|
||||||
|
}
|
||||||
} // namespace AppExecFwk
|
} // namespace AppExecFwk
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
|
@ -56,6 +56,9 @@ public:
|
|||||||
virtual int OnAcquireStateResult(FormState state, const std::string &provider, const Want &wantArg,
|
virtual int OnAcquireStateResult(FormState state, const std::string &provider, const Want &wantArg,
|
||||||
const Want &want) override;
|
const Want &want) override;
|
||||||
|
|
||||||
|
virtual void OnShareAcquire(int64_t formId, const std::string &remoteDeviceId,
|
||||||
|
const AAFwk::WantParams &wantParams, int64_t requestCode, const bool &result) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::mutex mutex;
|
static std::mutex mutex;
|
||||||
static sptr<MockFormSupplyCallback> instance;
|
static sptr<MockFormSupplyCallback> instance;
|
||||||
|
Loading…
Reference in New Issue
Block a user