Android emulator: editing init.rc file - android

I'm trying to learn Android internals and I've seen that boot process starts from init.rc file. I would like to know if there is a way to modify it when the emulator is off or it can be changed only while the emulator is up. In this case, I don't find a vi or similar text editor, so I must adb push the new file over the original, is it right?
Can anyone help me to find a way to edit init.rc file?

I know it might be late to answer but anyway:
If you want to replace the init.rc file by pushing a new edited file using adb you should have a root user permission to change the system from read only to read and write.
Another way is to download the source code of android x86 and then edit init.rc as you want then compile the code and build your own image of android x86. In this way you have the changes you did every time you install the image on any virtual machine.

Related

Can't boot Android device after replacing system.img

I am working on a custom android device using the i.MX53 board from NXP (formerly Freescale). I have the OS source code, various intermediate files, and the final resulting files once produced by another developer (who customized the OS, but has since left our company). I now need to modify the contents of the system partition on these devices. I have attempted to build and load a new system.img file using make_ext4fs.exe and the directory which contains the original collection of files the prior developer must have used. I believe I have created a nearly identical system image, as the one previously used. They are both ext4, 200MB.
There is a utility for this board (called MfgTool) which copies and mounts images automatically for you at the click of a button. That MfgTool successfully writes my image to the device. When I try to boot, however, it fails and just loops with the custom boot image being displayed. If I swap out the new system image and restore the prior one in this process, everything works again. So it has to simply be a matter of getting this system image built correctly.
What might be the cause? What difference in the images might cause this? Is it possible there is a signature needed, or some other kind of protection which I'm failing to account for?
Replace one of the system image service executable with a shell that dump kmsg and logcat to a file (in data partition or external storage for example) and then call the original executable. Then, boot to your previous system and collect those logs.
It turned out that my primary problem was that I need to set the mount point for the image to "system" NOT "/system" when it was created via make_ext4fs despite all documentation out there to the contrary! I figured this out by carefully reading the ASOP source: ...build\tools\releasetools\img_from_target_files.
Of note, after this hurdle, I ran it another problem where the device was acting funky. That turned out to be the result of not having any symbolic links in the image. It seems like at the least you normally have symbolic links directing your "bash" commands to the toolbox binary in system/bin. I don't know how you normally get those, but creating those links and then bundling them into the image fixed that. I suggest checking the bin directory for symbolic links if you manually create a system image like this.

Open a file to view the content through adb. (Android, Eclipse)

I have recently created some code which writes just some text to a file called 'config.txt', however; I want to be able to open this textfile and view its contents.
I have navigated to the file through the eclipse file explorer, but found you can't actually open the file from there.
Which commands do I need in order to open this file and view its contents?
I know this question has been asked before, but I have not yet found any commands which do not lead to an error message; or simply nothing happening.
Thanks for any help.
Callum
UPDATE
I think I have just answered my own question.
I did not realise that in the top left of the file explorer window, there is an icon which allows you to pull selected files from the device to your computer.
You'll probably need to download that file form your AVD to your computer via the "pull a file from the device" symbol in the top right corner first.
By the way, I asked a question about working with files in the AVD a few days ago. Unfortunately, I got no answer but there are some links in that question that might help you choose the way you prefer. So if you're interested: https://stackoverflow.com/questions/24013091/avd-android-virtual-device-sd-card-file-management
You could use adb from a command line if you are familiar with that (or willing to learn). :)
adb pull <remote> <local> would get the file similar to what you did with the GUI.
Or open an adb shell and read it from that session: cat <filename>.

"No media found". How to insert image in android

I am new to android programming so I will be really grateful if someone helps me.
I am trying to implement steganography in android but my problem is I don't know how to insert images in android. Because of which I am getting "No media found". Please help me with this.
I tried
c:> adb push c:\image1.png /sdcard/image1.png
But I get this in the Command Prompt.
failed to copy 'c:\image1.png' to 'sdcard/image1.png' : Read-only file system
I had the same problem, so in case anyone lands on this page here is how I solved it
When creating the emulator device (I use IntelliJ IDEA) - do not forget to move the radio button on SDCard option to the Size option, and specify the needed size, this way a new SDCard will be created and mounted to the emulator. In eclipse there are some command line parameters you can pass (or something else, I am not sure, since I read it only on the stackoverflow).
After that I stopped receiving the "Read-only file system" error, but I tried and tried and tried copying the files to the sdcard using:
adb push image.jpg /sdcard/image.jpg
or
adb push image.jpg /mnt/sdcard/image.jpg
but was receiving "No media found" error in my app or when I went to the gallery.
So I went to Dev Tools on the emulator applications, then to the Media Scanner. It quickly scanned the sdcard, and boom - I finally got to see my images.
Hope this helps :)
The correct directory for my emulator is mnt/sdcard. This works for me:
adb push README mnt/sdcard
Also note that you can explore directories using adb shell ls <path>, which might have tipped you off to the right path.
Edit - apparently sdcard is a symlink to mnt/sdcard and works for me as well. Using a file named image1.png is also working. Maybe there is a problematic file already located at that location for you?
Edit 2 - I think you also need to have the USB mounting option turned off when you use adb to push files. It sounds like you have this on given your comment about the gallery not finding your media.

How to restart Android emulator and preserve system data

Is it possible to preserve system data (not SD card data) on Android emulator when it is shutdown?
My specific problem is that I am trying to import a new root certificate into the /system/etc/security/cacerts.bks file, but that requires a restart, and when I do restart the emulator the file gets reverted to original state.
The file is a part of the system image, and is not a part of the files created under .avd folder.
Found a link on how to backup/modify a system image. The comments are not in English, but the commands are pretty straightforward.
I think that I once managed to do this by finding a temporary file that contained the modified /system image of the running emulator, and saving a copy which I later substituted for the initial image in an avd that I made to hack on.
Unfortunately I don't remember where I found the temp file. Playing with it at the moment the file called out in the avd seems to be changing and I can't find indication of any other candidates that are open. Perhaps what I did was copy that while the emulator was still running? At the moment dummy files I create in /system after remounting it writable seem to persist across emulator destruction and recreation without any effort on my part.
Additionally, are you sure that an actual reboot of the emulator is needed, that simply using the adb shell to 'stop' and then 'start' the android framework won't do the trick?

How to test the performance of an Android application?

How can I test an application for performance in Android? What is the support provided in Android and how do I use it?
If you want to profile your application to find performance bottlenecks you can use the traceview tool. This gives you a graphical view of performance traces of your application.
To create a trace add the following to your code where you want to start tracing:
Debug.startMethodTracing("myapp");
and then put the following when you want to stop tracing:
Debug.stopMethodTracing();
This will create a trace file call myapp.trace in the root directory of the SD Card. As it is written to the SD Card:
If you're using the emulator you'll need to add an SD card to your AVD.
You'll need to give you app permission to write the SD card by adding the following to your Manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Once the file has been created you'll need to copy it to your PC. You can do this using the adb command:
adb pull /sdcard/myapp.trace c:/my/dir/myapp.trace
Finally, start traceview giving it the full path to the trace file:
traceview c:/my/dir/myapp.trace
I did have some problems with traceview failing with OutOfMemory exceptions. I fixed this on Windows by changing the last line of traceview.bat from:
call java -Djava.ext.dirs=%javaextdirs% -Dcom.android.traceview.toolsdir= -jar %jarpath% %*
to:
call java -Xmx1g -Djava.ext.dirs=%javaextdirs% -Dcom.android.traceview.toolsdir= -jar %jarpath% %*
Adding the -Xmx1g option allows traceview to use more memory.
Also, theoretically, DDMS can get memory allocations for your program and then you can analyze the dump using profilers.
DDMS Reference.
The reason why I have theoretically in italics is that I myself have not tried doing anything such, yet.
I think traceView contains too much information, you can easily get lost.
My solution is just log the system time at three place in the code.
Before and after and center at the potiential slow code.
like binary search, next time, narrow it down step by step, then finally find the culprit code.
Another way to test is Using TruClient on Load Runner
Steps to be followed for Mobile Web are:
New VuGen Script
Mobile Protocol
Select TruClient Mobile Web
Click Create
Now you can generate scripts
Click Develop Script button
PoP up window appears to select the device
Select Actions and you can record the scripts
Steps to be followed for Native Mobile are:
New VuGen Script
Mobile Protocol
Select TruClient Native Mobile
Click Create
Now you can generate scripts
click develop script
TruClient window that plugged with Firefox appears
Click General Settings
Configure the SERVER URL PORT
If u don't know the server url port means install OS MONITOR application on your device. here you can find the ip address
Enter User Name and Password
Click done
you can record the scripts and perform your testing....
you can use load runner.,
use this link to find more about it.,
http://www.perftesting.co.uk/recording-and-performance-testing-android-applications-with-hp-loadrunner-vugen/2011/11/14/
Steps to be followed are:
Create New VuGen Script
Select Mobile Application-HTTP/HTML
Recording Options--> Select Record Emulator
Give the path to Record Emulator as D:\android\AVD Manager.exe
In the command line
-avd AVD_NAME -netspeed full -netdelay none
where AVD_Name is the name of your Device
select the working directory
click finish
Now you can perform your test.,

Categories

Resources