Merge "idmap2: fix clang-tidy warnings [modernize-*]"

This commit is contained in:
Todd Kennedy
2018-12-21 22:44:46 +00:00
committed by Android (Google) Code Review
32 changed files with 79 additions and 149 deletions

View File

@@ -29,8 +29,8 @@
using android::idmap2::CommandLineOptions;
typedef std::map<std::string, std::function<bool(const std::vector<std::string>&, std::ostream&)>>
NameToFunctionMap;
using NameToFunctionMap =
std::map<std::string, std::function<bool(const std::vector<std::string>&, std::ostream&)>>;
namespace {

View File

@@ -56,8 +56,7 @@ std::unique_ptr<std::vector<std::string>> FindApkFiles(const std::vector<std::st
}
paths.insert(apk_paths->cbegin(), apk_paths->cend());
}
return std::unique_ptr<std::vector<std::string>>(
new std::vector<std::string>(paths.cbegin(), paths.cend()));
return std::make_unique<std::vector<std::string>>(paths.cbegin(), paths.cend());
}
} // namespace
@@ -138,15 +137,15 @@ bool Scan(const std::vector<std::string>& args, std::ostream& out_error) {
}
std::stringstream stream;
for (auto iter = interesting_apks.cbegin(); iter != interesting_apks.cend(); ++iter) {
const std::string idmap_path = Idmap::CanonicalIdmapPathFor(output_directory, *iter);
for (const auto& apk : interesting_apks) {
const std::string idmap_path = Idmap::CanonicalIdmapPathFor(output_directory, apk);
std::stringstream dev_null;
if (!Verify(std::vector<std::string>({"--idmap-path", idmap_path}), dev_null) &&
!Create(std::vector<std::string>({
"--target-apk-path",
target_apk_path,
"--overlay-apk-path",
*iter,
apk,
"--idmap-path",
idmap_path,
}),

View File

@@ -56,8 +56,7 @@ Status error(const std::string& msg) {
} // namespace
namespace android {
namespace os {
namespace android::os {
Status Idmap2Service::getIdmapPath(const std::string& overlay_apk_path,
int32_t user_id ATTRIBUTE_UNUSED, std::string* _aidl_return) {
@@ -132,9 +131,8 @@ Status Idmap2Service::createIdmap(const std::string& target_apk_path,
return error("failed to write to idmap path " + idmap_path);
}
_aidl_return->reset(new std::string(idmap_path));
*_aidl_return = std::make_unique<std::string>(idmap_path);
return ok();
}
} // namespace os
} // namespace android
} // namespace android::os

View File

@@ -25,8 +25,8 @@
#include "android/os/BnIdmap2.h"
namespace android {
namespace os {
namespace android::os {
class Idmap2Service : public BinderService<Idmap2Service>, public BnIdmap2 {
public:
static char const* getServiceName() {
@@ -46,7 +46,7 @@ class Idmap2Service : public BinderService<Idmap2Service>, public BnIdmap2 {
const std::string& overlay_apk_path, int32_t user_id,
std::unique_ptr<std::string>* _aidl_return);
};
} // namespace os
} // namespace android
} // namespace android::os
#endif // IDMAP2_IDMAP2D_IDMAP2SERVICE_H_

View File

@@ -23,8 +23,7 @@
#include "idmap2/Idmap.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
class BinaryStreamVisitor : public Visitor {
public:
@@ -43,7 +42,6 @@ class BinaryStreamVisitor : public Visitor {
std::ostream& stream_;
};
} // namespace idmap2
} // namespace android
} // namespace android::idmap2
#endif // IDMAP2_INCLUDE_IDMAP2_BINARYSTREAMVISITOR_H_

View File

@@ -23,8 +23,7 @@
#include <string>
#include <vector>
namespace android {
namespace idmap2 {
namespace android::idmap2 {
/*
* Utility class to convert a command line, including options (--path foo.txt),
@@ -65,7 +64,6 @@ class CommandLineOptions {
std::string name_;
};
} // namespace idmap2
} // namespace android
} // namespace android::idmap2
#endif // IDMAP2_INCLUDE_IDMAP2_COMMANDLINEOPTIONS_H_

View File

@@ -22,9 +22,7 @@
#include <string>
#include <vector>
namespace android {
namespace idmap2 {
namespace utils {
namespace android::idmap2::utils {
constexpr const mode_t kIdmapFilePermissionMask = 0133; // u=rw,g=r,o=r
@@ -37,8 +35,6 @@ std::unique_ptr<std::string> ReadFile(int fd);
std::unique_ptr<std::string> ReadFile(const std::string& path);
} // namespace utils
} // namespace idmap2
} // namespace android
} // namespace android::idmap2::utils
#endif // IDMAP2_INCLUDE_IDMAP2_FILEUTILS_H_

View File

@@ -57,8 +57,7 @@
#include "androidfw/ResourceTypes.h"
#include "androidfw/StringPiece.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
class Idmap;
class Visitor;
@@ -271,7 +270,6 @@ class Visitor {
virtual void visit(const IdmapData::TypeEntry& type_entry) = 0;
};
} // namespace idmap2
} // namespace android
} // namespace android::idmap2
#endif // IDMAP2_INCLUDE_IDMAP2_IDMAP_H_

View File

@@ -25,14 +25,10 @@
#include "idmap2/Idmap.h"
#include "idmap2/Result.h"
namespace android {
namespace idmap2 {
namespace utils {
namespace android::idmap2::utils {
Result<std::string> WARN_UNUSED ResToTypeEntryName(const AssetManager2& am, ResourceId resid);
} // namespace utils
} // namespace idmap2
} // namespace android
} // namespace android::idmap2::utils
#endif // IDMAP2_INCLUDE_IDMAP2_RESOURCEUTILS_H_

View File

@@ -25,8 +25,7 @@
#include "androidfw/ResourceTypes.h"
#include "utils/String16.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
class Xml {
public:
@@ -45,7 +44,6 @@ class Xml {
DISALLOW_COPY_AND_ASSIGN(Xml);
};
} // namespace idmap2
} // namespace android
} // namespace android::idmap2
#endif // IDMAP2_INCLUDE_IDMAP2_XML_H_

View File

@@ -21,11 +21,10 @@
#include <string>
#include "android-base/macros.h"
#include "ziparchive/zip_archive.h"
#include "idmap2/Result.h"
#include "ziparchive/zip_archive.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
struct MemoryChunk {
size_t size;
@@ -56,7 +55,6 @@ class ZipFile {
DISALLOW_COPY_AND_ASSIGN(ZipFile);
};
} // namespace idmap2
} // namespace android
} // namespace android::idmap2
#endif // IDMAP2_INCLUDE_IDMAP2_ZIPFILE_H_

View File

@@ -22,8 +22,7 @@
#include "idmap2/BinaryStreamVisitor.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
void BinaryStreamVisitor::Write16(uint16_t value) {
uint16_t x = htodl(value);
@@ -77,5 +76,4 @@ void BinaryStreamVisitor::visit(const IdmapData::TypeEntry& type_entry) {
}
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -26,13 +26,11 @@
#include "idmap2/CommandLineOptions.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
std::unique_ptr<std::vector<std::string>> CommandLineOptions::ConvertArgvToVector(
int argc, const char** argv) {
return std::unique_ptr<std::vector<std::string>>(
new std::vector<std::string>(argv + 1, argv + argc));
return std::make_unique<std::vector<std::string>>(argv + 1, argv + argc);
}
CommandLineOptions& CommandLineOptions::OptionalFlag(const std::string& name,
@@ -111,8 +109,8 @@ bool CommandLineOptions::Parse(const std::vector<std::string>& argv, std::ostrea
}
if (!mandatory_opts.empty()) {
for (auto iter = mandatory_opts.cbegin(); iter != mandatory_opts.cend(); ++iter) {
outError << "error: " << *iter << ": missing mandatory option" << std::endl;
for (const auto& opt : mandatory_opts) {
outError << "error: " << opt << ": missing mandatory option" << std::endl;
}
Usage(outError);
return false;
@@ -159,5 +157,4 @@ void CommandLineOptions::Usage(std::ostream& out) const {
}
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -15,10 +15,10 @@
*/
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <cerrno>
#include <fstream>
#include <memory>
#include <string>
@@ -27,9 +27,7 @@
#include "idmap2/FileUtils.h"
namespace android {
namespace idmap2 {
namespace utils {
namespace android::idmap2::utils {
std::unique_ptr<std::vector<std::string>> FindFiles(const std::string& root, bool recurse,
const FindFilesPredicate& predicate) {
@@ -79,6 +77,4 @@ std::unique_ptr<std::string> ReadFile(int fd) {
return r == 0 ? std::move(str) : nullptr;
}
} // namespace utils
} // namespace idmap2
} // namespace android
} // namespace android::idmap2::utils

View File

@@ -36,8 +36,7 @@
#include "idmap2/Result.h"
#include "idmap2/ZipFile.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
namespace {
@@ -450,5 +449,4 @@ void Idmap::accept(Visitor* v) const {
}
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -24,8 +24,7 @@
#include "idmap2/ResourceUtils.h"
#include "idmap2/Result.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
#define RESID(pkg, type, entry) (((pkg) << 24) | ((type) << 16) | (entry))
@@ -73,5 +72,4 @@ void PrettyPrintVisitor::visit(const IdmapData::TypeEntry& type_entry) {
}
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -27,8 +27,7 @@
using android::ApkAssets;
namespace android {
namespace idmap2 {
namespace android::idmap2 {
// verbatim copy fomr PrettyPrintVisitor.cpp, move to common utils
#define RESID(pkg, type, entry) (((pkg) << 24) | ((type) << 16) | (entry))
@@ -127,5 +126,4 @@ void RawPrintVisitor::print(const std::string& value, const char* fmt, ...) {
offset_ += kIdmapStringLength;
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -25,9 +25,7 @@
using android::StringPiece16;
using android::util::Utf16ToUtf8;
namespace android {
namespace idmap2 {
namespace utils {
namespace android::idmap2::utils {
Result<std::string> WARN_UNUSED ResToTypeEntryName(const AssetManager2& am, ResourceId resid) {
AssetManager2::ResourceName name;
@@ -49,6 +47,4 @@ Result<std::string> WARN_UNUSED ResToTypeEntryName(const AssetManager2& am, Reso
return {out};
}
} // namespace utils
} // namespace idmap2
} // namespace android
} // namespace android::idmap2::utils

View File

@@ -21,8 +21,7 @@
#include "idmap2/Xml.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
std::unique_ptr<const Xml> Xml::Create(const uint8_t* data, size_t size, bool copyData) {
std::unique_ptr<Xml> xml(new Xml());
@@ -78,5 +77,4 @@ Xml::~Xml() {
xml_.uninit();
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -20,8 +20,7 @@
#include "idmap2/Result.h"
#include "idmap2/ZipFile.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
std::unique_ptr<MemoryChunk> MemoryChunk::Allocate(size_t size) {
void* ptr = ::operator new(sizeof(MemoryChunk) + size);
@@ -63,5 +62,4 @@ Result<uint32_t> ZipFile::Crc(const std::string& entryPath) const {
return status == 0 ? Result<uint32_t>(entry.crc32) : kResultError;
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -31,8 +31,7 @@
using ::testing::NotNull;
namespace android {
namespace idmap2 {
namespace android::idmap2 {
TEST(BinaryStreamVisitorTests, CreateBinaryStreamViaBinaryStreamVisitor) {
std::string raw(reinterpret_cast<const char*>(idmap_raw_data), idmap_raw_data_len);
@@ -124,5 +123,4 @@ TEST(BinaryStreamVisitorTests, CreateIdmapFromApkAssetsInteropWithLoadedIdmap) {
ASSERT_FALSE(success);
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -38,8 +38,7 @@
#include "TestHelpers.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
TEST(CommandLineOptionsTests, Flag) {
bool foo = true;
@@ -193,5 +192,4 @@ TEST(CommandLineOptionsTests, Usage) {
std::string::npos);
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -29,9 +29,7 @@
using ::testing::NotNull;
namespace android {
namespace idmap2 {
namespace utils {
namespace android::idmap2::utils {
TEST(FileUtilsTests, FindFilesFindEverythingNonRecursive) {
const auto& root = GetTestDataPath();
@@ -71,6 +69,4 @@ TEST(FileUtilsTests, ReadFile) {
close(pipefd[0]);
}
} // namespace utils
} // namespace idmap2
} // namespace android
} // namespace android::idmap2::utils

View File

@@ -46,8 +46,7 @@
using ::android::util::ExecuteBinary;
using ::testing::NotNull;
namespace android {
namespace idmap2 {
namespace android::idmap2 {
class Idmap2BinaryTests : public Idmap2Tests {};
@@ -313,5 +312,4 @@ TEST_F(Idmap2BinaryTests, InvalidCommandLineOptions) {
ASSERT_NE(result->status, EXIT_SUCCESS);
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -37,8 +37,7 @@
using ::testing::IsNull;
using ::testing::NotNull;
namespace android {
namespace idmap2 {
namespace android::idmap2 {
TEST(IdmapTests, TestCanonicalIdmapPathFor) {
ASSERT_EQ(Idmap::CanonicalIdmapPathFor("/foo", "/vendor/overlay/bar.apk"),
@@ -346,23 +345,23 @@ class TestVisitor : public Visitor {
explicit TestVisitor(std::ostream& stream) : stream_(stream) {
}
void visit(const Idmap& idmap ATTRIBUTE_UNUSED) {
void visit(const Idmap& idmap ATTRIBUTE_UNUSED) override {
stream_ << "TestVisitor::visit(Idmap)" << std::endl;
}
void visit(const IdmapHeader& idmap ATTRIBUTE_UNUSED) {
void visit(const IdmapHeader& idmap ATTRIBUTE_UNUSED) override {
stream_ << "TestVisitor::visit(IdmapHeader)" << std::endl;
}
void visit(const IdmapData& idmap ATTRIBUTE_UNUSED) {
void visit(const IdmapData& idmap ATTRIBUTE_UNUSED) override {
stream_ << "TestVisitor::visit(IdmapData)" << std::endl;
}
void visit(const IdmapData::Header& idmap ATTRIBUTE_UNUSED) {
void visit(const IdmapData::Header& idmap ATTRIBUTE_UNUSED) override {
stream_ << "TestVisitor::visit(IdmapData::Header)" << std::endl;
}
void visit(const IdmapData::TypeEntry& idmap ATTRIBUTE_UNUSED) {
void visit(const IdmapData::TypeEntry& idmap ATTRIBUTE_UNUSED) override {
stream_ << "TestVisitor::visit(IdmapData::TypeEntry)" << std::endl;
}
@@ -391,5 +390,4 @@ TEST(IdmapTests, TestVisitor) {
"TestVisitor::visit(IdmapData::TypeEntry)\n");
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -22,15 +22,13 @@
#include "TestHelpers.h"
namespace android {
namespace idmap2 {
namespace android::idmap2 {
std::string GetTestDataPath() {
return base::GetExecutableDirectory() + "/tests/data";
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);

View File

@@ -33,8 +33,7 @@ using ::testing::NotNull;
using android::ApkAssets;
namespace android {
namespace idmap2 {
namespace android::idmap2 {
TEST(PrettyPrintVisitorTests, CreatePrettyPrintVisitor) {
const std::string target_apk_path(GetTestDataPath() + "/target/target.apk");
@@ -78,5 +77,4 @@ TEST(PrettyPrintVisitorTests, CreatePrettyPrintVisitorWithoutAccessToApks) {
ASSERT_NE(stream.str().find("0x7f020000 -> 0x7f020000\n"), std::string::npos);
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -29,8 +29,7 @@
using ::testing::NotNull;
namespace android {
namespace idmap2 {
namespace android::idmap2 {
TEST(RawPrintVisitorTests, CreateRawPrintVisitor) {
const std::string target_apk_path(GetTestDataPath() + "/target/target.apk");
@@ -79,5 +78,4 @@ TEST(RawPrintVisitorTests, CreateRawPrintVisitorWithoutAccessToApks) {
ASSERT_NE(stream.str().find("0000021c: 00000000 0x7f020000 -> 0x7f020000\n"), std::string::npos);
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -28,8 +28,7 @@
using ::testing::NotNull;
namespace android {
namespace idmap2 {
namespace android::idmap2 {
class ResourceUtilsTests : public Idmap2Tests {
protected:
@@ -62,5 +61,4 @@ TEST_F(ResourceUtilsTests, ResToTypeEntryNameNoSuchResourceId) {
ASSERT_FALSE(name);
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -19,8 +19,7 @@
#include <string>
namespace android {
namespace idmap2 {
namespace android::idmap2 {
const unsigned char idmap_raw_data[] = {
// IDMAP HEADER
@@ -162,7 +161,6 @@ class Idmap2Tests : public testing::Test {
std::string idmap_path_;
};
} // namespace idmap2
} // namespace android
} // namespace android::idmap2
#endif // IDMAP2_TESTS_TESTHELPERS_H_

View File

@@ -27,8 +27,7 @@
using ::testing::IsNull;
using ::testing::NotNull;
namespace android {
namespace idmap2 {
namespace android::idmap2 {
TEST(XmlTests, Create) {
auto zip = ZipFile::Open(GetTestDataPath() + "/target/target.apk");
@@ -68,5 +67,4 @@ TEST(XmlTests, FindTag) {
ASSERT_THAT(fail, IsNull());
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2

View File

@@ -28,8 +28,7 @@
using ::testing::IsNull;
using ::testing::NotNull;
namespace android {
namespace idmap2 {
namespace android::idmap2 {
TEST(ZipFileTests, BasicOpen) {
auto zip = ZipFile::Open(GetTestDataPath() + "/target/target.apk");
@@ -66,5 +65,4 @@ TEST(ZipFileTests, Uncompress) {
ASSERT_THAT(fail, IsNull());
}
} // namespace idmap2
} // namespace android
} // namespace android::idmap2