Search in sources :

Example 1 with CellInfo

use of android.telephony.CellInfo in project android_frameworks_base by ResurrectionRemix.

the class NetworkMonitor method sendNetworkConditionsBroadcast.

/**
     * @param responseReceived - whether or not we received a valid HTTP response to our request.
     * If false, isCaptivePortal and responseTimestampMs are ignored
     * TODO: This should be moved to the transports.  The latency could be passed to the transports
     * along with the captive portal result.  Currently the TYPE_MOBILE broadcasts appear unused so
     * perhaps this could just be added to the WiFi transport only.
     */
private void sendNetworkConditionsBroadcast(boolean responseReceived, boolean isCaptivePortal, long requestTimestampMs, long responseTimestampMs) {
    if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 0) {
        return;
    }
    if (systemReady == false)
        return;
    Intent latencyBroadcast = new Intent(ACTION_NETWORK_CONDITIONS_MEASURED);
    switch(mNetworkAgentInfo.networkInfo.getType()) {
        case ConnectivityManager.TYPE_WIFI:
            WifiInfo currentWifiInfo = mWifiManager.getConnectionInfo();
            if (currentWifiInfo != null) {
                // NOTE: getSSID()'s behavior changed in API 17; before that, SSIDs were not
                // surrounded by double quotation marks (thus violating the Javadoc), but this
                // was changed to match the Javadoc in API 17. Since clients may have started
                // sanitizing the output of this method since API 17 was released, we should
                // not change it here as it would become impossible to tell whether the SSID is
                // simply being surrounded by quotes due to the API, or whether those quotes
                // are actually part of the SSID.
                latencyBroadcast.putExtra(EXTRA_SSID, currentWifiInfo.getSSID());
                latencyBroadcast.putExtra(EXTRA_BSSID, currentWifiInfo.getBSSID());
            } else {
                if (VDBG)
                    logw("network info is TYPE_WIFI but no ConnectionInfo found");
                return;
            }
            break;
        case ConnectivityManager.TYPE_MOBILE:
            latencyBroadcast.putExtra(EXTRA_NETWORK_TYPE, mTelephonyManager.getNetworkType());
            List<CellInfo> info = mTelephonyManager.getAllCellInfo();
            if (info == null)
                return;
            int numRegisteredCellInfo = 0;
            for (CellInfo cellInfo : info) {
                if (cellInfo.isRegistered()) {
                    numRegisteredCellInfo++;
                    if (numRegisteredCellInfo > 1) {
                        if (VDBG)
                            logw("more than one registered CellInfo." + " Can't tell which is active.  Bailing.");
                        return;
                    }
                    if (cellInfo instanceof CellInfoCdma) {
                        CellIdentityCdma cellId = ((CellInfoCdma) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoGsm) {
                        CellIdentityGsm cellId = ((CellInfoGsm) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoLte) {
                        CellIdentityLte cellId = ((CellInfoLte) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoWcdma) {
                        CellIdentityWcdma cellId = ((CellInfoWcdma) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else {
                        if (VDBG)
                            logw("Registered cellinfo is unrecognized");
                        return;
                    }
                }
            }
            break;
        default:
            return;
    }
    latencyBroadcast.putExtra(EXTRA_CONNECTIVITY_TYPE, mNetworkAgentInfo.networkInfo.getType());
    latencyBroadcast.putExtra(EXTRA_RESPONSE_RECEIVED, responseReceived);
    latencyBroadcast.putExtra(EXTRA_REQUEST_TIMESTAMP_MS, requestTimestampMs);
    if (responseReceived) {
        latencyBroadcast.putExtra(EXTRA_IS_CAPTIVE_PORTAL, isCaptivePortal);
        latencyBroadcast.putExtra(EXTRA_RESPONSE_TIMESTAMP_MS, responseTimestampMs);
    }
    mContext.sendBroadcastAsUser(latencyBroadcast, UserHandle.CURRENT, PERMISSION_ACCESS_NETWORK_CONDITIONS);
}
Also used : CellInfoCdma(android.telephony.CellInfoCdma) CellInfoWcdma(android.telephony.CellInfoWcdma) CellIdentityGsm(android.telephony.CellIdentityGsm) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) WifiInfo(android.net.wifi.WifiInfo) CellInfoGsm(android.telephony.CellInfoGsm) CellInfoLte(android.telephony.CellInfoLte) CellIdentityCdma(android.telephony.CellIdentityCdma) CellInfo(android.telephony.CellInfo) CellIdentityLte(android.telephony.CellIdentityLte) CellIdentityWcdma(android.telephony.CellIdentityWcdma)

Example 2 with CellInfo

use of android.telephony.CellInfo in project android_frameworks_base by DirtyUnicorns.

the class NetworkMonitor method sendNetworkConditionsBroadcast.

/**
     * @param responseReceived - whether or not we received a valid HTTP response to our request.
     * If false, isCaptivePortal and responseTimestampMs are ignored
     * TODO: This should be moved to the transports.  The latency could be passed to the transports
     * along with the captive portal result.  Currently the TYPE_MOBILE broadcasts appear unused so
     * perhaps this could just be added to the WiFi transport only.
     */
private void sendNetworkConditionsBroadcast(boolean responseReceived, boolean isCaptivePortal, long requestTimestampMs, long responseTimestampMs) {
    if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 0) {
        return;
    }
    if (systemReady == false)
        return;
    Intent latencyBroadcast = new Intent(ACTION_NETWORK_CONDITIONS_MEASURED);
    switch(mNetworkAgentInfo.networkInfo.getType()) {
        case ConnectivityManager.TYPE_WIFI:
            WifiInfo currentWifiInfo = mWifiManager.getConnectionInfo();
            if (currentWifiInfo != null) {
                // NOTE: getSSID()'s behavior changed in API 17; before that, SSIDs were not
                // surrounded by double quotation marks (thus violating the Javadoc), but this
                // was changed to match the Javadoc in API 17. Since clients may have started
                // sanitizing the output of this method since API 17 was released, we should
                // not change it here as it would become impossible to tell whether the SSID is
                // simply being surrounded by quotes due to the API, or whether those quotes
                // are actually part of the SSID.
                latencyBroadcast.putExtra(EXTRA_SSID, currentWifiInfo.getSSID());
                latencyBroadcast.putExtra(EXTRA_BSSID, currentWifiInfo.getBSSID());
            } else {
                if (VDBG)
                    logw("network info is TYPE_WIFI but no ConnectionInfo found");
                return;
            }
            break;
        case ConnectivityManager.TYPE_MOBILE:
            latencyBroadcast.putExtra(EXTRA_NETWORK_TYPE, mTelephonyManager.getNetworkType());
            List<CellInfo> info = mTelephonyManager.getAllCellInfo();
            if (info == null)
                return;
            int numRegisteredCellInfo = 0;
            for (CellInfo cellInfo : info) {
                if (cellInfo.isRegistered()) {
                    numRegisteredCellInfo++;
                    if (numRegisteredCellInfo > 1) {
                        if (VDBG)
                            logw("more than one registered CellInfo." + " Can't tell which is active.  Bailing.");
                        return;
                    }
                    if (cellInfo instanceof CellInfoCdma) {
                        CellIdentityCdma cellId = ((CellInfoCdma) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoGsm) {
                        CellIdentityGsm cellId = ((CellInfoGsm) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoLte) {
                        CellIdentityLte cellId = ((CellInfoLte) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoWcdma) {
                        CellIdentityWcdma cellId = ((CellInfoWcdma) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else {
                        if (VDBG)
                            logw("Registered cellinfo is unrecognized");
                        return;
                    }
                }
            }
            break;
        default:
            return;
    }
    latencyBroadcast.putExtra(EXTRA_CONNECTIVITY_TYPE, mNetworkAgentInfo.networkInfo.getType());
    latencyBroadcast.putExtra(EXTRA_RESPONSE_RECEIVED, responseReceived);
    latencyBroadcast.putExtra(EXTRA_REQUEST_TIMESTAMP_MS, requestTimestampMs);
    if (responseReceived) {
        latencyBroadcast.putExtra(EXTRA_IS_CAPTIVE_PORTAL, isCaptivePortal);
        latencyBroadcast.putExtra(EXTRA_RESPONSE_TIMESTAMP_MS, responseTimestampMs);
    }
    mContext.sendBroadcastAsUser(latencyBroadcast, UserHandle.CURRENT, PERMISSION_ACCESS_NETWORK_CONDITIONS);
}
Also used : CellInfoCdma(android.telephony.CellInfoCdma) CellInfoWcdma(android.telephony.CellInfoWcdma) CellIdentityGsm(android.telephony.CellIdentityGsm) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) WifiInfo(android.net.wifi.WifiInfo) CellInfoGsm(android.telephony.CellInfoGsm) CellInfoLte(android.telephony.CellInfoLte) CellIdentityCdma(android.telephony.CellIdentityCdma) CellInfo(android.telephony.CellInfo) CellIdentityLte(android.telephony.CellIdentityLte) CellIdentityWcdma(android.telephony.CellIdentityWcdma)

Example 3 with CellInfo

use of android.telephony.CellInfo in project android_frameworks_base by DirtyUnicorns.

the class EmergencyAffordanceService method handleUpdateCellInfo.

private boolean handleUpdateCellInfo() {
    List<CellInfo> cellInfos = mTelephonyManager.getAllCellInfo();
    if (cellInfos == null) {
        return false;
    }
    boolean stopScanningAfterScan = false;
    for (CellInfo cellInfo : cellInfos) {
        int mcc = 0;
        if (cellInfo instanceof CellInfoGsm) {
            mcc = ((CellInfoGsm) cellInfo).getCellIdentity().getMcc();
        } else if (cellInfo instanceof CellInfoLte) {
            mcc = ((CellInfoLte) cellInfo).getCellIdentity().getMcc();
        } else if (cellInfo instanceof CellInfoWcdma) {
            mcc = ((CellInfoWcdma) cellInfo).getCellIdentity().getMcc();
        }
        if (mccRequiresEmergencyAffordance(mcc)) {
            setNetworkNeedsEmergencyAffordance(true);
            return true;
        } else if (mcc != 0 && mcc != Integer.MAX_VALUE) {
            // we found an mcc that isn't in the list, abort
            stopScanningAfterScan = true;
        }
    }
    if (stopScanningAfterScan) {
        stopScanning();
    } else {
        onCellScanFinishedUnsuccessful();
    }
    setNetworkNeedsEmergencyAffordance(false);
    return false;
}
Also used : CellInfoLte(android.telephony.CellInfoLte) CellInfo(android.telephony.CellInfo) CellInfoWcdma(android.telephony.CellInfoWcdma) CellInfoGsm(android.telephony.CellInfoGsm)

Example 4 with CellInfo

use of android.telephony.CellInfo in project platform_frameworks_base by android.

the class NetworkMonitor method sendNetworkConditionsBroadcast.

/**
     * @param responseReceived - whether or not we received a valid HTTP response to our request.
     * If false, isCaptivePortal and responseTimestampMs are ignored
     * TODO: This should be moved to the transports.  The latency could be passed to the transports
     * along with the captive portal result.  Currently the TYPE_MOBILE broadcasts appear unused so
     * perhaps this could just be added to the WiFi transport only.
     */
private void sendNetworkConditionsBroadcast(boolean responseReceived, boolean isCaptivePortal, long requestTimestampMs, long responseTimestampMs) {
    if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 0) {
        return;
    }
    if (systemReady == false)
        return;
    Intent latencyBroadcast = new Intent(ACTION_NETWORK_CONDITIONS_MEASURED);
    switch(mNetworkAgentInfo.networkInfo.getType()) {
        case ConnectivityManager.TYPE_WIFI:
            WifiInfo currentWifiInfo = mWifiManager.getConnectionInfo();
            if (currentWifiInfo != null) {
                // NOTE: getSSID()'s behavior changed in API 17; before that, SSIDs were not
                // surrounded by double quotation marks (thus violating the Javadoc), but this
                // was changed to match the Javadoc in API 17. Since clients may have started
                // sanitizing the output of this method since API 17 was released, we should
                // not change it here as it would become impossible to tell whether the SSID is
                // simply being surrounded by quotes due to the API, or whether those quotes
                // are actually part of the SSID.
                latencyBroadcast.putExtra(EXTRA_SSID, currentWifiInfo.getSSID());
                latencyBroadcast.putExtra(EXTRA_BSSID, currentWifiInfo.getBSSID());
            } else {
                if (VDBG)
                    logw("network info is TYPE_WIFI but no ConnectionInfo found");
                return;
            }
            break;
        case ConnectivityManager.TYPE_MOBILE:
            latencyBroadcast.putExtra(EXTRA_NETWORK_TYPE, mTelephonyManager.getNetworkType());
            List<CellInfo> info = mTelephonyManager.getAllCellInfo();
            if (info == null)
                return;
            int numRegisteredCellInfo = 0;
            for (CellInfo cellInfo : info) {
                if (cellInfo.isRegistered()) {
                    numRegisteredCellInfo++;
                    if (numRegisteredCellInfo > 1) {
                        if (VDBG)
                            logw("more than one registered CellInfo." + " Can't tell which is active.  Bailing.");
                        return;
                    }
                    if (cellInfo instanceof CellInfoCdma) {
                        CellIdentityCdma cellId = ((CellInfoCdma) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoGsm) {
                        CellIdentityGsm cellId = ((CellInfoGsm) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoLte) {
                        CellIdentityLte cellId = ((CellInfoLte) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoWcdma) {
                        CellIdentityWcdma cellId = ((CellInfoWcdma) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else {
                        if (VDBG)
                            logw("Registered cellinfo is unrecognized");
                        return;
                    }
                }
            }
            break;
        default:
            return;
    }
    latencyBroadcast.putExtra(EXTRA_CONNECTIVITY_TYPE, mNetworkAgentInfo.networkInfo.getType());
    latencyBroadcast.putExtra(EXTRA_RESPONSE_RECEIVED, responseReceived);
    latencyBroadcast.putExtra(EXTRA_REQUEST_TIMESTAMP_MS, requestTimestampMs);
    if (responseReceived) {
        latencyBroadcast.putExtra(EXTRA_IS_CAPTIVE_PORTAL, isCaptivePortal);
        latencyBroadcast.putExtra(EXTRA_RESPONSE_TIMESTAMP_MS, responseTimestampMs);
    }
    mContext.sendBroadcastAsUser(latencyBroadcast, UserHandle.CURRENT, PERMISSION_ACCESS_NETWORK_CONDITIONS);
}
Also used : CellInfoCdma(android.telephony.CellInfoCdma) CellInfoWcdma(android.telephony.CellInfoWcdma) CellIdentityGsm(android.telephony.CellIdentityGsm) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) WifiInfo(android.net.wifi.WifiInfo) CellInfoGsm(android.telephony.CellInfoGsm) CellInfoLte(android.telephony.CellInfoLte) CellIdentityCdma(android.telephony.CellIdentityCdma) CellInfo(android.telephony.CellInfo) CellIdentityLte(android.telephony.CellIdentityLte) CellIdentityWcdma(android.telephony.CellIdentityWcdma)

Example 5 with CellInfo

use of android.telephony.CellInfo in project android_frameworks_base by crdroidandroid.

the class NetworkMonitor method sendNetworkConditionsBroadcast.

/**
     * @param responseReceived - whether or not we received a valid HTTP response to our request.
     * If false, isCaptivePortal and responseTimestampMs are ignored
     * TODO: This should be moved to the transports.  The latency could be passed to the transports
     * along with the captive portal result.  Currently the TYPE_MOBILE broadcasts appear unused so
     * perhaps this could just be added to the WiFi transport only.
     */
private void sendNetworkConditionsBroadcast(boolean responseReceived, boolean isCaptivePortal, long requestTimestampMs, long responseTimestampMs) {
    if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 0) {
        return;
    }
    if (systemReady == false)
        return;
    Intent latencyBroadcast = new Intent(ACTION_NETWORK_CONDITIONS_MEASURED);
    switch(mNetworkAgentInfo.networkInfo.getType()) {
        case ConnectivityManager.TYPE_WIFI:
            WifiInfo currentWifiInfo = mWifiManager.getConnectionInfo();
            if (currentWifiInfo != null) {
                // NOTE: getSSID()'s behavior changed in API 17; before that, SSIDs were not
                // surrounded by double quotation marks (thus violating the Javadoc), but this
                // was changed to match the Javadoc in API 17. Since clients may have started
                // sanitizing the output of this method since API 17 was released, we should
                // not change it here as it would become impossible to tell whether the SSID is
                // simply being surrounded by quotes due to the API, or whether those quotes
                // are actually part of the SSID.
                latencyBroadcast.putExtra(EXTRA_SSID, currentWifiInfo.getSSID());
                latencyBroadcast.putExtra(EXTRA_BSSID, currentWifiInfo.getBSSID());
            } else {
                if (VDBG)
                    logw("network info is TYPE_WIFI but no ConnectionInfo found");
                return;
            }
            break;
        case ConnectivityManager.TYPE_MOBILE:
            latencyBroadcast.putExtra(EXTRA_NETWORK_TYPE, mTelephonyManager.getNetworkType());
            List<CellInfo> info = mTelephonyManager.getAllCellInfo();
            if (info == null)
                return;
            int numRegisteredCellInfo = 0;
            for (CellInfo cellInfo : info) {
                if (cellInfo.isRegistered()) {
                    numRegisteredCellInfo++;
                    if (numRegisteredCellInfo > 1) {
                        if (VDBG)
                            logw("more than one registered CellInfo." + " Can't tell which is active.  Bailing.");
                        return;
                    }
                    if (cellInfo instanceof CellInfoCdma) {
                        CellIdentityCdma cellId = ((CellInfoCdma) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoGsm) {
                        CellIdentityGsm cellId = ((CellInfoGsm) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoLte) {
                        CellIdentityLte cellId = ((CellInfoLte) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else if (cellInfo instanceof CellInfoWcdma) {
                        CellIdentityWcdma cellId = ((CellInfoWcdma) cellInfo).getCellIdentity();
                        latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
                    } else {
                        if (VDBG)
                            logw("Registered cellinfo is unrecognized");
                        return;
                    }
                }
            }
            break;
        default:
            return;
    }
    latencyBroadcast.putExtra(EXTRA_CONNECTIVITY_TYPE, mNetworkAgentInfo.networkInfo.getType());
    latencyBroadcast.putExtra(EXTRA_RESPONSE_RECEIVED, responseReceived);
    latencyBroadcast.putExtra(EXTRA_REQUEST_TIMESTAMP_MS, requestTimestampMs);
    if (responseReceived) {
        latencyBroadcast.putExtra(EXTRA_IS_CAPTIVE_PORTAL, isCaptivePortal);
        latencyBroadcast.putExtra(EXTRA_RESPONSE_TIMESTAMP_MS, responseTimestampMs);
    }
    mContext.sendBroadcastAsUser(latencyBroadcast, UserHandle.CURRENT, PERMISSION_ACCESS_NETWORK_CONDITIONS);
}
Also used : CellInfoCdma(android.telephony.CellInfoCdma) CellInfoWcdma(android.telephony.CellInfoWcdma) CellIdentityGsm(android.telephony.CellIdentityGsm) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) WifiInfo(android.net.wifi.WifiInfo) CellInfoGsm(android.telephony.CellInfoGsm) CellInfoLte(android.telephony.CellInfoLte) CellIdentityCdma(android.telephony.CellIdentityCdma) CellInfo(android.telephony.CellInfo) CellIdentityLte(android.telephony.CellIdentityLte) CellIdentityWcdma(android.telephony.CellIdentityWcdma)

Aggregations

CellInfo (android.telephony.CellInfo)40 CellInfoGsm (android.telephony.CellInfoGsm)26 CellInfoLte (android.telephony.CellInfoLte)25 CellInfoWcdma (android.telephony.CellInfoWcdma)23 CellInfoCdma (android.telephony.CellInfoCdma)18 CellIdentityGsm (android.telephony.CellIdentityGsm)12 CellIdentityLte (android.telephony.CellIdentityLte)12 CellIdentityCdma (android.telephony.CellIdentityCdma)11 CellIdentityWcdma (android.telephony.CellIdentityWcdma)11 NeighboringCellInfo (android.telephony.NeighboringCellInfo)8 ArrayList (java.util.ArrayList)6 PendingIntent (android.app.PendingIntent)5 Intent (android.content.Intent)5 WifiInfo (android.net.wifi.WifiInfo)5 CellSignalStrengthLte (android.telephony.CellSignalStrengthLte)5 Parcel (android.os.Parcel)4 CellSignalStrengthGsm (android.telephony.CellSignalStrengthGsm)4 Test (org.junit.Test)4 SuppressLint (android.annotation.SuppressLint)3 TargetApi (android.annotation.TargetApi)3