I'm looking at android's source code and i'm trying to add file to the data partition in build time. For that i need to add file to the userdata partition.
Moreover, i need to find where the the permissions for the files in the data directory are determined, in order to give the file the permissions i want.
For that i need to see where in the source code is the userdata partition mounted, because i guess that the permissions are given there as well.
I've looked at init.rc but the only thing i saw is:
mkdir /data 0771 system system
But there doesn't seem to be any mount for user data..
Does someone knows where does this happen?
You can just use PRODUCT_COPY_FILES for example:
PRODUCT_COPY_FILES += device/repo/your_file.so:data/folder/your_file.so
...plenty of examples here, in my device repo... just copy it to data though, instead of system: https://github.com/sudosurootdev/device_lge_g2-common/blob/kk44/g2.mk
More examples: https://github.com/sudosurootdev/vendor_lge/blob/kk44/ls980/ls980-vendor-blobs.mk
NOTE: Just don't add it to an Android.mk file. Use another *.mk file either under an Android.mk which calls all subdir makefiles or call the file specifically from another:
include device/repo/your_file.mk
Now, if it needs it's own directory under data, you will want to add it in the init.rc like you posted.
Related
I have few message on device boot about missing files or directories:
[ 3.052514] init: write_file: Unable to open '/proc/cpu/alignment': No such file or directory
[ 4.931333] init: write_file: Unable to open '/proc/sys/vm/min_free_order_shift': No such file or directory
I've founded out that init process tries to write values to these files via command
write /proc/cpu/alignment 4
Documentation says that write can create new file if it doesn't exist. But in result I can't find this file. Seams it wasn't created. Even more, there is no folder which should contain this file.
So can write command create a folder if it doesn't exist?
Filesystem under '/proc' is special in sence that all of its files are "created" by the kernel, and user cannot create files there.
This is pseudo-filesystem: its files are not stored on hard disk, but exist only in RAM and reflect system properties. Writing into this files changes properties in a special way. You cannot create new properties there.
I'm trying to create a partition called "subdata" under "/data". But it's failing.
The steps I tried and the failure results are mentioned below.
File dir =new File(/data/subdata/");
boolean success = dir.mkdir();
Here, the "success" value is found "false".
File dir= context.getDir("/data/subdata",Context.MODE_WORLD_READABLE);
Here, I get "java.lang.IllegalArgumentException: File app_/data/subdata/ contains a path separator"
Please, help me in creating this subfolder under /data/ partition.
I solved my need in the below manner.
As I mentioned in the question that, if I create the sub folder manually, I'm able to read and write to that subfolder in the /data.
So, I created this subfolder through init.rc (as I mentioned, I have the build code also). As I'm more fluent in Linux than in Android, I fixed it through init.rc. Now I'm able to read/write to that folder through my android code.
i'm tring to move an apk files from /data/app/ to /system/app. I wrote this code
process = Runtime.getRuntime().exec("mv "+path+" "+"/system/app/);
Where path return sometime like /data/app/com.package.name-1.apk. This code doesn't work because the apk is not moved. Why? Where is the problem?
In order to modify the contents of /system you need root permission. Root your device first and then you can move the file as follows:
process = Runtime.getRuntime().exec("sudo mv "+path+" "+"/system/app/);
Don't forget to set the appropriate attributes using chmod after moving.
I'm trying to test the Expansion Pack Files (OBB) In Android following the guide here:
http://developer.android.com/google/play/expansion-files.html
I'm in the step where I need to test my app on my Nexus 4.
I generated my .obb file with jobb and adb-pushed it in the device in this location:
/mnt/shell/emulated/0/Android/obb/my.package/main.1.my.package.obb
When the app run it doesn't find the file.
Method:
Helpers.doesFileExist(context, fileName, xf.mFileSize, false)
return false for my file.
I debugged and found out it is looking for the file in:
/storage/emulated/0/Android/obb/my.package/main.1.my.package.obb
Specifically this is the path returned by:
Helpers.generateSaveFileName(c, fileName)
The /storage/emulated/0, returned by Environment.getExternalStorageDirectory() doesn't exist browsing the device with adb shell.
But it DOES at runtime, inside the app, I also checked what it contains: it contains almost the same things I found in /mnt/shell/emulated/0, it contains the Android/obb dir, which is empty.
How I found out the path /mnt/shell/emulated/0/Android/obb/my.package/main.1.my.package.obb where I placed my obb file:
$ adb shell
$ ls -ld sdcard
lrwxrwxrwx root root 2013-10-16 17:34 sdcard -> /storage/emulated/legacy
$ ls -ld /storage/emulated/legacy
lrwxrwxrwx root root 2013-10-16 17:34 legacy -> /mnt/shell/emulated/0
And inside that I already found the Android/obb directory, empty.
So the question is: where should I put my obb file for it to be in the right position at runtime?
I did everything said there:
created a draft application in the Market to get the public key
generated a random array of 20 byte (salt)
integrated play_licensing/library and play_apk_expansion/download_library
wrote my Service / Receiver
did the check using the Helpers etc.. exactly like the documentation say.
I suppose everything works but I can't just yet release on Play Store! I need to test locally and I'll have the need to change my obb file pretty often in this initial phase of development.
I can't test on the Emulator because I use 3D and device camera.
Since Android 4.2 multi users support have been added.
To support that Android mount an emulated disk for each users acting as a sandbox layer around the actual filesystem: this let Android handle gracefully either sharing of files between users either personal files.
Long story short:
/storage/emulated
is the emulated filesystem.
if you enter that directory from adb shell you may see a
/storage/emulated/obb
directory. Sometimes it doesn't show up, for some reason (see below for what to do if this happen)
It's not in /Android/obb but that's the right directory where to place your app package / obb file!
If you don't see that directory try looking in:
/mnt/shell/emulated/obb
You should be able to put your file there.
It will be correctly picked up at runtime ending at the
/storage/emulated/0/Android/obb/my.package/main.1.my.package.obb
path.
I think the Android documentation should explain this.
(I answer my own question because I found out how to solve it while writing it.)
For me the correct location is : mnt/sdcard/Android/obb/nameofyourpackage/
NOT "/mnt/shell"
Hi I need to copy/move the contents of data/tombstones to sdcard/tombstones
I'm using the command below:
mv data/tombstones /sdcard/tombstones
"failed on 'tombstones' - Cross-device link"
but I'm getting above error.
You have a SANE VERSION of the mv command
paraphrasing a few bits from lbcoder from xda and darkxuser from androidforums
"failed on 'tombstones' - Cross-device link"
It means that you can't create a hard link on one device (filesystem) that refers to a file on a different filesystem.
This is an age-old unix thing. You can NOT move a file across a filesystem using most implementations of mv. mv is not made to copy data from device to device, it simply changes a file's location within a partition. Since /data and /sdcard are different partitions, it's failing.
Consider yourself fortunate that you have a SANE VERSION of the mv command that doesn't try anyway -- some old versions will actually TRY to do this, which will result in a hard link that points to NOTHING, and the original data being INACCESSIBLE.
The mv command does NOT MOVE THE DATA!!! It moves the HARDLINK TO
THE DATA.
If you want to move the file to a different filesystem, you need to use the "cp" command. Copy the file to create a SECOND COPY of it on a different filesystem, and then DELETE the OLD one with the "rm" command.
A simple move command:
#!/bin/bash
dd if="$1" of="$2"
rm -f "$1"
You will note that the "cp" command returns true or false depending on the successful completion of the copy, therefore the original will only be removed IF the file copied successfully.
OR
#!/bin/bash
cat data/tombstones > sdcard/tombstones
rm data/tombstones
These script can be copied into some place referenced by the PATH variable and set executable.
Different Interface
If you need a different interface from adb you may move files using the FileExplorer in DDMS View.
Side note:
You can move a file into a folder when:
You're root;
It is your app directory;
You've used chmod from adb or elsewhere to change permissions
Basically you don't have permission to access /data/tombstones in a production version .
It seems we have to 'root' the device first.
But I failed to root my Samsung S4 which is using Android 4.3