Search This Blog

Friday, December 6, 2013

Speed Up "Android JNI" Tricks and Tips

Recently, I got a job to speed up application that using JNI. Many people thought by using native code, it should run faster than Java but I found out that is not always true.

First, the passing parameters from Java level to native code are using time to convert and if you use JNI so often then that gonna be heavy load.

Second, you need to allocate/deallocate resources by yourself in native level(there is no  garbage collector in C/C++ ) and that takes time to do anyway.

Ok. Here are tricks and tips for speed up your Android JNI app. Hope it works for you too  ...

1. allocate/deallocate just one
   The bigger memory you need, the slower you are. So, if it's possible. Try to do allocate and release the resources just one time.


2.don't allocate too big block memory
    Check you code that you really need that much resource? Just use that it needs to be run properly.
for example, data = (unsigned char *)malloc( BLOCKSIZE + 100 );
May be +100 is not necessary.

3. don't use double
   I don't know why but in native code, double makes slow. I changed it type to normal "int" and it running a lot faster.(make sure it doesn't make wrong result)

4. set MAX priority to the thread
   I found that when garbage collector thread is running, some delay may occur(not much but it does go slower) So, try to set your JNI caller thread's priority to MAX that will (somehow) prevent garbage collector thread to run during JNI call.

5. try "ARM" mode
   In your Android.Mk file, add LOCAL_ARM_MODE := arm line and rebuild the code. I found out that the default Thumb mode is slower than Arm mode. However, I'm not sure that it gonna be true for all device.


That is for today !! and may the Force be with you all :D

Wednesday, October 30, 2013

Monday, October 14, 2013

#ANDROID Fay FTP Client version 3.5 released

Now Fay FTP Client version 3.5 was released. Please try and give us more reviews and comments... m(_ _)m




What's New
1.Show progress bar when download/upload file
2.Tablet tested.
3.Fixed Bugs.
Download & Install here ->

Thursday, October 10, 2013

Mobile Apps By The Numbers

Mobile Apps by the Numbers
Explore more infographics like this one on the web's largest information design community - Visually.

Friday, August 2, 2013

#BOINC on my Nexus 10

Just installed BOINC(Berkeley Open Infrastructure for Network Computing) app on my Nexus 10 and Galaxy Nexus ... Hope I can help humanity (for a little bit) ...



Install BOINC here from Google Play ->
https://play.google.com/store/apps/details?id=edu.berkeley.boinc

Here is the tip, because it was so hot in japan now. So,If you ticked "Compute on Battery" then the limit maximum setting temperature will pause the calculate processes.
Tick "Show advanced preference and control .." and set "Max. battery temperature" to upper value (my case at 90 degree)

Tuesday, July 23, 2013

Fay Black Board version 1.0 released


 FAY(Fast And easY) Black Board version 1.0 released ... Try it now !!




Install here ->
https://play.google.com/store/apps/details?id=ataya.p.utilities.fayblackboard

Friday, June 7, 2013

Screen Capture by using adb

Just because my pc was very slow and capture screen with eclipse seems impossible for the large screen tablet. So I have to use adb to do the job instead ...

# adb shell screencap -p /mnt/sdcard/sc.png
# adb pull /mnt/sdcard/sc.png /home/your/Desktop

It works for my nexus 10. Enjoy !!


Unboxing Nexus 10

Just bought Nexus 10 from Google Play.

Nice box

Main screen

 I'm No.2


Saturday, June 1, 2013

#FIXBUG VFY: unable to find class referenced in signature

Today, After updated Android SDK to version 22.0.1 and back to work. This message just appeared and my app just crashed.

VFY: unable to find class referenced in signature

After google it. It seems they added more setting into Android project that make using libraries don't go with the apk. So, just right click on your project and click on
Java Build Path -> Order and Export and tick on "Android Private Libraries ".
 That is !!

Saturday, May 11, 2013

#GalaxyNexus Upgrade to 4.2.2

My Galaxy Nexus has informed me that the new upgrade is ready to be serve.
Now I got Jelly bean 4.2.2








Tuesday, March 12, 2013

Monkey Runner : Touch on Gallery view

I think it has a bug on MonkeyRunner that by using touch command, it can't touch on any item on Gallery view. After Googled it and tried a lot of solutions, I found one that might work for you ... Here it is

1.Using "adb shell" to enter your android device.
2.Then using "getevent" command to get every event happen from now
3.Touch on your Gallery item. You will get something like this ...

/dev/input/event4: 0003 0035 00000820   <-- X position
/dev/input/event4: 0003 0036 00000d26   <-- Y position
/dev/input/event4: 0003 0030 00000028
/dev/input/event4: 0003 0039 00000000
/dev/input/event4: 0000 0002 00000000
/dev/input/event4: 0003 0000 00000820
/dev/input/event4: 0003 0001 00000d26
/dev/input/event4: 0001 014a 00000001
/dev/input/event4: 0000 0000 00000000
/dev/input/event4: 0003 0035 00000820<---
unnecessary from here
/dev/input/event4: 0003 0036 00000d26
/dev/input/event4: 0003 0030 00000028
/dev/input/event4: 0003 0039 00000000
/dev/input/event4: 0000 0002 00000000
/dev/input/event4: 0000 0000 00000000
/dev/input/event4: 0003 0035 00000820
/dev/input/event4: 0003 0036 00000d26
/dev/input/event4: 0003 0030 00000028
/dev/input/event4: 0003 0039 00000000
/dev/input/event4: 0000 0002 00000000
/dev/input/event4: 0000 0000 00000000

/dev/input/event4: 0003 0035 00000820
/dev/input/event4: 0003 0036 00000d26
/dev/input/event4: 0003 0030 00000028
/dev/input/event4: 0003 0039 00000000
/dev/input/event4: 0000 0002 00000000
/dev/input/event4: 0000 0000 00000000
<--- unnecessary to here
/dev/input/event4: 0003 0035 00000820
/dev/input/event4: 0003 0036 00000d26
/dev/input/event4: 0003 0030 00000028
/dev/input/event4: 0003 0039 00000000
/dev/input/event4: 0000 0002 00000000
/dev/input/event4: 0000 0000 00000000
/dev/input/event4: 0001 014a 00000000
/dev/input/event4: 0000 0000 00000000


4.Making shell script to send event directly to device.
    - Convert Hex to Decimal
    - Skip the middle part that is make lag and unnecessary(Timing also big problem) 
    - Pass parameters for x,y position.
NOTE: below script is not match with above values. It was created from another capture.

#!/bin/sh
#
# Script to send touch event directly
# $1 for x , $2 for y
#

adb shell "sendevent /dev/input/event4 3 53 $1;
sendevent /dev/input/event4 3 54 $2;
sendevent /dev/input/event4 3 48 38;
sendevent /dev/input/event4 3 57 0;
sendevent /dev/input/event4 0 2 0;
sendevent /dev/input/event4 3 0 $1;
sendevent /dev/input/event4 3 1 $2;
sendevent /dev/input/event4 1 330 1;
sendevent /dev/input/event4 0 0 0;
sendevent /dev/input/event4 3 53 $1;
sendevent /dev/input/event4 3 54 $2;
sendevent /dev/input/event4 3 48 38;
sendevent /dev/input/event4 3 57 0;
sendevent /dev/input/event4 0 2 0;
sendevent /dev/input/event4 0 0 0;
sendevent /dev/input/event4 1 330 0;
sendevent /dev/input/event4 0 0 0"



5. In your Monkey Runner script, using subprocess to call the shell script file.

    try:
        subprocess.Popen(['bash', '-c', './yourshellscript.sh '+str(3000)+' '+str(3500)])    
    except:
        raise Exception('Could not open the File: yourshellscript.sh')


NOTE: x,y parameters are not the same value on screen resolution. you need to find the usable values.

Hope it will help.

Sunday, February 24, 2013

#AngryBird #StarWars [Path of the Jedi] All stages Cleared !!

Now I became a real Jedi knight ...(T^T)



Thursday, January 31, 2013

#MonkeyRunner : Delete Text on EditText

Now my job is about writing script for doing auto-testing using Monkey runner.
I found the way to delete text that has been entered inside Edittext. Here is the code ...

    # Max text length
    fieldLength = 100
    

    # Select all the chars on the right
    dev.press('KEYCODE_SHIFT_RIGHT', MonkeyDevice.DOWN)
    for i in range(fieldLength):
             dev.press('KEYCODE_DPAD_RIGHT', MonkeyDevice.DOWN_AND_UP)
         #MonkeyRunner.sleep(1)
      dev.press('KEYCODE_SHIFT_RIGHT', MonkeyDevice.UP)
    # Delete them
    dev.press('KEYCODE_DEL', MonkeyDevice.DOWN_AND_UP)
   
    # Select all the chars on the left
    dev.press('KEYCODE_SHIFT_LEFT', MonkeyDevice.DOWN)
    for i in range(fieldLength):
             dev.press('KEYCODE_DPAD_LEFT', MonkeyDevice.DOWN_AND_UP)
         #MonkeyRunner.sleep(1)
      dev.press('KEYCODE_SHIFT_LEFT', MonkeyDevice.UP)
    # Delete them
    dev.press('KEYCODE_DEL', MonkeyDevice.DOWN_AND_UP)


By running above script, it will select text and drag to the right then delete it. Afterthat it will select text and drag to the left and delete to make sure all text is clear.

Hope it helps...

Wednesday, January 16, 2013

How to Unlock Angry Birds:StarWars [Path of the Jedi] for FREE !!

Surely, I am a StarWars fanboy and I love playing Angry Birds. With all my Force I had spend, now I clear all free stages(with all 3 stars) and suddenly, I just realized that 'Path of the Jedi'  was unlocked !!  The Force is strong with me ...








*** all screenshots are Rovio Entertainment's property.