Search in sources :

Example 6 with CellInfo

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

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 7 with CellInfo

use of android.telephony.CellInfo in project android_packages_apps_Settings by LineageOS.

the class RadioInfo method buildCellInfoString.

private final String buildCellInfoString(List<CellInfo> arrayCi) {
    String value = new String();
    StringBuilder cdmaCells = new StringBuilder(), gsmCells = new StringBuilder(), lteCells = new StringBuilder(), wcdmaCells = new StringBuilder();
    if (arrayCi != null) {
        for (CellInfo ci : arrayCi) {
            if (ci instanceof CellInfoLte) {
                lteCells.append(buildLteInfoString((CellInfoLte) ci));
            } else if (ci instanceof CellInfoWcdma) {
                wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
            } else if (ci instanceof CellInfoGsm) {
                gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
            } else if (ci instanceof CellInfoCdma) {
                cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
            }
        }
        if (lteCells.length() != 0) {
            value += String.format("LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-4.4s %-4.4s %-2.2s\n", "SRV", "MCC", "MNC", "TAC", "CID", "PCI", "EARFCN", "RSRP", "RSRQ", "TA");
            value += lteCells.toString();
        }
        if (wcdmaCells.length() != 0) {
            value += String.format("WCDMA\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-3.3s %-4.4s\n", "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
            value += wcdmaCells.toString();
        }
        if (gsmCells.length() != 0) {
            value += String.format("GSM\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-4.4s %-4.4s\n", "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
            value += gsmCells.toString();
        }
        if (cdmaCells.length() != 0) {
            value += String.format("CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n", "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
            value += cdmaCells.toString();
        }
    } else {
        value = "unknown";
    }
    return value.toString();
}
Also used : CellInfoLte(android.telephony.CellInfoLte) CellInfo(android.telephony.CellInfo) NeighboringCellInfo(android.telephony.NeighboringCellInfo) CellInfoCdma(android.telephony.CellInfoCdma) CellInfoWcdma(android.telephony.CellInfoWcdma) CellInfoGsm(android.telephony.CellInfoGsm)

Example 8 with CellInfo

use of android.telephony.CellInfo in project satstat by mvglasow.

the class RadioSectionFragment method updateCellData.

/**
 * Updates all cell data.
 *
 * This method is called whenever any change in the cell environment (cells in view or signal
 * strengths) is signaled, e.g. by a call to a {@link android.telephony.PhoneStateListener}. The
 * arguments of this method should be filled with the data passed to the
 * {@link android.telephony.PhoneStateListener} where possible, and null passed for all others.
 *
 * To force an update of all cell data, simply call this method with each argument set to null.
 *
 * If any of the arguments is null, this method will try to obtain that data by querying
 * {@link android.telephony.TelephonyManager}. The only exception is {@code signalStrength}, which
 * will not be explicitly queried if missing.
 *
 * It will first process {@code aCellInfo}, then {@code aLocation}, querying current values from
 * {@link android.telephony.TelephonyManager} if one of these arguments is null. Next it will process
 * {@code signalStrength}, if supplied, and eventually obtain neighboring cells by calling
 * {@link android.telephony.TelephonyManager#getNeighboringCellInfo()} and process these. Eventually
 * it will refresh the list of cells.
 *
 * @param aLocation The {@link android.telephony.CellLocation} reported by a
 * {@link android.telephony.PhoneStateListener}. If null, the current value will be queried.
 * @param aSignalStrength The {@link android.telephony.SignalStrength} reported by a
 * {@link android.telephony.PhoneStateListener}. If null, the signal strength of the serving cell
 * will either be taken from {@code aCellInfo}, if available, or not be updated at all.
 * @param aCellInfo A list of {@link android.telephony.CellInfo} instances reported by a
 * {@link android.telephony.PhoneStateListener}. If null, the current value will be queried.
 */
@SuppressLint("NewApi")
public void updateCellData(CellLocation aLocation, SignalStrength signalStrength, List<CellInfo> aCellInfo) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        try {
            /*
				 * CellInfo requires API 17+ and should in theory return all cells in view. In practice,
				 * some devices do not implement it or return only a partial list. On some devices,
				 * PhoneStateListener#onCellInfoChanged() will fire but always receive a null argument.
				 */
            List<CellInfo> cellInfo = (aCellInfo != null) ? aCellInfo : mainActivity.telephonyManager.getAllCellInfo();
            mCellsGsm.updateAll(cellInfo);
            mCellsCdma.updateAll(cellInfo);
            mCellsLte.updateAll(cellInfo);
        } catch (SecurityException e) {
            // Permission not granted, can't retrieve cell data
            Log.w(TAG, "Permission not granted, TelephonyManager#getAllCellInfo() failed");
        }
    }
    try {
        /*
			 * CellLocation should return the serving cell, unless it is LTE (in which case it should
			 * return null). In practice, however, some devices do return LTE cells. The approach of
			 * this method does not work well for devices with multiple radios.
			 */
        CellLocation location = (aLocation != null) ? aLocation : mainActivity.telephonyManager.getCellLocation();
        String networkOperator = mainActivity.telephonyManager.getNetworkOperator();
        mCellsGsm.removeSource(CellTower.SOURCE_CELL_LOCATION);
        mCellsCdma.removeSource(CellTower.SOURCE_CELL_LOCATION);
        mCellsLte.removeSource(CellTower.SOURCE_CELL_LOCATION);
        if (location instanceof GsmCellLocation) {
            if (mLastNetworkGen < 4) {
                mServingCell = mCellsGsm.update(networkOperator, (GsmCellLocation) location);
                if ((mServingCell.getDbm() == CellTower.DBM_UNKNOWN) && (mServingCell instanceof CellTowerGsm))
                    ((CellTowerGsm) mServingCell).setAsu(mLastCellAsu);
            } else {
                mServingCell = mCellsLte.update(networkOperator, (GsmCellLocation) location);
                if (mServingCell.getDbm() == CellTower.DBM_UNKNOWN)
                    ((CellTowerLte) mServingCell).setAsu(mLastCellAsu);
            }
        } else if (location instanceof CdmaCellLocation) {
            mServingCell = mCellsCdma.update((CdmaCellLocation) location);
            if (mServingCell.getDbm() == CellTower.DBM_UNKNOWN)
                ((CellTowerCdma) mServingCell).setDbm(mLastCellDbm);
        }
        networkTimehandler.removeCallbacks(networkTimeRunnable);
    } catch (SecurityException e) {
        // Permission not granted, can't retrieve cell data
        Log.w(TAG, "Permission not granted, cannot retrieve cell location");
    }
    if ((mServingCell == null) || (mServingCell.getGeneration() <= 0)) {
        if ((mLastNetworkGen != 0) && (mServingCell != null))
            mServingCell.setGeneration(mLastNetworkGen);
        NetworkInfo netinfo = mainActivity.connectivityManager.getActiveNetworkInfo();
        if ((netinfo == null) || (netinfo.getType() < ConnectivityManager.TYPE_MOBILE_MMS) || (netinfo.getType() > ConnectivityManager.TYPE_MOBILE_HIPRI)) {
            networkTimehandler.postDelayed(networkTimeRunnable, NETWORK_REFRESH_DELAY);
        }
    } else if (mServingCell != null) {
        mLastNetworkGen = mServingCell.getGeneration();
    }
    if ((signalStrength != null) && (mServingCell != null)) {
        int pt = mainActivity.telephonyManager.getPhoneType();
        if (pt == PHONE_TYPE_GSM) {
            mLastCellAsu = signalStrength.getGsmSignalStrength();
            updateNeighboringCellInfo();
            if (mServingCell instanceof CellTowerGsm)
                ((CellTowerGsm) mServingCell).setAsu(mLastCellAsu);
            else
                Log.w(MainActivity.class.getSimpleName(), "Got SignalStrength for PHONE_TYPE_GSM but serving cell is not GSM");
        } else if (pt == PHONE_TYPE_CDMA) {
            mLastCellDbm = signalStrength.getCdmaDbm();
            if ((mServingCell != null) && (mServingCell instanceof CellTowerCdma))
                mServingCell.setDbm(mLastCellDbm);
            else
                Log.w(MainActivity.class.getSimpleName(), "Got SignalStrength for PHONE_TYPE_CDMA but serving cell is not CDMA");
        } else
            Log.w(MainActivity.class.getSimpleName(), String.format("Got SignalStrength for unknown phone type (%d)", pt));
    } else if (mServingCell == null) {
        Log.w(MainActivity.class.getSimpleName(), "Got SignalStrength but serving cell is null");
    }
    updateNeighboringCellInfo();
    showCells();
}
Also used : CellInfo(android.telephony.CellInfo) NeighboringCellInfo(android.telephony.NeighboringCellInfo) CellTowerGsm(com.vonglasow.michael.satstat.data.CellTowerGsm) NetworkInfo(android.net.NetworkInfo) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) CellTowerCdma(com.vonglasow.michael.satstat.data.CellTowerCdma) GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 9 with CellInfo

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

the class RadioInfo method buildCellInfoString.

private final String buildCellInfoString(List<CellInfo> arrayCi) {
    String value = new String();
    StringBuilder cdmaCells = new StringBuilder(), gsmCells = new StringBuilder(), lteCells = new StringBuilder(), wcdmaCells = new StringBuilder();
    if (arrayCi != null) {
        for (CellInfo ci : arrayCi) {
            if (ci instanceof CellInfoLte) {
                lteCells.append(buildLteInfoString((CellInfoLte) ci));
            } else if (ci instanceof CellInfoWcdma) {
                wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
            } else if (ci instanceof CellInfoGsm) {
                gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
            } else if (ci instanceof CellInfoCdma) {
                cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
            }
        }
        if (lteCells.length() != 0) {
            value += String.format("LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-4.4s %-4.4s %-2.2s\n", "SRV", "MCC", "MNC", "TAC", "CID", "PCI", "EARFCN", "RSRP", "RSRQ", "TA");
            value += lteCells.toString();
        }
        if (wcdmaCells.length() != 0) {
            value += String.format("WCDMA\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-3.3s %-4.4s\n", "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
            value += wcdmaCells.toString();
        }
        if (gsmCells.length() != 0) {
            value += String.format("GSM\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-4.4s %-4.4s\n", "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
            value += gsmCells.toString();
        }
        if (cdmaCells.length() != 0) {
            value += String.format("CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n", "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
            value += cdmaCells.toString();
        }
    } else {
        value = "unknown";
    }
    return value.toString();
}
Also used : CellInfoLte(android.telephony.CellInfoLte) CellInfo(android.telephony.CellInfo) NeighboringCellInfo(android.telephony.NeighboringCellInfo) CellInfoCdma(android.telephony.CellInfoCdma) CellInfoWcdma(android.telephony.CellInfoWcdma) CellInfoGsm(android.telephony.CellInfoGsm)

Example 10 with CellInfo

use of android.telephony.CellInfo in project android_packages_apps_Settings by SudaMod.

the class RadioInfo method buildCellInfoString.

private final String buildCellInfoString(List<CellInfo> arrayCi) {
    String value = new String();
    StringBuilder cdmaCells = new StringBuilder(), gsmCells = new StringBuilder(), lteCells = new StringBuilder(), wcdmaCells = new StringBuilder();
    if (arrayCi != null) {
        for (CellInfo ci : arrayCi) {
            if (ci instanceof CellInfoLte) {
                lteCells.append(buildLteInfoString((CellInfoLte) ci));
            } else if (ci instanceof CellInfoWcdma) {
                wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
            } else if (ci instanceof CellInfoGsm) {
                gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
            } else if (ci instanceof CellInfoCdma) {
                cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
            }
        }
        if (lteCells.length() != 0) {
            value += String.format("LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-4.4s %-4.4s %-2.2s\n", "SRV", "MCC", "MNC", "TAC", "CID", "PCI", "EARFCN", "RSRP", "RSRQ", "TA");
            value += lteCells.toString();
        }
        if (wcdmaCells.length() != 0) {
            value += String.format("WCDMA\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-3.3s %-4.4s\n", "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
            value += wcdmaCells.toString();
        }
        if (gsmCells.length() != 0) {
            value += String.format("GSM\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-4.4s %-4.4s\n", "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
            value += gsmCells.toString();
        }
        if (cdmaCells.length() != 0) {
            value += String.format("CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n", "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
            value += cdmaCells.toString();
        }
    } else {
        value = "unknown";
    }
    return value.toString();
}
Also used : CellInfoLte(android.telephony.CellInfoLte) CellInfo(android.telephony.CellInfo) NeighboringCellInfo(android.telephony.NeighboringCellInfo) CellInfoCdma(android.telephony.CellInfoCdma) CellInfoWcdma(android.telephony.CellInfoWcdma) CellInfoGsm(android.telephony.CellInfoGsm)

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