devel/android-tools-fastboot: update to 29.0.3

Changes:        https://android.googlesource.com/platform/system/core/+log/android-9.0.0_r3..platform-tools-29.0.3/fastboot
This commit is contained in:
Jan Beich 2019-09-12 12:52:57 +00:00
parent b2fed1ef86
commit ae64748fc5
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=511879
18 changed files with 235 additions and 231 deletions

View file

@ -1,9 +1,9 @@
# $FreeBSD$
PORTNAME= android-tools-fastboot
DISTVERSIONPREFIX= android-
DISTVERSION?= 9.0.0_r3
PORTREVISION?= 3
DISTVERSIONPREFIX= platform-tools-
DISTVERSION?= 29.0.3
PORTREVISION?= 0
CATEGORIES= devel sysutils
MASTER_SITES= https://salsa.debian.org/android-tools-team/android-tools/raw/706e754/debian/:manpage
DISTFILES= fastboot.1:manpage
@ -16,29 +16,25 @@ LICENSE= APACHE20 BSD2CLAUSE
LICENSE_COMB= multi
USE_GITHUB= yes
GH_ACCOUNT= aosp-mirror jbeich:extras
GH_PROJECT= platform_system_core platform_system_extras:extras
GH_ACCOUNT= aosp-mirror jbeich:extras,mkbootimg
GH_PROJECT= platform_system_core platform_system_extras:extras \
platform_system_tools_mkbootimg:mkbootimg
CONFLICTS_INSTALL?= ${PORTNAME}-devel-*
USES= compiler:c++11-lib pkgconfig uidfix
USES= compiler:c++17-lang pkgconfig ssl uidfix
BUILD_WRKSRC= ${WRKSRC}/fastboot
INSTALL_WRKSRC= ${BUILD_WRKSRC}
CPPFLAGS+= -D_GLIBCXX_USE_C99 # XXX ports/193528
MAKEFILE?= ${.CURDIR}/files/Makefile
MAKE_ENV= BINDIR="${PREFIX}/bin" EXTRADIR="${FILESDIR}" \
FILESDIR="${DOCSDIR}" \
VERSION="${SDK_REVISION}-0 ${GH_REVISION}-android" \
VERSION="${DISTVERSION}${DISTVERSIONSUFFIX}" \
MANDIR="${PREFIX}/man/man"
PLIST_FILES= bin/fastboot \
man/man1/fastboot.1.gz
PORTDOCS= *
SUB_FILES= pkg-message
# Generated by "make update-revision" for "fastboot --version"
SDK_REVISION?= 28.0.0
GH_REVISION= ${DISTVERSIONSUFFIX:U0fac9018f238:S/-g//}
OPTIONS_DEFINE= BASH DOCS
OPTIONS_SUB= yes
@ -59,31 +55,11 @@ post-extract:
${BUILD_WRKSRC}
# Adjust paths relative to core
@(cd ${WRKSRC_extras} && ${COPYTREE_SHARE} . ${WRKSRC})
@(cd ${WRKSRC_mkbootimg} && ${COPYTREE_SHARE} . ${WRKSRC})
post-install-BASH-on:
${MKDIR} ${STAGEDIR}${PREFIX}/${BASH_PLIST_FILES:H}
${INSTALL_DATA} ${WRKSRC_bashcomp}/android \
${STAGEDIR}${PREFIX}/${BASH_PLIST_FILES}
update-revision:
@${REINPLACE_CMD} -i '' -e "/^SDK_REVISION?=/s/=.*/= $$(\
${FETCH_CMD} -qo- \
https://github.com/${GH_ACCOUNT}/platform_build/raw/${GH_TAGNAME}/core/version_defaults.mk | \
${SED} -n 's/^[[:space:]]*PLATFORM_SDK_VERSION := //p' \
).0.0/" \
${.CURDIR}/Makefile
# https://developer.github.com/v3/repos/commits/#get-a-single-commit
# Pretend to be curl(1) for pretty-printed JSON to help parse with sed(1)
@${REINPLACE_CMD} -i '' -e "/^GH_REVISION=/s/:U[^}:]*/:U$$(\
${SETENV} HTTP_USER_AGENT=curl ${FETCH_CMD} -qo- \
https://api.github.com/repos/${GH_ACCOUNT}/${GH_PROJECT}/commits/${GH_TAGNAME} | \
${SED} -n '/sha/ { s/.*\"\([0-9a-f]\{12\}\).*/\1/p; q; }' \
)/" \
${.CURDIR}/Makefile
.include <bsd.port.mk>
# XXX Work around !target(makesum)
.ifndef DISTVERSIONSUFFIX
makesum: update-revision
.endif

View file

@ -1,9 +1,11 @@
TIMESTAMP = 1529542722
TIMESTAMP = 1565662258
SHA256 (fastboot.1) = 2af01b064440952a82f1602691a0fecc030302722a71444946fb70d9c423d283
SIZE (fastboot.1) = 5906
SHA256 (aosp-mirror-platform_system_core-android-9.0.0_r3_GH0.tar.gz) = b9de23465b304432aa2b585aa66c6bf4841b177f2139b75ca5adc5d917e0ecd6
SIZE (aosp-mirror-platform_system_core-android-9.0.0_r3_GH0.tar.gz) = 27484684
SHA256 (jbeich-platform_system_extras-android-9.0.0_r3_GH0.tar.gz) = d82c4576bed24bfe701bb8c781714fa70365c03aed93cf4777407215de4d672d
SIZE (jbeich-platform_system_extras-android-9.0.0_r3_GH0.tar.gz) = 211722695
SHA256 (aosp-mirror-platform_system_core-platform-tools-29.0.3_GH0.tar.gz) = f2938ab5d206f5d4e075afba1a3e32fc26656bb439b6208200bef0ea5bae77eb
SIZE (aosp-mirror-platform_system_core-platform-tools-29.0.3_GH0.tar.gz) = 61252755
SHA256 (jbeich-platform_system_extras-platform-tools-29.0.3_GH0.tar.gz) = 342433c834f260b5d55c5dc0b98ef27aea18feb50e1fff5e09fdb846c0f75a51
SIZE (jbeich-platform_system_extras-platform-tools-29.0.3_GH0.tar.gz) = 210790583
SHA256 (jbeich-platform_system_tools_mkbootimg-platform-tools-29.0.3_GH0.tar.gz) = 9c2f9ab0006969613a48b5a529674c0d79784b830479c28f802aa2a1916cdf53
SIZE (jbeich-platform_system_tools_mkbootimg-platform-tools-29.0.3_GH0.tar.gz) = 6620
SHA256 (mbrubeck-android-completion-c1b0656_GH0.tar.gz) = ca3311ba47a5edd56c929ac9aae57c02c2c3f1636519c5f67abb00b6e3ecd75c
SIZE (mbrubeck-android-completion-c1b0656_GH0.tar.gz) = 5967

View file

@ -3,15 +3,14 @@
PROG_CXX=fastboot
BINDIR?=/usr/bin
FILESDIR?=${DOCDIR}/${PROG}
VERSION?=0.0.0-0
FILES= README.md
SRCS+= bootimg_utils.cpp
SRCS+= engine.cpp
SRCS+= fastboot.cpp
SRCS+= fastboot_driver.cpp
SRCS+= ../fastboot/fs.cpp
SRCS+= protocol.cpp
SRCS+= main.cpp
SRCS+= socket.cpp
SRCS+= tcp.cpp
SRCS+= udp.cpp
@ -20,18 +19,33 @@ SRCS+= util.cpp
.PATH: ${EXTRADIR}
SRCS+= usb_freebsd.cpp
# required by fastboot
.PATH: ${.CURDIR}/../adb
SRCS+= diagnose_usb.cpp
# required by fastboot, diagnose_usb and libziparchive
.PATH: ${.CURDIR}/../base
SRCS+= errors_unix.cpp
SRCS+= file.cpp
SRCS+= logging.cpp
SRCS+= mapped_file.cpp
SRCS+= parsenetaddress.cpp
SRCS+= stringprintf.cpp
SRCS+= strings.cpp
SRCS+= threads.cpp
# required by fastboot
.PATH: ${.CURDIR}/../diagnose_usb
SRCS+= diagnose_usb.cpp
# required by fs_mgr/liblp
.PATH: ${.CURDIR}/../ext4_utils
SRCS+= ext4_sb.cpp
SRCS+= ext4_utils.cpp
# required by fastboot
.PATH: ${.CURDIR}/../fs_mgr/liblp
SRCS+= images.cpp
SRCS+= partition_opener.cpp
SRCS+= reader.cpp
SRCS+= utility.cpp
SRCS+= writer.cpp
# required by fastboot
.PATH: ${.CURDIR}/../libcutils
@ -45,36 +59,30 @@ CPPFLAGS.sockets.cpp+= -o ${.TARGET}
# required by base and libutils
.PATH: ${.CURDIR}/../liblog
SRCS+= config_read.c
SRCS+= config_write.c
SRCS+= fake_log_device.c
SRCS+= fake_writer.c
SRCS+= local_logger.c
SRCS+= logger_lock.c
SRCS+= logger_name.c
SRCS+= logger_write.c
SRCS+= logprint.c
SRCS+= stderr_write.c
SRCS+= test_utils.cpp
SRCS+= config_read.cpp
SRCS+= config_write.cpp
SRCS+= fake_log_device.cpp
SRCS+= fake_writer.cpp
SRCS+= logger_lock.cpp
SRCS+= logger_name.cpp
SRCS+= logger_write.cpp
SRCS+= logprint.cpp
SRCS+= stderr_write.cpp
# required by fastboot
.PATH: ${.CURDIR}/../libsparse
SRCS+= backed_block.c
SRCS+= output_file.c
SRCS+= sparse.c
SRCS+= sparse_crc32.c
SRCS+= sparse_err.c
SRCS+= backed_block.cpp
SRCS+= output_file.cpp
SRCS+= sparse.cpp
SRCS+= sparse_crc32.cpp
SRCS+= sparse_err.cpp
SRCS+= sparse_read.cpp
# required by libziparchive
.PATH: ${.CURDIR}/../libutils
SRCS+= FileMap.cpp
# required by fastboot
.PATH: ${.CURDIR}/../libziparchive
SRCS+= zip_archive.cc
CPPFLAGS+= -DFASTBOOT_VERSION="\"${VERSION}\""
CPPFLAGS+= -DPLATFORM_TOOLS_VERSION="\"${VERSION:U0.0.0}\""
CPPFLAGS+= -Doff64_t=off_t
CPPFLAGS+= -Dftruncate64=ftruncate
CPPFLAGS+= -Dlseek64=lseek
@ -83,21 +91,25 @@ CPPFLAGS+= -Dpread64=pread
CPPFLAGS+= -DFAKE_LOG_DEVICE=1
CPPFLAGS+= -I${.CURDIR}
CPPFLAGS+= -I${.CURDIR}/../include
CPPFLAGS+= -I${.CURDIR}/../adb
CPPFLAGS+= -I${.CURDIR}/../mkbootimg/include/bootimg
CPPFLAGS+= -I${.CURDIR}/../include/bootimg
CPPFLAGS+= -I${.CURDIR}/../base/include
CPPFLAGS+= -I${.CURDIR}/../diagnose_usb/include
CPPFLAGS+= -I${.CURDIR}/../ext4_utils/include
CPPFLAGS+= -I${.CURDIR}/../fs_mgr/liblp/include
CPPFLAGS+= -I${.CURDIR}/../libsparse/include
CPPFLAGS+= -I${.CURDIR}/../libziparchive/include
CPPFLAGS+= ${CPPFLAGS.${.IMPSRC:T}}
CPPFLAGS+= $$(${PKG_CONFIG} libcrypto --cflags 2>/dev/null)
CPPFLAGS+= $$(${PKG_CONFIG} libusb-1.0 --cflags 2>/dev/null)
CXXFLAGS+= -D__STDC_LIMIT_MACROS # DragonFly
CXXFLAGS+= -std=gnu++11
CXXFLAGS+= -std=gnu++17
.ifndef COMPILE.c
CFLAGS+= ${CPPFLAGS}
CXXFLAGS+= ${CPPFLAGS}
.endif
LDADD+= $$(${PKG_CONFIG} libcrypto --libs 2>/dev/null || echo -lcrypto)
LDADD+= $$(${PKG_CONFIG} libusb-1.0 --libs 2>/dev/null || echo -lusb)
LDADD+= -lz \-lpthread
DPADD+= ${LIBPTHREAD} ${LIBUSB} ${LIBZ}

View file

@ -1,43 +0,0 @@
--- adb/sysdeps.h.orig 2015-09-05 00:01:27 UTC
+++ adb/sysdeps.h
@@ -61,11 +61,13 @@
#endif
#endif
-#ifdef _WIN32
-
+#if !defined(__clang__) || __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 7)
// Clang-only nullability specifiers
#define _Nonnull
#define _Nullable
+#endif
+
+#ifdef _WIN32
#include <ctype.h>
#include <direct.h>
@@ -401,6 +401,11 @@ typedef std::unique_ptr<HANDLE, handle_d
#include <string>
+#if defined(__Bitrig__) || defined(__DragonFly__) || \
+ defined(__FreeBSD__) || defined(__OpenBSD__)
+#include <pthread_np.h>
+#endif
+
#define OS_PATH_SEPARATORS "/"
#define OS_PATH_SEPARATOR '/'
#define OS_PATH_SEPARATOR_STR "/"
@@ -627,6 +632,12 @@ static __inline__ bool adb_thread_create
static __inline__ int adb_thread_setname(const std::string& name) {
#ifdef __APPLE__
return pthread_setname_np(name.c_str());
+#elif defined(__Bitrig__) || defined(__DragonFly__) || \
+ defined(__FreeBSD__) || defined(__OpenBSD__)
+ pthread_set_name_np(pthread_self(), name.c_str());
+ return 0;
+#elif defined(__NetBSD__)
+ return pthread_setname_np(pthread_self(), "%s", (void*)name.c_str());
#else
const char *s = name.c_str();

View file

@ -1,11 +0,0 @@
--- base/errors_unix.cpp.orig 2016-02-20 02:39:51 UTC
+++ base/errors_unix.cpp
@@ -16,7 +16,7 @@
#include "android-base/errors.h"
-#include <errno.h>
+#include <string.h>
namespace android {
namespace base {

View file

@ -1,17 +1,14 @@
--- base/file.cpp.orig 2017-06-20 10:50:27 UTC
--- base/file.cpp.orig 2019-07-17 19:54:09 UTC
+++ base/file.cpp
@@ -19,6 +19,10 @@
#include <errno.h>
@@ -20,6 +20,7 @@
#include <fcntl.h>
#include <ftw.h>
#include <libgen.h>
+#include <limits.h> // PATH_MAX
+#include <stdio.h> // BUFSIZ
+#include <stdlib.h> // realpath
+#include <string.h> // strerror
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -36,6 +39,9 @@
+#include <limits.h> // PATH_MAX for GCC
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -35,6 +36,9 @@
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#endif
@ -19,9 +16,9 @@
+#include <sys/sysctl.h>
+#endif
#if defined(_WIN32)
#include <direct.h>
#include <windows.h>
#define O_CLOEXEC O_NOINHERIT
@@ -251,6 +258,23 @@ std::string GetExecutablePath() {
@@ -421,6 +425,23 @@ std::string GetExecutablePath() {
if (result == 0 || result == sizeof(path) - 1) return "";
path[PATH_MAX - 1] = 0;
return path;

View file

@ -1,11 +1,22 @@
--- base/include/android-base/logging.h.orig 2015-09-29 18:07:07 UTC
--- base/include/android-base/logging.h.orig 2019-07-17 19:54:09 UTC
+++ base/include/android-base/logging.h
@@ -25,6 +25,8 @@
#endif
#endif
+#include <errno.h>
+
#include <functional>
#include <memory>
#include <ostream>
@@ -350,7 +350,7 @@ struct LogAbortAfterFullExpr {
// DCHECKs are debug variants of CHECKs only enabled in debug builds. Generally
// CHECK should be used unless profiling identifies a CHECK as being in
// performance critical code.
-#if defined(NDEBUG) && !defined(__clang_analyzer__)
+#if defined(NDEBUG) && !defined(__clang_analyzer__) || !defined(__ANDROID__)
static constexpr bool kEnableDChecks = false;
#else
static constexpr bool kEnableDChecks = true;
@@ -486,8 +486,9 @@ namespace std { // NOLINT(cert-dcl58-cpp)
#pragma clang diagnostic ignored "-Wgcc-compat"
#define OSTREAM_STRING_POINTER_USAGE_WARNING \
__attribute__((diagnose_if(true, "Unexpected logging of string pointer", "warning")))
+OSTREAM_STRING_POINTER_USAGE_WARNING // GCC
inline std::ostream& operator<<(std::ostream& stream, const std::string* string_pointer)
- OSTREAM_STRING_POINTER_USAGE_WARNING {
+{
return stream << static_cast<const void*>(string_pointer);
}
#pragma clang diagnostic pop

View file

@ -1,10 +0,0 @@
--- base/parsenetaddress.cpp.orig 2016-02-20 02:39:51 UTC
+++ base/parsenetaddress.cpp
@@ -16,6 +16,7 @@
#include "android-base/parsenetaddress.h"
+#include <stdio.h> // sscanf
#include <algorithm>
#include "android-base/stringprintf.h"

View file

@ -1,25 +1,7 @@
--- base/logging.cpp.orig 2016-08-08 21:10:17 UTC
+++ base/logging.cpp
@@ -25,7 +25,7 @@
#include <time.h>
// For getprogname(3) or program_invocation_short_name.
-#if defined(__ANDROID__) || defined(__APPLE__)
+#if !defined(_WIN32) && !defined(__GLIBC__)
#include <stdlib.h>
#elif defined(__GLIBC__)
#include <errno.h>
@@ -35,6 +35,8 @@
#include <sys/uio.h>
#endif
+#include <cstring> // strrchr
+#include <cstdio> // fprintf
#include <iostream>
#include <limits>
#include <sstream>
@@ -71,6 +72,16 @@
#include <unistd.h>
--- base/threads.cpp.orig 2019-07-17 19:54:09 UTC
+++ base/threads.cpp
@@ -25,6 +25,16 @@
#include <syscall.h>
#elif defined(_WIN32)
#include <windows.h>
+#elif defined(__DragonFly__) || defined(__FreeBSD__)
@ -34,8 +16,8 @@
+#include <stdint.h>
#endif
#if defined(_WIN32)
@@ -88,6 +97,16 @@ static thread_id GetThreadId() {
namespace android {
@@ -41,6 +51,16 @@ uint64_t GetThreadId() {
return syscall(__NR_gettid);
#elif defined(_WIN32)
return GetCurrentThreadId();

View file

@ -0,0 +1,47 @@
--- ext4_utils/ext4_utils.cpp.orig 2019-08-13 02:10:50 UTC
+++ ext4_utils/ext4_utils.cpp
@@ -32,8 +32,16 @@
#if defined(__linux__)
#include <linux/fs.h>
-#elif defined(__APPLE__) && defined(__MACH__)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
+ || (defined(__APPLE__) && defined(__MACH__))
#include <sys/disk.h>
+#elif defined(__sun)
+#include <sys/dkio.h>
+#elif defined(__Bitrig__) || defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/disklabel.h>
+#include <sys/dkio.h>
+#elif defined(__DragonFly__)
+#include <sys/diskslice.h>
#endif
int force = 0;
@@ -206,10 +214,24 @@ u64 get_block_device_size(int fd)
u64 size = 0;
int ret;
-#if defined(__linux__)
+#if defined(BLKGETSIZE64)
ret = ioctl(fd, BLKGETSIZE64, &size);
-#elif defined(__APPLE__) && defined(__MACH__)
+#elif defined(DKIOCGETBLOCKCOUNT)
ret = ioctl(fd, DKIOCGETBLOCKCOUNT, &size);
+#elif defined(DIOCGMEDIASIZE)
+ ret = ioctl(fd, DIOCGMEDIASIZE, &size);
+#elif defined(DKIOCGMEDIAINFO)
+ struct dk_minfo minfo;
+ ret = ioctl(fd, DKIOCGMEDIAINFO, &minfo);
+ size = minfo.dki_lbsize * minfo.dki_capacity;
+#elif defined(DIOCGDINFO)
+ struct disklabel dl;
+ ret = ioctl(fd, DIOCGDINFO, &dl);
+ size = dl.d_secsize * dl.d_nsectors * dl.d_ntracks * dl.d_ncylinders;
+#elif defined(DIOCGPART)
+ struct partinfo pi;
+ ret = ioctl(fd, DIOCGPART, &pi);
+ size = pi.media_size;
#else
close(fd);
return 0;

View file

@ -0,0 +1,24 @@
--- fastboot/fastboot.cpp.orig 2019-08-13 02:10:58 UTC
+++ fastboot/fastboot.cpp
@@ -58,9 +58,20 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
+#ifdef PLATFORM_TOOLS_VERSION
+#include <sys/utsname.h>
+namespace android { namespace build {
+std::string GetBuildNumber() {
+ struct utsname uts;
+ if (uname(&uts) == -1)
+ return "unknown";
+ return uts.sysname;
+}}}
+#else
#include <build/version.h>
-#include <liblp/liblp.h>
#include <platform_tools_version.h>
+#endif
+#include <liblp/liblp.h>
#include <sparse/sparse.h>
#include <ziparchive/zip_archive.h>

View file

@ -0,0 +1,12 @@
--- liblog/fake_writer.cpp.orig 2019-07-17 19:54:09 UTC
+++ liblog/fake_writer.cpp
@@ -33,8 +33,8 @@ static int logFds[(int)LOG_ID_MAX] = {-1, -1, -1, -1,
struct android_log_transport_write fakeLoggerWrite = {
.node = {&fakeLoggerWrite.node, &fakeLoggerWrite.node},
- .context.priv = &logFds,
.name = "fake",
+ .context = { .priv = &logFds }, // GCC
.available = NULL,
.open = fakeOpen,
.close = fakeClose,

View file

@ -0,0 +1,16 @@
--- liblog/logger.h.orig 2019-08-13 02:10:58 UTC
+++ liblog/logger.h
@@ -16,7 +16,13 @@
#pragma once
+#ifdef __cplusplus
+#include <atomic>
+using std::atomic_int;
+using std::atomic_uintptr_t;
+#else
#include <stdatomic.h>
+#endif
#include <cutils/list.h>
#include <log/log.h>

View file

@ -1,5 +1,5 @@
--- liblog/logger_write.c.orig 2016-04-16 00:01:39 UTC
+++ liblog/logger_write.c
--- liblog/logger_write.cpp.orig 2019-07-17 19:54:09 UTC
+++ liblog/logger_write.cpp
@@ -15,12 +15,12 @@
*/
@ -9,7 +9,8 @@
#include <string.h>
#include <sys/time.h>
#ifdef __BIONIC__
-#ifdef __BIONIC__
+#if defined(__ANDROID__)
+#include <stdatomic.h>
#include <android/set_abort_message.h>
#endif

View file

@ -0,0 +1,12 @@
--- liblog/stderr_write.cpp.orig 2019-08-13 02:10:58 UTC
+++ liblog/stderr_write.cpp
@@ -55,8 +55,8 @@ struct stderrContext {
struct android_log_transport_write stderrLoggerWrite = {
.node = {&stderrLoggerWrite.node, &stderrLoggerWrite.node},
- .context.priv = NULL,
.name = "stderr",
+ .context = { .priv = NULL }, // GCC
.available = stderrAvailable,
.open = stderrOpen,
.close = stderrClose,

View file

@ -1,10 +0,0 @@
--- libsparse/sparse_read.cpp.orig 2017-06-20 10:50:27 UTC
+++ libsparse/sparse_read.cpp
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string>
+#include <string.h> // memset
#include <unistd.h>
#include <sparse/sparse.h>

View file

@ -1,29 +0,0 @@
--- libziparchive/zip_archive.cc.orig 2018-06-21 00:58:42 UTC
+++ libziparchive/zip_archive.cc
@@ -47,6 +47,17 @@
#include "zip_archive_common.h"
#include "zip_archive_private.h"
+#if !defined(_WIN32)
+#if __cplusplus >= 201703 || (defined(_LIBCPP_VERSION) && __has_include(<string_view>))
+#include <string_view>
+#elif __cplusplus >= 201402
+#include <experimental/string_view>
+namespace std {
+using std::experimental::string_view;
+}
+#endif // __cplusplus >= 201703
+#endif // !defined(_WIN32)
+
using android::base::get_unaligned;
// Used to turn on crc checks - verify that the content CRC matches the values
@@ -100,7 +111,7 @@ static uint32_t RoundUpPower2(uint32_t val) {
}
static uint32_t ComputeHash(const ZipString& name) {
-#if !defined(_WIN32)
+#if __cplusplus >= 201402 && !defined(_WIN32)
return std::hash<std::string_view>{}(
std::string_view(reinterpret_cast<const char*>(name.name), name.name_length));
#else

View file

@ -42,18 +42,20 @@ struct usb_handle {
unsigned char iface;
};
class LibusbUsbTransport : public Transport {
class LibusbUsbTransport : public UsbTransport {
public:
explicit LibusbUsbTransport(std::unique_ptr<usb_handle> handle):
h(std::move(handle)) {}
~LibusbUsbTransport() override = default;
explicit LibusbUsbTransport(std::unique_ptr<usb_handle> handle, uint32_t ms_timeout):
h(std::move(handle)), ms_timeout_(ms_timeout) {}
~LibusbUsbTransport() override;
ssize_t Read(void *_data, size_t len) override;
ssize_t Write(const void *_data, size_t len) override;
int Close() override;
int Reset() override;
private:
std::unique_ptr<usb_handle> h;
const uint32_t ms_timeout_;
DISALLOW_COPY_AND_ASSIGN(LibusbUsbTransport);
};
@ -174,7 +176,7 @@ LibusbUsbTransport::Write(const void *_data, size_t len)
int actlen;
if (libusb_bulk_transfer(h->handle, h->ep_out,
(unsigned char *)_data, len, &actlen, 0) < 0)
(unsigned char *)_data, len, &actlen, ms_timeout_) < 0)
return (-1);
return (actlen);
}
@ -185,11 +187,16 @@ LibusbUsbTransport::Read(void *_data, size_t len)
int actlen;
if (libusb_bulk_transfer(h->handle, h->ep_in,
(unsigned char *)_data, len, &actlen, 0) < 0)
(unsigned char *)_data, len, &actlen, ms_timeout_) < 0)
return (-1);
return (actlen);
}
LibusbUsbTransport::~LibusbUsbTransport()
{
Close();
}
int
LibusbUsbTransport::Close()
{
@ -200,9 +207,17 @@ LibusbUsbTransport::Close()
return (0);
}
Transport *
usb_open(ifc_match_func callback)
int
LibusbUsbTransport::Reset()
{
if (libusb_reset_device(h->handle))
return (-1);
return (0);
}
UsbTransport *
usb_open(ifc_match_func callback, uint32_t timeout_ms)
{
std::unique_ptr<usb_handle> h = enumerate(callback);
return (h ? new LibusbUsbTransport(std::move(h)) : nullptr);
return (h ? new LibusbUsbTransport(std::move(h), timeout_ms) : nullptr);
}