mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-26 04:22:30 -10:00
#!/bin/bash set -x pushd mobile/android/base # Can't be present in glob below. rm -rf java/org/mozilla/gecko for i in */ ; do # But is necessary to copy into. mkdir -p java/org/mozilla/gecko hg mv $i java/org/mozilla/gecko ; done hg mv *.java java/org/mozilla/gecko # Move back stuff we didn't want to move. hg mv java/org/mozilla/gecko/crashreporter crashreporter hg mv java/org/mozilla/gecko/docs docs hg mv java/org/mozilla/gecko/locales locales hg mv java/org/mozilla/gecko/resources resources popd
90 lines
3.0 KiB
Java
90 lines
3.0 KiB
Java
/* -*- 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 android.content.IntentFilter;
|
|
import android.net.ConnectivityManager;
|
|
import android.net.NetworkInfo;
|
|
import android.util.Log;
|
|
|
|
public class GeckoConnectivityReceiver extends BroadcastReceiver {
|
|
/*
|
|
* Keep the below constants in sync with
|
|
* http://mxr.mozilla.org/mozilla-central/source/netwerk/base/nsINetworkLinkService.idl
|
|
*/
|
|
private static final String LINK_DATA_UP = "up";
|
|
private static final String LINK_DATA_DOWN = "down";
|
|
private static final String LINK_DATA_CHANGED = "changed";
|
|
private static final String LINK_DATA_UNKNOWN = "unknown";
|
|
|
|
private static final String LOGTAG = "GeckoConnectivityReceiver";
|
|
|
|
private static final GeckoConnectivityReceiver sInstance = new GeckoConnectivityReceiver();
|
|
|
|
private final IntentFilter mFilter;
|
|
private Context mApplicationContext;
|
|
private boolean mIsEnabled;
|
|
|
|
public static GeckoConnectivityReceiver getInstance() {
|
|
return sInstance;
|
|
}
|
|
|
|
private GeckoConnectivityReceiver() {
|
|
mFilter = new IntentFilter();
|
|
mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
|
}
|
|
|
|
public synchronized void start(Context context) {
|
|
if (mIsEnabled) {
|
|
Log.w(LOGTAG, "Already started!");
|
|
return;
|
|
}
|
|
|
|
mApplicationContext = context.getApplicationContext();
|
|
|
|
// registerReceiver will return null if registering fails.
|
|
if (mApplicationContext.registerReceiver(this, mFilter) == null) {
|
|
Log.e(LOGTAG, "Registering receiver failed");
|
|
} else {
|
|
mIsEnabled = true;
|
|
}
|
|
}
|
|
|
|
public synchronized void stop() {
|
|
if (!mIsEnabled) {
|
|
Log.w(LOGTAG, "Already stopped!");
|
|
return;
|
|
}
|
|
|
|
mApplicationContext.unregisterReceiver(this);
|
|
mApplicationContext = null;
|
|
mIsEnabled = false;
|
|
}
|
|
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
NetworkInfo info = cm.getActiveNetworkInfo();
|
|
|
|
final String status;
|
|
if (info == null) {
|
|
status = LINK_DATA_UNKNOWN;
|
|
} else if (!info.isConnected()) {
|
|
status = LINK_DATA_DOWN;
|
|
} else {
|
|
status = LINK_DATA_UP;
|
|
}
|
|
|
|
if (GeckoThread.isRunning()) {
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createNetworkLinkChangeEvent(status));
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createNetworkLinkChangeEvent(LINK_DATA_CHANGED));
|
|
}
|
|
}
|
|
}
|