diff options
author | Ethan Yonker <dees_troy@teamw.in> | 2015-10-09 18:15:26 +0200 |
---|---|---|
committer | Ethan Yonker <dees_troy@teamw.in> | 2015-10-09 18:15:29 +0200 |
commit | c798c9cd2486e0ff83776002c74f113677b10a84 (patch) | |
tree | d128a80cbc58e63a622fda2774e727611f9d2cd4 /minadbd | |
parent | Add TW_IGNORE_ABS_MT_TRACKING_ID (diff) | |
parent | merge in mnc-release history after reset to mnc-dev (diff) | |
download | android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar.gz android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar.bz2 android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar.lz android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar.xz android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar.zst android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.zip |
Diffstat (limited to '')
-rw-r--r-- | minadbd.old/Android.mk | 30 | ||||
-rw-r--r-- | minadbd.old/README.txt | 39 | ||||
-rw-r--r-- | minadbd.old/adb.c (renamed from minadbd/adb.c) | 0 | ||||
-rw-r--r-- | minadbd.old/adb.h (renamed from minadbd/adb.h) | 0 | ||||
-rw-r--r-- | minadbd.old/fdevent.c (renamed from minadbd/fdevent.c) | 0 | ||||
-rw-r--r-- | minadbd.old/fdevent.h (renamed from minadbd/fdevent.h) | 0 | ||||
-rw-r--r-- | minadbd.old/fuse_adb_provider.c (renamed from minadbd/fuse_adb_provider.c) | 0 | ||||
-rw-r--r-- | minadbd.old/fuse_adb_provider.h | 22 | ||||
-rw-r--r-- | minadbd.old/mutex_list.h (renamed from minadbd/mutex_list.h) | 0 | ||||
-rw-r--r-- | minadbd.old/services.c (renamed from minadbd/services.c) | 0 | ||||
-rw-r--r-- | minadbd.old/sockets.c (renamed from minadbd/sockets.c) | 0 | ||||
-rw-r--r-- | minadbd.old/sysdeps.h (renamed from minadbd/sysdeps.h) | 0 | ||||
-rw-r--r-- | minadbd.old/transport.c (renamed from minadbd/transport.c) | 0 | ||||
-rw-r--r-- | minadbd.old/transport.h (renamed from minadbd/transport.h) | 0 | ||||
-rw-r--r-- | minadbd.old/transport_usb.c (renamed from minadbd/transport_usb.c) | 0 | ||||
-rw-r--r-- | minadbd.old/usb_linux_client.c (renamed from minadbd/usb_linux_client.c) | 0 | ||||
-rw-r--r-- | minadbd.old/utils.c (renamed from minadbd/utils.c) | 0 | ||||
-rw-r--r-- | minadbd.old/utils.h (renamed from minadbd/utils.h) | 0 | ||||
-rw-r--r-- | minadbd/Android.mk | 48 | ||||
-rw-r--r-- | minadbd/README.txt | 37 | ||||
-rw-r--r-- | minadbd/adb_main.cpp | 49 | ||||
-rw-r--r-- | minadbd/fuse_adb_provider.cpp | 61 | ||||
-rw-r--r-- | minadbd/fuse_adb_provider.h | 10 | ||||
-rw-r--r-- | minadbd/fuse_adb_provider_test.cpp | 88 | ||||
-rw-r--r-- | minadbd/services.cpp | 106 |
25 files changed, 436 insertions, 54 deletions
diff --git a/minadbd.old/Android.mk b/minadbd.old/Android.mk new file mode 100644 index 000000000..19c8b6047 --- /dev/null +++ b/minadbd.old/Android.mk @@ -0,0 +1,30 @@ +# Copyright 2005 The Android Open Source Project +# +# Android.mk for adb +# + +LOCAL_PATH:= $(call my-dir) + +# minadbd library +# ========================================================= + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + adb.c \ + fdevent.c \ + fuse_adb_provider.c \ + transport.c \ + transport_usb.c \ + sockets.c \ + services.c \ + usb_linux_client.c \ + utils.c + +LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter +LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE +LOCAL_MODULE_TAGS := eng +LOCAL_MODULE := libminadbd +LOCAL_C_INCLUDES += $(LOCAL_PATH)/../ +LOCAL_SHARED_LIBRARIES := libfusesideload libcutils libc +include $(BUILD_SHARED_LIBRARY) diff --git a/minadbd.old/README.txt b/minadbd.old/README.txt new file mode 100644 index 000000000..c9df484c3 --- /dev/null +++ b/minadbd.old/README.txt @@ -0,0 +1,39 @@ +The contents of this directory are copied from system/core/adb, with +the following changes: + +adb.c + - much support for host mode and non-linux OS's stripped out; this + version only runs as adbd on the device. + - always setuid/setgid's itself to the shell user + - only uses USB transport + - references to JDWP removed + - main() removed + - all ADB_HOST and win32 code removed + - removed listeners, logging code, background server (for host) + +adb.h + - minor changes to match adb.c changes + +sockets.c + - references to JDWP removed + - ADB_HOST code removed + +services.c + - all services except echo_service (which is commented out) removed + - all host mode support removed + - sideload_service() added; this is the only service supported. It + receives a single blob of data, writes it to a fixed filename, and + makes the process exit. + +Android.mk + - only builds in adbd mode; builds as static library instead of a + standalone executable. + +sysdeps.h + - changes adb_creat() to use O_NOFOLLOW + +transport.c + - removed ADB_HOST code + +transport_usb.c + - removed ADB_HOST code diff --git a/minadbd/adb.c b/minadbd.old/adb.c index c35e8300b..c35e8300b 100644 --- a/minadbd/adb.c +++ b/minadbd.old/adb.c diff --git a/minadbd/adb.h b/minadbd.old/adb.h index 08ee989d6..08ee989d6 100644 --- a/minadbd/adb.h +++ b/minadbd.old/adb.h diff --git a/minadbd/fdevent.c b/minadbd.old/fdevent.c index 5c374a71b..5c374a71b 100644 --- a/minadbd/fdevent.c +++ b/minadbd.old/fdevent.c diff --git a/minadbd/fdevent.h b/minadbd.old/fdevent.h index a0ebe2a7e..a0ebe2a7e 100644 --- a/minadbd/fdevent.h +++ b/minadbd.old/fdevent.h diff --git a/minadbd/fuse_adb_provider.c b/minadbd.old/fuse_adb_provider.c index f80533a8c..f80533a8c 100644 --- a/minadbd/fuse_adb_provider.c +++ b/minadbd.old/fuse_adb_provider.c diff --git a/minadbd.old/fuse_adb_provider.h b/minadbd.old/fuse_adb_provider.h new file mode 100644 index 000000000..0eb1f79d1 --- /dev/null +++ b/minadbd.old/fuse_adb_provider.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2014 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. + */ + +#ifndef __FUSE_ADB_PROVIDER_H +#define __FUSE_ADB_PROVIDER_H + +int run_adb_fuse(int sfd, uint64_t file_size, uint32_t block_size); + +#endif diff --git a/minadbd/mutex_list.h b/minadbd.old/mutex_list.h index 652dd7341..652dd7341 100644 --- a/minadbd/mutex_list.h +++ b/minadbd.old/mutex_list.h diff --git a/minadbd/services.c b/minadbd.old/services.c index 218b84a38..218b84a38 100644 --- a/minadbd/services.c +++ b/minadbd.old/services.c diff --git a/minadbd/sockets.c b/minadbd.old/sockets.c index 817410d13..817410d13 100644 --- a/minadbd/sockets.c +++ b/minadbd.old/sockets.c diff --git a/minadbd/sysdeps.h b/minadbd.old/sysdeps.h index 800ddb753..800ddb753 100644 --- a/minadbd/sysdeps.h +++ b/minadbd.old/sysdeps.h diff --git a/minadbd/transport.c b/minadbd.old/transport.c index 92679f518..92679f518 100644 --- a/minadbd/transport.c +++ b/minadbd.old/transport.c diff --git a/minadbd/transport.h b/minadbd.old/transport.h index 992e05285..992e05285 100644 --- a/minadbd/transport.h +++ b/minadbd.old/transport.h diff --git a/minadbd/transport_usb.c b/minadbd.old/transport_usb.c index 91cbf6151..91cbf6151 100644 --- a/minadbd/transport_usb.c +++ b/minadbd.old/transport_usb.c diff --git a/minadbd/usb_linux_client.c b/minadbd.old/usb_linux_client.c index ec32bcf91..ec32bcf91 100644 --- a/minadbd/usb_linux_client.c +++ b/minadbd.old/usb_linux_client.c diff --git a/minadbd/utils.c b/minadbd.old/utils.c index 91518bab6..91518bab6 100644 --- a/minadbd/utils.c +++ b/minadbd.old/utils.c diff --git a/minadbd/utils.h b/minadbd.old/utils.h index f70ecd24d..f70ecd24d 100644 --- a/minadbd/utils.h +++ b/minadbd.old/utils.h diff --git a/minadbd/Android.mk b/minadbd/Android.mk index 19c8b6047..36e14a51e 100644 --- a/minadbd/Android.mk +++ b/minadbd/Android.mk @@ -1,30 +1,38 @@ # Copyright 2005 The Android Open Source Project -# -# Android.mk for adb -# LOCAL_PATH:= $(call my-dir) -# minadbd library -# ========================================================= +minadbd_cflags := \ + -Wall -Werror \ + -Wno-unused-parameter \ + -Wno-missing-field-initializers \ + -DADB_HOST=0 \ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ - adb.c \ - fdevent.c \ - fuse_adb_provider.c \ - transport.c \ - transport_usb.c \ - sockets.c \ - services.c \ - usb_linux_client.c \ - utils.c - -LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter -LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE -LOCAL_MODULE_TAGS := eng + adb_main.cpp \ + fuse_adb_provider.cpp \ + services.cpp \ + ../fuse_sideload.c + LOCAL_MODULE := libminadbd -LOCAL_C_INCLUDES += $(LOCAL_PATH)/../ -LOCAL_SHARED_LIBRARIES := libfusesideload libcutils libc +LOCAL_CFLAGS := $(minadbd_cflags) +LOCAL_CONLY_FLAGS := -Wimplicit-function-declaration +LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. system/core/adb +LOCAL_WHOLE_STATIC_LIBRARIES := libadbd +LOCAL_SHARED_LIBRARIES := libbase liblog libmincrypttwrp libcutils libc + include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_CLANG := true +LOCAL_MODULE := minadbd_test +LOCAL_SRC_FILES := fuse_adb_provider_test.cpp +LOCAL_CFLAGS := $(minadbd_cflags) +LOCAL_C_INCLUDES := $(LOCAL_PATH) system/core/adb +LOCAL_STATIC_LIBRARIES := libminadbd +LOCAL_SHARED_LIBRARIES := liblog libbase libcutils + +include $(BUILD_NATIVE_TEST) diff --git a/minadbd/README.txt b/minadbd/README.txt index c9df484c3..e69dc87c6 100644 --- a/minadbd/README.txt +++ b/minadbd/README.txt @@ -1,39 +1,8 @@ -The contents of this directory are copied from system/core/adb, with -the following changes: +minadbd is now mostly built from libadbd. The fuse features are unique to +minadbd, and services.c has been modified as follows: -adb.c - - much support for host mode and non-linux OS's stripped out; this - version only runs as adbd on the device. - - always setuid/setgid's itself to the shell user - - only uses USB transport - - references to JDWP removed - - main() removed - - all ADB_HOST and win32 code removed - - removed listeners, logging code, background server (for host) - -adb.h - - minor changes to match adb.c changes - -sockets.c - - references to JDWP removed - - ADB_HOST code removed - -services.c - - all services except echo_service (which is commented out) removed + - all services removed - all host mode support removed - sideload_service() added; this is the only service supported. It receives a single blob of data, writes it to a fixed filename, and makes the process exit. - -Android.mk - - only builds in adbd mode; builds as static library instead of a - standalone executable. - -sysdeps.h - - changes adb_creat() to use O_NOFOLLOW - -transport.c - - removed ADB_HOST code - -transport_usb.c - - removed ADB_HOST code diff --git a/minadbd/adb_main.cpp b/minadbd/adb_main.cpp new file mode 100644 index 000000000..7fae99a9a --- /dev/null +++ b/minadbd/adb_main.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 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 <errno.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> + +#define TRACE_TAG TRACE_ADB + +#include "sysdeps.h" + +#include "adb.h" +#include "adb_auth.h" +#include "transport.h" + +int adb_main(int is_daemon, int server_port) +{ + atexit(usb_cleanup); + + adb_device_banner = "sideload"; + + // No SIGCHLD. Let the service subproc handle its children. + signal(SIGPIPE, SIG_IGN); + + // We can't require authentication for sideloading. http://b/22025550. + auth_required = false; + + init_transport_registration(); + usb_init(); + + D("Event loop starting\n"); + fdevent_loop(); + + return 0; +} diff --git a/minadbd/fuse_adb_provider.cpp b/minadbd/fuse_adb_provider.cpp new file mode 100644 index 000000000..d71807dfb --- /dev/null +++ b/minadbd/fuse_adb_provider.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2014 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 <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include "sysdeps.h" + +#include "adb.h" +#include "adb_io.h" +#include "fuse_adb_provider.h" +#include "fuse_sideload.h" + +int read_block_adb(void* data, uint32_t block, uint8_t* buffer, uint32_t fetch_size) { + adb_data* ad = reinterpret_cast<adb_data*>(data); + + if (!WriteFdFmt(ad->sfd, "%08u", block)) { + fprintf(stderr, "failed to write to adb host: %s\n", strerror(errno)); + return -EIO; + } + + if (!ReadFdExactly(ad->sfd, buffer, fetch_size)) { + fprintf(stderr, "failed to read from adb host: %s\n", strerror(errno)); + return -EIO; + } + + return 0; +} + +static void close_adb(void* data) { + adb_data* ad = reinterpret_cast<adb_data*>(data); + WriteFdExactly(ad->sfd, "DONEDONE"); +} + +int run_adb_fuse(int sfd, uint64_t file_size, uint32_t block_size) { + adb_data ad; + ad.sfd = sfd; + ad.file_size = file_size; + ad.block_size = block_size; + + provider_vtab vtab; + vtab.read_block = read_block_adb; + vtab.close = close_adb; + + return run_fuse_sideload(&vtab, &ad, file_size, block_size); +} diff --git a/minadbd/fuse_adb_provider.h b/minadbd/fuse_adb_provider.h index 0eb1f79d1..9941709b9 100644 --- a/minadbd/fuse_adb_provider.h +++ b/minadbd/fuse_adb_provider.h @@ -17,6 +17,16 @@ #ifndef __FUSE_ADB_PROVIDER_H #define __FUSE_ADB_PROVIDER_H +#include <stdint.h> + +struct adb_data { + int sfd; // file descriptor for the adb channel + + uint64_t file_size; + uint32_t block_size; +}; + +int read_block_adb(void* cookie, uint32_t block, uint8_t* buffer, uint32_t fetch_size); int run_adb_fuse(int sfd, uint64_t file_size, uint32_t block_size); #endif diff --git a/minadbd/fuse_adb_provider_test.cpp b/minadbd/fuse_adb_provider_test.cpp new file mode 100644 index 000000000..0f2e881c7 --- /dev/null +++ b/minadbd/fuse_adb_provider_test.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2015 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 "fuse_adb_provider.h" + +#include <gtest/gtest.h> + +#include <errno.h> +#include <fcntl.h> +#include <sys/socket.h> + +#include <string> + +#include "adb_io.h" + +TEST(fuse_adb_provider, read_block_adb) { + adb_data data = {}; + int sockets[2]; + + ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sockets)); + data.sfd = sockets[0]; + + int host_socket = sockets[1]; + fcntl(host_socket, F_SETFL, O_NONBLOCK); + + const char expected_data[] = "foobar"; + char block_data[sizeof(expected_data)] = {}; + + // If we write the result of read_block_adb's request before the request is + // actually made we can avoid needing an extra thread for this test. + ASSERT_TRUE(WriteFdExactly(host_socket, expected_data, + strlen(expected_data))); + + uint32_t block = 1234U; + const char expected_block[] = "00001234"; + ASSERT_EQ(0, read_block_adb(reinterpret_cast<void*>(&data), block, + reinterpret_cast<uint8_t*>(block_data), + sizeof(expected_data) - 1)); + + // Check that read_block_adb requested the right block. + char block_req[sizeof(expected_block)] = {}; + ASSERT_TRUE(ReadFdExactly(host_socket, block_req, 8)); + ASSERT_EQ(0, block_req[8]); + ASSERT_EQ(8U, strlen(block_req)); + ASSERT_STREQ(expected_block, block_req); + + // Check that read_block_adb returned the right data. + ASSERT_EQ(0, block_req[8]); + ASSERT_STREQ(expected_data, block_data); + + // Check that nothing else was written to the socket. + char tmp; + errno = 0; + ASSERT_EQ(-1, read(host_socket, &tmp, 1)); + ASSERT_EQ(EWOULDBLOCK, errno); + + close(sockets[0]); + close(sockets[1]); +} + +TEST(fuse_adb_provider, read_block_adb_fail_write) { + adb_data data = {}; + int sockets[2]; + + ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sockets)); + data.sfd = sockets[0]; + + ASSERT_EQ(0, close(sockets[1])); + + char buf[1]; + ASSERT_EQ(-EIO, read_block_adb(reinterpret_cast<void*>(&data), 0, + reinterpret_cast<uint8_t*>(buf), 1)); + + close(sockets[0]); +} diff --git a/minadbd/services.cpp b/minadbd/services.cpp new file mode 100644 index 000000000..dd1fd7c4b --- /dev/null +++ b/minadbd/services.cpp @@ -0,0 +1,106 @@ +/* + * 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 <errno.h> +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "sysdeps.h" + +#define TRACE_TAG TRACE_SERVICES +#include "adb.h" +#include "fdevent.h" +#include "fuse_adb_provider.h" + +typedef struct stinfo stinfo; + +struct stinfo { + void (*func)(int fd, void *cookie); + int fd; + void *cookie; +}; + +void* service_bootstrap_func(void* x) { + stinfo* sti = reinterpret_cast<stinfo*>(x); + sti->func(sti->fd, sti->cookie); + free(sti); + return 0; +} + +static void sideload_host_service(int sfd, void* data) { + const char* args = reinterpret_cast<const char*>(data); + int file_size; + int block_size; + if (sscanf(args, "%d:%d", &file_size, &block_size) != 2) { + printf("bad sideload-host arguments: %s\n", args); + exit(1); + } + + printf("sideload-host file size %d block size %d\n", file_size, block_size); + + int result = run_adb_fuse(sfd, file_size, block_size); + + printf("sideload_host finished\n"); + sleep(1); + exit(result == 0 ? 0 : 1); +} + +static int create_service_thread(void (*func)(int, void *), void *cookie) +{ + int s[2]; + if(adb_socketpair(s)) { + printf("cannot create service socket pair\n"); + return -1; + } + + stinfo* sti = reinterpret_cast<stinfo*>(malloc(sizeof(stinfo))); + if(sti == 0) fatal("cannot allocate stinfo"); + sti->func = func; + sti->cookie = cookie; + sti->fd = s[1]; + + adb_thread_t t; + if (adb_thread_create( &t, service_bootstrap_func, sti)){ + free(sti); + adb_close(s[0]); + adb_close(s[1]); + printf("cannot create service thread\n"); + return -1; + } + + D("service thread started, %d:%d\n",s[0], s[1]); + return s[0]; +} + +int service_to_fd(const char* name) { + int ret = -1; + + if (!strncmp(name, "sideload:", 9)) { + // this exit status causes recovery to print a special error + // message saying to use a newer adb (that supports + // sideload-host). + exit(3); + } else if (!strncmp(name, "sideload-host:", 14)) { + ret = create_service_thread(sideload_host_service, (void*)(name + 14)); + } + if (ret >= 0) { + close_on_exec(ret); + } + return ret; +} |