start-scan:
@startuml
participant SystemServer as SS
participant PackageManagerService as PKMS
participant ParallelPackageParser as P_PP
participant PackageParser as PP
==PKMS START and scan apk==
SS -> SS: run
SS -> SS: startBootstrapServices
activate SS
SS -> PKMS : mPackageManagerService = PackageManagerService.main
activate PKMS
PKMS -> PKMS: m = new PackageManagerService
'construct call'
activate PKMS #FF55FF
==scan apk ==
PKMS -> PKMS:scanDirTracedLI:dir
loop for file in dir
PKMS -> P_PP : parallelPackageParser.submit
P_PP -> PP: PackageParser.Package pr = packageParser.parsePackage\n(scanFile, parseFlags, true)
alt if packageFile.isDirectory()
PP -> PP: parsed = parseClusterPackage(packageFile, flags);
else
PP -> PP: parsed = parseMonolithicPackage(packageFile, flags);
activate PP #FF55FF
PP -> PP:parseBaseApk(apkFile, assets, flags)
activate PP #FFFF55
PP -> PP:parseBaseApkCommon
PP->PP: parse the AndroidManifest.xml
deactivate PP
PP -> PP:return pkg;
deactivate PP
end
PP->P_PP: return parsed
P_PP -> P_PP:mQueue.put(pr)
PKMS -> P_PP :ParallelPackageParser.ParseResult parseResult\n = parallelPackageParser.take
note left
get the parse result from the mQueue
end note
alt no error case
PKMS -> PKMS: <b>scanPackageLI</b>(parseResult.pkg,parseResult.scanFile,```)
activate PKMS #FFFF55
PKMS -> PKMS:<b>scanPackageInternalLI</b>
PKMS -> PKMS:check something about apk update
PKMS -> PKMS:collectCertificatesLI
note left
verify the apk and collect certificates,
if verify ok:
collect certificates to Package.mCertificates
if fail:
throw SignatureException/GeneralSecurityException/...
end note
PKMS -> PKMS:<b>scanPackageLI</b>(pkg, policyFlags,...)
note left
the another method of scanPackageLI
end note
PKMS -> PKMS:scanPackageDirtyLI
alt if scanFlags & SCAN_CHECK_ONLY) != 0
else else: update this package info to <b>PKMS</b>
PKMS -> PKMS:commitPackageSettings
PKMS -> PKMS:<b>mPackages.put(pkg.applicationInfo.packageName, pkg)&