mirror of
https://gitee.com/openharmony/print_print_fwk
synced 2024-11-26 18:40:40 +00:00
commit
473c82b39e
@ -44,7 +44,8 @@ int32_t PrintCallbackStub::OnRemoteRequest(
|
||||
if (itFunc != cmdMap_.end()) {
|
||||
auto requestFunc = itFunc->second;
|
||||
if (requestFunc != nullptr) {
|
||||
return static_cast<int32_t>((this->*requestFunc)(data, reply));
|
||||
bool result = (this->*requestFunc)(data, reply);
|
||||
return result ? E_PRINT_NONE : E_PRINT_SERVER_FAILURE;
|
||||
}
|
||||
}
|
||||
PRINT_HILOGW("default case, need check.");
|
||||
|
@ -43,7 +43,8 @@ int32_t PrintExtensionCallbackStub::OnRemoteRequest(
|
||||
if (itFunc != cmdMap_.end()) {
|
||||
auto requestFunc = itFunc->second;
|
||||
if (requestFunc != nullptr) {
|
||||
return static_cast<int32_t>((this->*requestFunc)(data, reply));
|
||||
bool result = (this->*requestFunc)(data, reply);
|
||||
return result ? E_PRINT_NONE : E_PRINT_SERVER_FAILURE;
|
||||
}
|
||||
}
|
||||
PRINT_HILOGW("default case, need check.");
|
||||
|
@ -167,6 +167,10 @@ int32_t PrintServiceProxy::QueryAllExtension(std::vector<PrintExtensionInfo> &ex
|
||||
}
|
||||
|
||||
uint32_t len = reply.ReadUint32();
|
||||
if (len > PRINT_MAX_PRINT_COUNT) {
|
||||
PRINT_HILOGE("len is out of range.");
|
||||
return E_PRINT_INVALID_PARAMETER;
|
||||
}
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
auto infoPtr = PrintExtensionInfo::Unmarshalling(reply);
|
||||
if (infoPtr == nullptr) {
|
||||
@ -560,6 +564,10 @@ int32_t PrintServiceProxy::QueryAllPrintJob(std::vector<PrintJob> &printJobs)
|
||||
}
|
||||
|
||||
uint32_t len = reply.ReadUint32();
|
||||
if (len > PRINT_MAX_PRINT_COUNT) {
|
||||
PRINT_HILOGE("len is out of range.");
|
||||
return E_PRINT_INVALID_PARAMETER;
|
||||
}
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
auto jobPtr = PrintJob::Unmarshalling(reply);
|
||||
if (jobPtr == nullptr) {
|
||||
|
@ -44,7 +44,8 @@ int32_t ScanCallbackStub::OnRemoteRequest(
|
||||
if (itFunc != cmdMap_.end()) {
|
||||
auto requestFunc = itFunc->second;
|
||||
if (requestFunc != nullptr) {
|
||||
return static_cast<int32_t>((this->*requestFunc)(data, reply));
|
||||
bool result = (this->*requestFunc)(data, reply);
|
||||
return result ? E_SCAN_NONE : E_SCAN_SERVER_FAILURE;
|
||||
}
|
||||
}
|
||||
SCAN_HILOGW("default case, need check.");
|
||||
|
@ -506,6 +506,10 @@ int32_t ScanServiceProxy::GetAddedScanner(std::vector<ScanDeviceInfo>& allAddedS
|
||||
return ret;
|
||||
}
|
||||
uint32_t len = reply.ReadUint32();
|
||||
if (len > SCAN_MAX_COUNT) {
|
||||
SCAN_HILOGE("len is out of range.");
|
||||
return E_SCAN_INVALID_PARAMETER;
|
||||
}
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
auto infoPtr = ScanDeviceInfo::Unmarshalling(reply);
|
||||
if (infoPtr == nullptr) {
|
||||
|
@ -110,15 +110,19 @@ bool JsPrintExtension::InitContextObj(JsRuntime &jsRuntime, napi_value &extObj,
|
||||
napi_env engine = jsRuntime.GetNapiEnv();
|
||||
napi_value contextObj = CreateJsPrintExtensionContext(engine, context, extensionId);
|
||||
auto shellContextRef = jsRuntime.LoadSystemModule("PrintExtensionContext", &contextObj, NapiPrintUtils::ARGC_ONE);
|
||||
if (shellContextRef == nullptr) {
|
||||
PRINT_HILOGE("Failed to load print extension context ref");
|
||||
return false;
|
||||
}
|
||||
contextObj = shellContextRef->GetNapiValue();
|
||||
PRINT_HILOGD("JsPrintExtension::Init Bind.");
|
||||
context->Bind(jsRuntime, shellContextRef.release());
|
||||
PRINT_HILOGD("JsPrintExtension::napi_set_named_property.");
|
||||
napi_set_named_property(engine, extObj, "context", contextObj);
|
||||
if (contextObj == nullptr) {
|
||||
PRINT_HILOGE("Failed to get Print extension native object");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("JsPrintExtension::Init Bind.");
|
||||
context->Bind(jsRuntime, shellContextRef.release());
|
||||
PRINT_HILOGD("JsPrintExtension::napi_set_named_property.");
|
||||
napi_set_named_property(engine, extObj, "context", contextObj);
|
||||
|
||||
napi_wrap(engine, contextObj, new std::weak_ptr<AbilityRuntime::Context>(context),
|
||||
[](napi_env, void *data, void *) {
|
||||
|
@ -28,12 +28,12 @@ bool PrintCallbackProxy::OnCallback()
|
||||
MessageOption option;
|
||||
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
auto remote = Remote();
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
PRINT_HILOGE("SendRequest failed, error: remote is null");
|
||||
return false;
|
||||
}
|
||||
int error = Remote()->SendRequest(PRINT_CALLBACK_TASK, data, reply, option);
|
||||
int error = remote->SendRequest(PRINT_CALLBACK_TASK, data, reply, option);
|
||||
if (error != 0) {
|
||||
PRINT_HILOGE("SendRequest failed, error %{public}d", error);
|
||||
return false;
|
||||
@ -54,7 +54,12 @@ bool PrintCallbackProxy::OnCallback(uint32_t state, const PrinterInfo &info)
|
||||
data.WriteUint32(state);
|
||||
info.Marshalling(data);
|
||||
|
||||
int error = Remote()->SendRequest(PRINT_CALLBACK_PRINTER, data, reply, option);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
PRINT_HILOGE("SendRequest failed, error: remote is null");
|
||||
return false;
|
||||
}
|
||||
int error = remote->SendRequest(PRINT_CALLBACK_PRINTER, data, reply, option);
|
||||
if (error != 0) {
|
||||
PRINT_HILOGE("SendRequest failed, error %{public}d", error);
|
||||
return false;
|
||||
@ -75,7 +80,12 @@ bool PrintCallbackProxy::OnCallback(uint32_t state, const PrintJob &info)
|
||||
data.WriteUint32(state);
|
||||
info.Marshalling(data);
|
||||
|
||||
int error = Remote()->SendRequest(PRINT_CALLBACK_PRINT_JOB, data, reply, option);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
PRINT_HILOGE("SendRequest failed, error: remote is null");
|
||||
return false;
|
||||
}
|
||||
int error = remote->SendRequest(PRINT_CALLBACK_PRINT_JOB, data, reply, option);
|
||||
if (error != 0) {
|
||||
PRINT_HILOGE("SendRequest failed, error %{public}d", error);
|
||||
return false;
|
||||
@ -95,7 +105,12 @@ bool PrintCallbackProxy::OnCallback(const std::string &extensionId, const std::s
|
||||
data.WriteString(extensionId);
|
||||
data.WriteString(info);
|
||||
|
||||
int error = Remote()->SendRequest(PRINT_CALLBACK_EXTINFO, data, reply, option);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
PRINT_HILOGE("SendRequest failed, error: remote is null");
|
||||
return false;
|
||||
}
|
||||
int error = remote->SendRequest(PRINT_CALLBACK_EXTINFO, data, reply, option);
|
||||
if (error != 0) {
|
||||
PRINT_HILOGE("SendRequest failed, error %{public}d", error);
|
||||
return false;
|
||||
@ -122,7 +137,12 @@ bool PrintCallbackProxy::OnCallbackAdapterLayout(const std::string &jobId, const
|
||||
newAttrs.Marshalling(data);
|
||||
data.WriteFileDescriptor(fd);
|
||||
|
||||
int error = Remote()->SendRequest(PRINT_CALLBACK_PRINT_JOB_ADAPTER, data, reply, option);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
PRINT_HILOGE("SendRequest failed, error: remote is null");
|
||||
return false;
|
||||
}
|
||||
int error = remote->SendRequest(PRINT_CALLBACK_PRINT_JOB_ADAPTER, data, reply, option);
|
||||
if (error != 0) {
|
||||
PRINT_HILOGE("SendRequest failed, error %{public}d", error);
|
||||
return false;
|
||||
@ -148,7 +168,12 @@ bool PrintCallbackProxy::onCallbackAdapterJobStateChanged(const std::string jobI
|
||||
data.WriteUint32(state);
|
||||
data.WriteUint32(subState);
|
||||
|
||||
int error = Remote()->SendRequest(PRINT_CALLBACK_PRINT_JOB_CHANGED_ADAPTER, data, reply, option);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
PRINT_HILOGE("SendRequest failed, error: remote is null");
|
||||
return false;
|
||||
}
|
||||
int error = remote->SendRequest(PRINT_CALLBACK_PRINT_JOB_CHANGED_ADAPTER, data, reply, option);
|
||||
if (error != 0) {
|
||||
PRINT_HILOGE("SendRequest failed, error %{public}d", error);
|
||||
return false;
|
||||
@ -171,7 +196,12 @@ bool PrintCallbackProxy::OnCallbackAdapterGetFile(uint32_t state)
|
||||
|
||||
data.WriteUint32(state);
|
||||
|
||||
int error = Remote()->SendRequest(PRINT_CALLBACK_PRINT_GET_FILE_ADAPTER, data, reply, option);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
PRINT_HILOGE("SendRequest failed, error: remote is null");
|
||||
return false;
|
||||
}
|
||||
int error = remote->SendRequest(PRINT_CALLBACK_PRINT_GET_FILE_ADAPTER, data, reply, option);
|
||||
if (error != 0) {
|
||||
PRINT_HILOGE("SendRequest failed, error %{public}d", error);
|
||||
return false;
|
||||
|
@ -1681,10 +1681,12 @@ void ScanServiceAbility::GeneratePictureBatch(const std::string &scannerId, std:
|
||||
int32_t nowScanId = it->first;
|
||||
file_name = "scan_tmp" + std::to_string(nowScanId) + ".jpg";
|
||||
std::string outputDir = ObtainUserCacheDirectory(currentUseScannerUserId_);
|
||||
if (!std::filesystem::exists(outputDir)) {
|
||||
SCAN_HILOGE("outputDir %{public}s does not exist.", outputDir.c_str());
|
||||
char canonicalPath[PATH_MAX] = { 0 };
|
||||
if (realpath(outputDir.c_str(), canonicalPath) == nullptr) {
|
||||
SCAN_HILOGE("The real output dir is null, errno:%{public}s", std::to_string(errno).c_str());
|
||||
return;
|
||||
}
|
||||
outputDir = canonicalPath;
|
||||
output_file = outputDir.append("/").append(file_name);
|
||||
ofp = fopen(output_file.c_str(), "w");
|
||||
if (ofp == nullptr) {
|
||||
@ -1718,10 +1720,12 @@ void ScanServiceAbility::GeneratePictureSingle(const std::string &scannerId, std
|
||||
int32_t nowScanId = it->first;
|
||||
file_name = "scan_tmp" + std::to_string(nowScanId) + ".jpg";
|
||||
std::string outputDir = ObtainUserCacheDirectory(currentUseScannerUserId_);
|
||||
if (!std::filesystem::exists(outputDir)) {
|
||||
SCAN_HILOGE("outputDir %{public}s does not exist.", outputDir.c_str());
|
||||
char canonicalPath[PATH_MAX] = { 0 };
|
||||
if (realpath(outputDir.c_str(), canonicalPath) == nullptr) {
|
||||
SCAN_HILOGE("The real output dir is null, errno:%{public}s", std::to_string(errno).c_str());
|
||||
return;
|
||||
}
|
||||
outputDir = canonicalPath;
|
||||
output_file = outputDir.append("/").append(file_name);
|
||||
ofp = fopen(output_file.c_str(), "w");
|
||||
if (ofp == nullptr) {
|
||||
|
@ -65,7 +65,8 @@ int32_t ScanServiceStub::OnRemoteRequest(
|
||||
if (itFunc != cmdMap_.end()) {
|
||||
auto requestFunc = itFunc->second;
|
||||
if (requestFunc != nullptr) {
|
||||
return (this->*requestFunc)(data, reply);
|
||||
bool result = (this->*requestFunc)(data, reply);
|
||||
return result ? E_SCAN_NONE : E_SCAN_SERVER_FAILURE;
|
||||
}
|
||||
}
|
||||
SCAN_HILOGW("default case, need check.");
|
||||
|
@ -95,7 +95,7 @@ HWTEST_F(PrintCallbackStubTest, PrintCallbackStubTest_0003, TestSize.Level1)
|
||||
auto callback = std::make_shared<MockPrintCallbackStub>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(*callback, OnCallback()).Times(1);
|
||||
EXPECT_TRUE(static_cast<bool>(callback->OnRemoteRequest(code, data, reply, option)));
|
||||
EXPECT_EQ(callback->OnRemoteRequest(code, data, reply, option), E_PRINT_NONE);
|
||||
}
|
||||
|
||||
MATCHER_P(PrinterInfoMatcher, oParam, "Match Printer Info")
|
||||
@ -135,7 +135,7 @@ HWTEST_F(PrintCallbackStubTest, PrintCallbackStubTest_0004, TestSize.Level1)
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(*callback, OnCallback(testState,
|
||||
Matcher<const PrinterInfo&>(PrinterInfoMatcher(testInfo)))).Times(1).WillOnce(Return(true));
|
||||
EXPECT_TRUE(static_cast<bool>(callback->OnRemoteRequest(code, data, reply, option)));
|
||||
EXPECT_EQ(callback->OnRemoteRequest(code, data, reply, option), E_PRINT_NONE);
|
||||
EXPECT_TRUE(reply.ReadBool());
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ HWTEST_F(PrintCallbackStubTest, PrintCallbackStubTest_0005, TestSize.Level1)
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(*callback, OnCallback(testState,
|
||||
Matcher<const PrintJob&>(PrintJobMatcher(testJob)))).Times(1).WillOnce(Return(true));
|
||||
EXPECT_TRUE(static_cast<bool>(callback->OnRemoteRequest(code, data, reply, option)));
|
||||
EXPECT_EQ(callback->OnRemoteRequest(code, data, reply, option), E_PRINT_NONE);
|
||||
EXPECT_TRUE(reply.ReadBool());
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ HWTEST_F(PrintCallbackStubTest, PrintCallbackStubTest_0006, TestSize.Level1)
|
||||
auto callback = std::make_shared<MockPrintCallbackStub>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(*callback, OnCallback(extensionId, extInfo)).Times(1).WillOnce(Return(true));
|
||||
EXPECT_TRUE(static_cast<bool>(callback->OnRemoteRequest(code, data, reply, option)));
|
||||
EXPECT_EQ(callback->OnRemoteRequest(code, data, reply, option), E_PRINT_NONE);
|
||||
EXPECT_TRUE(reply.ReadBool());
|
||||
}
|
||||
} // namespace Print
|
||||
|
@ -90,7 +90,7 @@ HWTEST_F(PrintExtensionCallbackStubTest, PrintExtensionCallbackStubTest_0003, Te
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(IPrintExtensionCallback::GetDescriptor()));
|
||||
PrintExtensionCallbackStub callback;
|
||||
EXPECT_FALSE(callback.OnRemoteRequest(code, data, reply, option));
|
||||
EXPECT_EQ(callback.OnRemoteRequest(code, data, reply, option), E_PRINT_SERVER_FAILURE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,7 +112,7 @@ HWTEST_F(PrintExtensionCallbackStubTest, PrintExtensionCallbackStubTest_0004, Te
|
||||
return true;
|
||||
};
|
||||
callback.SetExtCallback(extCb);
|
||||
EXPECT_TRUE(callback.OnRemoteRequest(code, data, reply, option));
|
||||
EXPECT_EQ(callback.OnRemoteRequest(code, data, reply, option), E_PRINT_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,7 +130,7 @@ HWTEST_F(PrintExtensionCallbackStubTest, PrintExtensionCallbackStubTest_0005, Te
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(IPrintExtensionCallback::GetDescriptor()));
|
||||
PrintExtensionCallbackStub callback;
|
||||
EXPECT_FALSE(callback.OnRemoteRequest(code, data, reply, option));
|
||||
EXPECT_EQ(callback.OnRemoteRequest(code, data, reply, option), E_PRINT_SERVER_FAILURE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,7 +152,7 @@ HWTEST_F(PrintExtensionCallbackStubTest, PrintExtensionCallbackStubTest_0006, Te
|
||||
return true;
|
||||
};
|
||||
callback.SetPrintJobCallback(printJobCb);
|
||||
EXPECT_TRUE(callback.OnRemoteRequest(code, data, reply, option));
|
||||
EXPECT_EQ(callback.OnRemoteRequest(code, data, reply, option), E_PRINT_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,7 +170,7 @@ HWTEST_F(PrintExtensionCallbackStubTest, PrintExtensionCallbackStubTest_0007, Te
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(IPrintExtensionCallback::GetDescriptor()));
|
||||
PrintExtensionCallbackStub callback;
|
||||
EXPECT_FALSE(callback.OnRemoteRequest(code, data, reply, option));
|
||||
EXPECT_EQ(callback.OnRemoteRequest(code, data, reply, option), E_PRINT_SERVER_FAILURE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,7 +195,7 @@ HWTEST_F(PrintExtensionCallbackStubTest, PrintExtensionCallbackStubTest_0008, Te
|
||||
return true;
|
||||
};
|
||||
callback.SetPrinterCallback(printerCb);
|
||||
EXPECT_TRUE(callback.OnRemoteRequest(code, data, reply, option));
|
||||
EXPECT_EQ(callback.OnRemoteRequest(code, data, reply, option), E_PRINT_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -213,7 +213,7 @@ HWTEST_F(PrintExtensionCallbackStubTest, PrintExtensionCallbackStubTest_0009, Te
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(IPrintExtensionCallback::GetDescriptor()));
|
||||
PrintExtensionCallbackStub callback;
|
||||
EXPECT_FALSE(callback.OnRemoteRequest(code, data, reply, option));
|
||||
EXPECT_EQ(callback.OnRemoteRequest(code, data, reply, option), E_PRINT_SERVER_FAILURE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,7 +241,7 @@ HWTEST_F(PrintExtensionCallbackStubTest, PrintExtensionCallbackStubTest_0010, Te
|
||||
return true;
|
||||
};
|
||||
callback.SetCapabilityCallback(testCb);
|
||||
EXPECT_TRUE(callback.OnRemoteRequest(code, data, reply, option));
|
||||
EXPECT_EQ(callback.OnRemoteRequest(code, data, reply, option), E_PRINT_NONE);
|
||||
auto result = PrinterCapability::Unmarshalling(reply);
|
||||
EXPECT_NE(result, nullptr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user