I get a trouble when learning android Data-Persistence.
I changed the daenter image description hereta/data/com.flexible.filepersistencetest/files/data permission to 777. But I still can't pull it to my PC.
when I try to delete Nexus_5_API_24.avd 's permission of Read-Only, the Read-Only will be back.
It really exaust me.
Any advice is ok, thank you very much!
change file permissions.
C:\Android\sdk\platform-tools> adb shell
generic_x86:/ $ su
generic_x86_64:/ # chmod -R 777 /data
generic_x86_64:/ # exit
run the below commands under the terminal in Android studio integration.
C:\Android\sdk\platform-tools> adb shell
generic_x86:/ $
generic_x86:/ $ exit
$ adb root
restarting adbd as root
$ adb shell
generic_x86:/ # exit
open cmd windows.
C:\Android\sdk\platform-tools> adb pull /data/data/xxxx C:\Android\sdk\platform-tools
or use "pull" button
Related
I wanted to get database file from the emulator. So, I tried to change the permission of package folder using adb shell. When I use the below command:
adb shell su -c chmod 777 /data/data/com.mypackage.test
It always returns:
Chmod: need 2 arguments
I have changed permission some days ago using above command. But recently I'm always getting the above warning. I have searched a lot and found large information regarding using above command but no one mentioned about this warning issue.
I have overcome this issue instead of running adb shell su -c "chmod 777 /data", I run the adb shell first and then the following command : su -c "chmod 777 /data".
I have overcome this issue : adb shell su -c 'chmod 777 /data/data/com.mypackage.test'
I know there are quite a few question like this around but none of them really seems to work for me.
I am writing a program that automatically updates and installs itself, however to install the update it requires user confirmation but I do not want this as the device I will deploy on will never be physically used by anyone. So to try work around this I want to root the device and use a runtime command in the code to get it to just install.
To test this out I want to try it on the (AVD) emulator first however it (obviously) needs to be rooted. So how would i go about this?
I have tried commands in the adb shell (and out of it with the adb shell) like:
mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system
push su /system/xbin/su
chmod 06755 /system
chmod 06755 /system/xbin/su
and a few others I can't find again at this moment but they will always give me errors such as cannot stat 'su' and stuff like that (will edit if i can find the commands and recreate again) or they just don't say anything and it doesn't appear to work.
If it helps i'm using xamarin in visual studio.
When working with android emulators, just do:
adb.exe root - restart adbd with root permissions
adb.exe unroot - restart adbd without root permissions
You can find adb.exe at: android_sdk\platform-tools\
You can confirm if the device is rooted by doing:
adb.exe shell
Inside the shell type: whoami. Then type exit to exit the shell
Example
P:\Android\sdk\platform-tools>adb.exe shell
generic_x86:/ $ whoami
shell
generic_x86:/ $ exit
P:\Android\sdk\platform-tools>adb.exe root
P:\Android\sdk\platform-tools>adb.exe shell
generic_x86:/ # whoami
root
generic_x86:/ # exit
P:\Android\sdk\platform-tools>adb.exe unroot
P:\Android\sdk\platform-tools>adb.exe shell
generic_x86:/ $ whoami
shell
generic_x86:/ $ exit
You can use https://www.genymotion.com/. All devices created are rooted by default. For example start a device then type adb shell command. It will open a rooted shell.
i am trying to pull db from my app but i keep getting this error in eclipse->DDMS->FileExplorer
[2014-08-07 12:53:03 - ddms] transfer error: Permission denied
[2014-08-07 12:53:03] Failed to pull selection: Permission denied
i tried to do it from CMD with this command
C:\Android\sdk\platform-tools>adb -d shell
shell#android:/ $ run-as com.iqpandroid
run-as com.iqpandroid
run-as: Package 'com.iqpandroid' has corrupt installation
as u can see the message that installation has currupt installation.. can somebody help?
Execute this command from terminal:
adb root - restarts the adb daemon with root permissions
As far as I am aware you will need to have root access.
From terminal:
adb shell
su
chmod -R 777 /data/data/com.your.package
Working on a root script for the Nexus 4 with the latest stock rom .img for google (occam) and I have the following code snippet:
./adb wait-for-device
echo "remounting system"
./adb shell "mount -o remount,rw /system"
./adb push su /system/bin/
echo "pushing super user"
./adb push Superuser.apk /system/app/
echo "pushing busybox"
./adb push busybox /system/xbin/
./adb shell "chmod 06755 /system/bin/su"
./adb shell "chmod 0644 /system/app/Superuser.apk"
./adb shell "chmod 04755 /system/xbin/busybox"
./adb shell "cd /system/xbin"
./adb shell "busybox --install /system/xbin/"
I keep getting the error
mount: Operation not permitted
failed to copy 'su' to '/system/bin//su': Read-only file system
pushing super user
failed to copy 'Superuser.apk' to '/system/app//Superuser.apk': Read-only file system
pushing busybox
failed to copy 'busybox' to '/system/xbin//busybox': Read-only file system
Unable to chmod /system/bin/su: No such file or directory
Unable to chmod /system/app/Superuser.apk: No such file or directory
Unable to chmod /system/xbin/busybox: No such file or directory
/system/bin/sh: busybox: not found
I've tried using multiple methods of obtaining r/w access, but nothing seems to be working. I have to automate this process due to the fact that other people will use the script so it needs to be automation friendly, but I just can't figure this out.
I've also tried the
#su
#mount
#mount | grep system
followed by inputting the partition with the system mount and changing it to r/w access, but that also hasn't worked.
Really frustrated at this point. Can anyone help?
It gives the error because you aren't root. The system partition is mounted read-only. You can try to push the binary to /data/local/tmp. Then you can make su executable and eventual run it. But it doesn't mean you can have root. To become root you need to push an exploit like psneuter to /data/local/tmp and run it. It crashes the shell and reopen a new one with root rights. Then you can remount the system-partition read-write and install su.
Try the commands below
adb shell "su -c mount -o remount,rw /system"
adb shell "su -c chmod 06755 /system/bin/su"
and so on.
Can anyone tell me, is it possible to use the ADB to pull and push a database from an app, without root privileges on the phone?
For example, I know the location on my rooted magic and dream is:
/data/data/com.xxxx.xxxx/databases/xxxx
I know that you can use ADB without root, but when trying to use the shell - you can't view that location without root privaliges. But I have been told you can use push and pull if you know the file you want?
Basically I want to pull a database from MY app on a non rooted phone modify it and push it back on.
Only trouble I have is, the two phones I have are both root and I don't have access to a non root one to try it out.
While Nilhcem's answer didn't work for me, it lead me in the right direction (for that I upvoted) and I now have a working solution.
Old answer that may not work with newer versions of Android:
#Transfer file from app databases directory to PC
adb shell
$ run-as package.name
$ cd ./databases/
$ ls -l #Find the current permissions - r=4, w=2, x=1
$ chmod 666 ./dbname.db
$ exit
$ exit
adb pull /data/data/package.name/databases/dbname.db ~/Desktop/
#Transfer file from PC to app databases directory (requires the above permission change)
adb push ~/Desktop/dbname.db /data/data/package.name/databases/dbname.db
adb shell
$ run-as package.name
$ chmod 660 ./databases/dbname.db #Restore original permissions
$ exit
$ exit
Alternate method using external storage (confirmed to work with 6.0.1):
#Transfer file from app databases directory to external storage
adb shell
$ run-as package.name
$ cp ./databases/dbname.db /sdcard/
$ exit
$ exit
#Transfer file from external storage to app databases directory
adb shell
$ run-as package.name
$ cp /sdcard/dbname.db ./databases/
$ exit
$ exit
A quick workaround is to use the run-as command to copy the database in a folder where you can have access, such as /sdcard and then, do a normal adb pull
adb shell
$ run-as package.name cp /data/data/package.name/dbname.db /sdcard/
$ exit
adb pull /sdcard/dbname.db
More information on the run-as command here
Note that the run-as command is available since API level 8 (Android 2.2) and can only be used if the application is debbugable.
On OxygenOS (based on Android 5.2) I've combined the two solutions provided by Pilot_51.
First, I used run-as to gain access to /data/data/package.name/databases, but from here I wasn't able to copy directly to /sdcard/ so I changed the permissions of the file. After that, I exited from run-as mode and used cp to copy the file in /sdcard/ storage. Finally, I was able to use adb pull
$ adb -s <DEVICE_ID> shell
$ run-as package.name
$ chmod 666 databases/dbname.db
$ exit
$ cp /data/data/package.name/databases/dbname.db /sdcard/dbname.db
$ exit
$ adb pull /sdcard/dbname.db ./dbname.db
We set the file permissions to readable for all users from within the app.
if (BuildConfig.DEBUG)
{
new File(mDB.getPath()).setReadable(true, false);
}
Then just pull the .db off with adb normally.
adb -d pull //data/data/xxxxx/databases/xxxxx.db .
NOTE: I've discovered that this needs to be done each time the database file is opened, for example in onCreate as well as the constructor of your SQLiteOpenHelper wrapper (when your database is not null) or perhaps onOpen. If only in onCreate, then the next time you run your app and the .db already exists, for some reason the permissions have been changed back. This might have something to do with how Android manages its data.
if you want to push db file into the application
first of all, place "file.db" under "/storage/emulated/0/" because of permission issue. then you should pretend as application to access data folder.
adb shell
$ run-as com.package.name
:/data/data/com.package.name $ cp /storage/emulated/0/file.db /data/data/com.package.name/databases/
it copies the file.db that in main folder to databases.