From 7459780d5329fc843075a9f62a14a321c49ec39e Mon Sep 17 00:00:00 2001 From: Jia Yuan Lo Date: Wed, 10 Feb 2021 17:57:28 +0800 Subject: [PATCH 1/2] android: new domain name creation method Signed-off-by: Jia Yuan Lo --- client/hostinfo_network.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/client/hostinfo_network.cpp b/client/hostinfo_network.cpp index ac60e4017ef..277586ec1e8 100644 --- a/client/hostinfo_network.cpp +++ b/client/hostinfo_network.cpp @@ -44,6 +44,10 @@ #include #endif +#ifdef ANDROID +#include // PROP_VALUE_MAX +#endif + #include "error_numbers.h" #include "file_names.h" #include "mac_address.h" @@ -58,17 +62,26 @@ #include "hostinfo.h" // get domain name and IP address of this host -// Android: if domain_name is empty, set it to android_xxxxxxxx +// Android: if domain_name is empty, set it to "brand model xxxxxxxx" +// else fallback to android_xxxxxxxx // int HOST_INFO::get_local_network_info() { safe_strcpy(ip_addr, ""); #ifdef ANDROID if (strlen(domain_name) && strcmp(domain_name, "localhost")) return 0; + char android_brand[PROP_VALUE_MAX]; + char android_model[PROP_VALUE_MAX]; char buf[256]; make_random_string("", buf); buf[8] = 0; - snprintf(domain_name, sizeof(domain_name), "android_%s", buf); + __system_property_get("ro.product.brand", android_brand); + __system_property_get("ro.product.model", android_model); + if (strlen(android_brand) && strlen(android_model)) { + snprintf(domain_name, sizeof(domain_name), "%s %s %s", android_brand, android_model, buf); + } else { + snprintf(domain_name, sizeof(domain_name), "android_%s", buf); + } return 0; #endif From 2378fb02e8bbbdc0e480c486ce02683a99deab77 Mon Sep 17 00:00:00 2001 From: Jia Yuan Lo Date: Fri, 5 Mar 2021 11:12:57 +0800 Subject: [PATCH 2/2] android: allow override hostname in cc_config.xml too --- client/hostinfo_network.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/hostinfo_network.cpp b/client/hostinfo_network.cpp index 277586ec1e8..df746f90c87 100644 --- a/client/hostinfo_network.cpp +++ b/client/hostinfo_network.cpp @@ -82,6 +82,9 @@ int HOST_INFO::get_local_network_info() { } else { snprintf(domain_name, sizeof(domain_name), "android_%s", buf); } + if (!cc_config.device_name.empty()) { + safe_strcpy(domain_name, cc_config.device_name.c_str()); + } return 0; #endif