Android应用程序组件Content Provider的启动过程源代码分析(4)
-
if (r != null && cpr.canRunHere(r)) {
-
// If this is a multiprocess provider, then just return its
-
// info and allow the caller to instantiate it. Only do
-
// this if the provider is the same user as the caller's
-
// process, or can run as root (so can be in any process).
-
return cpr;
-
}
-
// This is single process, and our app is now connecting to it.
-
// See if we are already in the process of launching this
-
// provider.
-
final int N = mLaunchingProviders.size();
-
int i;
-
for (i=0; i<N; i++) {
-
if (mLaunchingProviders.get(i) == cpr) {
-
break;
-
}
-
}
-
// If the provider is not already being launched, then get it
-
// started.
-
if (i >= N) {
-
final long origId = Binder.clearCallingIdentity();
-
ProcessRecord proc = startProcessLocked(cpi.processName,
-
cpr.appInfo, false, 0, "content provider",
-
new ComponentName(cpi.applicationInfo.packageName,
-
cpi.name), false);
-
......
-
mLaunchingProviders.add(cpr);
-
......
-
}
-
// Make sure the provider is published (the same provider class
-
// may be published under multiple names).
-
if (firstClass) {
-
mProvidersByClass.put(cpi.name, cpr);
-
}
-
cpr.launchingApp = proc;
-
mProvidersByName.put(name, cpr);
-
// Wait for the provider to be published...
-
synchronized (cpr) {
-
while (cpr.provider == null) {
-
......
-
try {
-
cpr.wait();
-
} catch (InterruptedException ex) {
-
}
-
}
-
}
这五步是标准的Android应用程序启动步骤,具体可以参考 Android应用程序启动过程源代码分析 一文中的Step 23到Step 27,或者 Android系统在新进程中启动自定义服务过程(startService)的原理分析 一文中的Step 4到Step 9,这里就不再详细描述了。