public final class QueryReceiver extends BroadcastReceiver
{ int messageID;
//**
// * @param context {@inheritDoc}.
//* @param intent the incoming {@link com.twofortyfouram.locale.Intent#ACTION_QUERY_CONDITION} Intent. This
//* should always contain the {@link com.twofortyfouram.locale.Intent#EXTRA_BUNDLE} that was
//* saved by {@link EditActivity} and later broadcast by Locale.
//*/
@Override
public void onReceive(final Context context, final Intent intent)
{
/*
* Always be strict on input parameters! A malicious third-party app could send a malformed Intent.
*/
if (!com.twofortyfouram.locale.Intent.ACTION_QUERY_CONDITION.equals(intent.getAction()))
{
if (Constants.IS_LOGGABLE)
{
Log.e(Constants.LOG_TAG,
String.format(Locale.US, "Received unexpected Intent action %s", intent.getAction())); //$NON-NLS-1$
}
return;
}
BundleScrubber.scrub(intent);
final String pageButtonPressed = intent.getStringExtra("PAGE_ID");
final Bundle bundle = intent.getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);
BundleScrubber.scrub(bundle);
if (PluginBundleManager.isBundleValid(bundle))
{
final String eventButtonPressed = bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING);
System.out.println("eventButtonPressed is" + eventButtonPressed);
System.out.println("pageButtonPressed is" + pageButtonPressed);
if ( messageID == -1 )
setResultCode( com.twofortyfouram.locale.Intent.RESULT_CONDITION_UNKNOWN );
else
{
if (pageButtonPressed != null && eventButtonPressed == pageButtonPressed)
{
setResultCode(com.twofortyfouram.locale.Intent.RESULT_CONDITION_SATISFIED);
}
else
{
setResultCode(com.twofortyfouram.locale.Intent.RESULT_CONDITION_UNSATISFIED);
}
}
// * Because conditions are queried in the background and possibly while the phone is asleep, it is
// * necessary to acquire a WakeLock in order to guarantee that the service is started.
//*/
ServiceWakeLockManager.aquireLock(context);