Merge "DO NOT MERGE - Merge Android 10 into master"

This commit is contained in:
Xin Li 2019-09-05 16:53:23 +00:00 committed by Gerrit Code Review
commit d0a45dbc9a
25 changed files with 195 additions and 92 deletions

View File

@ -337,9 +337,12 @@ void handle_packet(apacket *p, atransport *t)
case ADB_AUTH_SIGNATURE: {
// TODO: Switch to string_view.
std::string signature(p->payload.begin(), p->payload.end());
if (adbd_auth_verify(t->token, sizeof(t->token), signature)) {
std::string auth_key;
if (adbd_auth_verify(t->token, sizeof(t->token), signature, &auth_key)) {
adbd_auth_verified(t);
t->failed_auth_attempts = 0;
t->auth_key = auth_key;
adbd_notify_framework_connected_key(t);
} else {
if (t->failed_auth_attempts++ > 256) std::this_thread::sleep_for(1s);
send_auth_request(t);
@ -348,7 +351,8 @@ void handle_packet(apacket *p, atransport *t)
}
case ADB_AUTH_RSAPUBLICKEY:
adbd_auth_confirm_key(p->payload.data(), p->msg.data_length, t);
t->auth_key = std::string(p->payload.data());
adbd_auth_confirm_key(t);
break;
#endif
default:

View File

@ -33,6 +33,7 @@
constexpr size_t MAX_PAYLOAD_V1 = 4 * 1024;
constexpr size_t MAX_PAYLOAD = 1024 * 1024;
constexpr size_t MAX_FRAMEWORK_PAYLOAD = 64 * 1024;
constexpr size_t LINUX_MAX_SOCKET_SIZE = 4194304;

View File

@ -50,8 +50,10 @@ void adbd_auth_init(void);
void adbd_auth_verified(atransport *t);
void adbd_cloexec_auth_socket();
bool adbd_auth_verify(const char* token, size_t token_size, const std::string& sig);
void adbd_auth_confirm_key(const char* data, size_t len, atransport* t);
bool adbd_auth_verify(const char* token, size_t token_size, const std::string& sig,
std::string* auth_key);
void adbd_auth_confirm_key(atransport* t);
void adbd_notify_framework_connected_key(atransport* t);
void send_auth_request(atransport *t);

View File

@ -26,7 +26,9 @@
#include <resolv.h>
#include <stdio.h>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <memory>
#include <android-base/file.h>
@ -38,22 +40,24 @@
static fdevent* listener_fde = nullptr;
static fdevent* framework_fde = nullptr;
static int framework_fd = -1;
static auto& framework_mutex = *new std::mutex();
static int framework_fd GUARDED_BY(framework_mutex) = -1;
static auto& connected_keys GUARDED_BY(framework_mutex) = *new std::vector<std::string>;
static void usb_disconnected(void* unused, atransport* t);
static struct adisconnect usb_disconnect = { usb_disconnected, nullptr};
static atransport* usb_transport;
static void adb_disconnected(void* unused, atransport* t);
static struct adisconnect adb_disconnect = {adb_disconnected, nullptr};
static atransport* adb_transport;
static bool needs_retry = false;
bool auth_required = true;
bool adbd_auth_verify(const char* token, size_t token_size, const std::string& sig) {
bool adbd_auth_verify(const char* token, size_t token_size, const std::string& sig,
std::string* auth_key) {
static constexpr const char* key_paths[] = { "/adb_keys", "/data/misc/adb/adb_keys", nullptr };
for (const auto& path : key_paths) {
if (access(path, R_OK) == 0) {
LOG(INFO) << "Loading keys from " << path;
std::string content;
if (!android::base::ReadFileToString(path, &content)) {
PLOG(ERROR) << "Couldn't read " << path;
@ -61,6 +65,8 @@ bool adbd_auth_verify(const char* token, size_t token_size, const std::string& s
}
for (const auto& line : android::base::Split(content, "\n")) {
if (line.empty()) continue;
*auth_key = line;
// TODO: do we really have to support both ' ' and '\t'?
char* sep = strpbrk(const_cast<char*>(line.c_str()), " \t");
if (sep) *sep = '\0';
@ -88,9 +94,31 @@ bool adbd_auth_verify(const char* token, size_t token_size, const std::string& s
}
}
}
auth_key->clear();
return false;
}
static bool adbd_send_key_message_locked(std::string_view msg_type, std::string_view key)
REQUIRES(framework_mutex) {
if (framework_fd < 0) {
LOG(ERROR) << "Client not connected to send msg_type " << msg_type;
return false;
}
std::string msg = std::string(msg_type) + std::string(key);
int msg_len = msg.length();
if (msg_len >= static_cast<int>(MAX_FRAMEWORK_PAYLOAD)) {
LOG(ERROR) << "Key too long (" << msg_len << ")";
return false;
}
LOG(DEBUG) << "Sending '" << msg << "'";
if (!WriteFdExactly(framework_fd, msg.c_str(), msg_len)) {
PLOG(ERROR) << "Failed to write " << msg_type;
return false;
}
return true;
}
static bool adbd_auth_generate_token(void* token, size_t token_size) {
FILE* fp = fopen("/dev/urandom", "re");
if (!fp) return false;
@ -99,17 +127,28 @@ static bool adbd_auth_generate_token(void* token, size_t token_size) {
return okay;
}
static void usb_disconnected(void* unused, atransport* t) {
LOG(INFO) << "USB disconnect";
usb_transport = nullptr;
static void adb_disconnected(void* unused, atransport* t) {
LOG(INFO) << "ADB disconnect";
adb_transport = nullptr;
needs_retry = false;
{
std::lock_guard<std::mutex> lock(framework_mutex);
if (framework_fd >= 0) {
adbd_send_key_message_locked("DC", t->auth_key);
}
connected_keys.erase(std::remove(connected_keys.begin(), connected_keys.end(), t->auth_key),
connected_keys.end());
}
}
static void framework_disconnected() {
LOG(INFO) << "Framework disconnect";
if (framework_fde) {
fdevent_destroy(framework_fde);
framework_fd = -1;
{
std::lock_guard<std::mutex> lock(framework_mutex);
framework_fd = -1;
}
}
}
@ -120,41 +159,28 @@ static void adbd_auth_event(int fd, unsigned events, void*) {
if (ret <= 0) {
framework_disconnected();
} else if (ret == 2 && response[0] == 'O' && response[1] == 'K') {
if (usb_transport) {
adbd_auth_verified(usb_transport);
if (adb_transport) {
adbd_auth_verified(adb_transport);
}
}
}
}
void adbd_auth_confirm_key(const char* key, size_t len, atransport* t) {
if (!usb_transport) {
usb_transport = t;
t->AddDisconnect(&usb_disconnect);
void adbd_auth_confirm_key(atransport* t) {
if (!adb_transport) {
adb_transport = t;
t->AddDisconnect(&adb_disconnect);
}
if (framework_fd < 0) {
LOG(ERROR) << "Client not connected";
needs_retry = true;
return;
}
{
std::lock_guard<std::mutex> lock(framework_mutex);
if (framework_fd < 0) {
LOG(ERROR) << "Client not connected";
needs_retry = true;
return;
}
if (key[len - 1] != '\0') {
LOG(ERROR) << "Key must be a null-terminated string";
return;
}
char msg[MAX_PAYLOAD_V1];
int msg_len = snprintf(msg, sizeof(msg), "PK%s", key);
if (msg_len >= static_cast<int>(sizeof(msg))) {
LOG(ERROR) << "Key too long (" << msg_len << ")";
return;
}
LOG(DEBUG) << "Sending '" << msg << "'";
if (unix_write(framework_fd, msg, msg_len) == -1) {
PLOG(ERROR) << "Failed to write PK";
return;
adbd_send_key_message_locked("PK", t->auth_key);
}
}
@ -165,18 +191,46 @@ static void adbd_auth_listener(int fd, unsigned events, void* data) {
return;
}
if (framework_fd >= 0) {
LOG(WARNING) << "adb received framework auth socket connection again";
framework_disconnected();
{
std::lock_guard<std::mutex> lock(framework_mutex);
if (framework_fd >= 0) {
LOG(WARNING) << "adb received framework auth socket connection again";
framework_disconnected();
}
framework_fd = s;
framework_fde = fdevent_create(framework_fd, adbd_auth_event, nullptr);
fdevent_add(framework_fde, FDE_READ);
if (needs_retry) {
needs_retry = false;
send_auth_request(adb_transport);
}
// if a client connected before the framework was available notify the framework of the
// connected key now.
if (!connected_keys.empty()) {
for (const auto& key : connected_keys) {
adbd_send_key_message_locked("CK", key);
}
}
}
}
framework_fd = s;
framework_fde = fdevent_create(framework_fd, adbd_auth_event, nullptr);
fdevent_add(framework_fde, FDE_READ);
if (needs_retry) {
needs_retry = false;
send_auth_request(usb_transport);
void adbd_notify_framework_connected_key(atransport* t) {
if (!adb_transport) {
adb_transport = t;
t->AddDisconnect(&adb_disconnect);
}
{
std::lock_guard<std::mutex> lock(framework_mutex);
if (std::find(connected_keys.begin(), connected_keys.end(), t->auth_key) ==
connected_keys.end()) {
connected_keys.push_back(t->auth_key);
}
if (framework_fd >= 0) {
adbd_send_key_message_locked("CK", t->auth_key);
}
}
}

View File

@ -509,16 +509,14 @@ struct UsbFfsConnection : public Connection {
}
if (id.direction == TransferDirection::READ) {
if (!HandleRead(id, event.res)) {
return;
}
HandleRead(id, event.res);
} else {
HandleWrite(id);
}
}
}
bool HandleRead(TransferId id, int64_t size) {
void HandleRead(TransferId id, int64_t size) {
uint64_t read_idx = id.id % kUsbReadQueueDepth;
IoBlock* block = &read_requests_[read_idx];
block->pending = false;
@ -528,7 +526,7 @@ struct UsbFfsConnection : public Connection {
if (block->id().id != needed_read_id_) {
LOG(VERBOSE) << "read " << block->id().id << " completed while waiting for "
<< needed_read_id_;
return true;
return;
}
for (uint64_t id = needed_read_id_;; ++id) {
@ -537,22 +535,15 @@ struct UsbFfsConnection : public Connection {
if (current_block->pending) {
break;
}
if (!ProcessRead(current_block)) {
return false;
}
ProcessRead(current_block);
++needed_read_id_;
}
return true;
}
bool ProcessRead(IoBlock* block) {
void ProcessRead(IoBlock* block) {
if (!block->payload->empty()) {
if (!incoming_header_.has_value()) {
if (block->payload->size() != sizeof(amessage)) {
HandleError("received packet of unexpected length while reading header");
return false;
}
CHECK_EQ(sizeof(amessage), block->payload->size());
amessage msg;
memcpy(&msg, block->payload->data(), sizeof(amessage));
LOG(DEBUG) << "USB read:" << dump_header(&msg);
@ -560,10 +551,7 @@ struct UsbFfsConnection : public Connection {
} else {
size_t bytes_left = incoming_header_->data_length - incoming_payload_.size();
Block payload = std::move(*block->payload);
if (block->payload->size() > bytes_left) {
HandleError("received too many bytes while waiting for payload");
return false;
}
CHECK_LE(payload.size(), bytes_left);
incoming_payload_.append(std::make_unique<Block>(std::move(payload)));
}
@ -582,7 +570,6 @@ struct UsbFfsConnection : public Connection {
PrepareReadBlock(block, block->id().id + kUsbReadQueueDepth);
SubmitRead(block);
return true;
}
bool SubmitRead(IoBlock* block) {

View File

@ -275,6 +275,9 @@ class atransport {
std::string device;
std::string devpath;
// Used to provide the key to the framework.
std::string auth_key;
bool IsTcpDevice() const { return type == kTransportLocal; }
#if ADB_HOST

View File

@ -1093,8 +1093,8 @@ void RecordAbsoluteBootTime(BootEventRecordStore* boot_event_store,
void LogBootInfoToStatsd(std::chrono::milliseconds end_time,
std::chrono::milliseconds total_duration, int32_t bootloader_duration_ms,
double time_since_last_boot_sec) {
const auto reason = android::base::GetProperty(bootloader_reboot_reason_property, "<EMPTY>");
const auto system_reason = android::base::GetProperty(system_reboot_reason_property, "<EMPTY>");
auto reason = android::base::GetProperty(bootloader_reboot_reason_property, "<EMPTY>");
auto system_reason = android::base::GetProperty(system_reboot_reason_property, "<EMPTY>");
android::util::stats_write(android::util::BOOT_SEQUENCE_REPORTED, reason.c_str(),
system_reason.c_str(), end_time.count(), total_duration.count(),
(int64_t)bootloader_duration_ms,

View File

@ -23,7 +23,6 @@ CHARGER_STATIC_LIBRARIES := \
libcharger_sysprop \
libhidltransport \
libhidlbase \
libhwbinder_noltopgo \
libhealthstoragedefault \
libminui \
libvndksupport \
@ -77,7 +76,6 @@ LOCAL_STATIC_LIBRARIES := \
libcharger_sysprop \
libhidltransport \
libhidlbase \
libhwbinder_noltopgo \
libhealthstoragedefault \
libvndksupport \
libhealthd_charger_nops \

View File

@ -86,6 +86,7 @@ class FuseBridgeEntry {
const bool proxy_read_ready = last_proxy_events_.events & EPOLLIN;
const bool proxy_write_ready = last_proxy_events_.events & EPOLLOUT;
last_state_ = state_;
last_device_events_.events = 0;
last_proxy_events_.events = 0;

View File

@ -69,10 +69,11 @@ native_handle_t* native_handle_init(char* storage, int numFds, int numInts);
/*
* native_handle_create
*
*
* creates a native_handle_t and initializes it. must be destroyed with
* native_handle_delete().
*
* native_handle_delete(). Note that numFds must be <= NATIVE_HANDLE_MAX_FDS,
* numInts must be <= NATIVE_HANDLE_MAX_INTS, and both must be >= 0.
*
*/
native_handle_t* native_handle_create(int numFds, int numInts);

View File

@ -113,7 +113,7 @@ cc_test {
static_libs: ["libmemunreachable"],
shared_libs: [
"libbinder",
"libhwbinder",
"libhidlbase",
"libutils",
],
test_suites: ["device-tests"],

View File

@ -109,6 +109,11 @@ static int statsdOpen() {
if (sock < 0) {
ret = -errno;
} else {
int sndbuf = 1 * 1024 * 1024; // set max send buffer size 1MB
socklen_t bufLen = sizeof(sndbuf);
// SO_RCVBUF does not have an effect on unix domain socket, but SO_SNDBUF does.
// Proceed to connect even setsockopt fails.
setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &sndbuf, bufLen);
struct sockaddr_un un;
memset(&un, 0, sizeof(struct sockaddr_un));
un.sun_family = AF_UNIX;

View File

@ -0,0 +1,31 @@
// This file is autogenerated by hidl-gen. Do not edit manually.
// Source: android.hardware.graphics.common@1.2
// Location: hardware/interfaces/graphics/common/1.2/
#ifndef HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_2_EXPORTED_CONSTANTS_H_
#define HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_2_EXPORTED_CONSTANTS_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
HAL_HDR_HDR10_PLUS = 4,
} android_hdr_v1_2_t;
typedef enum {
HAL_DATASPACE_DISPLAY_BT2020 = 142999552 /* ((STANDARD_BT2020 | TRANSFER_SRGB) | RANGE_FULL) */,
HAL_DATASPACE_DYNAMIC_DEPTH = 4098 /* 0x1002 */,
HAL_DATASPACE_JPEG_APP_SEGMENTS = 4099 /* 0x1003 */,
HAL_DATASPACE_HEIF = 4100 /* 0x1004 */,
} android_dataspace_v1_2_t;
typedef enum {
HAL_PIXEL_FORMAT_HSV_888 = 55 /* 0x37 */,
} android_pixel_format_v1_2_t;
#ifdef __cplusplus
}
#endif
#endif // HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_2_EXPORTED_CONSTANTS_H_

View File

@ -3,5 +3,6 @@
#include "graphics-base-v1.0.h"
#include "graphics-base-v1.1.h"
#include "graphics-base-v1.2.h"
#endif // SYSTEM_CORE_GRAPHICS_BASE_H_

View File

@ -1433,8 +1433,8 @@ static int kill_one_process(struct proc* procp, int min_oom_score) {
set_process_group_and_prio(pid, SP_FOREGROUND, ANDROID_PRIORITY_HIGHEST);
inc_killcnt(procp->oomadj);
ALOGI("Kill '%s' (%d), uid %d, oom_adj %d to free %ldkB",
taskname, pid, uid, procp->oomadj, tasksize * page_k);
ALOGE("Kill '%s' (%d), uid %d, oom_adj %d to free %ldkB", taskname, pid, uid, procp->oomadj,
tasksize * page_k);
TRACE_KILL_END();

View File

@ -190,6 +190,7 @@ namespace.media.search.paths = /apex/com.android.media/${LIB}
namespace.media.asan.search.paths = /apex/com.android.media/${LIB}
namespace.media.permitted.paths = /apex/com.android.media/${LIB}/extractors
namespace.media.asan.permitted.paths = /apex/com.android.media/${LIB}/extractors
namespace.media.links = default,neuralnetworks
namespace.media.link.default.shared_libs = %LLNDK_LIBRARIES%
@ -723,6 +724,7 @@ namespace.media.search.paths = /apex/com.android.media/${LIB}
namespace.media.asan.search.paths = /apex/com.android.media/${LIB}
namespace.media.permitted.paths = /apex/com.android.media/${LIB}/extractors
namespace.media.asan.permitted.paths = /apex/com.android.media/${LIB}/extractors
namespace.media.links = default,neuralnetworks
namespace.media.link.default.shared_libs = %LLNDK_LIBRARIES%

View File

@ -1,6 +1,7 @@
# See https://android.googlesource.com/platform/ndk/+/master/docs/PlatformApis.md
libandroid.so
libaaudio.so
libamidi.so
libbinder_ndk.so
libc.so
libcamera2ndk.so

View File

@ -2,6 +2,7 @@
libandroid.so
libandroidthings.so
libaaudio.so
libamidi.so
libbinder_ndk.so
libc.so
libcamera2ndk.so

View File

@ -1,6 +1,7 @@
# See https://android.googlesource.com/platform/ndk/+/master/docs/PlatformApis.md
libandroid.so
libaaudio.so
libamidi.so
libbinder_ndk.so
libc.so
libcamera2ndk.so

View File

@ -431,10 +431,6 @@ on late-fs
# HALs required before storage encryption can get unlocked (FBE/FDE)
class_start early_hal
# Check and mark a successful boot, before mounting userdata with mount_all.
# No-op for non-A/B device.
exec_start update_verifier_nonencrypted
on post-fs-data
mark_post_data
@ -669,16 +665,22 @@ on zygote-start && property:persist.sys.fuse=""
# It is recommended to put unnecessary data/ initialization from post-fs-data
# to start-zygote in device's init.rc to unblock zygote start.
on zygote-start && property:ro.crypto.state=unencrypted
# A/B update verifier that marks a successful boot.
exec_start update_verifier_nonencrypted
start netd
start zygote
start zygote_secondary
on zygote-start && property:ro.crypto.state=unsupported
# A/B update verifier that marks a successful boot.
exec_start update_verifier_nonencrypted
start netd
start zygote
start zygote_secondary
on zygote-start && property:ro.crypto.state=encrypted && property:ro.crypto.type=file
# A/B update verifier that marks a successful boot.
exec_start update_verifier_nonencrypted
start netd
start zygote
start zygote_secondary
@ -702,6 +704,12 @@ on boot
chown root system /sys/module/lowmemorykiller/parameters/minfree
chmod 0664 /sys/module/lowmemorykiller/parameters/minfree
# System server manages zram writeback
chown root system /sys/block/zram0/idle
chmod 0664 /sys/block/zram0/idle
chown root system /sys/block/zram0/writeback
chmod 0664 /sys/block/zram0/writeback
# Tweak background writeout
write /proc/sys/vm/dirty_expire_centisecs 200
write /proc/sys/vm/dirty_background_ratio 5
@ -801,6 +809,8 @@ on property:vold.decrypt=trigger_post_fs_data
trigger zygote-start
on property:vold.decrypt=trigger_restart_min_framework
# A/B update verifier that marks a successful boot.
exec_start update_verifier
class_start main
on property:vold.decrypt=trigger_restart_framework

View File

@ -14,7 +14,7 @@ on post-fs-data
# adbd is controlled via property triggers in init.<platform>.usb.rc
service adbd /system/bin/adbd --root_seclabel=u:r:su:s0
class core
socket adbd stream 660 system system
socket adbd seqpacket 660 system system
disabled
seclabel u:r:adbd:s0

View File

@ -4,7 +4,7 @@ service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-sys
user root
group root readproc reserved_disk
socket zygote stream 660 root system
socket blastula_pool stream 660 root system
socket usap_pool_primary stream 660 root system
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on
onrestart restart audioserver

View File

@ -4,7 +4,7 @@ service zygote /system/bin/app_process32 -Xzygote /system/bin --zygote --start-s
user root
group root readproc reserved_disk
socket zygote stream 660 root system
socket blastula_pool stream 660 root system
socket usap_pool_primary stream 660 root system
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on
onrestart restart audioserver
@ -20,6 +20,6 @@ service zygote_secondary /system/bin/app_process64 -Xzygote /system/bin --zygote
user root
group root readproc reserved_disk
socket zygote_secondary stream 660 root system
socket blastula_pool_secondary stream 660 root system
socket usap_pool_secondary stream 660 root system
onrestart restart zygote
writepid /dev/cpuset/foreground/tasks

View File

@ -4,7 +4,7 @@ service zygote /system/bin/app_process64 -Xzygote /system/bin --zygote --start-s
user root
group root readproc reserved_disk
socket zygote stream 660 root system
socket blastula_pool stream 660 root system
socket usap_pool_primary stream 660 root system
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on
onrestart restart audioserver

View File

@ -4,7 +4,7 @@ service zygote /system/bin/app_process64 -Xzygote /system/bin --zygote --start-s
user root
group root readproc reserved_disk
socket zygote stream 660 root system
socket blastula_pool stream 660 root system
socket usap_pool_primary stream 660 root system
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on
onrestart restart audioserver
@ -20,6 +20,6 @@ service zygote_secondary /system/bin/app_process32 -Xzygote /system/bin --zygote
user root
group root readproc reserved_disk
socket zygote_secondary stream 660 root system
socket blastula_pool_secondary stream 660 root system
socket usap_pool_secondary stream 660 root system
onrestart restart zygote
writepid /dev/cpuset/foreground/tasks