mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 939680 - Implement nsINetworkLinkService.linkType on Android r=blassey
This commit is contained in:
parent
219aad07eb
commit
06028442a6
@ -66,6 +66,7 @@ import android.os.MessageQueue;
|
||||
import android.os.SystemClock;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.util.DisplayMetrics;
|
||||
@ -133,6 +134,18 @@ public class GeckoAppShell
|
||||
static public final int WPL_STATE_IS_DOCUMENT = 0x00020000;
|
||||
static public final int WPL_STATE_IS_NETWORK = 0x00040000;
|
||||
|
||||
/* Keep in sync with constants found here:
|
||||
http://mxr.mozilla.org/mozilla-central/source/netwerk/base/public/nsINetworkLinkService.idl
|
||||
*/
|
||||
static public final int LINK_TYPE_UNKNOWN = 0;
|
||||
static public final int LINK_TYPE_ETHERNET = 1;
|
||||
static public final int LINK_TYPE_USB = 2;
|
||||
static public final int LINK_TYPE_WIFI = 3;
|
||||
static public final int LINK_TYPE_WIMAX = 4;
|
||||
static public final int LINK_TYPE_2G = 5;
|
||||
static public final int LINK_TYPE_3G = 6;
|
||||
static public final int LINK_TYPE_4G = 7;
|
||||
|
||||
public static final String SHORTCUT_TYPE_WEBAPP = "webapp";
|
||||
public static final String SHORTCUT_TYPE_BOOKMARK = "bookmark";
|
||||
|
||||
@ -1532,6 +1545,65 @@ public class GeckoAppShell
|
||||
return true;
|
||||
}
|
||||
|
||||
@GeneratableAndroidBridgeTarget
|
||||
public static int networkLinkType() {
|
||||
ConnectivityManager cm = (ConnectivityManager)
|
||||
getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo info = cm.getActiveNetworkInfo();
|
||||
if (info == null) {
|
||||
return LINK_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
switch (info.getType()) {
|
||||
case ConnectivityManager.TYPE_ETHERNET:
|
||||
return LINK_TYPE_ETHERNET;
|
||||
case ConnectivityManager.TYPE_WIFI:
|
||||
return LINK_TYPE_WIFI;
|
||||
case ConnectivityManager.TYPE_WIMAX:
|
||||
return LINK_TYPE_WIMAX;
|
||||
case ConnectivityManager.TYPE_MOBILE:
|
||||
break; // We will handle sub-types after the switch.
|
||||
default:
|
||||
Log.w(LOGTAG, "Ignoring the current network type.");
|
||||
return LINK_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
TelephonyManager tm = (TelephonyManager)
|
||||
getContext().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (tm == null) {
|
||||
Log.e(LOGTAG, "Telephony service does not exist");
|
||||
return LINK_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
switch (tm.getNetworkType()) {
|
||||
case TelephonyManager.NETWORK_TYPE_IDEN:
|
||||
case TelephonyManager.NETWORK_TYPE_CDMA:
|
||||
case TelephonyManager.NETWORK_TYPE_GPRS:
|
||||
return LINK_TYPE_2G;
|
||||
case TelephonyManager.NETWORK_TYPE_1xRTT:
|
||||
case TelephonyManager.NETWORK_TYPE_EDGE:
|
||||
return LINK_TYPE_2G; // 2.5G
|
||||
case TelephonyManager.NETWORK_TYPE_UMTS:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_0:
|
||||
return LINK_TYPE_3G;
|
||||
case TelephonyManager.NETWORK_TYPE_HSPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_A:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
||||
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
||||
return LINK_TYPE_3G; // 3.5G
|
||||
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
||||
return LINK_TYPE_3G; // 3.75G
|
||||
case TelephonyManager.NETWORK_TYPE_LTE:
|
||||
return LINK_TYPE_4G; // 3.9G
|
||||
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
|
||||
default:
|
||||
Log.w(LOGTAG, "Connected to an unknown mobile network!");
|
||||
return LINK_TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@GeneratableAndroidBridgeTarget
|
||||
public static void setSelectedLocale(String localeCode) {
|
||||
/* Bug 713464: This method is still called from Gecko side.
|
||||
|
@ -49,7 +49,13 @@ nsAndroidNetworkLinkService::GetLinkType(uint32_t *aLinkType)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aLinkType);
|
||||
|
||||
// XXX This function has not yet been implemented for this platform
|
||||
*aLinkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN;
|
||||
if (!mozilla::AndroidBridge::Bridge()) {
|
||||
// Fail soft here and assume a connection exists
|
||||
NS_WARNING("GetLinkType is not supported without a bridge connection");
|
||||
*aLinkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aLinkType = mozilla::AndroidBridge::Bridge()->NetworkLinkType();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ void AndroidBridge::InitStubs(JNIEnv *jEnv) {
|
||||
jLockScreenOrientation = getStaticMethod("lockScreenOrientation", "(I)V");
|
||||
jMarkURIVisited = getStaticMethod("markUriVisited", "(Ljava/lang/String;)V");
|
||||
jMoveTaskToBack = getStaticMethod("moveTaskToBack", "()V");
|
||||
jNetworkLinkType = getStaticMethod("networkLinkType", "()I");
|
||||
jNotifyDefaultPrevented = getStaticMethod("notifyDefaultPrevented", "(Z)V");
|
||||
jNotifyIME = getStaticMethod("notifyIME", "(I)V");
|
||||
jNotifyIMEChange = getStaticMethod("notifyIMEChange", "(Ljava/lang/String;III)V");
|
||||
@ -1451,6 +1452,33 @@ void AndroidBridge::MoveTaskToBack() {
|
||||
env->PopLocalFrame(NULL);
|
||||
}
|
||||
|
||||
int32_t AndroidBridge::NetworkLinkType() {
|
||||
JNIEnv *env = GetJNIEnv();
|
||||
if (!env) {
|
||||
ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (env->PushLocalFrame(0) != 0) {
|
||||
ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t temp = env->CallStaticIntMethod(mGeckoAppShellClass, jNetworkLinkType);
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
env->PopLocalFrame(NULL);
|
||||
return 0;
|
||||
}
|
||||
env->PopLocalFrame(NULL);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void AndroidBridge::NotifyDefaultPrevented(bool a0) {
|
||||
JNIEnv *env = GetJNIEnv();
|
||||
if (!env) {
|
||||
|
@ -50,6 +50,7 @@ jmethodID jKillAnyZombies;
|
||||
jmethodID jLockScreenOrientation;
|
||||
jmethodID jMarkURIVisited;
|
||||
jmethodID jMoveTaskToBack;
|
||||
jmethodID jNetworkLinkType;
|
||||
jmethodID jNotifyDefaultPrevented;
|
||||
jmethodID jNotifyIME;
|
||||
jmethodID jNotifyIMEChange;
|
||||
@ -160,6 +161,7 @@ void KillAnyZombies();
|
||||
void LockScreenOrientation(int32_t a0);
|
||||
void MarkURIVisited(const nsAString& a0);
|
||||
void MoveTaskToBack();
|
||||
int32_t NetworkLinkType();
|
||||
void NotifyDefaultPrevented(bool a0);
|
||||
static void NotifyIME(int32_t a0);
|
||||
static void NotifyIMEChange(const nsAString& a0, int32_t a1, int32_t a2, int32_t a3);
|
||||
|
Loading…
Reference in New Issue
Block a user