Saturday, May 21, 2011

VPTCL Wireless: Connect to internet using VPTCL from Ubuntu 10.04


PTCL DSL is great. Its cheap and offers good (reasonable) speed. But PTCL landlines are very untrustworthy and you never know when it will stop working. So I keep VPTCL as my backup internet connection. It is not fast but it works and has almost no down time. PTCL provides drivers and documentation for connecting to internet with VPTCL but everything is for Windows. So you are at loss if you are a Linux user. But dont worry, its really easy to connect VPTCL from linux especially Ubuntu. Basically the driver is there (usb-serial), so all you need is a dialer to connect to internet. Wvdial is a good tool for dialing different PPP connections. Earlier I have written about connecting to Windows VPN using it. To install Wvdial use the following command:
sudo apt-get install wvdial  
after the installation is complete, open file /etc/wvdial.conf and add following lines to its end:
[Dialer VPTCL]
Modem = /dev/ttyUSB0
Baud = 230400
Phone = #777
Init1 = ATZ
Stupid Mode = 1
Dial Command = ATDT
Username = vwireless@ptcl.com
Password = ptcl
PPPD Options = lock noauth refuse-eap refuse-chap refuse-mschap nobsdcomp nodeflate
Now save and close the file. You will need sudo rights for installing wvdial and editing the conf file.
Now from terminal issue the following command:
wvdial VPTCL 
Wvdial will connect to internet using VPTCL. You will get the connection information in the terminal after issuing this command i.e DNS servers and other stuff. Don't close the terminal as this will disconnect you from internet. Only close it when you want to disconnect. Pressing Ctrl-C in terminal will also end wvdial and disconnect you from internet.

Note: PTCL charges 2 rupees per 20 minutes for VPTCL internet service.

Friday, May 6, 2011

Android: "Application not installed" error when trying to install an app from sdcard


When programming for Android using Eclipse + ADT plugin, whenever you build your app, your application's installable file (.apk) is created in Bin directory under the project folder. This apk file can be used to test your application on any Android device. Recently when I wanted to test my app, I decided to use the export wizard to export an apk file instead of using the one created in Bin directory. So I just ran the export wizard and exported my app without signing it. To my surprise I wasnt able to install my app on the device although I had enabled all the required options on the phone to be able to install apps outside the market. The error I got was not very informative. It simply said
Application not installed.
Now that is not very usefull, is it?

After little googling I found out that even with Unknown Sources enabled, the app needs to be signed. Now the question is why dont I get this message when I try the file created by ADT Plugin in Bin directory. After a little more googling I found out that the apk file in Bin directory is signed by a default key and hence can be used for testing on the phone but apps signed with default key are not accepted in the Android Market. So if you want to submit your app to Market you need to sign it with your private key. More information on signing your application can be found here.
To find out how to use standard Java SDK tools to sign your application you can read this post.

How to enable ARM1136JFS (ARM v6) MMU to have one to one mapping between physical and virtual address space?

Sometime ago I wanted to enable L2 cache on an ARM1136-JFS based processor. The problem with this ARM core is that you cant enable L2 cache without enabling MMU and enabling MMU means to have a physical to virtual address mapping. But I didnt need any virtual memory and only wanted to enable L2 cache. The only way that I could think of was to create a one-to-one physical-to-virtual address mapping so that I could use L2 cache. The code that I wrote, after reading uboots source code, is given below.

/* Setup types for virtual addresses, physical address, and the page table. */
typedef unsigned long vaddr_t;
typedef unsigned long paddr_t;
typedef unsigned long pde_t;

/* Reserve space for a page directory. Must be 16k aligned. */
pde_t page_directory
[1 << 12] ALIGNED(1 << 12);

/* Create a 1MB mapping in the given page directory from 'virt' to 'phys'. */
void set_large_page_mapping(pde_t *pd, vaddr_t virt, paddr_t phys)
{
    pde_t entry
= 0;
    entry
|= phys & 0xfff00000; /* Target of the mapping. */
    entry
|= 2;                 /* This is a 1MB section entry. */
    entry
|= 1 << 4;            /* Enable caches (C). */
    entry
|= 1 << 3;            /* Enable writeback (B). */
    entry
|= 3 << 10;           /* Full read/write permission. */
    pd
[virt >> 20] = entry;     /* Install the entry. */
}

/* Setup a page directory with one-to-one physical/virtual mappings. */
void setup_one_to_one_mappings(void)
{
   
unsigned long i;

   
/* Setup a mapping for each 1MB region in the virtual address space. */
   
for (i = 0; i < (1 << 12); i++) {
       
/* Map the virtual address "i << 20" to phys address "i << 20". */
       set_large_page_mapping
(page_directory, i << 20, i << 20);
   
}

   
/* TODO: Write function to install this page directory and enable the MMU. */
    enable_mmu
(page_directory);
}

 

Monday, May 2, 2011

Android: How to sign your application

If you want to install and run your Android app on your phone or if you want to market it, you need to sign your app. Signing apps helps prevent the user from fraudulent apps. Signing your app is simple and can be done with standard tools i.e keytool and jarsigner that come with a Java JDK. To sign your app first generate a valid key. You can use the following command for that purpose:

 keytool -genkey -v -keystore my-android-key.keystore -alias my_alias -keyalg RSA -validity 10000  

This will generate a file named my-android-key.keystore in the current directory. This file contains the key that you can use to sign your apps. If you want you can move this key to more appropriate location.

Now you need to sign your app using this key. This is done using the jarsigner utility from JDK. Given below is the command line you can use to sign your app i.e the .apk file with the above generated key:

 jarsigner -verbose -keystore /path/to/my-android-key.keystore  MYAPP.apk my_alias

And thats it. Your app is signed and ready to be used.

Saturday, April 30, 2011

Android Tabbed Layout with single activity.

In Android, the content for each tab in a Tab Layout can be implemented in one of two ways:
1. Use tabs to switch views within the same activity.
2. Use tabs to switch between different activities.
The tutorial in the Android documentation shows how to do it the 2nd way i.e use tabs to switch between activities but I couldnt find a reasonable example of the first case so I have created one and the contents for layout .xml file and the source .java files are given below.







Layout file
 <?xml version="1.0" encoding="utf-8"?>  
 <TabHost xmlns:android="http://schemas.android.com/apk/res/android"  
      android:id="@android:id/tabhost"   
      android:layout_width="fill_parent"  
      android:layout_height="fill_parent">  
      <LinearLayout android:orientation="vertical"  
           android:layout_width="fill_parent"   
           android:layout_height="fill_parent"  
           android:padding="5dp">  
           <TabWidget android:id="@android:id/tabs"  
                android:layout_width="fill_parent"   
                android:layout_height="wrap_content"   
                />  
           <FrameLayout android:id="@android:id/tabcontent"  
                android:layout_width="fill_parent" android:layout_height="fill_parent"  
                android:padding="5dp">  
                <LinearLayout android:id="@+id/layoutTab1"  
                     android:orientation="vertical"   
                     android:layout_width="fill_parent"  
                     android:layout_height="fill_parent">  
                     <TextView android:layout_width="fill_parent"  
                          android:layout_height="wrap_content"   
                          android:text="this is tab1. you can add whatever controls you want inside this Linear layout." />  
                </LinearLayout>  
                <LinearLayout android:id="@+id/layoutTab2"  
                     android:orientation="vertical"   
                     android:layout_width="fill_parent"  
                     android:layout_height="fill_parent">  
                     <TextView android:layout_width="fill_parent"  
                          android:layout_height="wrap_content"   
                          android:text="this is tab2. you can add whatever controls you want inside this Linear layout." />  
                </LinearLayout>  
           </FrameLayout>  
      </LinearLayout>  
 </TabHost>  

Java Source File
 package com.example;  
 import android.app.TabActivity;  
 import android.content.res.Resources;  
 import android.os.Bundle;  
 import android.widget.TabHost;  
 public class ExampleTabLayout extends TabActivity {  
      @Override  
      public void onCreate(Bundle savedInstanceState) {  
           super.onCreate(savedInstanceState);  
           setContentView(R.layout.main);  
           res = getResources();  
           TabHost tabHost = getTabHost();  
           TabHost.TabSpec spec;  
           spec = tabHost.newTabSpec("status").setIndicator("Status").setContent(R.id.layoutTab1);  
           tabHost.addTab(spec);  
           spec = tabHost.newTabSpec("actionitems").setIndicator("Action Items").setContent(R.id.layoutTab2);  
           tabHost.addTab(spec);  
           tabHost.setCurrentTab(0);  
      }  
      protected Resources res;  
 }  

Tuesday, March 29, 2011

Install Firefox 4 in Ubuntu

Firefox 4 is available for Ubuntu 10.04 and 10.10. To install it use the following commands

sudo add-apt-repository ppa:mozillateam/firefox-stable
sudo apt-get update
sudo apt-get upgrade

This will update your Firefox to version 4. Note that this will not install Firefox 4 side by side with your previous version as used to be the case with beta versions. As this installs the stable release version of Firefox so your previous version will be removed and after installation you will only have Firefox 4.0.

Tuesday, March 1, 2011

git bare repos

A normal git repository is a directory that contains:
  1. Our files: Files and directories that we have created and which contain our data. These files and directories are collectively known as working tree.
  2. .git directory: This folder contains all of the Git's control files.
A bare git repository does not have working tree and it also does not have .git directory either. All of the Git's control and management files are present in the directory directly. You can not checkout from a bare repository or commit to it.

So what are they useful for when you cant checkout or commit to them?

Bare Git repos are good for pushing and pulling only and they are designed this way so that they can be used as common shared repo by a group of people. So any one want to make changes makes a clone of that bare repo, makes changes in that cloned repo, commit them there and then push the changes to bare repo. Now any one wanting those changes can pull them from the bare repo.

To create and initialize a new bare git repo you can use the command:
git --bare init
and to clone an existing repo as a bare repo use:
git clone --bare