I'm working on building an UI application (.exe) to run on a Windows host, that should be able to
- List connected android devices.
- Write a file of exactly 512 bytes on internal memory (not sdcard). Path to write to be entered from UI.
The file to be written has to be exactly 512 bytes on internal memory, that's something which is vital for my application need. Here is how i am approaching:
- I have used Qt to code the UI and basic logic.
- The application uses adb devices to enumerate connected devices and display in the listView of the UI.
To write a file, i first create a file on disk (my PC), fill it with 512 bytes (my pre-configured contents), and then push this file onto device using adb
int DoWrite(Buffer* pBuf) { // pBuf contains preconfigured 512 byte pattern to be written to a file on device //prepare a local file char*cmdBuf = new char[512]; for (int i(0); i < 512; ++i) cmdBuf[i] = pBuf->operator[](i); ofstream myFormattedFile; if(myFormattedFile.is_open()) { //temp file creation successful pBuf->WriteFormattedDataToStream(myFormattedFile); myFormattedFile.close(); } FILE* fp = 0; fp = fopen("rawData.bin", "wb"); int temp = fwrite(cmdBuf, sizeof(char), 512, fp); fclose(fp); //push this file to device at /mnt/emmc/diagnose (or whatever the myFilePath is set to) //ADB_PATH is set to adb executable //m_filePath is set to /mnt/emmc std::string cmd = ADB_PATH + "adb push " + "C:\\Users\\MyUser\\DiagTool\\rawData.bin " + m_filePath; //Execute push command int rc = system(cmd.c_str()); delete [] cmdBuf; return 0; }
I am able to see that a file /mnt/emmc/diagnose is created. Getting adb shell, and executing ls -l on /mnt/emmc indeed shows filesize as 512!
So, here are my questions:
- The file which I'm creating locally displays following properties
Is it so that the file that i created on disk, is not actually of 512 bytes, but4KB?
So, if I use adb push, what will be the size of file created on device? 512 bytes or since it goes through OS, it will apply appropriate paddings and the actual file size won't be 512 bytes?
Is it the correct way to write to internal memory? Or is there a better approach?
I don't prefer to install any .apk on device, and interact with it using my application. But if nothing works, i can take that approach too!
Any help or pointer is appreciated...