client: get product name in Android

We want to track the product name (e.g. "HTC One X") of Android devices.
On Android, the API to get this is Java,
so we need to do it in the GUI rather than the client.
- Add product_name field to HOST_INFO
- Add a GUI RPC for passing this info from the GUI to the client.
- Store it in client_state.xml, so that the client knows it initially.

The product name is included in scheduler RPC requests, as part of <host_info>.
TODO: add server-side support for parsing it and storing in DB.

Also: move DEVICE_STATUS out of HOST_INFO; it didn't belong there.
This commit is contained in:
David Anderson 2013-05-21 13:20:56 -07:00
parent 078087985c
commit 1a6a7128a1
8 changed files with 69 additions and 9 deletions

View File

@ -86,6 +86,7 @@ Commands:\n\
--run_benchmarks\n\
--set_gpu_mode mode duration set GPU run mode for given duration\n\
mode = always | auto | never\n\
--set_host_info product_name\n\
--set_network_mode mode duration set network mode for given duration\n\
mode = always | auto | never\n\
--set_proxy_settings\n\
@ -323,6 +324,12 @@ int main(int argc, char** argv) {
} else {
fprintf(stderr, "Unknown op %s\n", op);
}
} else if (!strcmp(cmd, "--set_host_info")) {
HOST_INFO h;
memset(&h, 0, sizeof(h));
char* pn = next_arg(argc, argv, i);
strcpy(h.product_name, pn);
retval = rpc.set_host_info(h);
} else if (!strcmp(cmd, "--set_network_mode")) {
char* op = next_arg(argc, argv, i);
double duration;

View File

@ -133,6 +133,7 @@ CLIENT_STATE::CLIENT_STATE()
disable_graphics = false;
cant_write_state_file = false;
benchmarks_running = false;
device_status_time = 0;
rec_interval_start = 0;
retry_shmem_time = 0;

View File

@ -98,6 +98,10 @@ struct CLIENT_STATE {
ACTIVE_TASK_SET active_tasks;
HOST_INFO host_info;
// the following used only on Android
DEVICE_STATUS device_status;
double device_status_time;
VERSION_INFO core_client_version;
string statefile_platform_name;
int file_xfer_giveup_period;

View File

@ -373,6 +373,26 @@ static void handle_set_gpu_mode(GUI_RPC_CONN& grc) {
grc.mfout.printf("<success/>\n");
}
static void handle_set_host_info(GUI_RPC_CONN& grc) {
while (!grc.xp.get_tag()) {
if (grc.xp.match_tag("host_info")) {
HOST_INFO hi;
int retval = hi.parse(grc.xp);
if (retval) {
grc.mfout.printf("<error>host_info parse error</error>\n");
return;
}
if (strlen(hi.product_name)) {
strcpy(gstate.host_info.product_name, hi.product_name);
}
grc.mfout.printf("<success/>\n");
gstate.set_client_state_dirty("set_host_info RPC");
return;
}
}
grc.mfout.printf("<error>Missing host_info</error>\n");
}
static void handle_set_network_mode(GUI_RPC_CONN& grc) {
double duration = 0;
bool btemp;
@ -1140,8 +1160,8 @@ static void handle_report_device_status(GUI_RPC_CONN& grc) {
if (grc.xp.match_tag("device_status")) {
int retval = d.parse(grc.xp);
if (!retval) {
gstate.host_info.device_status = d;
gstate.host_info.device_status_time = gstate.now;
gstate.device_status = d;
gstate.device_status_time = gstate.now;
grc.mfout.printf("<success/>\n");
return;
}
@ -1257,6 +1277,7 @@ GUI_RPC gui_rpcs[] = {
GUI_RPC("set_global_prefs_override", handle_set_global_prefs_override,
true, false, false),
GUI_RPC("set_gpu_mode", handle_set_gpu_mode, true, false, false),
GUI_RPC("set_host_info", handle_set_host_info, true, false, false),
GUI_RPC("set_network_mode", handle_set_network_mode, true, false, false),
GUI_RPC("set_proxy_settings", handle_set_proxy_settings, true, false, false),
GUI_RPC("set_run_mode", handle_set_run_mode, true, false, false),

View File

@ -687,6 +687,7 @@ struct RPC_CLIENT {
int file_transfer_op(FILE_TRANSFER&, const char*);
int result_op(RESULT&, const char*);
int get_host_info(HOST_INFO&);
int set_host_info(HOST_INFO&);
int quit();
int acct_mgr_info(ACCT_MGR_INFO&);
const char* mode_name(int mode);

View File

@ -2092,6 +2092,27 @@ int RPC_CLIENT::get_host_info(HOST_INFO& h) {
return ERR_XML_PARSE;
}
// set HOST_INFO fields that are easier to get in the GUI than in the client.
// Currently this is just the product name on Android,
// which uses a Java version of this function
//
int RPC_CLIENT::set_host_info(HOST_INFO& h) {
SET_LOCALE sl;
RPC rpc(this);
char buf[1024];
sprintf(buf,
"<set_host_info>\n"
" <host_info>\n"
" <product_name>%s</product_name>\n"
" </host_info>\n"
"</set_host_info>\n",
h.product_name
);
int retval = rpc.do_rpc(buf);
if (retval) return retval;
return rpc.parse_reply();
}
int RPC_CLIENT::quit() {
int retval;

View File

@ -68,11 +68,10 @@ void HOST_INFO::clear_host_info() {
strcpy(os_name, "");
strcpy(os_version, "");
strcpy(product_name, "");
strcpy(virtualbox_version, "");
have_cpu_opencl = false;
device_status_time = 0;
}
int HOST_INFO::parse(XML_PARSER& xp, bool benchmarks_only) {
@ -94,6 +93,7 @@ int HOST_INFO::parse(XML_PARSER& xp, bool benchmarks_only) {
}
if (xp.parse_double("p_calculated", p_calculated)) continue;
if (xp.parse_bool("p_vm_extensions_disabled", p_vm_extensions_disabled)) continue;
if (xp.parse_str("product_name", product_name, sizeof(product_name))) continue;
if (benchmarks_only) continue;
@ -141,7 +141,7 @@ int HOST_INFO::parse(XML_PARSER& xp, bool benchmarks_only) {
int HOST_INFO::write(
MIOFILE& out, bool include_net_info, bool include_coprocs
) {
char pv[265], pm[256], pf[1024], osn[256], osv[256];
char pv[265], pm[256], pf[1024], osn[256], osv[256], pn[256];
out.printf(
"<host_info>\n"
" <timezone>%d</timezone>\n",
@ -196,6 +196,13 @@ int HOST_INFO::write(
osn,
osv
);
if (strlen(product_name)) {
xml_escape(product_name, pn, sizeof(pn));
out.printf(
" <product_name>%s</product_name>\n",
pn
);
}
if (strlen(virtualbox_version)) {
char buf[256];
xml_escape(virtualbox_version, buf, sizeof(buf));

View File

@ -61,6 +61,8 @@ public:
char os_name[256];
char os_version[256];
char product_name[256]; // manufacturer and/or model of system
// currently used for Android devices
// the following is non-empty if VBox is installed
//
@ -71,10 +73,6 @@ public:
bool have_cpu_opencl;
OPENCL_DEVICE_PROP cpu_opencl_prop;
// the following used only on Android
DEVICE_STATUS device_status;
double device_status_time;
HOST_INFO();
int parse(XML_PARSER&, bool benchmarks_only = false);
int write(MIOFILE&, bool include_net_info, bool include_coprocs);