Search in sources :

Example 1 with CellTowerGsm

use of com.vonglasow.michael.satstat.data.CellTowerGsm in project satstat by mvglasow.

the class RadioSectionFragment method showCells.

/**
 * Updates the list of cells in range.
 * <p>
 * This method is automatically called by
 * {@link PhoneStateListener#onCellInfoChanged(List)}
 * and {@link PhoneStateListener.onCellLocationChanged}. It must be called
 * manually whenever {@link #mCellsCdma}, {@link #mCellsGsm},
 * {@link #mCellsLte} or one of their values are modified, typically after
 * calling {@link android.telephony.TelephonyManager#getAllCellInfo()},
 * {@link android.telephony.TelephonyManager#getCellLocation()} or
 * {@link android.telephony.TelephonyManager#getNeighboringCellInfo()}.
 */
protected void showCells() {
    int cdmaVisibility = View.GONE;
    int gsmVisibility = View.GONE;
    int lteVisibility = View.GONE;
    rilCells.removeAllViews();
    if (mCellsGsm.containsValue(mServingCell)) {
        showCellGsm((CellTowerGsm) mServingCell);
        gsmVisibility = View.VISIBLE;
    }
    for (CellTowerGsm cell : mCellsGsm.getAll()) if (cell.hasSource() && (cell != mServingCell)) {
        showCellGsm(cell);
        gsmVisibility = View.VISIBLE;
    }
    rilGsmLayout.setVisibility(gsmVisibility);
    rilCdmaCells.removeAllViews();
    if (mCellsCdma.containsValue(mServingCell)) {
        showCellCdma((CellTowerCdma) mServingCell);
        cdmaVisibility = View.VISIBLE;
    }
    for (CellTowerCdma cell : mCellsCdma.getAll()) if (cell.hasSource() && (cell != mServingCell)) {
        showCellCdma(cell);
        cdmaVisibility = View.VISIBLE;
    }
    rilCdmaLayout.setVisibility(cdmaVisibility);
    rilLteCells.removeAllViews();
    if (mCellsLte.containsValue(mServingCell)) {
        showCellLte((CellTowerLte) mServingCell);
        lteVisibility = View.VISIBLE;
    }
    for (CellTowerLte cell : mCellsLte.getAll()) if (cell.hasSource() && (cell != mServingCell)) {
        showCellLte(cell);
        lteVisibility = View.VISIBLE;
    }
    rilLteLayout.setVisibility(lteVisibility);
}
Also used : CellTowerGsm(com.vonglasow.michael.satstat.data.CellTowerGsm) CellTowerCdma(com.vonglasow.michael.satstat.data.CellTowerCdma) CellTowerLte(com.vonglasow.michael.satstat.data.CellTowerLte) SuppressLint(android.annotation.SuppressLint)

Example 2 with CellTowerGsm

use of com.vonglasow.michael.satstat.data.CellTowerGsm 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)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 CellTowerCdma (com.vonglasow.michael.satstat.data.CellTowerCdma)2 CellTowerGsm (com.vonglasow.michael.satstat.data.CellTowerGsm)2 NetworkInfo (android.net.NetworkInfo)1 CellInfo (android.telephony.CellInfo)1 CellLocation (android.telephony.CellLocation)1 NeighboringCellInfo (android.telephony.NeighboringCellInfo)1 CdmaCellLocation (android.telephony.cdma.CdmaCellLocation)1 GsmCellLocation (android.telephony.gsm.GsmCellLocation)1 CellTowerLte (com.vonglasow.michael.satstat.data.CellTowerLte)1