diff options
Diffstat (limited to 'tools')
31 files changed, 520 insertions, 325 deletions
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp index 5b71adc..2149190 100644 --- a/tools/aapt/AaptAssets.cpp +++ b/tools/aapt/AaptAssets.cpp @@ -1185,6 +1185,11 @@ bool AaptGroupEntry::getDensityName(const char* name, return true; } + if (strcmp(name, "xxxhdpi") == 0) { + if (out) out->density = ResTable_config::DENSITY_XXXHIGH; + return true; + } + char* c = (char*)name; while (*c >= '0' && *c <= '9') { c++; diff --git a/tools/aapt/Android.mk b/tools/aapt/Android.mk index 5b88669..9b1658a 100644 --- a/tools/aapt/Android.mk +++ b/tools/aapt/Android.mk @@ -39,14 +39,14 @@ LOCAL_C_INCLUDES += external/libpng LOCAL_C_INCLUDES += external/zlib LOCAL_C_INCLUDES += build/libs/host/include -#LOCAL_WHOLE_STATIC_LIBRARIES := LOCAL_STATIC_LIBRARIES := \ libhost \ libandroidfw \ libutils \ libcutils \ libexpat \ - libpng + libpng \ + liblog ifeq ($(HOST_OS),linux) LOCAL_LDLIBS += -lrt -ldl -lpthread diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp index c3a0930..cadac02 100644 --- a/tools/aapt/Command.cpp +++ b/tools/aapt/Command.cpp @@ -592,6 +592,10 @@ int doDump(Bundle* bundle) goto bail; } printf("uses-permission: %s\n", name.string()); + int req = getIntegerAttribute(tree, REQUIRED_ATTR, NULL, 1); + if (!req) { + printf("optional-permission: %s\n", name.string()); + } } } } else if (strcmp("badging", option) == 0) { @@ -1033,6 +1037,10 @@ int doDump(Bundle* bundle) hasWriteCallLogPermission = true; } printf("uses-permission:'%s'\n", name.string()); + int req = getIntegerAttribute(tree, REQUIRED_ATTR, NULL, 1); + if (!req) { + printf("optional-permission:'%s'\n", name.string()); + } } else { fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n", error.string()); @@ -1283,7 +1291,7 @@ int doDump(Bundle* bundle) // network location feature, we infer that it meant to printf("uses-feature:'android.hardware.location.network'\n"); printf("uses-implied-feature:'android.hardware.location.network'," \ - "'requested android.permission.ACCESS_COURSE_LOCATION permission'\n"); + "'requested android.permission.ACCESS_COARSE_LOCATION permission'\n"); } // Bluetooth-related compatibility logic @@ -1852,10 +1860,12 @@ int doSingleCrunch(Bundle* bundle) String8 input(bundle->getSingleCrunchInputFile()); String8 output(bundle->getSingleCrunchOutputFile()); + if (preProcessImageToCache(bundle, input, output) != NO_ERROR) { // we can't return the status_t as it gets truncate to the lower 8 bits. return 42; } + return NO_ERROR; } diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp index 77168f9..6168bbd 100644 --- a/tools/aapt/Resource.cpp +++ b/tools/aapt/Resource.cpp @@ -1568,11 +1568,37 @@ static const char whitespace[] = return whitespace + sizeof(whitespace) - 1 - indent*4; } -static status_t fixupSymbol(String16* inoutSymbol) -{ - inoutSymbol->replaceAll('.', '_'); - inoutSymbol->replaceAll(':', '_'); - return NO_ERROR; +static String8 flattenSymbol(const String8& symbol) { + String8 result(symbol); + ssize_t first; + if ((first = symbol.find(":", 0)) >= 0 + || (first = symbol.find(".", 0)) >= 0) { + size_t size = symbol.size(); + char* buf = result.lockBuffer(size); + for (size_t i = first; i < size; i++) { + if (buf[i] == ':' || buf[i] == '.') { + buf[i] = '_'; + } + } + result.unlockBuffer(size); + } + return result; +} + +static String8 getSymbolPackage(const String8& symbol, const sp<AaptAssets>& assets, bool pub) { + ssize_t colon = symbol.find(":", 0); + if (colon >= 0) { + return String8(symbol.string(), colon); + } + return pub ? assets->getPackage() : assets->getSymbolsPrivatePackage(); +} + +static String8 getSymbolName(const String8& symbol) { + ssize_t colon = symbol.find(":", 0); + if (colon >= 0) { + return String8(symbol.string() + colon + 1); + } + return symbol; } static String16 getAttributeComment(const sp<AaptAssets>& assets, @@ -1616,12 +1642,8 @@ static status_t writeLayoutClasses( size_t N = symbols->getNestedSymbols().size(); for (i=0; i<N; i++) { sp<AaptSymbols> nsymbols = symbols->getNestedSymbols().valueAt(i); - String16 nclassName16(symbols->getNestedSymbols().keyAt(i)); - String8 realClassName(nclassName16); - if (fixupSymbol(&nclassName16) != NO_ERROR) { - hasErrors = true; - } - String8 nclassName(nclassName16); + String8 realClassName(symbols->getNestedSymbols().keyAt(i)); + String8 nclassName(flattenSymbol(realClassName)); SortedVector<uint32_t> idents; Vector<uint32_t> origOrder; @@ -1711,13 +1733,11 @@ static status_t writeLayoutClasses( } comment = String16(comment.string(), p-comment.string()); } - String16 name(name8); - fixupSymbol(&name); fprintf(fp, "%s <tr><td><code>{@link #%s_%s %s:%s}</code></td><td>%s</td></tr>\n", indentStr, nclassName.string(), - String8(name).string(), - assets->getPackage().string(), - String8(name).string(), + flattenSymbol(name8).string(), + getSymbolPackage(name8, assets, true).string(), + getSymbolName(name8).string(), String8(comment).string()); } } @@ -1731,11 +1751,9 @@ static status_t writeLayoutClasses( if (!publicFlags.itemAt(a) && !includePrivate) { continue; } - String16 name(sym.name); - fixupSymbol(&name); fprintf(fp, "%s @see #%s_%s\n", indentStr, nclassName.string(), - String8(name).string()); + flattenSymbol(sym.name).string()); } } fprintf(fp, "%s */\n", getIndentSpace(indent)); @@ -1778,11 +1796,7 @@ static status_t writeLayoutClasses( } else { getAttributeComment(assets, name8, &typeComment); } - String16 name(name8); - if (fixupSymbol(&name) != NO_ERROR) { - hasErrors = true; - } - + uint32_t typeSpecFlags = 0; String16 name16(sym.name); assets->getIncludedResources().identifierForName( @@ -1808,9 +1822,8 @@ static status_t writeLayoutClasses( "%s <p>This symbol is the offset where the {@link %s.R.attr#%s}\n" "%s attribute's value can be found in the {@link #%s} array.\n", indentStr, - pub ? assets->getPackage().string() - : assets->getSymbolsPrivatePackage().string(), - String8(name).string(), + getSymbolPackage(name8, assets, pub).string(), + getSymbolName(name8).string(), indentStr, nclassName.string()); } if (typeComment.size() > 0) { @@ -1823,18 +1836,19 @@ static status_t writeLayoutClasses( if (comment.size() > 0) { if (pub) { fprintf(fp, - "%s <p>This corresponds to the global attribute" + "%s <p>This corresponds to the global attribute\n" "%s resource symbol {@link %s.R.attr#%s}.\n", indentStr, indentStr, - assets->getPackage().string(), - String8(name).string()); + getSymbolPackage(name8, assets, true).string(), + getSymbolName(name8).string()); } else { fprintf(fp, "%s <p>This is a private symbol.\n", indentStr); } } fprintf(fp, "%s @attr name %s:%s\n", indentStr, - "android", String8(name).string()); + getSymbolPackage(name8, assets, pub).string(), + getSymbolName(name8).string()); fprintf(fp, "%s*/\n", indentStr); if (deprecated) { fprintf(fp, "%s@Deprecated\n", indentStr); @@ -1842,7 +1856,7 @@ static status_t writeLayoutClasses( fprintf(fp, "%spublic static final int %s_%s = %d;\n", indentStr, nclassName.string(), - String8(name).string(), (int)pos); + flattenSymbol(name8).string(), (int)pos); } } } @@ -1865,12 +1879,8 @@ static status_t writeTextLayoutClasses( size_t N = symbols->getNestedSymbols().size(); for (i=0; i<N; i++) { sp<AaptSymbols> nsymbols = symbols->getNestedSymbols().valueAt(i); - String16 nclassName16(symbols->getNestedSymbols().keyAt(i)); - String8 realClassName(nclassName16); - if (fixupSymbol(&nclassName16) != NO_ERROR) { - hasErrors = true; - } - String8 nclassName(nclassName16); + String8 realClassName(symbols->getNestedSymbols().keyAt(i)); + String8 nclassName(flattenSymbol(realClassName)); SortedVector<uint32_t> idents; Vector<uint32_t> origOrder; @@ -1930,10 +1940,6 @@ static status_t writeTextLayoutClasses( } else { getAttributeComment(assets, name8, &typeComment); } - String16 name(name8); - if (fixupSymbol(&name) != NO_ERROR) { - hasErrors = true; - } uint32_t typeSpecFlags = 0; String16 name16(sym.name); @@ -1948,7 +1954,7 @@ static status_t writeTextLayoutClasses( fprintf(fp, "int styleable %s_%s %d\n", nclassName.string(), - String8(name).string(), (int)pos); + flattenSymbol(name8).string(), (int)pos); } } } @@ -1982,10 +1988,7 @@ static status_t writeSymbolClass( if (!assets->isJavaSymbol(sym, includePrivate)) { continue; } - String16 name(sym.name); - if (fixupSymbol(&name) != NO_ERROR) { - return UNKNOWN_ERROR; - } + String8 name8(sym.name); String16 comment(sym.comment); bool haveComment = false; bool deprecated = false; @@ -2026,7 +2029,7 @@ static status_t writeSymbolClass( } fprintf(fp, id_format, getIndentSpace(indent), - String8(name).string(), (int)sym.int32Val); + flattenSymbol(name8).string(), (int)sym.int32Val); } for (i=0; i<N; i++) { @@ -2037,10 +2040,7 @@ static status_t writeSymbolClass( if (!assets->isJavaSymbol(sym, includePrivate)) { continue; } - String16 name(sym.name); - if (fixupSymbol(&name) != NO_ERROR) { - return UNKNOWN_ERROR; - } + String8 name8(sym.name); String16 comment(sym.comment); bool deprecated = false; if (comment.size() > 0) { @@ -2063,7 +2063,7 @@ static status_t writeSymbolClass( } fprintf(fp, "%spublic static final String %s=\"%s\";\n", getIndentSpace(indent), - String8(name).string(), sym.stringVal.string()); + flattenSymbol(name8).string(), sym.stringVal.string()); } sp<AaptSymbols> styleableSymbols; @@ -2112,14 +2112,10 @@ static status_t writeTextSymbolClass( continue; } - String16 name(sym.name); - if (fixupSymbol(&name) != NO_ERROR) { - return UNKNOWN_ERROR; - } - + String8 name8(sym.name); fprintf(fp, "int %s %s 0x%08x\n", className.string(), - String8(name).string(), (int)sym.int32Val); + flattenSymbol(name8).string(), (int)sym.int32Val); } N = symbols->getNestedSymbols().size(); diff --git a/tools/aidl/aidl.cpp b/tools/aidl/aidl.cpp index 0728246..071a8d7 100644 --- a/tools/aidl/aidl.cpp +++ b/tools/aidl/aidl.cpp @@ -23,6 +23,12 @@ # define O_BINARY 0 #endif +// The following are gotten as the offset from the allowable id's between +// android.os.IBinder.FIRST_CALL_TRANSACTION=1 and +// android.os.IBinder.LAST_CALL_TRANSACTION=16777215 +#define MIN_USER_SET_METHOD_ID 0 +#define MAX_USER_SET_METHOD_ID 16777214 + using namespace std; static void @@ -847,6 +853,72 @@ parse_preprocessed_file(const string& filename) return 0; } +static int +check_and_assign_method_ids(const char * filename, interface_item_type* first_item) +{ + // Check whether there are any methods with manually assigned id's and any that are not. + // Either all method id's must be manually assigned or all of them must not. + // Also, check for duplicates of user set id's and that the id's are within the proper bounds. + set<int> usedIds; + interface_item_type* item = first_item; + bool hasUnassignedIds = false; + bool hasAssignedIds = false; + while (item != NULL) { + if (item->item_type == METHOD_TYPE) { + method_type* method_item = (method_type*)item; + if (method_item->hasId) { + hasAssignedIds = true; + method_item->assigned_id = atoi(method_item->id.data); + // Ensure that the user set id is not duplicated. + if (usedIds.find(method_item->assigned_id) != usedIds.end()) { + // We found a duplicate id, so throw an error. + fprintf(stderr, + "%s:%d Found duplicate method id (%d) for method: %s\n", + filename, method_item->id.lineno, + method_item->assigned_id, method_item->name.data); + return 1; + } + // Ensure that the user set id is within the appropriate limits + if (method_item->assigned_id < MIN_USER_SET_METHOD_ID || + method_item->assigned_id > MAX_USER_SET_METHOD_ID) { + fprintf(stderr, "%s:%d Found out of bounds id (%d) for method: %s\n", + filename, method_item->id.lineno, + method_item->assigned_id, method_item->name.data); + fprintf(stderr, " Value for id must be between %d and %d inclusive.\n", + MIN_USER_SET_METHOD_ID, MAX_USER_SET_METHOD_ID); + return 1; + } + usedIds.insert(method_item->assigned_id); + } else { + hasUnassignedIds = true; + } + if (hasAssignedIds && hasUnassignedIds) { + fprintf(stderr, + "%s: You must either assign id's to all methods or to none of them.\n", + filename); + return 1; + } + } + item = item->next; + } + + // In the case that all methods have unassigned id's, set a unique id for them. + if (hasUnassignedIds) { + int newId = 0; + item = first_item; + while (item != NULL) { + if (item->item_type == METHOD_TYPE) { + method_type* method_item = (method_type*)item; + method_item->assigned_id = newId++; + } + item = item->next; + } + } + + // success + return 0; +} + // ========================================================== static int compile_aidl(Options& options) @@ -937,6 +1009,12 @@ compile_aidl(Options& options) bool onlyParcelable = false; err |= exactly_one_interface(options.inputFileName.c_str(), mainDoc, options, &onlyParcelable); + // If this includes an interface definition, then assign method ids and validate. + if (!onlyParcelable) { + err |= check_and_assign_method_ids(options.inputFileName.c_str(), + ((interface_type*)mainDoc)->interface_items); + } + // after this, there shouldn't be any more errors because of the // input. if (err != 0 || mainDoc == NULL) { diff --git a/tools/aidl/aidl_language.h b/tools/aidl/aidl_language.h index f203dbb..de1370c 100644 --- a/tools/aidl/aidl_language.h +++ b/tools/aidl/aidl_language.h @@ -57,9 +57,13 @@ typedef struct method_type { buffer_type open_paren_token; arg_type* args; buffer_type close_paren_token; + bool hasId; + buffer_type equals_token; + buffer_type id; // XXX missing comments/copy text here buffer_type semicolon_token; buffer_type* comments_token; // points into this structure, DO NOT DELETE + int assigned_id; } method_type; enum { diff --git a/tools/aidl/aidl_language_l.l b/tools/aidl/aidl_language_l.l index 7c5290c..3d33e7a 100644 --- a/tools/aidl/aidl_language_l.l +++ b/tools/aidl/aidl_language_l.l @@ -36,6 +36,7 @@ static void do_package_statement(const char* importText); identifier [_a-zA-Z][_a-zA-Z0-9\.]* whitespace ([ \t\n\r]+) brackets \[{whitespace}?\] +idvalue (0|[1-9][0-9]*) %% @@ -77,6 +78,7 @@ brackets \[{whitespace}?\] \( { SET_BUFFER('('); return '('; } \) { SET_BUFFER(')'); return ')'; } , { SET_BUFFER(','); return ','; } += { SET_BUFFER('='); return '='; } /* keywords */ parcelable { SET_BUFFER(PARCELABLE); return PARCELABLE; } @@ -89,7 +91,7 @@ inout { SET_BUFFER(INOUT); return INOUT; } oneway { SET_BUFFER(ONEWAY); return ONEWAY; } {brackets}+ { SET_BUFFER(ARRAY); return ARRAY; } - +{idvalue} { SET_BUFFER(IDVALUE); return IDVALUE; } {identifier} { SET_BUFFER(IDENTIFIER); return IDENTIFIER; } {identifier}\<{whitespace}*{identifier}({whitespace}*,{whitespace}*{identifier})*{whitespace}*\> { SET_BUFFER(GENERIC); return GENERIC; } diff --git a/tools/aidl/aidl_language_y.y b/tools/aidl/aidl_language_y.y index cc04d15..9b40d28 100644 --- a/tools/aidl/aidl_language_y.y +++ b/tools/aidl/aidl_language_y.y @@ -15,6 +15,7 @@ static int count_brackets(const char*); %token IMPORT %token PACKAGE %token IDENTIFIER +%token IDVALUE %token GENERIC %token ARRAY %token PARCELABLE @@ -211,13 +212,16 @@ method_decl: method_type *method = (method_type*)malloc(sizeof(method_type)); method->interface_item.item_type = METHOD_TYPE; method->interface_item.next = NULL; - method->type = $1.type; method->oneway = false; + method->type = $1.type; memset(&method->oneway_token, 0, sizeof(buffer_type)); method->name = $2.buffer; method->open_paren_token = $3.buffer; method->args = $4.arg; method->close_paren_token = $5.buffer; + method->hasId = false; + memset(&method->equals_token, 0, sizeof(buffer_type)); + memset(&method->id, 0, sizeof(buffer_type)); method->semicolon_token = $6.buffer; method->comments_token = &method->type.type; $$.method = method; @@ -233,10 +237,49 @@ method_decl: method->open_paren_token = $4.buffer; method->args = $5.arg; method->close_paren_token = $6.buffer; + method->hasId = false; + memset(&method->equals_token, 0, sizeof(buffer_type)); + memset(&method->id, 0, sizeof(buffer_type)); method->semicolon_token = $7.buffer; method->comments_token = &method->oneway_token; $$.method = method; } + | type IDENTIFIER '(' arg_list ')' '=' IDVALUE ';' { + method_type *method = (method_type*)malloc(sizeof(method_type)); + method->interface_item.item_type = METHOD_TYPE; + method->interface_item.next = NULL; + method->oneway = false; + memset(&method->oneway_token, 0, sizeof(buffer_type)); + method->type = $1.type; + method->name = $2.buffer; + method->open_paren_token = $3.buffer; + method->args = $4.arg; + method->close_paren_token = $5.buffer; + method->hasId = true; + method->equals_token = $6.buffer; + method->id = $7.buffer; + method->semicolon_token = $8.buffer; + method->comments_token = &method->type.type; + $$.method = method; + } + | ONEWAY type IDENTIFIER '(' arg_list ')' '=' IDVALUE ';' { + method_type *method = (method_type*)malloc(sizeof(method_type)); + method->interface_item.item_type = METHOD_TYPE; + method->interface_item.next = NULL; + method->oneway = true; + method->oneway_token = $1.buffer; + method->type = $2.type; + method->name = $3.buffer; + method->open_paren_token = $4.buffer; + method->args = $5.arg; + method->close_paren_token = $6.buffer; + method->hasId = true; + method->equals_token = $7.buffer; + method->id = $8.buffer; + method->semicolon_token = $9.buffer; + method->comments_token = &method->oneway_token; + $$.method = method; + } ; arg_list: diff --git a/tools/aidl/generate_java_binder.cpp b/tools/aidl/generate_java_binder.cpp index f80a388..f291ceb 100644 --- a/tools/aidl/generate_java_binder.cpp +++ b/tools/aidl/generate_java_binder.cpp @@ -260,7 +260,7 @@ generate_method(const method_type* method, Class* interface, string transactCodeName = "TRANSACTION_"; transactCodeName += method->name.data; - char transactCodeValue[50]; + char transactCodeValue[60]; sprintf(transactCodeValue, "(android.os.IBinder.FIRST_CALL_TRANSACTION + %d)", index); Field* transactCode = new Field(STATIC | FINAL, @@ -548,7 +548,8 @@ generate_binder_interface_class(const interface_type* iface) interface_item_type* item = iface->interface_items; while (item != NULL) { if (item->item_type == METHOD_TYPE) { - generate_method((method_type*)item, interface, stub, proxy, index); + method_type * method_item = (method_type*) item; + generate_method(method_item, interface, stub, proxy, method_item->assigned_id); } item = item->next; index++; diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java index cbc199a..446d139 100644 --- a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +++ b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java @@ -218,7 +218,7 @@ public final class BridgeTypedArray extends TypedArray { return defValue; } - if (s == null) { + if (s == null || s.length() == 0) { return defValue; } @@ -894,7 +894,7 @@ public final class BridgeTypedArray extends TypedArray { } /** - * Give back a previously retrieved StyledAttributes, for later re-use. + * Give back a previously retrieved TypedArray, for later re-use. */ @Override public void recycle() { diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java index 9a51817..d1d0f09 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java @@ -328,12 +328,19 @@ public final class Canvas_Delegate { } @LayoutlibDelegate - /*package*/ static void native_setBitmap(int nativeCanvas, int nativeBitmap) { - Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nativeBitmap); - Canvas_Delegate canvasDelegate = Canvas_Delegate.getDelegate(nativeCanvas); - if (canvasDelegate != null && bitmapDelegate != null) { - canvasDelegate.setBitmap(bitmapDelegate); + /*package*/ static void copyNativeCanvasState(int srcCanvas, int dstCanvas) { + // get the delegate from the native int. + Canvas_Delegate srcCanvasDelegate = sManager.getDelegate(srcCanvas); + if (srcCanvasDelegate == null) { + return; + } + + // get the delegate from the native int. + Canvas_Delegate dstCanvasDelegate = sManager.getDelegate(dstCanvas); + if (dstCanvasDelegate == null) { + return; } + // TODO: actually copy the canvas state. } @LayoutlibDelegate @@ -561,15 +568,15 @@ public final class Canvas_Delegate { } @LayoutlibDelegate - /*package*/ static boolean native_quickReject(int nativeCanvas, RectF rect, - int native_edgeType) { + /*package*/ static boolean native_quickReject(int nativeCanvas, + RectF rect) { // FIXME properly implement quickReject return false; } @LayoutlibDelegate - /*package*/ static boolean native_quickReject(int nativeCanvas, int path, - int native_edgeType) { + /*package*/ static boolean native_quickReject(int nativeCanvas, + int path) { // FIXME properly implement quickReject return false; } @@ -577,8 +584,7 @@ public final class Canvas_Delegate { @LayoutlibDelegate /*package*/ static boolean native_quickReject(int nativeCanvas, float left, float top, - float right, float bottom, - int native_edgeType) { + float right, float bottom) { // FIXME properly implement quickReject return false; } diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java index 245617b..4ad1a17 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java @@ -568,30 +568,31 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static float native_measureText(Paint thisPaint, char[] text, int index, - int count) { + int count, int bidiFlags) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { return 0; } - RectF bounds = delegate.measureText(text, index, count, false /*isRtl*/); + RectF bounds = delegate.measureText(text, index, count, isRtl(bidiFlags)); return bounds.right - bounds.left; } @LayoutlibDelegate - /*package*/ static float native_measureText(Paint thisPaint, String text, int start, int end) { - return native_measureText(thisPaint, text.toCharArray(), start, end - start); + /*package*/ static float native_measureText(Paint thisPaint, String text, int start, int end, + int bidiFlags) { + return native_measureText(thisPaint, text.toCharArray(), start, end - start, bidiFlags); } @LayoutlibDelegate - /*package*/ static float native_measureText(Paint thisPaint, String text) { - return native_measureText(thisPaint, text.toCharArray(), 0, text.length()); + /*package*/ static float native_measureText(Paint thisPaint, String text, int bidiFlags) { + return native_measureText(thisPaint, text.toCharArray(), 0, text.length(), bidiFlags); } @LayoutlibDelegate /*package*/ static int native_breakText(Paint thisPaint, char[] text, int index, int count, - float maxWidth, float[] measuredWidth) { + float maxWidth, int bidiFlags, float[] measuredWidth) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); @@ -614,7 +615,7 @@ public class Paint_Delegate { } // measure from start to end - RectF bounds = delegate.measureText(text, start, end - start + 1, false /*isRtl*/); + RectF bounds = delegate.measureText(text, start, end - start + 1, isRtl(bidiFlags)); float res = bounds.right - bounds.left; if (measuredWidth != null) { @@ -635,9 +636,9 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static int native_breakText(Paint thisPaint, String text, boolean measureForwards, - float maxWidth, float[] measuredWidth) { + float maxWidth, int bidiFlags, float[] measuredWidth) { return native_breakText(thisPaint, text.toCharArray(), 0, text.length(), maxWidth, - measuredWidth); + bidiFlags, measuredWidth); } @LayoutlibDelegate @@ -922,7 +923,7 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static int native_getTextWidths(int native_object, char[] text, int index, - int count, float[] widths) { + int count, int bidiFlags, float[] widths) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { @@ -964,9 +965,9 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static int native_getTextWidths(int native_object, String text, int start, - int end, float[] widths) { + int end, int bidiFlags, float[] widths) { return native_getTextWidths(native_object, text.toCharArray(), start, end - start, - widths); + bidiFlags, widths); } @LayoutlibDelegate @@ -979,7 +980,7 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static float native_getTextRunAdvances(int native_object, char[] text, int index, int count, int contextIndex, int contextCount, - int flags, float[] advances, int advancesIndex, int reserved) { + int flags, float[] advances, int advancesIndex) { if (advances != null) for (int i = advancesIndex; i< advancesIndex+count; i++) @@ -1000,14 +1001,14 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static float native_getTextRunAdvances(int native_object, String text, int start, int end, int contextStart, int contextEnd, - int flags, float[] advances, int advancesIndex, int reserved) { + int flags, float[] advances, int advancesIndex) { // FIXME: support contextStart and contextEnd int count = end - start; char[] buffer = TemporaryBuffer.obtain(count); TextUtils.getChars(text, start, end, buffer, 0); return native_getTextRunAdvances(native_object, buffer, 0, count, contextStart, - contextEnd - contextStart, flags, advances, advancesIndex, reserved); + contextEnd - contextStart, flags, advances, advancesIndex); } @LayoutlibDelegate @@ -1046,22 +1047,21 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static void nativeGetStringBounds(int nativePaint, String text, int start, - int end, Rect bounds) { - nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start, + int end, int bidiFlags, Rect bounds) { + nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start, bidiFlags, bounds); } @LayoutlibDelegate /*package*/ static void nativeGetCharArrayBounds(int nativePaint, char[] text, int index, - int count, Rect bounds) { + int count, int bidiFlags, Rect bounds) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(nativePaint); if (delegate == null || delegate.mFonts == null || delegate.mFonts.size() == 0) { return; } - - delegate.measureText(text, index, count, false /*isRtl*/).roundOut(bounds); + delegate.measureText(text, index, count, isRtl(bidiFlags)).roundOut(bounds); } @LayoutlibDelegate diff --git a/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java index cb31b8f..57af6e9 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java @@ -275,21 +275,21 @@ public class Region_Delegate { } @LayoutlibDelegate - /*package*/ static boolean nativeSetRegion(int native_dst, int native_src) { + /*package*/ static void nativeSetRegion(int native_dst, int native_src) { Region_Delegate dstRegion = sManager.getDelegate(native_dst); if (dstRegion == null) { - return true; + return; } Region_Delegate srcRegion = sManager.getDelegate(native_src); if (srcRegion == null) { - return true; + return; } dstRegion.mArea.reset(); dstRegion.mArea.add(srcRegion.mArea); - return true; + return; } @LayoutlibDelegate diff --git a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java index 9b291cf..b50e98b 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java @@ -191,11 +191,6 @@ public final class Typeface_Delegate { return delegate.mStyle; } - @LayoutlibDelegate - /*package*/ static void setGammaForText(float blackGamma, float whiteGamma) { - // This is for device testing only: pass - } - // ---- Private delegate/helper methods ---- private Typeface_Delegate(String family, int style) { diff --git a/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java b/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java index 091c6e5..434b131 100644 --- a/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java +++ b/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java @@ -16,12 +16,14 @@ package android.view; +import android.graphics.Point; import com.android.internal.view.IInputContext; import com.android.internal.view.IInputMethodClient; import android.content.res.CompatibilityInfo; import android.content.res.Configuration; import android.graphics.Bitmap; +import android.graphics.Rect; import android.os.Bundle; import android.os.IBinder; import android.os.IRemoteCallback; @@ -30,13 +32,11 @@ import android.util.DisplayMetrics; import android.view.Display; import android.view.Gravity; import android.view.IApplicationToken; -import android.view.IDisplayContentChangeListener; import android.view.IInputFilter; import android.view.IOnKeyguardExitResult; import android.view.IRotationWatcher; import android.view.IWindowManager; import android.view.IWindowSession; -import android.view.WindowInfo; import java.util.List; @@ -87,7 +87,7 @@ public class IWindowManagerImpl implements IWindowManager { // ---- unused implementation of IWindowManager ---- @Override - public void addAppToken(int arg0, int arg1p5, IApplicationToken arg1, int arg2, int arg3, boolean arg4, + public void addAppToken(int arg0, IApplicationToken arg1, int arg2, int arg3, boolean arg4, boolean arg5) throws RemoteException { // TODO Auto-generated method stub @@ -111,6 +111,12 @@ public class IWindowManagerImpl implements IWindowManager { } @Override + public void setOverscan(int displayId, int left, int top, int right, int bottom) + throws RemoteException { + // TODO Auto-generated method stub + } + + @Override public void closeSystemDialogs(String arg0) throws RemoteException { // TODO Auto-generated method stub @@ -343,11 +349,31 @@ public class IWindowManagerImpl implements IWindowManager { } @Override + public void getInitialDisplaySize(int displayId, Point size) { + // TODO Auto-generated method stub + } + + @Override + public void getBaseDisplaySize(int displayId, Point size) { + // TODO Auto-generated method stub + } + + @Override public void setForcedDisplaySize(int displayId, int arg0, int arg1) throws RemoteException { // TODO Auto-generated method stub } @Override + public int getInitialDisplayDensity(int displayId) { + return -1; + } + + @Override + public int getBaseDisplayDensity(int displayId) { + return -1; + } + + @Override public void setForcedDisplayDensity(int displayId, int density) throws RemoteException { // TODO Auto-generated method stub } @@ -423,6 +449,10 @@ public class IWindowManagerImpl implements IWindowManager { } @Override + public void removeRotationWatcher(IRotationWatcher arg0) throws RemoteException { + } + + @Override public boolean waitForWindowDrawn(IBinder token, IRemoteCallback callback) { return false; } @@ -446,7 +476,7 @@ public class IWindowManagerImpl implements IWindowManager { public void lockNow(Bundle options) { // TODO Auto-generated method stub } - + @Override public boolean isSafeModeEnabled() { return false; @@ -464,43 +494,34 @@ public class IWindowManagerImpl implements IWindowManager { } @Override - public float getWindowCompatibilityScale(IBinder windowToken) throws RemoteException { - // TODO Auto-generated method stub - return 0; - } - - @Override public void setInputFilter(IInputFilter filter) throws RemoteException { // TODO Auto-generated method stub } @Override - public void magnifyDisplay(int dipslayId, float scale, float offsetX, float offsetY) - throws RemoteException { + public void getWindowFrame(IBinder token, Rect outFrame) { // TODO Auto-generated method stub } @Override - public void addDisplayContentChangeListener(int displayId, - IDisplayContentChangeListener listener) throws RemoteException { + public void setMagnificationCallbacks(IMagnificationCallbacks callbacks) { // TODO Auto-generated method stub } @Override - public void removeDisplayContentChangeListener(int displayId, - IDisplayContentChangeListener listener) throws RemoteException { + public void setMagnificationSpec(MagnificationSpec spec) { // TODO Auto-generated method stub } @Override - public WindowInfo getWindowInfo(IBinder token) throws RemoteException { + public MagnificationSpec getCompatibleMagnificationSpecForWindow(IBinder windowToken) { // TODO Auto-generated method stub return null; } @Override - public void getVisibleWindowsForDisplay(int displayId, List<WindowInfo> outInfos) - throws RemoteException { + public boolean isRotationFrozen() throws RemoteException { // TODO Auto-generated method stub + return false; } } diff --git a/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java b/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java index 7a6e52e..dc4f9c8 100644 --- a/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java +++ b/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java @@ -22,6 +22,6 @@ package android.view.inputmethod; public class InputMethodManager_Accessor { public static void resetInstance() { - InputMethodManager.mInstance = null; + InputMethodManager.sInstance = null; } } diff --git a/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Delegate.java b/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Delegate.java index f056040..7c98847 100644 --- a/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Delegate.java +++ b/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Delegate.java @@ -35,28 +35,15 @@ public class InputMethodManager_Delegate { // ---- Overridden methods ---- @LayoutlibDelegate - /*package*/ static InputMethodManager getInstance(Looper mainLooper) { - synchronized (InputMethodManager.mInstanceSync) { - if (InputMethodManager.mInstance != null) { - return InputMethodManager.mInstance; + /*package*/ static InputMethodManager getInstance() { + synchronized (InputMethodManager.class) { + InputMethodManager imm = InputMethodManager.peekInstance(); + if (imm == null) { + imm = new InputMethodManager( + new BridgeIInputMethodManager(), Looper.getMainLooper()); + InputMethodManager.sInstance = imm; } - - InputMethodManager.mInstance = new InputMethodManager(new BridgeIInputMethodManager(), - mainLooper); - } - return InputMethodManager.mInstance; - } - - @LayoutlibDelegate - /*package*/ static InputMethodManager getInstance(Context context) { - synchronized (InputMethodManager.mInstanceSync) { - if (InputMethodManager.mInstance != null) { - return InputMethodManager.mInstance; - } - - InputMethodManager.mInstance = new InputMethodManager(new BridgeIInputMethodManager(), - Looper.myLooper()); + return imm; } - return InputMethodManager.mInstance; } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContentProvider.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContentProvider.java index f770ccc..4aea38f 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContentProvider.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContentProvider.java @@ -40,26 +40,30 @@ import java.util.ArrayList; */ public final class BridgeContentProvider implements IContentProvider { @Override - public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> arg0) + public ContentProviderResult[] applyBatch(String callingPackage, + ArrayList<ContentProviderOperation> arg0) throws RemoteException, OperationApplicationException { // TODO Auto-generated method stub return null; } @Override - public int bulkInsert(Uri arg0, ContentValues[] arg1) throws RemoteException { + public int bulkInsert(String callingPackage, Uri arg0, ContentValues[] arg1) + throws RemoteException { // TODO Auto-generated method stub return 0; } @Override - public Bundle call(String arg0, String arg1, Bundle arg2) throws RemoteException { + public Bundle call(String callingPackage, String arg0, String arg1, Bundle arg2) + throws RemoteException { // TODO Auto-generated method stub return null; } @Override - public int delete(Uri arg0, String arg1, String[] arg2) throws RemoteException { + public int delete(String callingPackage, Uri arg0, String arg1, String[] arg2) + throws RemoteException { // TODO Auto-generated method stub return 0; } @@ -71,35 +75,35 @@ public final class BridgeContentProvider implements IContentProvider { } @Override - public Uri insert(Uri arg0, ContentValues arg1) throws RemoteException { + public Uri insert(String callingPackage, Uri arg0, ContentValues arg1) throws RemoteException { // TODO Auto-generated method stub return null; } @Override - public AssetFileDescriptor openAssetFile(Uri arg0, String arg1) throws RemoteException, - FileNotFoundException { + public AssetFileDescriptor openAssetFile(String callingPackage, Uri arg0, String arg1) + throws RemoteException, FileNotFoundException { // TODO Auto-generated method stub return null; } @Override - public ParcelFileDescriptor openFile(Uri arg0, String arg1) throws RemoteException, - FileNotFoundException { + public ParcelFileDescriptor openFile(String callingPackage, Uri arg0, String arg1) + throws RemoteException, FileNotFoundException { // TODO Auto-generated method stub return null; } @Override - public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, String arg4, - ICancellationSignal arg5) throws RemoteException { + public Cursor query(String callingPackage, Uri arg0, String[] arg1, String arg2, String[] arg3, + String arg4, ICancellationSignal arg5) throws RemoteException { // TODO Auto-generated method stub return null; } @Override - public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) - throws RemoteException { + public int update(String callingPackage, Uri arg0, ContentValues arg1, String arg2, + String[] arg3) throws RemoteException { // TODO Auto-generated method stub return 0; } @@ -117,8 +121,8 @@ public final class BridgeContentProvider implements IContentProvider { } @Override - public AssetFileDescriptor openTypedAssetFile(Uri arg0, String arg1, Bundle arg2) - throws RemoteException, FileNotFoundException { + public AssetFileDescriptor openTypedAssetFile(String callingPackage, Uri arg0, String arg1, + Bundle arg2) throws RemoteException, FileNotFoundException { // TODO Auto-generated method stub return null; } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java index 3fcd987..9464f8c 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java @@ -1101,6 +1101,12 @@ public final class BridgeContext extends Context { } @Override + public String getBasePackageName() { + // pass + return null; + } + + @Override public ApplicationInfo getApplicationInfo() { return mApplicationInfo; } @@ -1221,6 +1227,11 @@ public final class BridgeContext extends Context { } @Override + public void sendBroadcast(Intent intent, String receiverPermission, int appOp) { + // pass + } + + @Override public void sendOrderedBroadcast(Intent arg0, String arg1) { // pass @@ -1235,6 +1246,13 @@ public final class BridgeContext extends Context { } @Override + public void sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp, + BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, + String initialData, Bundle initialExtras) { + // pass + } + + @Override public void sendBroadcastAsUser(Intent intent, UserHandle user) { // pass } @@ -1401,4 +1419,12 @@ public final class BridgeContext extends Context { // pass return null; } + + /** + * @hide + */ + @Override + public int getUserId() { + return 0; // not used + } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java index fa660e6..df576d2 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java @@ -47,7 +47,7 @@ public final class BridgeWindow implements IWindow { } @Override - public void resized(Rect arg1, Rect arg2, Rect arg3, + public void resized(Rect arg1, Rect arg1p5, Rect arg2, Rect arg3, boolean arg4, Configuration arg5) throws RemoteException { // pass for now. } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java index 67b0a9c..09e6878 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java @@ -24,6 +24,7 @@ import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; import android.view.IWindow; +import android.view.IWindowId; import android.view.IWindowSession; import android.view.InputChannel; import android.view.Surface; @@ -86,7 +87,7 @@ public final class BridgeWindowSession implements IWindowSession { } @Override public int relayout(IWindow arg0, int seq, LayoutParams arg1, int arg2, int arg3, int arg4, - int arg4_5, Rect arg5, Rect arg6, Rect arg7, Configuration arg7b, + int arg4_5, Rect arg5Z, Rect arg5, Rect arg6, Rect arg7, Configuration arg7b, Surface arg8) throws RemoteException { // pass for now. return 0; @@ -199,4 +200,10 @@ public final class BridgeWindowSession implements IWindowSession { public void onRectangleOnScreenRequested(IBinder window, Rect rectangle, boolean immediate) { // pass for now. } + + @Override + public IWindowId getWindowId(IBinder window) throws RemoteException { + // pass for now. + return null; + } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java index ced1387..60f5331 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java @@ -234,7 +234,7 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso sCurrentContext = mContext; // create an InputMethodManager - InputMethodManager.getInstance(Looper.myLooper()); + InputMethodManager.getInstance(); LayoutLog currentLog = mParams.getLog(); Bridge.setLog(currentLog); diff --git a/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java b/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java index fd75f70..06ae804 100644 --- a/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java +++ b/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java @@ -17,6 +17,8 @@ package libcore.icu; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; +import com.ibm.icu.text.DateTimePatternGenerator; +import com.ibm.icu.util.ULocale; import java.util.Locale; @@ -44,6 +46,17 @@ public class ICU_Delegate { // --- Native methods accessing ICU's database. @LayoutlibDelegate + /*package*/ static String getBestDateTimePattern(String skeleton, String localeName) { + return DateTimePatternGenerator.getInstance(new ULocale(localeName)) + .getBestPattern(skeleton); + } + + @LayoutlibDelegate + /*package*/ static String getCldrVersion() { + return "22.1.1"; // TODO: check what the right value should be. + } + + @LayoutlibDelegate /*package*/ static String getIcuVersion() { return "unknown_layoutlib"; } diff --git a/tools/layoutlib/create/README.txt b/tools/layoutlib/create/README.txt index e490ac5..ef2b185 100644 --- a/tools/layoutlib/create/README.txt +++ b/tools/layoutlib/create/README.txt @@ -169,11 +169,10 @@ This is the easiest: we currently inject the following classes: their return value. - CreateInfo class, which configured the generator. Not used yet, but could in theory help us track what the generator changed. -- AutoCloseable is part of Java 7. To enable us to still run on Java 6, a new class is - injected. The implementation for the class has been taken from Android's libcore - (platform/libcore/luni/src/main/java/java/lang/AutoCloseable.java). -- Charsets, ModifiedUtf8, IntegralToString and UnsafeByteSequence are not part of the - standard JAVA VM. +- AutoCloseable and Objects are part of Java 7. To enable us to still run on Java 6, new + classes are injected. The implementation for these classes has been taken from + Android's libcore (platform/libcore/luni/src/main/java/java/...). +- Charsets, IntegralToString and UnsafeByteSequence are not part of the standard JAVA VM. They are added to the Dalvik VM for performance reasons. An implementation that is very close to the original (which is at platform/libcore/luni/src/main/java/...) is injected. Since these classees were in part of the java package, where we can't inject classes, diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java index 93cf7d5..f362254 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java @@ -18,9 +18,9 @@ package com.android.tools.layoutlib.create; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import com.android.tools.layoutlib.java.AutoCloseable; -import com.android.tools.layoutlib.java.ModifiedUtf8; import com.android.tools.layoutlib.java.Charsets; import com.android.tools.layoutlib.java.IntegralToString; +import com.android.tools.layoutlib.java.Objects; import com.android.tools.layoutlib.java.UnsafeByteSequence; /** @@ -112,9 +112,9 @@ public final class CreateInfo implements ICreateInfo { LayoutlibDelegate.class, /* Java package classes */ AutoCloseable.class, + Objects.class, IntegralToString.class, UnsafeByteSequence.class, - ModifiedUtf8.class, Charsets.class, }; @@ -229,7 +229,7 @@ public final class CreateInfo implements ICreateInfo { private final static String[] JAVA_PKG_CLASSES = new String[] { "java.lang.AutoCloseable", "com.android.tools.layoutlib.java.AutoCloseable", - "java.nio.charset.ModifiedUtf8", "com.android.tools.layoutlib.java.ModifiedUtf8", + "java.util.Objects", "com.android.tools.layoutlib.java.Objects", "java.nio.charset.Charsets", "com.android.tools.layoutlib.java.Charsets", "java.lang.IntegralToString", "com.android.tools.layoutlib.java.IntegralToString", "java.lang.UnsafeByteSequence", "com.android.tools.layoutlib.java.UnsafeByteSequence", diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/java/ModifiedUtf8.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/java/ModifiedUtf8.java deleted file mode 100644 index 77c4f3a..0000000 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/java/ModifiedUtf8.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -package com.android.tools.layoutlib.java; - -import java.io.UTFDataFormatException; -import java.nio.ByteOrder; - -/** - * Defines the same class as the java.nio.charset.ModifiedUtf8 which was added in - * Dalvik VM. This hack, provides a replacement for that class which can't be - * loaded in the standard JVM since it's in the java package and standard JVM - * doesn't have it. An implementation of the native methods in the original - * class has been added. - * <p/> - * Extracted from API level 17, file: - * platform/libcore/luni/src/main/java/java/nio/charset/ModifiedUtf8 - */ -public class ModifiedUtf8 { - /** - * Decodes a byte array containing <i>modified UTF-8</i> bytes into a string. - * - * <p>Note that although this method decodes the (supposedly impossible) zero byte to U+0000, - * that's what the RI does too. - */ - public static String decode(byte[] in, char[] out, int offset, int utfSize) throws UTFDataFormatException { - int count = 0, s = 0, a; - while (count < utfSize) { - if ((out[s] = (char) in[offset + count++]) < '\u0080') { - s++; - } else if (((a = out[s]) & 0xe0) == 0xc0) { - if (count >= utfSize) { - throw new UTFDataFormatException("bad second byte at " + count); - } - int b = in[offset + count++]; - if ((b & 0xC0) != 0x80) { - throw new UTFDataFormatException("bad second byte at " + (count - 1)); - } - out[s++] = (char) (((a & 0x1F) << 6) | (b & 0x3F)); - } else if ((a & 0xf0) == 0xe0) { - if (count + 1 >= utfSize) { - throw new UTFDataFormatException("bad third byte at " + (count + 1)); - } - int b = in[offset + count++]; - int c = in[offset + count++]; - if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) { - throw new UTFDataFormatException("bad second or third byte at " + (count - 2)); - } - out[s++] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F)); - } else { - throw new UTFDataFormatException("bad byte at " + (count - 1)); - } - } - return new String(out, 0, s); - } - - /** - * Returns the number of bytes the modified UTF-8 representation of 's' would take. Note - * that this is just the space for the bytes representing the characters, not the length - * which precedes those bytes, because different callers represent the length differently, - * as two, four, or even eight bytes. If {@code shortLength} is true, we'll throw an - * exception if the string is too long for its length to be represented by a short. - */ - public static long countBytes(String s, boolean shortLength) throws UTFDataFormatException { - long result = 0; - final int length = s.length(); - for (int i = 0; i < length; ++i) { - char ch = s.charAt(i); - if (ch != 0 && ch <= 127) { // U+0000 uses two bytes. - ++result; - } else if (ch <= 2047) { - result += 2; - } else { - result += 3; - } - if (shortLength && result > 65535) { - throw new UTFDataFormatException("String more than 65535 UTF bytes long"); - } - } - return result; - } - - /** - * Encodes the <i>modified UTF-8</i> bytes corresponding to string {@code s} into the - * byte array {@code dst}, starting at the given {@code offset}. - */ - public static void encode(byte[] dst, int offset, String s) { - final int length = s.length(); - for (int i = 0; i < length; i++) { - char ch = s.charAt(i); - if (ch != 0 && ch <= 127) { // U+0000 uses two bytes. - dst[offset++] = (byte) ch; - } else if (ch <= 2047) { - dst[offset++] = (byte) (0xc0 | (0x1f & (ch >> 6))); - dst[offset++] = (byte) (0x80 | (0x3f & ch)); - } else { - dst[offset++] = (byte) (0xe0 | (0x0f & (ch >> 12))); - dst[offset++] = (byte) (0x80 | (0x3f & (ch >> 6))); - dst[offset++] = (byte) (0x80 | (0x3f & ch)); - } - } - } - - /** - * Returns an array containing the <i>modified UTF-8</i> form of {@code s}, using a - * big-endian 16-bit length. Throws UTFDataFormatException if {@code s} is too long - * for a two-byte length. - */ - public static byte[] encode(String s) throws UTFDataFormatException { - int utfCount = (int) ModifiedUtf8.countBytes(s, true); - // Original statement used libcore.io.SizeOf.SHORT. Since we don't have that, we - // substitute it's value directly, which is 2. - byte[] result = new byte[2 + utfCount]; - // The original statement had libcore.io.Memory.pokeShort(). We provide it's implementation - // below in a private method. - pokeShort(result, 0, (short) utfCount, ByteOrder.BIG_ENDIAN); - ModifiedUtf8.encode(result, 2, s); - return result; - } - - // Copied from libcore.io.Memory.pokeShort(). - private static void pokeShort(byte[] dst, int offset, short value, ByteOrder order) { - if (order == ByteOrder.BIG_ENDIAN) { - dst[offset++] = (byte) ((value >> 8) & 0xff); - dst[offset ] = (byte) ((value >> 0) & 0xff); - } else { - dst[offset++] = (byte) ((value >> 0) & 0xff); - dst[offset ] = (byte) ((value >> 8) & 0xff); - } - } - - private ModifiedUtf8() { - } -} diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/java/Objects.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/java/Objects.java new file mode 100644 index 0000000..eb1ef72 --- /dev/null +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/java/Objects.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2013 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. + */ + +package com.android.tools.layoutlib.java; + +import java.util.Arrays; +import java.util.Comparator; + +/** + * Defines the same class as the java.util.Objects which is added in Java 7. + * This hack makes it possible to run the Android code which uses Java 7 features + * (API 18 and beyond) to run on Java 6. + * <p/> + * Extracted from API level 19, file: + * platform/libcore/luni/src/main/java/java/util/Objects.java + */ +public final class Objects { + private Objects() {} + + /** + * Returns 0 if {@code a == b}, or {@code c.compare(a, b)} otherwise. + * That is, this makes {@code c} null-safe. + */ + public static <T> int compare(T a, T b, Comparator<? super T> c) { + if (a == b) { + return 0; + } + return c.compare(a, b); + } + + /** + * Returns true if both arguments are null, + * the result of {@link Arrays#equals} if both arguments are primitive arrays, + * the result of {@link Arrays#deepEquals} if both arguments are arrays of reference types, + * and the result of {@link #equals} otherwise. + */ + public static boolean deepEquals(Object a, Object b) { + if (a == null || b == null) { + return a == b; + } else if (a instanceof Object[] && b instanceof Object[]) { + return Arrays.deepEquals((Object[]) a, (Object[]) b); + } else if (a instanceof boolean[] && b instanceof boolean[]) { + return Arrays.equals((boolean[]) a, (boolean[]) b); + } else if (a instanceof byte[] && b instanceof byte[]) { + return Arrays.equals((byte[]) a, (byte[]) b); + } else if (a instanceof char[] && b instanceof char[]) { + return Arrays.equals((char[]) a, (char[]) b); + } else if (a instanceof double[] && b instanceof double[]) { + return Arrays.equals((double[]) a, (double[]) b); + } else if (a instanceof float[] && b instanceof float[]) { + return Arrays.equals((float[]) a, (float[]) b); + } else if (a instanceof int[] && b instanceof int[]) { + return Arrays.equals((int[]) a, (int[]) b); + } else if (a instanceof long[] && b instanceof long[]) { + return Arrays.equals((long[]) a, (long[]) b); + } else if (a instanceof short[] && b instanceof short[]) { + return Arrays.equals((short[]) a, (short[]) b); + } + return a.equals(b); + } + + /** + * Null-safe equivalent of {@code a.equals(b)}. + */ + public static boolean equals(Object a, Object b) { + return (a == null) ? (b == null) : a.equals(b); + } + + /** + * Convenience wrapper for {@link Arrays#hashCode}, adding varargs. + * This can be used to compute a hash code for an object's fields as follows: + * {@code Objects.hash(a, b, c)}. + */ + public static int hash(Object... values) { + return Arrays.hashCode(values); + } + + /** + * Returns 0 for null or {@code o.hashCode()}. + */ + public static int hashCode(Object o) { + return (o == null) ? 0 : o.hashCode(); + } + + /** + * Returns {@code o} if non-null, or throws {@code NullPointerException}. + */ + public static <T> T requireNonNull(T o) { + if (o == null) { + throw new NullPointerException(); + } + return o; + } + + /** + * Returns {@code o} if non-null, or throws {@code NullPointerException} + * with the given detail message. + */ + public static <T> T requireNonNull(T o, String message) { + if (o == null) { + throw new NullPointerException(message); + } + return o; + } + + /** + * Returns "null" for null or {@code o.toString()}. + */ + public static String toString(Object o) { + return (o == null) ? "null" : o.toString(); + } + + /** + * Returns {@code nullString} for null or {@code o.toString()}. + */ + public static String toString(Object o, String nullString) { + return (o == null) ? nullString : o.toString(); + } +}
\ No newline at end of file diff --git a/tools/obbtool/Android.mk b/tools/obbtool/Android.mk index dd57ae6..ad8de69 100644 --- a/tools/obbtool/Android.mk +++ b/tools/obbtool/Android.mk @@ -20,7 +20,8 @@ LOCAL_CFLAGS := -Wall -Werror LOCAL_STATIC_LIBRARIES := \ libutils \ libandroidfw \ - libcutils + libcutils \ + liblog ifeq ($(HOST_OS),linux) LOCAL_LDLIBS += -ldl -lpthread diff --git a/tools/preload/Policy.java b/tools/preload/Policy.java index f557365..ca0291b 100644 --- a/tools/preload/Policy.java +++ b/tools/preload/Policy.java @@ -69,6 +69,7 @@ public class Policy { // Threads "android.os.AsyncTask", "android.pim.ContactsAsyncHelper", + "android.webkit.WebViewClassic$1", "java.lang.ProcessManager" )); diff --git a/tools/preload/Record.java b/tools/preload/Record.java index 14e9201..d0a2af4 100644 --- a/tools/preload/Record.java +++ b/tools/preload/Record.java @@ -42,14 +42,24 @@ class Record { "com.android.fakeoemfeatures\\u003Abackground", "com.android.fakeoemfeatures:core", "com.android.fakeoemfeatures\\u003Acore", + "com.android.launcher:wallpaper_chooser", + "com.android.launcher\\u003Awallpaper_chooser", + "com.android.nfc:handover", + "com.android.nfc\\u003Ahandover", "com.google.android.music:main", "com.google.android.music\\u003Amain", "com.google.android.music:ui", "com.google.android.music\\u003Aui", "com.google.android.setupwarlock:broker", "com.google.android.setupwarlock\\u003Abroker", + "mobi.mgeek.TunnyBrowser:DolphinNotification", + "mobi.mgeek.TunnyBrowser\\u003ADolphinNotification", + "com.qo.android.sp.oem:Quickword", + "com.qo.android.sp.oem\\u003AQuickword", "android:ui", "android\\u003Aui", + "system:ui", + "system\\u003Aui", }; enum Type { diff --git a/tools/validatekeymaps/Android.mk b/tools/validatekeymaps/Android.mk index fce2e93..90fbc08 100644 --- a/tools/validatekeymaps/Android.mk +++ b/tools/validatekeymaps/Android.mk @@ -20,7 +20,8 @@ LOCAL_CFLAGS := -Wall -Werror LOCAL_STATIC_LIBRARIES := \ libandroidfw \ libutils \ - libcutils + libcutils \ + liblog ifeq ($(HOST_OS),linux) LOCAL_LDLIBS += -ldl -lpthread |