summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJosh Guilfoyle <Josh.Guilfoyle@T-Mobile.com>2010-12-23 14:30:28 -0800
committerJosh Guilfoyle <Josh.Guilfoyle@T-Mobile.com>2010-12-23 22:33:16 -0800
commitce9c0447f946d8fe20d020f01b6548c815579848 (patch)
tree27f4eac06f8960e31f9dfb670f4e67f11029e486 /tools
parent0e7ab2f533037698b4ab4255828fa2e08f90566f (diff)
parent6bcc7a7e5fc5a2340c4f060141bec9d181454807 (diff)
downloadframeworks_base-ce9c0447f946d8fe20d020f01b6548c815579848.zip
frameworks_base-ce9c0447f946d8fe20d020f01b6548c815579848.tar.gz
frameworks_base-ce9c0447f946d8fe20d020f01b6548c815579848.tar.bz2
Merge commit 'android-2.3.1_r1' into themes-exp-2.3.1_r1
Conflicts: core/java/android/app/ActivityThread.java core/java/android/content/pm/ApplicationInfo.java core/java/android/content/pm/PackageParser.java core/res/AndroidManifest.xml services/java/com/android/server/PackageManagerService.java services/java/com/android/server/SystemServer.java test-runner/src/android/test/mock/MockPackageManager.java
Diffstat (limited to 'tools')
-rw-r--r--tools/aapt/AaptAssets.cpp15
-rw-r--r--tools/aapt/Android.mk6
-rw-r--r--tools/aapt/Bundle.h10
-rw-r--r--tools/aapt/Command.cpp93
-rw-r--r--tools/aapt/Main.cpp34
-rw-r--r--tools/aapt/Resource.cpp77
-rw-r--r--tools/aapt/ResourceTable.cpp113
-rw-r--r--tools/aapt/XMLNode.cpp112
-rw-r--r--tools/aapt/XMLNode.h1
-rw-r--r--tools/aapt/ZipEntry.h10
-rw-r--r--tools/aidl/Android.mk5
-rw-r--r--tools/aidl/aidl.cpp2
-rw-r--r--tools/layoutlib/Android.mk20
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Paint.java2
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java11
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContentResolver.java113
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContext.java34
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeXmlPullAttributes.java23
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/ResourceHelper.java3
-rw-r--r--tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java1
-rw-r--r--tools/localize/Android.mk2
-rw-r--r--tools/obbtool/Android.mk46
-rw-r--r--tools/obbtool/Main.cpp301
-rwxr-xr-xtools/obbtool/mkobb.sh281
-rw-r--r--tools/obbtool/pbkdf2gen.cpp78
-rw-r--r--tools/preload/WritePreloadedClassFile.java13
-rw-r--r--tools/preload/loadclass/Android.mk1
27 files changed, 1309 insertions, 98 deletions
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp
index efc9619..e4f447e 100644
--- a/tools/aapt/AaptAssets.cpp
+++ b/tools/aapt/AaptAssets.cpp
@@ -766,6 +766,11 @@ bool AaptGroupEntry::getScreenLayoutSizeName(const char* name,
(out->screenLayout&~ResTable_config::MASK_SCREENSIZE)
| ResTable_config::SCREENSIZE_LARGE;
return true;
+ } else if (strcmp(name, "xlarge") == 0) {
+ if (out) out->screenLayout =
+ (out->screenLayout&~ResTable_config::MASK_SCREENSIZE)
+ | ResTable_config::SCREENSIZE_XLARGE;
+ return true;
}
return false;
@@ -1825,6 +1830,16 @@ ssize_t AaptAssets::slurpResourceTree(Bundle* bundle, const String8& srcDir)
continue;
}
+ if (bundle->getMaxResVersion() != NULL && group.version.length() != 0) {
+ int maxResInt = atoi(bundle->getMaxResVersion());
+ const char *verString = group.version.string();
+ int dirVersionInt = atoi(verString + 1); // skip 'v' in version name
+ if (dirVersionInt > maxResInt) {
+ fprintf(stderr, "max res %d, skipping %s\n", maxResInt, entry->d_name);
+ continue;
+ }
+ }
+
FileType type = getFileType(subdirName.string());
if (type == kFileTypeDirectory) {
diff --git a/tools/aapt/Android.mk b/tools/aapt/Android.mk
index 499a7ac..094b7db 100644
--- a/tools/aapt/Android.mk
+++ b/tools/aapt/Android.mk
@@ -4,6 +4,9 @@
# Android Asset Packaging Tool
#
+# This tool is prebuilt if we're doing an app-only build.
+ifeq ($(TARGET_BUILD_APPS),)
+
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
@@ -38,7 +41,7 @@ LOCAL_STATIC_LIBRARIES := \
libpng
ifeq ($(HOST_OS),linux)
-LOCAL_LDLIBS += -lrt
+LOCAL_LDLIBS += -lrt -lpthread
endif
# Statically link libz for MinGW (Win SDK under Linux),
@@ -53,3 +56,4 @@ LOCAL_MODULE := aapt
include $(BUILD_HOST_EXECUTABLE)
+endif # TARGET_BUILD_APPS
diff --git a/tools/aapt/Bundle.h b/tools/aapt/Bundle.h
index b0f0c7e..aac614f 100644
--- a/tools/aapt/Bundle.h
+++ b/tools/aapt/Bundle.h
@@ -46,6 +46,7 @@ public:
mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL),
+ mMaxResVersion(NULL), mDebugMode(false), mProduct(NULL),
mArgc(0), mArgv(NULL)
{}
~Bundle(void) {}
@@ -137,6 +138,12 @@ public:
void setVersionName(const char* val) { mVersionName = val; }
const char* getCustomPackage() const { return mCustomPackage; }
void setCustomPackage(const char* val) { mCustomPackage = val; }
+ const char* getMaxResVersion() const { return mMaxResVersion; }
+ void setMaxResVersion(const char * val) { mMaxResVersion = val; }
+ bool getDebugMode() { return mDebugMode; }
+ void setDebugMode(bool val) { mDebugMode = val; }
+ const char* getProduct() const { return mProduct; }
+ void setProduct(const char * val) { mProduct = val; }
/*
* Set and get the file specification.
@@ -234,6 +241,9 @@ private:
const char* mVersionCode;
const char* mVersionName;
const char* mCustomPackage;
+ const char* mMaxResVersion;
+ bool mDebugMode;
+ const char* mProduct;
/* file specification */
int mArgc;
diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp
index 83057b8..661ecb1 100644
--- a/tools/aapt/Command.cpp
+++ b/tools/aapt/Command.cpp
@@ -141,9 +141,9 @@ int doList(Bundle* bundle)
if (bundle->getVerbose()) {
printf("Archive: %s\n", zipFileName);
printf(
- " Length Method Size Ratio Date Time CRC-32 Name\n");
+ " Length Method Size Ratio Offset Date Time CRC-32 Name\n");
printf(
- "-------- ------ ------- ----- ---- ---- ------ ----\n");
+ "-------- ------ ------- ----- ------- ---- ---- ------ ----\n");
}
totalUncLen = totalCompLen = 0;
@@ -159,12 +159,13 @@ int doList(Bundle* bundle)
strftime(dateBuf, sizeof(dateBuf), "%m-%d-%y %H:%M",
localtime(&when));
- printf("%8ld %-7.7s %7ld %3d%% %s %08lx %s\n",
+ printf("%8ld %-7.7s %7ld %3d%% %8zd %s %08lx %s\n",
(long) entry->getUncompressedLen(),
compressionName(entry->getCompressionMethod()),
(long) entry->getCompressedLen(),
calcPercent(entry->getUncompressedLen(),
entry->getCompressedLen()),
+ (size_t) entry->getLFHOffset(),
dateBuf,
entry->getCRC32(),
entry->getFileName());
@@ -331,12 +332,15 @@ enum {
REQ_FIVE_WAY_NAV_ATTR = 0x01010232,
TARGET_SDK_VERSION_ATTR = 0x01010270,
TEST_ONLY_ATTR = 0x01010272,
- DENSITY_ATTR = 0x0101026c,
+ ANY_DENSITY_ATTR = 0x0101026c,
GL_ES_VERSION_ATTR = 0x01010281,
SMALL_SCREEN_ATTR = 0x01010284,
NORMAL_SCREEN_ATTR = 0x01010285,
LARGE_SCREEN_ATTR = 0x01010286,
+ XLARGE_SCREEN_ATTR = 0x010102bf,
REQUIRED_ATTR = 0x0101028e,
+ SCREEN_SIZE_ATTR = 0x010102ca,
+ SCREEN_DENSITY_ATTR = 0x010102cb,
};
const char *getComponentName(String8 &pkgName, String8 &componentName) {
@@ -353,6 +357,42 @@ const char *getComponentName(String8 &pkgName, String8 &componentName) {
return retStr.string();
}
+static void printCompatibleScreens(ResXMLTree& tree) {
+ size_t len;
+ ResXMLTree::event_code_t code;
+ int depth = 0;
+ bool first = true;
+ printf("compatible-screens:");
+ while ((code=tree.next()) != ResXMLTree::END_DOCUMENT && code != ResXMLTree::BAD_DOCUMENT) {
+ if (code == ResXMLTree::END_TAG) {
+ depth--;
+ if (depth < 0) {
+ break;
+ }
+ continue;
+ }
+ if (code != ResXMLTree::START_TAG) {
+ continue;
+ }
+ depth++;
+ String8 tag(tree.getElementName(&len));
+ if (tag == "screen") {
+ int32_t screenSize = getIntegerAttribute(tree,
+ SCREEN_SIZE_ATTR, NULL, -1);
+ int32_t screenDensity = getIntegerAttribute(tree,
+ SCREEN_DENSITY_ATTR, NULL, -1);
+ if (screenSize > 0 && screenDensity > 0) {
+ if (!first) {
+ printf(",");
+ }
+ first = false;
+ printf("'%d/%d'", screenSize, screenDensity);
+ }
+ }
+ }
+ printf("\n");
+}
+
/*
* Handle the "dump" command, to extract select data from an archive.
*/
@@ -569,6 +609,8 @@ int doDump(Bundle* bundle)
int smallScreen = 1;
int normalScreen = 1;
int largeScreen = 1;
+ int xlargeScreen = 1;
+ int anyDensity = 1;
String8 pkg;
String8 activityName;
String8 activityLabel;
@@ -736,14 +778,6 @@ int doDump(Bundle* bundle)
printf(" reqFiveWayNav='%d'", reqFiveWayNav);
}
printf("\n");
- } else if (tag == "supports-density") {
- int32_t dens = getIntegerAttribute(tree, DENSITY_ATTR, &error);
- if (error != "") {
- fprintf(stderr, "ERROR getting 'android:density' attribute: %s\n",
- error.string());
- goto bail;
- }
- printf("supports-density:'%d'\n", dens);
} else if (tag == "supports-screens") {
smallScreen = getIntegerAttribute(tree,
SMALL_SCREEN_ATTR, NULL, 1);
@@ -751,6 +785,10 @@ int doDump(Bundle* bundle)
NORMAL_SCREEN_ATTR, NULL, 1);
largeScreen = getIntegerAttribute(tree,
LARGE_SCREEN_ATTR, NULL, 1);
+ xlargeScreen = getIntegerAttribute(tree,
+ XLARGE_SCREEN_ATTR, NULL, 1);
+ anyDensity = getIntegerAttribute(tree,
+ ANY_DENSITY_ATTR, NULL, 1);
} else if (tag == "uses-feature") {
String8 name = getAttribute(tree, NAME_ATTR, &error);
@@ -848,6 +886,15 @@ int doDump(Bundle* bundle)
error.string());
goto bail;
}
+ } else if (tag == "uses-package") {
+ String8 name = getAttribute(tree, NAME_ATTR, &error);
+ if (name != "" && error == "") {
+ printf("uses-package:'%s'\n", name.string());
+ } else {
+ fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n",
+ error.string());
+ goto bail;
+ }
} else if (tag == "original-package") {
String8 name = getAttribute(tree, NAME_ATTR, &error);
if (name != "" && error == "") {
@@ -857,6 +904,18 @@ int doDump(Bundle* bundle)
error.string());
goto bail;
}
+ } else if (tag == "uses-gl-texture") {
+ String8 name = getAttribute(tree, NAME_ATTR, &error);
+ if (name != "" && error == "") {
+ printf("uses-gl-texture:'%s'\n", name.string());
+ } else {
+ fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n",
+ error.string());
+ goto bail;
+ }
+ } else if (tag == "compatible-screens") {
+ printCompatibleScreens(tree);
+ depth--;
}
} else if (depth == 3 && withinApplication) {
withinActivity = false;
@@ -1079,12 +1138,22 @@ int doDump(Bundle* bundle)
if (largeScreen > 0) {
largeScreen = targetSdk >= 4 ? -1 : 0;
}
+ if (xlargeScreen > 0) {
+ // Introduced in Gingerbread.
+ xlargeScreen = targetSdk >= 9 ? -1 : 0;
+ }
+ if (anyDensity > 0) {
+ anyDensity = targetSdk >= 4 ? -1 : 0;
+ }
printf("supports-screens:");
if (smallScreen != 0) printf(" 'small'");
if (normalScreen != 0) printf(" 'normal'");
if (largeScreen != 0) printf(" 'large'");
+ if (xlargeScreen != 0) printf(" 'xlarge'");
printf("\n");
+ printf("supports-any-density: '%s'\n", anyDensity ? "true" : "false");
+
printf("locales:");
Vector<String8> locales;
res.getLocales(&locales);
diff --git a/tools/aapt/Main.cpp b/tools/aapt/Main.cpp
index 4461e67..dfc0e80 100644
--- a/tools/aapt/Main.cpp
+++ b/tools/aapt/Main.cpp
@@ -59,15 +59,17 @@ void usage(void)
fprintf(stderr,
" %s p[ackage] [-d][-f][-m][-u][-v][-x[ extending-resource-id]][-z][-M AndroidManifest.xml] \\\n"
" [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \\\n"
- " [--min-sdk-version VAL] [--target-sdk-version VAL] \\\n"
+ " [--debug-mode] [--min-sdk-version VAL] [--target-sdk-version VAL] \\\n"
" [--app-version VAL] [--app-version-name TEXT] [--custom-package VAL] \\\n"
" [--rename-manifest-package PACKAGE] \\\n"
" [--rename-instrumentation-target-package PACKAGE] \\\n"
" [--utf16] [--auto-add-overlay] \\\n"
+ " [--max-res-version VAL] \\\n"
" [-I base-package [-I base-package ...]] \\\n"
" [-A asset-source-dir] [-G class-list-file] [-P public-definitions-file] \\\n"
" [-S resource-sources [-S resource-sources ...]] "
" [-F apk-file] [-J R-file-dir] \\\n"
+ " [--product product1,product2,...] \\\n"
" [raw-files-dir [raw-files-dir] ...]\n"
"\n"
" Package the android resources. It will read assets and resources that are\n"
@@ -125,11 +127,16 @@ void usage(void)
" -0 specifies an additional extension for which such files will not\n"
" be stored compressed in the .apk. An empty string means to not\n"
" compress any files at all.\n"
+ " --debug-mode\n"
+ " inserts android:debuggable=\"true\" in to the application node of the\n"
+ " manifest, making the application debuggable even on production devices.\n"
" --min-sdk-version\n"
" inserts android:minSdkVersion in to manifest. If the version is 7 or\n"
" higher, the default encoding for resources will be in UTF-8.\n"
" --target-sdk-version\n"
" inserts android:targetSdkVersion in to manifest.\n"
+ " --max-res-version\n"
+ " ignores versioned resource directories above the given value.\n"
" --values\n"
" when used with \"dump resources\" also includes resource values.\n"
" --version-code\n"
@@ -150,6 +157,9 @@ void usage(void)
" components target the given package. Useful when used in\n"
" conjunction with --rename-manifest-package to fix tests against\n"
" a package that has been renamed.\n"
+ " --product\n"
+ " Specifies which variant to choose for strings that have\n"
+ " product variants\n"
" --utf16\n"
" changes default encoding for resources to UTF-16. Only useful when API\n"
" level is set to 7 or higher where the default encoding is UTF-8.\n");
@@ -399,7 +409,9 @@ int main(int argc, char* const argv[])
}
break;
case '-':
- if (strcmp(cp, "-min-sdk-version") == 0) {
+ if (strcmp(cp, "-debug-mode") == 0) {
+ bundle.setDebugMode(true);
+ } else if (strcmp(cp, "-min-sdk-version") == 0) {
argc--;
argv++;
if (!argc) {
@@ -426,6 +438,15 @@ int main(int argc, char* const argv[])
goto bail;
}
bundle.setMaxSdkVersion(argv[0]);
+ } else if (strcmp(cp, "-max-res-version") == 0) {
+ argc--;
+ argv++;
+ if (!argc) {
+ fprintf(stderr, "ERROR: No argument supplied for '--max-res-version' option\n");
+ wantUsage = true;
+ goto bail;
+ }
+ bundle.setMaxResVersion(argv[0]);
} else if (strcmp(cp, "-version-code") == 0) {
argc--;
argv++;
@@ -477,6 +498,15 @@ int main(int argc, char* const argv[])
bundle.setInstrumentationPackageNameOverride(argv[0]);
} else if (strcmp(cp, "-auto-add-overlay") == 0) {
bundle.setAutoAddOverlay(true);
+ } else if (strcmp(cp, "-product") == 0) {
+ argc--;
+ argv++;
+ if (!argc) {
+ fprintf(stderr, "ERROR: No argument supplied for '--product' option\n");
+ wantUsage = true;
+ goto bail;
+ }
+ bundle.setProduct(argv[0]);
} else {
fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp);
wantUsage = true;
diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp
index cafd635..c8ba904 100644
--- a/tools/aapt/Resource.cpp
+++ b/tools/aapt/Resource.cpp
@@ -678,6 +678,13 @@ status_t massageManifest(Bundle* bundle, sp<XMLNode> root)
bundle->getMaxSdkVersion());
}
+ if (bundle->getDebugMode()) {
+ sp<XMLNode> application = root->getChildElement(String16(), String16("application"));
+ if (application != NULL) {
+ addTagAttribute(application, RESOURCES_ANDROID_NAMESPACE, "debuggable", "true");
+ }
+ }
+
// Deal with manifest package name overrides
const char* manifestPackageNameOverride = bundle->getManifestPackageNameOverride();
if (manifestPackageNameOverride != NULL) {
@@ -828,7 +835,9 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
bool hasErrors = false;
if (drawables != NULL) {
- err = preProcessImages(bundle, assets, drawables);
+ if (bundle->getOutputAPKFile() != NULL) {
+ err = preProcessImages(bundle, assets, drawables);
+ }
if (err == NO_ERROR) {
err = makeFileResources(bundle, assets, &table, drawables, "drawable");
if (err != NO_ERROR) {
@@ -1880,7 +1889,7 @@ addProguardKeepRule(ProguardKeepSet* keep, const String8& inClassName,
className.append(inClassName);
}
}
-
+
String8 rule("-keep class ");
rule += className;
rule += " { <init>(...); }";
@@ -1955,7 +1964,7 @@ writeProguardForAndroidManifest(ProguardKeepSet* keep, const sp<AaptAssets>& ass
if (tag == "application") {
inApplication = true;
keepTag = true;
-
+
String8 agent = getAttribute(tree, "http://schemas.android.com/apk/res/android",
"backupAgent", &error);
if (agent.length() > 0) {
@@ -1988,9 +1997,17 @@ writeProguardForAndroidManifest(ProguardKeepSet* keep, const sp<AaptAssets>& ass
return NO_ERROR;
}
+struct NamespaceAttributePair {
+ const char* ns;
+ const char* attr;
+
+ NamespaceAttributePair(const char* n, const char* a) : ns(n), attr(a) {}
+ NamespaceAttributePair() : ns(NULL), attr(NULL) {}
+};
+
status_t
writeProguardForXml(ProguardKeepSet* keep, const sp<AaptFile>& layoutFile,
- const char* startTag, const char* altTag)
+ const char* startTag, const KeyedVector<String8, NamespaceAttributePair>* tagAttrPairs)
{
status_t err;
ResXMLTree tree;
@@ -2020,7 +2037,7 @@ writeProguardForXml(ProguardKeepSet* keep, const sp<AaptFile>& layoutFile,
return NO_ERROR;
}
}
-
+
while ((code=tree.next()) != ResXMLTree::END_DOCUMENT && code != ResXMLTree::BAD_DOCUMENT) {
if (code != ResXMLTree::START_TAG) {
continue;
@@ -2031,16 +2048,21 @@ writeProguardForXml(ProguardKeepSet* keep, const sp<AaptFile>& layoutFile,
if (strchr(tag.string(), '.')) {
addProguardKeepRule(keep, tag, NULL,
layoutFile->getPrintableSource(), tree.getLineNumber());
- } else if (altTag != NULL && tag == altTag) {
- ssize_t classIndex = tree.indexOfAttribute(NULL, "class");
- if (classIndex < 0) {
- fprintf(stderr, "%s:%d: <view> does not have class attribute.\n",
- layoutFile->getPrintableSource().string(), tree.getLineNumber());
- } else {
- size_t len;
- addProguardKeepRule(keep,
- String8(tree.getAttributeStringValue(classIndex, &len)), NULL,
- layoutFile->getPrintableSource(), tree.getLineNumber());
+ } else if (tagAttrPairs != NULL) {
+ ssize_t tagIndex = tagAttrPairs->indexOfKey(tag);
+ if (tagIndex >= 0) {
+ const NamespaceAttributePair& nsAttr = tagAttrPairs->valueAt(tagIndex);
+ ssize_t attrIndex = tree.indexOfAttribute(nsAttr.ns, nsAttr.attr);
+ if (attrIndex < 0) {
+ // fprintf(stderr, "%s:%d: <%s> does not have attribute %s:%s.\n",
+ // layoutFile->getPrintableSource().string(), tree.getLineNumber(),
+ // tag.string(), nsAttr.ns, nsAttr.attr);
+ } else {
+ size_t len;
+ addProguardKeepRule(keep,
+ String8(tree.getAttributeStringValue(attrIndex, &len)), NULL,
+ layoutFile->getPrintableSource(), tree.getLineNumber());
+ }
}
}
}
@@ -2048,25 +2070,42 @@ writeProguardForXml(ProguardKeepSet* keep, const sp<AaptFile>& layoutFile,
return NO_ERROR;
}
+static void addTagAttrPair(KeyedVector<String8, NamespaceAttributePair>* dest,
+ const char* tag, const char* ns, const char* attr) {
+ dest->add(String8(tag), NamespaceAttributePair(ns, attr));
+}
+
status_t
writeProguardForLayouts(ProguardKeepSet* keep, const sp<AaptAssets>& assets)
{
status_t err;
+
+ // tag:attribute pairs that should be checked in layout files.
+ KeyedVector<String8, NamespaceAttributePair> kLayoutTagAttrPairs;
+ addTagAttrPair(&kLayoutTagAttrPairs, "view", NULL, "class");
+ addTagAttrPair(&kLayoutTagAttrPairs, "fragment", RESOURCES_ANDROID_NAMESPACE, "name");
+
+ // tag:attribute pairs that should be checked in xml files.
+ KeyedVector<String8, NamespaceAttributePair> kXmlTagAttrPairs;
+ addTagAttrPair(&kXmlTagAttrPairs, "PreferenceScreen", RESOURCES_ANDROID_NAMESPACE, "fragment");
+ addTagAttrPair(&kXmlTagAttrPairs, "Header", RESOURCES_ANDROID_NAMESPACE, "fragment");
+
const Vector<sp<AaptDir> >& dirs = assets->resDirs();
const size_t K = dirs.size();
for (size_t k=0; k<K; k++) {
const sp<AaptDir>& d = dirs.itemAt(k);
const String8& dirName = d->getLeaf();
const char* startTag = NULL;
- const char* altTag = NULL;
+ const KeyedVector<String8, NamespaceAttributePair>* tagAttrPairs = NULL;
if ((dirName == String8("layout")) || (strncmp(dirName.string(), "layout-", 7) == 0)) {
- altTag = "view";
+ tagAttrPairs = &kLayoutTagAttrPairs;
} else if ((dirName == String8("xml")) || (strncmp(dirName.string(), "xml-", 4) == 0)) {
startTag = "PreferenceScreen";
+ tagAttrPairs = &kXmlTagAttrPairs;
} else {
continue;
}
-
+
const KeyedVector<String8,sp<AaptGroup> > groups = d->getFiles();
const size_t N = groups.size();
for (size_t i=0; i<N; i++) {
@@ -2074,7 +2113,7 @@ writeProguardForLayouts(ProguardKeepSet* keep, const sp<AaptAssets>& assets)
const DefaultKeyedVector<AaptGroupEntry, sp<AaptFile> >& files = group->getFiles();
const size_t M = files.size();
for (size_t j=0; j<M; j++) {
- err = writeProguardForXml(keep, files.valueAt(j), startTag, altTag);
+ err = writeProguardForXml(keep, files.valueAt(j), startTag, tagAttrPairs);
if (err < 0) {
return err;
}
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index 2356518..08f5389 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -574,6 +574,8 @@ status_t parseAndAddBag(Bundle* bundle,
const String16& parentIdent,
const String16& itemIdent,
int32_t curFormat,
+ bool isFormatted,
+ const String16& product,
bool pseudolocalize,
const bool overwrite,
ResourceTable* outTable)
@@ -584,7 +586,7 @@ status_t parseAndAddBag(Bundle* bundle,
String16 str;
Vector<StringPool::entry_style_span> spans;
err = parseStyledString(bundle, in->getPrintableSource().string(),
- block, item16, &str, &spans,
+ block, item16, &str, &spans, isFormatted,
pseudolocalize);
if (err != NO_ERROR) {
return err;
@@ -606,6 +608,32 @@ status_t parseAndAddBag(Bundle* bundle,
return err;
}
+/*
+ * Returns true if needle is one of the elements in the comma-separated list
+ * haystack, false otherwise.
+ */
+bool isInProductList(const String16& needle, const String16& haystack) {
+ const char16_t *needle2 = needle.string();
+ const char16_t *haystack2 = haystack.string();
+ size_t needlesize = needle.size();
+
+ while (*haystack2 != '\0') {
+ if (strncmp16(haystack2, needle2, needlesize) == 0) {
+ if (haystack2[needlesize] == '\0' || haystack2[needlesize] == ',') {
+ return true;
+ }
+ }
+
+ while (*haystack2 != '\0' && *haystack2 != ',') {
+ haystack2++;
+ }
+ if (*haystack2 == ',') {
+ haystack2++;
+ }
+ }
+
+ return false;
+}
status_t parseAndAddEntry(Bundle* bundle,
const sp<AaptFile>& in,
@@ -617,6 +645,8 @@ status_t parseAndAddEntry(Bundle* bundle,
const String16& curTag,
bool curIsStyled,
int32_t curFormat,
+ bool isFormatted,
+ const String16& product,
bool pseudolocalize,
const bool overwrite,
ResourceTable* outTable)
@@ -627,12 +657,53 @@ status_t parseAndAddEntry(Bundle* bundle,
Vector<StringPool::entry_style_span> spans;
err = parseStyledString(bundle, in->getPrintableSource().string(), block,
curTag, &str, curIsStyled ? &spans : NULL,
- pseudolocalize);
+ isFormatted, pseudolocalize);
if (err < NO_ERROR) {
return err;
}
+ /*
+ * If a product type was specified on the command line
+ * and also in the string, and the two are not the same,
+ * return without adding the string.
+ */
+
+ const char *bundleProduct = bundle->getProduct();
+ if (bundleProduct == NULL) {
+ bundleProduct = "";
+ }
+
+ if (product.size() != 0) {
+ /*
+ * If the command-line-specified product is empty, only "default"
+ * matches. Other variants are skipped. This is so generation
+ * of the R.java file when the product is not known is predictable.
+ */
+
+ if (bundleProduct[0] == '\0') {
+ if (strcmp16(String16("default").string(), product.string()) != 0) {
+ return NO_ERROR;
+ }
+ } else {
+ /*
+ * The command-line product is not empty.
+ * If the product for this string is on the command-line list,
+ * it matches. "default" also matches, but only if nothing
+ * else has matched already.
+ */
+
+ if (isInProductList(product, String16(bundleProduct))) {
+ ;
+ } else if (strcmp16(String16("default").string(), product.string()) == 0 &&
+ !outTable->hasBagOrEntry(myPackage, curType, ident)) {
+ ;
+ } else {
+ return NO_ERROR;
+ }
+ }
+ }
+
NOISY(printf("Adding resource entry l=%c%c c=%c%c orien=%d d=%d id=%s: %s\n",
config.language[0], config.language[1],
config.country[0], config.country[1],
@@ -710,12 +781,18 @@ status_t compileResourceFile(Bundle* bundle,
// useful attribute names and special values
const String16 name16("name");
const String16 translatable16("translatable");
+ const String16 formatted16("formatted");
const String16 false16("false");
const String16 myPackage(assets->getPackage());
bool hasErrors = false;
-
+
+ bool fileIsTranslatable = true;
+ if (strstr(in->getPrintableSource().string(), "donottranslate") != NULL) {
+ fileIsTranslatable = false;
+ }
+
DefaultKeyedVector<String16, uint32_t> nextPublicId(0);
ResXMLTree::event_code_t code;
@@ -752,6 +829,7 @@ status_t compileResourceFile(Bundle* bundle,
bool curIsBagReplaceOnOverwrite = false;
bool curIsStyled = false;
bool curIsPseudolocalizable = false;
+ bool curIsFormatted = fileIsTranslatable;
bool localHasErrors = false;
if (strcmp16(block.getElementName(&len), skip16.string()) == 0) {
@@ -1137,6 +1215,7 @@ status_t compileResourceFile(Bundle* bundle,
String8 locale(rawLocale);
String16 name;
String16 translatable;
+ String16 formatted;
size_t n = block.getAttributeCount();
for (size_t i = 0; i < n; i++) {
@@ -1146,11 +1225,14 @@ status_t compileResourceFile(Bundle* bundle,
name.setTo(block.getAttributeStringValue(i, &length));
} else if (strcmp16(attr, translatable16.string()) == 0) {
translatable.setTo(block.getAttributeStringValue(i, &length));
+ } else if (strcmp16(attr, formatted16.string()) == 0) {
+ formatted.setTo(block.getAttributeStringValue(i, &length));
}
}
if (name.size() > 0) {
if (translatable == false16) {
+ curIsFormatted = false;
// Untranslatable strings must only exist in the default [empty] locale
if (locale.size() > 0) {
fprintf(stderr, "aapt: warning: string '%s' in %s marked untranslatable but exists"
@@ -1168,6 +1250,10 @@ status_t compileResourceFile(Bundle* bundle,
} else {
outTable->addLocalization(name, locale);
}
+
+ if (formatted == false16) {
+ curIsFormatted = false;
+ }
}
curTag = &string16;
@@ -1267,6 +1353,12 @@ status_t compileResourceFile(Bundle* bundle,
hasErrors = localHasErrors = true;
}
+ String16 product;
+ identIdx = block.indexOfAttribute(NULL, "product");
+ if (identIdx >= 0) {
+ product = String16(block.getAttributeStringValue(identIdx, &len));
+ }
+
String16 comment(block.getComment(&len) ? block.getComment(&len) : nulStr);
if (curIsBag) {
@@ -1357,8 +1449,8 @@ status_t compileResourceFile(Bundle* bundle,
block.getPosition(&parserPosition);
err = parseAndAddBag(bundle, in, &block, curParams, myPackage, curType,
- ident, parentIdent, itemIdent, curFormat,
- false, overwrite, outTable);
+ ident, parentIdent, itemIdent, curFormat, curIsFormatted,
+ product, false, overwrite, outTable);
if (err == NO_ERROR) {
if (curIsPseudolocalizable && localeIsDefined(curParams)
&& bundle->getPseudolocalize()) {
@@ -1366,8 +1458,8 @@ status_t compileResourceFile(Bundle* bundle,
#if 1
block.setPosition(parserPosition);
err = parseAndAddBag(bundle, in, &block, pseudoParams, myPackage,
- curType, ident, parentIdent, itemIdent, curFormat, true,
- overwrite, outTable);
+ curType, ident, parentIdent, itemIdent, curFormat,
+ curIsFormatted, product, true, overwrite, outTable);
#endif
}
}
@@ -1390,7 +1482,8 @@ status_t compileResourceFile(Bundle* bundle,
block.getPosition(&parserPosition);
err = parseAndAddEntry(bundle, in, &block, curParams, myPackage, curType, ident,
- *curTag, curIsStyled, curFormat, false, overwrite, outTable);
+ *curTag, curIsStyled, curFormat, curIsFormatted,
+ product, false, overwrite, outTable);
if (err < NO_ERROR) { // Why err < NO_ERROR instead of err != NO_ERROR?
hasErrors = localHasErrors = true;
@@ -1401,7 +1494,9 @@ status_t compileResourceFile(Bundle* bundle,
// pseudolocalize here
block.setPosition(parserPosition);
err = parseAndAddEntry(bundle, in, &block, pseudoParams, myPackage, curType,
- ident, *curTag, curIsStyled, curFormat, true, overwrite, outTable);
+ ident, *curTag, curIsStyled, curFormat,
+ curIsFormatted, product,
+ true, overwrite, outTable);
if (err != NO_ERROR) {
hasErrors = localHasErrors = true;
}
diff --git a/tools/aapt/XMLNode.cpp b/tools/aapt/XMLNode.cpp
index 4c59288..8551b0f 100644
--- a/tools/aapt/XMLNode.cpp
+++ b/tools/aapt/XMLNode.cpp
@@ -68,12 +68,118 @@ String16 getNamespaceResourcePackage(String16 namespaceUri, bool* outIsPublic)
return String16(namespaceUri, namespaceUri.size()-prefixSize, prefixSize);
}
+status_t hasSubstitutionErrors(const char* fileName,
+ ResXMLTree* inXml,
+ String16 str16)
+{
+ const char16_t* str = str16.string();
+ const char16_t* p = str;
+ const char16_t* end = str + str16.size();
+
+ bool nonpositional = false;
+ int argCount = 0;
+
+ while (p < end) {
+ /*
+ * Look for the start of a Java-style substitution sequence.
+ */
+ if (*p == '%' && p + 1 < end) {
+ p++;
+
+ // A literal percent sign represented by %%
+ if (*p == '%') {
+ p++;
+ continue;
+ }
+
+ argCount++;
+
+ if (*p >= '0' && *p <= '9') {
+ do {
+ p++;
+ } while (*p >= '0' && *p <= '9');
+ if (*p != '$') {
+ // This must be a size specification instead of position.
+ nonpositional = true;
+ }
+ } else if (*p == '<') {
+ // Reusing last argument; bad idea since it can be re-arranged.
+ nonpositional = true;
+ p++;
+
+ // Optionally '$' can be specified at the end.
+ if (p < end && *p == '$') {
+ p++;
+ }
+ } else {
+ nonpositional = true;
+ }
+
+ // Ignore flags and widths
+ while (p < end && (*p == '-' ||
+ *p == '#' ||
+ *p == '+' ||
+ *p == ' ' ||
+ *p == ',' ||
+ *p == '(' ||
+ (*p >= '0' && *p <= '9'))) {
+ p++;
+ }
+
+ /*
+ * This is a shortcut to detect strings that are going to Time.format()
+ * instead of String.format()
+ *
+ * Comparison of String.format() and Time.format() args:
+ *
+ * String: ABC E GH ST X abcdefgh nost x
+ * Time: DEFGHKMS W Za d hkm s w yz
+ *
+ * Therefore we know it's definitely Time if we have:
+ * DFKMWZkmwyz
+ */
+ if (p < end) {
+ switch (*p) {
+ case 'D':
+ case 'F':
+ case 'K':
+ case 'M':
+ case 'W':
+ case 'Z':
+ case 'k':
+ case 'm':
+ case 'w':
+ case 'y':
+ case 'z':
+ return NO_ERROR;
+ }
+ }
+ }
+
+ p++;
+ }
+
+ /*
+ * If we have more than one substitution in this string and any of them
+ * are not in positional form, give the user an error.
+ */
+ if (argCount > 1 && nonpositional) {
+ SourcePos(String8(fileName), inXml->getLineNumber()).error(
+ "Multiple substitutions specified in non-positional format; "
+ "did you mean to add the formatted=\"false\" attribute?\n");
+ return NOT_ENOUGH_DATA;
+ }
+
+ return NO_ERROR;
+}
+
status_t parseStyledString(Bundle* bundle,
const char* fileName,
ResXMLTree* inXml,
const String16& endTag,
String16* outString,
Vector<StringPool::entry_style_span>* outSpans,
+ bool isFormatted,
bool pseudolocalize)
{
Vector<StringPool::entry_style_span> spanStack;
@@ -101,7 +207,11 @@ status_t parseStyledString(Bundle* bundle,
std::string pseudo = pseudolocalize_string(orig);
curString.append(String16(String8(pseudo.c_str())));
} else {
- curString.append(text);
+ if (isFormatted && hasSubstitutionErrors(fileName, inXml, text) != NO_ERROR) {
+ return UNKNOWN_ERROR;
+ } else {
+ curString.append(text);
+ }
}
} else if (code == ResXMLTree::START_TAG) {
const String16 element16(inXml->getElementName(&len));
diff --git a/tools/aapt/XMLNode.h b/tools/aapt/XMLNode.h
index e9a263b..05624b7 100644
--- a/tools/aapt/XMLNode.h
+++ b/tools/aapt/XMLNode.h
@@ -25,6 +25,7 @@ status_t parseStyledString(Bundle* bundle,
const String16& endTag,
String16* outString,
Vector<StringPool::entry_style_span>* outSpans,
+ bool isFormatted,
bool isPseudolocalizable);
void printXMLBlock(ResXMLTree* block);
diff --git a/tools/aapt/ZipEntry.h b/tools/aapt/ZipEntry.h
index 7f721b4..c2f3227 100644
--- a/tools/aapt/ZipEntry.h
+++ b/tools/aapt/ZipEntry.h
@@ -72,6 +72,11 @@ public:
off_t getCompressedLen(void) const { return mCDE.mCompressedSize; }
/*
+ * Return the offset of the local file header.
+ */
+ off_t getLFHOffset(void) const { return mCDE.mLocalHeaderRelOffset; }
+
+ /*
* Return the absolute file offset of the start of the compressed or
* uncompressed data.
*/
@@ -186,11 +191,6 @@ protected:
void setModWhen(time_t when);
/*
- * Return the offset of the local file header.
- */
- off_t getLFHOffset(void) const { return mCDE.mLocalHeaderRelOffset; }
-
- /*
* Set the offset of the local file header, relative to the start of
* the current file.
*/
diff --git a/tools/aidl/Android.mk b/tools/aidl/Android.mk
index 944aeb6..2ad0728 100644
--- a/tools/aidl/Android.mk
+++ b/tools/aidl/Android.mk
@@ -2,6 +2,9 @@
#
# Copies files into the directory structure described by a manifest
+# This tool is prebuilt if we're doing an app-only build.
+ifeq ($(TARGET_BUILD_APPS),)
+
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
@@ -21,4 +24,4 @@ LOCAL_MODULE := aidl
include $(BUILD_HOST_EXECUTABLE)
-
+endif # TARGET_BUILD_APPS
diff --git a/tools/aidl/aidl.cpp b/tools/aidl/aidl.cpp
index fc658f5..f17f66b 100644
--- a/tools/aidl/aidl.cpp
+++ b/tools/aidl/aidl.cpp
@@ -55,7 +55,7 @@ test_document(document_item_type* d)
printf("parcelable %s %s;\n", b->package, b->name.data);
}
else {
- printf("UNKNOWN d=0x%08x d->item_type=%ld\n", (long)d, d->item_type);
+ printf("UNKNOWN d=0x%08lx d->item_type=%d\n", (long)d, d->item_type);
}
d = d->next;
}
diff --git a/tools/layoutlib/Android.mk b/tools/layoutlib/Android.mk
index 6d606a9..b27ce0e 100644
--- a/tools/layoutlib/Android.mk
+++ b/tools/layoutlib/Android.mk
@@ -25,15 +25,11 @@ include $(CLEAR_VARS)
# We need to process the framework classes.jar file, but we can't
# depend directly on it (private vars won't be inherited correctly).
# So, we depend on framework's BUILT file.
-built_framework_dep := \
- $(call intermediates-dir-for,JAVA_LIBRARIES,framework)/javalib.jar
-built_framework_classes := \
- $(call intermediates-dir-for,JAVA_LIBRARIES,framework)/classes.jar
+built_framework_dep := $(call java-lib-deps,framework)
+built_framework_classes := $(call java-lib-files,framework)
-built_core_dep := \
- $(call intermediates-dir-for,JAVA_LIBRARIES,core)/javalib.jar
-built_core_classes := \
- $(call intermediates-dir-for,JAVA_LIBRARIES,core)/classes.jar
+built_core_dep := $(call java-lib-deps,core)
+built_core_classes := $(call java-lib-files,core)
built_layoutlib_create_jar := $(call intermediates-dir-for, \
JAVA_LIBRARIES,layoutlib_create,HOST)/javalib.jar
@@ -52,13 +48,15 @@ include $(BUILD_SYSTEM)/base_rules.mk
$(LOCAL_BUILT_MODULE): $(built_core_dep) \
$(built_framework_dep) \
$(built_layoutlib_create_jar)
- @echo "host layoutlib_create: $@"
- @mkdir -p $(dir $@)
- @rm -f $@
+ $(hide) echo "host layoutlib_create: $@"
+ $(hide) mkdir -p $(dir $@)
+ $(hide) rm -f $@
+ $(hide) ls -l $(built_framework_classes)
$(hide) java -jar $(built_layoutlib_create_jar) \
$@ \
$(built_core_classes) \
$(built_framework_classes)
+ $(hide) ls -l $(built_framework_classes)
#
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint.java b/tools/layoutlib/bridge/src/android/graphics/Paint.java
index 619ab30..d13b5fe 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Paint.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Paint.java
@@ -283,6 +283,8 @@ public class Paint extends _Original_Paint {
mStyle = src.mStyle;
mFlags = src.mFlags;
+ updateFontObject();
+
super.set(src);
}
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index 4201e80..f91f601 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -46,6 +46,7 @@ import android.os.RemoteException;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.BridgeInflater;
+import android.view.InputChannel;
import android.view.IWindow;
import android.view.IWindowSession;
import android.view.KeyEvent;
@@ -990,13 +991,21 @@ public final class Bridge implements ILayoutBridge {
private static final class WindowSession implements IWindowSession {
@SuppressWarnings("unused")
- public int add(IWindow arg0, LayoutParams arg1, int arg2, Rect arg3)
+ public int add(IWindow arg0, LayoutParams arg1, int arg2, Rect arg3,
+ InputChannel outInputchannel)
throws RemoteException {
// pass for now.
return 0;
}
@SuppressWarnings("unused")
+ public int addWithoutInputChannel(IWindow arg0, LayoutParams arg1, int arg2, Rect arg3)
+ throws RemoteException {
+ // pass for now.
+ return 0;
+ }
+
+ @SuppressWarnings("unused")
public void finishDrawing(IWindow arg0) throws RemoteException {
// pass for now.
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContentResolver.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContentResolver.java
index cfab90a..20ccc0b 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContentResolver.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContentResolver.java
@@ -16,12 +16,27 @@
package com.android.layoutlib.bridge;
+import android.content.ContentProviderOperation;
+import android.content.ContentProviderResult;
import android.content.ContentResolver;
+import android.content.ContentValues;
import android.content.Context;
import android.content.IContentProvider;
+import android.content.OperationApplicationException;
+import android.content.res.AssetFileDescriptor;
import android.database.ContentObserver;
+import android.database.Cursor;
+import android.database.CursorWindow;
+import android.database.IBulkCursor;
+import android.database.IContentObserver;
import android.net.Uri;
import android.os.Bundle;
+import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
/**
* A mock content resolver for the LayoutLib Bridge.
@@ -32,14 +47,98 @@ import android.os.Bundle;
*/
public class BridgeContentResolver extends ContentResolver {
+ private BridgeContentProvider mProvider = null;
+
+ public static final class BridgeContentProvider implements IContentProvider {
+
+ public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> arg0)
+ throws RemoteException, OperationApplicationException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int bulkInsert(Uri arg0, ContentValues[] arg1) throws RemoteException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public IBulkCursor bulkQuery(Uri arg0, String[] arg1, String arg2, String[] arg3,
+ String arg4, IContentObserver arg5, CursorWindow arg6) throws RemoteException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Bundle call(String arg0, String arg1, Bundle arg2) throws RemoteException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int delete(Uri arg0, String arg1, String[] arg2) throws RemoteException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String getType(Uri arg0) throws RemoteException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Uri insert(Uri arg0, ContentValues arg1) throws RemoteException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public AssetFileDescriptor openAssetFile(Uri arg0, String arg1) throws RemoteException,
+ FileNotFoundException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ParcelFileDescriptor openFile(Uri arg0, String arg1) throws RemoteException,
+ FileNotFoundException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, String arg4)
+ throws RemoteException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3)
+ throws RemoteException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public IBinder asBinder() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
+
public BridgeContentResolver(Context context) {
super(context);
}
@Override
public IContentProvider acquireProvider(Context c, String name) {
- // ignore
- return null;
+ if (mProvider == null) {
+ mProvider = new BridgeContentProvider();
+ }
+
+ return mProvider;
+ }
+
+ @Override
+ public IContentProvider acquireExistingProvider(Context c, String name) {
+ if (mProvider == null) {
+ mProvider = new BridgeContentProvider();
+ }
+
+ return mProvider;
}
@Override
@@ -47,7 +146,7 @@ public class BridgeContentResolver extends ContentResolver {
// ignore
return false;
}
-
+
/**
* Stub for the layoutlib bridge content resolver.
*/
@@ -56,7 +155,7 @@ public class BridgeContentResolver extends ContentResolver {
ContentObserver observer) {
// pass
}
-
+
/**
* Stub for the layoutlib bridge content resolver.
*/
@@ -64,7 +163,7 @@ public class BridgeContentResolver extends ContentResolver {
public void unregisterContentObserver(ContentObserver observer) {
// pass
}
-
+
/**
* Stub for the layoutlib bridge content resolver.
*/
@@ -72,7 +171,7 @@ public class BridgeContentResolver extends ContentResolver {
public void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork) {
// pass
}
-
+
/**
* Stub for the layoutlib bridge content resolver.
*/
@@ -80,7 +179,7 @@ public class BridgeContentResolver extends ContentResolver {
public void startSync(Uri uri, Bundle extras) {
// pass
}
-
+
/**
* Stub for the layoutlib bridge content resolver.
*/
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContext.java
index 744bfbe..ecd22e2 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContext.java
@@ -245,8 +245,8 @@ public final class BridgeContext extends Context {
BridgeXmlBlockParser parser = null;
if (set instanceof BridgeXmlBlockParser) {
parser = (BridgeXmlBlockParser)set;
- } else {
- // reall this should not be happening since its instantiated in Bridge
+ } else if (set != null) { // null parser is ok
+ // really this should not be happening since its instantiated in Bridge
mLogger.error("Parser is not a BridgeXmlBlockParser!");
return null;
}
@@ -255,15 +255,18 @@ public final class BridgeContext extends Context {
TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes);
BridgeTypedArray ta = ((BridgeResources) mResources).newTypeArray(attrs.length,
- parser.isPlatformFile());
+ parser != null ? parser.isPlatformFile() : true);
// resolve the defStyleAttr value into a IStyleResourceValue
IStyleResourceValue defStyleValues = null;
// look for a custom style.
- String customStyle = parser.getAttributeValue(null /* namespace*/, "style");
+ String customStyle = null;
+ if (parser != null) {
+ customStyle = parser.getAttributeValue(null /* namespace*/, "style");
+ }
if (customStyle != null) {
- IResourceValue item = findResValue(customStyle);
+ IResourceValue item = findResValue(customStyle, false /*forceFrameworkOnly*/);
if (item instanceof IStyleResourceValue) {
defStyleValues = (IStyleResourceValue)item;
@@ -280,7 +283,7 @@ public final class BridgeContext extends Context {
if (item != null) {
// item is a reference to a style entry. Search for it.
- item = findResValue(item.getValue());
+ item = findResValue(item.getValue(), false /*forceFrameworkOnly*/);
if (item instanceof IStyleResourceValue) {
defStyleValues = (IStyleResourceValue)item;
@@ -308,7 +311,10 @@ public final class BridgeContext extends Context {
int index = styleAttribute.getKey().intValue();
String name = styleAttribute.getValue();
- String value = parser.getAttributeValue(namespace, name);
+ String value = null;
+ if (parser != null) {
+ value = parser.getAttributeValue(namespace, name);
+ }
// if there's no direct value for this attribute in the XML, we look for default
// values in the widget defStyle, and then in the theme.
@@ -407,7 +413,7 @@ public final class BridgeContext extends Context {
}
// get the IResourceValue referenced by this value
- IResourceValue resValue = findResValue(value);
+ IResourceValue resValue = findResValue(value, false /*forceFrameworkOnly*/);
// if resValue is null, but value is not null, this means it was not a reference.
// we return the name/value wrapper in a IResourceValue
@@ -443,7 +449,7 @@ public final class BridgeContext extends Context {
}
// else attempt to find another IResourceValue referenced by this one.
- IResourceValue resolvedValue = findResValue(value.getValue());
+ IResourceValue resolvedValue = findResValue(value.getValue(), value.isFramework());
// if the value did not reference anything, then we simply return the input value
if (resolvedValue == null) {
@@ -470,9 +476,11 @@ public final class BridgeContext extends Context {
* only support the android namespace.
*
* @param reference the resource reference to search for.
+ * @param forceFrameworkOnly if true all references are considered to be toward framework
+ * resource even if the reference does not include the android: prefix.
* @return a {@link IResourceValue} or <code>null</code>.
*/
- IResourceValue findResValue(String reference) {
+ IResourceValue findResValue(String reference, boolean forceFrameworkOnly) {
if (reference == null) {
return null;
}
@@ -554,7 +562,8 @@ public final class BridgeContext extends Context {
segments[1] = segments[1].substring(BridgeConstants.PREFIX_ANDROID.length());
}
- return findResValue(segments[0], segments[1], frameworkOnly);
+ return findResValue(segments[0], segments[1],
+ forceFrameworkOnly ? true :frameworkOnly);
}
// Looks like the value didn't reference anything. Return null.
@@ -991,8 +1000,7 @@ public final class BridgeContext extends Context {
@Override
public ApplicationInfo getApplicationInfo() {
- // TODO Auto-generated method stub
- return null;
+ return new ApplicationInfo();
}
@Override
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeXmlPullAttributes.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeXmlPullAttributes.java
index 4be6eab..d145ff6 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeXmlPullAttributes.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeXmlPullAttributes.java
@@ -41,7 +41,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
/*
* (non-Javadoc)
* @see android.util.XmlPullAttributes#getAttributeNameResource(int)
- *
+ *
* This methods must return com.android.internal.R.attr.<name> matching
* the name of the attribute.
* It returns 0 if it doesn't find anything.
@@ -50,19 +50,19 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
public int getAttributeNameResource(int index) {
// get the attribute name.
String name = getAttributeName(index);
-
+
// get the attribute namespace
String ns = mParser.getAttributeNamespace(index);
-
+
if (BridgeConstants.NS_RESOURCES.equals(ns)) {
Integer v = Bridge.getResourceValue(BridgeConstants.RES_ATTR, name);
if (v != null) {
return v.intValue();
}
-
+
return 0;
}
-
+
// this is not an attribute in the android namespace, we query the customviewloader, if
// the namespaces match.
if (mContext.getProjectCallback().getNamespace().equals(ns)) {
@@ -75,7 +75,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
return 0;
}
-
+
/*
* (non-Javadoc)
* @see android.util.XmlPullAttributes#getAttributeResourceValue(int, int)
@@ -83,7 +83,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
@Override
public int getAttributeResourceValue(int index, int defaultValue) {
String value = getAttributeValue(index);
-
+
return resolveResourceValue(value, defaultValue);
}
@@ -94,14 +94,15 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
@Override
public int getAttributeResourceValue(String namespace, String attribute, int defaultValue) {
String value = getAttributeValue(namespace, attribute);
-
+
return resolveResourceValue(value, defaultValue);
}
private int resolveResourceValue(String value, int defaultValue) {
// now look for this particular value
- IResourceValue resource = mContext.resolveResValue(mContext.findResValue(value));
-
+ IResourceValue resource = mContext.resolveResValue(
+ mContext.findResValue(value, mPlatformFile));
+
if (resource != null) {
Integer id = null;
if (mPlatformFile || resource.isFramework()) {
@@ -115,7 +116,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
return id;
}
}
-
+
return defaultValue;
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/ResourceHelper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/ResourceHelper.java
index 3d0dd73..f624753 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/ResourceHelper.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/ResourceHelper.java
@@ -148,8 +148,7 @@ public final class ResourceHelper {
parser.setInput(new FileReader(f));
d = Drawable.createFromXml(context.getResources(),
- // FIXME: we need to know if this resource is platform or not
- new BridgeXmlBlockParser(parser, context, false));
+ new BridgeXmlBlockParser(parser, context, isFramework));
return d;
} catch (XmlPullParserException e) {
context.getLogger().error(e);
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java
index 303f097..b30e9e5 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java
@@ -67,6 +67,7 @@ public class Main {
"com.android.internal.R**",
"android.pim.*", // for datepicker
"android.os.*", // for android.os.Handler
+ "android.database.ContentObserver", // for Digital clock
});
aa.analyze();
agen.generate();
diff --git a/tools/localize/Android.mk b/tools/localize/Android.mk
index ab79f8d..f284e86 100644
--- a/tools/localize/Android.mk
+++ b/tools/localize/Android.mk
@@ -34,7 +34,7 @@ LOCAL_STATIC_LIBRARIES := \
libcutils
ifeq ($(HOST_OS),linux)
-LOCAL_LDLIBS += -lrt
+LOCAL_LDLIBS += -lrt -lpthread
endif
diff --git a/tools/obbtool/Android.mk b/tools/obbtool/Android.mk
new file mode 100644
index 0000000..d118bd7
--- /dev/null
+++ b/tools/obbtool/Android.mk
@@ -0,0 +1,46 @@
+#
+# Copyright 2010 The Android Open Source Project
+#
+# Opaque Binary Blob (OBB) Tool
+#
+
+# This tool is prebuilt if we're doing an app-only build.
+ifeq ($(TARGET_BUILD_APPS),)
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ Main.cpp
+
+LOCAL_CFLAGS := -Wall -Werror
+
+#LOCAL_C_INCLUDES +=
+
+LOCAL_STATIC_LIBRARIES := \
+ libutils \
+ libcutils
+
+ifeq ($(HOST_OS),linux)
+LOCAL_LDLIBS += -lpthread
+endif
+
+LOCAL_MODULE := obbtool
+
+include $(BUILD_HOST_EXECUTABLE)
+
+#####################################################
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := pbkdf2gen
+LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -Wall -Werror
+LOCAL_SRC_FILES := pbkdf2gen.cpp
+LOCAL_LDLIBS += -ldl
+LOCAL_C_INCLUDES := external/openssl/include $(LOCAL_C_INCLUDES)
+LOCAL_STATIC_LIBRARIES := libcrypto_static
+
+include $(BUILD_HOST_EXECUTABLE)
+
+#######################################################
+endif # TARGET_BUILD_APPS
diff --git a/tools/obbtool/Main.cpp b/tools/obbtool/Main.cpp
new file mode 100644
index 0000000..932dbec
--- /dev/null
+++ b/tools/obbtool/Main.cpp
@@ -0,0 +1,301 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#include <utils/ObbFile.h>
+#include <utils/String8.h>
+
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+using namespace android;
+
+static const char* gProgName = "obbtool";
+static const char* gProgVersion = "1.0";
+
+static int wantUsage = 0;
+static int wantVersion = 0;
+
+#define SALT_LEN 8
+
+#define ADD_OPTS "n:v:os:"
+static const struct option longopts[] = {
+ {"help", no_argument, &wantUsage, 1},
+ {"version", no_argument, &wantVersion, 1},
+
+ /* Args for "add" */
+ {"name", required_argument, NULL, 'n'},
+ {"version", required_argument, NULL, 'v'},
+ {"overlay", optional_argument, NULL, 'o'},
+ {"salt", required_argument, NULL, 's'},
+
+ {NULL, 0, NULL, '\0'}
+};
+
+class PackageInfo {
+public:
+ PackageInfo()
+ : packageName(NULL)
+ , packageVersion(-1)
+ , overlay(false)
+ , salted(false)
+ {
+ memset(&salt, 0, sizeof(salt));
+ }
+
+ char* packageName;
+ int packageVersion;
+ bool overlay;
+ bool salted;
+ unsigned char salt[SALT_LEN];
+};
+
+/*
+ * Print usage info.
+ */
+void usage(void)
+{
+ fprintf(stderr, "Opaque Binary Blob (OBB) Tool\n\n");
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr,
+ " %s a[dd] [ OPTIONS ] FILENAME\n"
+ " Adds an OBB signature to the file.\n\n", gProgName);
+ fprintf(stderr,
+ " Options:\n"
+ " -n <package name> sets the OBB package name (required)\n"
+ " -v <OBB version> sets the OBB version (required)\n"
+ " -o sets the OBB overlay flag\n"
+ " -s <8 byte hex salt> sets the crypto key salt (if encrypted)\n"
+ "\n");
+ fprintf(stderr,
+ " %s r[emove] FILENAME\n"
+ " Removes the OBB signature from the file.\n\n", gProgName);
+ fprintf(stderr,
+ " %s i[nfo] FILENAME\n"
+ " Prints the OBB signature information of a file.\n\n", gProgName);
+}
+
+void doAdd(const char* filename, struct PackageInfo* info) {
+ ObbFile *obb = new ObbFile();
+ if (obb->readFrom(filename)) {
+ fprintf(stderr, "ERROR: %s: OBB signature already present\n", filename);
+ return;
+ }
+
+ obb->setPackageName(String8(info->packageName));
+ obb->setVersion(info->packageVersion);
+ obb->setOverlay(info->overlay);
+ if (info->salted) {
+ obb->setSalt(info->salt, SALT_LEN);
+ }
+
+ if (!obb->writeTo(filename)) {
+ fprintf(stderr, "ERROR: %s: couldn't write OBB signature: %s\n",
+ filename, strerror(errno));
+ return;
+ }
+
+ fprintf(stderr, "OBB signature successfully written\n");
+}
+
+void doRemove(const char* filename) {
+ ObbFile *obb = new ObbFile();
+ if (!obb->readFrom(filename)) {
+ fprintf(stderr, "ERROR: %s: no OBB signature present\n", filename);
+ return;
+ }
+
+ if (!obb->removeFrom(filename)) {
+ fprintf(stderr, "ERROR: %s: couldn't remove OBB signature\n", filename);
+ return;
+ }
+
+ fprintf(stderr, "OBB signature successfully removed\n");
+}
+
+void doInfo(const char* filename) {
+ ObbFile *obb = new ObbFile();
+ if (!obb->readFrom(filename)) {
+ fprintf(stderr, "ERROR: %s: couldn't read OBB signature\n", filename);
+ return;
+ }
+
+ printf("OBB info for '%s':\n", filename);
+ printf("Package name: %s\n", obb->getPackageName().string());
+ printf(" Version: %d\n", obb->getVersion());
+ printf(" Flags: 0x%08x\n", obb->getFlags());
+ printf(" Overlay: %s\n", obb->isOverlay() ? "true" : "false");
+ printf(" Salt: ");
+
+ size_t saltLen;
+ const unsigned char* salt = obb->getSalt(&saltLen);
+ if (salt != NULL) {
+ for (int i = 0; i < SALT_LEN; i++) {
+ printf("%02x", salt[i]);
+ }
+ printf("\n");
+ } else {
+ printf("<empty>\n");
+ }
+}
+
+bool fromHex(char h, unsigned char *b) {
+ if (h >= '0' && h <= '9') {
+ *b = h - '0';
+ return true;
+ } else if (h >= 'a' && h <= 'f') {
+ *b = h - 'a' + 10;
+ return true;
+ } else if (h >= 'A' && h <= 'F') {
+ *b = h - 'A' + 10;
+ return true;
+ }
+ return false;
+}
+
+bool hexToByte(char h1, char h2, unsigned char* b) {
+ unsigned char first, second;
+ if (!fromHex(h1, &first)) return false;
+ if (!fromHex(h2, &second)) return false;
+ *b = (first << 4) | second;
+ return true;
+}
+
+/*
+ * Parse args.
+ */
+int main(int argc, char* const argv[])
+{
+ int opt;
+ int option_index = 0;
+ struct PackageInfo package_info;
+
+ int result = 1; // pessimistically assume an error.
+
+ if (argc < 2) {
+ wantUsage = 1;
+ goto bail;
+ }
+
+ while ((opt = getopt_long(argc, argv, ADD_OPTS, longopts, &option_index)) != -1) {
+ switch (opt) {
+ case 0:
+ if (longopts[option_index].flag)
+ break;
+ fprintf(stderr, "'%s' requires an argument\n", longopts[option_index].name);
+ wantUsage = 1;
+ goto bail;
+ case 'n':
+ package_info.packageName = optarg;
+ break;
+ case 'v': {
+ char* end;
+ package_info.packageVersion = strtol(optarg, &end, 10);
+ if (*optarg == '\0' || *end != '\0') {
+ fprintf(stderr, "ERROR: invalid version; should be integer!\n\n");
+ wantUsage = 1;
+ goto bail;
+ }
+ break;
+ }
+ case 'o':
+ package_info.overlay = true;
+ break;
+ case 's':
+ if (strlen(optarg) != SALT_LEN * 2) {
+ fprintf(stderr, "ERROR: salt must be 8 bytes in hex (e.g., ABCD65031337D00D)\n\n");
+ wantUsage = 1;
+ goto bail;
+ }
+
+ package_info.salted = true;
+
+ unsigned char b;
+ for (int i = 0, j = 0; i < SALT_LEN; i++, j+=2) {
+ if (!hexToByte(optarg[j], optarg[j+1], &b)) {
+ fprintf(stderr, "ERROR: salt must be in hex (e.g., ABCD65031337D00D)\n");
+ wantUsage = 1;
+ goto bail;
+ }
+ package_info.salt[i] = b;
+ }
+ break;
+ case '?':
+ wantUsage = 1;
+ goto bail;
+ }
+ }
+
+ if (wantVersion) {
+ fprintf(stderr, "%s %s\n", gProgName, gProgVersion);
+ }
+
+ if (wantUsage) {
+ goto bail;
+ }
+
+#define CHECK_OP(name) \
+ if (strncmp(op, name, opsize)) { \
+ fprintf(stderr, "ERROR: unknown function '%s'!\n\n", op); \
+ wantUsage = 1; \
+ goto bail; \
+ }
+
+ if (optind < argc) {
+ const char* op = argv[optind++];
+ const int opsize = strlen(op);
+
+ if (optind >= argc) {
+ fprintf(stderr, "ERROR: filename required!\n\n");
+ wantUsage = 1;
+ goto bail;
+ }
+
+ const char* filename = argv[optind++];
+
+ switch (op[0]) {
+ case 'a':
+ CHECK_OP("add");
+ if (package_info.packageName == NULL) {
+ fprintf(stderr, "ERROR: arguments required 'packageName' and 'version'\n");
+ goto bail;
+ }
+ doAdd(filename, &package_info);
+ break;
+ case 'r':
+ CHECK_OP("remove");
+ doRemove(filename);
+ break;
+ case 'i':
+ CHECK_OP("info");
+ doInfo(filename);
+ break;
+ default:
+ fprintf(stderr, "ERROR: unknown command '%s'!\n\n", op);
+ wantUsage = 1;
+ goto bail;
+ }
+ }
+
+bail:
+ if (wantUsage) {
+ usage();
+ result = 2;
+ }
+
+ return result;
+}
diff --git a/tools/obbtool/mkobb.sh b/tools/obbtool/mkobb.sh
new file mode 100755
index 0000000..725250d
--- /dev/null
+++ b/tools/obbtool/mkobb.sh
@@ -0,0 +1,281 @@
+#!/bin/bash
+#
+# Copyright (C) 2010 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.
+#
+
+# mkobb.sh - Creates OBB files on Linux machines
+
+# Directory where we should temporarily mount the OBB loopback to copy files
+MOUNTDIR=/tmp
+
+# Presets. Changing these will probably break your OBB on the device
+CRYPTO=twofish
+FS=vfat
+MKFS=mkfs.vfat
+LOSETUP=losetup
+BLOCK_SIZE=512
+SLOP=512 # Amount of filesystem slop in ${BLOCK_SIZE} blocks
+
+find_binaries() {
+ MKFSBIN=`which ${MKFS}`
+ LOSETUPBIN=`which ${LOSETUP}`
+ MOUNTBIN=`which mount`
+ UMOUNTBIN=`which umount`
+ DDBIN=`which dd`
+ RSYNCBIN=`which rsync`
+ PBKDF2GEN=`which pbkdf2gen`
+}
+
+check_prereqs() {
+ if [ "`uname -s`x" != "Linuxx" ]; then \
+ echo "ERROR: This script only works on Linux!"
+ exit 1
+ fi
+
+ if ! egrep -q "^cryptoloop " /proc/modules; then \
+ echo "ERROR: Could not find cryptoloop in the kernel."
+ echo "Perhaps you need to: modprobe cryptoloop"
+ exit 1
+ fi
+
+ if ! egrep -q "name\s*:\s*${CRYPTO}$" /proc/crypto; then \
+ echo "ERROR: Could not find crypto \`${CRYPTO}' in the kernel."
+ echo "Perhaps you need to: modprobe ${CRYPTO}"
+ exit 1
+ fi
+
+ if ! egrep -q "^\s*${FS}$" /proc/filesystems; then \
+ echo "ERROR: Could not find filesystem \`${FS}' in the kernel."
+ echo "Perhaps you need to: modprobe ${FS}"
+ exit 1
+ fi
+
+ if [ "${MKFSBIN}x" = "x" ]; then \
+ echo "ERROR: Could not find ${MKFS} in your path!"
+ exit 1
+ elif [ ! -x "${MKFSBIN}" ]; then \
+ echo "ERROR: ${MKFSBIN} is not executable!"
+ exit 1
+ fi
+
+ if [ "${LOSETUPBIN}x" = "x" ]; then \
+ echo "ERROR: Could not find ${LOSETUP} in your path!"
+ exit 1
+ elif [ ! -x "${LOSETUPBIN}" ]; then \
+ echo "ERROR: ${LOSETUPBIN} is not executable!"
+ exit 1
+ fi
+
+ if [ "${PBKDF2GEN}x" = "x" ]; then \
+ echo "ERROR: Could not find pbkdf2gen in your path!"
+ exit 1
+ fi
+}
+
+cleanup() {
+ if [ "${loopdev}x" != "x" ]; then \
+ ${LOSETUPBIN} -d ${loopdev}
+ fi
+}
+
+hidden_prompt() {
+ unset output
+ prompt="$1"
+ outvar="$2"
+ while read -s -n 1 -p "$prompt" c; do \
+ if [ "x$c" = "x" ]; then \
+ break
+ fi
+ prompt='*'
+ output="${output}${c}"
+ done
+ echo
+ eval $outvar="$output"
+ unset output
+}
+
+read_key() {
+ hidden_prompt " Encryption key: " key
+
+ if [ "${key}x" = "x" ]; then \
+ echo "ERROR: An empty key is not allowed!"
+ exit 1
+ fi
+
+ hidden_prompt "Encryption key (again): " key2
+
+ if [ "${key}x" != "${key2}x" ]; then \
+ echo "ERROR: Encryption keys do not match!"
+ exit 1
+ fi
+}
+
+onexit() {
+ if [ "x${temp_mount}" != "x" ]; then \
+ ${UMOUNTBIN} ${temp_mount}
+ rmdir ${temp_mount}
+ fi
+ if [ "x${loop_dev}" != "x" ]; then \
+ if [ ${use_crypto} -eq 1 ]; then \
+ dmsetup remove -f ${loop_dev}
+ ${LOSETUPBIN} -d ${old_loop_dev}
+ else \
+ ${LOSETUPBIN} -d ${loop_dev}
+ fi
+ fi
+ if [ "x${tempfile}" != "x" -a -f "${tempfile}" ]; then \
+ rm -f ${tempfile}
+ fi
+ if [ "x${keyfile}" != "x" -a -f "${keyfile}" ]; then \
+ rm -f ${keyfile}
+ fi
+ echo "Fatal error."
+ exit 1
+}
+
+usage() {
+ echo "mkobb.sh -- Create OBB files for use on Android"
+ echo ""
+ echo " -d <directory> Use <directory> as input for OBB files"
+ echo " -k <key> Use <key> to encrypt OBB file"
+ echo " -K Prompt for key to encrypt OBB file"
+ echo " -o <filename> Write OBB file out to <filename>"
+ echo " -v Verbose mode"
+ echo " -h Help; this usage screen"
+}
+
+find_binaries
+check_prereqs
+
+use_crypto=0
+
+args=`getopt -o d:hk:Ko:v -- "$@"`
+eval set -- "$args"
+
+while true; do \
+ case "$1" in
+ -d) directory=$2; shift 2;;
+ -h) usage; exit 1;;
+ -k) key=$2; use_crypto=1; shift 2;;
+ -K) prompt_key=1; use_crypto=1; shift;;
+ -v) verbose=1; shift;;
+ -o) filename=$2; shift 2;;
+ --) shift; break;;
+ *) echo "ERROR: Invalid argument in option parsing! Cannot recover. Ever."; exit 1;;
+ esac
+done
+
+if [ "${directory}x" = "x" -o ! -d "${directory}" ]; then \
+ echo "ERROR: Must specify valid input directory"
+ echo ""
+ usage
+ exit 1;
+fi
+
+if [ "${filename}x" = "x" ]; then \
+ echo "ERROR: Must specify filename"
+ echo ""
+ usage
+ exit 1;
+fi
+
+if [ ${use_crypto} -eq 1 -a "${key}x" = "x" -a 0${prompt_key} -eq 0 ]; then \
+ echo "ERROR: Crypto desired, but no key supplied or requested to prompt for."
+ exit 1
+fi
+
+if [ 0${prompt_key} -eq 1 ]; then \
+ read_key
+fi
+
+outdir=`dirname ${filename}`
+if [ ! -d "${outdir}" ]; then \
+ echo "ERROR: Output directory does not exist: ${outdir}"
+ exit 1
+fi
+
+# Make sure we clean up any stuff we create from here on during error conditions
+trap onexit ERR
+
+tempfile=$(tempfile -d ${outdir}) || ( echo "ERROR: couldn't create temporary file in ${outdir}"; exit 1 )
+
+block_count=`du -s --apparent-size --block-size=512 ${directory} | awk '{ print $1; }'`
+if [ $? -ne 0 ]; then \
+ echo "ERROR: Couldn't read size of input directory ${directory}"
+ exit 1
+fi
+
+echo "Creating temporary file..."
+${DDBIN} if=/dev/zero of=${tempfile} bs=${BLOCK_SIZE} count=$((${block_count} + ${SLOP})) > /dev/null 2>&1
+if [ $? -ne 0 ]; then \
+ echo "ERROR: creating temporary file: $?"
+fi
+
+loop_dev=$(${LOSETUPBIN} -f) || ( echo "ERROR: losetup wouldn't tell us the next unused device"; exit 1 )
+
+${LOSETUPBIN} ${loop_dev} ${tempfile} || ( echo "ERROR: couldn't create loopback device"; exit 1 )
+
+if [ ${use_crypto} -eq 1 ]; then \
+ eval `${PBKDF2GEN} ${key}`
+ unique_dm_name=`basename ${tempfile}`
+ echo "0 `blockdev --getsize ${loop_dev}` crypt ${CRYPTO} ${key} 0 ${loop_dev} 0" | dmsetup create ${unique_dm_name}
+ old_loop_dev=${loop_dev}
+ loop_dev=/dev/mapper/${unique_dm_name}
+fi
+
+#
+# Create the filesystem
+#
+echo ""
+${MKFSBIN} -I ${loop_dev}
+echo ""
+
+#
+# Make the temporary mount point and mount it
+#
+temp_mount="${MOUNTDIR}/${RANDOM}"
+mkdir ${temp_mount}
+${MOUNTBIN} -t ${FS} -o loop ${loop_dev} ${temp_mount}
+
+#
+# rsync the files!
+#
+echo "Copying files:"
+${RSYNCBIN} -av --no-owner --no-group ${directory}/ ${temp_mount}/
+echo ""
+
+echo "Successfully created \`${filename}'"
+
+if [ ${use_crypto} -eq 1 ]; then \
+ echo "salt for use with obbtool is:"
+ echo "${salt}"
+fi
+
+#
+# Undo all the temporaries
+#
+umount ${temp_mount}
+rmdir ${temp_mount}
+if [ ${use_crypto} -eq 1 ]; then \
+ dmsetup remove -f ${loop_dev}
+ ${LOSETUPBIN} -d ${old_loop_dev}
+else \
+ ${LOSETUPBIN} -d ${loop_dev}
+fi
+mv ${tempfile} ${filename}
+
+trap - ERR
+
+exit 0
diff --git a/tools/obbtool/pbkdf2gen.cpp b/tools/obbtool/pbkdf2gen.cpp
new file mode 100644
index 0000000..98d67c0
--- /dev/null
+++ b/tools/obbtool/pbkdf2gen.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#include <openssl/evp.h>
+
+#include <sys/types.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+/**
+ * Simple program to generate a key based on PBKDF2 with preset inputs.
+ *
+ * Will print out the salt and key in hex.
+ */
+
+#define SALT_LEN 8
+#define ROUNDS 1024
+#define KEY_BITS 128
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <password>\n", argv[0]);
+ exit(1);
+ }
+
+ int fd = open("/dev/urandom", O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Could not open /dev/urandom: %s\n", strerror(errno));
+ close(fd);
+ exit(1);
+ }
+
+ unsigned char salt[SALT_LEN];
+
+ if (read(fd, &salt, SALT_LEN) != SALT_LEN) {
+ fprintf(stderr, "Could not read salt from /dev/urandom: %s\n", strerror(errno));
+ close(fd);
+ exit(1);
+ }
+ close(fd);
+
+ unsigned char rawKey[KEY_BITS];
+
+ if (PKCS5_PBKDF2_HMAC_SHA1(argv[1], strlen(argv[1]), salt, SALT_LEN,
+ ROUNDS, KEY_BITS, rawKey) != 1) {
+ fprintf(stderr, "Could not generate PBKDF2 output: %s\n", strerror(errno));
+ exit(1);
+ }
+
+ printf("salt=");
+ for (int i = 0; i < SALT_LEN; i++) {
+ printf("%02x", salt[i]);
+ }
+ printf("\n");
+
+ printf("key=");
+ for (int i = 0; i < (KEY_BITS / 8); i++) {
+ printf("%02x", rawKey[i]);
+ }
+ printf("\n");
+}
diff --git a/tools/preload/WritePreloadedClassFile.java b/tools/preload/WritePreloadedClassFile.java
index 96c539b..b067bc2 100644
--- a/tools/preload/WritePreloadedClassFile.java
+++ b/tools/preload/WritePreloadedClassFile.java
@@ -34,6 +34,11 @@ public class WritePreloadedClassFile {
*/
static final int MIN_LOAD_TIME_MICROS = 1250;
+ /**
+ * Preload any class that was loaded by at least MIN_PROCESSES processes.
+ */
+ static final int MIN_PROCESSES = 10;
+
public static void main(String[] args) throws IOException,
ClassNotFoundException {
if (args.length != 1) {
@@ -58,6 +63,7 @@ public class WritePreloadedClassFile {
out.write("# Automatically generated by frameworks/base/tools/preload/"
+ WritePreloadedClassFile.class.getSimpleName() + ".java.\n");
out.write("# MIN_LOAD_TIME_MICROS=" + MIN_LOAD_TIME_MICROS + "\n");
+ out.write("# MIN_PROCESSES=" + MIN_PROCESSES + "\n");
/*
* The set of classes to preload. We preload a class if:
@@ -73,7 +79,12 @@ public class WritePreloadedClassFile {
// the memory associated with these classes will be shared.
for (LoadedClass loadedClass : root.loadedClasses.values()) {
Set<String> names = loadedClass.processNames();
- if (shouldPreload(loadedClass) && names.size() > 1) {
+ if (!Policy.isPreloadable(loadedClass)) {
+ continue;
+ }
+
+ if (names.size() >= MIN_PROCESSES ||
+ (loadedClass.medianTimeMicros() > MIN_LOAD_TIME_MICROS && names.size() > 1)) {
toPreload.add(loadedClass);
}
}
diff --git a/tools/preload/loadclass/Android.mk b/tools/preload/loadclass/Android.mk
index 435699d..65828be 100644
--- a/tools/preload/loadclass/Android.mk
+++ b/tools/preload/loadclass/Android.mk
@@ -2,6 +2,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
+LOCAL_MODULE_TAGS := tests
LOCAL_MODULE := loadclass