Java Code Examples for android.telephony.CellInfo

The following are top voted examples for showing how to use android.telephony.CellInfo. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: AIMSICDL   File: DeviceApi18.java   View source code 7 votes vote down vote up
public static void loadCellInfo(TelephonyManager tm, Device pDevice) {
    int lCurrentApiVersion = android.os.Build.VERSION.SDK_INT;
    try {
        if (pDevice.mCell == null) {
            pDevice.mCell = new Cell();
        }
        List<CellInfo> cellInfoList = tm.getAllCellInfo();
        if (cellInfoList != null) {
            for (final CellInfo info : cellInfoList) {

                //Network Type
                pDevice.mCell.setNetType(tm.getNetworkType());

                if (info instanceof CellInfoGsm) {
                    final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
                    final CellIdentityGsm identityGsm = ((CellInfoGsm) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(gsm.getDbm()); // [dBm]
                    // Cell Identity
                    pDevice.mCell.setCID(identityGsm.getCid());
                    pDevice.mCell.setMCC(identityGsm.getMcc());
                    pDevice.mCell.setMNC(identityGsm.getMnc());
                    pDevice.mCell.setLAC(identityGsm.getLac());

                } else if (info instanceof CellInfoCdma) {
                    final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();
                    final CellIdentityCdma identityCdma = ((CellInfoCdma) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(cdma.getDbm());
                    // Cell Identity
                    pDevice.mCell.setCID(identityCdma.getBasestationId());
                    pDevice.mCell.setMNC(identityCdma.getSystemId());
                    pDevice.mCell.setLAC(identityCdma.getNetworkId());
                    pDevice.mCell.setSID(identityCdma.getSystemId());

                } else if (info instanceof CellInfoLte) {
                    final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
                    final CellIdentityLte identityLte = ((CellInfoLte) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(lte.getDbm());
                    pDevice.mCell.setTimingAdvance(lte.getTimingAdvance());
                    // Cell Identity
                    pDevice.mCell.setMCC(identityLte.getMcc());
                    pDevice.mCell.setMNC(identityLte.getMnc());
                    pDevice.mCell.setCID(identityLte.getCi());

                } else if  (lCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 && info instanceof CellInfoWcdma) {
                    final CellSignalStrengthWcdma wcdma = ((CellInfoWcdma) info).getCellSignalStrength();
                    final CellIdentityWcdma identityWcdma = ((CellInfoWcdma) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(wcdma.getDbm());
                    // Cell Identity
                    pDevice.mCell.setLAC(identityWcdma.getLac());
                    pDevice.mCell.setMCC(identityWcdma.getMcc());
                    pDevice.mCell.setMNC(identityWcdma.getMnc());
                    pDevice.mCell.setCID(identityWcdma.getCid());
                    pDevice.mCell.setPSC(identityWcdma.getPsc());

                } else {
                    Log.i(TAG, mTAG + "Unknown type of cell signal!"
                            + "\n ClassName: " + info.getClass().getSimpleName()
                            + "\n ToString: " + info.toString());
                }
                if (pDevice.mCell.isValid()) {
                    break;
                }
            }
        }
    } catch (NullPointerException npe) {
       Log.e(TAG, mTAG + "loadCellInfo: Unable to obtain cell signal information: ", npe);
    }
}
 
Example 2
Project: chromium-net-for-android   File: AndroidCellularSignalStrength.java   View source code 6 votes vote down vote up
/**
 * Returns all observed cell information from all radios on the device including the primary
 * and neighboring cells. Returns only the information of cells that are registered to a
 * mobile network. May return {@code null}.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static List<CellInfo> getRegisteredCellInfo(Context context) {
    if (!isAPIAvailable(context)) {
        return null;
    }

    TelephonyManager telephonyManager =
            (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) {
        return null;
    }

    List<CellInfo> cellInfos = telephonyManager.getAllCellInfo();
    if (cellInfos == null) {
        return null;
    }

    Iterator<CellInfo> iter = cellInfos.iterator();
    while (iter.hasNext()) {
        if (!iter.next().isRegistered()) {
            iter.remove();
        }
    }
    return cellInfos;
}
 
Example 3
Project: chromium-net-for-android   File: AndroidCellularSignalStrength.java   View source code 6 votes vote down vote up
/**
 * @return Signal strength (in dbM) from {@link cellInfo}. Returns {@link
 * CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal strength is unavailable.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static int getSignalStrengthDbm(CellInfo cellInfo) {
    if (cellInfo instanceof CellInfoCdma) {
        return ((CellInfoCdma) cellInfo).getCellSignalStrength().getDbm();
    }
    if (cellInfo instanceof CellInfoGsm) {
        return ((CellInfoGsm) cellInfo).getCellSignalStrength().getDbm();
    }
    if (cellInfo instanceof CellInfoLte) {
        return ((CellInfoLte) cellInfo).getCellSignalStrength().getDbm();
    }
    if (cellInfo instanceof CellInfoWcdma) {
        return ((CellInfoWcdma) cellInfo).getCellSignalStrength().getDbm();
    }
    return CellularSignalStrengthError.ERROR_NOT_SUPPORTED;
}
 
Example 4
Project: chromium-net-for-android   File: AndroidCellularSignalStrength.java   View source code 6 votes vote down vote up
/**
 * @return the signal level from {@link cellInfo}. Returns {@link
 * CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal
 * level is unavailable with lower value indicating lower signal strength.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static int getSignalStrengthLevel(CellInfo cellInfo) {
    if (cellInfo instanceof CellInfoCdma) {
        return ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel();
    }
    if (cellInfo instanceof CellInfoGsm) {
        return ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel();
    }
    if (cellInfo instanceof CellInfoLte) {
        return ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel();
    }
    if (cellInfo instanceof CellInfoWcdma) {
        return ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel();
    }
    return CellularSignalStrengthError.ERROR_NOT_SUPPORTED;
}
 
Example 5
Project: open-rmbt   File: CellInformationWrapper.java   View source code 6 votes vote down vote up
public CellInformationWrapper(CellInfo cellInfo) {
    setRegistered(cellInfo.isRegistered());
    this.setTimeStamp(cellInfo.getTimeStamp());

    if (cellInfo.getClass().equals(CellInfoLte.class)) {
        setTechnology(Technology.CONNECTION_4G);
        this.ci = new CellIdentity(((CellInfoLte) cellInfo).getCellIdentity());
        this.cs = new CellSignalStrength(((CellInfoLte) cellInfo).getCellSignalStrength());
    }
    else if (cellInfo.getClass().equals(CellInfoWcdma.class)) {
        setTechnology(Technology.CONNECTION_3G);
        this.ci = new CellIdentity(((CellInfoWcdma) cellInfo).getCellIdentity());
        this.cs = new CellSignalStrength(((CellInfoWcdma) cellInfo).getCellSignalStrength());
    }
    else if (cellInfo.getClass().equals(CellInfoGsm.class)) {
        setTechnology(Technology.CONNECTION_2G);
        this.ci = new CellIdentity(((CellInfoGsm) cellInfo).getCellIdentity());
        this.cs = new CellSignalStrength(((CellInfoGsm) cellInfo).getCellSignalStrength());
    }
    else if (cellInfo.getClass().equals(CellInfoCdma.class)) {
        setTechnology(Technology.CONNECTION_2G);
        this.ci = new CellIdentity(((CellInfoCdma) cellInfo).getCellIdentity());
        this.cs = new CellSignalStrength(((CellInfoCdma) cellInfo).getCellSignalStrength());
    }
}
 
Example 6
Project: TPlayer   File: MethodProxies.java   View source code 6 votes vote down vote up
private static CellInfo createCellInfo(VCell cell) {
    if (cell.type == 2) { // CDMA
        CellInfoCdma cdma = mirror.android.telephony.CellInfoCdma.ctor.newInstance();
        CellIdentityCdma identityCdma = mirror.android.telephony.CellInfoCdma.mCellIdentityCdma.get(cdma);
        CellSignalStrengthCdma strengthCdma = mirror.android.telephony.CellInfoCdma.mCellSignalStrengthCdma.get(cdma);
        mirror.android.telephony.CellIdentityCdma.mNetworkId.set(identityCdma, cell.networkId);
        mirror.android.telephony.CellIdentityCdma.mSystemId.set(identityCdma, cell.systemId);
        mirror.android.telephony.CellIdentityCdma.mBasestationId.set(identityCdma, cell.baseStationId);
        mirror.android.telephony.CellSignalStrengthCdma.mCdmaDbm.set(strengthCdma, -74);
        mirror.android.telephony.CellSignalStrengthCdma.mCdmaEcio.set(strengthCdma, -91);
        mirror.android.telephony.CellSignalStrengthCdma.mEvdoDbm.set(strengthCdma, -64);
        mirror.android.telephony.CellSignalStrengthCdma.mEvdoSnr.set(strengthCdma, 7);
        return cdma;
    } else { // GSM
        CellInfoGsm gsm = mirror.android.telephony.CellInfoGsm.ctor.newInstance();
        CellIdentityGsm identityGsm = mirror.android.telephony.CellInfoGsm.mCellIdentityGsm.get(gsm);
        CellSignalStrengthGsm strengthGsm = mirror.android.telephony.CellInfoGsm.mCellSignalStrengthGsm.get(gsm);
        mirror.android.telephony.CellIdentityGsm.mMcc.set(identityGsm, cell.mcc);
        mirror.android.telephony.CellIdentityGsm.mMnc.set(identityGsm, cell.mnc);
        mirror.android.telephony.CellIdentityGsm.mLac.set(identityGsm, cell.lac);
        mirror.android.telephony.CellIdentityGsm.mCid.set(identityGsm, cell.cid);
        mirror.android.telephony.CellSignalStrengthGsm.mSignalStrength.set(strengthGsm, 20);
        mirror.android.telephony.CellSignalStrengthGsm.mBitErrorRate.set(strengthGsm, 0);
        return gsm;
    }
}
 
Example 7
Project: TowerCollector   File: CellIdentityValidator.java   View source code 6 votes vote down vote up
public boolean isValid(CellInfo cellInfo) {
    if (cellInfo instanceof CellInfoGsm) {
        CellInfoGsm gsmCellInfo = (CellInfoGsm) cellInfo;
        // If is compatible with API 17 hack (PSC on GSM) return true
        boolean wcdmaApi17Valid = getWcdmaValidator().isValid(gsmCellInfo.getCellIdentity());
        if (wcdmaApi17Valid)
            return true;
        return getGsmValidator().isValid(gsmCellInfo.getCellIdentity());
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && cellInfo instanceof CellInfoWcdma) {
        CellInfoWcdma wcdmaCellInfo = (CellInfoWcdma) cellInfo;
        return getWcdmaValidator().isValid(wcdmaCellInfo.getCellIdentity());
    }
    if (cellInfo instanceof CellInfoLte) {
        CellInfoLte lteCellInfo = (CellInfoLte) cellInfo;
        return getLteValidator().isValid(lteCellInfo.getCellIdentity());
    }
    if (cellInfo instanceof CellInfoCdma) {
        CellInfoCdma cdmaCellInfo = (CellInfoCdma) cellInfo;
        return getCdmaValidator().isValid(cdmaCellInfo.getCellIdentity());
    }
    throw new UnsupportedOperationException("Cell identity type not supported `" + cellInfo.getClass().getName() + "`");
}
 
Example 8
Project: TowerCollector   File: Api17PlusMeasurementParser.java   View source code 6 votes vote down vote up
private void removeDuplicatedCells(List<CellInfo> cells) {
    List<CellInfo> cellsToRemove = new ArrayList<CellInfo>();
    Set<String> uniqueCellKeys = new HashSet<String>();

    for (CellInfo cell : cells) {
        String key = cellIdentityConverter.createCellKey(cell);
        if (uniqueCellKeys.contains(key)) {
            Log.d("removeDuplicatedCells(): Remove duplicated cell: %s", key);
            cellsToRemove.add(cell);
        } else {
            uniqueCellKeys.add(key);
        }
    }

    cells.removeAll(cellsToRemove);
}
 
Example 9
Project: TowerCollector   File: MobileUtils.java   View source code 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static boolean isApi17CellInfoAvailable(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    List<CellInfo> cells;
    try {
        cells = telephonyManager.getAllCellInfo();
    } catch (SecurityException ex) {
        Log.d("isApi17CellInfoAvailable(): Result = coarse location permission is denied", ex);
        return false;
    }
    if (cells == null || cells.size() == 0) {
        Log.d("isApi17CellInfoAvailable(): Result = no cell info");
        return false;
    }
    CellIdentityValidator validator = new CellIdentityValidator();
    for (CellInfo cell : cells) {
        if (validator.isValid(cell)) {
            Log.d("isApi17CellInfoAvailable(): Result = true");
            return true;
        }
    }
    Log.d("isApi17CellInfoAvailable(): Result = false");
    return false;
}
 
Example 10
Project: CellularSignal   File: RadioInfo.java   View source code 6 votes vote down vote up
private void getWcdmaSignalStrength() {
    List<CellInfo> cellInfoList = mTM.getAllCellInfo();

    if (cellInfoList == null) {
        //Log.e(Tag,"getAllCellInfo is null");
        return;
    }
    //Log.e(Tag,"getAllCellInfo size "+cellInfoList.size());

    for (CellInfo cellInfo : cellInfoList) {

        if (!cellInfo.isRegistered())
            continue;

        if (cellInfo instanceof CellInfoWcdma) {
            CellInfoWcdma wcdmaInfo = (CellInfoWcdma) cellInfo;
            wcdma_RSSI = wcdmaInfo.getCellSignalStrength().getDbm();
        }
    }
}
 
Example 11
Project: 365browser   File: PlatformNetworksManager.java   View source code 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static Set<VisibleCell> getAllVisibleCellsPostJellyBeanMr1(
        TelephonyManager telephonyManager) {
    Set<VisibleCell> visibleCells = new HashSet<>();
    // Retrieve visible cell networks
    List<CellInfo> cellInfos = telephonyManager.getAllCellInfo();
    if (cellInfos == null) {
        return visibleCells;
    }

    long elapsedTime = sTimeProvider.getElapsedRealtime();
    long currentTime = sTimeProvider.getCurrentTime();
    for (int i = 0; i < cellInfos.size(); i++) {
        CellInfo cellInfo = cellInfos.get(i);
        VisibleCell visibleCell =
                getVisibleCellPostJellyBeanMr1(cellInfo, elapsedTime, currentTime);
        if (visibleCell.radioType() != VisibleCell.UNKNOWN_RADIO_TYPE) {
            visibleCells.add(visibleCell);
        }
    }
    return visibleCells;
}
 
Example 12
Project: 365browser   File: PlatformNetworksManager.java   View source code 6 votes vote down vote up
/**
 * Returns a CellInfo object representing the currently registered base stations, containing
 * its identity fields and signal strength. Null if no base station is active.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Nullable
private static CellInfo getActiveCellInfo(TelephonyManager telephonyManager) {
    int numRegisteredCellInfo = 0;
    List<CellInfo> cellInfos = telephonyManager.getAllCellInfo();

    if (cellInfos == null) {
        return null;
    }
    CellInfo result = null;

    for (int i = 0; i < cellInfos.size(); i++) {
        CellInfo cellInfo = cellInfos.get(i);
        if (cellInfo.isRegistered()) {
            numRegisteredCellInfo++;
            if (numRegisteredCellInfo > 1) {
                return null;
            }
            result = cellInfo;
        }
    }
    // Only found one registered cellinfo, so we know which base station was used to measure
    // network quality
    return result;
}
 
Example 13
Project: 365browser   File: AndroidCellularSignalStrength.java   View source code 6 votes vote down vote up
/**
 * @return Signal strength (in dbM) from {@link cellInfo}. Returns {@link
 * CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal strength is unavailable.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static int getSignalStrengthDbm(CellInfo cellInfo) {
    if (cellInfo instanceof CellInfoCdma) {
        return ((CellInfoCdma) cellInfo).getCellSignalStrength().getDbm();
    }
    if (cellInfo instanceof CellInfoGsm) {
        return ((CellInfoGsm) cellInfo).getCellSignalStrength().getDbm();
    }
    if (cellInfo instanceof CellInfoLte) {
        return ((CellInfoLte) cellInfo).getCellSignalStrength().getDbm();
    }
    if (cellInfo instanceof CellInfoWcdma) {
        return ((CellInfoWcdma) cellInfo).getCellSignalStrength().getDbm();
    }
    return CellularSignalStrengthError.ERROR_NOT_SUPPORTED;
}
 
Example 14
Project: 365browser   File: AndroidCellularSignalStrength.java   View source code 6 votes vote down vote up
/**
 * @return the signal level from {@link cellInfo}. Returns {@link
 * CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal
 * level is unavailable with lower value indicating lower signal strength.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static int getSignalStrengthLevel(CellInfo cellInfo) {
    if (cellInfo instanceof CellInfoCdma) {
        return ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel();
    }
    if (cellInfo instanceof CellInfoGsm) {
        return ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel();
    }
    if (cellInfo instanceof CellInfoLte) {
        return ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel();
    }
    if (cellInfo instanceof CellInfoWcdma) {
        return ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel();
    }
    return CellularSignalStrengthError.ERROR_NOT_SUPPORTED;
}
 
Example 15
Project: PhoneProfilesPlus   File: PhoneStateScanner.java   View source code 6 votes vote down vote up
@Override
public void onCellInfoChanged(List<CellInfo> cellInfo)
{
    super.onCellInfoChanged(cellInfo);

    PPApplication.logE("PhoneStateScanner.onCellInfoChanged", "telephonyManager="+telephonyManager);
    CallsCounter.logCounter(context, "PhoneStateScanner.onCellInfoChanged", "PhoneStateScanner_onCellInfoChanged");

    if (cellInfo == null)
        getAllCellInfo();
    else
        getAllCellInfo(cellInfo);

    if (registeredCell != Integer.MAX_VALUE) {
        DatabaseHandler db = DatabaseHandler.getInstance(context);
        db.updateMobileCellLastConnectedTime(registeredCell, lastConnectedTime);
    }

    doAutoRegistration();
    sendBroadcast();
}
 
Example 16
Project: tabulae   File: CellId.java   View source code 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static void fill(TheDictionary map, CellInfo value) throws Exception {
	if (value != null) {
		map.put("time_stamp", value.getTimeStamp());
		map.put("registered", value.isRegistered());
		if (value instanceof CellInfoCdma) {
			fill(map, ((CellInfoCdma) value).getCellIdentity());
			fill(map, ((CellInfoCdma) value).getCellSignalStrength());
		} else if (value instanceof CellInfoGsm) {
			fill(map, ((CellInfoGsm) value).getCellIdentity());
			fill(map, ((CellInfoGsm) value).getCellSignalStrength());
		} else if (value instanceof CellInfoWcdma) {
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
				fill(map, ((CellInfoWcdma) value).getCellIdentity());
				fill(map, ((CellInfoWcdma) value).getCellSignalStrength());
			}
		} else if (value instanceof CellInfoLte) {
			fill(map, ((CellInfoLte) value).getCellIdentity());
			fill(map, ((CellInfoLte) value).getCellSignalStrength());
		} else {
			map.put("class", value.getClass().getName());
			map.put("string", value.toString());
		}
	}
}
 
Example 17
Project: SignalAnalysis   File: PhoneStateHelper.java   View source code 6 votes vote down vote up
/**
 * Get current cell info
 * 
 * @return cell information format as {@link String}
 */
public String getCellInfo() {
	if (DBG)
		Log.d(Config.TAG, TAG + "getCellInfo called");
	String ret = null;
	List<CellInfo> listCellInfo = mTelMgr.getAllCellInfo();
	if (listCellInfo != null)
		for (CellInfo a_Info : listCellInfo) {
			if (CellInfoCdma.class.isInstance(a_Info))
				ret = ret + "\n Cell info cdma: " + a_Info.toString();
			else if (CellInfoGsm.class.isInstance(a_Info))
				ret = ret + "\n Cell info gsm: " + a_Info.toString();
			else if (CellInfoLte.class.isInstance(a_Info)) {
				ret = ret + "\n Cell info lte: " + a_Info.toString();
				CellInfoLte cellInfoLte = (CellInfoLte) a_Info;
				CellIdentityLte cellIdentity = cellInfoLte
						.getCellIdentity();
				Log.d(Config.TAG, TAG + " LTE - " + cellIdentity.getCi()
						+ cellIdentity.getTac() + cellIdentity.getPci());

			} else if (CellInfoWcdma.class.isInstance(a_Info))
				ret = ret + "\n Cell info : wcdma" + a_Info.toString();
		}
	return ret;
}
 
Example 18
Project: chromium-net-for-android   File: AndroidCellularSignalStrength.java   View source code 5 votes vote down vote up
/**
 * @return Signal strength (in dbM) for the currently registered cellular network. Returns
 * {@link CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal strength is
 * unavailable or if there are multiple cellular radios on the device.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@CalledByNative
public static int getSignalStrengthDbm(Context context) {
    List<CellInfo> cellInfos = getRegisteredCellInfo(context);
    return cellInfos == null || cellInfos.size() != 1
            ? CellularSignalStrengthError.ERROR_NOT_SUPPORTED
            : getSignalStrengthDbm(cellInfos.get(0));
}
 
Example 19
Project: chromium-net-for-android   File: AndroidCellularSignalStrength.java   View source code 5 votes vote down vote up
/**
 * @return the signal strength level (between 0 and 4, both inclusive) for the currently
 * registered cellular network with lower value indicating lower signal strength. Returns
 * {@link CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal strength level is
 * unavailable or if there are multiple cellular radios on the device.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@CalledByNative
public static int getSignalStrengthLevel(Context context) {
    List<CellInfo> cellInfos = getRegisteredCellInfo(context);
    return cellInfos == null || cellInfos.size() != 1
            ? CellularSignalStrengthError.ERROR_NOT_SUPPORTED
            : getSignalStrengthLevel(cellInfos.get(0));
}
 
Example 20
Project: proto-collecte   File: CellInfoUtil.java   View source code 5 votes vote down vote up
public ArrayList<CommonCellInfo> toCellularInfo(List<CellInfo> cellInfoList) {
    final ArrayList<CommonCellInfo> res = new ArrayList<CommonCellInfo>();
    if (cellInfoList == null) {
        return res;
    }

    for (CellInfo cellInfo : cellInfoList) {
        if (!cellInfo.isRegistered()) {
            continue;
        }
        //Wcdma : Wideband Code Division Multiple Access : multiplexage par code à large bande
        if (cellInfo instanceof CellInfoWcdma) {
            CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
            res.add(toCellularInfo(cellInfoWcdma));
        }

        if (cellInfo instanceof CellInfoGsm) {
            final CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
            res.add(toCellularInfo(cellInfoGsm));
        }

        if (cellInfo instanceof CellInfoLte) {
            final CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
            res.add(toCellularInfo(cellInfoLte));
        }

        // TODO: gérer CDMA
    }
    return res;
}
 
Example 21
Project: localcloud_fe   File: CellLocationController.java   View source code 5 votes vote down vote up
/**
 * Returns all observed cell information from all radios on the device including the primary and
 * neighboring cells. Calling this method does not trigger a call to onCellInfoChanged(), or change
 * the rate at which onCellInfoChanged() is called.
 */
private void getAllCellInfos(){
    if(_telephonyManager != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        final List<CellInfo> cellInfos = _telephonyManager.getAllCellInfo();
        processCellInfos(cellInfos);
    }
    else {
        Log.w(TAG, "Unable to provide cell info due to version restriction");
    }
}
 
Example 22
Project: localcloud_fe   File: CellLocationController.java   View source code 5 votes vote down vote up
private static void processCellInfos(List<CellInfo> cellInfos){
    if(cellInfos != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){

        for(CellInfo cellInfo : cellInfos){

            if(cellInfo instanceof  CellInfoWcdma){
                final CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoWCDMAJSON(cellInfoWcdma, _returnSignalStrength));
            }
            if(cellInfo instanceof CellInfoGsm){
                final CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoGSMJSON(cellInfoGsm, _returnSignalStrength));
            }
            if(cellInfo instanceof  CellInfoCdma){
                final CellInfoCdma cellIdentityCdma = (CellInfoCdma) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoCDMAJSON(cellIdentityCdma, _returnSignalStrength));
            }
            if(cellInfo instanceof  CellInfoLte){
                final CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoLTEJSON(cellInfoLte, _returnSignalStrength));
            }

            Log.d(TAG,cellInfo.toString());
        }
    }
    else {
        Log.e(TAG, "CellInfoLocation returning null. Is it supported on this phone?");

        // There are several reasons as to why cell location data would be null.
        // * could be an older device running an unsupported version of the Android OS
        // * could be a device that doesn't support this capability.
        // * could be incorrect permissions: ACCESS_COARSE_LOCATION
        sendCallback(PluginResult.Status.ERROR,
                JSONHelper.errorJSON(CELLINFO_PROVIDER, ErrorMessages.CELL_DATA_IS_NULL()));
    }
}
 
Example 23
Project: localcloud_fe   File: CellLocationController.java   View source code 5 votes vote down vote up
/**
 * Returns all observed cell information from all radios on the device including the primary and
 * neighboring cells. Calling this method does not trigger a call to onCellInfoChanged(), or change
 * the rate at which onCellInfoChanged() is called.
 */
private void getAllCellInfos(){
    if(_telephonyManager != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        final List<CellInfo> cellInfos = _telephonyManager.getAllCellInfo();
        processCellInfos(cellInfos);
    }
    else {
        Log.w(TAG, "Unable to provide cell info due to version restriction");
    }
}
 
Example 24
Project: localcloud_fe   File: CellLocationController.java   View source code 5 votes vote down vote up
private static void processCellInfos(List<CellInfo> cellInfos){
    if(cellInfos != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){

        for(CellInfo cellInfo : cellInfos){

            if(cellInfo instanceof  CellInfoWcdma){
                final CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoWCDMAJSON(cellInfoWcdma, _returnSignalStrength));
            }
            if(cellInfo instanceof CellInfoGsm){
                final CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoGSMJSON(cellInfoGsm, _returnSignalStrength));
            }
            if(cellInfo instanceof  CellInfoCdma){
                final CellInfoCdma cellIdentityCdma = (CellInfoCdma) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoCDMAJSON(cellIdentityCdma, _returnSignalStrength));
            }
            if(cellInfo instanceof  CellInfoLte){
                final CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoLTEJSON(cellInfoLte, _returnSignalStrength));
            }

            Log.d(TAG,cellInfo.toString());
        }
    }
    else {
        Log.e(TAG, "CellInfoLocation returning null. Is it supported on this phone?");

        // There are several reasons as to why cell location data would be null.
        // * could be an older device running an unsupported version of the Android OS
        // * could be a device that doesn't support this capability.
        // * could be incorrect permissions: ACCESS_COARSE_LOCATION
        sendCallback(PluginResult.Status.ERROR,
                JSONHelper.errorJSON(CELLINFO_PROVIDER, ErrorMessages.CELL_DATA_IS_NULL()));
    }
}
 
Example 25
Project: localcloud_fe   File: CellLocationController.java   View source code 5 votes vote down vote up
/**
 * Returns all observed cell information from all radios on the device including the primary and
 * neighboring cells. Calling this method does not trigger a call to onCellInfoChanged(), or change
 * the rate at which onCellInfoChanged() is called.
 */
private void getAllCellInfos(){
    if(_telephonyManager != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        final List<CellInfo> cellInfos = _telephonyManager.getAllCellInfo();
        processCellInfos(cellInfos);
    }
    else {
        Log.w(TAG, "Unable to provide cell info due to version restriction");
    }
}
 
Example 26
Project: localcloud_fe   File: CellLocationController.java   View source code 5 votes vote down vote up
private static void processCellInfos(List<CellInfo> cellInfos){
    if(cellInfos != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){

        for(CellInfo cellInfo : cellInfos){

            if(cellInfo instanceof  CellInfoWcdma){
                final CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoWCDMAJSON(cellInfoWcdma, _returnSignalStrength));
            }
            if(cellInfo instanceof CellInfoGsm){
                final CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoGSMJSON(cellInfoGsm, _returnSignalStrength));
            }
            if(cellInfo instanceof  CellInfoCdma){
                final CellInfoCdma cellIdentityCdma = (CellInfoCdma) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoCDMAJSON(cellIdentityCdma, _returnSignalStrength));
            }
            if(cellInfo instanceof  CellInfoLte){
                final CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoLTEJSON(cellInfoLte, _returnSignalStrength));
            }

            Log.d(TAG,cellInfo.toString());
        }
    }
    else {
        Log.e(TAG, "CellInfoLocation returning null. Is it supported on this phone?");

        // There are several reasons as to why cell location data would be null.
        // * could be an older device running an unsupported version of the Android OS
        // * could be a device that doesn't support this capability.
        // * could be incorrect permissions: ACCESS_COARSE_LOCATION
        sendCallback(PluginResult.Status.ERROR,
                JSONHelper.errorJSON(CELLINFO_PROVIDER, ErrorMessages.CELL_DATA_IS_NULL()));
    }
}
 
Example 27
Project: TPlayer   File: MethodProxies.java   View source code 5 votes vote down vote up
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    if (isFakeLocationEnable()) {
        List<VCell> cells = VirtualLocationManager.get().getAllCell(getAppUserId(), getAppPkg());
        if (cells != null) {
            List<CellInfo> result = new ArrayList<CellInfo>();
            for (VCell cell : cells) {
                result.add(createCellInfo(cell));
            }
            return result;
        }

    }
    return super.call(who, method, args);
}
 
Example 28
Project: cordova-plugin-advanced-geolocation   File: CellLocationController.java   View source code 5 votes vote down vote up
/**
 * Returns all observed cell information from all radios on the device including the primary and
 * neighboring cells. Calling this method does not trigger a call to onCellInfoChanged(), or change
 * the rate at which onCellInfoChanged() is called.
 */
private void getAllCellInfos(){
    if(_telephonyManager != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        final List<CellInfo> cellInfos = _telephonyManager.getAllCellInfo();
        processCellInfos(cellInfos);
    }
    else {
        Log.w(TAG, "Unable to provide cell info due to version restriction");
    }
}
 
Example 29
Project: cordova-plugin-advanced-geolocation   File: CellLocationController.java   View source code 5 votes vote down vote up
private static void processCellInfos(List<CellInfo> cellInfos){
    if(cellInfos != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){

        for(CellInfo cellInfo : cellInfos){

            if(cellInfo instanceof  CellInfoWcdma){
                final CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoWCDMAJSON(cellInfoWcdma, _returnSignalStrength));
            }
            if(cellInfo instanceof CellInfoGsm){
                final CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoGSMJSON(cellInfoGsm, _returnSignalStrength));
            }
            if(cellInfo instanceof  CellInfoCdma){
                final CellInfoCdma cellIdentityCdma = (CellInfoCdma) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoCDMAJSON(cellIdentityCdma, _returnSignalStrength));
            }
            if(cellInfo instanceof  CellInfoLte){
                final CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoLTEJSON(cellInfoLte, _returnSignalStrength));
            }

            Log.d(TAG,cellInfo.toString());
        }
    }
    else {
        Log.e(TAG, "CellInfoLocation returning null. Is it supported on this phone?");

        // There are several reasons as to why cell location data would be null.
        // * could be an older device running an unsupported version of the Android OS
        // * could be a device that doesn't support this capability.
        // * could be incorrect permissions: ACCESS_COARSE_LOCATION
        sendCallback(PluginResult.Status.ERROR,
                JSONHelper.errorJSON(CELLINFO_PROVIDER, ErrorMessages.CELL_DATA_IS_NULL()));
    }
}
 
Example 30
Project: TowerCollector   File: MeasurementUpdater.java   View source code 5 votes vote down vote up
public synchronized void setLastCellInfo(List<CellInfo> cellInfo) {
    Log.d("setLastCellInfo(): Cell info updated: %s ", cellInfo);
    this.lastCellInfo = cellInfo;
    this.lastNetworkType = NetworkGroup.Unknown;
    this.lastOperatorName = null;
    notifyIfReadyToProcess();
}
 
Example 31
Project: 365browser   File: PlatformNetworksManager.java   View source code 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static VisibleCell getConnectedCellPostJellyBeanMr1(
        Context context, TelephonyManager telephonyManager) {
    if (!hasLocationPermission(context)) {
        return VisibleCell.UNKNOWN_MISSING_LOCATION_PERMISSION_VISIBLE_CELL;
    }
    CellInfo cellInfo = getActiveCellInfo(telephonyManager);
    return getVisibleCellPostJellyBeanMr1(
            cellInfo, sTimeProvider.getElapsedRealtime(), sTimeProvider.getCurrentTime());
}
 
Example 32
Project: 365browser   File: AndroidCellularSignalStrength.java   View source code 5 votes vote down vote up
/**
 * @return Signal strength (in dbM) for the currently registered cellular network. Returns
 * {@link CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal strength is
 * unavailable or if there are multiple cellular radios on the device.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@CalledByNative
public static int getSignalStrengthDbm() {
    List<CellInfo> cellInfos = getRegisteredCellInfo();
    return cellInfos == null || cellInfos.size() != 1
            ? CellularSignalStrengthError.ERROR_NOT_SUPPORTED
            : getSignalStrengthDbm(cellInfos.get(0));
}
 
Example 33
Project: 365browser   File: AndroidCellularSignalStrength.java   View source code 5 votes vote down vote up
/**
 * @return the signal strength level (between 0 and 4, both inclusive) for the currently
 * registered cellular network with lower value indicating lower signal strength. Returns
 * {@link CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal strength level is
 * unavailable or if there are multiple cellular radios on the device.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@CalledByNative
public static int getSignalStrengthLevel() {
    List<CellInfo> cellInfos = getRegisteredCellInfo();
    return cellInfos == null || cellInfos.size() != 1
            ? CellularSignalStrengthError.ERROR_NOT_SUPPORTED
            : getSignalStrengthLevel(cellInfos.get(0));
}
 
Example 34
Project: 365browser   File: AndroidCellularSignalStrength.java   View source code 5 votes vote down vote up
/**
 * Returns all observed cell information from all radios on the device including the primary
 * and neighboring cells. Returns only the information of cells that are registered to a
 * mobile network. May return {@code null}.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static List<CellInfo> getRegisteredCellInfo() {
    if (!isAPIAvailable()) {
        return null;
    }

    TelephonyManager telephonyManager =
            (TelephonyManager) ContextUtils.getApplicationContext().getSystemService(
                    Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) {
        return null;
    }

    List<CellInfo> cellInfos = telephonyManager.getAllCellInfo();
    if (cellInfos == null) {
        return null;
    }

    Iterator<CellInfo> iter = cellInfos.iterator();
    while (iter.hasNext()) {
        if (!iter.next().isRegistered()) {
            iter.remove();
        }
    }
    return cellInfos;
}
 
Example 35
Project: RadioControl   File: Utilities.java   View source code 5 votes vote down vote up
public static int getCellStatus(Context c){
    int z = 0;
    try {
        TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
        List<CellInfo> cellInfoList = tm.getAllCellInfo();
        //This means cell is off
        if (cellInfoList.isEmpty()) {
            z = 1;
        }
        return z;
    } catch(SecurityException e){
        Log.e("RadioControl","Unable to get Location Permission",e);
    }
    return z;
}
 
Example 36
Project: android_external_UnifiedNlpApi   File: CellBackendHelper.java   View source code 5 votes vote down vote up
/**
 * Call this in {@link org.microg.nlp.api.LocationBackendService#onOpen()}.
 */
@Override
public synchronized void onOpen() {
    super.onOpen();

    if (phoneStateListener == null) {
        Handler mainHandler = new Handler(context.getMainLooper());
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                phoneStateListener = new PhoneStateListener() {

                    @Override
                    public void onCellInfoChanged(List<CellInfo> cellInfo) {
                        if (cellInfo != null && !cellInfo.isEmpty()) {
                            onCellsChanged(cellInfo);
                        } else if (supportsCellInfoChanged) {
                            supportsCellInfoChanged = false;
                            onSignalStrengthsChanged(null);
                        }
                    }

                    @Override
                    public void onSignalStrengthsChanged(SignalStrength signalStrength) {
                        if (!supportsCellInfoChanged) {
                            fallbackScan();
                        }
                    }
                };
                registerPhoneStateListener();
            }
        });
    } else {
        registerPhoneStateListener();
    }
}
 
Example 37
Project: android_external_UnifiedNlpApi   File: CellBackendHelper.java   View source code 5 votes vote down vote up
@SuppressWarnings("deprecation")
private synchronized void fallbackScan() {
    if (lastScan + MIN_UPDATE_INTERVAL > System.currentTimeMillis()) return;
    List<CellInfo> allCellInfo = telephonyManager.getAllCellInfo();
    if ((allCellInfo == null || allCellInfo.isEmpty()) && telephonyManager.getNetworkType() > 0) {
        allCellInfo = new ArrayList<CellInfo>();
        CellLocation cellLocation = telephonyManager.getCellLocation();
        CellInfo cellInfo = fromCellLocation(cellLocation);
        if (cellInfo != null) allCellInfo.add(cellInfo);
    }
    onCellsChanged(allCellInfo);
}
 
Example 38
Project: smartcells   File: CellManager.java   View source code 5 votes vote down vote up
/**
 * Create a measure from current CellInfo
 *
 * @return a current measure
 */
public Measure createMeasure() {
    // Create a measure
    Measure m = new Measure();
    m.timestamp = System.currentTimeMillis();
    TelephonyManager tel = (TelephonyManager) app.getSystemService(Context.TELEPHONY_SERVICE);
    for (CellInfo ci : tel.getAllCellInfo()) {
        TowerInfo ti = new TowerInfo();
        if (ci instanceof CellInfoCdma) {
            ti.type = TowerInfo.CDMA;
            ti.id = ((CellInfoCdma) ci).getCellIdentity().getBasestationId();
            ti.psc = -1;
            ti.dbm = ((CellInfoCdma) ci).getCellSignalStrength().getDbm();
        } else if (ci instanceof CellInfoGsm) {
            ti.type = TowerInfo.GSM;
            ti.id = ((CellInfoGsm) ci).getCellIdentity().getCid();
            ti.psc = -1; // undefined for GSM
            ti.dbm = ((CellInfoGsm) ci).getCellSignalStrength().getDbm();
        } else if (ci instanceof CellInfoLte) {
            ti.type = TowerInfo.LTE;
            ti.id = ((CellInfoLte) ci).getCellIdentity().getCi();
            ti.psc = -1;
            ti.dbm = ((CellInfoLte) ci).getCellSignalStrength().getDbm();
        } else if (ci instanceof CellInfoWcdma) {
            ti.type = TowerInfo.WCDMA;
            ti.id = ((CellInfoWcdma) ci).getCellIdentity().getCid();
            ti.psc = ((CellInfoWcdma) ci).getCellIdentity().getPsc();
            ti.dbm = ((CellInfoWcdma) ci).getCellSignalStrength().getDbm();
        }
        m.towerInfos.add(ti);
    }
    return m;
}
 
Example 39
Project: PhoneProfilesPlus   File: PhoneStateScanner.java   View source code 5 votes vote down vote up
@SuppressLint("MissingPermission")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void getAllCellInfo() {
    if (telephonyManager != null) {
        List<CellInfo> cellInfo = null;
        if (Permissions.checkLocation(context.getApplicationContext()))
            cellInfo = telephonyManager.getAllCellInfo();
        getAllCellInfo(cellInfo);
    }
}
 
Example 40
Project: myinfos   File: CellDataFactory.java   View source code 5 votes vote down vote up
public static CellData parseData(CellInfo cellInfo) {
    if (cellInfo instanceof CellInfoGsm) {
        return parseCellGsm((CellInfoGsm) cellInfo);
    } else if (cellInfo instanceof CellInfoCdma) {
        return parseCellCdma((CellInfoCdma) cellInfo);
    } else if (cellInfo instanceof CellInfoWcdma) {
        return parseCellWcdma((CellInfoWcdma) cellInfo);
    } else if (cellInfo instanceof CellInfoLte) {
        return parseCellLte((CellInfoLte) cellInfo);
    } else {
        return null;
    }
}