【Android】圖文解密Android PackageManagerService

1、簡介

PackageManagerService(PMS)的主要職責是apk管理,下圖列出了PMS大家族相關的成員有哪些。

在這裏插入圖片描述

2、啓動

PMS在SystemServer的Bootstrap階段啓動,啓動過程中按順序創建了許多對象,掃描了不同目錄下的App進行安裝。

在這裏插入圖片描述

3、apk打包

apk打包流程如下圖所示。

在這裏插入圖片描述

4、apk安裝

apk安裝有兩種方式,一種是不帶安裝界面的,在PMS啓動時會掃描某些目錄下的apk進行安裝,或者通過adb進行安裝;另一種是有安裝界面的,有專門的PackageInstaller.apk爲之服務,如常見的從應用市場下載安裝。下面分析PMS啓動時掃描/system/app目錄下的apk流程。

在這裏插入圖片描述

5、app啓動

Android開機啓動時,會依次自動啓動SystemUI、Persistent App、Home,流程如下圖。

在這裏插入圖片描述

Persistent App即AndroidManifest.xml中application的android:persistent屬性設置爲true,默認爲false,詳細說明如下。

android:persistent
Whether or not the application should remain running at all times — “true” if it should, and “false” if not. The default value is “false”. Applications should not normally set this flag; persistence mode is intended only for certain system applications.

參考:https://developer.android.com/guide/topics/manifest/application-element#persistent

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章