Search in sources :

Example 76 with WifiInfo

use of android.net.wifi.WifiInfo in project BookReader by JustWayward.

the class NetworkUtils method getConnectWifiSsid.

/**
     * 获取当前连接wifi的名称
     *
     * @return
     */
public static String getConnectWifiSsid(Context context) {
    if (isWifiConnected(context)) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        return wifiInfo.getSSID();
    }
    return null;
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo)

Example 77 with WifiInfo

use of android.net.wifi.WifiInfo in project BookReader by JustWayward.

the class DeviceUtils method getMacAddress.

/**
     * 获取 MAC 地址
     * 须配置android.permission.ACCESS_WIFI_STATE权限
     */
public static String getMacAddress(Context context) {
    //wifi mac地址
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    String mac = info.getMacAddress();
    LogUtils.i(TAG, " MAC:" + mac);
    return mac;
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo)

Example 78 with WifiInfo

use of android.net.wifi.WifiInfo in project android_frameworks_base by AOSPA.

the class WifiAssociationTest method testWifiAssociation.

/**
     * Test that the wifi can associate with a given access point.
     */
@LargeTest
public void testWifiAssociation() {
    WifiAssociationTestRunner runner = (WifiAssociationTestRunner) getInstrumentation();
    Bundle arguments = runner.getArguments();
    String ssid = arguments.getString("ssid");
    assertNotNull("ssid is empty", ssid);
    String securityTypeStr = arguments.getString("security-type");
    assertNotNull("security-type is empty", securityTypeStr);
    SecurityType securityType = SecurityType.valueOf(securityTypeStr);
    String password = arguments.getString("password");
    String freqStr = arguments.getString("frequency-band");
    if (freqStr != null) {
        setFrequencyBand(freqStr);
    }
    assertTrue("enable Wifi failed", enableWifi());
    WifiInfo wi = mWifiManager.getConnectionInfo();
    logv("%s", wi);
    assertNotNull("no active wifi info", wi);
    WifiConfiguration config = getConfig(ssid, securityType, password);
    logv("Network config: %s", config.toString());
    connectToWifi(config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) Bundle(android.os.Bundle) WifiAssociationTestRunner(com.android.connectivitymanagertest.WifiAssociationTestRunner) WifiInfo(android.net.wifi.WifiInfo) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 79 with WifiInfo

use of android.net.wifi.WifiInfo in project android_frameworks_base by ResurrectionRemix.

the class OSUManager method wnmRemediate.

// !!! Consistently check passpoint match.
// !!! Convert to a one-thread thread-pool
public void wnmRemediate(long bssid, String url, PasspointMatch match) throws IOException, SAXException {
    WifiConfiguration config = mWifiNetworkAdapter.getActiveWifiConfig();
    HomeSP homeSP = MOManager.buildSP(config.getMoTree());
    if (homeSP == null) {
        throw new IOException("Remediation request for unidentified Passpoint network " + config.networkId);
    }
    Network network = mWifiNetworkAdapter.getCurrentNetwork();
    if (network == null) {
        throw new IOException("Failed to determine current network");
    }
    WifiInfo wifiInfo = mWifiNetworkAdapter.getConnectionInfo();
    if (wifiInfo == null || Utils.parseMac(wifiInfo.getBSSID()) != bssid) {
        throw new IOException("Mismatching BSSID");
    }
    Log.d(TAG, "WNM Remediation on " + network.netId + " FQDN " + homeSP.getFQDN());
    doRemediate(url, network, homeSP, false);
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) WifiConfiguration(android.net.wifi.WifiConfiguration) Network(android.net.Network) IOException(java.io.IOException) WifiInfo(android.net.wifi.WifiInfo)

Example 80 with WifiInfo

use of android.net.wifi.WifiInfo in project android_frameworks_base by ResurrectionRemix.

the class DevicePolicyManagerTest method testGetMacAddress.

public void testGetMacAddress() throws Exception {
    mContext.callerPermissions.add(permission.MANAGE_DEVICE_ADMINS);
    mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
    mContext.callerPermissions.add(permission.INTERACT_ACROSS_USERS_FULL);
    // In this test, change the caller user to "system".
    mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
    // Make sure admin1 is installed on system user.
    setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
    // Test 1. Caller doesn't have DO or DA.
    try {
        dpm.getWifiMacAddress(admin1);
        fail();
    } catch (SecurityException e) {
        MoreAsserts.assertContainsRegex("No active admin", e.getMessage());
    }
    // DO needs to be an DA.
    dpm.setActiveAdmin(admin1, /* replace =*/
    false);
    assertTrue(dpm.isAdminActive(admin1));
    // Test 2. Caller has DA, but not DO.
    try {
        dpm.getWifiMacAddress(admin1);
        fail();
    } catch (SecurityException e) {
        MoreAsserts.assertContainsRegex("does not own the device", e.getMessage());
    }
    // Test 3. Caller has PO, but not DO.
    assertTrue(dpm.setProfileOwner(admin1, null, UserHandle.USER_SYSTEM));
    try {
        dpm.getWifiMacAddress(admin1);
        fail();
    } catch (SecurityException e) {
        MoreAsserts.assertContainsRegex("does not own the device", e.getMessage());
    }
    // Remove PO.
    dpm.clearProfileOwner(admin1);
    dpm.setActiveAdmin(admin1, false);
    // Test 4, Caller is DO now.
    assertTrue(dpm.setDeviceOwner(admin1, null, UserHandle.USER_SYSTEM));
    // 4-1.  But no WifiInfo.
    assertNull(dpm.getWifiMacAddress(admin1));
    // 4-2.  Returns WifiInfo, but with the default MAC.
    when(mContext.wifiManager.getConnectionInfo()).thenReturn(new WifiInfo());
    assertNull(dpm.getWifiMacAddress(admin1));
    // 4-3. With a real MAC address.
    final WifiInfo wi = new WifiInfo();
    wi.setMacAddress("11:22:33:44:55:66");
    when(mContext.wifiManager.getConnectionInfo()).thenReturn(wi);
    assertEquals("11:22:33:44:55:66", dpm.getWifiMacAddress(admin1));
}
Also used : WifiInfo(android.net.wifi.WifiInfo)

Aggregations

WifiInfo (android.net.wifi.WifiInfo)99 WifiManager (android.net.wifi.WifiManager)53 WifiConfiguration (android.net.wifi.WifiConfiguration)16 NetworkInfo (android.net.NetworkInfo)13 Intent (android.content.Intent)11 IOException (java.io.IOException)8 Test (org.junit.Test)8 Bundle (android.os.Bundle)7 ScanResult (android.net.wifi.ScanResult)6 WifiAssociationTestRunner (com.android.connectivitymanagertest.WifiAssociationTestRunner)6 PendingIntent (android.app.PendingIntent)5 ConnectivityManager (android.net.ConnectivityManager)5 Network (android.net.Network)5 CellIdentityCdma (android.telephony.CellIdentityCdma)5 CellIdentityGsm (android.telephony.CellIdentityGsm)5 CellIdentityLte (android.telephony.CellIdentityLte)5 CellIdentityWcdma (android.telephony.CellIdentityWcdma)5 CellInfo (android.telephony.CellInfo)5 CellInfoCdma (android.telephony.CellInfoCdma)5 CellInfoGsm (android.telephony.CellInfoGsm)5