1
2
3
4
5
6
|
<
receiver
android:name
=
"com.roger.BroadcastTest.Receiver"
android:enabled
=
"true"
android:exported
=
"true"
>
<
intent-filter
>
<
action
android:name
=
"android.intent.action.BOOT_COMPLETED"
>
<
action
android:name
=
"com.roger.broadcast.test"
>
action
>
action
>
intent-filter
>
receiver
>
|
1
2
3
4
5
6
7
8
|
public
class
Receiver
extends
BroadcastReceiver {
@Override
public
void
onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Log.i(
"Tag"
,
"receive:"
+ arg1.getAction());
}
}
|
1
2
3
4
5
|
/** @hide */
public
boolean
isExcludingStopped() {
return
(mFlags&(FLAG_EXCLUDE_STOPPED_PACKAGES|FLAG_INCLUDE_STOPPED_PACKAGES))
== FLAG_EXCLUDE_STOPPED_PACKAGES;
}
|
1
|
final
boolean
excludingStopped = intent.isExcludingStopped();
|
1
2
3
4
5
6
|
if
(excludingStopped && isFilterStopped(filter, userId)) {
if
(debug) {
Slog.v(TAG,
" Filter's target is stopped; skipping"
);
}
continue
;
}
|
1
2
3
4
5
6
7
8
|
/**
* Returns whether the object associated with the given filter is
* "stopped," that is whether it should not be included in the result
* if the intent requests to excluded stopped objects.
*/
protected
boolean
isFilterStopped(F filter,
int
userId) {
return
false
;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
|
@Override
protected
boolean
isFilterStopped(PackageParser.ActivityIntentInfo filter,
int
userId) {
if
(!sUserManager.exists(userId))
return
true
;
PackageParser.Package p = filter.activity.owner;
if
(p !=
null
) {
PackageSetting ps = (PackageSetting)p.mExtras;
if
(ps !=
null
) {
// System apps are never considered stopped for purposes of
// filtering, because there may be no way for the user to
// actually re-launch them.
return
(ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) ==
0
&& ps.getStopped(userId);
}
}
return
false
;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
|
// All available activities, for your resolving pleasure.
final
ActivityIntentResolver mActivities =
new
ActivityIntentResolver();
// All available receivers, for your resolving pleasure.
final
ActivityIntentResolver mReceivers =
new
ActivityIntentResolver();
// All available services, for your resolving pleasure.
final
ServiceIntentResolver mServices =
new
ServiceIntentResolver();
// All available providers, for your resolving pleasure.
final
ProviderIntentResolver mProviders =
new
ProviderIntentResolver();
|
1
2
3
|
void
setStopped(
boolean
stop,
int
userId) {
modifyUserState(userId).stopped = stop;
}
|
1
2
3
4
5
6
|
// Launching this app's activity, make sure the app is no longer
// considered stopped.
try
{
AppGlobals.getPackageManager().setPackageStoppedState(
next.packageName,
false
, next.userId);
/* TODO: Verify if correct userid */
}
|
01
02
03
04
05
06
07
08
09
10
11
|
// Service is now being launched, its package can't be stopped.
try
{
AppGlobals.getPackageManager().setPackageStoppedState(
r.packageName,
false
, r.userId);
}
ActivityManagerService中
// Content provider is now in use, its package can't be stopped.
try
{
AppGlobals.getPackageManager().setPackageStoppedState(
cpr.appInfo.packageName,
false
, userId);
}
|
1
2
3
4
5
|
// Broadcast is being executed, its package can't be stopped.
try
{
AppGlobals.getPackageManager().setPackageStoppedState(
r.curComponent.getPackageName(),
false
, UserHandle.getUserId(r.callingUid));
}
|
1
2
3
4
5
6
|
private
void
killProcesses() {
ActivityManager am = (ActivityManager)getActivity().getSystemService(
Context.ACTIVITY_SERVICE);
am.forceStopPackage(mEntry.mUiPackage);
checkForceStop();
}
|