void onLoadResource(WebView view, String url)

외부 리소스를 불러올 때 처리할 내용을 구현한다.


void onPageFinished(WebView view, String url)

페이지 로딩이 완료 되었을 때 처리할 내용을 구현한다.


void onPageStarted(WebView view, String url, Bitmap favicon)

페이지 로딩이 시작될 때 처리할 내용을 구현한다.


void onReceivedError(WebView view, int errorCode, String description, String failingUrl)

오류가 발생했을 때 처리할 내용을 구현한다.


void onScaleChanged(WebView view, float oldScale, float newScale)

스케일이 변경되었을 때 처리할 내용을 구현한다.


WebResourceResponse shouldInterceptRequest(WebView view, String url)

리소스 요청이 있을 때 처리할 내용을 구현한다.


boolean shouldOverrideKeyEvent(WebView view, KeyEvent event)

키 이벤트 발생시에 처리할 내용을 구현한다.


boolean shouldOverrideUrlLoading(WebView view, String url)

새로운 Url을 불러 오려고 할 때 처리할 내용을 구현한다.

안드로이드 개발자 사이트에 보면 tcpdump 를 이용하는 방법이 있다. 
Linux나 Windows에서 tcpdump를 사용해본 경험이 있는 분들은 간단하게 아래 설명을 보면된다.

arm용으로 빌드된 tcpdump-arm (첨부파일을 받아 확장자 변경) 바이너리를 단말기나 Emulator에 push한다.

$adb remount
$adb push ./tcpdump-arm /data/local
$adb
#cd /data/local
#chmod 777 tcpdump-arm
#./tcpdump-arm -X -n -s 0 port 80 -w /sdcard/capture.pcap //만일 80 포트에서 I/O되는 패킷을 저장할 경우 
...
... 인터넷 작업...
...
#^c
sdcard에서 저장된 capture.pcap파일을 꺼내어 wireshark(http://www.wireshark.org/download.html) 를 이용하여 TCP Stream을 확인하면 된다. tcpdump는 서버로부터 아무 응답이 없는 경우 단말기의 Socket에서 SYN (TCP 연결) 패킷이 보내졌는지, 서버가 응답안하는지, 전송, 응답 패킷을 확인하는 경우 유용하다.

[펌] Debugging with tcpdump and other tools

Installing tcpdump

Pushing the binary to an existing device

Download tcpdump from http://www.tcpdump.org/, then execute:

adb root
adb remount
adb push /wherever/you/put/tcpdump /system/xbin/tcpdump
adb shell chmod 6755 /data/local/tmp/tcpdump
adb shell
#./tcpdump-arm 

If you are running your own build, execute:

mmm external/tcpdump  # install the binary in out/.../system/xbin
make snod # build a new system.img that includes it

Flash the device as usual, for example, fastboot flashball.

If you want to build tcpdump by default, add CUSTOM_TARGETS += tcpdump to your buildspec.mk.

Running tcpdump

You need to have root access on your device.

Batch mode capture

The typical procedure is to capture packets to a file and then examine the file on the desktop, as illustrated below:

adb shell tcpdump -i any -p -s 0 -w /sdcard/capture.pcap
# "-i any": listen on any network interface
# "-p": disable promiscuous mode (doesn't work anyway)
# "-s 0": capture the entire packet
# "-w": write packets to a file (rather than printing to stdout)

... do whatever you want to capture, then ^C to stop it ...

adb pull /sdcard/capture.pcap .
sudo apt-get install wireshark # or ethereal, if you're still on dapper
wireshark capture.pcap # or ethereal

... look at your packets and be wise ...

You can run tcpdump in the background from an interactive shell or from Terminal. By default,tcpdump captures all traffic without filtering. If you prefer, add an expression like port 80 to thetcpdump command line.

Real time packet monitoring

Execute the following if you would like to watch packets go by rather than capturing them to a file (-n skips DNS lookups. -s 0 captures the entire packet rather than just the header):

adb shell tcpdump -n -s 0

Typical tcpdump options apply. For example, if you want to see HTTP traffic:

adb shell tcpdump -X -n -s 0 port 80

You can also monitor packets with wireshark or ethereal, as shown below:

# In one shell, start tcpdump.
adb shell "tcpdump -n -s 0 -w - | nc -l -p 11233"

# In a separate shell, forward data and run ethereal.
adb forward tcp:11233 tcp:11233 && nc 127.0.0.1 11233 | ethereal -k -S -i -

Note that you can't restart capture via ethereal. If anything goes wrong, you will need to rerun both commands.

For more immediate output, add -l to the tcpdump command line, but this can cause adb to choke (it helps to use a nonzero argument for -s to limit the amount of data captured per packet; -s 100is sufficient if you just want to see headers).

Disabling encryption

If your service runs over httpstcpdump is of limited use. In this case, you can rewrite some service URLs to use http, for example:

vendor/google/tools/override-gservices url:calendar_sync_https_proxy \

https://www.google.com/calendar rewrite http://android.clients.google.com/proxy/calendar

Other network debugging commands

On the device:

  • ifconfig interface: note that unlike Linux, you need to give ifconfig an argument
  • netcfg: lists interfaces and IP addresses
  • iftop: like top for network
  • route: examine the routing table
  • netstat: see active network connections
  • ncnetcat connection utility

On the desktop:

  • curl: fetch URLs directly to emulate device requests

Sunday, August 30th, 2009 | Author: Tim

Dumping packets..

So a while back I had written about gathering packets from the android phone - often using simple ARP spoofing and Wireshark to grab all the traffic. Sadly I kept postponing this post and then just forgot to put it up, showing how to grab the packets in a much easier way, which doesn’t even require you to put your android phone on a WIFI network.

I’m not sure why this method never seemed to dawn on me in the beginning - since it’s so simple basically and has come in hand numerous times since :)

On your computers shell/cmd;

adb shell tcpdump -vv -s 0 -w /sdcard/output.cap

A quick run down of the switches we are using are the following;

-vv puts tcpdump into verbose mode - to give us some extra information
-s 0 sets the size of sender to look for to zero, telling the program to grab all packets
-w /sdcard/output.cap will let us set the packets grabbed to be written to the sdcard for analysis later.

Once your done just break the command (control-c) and go open up the .cap file with your favorite analyzer like wireshark.

You can also just run this command from your favorite terminal on the phone — allowing you to grab packets on the go. This should be pretty obvious, though I feel I must say it since people seem to think adb is something unlike a terminal? I’m not sure why this comes up, but people end up pasting the same thing I’ve done often, and then saying “You can just do it in a terminal on the phone, and it’s easiierr!”. Well yes, yes you can… Though copy-pasta-ing someones ideadoesn’t make your much brighter ;)

Directly on the phone, or already adb’ed into it;

tcpdump -vv -s 0 -w /sdcard/output.cap

Update: 8/31/09 I’ve pulled the tcpdump from my rom and uploaded it to my server, you can download it here: tcpdump. It is tcpdump version 3.9.8 libpcap version 0.9.8 - for anyone wondering. Push this file to you /system/bin or /system/xbin and then chmod’ing it to be executable should make this work. Enjoy!


출처 : http://blog.naver.com/PostView.nhn?blogId=vicfaith&logNo=150086174382

프로그래밍에 친숙한 네트워크 전문가는 프로토콜 문서를 보는 것보다 그 프로토콜이 구현된 API를 들여다 보는 것을 통해 보다 빠르고 정확하게 프로토콜에 대해 이해하기도 한다. - Softgear Ko


본 문서는 http://developer.android.com/sdk/android-4.0.html 의 WiFi Direct 를 번역하였습니다.


Wi-Fi Direct

안 드로이드는 이제 사용자간 연결(P2P)을 위한 Wi-Fi Direct 를 지원한다. 이 P2P 연결은, 핫스팟이나 인터넷 연결 없이, 안드로이드 장치 또는 다른 디바이스 간의 직접 연결 및 통신을 말한다. 안드로이드 프레임워크는 Wi-Fi P2P API를 제공하여, 당신이 Wi-Fi Direct를 지원하는 다른 디바이스를 찾고 연결할 수 있도록 하고, Bluetooth 연결보다 더 긴 거리에서 더 빠른 통신을 가능하게 한다.


새로운 패키지 android.net.wifi.p2p 

(http://developer.android.com/reference/android/net/wifi/p2p/package-summary.html

는 Wi-Fi를 통한 P2P 연결을 수행하는데 필요한 모든 API를 포함한다. 당신이 사용하게 될 주 클래스는 WifiP2pManager 이다. 이는 당신이 getSystemService(WIFI_P2P_SERVICE) 를 호출하여 사용할 수 있다. WifiP2pManager 는 다음 기능을 가진 API들을 포함한다.


* initialize() 를 호출하여 P2P 연결을 위한 당신의 어플리케이션을 초기화

* discoverPeers() 를 호출하여 이웃 디바이스를 찾아내기(discover)

* connect()를 호출하여 P2P 연결을 시작

* 기타 기능


몇몇 다른 필수적인 인터페이스 및 클래스는 다음과 같다.

* WifiP2pManager.ActionListener 인터페이스는 당신이 상대방을 찾거나(discover) 연결하는 동작이 성공하거나 실패한 경우 호출되는 콜백(callback)을 받을 수 있게 한다.

* WifiP2pManager.PeerListListener 인터페이스는 당신이 발견된 상대방에 관한 정보를 받을 수 있게 한다. 이 콜백은 WifiP2pDeviceList 를 제공하는데, 여기서 통신 범위내에 있는 각 디바이스 별 WifiP2pDevice 객체를 뽑아내어, 디바이스 이름, 주소, 디바이스 타입, WPS 설정 등과 같은 정보를 얻을 수 있다.

* WifiP2pManager.GroupInfoListener 인터페이스는 당신이 P2P 그룹에 관한 정보를 받을 수 있게 한다. 이 콜백은 WifiP2pGroup 객체를 제공하는데, 이는 소유자(owner), 네트워크 이름, 암호구문(passphrase) 등과 같은 그룹 정보를 제공한다.

* WifiP2pManager.ConnectionInfoListener 인터페이스는 당신이 현재 연결에 관한 정보를 받도록 한다. 이 콜백은 WifiP2pInfo 객체를 제공하는데, 이는 그룹이 구성되었는지 여부, 누가 그룹 소유자인지를 포함한다.


Wi-Fi P2P API들을 사용하기 위해서는, 당신의 어플은 다음 사용자 권한들을 요청해야 한다.

* ACCESS_WIFI_STATE

* CHANGE_WIFI_STATE

* INTERNET (비록 당신의 어플이 기술적으로 인터넷에 연결하지 않을지라도, Wi-Fi Direct 통신을 위한 표준 java socket들은 Internet permission을 요구한다)


안드로이드 시스템은 다음과 같은 Wi-Fi P2P 이벤트에 대해 몇가지 action을 broadcast한다.

* WIFI_P2P_CONNECTION_CHANGED_ACTION: P2P연결 상태가 변경 되었음을 나타낸다.. 이는 WifiP2pInfo 객체를 가진 EXTRA_WIFI_P2P_INFO 와 NetworkInfo 객체를 가진 EXTRA_NETWORK_INFO 를 전달한다.

* WIFI_P2P_STATE_CHANGED_ACTION: P2P 상태가 enabled와 disabled 사이에서 변경 되었음을 나타낸다. 이는 WIFI_P2P_STATE_DISABLED 또는 WIFI_P2P_STATE_ENABLED 를 가진 EXTRA_WIFI_STATE 를 전달한다.

* WIFI_P2P_PEERS_CHANGED_ACTION: 상대방 디바이스 리스트가 변경되었음을 나타낸다.

* WIFI_P2P_THIS_DEVICE_CHANGED_ACTION: 이 디바이스에 대한 세부사항(details)가 변경되었음을 나타낸다.


더 자세한 정보를 위해서는 WifiP2pManager 문서 

http://developer.android.com/reference/android/net/wifi/p2p/WifiP2pManager.html ) 

를 참고하라. 그리고 또한, Wi-Fi Direct 데모 샘플 어플리케이션 

http://developer.android.com/resources/samples/WiFiDirectDemo/index.html ) 

을 보라.


- 문서끝.


출 처: 쏘프트 스토리에서 퍼옴.
         http://blog.naver.com/PostView.nhn?blogId=softgear&logNo=100150666274

'안드로이드' 카테고리의 다른 글

WebViewClient  (0) 2012.07.12
Android WireShark TCP dump  (0) 2012.07.12
Android 빌드하기  (0) 2012.03.03
Framework에서 Attrs.xml에 추가하기  (0) 2012.02.03
Device Administration  (0) 2012.01.28

+ Recent posts