Sunday, June 29, 2014

How to Submit android app to Amazon app store

If you are new to android development and specifically planning to launch your app to Amazon app store. Then you must be feeling a little bit left behind, because there you won't find much over net apart from Amazon's own material. 

Although it is mentioned on their site clearly, I thought of repeating it, because it will just some one else to find the right thing :

So if you want to add the ad api so here is the way : 

1.  Download sdk from here.
2.  Now add the Jar in Eclipse using Install New Software. After that add this link as name Amazon.
3.  Now Import your android project, remove all the google play service api from it, and add Amazon api. To do that right click on your project, and click on Properties. And then in that click on Amazon Mobile app SDK. 
4. There you can select whatever you want to use, Mobile Ads, ADM, In-App purchasing etc.
5. Now it comes to the coding part. Wherever you want to use it, include the following code :

AdRegistration.setAppKey("37de83fd21234ed4811e241507876542F"); // put your Application id
    
   this.adView = (AdLayout) findViewById(R.id.adview);
   
   AdTargetingOptions adOptions = new AdTargetingOptions().enableGeoLocation(true);
   // Optional: Set ad targeting options here.
   this.adView.loadAd(adOptions); // Retrieves an ad on background thread

And you have to create corresponding entry in xml :

 
    android:id="@+id/adview"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"/>

6. And you are good to go. 
7. Use Test your app option on Amazon before uploading your apk to Amazon app store.

I hope this blog help you to publish your first App on Amazon app store.

Thursday, June 26, 2014

Android : How to Check whether device is rooted or not ?

Many time user go for rooting their phone to break the constraints put by operator and OEMs. 
So Rooting your phone opens a door of new features which could be really useful. 

To root your phone, I will suggest you to go to Xda developers. They have wide range of tutorial specifically for each devices. So once you have followed their steps, and just wanted to confirm whether your device has been rooted, Here is a simple app called Root Verifier Pro Launched by Bitdroid Devz

I will suggest you to try it, it worked fine for me. 

Thursday, June 19, 2014

HWComposer : Android Surface Composition Logic Module

After my last post of SurfaceFlinger few people asked me to write on HWcomposer, which is tightly associated with SurfaceFlinger. 
I here would like to mention that Google's Graphics Architecture link helped me a lot.  So I will be mentioning many of those points here again.
So here we go 

HWComposer(HWC)'s primary purpose is to determing the most efficient way to composite buffers with the available hardware.
You can easily recognize the value of HWC, when you consider "overlay planes". The purpose of overlay planes is to composite the multiple buffers together, but in the display hardware(MDP in case of QCom) rather than the GPU. You can refer this link for diagram.

The mentioned link describes it very well, it goes like :
In General you have three buffers for Android screen at a time, one for Status bar, second for Navigation bar and third for Application. So instead of compositing all three buffers, SurfaceFlinger pass these buffers to Display Hardware to process. So HWC works like this :

  • SurfaceFlinger provides the HWC with a full list of layers, and asks, "how do you want to handle this?"
  • The HWC responds by marking each layer as "overlay" or "GLES composition."
  • SurfaceFlinger takes care of any GLES composition, passing the output buffer to HWC, and lets HWC handle the rest.

  • Now as mentioned in 3rd point, Surfaceflinger passes the output buffer to HWC. This is quite useful when there is no update in the screen. In this scenario, HWC can choose GLES composition for those buffer. Because of this, When Surfaceflinger comes up with the same set of buffers(as no screen is changed), HWC can just continue to show the previously composite buffer.

    Code Flow:

    Linking of hwc module :

    SurfaceFlinger::init() -> HWComposer() -> loadHWCModule() -> hwc_open_1 -> (module->methods-->open) ->open() [defined in hwc.cpp]

     Now whenever Surfaceflinger have new buffers to update, it calls setupHWComposer(). This function is used to get all layers, using 
    currentLayers = hw->getVisibleLayersSortedByZ();

    after setting the data, it calls prepare()  which in turns call prepare()[hwc.cpp][I will definde the details of this function later].

    After all processing and composition is done, we call postFrameBuffer(), it calls commit() and finally hwc::set(). Which goes like this :

    hwc::set() -> hwc_set_primary() -> (mFbUpdate->draw())* -> ov.queueBuffer() -> GenericPipe::queueBuffer() -> Data:queueBuffer()(OverlayCtrlData.h) -> MdpData:play()(overlaymdp.h) -> play()(MdpWrapper.h) ->ioctl(fd,MSMFB_OVERLAY_PLAY,offset)

    this fd and offset it is getting from 
    fbLayer = &list->hwLayers[last];
    hnd = (private_handle_t *) fbLayer->handle;


    after (mFbUpdate->draw()) calls finishes, flow goes like 
    (Overlay->displayCommit()) -> displayCommit()(Overlay.cpp) -> displayCommit()(MdpWrapper.h) -> ioctl(fd, MSMFB_OVERLAY_COMMIT, info)

    After this lcd driver starts doing the final task.

    Now lets understand what prepare() function do. 

    prepare is called for each frame before composition and is used by SurfaceFlinger to determine what composition steps the HWC can handle. 
    The HWC responds by setting the compositionType field in each layer to either HWC_FRAMEBUFFER or HWC_OVERLAY.
    In case of HWC_FRAMEBUFFER, composition is handled by SurfaceFlinger using OpenGL ES, in later case HWC will have to handle the layer's composition.

    Now other important function in hwc.cpp is set(). When this call returns the caller assumes that the display will be updated in the near future with the content of their work list.



    Wednesday, June 11, 2014

    difference between Kernel Thread and User thread

    1. Kernel threads run only in Kernel Mode, while regular processes run alternatively in Kernel Mode and in User Mode.

    2. Because kernel threads run only in Kernel Mode, they use only linear addresses greater than PAGE_OFFSET. Regular processes, on the other hand, use all four gigabytes of linear addresses, in either User Mode or Kernel Mode.

    Process 0 :
    This is the ancestor of all processes, also known as the idle process. it is a kernel thread created from scratch during the intialization phase of linux. This ancestor proces uses the following statically allocated data structures.

    1. A process descriptor stored in the init_task variable, initialized by the INIT_TASK macro.
    2. A thread_info descriptor and a Kernel Mode stack stored in the init_thread_union variable and initialized by the INIT_THREAD_INFO macro.
    3. The following tables, which is the process descriptor points to:

    - init_mm ( initialized by INIT_MM)
    - init_fs (initlialized by INIT_FS)
    - init_files (initlialized by INIT_FILES)
    - init_signals(initialized by INIT_SIGNALS)
    - init_sighand(initialized by INIT_SIGHAND)

    4. The master kernel Page Global Directory stored in swapper_pg_dir.

    The start_kernel() function intializes all the data structures needed by the kernel enables interrupts, and creates another kernel thread, named process 1 (known as init process).

    After creating init process, Process 0 is selected by scheduler only when there are no other processes in the TASK_RUNNING state.

    For multiprocessor system, there is a process 0 for each CPU.

    Monday, June 2, 2014

    Check if a character link list is palindrome or not.

    Hi Folks,

    Here is my implementation for checking whether link list is palindrome or not.

    #include <iostream>
    #include <stack>
    #include <cstdlib>

    struct node
    {
    int data;
    struct node *next;
    };

    using namespace std;

    struct node *head;

    void addNode(int data)
    {
    struct node *temp;
    temp = (struct node *) malloc(sizeof(struct node));
    temp -> next = NULL;
    temp->data = data;

    if(head == NULL)
    head = temp;
    else
    {
    struct node *head1;
    head1 = head;
    while(head1 ->next != NULL)
    {
    head1 = head1->next;
    }
    head1->next = temp;
    }
    }


    int main()
    {
    int N;
    cin >> N;

    for(int i=0;i<N;i++)
    {
    int temp;
    cin >> temp;
    addNode(temp);
    }

    struct node *slow, *fast;
    stack<int> stk;

    slow = head;
    fast = head;

    while(fast->next != NULL)
    {
    stk.push(slow->data);
    slow = slow->next;
    fast = fast->next;
    if(fast->next != NULL)
    fast = fast->next;
    }

    if(N %2 != 0)
    slow = slow->next;
    while(!stk.empty())
    {

    // cout << (stk.top()) <<" " << (slow->data) <<endl;
    if(stk.top() == slow->data)
    {
    slow = slow->next;
    stk.pop();
    }
    else
    {
    cout <<"No Pallindrome" <<endl;
    return false;
    }
    }

    cout <<"Pallindrome" <<endl;//return true;
    }

    Sunday, June 1, 2014

    Generate all combination of elements of an array : Power Set Algorithm

    #include
    #include
    #define MAX 100010
    using namespace std;

    int arr[MAX];

    void powerset(int arr[], vector v, int start, int end)
    {
    if(start > end)
    return;
    v.push_back(arr[start]);
    vector::iterator i;
    for(i = v.begin(); i
    {
    cout << *i;
    }
    cout << "\n";

    powerset(arr,v,start+1,end);
    v.pop_back();
    powerset(arr,v,start+1,end);

    }

    int main()
    {
    int T,N;
    cin >> T;
    while(T-- > 0)
    {
    cin >> N;

    for(int i=0;i
    cin >> arr[i];
    vector v;
    powerset(arr,v,0,N-1);
    }
    return 0;
    }