mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1236433 - Part 2: Adopt Wrapper in Network Utilities; r=edgar
--HG-- extra : transplant_source : %EC%8B%3C%1C%8C%D49%5B%C5%CB%2BMf%0F%CC%86%FB%0C%A0%BE
This commit is contained in:
parent
f4f2ecb435
commit
9670cbea5b
@ -7,10 +7,12 @@
|
||||
#include "NetUtils.h"
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <cutils/properties.h>
|
||||
#include "prinit.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "nsDebug.h"
|
||||
#include "SystemProperty.h"
|
||||
|
||||
using mozilla::system::Property;
|
||||
|
||||
static void* sNetUtilsLib;
|
||||
static PRCallOnceType sInitNetUtilsLib;
|
||||
@ -45,8 +47,8 @@ NetUtils::GetSharedLibrary()
|
||||
int32_t
|
||||
NetUtils::SdkVersion()
|
||||
{
|
||||
char propVersion[PROPERTY_VALUE_MAX];
|
||||
property_get("ro.build.version.sdk", propVersion, "0");
|
||||
char propVersion[Property::VALUE_MAX_LENGTH];
|
||||
Property::Get("ro.build.version.sdk", propVersion, "0");
|
||||
int32_t version = strtol(propVersion, nullptr, 10);
|
||||
return version;
|
||||
}
|
||||
@ -177,7 +179,7 @@ int32_t NetUtils::do_dhcp_do_request(const char *ifname,
|
||||
DEFINE_DLFUNC(dhcp_do_request, int32_t, const char*, char*, char*, uint32_t*, char**, char*, uint32_t*, char*, char*)
|
||||
USE_DLFUNC(dhcp_do_request)
|
||||
char *dns[3] = {dns1, dns2, nullptr};
|
||||
char domains[PROPERTY_VALUE_MAX];
|
||||
char domains[Property::VALUE_MAX_LENGTH];
|
||||
ret = dhcp_do_request(ifname, ipaddr, gateway, prefixLength, dns,
|
||||
server, lease, vendorinfo, domains);
|
||||
} else if (sdkVersion >= 19) {
|
||||
@ -188,8 +190,8 @@ int32_t NetUtils::do_dhcp_do_request(const char *ifname,
|
||||
DEFINE_DLFUNC(dhcp_do_request, int32_t, const char*, char*, char*, uint32_t*, char**, char*, uint32_t*, char*, char*, char*)
|
||||
USE_DLFUNC(dhcp_do_request)
|
||||
char *dns[3] = {dns1, dns2, nullptr};
|
||||
char domains[PROPERTY_VALUE_MAX];
|
||||
char mtu[PROPERTY_VALUE_MAX];
|
||||
char domains[Property::VALUE_MAX_LENGTH];
|
||||
char mtu[Property::VALUE_MAX_LENGTH];
|
||||
ret = dhcp_do_request(ifname, ipaddr, gateway, prefixLength, dns, server, lease, vendorinfo, domains, mtu);
|
||||
} else {
|
||||
NS_WARNING("Unable to perform do_dhcp_request: unsupported sdk version!");
|
||||
|
@ -16,9 +16,9 @@
|
||||
#include "NetworkUtils.h"
|
||||
|
||||
#include "prprf.h"
|
||||
#include "SystemProperty.h"
|
||||
|
||||
#include <android/log.h>
|
||||
#include <cutils/properties.h>
|
||||
#include <limits>
|
||||
#include "mozilla/dom/network/NetUtils.h"
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::ipc;
|
||||
using mozilla::system::Property;
|
||||
|
||||
static const char* PERSIST_SYS_USB_CONFIG_PROPERTY = "persist.sys.usb.config";
|
||||
static const char* SYS_USB_CONFIG_PROPERTY = "sys.usb.config";
|
||||
@ -91,9 +92,9 @@ static uint32_t SDK_VERSION;
|
||||
static uint32_t SUPPORT_IPV6_TETHERING;
|
||||
|
||||
struct IFProperties {
|
||||
char gateway[PROPERTY_VALUE_MAX];
|
||||
char dns1[PROPERTY_VALUE_MAX];
|
||||
char dns2[PROPERTY_VALUE_MAX];
|
||||
char gateway[Property::VALUE_MAX_LENGTH];
|
||||
char dns1[Property::VALUE_MAX_LENGTH];
|
||||
char dns2[Property::VALUE_MAX_LENGTH];
|
||||
};
|
||||
|
||||
struct CurrentCommand {
|
||||
@ -372,13 +373,13 @@ static void join(nsTArray<nsCString>& array,
|
||||
*/
|
||||
static void getIFProperties(const char* ifname, IFProperties& prop)
|
||||
{
|
||||
char key[PROPERTY_KEY_MAX];
|
||||
PR_snprintf(key, PROPERTY_KEY_MAX - 1, "net.%s.gw", ifname);
|
||||
property_get(key, prop.gateway, "");
|
||||
PR_snprintf(key, PROPERTY_KEY_MAX - 1, "net.%s.dns1", ifname);
|
||||
property_get(key, prop.dns1, "");
|
||||
PR_snprintf(key, PROPERTY_KEY_MAX - 1, "net.%s.dns2", ifname);
|
||||
property_get(key, prop.dns2, "");
|
||||
char key[Property::KEY_MAX_LENGTH];
|
||||
PR_snprintf(key, Property::KEY_MAX_LENGTH - 1, "net.%s.gw", ifname);
|
||||
Property::Get(key, prop.gateway, "");
|
||||
PR_snprintf(key, Property::KEY_MAX_LENGTH - 1, "net.%s.dns1", ifname);
|
||||
Property::Get(key, prop.dns1, "");
|
||||
PR_snprintf(key, Property::KEY_MAX_LENGTH - 1, "net.%s.dns2", ifname);
|
||||
Property::Get(key, prop.dns2, "");
|
||||
}
|
||||
|
||||
static int getIpType(const char *aIp) {
|
||||
@ -1623,11 +1624,11 @@ NetworkUtils::NetworkUtils(MessageCallback aCallback)
|
||||
{
|
||||
mNetUtils = new NetUtils();
|
||||
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
property_get("ro.build.version.sdk", value, nullptr);
|
||||
char value[Property::VALUE_MAX_LENGTH];
|
||||
Property::Get("ro.build.version.sdk", value, nullptr);
|
||||
SDK_VERSION = atoi(value);
|
||||
|
||||
property_get(IPV6_TETHERING, value, "0");
|
||||
Property::Get(IPV6_TETHERING, value, "0");
|
||||
SUPPORT_IPV6_TETHERING = atoi(value);
|
||||
|
||||
gNetworkUtils = this;
|
||||
@ -1831,26 +1832,26 @@ CommandResult NetworkUtils::setDNS(NetworkParams& aOptions)
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
NS_ConvertUTF16toUTF8 autoDns(aOptions.mDnses[i]);
|
||||
|
||||
char dns_prop_key[PROPERTY_VALUE_MAX];
|
||||
char dns_prop_key[Property::VALUE_MAX_LENGTH];
|
||||
PR_snprintf(dns_prop_key, sizeof dns_prop_key, "net.dns%d", i+1);
|
||||
property_set(dns_prop_key, autoDns.get());
|
||||
Property::Set(dns_prop_key, autoDns.get());
|
||||
}
|
||||
} else {
|
||||
// Set dnses from system properties.
|
||||
IFProperties interfaceProperties;
|
||||
getIFProperties(GET_CHAR(mIfname), interfaceProperties);
|
||||
|
||||
property_set("net.dns1", interfaceProperties.dns1);
|
||||
property_set("net.dns2", interfaceProperties.dns2);
|
||||
Property::Set("net.dns1", interfaceProperties.dns1);
|
||||
Property::Set("net.dns2", interfaceProperties.dns2);
|
||||
}
|
||||
|
||||
// Bump the DNS change property.
|
||||
char dnschange[PROPERTY_VALUE_MAX];
|
||||
property_get("net.dnschange", dnschange, "0");
|
||||
char dnschange[Property::VALUE_MAX_LENGTH];
|
||||
Property::Get("net.dnschange", dnschange, "0");
|
||||
|
||||
char num[PROPERTY_VALUE_MAX];
|
||||
PR_snprintf(num, PROPERTY_VALUE_MAX - 1, "%d", atoi(dnschange) + 1);
|
||||
property_set("net.dnschange", num);
|
||||
char num[Property::VALUE_MAX_LENGTH];
|
||||
PR_snprintf(num, Property::VALUE_MAX_LENGTH - 1, "%d", atoi(dnschange) + 1);
|
||||
Property::Set("net.dnschange", num);
|
||||
|
||||
// DNS needs to be set through netd since JellyBean (4.3).
|
||||
if (SDK_VERSION >= 20) {
|
||||
@ -1909,14 +1910,14 @@ CommandResult NetworkUtils::dhcpRequest(NetworkParams& aOptions) {
|
||||
mozilla::dom::NetworkResultOptions result;
|
||||
|
||||
NS_ConvertUTF16toUTF8 autoIfname(aOptions.mIfname);
|
||||
char ipaddr[PROPERTY_VALUE_MAX];
|
||||
char gateway[PROPERTY_VALUE_MAX];
|
||||
char ipaddr[Property::VALUE_MAX_LENGTH];
|
||||
char gateway[Property::VALUE_MAX_LENGTH];
|
||||
uint32_t prefixLength;
|
||||
char dns1[PROPERTY_VALUE_MAX];
|
||||
char dns2[PROPERTY_VALUE_MAX];
|
||||
char server[PROPERTY_VALUE_MAX];
|
||||
char dns1[Property::VALUE_MAX_LENGTH];
|
||||
char dns2[Property::VALUE_MAX_LENGTH];
|
||||
char server[Property::VALUE_MAX_LENGTH];
|
||||
uint32_t lease;
|
||||
char vendorinfo[PROPERTY_VALUE_MAX];
|
||||
char vendorinfo[Property::VALUE_MAX_LENGTH];
|
||||
int32_t ret = mNetUtils->do_dhcp_do_request(autoIfname.get(),
|
||||
ipaddr,
|
||||
gateway,
|
||||
@ -2037,11 +2038,11 @@ CommandResult NetworkUtils::setDefaultRouteLegacy(NetworkParams& aOptions)
|
||||
}
|
||||
} else {
|
||||
// Set default froute from system properties.
|
||||
char key[PROPERTY_KEY_MAX];
|
||||
char gateway[PROPERTY_KEY_MAX];
|
||||
char key[Property::KEY_MAX_LENGTH];
|
||||
char gateway[Property::KEY_MAX_LENGTH];
|
||||
|
||||
PR_snprintf(key, sizeof key - 1, "net.%s.gw", autoIfname.get());
|
||||
property_get(key, gateway, "");
|
||||
Property::Get(key, gateway, "");
|
||||
|
||||
int type = getIpType(gateway);
|
||||
if (type != AF_INET && type != AF_INET6) {
|
||||
@ -2538,8 +2539,8 @@ CommandResult NetworkUtils::checkUsbRndisState(NetworkParams& aOptions)
|
||||
{
|
||||
static uint32_t retry = 0;
|
||||
|
||||
char currentState[PROPERTY_VALUE_MAX];
|
||||
property_get(SYS_USB_STATE_PROPERTY, currentState, nullptr);
|
||||
char currentState[Property::VALUE_MAX_LENGTH];
|
||||
Property::Get(SYS_USB_STATE_PROPERTY, currentState, nullptr);
|
||||
|
||||
nsTArray<nsCString> stateFuncs;
|
||||
split(currentState, USB_CONFIG_DELIMIT, stateFuncs);
|
||||
@ -2588,14 +2589,14 @@ CommandResult NetworkUtils::enableUsbRndis(NetworkParams& aOptions)
|
||||
//
|
||||
// and when rndis is disabled, it should revert to persist.sys.usb.config
|
||||
|
||||
char currentConfig[PROPERTY_VALUE_MAX];
|
||||
property_get(SYS_USB_CONFIG_PROPERTY, currentConfig, nullptr);
|
||||
char currentConfig[Property::VALUE_MAX_LENGTH];
|
||||
Property::Get(SYS_USB_CONFIG_PROPERTY, currentConfig, nullptr);
|
||||
|
||||
nsTArray<nsCString> configFuncs;
|
||||
split(currentConfig, USB_CONFIG_DELIMIT, configFuncs);
|
||||
|
||||
char persistConfig[PROPERTY_VALUE_MAX];
|
||||
property_get(PERSIST_SYS_USB_CONFIG_PROPERTY, persistConfig, nullptr);
|
||||
char persistConfig[Property::VALUE_MAX_LENGTH];
|
||||
Property::Get(PERSIST_SYS_USB_CONFIG_PROPERTY, persistConfig, nullptr);
|
||||
|
||||
nsTArray<nsCString> persistFuncs;
|
||||
split(persistConfig, USB_CONFIG_DELIMIT, persistFuncs);
|
||||
@ -2613,11 +2614,11 @@ CommandResult NetworkUtils::enableUsbRndis(NetworkParams& aOptions)
|
||||
configFuncs = persistFuncs;
|
||||
}
|
||||
|
||||
char newConfig[PROPERTY_VALUE_MAX] = "";
|
||||
property_get(SYS_USB_CONFIG_PROPERTY, currentConfig, nullptr);
|
||||
join(configFuncs, USB_CONFIG_DELIMIT, PROPERTY_VALUE_MAX, newConfig);
|
||||
char newConfig[Property::VALUE_MAX_LENGTH] = "";
|
||||
Property::Get(SYS_USB_CONFIG_PROPERTY, currentConfig, nullptr);
|
||||
join(configFuncs, USB_CONFIG_DELIMIT, Property::VALUE_MAX_LENGTH, newConfig);
|
||||
if (strcmp(currentConfig, newConfig)) {
|
||||
property_set(SYS_USB_CONFIG_PROPERTY, newConfig);
|
||||
Property::Set(SYS_USB_CONFIG_PROPERTY, newConfig);
|
||||
}
|
||||
|
||||
// Trigger the timer to check usb state and report the result to NetworkManager.
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "cutils/properties.h"
|
||||
#include "android/log.h"
|
||||
|
||||
#include "nsWhitespaceTokenizer.h"
|
||||
@ -18,12 +17,15 @@
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Snprintf.h"
|
||||
#include "SystemProperty.h"
|
||||
|
||||
#define NETD_LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
|
||||
#define ICS_SYS_USB_RNDIS_MAC "/sys/class/android_usb/android0/f_rndis/ethaddr"
|
||||
#define INVALID_SOCKET -1
|
||||
#define MAX_RECONNECT_TIMES 10
|
||||
|
||||
using mozilla::system::Property;
|
||||
|
||||
namespace {
|
||||
|
||||
RefPtr<mozilla::ipc::NetdClient> gNetdClient;
|
||||
@ -58,7 +60,7 @@ InitRndisAddress()
|
||||
return false;
|
||||
}
|
||||
|
||||
property_get("ro.serialno", serialno, "1234567890ABCDEF");
|
||||
Property::Get("ro.serialno", serialno, "1234567890ABCDEF");
|
||||
|
||||
memset(address, 0, sizeof(address));
|
||||
// First byte is 0x02 to signify a locally administered address.
|
||||
@ -292,12 +294,12 @@ static void
|
||||
InitNetdIOThread()
|
||||
{
|
||||
bool result;
|
||||
char propValue[PROPERTY_VALUE_MAX];
|
||||
char propValue[Property::VALUE_MAX_LENGTH];
|
||||
|
||||
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
||||
MOZ_ASSERT(!gNetdClient);
|
||||
|
||||
property_get("ro.build.version.sdk", propValue, "0");
|
||||
Property::Get("ro.build.version.sdk", propValue, "0");
|
||||
// Assign rndis address for usb tethering in ICS.
|
||||
if (atoi(propValue) >= 15) {
|
||||
result = InitRndisAddress();
|
||||
|
Loading…
Reference in New Issue
Block a user