The APK program under the Android system is managed by the package management Service called Packagemanagerservice. Packetmanagerservice is an important service of Android system, launched by Systemserver, mainly implements APK package parsing, installation, updating, mobile, uninstall and other services. Whether it's a system apk (/system/app), or we install it manually, all of the system's APK is managed by it.
Take the Android 4.0.4 source code as an example, Android4.0.4/frameworks/base/services/java/com/android/server/systemserver.java in the Run () The function is the implementation process for all system services that the Systemserver component initiates, including Packagemanagerservice. An object of the Packagemanagerservice class is defined in line 112 of the file.
Ipackagemanager pm = null; Defines an object of a Packagemanagerservice class
and then from 163 Line start to 170 line implementation of the Packagemanagerservice object construction process, in fact, here is the most complex? Packagemanagerservice the process of constructing an object, the startup process is relatively straightforward.
PM = Packagemanagerservice.main (context, factorytest! = Systemserver.factory_test_off, onlycore); Starting Packagemanagerservice, the implementation of this main function is shown in the current directory Pm/packagemanagerservice.java 831 lines Boolean firstboot = false; Determines whether the Packagemanagerservice is the first start of the try { firstboot = Pm.isfirstboot (); } catch (RemoteException e) { } Packagemanagerservice.main () This function implements the Packagemanagerservice startup and registration process, the code is as follows: public static Final Ipackagemanager Main (Context context, Boolean factorytest, boolean onlycore) { Packagemanagerservice m = new Packagemanagerservice (context, factorytest, onlycore); A Packagemanagerservice object is constructed here and the servicemanager.addservice ("package", m) is started; Register Packagemanagerservice to ServiceManager return m; }