From e9d20f0ebb05cde2dc03f32ce1d010c89d11a2ff Mon Sep 17 00:00:00 2001 From: Alex Buynytskyy Date: Fri, 20 Mar 2020 10:45:51 -0700 Subject: [PATCH] Adding block kind to protocol for future streaming of a tree. Bug: b/152050621 Test: adb install --incremental megacity.apk Change-Id: Icf37dd93e8ce62eb973f54c896d64d475ed85d69 --- ...m_PackageManagerShellCommandDataLoader.cpp | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/services/core/jni/com_android_server_pm_PackageManagerShellCommandDataLoader.cpp b/services/core/jni/com_android_server_pm_PackageManagerShellCommandDataLoader.cpp index 5f0c8fe3f1f73..725036c9df0f0 100644 --- a/services/core/jni/com_android_server_pm_PackageManagerShellCommandDataLoader.cpp +++ b/services/core/jni/com_android_server_pm_PackageManagerShellCommandDataLoader.cpp @@ -51,7 +51,8 @@ using BlockSize = int16_t; using FileIdx = int16_t; using BlockIdx = int32_t; using NumBlocks = int32_t; -using CompressionType = int16_t; +using BlockType = int8_t; +using CompressionType = int8_t; using RequestType = int16_t; using MagicType = uint32_t; @@ -59,7 +60,7 @@ static constexpr int BUFFER_SIZE = 256 * 1024; static constexpr int BLOCKS_COUNT = BUFFER_SIZE / INCFS_DATA_FILE_BLOCK_SIZE; static constexpr int COMMAND_SIZE = 4 + 2 + 2 + 4; // bytes -static constexpr int HEADER_SIZE = 2 + 2 + 4 + 2; // bytes +static constexpr int HEADER_SIZE = 2 + 1 + 1 + 4 + 2; // bytes static constexpr std::string_view OKAY = "OKAY"sv; static constexpr MagicType INCR = 0x52434e49; // BE INCR @@ -110,6 +111,7 @@ const JniIds& jniIds(JNIEnv* env) { struct BlockHeader { FileIdx fileIdx = -1; + BlockType blockType = -1; CompressionType compressionType = -1; BlockIdx blockIdx = -1; BlockSize blockSize = -1; @@ -649,8 +651,8 @@ private: auto remainingData = std::span(data); while (!remainingData.empty()) { auto header = readHeader(remainingData); - if (header.fileIdx == -1 && header.compressionType == 0 && header.blockIdx == 0 && - header.blockSize == 0) { + if (header.fileIdx == -1 && header.blockType == 0 && header.compressionType == 0 && + header.blockIdx == 0 && header.blockSize == 0) { ALOGI("Stop signal received. Sending exit command (remaining bytes: %d).", int(remainingData.size())); @@ -658,8 +660,8 @@ private: mStopReceiving = true; break; } - if (header.fileIdx < 0 || header.blockSize <= 0 || header.compressionType < 0 || - header.blockIdx < 0) { + if (header.fileIdx < 0 || header.blockSize <= 0 || header.blockType < 0 || + header.compressionType < 0 || header.blockIdx < 0) { ALOGE("invalid header received. Abort."); mStopReceiving = true; break; @@ -687,7 +689,7 @@ private: .fileFd = writeFd, .pageIndex = static_cast(header.blockIdx), .compression = static_cast(header.compressionType), - .kind = INCFS_BLOCK_KIND_DATA, + .kind = static_cast(header.blockType), .dataSize = static_cast(header.blockSize), .data = (const char*)remainingData.data(), }; @@ -761,8 +763,8 @@ BlockHeader readHeader(std::span& data) { } header.fileIdx = static_cast(be16toh(*reinterpret_cast(&data[0]))); - header.compressionType = - static_cast(be16toh(*reinterpret_cast(&data[2]))); + header.blockType = static_cast(data[2]); + header.compressionType = static_cast(data[3]); header.blockIdx = static_cast(be32toh(*reinterpret_cast(&data[4]))); header.blockSize = static_cast(be16toh(*reinterpret_cast(&data[8])));