Example usage for android.net.wifi WifiInfo getBSSID

List of usage examples for android.net.wifi WifiInfo getBSSID

Introduction

In this page you can find the example usage for android.net.wifi WifiInfo getBSSID.

Prototype

public String getBSSID() 

Source Link

Document

Return the basic service set identifier (BSSID) of the current access point.

Usage

From source file:org.fdroid.fdroid.views.ManageReposActivity.java

private void checkIfNewRepoOnSameWifi(NewRepoConfig newRepo) {
    // if this is a local repo, check we're on the same wifi
    if (!TextUtils.isEmpty(newRepo.getBssid())) {
        WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        String bssid = wifiInfo.getBSSID();
        if (TextUtils.isEmpty(bssid)) { /* not all devices have wifi */
            return;
        }// w  w w  .  java  2 s. c o  m
        bssid = bssid.toLowerCase(Locale.ENGLISH);
        String newRepoBssid = Uri.decode(newRepo.getBssid()).toLowerCase(Locale.ENGLISH);
        if (!bssid.equals(newRepoBssid)) {
            String msg = String.format(getString(R.string.not_on_same_wifi), newRepo.getSsid());
            Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        }
        // TODO we should help the user to the right thing here,
        // instead of just showing a message!
    }
}

From source file:org.pidome.client.services.aidl.service.SystemServiceAidl.java

private void setHome() {
    if (prefs != null) {
        if (prefs.getBoolPreference("wifiConnectHomeEnabled", false)) {
            ConnectivityManager connManager = (ConnectivityManager) getSystemService(
                    Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
            if (networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
                if (connectionInfo != null) {
                    String SSID = connectionInfo.getSSID();
                    String BSSID = connectionInfo.getBSSID();
                    if (SSID != null && BSSID != null) {
                        if (SSID.equals(prefs.getStringPreference("wifiConnectSSID",
                                java.util.UUID.randomUUID().toString()))
                                && BSSID.equals(prefs.getStringPreference("wifiConnectBSSID",
                                        java.util.UUID.randomUUID().toString()))) {
                            singleThreadfPipeExecutor.execute((Runnable) () -> {
                                int i = SystemServiceAidl.this.clientCallBackList.beginBroadcast();
                                while (i > 0) {
                                    i--;
                                    try {
                                        clientCallBackList.beginBroadcast();
                                        clientCallBackList.getBroadcastItem(i).updateUserPresence(1);
                                        clientCallBackList.finishBroadcast();
                                    } catch (RemoteException ex) {
                                        Logger.getLogger(SystemServiceAidl.class.getName()).log(Level.SEVERE,
                                                null, ex);
                                    }/*w w w.  j  a  va2s. c o  m*/
                                }
                            });
                            localizationService.setHome(true);
                        } else {
                            localizationService.setHome(false);
                        }
                    }
                }
            } else if (networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                localizationService.setHome(false);
            }
        }
    }
}

From source file:fr.inria.ucn.collectors.NetworkStateCollector.java

private JSONObject getWifi(Context c) throws JSONException {
    WifiManager wm = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wi = wm.getConnectionInfo();

    // start a wifi AP scan
    Helpers.acquireWifiLock(c);/*from   ww  w.  j  a v  a2  s. c o m*/
    IntentFilter filter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    c.registerReceiver(this, filter);
    wm.startScan();

    JSONObject o = new JSONObject();
    o.put("link_speed", wi.getLinkSpeed());
    o.put("link_speed_units", WifiInfo.LINK_SPEED_UNITS);
    o.put("signal_level", WifiManager.calculateSignalLevel(wi.getRssi(), 100));
    o.put("rssi", wi.getRssi());
    o.put("bssid", wi.getBSSID());
    o.put("ssid", wi.getSSID().replaceAll("\"", ""));
    o.put("mac", wi.getMacAddress());

    int ip = wi.getIpAddress();
    String ipstr = String.format(Locale.US, "%d.%d.%d.%d", (ip & 0xff), (ip >> 8 & 0xff), (ip >> 16 & 0xff),
            (ip >> 24 & 0xff));
    o.put("ip", ipstr);

    return o;
}

From source file:com.mobilyzer.util.PhoneUtils.java

public String getWifiBSSID() {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo != null) {
        return wifiInfo.getBSSID();
    }/*from  w w  w.ja v a 2s  .  c om*/
    return null;
}

From source file:org.restcomm.app.qoslib.Utils.QosInfo.java

private void setWifi(WifiInfo wifiInfo, WifiConfiguration wifiConfig) {
    if (wifiInfo == null || wifiConfig == null)
        return;//from w  w  w. j a v  a  2 s.co  m

    String macid = wifiInfo.getBSSID();
    if (macid == null)
        return;
    String[] bytes = macid.split(":");
    long bssid = 0;
    for (int i = 0; i < 6; i++) {
        if (i < bytes.length) {
            long v = hexval(bytes[i]);
            bssid = bssid + (v << ((5 - i) * 8));
        }
    }
    WifiID = bssid;

    if (wifiConfig != null) {
        int bits = 0;
        for (int i = 0; i < 4; i++) {
            if (wifiConfig.allowedKeyManagement.get(i))
                bits += 1 << i;
        }
        BitSet bs = new BitSet();
        //bs.set(WifiConfiguration.KeyMgmt.NONE);
        //if (wifiConfig.allowedKeyManagement..allowedAuthAlgorithms.intersects(bs))
        WifiSec = bits;
    }

    int freq = getWifiFrequency(wifiInfo);
    if (freq != -1)
        WifiFreq = freq;

    int sig = wifiInfo.getRssi();
    WifiSig = sig;
}

From source file:org.restcomm.app.qoslib.Utils.QosInfo.java

private WifiConfiguration getWifiConfig() {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    WifiConfiguration activeConfig = null;
    if (wifiManager.getConfiguredNetworks() == null)
        return null;

    for (WifiConfiguration conn : wifiManager.getConfiguredNetworks()) {
        if ((conn.BSSID != null && conn.BSSID.equals(wifiInfo.getBSSID()))
                || (conn.SSID != null && conn.SSID.equals(wifiInfo.getSSID()))) {
            activeConfig = conn;/*from  ww  w .  j a va2  s . c o m*/
            break;
        }
    }
    if (activeConfig != null) {
        return activeConfig;
    }
    return null;
}

From source file:at.alladin.rmbt.android.util.InformationCollector.java

private void getWiFiInfo() {
    initNetwork();/*from w ww . j  a v a  2  s  . co  m*/
    if (wifiManager != null) {
        final WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        fullInfo.setProperty("WIFI_SSID",
                String.valueOf(Helperfunctions.removeQuotationsInCurrentSSIDForJellyBean(wifiInfo.getSSID())));
        /*
         * fullInfo.setProperty("WIFI_LINKSPEED",
         * String.valueOf(wifiInfo.getLinkSpeed()));
         */
        fullInfo.setProperty("WIFI_BSSID", String.valueOf(wifiInfo.getBSSID()));
        fullInfo.setProperty("WIFI_NETWORK_ID", String.valueOf(wifiInfo.getNetworkId()));
        /*
         * fullInfo.setProperty("WIFI_RSSI",
         * String.valueOf(wifiInfo.getRssi()));
         */
        final SupplicantState wifiState = wifiInfo.getSupplicantState();
        fullInfo.setProperty("WIFI_SUPPLICANT_STATE", String.valueOf(wifiState.name()));
        final DetailedState wifiDetail = WifiInfo.getDetailedStateOf(wifiState);
        fullInfo.setProperty("WIFI_SUPPLICANT_STATE_DETAIL", String.valueOf(wifiDetail.name()));

        if (getNetwork() == NETWORK_WIFI) {

            final int rssi = wifiInfo.getRssi();
            if (rssi != -1 && rssi >= ACCEPT_WIFI_RSSI_MIN) {
                int linkSpeed = wifiInfo.getLinkSpeed();
                if (linkSpeed < 0) {
                    linkSpeed = 0;
                }

                final SignalItem signalItem = SignalItem.getWifiSignalItem(linkSpeed, rssi);
                if (this.collectInformation) {
                    signals.add(signalItem);
                }
                lastSignalItem.set(signalItem);
                signal.set(rssi);
                signalType.set(SINGAL_TYPE_WLAN);
                //                    Log.i(DEBUG_TAG, "Signals1: " + signals.toString());
            }
        }
    }
}

From source file:org.restcomm.app.qoslib.Services.Events.EventManager.java

public WifiConfiguration getWifiConfig() {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    WifiConfiguration activeConfig = null;
    if (wifiManager.getConfiguredNetworks() == null)
        return null;

    for (WifiConfiguration conn : wifiManager.getConfiguredNetworks()) {
        if ((conn.BSSID != null && conn.BSSID.equals(wifiInfo.getBSSID()))
                || (conn.SSID != null && conn.SSID.equals(wifiInfo.getSSID()))) {
            activeConfig = conn;//from w w  w  .  j  ava2s.  c o m
            break;
        }
    }
    if (activeConfig != null) {
        return activeConfig;
    }
    return null;
}

From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java

public void processNewMMCSignal(SignalEx signal) {
    ContentValues values = null;/*from w  ww .  j a  v  a2s . c o  m*/
    // if in a service outage, store a null signal
    // (I've seen cases where phone was out of service yet it was still returning a signal level)
    try {
        if (mPhoneState.getLastServiceState() == ServiceState.STATE_OUT_OF_SERVICE)
            signal = null;

        // avoid storing repeating identical signals
        if (mPhoneState.lastKnownMMCSignal != null && mPhoneState.lastKnownMMCSignal.getSignalStrength() != null
                && signal != null && signal.getSignalStrength() != null)
            if (mPhoneState.lastKnownMMCSignal.getSignalStrength().toString().equals(
                    signal.getSignalStrength().toString()) && tmlastSig + 3000 > System.currentTimeMillis())
                return;
        tmlastSig = System.currentTimeMillis();
        Integer dbmValue = 0;
        boolean isLTE = false;
        if (signal == null)
            dbmValue = -256;
        else if (signal.getSignalStrength() == null)
            dbmValue = 0;

        //store the last known signal
        if (signal != null && signal.getSignalStrength() != null) {
            prevMMCSignal = mPhoneState.lastKnownMMCSignal; // used for looking at signal just before a call ended
            mPhoneState.lastKnownMMCSignal = signal;
        } else if (signal == null)
            mPhoneState.lastKnownMMCSignal = null;

        //push the new signal level into the sqlite database
        long stagedEventId = owner.getEventManager().getStagedEventId();
        int serviceState = mPhoneState.getLastServiceState();
        int wifiSignal = -1;
        WifiManager wifiManager = (WifiManager) owner.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiinfo = wifiManager.getConnectionInfo();
        if (wifiinfo != null && wifiinfo.getBSSID() != null)
            wifiSignal = wifiManager.getConnectionInfo().getRssi();

        //if (signal != null) //  disabled because we do want the no-signal to be written to the signals table
        {
            values = ContentValuesGenerator.generateFromSignal(signal, telephonyManager.getPhoneType(),
                    telephonyManager.getNetworkType(), serviceState, telephonyManager.getDataState(),
                    stagedEventId, wifiSignal, mPhoneState.mServicemode);
            Integer valSignal = (Integer) values.get("signal");
            if (mPhoneState.getNetworkType() == PhoneState.NETWORK_NEWTYPE_LTE) // && phoneStateListener.previousNetworkState == TelephonyManager.DATA_CONNECTED)
                valSignal = (Integer) values.get("lteRsrp");
            if (valSignal != null && dbmValue != null && valSignal > -130 && valSignal < -30) //  && (dbmValue <= -120 || dbmValue >= -1))
                dbmValue = valSignal;
            if ((dbmValue > -120 || mPhoneState.getNetworkType() == PhoneState.NETWORK_NEWTYPE_LTE)
                    && dbmValue < -40)
                this.validSignal = true;
            if (this.validSignal) // make sure phone has at least one valid signal before recording
                owner.getDBProvider(owner).insert(TablesEnum.SIGNAL_STRENGTHS.getContentUri(), values);

        }
        //update the signal strength percentometer, chart, and look for low/high signal event
        if (dbmValue != null) {
            if (dbmValue < -120) // might be -256 if no service, but want to display as -120 on livestatus chart
                dbmValue = -120;

            owner.getIntentDispatcher().updateSignalStrength(dbmValue, mPhoneState.getNetworkType(),
                    owner.bWifiConnected, wifiSignal);

            // Store signal in a sharedPreference for tools such as Indoor/Transit sample mapper, which dont have reference to service
            if (isLTE == true) // improve the value of the signal for LTE, so that Indoor samples don't look redder in LTE
                PreferenceManager.getDefaultSharedPreferences(owner).edit()
                        .putInt(PreferenceKeys.Miscellaneous.SIGNAL_STRENGTH, (dbmValue + 15)).commit();
            else
                PreferenceManager.getDefaultSharedPreferences(owner).edit()
                        .putInt(PreferenceKeys.Miscellaneous.SIGNAL_STRENGTH, dbmValue).commit();

        }
    } catch (Exception e) {
        LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "processNewMMCSignal", "exception", e);
        LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "processNewMMCSignal", "values: " + values);
    } catch (Error err) {
        LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "processNewMMCSignal", "error" + err.getMessage());
    }
}