随笔 - 224  文章 - 41  trackbacks - 0
<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

享受编程

常用链接

留言簿(11)

随笔分类(159)

随笔档案(224)

文章分类(2)

文章档案(4)

经典c++博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜

原文地址:http://blog.csdn.net/chief1985/archive/2010/05/03/5553022.aspx

android的adb采用的是server+client的方式,所以adb是支持多个设备同时连接的。通过adb devices命令可以看到所有连接的android设备,而多个设备都连上adb server,如果你想针对某一个设备执行adb命令,可以在adb命令后面加上-s <serial number>,例如adb –s 12345678 push c:\a.txt /data/。adb的设计可以参考http://blog.csdn.net/wbw1985/archive/2010/04/02/5443910.aspx

对于adb shell,后面可以跟的命令主要来自android-1.5\system\core\toolbox里面,如下:

    ls 
    mount 
    cat 
    ps 
    kill 
    ln 
    insmod 
    rmmod 
    lsmod 
    ifconfig 
    setconsole 
    rm 
    mkdir 
    rmdir 
    reboot 
    getevent 
    sendevent 
    date 
    wipe 
    sync 
    umount 
    start 
    stop 
    notify 
    cmp 
    dmesg 
    route 
    hd 
    dd 
    df 
    getprop 
    setprop 
    watchprops 
    log 
    sleep 
    renice 
    printenv 
    smd 
    chmod 
    chown 
    mkdosfs 
    netstat 
    ioctl 
    mv 
    schedtop 
    top 
    iftop 
    id 
    vmstat

具体的意思就不解释了,大家可以去看linux手册或者看android的源码。需要说一下的是ps命令,很多时候我们想只列举出我们需要的进程列表,例如列举出所有运行的app。从ps的源码来看,它是支持filter的,ps app应该可以列举出所有以app开头的进程,但在某些手机里面运行时这个filter又是没用的,可能是这些手机修改了ps的代码。

还有两个比较好用的命令是adb shell am和adb shell pm,这两个命令在frameworks/base/cmds下面。am命令主要用于管理Activity,例如启动,停止Activity(eclipse在运行Activity就使用了这个命令),发送intent;pm命令则主要用于管理应用package的管理,有点像控制面板的添加和删除程序。

am命令的具体用法如下:

usage: am [start|broadcast|instrument|profile]
am start -D INTENT
am broadcast INTENT
am instrument [-r] [-e <ARG_NAME> <ARG_VALUE>] [-p <PROF_FILE>]
[-w] <COMPONENT>
am profile <PROCESS> [start <PROF_FILE>|stop]
INTENT is described with:
[-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[-n <COMPONENT>] [-f <FLAGS>] [<URI>]
The start command starts activity. Use -D option to make 'DebugOption' true.
The broadcast command sends broadcast.
The instrument command starts instrumentation.
Use -r option to make 'rawMode' true.
Use -e option to add the pair of ARG_NAME and ARG_VALUE into Bundle.
Use -p option to specify profileFile.
Use -w option to make 'wait' true in order to new an instance of InstrumentationWatcher.
Use COMPONENT to specify the name of the instrumentation component.
The profile command turn on/off profiling in a particular process specified by PROCESS.
Use start option to turn on and stop to turn off.Use PROF_FILE to specify the file path of profile.
Use -a to set action specified by ACTION to be performed.
Use -d to create a Uri(data) which parses the given encoded URI string DATA_URI.
Use -t to specify the type specified by MIME_TYPE. Use -c to add a new category specified by
CATEGORY to the intent.
Use -e or --es to add extended data to the intent.EXTRA_KEY specifies the name of the extra data and
EXTRA_STRING_VALUE specifies the string data value.
Use --ez to add extended data to the intent. EXTRA_KEY specifies the name of the extra data and
EXTRA_BOOLEAN_VALUE specifies the serializable data value.
Use -e or --ei to add extended data to the intent. EXTRA_KEY specifies the name of the extra data and
EXTRA_INT_VALUE specifies the serializable data value.
Use -n to explicitly set the component specified by COMPONENT to handle the intent.
Use -f to set special flags controlling how this intent is handled.FLAGS specifies the desired flags.
Use URI to create an intent from a URI.

pm命令的具体用法如下:

usage: pm [list|path|install|uninstall]
       pm list packages [-f]
       pm list permission-groups
       pm list permissions [-g] [-f] [-d] [-u] [GROUP]
       pm list instrumentation [-f] [TARGET-PACKAGE]
       pm path PACKAGE
       pm install [-l] [-r] PATH
       pm uninstall [-k] PACKAGE
       pm enable PACKAGE_OR_COMPONENT
       pm disable PACKAGE_OR_COMPONENT

The list packages command prints all packages.  Use
the -f option to see their associated file.

The list permission-groups command prints all known
permission groups.

The list permissions command prints all known
permissions, optionally only those in GROUP.  Use
the -g option to organize by group.  Use
the -f option to print all information.  Use
the -s option for a short summary.  Use
the -d option to only list dangerous permissions.  Use
the -u option to list only the permissions users will see.

The list instrumentation command prints all instrumentations,
or only those that target a specified package.  Use the -f option
to see their associated file.

The path command prints the path to the .apk of a package.

The install command installs a package to the system.  Use
the -l option to install the package with FORWARD_LOCK. Use
the -r option to reinstall an exisiting app, keeping its data.

The uninstall command removes a package from the system. Use
the -k option to keep the data and cache directories around
after the package removal.

The enable and disable commands change the enabled state of
a given package or component (written as "package/class").
 

frameworks/base/cmds下面还有一个别的命令,如下


dumpstate
dumpsys
ime
input
installd
runtime
service
servicemanager
surfaceflinger
svc
system_server

下面是上述命令的一些输出:

C:\Users\xufan>adb shell dumpstate
========================================================
== dumpstate
========================================================
------ MEMORY INFO ------
MemTotal:        94348 kB
MemFree:          9912 kB
Buffers:             0 kB
Cached:          47876 kB
SwapCached:          0 kB
Active:          47016 kB
Inactive:        29980 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:               0 kB
Writeback:           0 kB
AnonPages:       29156 kB
Mapped:          22948 kB
Slab:             2992 kB
SReclaimable:      796 kB
SUnreclaim:       2196 kB
PageTables:       2180 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
WritebackTmp:        0 kB
CommitLimit:     47172 kB
Committed_AS:   658548 kB
VmallocTotal:   876544 kB
VmallocUsed:      8380 kB
VmallocChunk:   859132 kB

------ CPU INFO ------

User 7%, System 23%, IOW 0%, IRQ 0%
User 11 + Nice 0 + Sys 33 + Idle 98 + IOW 0 + IRQ 0 + SIRQ 0 = 142

  PID   TID CPU% S     VSS     RSS UID      Thread          Proc
  743   743  26% R    928K    384K shell    top             top
  565   581   1% S 177876K  25384K system   er.ServerThread system_server
  565   570   0% S 177876K  25384K system   Binder Thread # system_server
  565   571   0% S 177876K  25384K system   Binder Thread # system_server
  605   605   0% S 105820K  17540K radio    app_process     com.android.phone
  565   619   0% S 177876K  25384K system   er$SensorThread system_server
  565   585   0% S 177876K  25384K system   PackageManager  system_server
  565   586   0% S 177876K  25384K system   FileObserver    system_server
  565   589   0% S 177876K  25384K system   SyncHandlerThre system_server
  565   590   0% S 177876K  25384K system   UEventObserver  system_server
  565   591   0% S 177876K  25384K system   PowerManagerSer system_server
  565   592   0% S 177876K  25384K system   AlarmManager    system_server
  565   593   0% S 177876K  25384K system   WindowManager   system_server
  565   594   0% S 177876K  25384K system   InputDeviceRead system_server
  565   595   0% S 177876K  25384K system   WindowManagerPo system_server
  565   596   0% S 177876K  25384K system   InputDispatcher system_server
  565   597   0% S 177876K  25384K system   ConnectivityThr system_server
  565   598   0% S 177876K  25384K system   WifiService     system_server
  565   599   0% S 177876K  25384K system   WifiWatchdogThr system_server
  565   600   0% S 177876K  25384K system   er.ServerThread system_server
  565   601   0% S 177876K  25384K system   GpsEventThread  system_server
  565   602   0% S 177876K  25384K system   AudioService    system_server
  565   603   0% S 177876K  25384K system   android:unnamed system_server
  565   604   0% S 177876K  25384K system   android:unnamed system_server
  565   609   0% S 177876K  25384K system   watchdog        system_server
  565   640   0% S 177876K  25384K system   r.MountListener system_server
  565   651   0% S 177876K  25384K system   Binder Thread # system_server
  565   678   0% S 177876K  25384K system   Binder Thread # system_server
  605   606   0% S 105820K  17540K radio    HeapWorker      com.android.phone
  605   607   0% S 105820K  17540K radio    Signal Catcher  com.android.phone
------ PROCRANK ------
 


 

C:\Users\xufan>adb shell dumpsys

  Provider mms-sms
    ContentProviderRecord{436a0040 com.android.providers.telephony.MmsSmsProvide
r}
    package=com.android.providers.telephony process=com.android.phone
    app=ProcessRecord{43638990 605:com.android.phone/1001}
    launchingApp=null
    provider=android.content.ContentProviderProxy@436c8c88
    name=mms-sms
    isSyncable=false
    multiprocess=true initOrder=0 uid=1001
    clients=[]
    externals=0

  Published content providers (by class):
  Provider android.content.SyncProvider
    ContentProviderRecord{435bceb8 android.content.SyncProvider}
    package=android process=system
    app=ProcessRecord{436236b8 565:system/1000}
    launchingApp=null
    provider=android.content.ContentProvider$Transport@43634c48
    name=sync
    isSyncable=false
    multiprocess=false initOrder=0 uid=1000
    clients=[]
    externals=0
  Provider com.android.providers.telephony.MmsSmsProvider
    ContentProviderRecord{436a0040 com.android.providers.telephony.MmsSmsProvide
r}
    package=com.android.providers.telephony process=com.android.phone
    app=ProcessRecord{43638990 605:com.android.phone/1001}
    launchingApp=null
    provider=android.content.ContentProviderProxy@436c8c88
    name=mms-sms
    isSyncable=false
    multiprocess=true initOrder=0 uid=1001
    clients=[]
    externals=0
  Provider com.android.providers.settings.SettingsProvider
    ContentProviderRecord{435bda90 com.android.providers.settings.SettingsProvid
er}
    package=com.android.providers.settings process=system
    app=ProcessRecord{436236b8 565:system/1000}
    launchingApp=null
    provider=android.content.ContentProvider$Transport@435a2b58
    name=settings
    isSyncable=false
    multiprocess=false initOrder=100 uid=1000
    clients=[ProcessRecord{4371bad0 655:com.android.alarmclock/10000}, ProcessRe
cord{43638990 605:com.android.phone/1001}]
    externals=0
  Provider com.android.providers.userdictionary.UserDictionaryProvider
    ContentProviderRecord{436a2398 com.android.providers.userdictionary.UserDict
ionaryProvider}
    package=com.android.providers.userdictionary process=android.process.acore
    app=ProcessRecord{43645bc0 608:android.process.acore/10004}
    launchingApp=null
    provider=android.content.ContentProviderProxy@436ccca0
    name=user_dictionary
    isSyncable=false
    multiprocess=false initOrder=0 uid=10004
    clients=[]
    externals=0
  Provider com.android.providers.contacts.ContactsProvider
    ContentProviderRecord{436a25e8 com.android.providers.contacts.ContactsProvid
er}
    package=com.android.providers.contacts process=android.process.acore
    app=ProcessRecord{43645bc0 608:android.process.acore/10004}
    launchingApp=null
    provider=android.content.ContentProviderProxy@436cd910
    name=contacts;call_log
    isSyncable=false
    multiprocess=false initOrder=0 uid=10004
    clients=[]
    externals=0
  Provider com.android.providers.drm.DrmProvider
    ContentProviderRecord{4361c528 com.android.providers.drm.DrmProvider}
    package=com.android.providers.drm process=android.process.media
    app=ProcessRecord{436e89e8 644:android.process.media/10003}
    launchingApp=null
    provider=android.content.ContentProviderProxy@435ffed0
    name=drm
    isSyncable=false
    multiprocess=false initOrder=0 uid=10003
    clients=[]
    externals=0
  Provider com.android.launcher.LauncherProvider
    ContentProviderRecord{436a2710 com.android.launcher.LauncherProvider}
    package=com.android.launcher process=android.process.acore
    app=ProcessRecord{43645bc0 608:android.process.acore/10004}
    launchingApp=null
    provider=android.content.ContentProviderProxy@436cdff0
    name=com.android.launcher.settings
    isSyncable=false
    multiprocess=false initOrder=0 uid=10004
    clients=[]
    externals=0
  Provider com.android.providers.media.MediaProvider
    ContentProviderRecord{436e8728 com.android.providers.media.MediaProvider}
    package=com.android.providers.media process=android.process.media
    app=ProcessRecord{436e89e8 644:android.process.media/10003}
    launchingApp=ProcessRecord{436e89e8 644:android.process.media/10003}
    provider=android.content.ContentProviderProxy@435ff638
    name=media
    isSyncable=false
    multiprocess=false initOrder=0 uid=10003
    clients=[]
    externals=0
  Provider com.android.providers.downloads.DownloadProvider
    ContentProviderRecord{4369e808 com.android.providers.downloads.DownloadProvi
der}
    package=com.android.providers.downloads process=android.process.media
    app=ProcessRecord{436e89e8 644:android.process.media/10003}
    launchingApp=null
    provider=android.content.ContentProviderProxy@43600a50
    name=downloads
    isSyncable=false
    multiprocess=false initOrder=0 uid=10003
    clients=[]
    externals=0
  Provider com.android.providers.telephony.MmsProvider
    ContentProviderRecord{436a0f28 com.android.providers.telephony.MmsProvider}
    package=com.android.providers.telephony process=com.android.phone
    app=ProcessRecord{43638990 605:com.android.phone/1001}
    launchingApp=null
    provider=android.content.ContentProviderProxy@436c93a8
    name=mms
    isSyncable=false
    multiprocess=true initOrder=0 uid=1001
    clients=[]
    externals=0
  Provider com.android.googlesearch.SuggestionProvider
    ContentProviderRecord{436a24c0 com.android.googlesearch.SuggestionProvider}
    package=com.android.googlesearch process=android.process.acore
    app=ProcessRecord{43645bc0 608:android.process.acore/10004}
    launchingApp=null
    provider=android.content.ContentProviderProxy@436cd288
    name=com.android.googlesearch.SuggestionProvider
    isSyncable=false
    multiprocess=false initOrder=0 uid=10004
    clients=[]
    externals=0
  Provider com.android.providers.telephony.TelephonyProvider
    ContentProviderRecord{436a1030 com.android.providers.telephony.TelephonyProv
ider}
    package=com.android.providers.telephony process=com.android.phone
    app=ProcessRecord{43638990 605:com.android.phone/1001}
    launchingApp=null
    provider=android.content.ContentProviderProxy@436c9988
    name=telephony
    isSyncable=false
    multiprocess=true initOrder=0 uid=1001
    clients=[]
    externals=0
  Provider com.android.providers.telephony.SmsProvider
    ContentProviderRecord{436a1138 com.android.providers.telephony.SmsProvider}
    package=com.android.providers.telephony process=com.android.phone
    app=ProcessRecord{43638990 605:com.android.phone/1001}
    launchingApp=null
    provider=android.content.ContentProviderProxy@436ca038
    name=sms
    isSyncable=false
    multiprocess=true initOrder=0 uid=1001
    clients=[]
    externals=0
  Provider com.android.phone.SimProvider
    ContentProviderRecord{436a1240 com.android.phone.SimProvider}
    package=com.android.phone process=com.android.phone
    app=ProcessRecord{43638990 605:com.android.phone/1001}
    launchingApp=null
    provider=android.content.ContentProviderProxy@436ca648
    name=sim
    isSyncable=false
    multiprocess=true initOrder=0 uid=1001
    clients=[]
    externals=0
  Provider com.android.alarmclock.AlarmProvider
    ContentProviderRecord{4371d520 com.android.alarmclock.AlarmProvider}
    package=com.android.alarmclock process=com.android.alarmclock
    app=ProcessRecord{4371bad0 655:com.android.alarmclock/10000}
    launchingApp=null
    provider=android.content.ContentProviderProxy@435e2c10
    name=com.android.alarmclock
    isSyncable=false
    multiprocess=false initOrder=0 uid=10000
    clients=[]
    externals=0

Granted Uri Permissions:
-------------------------------------------------------------------------------
DUMP OF SERVICE activity.senders:
Intent Senders in Current Activity Manager State:
  IntentSender IntentSenderRecord{435bb968 android broadcastIntent}
    packageName=android type=broadcastIntent flags=0x0
    activity=null who=null
    requestCode=0 requestResolvedType=null
    requestIntent=Intent { action=android.content.syncmanager.SYNC_ALARM }
    sent=false canceled=false
  IntentSender IntentSenderRecord{4359f4e0 android broadcastIntent}
    packageName=android type=broadcastIntent flags=0x0
    activity=null who=null
    requestCode=0 requestResolvedType=null
    requestIntent=Intent { action=android.intent.action.DATE_CHANGED }
    sent=false canceled=false
  IntentSender IntentSenderRecord{43638b10 android broadcastIntent}
    packageName=android type=broadcastIntent flags=0x0
    activity=null who=null
    requestCode=0 requestResolvedType=null
    requestIntent=Intent { action=com.android.service.Watchdog.REBOOT }
    sent=false canceled=false
  IntentSender IntentSenderRecord{436714c0 android broadcastIntent}
    packageName=android type=broadcastIntent flags=0x0
    activity=null who=null
    requestCode=0 requestResolvedType=null
    requestIntent=Intent { action=com.android.server.WifiManager.action.DEVICE_I
DLE }
    sent=false canceled=false
  IntentSender IntentSenderRecord{435e56d8 android broadcastIntent}
    packageName=android type=broadcastIntent flags=0x0
    activity=null who=null
    requestCode=0 requestResolvedType=null
    requestIntent=Intent { action=android.intent.action.TIME_TICK flags=0x400000
00 }
    sent=true canceled=false
  IntentSender IntentSenderRecord{435adb08 android broadcastIntent}
    packageName=android type=broadcastIntent flags=0x0
    activity=null who=null
    requestCode=0 requestResolvedType=null
    requestIntent=Intent { action=android.content.syncmanager.SYNC_POLL_ALARM }
    sent=true canceled=false
  IntentSender IntentSenderRecord{4359edf0 android broadcastIntent}
    packageName=android type=broadcastIntent flags=0x0
    activity=null who=null
    requestCode=0 requestResolvedType=null
    requestIntent=Intent { action=com.android.service.Watchdog.CHECKUP }
    sent=false canceled=false
  IntentSender IntentSenderRecord{436e3198 android broadcastIntent}
    packageName=android type=broadcastIntent flags=0x0
    activity=null who=null
    requestCode=0 requestResolvedType=null
    requestIntent=Intent { }
    sent=false canceled=false
-------------------------------------------------------------------------------
DUMP OF SERVICE activity.services:
Services in Current Activity Manager State:
-------------------------------------------------------------------------------
DUMP OF SERVICE alarm:
Current Alarm Manager state:

  Realtime alarms that are scheduled:
  RTC #1:
    Alarm{436358a0 type 1 android}
    type=1 when=1272931200000 repeatInterval=0 count=0
    operation=PendingIntent{43617020 target IntentSenderRecord{4359f4e0 android
broadcastIntent}}
  RTC #0:
    Alarm{43695080 type 1 android}
    type=1 when=1272884280000 repeatInterval=0 count=0
    operation=PendingIntent{4358e9d8 target IntentSenderRecord{435e56d8 android
broadcastIntent}}

  Elapsed realtime wakeup alarms that are scheduled:
  ELAPSED_REALTIME_WAKEUP #0:
    Alarm{4361e8e8 type 2 android}
    type=2 when=90877805 repeatInterval=0 count=0
    operation=PendingIntent{435adc60 target IntentSenderRecord{435adb08 android
broadcastIntent}}

  Broadcast ref count: 0

  Alarm Stats:
  android
    4729ms running, 1 wakeups
    1 alarms: Intent { action=android.content.syncmanager.SYNC_POLL_ALARM flags=
0x4 (has extras) }
    28 alarms: Intent { action=android.intent.action.TIME_TICK flags=0x40000004
(has extras) }
-------------------------------------------------------------------------------
DUMP OF SERVICE appwidget:
Providers: (size=3)
  [0] provder=ComponentInfo{com.android.alarmclock/com.android.alarmclock.Analog
AppWidgetProvider} min=(146x146) updatePeriodMillis=0 initialLayout=2130903043 z
ombie=false
  [1] provder=ComponentInfo{com.android.camera/com.android.camera.PhotoAppWidget
Provider} min=(146x146) updatePeriodMillis=0 initialLayout=2130903052 zombie=fal
se
  [2] provder=ComponentInfo{com.android.music/com.android.music.MediaAppWidgetPr
ovider} min=(294x72) updatePeriodMillis=0 initialLayout=2130903040 zombie=false
AppWidgetIds: (size=1)
  [0] appWidgetId=1 host=1024/com.android.launcher provider=ComponentInfo{com.an
droid.alarmclock/com.android.alarmclock.AnalogAppWidgetProvider} host.callbacks=
com.android.internal.appwidget.IAppWidgetHost$Stub$Proxy@4363f610 views=android.
widget.RemoteViews@43731e90
Hosts: (size=1)
  [0] packageName=com.android.launcher uid=10004 hostId=1024 callbacks=com.andro
id.internal.appwidget.IAppWidgetHost$Stub$Proxy@4363f610 instances.size=1 zombie
=false
-------------------------------------------------------------------------------
DUMP OF SERVICE audio:
 

 

C:\Users\xufan>adb shell ime list
com.android.inputmethod.latin/.LatinIME:
  mId=com.android.inputmethod.latin/.LatinIME mSettingsActivityName=com.android.
inputmethod.latin.LatinIMESettings
  mIsDefaultResId=0x7f060001
  Service:
    Filter: null
    priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
    labelRes=0x0 nonLocalizedLabel=null icon=0x0
    ServiceInfo:
com.android.inputmethod.pinyin/.PinyinIME:
  mId=com.android.inputmethod.pinyin/.PinyinIME mSettingsActivityName=com.androi
d.inputmethod.pinyin.SettingsActivity
  mIsDefaultResId=0x7f060000
  Service:
    Filter: null
    priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
    labelRes=0x0 nonLocalizedLabel=null icon=0x0
    ServiceInfo:

 

C:\Users\xufan>adb shell input
usage: input [text|keyevent]
       input text <string>
       input keyevent <event_code>

posted on 2010-06-09 22:04 漂漂 阅读(5031) 评论(0)  编辑 收藏 引用 所属分类: android 开发

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理