Commit 05e7967b authored by jbeich's avatar jbeich
Browse files

devel/android-tools-adb-devel: add new slave port for git master

A temporary port to facilitate testing and updating master.

While copying usb_libusb.c [1] under FILESDIR clean it up:
- Add static keyword for file-local functions
- Fix const usage exposed in C++ mode [2]
- Fix casting 3rd argument of libusb_bulk_transfer(3) exposed in C++ mode
- Fix inconsistent whitespace: trailing, tabs + spaces, bogus indentation
- Fix typo in usb_kick() trace message
- Fix fprintf(3) warning in scan_usb_devices() trace message
- Convert err(3) usage to fatal_errno()
- Drop BSDism of sysexits(3)
- Drop unecessary struct keyword
- Drop unused headers [2]
- Explicitly include <signal.h> header

And chase the following commits:
https://android.googlesource.com/platform/system/core/+/506aea4%5E!/ [1]
https://android.googlesource.com/platform/system/core/+/dc3b459%5E!/#F3
https://android.googlesource.com/platform/system/core/+/9b0f354%5E!/#F5
https://android.googlesource.com/platform/system/core/+/cf07494%5E!/#F8
https://android.googlesource.com/platform/system/core/+/3313426%5E!/#F20
https://android.googlesource.com/platform/system/core/+/7664901%5E!/#F18

Changes:	https://android.googlesource.com/platform/system/core/+log/53d504f/adb
Differential Revision:	https://reviews.freebsd.org/D2870
Obtained from:	devel/android-tools-fastboot-devel (based on)
Obtained from:	OpenBSD ports [2]
Approved by:	kevlo (maintainer)
parent eecea3be
......@@ -57,6 +57,7 @@
SUBDIR += amd64-gcc
SUBDIR += amd64-xtoolchain-gcc
SUBDIR += android-tools-adb
SUBDIR += android-tools-adb-devel
SUBDIR += android-tools-fastboot
SUBDIR += android-tools-fastboot-devel
SUBDIR += anjuta
......
# $FreeBSD$
DISTVERSION= m-preview-122
DISTVERSIONSUFFIX= -g53d504f
PORTREVISION= 0
PKGNAMESUFFIX= -devel
CONFLICTS_INSTALL= ${PORTNAME}-[0-9]*
MASTERDIR= ${.CURDIR}/../android-tools-adb
DISTINFO_FILE= ${.CURDIR}/distinfo
MAKEFILE= ${.CURDIR}/files/Makefile
FILESDIR= ${.CURDIR}/files
PATCHDIR= ${.CURDIR}/files
USES= compiler:c++11-lib
BUILD_WRKSRC= ${WRKSRC}/adb
INSTALL_WRKSRC= ${BUILD_WRKSRC}
MAKE_ENV= FILESDIR="${FILESDIR}"
CFLAGS+= -DADB_REVISION='\"${DISTVERSIONFULL}\"'
.include "${MASTERDIR}/Makefile"
SHA256 (android-platform_system_core-android-m-preview-122-g53d504f_GH0.tar.gz) = 8d49065aff063fb02cc175c634384eb1dc9ed87b85d16e85f0c70bff01415948
SIZE (android-platform_system_core-android-m-preview-122-g53d504f_GH0.tar.gz) = 1182976
SHA256 (bash_completion.d/adb?id=2b8cfec) = 0d7989596a3e4937834d582eb0ddc88b8186505570772304fe51870d473916a7
SIZE (bash_completion.d/adb?id=2b8cfec) = 5198
# $FreeBSD$
PROG_CXX=adb
NO_MAN=
BINDIR?=/usr/bin
SRCS+= adb.cpp
SRCS+= adb_auth.cpp
SRCS+= adb_auth_host.cpp
SRCS+= adb_client.cpp
SRCS+= adb_io.cpp
SRCS+= adb_listeners.cpp
SRCS+= adb_utils.cpp
SRCS+= commandline.cpp
SRCS+= console.cpp
SRCS+= fdevent.cpp
SRCS+= file_sync_client.cpp
SRCS+= services.cpp
SRCS+= sockets.cpp
SRCS+= transport.cpp
SRCS+= transport_local.cpp
SRCS+= transport_usb.cpp
.PATH: ${.CURDIR}/client
SRCS+= main.cpp
.PATH: ${FILESDIR}
SRCS+= get_my_path_freebsd.cpp
SRCS+= usb_libusb.cpp
.PATH: ${.CURDIR}/../base
SRCS+= file.cpp
SRCS+= logging.cpp
SRCS+= strings.cpp
SRCS+= stringprintf.cpp
.PATH: ${.CURDIR}/../libcutils
SRCS+= socket_inaddr_any_server.c
SRCS+= socket_local_client.c
SRCS+= socket_local_server.c
SRCS+= socket_loopback_client.c
SRCS+= socket_loopback_server.c
SRCS+= socket_network_client.c
SRCS+= load_file.c
SRCS+= threads.c
# required by base/file.cpp
.PATH: ${.CURDIR}/../liblog
SRCS+= fake_log_device.c
SRCS+= logd_write.c
CFLAGS+= -DADB_HOST=1
CFLAGS+= -DHAVE_FORKEXEC=1
CFLAGS+= -DHAVE_SYMLINKS
CFLAGS+= -DHAVE_TERMIO_H
CFLAGS+= -DHAVE_SYS_SOCKET_H
CFLAGS+= -D_FILE_OFFSET_BITS=64
CFLAGS+= -DFAKE_LOG_DEVICE=1
CFLAGS+= -I${.CURDIR}
CFLAGS+= -I${.CURDIR}/../include
CFLAGS+= -I${.CURDIR}/../base/include
CXXFLAGS+= -std=gnu++11
CXXFLAGS+= ${CFLAGS:N-std*}
LDADD+= -lcrypto -lpthread -lusb -lz
DPADD+= ${LIBCRYPTO} ${LIBPTHREAD} ${LIBUSB} ${LIBZ}
.include <bsd.prog.mk>
/*
* Copyright (C) 2009 bsdroid project
* Alexey Tarasov <tarasov@dodologics.com>
*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <sys/types.h>
#include <sys/sysctl.h>
#include <unistd.h>
void
get_my_path(char *exe, size_t maxLen)
{
int mib[4] = {
CTL_KERN,
KERN_PROC,
KERN_PROC_PATHNAME,
getpid()
};
sysctl(mib, 4, exe, &maxLen, NULL, 0);
}
--- adb/commandline.cpp.orig 2015-06-17 22:20:38 UTC
+++ adb/commandline.cpp
@@ -637,7 +637,7 @@ static int ppp(int argc, const char** ar
// copy args
ppp_args = (const char **) alloca(sizeof(char *) * argc + 1);
- ppp_args[0] = "pppd";
+ ppp_args[0] = "ppp";
for (i = 2 ; i < argc ; i++) {
//argv[2] and beyond become ppp_args[1] and beyond
ppp_args[i - 1] = argv[i];
@@ -651,10 +651,10 @@ static int ppp(int argc, const char** ar
adb_close(STDERR_FILENO);
adb_close(fd);
- err = execvp("pppd", (char * const *)ppp_args);
+ err = execvp("ppp", (char * const *)ppp_args);
if (err < 0) {
- perror("execing pppd");
+ perror("execing ppp");
}
exit(-1);
} else {
--- base/file.cpp.orig 2015-05-27 20:24:08 UTC
+++ base/file.cpp
@@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <sys/types.h>
+#include <cstring> // strerror
#include <string>
#include "base/macros.h" // For TEMP_FAILURE_RETRY on Darwin.
--- base/logging.cpp.orig 2015-06-17 22:20:38 UTC
+++ base/logging.cpp
@@ -23,12 +23,14 @@
#include <libgen.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>
#endif
+#include <cstring> // strlen
+#include <cstdio> // fprintf
#include <iostream>
#include <limits>
#include <sstream>
--- libcutils/threads.c.orig 2015-06-17 22:20:38 UTC
+++ libcutils/threads.c
@@ -29,6 +29,14 @@
#include <unistd.h>
#elif defined(_WIN32)
#include <windows.h>
+#elif defined(__DragonFly__)
+#include <unistd.h>
+#elif defined(__FreeBSD__)
+#include <sys/param.h>
+#include <sys/thr.h>
+#include <pthread_np.h>
+#elif defined(__NetBSD__)
+#include <lwp.h>
#endif
// No definition needed for Android because we'll just pick up bionic's copy.
@@ -40,6 +48,20 @@ pid_t gettid() {
return syscall(__NR_gettid);
#elif defined(_WIN32)
return GetCurrentThreadId();
+#elif defined(__DragonFly__)
+ return lwp_gettid();
+#elif defined(__NetBSD__)
+ return _lwp_self();
+#elif defined(__FreeBSD__)
+# if __FreeBSD_version > 900030
+ return pthread_getthreadid_np();
+# else
+ long lwpid;
+ thr_self(&lwpid);
+ return lwpid;
+# endif
+#else
+ return (intptr_t) pthread_self();
#endif
}
#endif // __ANDROID__
--- liblog/logd_write.c.orig 2015-05-27 20:24:08 UTC
+++ liblog/logd_write.c
@@ -22,7 +22,9 @@
#include <pthread.h>
#endif
#include <stdarg.h>
+#if (FAKE_LOG_DEVICE == 0)
#include <stdatomic.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* Copyright (C) 2009 bsdroid project
* Alexey Tarasov <tarasov@dodologics.com>
*
* Copyright (C) 2007 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.
*/
#define TRACE_TAG TRACE_USB
#include "sysdeps.h"
#include <libusb.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "adb.h"
#include "transport.h"
ADB_MUTEX_DEFINE( usb_lock );
static libusb_context *ctx = NULL;
struct usb_handle
{
usb_handle *prev;
usb_handle *next;
libusb_device *dev;
libusb_device_handle *devh;
int interface;
uint8_t dev_bus;
uint8_t dev_addr;
int zero_mask;
unsigned char end_point_address[2];
char serial[128];
adb_cond_t notify;
adb_mutex_t lock;
};
static usb_handle handle_list = {
.prev = &handle_list,
.next = &handle_list,
};
static void
usb_cleanup()
{
libusb_exit(ctx);
}
static void
report_bulk_libusb_error(int r)
{
switch (r) {
case LIBUSB_ERROR_TIMEOUT:
D("Transfer timeout\n");
break;
case LIBUSB_ERROR_PIPE:
D("Control request is not supported\n");
break;
case LIBUSB_ERROR_OVERFLOW:
D("Device offered more data\n");
break;
case LIBUSB_ERROR_NO_DEVICE :
D("Device was disconnected\n");
break;
default:
D("Error %d during transfer\n", r);
break;
};
}
static int
usb_bulk_write(usb_handle *uh, const void *data, int len)
{
int r = 0;
int transferred = 0;
r = libusb_bulk_transfer(uh->devh, uh->end_point_address[1],
(unsigned char *)data, len, &transferred, 0);
if (r != 0) {
D("usb_bulk_write(): ");
report_bulk_libusb_error(r);
return r;
}
return (transferred);
}
static int
usb_bulk_read(usb_handle *uh, void *data, int len)
{
int r = 0;
int transferred = 0;
r = libusb_bulk_transfer(uh->devh, uh->end_point_address[0],
(unsigned char *)data, len,
&transferred, 0);
if (r != 0) {
D("usb_bulk_read(): ");
report_bulk_libusb_error(r);
return r;
}
return (transferred);
}
int
usb_write(usb_handle *uh, const void *_data, int len)
{
unsigned char *data = (unsigned char*) _data;
int n;
int need_zero = 0;
if (uh->zero_mask == 1) {
if (!(len & uh->zero_mask)) {
need_zero = 1;
}
}
D("usb_write(): %p:%d -> transport %p\n", _data, len, uh);
while (len > 0) {
int xfer = (len > 4096) ? 4096 : len;
n = usb_bulk_write(uh, data, xfer);
if (n != xfer) {
D("usb_write(): failed for transport %p (%d bytes left)\n", uh, len);
return -1;
}
len -= xfer;
data += xfer;
}
if (need_zero){
n = usb_bulk_write(uh, _data, 0);
if (n < 0) {
D("usb_write(): failed to finish operation for transport %p\n", uh);
}
return n;
}
return 0;
}
int
usb_read(usb_handle *uh, void *_data, int len)
{
unsigned char *data = (unsigned char*)_data;
int n;
D("usb_read(): %p:%d <- transport %p\n", _data, len, uh);
while (len > 0) {
int xfer = (len > 4096) ? 4096 : len;
n = usb_bulk_read(uh, data, xfer);
if (n != xfer) {
if (n > 0) {
data += n;
len -= n;
continue;
}
D("usb_read(): failed for transport %p (%d bytes left)\n", uh, len);
return -1;
}
len -= xfer;
data += xfer;
}
return 0;
}
int
usb_close(usb_handle *h)
{
D("usb_close(): closing transport %p\n", h);
adb_mutex_lock(&usb_lock);
h->next->prev = h->prev;
h->prev->next = h->next;
h->prev = NULL;
h->next = NULL;
libusb_release_interface(h->devh, h->interface);
libusb_close(h->devh);
libusb_unref_device(h->dev);
adb_mutex_unlock(&usb_lock);
free(h);
return (0);
}
void
usb_kick(usb_handle *h)
{
D("usb_kick(): kicking transport %p\n", h);
adb_mutex_lock(&h->lock);
unregister_usb_transport(h);
adb_mutex_unlock(&h->lock);
h->next->prev = h->prev;
h->prev->next = h->next;
h->prev = NULL;
h->next = NULL;
libusb_release_interface(h->devh, h->interface);
libusb_close(h->devh);
libusb_unref_device(h->dev);
free(h);
}
static int
check_usb_interface(libusb_interface const *interface,
libusb_device_descriptor const *desc,
usb_handle *uh)
{
int e;
if (interface->num_altsetting == 0) {
D("check_usb_interface(): No interface settings\n");
return -1;
}
libusb_interface_descriptor const *idesc = &interface->altsetting[0];
if (idesc->bNumEndpoints != 2) {
D("check_usb_interface(): Interface have not 2 endpoints, ignoring\n");
return -1;
}
for (e = 0; e < idesc->bNumEndpoints; e++) {
libusb_endpoint_descriptor const *edesc = &idesc->endpoint[e];
if (edesc->bmAttributes != LIBUSB_TRANSFER_TYPE_BULK) {
D("check_usb_interface(): Endpoint (%u) is not bulk (%u), ignoring\n",
edesc->bmAttributes, LIBUSB_TRANSFER_TYPE_BULK);
return -1;
}
if (edesc->bEndpointAddress & LIBUSB_ENDPOINT_IN)
uh->end_point_address[0] = edesc->bEndpointAddress;
else
uh->end_point_address[1] = edesc->bEndpointAddress;
/* aproto 01 needs 0 termination */
if (idesc->bInterfaceProtocol == 0x01) {
uh->zero_mask = edesc->wMaxPacketSize - 1;
D("check_usb_interface(): Forced Android interface protocol v.1\n");
}
}
D("check_usb_interface(): Device: %04x:%04x "
"iclass: %x, isclass: %x, iproto: %x ep: %x/%x-> ",
desc->idVendor, desc->idProduct, idesc->bInterfaceClass,
idesc->bInterfaceSubClass, idesc->bInterfaceProtocol,
uh->end_point_address[0], uh->end_point_address[1]);
if (!is_adb_interface(desc->idVendor, desc->idProduct,
idesc->bInterfaceClass, idesc->bInterfaceSubClass,
idesc->bInterfaceProtocol))
{
D("not matches\n");
return -1;
}
D("matches\n");
return 1;
}
static int
check_usb_interfaces(libusb_config_descriptor *config,
libusb_device_descriptor *desc,
usb_handle *uh)
{
int i;
for (i = 0; i < config->bNumInterfaces; ++i) {
if (check_usb_interface(&config->interface[i], desc, uh) != -1) {
/* found some interface and saved information about it */
D("check_usb_interfaces(): Interface %d of %04x:%04x "
"matches Android device\n", i, desc->idVendor,
desc->idProduct);
return i;
}
}
return -1;
}
static int
register_device(usb_handle *uh, const char *serial)
{
D("register_device(): Registering %p [%s] as USB transport\n",
uh, serial);
usb_handle* usb = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle)));
if (usb == nullptr) fatal("couldn't allocate usb_handle");
memcpy(usb, uh, sizeof(usb_handle));
strcpy(usb->serial, uh->serial);
adb_cond_init(&usb->notify, 0);
adb_mutex_init(&usb->lock, 0);
adb_mutex_lock(&usb_lock);
usb->next = &handle_list;
usb->prev = handle_list.prev;