Bug 1241810 - Run setup on app start and when the device boots. r=mcomella
MozReview-Commit-ID: 4k5KqnjLg3L
--- a/mobile/android/base/AndroidManifest.xml.in
+++ b/mobile/android/base/AndroidManifest.xml.in
@@ -357,16 +357,24 @@
android:exported="false"
android:name="org.mozilla.gecko.feeds.FeedService">
</service>
<receiver
android:name="org.mozilla.gecko.feeds.FeedAlarmReceiver"
android:exported="false" />
+ <receiver
+ android:name="org.mozilla.gecko.BootReceiver"
+ android:exported="false">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED"></action>
+ </intent-filter>
+ </receiver>
+
<service
android:name="org.mozilla.gecko.telemetry.TelemetryUploadService"
android:exported="false"/>
#include ../services/manifests/FxAccountAndroidManifest_services.xml.in
<service
android:name="org.mozilla.gecko.tabqueue.TabReceivedService"
--- a/mobile/android/base/FennecManifest_permissions.xml.in
+++ b/mobile/android/base/FennecManifest_permissions.xml.in
@@ -24,16 +24,17 @@
<uses-permission android:name="@ANDROID_PACKAGE_NAME@.permission.PER_ANDROID_PACKAGE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- READ_EXTERNAL_STORAGE was added in API 16, and is only enforced in API
19+. We declare it so that the bouncer APK and the main APK have the
same set of permissions. -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/BootReceiver.java
@@ -0,0 +1,27 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+import org.mozilla.gecko.feeds.FeedService;
+
+/**
+ * This broadcast receiver receives ACTION_BOOT_COMPLETED broadcasts and starts components that should
+ * run after the device has booted.
+ */
+public class BootReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent == null || !intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
+ return; // This is not the broadcast you are looking for.
+ }
+
+ FeedService.setup(context);
+ }
+}
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -20,16 +20,17 @@ import org.mozilla.gecko.animation.ViewH
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.SuggestedSites;
import org.mozilla.gecko.distribution.Distribution;
import org.mozilla.gecko.dlc.DownloadContentService;
import org.mozilla.gecko.favicons.Favicons;
import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
import org.mozilla.gecko.favicons.decoders.IconDirectoryEntry;
+import org.mozilla.gecko.feeds.FeedService;
import org.mozilla.gecko.firstrun.FirstrunAnimationContainer;
import org.mozilla.gecko.gfx.DynamicToolbarAnimator;
import org.mozilla.gecko.gfx.DynamicToolbarAnimator.PinReason;
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.home.BrowserSearch;
import org.mozilla.gecko.home.HomeBanner;
import org.mozilla.gecko.home.HomeConfig;
@@ -1906,16 +1907,18 @@ public class BrowserApp extends GeckoApp
}
}, oneSecondInMillis);
}
if (AppConstants.MOZ_ANDROID_DOWNLOAD_CONTENT_SERVICE) {
DownloadContentService.startVerification(this);
}
+ FeedService.setup(this);
+
super.handleMessage(event, message);
} else if (event.equals("Gecko:Ready")) {
// Handle this message in GeckoApp, but also enable the Settings
// menuitem, which is specific to BrowserApp.
super.handleMessage(event, message);
final Menu menu = mMenu;
ThreadUtils.postToUiThread(new Runnable() {
@Override
--- a/mobile/android/base/java/org/mozilla/gecko/feeds/FeedService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/feeds/FeedService.java
@@ -28,16 +28,22 @@ public class FeedService extends IntentS
private static final String LOGTAG = "GeckoFeedService";
public static final String ACTION_SETUP = AppConstants.ANDROID_PACKAGE_NAME + ".FEEDS.SETUP";
public static final String ACTION_SUBSCRIBE = AppConstants.ANDROID_PACKAGE_NAME + ".FEEDS.SUBSCRIBE";
public static final String ACTION_CHECK = AppConstants.ANDROID_PACKAGE_NAME + ".FEEDS.CHECK";
public static final String ACTION_ENROLL = AppConstants.ANDROID_PACKAGE_NAME + ".FEEDS.ENROLL";
public static final String ACTION_WITHDRAW = AppConstants.ANDROID_PACKAGE_NAME + ".FEEDS.WITHDRAW";
+ public static void setup(Context context) {
+ Intent intent = new Intent(context, FeedService.class);
+ intent.setAction(ACTION_SETUP);
+ context.startService(intent);
+ }
+
public static void subscribe(Context context, String guid, String feedUrl) {
Intent intent = new Intent(context, FeedService.class);
intent.setAction(ACTION_SUBSCRIBE);
intent.putExtra(SubscribeAction.EXTRA_GUID, guid);
intent.putExtra(SubscribeAction.EXTRA_FEED_URL, feedUrl);
context.startService(intent);
}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -198,16 +198,17 @@ gbjar.sources += ['java/org/mozilla/geck
'animation/HeightChangeAnimation.java',
'animation/PropertyAnimator.java',
'animation/Rotate3DAnimation.java',
'animation/TransitionsTracker.java',
'animation/ViewHelper.java',
'ANRReporter.java',
'AppNotificationClient.java',
'BaseGeckoInterface.java',
+ 'BootReceiver.java',
'BrowserApp.java',
'BrowserLocaleManager.java',
'ContactService.java',
'ContextGetter.java',
'CrashHandler.java',
'CustomEditText.java',
'DataReportingNotification.java',
'db/AbstractPerProfileDatabaseProvider.java',