Skip to content

Commit 73d44bb

Browse files
jmgaoGerrit Code Review
authored and
Gerrit Code Review
committed
Merge changes I90e10c74,I038d1df4,I4299bd96
* changes: adbd: delete unused variable. adb: move things around to prepare to add LZ4. adb: fix misindentation in Android.bp
2 parents d54a4bf + e485bdf commit 73d44bb

File tree

4 files changed

+44
-45
lines changed

4 files changed

+44
-45
lines changed

adb/Android.bp

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ cc_binary_host {
317317
static_libs: [
318318
"libadb_crypto",
319319
"libadb_host",
320-
"libadb_pairing_auth",
321-
"libadb_pairing_connection",
320+
"libadb_pairing_auth",
321+
"libadb_pairing_connection",
322322
"libadb_protos",
323323
"libadb_tls_connection",
324324
"libandroidfw",

adb/client/file_sync_client.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include "adb_client.h"
4343
#include "adb_io.h"
4444
#include "adb_utils.h"
45-
#include "brotli_utils.h"
45+
#include "compression_utils.h"
4646
#include "file_sync_protocol.h"
4747
#include "line_printer.h"
4848
#include "sysdeps/errno.h"
@@ -580,8 +580,8 @@ class SyncConnection {
580580

581581
while (true) {
582582
Block output;
583-
BrotliEncodeResult result = encoder.Encode(&output);
584-
if (result == BrotliEncodeResult::Error) {
583+
EncodeResult result = encoder.Encode(&output);
584+
if (result == EncodeResult::Error) {
585585
Error("compressing '%s' locally failed", lpath.c_str());
586586
return false;
587587
}
@@ -592,12 +592,12 @@ class SyncConnection {
592592
WriteOrDie(lpath, rpath, &sbuf, sizeof(SyncRequest) + output.size());
593593
}
594594

595-
if (result == BrotliEncodeResult::Done) {
595+
if (result == EncodeResult::Done) {
596596
sending = false;
597597
break;
598-
} else if (result == BrotliEncodeResult::NeedInput) {
598+
} else if (result == EncodeResult::NeedInput) {
599599
break;
600-
} else if (result == BrotliEncodeResult::MoreOutput) {
600+
} else if (result == EncodeResult::MoreOutput) {
601601
continue;
602602
}
603603
}
@@ -1076,9 +1076,9 @@ static bool sync_recv_v2(SyncConnection& sc, const char* rpath, const char* lpat
10761076

10771077
while (true) {
10781078
std::span<char> output;
1079-
BrotliDecodeResult result = decoder.Decode(&output);
1079+
DecodeResult result = decoder.Decode(&output);
10801080

1081-
if (result == BrotliDecodeResult::Error) {
1081+
if (result == DecodeResult::Error) {
10821082
sc.Error("decompress failed");
10831083
adb_unlink(lpath);
10841084
return false;
@@ -1097,15 +1097,15 @@ static bool sync_recv_v2(SyncConnection& sc, const char* rpath, const char* lpat
10971097
sc.RecordBytesTransferred(msg.data.size);
10981098
sc.ReportProgress(name != nullptr ? name : rpath, bytes_copied, expected_size);
10991099

1100-
if (result == BrotliDecodeResult::NeedInput) {
1100+
if (result == DecodeResult::NeedInput) {
11011101
break;
1102-
} else if (result == BrotliDecodeResult::MoreOutput) {
1102+
} else if (result == DecodeResult::MoreOutput) {
11031103
continue;
1104-
} else if (result == BrotliDecodeResult::Done) {
1104+
} else if (result == DecodeResult::Done) {
11051105
reading = false;
11061106
break;
11071107
} else {
1108-
LOG(FATAL) << "invalid BrotliDecodeResult: " << static_cast<int>(result);
1108+
LOG(FATAL) << "invalid DecodeResult: " << static_cast<int>(result);
11091109
}
11101110
}
11111111
}

adb/brotli_utils.h renamed to adb/compression_utils.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@
2323

2424
#include "types.h"
2525

26-
enum class BrotliDecodeResult {
26+
enum class DecodeResult {
27+
Error,
28+
Done,
29+
NeedInput,
30+
MoreOutput,
31+
};
32+
33+
enum class EncodeResult {
2734
Error,
2835
Done,
2936
NeedInput,
@@ -38,7 +45,7 @@ struct BrotliDecoder {
3845

3946
void Append(Block&& block) { input_buffer_.append(std::move(block)); }
4047

41-
BrotliDecodeResult Decode(std::span<char>* output) {
48+
DecodeResult Decode(std::span<char>* output) {
4249
size_t available_in = input_buffer_.front_size();
4350
const uint8_t* next_in = reinterpret_cast<const uint8_t*>(input_buffer_.front_data());
4451

@@ -56,16 +63,16 @@ struct BrotliDecoder {
5663

5764
switch (r) {
5865
case BROTLI_DECODER_RESULT_SUCCESS:
59-
return BrotliDecodeResult::Done;
66+
return DecodeResult::Done;
6067
case BROTLI_DECODER_RESULT_ERROR:
61-
return BrotliDecodeResult::Error;
68+
return DecodeResult::Error;
6269
case BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:
6370
// Brotli guarantees as one of its invariants that if it returns NEEDS_MORE_INPUT,
6471
// it will consume the entire input buffer passed in, so we don't have to worry
6572
// about bytes left over in the front block with more input remaining.
66-
return BrotliDecodeResult::NeedInput;
73+
return DecodeResult::NeedInput;
6774
case BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:
68-
return BrotliDecodeResult::MoreOutput;
75+
return DecodeResult::MoreOutput;
6976
}
7077
}
7178

@@ -75,13 +82,6 @@ struct BrotliDecoder {
7582
std::unique_ptr<BrotliDecoderState, void (*)(BrotliDecoderState*)> decoder_;
7683
};
7784

78-
enum class BrotliEncodeResult {
79-
Error,
80-
Done,
81-
NeedInput,
82-
MoreOutput,
83-
};
84-
8585
template <size_t OutputBlockSize>
8686
struct BrotliEncoder {
8787
explicit BrotliEncoder()
@@ -95,7 +95,7 @@ struct BrotliEncoder {
9595
void Append(Block input) { input_buffer_.append(std::move(input)); }
9696
void Finish() { finished_ = true; }
9797

98-
BrotliEncodeResult Encode(Block* output) {
98+
EncodeResult Encode(Block* output) {
9999
output->clear();
100100
while (true) {
101101
size_t available_in = input_buffer_.front_size();
@@ -112,7 +112,7 @@ struct BrotliEncoder {
112112

113113
if (!BrotliEncoderCompressStream(encoder_.get(), op, &available_in, &next_in,
114114
&available_out, &next_out, nullptr)) {
115-
return BrotliEncodeResult::Error;
115+
return EncodeResult::Error;
116116
}
117117

118118
size_t bytes_consumed = input_buffer_.front_size() - available_in;
@@ -123,14 +123,14 @@ struct BrotliEncoder {
123123
if (BrotliEncoderIsFinished(encoder_.get())) {
124124
output_block_.resize(OutputBlockSize - output_bytes_left_);
125125
*output = std::move(output_block_);
126-
return BrotliEncodeResult::Done;
126+
return EncodeResult::Done;
127127
} else if (output_bytes_left_ == 0) {
128128
*output = std::move(output_block_);
129129
output_block_.resize(OutputBlockSize);
130130
output_bytes_left_ = OutputBlockSize;
131-
return BrotliEncodeResult::MoreOutput;
131+
return EncodeResult::MoreOutput;
132132
} else if (input_buffer_.empty()) {
133-
return BrotliEncodeResult::NeedInput;
133+
return EncodeResult::NeedInput;
134134
}
135135
}
136136
}

adb/daemon/file_sync_service.cpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#include "adb_io.h"
5858
#include "adb_trace.h"
5959
#include "adb_utils.h"
60-
#include "brotli_utils.h"
60+
#include "compression_utils.h"
6161
#include "file_sync_protocol.h"
6262
#include "security_log_tags.h"
6363
#include "sysdeps/errno.h"
@@ -288,8 +288,8 @@ static bool handle_send_file_compressed(borrowed_fd s, unique_fd fd, uint32_t* t
288288

289289
while (true) {
290290
std::span<char> output;
291-
BrotliDecodeResult result = decoder.Decode(&output);
292-
if (result == BrotliDecodeResult::Error) {
291+
DecodeResult result = decoder.Decode(&output);
292+
if (result == DecodeResult::Error) {
293293
SendSyncFailErrno(s, "decompress failed");
294294
return false;
295295
}
@@ -299,14 +299,14 @@ static bool handle_send_file_compressed(borrowed_fd s, unique_fd fd, uint32_t* t
299299
return false;
300300
}
301301

302-
if (result == BrotliDecodeResult::NeedInput) {
302+
if (result == DecodeResult::NeedInput) {
303303
break;
304-
} else if (result == BrotliDecodeResult::MoreOutput) {
304+
} else if (result == DecodeResult::MoreOutput) {
305305
continue;
306-
} else if (result == BrotliDecodeResult::Done) {
306+
} else if (result == DecodeResult::Done) {
307307
break;
308308
} else {
309-
LOG(FATAL) << "invalid BrotliDecodeResult: " << static_cast<int>(result);
309+
LOG(FATAL) << "invalid DecodeResult: " << static_cast<int>(result);
310310
}
311311
}
312312
}
@@ -591,7 +591,6 @@ static bool do_send_v2(int s, const std::string& path, std::vector<char>& buffer
591591
static bool recv_uncompressed(borrowed_fd s, unique_fd fd, std::vector<char>& buffer) {
592592
syncmsg msg;
593593
msg.data.id = ID_DATA;
594-
std::optional<BrotliEncoder<SYNC_DATA_MAX>> encoder;
595594
while (true) {
596595
int r = adb_read(fd.get(), &buffer[0], buffer.size() - sizeof(msg.data));
597596
if (r <= 0) {
@@ -633,8 +632,8 @@ static bool recv_compressed(borrowed_fd s, unique_fd fd) {
633632

634633
while (true) {
635634
Block output;
636-
BrotliEncodeResult result = encoder.Encode(&output);
637-
if (result == BrotliEncodeResult::Error) {
635+
EncodeResult result = encoder.Encode(&output);
636+
if (result == EncodeResult::Error) {
638637
SendSyncFailErrno(s, "compress failed");
639638
return false;
640639
}
@@ -647,12 +646,12 @@ static bool recv_compressed(borrowed_fd s, unique_fd fd) {
647646
}
648647
}
649648

650-
if (result == BrotliEncodeResult::Done) {
649+
if (result == EncodeResult::Done) {
651650
sending = false;
652651
break;
653-
} else if (result == BrotliEncodeResult::NeedInput) {
652+
} else if (result == EncodeResult::NeedInput) {
654653
break;
655-
} else if (result == BrotliEncodeResult::MoreOutput) {
654+
} else if (result == EncodeResult::MoreOutput) {
656655
continue;
657656
}
658657
}

0 commit comments

Comments
 (0)