use of android.net.DhcpInfo in project XPrivacy by M66B.
the class XWifiManager method after.
@Override
@SuppressWarnings("rawtypes")
protected void after(XParam param) throws Throwable {
switch(mMethod) {
case Srv_getBatchedScanResults:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(new ArrayList());
break;
case getConfiguredNetworks:
case Srv_getConfiguredNetworks:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(new ArrayList<WifiConfiguration>());
break;
case getConnectionInfo:
case Srv_getConnectionInfo:
if (param.getResult() != null)
if (isRestricted(param)) {
WifiInfo result = (WifiInfo) param.getResult();
WifiInfo wInfo = WifiInfo.class.getConstructor(WifiInfo.class).newInstance(result);
if (getRestrictionName().equals(PrivacyManager.cInternet)) {
// Supplicant state
try {
Field fieldState = WifiInfo.class.getDeclaredField("mSupplicantState");
fieldState.setAccessible(true);
fieldState.set(wInfo, SupplicantState.DISCONNECTED);
} catch (Throwable ex) {
Util.bug(this, ex);
}
} else {
// BSSID
try {
Field fieldBSSID = WifiInfo.class.getDeclaredField("mBSSID");
fieldBSSID.setAccessible(true);
fieldBSSID.set(wInfo, PrivacyManager.getDefacedProp(Binder.getCallingUid(), "MAC"));
} catch (Throwable ex) {
Util.bug(this, ex);
}
// IP address
try {
Field fieldIp = WifiInfo.class.getDeclaredField("mIpAddress");
fieldIp.setAccessible(true);
fieldIp.set(wInfo, PrivacyManager.getDefacedProp(Binder.getCallingUid(), "InetAddress"));
} catch (Throwable ex) {
Util.bug(this, ex);
}
// MAC address
try {
Field fieldMAC = WifiInfo.class.getDeclaredField("mMacAddress");
fieldMAC.setAccessible(true);
fieldMAC.set(wInfo, PrivacyManager.getDefacedProp(Binder.getCallingUid(), "MAC"));
} catch (Throwable ex) {
Util.bug(this, ex);
}
// SSID
String ssid = (String) PrivacyManager.getDefacedProp(Binder.getCallingUid(), "SSID");
try {
Field fieldSSID = WifiInfo.class.getDeclaredField("mSSID");
fieldSSID.setAccessible(true);
fieldSSID.set(wInfo, ssid);
} catch (Throwable ex) {
try {
Field fieldWifiSsid = WifiInfo.class.getDeclaredField("mWifiSsid");
fieldWifiSsid.setAccessible(true);
Object mWifiSsid = fieldWifiSsid.get(wInfo);
if (mWifiSsid != null) {
// public static WifiSsid
// createFromAsciiEncoded(String
// asciiEncoded)
Method methodCreateFromAsciiEncoded = mWifiSsid.getClass().getDeclaredMethod("createFromAsciiEncoded", String.class);
fieldWifiSsid.set(wInfo, methodCreateFromAsciiEncoded.invoke(null, ssid));
}
} catch (Throwable exex) {
Util.bug(this, exex);
}
}
}
param.setResult(wInfo);
}
break;
case getDhcpInfo:
case Srv_getDhcpInfo:
if (param.getResult() != null)
if (isRestricted(param)) {
DhcpInfo result = (DhcpInfo) param.getResult();
DhcpInfo dInfo = DhcpInfo.class.getConstructor(DhcpInfo.class).newInstance(result);
dInfo.ipAddress = (Integer) PrivacyManager.getDefacedProp(Binder.getCallingUid(), "IPInt");
dInfo.gateway = dInfo.ipAddress;
dInfo.dns1 = dInfo.ipAddress;
dInfo.dns2 = dInfo.ipAddress;
dInfo.serverAddress = dInfo.ipAddress;
param.setResult(dInfo);
}
break;
case getScanResults:
case Srv_getScanResults:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(new ArrayList<ScanResult>());
break;
case getWifiApConfiguration:
case Srv_getWifiApConfiguration:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(null);
break;
}
}
use of android.net.DhcpInfo in project robolectric by robolectric.
the class ShadowWifiManagerTest method shouldReturnDhcpInfo.
@Test
public void shouldReturnDhcpInfo() {
DhcpInfo dhcpInfo = new DhcpInfo();
shadowWifiManager.setDhcpInfo(dhcpInfo);
assertThat(wifiManager.getDhcpInfo()).isSameAs(dhcpInfo);
}
use of android.net.DhcpInfo in project android_frameworks_base by ParanoidAndroid.
the class WifiService method getDhcpInfo.
/**
* Return the DHCP-assigned addresses from the last successful DHCP request,
* if any.
* @return the DHCP information
* @deprecated
*/
public DhcpInfo getDhcpInfo() {
enforceAccessPermission();
DhcpResults dhcpResults = mWifiStateMachine.syncGetDhcpResults();
if (dhcpResults.linkProperties == null)
return null;
DhcpInfo info = new DhcpInfo();
for (LinkAddress la : dhcpResults.linkProperties.getLinkAddresses()) {
InetAddress addr = la.getAddress();
if (addr instanceof Inet4Address) {
info.ipAddress = NetworkUtils.inetAddressToInt((Inet4Address) addr);
break;
}
}
for (RouteInfo r : dhcpResults.linkProperties.getRoutes()) {
if (r.isDefaultRoute()) {
InetAddress gateway = r.getGateway();
if (gateway instanceof Inet4Address) {
info.gateway = NetworkUtils.inetAddressToInt((Inet4Address) gateway);
}
} else if (r.hasGateway() == false) {
LinkAddress dest = r.getDestination();
if (dest.getAddress() instanceof Inet4Address) {
info.netmask = NetworkUtils.prefixLengthToNetmaskInt(dest.getNetworkPrefixLength());
}
}
}
int dnsFound = 0;
for (InetAddress dns : dhcpResults.linkProperties.getDnses()) {
if (dns instanceof Inet4Address) {
if (dnsFound == 0) {
info.dns1 = NetworkUtils.inetAddressToInt((Inet4Address) dns);
} else {
info.dns2 = NetworkUtils.inetAddressToInt((Inet4Address) dns);
}
if (++dnsFound > 1)
break;
}
}
InetAddress serverAddress = dhcpResults.serverAddress;
if (serverAddress instanceof Inet4Address) {
info.serverAddress = NetworkUtils.inetAddressToInt((Inet4Address) serverAddress);
}
info.leaseDuration = dhcpResults.leaseDuration;
return info;
}
use of android.net.DhcpInfo in project dobby-android by InceptAi.
the class WifiAnalyzer method processNetworkStateChangedIntent.
private void processNetworkStateChangedIntent(Intent intent) {
final NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (networkInfo != null) {
NetworkInfo.DetailedState detailedWifiState = networkInfo.getDetailedState();
updateWifiStatsDetailedState(detailedWifiState);
}
boolean wasConnected = wifiConnected;
wifiConnected = networkInfo != null && networkInfo.isConnected();
//If no longer connected, clear the connection info
if (!wifiConnected) {
wifiState.clearWifiConnectionInfo();
}
// If we just connected, grab the initial signal strength and SSID
if (wifiConnected && !wasConnected) {
postToEventBus(DobbyEvent.EventType.WIFI_CONNECTED);
// try getting it out of the intent first
WifiInfo info = (WifiInfo) intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
updateWifiStatsWithWifiInfo(info);
DhcpInfo dhcpInfo = getDhcpInfo();
if (dhcpInfo != null && dhcpInfo.ipAddress != 0) {
eventBus.postEvent(new DobbyEvent(DobbyEvent.EventType.DHCP_INFO_AVAILABLE));
}
} else if (!wifiConnected && wasConnected) {
postToEventBus(DobbyEvent.EventType.WIFI_NOT_CONNECTED);
} else {
if (wifiConnected) {
if (!publishedWifiState) {
postToEventBus(DobbyEvent.EventType.WIFI_CONNECTED);
}
DobbyLog.v("No change in wifi state -- we were connected and are connected");
} else {
//So that we publish this event at least once
if (!publishedWifiState) {
postToEventBus(DobbyEvent.EventType.WIFI_NOT_CONNECTED);
}
DobbyLog.v("No change in wifi state -- we were NOT connected and are still NOT connected");
}
}
}
use of android.net.DhcpInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ConfigureWifiSettings method refreshWifiInfo.
private void refreshWifiInfo() {
final Context context = getActivity();
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress : context.getString(R.string.status_unavailable));
wifiMacAddressPref.setSelectable(false);
Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);
String ipAddress = Utils.getWifiIpAddresses(context);
wifiIpAddressPref.setSummary(ipAddress == null ? context.getString(R.string.status_unavailable) : ipAddress);
wifiIpAddressPref.setSelectable(false);
// Wifi extension requirement
Preference wifiGatewayPref = findPreference(KEY_CURRENT_GATEWAY);
String gateway = null;
Preference wifiNetmaskPref = findPreference(KEY_CURRENT_NETMASK);
String netmask = null;
if (getResources().getBoolean(R.bool.config_netinfo)) {
DhcpInfo dhcpInfo = mWifiManager.getDhcpInfo();
if (wifiInfo != null) {
if (dhcpInfo != null) {
gateway = Formatter.formatIpAddress(dhcpInfo.gateway);
netmask = Formatter.formatIpAddress(dhcpInfo.netmask);
}
}
if (wifiGatewayPref != null) {
wifiGatewayPref.setSummary((gateway == null || dhcpInfo.gateway == 0) ? getString(R.string.status_unavailable) : gateway);
}
if (wifiNetmaskPref != null) {
wifiNetmaskPref.setSummary((netmask == null || dhcpInfo.netmask == 0) ? getString(R.string.status_unavailable) : netmask);
}
} else {
if (wifiGatewayPref != null) {
getPreferenceScreen().removePreference(wifiGatewayPref);
}
if (wifiNetmaskPref != null) {
getPreferenceScreen().removePreference(wifiNetmaskPref);
}
}
}
Aggregations