Thursday, November 8, 2012

Adding logs in android Middleware

Changes in .mk file :

 LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM



changes in file :

 #include <android/log.h>
 #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "webkit_test", __VA_ARGS__))

  addings logs
    LOGI("Test logs");

Friday, October 26, 2012

Queue


Another important DS we are going to discuss

QUEUE …

What is queue
    

See the above Image ,  peoples are standing in the queue and guy in the counter giving tickets or serving something …
Now think , if counter guy able to give ticket  in an ignore time , then do we require queue anymore … No absolutely not .
 But in practical situation, service provider(counter guy) not able to  serve the request (ppl standing in the queue) in an ignore time. So, we need queue in order to serve all the request.

 Queue has a sequence of the request, where which request comes first that will be processed first. And of-course there are some priority queue (this we will discuss later )

Lets see the implementation of the queue (C++)   .. it is under construction .. I'll post this soon

Tuesday, October 9, 2012

Adding your application in android source code



1. Paste your project in "Packages/apps/" folder
2. Add Android.mk file in your project (you can refer the other app make file)
3. have to add your project name in  generic_no_telephony.mk & large_emu_hw.mk file (available in build/target/product/)

thats all . build the source code and launch the emulator ,you can see your application in Emulator

Sunday, September 30, 2012

Android source code build error

There are some issues I have faced while building the android source code ...

I have listed it and of-course  solution too  :)


/bin/bash: prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi-gcc: Permission denied
soln : change the permission

prebuilt/linux-x86/sdl/bin/sdl-config: Permission denied
soln : change the permission


/usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
 soln : apt-get install gcc-multilib  On x86_64 with debian / ubuntu / mint:
 

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.so when searching for -lstdc++

/usr/bin/ld: cannot find -lstdc++

Soln : sudo ln -s /usr/lib32/libstdc++.so.6 /usr/lib32/libstdc++.so


btw if you get the permission denied error still , do the following

chmod -Rf 777  <android_SRC>

Sunday, September 16, 2012

Something about freind in C++

There are some threads debating about friend class , is violating encapsulation (one of the important oops concept). there are some genuine case where we need friend ..

Before that we will discuss about the friend class  .. not much   briefly  :)

well, A very good name given to this concept by the inventor. In general , we are sharing our personal (private) data to our friends only  . Similarly A Class can share its  private data to its friend class .

   lets look at this code

    class nanban;

   class dude
    {
    int data ;
    friend class nanban;
    } ;


now , nanban class has the privilege to access dude class's private data ..

Coming to the point , where it can be used

  Unit testing
       To accomplish this , we need to write some additional piece of code to test the main code . There we can't write additional function for this purpose .
lets take the above example

dude class only contains data (by default it is private) , I want to test the value of data from the testing framework , Instead of writing a public function (introducing function increases .exe size) which will return the value of data , I am making nanban class as friend of dude .So that I can get the value directly. 

   Well , thats it . any quires !!!

 

Thursday, August 30, 2012

Calling a function using NULL object

#include <iostream.h>
#include <conio.h>

  class base 
    {
     int a ;
     public:
     
       void displaySomething()
       {
       cout<< "displaySomething"<<endl ;                   
       } 
  
      void displayMember()
      {
       cout<< a;    
       }
                
      };

  main()
  {
   base * obj = NULL ;
   obj->displaySomething();
   obj->displayMember();
     getch();
     }


Check out the above simple pgm , before running it  .. just think , where the app will crash??
 1. will it crash in obj->displaySomething(); 
 2. obj->displayMember();
 3.  cout<< a;  

run the program 

Are you surprised !!!    

here lesson is , to call the function , we don't need concrete object  (btw , this functions are stored in code segment) .

when we are trying to call "a" which is not available in memory , then app leads to crash   

(Note :  In 3rd party or Native application , we are writing logs at the  beginning and end of the function       for debug purposes . there may be some cases, we will get crash logs , showing only beginning of the function . At this point we are start focusing on the function but null object could be the reason crashing )

However it is a good pgm to know about the data and code segment .

Monday, August 27, 2012

Reversing singly Linked List - Explanation

I have searched some sites to know how they are reversing linked list , yeah I found so many sites but none of them are explained . So , I conclude it  to do in my blog



Below are the working piece of code 

#include <iostream.h>
#include <conio.h>

class Node
{
  public:
      int data ;
      Node * next ;
      Node(int in){data = in; }     // public param cons
   
      };



Node* Reverse(Node * head )
 {
          Node * temp = NULL ;
          Node * np = NULL;
       
        while (head)
          {
           temp = head->next;
           head->next = np;
           np = head ;
           head = temp;    
       
          }
          return np ;
           
 }


  void Display(Node * head )
   {
      while (head)
      {
       printf("%d \t" , head->data);
       head = head-> next ;  
      }
   }



main()
{
   Node * obj1= new  Node(10) ;
   Node * obj2= new  Node(20) ;
   Node * obj3= new  Node(30) ;
   Node * obj4= new  Node(40) ;
 
   obj1->next = obj2 ;
   obj2->next = obj3 ;
   obj3->next = obj4 ;
 
   printf("Before reversing ");  
   Display(obj1);  
     
   Node * head =  Reverse(obj1);
 
   printf("\n After  reversing ");  
   Display(head);
   getch();  
     
}



Lets see the explanation of Important lines 
  before getting in to that , you need two variable
1. temp -> used to hold next element pointer and given back the address to head
2. np    -> Assign it to head->next

lets discuss the code line by line

step1 :        temp = head->next;  
 take the information of next , so that we can play with head->next

step2:        head->next = np ;
 yeah , In the next line we are changing head->next  ( anyway we are having this info in temp   for later use)
initially np  is null , but from the second iteration it has the info of prev element

step3:       np = head ;
yeh , this step does the same what we want in step 2

step4:    head = temp ;

finally head should move to next element . fortunately this info is stored in temp 


thats all dudes , np will become your new head pointer .

 It may not be the great explanation , but it will be used to the beginners .
 


Sunday, August 26, 2012

Template

we are going to discuss about the template 

Template is a skeleton for which we are going to give different body .



where it can be used

one important thing comes in to my mind ... that is logs 

I have written one third party app , also it has one log to write some important logs 

well, the input param could be either int , string  ,double  or float .. I guess , for logs we are not using more than this primitive 

Code

template <class T>

void log_function(T in , const char* tag)
 {
 cout<<tag << "\t" << in ;
}

see , how good it is , otherwise we are going to write a overload function which will take the different data type 


by the way , when call is made 

Ex:    log_function(15 ,"TAG LINE");
         log_function("hello world" ,"TAG LINE");
         log_function(15.45 ,"TAG LINE"); 

compiler generates function for each data type . So, it internally does the overloading :) 

good news is , we can avoid manual mistakes 

STACK

STACK is the one of the important data structure in the computer science world .
every one should know , how stack DS is implemented in program .

Lets see the below code


int add(int a ,int b)
{
  return a+b ;
}

add(3,5) ;  


when add is getting called , we should know ,what is happening internally and what are the information is storing in stack .


If you realize this , then you can understand the risk of using recursive function :)

well, from the above , you can infer , why thread needs separate Stack .

Stack is very simple but from that you can learn more


by the way , Don't think  Stack  is different memory . It is same as Heap , Both memory (Heap and Stack ) taken from RAM .
Small amount of memory is separated and it is surrounded by the Stack DS .  




Tuesday, August 14, 2012

Singleton Pattern

Singleton is one of the important design pattern in software development

Main objective of this pattern is , to create single instance of the  class  . Lets see how we are achieving that



class singleton
{
 private
   singleton() {}  

public:
  static singleton* CreateInstance() {

     if(!instance )
     {
     instance  = new singleton() ;
      }
   
    return instance  ;
   }

static singleton* instance ;

}


Important things you must know :

 1. Why Constructor is private
     -> So that , other class (outside of this class )  can't create the object .
                   

2. Why we need static function  ie  static singleton* CreateInstance()
   ->  From first point , it is clear ,we can't create object of the class . So, static is the only way we can call function with out creating object of the class

3.  Why member is static
   ->  As it is used inside the static function , It should be static
    just google it , you will get more details about it


Advantage :
 Using this pattern you are maintaining only one instance of this class

Setback :
  1. This object is alive as long as application is alive

Thursday, July 26, 2012

List of Permission in android

<uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCOUNT_MANAGER" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.BIND_APPWIDGET" />
<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" />
<uses-permission android:name="android.permission.BIND_INPUT_METHOD" />
<uses-permission android:name="android.permission.BIND_REMOTEVIEWS" />
<uses-permission android:name="android.permission.BIND_WALLPAPER" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BRICK" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />
<uses-permission android:name="android.permission.BROADCAST_SMS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.BROADCAST_WAP_PUSH" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
<uses-permission android:name="android.permission.CLEAR_APP_USER_DATA" />
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />
<uses-permission android:name="android.permission.DELETE_CACHE_FILES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
<uses-permission android:name="android.permission.DIAGNOSTIC" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.DUMP" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.FACTORY_TEST" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.FORCE_BACK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.GLOBAL_SEARCH" />
<uses-permission android:name="android.permission.HARDWARE_TEST" />
<uses-permission android:name="android.permission.INJECT_EVENTS" />
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_APP_TOKENS" />
<uses-permission android:name="android.permission.MASTER_CLEAR" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.MOUNT_FORMAT_FILESYSTEMS" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" />
<uses-permission android:name="android.permission.READ_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.READ_INPUT_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER" />
<uses-permission android:name="android.permission.SET_ALARM" />
<uses-permission android:name="android.permission.SET_ALWAYS_FINISH" />
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE" />
<uses-permission android:name="android.permission.SET_DEBUG_APP" />
<uses-permission android:name="android.permission.SET_ORIENTATION" />
<uses-permission android:name="android.permission.SET_POINTER_SPEED" />
<uses-permission android:name="android.permission.SET_PROCESS_LIMIT" />
<uses-permission android:name="android.permission.SET_TIME" />
<uses-permission android:name="android.permission.SET_TIME_ZONE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
<uses-permission android:name="android.permission.SIGNAL_PERSISTENT_PROCESSES" />
<uses-permission android:name="android.permission.STATUS_BAR" />
<uses-permission android:name="android.permission.SUBSCRIBED_FEEDS_READ" />
<uses-permission android:name="android.permission.SUBSCRIBED_FEEDS_WRITE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_APN_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />