ADB command history

2019-07-24 17:29发布

问题:

I need ADB command history similar to bash history. I need a history file to be created in the Android phone.

Is there any such functionality?

If not, can any one point me to the code in ADBD where it receives the commands form the desktop?

I can implement the same.

I tried enabling shell history on Android, but it does not work for the commands invoked by ADB.

回答1:

I changed the code in ADBD to implement the functionality. Modified file: system/core/adb/shell_service.cpp

bool Subprocess::ForkAndExec(std::string* error) { ----------- /* Writing the command to history file just before it is executed. */ addToHistory(command_.c_str()); execle(_PATH_BSHELL, _PATH_BSHELL, "-c", command_.c_str(), nullptr, cenv.data()); ----------- }

void addToHistory(const char * cmd) {

    FILE *fp = fopen("/data/adb_history.txt", "a");

    if(NULL == fp)
    {
            printf("ERROR\n");
            return;
    }

    fwrite(cmd, strlen(cmd), 1, fp); 
    fwrite("\n", 1, 1, fp); 
    fclose(fp);
    return;

}

For now, it is working in superuser mode only.



标签: android adb