码迷,mamicode.com
首页 > 移动开发 > 详细

Android ADB工具-管理设备 app(二)

时间:2015-08-16 16:40:15      阅读:389      评论:0      收藏:0      [点我收藏+]

标签:android   shell   adb-shell   命令   

Android ADB工具-管理设备 app(二)

标签(空格分隔): Android


4.管理设备 app

命令 功能
adb install [-r|-s] <apkfile> 安装 apk 文件
adb uninstall [-k] <packagename> 卸载 app
adb shell top [-m <number>] 查看内存占用情况
adb shell ps 查看进程列表
adb shell kill <pid> 杀死一个进程
adb shell ps –x <pid> 查看指定进程的状态
adb shell service list 查看后台 services 信息
adb shell cat /proc/meminfo 查看当前内存占用
adb shell cat /proc/iomem 查看 IO 内存分区

演示apk:package=”com.example.Test”
名称:Test.apk
路径:C:\Users\Administrator\Desktop\Test.apk

adb shell安装apk

>C:\Users\Administrator>adb install >C:\Users\Administrator\Desktop\Test.apk
>642 KB/s (37500 bytes in 0.057s)
>open: Permission denied
>open: Permission denied
>        pkg: /data/local/tmp/Test.apk
>Success

如果已经安装了Test.apk,则无法安装

C:\Users\Administrator>adb install C:\Users\Administrator\Desktop\Test.apk
653 KB/s (37500 bytes in 0.056s)
open: Permission denied
open: Permission denied
        pkg: /data/local/tmp/Test.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]

INSTALL_FAILED_ALREADY_EXISTS:这说明你原来安装过这个软件

如果已经安装了,怎么办?

第一种方法:卸载(后面介绍)

第二种方法:覆盖安装
adb install -r C:\Users\Administrator\Desktop\Test.apk

C:\Users\Administrator>adb install -r C:\Users\Administrator\Desktop\Test.apk
631 KB/s (37500 bytes in 0.058s)
open: Permission denied
open: Permission denied
        pkg: /data/local/tmp/Test.apk
Success

安装到sdkcard中

C:\Users\Administrator>adb install -d C:\Users\Administrator\Desktop\Test.apk
620 KB/s (37500 bytes in 0.059s)
open: Permission denied
open: Permission denied
        pkg: /data/local/tmp/Test.apk
Success

卸载程序需要知apk包名,获取手机apk包名

C:\Users\Administrator>adb shell pm list package
open: Permission denied
open: Permission denied
package:com.qualcomm.fastdormancy
package:com.miui.gallery
package:com.qualcomm.timeservice
package:com.android.defcontainer
package:com.tencent.mm
package:com.UCMobile
package:com.android.quicksearchbox
package:com.android.contacts
package:com.android.phone
package:com.dangdang.reader
package:com.android.calculator2
package:com.myzaker.ZAKER_Phone
package:com.miui.player
package:com.android.htmlviewer
package:com.xiaomi.mitunes
package:com.example.TestDemo
package:com.miui.guardprovider
package:com.kingroot.kinguser
...此处省略一大波···

卸载程序

通过adb shell pm list package获取到包名

C:\Users\Administrator>adb uninstall com.example.TestDemo
open: Permission denied
open: Permission denied
Success

卸载程序,但是保留数据和缓存目录

C:\Users\Administrator>adb uninstall -k com.example.TestDemo
The -k option uninstalls the application while retaining the data/cache.
At the moment, there is no way to remove the remaining data.
You will have to reinstall the application with the same signature, and fully un
install it.
If you truly wish to continue, execute ‘adb shell pm uninstall -k com.example.Te
stDemo‘

这个意思是要真的想要这么做请使用adb shell pm uninstall -k com.example.Te
stDemo这个命令

查看所有程序占用内存的情况

C:\Users\Administrator>adb shell -m
 1157  1   4% S    56 665364K 115128K  fg system   com.android.systemui
  214  1   2% S    14  63016K   7092K  fg system   /system/bin/surfaceflinger
  204  1   2% D     1   1436K    148K  fg root     /sbin/healthd
32305  0   2% R     1   1356K    584K     shell    top
31727  1   1% S    12 521640K  47428K  bg u0_a86   com.myzaker.ZAKER_Phone:remot
e
   33  0   1% S     1      0K      0K     root     kworker/u:1H
24725  1   1% S   102 749556K 105936K  bg u0_a86   com.myzaker.ZAKER_Phone
....省略一大波...

查看前3个程序占用内存的情况


C:\Users\Administrator>adb shell top -m 3

User 10%, System 20%, IOW 0%, IRQ 0%
User 51 + Nice 0 + Sys 101 + Idle 353 + IOW 0 + IRQ 0 + SIRQ 0 = 505

  PID PR CPU% S  #THR     VSS     RSS PCY UID      Name
  471  0   8% D     1    948K    396K     system   /system/bin/charger_monitor
 1078  0   3% S   109 706160K 109276K  fg system   system_server
 1157  0   3% S    56 665364K 116728K  fg system   com.android.systemui



User 13%, System 27%, IOW 0%, IRQ 0%
User 40 + Nice 0 + Sys 79 + Idle 170 + IOW 0 + IRQ 0 + SIRQ 0 = 289

  PID PR CPU% S  #THR     VSS     RSS PCY UID      Name
  471  0  15% S     1    948K    396K     system   /system/bin/charger_monitor
 1157  0   5% S    56 665344K 116796K  fg system   com.android.systemui
 1078  0   4% S   109 706160K 109276K  fg system   system_server

刷新一次内存然后返回所有程序占用内存的情况

C:\Users\Administrator>adb shell top -n 1

查看后台Service

C:\Users\Administrator>adb shell service list
Found 91 services:
0       sip: [android.net.sip.ISipService]
1       phone: [com.android.internal.telephony.ITelephony]
2       phone.0: [com.android.internal.telephony.ITelephony]
3       isms.0: [com.android.internal.telephony.ISms]
4       isms: [com.android.internal.telephony.ISms]
....省略...
发现后台91后台服务

查看当前内存的占用

C:\Users\Administrator>adb shell cat /proc/meminfo
MemTotal:        1913548 kB
MemFree:           76800 kB
Buffers:           23284 kB
Cached:           287520 kB
SwapCached:            0 kB
Active:          1196176 kB
Inactive:         151964 kB
Active(anon):    1041676 kB
Inactive(anon):     7368 kB
Active(file):     154500 kB
Inactive(file):   144596 kB
Unevictable:        1788 kB
Mlocked:              24 kB
HighTotal:       1178620 kB
HighFree:           8980 kB
LowTotal:         734928 kB
LowFree:           67820 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:       1039100 kB
Mapped:           167212 kB
Shmem:              9944 kB
Slab:              65696 kB
SReclaimable:      20148 kB
SUnreclaim:        45548 kB
KernelStack:       22920 kB
PageTables:        28068 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      956772 kB
Committed_AS:   32547196 kB
VmallocTotal:     122880 kB
VmallocUsed:       12740 kB
VmallocChunk:      75632 kB

总共的内存大小MemTotal: 1913548 kB
还可以使用的内存MemFree: 76800 kB

查看IO内存分区

C:\Users\Administrator>adb shell cat /proc/iomem
00000000-07ffffff : System RAM
  00000000-00000000 : ram_console
  00008000-00cc0143 : Kernel code
  00e0c000-016c551f : Kernel data
0f500000-0f9fffff : System RAM
0ff00000-7f2fffff : System RAM
f9017000-f9017fff : msm-watchdog
f9824900-f9824a1b : mmc0
f98a4900-f98a4a1b : mmc1
f991f000-f991ffff : msm_serial_hsl
f9923000-f9923fff : spi_qsd
f9925000-f9925fff : f9925000.i2c
f9926000-f9926fff : f9926000.i2c
f9927000-f9927fff : f9927000.i2c
f9928000-f9928fff : f9928000.i2c
f9a55000-f9a553ff : /soc/usb@f9a55000
  f9a55000-f9a553ff : /soc/usb@f9a55000
fb21b000-fb21dfff : pmu_base
fc380000-fc3e9fff : fc380000.msm-bimc
fc401680-fc401683 : restart_reg
fc4016c0-fc4016c3 : restart_reg
fc401700-fc401703 : clk_base
fc4281d0-fc4291cf : vmpm
fc460000-fc463fff : fc460000.msm-sys-noc
fc468000-fc46bfff : fc468000.msm-periph-noc
fc478000-fc47bfff : fc478000.msm-mmss-noc
fc480000-fc483fff : fc480000.msm-config-noc
fc4a8000-fc4a9fff : tsens_physical
fc4bc000-fc4bcfff : tsens_eeprom_physical
fc820000-fc82001f : rmb_base
fc880000-fc8800ff : qdsp6_base
fd485300-fd48530b : halt_base
fda00020-fda0002f : csi_clk_mux
fda00030-fda00033 : csiphy_clk_mux
fda00038-fda0003b : csiphy_clk_mux
fda04000-fda040ff : fda04000.qcom,cpp
fda08000-fda080ff : fda08000.qcom,csid
fda08400-fda084ff : fda08400.qcom,csid
fda0a000-fda0a4ff : fda0a000.qcom,ispif
fda0ac00-fda0adff : fda0ac00.qcom,csiphy
fda0b000-fda0b1ff : fda0b000.qcom,csiphy
fda0c000-fda0cfff : fda0c000.qcom,cci
fdb00000-fdb0ffff : kgsl-3d0
fdb20000-fdb2ffff : kgsl-3d0
fdc80000-fdc803ff : vbif_base
fdce0000-fdce3fff : wrapper_base
fe200000-fe2000ff : qdsp6_base
fec00000-fec1ffff : fdd00000.qcom,ocmem

未完待续…

版权声明:本文为博主原创文章,未经博主允许不得转载。

Android ADB工具-管理设备 app(二)

标签:android   shell   adb-shell   命令   

原文地址:http://blog.csdn.net/fenggit/article/details/47703205

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!