upload android base code part3
This commit is contained in:
parent
71b83c22f1
commit
b9e30e05b1
15122 changed files with 2089659 additions and 0 deletions
39
android/bootable/recovery/minadbd/Android.mk
Normal file
39
android/bootable/recovery/minadbd/Android.mk
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Copyright 2005 The Android Open Source Project
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
minadbd_cflags := \
|
||||
-Wall -Werror \
|
||||
-Wno-unused-parameter \
|
||||
-Wno-missing-field-initializers \
|
||||
-DADB_HOST=0 \
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
fuse_adb_provider.cpp \
|
||||
minadbd.cpp \
|
||||
minadbd_services.cpp \
|
||||
|
||||
LOCAL_CLANG := true
|
||||
LOCAL_MODULE := libminadbd
|
||||
LOCAL_CFLAGS := $(minadbd_cflags)
|
||||
LOCAL_CONLY_FLAGS := -Wimplicit-function-declaration
|
||||
LOCAL_C_INCLUDES := bootable/recovery system/core/adb
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES := libadbd
|
||||
LOCAL_STATIC_LIBRARIES := libcrypto libbase
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
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
|
||||
|
||||
include $(BUILD_NATIVE_TEST)
|
26
android/bootable/recovery/minadbd/AndroidTest.xml
Normal file
26
android/bootable/recovery/minadbd/AndroidTest.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2017 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.
|
||||
-->
|
||||
<configuration description="Config for minadbd_test">
|
||||
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
|
||||
<option name="cleanup" value="true" />
|
||||
<option name="push" value="minadbd_test->/data/local/tmp/minadbd_test" />
|
||||
</target_preparer>
|
||||
<option name="test-suite-tag" value="apct" />
|
||||
<test class="com.android.tradefed.testtype.GTest" >
|
||||
<option name="native-test-device-path" value="/data/local/tmp" />
|
||||
<option name="module-name" value="minadbd_test" />
|
||||
</test>
|
||||
</configuration>
|
8
android/bootable/recovery/minadbd/README.md
Normal file
8
android/bootable/recovery/minadbd/README.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
minadbd is now mostly built from libadbd. The fuse features are unique to
|
||||
minadbd, and services.c has been modified as follows:
|
||||
|
||||
- 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.
|
59
android/bootable/recovery/minadbd/fuse_adb_provider.cpp
Normal file
59
android/bootable/recovery/minadbd/fuse_adb_provider.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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 "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);
|
||||
}
|
32
android/bootable/recovery/minadbd/fuse_adb_provider.h
Normal file
32
android/bootable/recovery/minadbd/fuse_adb_provider.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
#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
|
90
android/bootable/recovery/minadbd/fuse_adb_provider_test.cpp
Normal file
90
android/bootable/recovery/minadbd/fuse_adb_provider_test.cpp
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* 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 <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "adb_io.h"
|
||||
#include "fuse_adb_provider.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(static_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]));
|
||||
|
||||
// write(2) raises SIGPIPE since the reading end has been closed. Ignore the signal to avoid
|
||||
// failing the test.
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
char buf[1];
|
||||
ASSERT_EQ(-EIO, read_block_adb(static_cast<void*>(&data), 0, reinterpret_cast<uint8_t*>(buf), 1));
|
||||
|
||||
close(sockets[0]);
|
||||
}
|
43
android/bootable/recovery/minadbd/minadbd.cpp
Normal file
43
android/bootable/recovery/minadbd/minadbd.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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 "minadbd.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "adb.h"
|
||||
#include "adb_auth.h"
|
||||
#include "transport.h"
|
||||
|
||||
int minadbd_main() {
|
||||
adb_device_banner = "sideload";
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
// We can't require authentication for sideloading. http://b/22025550.
|
||||
auth_required = false;
|
||||
|
||||
init_transport_registration();
|
||||
usb_init();
|
||||
|
||||
VLOG(ADB) << "Event loop starting";
|
||||
fdevent_loop();
|
||||
|
||||
return 0;
|
||||
}
|
22
android/bootable/recovery/minadbd/minadbd.h
Normal file
22
android/bootable/recovery/minadbd/minadbd.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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 MINADBD_H__
|
||||
#define MINADBD_H__
|
||||
|
||||
int minadbd_main();
|
||||
|
||||
#endif
|
77
android/bootable/recovery/minadbd/minadbd_services.cpp
Normal file
77
android/bootable/recovery/minadbd/minadbd_services.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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 <string>
|
||||
#include <thread>
|
||||
|
||||
#include "adb.h"
|
||||
#include "fdevent.h"
|
||||
#include "fuse_adb_provider.h"
|
||||
#include "sysdeps.h"
|
||||
|
||||
static void sideload_host_service(int sfd, const std::string& args) {
|
||||
int file_size;
|
||||
int block_size;
|
||||
if (sscanf(args.c_str(), "%d:%d", &file_size, &block_size) != 2) {
|
||||
printf("bad sideload-host arguments: %s\n", args.c_str());
|
||||
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");
|
||||
exit(result == 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
static int create_service_thread(void (*func)(int, const std::string&), const std::string& args) {
|
||||
int s[2];
|
||||
if (adb_socketpair(s)) {
|
||||
printf("cannot create service socket pair\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::thread([s, func, args]() { func(s[1], args); }).detach();
|
||||
|
||||
VLOG(SERVICES) << "service thread started, " << s[0] << ":" << s[1];
|
||||
return s[0];
|
||||
}
|
||||
|
||||
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)) {
|
||||
std::string arg(name + 14);
|
||||
ret = create_service_thread(sideload_host_service, arg);
|
||||
}
|
||||
if (ret >= 0) {
|
||||
close_on_exec(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue