Linux commands

Wednesday, October 17, 2012

Different ways of compilations in android

Different compilations are used for android code

1. Compilation of complete code
$make
2. Compiling android kernel
$make bootimage
3. compiling system img
$make systemimage
4. compilation of an apk
open Android.mk of an apk
LOCAL_MODULE := xyz_module_name
$make xyz_module_name

5. mm is command to compile the indiviual modules . TO work this command first all the code should compile atleast once

Monday, September 3, 2012

how to compile SystemUI

Go to base SystemUI folder and type
$mm

SystemUI.apk is generated in out folder

//install to phone
adb root
adb remount
adb push SystemUI.apk /system/app/

adb reboot

Wednesday, August 22, 2012

Reverse single linked list.



#include<stdio.h>
#include<stdlib.h>
typedef struct node {
int data;
struct node *next;
};

struct node *head=NULL;

void push(int d)
{
struct node *tmp = (struct node *)malloc(sizeof(struct node*));
struct node *ptr = head;
if( head == NULL)
{
tmp->data = d;
tmp->next = NULL;
head = tmp;
} else {
tmp->data = d;
tmp->next = NULL;
while(ptr->next != NULL)
{
ptr = ptr->next;
}
ptr->next = tmp;
}
}

void display()
{
struct node *ptr = head;
while(ptr)
{
printf("%d",ptr->data);
ptr = ptr->next;
}
}

void delete(int n)
{
struct node *ptr=head;
struct node *pre;
int i=1;
if(head != NULL && n==1)
{
head = head->next;
free(ptr);
return;
}
while(ptr != NULL)
{
if(i == n)
{
pre->next = ptr->next;
free(ptr);
ptr=pre->next;
break;
}
pre= ptr;
ptr= ptr->next;
i++;
}
}

void reverse()
{
struct node *ptr=head;
struct node *tmp=NULL;
struct node *next=NULL;
while(ptr)
{
next = ptr->next;
ptr->next = tmp;
tmp=ptr;
ptr=next;
}
head = tmp;
}
main()
{
int d=0,i=0;
while(i<5)
{
i++;
scanf("%d",&d);
push(d);
}
display();
scanf("%d",&d);
delete(d);
display();
printf("reverse ");
reverse();
display();
}



Tuesday, August 21, 2012

delete nth element linked list

void delete(int n)
{
        struct node *ptr=head;
        struct node *pre;
        int i=1;
        if((ptr != NULL) && n == 1)
        {
                head = head->next;
                free(ptr);
                return;
        }
        while(ptr != NULL)
        {
                if(i == n)
                {
                        pre->next = ptr->next;
                        free(ptr);
                        ptr=pre->next;
                        break;
                }
                pre= ptr;
                ptr= ptr->next;
                i++;
        }
}

Thursday, July 5, 2012

How to declare new system property in Android

Go to init.rc

//define property
setprop  sys.xyz 0

//use in your code
int ret;
char prop_value[MAX];
ret = property_get("sys.xyz",prop_value,NULL)

Thursday, June 21, 2012

No manual entry for pthread_create


library is required to install in system

apt-get install glibc-doc
apt-get install manpages-dev
apt-get install manpages-posix-dev

Monday, May 21, 2012

cc1: warnings being treated as errors/treat warning as error in gcc

Warnings are reported as errors 

-Werror  this flag in Makefile will treat warnings as errors.

//comment this line or remove the flag
CFLAGS += -Werror


Thursday, May 10, 2012

how to make clean module in android

clean module

 $ make clean-<moudlename>
 

   eg: make clean-libxyz (to clean libxyz.so) 


 $ make clean 
   will clean entire android code 


or


 $ mm -B  
   will rebuild all the code and dependencies

Wednesday, May 9, 2012

how to pop up window/notification on startup of android


SystemUI is responsible to display the notification and alters and dialog windows with out depend on Activity. If you want to display an Alert after the boot up of android then add a peace of your code in
SystemUI apk. If any Intent is broadcasted then SystemUI broadcast receiver will receive that intent and call your function,
for  example you want to display an alert after boot completed then add code at where the Boot_COMPLETED intent should receive in SystemUI

Tuesday, May 8, 2012

how to compile apk in android


Open the Android.mk of your apk then find the 

LOCAL_PACKAGE_NAME := Settings
or
LOCAL_MODULE := 

then come the back to android base folder 

$make Settings

Apk will be generated in out folder

If apk is your properitery then install it with 

adb install -r  xyz.apk

if the apk belongs to android base code
then 

adb root
adb remount
adb push xyz.apk /system/app/

how to pop up window/notification after bootup of android

SystemUI is responsible to display the notification and alters and dialog windows with out depend on Activity. If you want to display an Alert after the boot up of android then add a peace of your code in
SystemUI apk. If any Intent is broadcasted then SystemUI broadcast receiver will receive that intent and call your function,
for  example you want to display an alert after boot completed then add code at where the Boot_COMPLETED intent should receive in SystemUI

how to flash systemui.apk


$adb root
$adb remount
$adb push SystemUI.apk /system/app/
$adb reboot
After restarting it starts with new SystemUI 

Thursday, April 26, 2012

how to import android.os.SystemProperties in android app

Please follow the below steps to solve this problem, I solved the same issue

Some properties will not directly accessible to app layer in android, It is need to load the package dynamically, for that need to create a class SystemPropertiesProxy


Copy the below code as it is in SystemPropertiesProxy.java




package com.example.packname;


import java.io.File;

import java.lang.reflect.Method;

import android.content.Context;

import dalvik.system.DexFile;





public class SystemPropertiesProxy

{



/**

 * This class cannot be instantiated

 */

private SystemPropertiesProxy(){



}



    /**

     * Get the value for the given key.

     * @return an empty string if the key isn't found

     * @throws IllegalArgumentException if the key exceeds 32 characters

     */

    public static String get(Context context, String key) throws IllegalArgumentException {



        String ret= "";



        try{



          ClassLoader cl = context.getClassLoader();

          @SuppressWarnings("rawtypes")

          Class SystemProperties = cl.loadClass("android.os.SystemProperties");



          //Parameters Types

          @SuppressWarnings("rawtypes")

              Class[] paramTypes= new Class[1];

          paramTypes[0]= String.class;



          Method get = SystemProperties.getMethod("get", paramTypes);



          //Parameters

          Object[] params= new Object[1];

          params[0]= new String(key);



          ret= (String) get.invoke(SystemProperties, params);



        }catch( IllegalArgumentException iAE ){

            throw iAE;

        }catch( Exception e ){

            ret= "";

            //TODO

        }



        return ret;



    }



    /**

     * Get the value for the given key.

     * @return if the key isn't found, return def if it isn't null, or an empty string otherwise

     * @throws IllegalArgumentException if the key exceeds 32 characters

     */

    public static String get(Context context, String key, String def) throws IllegalArgumentException {



        String ret= def;



        try{



          ClassLoader cl = context.getClassLoader();

          @SuppressWarnings("rawtypes")

          Class SystemProperties = cl.loadClass("android.os.SystemProperties");



          //Parameters Types

          @SuppressWarnings("rawtypes")

              Class[] paramTypes= new Class[2];

          paramTypes[0]= String.class;

          paramTypes[1]= String.class;         



          Method get = SystemProperties.getMethod("get", paramTypes);



          //Parameters

          Object[] params= new Object[2];

          params[0]= new String(key);

          params[1]= new String(def);



          ret= (String) get.invoke(SystemProperties, params);



        }catch( IllegalArgumentException iAE ){

            throw iAE;

        }catch( Exception e ){

            ret= def;

            //TODO

        }



        return ret;



    }



    /**

     * Get the value for the given key, and return as an integer.

     * @param key the key to lookup

     * @param def a default value to return

     * @return the key parsed as an integer, or def if the key isn't found or

     *         cannot be parsed

     * @throws IllegalArgumentException if the key exceeds 32 characters

     */

    public static Integer getInt(Context context, String key, int def) throws IllegalArgumentException {



        Integer ret= def;



        try{



          ClassLoader cl = context.getClassLoader();

          @SuppressWarnings("rawtypes")

          Class SystemProperties = cl.loadClass("android.os.SystemProperties");



          //Parameters Types

          @SuppressWarnings("rawtypes")

              Class[] paramTypes= new Class[2];

          paramTypes[0]= String.class;

          paramTypes[1]= int.class; 



          Method getInt = SystemProperties.getMethod("getInt", paramTypes);



          //Parameters

          Object[] params= new Object[2];

          params[0]= new String(key);

          params[1]= new Integer(def);



          ret= (Integer) getInt.invoke(SystemProperties, params);



        }catch( IllegalArgumentException iAE ){

            throw iAE;

        }catch( Exception e ){

            ret= def;

            //TODO

        }



        return ret;



    }



    /**

     * Get the value for the given key, and return as a long.

     * @param key the key to lookup

     * @param def a default value to return

     * @return the key parsed as a long, or def if the key isn't found or

     *         cannot be parsed

     * @throws IllegalArgumentException if the key exceeds 32 characters

     */

    public static Long getLong(Context context, String key, long def) throws IllegalArgumentException {



        Long ret= def;



        try{



          ClassLoader cl = context.getClassLoader();

          @SuppressWarnings("rawtypes")

              Class SystemProperties= cl.loadClass("android.os.SystemProperties");



          //Parameters Types

          @SuppressWarnings("rawtypes")

              Class[] paramTypes= new Class[2];

          paramTypes[0]= String.class;

          paramTypes[1]= long.class; 



          Method getLong = SystemProperties.getMethod("getLong", paramTypes);



          //Parameters

          Object[] params= new Object[2];

          params[0]= new String(key);

          params[1]= new Long(def);



          ret= (Long) getLong.invoke(SystemProperties, params);



        }catch( IllegalArgumentException iAE ){

            throw iAE;

        }catch( Exception e ){

            ret= def;

            //TODO

        }



        return ret;



    }



    /**

     * Get the value for the given key, returned as a boolean.

     * Values 'n', 'no', '0', 'false' or 'off' are considered false.

     * Values 'y', 'yes', '1', 'true' or 'on' are considered true.

     * (case insensitive).

     * If the key does not exist, or has any other value, then the default

     * result is returned.

     * @param key the key to lookup

     * @param def a default value to return

     * @return the key parsed as a boolean, or def if the key isn't found or is

     *         not able to be parsed as a boolean.

     * @throws IllegalArgumentException if the key exceeds 32 characters

     */

    public static Boolean getBoolean(Context context, String key, boolean def) throws IllegalArgumentException {



        Boolean ret= def;



        try{



          ClassLoader cl = context.getClassLoader();

          @SuppressWarnings("rawtypes")

          Class SystemProperties = cl.loadClass("android.os.SystemProperties");



          //Parameters Types

          @SuppressWarnings("rawtypes")

              Class[] paramTypes= new Class[2];

          paramTypes[0]= String.class;

          paramTypes[1]= boolean.class; 



          Method getBoolean = SystemProperties.getMethod("getBoolean", paramTypes);



          //Parameters       

          Object[] params= new Object[2];

          params[0]= new String(key);

          params[1]= new Boolean(def);



          ret= (Boolean) getBoolean.invoke(SystemProperties, params);



        }catch( IllegalArgumentException iAE ){

            throw iAE;

        }catch( Exception e ){

            ret= def;

            //TODO

        }



        return ret;



    }



    /**

     * Set the value for the given key.

     * @throws IllegalArgumentException if the key exceeds 32 characters

     * @throws IllegalArgumentException if the value exceeds 92 characters

     */

    public static void set(Context context, String key, String val) throws IllegalArgumentException {



        try{



          @SuppressWarnings("unused")

          DexFile df = new DexFile(new File("/system/app/Settings.apk"));

          @SuppressWarnings("unused")

          ClassLoader cl = context.getClassLoader();

          @SuppressWarnings("rawtypes")

          Class SystemProperties = Class.forName("android.os.SystemProperties");



          //Parameters Types

          @SuppressWarnings("rawtypes")

              Class[] paramTypes= new Class[2];

          paramTypes[0]= String.class;

          paramTypes[1]= String.class; 



          Method set = SystemProperties.getMethod("set", paramTypes);



          //Parameters       

          Object[] params= new Object[2];

          params[0]= new String(key);

          params[1]= new String(val);



          set.invoke(SystemProperties, params);



        }catch( IllegalArgumentException iAE ){

            throw iAE;

        }catch( Exception e ){

            //TODO

        }



    }

}
----------------------------------------------------------------------------------------------------------------------

Calling in your code

import com.example.packname.*;

String property = SystemPropertiesProxy.get(this, "sys.boot_completed");


Thus your problem gets solved.



Wednesday, April 4, 2012

keytool error: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider

Dude nothing to worry , I solved the same error, please concentrate on JAVA paths

install java -6-openjdk

find out right java path first
Find outjava(executable) in  in this path it is there or not
$/usr/lib/jvm/java-6-openjdk/jre/bin
if is there then do
Now java home will become
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/jre

PATH will become
export PATH=$PATH:$JAVA_HOME/bin
or
export PATH=$PATH:/usr/lib/jvm/java-6-openjdk/jre/bin

In this path /usr/lib/jvm/java-6-openjdk/jre/bin  u can find out keytool(executable) that means you are pointing to correct location
now run

command is correct
$ keytool -keystore /home/moto/cacerts.bks -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storepass changeit -list -v

I got the output



Keystore type: BKS
Keystore provider: BC


Your keystore contains 157 entries


Alias name: 109
Creation date: 3 Sep, 2011
Entry type: trustedCertEntry


Owner: C=US,O=AffirmTrust,CN=AffirmTrust Commercial
Issuer: C=US,O=AffirmTrust,CN=AffirmTrust Commercial
Serial number: 7777062726a9b17c
Valid from: Fri Jan 29 19:36:06 IST 2010 until: Tue Dec 31 19:36:06 IST 2030
Certificate fingerprints:
         MD5:  82:92:BA:5B:EF:CD:8A:6F:A6:3D:55:F9:84:F6:D6:B7
         SHA1: F9:B5:B6:32:45:5F:9C:BE:EC:57:5F:80:DC:E9:6E:2C:C7:B2:78:B7
         Signature algorithm name: SHA256WithRSAEncryption
         Version: 3




*******************************************
*******************************************
                                                              1


Tuesday, April 3, 2012

Reboot android phone by setting system property

//rebooting by setting android propertyAfter setting this property phone will reboot after 10 seconds(time defined in init.rc)

property_set("sys.reboot","1");

axconfig: port 1 not active axconfig: port 2 not active

Error while running the node command, I solved the same problem please follow the below lines

This problem no where related to nodejs.

step 1. Do not install from sudo apt-get install node. This will install radio package. this radio package requires axports to be active, which is not linked with nodejs
step 2. If you already installed like step1 then do uninstall node by sudo apt-get remove node

step 3. Only Download nodejs from http://nodejs.org/ or using git from https://github.com/joyent/node.git but make sure you install the stable branch(0.4.x).
For installing please follow the README.md

step 4. After installing then set the environment variables
export PATH=$PTATH:/home/user/pathtonode/

If you have still problem of running then comment on this page

Hp authorized service centers in hyderabad


Maha electronics

Genuine address you can go it

Address
L&T insurance building , First floor, Rajbhavan road, hyderabad
contact information
ph no : 040 30645918/09

I got repaired my hp laptop on this service center ..its good .. go for it ..


How to declare new system property in Android

Open init.rc or your proprietary init.xyz.rc
//declare new property from following line
setprop sys.newprop 0

//Now you can use it in your code as follows
#include <cutils/properties.h>
property_set("sys.newprop","1");

Reboot android phone from kernel code


//from kernel code
#inlude <linux/reboot.h>
machine_restart (NULL)


//from framework layer

//include this file
#include<cutils/android_reboot.h>

//call this function
android_reboot(ANDROID_RB_RESTART,0,0);


//rebooting by setting android property
property_set("sys.reboot","1");