Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add APK support #2921

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sharing/attachment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Attachment::Attachment(Attachment::Family family, int64_t size,

Attachment::Attachment(int64_t id, Attachment::Family family, int64_t size,
int32_t batch_id, SourceType source_type)
: id_(id),
: id_(id == 0 ? CreateRandomId() : id),
family_(family),
size_(size),
batch_id_(batch_id),
Expand Down
36 changes: 36 additions & 0 deletions sharing/incoming_share_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace nearby::sharing {
namespace {

using ::location::nearby::proto::sharing::OSType;
using ::nearby::sharing::service::proto::AppMetadata;
using ::nearby::sharing::service::proto::ConnectionResponseFrame;
using ::nearby::sharing::service::proto::IntroductionFrame;
using ::location::nearby::proto::sharing::ResponseToIntroduction;
Expand Down Expand Up @@ -116,6 +117,41 @@ IncomingShareSession::ProcessIntroduction(
file_size_sum += file.size();
}

for (const AppMetadata& apk : introduction_frame.app_metadata()) {
if (apk.size() <= 0) {
NL_LOG(WARNING)
<< __func__
<< ": Ignore introduction, due to invalid attachment size";
return TransferMetadata::Status::kUnsupportedAttachmentType;
}

VLOG(1) << __func__ << ": Found app attachment: id=" << apk.id()
<< ", app_name=" << apk.app_name()
<< ", package_name=" << apk.package_name()
<< ", size=" << apk.size();
if (std::numeric_limits<int64_t>::max() - apk.size() < file_size_sum) {
NL_LOG(WARNING) << __func__
<< ": Ignoring introduction, total file size overflowed "
"64 bit integer.";
container.Clear();
return TransferMetadata::Status::kNotEnoughSpace;
}
for (int index = 0; index < apk.file_name_size(); ++index) {
FileAttachment apk_file(
/*id=*/0, apk.file_size(index), apk.file_name(index),
/*mime_type=*/"", service::proto::FileMetadata::ANDROID_APP,
apk.package_name());
int64_t apk_file_id = apk_file.id();
VLOG(1) << __func__ << ": Found app file name: " << apk.file_name(index)
<< ", attachment id=" << apk_file_id
<< ", file size=" << apk.file_size(index)
<< ", payload_id=" << apk.payload_id(index);
container.AddFileAttachment(std::move(apk_file));
SetAttachmentPayloadId(apk_file_id, apk.payload_id(index));
}
file_size_sum += apk.size();
}

for (const auto& text : introduction_frame.text_metadata()) {
if (text.size() <= 0) {
NL_LOG(WARNING)
Expand Down
Loading