Monday, March 11, 2013

Android memory corruption

Gotta know this one http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android/2299813#2299813

Friday, January 25, 2013

Start call settings with newer Android

Newer Android remove the access to call settings app.  It can launched with this


adb shell am start -a com.android.phone.CallFeaturesSetting.ADD_VOICEMAIL

Wednesday, August 5, 2009

enable wifi ad hoc on Andrid

Android comes with wifi ad hoc disable by default.  I have always wanted to use my Android the cheap way.  I do not have data plan.  Typically I am either at home or work.  My android is configured to connect to my home router via wifi.  We can not have a wifi router at work.  So a peer to peer connection would let my pc tether for my Android phone's internet connection.  And today I found it amazingly easy to do.

1.  edit /system/etc/wifi/tiwlan.ini

adb pull /system/etc/wifi/tiwlan.ini .
vi tiwlan.ini
find line "WiFiAdhoc = 0" and make the 0 1.  This would probably already be ok.  But somewhere I copied and pasted 2 more lines below, so now that block looks like

WiFiAdhoc = 1
dot11DesiredSSID = YOUR_SSID
dot11DesiredBSSType = 0
....

2  edit /data/misc/wifi/wpa_supplicant.conf 
This is for security.  Of course if you want to use it every day.
adb pull /data/misc/wifi/wpa_supplicant.conf .
vi wpa_supplicant.conf
if it is and empty file, paste in below and modify your ssid and wep_key0
update_config=0
ctrl_interface=tiwlan0
eapol_version=2
ap_scan=2
fast_reauth=1
network={
    ssid="YOUR_SSID"
    scan_ssid=0
    mode=1
    key_mgmt=NONE
    group=WEP104
    auth_alg=SHARED
    wep_key0="13alphanumeri"
}

if it not an empty, you must already have a ap connection configuration.  Just paste in the network clause.  Then it seems one or both of the below 2 lines is a must have to have security turned on.  
eapol_version=2
ap_scan=2

Then your pc or linux will be able to find the ssid specifed in the network clause as soon as wifi is turned on on Android.  Connect and enter the preset wep_key.  Make sure the pc or linux is configured to share internet connection.

Pretty sweet.

Thursday, May 14, 2009

command line launching Android app

am start -a android.intent.action.MAIN -n com.android.settings/.Settings

Sunday, February 22, 2009

PAN and SSH Android phone

Again, internet is good stuff. Without it, none of this would be this easy.

To do anything below, the phone must be rootable. G1 dev phone, or hacked G1 commercial. There is hacking info all over the web. Maybe someday I will come back and sort it up and place it here.

Enabling PAN on Android.

Android does not come with PAN enabled. The default Bluetooth profiles are Handsfree and Headset. When tried with "pand" command, error return says "Failed to open control socket: Protocol not supported". This means it needs bnep.ko module.

To enable PAN, I needed to build bnep.ko kernel module and insmod it on the device. Here is a very good tutorial. I pretty much followed it.

But it did work for me initially. When loading the ko module, it told me "insmod: init_module 'bnep.ko' failed (Exec format error)". Dmesg gets "bnep: version magic '2.6.27-01843-gfea26b0 preempt mod_unload modversions ARMv6 ' should be '2.6.25-01843-gfea26b0 preempt mod_unload ARMv6 '". Ahh! So the version of my kernel source is newer than the one in my phone. Then I went off to www.kernel.org and downloaded version 2.6.25, and repeated the same work, config, make modules, adb push bnep.ko, insmod. Dallah!

Then set up a pand NAP
# pand -s -r NAP

Now if I see NAP in my service list
# sdptool browse local
...
Service Name: Network Access Point
Service Description: BlueZ PAN Service
Service Provider: BlueZ PAN
Service RecHandle: 0x10002
Service Class ID List:
"Network Access Point" (0x1116)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 15
"BNEP" (0x000f)
Version: 0x0100
SEQ16: 800 806
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Network Access Point" (0x1116)
Version: 0x0100

A simple "pand -c
" from my computer, I had 2 devices connected via PAN. Of course I had to assign them IP address manually. A little tricky with Android is that, ifconfig does not print anything. But I figured out that before they could ping each other, I had to explicitly
# ifconfig bnep0 up

SSH from PAN'ed Android phone
Natually, I wanted to try ssh once the 2 devices can see each other on the same subnet. But here is what I get
# ssh ktang@192.168.11.4
ssh: Warning: Reading the random source seems to have blocked.
If you experience problems, you probably need to find a better entropy source.

Internet never fails me. Here is some good info. Smart people everywhere. Briefly, this is the cure.
# ls /dev/random
/dev/random
# ls /dev/urandom
/dev/urandom
# mv /dev/random /dev/random.bk
# ln -s /dev/urandom /dev/random
# ssh ktang@192.168.11.4
ssh: Warning: failed creating //.ssh: Read-only file system

Host '192.168.11.4' is not in the trusted hosts file.
(fingerprint md5 ..................................)
Do you want to continue connecting? (y/n)
y
Password:
Last login: Sun Feb 22 02:08:36 2009 from tanglin
TangMac:~ ktang$

Made me happy!

Sunday, February 15, 2009

enabling ip forward

ktang@TangLin:~$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

ktang@TangLin:~$ sudo vi /etc/sysctl.conf

ktang@TangLin:~$ sudo sysctl -p /etc/sysctl.conf
kernel.printk = 4 4 1 7
kernel.maps_protect = 1
fs.inotify.max_user_watches = 524288
vm.mmap_min_addr = 65536
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.ip_forward = 1

ktang@TangLin:~$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

Here is a great site of cheap sheet

Wednesday, January 21, 2009

Installing Adobe Flash Player 10 on Ubuntu Hardy

Due to the previously mentioned 2 GB limit with flash player 9, I attempted to upgrade Hardy with Adobe provided player 10 deb.

sudo apt-get install remove --purge flashplugin-nonfree libflashsupport
dpkg -i install_flash_player_10_linux.deb

But it did not work. After all the googling fun, this link was helpful. Briefly this is the key:

sudo ln -s /usr/lib/libssl3.so.1d /usr/lib/libssl3.so
sudo ln -s /usr/lib/libnss3.so.1d /usr/lib/libnss3.so
sudo ln -s /usr/lib/libnspr4.so.0d /usr/lib/libnspr4.so

sudo ln -s /usr/lib/libsmime3.so.1d /usr/lib/libsmime3.so
sudo ln -s /usr/lib/libplds4.so.0d /usr/lib/libplds4.so
sudo ln -s /usr/lib/libplc4.so.0d /usr/lib/libplc4.so

Yeah, it worked, for me at least.

Another overflow, or it looks like

Had a few large mp4 files unable to play on adobe flash player. The threshold happens to be 2 GB (overflow of a signed integer, it must be). Here is a bullet from Adobe Flash Player 9 release notes

  • Flash Player cannot progressively load files that are greater than 2Gb (210223)
I hope my guess was wrong. It would have been a low bug then.

Thursday, January 8, 2009

MP4Box - Out Of Memory

It wasn't this easy to find out.  It all started from when I was trying to convert my son's favorite dinosaur DVD's to h264 files.  I have a script, that calls for ffmpeg, feeding in parameters, and have the h264 files generated to the directories I want, then run MP4Box to hint them.  There were a dozen of them.  Encoding h264 isn't anything for the impatient.  So I left it running.  Day after day, there were some new h264 file created.  Then all done, finally.  But I found 2 largest VOB files (4.4 GB and 4.3 GB) ended up to be converted to mp4 files of 68 bytes each.  Bummer!

Of course I first thought it was ffmpeg, that it might have overflow problem.  Long story short, it was not.  I suddenly remembered that there was MP4Box hinting invoked at the end of the script.  Then I broke it into 2 steps, or course, ffmpeg got me a good unhinted mp4 file.  While I tried to run MP4Box on it, it gave me 

[iso file] Read Box "..A." failed (Out Of Memory)

I was using MP4Box from gpac 0.4.4.  Upgrading to gpac 0.4.5 fixed it.  What was unbelievable was 0.4.5 wasn't out until Dec 2008.  And until then, no one had such problem?  MP4Box isn't anything new to world.  Neither is DVD.  How come the fix isn't out until a month ago?  Weird.

A little side story on this.  When I first upgraded it, I did not see the upgrade fixing the problem.  What happened was that I made a build with the new source code, and ran the new MP4Box locally.  It did not work because it was pulling the libgpac.so from system directory, which was still the older version, because I did not "make install" the new version yet.  Seeing it not working, I was so pumped up to fix it myself.  So I loaded up ddd debugger.  That was where I found out it was using the libgpac.so of the older version.  So that took me no time.  Just that I did not get to have the sense of accomplishment.  But I am happy it is working now.

Monday, November 24, 2008

burn cd / dvd

CD --

mkisofs -f -U -iso-level 4 -R -x unused_dir 59m/59mh | cdrecord -v -pad speed=1 dev='/dev/scd1' -

In this command, "-f" makes it follow symbolic link. 59m/59mh is the src dir. What will be burnt into the CD everything under this dir recursively. But 59m or 59mh will NOT be in the image. /dev/scd1 is the cdrom device.

DVD --

Unsure if this can be piped. But breaking it down to 2 steps works fine

mkisofs -f -U -iso-level 4 -R -x unused_dir src | growisofs -dvd-compat -Z /dev/scd1=/dev/fd/0

(http://ubuntuforums.org/showthread.php?t=363666)

Wednesday, October 15, 2008

ripping an audio cd on linux

Still in the after shock of losing my Windows system.  This time I need to rip an audio cd.  Well everything can be done on Linux.  No doubt about that.  And can be done in easier ways, and funner.  Just that you need to find it.  Yes, Google made it possible.  Also credits go there...

cdparanoia -wB -d/dev/cdrom
for i in *.wav; do lame -b 192 $i `basename $i .wav`.mp3; done

Power of collective talents!

Thursday, September 11, 2008

the evil CSS, region cod, etc.

Typically technologies are enablers.  DVD is far from being the newest technology, but it makes easy and quality yet at home movies watch experiences possible.  DVDs are affordable, if you don't travel.

There are other "technologies", that are rather blockers.  They are there to make something not working for paid users, in hopes that (abiding) users pay double or multiple.  Among the most evils, is this DVD region + css thing.  Someone decided that DVD buyer only can see a DVD in 1 geographic region by paying once.  If you want to see your favorite movie in Japan while you already purchased a DVD in U.S., you still have to pay for another copy in Japan.  If you travel globally, you better not want to watch different movies, otherwise you have to pay for the same thing 7 times.  And whats worse, you better not buy DVDs outside your region, because your home DVD player is not supposed to be able to play them, after 5 times region switches.  Or you must pay a hefty fee to the player manufacturer to get you addition 5 region switches.  All but you are the winners.  Good deal!

Losers, forced ones, don't get to be good citizens, not voluntarily.

My new toy, that 24" iMac, lovely as it is, has a Matsushita UJ-875 DVD rom in it.  Most late DVD ROMs have region control in firmware.  In this case using a region relaxed player ain't cutting it.  For many of such RPC2 ROMs, http://forum.rpc1.org is a good place to look for upgrade firmware.  Nothing else on earth deserves the word UPGRADE more.  I am unlucky.  Searching with my Matsushita version DB09 gets me no goody.  
I do have another box, a Ubuntu Hardy Heron.  It is headless (no monitor connected to it).  So viewing needs to be on iMac.  Playing directly on Ubuntu via ssh and pipe the raw frames to iMac is not an option.  It takes too much bandwidth than my LAN can handle, 480x720x30(fps)x8x4(32 bit) = ~320 Mbps.  I think my router is the bottle neck, but I am not sure.  Wikipedia tells me full duplex ethernet gets only 200 Mbps.  This would not be enough either.
Sharing Ubuntu DVD ROM seems a natural solution.  But I was unable to find how to share DVD via nfs.  I would certainly guess it is possible, why would it not be?  Sharing via samba made it work, however.  Two plain tricks.  One is I had to install libdvdnav, libdvdread, and libdvdcss on Ubuntu.  I found this surprising.  So the shared DVD ROM is not receive IO commands and then reading the binary out to the remote machine, but receives DVD commands.  Second, the original movie player on iMac does not work with this approach.  No idea why not.  But at least VLC works.  So I am happy.
While googling, I found a software called k9copy.  It is said to work like DVD Shrink on windows.  Just downloaded and made a build.  Will mess with it one day, when my son orders me to make a copy for him.  It won't be long.

Monday, September 1, 2008

svn server set up

Today I set up a svn server on my Ubuntu.   Since I am good at losing my works, thought svn might be a good help.  I don't have a good grasp on cvs, and pretty close to hating it.  svn on the other hand is closer to clearcase that I am most used to.  So that was my choice.  Well, clearcaes would have been nice, just that it surely would be an overkill, and non open source.

To get to the meat, first this very nice site got me a jump start - http://www.section6.net/wiki/index.php/Setting_up_Subversion_in_Linux

I already had svn installed.  But to follow the instructions, I did 

apt-get install subversion-tools python-subversion libsvn-perl
mkdir /svnroot
svnadmin create /svnroot
vi /svnroot/conf/svnserve.conf (set proper configs, commends are explanatory) 
vi /svnroot/conf/authz (to add rw account to /)
vi /svnroot/conf/passwd (to add account / password pairs)
vi /etc/init.d/svnserve (paste in the bash script provided by the above mentioned blog)
chmod +x /etc/init.d/svnserve
update-rc.d svnserve defaults
/etc/init.d/svnserve start

Unless I forgot something, these were all I did.  It was pretty simple and quick, and working (more importantly).  Not bad, eh?

Saturday, August 30, 2008

"find" performance on windows ntfs vs linux ext3

Just for the heck of it, I ran a find command to look for the same file under the same relative path, in (Cygwin over) Windows and in Linux.  The performance is ~50 times difference. Guess who is faster :) .  Add more to the twist, my Windows machine is a Core 2 Duo @ 2.13 Gig (each, of course), with 2.5GB ram; Linux is running on a Pentium-4 @ 2.8 Gig, single core, 2GB ram.

Cygwin over Windows:
ztang@LV017554 /cygdrive/c/same_folder_tree_node 
$ time find . -name b.bat
./b.bat

real 0m9.290s
user 0m1.483s
sys 0m7.796s


Linux
ztang@ubuntu2:~/projects/same_folder_tree_node$ time find . -name b.bat
./b.bat

real 0m0.196s
user 0m0.056s
sys 0m0.136s

sdl, gpac, dss, and others

I should have roughly about 300 gig HDD to fill for my new toy, Ubuntu 8.04.  The smallest of the 4 HDDs is a 40 gig one, where I store the boot, os, and everything the is dependent on it, so that pretty much means all the software.  Then I should have 250+ gigs for data, should be primarily multimedia.  That should be fun.

For now, I am reloading the all software I used and think that I will be using, ffmpeg, mm codecs, mplayer, vlc, etc.  All were kind of smooth, just time consuming.  Here are couple of hurdles that might be worth documenting.

SDL - when configuring and compiling SDL, it does not care if there is no graphic drivers, or devices available.  Don't get why.  So a successful build of it does not mean much.  I ran vlc or mplayer, all were fine with audio, but video could not find any device.  So I had to go apt-get install a bunch of directfb, gtk stuffs.  Easy enough, just don't get why SDL doesn't crap out at config time.

gpac, except for its MP4Box, I never used anything else of it.  But it seems it has a player, a streamer, along with many other cool stuffs.  It seems that it does not compile with OpenGL.  Could also be something of OpenGL is missing on my machine.  I did not dig into it.  It was not recommended to build with OpenGL anyways, for performance risks, as it said in README.

dss, this is an interesting one.  It does not compile.  Something are apparently missing in header files, conditional compiled linux defs, head inclusion path in makefiles, head includes are even spelt wrong (in upper / lower cases).  It does not even have a readme file to tell you how to compile.  Try at your own risk :) .   Tired and frustrated, at 2 am in the morning, I found a patch file by chance, http://freebsd.ntu.edu.tw/FreeBSD/ports/local-distfiles/nork/dss-6.0.3.patch . No description or anything.  I figure it wont hurt to give a try.  Turned out it was one of the few right things I did in my life.  It took me 2+ hours to bust a quarter of all the problems, but 1.5 seconds to resolved the rest with this patch.  And then the build and install went on a smooth sail.

By now I think the re-setup of my Linux box, upgraded with Ubuntu 8.04 Hardy Heron is pretty done.  It is a pretty distro.  When I plugged my cell phone, a mass storage device was automatically mounted.  

Sunday, August 24, 2008

GRUB Loading, Error 15

Loading Ubuntu is a labor job. Then starting with it, I get this on the boot up screen

GRUB Loading Stage1.5

Grub Loading, please wait...
Error 15

I don't remember when was last time I did not hit a wall the first step out of the door. Anyhow, standard procedure is googling with this error. So I did. Unlike most of the other times, did not find something that was close enough. So I played with it myself, and found something. The root cause was as dumb as it could be, the /boot partition did not have bootable flag set.

I have a total of 4 HDDs in the system, 2 previously loaded with fc6, 2 were from my Sony Vaio. While loading Ubuntu, I did not want to lose any data, so I loaded onto a hw that only had fc6 boot partition. That was a 40GB HDD. I loaded the whole Ubuntu 8.04 system on this single HDD. For some reason, bootable flag was not set, or perhaps was not set correctly. I found 2 other partitions were set with this flag, but not the actualy boot. Changing the flag fixed problem.

Today, a year after I posted the above, I was reading something regarding GRUB, where it mentioned that GRUB stage 1.5 is to load a program that understands file systems, ext2, ext3, or rfs. It is located in the first 30 kilobytes of hard disk immediately following the MBR. So guess my original problem was that this program was loaded, but when it tried to parse the boot flag marked partition, which did NOT have GRUB stage 2 to be found and loaded, it hung.

Grub error 17, cannot mount selected partition

I was not done with grub yet.  After grub loaded, it shows all the bootable options, all 4 of them, Ubuntu 8.04, Ubuntu 8.04 (recovery), memory test, and XP (the HDDs from Vaio).  That was nice to see things going fine, until it came to me the another error after hit the first boot option.

Grub error 17

Cannot mount selected partition

It apparently was trying to start Linux OS.  But I did not have guesses better than this.  Google proved to be my friend this time.  Here is a link to some very nice info.

http://ubuntuforums.org/showthread.php?t=442945#9

Briefly, there is misunderstanding between what hd[0 - 3] are on my system, between Ubuntu and BIOS.  The HDD, that has both boot and root on it, was considered hd0 by BIOS, but Ubuntu's guess was hd3.  So when Ubuntu wrote up the menu.lst for grub to find os image, it put hd3.  Modifying menu.list so thta it points to hd0 fixed problem.

Now I am awaiting for the next blocker.

Overtuure - Never ending problems

Been an engineer for so many year, I am led to believe that we are here not just to fix problems, but to also create problems (so that we can then fix).  If there is a quiet period of time when there is no problems to tackle, it itches. 

Lately I killed my Sony Vaio (that I never quite understood how I did it), so bad that, I think the motherboard is gone.  Buying a new 24" iMac as the consequence of it made this rather a celebrative accident than sorrowful, but the engineer part of me took out the 2 hard drives from Vaio and put in my OTHER box, which is a fc6 Linux.  I had a PCI raid card in it from a coupla years ago, so I can have up to a total of 6 (P)ATA HDDs.  Well, now I have 4.  The fc6 finds the PCI card, but NOT the 2 foreign HDDs.  FC6 is kind of old, and every customization I ever tried to have, I had change a lot of things, and many times rebuild the kernel.  So finally I got fed up with it, and decided to load Ubuntu (better forum support) 8.04.  

OK, this is gonna make me busy for the next few months, I am pretty sure.  Since I did that two sleepless nights ago, I have already experienced quite a few problems.  I never used to do this, but age finally put me to where, I believe some documentation might save time.  Now I got myself a fresh start (newly loaded Ubuntu, well, sort of), I will log the problems I experience.