Bug 1243585 - Remove unused BackgroundService & related code. r=sebastian
Note: this is still not expected to compile.
MozReview-Commit-ID: KTMyKTHm1RS
--- a/mobile/android/base/android-services.mozbuild
+++ b/mobile/android/base/android-services.mozbuild
@@ -759,17 +759,16 @@ sync_thirdparty_java_files = [
'org/mozilla/apache/commons/codec/net/URLCodec.java',
'org/mozilla/apache/commons/codec/net/Utils.java',
'org/mozilla/apache/commons/codec/StringDecoder.java',
'org/mozilla/apache/commons/codec/StringEncoder.java',
'org/mozilla/apache/commons/codec/StringEncoderComparator.java',
]
sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozilla/gecko/' + x for x in [
- 'background/BackgroundService.java',
'background/common/EditorBranch.java',
'background/common/GlobalConstants.java',
'background/common/log/Logger.java',
'background/common/log/writers/AndroidLevelCachingLogWriter.java',
'background/common/log/writers/AndroidLogWriter.java',
'background/common/log/writers/LevelFilteringLogWriter.java',
'background/common/log/writers/LogWriter.java',
'background/common/log/writers/PrintLogWriter.java',
deleted file mode 100644
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/background/BackgroundService.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/* 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.background;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.mozilla.gecko.background.common.log.Logger;
-
-import android.app.AlarmManager;
-import android.app.IntentService;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.os.Build;
-
-public abstract class BackgroundService extends IntentService {
- private static final String LOG_TAG = BackgroundService.class.getSimpleName();
-
- protected BackgroundService() {
- super(LOG_TAG);
- }
-
- protected BackgroundService(String threadName) {
- super(threadName);
- }
-
- public static void runIntentInService(Context context, Intent intent, Class<? extends BackgroundService> serviceClass) {
- Intent service = new Intent(context, serviceClass);
- service.setAction(intent.getAction());
- service.putExtras(intent);
- context.startService(service);
- }
-
- /**
- * Returns true if the OS will allow us to perform background
- * data operations. This logic varies by OS version.
- */
- @SuppressWarnings("deprecation")
- protected static boolean backgroundDataIsEnabled(final Context context) {
- final ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
- return connectivity.getBackgroundDataSetting();
- }
- NetworkInfo networkInfo = connectivity.getActiveNetworkInfo();
- if (networkInfo == null) {
- return false;
- }
- return networkInfo.isAvailable();
- }
-
- protected AlarmManager getAlarmManager() {
- return getAlarmManager(this.getApplicationContext());
- }
-
- protected static AlarmManager getAlarmManager(Context context) {
- return (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- }
-
- protected void scheduleAlarm(long pollInterval, PendingIntent pendingIntent) {
- Logger.info(LOG_TAG, "Setting inexact repeating alarm for interval " + pollInterval);
- if (pollInterval <= 0) {
- throw new IllegalArgumentException("pollInterval " + pollInterval + " must be positive");
- }
- final AlarmManager alarm = getAlarmManager();
- final long firstEvent = System.currentTimeMillis();
- alarm.setInexactRepeating(AlarmManager.RTC, firstEvent, pollInterval, pendingIntent);
- }
-
- protected void cancelAlarm(PendingIntent pendingIntent) {
- final AlarmManager alarm = getAlarmManager();
- alarm.cancel(pendingIntent);
- // For testing - allows us to see if the intent, and thus the alarm, has been cancelled.
- pendingIntent.cancel();
- }
-
- /**
- * To avoid tight coupling to Fennec, we use reflection to find
- * <code>GeckoPreferences</code>, invoking the same code path that
- * <code>GeckoApp</code> uses on startup to send the <i>other</i>
- * notification to which we listen.
- *
- * Invoke this to handle one of the system intents to which we listen to
- * launch our service without the browser being opened.
- *
- * All of this is neatly wrapped in <code>try…catch</code>, so this code
- * will run safely without a Firefox build installed.
- */
- protected static void reflectContextToFennec(Context context, String className, String methodName) {
- // Ask the browser to tell us the current state of the preference.
- try {
- Class<?> geckoPreferences = Class.forName(className);
- Method broadcastSnippetsPref = geckoPreferences.getMethod(methodName, Context.class);
- broadcastSnippetsPref.invoke(null, context);
- return;
- } catch (ClassNotFoundException e) {
- Logger.error(LOG_TAG, "Class " + className + " not found!");
- return;
- } catch (NoSuchMethodException e) {
- Logger.error(LOG_TAG, "Method " + className + "/" + methodName + " not found!");
- return;
- } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
- Logger.error(LOG_TAG, "Got exception invoking " + methodName + ".");
- }
- }
-}
--- a/mobile/android/tests/background/junit3/background_junit3_sources.mozbuild
+++ b/mobile/android/tests/background/junit3/background_junit3_sources.mozbuild
@@ -18,17 +18,16 @@ background_junit3_sources = [
'src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java',
'src/org/mozilla/gecko/background/db/TestFormHistoryRepositorySession.java',
'src/org/mozilla/gecko/background/db/TestPasswordsRepository.java',
'src/org/mozilla/gecko/background/db/TestTopSites.java',
'src/org/mozilla/gecko/background/fxa/authenticator/TestAccountPickler.java',
'src/org/mozilla/gecko/background/fxa/TestAccountLoader.java',
'src/org/mozilla/gecko/background/fxa/TestBrowserIDKeyPairGeneration.java',
'src/org/mozilla/gecko/background/helpers/AndroidSyncTestCase.java',
- 'src/org/mozilla/gecko/background/helpers/BackgroundServiceTestCase.java',
'src/org/mozilla/gecko/background/helpers/DBHelpers.java',
'src/org/mozilla/gecko/background/helpers/DBProviderTestCase.java',
'src/org/mozilla/gecko/background/nativecode/test/TestNativeCrypto.java',
'src/org/mozilla/gecko/background/sync/AndroidSyncTestCaseWithAccounts.java',
'src/org/mozilla/gecko/background/sync/helpers/BookmarkHelpers.java',
'src/org/mozilla/gecko/background/sync/helpers/DefaultBeginDelegate.java',
'src/org/mozilla/gecko/background/sync/helpers/DefaultCleanDelegate.java',
'src/org/mozilla/gecko/background/sync/helpers/DefaultDelegate.java',
deleted file mode 100644
--- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/BackgroundServiceTestCase.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ */
-
-package org.mozilla.gecko.background.helpers;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.test.ServiceTestCase;
-import java.util.concurrent.BrokenBarrierException;
-import java.util.concurrent.CyclicBarrier;
-import java.util.UUID;
-
-import org.mozilla.gecko.background.common.GlobalConstants;
-
-/**
- * An abstract test class for testing background services. Since we have to wait for background
- * services to finish before asserting the changed state, this class provides much of the
- * functionality to do this. Extending classes need still need to implement some of the components -
- * see {@link TestHealthReportBroadcastService} for an example.
- */
-public abstract class BackgroundServiceTestCase<T extends Service> extends ServiceTestCase<T> {
- private static final String SHARED_PREFS_PREFIX = "BackgroundServiceTestCase-";
- // Ideally, this would not be static so multiple test classes can be run in parallel. However,
- // mServiceClass can only retrieve this reference statically because mServiceClass cannot get a
- // reference to the Test* class as ServiceTestCase instantiates it via reflection and we can't
- // pass it as a constructor arg.
- protected static String sharedPrefsName;
-
- private final Class<T> mServiceClass;
-
- protected static CyclicBarrier barrier;
- protected Intent intent;
-
- public BackgroundServiceTestCase(Class<T> serviceClass) {
- super(serviceClass);
- mServiceClass = serviceClass;
- }
-
- @Override
- public void setUp() throws Exception {
- barrier = new CyclicBarrier(2);
- intent = new Intent(getContext(), mServiceClass);
- sharedPrefsName = SHARED_PREFS_PREFIX + mServiceClass.getName() + "-" + UUID.randomUUID();
- }
-
- @Override
- public void tearDown() throws Exception {
- barrier = null;
- intent = null;
- clearSharedPrefs(); // Not necessary but reduces file system cruft.
- }
-
- protected SharedPreferences getSharedPreferences() {
- return getContext().getSharedPreferences(sharedPrefsName,
- GlobalConstants.SHARED_PREFERENCES_MODE);
- }
-
- protected void clearSharedPrefs() {
- getSharedPreferences().edit()
- .clear()
- .commit();
- }
-
- protected void await() {
- try {
- barrier.await();
- } catch (InterruptedException e) {
- fail("Test runner thread should not be interrupted.");
- } catch (BrokenBarrierException e) {
- fail("Background services should not timeout or be interrupted");
- }
- }
-
- protected void cancelAlarm(Intent intent) {
- final AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
- final PendingIntent pi = PendingIntent.getService(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- am.cancel(pi);
- pi.cancel();
- }
-
- protected boolean isServiceAlarmSet(Intent intent) {
- return PendingIntent.getService(getContext(), 0, intent, PendingIntent.FLAG_NO_CREATE) != null;
- }
-}