1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/background/healthreport/HealthReportBroadcastReceiver.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,41 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.background.healthreport; 1.9 + 1.10 +import org.mozilla.gecko.background.common.log.Logger; 1.11 + 1.12 +import android.content.BroadcastReceiver; 1.13 +import android.content.Context; 1.14 +import android.content.Intent; 1.15 + 1.16 +/** 1.17 + * Watch for notifications to start Health Report background services. 1.18 + * 1.19 + * Some observations: 1.20 + * 1.21 + * From the Android documentation: "Also note that as of Android 3.0 the user 1.22 + * needs to have started the application at least once before your application 1.23 + * can receive android.intent.action.BOOT_COMPLETED events." 1.24 + * 1.25 + * We really do want to launch on BOOT_COMPLETED, since it's possible for a user 1.26 + * to run Firefox, shut down the phone, then power it on again on the same day. 1.27 + * We want to submit a health report in this case, even though they haven't 1.28 + * launched Firefox since boot. 1.29 + */ 1.30 +public class HealthReportBroadcastReceiver extends BroadcastReceiver { 1.31 + public static final String LOG_TAG = HealthReportBroadcastReceiver.class.getSimpleName(); 1.32 + 1.33 + /** 1.34 + * Forward the intent to an IntentService to do background processing. 1.35 + */ 1.36 + @Override 1.37 + public void onReceive(Context context, Intent intent) { 1.38 + Logger.debug(LOG_TAG, "Received intent - forwarding to BroadcastService."); 1.39 + Intent service = new Intent(context, HealthReportBroadcastService.class); 1.40 + service.putExtras(intent); 1.41 + service.setAction(intent.getAction()); 1.42 + context.startService(service); 1.43 + } 1.44 +}