ADB command history

2019-07-24 16:48发布

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.

标签: android adb
1条回答
做个烂人
2楼-- · 2019-07-24 17:38

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.

查看更多
登录 后发表回答