use of android.net.wifi.WifiInfo in project android_frameworks_base by ParanoidAndroid.
the class WifiConnectionTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
mRunner = ((ConnectivityManagerTestRunner) getInstrumentation());
mWifiManager = (WifiManager) mRunner.getContext().getSystemService(Context.WIFI_SERVICE);
mAct = getActivity();
networks = mAct.loadNetworkConfigurations();
if (DEBUG) {
printNetworkConfigurations();
}
// enable Wifi and verify wpa_supplicant is started
assertTrue("enable Wifi failed", mAct.enableWifi());
sleep(2 * ConnectivityManagerTestActivity.SHORT_TIMEOUT, "interrupted while waiting for WPA_SUPPLICANT to start");
WifiInfo mConnection = mAct.mWifiManager.getConnectionInfo();
assertNotNull(mConnection);
assertTrue("wpa_supplicant is not started ", mAct.mWifiManager.pingSupplicant());
}
use of android.net.wifi.WifiInfo 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.wifi.WifiInfo in project OpenMEAP by OpenMEAP.
the class MainActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get rid of the android title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
CredentialsProviderFactory.setDefaultCredentialsProviderFactory(new OmSlicCredentialsProvider.Factory(this));
HttpRequestExecuterFactory.setDefaultType(HttpRequestExecuterImpl.class);
DigestInputStreamFactory.setDigestInputStreamForName("md5", Md5DigestInputStream.class);
DigestInputStreamFactory.setDigestInputStreamForName("sha1", Sha1DigestInputStream.class);
// setup the SLICConfig instance
Preferences prefs = new SharedPreferencesImpl(getSharedPreferences(SLICConfig.PREFERENCES_FILE, MODE_PRIVATE));
try {
Properties props = new Properties();
props.load(getAssets().open(SLICConfig.PROPERTIES_FILE));
config = new AndroidSLICConfig(this, prefs, props);
} catch (IOException ioe) {
// then the application is fail
throw new RuntimeException("The primary configuration file (" + SLICConfig.PROPERTIES_FILE + ") could not be opened.");
}
// perform our first-run-check
Object o = getSystemService(Context.WIFI_SERVICE);
if (o instanceof WifiManager) {
WifiManager wifiManager = (WifiManager) o;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null && wifiInfo.getMacAddress() != null) {
Runnable firstRunCheck = new FirstRunCheck(config, wifiInfo.getMacAddress(), HttpRequestExecuterFactory.newDefault());
new Thread(firstRunCheck).start();
}
}
if (config.isDevelopmentMode()) {
System.setProperty(HttpRequestExecuter.SSL_PEER_NOVERIFY_PROPERTY, "true");
} else {
System.setProperty(HttpRequestExecuter.SSL_PEER_NOVERIFY_PROPERTY, "false");
}
storage = new LocalStorageImpl(this);
updateHandler = new UpdateHandler(this, config, storage);
// Calls the title from client.properties
// setupWindowTitle();
}
use of android.net.wifi.WifiInfo in project FastDev4Android by jiangqqlmj.
the class StrUtils method getIpAddress.
// 获取用户的IPd
public static int getIpAddress() {
int ipAddress = 0;
WifiManager wifiManager = (WifiManager) FDApplication.getInstance().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo == null || wifiInfo.equals("")) {
return ipAddress;
} else {
ipAddress = wifiInfo.getIpAddress();
}
return ipAddress;
}
use of android.net.wifi.WifiInfo in project SmartAndroidSource by jaychou2012.
the class SystemInfo method getWifiMacAddress.
/**
* getWifiMacAddress
*
* @return the wifi's MacAddress
*/
public String getWifiMacAddress() {
WifiManager wifi_service = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifi_service.getConnectionInfo();
return wifiInfo.getMacAddress();
}
Aggregations