2010年11月27日 星期六

[Android] Install Android market in Android emulator 2.2

使用SDK下載回來的avd:
1.Download Android market apk
$ wget http://goo.gl/dz3ZB
2.Create froyo AVD
$ android create avd --target 8 --name froyo
3.Start emulator
$ emulator -avd froyo -partition-size 96
3.Modified build.prop and comment "ro.config.nocheckin=yes"
$ adb pull /system/build.prop
$ vim build.prop
#ro.config.nocheckin=yes
4.Restore to system
$ adb remount /system
$ adb push build.prop /system
5.Remove SdkSetup.apk
$ adb shell rm /system/app/SdkSetup.apk
$ adb push GoogleServicesFramework.apk /system/app
$ adb push Vending.apk /system/app
6.Shut down the emulator
$ adb reboot
7.Remove emulator image
$ cd /path/to/avd
$ rm userdata-qemu.img userdata.img cache.img
8.Restart emulator


使用自己編出來的system.img:
1.直接安裝Vending.apk和GoogleServicesFramework.apk就好了
$ adb install GoogleServicesFramework.apk
$ adb install Vending.apk
2.Restart emulator

reference:
* [Android]在SDK 2.2模擬器中安裝Market

2010年11月26日 星期五

[Security] 看雪論壇十週年

大陸最有名的資訊安全論壇看雪論壇中秋禮物(當然還有很多有名的論壇,比如說邪惡八進制等...),裡面有很多好東西,先備份一下,未來再慢慢研究吧...

順道一提完全無關的事,就是剛好在備份的時候發現,不同的壓縮演算法其實壓縮比差蠻多的,我是比了bzip2,rar,gzip,zip四種格式而已(使用預設壓縮比率)
-rw-r--r--  1 44768826 2010-11-24 11:11 pediy.tar.bz
-rw-r--r--  1 47059808 2010-11-24 11:25 pediy.rar
-rw-r--r--  1 45356338 2010-11-24 11:27 pediy.tar.gz
-rw-r--r--  1 45355127 2010-11-24 11:18 pediy.zip
這四種格式看起來是bzip2的壓縮效率最好,雖然沒有在網路上找到壓縮比的評比來實證,但wikipedia還是有列出一些其他方面的比較

2010年11月23日 星期二

[Tips] Tips to make Ubuntu faster

最近遇到問題是檔案夾開啟的速度非常緩慢,就看看是否有什麼方法可以調整一下Ubuntu的效能,目前照網路上常見的幾招來改,看起來效果不錯: )

1.更改置換檔(swap)使用率設定
$ sudo vim /etc/sysctl.conf
新增一行
vm.swappiness=10
重啟sysctl讓設定生效
$ sudo sysctl -p

2.使用readahead(不用設定)
$ sudo apt-get install readahead

3.使用localepurge清除不需要的語言檔
$ sudo apt-get install localepurge

4.使用Preload(不用設定)
$ sudo apt-get install preload

5.使用Prelink
$ sudo apt-get install prelink
修改設定
$ sudo vim /etc/default/prelink
新增一行
PRELINKING=yes
執行cron
$ /etc/cron.daily/prelink

6.關閉不需要的Gnome作業階段
System -> Preferences -> Startup Applications

7.關閉不必要的系統服務(Service)
sysv-rc-conf修改不同runlevel服務啟動的狀態
$ sudo apt-get install sysv-rc-conf
$ sudo sysv-rc-conf

8.同步啟動(Concurrent Booting)
修改啟動的rc設定檔
$ sudo vim /etc/init.d/rc
修改CONCURRENCY從none改為shell
CONCURRENCY=shell

有些設定還沒完全瞭解原理,之後碰到再寫清楚吧

reference: Ubuntu 進階優化和調校

2010年11月22日 星期一

[Android] Build Android bootchart

bootchart是一套可視覺化分析GNU/Linux啟動過程的工具,它可蒐集啟動的資訊,並產生PNG/SVG/EPS等格式的圖檔,提供我們做進一步的效能分析,以下簡述安裝過程:

1.安裝bootchart工具
$ sudo apt-get install bootchart

2.重新編譯init(讓init支援bootchart)
切換到Android source code目錄下
$ cd /path/to/android
改變init系統時間
$ touch system/core/init/init.c
載入Android bash工具
$ . build/envsetup.sh
編譯init模組
$ m INIT_BOOTCHART=true
啟動機器
$ emulator -system {/path/to}/system.img -data {/path/to}/userdata.img -ramdisk {/path/to}/ramdisk.img
設定init的time out
$ adb shell 'echo 180 > /data/bootchart-start'
$ adb shell 'mkdir /data/bootchart'

3.重新啟動機器
$ adb reboot

4.重新開機完成後檢視是否有紀錄
$ adb shell ls /data/bootchart
header
kernel_pacct
proc_diskstats.log
proc_ps.log
proc_stat.log

5.下載開機紀錄
$ cd /whatever/path
$ adb pull /data/bootchart/header
$ adb pull /data/bootchart/kernel_pacct
$ adb pull /data/bootchart/proc_diskstats.log
$ adb pull /data/bootchart/proc_ps.log
$ adb pull /data/bootchart/proc_stat.log

6.產生bootchart.tgz
$ {path/to/android}/system/core/init/grab-bootchart.sh

7.產生bootchart圖檔
$ java -jar /usr/share/bootchart/bootchart.jar bootchart.tgz
Parsing /tmp/android-bootchart/bootchart.tgz
Wrote image: ./bootchart.png


如果沒有/usr/share/bootchar/bootchart.jar這個檔案,可以在這裡取得source,解開後執行ant將會編出bootchart.jar

reference:
* Build Android Bootchart
* Using Bootchart on Android

2010年11月20日 星期六

[Android] Modify ramdisk.img on Android

ramdisk.img
A small partition image with gzipped cpio archive that is mounted read-only by the kernel at boot time. It only contains /init and a few config files. It is used to start init which will mount the rest of the system images properly and run the init procedure. A Ramdisk is a standard Linux feature.

system.img
A partition image that will be mounted as /system and thus contains all system binaries

userdata.img
A partition image that can be mounted as /data and thus contains all application-specific and user-specific data.

Here is the steps:
1.Change directory to whatever/path
$ cd whatever/path
2.Copy the original ramdisk.img
$ cp /path/to/ramdisk.img .
3.Create a temporary folder, say ramdisk-ext
$ mkdir ramdisk-ext
4.Change directory to ramdisk-ext
$ cd ramdisk-ext
5.Extract the ramdisk.cpio in the ramdisk-ext folder
$ gunzip -dcv ../ramdisk.img | cpio -idm
6.Check out the directories in ramdisk.img
$ ls
data          dev   init.goldfish.rc  proc  sys
default.prop  init  init.rc           sbin  system
7.Do some modifications
$ touch foo
$ mkdir bar
8.Recreate the ramdisk.cpio
$ find . | cpio -H newc -o | gzip -9 >../ramdisk.img
9.Start the emulator
$ emulator -system system.img -data userdata.img -ramdisk ramdisk.img
10.Check out the directories in the emulator
$ adb shell ls -l
drwxrwxrwt root     root              2010-11-26 16:54 sqlite_stmt_journals
drwxrwx--- system   cache             2010-11-26 16:54 cache
d--------- system   system            2010-11-26 16:54 sdcard
lrwxrwxrwx root     root              2010-11-26 16:54 etc -> /system/etc
drwxr-xr-x root     root              2010-11-15 07:33 system
drwxr-xr-x system   system            2010-11-26 16:53 bar
drwxr-x--- system   system            2010-11-26 16:52 sbin
-rwxr-x--- system   system       1677 1970-01-01 00:00 init.goldfish.rc
dr-xr-xr-x root     root              1970-01-01 00:00 proc
-rw-r--r-- system   system          0 2010-11-26 16:52 foo
-rwxr-x--- system   system     106696 1970-01-01 00:00 init
-rwxr-x--- system   system      10700 1970-01-01 00:00 init.rc
drwxr-xr-x root     root              1970-01-01 00:00 sys
-rw-r--r-- system   system        118 1970-01-01 00:00 default.prop
drwxrwx--x system   system            2010-11-16 09:04 data
drwx------ root     root              2009-08-07 03:35 root
drwxr-xr-x root     root              2010-11-26 16:54 dev

gunzip options:
-c, --stdout      write on standard output, keep original files unchanged
-d, --decompress  decompress
-v, --verbose     verbose mode
-1, --fast        compress faster
-9, --best        compress better

cpio options:
-i, --extract                    Extract files from an archive (run in copy-in mode)
-d, --make-directories           Create leading directories where needed
-m, --preserve-modification-time Retain previous file modification times when creating files
-H, --format=FORMAT              Use given archive FORMAT
-c                               Use the old portable (ASCII) archive format
-o, --create                     Create the archive (run in copy-out mode)
-v, --verbose                    Verbosely list the files processed
-B                               Set the I/O block size to 5120 bytes
-u, --unconditional              Replace all files unconditionally

Examples:
  cpio -covB  > [file|device]<== Backup
  cpio -icduv < [file|device]<== Restore

"-H newc" use the new (SVR4) portable format. If you wish the old portable (ASCII) archive format, use "-H odc" instead. 

reference:
* Android ramdisk.img system.img userdata.img
* android ramdisk的壓縮與解壓縮

人肉搜尋

剛剛無聊,逛到一個我覺的還蠻人肉搜尋的網站,只要打上想要查詢的帳號,就可以搜尋到許多跟該帳號相關的資料
如果你的帳號比較特別的話,目標就很明顯了...

在網路上果然要匿名的好阿...

[Tips] screen教學

screen是非常好用的工具,男人告訴我們
screen - screen manager with VT100/ANSI terminal emulation

screen的指令都是以Ctrl鍵加上a鍵開始的,後面將以C-a代表按住Ctrl鍵+a鍵,後面將以"視窗"代表screen,基本使用到的指令大概如下:

進入screen模式
$ screen

建立screen (同時切換到新視窗)
$ C-a c

查詢所有開啟的視窗號碼,列出*號表示目前所在視窗
$ C-a w
0-$ bash 1$ bash 2*$ bash

切換視窗(# 切換到第{1..9}個視窗)
$ C-a {1..9}

清除目前視窗內容
$ C-a c

查詢全部的視窗
$ screen -ls
There is a screen on:
13931.pts-6.ubuntu (11/20/2010 06:52:09 PM) (Attached)

脫離視窗
$ C-a d
There is a screen on:
13931.pts-6.ubuntu (11/20/2010 06:52:09 PM) (Detached)

連接視窗(根據screen -ls所顯示的號碼,連接到第{號碼}的視窗)
$ screen -r {號碼}
$ screen -r 13931
There is a screen on:
13931.pts-6.ubuntu (11/20/2010 06:52:09 PM) (Attached)

更多指令教學可參考這篇

[Android] 在Android shell以Dalvik VM執行Java應用程式

由於Android上的Java程式需要在Dalvik VM下才能執行,因此Android上的App就是透過Zygote去fork出child process去執行,但如果我們希望可以直接在Android的shell下執行Java應用程式,需要一些小技巧

1.撰寫Java測試程式HelloWorld.java
//
// HelloWorld.java
//
public class HelloWorld {
    public static void main(String args[]) {
        System.out.println("Hello World!!\n");
    }   
}

2.編譯HelloWorld.java
$ javac HelloWorld.java

3.將dx設在環境變數路徑
$ export PATH={path/to/sdk}/platforms/{android-platform-number}/tools:$PATH

4.以dx工具將bytecode轉成Dalvik executable format(.dex)格式的jar
$ dx --dex --output=helloworld.jar HelloWorld.class

5.上傳到模擬器
$ adb push helloworld.jar /data

6.在Android shell下執行
$ adb shell
# /system/bin/dalvikvm -cp /data/helloworld.jar HelloWorld
Hello World!!

2010年11月18日 星期四

[Tips] File sharing in Ubuntu through samba

要透過samba分享Ubuntu的檔案非常容易,不論是要分享給別人或是存取別人的分享都只要幾個步驟即可完成

分享給別人:
1.安裝smbd服務
$ sudo apt-get install smbfs
2.修改設定檔(範例)
$ vim /etc/samba/smb.conf
[share]
   comment = share folder
   path = /path/to/share
   browseable = yes 
   read only = no          # allow read/write
3.新增使用者
$ sudo smbpasswd -a [username]
4.重新啟動服務即可
$ sudo smbd restart

若要修改不同runlevel的啟動情形,先安裝sysv-rc-conf
$ sudo apt-get install sysv-rc-conf
要在runlevel 5自動啟動smbd服務
$ sudo sysv-rc-conf
service      1       2       3       4       5       0       6      S    
----------------------------------------------------------------------------    
smbd        [ ]     [ ]     [ ]     [ ]     [X]     [ ]     [ ]     [ ]  


存取別人的分享:
1.以GNOME為例
Places->Connect to Server...
2.選擇分享類型
Server Type: Windows share
Server: /ip/to/server
Folder: /name/of/share
User Name: /name/of/user
Domain Name: WORKGROUP # if connect to Windows


有關samba的常見參數設定可參考31.5. Configuration of the /etc/smb.conf file

[Tips] Pidgin invalid SSL certificate problem

這兩天pidgin一直出現這樣的錯誤訊息
Unable to validate certificate
The certificate for omega.contacts.msn.com could not be validated. The certificate chain presented is invalid.

根據OMGUbuntu的解決方法要這樣做,
1.用Firefox開啟https://omega.contacts.msn.com (有Directory Listing Denied錯誤訊息是正常的)
2.在Firefox頁面右下角有個"小鎖"的圖示,點擊該圖示
3.點選上方"Security"的Tab
4.點選"View Certificate"按鈕
5.點選右上方"Detail"的Tab
6.點選左下角"Export..."按鈕
7.將檔名更改為"omega.contacts.msn.com",並存成"X.509 Certificate with chain(PEM)"類型
8.將該憑證存到個人憑證目錄下
{/home/user}/.purple/certificates/x509/tls_peers/
9.重新登入即可

用pidgin好幾年了,第一次遇到這問題

2010年11月16日 星期二

[Tips] fdisk & fsck & mount usb stick in Ubuntu

隨手記...

1.先確定usb裝置是否有偵測到
$ lsusb
Bus 001 Device 042: ID 090c:6000 Feiya Technology Corp. SD/SDHC Card Reader (SG365 / FlexiDrive XC+)
如果沒有的話,就用dmesg查看Ubuntu把隨身碟辨認成什麼裝置
$ dmesg |grep usb

2.查詢目前掛載到的disk與裝置(/dev)的連結
$ ls -al /dev/disk/by-id/
lrwxrwxrwx 1 root root   9 2010-11-26 17:37 usb-Generic_USB2.0_Card_Reader_12345678901234567890-0:0 -> ../../sdb
查詢隨身碟的partition tables(非必要)
$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 2006 MB, 2006974464 bytes
62 heads, 62 sectors/track, 1019 cylinders
Units = cylinders of 3844 * 512 = 1968128 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
3.切成只有一個partition
$ sudo fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
查詢指令
Command (m for help): m
Command action
a   toggle a bootable flag
b   edit bsd disklabel
c   toggle the dos compatibility flag
d   delete a partition
l   list known partition types
m   print this menu
n   add a new partition
o   create a new empty DOS partition table
p   print the partition table
q   quit without saving changes
s   create a new empty Sun disklabel
t   change a partition's system id
u   change display/entry units
v   verify the partition table
w   write table to disk and exit
x   extra functionality (experts only)
4.建立新的partition(如果不是全新的disk)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
新增primary partition,起始磁柱為1,最後的磁柱為1019(default)
p
Partition number (1-4): 1
First cylinder (1-1019, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1019, default 1019): 
Using default value 1019
確認partition table
Command (m for help): p
Disk /dev/sdb: 2006 MB, 2006974464 bytes
62 heads, 62 sectors/track, 1019 cylinders
Units = cylinders of 3844 * 512 = 1968128 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1019     1958487   83  Linux
5.建立完成後寫入partition table
Command (m for help): w
如果順利的話,會出現這樣的訊息
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

如果出現
WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

解決方法如以下步驟
$ sudo fdisk /dev/sdb
Command (m for help): p

Disk /dev/sdb: 4005 MB, 4005560320 bytes
124 heads, 62 sectors/track, 1017 cylinders
Units = cylinders of 7688 * 512 = 3936256 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0f60e47c

   Device Boot      Start         End      Blocks   Id  System
建一個空的DOS partition table到隨身碟
Command (m for help): o

Building a new DOS disklabel with disk identifier 0x38e86b45.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
再次存檔
Command (m for help): w
寫入成功了
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
就再重切一次吧
$ sudo fdisk /dev/sdb
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1019, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1019, default 1019): 
Using default value 1019

Command (m for help): p

Disk /dev/sdb: 2006 MB, 2006974464 bytes
62 heads, 62 sectors/track, 1019 cylinders
Units = cylinders of 3844 * 512 = 1968128 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1019     1958487   83  Linux
建立完成後寫入partition table
Command (m for help): w
這次就寫入成功
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

6.接著是格式化隨身碟
假設掛載在/dev/sdb1的裝置希望格式化成ext2格式
$ sudo mkfs.ext2 /dev/sdb1
mke2fs 1.41.11 (14-Mar-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
122640 inodes, 489952 blocks
24497 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=503316480
15 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks: 
 32768, 98304, 163840, 229376, 294912

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: 
改變隨身碟的系統標籤(非必要)
$ sudo e2label /dev/sdb1 {label}
建立掛載點
$ mkdir {path/to/dir}
將隨身碟掛上
$ mount -t ext2 /dev/sdb1 {/path/to/dir}


有時候在資料讀取/寫入過程中,如果I/O沒有順利結束,就會發生錯誤,例如看到這樣的訊息
$ sudo mount /dev/sdb1 {/path/to/dir}
$ cd {/path/to/dir}
$ sudo rm -rf *
rm: cannot remove `data/system/batterystats.bin': Input/output error
rm: cannot remove `data/system/packages.xml': Input/output error
這時候就先umount隨身碟,用fsck進行修復,然後一路y到底
$ sudo umount /dev/sdb1
$ sudo fsck.ext2 /dev/sdb1
e2fsck 1.41.11 (14-Mar-2010)
/dev/sdb1 contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Entry 'batterystats.bin' in /data/system (24504) has deleted/unused inode 24604.  Clear? yes

Entry 'packages.xml' in /data/system (24504) has deleted/unused inode 24608.  Clear? yes

Pass 3: Checking directory connectivity
/lost+found not found.  Create? yes

Pass 4: Checking reference counts
Pass 5: Checking group summary information
Block bitmap differences:  -(16385--16733) -26624 -(110592--110600) -124933 -(151552--151553) -153601 -(278528--279183)
Fix? yes

Free blocks count wrong for group #0 (31663, counted=32013).
Fix? yes

Free blocks count wrong for group #3 (32004, counted=32014).
Fix? yes

Free blocks count wrong for group #4 (32253, counted=32256).
Fix? yes

Free blocks count wrong for group #8 (31600, counted=32256).
Fix? yes

Free blocks count wrong (959025, counted=960044).
Fix? yes

Inode bitmap differences:  -(15--16) -24602 -24608 -(65281--65299)
Fix? yes

Free inodes count wrong for group #0 (8147, counted=8149).
Fix? yes

Free inodes count wrong for group #3 (8156, counted=8158).
Fix? yes

Free inodes count wrong for group #8 (8141, counted=8160).
Fix? yes

Directories count wrong for group #8 (1, counted=0).
Fix? yes

Free inodes count wrong (244764, counted=244787).
Fix? yes


/dev/sdb1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdb1: 13/244800 files (0.0% non-contiguous), 17285/977329 blocks

2010年11月14日 星期日

[Java] RMI

名詞解釋:在RMI中,用戶端的helper稱為stub,而伺服器端的helper稱為skeleton, 示意圖
        (RMI STUB)   (RMI SKELETON)  
client    client<------>service     service
object    helper        helper      object

建構遠端服務(serice)
步驟一:建構Remote interface
* extend過java.rmi.Remote
* 宣告所有的method都會拋出RemoteException
* 確定參數與回傳值都是primitive或Serializable
import java.rmi.*;

public interface MyRemote extends Remote {
    public String sayHello() throws RemoteException;
}

步驟二:實做Remote
* 實做Remote這個interface
* extend過UnicastRemoteObject
* 撰寫宣告RemoteException的無參數constructor
* 向RMI registry登記服務
import java.rmi.*;
import java.rmi.server.*;

public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote {
    public String sayHello() {
        return "Server says, 'Hey'";
    }   

    public MyRemoteImpl() throws RemoteException {}

    public static void main(String[] args) {
        try {
            MyRemote service = new MyRemoteImpl();
            Naming.rebind("//127.0.0.1/Remote", service);
        } catch (Exception ex) {
            ex.printStackTrace();
        }   
    }   
}

步驟三:以rmic產生stub與skeleton
* 對實做出的class(非interface)執行rmic
$ rmic MyRemoteImpl

步驟四:啟動RMI registry(rmiregistry)
* 叫出命令列來啟動rmiregistry
$ rmiregistry

步驟五:啟動遠端服務
* 叫出另一個命令列來啟動服務
$ java MyRemoteImpl


建構用戶端(client)
* 用戶端查詢RMI registry
* RMI registry傳回stub物件
* 用戶端就像取用真正的服務一樣的叫用stub上的method
import java.rmi.*;

public class MyRemoteClient {
    public static void main(String[] args) {
        new MyRemoteClient().go();
    }   

    public void go() {
        try {
            MyRemote service = (MyRemote) Naming.lookup("rmi://127.0.0.1/Remote");
            String s = service.sayHello();

            System.out.println(s);

        } catch (Exception ex) {
            ex.printStackTrace();
        }   
    }   
}

注意事項:
* RMI在網路間的傳遞過程一樣使用socket
* 啟動遠端服務之前需先啟動rmiregistry
* client端需要有service端的stub和interface(*.class)

範例來自深入淺出Java程式設計

2010年11月10日 星期三

[Tips] Run Android application from command line

syntax:
# am start -a android.intent.action.MAIN -n package/class_fullname

example:
# am start -a android.intent.action.MAIN -n my.demo/my.demo.HelloWorld

usage:
usage: am [subcommand] [options]

    start an Activity: am start [-D] [-W] 
        -D: enable debugging
        -W: wait for launch to complete

    start a Service: am startservice 

    send a broadcast Intent: am broadcast 

    start an Instrumentation: am instrument [flags] 
        -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
        -e  : set argument  to 
        -p : write profiling data to 
        -w: wait for instrumentation to finish before returning

    start profiling: am profile  start 
    stop profiling: am profile  stop

     specifications include these flags:
        [-a ] [-d ] [-t ]
        [-c  [-c ] ...]
        [-e|--es   ...]
        [--esn  ...]
        [--ez   ...]
        [-e|--ei   ...]
        [-n ] [-f ]
        [--grant-read-uri-permission] [--grant-write-uri-permission]
        [--debug-log-resolution]
        [--activity-brought-to-front] [--activity-clear-top]
        [--activity-clear-when-task-reset] [--activity-exclude-from-recents]
        [--activity-launched-from-history] [--activity-multiple-task]
        [--activity-no-animation] [--activity-no-history]
        [--activity-no-user-action] [--activity-previous-is-top]
        [--activity-reorder-to-front] [--activity-reset-task-if-needed]
        [--activity-single-top]
        [--receiver-registered-only] [--receiver-replace-pending]
        []

reference: Run Android Application from Command Line