зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1286662 - Add native methods for GeckoNetworkManager notifications; r=snorp
Add and use onConnectionChanged and onStatusChanged native methods in GeckoNetworkManager in place of the network events in GeckoEvent.
This commit is contained in:
Родитель
44909016ff
Коммит
071e1acf10
|
@ -6,6 +6,7 @@
|
||||||
package org.mozilla.gecko;
|
package org.mozilla.gecko;
|
||||||
|
|
||||||
import org.mozilla.gecko.annotation.JNITarget;
|
import org.mozilla.gecko.annotation.JNITarget;
|
||||||
|
import org.mozilla.gecko.annotation.WrapForJNI;
|
||||||
import org.mozilla.gecko.util.NativeEventListener;
|
import org.mozilla.gecko.util.NativeEventListener;
|
||||||
import org.mozilla.gecko.util.NativeJSObject;
|
import org.mozilla.gecko.util.NativeJSObject;
|
||||||
import org.mozilla.gecko.util.EventCallback;
|
import org.mozilla.gecko.util.EventCallback;
|
||||||
|
@ -72,8 +73,11 @@ public class GeckoNetworkManager extends BroadcastReceiver implements NativeEven
|
||||||
|
|
||||||
private ManagerState currentState = ManagerState.OffNoListeners;
|
private ManagerState currentState = ManagerState.OffNoListeners;
|
||||||
private ConnectionType currentConnectionType = ConnectionType.NONE;
|
private ConnectionType currentConnectionType = ConnectionType.NONE;
|
||||||
private NetworkStatus currentNetworkStatus = NetworkStatus.UNKNOWN;
|
private ConnectionType previousConnectionType = ConnectionType.NONE;
|
||||||
private ConnectionSubType currentConnectionSubtype = ConnectionSubType.UNKNOWN;
|
private ConnectionSubType currentConnectionSubtype = ConnectionSubType.UNKNOWN;
|
||||||
|
private ConnectionSubType previousConnectionSubtype = ConnectionSubType.UNKNOWN;
|
||||||
|
private NetworkStatus currentNetworkStatus = NetworkStatus.UNKNOWN;
|
||||||
|
private NetworkStatus previousNetworkStatus = NetworkStatus.UNKNOWN;
|
||||||
|
|
||||||
private enum InfoType {
|
private enum InfoType {
|
||||||
MCC,
|
MCC,
|
||||||
|
@ -283,27 +287,52 @@ public class GeckoNetworkManager extends BroadcastReceiver implements NativeEven
|
||||||
Log.d(LOGTAG, "New network state: " + currentNetworkStatus + ", " + currentConnectionType + ", " + currentConnectionSubtype);
|
Log.d(LOGTAG, "New network state: " + currentNetworkStatus + ", " + currentConnectionType + ", " + currentConnectionSubtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WrapForJNI
|
||||||
|
private static native void onConnectionChanged(int type, String subType,
|
||||||
|
boolean isWifi, int DHCPGateway);
|
||||||
|
|
||||||
|
@WrapForJNI
|
||||||
|
private static native void onStatusChanged(String status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send current network state and connection type as a GeckoEvent, to whomever is listening.
|
* Send current network state and connection type as a GeckoEvent, to whomever is listening.
|
||||||
*/
|
*/
|
||||||
private void sendNetworkStateToListeners() {
|
private void sendNetworkStateToListeners() {
|
||||||
final Context applicationContext = GeckoAppShell.getApplicationContext();
|
if (currentConnectionType != previousConnectionType ||
|
||||||
final GeckoEvent networkEvent = GeckoEvent.createNetworkEvent(
|
currentConnectionSubtype != previousConnectionSubtype) {
|
||||||
currentConnectionType.value,
|
previousConnectionType = currentConnectionType;
|
||||||
currentConnectionType == ConnectionType.WIFI,
|
previousConnectionSubtype = currentConnectionSubtype;
|
||||||
wifiDhcpGatewayAddress(applicationContext),
|
|
||||||
currentConnectionSubtype.value
|
|
||||||
);
|
|
||||||
final GeckoEvent networkLinkChangeValueEvent = GeckoEvent.createNetworkLinkChangeEvent(
|
|
||||||
currentNetworkStatus.value
|
|
||||||
);
|
|
||||||
final GeckoEvent networkLinkChangeNotificationEvent = GeckoEvent.createNetworkLinkChangeEvent(
|
|
||||||
LINK_DATA_CHANGED
|
|
||||||
);
|
|
||||||
|
|
||||||
GeckoAppShell.sendEventToGecko(networkEvent);
|
final boolean isWifi = currentConnectionType == ConnectionType.WIFI;
|
||||||
GeckoAppShell.sendEventToGecko(networkLinkChangeValueEvent);
|
final int gateway = !isWifi ? 0 :
|
||||||
GeckoAppShell.sendEventToGecko(networkLinkChangeNotificationEvent);
|
wifiDhcpGatewayAddress(GeckoAppShell.getApplicationContext());
|
||||||
|
|
||||||
|
if (GeckoThread.isRunning()) {
|
||||||
|
onConnectionChanged(currentConnectionType.value,
|
||||||
|
currentConnectionSubtype.value, isWifi, gateway);
|
||||||
|
} else {
|
||||||
|
GeckoThread.queueNativeCall(GeckoNetworkManager.class, "onConnectionChanged",
|
||||||
|
currentConnectionType.value,
|
||||||
|
String.class, currentConnectionSubtype.value,
|
||||||
|
isWifi, gateway);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final String status;
|
||||||
|
|
||||||
|
if (currentNetworkStatus != previousNetworkStatus) {
|
||||||
|
previousNetworkStatus = currentNetworkStatus;
|
||||||
|
status = currentNetworkStatus.value;
|
||||||
|
} else {
|
||||||
|
status = LINK_DATA_CHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GeckoThread.isRunning()) {
|
||||||
|
onStatusChanged(status);
|
||||||
|
} else {
|
||||||
|
GeckoThread.queueNativeCall(GeckoNetworkManager.class, "onStatusChanged",
|
||||||
|
String.class, status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
/* -*- Mode: c++; 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/. */
|
||||||
|
|
||||||
|
#ifndef GeckoNetworkManager_h
|
||||||
|
#define GeckoNetworkManager_h
|
||||||
|
|
||||||
|
#include "GeneratedJNINatives.h"
|
||||||
|
#include "nsAppShell.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsINetworkLinkService.h"
|
||||||
|
|
||||||
|
#include "mozilla/Services.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
class GeckoNetworkManager final
|
||||||
|
: public widget::GeckoNetworkManager::Natives<GeckoNetworkManager>
|
||||||
|
, public UsesGeckoThreadProxy
|
||||||
|
{
|
||||||
|
GeckoNetworkManager() = delete;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void
|
||||||
|
OnConnectionChanged(int32_t aType, jni::String::Param aSubType,
|
||||||
|
bool aIsWifi, int32_t aGateway)
|
||||||
|
{
|
||||||
|
hal::NotifyNetworkChange(hal::NetworkInformation(
|
||||||
|
aType, aIsWifi, aGateway));
|
||||||
|
|
||||||
|
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
||||||
|
if (os) {
|
||||||
|
os->NotifyObservers(nullptr,
|
||||||
|
NS_NETWORK_LINK_TYPE_TOPIC,
|
||||||
|
aSubType->ToString().get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
OnStatusChanged(jni::String::Param aStatus)
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||||
|
if (os) {
|
||||||
|
os->NotifyObservers(nullptr,
|
||||||
|
NS_NETWORK_LINK_TOPIC,
|
||||||
|
aStatus->ToString().get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif // GeckoNetworkManager_h
|
|
@ -61,6 +61,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ANRReporter.h"
|
#include "ANRReporter.h"
|
||||||
|
#include "GeckoNetworkManager.h"
|
||||||
#include "PrefsHelper.h"
|
#include "PrefsHelper.h"
|
||||||
|
|
||||||
#ifdef DEBUG_ANDROID_EVENTS
|
#ifdef DEBUG_ANDROID_EVENTS
|
||||||
|
@ -385,6 +386,7 @@ nsAppShell::nsAppShell()
|
||||||
GeckoAppShellSupport::Init();
|
GeckoAppShellSupport::Init();
|
||||||
GeckoThreadSupport::Init();
|
GeckoThreadSupport::Init();
|
||||||
mozilla::ANRReporter::Init();
|
mozilla::ANRReporter::Init();
|
||||||
|
mozilla::GeckoNetworkManager::Init();
|
||||||
mozilla::PrefsHelper::Init();
|
mozilla::PrefsHelper::Init();
|
||||||
nsWindow::InitNatives();
|
nsWindow::InitNatives();
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче