public abstract class AbstractPluginConditionReceiver extends BroadcastReceiver
Abstract superclass for a plug-in condition BroadcastReceiver implementation.
The plug-in receiver lifecycle is as follows:
onReceive(android.content.Context, android.content.Intent)
is called by the Android
frameworks.
onReceive() will verify that the Intent is valid. If the Intent is invalid, then the receiver
sets the result to RESULT_CONDITION_UNKNOWN
and
returns. If the Intent appears to be valid, then the lifecycle continues.isBundleValid(android.os.Bundle)
is called to determine whether EXTRA_BUNDLE
is valid. If the Bundle is
invalid, then the
receiver
sets the result to RESULT_CONDITION_UNKNOWN
and
returns. If the bundle is valid, then the lifecycle continues.isAsync()
is called to determine whether the remaining work should be performed on
a
background thread.getPluginConditionResult(android.content.Context, android.os.Bundle)
is called to
determine the plug-in's status, and the return value of this method is set as the receiver's
result code.
Implementations of this BroadcastReceiver must be registered in the Android
Manifest with an Intent filter for
ACTION_QUERY_CONDITION
. The
BroadcastReceiver must be exported, enabled, and cannot have permissions
enforced on it.
Modifier and Type | Class and Description |
---|---|
static interface |
AbstractPluginConditionReceiver.ConditionResult |
BroadcastReceiver.PendingResult
Constructor and Description |
---|
AbstractPluginConditionReceiver() |
Modifier and Type | Method and Description |
---|---|
protected abstract int |
getPluginConditionResult(Context context,
Bundle bundle)
Determines the state of the plug-in.
|
protected abstract boolean |
isAsync()
Configures the receiver whether it should process the Intent in a
background thread.
|
protected abstract boolean |
isBundleValid(Bundle bundle)
Gives the plug-in receiver an opportunity to validate the Bundle, to
ensure that a malicious application isn't attempting to pass
an invalid Bundle.
|
void |
onReceive(Context context,
Intent intent) |
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, goAsync, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras
public final void onReceive(Context context, Intent intent)
onReceive
in class BroadcastReceiver
protected abstract boolean isBundleValid(Bundle bundle)
Gives the plug-in receiver an opportunity to validate the Bundle, to ensure that a malicious application isn't attempting to pass an invalid Bundle.
This method will be called on the BroadcastReceiver's Looper (normatively the main thread)
bundle
- The plug-in's Bundle previously returned by the edit
Activity. bundle
should not be mutated by this method.bundle
appears to be valid. false if bundle
appears to be
invalid.protected abstract boolean isAsync()
getPluginConditionResult(Context, Bundle)
method performs any
sort of disk IO (ContentProvider query, reading SharedPreferences, etc.).
or other work that may be slow.
Asynchronous BroadcastReceivers are not supported prior to Honeycomb, so with older platforms broadcasts will always be processed on the BroadcastReceiver's Looper (which for Manifest registered receivers will be the main thread).
protected abstract int getPluginConditionResult(Context context, Bundle bundle)
isAsync()
returns true, this method will be called on a
background thread. If isAsync()
returns false, this method will
be called on the main thread. Regardless of which thread this method is
called on, this method MUST return within 10 seconds per the requirements
for BroadcastReceivers.context
- BroadcastReceiver context.bundle
- The plug-in's Bundle previously returned by the edit
Activity.RESULT_CONDITION_SATISFIED
,
RESULT_CONDITION_UNSATISFIED
, or
RESULT_CONDITION_UNKNOWN
. If bundle
is invalid, implementations must return
RESULT_CONDITION_UNKNOWN