基於Android 7.0的源碼分析android
前面介紹過AMS相關的一些數據結構,每一個數據結構有大量的成員變量,爲了查詢當前手機運行時狀態的 變化值,能夠經過dumpsys activity命令來完成,該方法最終是調用AMS.dump()方法。git
dumpsys命令用法簡要介紹過dumpsys命令 的基本用法,以及系統服務列表信息,那麼本文重點介紹AMS。 根據dumpsys activity傳遞不一樣的參數, 對於AMS.dump便會輸出相應的對象信息。 具體能夠跟哪些參數.bash
dumpsys activity [options] [WHAT]
複製代碼
其中options爲可選項,以-
開頭, 主要有如下幾類:數據結構
options | 含義 |
---|---|
-a | 包括全部可用Server狀態 |
-c | 包括Client狀態,即App端狀況 |
-p PACKAGE | 限定輸出指定包名 |
列舉常見的WHAT參數:app
序號 | WHAT | 解釋 | 對應源碼 |
---|---|---|---|
1 | a[ctivities] | activity狀態 | dumpActivitiesLocked() |
2 | b[roadcasts] [PACKAGE_NAME] | broadcast狀態 | dumpBroadcastsLocked() |
3 | s[ervices] [COMP_SPEC …] | service狀態 | newServiceDumperLocked().dumpLocked |
4 | prov[iders] [COMP_SPEC …] | content provider狀態 | dumpProvidersLocked() |
5 | p[rocesses] [PACKAGE_NAME] | 進程狀態 | dumpProcessesLocked() |
6 | o[om] | 內存管理 | dumpOomLocked() |
7 | i[ntents] [PACKAGE_NAME] | pending intent狀態 | dumpPendingIntentsLocked() |
8 | r[ecents] | 最近activity | dumpRecentsLocked() |
9 | perm[issions] | URI受權狀況 | dumpPermissionsLocked() |
10 | all | 全部activities信息 | dumpActivity() |
11 | top | 頂部activity信息 | dumpActivity() |
12 | package | package相關信息 | dump() |
其中PACKAGE_NAME是指可跟包名,COMP_SPEC是指可跟具體組件信息,中括號是指縮寫字母;ide
前面介紹dumpsys activity根據後面跟着的不一樣參數則輸出相應的內容,當不跟任何參數, dumpsys activity
等價於依次輸出下面8條命令:oop
dumpsys activity intents
dumpsys activity broadcasts //廣播
dumpsys activity providers //provider
dumpsys activity permissions
dumpsys activity services //服務
dumpsys activity recents
dumpsys activity activities //activity
dumpsys activity processes
複製代碼
依次簡要說明這8條命令:源碼分析
//標誌性開頭,dumpPendingIntentsLocked
ACTIVITY MANAGER PENDING INTENTS (dumpsys activity intents)
複製代碼
輸出對象:ui
//標誌性開頭,dumpBroadcastsLocked
ACTIVITY MANAGER BROADCAST STATE (dumpsys activity broadcasts)
Registered Receivers:
Receiver Resolver Table:
Historical broadcasts [foreground]:
Historical broadcasts summary [foreground]:
Historical broadcasts [background]:
Historical broadcasts summary [background]:
Sticky broadcasts
mHandler
複製代碼
主要輸出的對象:spa
//標誌性開頭,dumpProvidersLocked
ACTIVITY MANAGER CONTENT PROVIDERS (dumpsys activity providers)
Published single-user content providers (by class):
Published user [n] content providers (by class):
Single-user authority to provider mappings:
User [n] authority to provider mappings:
複製代碼
主要輸出的對象:
//標誌性開頭,dumpPermissionsLocked
ACTIVITY MANAGER URI PERMISSIONS (dumpsys activity permissions)
複製代碼
主要輸出的對象:
//標誌性開頭,newServiceDumperLocked().dumpLocked
ACTIVITY MANAGER SERVICES (dumpsys activity services)
複製代碼
主要輸出的對象:
//標誌性開頭,dumpRecentsLocked
ACTIVITY MANAGER RECENT TASKS (dumpsys activity recents)
複製代碼
主要輸出的對象:
//標誌性開頭,dumpActivitiesLocked
ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
Display #0 (activities from top to bottom):
Stack #0:
Task id #[n]
* Hist #[m]:
Stack #1:
複製代碼
主要輸出的對象:
輸出格式樣例:
//{Hashcode #TaskId Affinity UserId 該task的Activity個數};
TaskRecord{e6d7a8e #156 A=com.gityuan.demo U=0 sz=1}
userId=0 effectiveUid=1000 mCallingUid=1000 mCallingPackage=android
realActivity=com.gityuan.demo/.Blog
//ProcessRecord{Hashcode pid:進程名/uid}
ProcessRecord{7c8a2af 12265:com.gityuan.demo/1000}
複製代碼
//標誌性開頭,dumpProcessesLocked
ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes)
All known processes:
Isolated process list (sorted by uid):
UID states:
UID validation:
Process LRU list (sorted by oom_adj, 60 total, non-act at 2, non-svc at 2):
PID mappings:
Foreground Processes:
複製代碼
主要輸出的對象:
轉載:http://gityuan.com/2017/07/04/ams_dumpsys/