Sunday, April 14, 2013

Adding custom return type for marshalling/unmarshalling the data type in AIDL:

In Android application, while working with AIDL, I faced this problem.

If I am going to return any custom datatype or class in interface's functions, then we need to write .aidl and .java file.

For example from my AIDL interface function, I am going to return Rect custom class. Then I have to do the following:


Rect.aidl:
=========
package android.graphics;

// Declare Rect so AIDL can find it and knows that it implements
// the parcelable protocol.
parcelable Rect;


Rect.java
==============


import android.os.Parcel;
import android.os.Parcelable;

public final class Rect implements Parcelable {
    public int left;
    public int top;
    public int right;
    public int bottom;

    public static final Parcelable.Creator<Rect> CREATOR = new
Parcelable.Creator<Rect>() {
        public Rect createFromParcel(Parcel in) {
            return new Rect(in);
        }

        public Rect[] newArray(int size) {
            return new Rect[size];
        }
    };

    public Rect() {
    }

    private Rect(Parcel in) {
        readFromParcel(in);
    }

    public void writeToParcel(Parcel out) {
        out.writeInt(left);
        out.writeInt(top);
        out.writeInt(right);
        out.writeInt(bottom);
    }

    public void readFromParcel(Parcel in) {
        left = in.readInt();
        top = in.readInt();
        right = in.readInt();
        bottom = in.readInt();
    }
}

I have to include this Rect.java in android compilation make file [make];

we should not include the .aidl file in Android.mk for this scenario.

This can happen when we are using NDK compilation. In NDK case, we will include java/include files in Android.mk.

Error:

* in my Android.mk file, I have added:
LOCAL_SRC_FILES += \
        src/com/mycompany/mypackage/Rect.aidl \

But when we compile we will
Aidl: Test <= src/com/mycompany/mypackage//Rect.aidl
src/com/mycompany/mypackage/Rect.aidl:19 aidl can only generate
code for interfaces, not parcelables,
src/com/mycompany/mypackage/Rect.aidl:19 .aidl files that only
declare parcelables don't need to go in the Makefile.

Labels: , ,

Android Application AIDL error:

In android application, while working with AIDL, I observed an error.
My function is returning the class Employee. But I got the below error

Aidl: huey <= external/testapp/IMyService.aidl
external/testapp/Ioffice.aidl:16: couldn't find import for class com.sundar.Employee
make: *** [out/target/common/obj/JAVA_LIBRARIES/MyService_intermediates/src/com/IMyService.java] Error 1


IMyService.aidl

interface IOffice
{
 Employee get();
};


I have added the Employee.java which is derived from Parcelable class. I have also added this java file in make file.
But still I got this error.

How to resolve it:
I created the Employee.aidl and copied the below contents

package com.MyService;
parcelable Employee;

I copied the Employee.aidl and copied to the folder where Employee.java is there.Afterwards, it is compiling fine without any error.
 But Employee.aidl is not at all added in Android.mk

Labels: , , ,

Saturday, April 13, 2013

How to get result from an activity:
=====================================

The following program snippet depicts how we can get result from an activity in an android application.

To launch an activity:
===========================
    Intent pickIntent= new Intent(this,PickServerActivity.class);
    //To launch an activity use below command:
    startActivityForResult(pickIntent, REQUEST_CODE_PICK_SERVER);

within activity, how to set result:
====================================
  Intent intent = new Intent();
  // start intent
   if(bServerSelected)
   {   
      intent.putExtra(ServerIntents.EXTRA_SERVER_NAME, selectedServerName);
      setResult(RESULT_OK, intent);
    } else {
          setResult(RESULT_CANCELED, intent);
     }

To get result from an activity:
====================================

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_PICK_SERVER) {
            if (resultCode == RESULT_OK) {
                Bundle extras = data.getExtras();
                if (extras != null) {
                    mServerName = extras.getString(EXTRA_SERVER_NAME);
            //Display Selected server from the activity   
                }
           
            }
        }
    }
   

Labels: , , ,

Friday, January 18, 2013


Android Compilation  & use emulator:
=======================
source build/envsetup.sh
lunch sdk-eng
make sdk

This will build the android code.


We can use emulator to test the compiled code.

mksdcard -l sdjb 256M sdjb.img
emulator -sdcard sdjb.img


This code launches the emulator.Emulator makes use of system.img. System.img is nothing but the compressed format of output system folder
binaries.

If we are pushing any data to sdcard

Push data to sdcard:
adb push test.3gp /sdcard

copy data from sdcard to current folder:
adb pull /sdcard/test.3gp .

We can also use DDMS to copy file to/from device.
Afterwards, we can check gallery. It will list the sdcard in gallery and will show the copied test.3gp in gallery.By clicking it we can play the video. we can also see the logs using adb logcat command.

To compile module level code & use it in emulator follow below steps:
we can use

cd frameworks/av/media/libstagefright
touch AwesomePlayer.cpp
mm

This will generate the module level compilation.

After module level compilation to reflect in emulator's system.img
  give

 "make snod"
from android filesystem.


or

do the following:
cd frameworks/av/media/libstagefright
touch AwesomePlayer.cpp
mmm

mmm will compile the current directory code,dependency code and will update the system.img with modified binaries.

Labels: , ,

Saturday, November 24, 2012


How to maintain various versions with the same target binary inside android file system ???


In Android, whatever folders with Android.mk files are added to external folder in android file system,while building the android, it will be compiled.

   I faced an interesting problem.  Wifi need wpa_supplicant. There are multiple wpa_supplicants are available in external folder. I could not figure it out which one will be compiled.
   external/wpa_supplicant
   external/wpa_supplicant_6
   external/wpa_supplicant_8

Because whatever things we copied to external folder, if it has Android.mk, then that folder will be compiled.
All 3 folders are having same target binary [wpa_supplicant,wpa_cli]. If we have multiple target binary with the same name, compilation will fail.

I analysed and found that in device.../BoardConfig.mk will have the macro to specify the WPA_SUPPLICANT_VERSION=0_x_8.0

if the WPA_SUPPLICANT_VERSION is 5.0, wpa_supplicant folder will be compiled.
if the WPA_SUPPLICANT_VERSION is 6.0, wpa_supplicant_6 folder will be compiled.
if the WPA_SUPPLICANT_VERSION is 8.0, wpa_supplicant_8 folder will be compiled.

within the external/wpa_supplicant/Android.mk if the WPA_SUPPLICANT_VERSION == 0_x_5.0, then only the folder source codes will be compiled.
within the external/wpa_supplicant6/Android.mk if the WPA_SUPPLICANT_VERSION == 0_x_6.0, then only the folder source codes will be compiled.
within the external/wpa_supplicant8/Android.mk if the WPA_SUPPLICANT_VERSION == 0_x_8.0, then only the folder source codes will be compiled.
Target android board can have any supplicant version, it might be 5.0 /6.0/8.0.


   Lessons learnt:
  
   we can have multiple versions of the same binary under external folder,decide which version to be compiled based on target board.

  where I can apply:

     Assume that TI android board has various accelerators for display.Some TI boards will use x hardware accelerators for display. Some boards will use Y hardware accelerators for display. We can use same target binary  so it can either use x hardware accelerator or y hardware accelerator for display based on BoardConfig. Finaly display binary is same.

 we can not put only x hardware accelerator source code in android. It will fail while compiling for Y hardware accelerator source.
User has to take care of copying the code based hardware accelerator. Or else we can copy x and y hardware accelerator code and decide which
one to be compiled by boardconfig.mk macros .



 

Labels: , , , ,

Monday, November 19, 2012

Android logcat with Process ID and Thread ID:
         Android logs can be printed with Process ID and thread ID.

Command to print logcat with PID and TID:

   /system/bin/logcat -v threadtime

When it will be useful ?

     1)  If any crash is occured, we can identify which thread or process id is crashing. we can enable logs in all the modules. If we got any logs from crashing  thread, then crashing thread and logs  TID and PID will match . Based on it, we can localize the crashing location/thread.

  2)   PID and TID will be useful to check which  framework classes used by application.  For example, If I want to check audio track is used by application or not. I can enable logs in audio track class. While printing logs, it will show the process id and thread ID for Audio Track class.

  we can match the PID with running applications PID  to figure it out.

  otherway is we can decompile the APK binary to source code to check whether AudioTrack/framework class is used.


Labels: , ,

Sunday, November 18, 2012

Running/Launching Linux/Android OS with  same kernel, Is it possible How to do?:

In Embedded/STB devices, Mostly they will be using the Linux OS.
Now they are moving to android. How it is possible for them to move to linux???

  over the Linux kernel, Some patches/changes are applied and it is called as android kernel. They are having separate branch also.
 To run android, Below Components involved:
    bootloader, kernel,android source code compiled binaries

    we have to compile kernel with target[ARM /x86] architecture. In the same way we have to compile android source code to the target architecture[x86/ARM].

   Initially the bootloader will loads kernel. Kernel will starts init process of android.

This init process will loads init.rc, init_board.rc scripts and also launches all the android services.

   The user can load linux/android OS with same kernel.

we can have a script to launch android/linux OS or based on user choice.

In launching an android script, we have to run android init processes in background;

android_launch.sh
  ./androidbin/init & # This init binary is generated from android source code.

  The target device should have all the android binaries.
        
 Linux also have the same script.
 
linux_launch.sh
   ./linuxbin/init &

   Linux source code also has init source code. This should be invoked if we want to launch the linux.This init process will launch all linux binaries.
The device should have all the linux source code compiled binaries.

Labels: ,

Sunday, October 14, 2012

Circular Dependency:

I added new xml to settings due to that I got "Stack overflow error" in android runtime,Settings application was not launched.
        Added xml file is ic_settings_ethernet.xml.





 

ic_settings_ethernet.xml contents:
=======================

https://groups.google.com/forum/?fromgroups=#!msg/rowboat/lP65eylKHkQ/flHykmz15xAJ

The stack overflow is caused by the the res/drawable/ic_settings_ethernet.xml file in packages/apps/Settings which references itself, creating a circular dependency. I could not find any use of this file in any of the other resource files or in the Java source code. Simply removing it allows me to start the Settings app without crashes.

Labels: ,

How to disable the WiFi/any networking or add any network in android :
 
  In android framework, there is a file to configure available networks.
If we disabled particular network in that file, Particular network will be disabled in android.

name of the file need to be modified to disable networks:
frameworks/base/core/res/res/values/config.xml

This file contents are as below:
 
  translatable="false" name="networkAttributes">
        "wifi,1,1,1"
        "mobile,0,0,0"
        "mobile_mms,2,0,2"
        "mobile_supl,3,0,2"
        "mobile_dun,4,0,4"
        "mobile_hipri,5,0,3"
    
 
 
In android framework, Connnectivity manager/service is reponsible for handling available networks.
If I want to add new network, I have to develop a service,NetworkStateTracker  and add the content in the above file.
 
 
Let me say If I want to add ethernet support, ethernet service should be written, launched from ConnectivityService.
we need to develop our own NetworkStateTracker derived class to maintain the state of ethernet.
We also need to add new item in the above file.
   From the above file only, Android will comes to know the available networks.
Let me say if I removed the wifi item, then WiFi wont be detected. Because android framework doesnt know the wifi network is available 
 
 
 

Labels: , , , ,


How to display logs from android service:

By default,If we added any android service in init.rc, logs are redirected to null device. So logs wont be shown from service. Sometimes it will show sometimes it wont show logs. To display logs always from service,


we have to do the following

service serviceName /system/bin/logwrapper /system/bin/dhcpcd -BKLA -d eth0
disabled
oneshot

/system/bin/logwrapper - this will redirect the  service logs to logcat.

init.rc script is executed by init process.

Labels: , ,


How to communicate between two process /To pass information from one application to another application in android java:

 Best ways are intents. whoever wants to send message, He has to raise an intent.Whichever Application wants to receive the message, It has to implement  BroadcastStatusReceiver class.

We can raise intent like this... 

Intent sIntent = new Intent(EthernetManager.ETHERNET_STATE_CHANGED_ACTION);
sIntent.putExtra("EthUp",true) //THis is information to be passed
                                                   //Intent has different methods for string/int and   //so on


whoever[applications] wants to receive this intent they register this intent in their androidmanifest.xml, they will implement the BroadcastStatusReceiver for the same.
From the receiver application's BroadcastStatusReciever's OnReceive()
{
   if(recvdIntent.Equals(ETHERNET_STATE_CHANGED_ACTION)
   {
     boolean b=getBooleanExtra("EthUp");
    }


}


Labels: , ,

Thursday, October 04, 2012

To Enable logs in android Java files:   

import android.util.Slog;
 private void log(String s) {
        Slog.d(TAG, s);
    }

Labels: , ,

How to add logs in android C/C++ files:

#define LOG_TAG XXX   // its the tag u can see in the logcat.
#include  

LOGE("printing log %s,%d",__FILE__,__LINE__);
 

In Android.mk, Add below line :

LOCAL_SHARED_LIBRARIES := \
        libutils          \

Labels: ,

How to Launch an activity/application  in android from commandline:
=============================================

commands to launch an application in android:

adb shell am start -a android.intent.action.MAIN -n packageName/.mainActivityName

If I want to launch one application from commandline, what things I need to do:

1)From APK's AndroidManifest.xml,we can identify the main activity.Then we can use above command

2)Another easy way is launch an application using GUI/by clicking the application At the same time take logs using "adb logcat".

ActivityManager(1132): Starting activity: Intent { cmp=com.android.providers.subscribedfeeds/com.android.settings.ManageAccountsSettings }

ActivityManager(1132): Displayed activity  com.android.providers.subscribedfeeds/com.android.settings.ManageAccountsSettings :500 ms


 we can launch this activity from commandline as below:

 adb shell am start -a android.intent.action.MAIN -n 
com.android.providers.subscribedfeeds/com.android.settings.ManageAccountsSettings
 

Labels: , ,

How to know the services currently running in Android:

     To list the running services in android

  •   Menu->Setting->Applications->Running Services 

Labels: ,

Tuesday, August 21, 2012


I)What is CTS ?
II)CTS components
III)How to Run CTS from end user level?
IV)How to run CTS from Windows?
V)CTS binaries and source code structure


I)Why we need CTS ?
 
CTS testcases tests whether any android apis are modified or any changes done in android that is not compliant to android standard.
Google approves binary only when all CTS testcases are successful. For google approval process,
CTS test cases are executed on device and output .xml is sent to google team.

They will also run the CTS testcases from their end. If there is no failure, then they will approve the binary for the release.
Most of the Mobile operators will expect that the binary should be approved by google.

For some failure cases, we can get a waiver from google. For example, if it is a android DTV/Setupbox, then there wont be any GPS device in it.So all the GPS testcases will fail or not applicable for that device. Waiver request should be reasonable.

II) CTS components:
    CTS is an automated testing application that includes two major components
 1)CTS test application runs on desktop & manages test execution]
 2)Junit testcases running on Mobile or emulator or android device
  JUnit testcases are written in Java and packaged in Android.apk files to run on target device[emulator or android device].
 
III)How to run CTS from end user level?
   1.CTS can be run from Source code in linux
     
 if we have android source code, android/CTS folder will be there.
 we can compile CTS by following steps

 source build/envsetup.sh
 lunch sdk-eng
 make cts 

 Once the compilation is over, we can run
 >cts-tradefed 
 from command line.
 From cts-tradefed it will gives cts prompt.In cts prompt,
 type "list devices" to list the connected devices/emulator.You can refer the android cts document for    more information on list of commands.

 [cts-tradefed binary will be available in out/host/linux-x86/bin/cts/android-cts/tools/]
 cts-tradefed is a script file to run JUnit testcases.

     
   2.CTS can be run from downloaded binary  
         we have to download android compatiblity test suite from android site.

we have to configure this folder in PATH variable
and then we can run
 cts-tradefed in commandline.
     

 IV)How to run CTS from Windows ? Is it possible ?
      It is possible to run CTS from windows.
 Reason:
 "JUnit testcases are written in Java and packaged in Android.apk files to run on target device" from android cts manual.

 cts-tradefed is a script which will configures java to run Junit testcases.

 Configure CTS in Windows OS:

 Step1: adb path should be configured in PATH variable and "adb devices" should list down the devices.
 Step 2:
    cts-tradefed script will contains the following lines:


CTS_ROOT=${ANDROID_BUILD_TOP}/out/host/${OS}/cts
    JAR_DIR=${CTS_ROOT}/android-cts/tools
JARS="ddmlib-prebuilt.jar tradefed-prebuilt.jar hosttestlib.jar cts-tradefed.jar"

for JAR in $JARS; do
checkFile ${JAR_DIR}/${JAR}
JAR_PATH=${JAR_PATH}:${JAR_DIR}/${JAR}
done

   java -cp ${JAR_PATH} -DCTS_ROOT=${CTS_ROOT} com.android.cts.tradefed.command.CtsConsole

Assume that I have downloaded "android-cts-4.0.3_r3-linux_x86-arm.zip"  and unzipped it

My folder structure will be as follows:D:\android-cts-4.0.3_r3-linux_x86-arm\android-cts\tools
The simplification of this script is as follows for windows:

java -Xmx512M -cp D:\android-cts-4.0.3_r3-linux_x86-arm\android-cts\tools\cts-tradefed.jar;D:\android-cts-4.0.3_r3-linux_x86-arm\android-cts\tools\hosttestlib.jar;D:\android-cts-4.0.3_r3-linux_x86-arm\android-cts\tools\ddmlib-prebuilt.jar;D:\android-cts-4.0.3_r3-linux_x86-arm\android-cts\tools\tradefed-prebuilt.jar -DCTS_ROOT=D:\android-cts-4.0.3_r3-linux_x86-arm\   com.android.cts.tradefed.command.CtsConsole

run this command in commandline then you will get cts prompt in windows OS too.

-cp is the class search path for the zip or jar files. whenever some class is encountered in jar file,java will look for it in class search path.
CTS_ROOT will be used internally in jar files, so we are setting CTS_ROOT by -DCTS_ROOT.
CTS_ROOT is D:\android-cts-4.0.3_r3-linux_x86-arm. not a D:\android-cts-4.0.3_r3-linux_x86-arm\android-cts.[by giving this, i got errors]


V) CTS Binaries & source code structure:
          1)cts-tradefed.jar source code path is "android_source_path/cts"
 2)hosttestlib.jar
 3)Junit.tar
          4)ddmlib-prebuilt.jar
          5)tradefed-prebuilt.jar

 ddmlib-prebuilt.jar and tradefed-prebuilt.jar is available as prebuilt binaries. No source code available

 tradefed-prebuilt.jar is a CTS component runs on Desktop machine and manages test execution. platform/tools/tradefederation is the source code folder path for tradefed-prebuilt.jar file.














     

Labels: , , , ,

Friday, August 17, 2012


Following steps  are needed for ICS Android application Development Setup :

1.Downloaded the JDK7 and installed it in machine
2.Downloaded installer_r20.0.3-windows.exe from google site
3.Run the "installer_r20.0.3-windows.exe"
4.Followed the below blog to download ICS SDK
http://www.android.pk/blog/tutorials/install-and-run-android-4-0-sdk-and-ice-cream-sandwich-on-pc/
Now ICS SDKs are installed.Create the AVD for for any platform which requires for application development
5.Downloaded ADT plugin from google site
6.Downloaded the Eclipse classic
7.Downloaded the android_sdk_for_windows.zip and set the tools/platform-tools  folder in PATH variable
8.Installed & Opened the Eclipse classic application
9.In Eclipse, Select    Install new software & select the localpath and add the ADT plugin zip file &
install the files
10.After the ADT plugin was installed, eclipse showed that it requires android support libraries...I installed that android support libraries too...


11.In eclipse->Preferences->Android->SDK location as "android_sdk_windows" folder path.
12.create new android application in eclipse
13.To run the application in emulator,
In Eclipse, Select Run->Run Configurations->Give Some string in "Name" box and select Launch default activity.
 In "Target" tab,select the AVD configuration to run the application





Labels: , , , ,

Friday, July 27, 2012

What is missing in Android Stagefright/NuPlayer RTSP streaming ?

1.Jitter buffer handling
2.RTCP handling
3.Error correction and feedback through RTCP Sender report/receiver report

Labels: , ,

Tuesday, May 25, 2010

Register Node/Recognizer/OMX decoder component

Register Node/Recognizer/OMX decoder component:
----------------------------------------------------------------------------

//Add the dummy recognizer code in Recognizer folder;

1.#include the rec_factory.h in external\opencore\engines\player\config\core\pv_player_node_registry_populator.cpp
2.Create the instance in RegisterAllRecognizers() fn of the same file.


3.BUILD_MACRO defns available in \external\opencore\build_config\opencore_dynamic\pv_config.h file

4.We need to add our Node/register's library & android.mk in
\external\opencore\build_config\opencore_dynamic\Android_opencore_player.mk file

 

5.Configure Node/recognizer/decoder (pvyuvffrecognizer_lib=m) in \external\opencore\build_config\opencore_dynamic\pv_config_selected.mk

6.Configure the shared recognizer/node/decoder's library make path(/pvmi/recognizer/plugins/pvyuvffrecognizer/build/make)
in \external\opencore\build_config\opencore_dynamic\pv_config_derived.mk

 

Labels:

Wednesday, May 19, 2010

You are attempting with incorrect version of javac in Ubuntu while building android source code

Situation:

I have copied the JRE & JAVA SDK folder and set the environment variable . (without installing java, make it as
like an installed). with this one, I am able to compile android checkout.
I have checked the version of the java. its version is JDK_1.0.5_19;
Once I tried to install eclipse, then old version or updated version is installed in my laptop ,
so I couldnt be able to compile android source code and got the error as follows:


Error: You are attempting with incorrect version of javac in Ubuntu while building android source code


Solution:
We can get current java version by typing "java -version". I found that the java version is different from working version (android compiled code);
So we have to remove the recently installed version and reinstall the java .

We have to search the recently installed version by typing the command:

"aptitude search jdk"

it will lists out the JDK packages.

Remove all the JDK packages (Our JDK package doesnt need installation) by typing the following command:

aptitude purge $1 ($1 is the package listed in "aptitude search jdk")

install java_1_5_0_19 .bin file and then now try recompiling the code.Now it is working.

Labels: