正文
Binder
.
restoreCallingIdentity
(
origId
);
return
res
;
}
}
在上述的代码中,调用了ActiveServices的startServiceLocked方法,那么现在Service的启动过程从AMS转移到了ActiveServices了。
继续跟进ActiveServices的startServiceLocked方法,如下:
ComponentName startServiceLocked
(
IApplicationThread
caller
,
Intent
service
,
String
resolvedType
,
int
callingPid
,
int
callingUid
,
String
callingPackage
,
int
userId
)
throws
TransactionTooLargeException
{
//代码省略
ServiceLookupResult
res
=
retrieveServiceLocked
(
service
,
resolvedType
,
callingPackage
,
callingPid
,
callingUid
,
userId
,
true
,
callerFg
);
//代码省略
ServiceRecord
r
=
res
.
record
;
//代码省略
return
startServiceInnerLocked
(
smap
,
service
,
r
,
callerFg
,
addToStarting
);
}
在startServiceLocked方法中又会调用startServiceInnerLocked方法,
我们瞧瞧startServiceInnerLocked方法,
ComponentName startServiceInnerLocked
(
ServiceMap
smap
,
Intent
service
,
ServiceRecord
r
,
boolean
callerFg
,
boolean
addToStarting
)
throws
TransactionTooLargeException
{
ProcessStats
.
ServiceState
stracker
=
r
.
getTracker
();
if
(
stracker
!=
null
)
{
stracker
.
setStarted
(
true
,
mAm
.
mProcessStats
.
getMemFactorLocked
(),
r
.
lastActivity
);
}
r
.
callStart
=
false
;
synchronized
(
r
.
stats
.
getBatteryStats
())
{
r
.
stats
.
startRunningLocked
();
}
String
error
=
bringUpServiceLocked
(
r
,
service
.
getFlags
(),
callerFg
,
false
);
//代码省略
return
r
.