Tuesday, April 21, 2015

Debugging the Android EMM Agent - WSO2 EMM 1.1.0

We have done a custom debugger for Android Agent to check the input and output operations real time on the Agent app itself. To use this feature, we should 1st build the Android Agent by following [1]. And before we generate the APK file, make sure you change the constant "DEBUG_MODE_ENABLED' in the CommonUtilities.java [2] to True.

Once it's built and installed on a device. You can first enroll the device to the EMM server. Once you reach the Register success screen of the Agent app. (When you reach the below Screen)

Once you reach this screen, click on the options icon on the top right corner of the app and click on Debug Log option and you will see the live logs. Click on Refresh to view the latest command logs. And these logs will be saved in a file named "wso2log.txt" in the device external storage.

If you need more information on configuring and debugging EMM visit [3] and [4]

[1] - https://docs.wso2.com/display/EMM110/Android+Configurations
[2] - https://github.com/wso2/emm-agent-android/blob/master/src/org/wso2/emm/agent/utils/CommonUtilities.java
[3] - http://wso2.com/library/articles/2014/03/how-wso2-emm-addresses-the-android-challenge/
[4]  - http://wso2.com/library/webinars/2014/09/getting-your-android-device-managed-by-wso2-emm/

Monday, March 31, 2014

Let’s make our apps less battery consumptive

Major characteristics of a high battery consumptive app

1.) Apps that run without the user’s permission (Ex : Apps with administrator privileges).

2.) High usage of device functions which require high energy, such as GPS, accelerometer, camera and other sensors, or when the app fails to turn off those functions when the are not in use.

3.) Apps which do frequent wake-ups on smartphone or prevent the smartphone from going to sleep mode. (Handsets go into sleep mode when they are idle to enhance the battery life but it can be prevented programmatically by apps – Wakelocks)

4.) “no-sleep energy bug” – This is a situation where at least one component of the device is woken up by our app and failed to put back to sleep due to a programming error and it causes battery drain as well.

5.) Apps with high-end graphics such as games

Verizon rates apps considering battery consumption [1] and according to that, If the device consumes less than 30 minutes of battery time, it gets five stars.
  • 5 stars: current drain less than or equal to 5mA; up to 30 minutes battery life lost.
  • 4 stars: current drain 5-10mA; 30 minutes to 1 hour battery life lost.
  • 3 stars: current drain 10-15mA; 1-1.5 hours battery life lost.
  • 2 stars: current drain 15-20mA; 1.5-2 hours battery life lost.
  • 1 star: current drain over 20mA; over 2 hours battery life lost.
How do we optimize our app?

1.) Use resource optimizer tool by AT & T [2] to test and optimize the app (this tool is free and open source.)

2.) Use Wakelock Detector [3] to monitor our app's impact on waking the device up - This identifies all apps on the device that, with or without permission, override the sleep function.

3.) Performing updates while a device is charging causes minimal battery drain, so we can create our app to maximise its update rate when the device is charging. We can also reduce the update rate when the device is not connected to conserve battery life. Read android developer guide [4] for more information.

4.) We can use BatteryManager [5] to broadcast battery and charging details. BatteryManager broadcasts whenever your device is connected or disconnected from power. These events can determine how often you start your app in a background state. To monitor changes in the charging state, register a BroadcastReceiver in your manifest to listen for these events by defining ACTION_POWER_CONNECTED and ACTION_POWER_DISCONNECTED. Generally, you only need to monitor significant battery changes. To do this, you can use the intents ACTION_BATTERY_LOW and ACTION_BATTERY_OKAY, so you can determine when to disable all your background updates. For the full tutorial, see Monitoring the Battery Level and Charging State [6].

5.) The problem with using a BroadcastReceiver is that your app will wake up each time any of the receivers are triggered. However, you can disable or enable the broadcast receivers at runtime. This way the receivers you declared in the manifest are triggered by system events only when necessary. You can use the PackageManager to toggle the enabled state on any component defined in the manifest. - Blackberry developer blogs [7].

6.) If you determine that connectivity has been lost, you can disable all of your receivers except android.net.conn.CONNECTIVITY_CHANGE, which informs you when the internet connectivity status changes. Once you are connected, you can stop listening for connectivity changes. You can use this technique to delay larger downloads by enabling a broadcast receiver that initiates downloads only after you are connected to Wi-Fi.

7.) Stop view animations when they're not really necessary (Incl progressbar)

8.) Be very careful with location requests - Unless your app needs to know the device's precise geographic coordinates at all times (Ex: Map or navigation app), you should carefully decide on how often you send location requests.

9.) Push data to your apps (Using GCM) without making data calls always to check for updates.

To read in-depth on mobile application quality improvement, read the article [8] by “The App Quality Alliance”


Sunday, March 16, 2014

WSO2 ESB - The FASTEST ESB on Earth.!

The latest round of performance testing results has been published by WSO2: WSO2 ESB Performance Round 7.5 with the release of WSO2 ESB 4.8.1.



Above results clearly depicts that the WSO2 ESB is the fastest giant in the ESB space, when compared with almost all the popular open source ESBs.

Sunday, April 21, 2013

Rooting your android devices using ADB shell

As prerequisites you should have an android device and a USB cable to connect with the PC. Download this zip package which you will need in the rooting process, please follow this link and get the files you need and the Android SDK/ADB up and running on your computer. If you are unfamiliar with ADB, please follow this ADB tutorial.

Unzip the SuperOneClick .zip find the su-v3, busybox, Superuser.apk, psneuter, and GingerBreak files. Rename su-v3 to su, and place the files in your ADB Platform-tools directory, which is contained in the Android SDK folder on your computer for the ease of executing shell commands.

If you are a windows user, please download USB drivers for your android device from the manufacturers website.

Steps for Rooting your device

The method we're going to use in order to rot the device is, using an exploit. (An exploit takes advantage of a known vulnerability to allow the Android user the ability to increase his or her level of privilege and access root.) When you have ADB setup and the proper exploit files, you are ready to root. Still, before you start running commands, you need to put your phone in USB debugging mode (settings > applications > development > enable USB debugging) and connect it to your computer.

Open the command prompt (windows) or the terminal (linux). Change your directory (cd command) to platform-tools folder in the android sdk folder.

This command will leave you with a shell prompt in the platform-tools directory. From here, you can run the commands that will actually root your phone. Be sure to run these commands in the same order.

First, here are the commands that run the psneuter exploit and gain a root shell.

adb devices
adb push psneuter /data/local/tmp
adb shell
$ cd /data/local/tmp
$ chmod 777 psneuter
$ ./psneuter

At this point, the exploit will run and close the shell. You will need to run these commands to restart the ADB server.
db kill-server
adb devices

Then use this command,
adb shell

command to open a shell. If you see a "#" sign, you have root access, so go ahead and continue to the next step.

We now need to make this root permanent. From the root shell you just opened, type the following commands.
# mount -o remount,rw -t rfs /dev/block/st19 /system
# exit
adb push busybox /system/bin
adb push su /system/bin
adb install Superuser.apk
adb shell
# chmod 4755 /system/bin/busybox
# chmod 4755 /system/bin/su
# mount -o remount,ro -t rfs /dev/block/st19 /system
# exit
adb reboot

Your device will reboot now. To check whether your device is rooted, try and install a root only app like Titanium Backup. If such an app works in your device, that means you have successfully rooted your device. Enjoy. :)

Saturday, March 26, 2011

Lets step on to the amazing C++ world - Part 2 - Environment Contd..

Hello guys, I think now you're comfortable with the basic environment of C++. Today, I'm going to introduce you a new platform to compile C++ programs. That is visual C++ which is a Microsoft's implementation of C++. There are 6 main phases in visual C++.

       1.) Edit - Program is created in the editor and stored on the disk.
       2.) Preprocess -  Preprocessor, processes the code
       3.) Compile - Creates the object code and stores on the disk
       4.) Link - Linker links the object code with the libraries
       5.) Load - Loader puts program in memory
       6.) Execute - CPU takes each instruction and execute it, storing new data values also will happen as it     executes the program.

 Those are the main steps in visual C++. In Microsoft platform, there are two main compiler applications to compile and execute C++ programs. They are Visual C++ 6.0 and Visual C++.net. The difference between these two is, Visual C++ 6.0 produces an unmanaged code (Direct conversion of High Level Language to Machine Language using a compiler) and Visual C++.net produces a managed code (Using intermediate language between the High level language and the machine language.).

To work with this Microsoft's platform, you need to use "Namespaces". All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. In order to access its functionality we declare with this expression that we will be using these entities. std:: specifies using name that belongs to “namespace”. As an example, when you are using insertion operator (which will be discussed in the next lesson), we have to declare std : : cout; . So for library functions, we need to use this. But with a single statement "using namespace std;" we can avoid declaring it everywhere. So,, that's it about basics of the Visual C++ environment. You can use Visual C++ 6.0 or Visual Studio (for .net) to work with C++. But my preference is to work with Turbo C++ which I mentioned in previous lesson.

So... now you are up to speed to be a C++ programmer. Then Let's start with codings and C++ coding basics.  

Saturday, March 19, 2011

Lets step on to the amazing C++ world - Part 1 - Environment

Can a computer understand the language we speak? Can we directly give commands to the computer? In simple terms, can we communicate with the computer in our language? Simple answer is "NO". So, how can we communicate? Lets simply take an example, assume, we need to talk with a person who came from Siberia,, we don't know their language,, so how do we communicate? We gonna need a translator. So same as that, to communicate with the computer, we gonna need a translator. Because the language that the computer understands is, Binary Language. It's called the Machine language. There is another computer language type called assembly language (English-Like representing representing elementary computer operations) and we need assemblers (translator) to convert it to machine language.

Another language type is, High-Level languages. It's similar to English and uses common mathematical notations. There, a single statement accomplish substantial tasks. (Ex: TotalPay =  Payment + Bonus - Tax ). We need a translator programs (Compiler) to convert it to machine language or an interpreter which directly converts high level language programs.    

Computer program is a set of instructions that control the computer's processing of data. And C++ is a high level language which facilitates structured and disciplined approach to computer program design. And its an Object Oriented Language (We will discuss more on Object Orientation in future). To compile C++ programs you gonna need a compiler. A link to download a compiler is given below. If any problem occurs, please contact me by leaving a comment here. Download it and install it on your PC and we gonna need it from the next lesson.

Link to download a compiler :  http://www.4shared.com/file/K7WLGlcW/Borland_Turbo_C_45.html
Link 2 :  http://www.4shared.com/file/Vk41ajgi/Turbo_C_v45.html

After installing, open the program by double clicking the Turbo C++ icon. The main layout of the Turbo C++ is described below.

                                 Click on the image to enlarge it.

You can write programs by making new file and save it as name.cpp (*important). And first Build it by clicking Build Button and check for errors. And debug if there are errors. And then run the program. Lets move on to the coding. And lets start with C++ from the next discussion. :)

Friday, March 18, 2011

Lets Start with C++, My Favourite

Without any argument C++ is the most efficient, fast, flexible and interesting language that I've ever coded with.
Therefore with the grand opening of my 1st blog, I really would love to tell you about C++. As I know, it provides flexibility other than any other language because it has both the Object Oriented features and the memory concepts that we use in C which is the mother language of C++.

So,,lets talk a little bit about the history and the birth of C++. C++ was introduced to the world by Bjarne Stroustrup  at Bell Labs during 1983-1985 as an enhancement to the great C. And our subject C++s original name was "C with classes", but a little later it was named as C++ which is using all over the world and which is a leading, controversial and revolutionary language in the present world.

Lets start with it. This is for both the beginners and masters of C++ which flows as both the basic and advanced C++ concepts at the same time. For beginners, I'll be starting as "Lets step on to the amazing C++ world" and for ones who knows C++ basics, I'll be starting with "Advanced concepts of C++". So enjoy this series of posts and enjoy the world of C++.