Wednesday, January 21, 2015

How a Broadcast receiver is Implemented in Android?

At the time of application installation, it's manifest file is parsed and stored internally in Android System.

When a broadcast is sent say "Battery_low", then the android system looks up the loaded application's Manifest(that's already parsed and stored internally at the time of installation)
to see whether the application is indented to handle the broadcast message.

Monday, January 5, 2015

GIT - A Simple Reference -- continued 1

To rebase the local dev branch, 
$ git rebase -p dev

If git conflicts occur, to list the conflict files do this,
$ git status

The conflict file looks like this,

<<<<<<< HEAD
<Code Modified>
=======
<Old Code>
>>>>>>> branch Name

When the conflict occurs, git internally creates a temporary branch (no branch),
To confirm that do,
$ git branch
* (no-Branch)
* dev
* feature/xyz
* master

Manually merge the changes and do the following,

$ git add <file-name>
$ git commit -m "Meaningful Comment" <File Name>

$ git rebase --continue

On completion the temporary branch(no-branch) is deleted and control comes to your feature branch,
$ git branch
  dev
* feature/xyz
  master
 
Then finish the feature and push to origin/remote branch,

$ git flow feature finish <ID>
$ git push origin dev

If the origin dev has been updated in meanwhile, then the git push origin dev will fail with following message,

To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.


Then to resolve this do the following,

$ git fetch
$ git rebase -p origin/dev
$ git push origin dev

Sunday, January 4, 2015

NFS Server porting to Android-4.2 (Should work for different version)

                    NFS SERVER PORTING TO ANDROID

QUICK TESTING OF NFS SERVER ON LINUX MACHINE:

# apt-get install nfs-kernel-server
# cat /etc/exports
/path-to-be-shared system-ip-address-which-accesses-shared-folder (rw,sync)
# /etc/init.d/nfs-kernel-server start

In remote machine mount the shared folder
# mount -t nfs -o nolock ip-addr-server-folder:/path-shared path-to-be-mounted-in-local-machine

NOTES
* Mounted directory will show the entire disk size of the server pc. One way to restrict the export folder size is creating a special file of required size, partition it, mount as a loop device locally and export it to client

DIFFERENT TECHNIQUES TO PORT NFS SERVER TO ANDROID:

1. STATIC CROSS COMPILATION WITH LINUX TOOL CHAIN--- Kernel support for NFS

--- Static Cross compilation

--- Runtime environmental setup

2. INTEGRATION OF NFS-UTILS INTO ANDROID BSP
--- Kernel support for NFS

--- Integrate NFS utils source into Android build

--- Run NFS service 

3. LIGHT WEIGHT NFS SERVER APP
--- Taking a Open source Java NFS server code and port it to Android

PORTING NFS SERVER TO ANDROID - LINUX TOOLCHAIN METHOD:

--- Kernel support for NFS

CONFIG_NETWORK_FILESYSTEMS=y
CONFIG_NFS_FS=y
CONFIG_NFS_V3=y
CONFIG_NFS_V3_ACL=y
# CONFIG_NFS_V4 is not set
CONFIG_ROOT_NFS=y
CONFIG_NFS_FSCACHE=y
CONFIG_NFSD=y
CONFIG_NFSD_DEPRECATED=y
CONFIG_NFSD_V2_ACL=y
CONFIG_NFSD_V3=y
CONFIG_NFSD_V3_ACL=y
# CONFIG_NFSD_V4 is not set
CONFIG_LOCKD=y
CONFIG_LOCKD_V4=y
CONFIG_NFS_ACL_SUPPORT=y
CONFIG_NFS_COMMON=y
CONFIG_SUNRPC=y
CONFIG_SUNRPC_GSS=y
CONFIG_RPCSEC_GSS_KRB5=y

************Kernel HACK Starts here****************
kernel_imx/kernel/capability.c

bool ns_capable(struct user_namespace *ns, int cap)
{
        if (unlikely(!cap_valid(cap))) {
                printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
                BUG();
        }

// if (security_capable(ns, current_cred(), cap) == 0) { // Serious kernel hacking: commented out the condition check and false return always
                current->flags |= PF_SUPERPRIV;
                return true;
// }
// return false;
}
EXPORT_SYMBOL(ns_capable);
************Kernel HACK Ends here****************

--- Static cross compilation

* Download NFS utils from below path
http://sourceforge.net/projects/nfs/files/nfs-utils/1.3.1/

* Cross compile required utils such as exportfs, nfsd, mountd statically (Copy all required source files from support folder to respective utils folder to make use of below command for all utilities)
# /opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-gcc -DHAVE_CONFIG_H -I../../support/include -D_GNU_SOURCE -Wall -Wextra -Wstrict-prototypes -pipe -g -O2 *.c -static -o binary-name

* Setup the run time environement
# mkdir -p /var/lib/nfs
# mkdir -p /var/lock/subsys
# mkdir -p /var/lib/nfs/sm
# mkdir -p /var/lib/nfs/sm.bak
# touch /var/lib/nfs/etab
# touch /var/lib/nfs/rmtab
# touch /var/lib/nfs/state
# touch /var/lib/nfs/xtab
# chmod -R 777 /proc/fs/nfsd/
# chmod -R 777 /var
# busybox vi /etc/exports
/path-to-be-shared 192.168.42.130(fsid=0,rw,async,insecure,no_subtree_check,no_root_squash)

* Run the Below utilities to start NFS Server
# mount -t nfsd nfsd /proc/fs/nfsd
# portmap
# exportfs -ra
# nfsd -p 2049
# mountd

NOTES
1. NFS Kernel space files
kernel_imx/net/sunrpc/svc.c
kernel_imx/fs/lockd/svc.c
kernel_imx/fs/nfsd/nfssvc.c
2. Configure and compile NFS package (dynamic cross compilation)
# export PATH=$PATH:/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/
# ./configure --host=arm-fsl-linux-gnueabi --disable-nfsv4 --disable-nfsv41 --disable-gss --disable-uuid --enable-mount=yes --without-tcp-wrappers --with-gnu-ld
# make

Saturday, December 20, 2014

GIT - A Simple Reference


Assume a case where there is Master Branch and Development Branch.

$ git branch
*dev
master

GIT - Work Flow (To create a work flow/branch and work)
-----------------------------------------------------------------------

$ git flow init
$ git flow feature start <id>

After creating the Work flow, moves to feature branch(indicated by *)

$ git branch
   dev
* feature/<ID>
   master

$ git add "modified file names with spaces"
$ git commit -am "Meaningful comment"
$ git flow feature finish <id>


Reset to the head of the current branch
----------------------------------------
$ git reset --hard HEAD

To see the list of check-in's made
------------------------------------
$ git log - prints the list of check-in's made
commit  <SHA ID 1>
Author: name <name@domain.com>
Date:   <Date of commit>

To Delete a WorkFlow/Branch
------------------------------------
$ git branch -D  feature/<ID>

To update the feature branch changes to dev branch
--------------------------------------------------
$ git checkout dev
$ git fetch
$ git rebase -p origin/dev
$ git checkout feature/<id>
$ git rebase -p dev
$ git flow feature finish <id>

To Push the code to Origin/Remote dev
------------------------------------
-$ git push origin dev

Monday, November 24, 2014

How to write a make file(Android.mk) for Android Application when you build from Android Source Code?

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4 <UR-JAVA-Library>

LOCAL_PACKAGE_NAME := <APP-NAME>

LOCAL_SDK_VERSION := current

include $(BUILD_PACKAGE)

# Use the following include to make your own test apk.

include $(call all-makefiles-under,$(LOCAL_PATH))

Tuesday, November 18, 2014

Problem Solving: Improvise, Adapt, Overcome (Given a problem, what should I do??)

Given a problem, what should I do??

http://www.peakprosperity.com/blog/improvise-adapt-overcome/52001

C Debugging

What happens to the following program,

int main()
{
        char *a = malloc(sizeof(100));
        printf("a = %p\n",a);
        a++;
        printf("a = %p",a);
        free(a);
}