summaryrefslogtreecommitdiff
path: root/include
AgeCommit message (Collapse)Author
2018-08-13Move libcore/include to point of useNeil Fuller
Move the ScopedIcuLocale.h and ScopedJavaUnicodeString.h to the places they are used. Remove the pretence that libcore/ is in the business of providing native utility code and this should make that more obvious. Test: Build Bug: 111055375 Change-Id: I5113a2a5275cf4e1dcc52782bc957986af35f9c3
2017-07-19libcore: use proper nativehelper headersSteven Moreland
libnativeheader exports headers under nativeheader. These were available before incorrectly as global headers in order to give access to jni.h. Test: modules using libcore find headers Bug: 63762847 Change-Id: Ic5873017bcf4d1c6e0873d7030ce56ee597b580d
2017-07-17Update JNI code in preparation for ICU 59 switching to C++11 char16_t.Fredrik Roubert
ICU 59 (update pending on the aosp/icu59 branch) has switched to using the C++11 char16_t data type, which is a distinct type from uint16_t (which is what JNI's jchar is typedef'd as), even though they are bitwise identical. All code that passes UTF-16 data between ICU4C and JNI must therefore be updated with typecasts in the appropriate places before ICU 59 is merged to aosp/master. Bug: 37554848 Test: make Change-Id: I10808c4104e9dabfd90975ee61c465b22ff30281
2016-09-14Remove LocalArray.h.Chih-Hung Hsieh
* Replace LocalArray with android::base::StringPrintf. Bug: 28341362 Test: build with WITH_TIDY=1 Change-Id: Ifa0c8f5d9f41617613ba7ea771e32d4019b61f65
2016-07-27Remove ScopedPthreadMutexLock.hColin Cross
libnativehelper was the last user, and has been converted to use std::lock_guard instead. Change-Id: I61cb72050f6ad033f90e70849a5db03b09ef0454
2015-03-06Explicitly specify the icu:: namespace.Elliott Hughes
Bug: 15350832 Change-Id: I8d84f3e50b643806ccf01190797c69ce6445b539
2014-06-16Pass BCP-47 tags and not Locale.toString results to ICU.Elliott Hughes
ICU can't handle the new toString forms for scripts etc. and it's also guaranteed to deal with BCP-47 tags correctly. Most of the changes in this patch are required to keep backwards compatibility for getDisplayCountry string etc. in the face of the transformations toLanguageTag performs. A few tests were changed, but for the better. The tagalog -> filipino charlie foxtrot will be dealt with in a follow up change. Co-Authored-By: Narayan Kamath <narayan@google.com> Change-Id: Ia7f26d92a0e38c4bbb1d839c0fbd8ad16a473bf5
2013-09-06Remove StaticAssert.h.Elliott Hughes
The switch to C++11 means we have static_assert now. Change-Id: Iaa39af8c4fa7143fc83fda550543eb3270f9f161
2013-05-14Move ScopedFd from libcore to libnativehelper (part 2)Brian Carlstrom
Change-Id: Idd1aca43a2315398d52fec7c8fba8906e970d8cb
2013-05-10Move more utility classes from libcore to libnativehelper (part 2)Brian Carlstrom
Change-Id: If23ff812f5283c15aeb2ca3a5d82f685f78d540d
2013-05-01Fix ScopedStringChars to behave like ScopedUtfChars.Elliott Hughes
Also reformat in Google C++ style and remove a couple of unnecessary #includes. Bug: https://code.google.com/p/android/issues/detail?id=45724 Change-Id: I6d1a78b3b1f72e7015baba64811d9749f330fba7
2013-02-08Expose Java arrays inside ScopedPrimitiveArrays.Jeff Sharkey
This makes writing SetObjectField() code easier. (cherry-pick of 74adde45e60587a41d7ec8ed59f247f7c33ac6ac.) Change-Id: Ia64d58748ce721cbdc89742c020edd22dbb694b0
2013-02-04Add icu4c-backed transliteration.Elliott Hughes
Change-Id: I4194810646a2a0661331aaf941fb5f99ce7758b1
2012-08-01Clean up #includes in ScopedLocalRef.h.Elliott Hughes
Change-Id: I755dc2feb90d767a1e16e98bd39f1de7681eb60c
2012-08-01Improve the BaseDexClassLoader detail message, and make ScopedLocalRef more ↵Elliott Hughes
unique_ptr-like. (cherry-pick of 1c459db4ea31c1f284353bc71bfd2dbc97ca53d7.) Conflicts: include/ScopedLocalRef.h Change-Id: Id01cb907406cc93f6b0f6ddaa8e7fb3714d18c53
2011-06-07Check that the result of UniquePtr::release is always used.Elliott Hughes
(And silence the warnings in those cases where it isn't because we're working around OpenSSL API lossage.) Change-Id: Ibc7958373e7a899a6cd03a0177f97bf3a73c0e15
2011-04-25Fix ByteBuffer.put(ByteBuffer).Elliott Hughes
To do this tastefully required some cunning in the native code. The new ScopedBytesRO/ScopedBytesRW classes let us paper over the differences between byte[] and DirectByteBuffer, which in turn lets us paper over the differences between the various kinds of ByteBuffer. I've also rewritten Posix.read/Posix.readDirectBuffer and Posix.write/Posix.writeDirectBuffer to use the same idea. I haven't rewritten readv and writev, but can do and probably should. Bug: http://code.google.com/p/android/issues/detail?id=16184 Change-Id: Ia30d2f2fe1b1716a8f068187df2218b407a55aae
2011-04-08Use JNI's jchar instead of ICU's (equivalent) UChar.Elliott Hughes
This class should be usable by native code unrelated to ICU. Change-Id: I5017a023b68b3c9d625162f3a0b2dfb7a6edbeb8
2011-02-07Clean up the CharsetDecoder/CharsetEncoder implementation a bit more.Elliott Hughes
This removes the duplicated error-checking in the ICU classes that started this investigation, but also cleans up a bunch of other stuff. There shouldn't be any other behavioral differences, just clearer code. Bug: 3418769 Change-Id: I4da4d2a5b2fce1b152e527909b7c76a6db76c5c0
2010-10-18Add and use STATIC_ASSERT for compile-time asserts, and remove some 32-bit ↵Elliott Hughes
limits. This started with the question "are the fields in struct statfs really 64-bit?", but grew a bit. I'll need ftruncate64 in bionic before we can kill offsetTooLarge completely. Change-Id: Ia1dcda49e2c93c3cb0f9efe61a70c667c1415bee
2010-08-09Make network I/O interruptible.Elliott Hughes
Every thread about to block on network I/O registers its thread id and the fd it's going to block on. In close, we scan the list and signal every thread that's blocked on the fd we're closing. They wake up with EINTR, see that their java.io.FileDescriptor has been invalidated (by the close code), and infer that this EINTR is not to be retried: this EINTR implies that they should throw. This patch also fixes a couple of bugs in accept. We were trying (and, obviously, failing) to reset SO_RCVTIMEO on fd -1 if the accept failed, and then throwing an exception relating to that rather than the failed accept(2). We were also not treating timeouts as a special case of failure and throwing the appropriate SocketTimeoutException. (One has to suspect that there's an errno-to-Exception function that we could write that would work for all this native code.) This patch also cleans up connect a little more. I've inlined doConnect into its single caller, I've removed the bogus use of 100ms polling, and I've rewritten the checking for success/failure to be based on the advice in Stevens' "Unix Network Programming". Bug: 2823977 Change-Id: I4f0cbd95be9ba25368be166008855a80c5d30845
2010-07-12Add null-pointer checking to ScopedPrimitiveArray.Elliott Hughes
This style worked well for ScopedUtfChars. It moves null-pointer checking inside the class, thereby encouraging us to remember to check for the unlikely out-of-memory failures too. I've also broken up some tests that were trying to check multiple scoped arrays at once. This idiom was broken because as soon as there's a pending exception, it's a JNI error to even attempt to set up the next scoped primitive array. In the absence of C++ exceptions, we have to check these one by one. Change-Id: I2f4b397ae2873597e309d86fcc5912f3fcf0f304
2010-06-01Fix sim-eng build with missing #include.Elliott Hughes
Change-Id: I77d9841f7112235096c54ac70479ad09f2b0559d
2010-06-01Refactor some of the OSNetworkSystem stuff to more appropriate homes.Elliott Hughes
Also rewrite PlainDatagramSocketImpl.peek in terms of existing primitives rather than requiring its own. I still don't see how it can get called, but at least now it doesn't require its own native code. Bug: 2686833 Change-Id: I0453add66dab4c7095ee2a3f51a49efbd1205598
2010-05-26Enhance ScopedUtfChars to include the null check most callers were missing.Elliott Hughes
Also switch most non-users over to ScopedUtfChars. Also ensure all users check that ScopedUtfChars was successful in getting the chars. Also rewrite ObjectInputStream and ObjectOutputStream without duplication. Change-Id: I929d00fe3ff50b303cba4a2cf2269355e9fef5f9
2010-05-20Add write-back ScopedPrimitiveArrays (and use them).Elliott Hughes
I've left the remaining Get/Release Critical calls in "NativeConverter.cpp" for the next patch, even though getting into position to fix them is part of the point of this patch. Change-Id: I99e15a3cf3919008343ae4dc856c86ced233e07a
2010-05-17Make ScopedLocalRef more convenient, and use it more widely.Elliott Hughes
Even though every reference type is a jobject, it's useful to be able to use more specific types. Change-Id: Id8056d0e18380675c90f08c4173a8b34b4d5d983
2010-05-17Expand upon the old ScopedByteArray, and start removing some of the ↵Elliott Hughes
Get/ReleaseCritical calls. This adds Scoped*Array classes for all primitive types, and switches all read-only users of arrays over. At the same time, all read-only users of Get/ReleaseCritical get switched to non-critical access. Bug: 2663177 Change-Id: I5542cea3e24faa987ced463fcb695b9598da94af
2010-05-15Remove ScopedGlobalRef (and other cleanups)Brian Carlstrom
ScopedGlobalRef caused more trouble that it was worth. Rather than trying to fix it to require updating of the JNIEnv, remove it to remove the temptation for others to use it. Also update SSL_set_ciphers_lists to use ScopedLocalRef and add HTML anchors to Standard names javadoc JSEE references. Change-Id: Ic3ed1bae3f29ee971d4461de31395b78c4949090
2010-05-11Reduced the amount of memory used by the TimeZone display names.Elliott Hughes
Bug: 2672057 Change-Id: I2f31ff3b5fbbf5cf8e16c89ef78a5246c6c3733a
2010-05-07Move ScopedJavaUnicodeString to include/Kenny Root
Change-Id: I51a2cdd80e910996f3143a7b699c3d4b408d105a
2010-05-06Moving OpenSSLSocketImpl native code to NativeCrypto (and other clearnup)Brian Carlstrom
Summary: - Finished consolidating OpenSSL native code into NativeCrypto - fixing local vs global ref bug with AppData Added new ScopedGlobalRef as part of this fix - fixed many historical memory leaks identified during code review - fixed lack of error checking on allcoation with OpenSSL *_new routines - Added to_SSL_CTX and to_SSL_SESSION to match to_SSL (renamed from getSslPointer) - Replaced most uses of GetByteArrayElements with ScopedByteArray (including cases where we we using ReleaseByteArrayElements(..,...,0) instead of JNI_ABORT) - Replaced uses of GetStringUTFChars with ScopedUtfChars Details: Finished consolidating OpenSSL native code into NativeCrypto OpenSSLSocketImpl NativeCrypto --------------------------------------- nativeread SSL_read_byte nativeread SSL_read nativewrite SSL_write_byte nativewrite SSL_write nativeinterrupt SSL_interrupt nativeclose SSL_shutdown nativeverifysignature verifysignature Also removed dead code that was wrapping SSL_get1_session luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp Fixed NativeCrypto_SSL_write and NativeCrypto_d2i_SSL_SESSION to use JNI_ABORT on release to avoid copy back of unchanged data (via ScopedByteArray). luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp While running the usual tests: adb shell run-core-tests tests.xnet.AllTests javax.net.ssl.AllTests there was an abort from the JNI checking because in the recent handshaking change, local refs were kept in AppData and then reused in later calls. Added new ScopedGlobalRef to handle the book keeping of this. luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java include/ScopedGlobalRef.h Fixed various leaks on old error paths spotted by reviewer. luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp Tracking move of verifySignature, a non-SSL bit of code that was lurking in OpenSSLSocketImpl luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java Change-Id: If1e409782bc99dc684039cfe3f53f8244e29346e
2010-04-23Dead code/cruft removal in the collation code.Elliott Hughes
I've also renamed ScopedUtfChars::data to ScopedUtfChars::c_str, by analogy with std::string (since this method has always been more like c_str than data). This also fixes a few leaks on error paths. The old code used to go all the way into native code to return a constant hash code of 1, so I've removed all that and switched to the idiomatic bogo hash code (with the idiomatic comment). Change-Id: I25da8c422155860b5ab348786d369c6c7598135c
2010-04-16Move the libcore registration out of libnativehelpers and into libcore.Elliott Hughes
Bug: 754114 Change-Id: Iaa03def509c10cbaa12fd2128584b93d4be4a6b7
2010-03-29Fix a bug, and protect against an unrelated class of bugs.Elliott Hughes
If the Java array allocation in InetAddress.cpp failed, we'd free NULL instead of the previously-allocated structure. This is a new bug in froyo, but only happens in out of memory situations, so doesn't seem worth fixing there. Unrelatedly, let's disallow assignment and copying of all our RAII classes. This isn't a mistake I've seen made, but it's easy to protect against, so we may as well do so consistently. Change-Id: I2433b31ff983d388788b09e59e08d661f1725ecd
2010-03-26Start cleaning up the Charset implementation.Elliott Hughes
This was going to be https://issues.apache.org/jira/browse/HARMONY-6461, but I couldn't resist cleaning up some of the surrounding code, and ended up cleaning up some of our native code too. In the course of the afternoon I spent on this, I lost my conviction that the upstream change makes sense, so I reverted that, leaving this change just pure cleanup. (Note that the cleanup work is incomplete. This is an improvement, but there's plenty left to do. I just don't want to get too distracted until all the Java 6 changes are done.) Change-Id: I56841db5f6c038bbf7942e83a148dca546519269
2010-02-10Add a general-purpose scoped pointer for libcore JNI.Elliott Hughes
This is a functional equivalent of C++0x's std::unique_ptr. (I'm not planning to use this in froyo, but I want it there in case I have to backport changes from dalvik-dev.)
2009-12-08Improve the FileNotFoundExceptions thrown by OSFileSystem.open.Elliott Hughes
When I improved the internals of java.io.File, I failed to keep OSFileSystem.open (which uses the internals of java.io.File) in sync, leading to misleading error reporting. java.io.File's internals now include a trailing NUL, which is useful for the native code but confuses Java if it tries to decode the byte[] as a UTF-8 sequence. This patch fixes the bug and also improves OSFileSystem.open's error reporting to include the reason for the failure. Bug: 2313271
2009-11-20Rewrite NetworkInterface's JNI for IPv6.Elliott Hughes
The old ioctl SIOCGIFCONF implementation of getNetworkInterfaces only returns IPv4 addresses. Now we've switched everything over to IPv6, that's not good enough. This change (a) implements glibc/BSD-like getifaddrs(3)/freeifaddrs(3) for Android, and (b) rewrites our getNetworkInterfaces to use that method. Of particular note is that we now do more of the work in Java. The JNI hands back a Java equivalent of getifaddrs(3)'s linked list of ifaddrs structs. The new package-private java.net.InterfaceAddress class serves as Java's "struct ifaddrs". The old implementation was also broken: SIOCGIFCONF doesn't actually return interface indexes from the kernel as the old code believed, so we were pulling the address family out of the IPv4 address it returned, leading us to assign the index 2 to all network interfaces. This caused all kinds of weird behavior later. I also had to fix GenericIPMreq so that its interface index field is actually set. The native code gets passed one of these objects when setNetworkInterface is called, so it's kind of important that the object identify which interface it's supposed to correspond to. I've also added missing copyright headers. This fixes all of the harmony tests on the simulator and on the device. It fixes several but not all of the jtreg MulticastSocket and IPv6 tests.
2009-11-13Don't allocate arbitrary-length buffers on the stack.Elliott Hughes
A new LocalArray C++ class lets us specify a "reasonable" amount of stack to use, but transparently fall back to using the heap if we need more space. The three places I've chosen to use LocalArray in this patch are fairly random; all they have in common is that they're the places where we call GetStringUTFRegion. There are more places LocalArray will be useful: the java.io.File JNI in particular. Bug: 2257819