My Project runs C++ test cases on Android devices. An exectuable gets generated and along with that, couple of shared object files also gets copied over to the device and the executable is then run. Till now, all those data were being copied over to /data/local/tmp folder. After the test cases are run, the content from /data/local/tmp is deleted using adb shell command. With Pixel 2 devices, I am able to copy the exe and shared object files to the tmp folder, but unable to delete them once the test cases are completed. I tried using /data/local/temp folder, but I am unable to push files to that folder. Tried using /sdcard but it does not allow the exe files to be executed. I am clueless as to which specific directory I should be using to run my native test cases on Pixel 2 devices. Does anyone has any pointers? Please help.
if you create files from adb, uid:gid is set to 2000:2000 and permissions of /data/local/tmp is 0771, this means you always can remove your own files. There is no other location for this, you must have messed with permissions
adb shell
touch /data/local/tmp/my-file
ls -an /data/local/tmp
rm /data/local/tmp/my-file
Related
I am trying to rsync a directory from my Linux Mint 20.3 machine to my Pixel 6 using the following command:
rsync -hvr --progress --omit-dir-times --no-perms --inplace /linux_dir/ /run/user/*/gvfs/*/Internal\ shared\ storage/android_dir/
The initial file copy proceeds as I expect; I can see and open the files on my phone. However, if I run the command again, it proceeds to re-copy every file over again, seemingly without taking into account the files that already exist on the phone. Any idea why that may be?
Your problem lies in the use of "--omit-dir-times".
Basic uncomplicated rsync needs size and time for comparison.
If unable to match both (you aren't providing the time), rsync deems all directories to be copied, and by implication, the contents of those directories.
I am developing an application using ionic framework.
The app creates files (*.json) and stores them in /data/user/0/ when i verify whether they exist or not, the result was true which means the files exist in the mentioned directory and I can access and modify their content without problem, but when I check the directory with a file manager or from the computer, no result, the directory is empty.
Could someone tell me what should I do?
use adb to copy the file. Even if it's in root dir, u should have access to it via adb.
Do adb pull data/user/0/filename.json path_on_ur_comp.json.
this will copy the file to the directory you define in the 2nd parameter.
// EDIT:
adb is part of the Android SDK, stands for Android Debug Bridge.
You can use this for MANY MANY different reason but of course, the "main" reason is to debug Android devices. You can use it to transfer files in your case.
In Windows, it's located here:
C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools\adb
In Mac, it's lcoated here:
/Users/USERNAME/Library/Android/sdk/platform-tools/adb
Depending on which OS you use, open that either with Terminal (Mac) or Command Prompt (Windows).
Once you do that, run the following command:
For Mac:
adb pull data/user/0/filename.json /Users/USERNAME/Desktop/somefile.json
For Windows:
adb pull data/user/0/filename.json c:\Users\USERNAME\Desktop\somefile.json
This will copy the file and put it on your desktop
I pulled out a file from the android sdcard using adb and it seems it goes to c:\documents and settings\userName by default. I don't know how it got set to this folder since this is not where adb is installed, but probably has got something to do with the fact that both the workspace and .android folders are located here. How do I change this default location for pull command of adb?
The default directory for adb pull or adb push seems to be the current directory (aka . ).
If you issue a command such as the following, not specifying the target directory
adb pull /boot.txt
the file (provided it exists) will be copied to the current directory.
Windows users:
Take notice of the following: If you are using Windows (Vista or newer), chances are that if the current directory requires elevated privileges to write on, Windows will silently replicate the directory structure of your current directory in a special folder called VirtualStore and will copy your files in it.
The full path for VirtualStore is: %LOCALAPPDATA%\VirtualStore, which most likely will translate into C:\Users\<account_name>\AppData\Local\VirtualStore.
So, in the following scenario,
C:\> cd "C:\Program Files (x86)\MyCustomADBInstallLocation"
C:\Program Files (x86)\MyCustomADBInstallLocation> adb pull /boot.txt
your file boot.txt will end up in this folder
C:\Users\<account_name>\AppData\Local\VirtualStore\Program Files (x86)\MyCustomADBInstallLocation\
you can mention the destination location for adb push/pull, see example:-
adb push a.txt /data/local
adb pull /data/local/a.txt .
. means present directory.
or
adb pull /data/local/a.txt C:\
Hope this helps.
i'm using linux, and noticed that if i opened the terminal as root, its opened # home. when i pull items, it dumps to that repository, meaning to my "home" directory. will try opening terminal in a different folder and running adb pull from there to see if that makes the files dump to the folder terminal is opened in.
I am making one app on Android and I have no idea what is doing one file which is installed after app installation. This file is quite big (this is about this same size as installed apk - even after uninstall ~ 5MB) so this is the reason of my question.
he file is set in data/local/tmp/'name of my apk'.apk
What is it and when it is deleted, because when I'm testing my app on emulator and uninstall it then it still exists.
EDIT AND ANSWERS:
I am not sure of my app is using tmp files. The only file or resource my app is using is movie placed in resources folder which is around 5MB. Deleting this file after app uninstall brings back free space. Before uninstall no. But I want to have deleted it melodramatically or not created at all because this file makes me app 2 times bigger.
The files in there are temporary files and you can safely delete them.
For instance, these are created when you:
Install an APK trought the command line with adb install (the temporary file will have the same name as the original file);
Install / Run an application through Android Studio (the temporary file will have the application package name).
To easily list all the temporary files, you can use the following command:
adb shell ls /data/local/tmp
To remove all of them, you can just use the following command:
adb shell rm /data/local/tmp/*
The .apk is your application. You'd be Sad if Android deleted it behind your back :)
http://developer.android.com/guide/developing/building/index.html#detailed-build
http://www.ibm.com/developerworks/xml/library/x-androidstorage/index.html
This file is the uploaded apk on emulator. Like normal file upload on device.
I have created a directory in my app's internal storage (/data/data/com.my_app) and gave global read/write permissions to the directory via the method
context.getDir(DATA_DIR_NAME, Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
Through my app, I verified that the linux file permissions are correct:
drw-rw-rw- app_71 app_71 2010-11-16 18:38 app_data
And I was able to read/write files in-to/out-of the directory app_data just fine. However, one of my developers suddenly wasn't able to write to the directory anymore. Our application has trouble accessing the directory on his device as well.
The strange thing is that the file permission for the directory is still the same. We can't do any sort of writes to the directory, and we can't read any files within the directory anymore either (the files were given global rw permission previously).
The only thing we can do is adb shell ls /data/data/my_app/app_data to see our list of files. Doing adb shell ls -l /data/data/my_app/app_data strangely doesn't return anything. And we can't CD into the directory either.
Does anyone have any pointer on what the problem is or how to solve this? We are at our wit's end.
Much appreciated.
Directories need to have the execute (X) bit set to be able to access the contents of the directory. I don't know the android modes, but look for MODE_WORLD_EXECUTABLE and see if you can set that.
Basically, you need mode 0777 (rwxrwxrwx) for a directory to be globally accessed with all permissions.
The reason ls works is that you have permission to read the filenames in the directory. ls -l does not work, because you cannot access the files in the directory to get the metadata that -l will print.