diff options
Diffstat (limited to 'minadbd')
-rw-r--r-- | minadbd/Android.mk | 41 | ||||
-rw-r--r-- | minadbd/fuse_adb_provider.cpp | 53 | ||||
-rw-r--r-- | minadbd/fuse_adb_provider.h | 8 | ||||
-rw-r--r-- | minadbd/fuse_adb_provider_test.cpp | 6 | ||||
-rw-r--r-- | minadbd/minadbd_services.cpp | 38 |
5 files changed, 86 insertions, 60 deletions
diff --git a/minadbd/Android.mk b/minadbd/Android.mk index dfeb85ef6..a50d8444f 100644 --- a/minadbd/Android.mk +++ b/minadbd/Android.mk @@ -1,14 +1,26 @@ # Copyright 2005 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. LOCAL_PATH:= $(call my-dir) minadbd_cflags := \ -Wall -Werror \ - -Wno-unused-parameter \ - -Wno-missing-field-initializers \ -DADB_HOST=0 \ -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) +# libminadbd (static library) +# =============================== include $(CLEAR_VARS) LOCAL_SRC_FILES := \ @@ -17,9 +29,8 @@ LOCAL_SRC_FILES := \ minadbd.cpp \ minadbd_services.cpp \ -LOCAL_CLANG := true LOCAL_MODULE := libminadbd -LOCAL_CFLAGS := $(minadbd_cflags) +LOCAL_CFLAGS := $(minadbd_cflags) -Wno-unused-parameter LOCAL_CONLY_FLAGS := -Wimplicit-function-declaration LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. system/core/adb LOCAL_WHOLE_STATIC_LIBRARIES := libadbd @@ -32,6 +43,10 @@ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0) else LOCAL_SHARED_LIBRARIES += libcrypto \ $(if $(WITH_CRYPTO_UTILS),libcrypto_utils) + ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0) + # Needed in Android 9.0 + LOCAL_WHOLE_STATIC_LIBRARIES += libasyncio + endif endif include $(BUILD_SHARED_LIBRARY) @@ -46,7 +61,7 @@ LOCAL_SRC_FILES := \ LOCAL_CLANG := true LOCAL_MODULE := libminadbd -LOCAL_CFLAGS := $(minadbd_cflags) +LOCAL_CFLAGS := $(minadbd_cflags) -Wno-unused-parameter LOCAL_CONLY_FLAGS := -Wimplicit-function-declaration LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. system/core/adb LOCAL_WHOLE_STATIC_LIBRARIES := libadbd @@ -59,19 +74,29 @@ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0) else LOCAL_SHARED_LIBRARIES += libcrypto \ $(if $(WITH_CRYPTO_UTILS),libcrypto_utils) + ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0) + # Needed in Android 9.0 + LOCAL_WHOLE_STATIC_LIBRARIES += libasyncio + endif endif include $(BUILD_STATIC_LIBRARY) +# minadbd_test (native test) +# =============================== include $(CLEAR_VARS) -LOCAL_CLANG := true LOCAL_MODULE := minadbd_test LOCAL_COMPATIBILITY_SUITE := device-tests 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 +LOCAL_STATIC_LIBRARIES := \ + libBionicGtestMain \ + libminadbd +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libbase \ + libcutils include $(BUILD_NATIVE_TEST) diff --git a/minadbd/fuse_adb_provider.cpp b/minadbd/fuse_adb_provider.cpp index 0f4c2563d..9bd3f2392 100644 --- a/minadbd/fuse_adb_provider.cpp +++ b/minadbd/fuse_adb_provider.cpp @@ -14,46 +14,43 @@ * limitations under the License. */ -#include <stdlib.h> +#include "fuse_adb_provider.h" + +#include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <errno.h> + +#include <functional> #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; - } +int read_block_adb(const adb_data& ad, uint32_t block, uint8_t* buffer, uint32_t fetch_size) { + 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; -} + if (!ReadFdExactly(ad.sfd, buffer, fetch_size)) { + fprintf(stderr, "failed to read from adb host: %s\n", strerror(errno)); + return -EIO; + } -static void close_adb(void* data) { - adb_data* ad = reinterpret_cast<adb_data*>(data); - WriteFdExactly(ad->sfd, "DONEDONE"); + return 0; } 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; + 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; + provider_vtab vtab; + vtab.read_block = std::bind(read_block_adb, ad, std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3); + vtab.close = [&ad]() { WriteFdExactly(ad.sfd, "DONEDONE"); }; - return run_fuse_sideload(&vtab, &ad, file_size, block_size); + return run_fuse_sideload(vtab, file_size, block_size); } diff --git a/minadbd/fuse_adb_provider.h b/minadbd/fuse_adb_provider.h index 9941709b9..36d86d539 100644 --- a/minadbd/fuse_adb_provider.h +++ b/minadbd/fuse_adb_provider.h @@ -20,13 +20,13 @@ #include <stdint.h> struct adb_data { - int sfd; // file descriptor for the adb channel + int sfd; // file descriptor for the adb channel - uint64_t file_size; - uint32_t block_size; + 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 read_block_adb(const adb_data& ad, 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 index 31be2a64e..00250e505 100644 --- a/minadbd/fuse_adb_provider_test.cpp +++ b/minadbd/fuse_adb_provider_test.cpp @@ -46,8 +46,8 @@ TEST(fuse_adb_provider, read_block_adb) { uint32_t block = 1234U; const char expected_block[] = "00001234"; - ASSERT_EQ(0, read_block_adb(static_cast<void*>(&data), block, - reinterpret_cast<uint8_t*>(block_data), sizeof(expected_data) - 1)); + ASSERT_EQ(0, read_block_adb(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)] = {}; @@ -84,7 +84,7 @@ TEST(fuse_adb_provider, read_block_adb_fail_write) { signal(SIGPIPE, SIG_IGN); char buf[1]; - ASSERT_EQ(-EIO, read_block_adb(static_cast<void*>(&data), 0, reinterpret_cast<uint8_t*>(buf), 1)); + ASSERT_EQ(-EIO, read_block_adb(data, 0, reinterpret_cast<uint8_t*>(buf), 1)); close(sockets[0]); } diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp index 6919cdd40..03692d00c 100644 --- a/minadbd/minadbd_services.cpp +++ b/minadbd/minadbd_services.cpp @@ -117,26 +117,30 @@ static int create_service_thread(void (*func)(int, const std::string&), const st } #endif -int service_to_fd(const char* name, const atransport* transport) { - 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)) { +#if PLATFORM_SDK_VERSION >= 28 +int service_to_fd(const char* name, atransport* /* transport */) { +#else +int service_to_fd(const char* name, const atransport* transport __unused) { +#endif + 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)) { #if PLATFORM_SDK_VERSION < 26 - char* arg = strdup(name + 14); + char* arg = strdup(name + 14); #else - std::string arg(name + 14); + std::string arg(name + 14); #endif - ret = create_service_thread(sideload_host_service, arg); - } - if (ret >= 0) { - close_on_exec(ret); - } - return ret; + ret = create_service_thread(sideload_host_service, arg); + } + if (ret >= 0) { + close_on_exec(ret); + } + return ret; } #if PLATFORM_SDK_VERSION == 23 |