Thursday, July 28, 2011

How to request 'super user' permission from your app?

NOTE: This blog assumes that you have installed Superuser application installed on your device! Also, I'm not responsible for any bricked devices!

Process p;
try {
    p = Runtime.getRuntime().exec("su");
}
catch(IOException e) {
    e.printStackTrace();
}

This will pop up a window from 'Superuser' application which will ask user to whether allow your app to be given 'su' permissions or not. Users can either 'Allow' or 'Deny' and also set 'Remember this option' on this window.

Hope this helps!

AdbCommandRejectedException!

Sometimes, adb goes crazy on my Win7. If I open 'ddms' (to view logcat messages), I wont see any messages at all! If I look into the 'Command Window', I see the above exception being raised in it. Apparently, the work-around this is to do the following:
  1. Un-plug the USB cable.
  2. Kill the adb-server (adb kill-server)
  3. Start the adb-server (adb start-server)
  4. Plug in the USB
 Hope this helps!

Sunday, July 24, 2011

Camera shutter sound on CM7!

Due to legal issues in some countries (see this issue) cyanogenmod doesn't support any settings for enabling/disabling camera shutter sound (It is enabled by default!). However, there's a system property which one can set in order to turn off the shutter sound. But, unfortuantely for this you need to install android SDK on your system and plug USB cable to your phone and connect it to your PC. (Also, do not forget to 'enable USB debugging'!!).
  adb shell setprop persist.camera.shutter.disable 1

NOTE:
 I'm not responsible for any damages/law-suites caused (whatsoever), by disabling the shutter sound of your phone's camera!

Tuesday, July 19, 2011

Measuring read/write BW of sdcard(s) on your android phones

I needed a quantitative way to measure the performance of the sd-card on my LG Optimus 2X. Hence I wrote the tool 'sd-speed'. Currently, this tool is supported only on linux and windows platforms. The project is hosted on github at the following location: 'git@github.com:teju85/sd-speed.git'. I have released it with the WTFPL (do What The Fuck you want to Public License).

Here are the results of running my program on my 'external sd-card', 'internal sd-card' and on 'phone memory' respectively: (Phone: LG O2X, CM7)

External sd-card
$ ./sdCardSpeedTest.sh /mnt/sdcard
NOTE: Test might take about 5-10 min depending on your sd-card speed!
      Please be patient during this time...

Evaluating write-BW...
100000000 bytes transferred in 26.371 secs (3792044 bytes/sec)
100000000 bytes transferred in 19.656 secs (5087505 bytes/sec)
100000000 bytes transferred in 20.697 secs (4831618 bytes/sec)
100000000 bytes transferred in 20.086 secs (4978592 bytes/sec)
100000000 bytes transferred in 53.975 secs (1852709 bytes/sec)
100000000 bytes transferred in 28.934 secs (3456141 bytes/sec)
Write BandWidth: 3.81448 MBps

Evaluating read-BW...
100000000 bytes transferred in 18.844 secs (5306728 bytes/sec)
100000000 bytes transferred in 17.818 secs (5612302 bytes/sec)
100000000 bytes transferred in 17.331 secs (5770007 bytes/sec)
100000000 bytes transferred in 17.301 secs (5780012 bytes/sec)
100000000 bytes transferred in 17.306 secs (5778342 bytes/sec)
100000000 bytes transferred in 17.310 secs (5777007 bytes/sec)
Read BandWidth: 5.40803 MBps

Cleaning up all the temporary files...


Internal sd-card
$ ./sdCardSpeedTest.sh /mnt/emmc
NOTE: Test might take about 5-10 min depending on your sd-card speed!
      Please be patient during this time...

Evaluating write-BW...
100000000 bytes transferred in 9.372 secs (10670081 bytes/sec)
100000000 bytes transferred in 6.579 secs (15199878 bytes/sec)
100000000 bytes transferred in 6.252 secs (15994881 bytes/sec)
100000000 bytes transferred in 6.321 secs (15820281 bytes/sec)
100000000 bytes transferred in 6.532 secs (15309246 bytes/sec)
100000000 bytes transferred in 6.516 secs (15346838 bytes/sec)
Write BandWidth: 14.0415 MBps

Evaluating read-BW...
100000000 bytes transferred in 5.168 secs (19349845 bytes/sec)
100000000 bytes transferred in 5.038 secs (19849146 bytes/sec)
100000000 bytes transferred in 4.661 secs (21454623 bytes/sec)
100000000 bytes transferred in 4.671 secs (21408691 bytes/sec)
100000000 bytes transferred in 4.694 secs (21303792 bytes/sec)
100000000 bytes transferred in 4.693 secs (21308331 bytes/sec)
Read BandWidth: 19.8165 MBps

Cleaning up all the temporary files...


Phone memory
$ ./sdCardSpeedTest.sh /data/local
NOTE: Test might take about 5-10 min depending on your sd-card speed!
      Please be patient during this time...

Evaluating write-BW...
100000000 bytes transferred in 6.876 secs (14543339 bytes/sec)
100000000 bytes transferred in 8.566 secs (11674060 bytes/sec)
100000000 bytes transferred in 8.565 secs (11675423 bytes/sec)
100000000 bytes transferred in 6.783 secs (14742739 bytes/sec)
100000000 bytes transferred in 7.617 secs (13128528 bytes/sec)
100000000 bytes transferred in 8.168 secs (12242899 bytes/sec)
Write BandWidth: 12.3989 MBps

Evaluating read-BW...
100000000 bytes transferred in 5.537 secs (18060321 bytes/sec)
100000000 bytes transferred in 5.641 secs (17727353 bytes/sec)
100000000 bytes transferred in 5.274 secs (18960940 bytes/sec)
100000000 bytes transferred in 5.275 secs (18957345 bytes/sec)
100000000 bytes transferred in 5.268 secs (18982536 bytes/sec)
100000000 bytes transferred in 5.273 secs (18964536 bytes/sec)
Read BandWidth: 17.7468 MBps

Cleaning up all the temporary files...

I have compiled these results in a tabular format for quick comparison.
Location Write BW (MBps) Read BW (MBps)
External sd-card 3.81 5.41
Internal sd-card 14.04 19.82
Phone Memory 12.40 17.75
If you find any issues with this tool, do drop-in a comment here!

Friday, July 15, 2011

How did I 'almost' brick my phone (and recovered from it)?

I use CM7 (nightly-74). When I heard that LG had released 0622 baseband version I couldn't resist to go back to stock ROM and try it out. :) And I did exactly that... However, somehow, during the update using the LG PCsuite, it said 'failed to communicate with phone' and asked me to remove battery, restart and plug in USB and start over again. When I tried that, after the LG boot-splash, I got this screen. :( And that's when I knew, I had screwed up my phone!

Then I went to modaco-forums to find that Paul had given a nice tutorial on how to flash your phone to the stock ROM (using nvflash). I successfully flashed the stock ROM. But little did I knew that worse was waiting when I would boot the phone. My baseband firmware was no more! Meaning my phone had become a wifi-tablet :(( Luckily, I found this thread in modaco-forums on how to flash baseband-firmware (using smartflash). Instructions were pretty simple and using this, at the end, I was able to get back my baseband to 0622 version :D (phewww!!)

Now, I just had to manually install CWM (ClockWorkrecovery Mod) version 4.0.0.5 and restore my CM7 (nightly-64) from the nandroid backups. Now I'm enjoying the nightly-74 on CM7 with the latest baseband firmware!

Wednesday, July 13, 2011

Manually installing clockworkmod (CWM) recovery on LG O2X

Strange as it seems, on my phone, 'ROM Manager' does not allow an upgrade to the CWM after 3.0.2.8. :( So, I wanted to install it manually. The steps I followed were from the one given by our very own Paul on modaco forums. However, I wanted to understand what exactly those 'install-clockworkmod-windows.bat' kind of scripts did. Here it is... (I used the windows batch file in order to install CWM)


# copy over the psneuter binary to your phone
> adb-windows push psneuter /data/local/psneuter

# give this binary on your phone, the executable permission> adb-windows shell chmod 4755 /data/local/psneuter

# run this exe, (psneuter exploit to gain root access)
# you wouldn't need it if your phone is already rooted(?)
> adb-windows shell /data/local/psneuter

# wait the device to come online (as the above exploit would have killed the adbd)
> adb-windows wait-for-device

# copy the CWM image over to your phone> adb-windows push clockworkmod.img /data/local/
 
# place this image over to the appropriate location?
> adb-windows shell dd if=/data/local/clockworkmod.img of=/dev/block/mmcblk0p7

Clockworkrecoverymod v3.0.2.8 bug! :(

Seems like this version does not properly restore the nandroid backups. I tried to restore using this version and the restore succeeded. However, during the bootup, (LG O2X) it used to hang on the second LG screen! The solution is to upgrade it to later version (latest verion 4.0.0.5) seems to work properly. I'll write a blog on how to manually upgrade CWM sooner...