!7171 proxy超大函数整改

Merge pull request !7171 from savior-xzh/superfunction
This commit is contained in:
openharmony_ci 2023-12-18 10:23:00 +00:00 committed by Gitee
commit 04aa4b4c68
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -30,6 +30,15 @@
namespace OHOS {
namespace AAFwk {
namespace {
#define PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(messageParcel, type, value) \
do { \
if (!(messageParcel).Write##type(value)) { \
HILOG_ERROR("failed to write %{public}s", #value); \
return INNER_ERR; \
} \
} while (0)
}
using AutoStartupInfo = AbilityRuntime::AutoStartupInfo;
constexpr int32_t CYCLE_LIMIT = 1000;
constexpr int32_t MAX_AUTO_STARTUP_COUNT = 100;
@ -310,53 +319,29 @@ int AbilityManagerProxy::StartAbility(const Want &want, const StartOptions &star
int AbilityManagerProxy::StartAbilityAsCaller(const Want &want, const sptr<IRemoteObject> &callerToken,
sptr<IRemoteObject> asCallerSourceToken, int32_t userId, int requestCode, bool isSendDialogResult)
{
int error;
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(data)) {
return INNER_ERR;
}
if (!data.WriteParcelable(&want)) {
HILOG_ERROR("want write failed.");
return INNER_ERR;
}
PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
if (callerToken) {
if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
HILOG_ERROR("callerToken and flag write failed.");
return INNER_ERR;
}
PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
} else {
if (!data.WriteBool(false)) {
HILOG_ERROR("flag write failed.");
return INNER_ERR;
}
PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
}
if (asCallerSourceToken) {
if (!data.WriteBool(true) || !data.WriteRemoteObject(asCallerSourceToken)) {
HILOG_ERROR("asCallerSourceToken and flag write failed.");
return INNER_ERR;
}
PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, asCallerSourceToken);
} else {
if (!data.WriteBool(false)) {
HILOG_ERROR("flag write failed.");
return INNER_ERR;
}
PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
}
if (!data.WriteInt32(userId)) {
HILOG_ERROR("userId write failed.");
return INNER_ERR;
}
if (!data.WriteInt32(requestCode)) {
HILOG_ERROR("requestCode write failed.");
return INNER_ERR;
}
if (!data.WriteBool(isSendDialogResult)) {
HILOG_ERROR("isSendDialogResult write failed.");
return INNER_ERR;
}
error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_BY_TOKEN, data, reply, option);
PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, requestCode);
PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, isSendDialogResult);
int error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_BY_TOKEN, data, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Send request error: %{public}d", error);
return error;