Add a new variable length string to the idmap file format. This string will
hold debug information like fulfilled policies and any warnings triggered while
generating the file.
Bump the idmap version to 3.
Adjust the idmap header definition in ResourceType.h to take the new string
into account.
Example debug info:
$ idmap2 create \
--target-apk-path frameworks/base/cmds/idmap2/tests/data/target/target.apk \
--overlay-apk-path frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk \
--idmap-path /tmp/a.idmap \
--policy public \
--policy oem
$ idmap2 dump --idmap-path /tmp/a.idmap
target apk path : frameworks/base/cmds/idmap2/tests/data/target/target.apk
overlay apk path : frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk
I fulfilled_policies=oem|public enforce_overlayable=true
W failed to find resource "integer/not_in_target" in target resources
0x7f010000 -> 0x7f010000 integer/int1
0x7f02000c -> 0x7f020000 string/str1
[...]
$ idmap2 dump --idmap-path /tmp/a.idmap --verbose
00000000: 504d4449 magic
00000004: 00000003 version
00000008: 76a20829 target crc
0000000c: c054fb26 overlay crc
00000010: ........ target path: frameworks/base/cmds/idmap2/tests/data/target/target.apk
00000110: ........ overlay path: frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk
00000210: ........ debug info: ...
00000294: 7f target package id
00000295: 7f overlay package id
[...]
Also, tell cpplint to accept non-const references as function parameters:
they make more sense as out-parameters than pointers that are assumed to
be non-null.
Also, switch to regular expressions in the RawPrintVisitorTests: no more
manual fixups of the stream offsets! Tell cpplint that the <regex>
header is OK to use.
Bug: 140790707
Test: idmap2_tests
Change-Id: Ib94684a3b4001240321801e21af8e132fbcf6609
191 lines
6.8 KiB
C++
191 lines
6.8 KiB
C++
/*
|
|
* Copyright (C) 2018 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#ifndef IDMAP2_TESTS_TESTHELPERS_H_
|
|
#define IDMAP2_TESTS_TESTHELPERS_H_
|
|
|
|
#include <string>
|
|
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace android::idmap2 {
|
|
|
|
const unsigned char idmap_raw_data[] = {
|
|
// IDMAP HEADER
|
|
// 0x0: magic
|
|
0x49, 0x44, 0x4d, 0x50,
|
|
|
|
// 0x4: version
|
|
0x03, 0x00, 0x00, 0x00,
|
|
|
|
// 0x8: target crc
|
|
0x34, 0x12, 0x00, 0x00,
|
|
|
|
// 0xc: overlay crc
|
|
0x78, 0x56, 0x00, 0x00,
|
|
|
|
// 0x10: target path "targetX.apk"
|
|
0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
// 0x110: overlay path "overlayX.apk"
|
|
0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
// 0x210: debug string
|
|
// string length, including terminating null
|
|
0x08, 0x00, 0x00, 0x00,
|
|
|
|
// string contents "debug\0\0\0" (padded to word alignment)
|
|
0x64, 0x65, 0x62, 0x75, 0x67, 0x00, 0x00, 0x00,
|
|
|
|
// DATA HEADER
|
|
// 0x21c: target_package_id
|
|
0x7f,
|
|
|
|
// 0x21d: overlay_package_id
|
|
0x7f,
|
|
|
|
// 0x21e: target_entry_count
|
|
0x03, 0x00, 0x00, 0x00,
|
|
|
|
// 0x222: overlay_entry_count
|
|
0x03, 0x00, 0x00, 0x00,
|
|
|
|
// 0x226: string_pool_offset
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
// 0x22a: string_pool_byte_length
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
// TARGET ENTRIES
|
|
// 0x22e: 0x7f020000
|
|
0x00, 0x00, 0x02, 0x7f,
|
|
|
|
// 0x232: TYPE_REFERENCE
|
|
0x01,
|
|
|
|
// 0x233: 0x7f020000
|
|
0x00, 0x00, 0x02, 0x7f,
|
|
|
|
// 0x237: 0x7f030000
|
|
0x00, 0x00, 0x03, 0x7f,
|
|
|
|
// 0x23b: TYPE_REFERENCE
|
|
0x01,
|
|
|
|
// 0x23c: 0x7f030000
|
|
0x00, 0x00, 0x03, 0x7f,
|
|
|
|
// 0x240: 0x7f030002
|
|
0x02, 0x00, 0x03, 0x7f,
|
|
|
|
// 0x244: TYPE_REFERENCE
|
|
0x01,
|
|
|
|
// 0x245: 0x7f030001
|
|
0x01, 0x00, 0x03, 0x7f,
|
|
|
|
// OVERLAY ENTRIES
|
|
// 0x249: 0x7f020000 -> 0x7f020000
|
|
0x00, 0x00, 0x02, 0x7f, 0x00, 0x00, 0x02, 0x7f,
|
|
|
|
// 0x251: 0x7f030000 -> 0x7f030000
|
|
0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x03, 0x7f,
|
|
|
|
// 0x259: 0x7f030001 -> 0x7f030002
|
|
0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f};
|
|
|
|
const unsigned int idmap_raw_data_len = 0x261;
|
|
|
|
std::string GetTestDataPath();
|
|
|
|
class Idmap2Tests : public testing::Test {
|
|
protected:
|
|
void SetUp() override {
|
|
#ifdef __ANDROID__
|
|
tmp_dir_path_ = "/data/local/tmp/idmap2-tests-XXXXXX";
|
|
#else
|
|
tmp_dir_path_ = "/tmp/idmap2-tests-XXXXXX";
|
|
#endif
|
|
EXPECT_NE(mkdtemp(const_cast<char*>(tmp_dir_path_.c_str())), nullptr)
|
|
<< "Failed to create temporary directory: " << strerror(errno);
|
|
target_apk_path_ = GetTestDataPath() + "/target/target.apk";
|
|
overlay_apk_path_ = GetTestDataPath() + "/overlay/overlay.apk";
|
|
idmap_path_ = tmp_dir_path_ + "/a.idmap";
|
|
}
|
|
|
|
void TearDown() override {
|
|
EXPECT_EQ(rmdir(tmp_dir_path_.c_str()), 0)
|
|
<< "Failed to remove temporary directory " << tmp_dir_path_ << ": " << strerror(errno);
|
|
}
|
|
|
|
const std::string& GetTempDirPath() {
|
|
return tmp_dir_path_;
|
|
}
|
|
|
|
const std::string& GetTargetApkPath() {
|
|
return target_apk_path_;
|
|
}
|
|
|
|
const std::string& GetOverlayApkPath() {
|
|
return overlay_apk_path_;
|
|
}
|
|
|
|
const std::string& GetIdmapPath() {
|
|
return idmap_path_;
|
|
}
|
|
|
|
private:
|
|
std::string tmp_dir_path_;
|
|
std::string target_apk_path_;
|
|
std::string overlay_apk_path_;
|
|
std::string idmap_path_;
|
|
};
|
|
|
|
} // namespace android::idmap2
|
|
|
|
#endif // IDMAP2_TESTS_TESTHELPERS_H_
|