diff options
Diffstat (limited to 'tools')
52 files changed, 512 insertions, 134 deletions
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp index c1cfd0b5f1e7..3c3edda85e4f 100644 --- a/tools/aapt/AaptAssets.cpp +++ b/tools/aapt/AaptAssets.cpp @@ -1309,8 +1309,8 @@ bail: status_t AaptAssets::filter(Bundle* bundle) { - WeakResourceFilter reqFilter; - status_t err = reqFilter.parse(bundle->getConfigurations()); + sp<WeakResourceFilter> reqFilter(new WeakResourceFilter()); + status_t err = reqFilter->parse(bundle->getConfigurations()); if (err != NO_ERROR) { return err; } @@ -1326,12 +1326,12 @@ status_t AaptAssets::filter(Bundle* bundle) preferredDensity = preferredConfig.density; } - if (reqFilter.isEmpty() && preferredDensity == 0) { + if (reqFilter->isEmpty() && preferredDensity == 0) { return NO_ERROR; } if (bundle->getVerbose()) { - if (!reqFilter.isEmpty()) { + if (!reqFilter->isEmpty()) { printf("Applying required filter: %s\n", bundle->getConfigurations().string()); } @@ -1383,7 +1383,7 @@ status_t AaptAssets::filter(Bundle* bundle) continue; } const ResTable_config& config(file->getGroupEntry().toParams()); - if (!reqFilter.match(config)) { + if (!reqFilter->match(config)) { if (bundle->getVerbose()) { printf("Pruning unneeded resource: %s\n", file->getPrintableSource().string()); diff --git a/tools/aapt/AaptAssets.h b/tools/aapt/AaptAssets.h index 4fdc9640e8e5..eadd48a6c261 100644 --- a/tools/aapt/AaptAssets.h +++ b/tools/aapt/AaptAssets.h @@ -103,7 +103,7 @@ struct AaptGroupEntry { public: AaptGroupEntry() {} - AaptGroupEntry(const ConfigDescription& config) : mParams(config) {} + explicit AaptGroupEntry(const ConfigDescription& config) : mParams(config) {} bool initFromDirName(const char* dir, String8* resType); @@ -312,7 +312,7 @@ public: : isPublic(false), isJavaSymbol(false), typeCode(TYPE_UNKNOWN) { } - AaptSymbolEntry(const String8& _name) + explicit AaptSymbolEntry(const String8& _name) : name(_name), isPublic(false), isJavaSymbol(false), typeCode(TYPE_UNKNOWN) { } diff --git a/tools/aapt/Android.mk b/tools/aapt/Android.mk index 2a490d1097ef..04f46d9b27fc 100644 --- a/tools/aapt/Android.mk +++ b/tools/aapt/Android.mk @@ -61,7 +61,7 @@ aaptHostStaticLibs := \ liblog \ libcutils \ libexpat \ - libziparchive-host \ + libziparchive \ libbase aaptCFlags := -DAAPT_VERSION=\"$(BUILD_NUMBER_FROM_FILE)\" diff --git a/tools/aapt/ApkBuilder.h b/tools/aapt/ApkBuilder.h index 0d7f06b1f323..5d3abc63519f 100644 --- a/tools/aapt/ApkBuilder.h +++ b/tools/aapt/ApkBuilder.h @@ -32,7 +32,7 @@ class AaptFile; class ApkBuilder : public android::RefBase { public: - ApkBuilder(const sp<WeakResourceFilter>& configFilter); + explicit ApkBuilder(const sp<WeakResourceFilter>& configFilter); /** * Tells the builder to generate a separate APK for resources that diff --git a/tools/aapt/CacheUpdater.h b/tools/aapt/CacheUpdater.h index 10a1bbc2f4aa..6fa96d67e6a3 100644 --- a/tools/aapt/CacheUpdater.h +++ b/tools/aapt/CacheUpdater.h @@ -51,7 +51,7 @@ private: class SystemCacheUpdater : public CacheUpdater { public: // Constructor to set bundle to pass to preProcessImage - SystemCacheUpdater (Bundle* b) + explicit SystemCacheUpdater (Bundle* b) : bundle(b) { }; // Make sure all the directories along this path exist diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp index ad583a8123d4..1dd43f79471d 100644 --- a/tools/aapt/Command.cpp +++ b/tools/aapt/Command.cpp @@ -248,7 +248,7 @@ bail: } static void printResolvedResourceAttribute(const ResTable& resTable, const ResXMLTree& tree, - uint32_t attrRes, String8 attrLabel, String8* outError) + uint32_t attrRes, const String8& attrLabel, String8* outError) { Res_value value; AaptXml::getResolvedResourceAttribute(resTable, tree, attrRes, &value, outError); @@ -399,7 +399,7 @@ static void printUsesImpliedPermission(const String8& name, const String8& reaso ResTable::normalizeForOutput(reason.string()).string()); } -Vector<String8> getNfcAidCategories(AssetManager& assets, String8 xmlPath, bool offHost, +Vector<String8> getNfcAidCategories(AssetManager& assets, const String8& xmlPath, bool offHost, String8 *outError = NULL) { Asset* aidAsset = assets.openNonAsset(xmlPath, Asset::ACCESS_BUFFER); diff --git a/tools/aapt/ConfigDescription.h b/tools/aapt/ConfigDescription.h index 4f999a2ff0c6..09430f2532fa 100644 --- a/tools/aapt/ConfigDescription.h +++ b/tools/aapt/ConfigDescription.h @@ -29,7 +29,7 @@ struct ConfigDescription : public android::ResTable_config { size = sizeof(android::ResTable_config); } - ConfigDescription(const android::ResTable_config&o) { + ConfigDescription(const android::ResTable_config&o) { // NOLINT(implicit) *static_cast<android::ResTable_config*>(this) = o; size = sizeof(android::ResTable_config); } diff --git a/tools/aapt/CrunchCache.cpp b/tools/aapt/CrunchCache.cpp index 0d574cf127dd..7b8a576b88d3 100644 --- a/tools/aapt/CrunchCache.cpp +++ b/tools/aapt/CrunchCache.cpp @@ -94,7 +94,7 @@ void CrunchCache::loadFiles() delete dw; } -bool CrunchCache::needsUpdating(String8 relativePath) const +bool CrunchCache::needsUpdating(const String8& relativePath) const { // Retrieve modification dates for this file entry under the source and // cache directory trees. The vectors will return a modification date of 0 diff --git a/tools/aapt/CrunchCache.h b/tools/aapt/CrunchCache.h index be3da5c40b25..4d6a16922f25 100644 --- a/tools/aapt/CrunchCache.h +++ b/tools/aapt/CrunchCache.h @@ -81,7 +81,7 @@ private: * // Recrunch sourceFile out to destFile. * */ - bool needsUpdating(String8 relativePath) const; + bool needsUpdating(const String8& relativePath) const; // DATA MEMBERS ==================================================== diff --git a/tools/aapt/FileFinder.cpp b/tools/aapt/FileFinder.cpp index 18775c06863f..c9d0744a4463 100644 --- a/tools/aapt/FileFinder.cpp +++ b/tools/aapt/FileFinder.cpp @@ -77,7 +77,7 @@ bool SystemFileFinder::findFiles(String8 basePath, Vector<String8>& extensions, return true; } -void SystemFileFinder::checkAndAddFile(String8 path, const struct stat* stats, +void SystemFileFinder::checkAndAddFile(const String8& path, const struct stat* stats, Vector<String8>& extensions, KeyedVector<String8,time_t>& fileStore) { diff --git a/tools/aapt/FileFinder.h b/tools/aapt/FileFinder.h index 6974aee033a8..f405381ee275 100644 --- a/tools/aapt/FileFinder.h +++ b/tools/aapt/FileFinder.h @@ -72,7 +72,7 @@ private: * time as the value. * */ - static void checkAndAddFile(String8 path, const struct stat* stats, + static void checkAndAddFile(const String8& path, const struct stat* stats, Vector<String8>& extensions, KeyedVector<String8,time_t>& fileStore); diff --git a/tools/aapt/Images.cpp b/tools/aapt/Images.cpp index aea16c715b95..5f586a15eeb8 100644 --- a/tools/aapt/Images.cpp +++ b/tools/aapt/Images.cpp @@ -833,6 +833,7 @@ static void dump_image(int w, int h, png_bytepp rows, int color_type) bpp = 4; } else { printf("Unknown color type %d.\n", color_type); + return; } for (j = 0; j < h; j++) { diff --git a/tools/aapt/IndentPrinter.h b/tools/aapt/IndentPrinter.h index 6fc94bc927b8..bd0edcbed8ad 100644 --- a/tools/aapt/IndentPrinter.h +++ b/tools/aapt/IndentPrinter.h @@ -3,7 +3,7 @@ class IndentPrinter { public: - IndentPrinter(FILE* stream, int indentSize=2) + explicit IndentPrinter(FILE* stream, int indentSize=2) : mStream(stream) , mIndentSize(indentSize) , mIndent(0) diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp index 5f91f17b05a3..3e8abb121c42 100644 --- a/tools/aapt/Resource.cpp +++ b/tools/aapt/Resource.cpp @@ -23,12 +23,8 @@ // STATUST: mingw does seem to redefine UNKNOWN_ERROR from our enum value, so a cast is necessary. #if !defined(_WIN32) -# define ZD "%zd" -# define ZD_TYPE ssize_t # define STATUST(x) x #else -# define ZD "%ld" -# define ZD_TYPE long # define STATUST(x) (status_t)x #endif @@ -399,7 +395,7 @@ static void collect_files(const sp<AaptDir>& dir, const DefaultKeyedVector<String8, sp<AaptGroup> >& groups = dir->getFiles(); int N = groups.size(); for (int i=0; i<N; i++) { - String8 leafName = groups.keyAt(i); + const String8& leafName = groups.keyAt(i); const sp<AaptGroup>& group = groups.valueAt(i); const DefaultKeyedVector<AaptGroupEntry, sp<AaptFile> >& files @@ -422,7 +418,7 @@ static void collect_files(const sp<AaptDir>& dir, set->add(leafName, group); resources->add(resType, set); } else { - sp<ResourceTypeSet> set = resources->valueAt(index); + const sp<ResourceTypeSet>& set = resources->valueAt(index); index = set->indexOfKey(leafName); if (index < 0) { if (kIsDebug) { @@ -457,7 +453,7 @@ static void collect_files(const sp<AaptAssets>& ass, int N = dirs.size(); for (int i=0; i<N; i++) { - sp<AaptDir> d = dirs.itemAt(i); + const sp<AaptDir>& d = dirs.itemAt(i); if (kIsDebug) { printf("Collecting dir #%d %p: %s, leaf %s\n", i, d.get(), d->getPath().string(), d->getLeaf().string()); @@ -615,7 +611,7 @@ static bool applyFileOverlay(Bundle *bundle, // get the overlay resources of the requested type ssize_t index = overlayRes->indexOfKey(resTypeString); if (index >= 0) { - sp<ResourceTypeSet> overlaySet = overlayRes->valueAt(index); + const sp<ResourceTypeSet>& overlaySet = overlayRes->valueAt(index); // for each of the resources, check for a match in the previously built // non-overlay "baseset". @@ -765,7 +761,7 @@ bool addTagAttribute(const sp<XMLNode>& node, const char* ns8, return addTagAttribute(node, ns8, attr8, value, errorOnFailedInsert, false); } -static void fullyQualifyClassName(const String8& package, sp<XMLNode> node, +static void fullyQualifyClassName(const String8& package, const sp<XMLNode>& node, const String16& attrName) { XMLNode::attribute_entry* attr = node->editAttribute( String16("http://schemas.android.com/apk/res/android"), attrName); @@ -1355,7 +1351,7 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets, sp<ApkBuil ResourceDirIterator it(resources->valueAt(index), String8("values")); ssize_t res; while ((res=it.next()) == NO_ERROR) { - sp<AaptFile> file = it.getFile(); + const sp<AaptFile>& file = it.getFile(); res = compileResourceFile(bundle, assets, file, it.getParams(), (current!=assets), &table); if (res != NO_ERROR) { @@ -2693,7 +2689,7 @@ status_t writeResourceSymbols(Bundle* bundle, const sp<AaptAssets>& assets, String8 dest(bundle->getRClassDir()); if (bundle->getMakePackageDirs()) { - String8 pkg(package); + const String8& pkg(package); const char* last = pkg.string(); const char* s = last-1; do { diff --git a/tools/aapt/ResourceFilter.h b/tools/aapt/ResourceFilter.h index d6430c0409cc..40d5b752000c 100644 --- a/tools/aapt/ResourceFilter.h +++ b/tools/aapt/ResourceFilter.h @@ -78,7 +78,7 @@ private: class StrongResourceFilter : public ResourceFilter { public: StrongResourceFilter() {} - StrongResourceFilter(const std::set<ConfigDescription>& configs) + explicit StrongResourceFilter(const std::set<ConfigDescription>& configs) : mConfigs(configs) {} android::status_t parse(const android::String8& str); @@ -106,7 +106,7 @@ private: */ class InverseResourceFilter : public ResourceFilter { public: - InverseResourceFilter(const android::sp<ResourceFilter>& filter) + explicit InverseResourceFilter(const android::sp<ResourceFilter>& filter) : mFilter(filter) {} bool match(const android::ResTable_config& config) const { diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp index 9cae00f778b4..661409e3d4bc 100644 --- a/tools/aapt/ResourceTable.cpp +++ b/tools/aapt/ResourceTable.cpp @@ -4081,7 +4081,7 @@ status_t ResourceTable::Type::applyPublicEntryOrder() j = 0; for (i=0; i<N; i++) { - sp<ConfigList> e = origOrder.itemAt(i); + const sp<ConfigList>& e = origOrder.itemAt(i); // There will always be enough room for the remaining entries. while (mOrderedConfigs.itemAt(j) != NULL) { j++; @@ -4203,7 +4203,7 @@ status_t ResourceTable::Package::applyPublicTypeOrder() size_t j=0; for (i=0; i<N; i++) { - sp<Type> t = origOrder.itemAt(i); + const sp<Type>& t = origOrder.itemAt(i); // There will always be enough room for the remaining types. while (mOrderedTypes.itemAt(j) != NULL) { j++; @@ -4636,7 +4636,7 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle) { c->getEntries(); const size_t entryCount = entries.size(); for (size_t ei = 0; ei < entryCount; ei++) { - sp<Entry> e = entries.valueAt(ei); + const sp<Entry>& e = entries.valueAt(ei); if (e == NULL || e->getType() != Entry::TYPE_BAG) { continue; } diff --git a/tools/aapt/StringPool.cpp b/tools/aapt/StringPool.cpp index 9908c44c6d1f..866291a3b678 100644 --- a/tools/aapt/StringPool.cpp +++ b/tools/aapt/StringPool.cpp @@ -14,12 +14,8 @@ // SSIZE: mingw does not have signed size_t == ssize_t. #if !defined(_WIN32) -# define ZD "%zd" -# define ZD_TYPE ssize_t # define SSIZE(x) x #else -# define ZD "%ld" -# define ZD_TYPE long # define SSIZE(x) (signed size_t)x #endif @@ -390,12 +386,12 @@ sp<AaptFile> StringPool::createStringBlock() #define ENCODE_LENGTH(str, chrsz, strSize) \ { \ - size_t maxMask = 1 << ((chrsz*8)-1); \ + size_t maxMask = 1 << (((chrsz)*8)-1); \ size_t maxSize = maxMask-1; \ - if (strSize > maxSize) { \ - *str++ = maxMask | ((strSize>>(chrsz*8))&maxSize); \ + if ((strSize) > maxSize) { \ + *(str)++ = maxMask | (((strSize)>>((chrsz)*8))&maxSize); \ } \ - *str++ = strSize; \ + *(str)++ = strSize; \ } status_t StringPool::writeStringBlock(const sp<AaptFile>& pool) diff --git a/tools/aapt/StringPool.h b/tools/aapt/StringPool.h index 4b0d920c3274..253bcca4f507 100644 --- a/tools/aapt/StringPool.h +++ b/tools/aapt/StringPool.h @@ -12,7 +12,6 @@ #include <androidfw/ResourceTypes.h> #include <utils/String16.h> -#include <utils/TypeHelpers.h> #include <sys/types.h> #include <sys/stat.h> @@ -41,7 +40,7 @@ class StringPool public: struct entry { entry() : offset(0) { } - entry(const String16& _value) : value(_value), offset(0), hasStyles(false) { } + explicit entry(const String16& _value) : value(_value), offset(0), hasStyles(false) { } entry(const entry& o) : value(o.value), offset(o.offset), hasStyles(o.hasStyles), indices(o.indices), configTypeName(o.configTypeName), configs(o.configs) { } @@ -179,13 +178,5 @@ private: Vector<size_t> mOriginalPosToNewPos; }; -// The entry types are trivially movable because all fields they contain, including -// the vectors and strings, are trivially movable. -namespace android { - ANDROID_TRIVIAL_MOVE_TRAIT(StringPool::entry); - ANDROID_TRIVIAL_MOVE_TRAIT(StringPool::entry_style_span); - ANDROID_TRIVIAL_MOVE_TRAIT(StringPool::entry_style); -}; - #endif diff --git a/tools/aapt/WorkQueue.h b/tools/aapt/WorkQueue.h index d38f05d034e9..ab5f9691c21d 100644 --- a/tools/aapt/WorkQueue.h +++ b/tools/aapt/WorkQueue.h @@ -47,7 +47,7 @@ public: }; /* Creates a work queue with the specified maximum number of work threads. */ - WorkQueue(size_t maxThreads, bool canCallJava = true); + explicit WorkQueue(size_t maxThreads, bool canCallJava = true); /* Destroys the work queue. * Cancels pending work and waits for all remaining threads to complete. diff --git a/tools/aapt/XMLNode.cpp b/tools/aapt/XMLNode.cpp index 5b215daeb494..15ec4afa52dd 100644 --- a/tools/aapt/XMLNode.cpp +++ b/tools/aapt/XMLNode.cpp @@ -67,7 +67,7 @@ static const String16 RESOURCES_PREFIX_AUTO_PACKAGE(RESOURCES_AUTO_PACKAGE_NAMES static const String16 RESOURCES_PRV_PREFIX(RESOURCES_ROOT_PRV_NAMESPACE); static const String16 RESOURCES_TOOLS_NAMESPACE("http://schemas.android.com/tools"); -String16 getNamespaceResourcePackage(String16 appPackage, String16 namespaceUri, bool* outIsPublic) +String16 getNamespaceResourcePackage(const String16& appPackage, const String16& namespaceUri, bool* outIsPublic) { //printf("%s starts with %s?\n", String8(namespaceUri).string(), // String8(RESOURCES_PREFIX).string()); @@ -98,7 +98,7 @@ String16 getNamespaceResourcePackage(String16 appPackage, String16 namespaceUri, status_t hasSubstitutionErrors(const char* fileName, ResXMLTree* inXml, - String16 str16) + const String16& str16) { const char16_t* str = str16.string(); const char16_t* p = str; diff --git a/tools/aapt/XMLNode.h b/tools/aapt/XMLNode.h index 749bf9f59bf7..ac920186fe63 100644 --- a/tools/aapt/XMLNode.h +++ b/tools/aapt/XMLNode.h @@ -178,7 +178,7 @@ private: XMLNode(const String8& filename, const String16& s1, const String16& s2, bool isNamespace); // Creating a CDATA node. - XMLNode(const String8& filename); + explicit XMLNode(const String8& filename); status_t collect_strings(StringPool* dest, Vector<uint32_t>* outResIds, bool stripComments, bool stripRawValues) const; diff --git a/tools/aapt/ZipEntry.cpp b/tools/aapt/ZipEntry.cpp index 54a8e9c9b247..5339285f5667 100644 --- a/tools/aapt/ZipEntry.cpp +++ b/tools/aapt/ZipEntry.cpp @@ -23,9 +23,10 @@ #include "ZipEntry.h" #include <utils/Log.h> +#include <assert.h> #include <stdio.h> #include <string.h> -#include <assert.h> +#include <time.h> using namespace android; diff --git a/tools/aapt/pseudolocalize.h b/tools/aapt/pseudolocalize.h index 1faecd14172d..9bb1fd8312b0 100644 --- a/tools/aapt/pseudolocalize.h +++ b/tools/aapt/pseudolocalize.h @@ -43,7 +43,7 @@ class PseudoMethodAccent : public PseudoMethodImpl { class Pseudolocalizer { public: - Pseudolocalizer(PseudolocalizationMethod m); + explicit Pseudolocalizer(PseudolocalizationMethod m); ~Pseudolocalizer() { if (mImpl) delete mImpl; } void setMethod(PseudolocalizationMethod m); String16 start() { return mImpl->start(); } diff --git a/tools/aapt2/Android.mk b/tools/aapt2/Android.mk index 4b5ea65d8fed..53225da14569 100644 --- a/tools/aapt2/Android.mk +++ b/tools/aapt2/Android.mk @@ -127,10 +127,10 @@ hostStaticLibs := \ liblog \ libcutils \ libexpat \ - libziparchive-host \ + libziparchive \ libpng \ libbase \ - libprotobuf-cpp-lite_static + libprotobuf-cpp-lite # Statically link libz for MinGW (Win SDK under Linux), @@ -142,7 +142,7 @@ hostLdLibs_darwin := -lz cFlags := -Wall -Werror -Wno-unused-parameter -UNDEBUG cFlags_darwin := -D_DARWIN_UNLIMITED_STREAMS cFlags_windows := -Wno-maybe-uninitialized # Incorrectly marking use of Maybe.value() as error. -cppFlags := -std=c++11 -Wno-missing-field-initializers -fno-exceptions -fno-rtti +cppFlags := -Wno-missing-field-initializers -fno-exceptions -fno-rtti protoIncludes := $(call generated-sources-dir-for,STATIC_LIBRARIES,libaapt2,HOST) # ========================================================== diff --git a/tools/aapt2/ConfigDescription.h b/tools/aapt2/ConfigDescription.h index 5749816f5124..b1397d2e2816 100644 --- a/tools/aapt2/ConfigDescription.h +++ b/tools/aapt2/ConfigDescription.h @@ -51,7 +51,7 @@ struct ConfigDescription : public android::ResTable_config { static void applyVersionForCompatibility(ConfigDescription* config); ConfigDescription(); - ConfigDescription(const android::ResTable_config& o); + ConfigDescription(const android::ResTable_config& o); // NOLINT(implicit) ConfigDescription(const ConfigDescription& o); ConfigDescription(ConfigDescription&& o); diff --git a/tools/aapt2/Resource.h b/tools/aapt2/Resource.h index 03ca42b286d6..9126b9592faa 100644 --- a/tools/aapt2/Resource.h +++ b/tools/aapt2/Resource.h @@ -98,7 +98,7 @@ struct ResourceNameRef { ResourceNameRef() = default; ResourceNameRef(const ResourceNameRef&) = default; ResourceNameRef(ResourceNameRef&&) = default; - ResourceNameRef(const ResourceName& rhs); + ResourceNameRef(const ResourceName& rhs); // NOLINT(implicit) ResourceNameRef(const StringPiece16& p, ResourceType t, const StringPiece16& e); ResourceNameRef& operator=(const ResourceNameRef& rhs) = default; ResourceNameRef& operator=(ResourceNameRef&& rhs) = default; @@ -124,7 +124,7 @@ struct ResourceId { ResourceId(); ResourceId(const ResourceId& rhs); - ResourceId(uint32_t resId); + ResourceId(uint32_t resId); // NOLINT(implicit) ResourceId(uint8_t p, uint8_t t, uint16_t e); bool isValid() const; diff --git a/tools/aapt2/ResourceTable.cpp b/tools/aapt2/ResourceTable.cpp index e700ed98365a..f9707e41bb3d 100644 --- a/tools/aapt2/ResourceTable.cpp +++ b/tools/aapt2/ResourceTable.cpp @@ -274,7 +274,7 @@ bool ResourceTable::addResource(const ResourceNameRef& name, } bool ResourceTable::addResource(const ResourceNameRef& name, - const ResourceId resId, + const ResourceId& resId, const ConfigDescription& config, const StringPiece& product, std::unique_ptr<Value> value, @@ -325,7 +325,7 @@ bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, } bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, - const ResourceId id, + const ResourceId& id, const ConfigDescription& config, const StringPiece& product, std::unique_ptr<Value> value, @@ -335,7 +335,7 @@ bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, } bool ResourceTable::addResourceImpl(const ResourceNameRef& name, - const ResourceId resId, + const ResourceId& resId, const ConfigDescription& config, const StringPiece& product, std::unique_ptr<Value> value, @@ -426,18 +426,18 @@ bool ResourceTable::addResourceImpl(const ResourceNameRef& name, return true; } -bool ResourceTable::setSymbolState(const ResourceNameRef& name, const ResourceId resId, +bool ResourceTable::setSymbolState(const ResourceNameRef& name, const ResourceId& resId, const Symbol& symbol, IDiagnostics* diag) { return setSymbolStateImpl(name, resId, symbol, kValidNameChars, diag); } bool ResourceTable::setSymbolStateAllowMangled(const ResourceNameRef& name, - const ResourceId resId, + const ResourceId& resId, const Symbol& symbol, IDiagnostics* diag) { return setSymbolStateImpl(name, resId, symbol, kValidNameMangledChars, diag); } -bool ResourceTable::setSymbolStateImpl(const ResourceNameRef& name, const ResourceId resId, +bool ResourceTable::setSymbolStateImpl(const ResourceNameRef& name, const ResourceId& resId, const Symbol& symbol, const char16_t* validChars, IDiagnostics* diag) { assert(diag && "diagnostics can't be nullptr"); diff --git a/tools/aapt2/ResourceTable.h b/tools/aapt2/ResourceTable.h index 5690ea6fa614..cf9e7b8bfc00 100644 --- a/tools/aapt2/ResourceTable.h +++ b/tools/aapt2/ResourceTable.h @@ -103,7 +103,7 @@ public: */ std::vector<std::unique_ptr<ResourceConfigValue>> values; - ResourceEntry(const StringPiece16& name) : name(name.toString()) { } + explicit ResourceEntry(const StringPiece16& name) : name(name.toString()) { } ResourceConfigValue* findValue(const ConfigDescription& config); ResourceConfigValue* findValue(const ConfigDescription& config, const StringPiece& product); @@ -200,7 +200,7 @@ public: IDiagnostics* diag); bool addResource(const ResourceNameRef& name, - const ResourceId resId, + const ResourceId& resId, const ConfigDescription& config, const StringPiece& product, std::unique_ptr<Value> value, @@ -231,19 +231,19 @@ public: IDiagnostics* diag); bool addResourceAllowMangled(const ResourceNameRef& name, - const ResourceId id, + const ResourceId& id, const ConfigDescription& config, const StringPiece& product, std::unique_ptr<Value> value, IDiagnostics* diag); bool setSymbolState(const ResourceNameRef& name, - const ResourceId resId, + const ResourceId& resId, const Symbol& symbol, IDiagnostics* diag); bool setSymbolStateAllowMangled(const ResourceNameRef& name, - const ResourceId resId, + const ResourceId& resId, const Symbol& symbol, IDiagnostics* diag); @@ -294,7 +294,7 @@ private: IDiagnostics* diag); bool addResourceImpl(const ResourceNameRef& name, - ResourceId resId, + const ResourceId& resId, const ConfigDescription& config, const StringPiece& product, std::unique_ptr<Value> value, @@ -303,7 +303,7 @@ private: IDiagnostics* diag); bool setSymbolStateImpl(const ResourceNameRef& name, - ResourceId resId, + const ResourceId& resId, const Symbol& symbol, const char16_t* validChars, IDiagnostics* diag); diff --git a/tools/aapt2/ResourceValues.h b/tools/aapt2/ResourceValues.h index aa1b550bdf09..9a6f1a1dff96 100644 --- a/tools/aapt2/ResourceValues.h +++ b/tools/aapt2/ResourceValues.h @@ -198,7 +198,7 @@ struct Id : public BaseItem<Id> { struct RawString : public BaseItem<RawString> { StringPool::Ref value; - RawString(const StringPool::Ref& ref); + explicit RawString(const StringPool::Ref& ref); bool equals(const Value* value) const override; bool flatten(android::Res_value* outValue) const override; @@ -209,7 +209,7 @@ struct RawString : public BaseItem<RawString> { struct String : public BaseItem<String> { StringPool::Ref value; - String(const StringPool::Ref& ref); + explicit String(const StringPool::Ref& ref); bool equals(const Value* value) const override; bool flatten(android::Res_value* outValue) const override; @@ -220,7 +220,7 @@ struct String : public BaseItem<String> { struct StyledString : public BaseItem<StyledString> { StringPool::StyleRef value; - StyledString(const StringPool::StyleRef& ref); + explicit StyledString(const StringPool::StyleRef& ref); bool equals(const Value* value) const override; bool flatten(android::Res_value* outValue) const override; @@ -237,7 +237,7 @@ struct FileReference : public BaseItem<FileReference> { io::IFile* file = nullptr; FileReference() = default; - FileReference(const StringPool::Ref& path); + explicit FileReference(const StringPool::Ref& path); bool equals(const Value* value) const override; bool flatten(android::Res_value* outValue) const override; @@ -252,7 +252,7 @@ struct BinaryPrimitive : public BaseItem<BinaryPrimitive> { android::Res_value value; BinaryPrimitive() = default; - BinaryPrimitive(const android::Res_value& val); + explicit BinaryPrimitive(const android::Res_value& val); BinaryPrimitive(uint8_t dataType, uint32_t data); bool equals(const Value* value) const override; @@ -272,7 +272,7 @@ struct Attribute : public BaseValue<Attribute> { int32_t maxInt; std::vector<Symbol> symbols; - Attribute(bool w, uint32_t t = 0u); + explicit Attribute(bool w, uint32_t t = 0u); bool equals(const Value* value) const override; Attribute* clone(StringPool* newPool) const override; diff --git a/tools/aapt2/SdkConstants.cpp b/tools/aapt2/SdkConstants.cpp index c2a22bf2a373..00bac05fb3b4 100644 --- a/tools/aapt2/SdkConstants.cpp +++ b/tools/aapt2/SdkConstants.cpp @@ -49,7 +49,7 @@ static bool lessEntryId(const std::pair<uint16_t, size_t>& p, uint16_t entryId) return p.first < entryId; } -size_t findAttributeSdkLevel(ResourceId id) { +size_t findAttributeSdkLevel(const ResourceId& id) { if (id.packageId() != 0x01 && id.typeId() != 0x01) { return 0; } diff --git a/tools/aapt2/SdkConstants.h b/tools/aapt2/SdkConstants.h index 282ed9a56f5c..8a7e3436ed6e 100644 --- a/tools/aapt2/SdkConstants.h +++ b/tools/aapt2/SdkConstants.h @@ -45,7 +45,7 @@ enum { SDK_MARSHMALLOW = 23, }; -size_t findAttributeSdkLevel(ResourceId id); +size_t findAttributeSdkLevel(const ResourceId& id); size_t findAttributeSdkLevel(const ResourceName& name); } // namespace aapt diff --git a/tools/aapt2/StringPool.h b/tools/aapt2/StringPool.h index 509e3041e081..9e1ca912796a 100644 --- a/tools/aapt2/StringPool.h +++ b/tools/aapt2/StringPool.h @@ -65,7 +65,7 @@ public: private: friend class StringPool; - Ref(Entry* entry); + explicit Ref(Entry* entry); Entry* mEntry; }; @@ -88,7 +88,7 @@ public: private: friend class StringPool; - StyleRef(StyleEntry* entry); + explicit StyleRef(StyleEntry* entry); StyleEntry* mEntry; }; diff --git a/tools/aapt2/util/Files.cpp b/tools/aapt2/util/Files.cpp index f5e49f11c082..042ff0e6c1b9 100644 --- a/tools/aapt2/util/Files.cpp +++ b/tools/aapt2/util/Files.cpp @@ -72,8 +72,8 @@ std::vector<std::string> listFiles(const StringPiece& root, std::string* outErro std::stringstream errorStr; errorStr << "unable to open file: " << strerror(errno); *outError = errorStr.str(); - return {}; } + return {}; } std::vector<std::string> files; diff --git a/tools/aapt2/util/Util.cpp b/tools/aapt2/util/Util.cpp index 5a87c334c59e..e07c88ec9579 100644 --- a/tools/aapt2/util/Util.cpp +++ b/tools/aapt2/util/Util.cpp @@ -430,7 +430,11 @@ std::u16string utf8ToUtf16(const StringPiece& utf8) { std::u16string utf16; utf16.resize(utf16Length); - utf8_to_utf16(reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length(), &*utf16.begin()); + utf8_to_utf16( + reinterpret_cast<const uint8_t*>(utf8.data()), + utf8.length(), + &*utf16.begin(), + (size_t) utf16Length + 1); return utf16; } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/libcore/io/BridgeBufferIterator.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/libcore/io/BridgeBufferIterator.java index 7e361a11f387..96cba783d367 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/libcore/io/BridgeBufferIterator.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/libcore/io/BridgeBufferIterator.java @@ -40,6 +40,11 @@ public class BridgeBufferIterator extends BufferIterator { } @Override + public int pos() { + return mByteBuffer.position(); + } + + @Override public void skip(int byteCount) { int newPosition = mByteBuffer.position() + byteCount; assert newPosition <= mSize; diff --git a/tools/layoutlib/bridge/tests/Android.mk b/tools/layoutlib/bridge/tests/Android.mk index 8a81d0b684db..465647606e52 100644 --- a/tools/layoutlib/bridge/tests/Android.mk +++ b/tools/layoutlib/bridge/tests/Android.mk @@ -28,7 +28,7 @@ LOCAL_JAVA_LIBRARIES := layoutlib \ layoutlib_api-prebuilt \ tools-common-prebuilt \ sdk-common \ - junit + junit-host include $(BUILD_HOST_JAVA_LIBRARY) diff --git a/tools/layoutlib/create/tests/Android.mk b/tools/layoutlib/create/tests/Android.mk index dafb9c6f9402..61e381d48b16 100644 --- a/tools/layoutlib/create/tests/Android.mk +++ b/tools/layoutlib/create/tests/Android.mk @@ -23,7 +23,7 @@ LOCAL_JAVA_RESOURCE_DIRS := data mock_data LOCAL_MODULE := layoutlib-create-tests LOCAL_MODULE_TAGS := optional -LOCAL_JAVA_LIBRARIES := layoutlib_create junit +LOCAL_JAVA_LIBRARIES := layoutlib_create junit-host LOCAL_STATIC_JAVA_LIBRARIES := asm-5.0 include $(BUILD_HOST_JAVA_LIBRARY) diff --git a/tools/preload2/Android.mk b/tools/preload2/Android.mk index 35d28fbfeba8..d3ee1d370855 100644 --- a/tools/preload2/Android.mk +++ b/tools/preload2/Android.mk @@ -3,30 +3,28 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(call all-java-files-under,src) -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk # To connect to devices (and take hprof dumps). -LOCAL_STATIC_JAVA_LIBRARIES := ddmlib-prebuilt +LOCAL_STATIC_JAVA_LIBRARIES := ddmlib-prebuilt tools-common-prebuilt # To process hprof dumps. LOCAL_STATIC_JAVA_LIBRARIES += perflib-prebuilt trove-prebuilt guavalib # For JDWP access we use the framework in the JDWP tests from Apache Harmony, for # convenience (and to not depend on internal JDK APIs). -LOCAL_STATIC_JAVA_LIBRARIES += apache-harmony-jdwp-tests-host junit +LOCAL_STATIC_JAVA_LIBRARIES += apache-harmony-jdwp-tests-host junit-host LOCAL_MODULE:= preload2 include $(BUILD_HOST_JAVA_LIBRARY) +# Copy to build artifacts +$(call dist-for-goals,dist_files,$(LOCAL_BUILT_MODULE):$(LOCAL_MODULE).jar) # Copy the preload-tool shell script to the host's bin directory. include $(CLEAR_VARS) LOCAL_IS_HOST_MODULE := true -LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := EXECUTABLES LOCAL_MODULE := preload-tool -include $(BUILD_SYSTEM)/base_rules.mk -$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/preload-tool $(ACP) - @echo "Copy: $(PRIVATE_MODULE) ($@)" - $(copy-file-to-new-target) - $(hide) chmod 755 $@ +LOCAL_SRC_FILES := preload-tool +LOCAL_REQUIRED_MODULES := preload2 +include $(BUILD_PREBUILT) diff --git a/tools/preload2/preload-tool b/tools/preload2/preload-tool index 36dbc1c775b1..322b62fda071 100644 --- a/tools/preload2/preload-tool +++ b/tools/preload2/preload-tool @@ -34,4 +34,4 @@ PROG_NAME="$(follow_links)" PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" ANDROID_ROOT=$PROG_DIR/.. -java -cp $ANDROID_ROOT/framework/preload2.jar com.android.preload.Main +java -cp $ANDROID_ROOT/framework/preload2.jar com.android.preload.Main $@ diff --git a/tools/preload2/src/com/android/preload/DeviceUtils.java b/tools/preload2/src/com/android/preload/DeviceUtils.java index 72de7b58b0a7..803a7f195a59 100644 --- a/tools/preload2/src/com/android/preload/DeviceUtils.java +++ b/tools/preload2/src/com/android/preload/DeviceUtils.java @@ -285,7 +285,7 @@ public class DeviceUtils { if (device == null) { try { - wait(timeout); + wfdl.wait(timeout); } catch (InterruptedException e) { // Ignore spurious wakeups. } @@ -304,7 +304,7 @@ public class DeviceUtils { if (!device.hasClients()) { try { - wait(timeout); + wfcl.wait(timeout); } catch (InterruptedException e) { // Ignore spurious wakeups. } diff --git a/tools/preload2/src/com/android/preload/Main.java b/tools/preload2/src/com/android/preload/Main.java index ca5b0e005a1d..c42a19b58811 100644 --- a/tools/preload2/src/com/android/preload/Main.java +++ b/tools/preload2/src/com/android/preload/Main.java @@ -32,12 +32,18 @@ import com.android.preload.actions.ShowDataAction; import com.android.preload.classdataretrieval.ClassDataRetriever; import com.android.preload.classdataretrieval.hprof.Hprof; import com.android.preload.classdataretrieval.jdwp.JDWPClassDataRetriever; -import com.android.preload.ui.UI; +import com.android.preload.ui.IUI; +import com.android.preload.ui.SequenceUI; +import com.android.preload.ui.SwingUI; +import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.NoSuchElementException; import javax.swing.Action; import javax.swing.DefaultListModel; @@ -66,7 +72,7 @@ public class Main { private DumpTableModel dataTableModel; private DefaultListModel<Client> clientListModel; - private UI ui; + private IUI ui; // Actions that need to be updated once a device is selected. private Collection<DeviceSpecific> deviceSpecificActions; @@ -85,17 +91,30 @@ public class Main { + "android.webkit.WebViewClassic\\$1$" + "|" + "java.lang.ProcessManager$" + "|" + "(.*\\$NoPreloadHolder$)"; + public final static String SCAN_ALL_CMD = "scan-all"; + public final static String SCAN_PACKAGE_CMD = "scan"; + public final static String COMPUTE_FILE_CMD = "comp"; + public final static String EXPORT_CMD = "export"; + public final static String IMPORT_CMD = "import"; + /** * @param args */ public static void main(String[] args) { - Main m = new Main(); - top = m; + Main m; + if (args.length > 0 && args[0].equals("--seq")) { + m = createSequencedMain(args); + } else { + m = new Main(new SwingUI()); + } + top = m; m.startUp(); } - public Main() { + public Main(IUI ui) { + this.ui = ui; + clientListModel = new DefaultListModel<Client>(); dataTableModel = new DumpTableModel(); @@ -124,11 +143,74 @@ public class Main { } } - ui = new UI(clientListModel, dataTableModel, actions); - ui.setVisible(true); + ui.prepare(clientListModel, dataTableModel, actions); + } + + /** + * @param args + * @return + */ + private static Main createSequencedMain(String[] args) { + SequenceUI ui = new SequenceUI(); + Main main = new Main(ui); + + Iterator<String> it = Arrays.asList(args).iterator(); + it.next(); // --seq + // Setup + ui.choice("#" + it.next()); // Device. + ui.confirmNo(); // Prepare: no. + // Actions + try { + while (it.hasNext()) { + String op = it.next(); + // Operation: Scan a single package + if (SCAN_PACKAGE_CMD.equals(op)) { + System.out.println("Scanning package."); + ui.action(ScanPackageAction.class); + ui.client(it.next()); + // Operation: Scan all packages + } else if (SCAN_ALL_CMD.equals(op)) { + System.out.println("Scanning all packages."); + ui.action(ScanAllPackagesAction.class); + // Operation: Export the output to a file + } else if (EXPORT_CMD.equals(op)) { + System.out.println("Exporting data."); + ui.action(ExportAction.class); + ui.output(new File(it.next())); + // Operation: Import the input from a file or directory + } else if (IMPORT_CMD.equals(op)) { + System.out.println("Importing data."); + File file = new File(it.next()); + if (!file.exists()) { + throw new RuntimeException( + String.format("File does not exist, %s.", file.getAbsolutePath())); + } else if (file.isFile()) { + ui.action(ImportAction.class); + ui.input(file); + } else if (file.isDirectory()) { + for (File content : file.listFiles()) { + ui.action(ImportAction.class); + ui.input(content); + } + } + // Operation: Compute preloaded classes with specific threshold + } else if (COMPUTE_FILE_CMD.equals(op)) { + System.out.println("Compute preloaded classes."); + ui.action(ComputeThresholdXAction.class); + ui.input(it.next()); + ui.confirmYes(); + ui.output(new File(it.next())); + } + } + } catch (NoSuchElementException e) { + System.out.println("Failed to parse action sequence correctly."); + throw e; + } + + return main; } - public static UI getUI() { + public static IUI getUI() { return top.ui; } @@ -176,6 +258,7 @@ public class Main { new ReloadListAction(clientUtils, getDevice(), clientListModel).run(); getUI().hideWaitDialog(); + getUI().ready(); } private void initDevice() { diff --git a/tools/preload2/src/com/android/preload/actions/AbstractThreadedAction.java b/tools/preload2/src/com/android/preload/actions/AbstractThreadedAction.java index fbf83d2e2339..5787d8507230 100644 --- a/tools/preload2/src/com/android/preload/actions/AbstractThreadedAction.java +++ b/tools/preload2/src/com/android/preload/actions/AbstractThreadedAction.java @@ -16,6 +16,7 @@ package com.android.preload.actions; +import com.android.preload.Main; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; @@ -28,7 +29,11 @@ public abstract class AbstractThreadedAction extends AbstractAction implements R @Override public void actionPerformed(ActionEvent e) { - new Thread(this).start(); + if (Main.getUI().isSingleThreaded()) { + run(); + } else { + new Thread(this).start(); + } } } diff --git a/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java b/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java index b524716fc2cb..3a7f7f74d755 100644 --- a/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java +++ b/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java @@ -32,14 +32,13 @@ import java.util.TreeSet; import java.util.regex.Pattern; import javax.swing.AbstractAction; -import javax.swing.JFileChooser; /** * Compute an intersection of classes from the given data. A class is in the intersection if it * appears in at least the number of threshold given packages. An optional blacklist can be * used to filter classes from the intersection. */ -public class ComputeThresholdAction extends AbstractAction implements Runnable { +public class ComputeThresholdAction extends AbstractThreadedAction { protected int threshold; private Pattern blacklist; private DumpTableModel dataTableModel; @@ -72,7 +71,7 @@ public class ComputeThresholdAction extends AbstractAction implements Runnable { return; } - new Thread(this).start(); + super.actionPerformed(e); } @Override @@ -92,10 +91,8 @@ public class ComputeThresholdAction extends AbstractAction implements Runnable { boolean ret = Main.getUI().showConfirmDialog("Computed a set with " + result.size() + " classes, would you like to save to disk?", "Save?"); if (ret) { - JFileChooser jfc = new JFileChooser(); - int ret2 = jfc.showSaveDialog(Main.getUI()); - if (ret2 == JFileChooser.APPROVE_OPTION) { - File f = jfc.getSelectedFile(); + File f = Main.getUI().showSaveDialog(); + if (f != null) { saveSet(result, f); } } diff --git a/tools/preload2/src/com/android/preload/actions/ExportAction.java b/tools/preload2/src/com/android/preload/actions/ExportAction.java index cb8b3df75b18..848a56826788 100644 --- a/tools/preload2/src/com/android/preload/actions/ExportAction.java +++ b/tools/preload2/src/com/android/preload/actions/ExportAction.java @@ -19,14 +19,11 @@ package com.android.preload.actions; import com.android.preload.DumpDataIO; import com.android.preload.DumpTableModel; import com.android.preload.Main; - import java.awt.event.ActionEvent; import java.io.File; import java.io.PrintWriter; -import javax.swing.AbstractAction; - -public class ExportAction extends AbstractAction implements Runnable { +public class ExportAction extends AbstractThreadedAction { private File lastSaveFile; private DumpTableModel dataTableModel; @@ -39,7 +36,7 @@ public class ExportAction extends AbstractAction implements Runnable { public void actionPerformed(ActionEvent e) { lastSaveFile = Main.getUI().showSaveDialog(); if (lastSaveFile != null) { - new Thread(this).start(); + super.actionPerformed(e); } } diff --git a/tools/preload2/src/com/android/preload/actions/ImportAction.java b/tools/preload2/src/com/android/preload/actions/ImportAction.java index 5c1976580f94..bfeeb836fd45 100644 --- a/tools/preload2/src/com/android/preload/actions/ImportAction.java +++ b/tools/preload2/src/com/android/preload/actions/ImportAction.java @@ -27,7 +27,7 @@ import java.util.Collection; import javax.swing.AbstractAction; -public class ImportAction extends AbstractAction implements Runnable { +public class ImportAction extends AbstractThreadedAction { private File[] lastOpenFiles; private DumpTableModel dataTableModel; @@ -40,7 +40,7 @@ public class ImportAction extends AbstractAction implements Runnable { public void actionPerformed(ActionEvent e) { lastOpenFiles = Main.getUI().showOpenDialog(true); if (lastOpenFiles != null) { - new Thread(this).start(); + super.actionPerformed(e); } } diff --git a/tools/preload2/src/com/android/preload/actions/RunMonkeyAction.java b/tools/preload2/src/com/android/preload/actions/RunMonkeyAction.java index 385e8577b1c8..29464fc7abdf 100644 --- a/tools/preload2/src/com/android/preload/actions/RunMonkeyAction.java +++ b/tools/preload2/src/com/android/preload/actions/RunMonkeyAction.java @@ -58,7 +58,12 @@ public class RunMonkeyAction extends AbstractAction implements DeviceSpecific { if (packages.isEmpty()) { packages = DEFAULT_MONKEY_PACKAGES; } - new Thread(new RunMonkeyRunnable(packages)).start(); + Runnable r = new RunMonkeyRunnable(packages); + if (Main.getUI().isSingleThreaded()) { + r.run(); + } else { + new Thread(r).start(); + } } private class RunMonkeyRunnable implements Runnable { diff --git a/tools/preload2/src/com/android/preload/classdataretrieval/hprof/Hprof.java b/tools/preload2/src/com/android/preload/classdataretrieval/hprof/Hprof.java index 21b7a04e07dc..84ec8b7d0fdd 100644 --- a/tools/preload2/src/com/android/preload/classdataretrieval/hprof/Hprof.java +++ b/tools/preload2/src/com/android/preload/classdataretrieval/hprof/Hprof.java @@ -171,6 +171,9 @@ public class Hprof implements ClassDataRetriever { arg1.getDevice().getSyncService().pullFile(arg0, target.getAbsoluteFile().toString(), new NullProgressMonitor()); } catch (Exception e) { + if (target != null) { + target.delete(); + } e.printStackTrace(); target = null; } @@ -189,6 +192,9 @@ public class Hprof implements ClassDataRetriever { out.write(arg0); out.close(); } catch (Exception e) { + if (target != null) { + target.delete(); + } e.printStackTrace(); target = null; } @@ -215,6 +221,8 @@ public class Hprof implements ClassDataRetriever { return analyzeHprof(hprofLocalFile); } catch (Exception e) { throw new RuntimeException(e); + } finally { + hprofLocalFile.delete(); } } } diff --git a/tools/preload2/src/com/android/preload/ui/IUI.java b/tools/preload2/src/com/android/preload/ui/IUI.java new file mode 100644 index 000000000000..9371463e9a79 --- /dev/null +++ b/tools/preload2/src/com/android/preload/ui/IUI.java @@ -0,0 +1,45 @@ +package com.android.preload.ui; + +import com.android.ddmlib.Client; +import java.io.File; +import java.util.List; +import javax.swing.Action; +import javax.swing.ListModel; +import javax.swing.table.TableModel; + +/** + * UI abstraction for the tool. This allows a graphical mode, command line mode, + * or silent mode. + */ +public interface IUI { + + void prepare(ListModel<Client> clientListModel, TableModel dataTableModel, + List<Action> actions); + + void ready(); + + boolean isSingleThreaded(); + + Client getSelectedClient(); + + int getSelectedDataTableRow(); + + void showWaitDialog(); + + void updateWaitDialog(String s); + + void hideWaitDialog(); + + void showMessageDialog(String s); + + boolean showConfirmDialog(String title, String message); + + String showInputDialog(String message); + + <T> T showChoiceDialog(String title, String message, T[] choices); + + File showSaveDialog(); + + File[] showOpenDialog(boolean multi); + +} diff --git a/tools/preload2/src/com/android/preload/ui/SequenceUI.java b/tools/preload2/src/com/android/preload/ui/SequenceUI.java new file mode 100644 index 000000000000..dc6a4f389b10 --- /dev/null +++ b/tools/preload2/src/com/android/preload/ui/SequenceUI.java @@ -0,0 +1,222 @@ +package com.android.preload.ui; + +import com.android.ddmlib.Client; +import com.android.ddmlib.ClientData; +import java.io.File; +import java.util.LinkedList; +import java.util.List; +import javax.swing.Action; +import javax.swing.ListModel; +import javax.swing.table.TableModel; + +public class SequenceUI implements IUI { + + private ListModel<Client> clientListModel; + @SuppressWarnings("unused") + private TableModel dataTableModel; + private List<Action> actions; + + private List<Object> sequence = new LinkedList<>(); + + public SequenceUI() { + } + + @Override + public boolean isSingleThreaded() { + return true; + } + + @Override + public void prepare(ListModel<Client> clientListModel, TableModel dataTableModel, + List<Action> actions) { + this.clientListModel = clientListModel; + this.dataTableModel = dataTableModel; + this.actions = actions; + } + + public SequenceUI action(Action a) { + sequence.add(a); + return this; + } + + public SequenceUI action(Class<? extends Action> actionClass) { + for (Action a : actions) { + if (actionClass.equals(a.getClass())) { + sequence.add(a); + return this; + } + } + throw new IllegalArgumentException("No action of class " + actionClass + " found."); + } + + public SequenceUI confirmYes() { + sequence.add(Boolean.TRUE); + return this; + } + + public SequenceUI confirmNo() { + sequence.add(Boolean.FALSE); + return this; + } + + public SequenceUI input(String input) { + sequence.add(input); + return this; + } + + public SequenceUI input(File... f) { + sequence.add(f); + return this; + } + + public SequenceUI output(File f) { + sequence.add(f); + return this; + } + + public SequenceUI tableRow(int i) { + sequence.add(i); + return this; + } + + private class ClientSelector { + private String pkg; + + public ClientSelector(String pkg) { + this.pkg = pkg; + } + + public Client getClient() { + for (int i = 0; i < clientListModel.getSize(); i++) { + ClientData cd = clientListModel.getElementAt(i).getClientData(); + if (cd != null) { + String s = cd.getClientDescription(); + if (pkg.equals(s)) { + return clientListModel.getElementAt(i); + } + } + } + throw new RuntimeException("Didn't find client " + pkg); + } + } + + public SequenceUI client(String pkg) { + sequence.add(new ClientSelector(pkg)); + return this; + } + + public SequenceUI choice(String pattern) { + sequence.add(pattern); + return this; + } + + @Override + public void ready() { + // Run the actions. + // No iterator or foreach loop as the sequence will be emptied while running. + try { + while (!sequence.isEmpty()) { + Object next = sequence.remove(0); + if (next instanceof Action) { + ((Action)next).actionPerformed(null); + } else { + throw new IllegalStateException("Didn't expect a non-action: " + next); + } + } + } catch (Exception e) { + e.printStackTrace(System.out); + } + + // Now shut down. + System.exit(0); + } + + @Override + public Client getSelectedClient() { + Object next = sequence.remove(0); + if (next instanceof ClientSelector) { + return ((ClientSelector)next).getClient(); + } + throw new IllegalStateException("Unexpected: " + next); + } + + @Override + public int getSelectedDataTableRow() { + Object next = sequence.remove(0); + if (next instanceof Integer) { + return ((Integer)next).intValue(); + } + throw new IllegalStateException("Unexpected: " + next); + } + + @Override + public void showWaitDialog() { + } + + @Override + public void updateWaitDialog(String s) { + System.out.println(s); + } + + @Override + public void hideWaitDialog() { + } + + @Override + public void showMessageDialog(String s) { + System.out.println(s); + } + + @Override + public boolean showConfirmDialog(String title, String message) { + Object next = sequence.remove(0); + if (next instanceof Boolean) { + return ((Boolean)next).booleanValue(); + } + throw new IllegalStateException("Unexpected: " + next); + } + + @Override + public String showInputDialog(String message) { + Object next = sequence.remove(0); + if (next instanceof String) { + return (String)next; + } + throw new IllegalStateException("Unexpected: " + next); + } + + @Override + public <T> T showChoiceDialog(String title, String message, T[] choices) { + Object next = sequence.remove(0); + if (next instanceof String) { + String s = (String)next; + for (T t : choices) { + if (t.toString().contains(s)) { + return t; + } + } + return null; + } + throw new IllegalStateException("Unexpected: " + next); + } + + @Override + public File showSaveDialog() { + Object next = sequence.remove(0); + if (next instanceof File) { + System.out.println(next); + return (File)next; + } + throw new IllegalStateException("Unexpected: " + next); + } + + @Override + public File[] showOpenDialog(boolean multi) { + Object next = sequence.remove(0); + if (next instanceof File[]) { + return (File[])next; + } + throw new IllegalStateException("Unexpected: " + next); + } + +} diff --git a/tools/preload2/src/com/android/preload/ui/UI.java b/tools/preload2/src/com/android/preload/ui/SwingUI.java index 47174ddd0e07..cab3744ad74c 100644 --- a/tools/preload2/src/com/android/preload/ui/UI.java +++ b/tools/preload2/src/com/android/preload/ui/SwingUI.java @@ -41,7 +41,7 @@ import javax.swing.ListModel; import javax.swing.SwingUtilities; import javax.swing.table.TableModel; -public class UI extends JFrame { +public class SwingUI extends JFrame implements IUI { private JList<Client> clientList; private JTable dataTable; @@ -49,11 +49,18 @@ public class UI extends JFrame { // Shared file chooser, means the directory is retained. private JFileChooser jfc; - public UI(ListModel<Client> clientListModel, - TableModel dataTableModel, - List<Action> actions) { + public SwingUI() { super("Preloaded-classes computation"); + } + + @Override + public boolean isSingleThreaded() { + return false; + } + @Override + public void prepare(ListModel<Client> clientListModel, TableModel dataTableModel, + List<Action> actions) { getContentPane().add(new JScrollPane(clientList = new JList<Client>(clientListModel)), BorderLayout.WEST); clientList.setCellRenderer(new ClientListCellRenderer()); @@ -74,18 +81,27 @@ public class UI extends JFrame { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 800, 600); + + setVisible(true); + } + + @Override + public void ready() { } + @Override public Client getSelectedClient() { return clientList.getSelectedValue(); } + @Override public int getSelectedDataTableRow() { return dataTable.getSelectedRow(); } private JDialog currentWaitDialog = null; + @Override public void showWaitDialog() { if (currentWaitDialog == null) { currentWaitDialog = new JDialog(this, "Please wait...", true); @@ -111,6 +127,7 @@ public class UI extends JFrame { }); } + @Override public void updateWaitDialog(String s) { if (currentWaitDialog != null) { ((JLabel) currentWaitDialog.getContentPane().getComponent(0)).setText(s); @@ -124,6 +141,7 @@ public class UI extends JFrame { } } + @Override public void hideWaitDialog() { if (currentWaitDialog != null) { currentWaitDialog.setVisible(false); @@ -131,6 +149,7 @@ public class UI extends JFrame { } } + @Override public void showMessageDialog(String s) { // Hide the wait dialog... if (currentWaitDialog != null) { @@ -147,6 +166,7 @@ public class UI extends JFrame { } } + @Override public boolean showConfirmDialog(String title, String message) { // Hide the wait dialog... if (currentWaitDialog != null) { @@ -164,6 +184,7 @@ public class UI extends JFrame { } } + @Override public String showInputDialog(String message) { // Hide the wait dialog... if (currentWaitDialog != null) { @@ -180,6 +201,7 @@ public class UI extends JFrame { } } + @Override @SuppressWarnings("unchecked") public <T> T showChoiceDialog(String title, String message, T[] choices) { // Hide the wait dialog... @@ -203,6 +225,7 @@ public class UI extends JFrame { } } + @Override public File showSaveDialog() { // Hide the wait dialog... if (currentWaitDialog != null) { @@ -228,6 +251,7 @@ public class UI extends JFrame { } } + @Override public File[] showOpenDialog(boolean multi) { // Hide the wait dialog... if (currentWaitDialog != null) { diff --git a/tools/split-select/Android.mk b/tools/split-select/Android.mk index 863abae1e0fb..4a1511eae43a 100644 --- a/tools/split-select/Android.mk +++ b/tools/split-select/Android.mk @@ -51,7 +51,7 @@ hostStaticLibs := \ liblog \ libcutils \ libexpat \ - libziparchive-host \ + libziparchive \ libbase cFlags := -Wall -Werror @@ -73,7 +73,7 @@ LOCAL_MODULE := libsplit-select LOCAL_MODULE_HOST_OS := darwin linux windows LOCAL_SRC_FILES := $(sources) - +LOCAL_STATIC_LIBRARIES := $(hostStaticLibs) LOCAL_C_INCLUDES := $(cIncludes) LOCAL_CFLAGS := $(cFlags) -D_DARWIN_UNLIMITED_STREAMS diff --git a/tools/split-select/SplitSelector.h b/tools/split-select/SplitSelector.h index 193fda7077d3..120354f608f3 100644 --- a/tools/split-select/SplitSelector.h +++ b/tools/split-select/SplitSelector.h @@ -29,7 +29,7 @@ namespace split { class SplitSelector { public: SplitSelector(); - SplitSelector(const android::Vector<SplitDescription>& splits); + explicit SplitSelector(const android::Vector<SplitDescription>& splits); android::Vector<SplitDescription> getBestSplits(const SplitDescription& target) const; |