As far as I understand you want to execute commands from within your app like the ADB command line client.
Then I would have a look at the ADB client sources to see how that communicates with the server background process. Together with the
GitHub - cstyan/adbDocumentation: Better documentation of the ADB protocol, specifically for USB uses.[
^] you should be able to communicate.
In other words:
Just use the ADB client sources in your project without the
main()
function implementation and call the functions as done by
main
.
Example for "adb devices":
clinet/main.cpp[
^]
return adb_commandline(argc - 1, const_cast<const char**>(argv + 1));
commandline.cpp[
^]
if (!strcmp(argv[0], "devices")) {
const char *listopt;
if (argc < 2) {
listopt = "";
} else if (argc == 2 && !strcmp(argv[1], "-l")) {
listopt = argv[1];
} else {
fprintf(stderr, "Usage: adb devices [-l]\n");
return 1;
}
std::string query = android::base::StringPrintf("host:%s%s", argv[0], listopt);
printf("List of devices attached\n");
return adb_query_command(query);
}
As you can see it builds a query string and calls
adb_query_command
.