Java Code Examples for android.telephony.gsm.GsmCellLocation#getPsc()

The following examples show how to use android.telephony.gsm.GsmCellLocation#getPsc() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MeasurementUpdater.java    From TowerCollector with Mozilla Public License 2.0 6 votes vote down vote up
private boolean isCellLocationEqual(CellLocation cl1, CellLocation cl2) {
    boolean result;
    if (cl1 instanceof GsmCellLocation && cl2 instanceof GsmCellLocation) {
        GsmCellLocation gsm1 = (GsmCellLocation) cl1;
        GsmCellLocation gsm2 = (GsmCellLocation) cl2;
        result = (gsm1.getCid() == gsm2.getCid()
                && gsm1.getLac() == gsm2.getLac()
                && gsm1.getPsc() == gsm2.getPsc());
        Timber.d("isCellLocationEqual(): GSM equals = %s", result);
    } else if (cl1 instanceof CdmaCellLocation && cl2 instanceof CdmaCellLocation) {
        CdmaCellLocation cdma1 = (CdmaCellLocation) cl1;
        CdmaCellLocation cdma2 = (CdmaCellLocation) cl2;
        result = (cdma1.getBaseStationId() == cdma2.getBaseStationId()
                && cdma1.getNetworkId() == cdma2.getNetworkId()
                && cdma1.getSystemId() == cdma2.getSystemId());
        Timber.d("isCellLocationEqual(): CDMA equal = %s", result);
    } else {
        // different types or nulls
        result = false;
        Timber.d("isCellLocationEqual(): Different types or nulls");
    }
    return result;
}
 
Example 2
Source File: CellLocationConverter.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
public Cell convert(CellLocation cellLocation, int mcc, int mnc, NetworkGroup networkType) {
    Cell cell = new Cell();
    if (cellLocation instanceof GsmCellLocation) {
        GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
        if (gsmCellLocation.getCid() <= 65535 && gsmCellLocation.getPsc() == NeighboringCellInfo.UNKNOWN_CID) {
            cell.setGsmCellLocation(mcc, mnc, gsmCellLocation.getLac(), gsmCellLocation.getCid(), NetworkGroup.Gsm);
        } else {
            // fix invalid network types (unfortunately not possible to distinguish between UMTS and LTE)
            if (networkType == NetworkGroup.Gsm || networkType == NetworkGroup.Cdma)
                networkType = NetworkGroup.Unknown;
            int psc = gsmCellLocation.getPsc();
            if (psc == NeighboringCellInfo.UNKNOWN_CID || psc == Cell.UNKNOWN_CID) {
                psc = Cell.UNKNOWN_CID;
            } else if (psc >= 504) {
                // only UMTS networks support larger PSC
                networkType = NetworkGroup.Wcdma;
            }
            cell.setGsmCellLocation(mcc, mnc, gsmCellLocation.getLac(), gsmCellLocation.getCid(), psc, networkType);
        }
    } else if (cellLocation instanceof CdmaCellLocation) {
        CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
        cell.setCdmaCellLocation(cdmaCellLocation.getSystemId(), cdmaCellLocation.getNetworkId(), cdmaCellLocation.getBaseStationId());
    } else {
        throw new UnsupportedOperationException("Cell location type not supported `" + cellLocation.getClass().getName() + "`");
    }
    return cell;
}
 
Example 3
Source File: CellTowerListLte.java    From satstat with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds or updates a cell tower.
 * <p>
 * If the cell tower is already in the list, its data is updated; if not, a
 * new entry is created.
 * <p>
 * This method will set the cell's identity data. After this call,
 * {@link #isServing()} will return {@code true} for this cell.
 * @param networkOperator The network operator, as returned by {@link android.telephony.TelephonyManager#getNetworkOperator()}.
 * @param location The {@link android.telephony.GsmCellLocation}, as returned by {@link android.telephony.TelephonyManager#getCellLocation()}.
 * @return The new or updated entry.
 */
public CellTowerLte update(String networkOperator, GsmCellLocation location) {
	int mcc = CellTower.UNKNOWN;
	int mnc = CellTower.UNKNOWN;
	if (networkOperator.length() > 3) {
		mcc = Integer.parseInt(networkOperator.substring(0, 3));
		mnc = Integer.parseInt(networkOperator.substring(3));
	}
	CellTowerLte result = null;
	CellTowerLte cand = this.get(mcc, mnc, location.getLac(), location.getCid());
	if ((cand != null) && CellTower.matches(location.getPsc(), cand.getPci()))
		result = cand;
	if (result == null) {
		cand = this.get(location.getPsc());
		if ((cand != null)
				&& CellTower.matches(mcc, cand.getMcc())
				&& CellTower.matches(mnc, cand.getMnc())
				&& CellTower.matches(location.getLac(), cand.getTac())
				&& CellTower.matches(location.getCid(), cand.getCi()))
			result = cand;
	}
	if (result == null)
		result = new CellTowerLte(mcc, mnc, location.getLac(), location.getCid(), location.getPsc());
	if (result.getMcc() == CellTower.UNKNOWN)
		result.setMcc(mcc);
	if (result.getMnc() == CellTower.UNKNOWN)
		result.setMnc(mnc);
	if (result.getTac() == CellTower.UNKNOWN)
		result.setTac(location.getLac());
	if (result.getCi() == CellTower.UNKNOWN)
		result.setCi(location.getCid());
	if (result.getPci() == CellTower.UNKNOWN)
		result.setPci(location.getPsc());
	this.put(result.getText(), result);
	this.put(result.getAltText(), result);
	result.setCellLocation(true);
	Log.d(this.getClass().getSimpleName(), String.format("Added GsmCellLocation for %s, %d G", result.getText(), result.getGeneration()));
	return result;
}
 
Example 4
Source File: CellTowerListGsm.java    From satstat with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds or updates a cell tower.
 * <p>
 * If the cell tower is already in the list, its data is updated; if not, a
 * new entry is created.
 * <p>
 * This method will set the cell's identity data. After this call,
 * {@link #isServing()} will return {@code true} for this cell. 
 * @param networkOperator The network operator, as returned by {@link android.telephony.TelephonyManager#getNetworkOperator()}.
 * @param location The {@link android.telephony.GsmCellLocation}, as returned by {@link android.telephony.TelephonyManager#getCellLocation()}.
 * @return The new or updated entry.
 */
public CellTowerGsm update(String networkOperator, GsmCellLocation location) {
	int mcc = CellTower.UNKNOWN;
	int mnc = CellTower.UNKNOWN;
	if (networkOperator.length() > 3) {
		mcc = Integer.parseInt(networkOperator.substring(0, 3));
		mnc = Integer.parseInt(networkOperator.substring(3));
	}
	CellTowerGsm result = null;
	CellTowerGsm cand = this.get(mcc, mnc, location.getLac(), location.getCid());
	if ((cand != null) && CellTower.matches(location.getPsc(), cand.getPsc()))
		result = cand;
	if (result == null) {
		cand = this.get(location.getPsc());
		if ((cand != null)
				&& CellTower.matches(mcc, cand.getMcc())
				&& CellTower.matches(mnc, cand.getMnc())
				&& CellTower.matches(location.getLac(), cand.getLac())
				&& CellTower.matches(location.getCid(), cand.getCid()))
			result = cand;
	}
	if (result == null)
		result = new CellTowerGsm(mcc, mnc, location.getLac(), location.getCid(), location.getPsc());
	if (result.getMcc() == CellTower.UNKNOWN)
		result.setMcc(mcc);
	if (result.getMnc() == CellTower.UNKNOWN)
		result.setMnc(mnc);
	if (result.getLac() == CellTower.UNKNOWN)
		result.setLac(location.getLac());
	if (result.getCid() == CellTower.UNKNOWN)
		result.setCid(location.getCid());
	if (result.getPsc() == CellTower.UNKNOWN)
		result.setPsc(location.getPsc());
	this.put(result.getText(), result);
	this.put(result.getAltText(), result);
	if ((result.getText() == null) && (result.getAltText() == null))
		Log.d(this.getClass().getSimpleName(), String.format("Added %d G cell with no data from GsmCellLocation", result.getGeneration()));
	result.setCellLocation(true);
	return result;
}
 
Example 5
Source File: CellTracker.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
public void onCellLocationChanged(CellLocation location) {

            checkForNeighbourCount(location);
            compareLac(location);
            refreshDevice();
            mDevice.setNetID(tm);
            mDevice.getNetworkTypeName();

            switch (mDevice.getPhoneID()) {

                case TelephonyManager.PHONE_TYPE_NONE:
                case TelephonyManager.PHONE_TYPE_SIP:
                case TelephonyManager.PHONE_TYPE_GSM:
                    GsmCellLocation gsmCellLocation = (GsmCellLocation) location;
                    if (gsmCellLocation != null) {
                        //TODO @EVA where are we sending this setCellInfo data?

                        //TODO
                        /*@EVA
                            Is it a good idea to dump all cells to db because if we spot a known cell
                            with different lac then this will also be dump to db.

                        */
                        mDevice.setCellInfo(
                                gsmCellLocation.toString() +                // ??
                                mDevice.getDataActivityTypeShort() + "|" +  // No,In,Ou,IO,Do
                                mDevice.getDataStateShort() + "|" +         // Di,Ct,Cd,Su
                                mDevice.getNetworkTypeName() + "|"          // HSPA,LTE etc
                        );

                        mDevice.mCell.setLAC(gsmCellLocation.getLac());     // LAC
                        mDevice.mCell.setCID(gsmCellLocation.getCid());     // CID
                        if (gsmCellLocation.getPsc() != -1) {
                            mDevice.mCell.setPSC(gsmCellLocation.getPsc()); // PSC
                        }

                        /*
                            Add cell if gps is not enabled
                            when gps enabled lat lon will be updated
                            by function below

                         */
                    }
                    break;

                case TelephonyManager.PHONE_TYPE_CDMA:
                    CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) location;
                    if (cdmaCellLocation != null) {
                        mDevice.setCellInfo(
                                cdmaCellLocation.toString() +                       // ??
                                mDevice.getDataActivityTypeShort() + "|" +  // No,In,Ou,IO,Do
                                mDevice.getDataStateShort() + "|" +         // Di,Ct,Cd,Su
                                mDevice.getNetworkTypeName() + "|"          // HSPA,LTE etc
                        );
                        mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId());      // NID
                        mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId());  // BID
                        mDevice.mCell.setSID(cdmaCellLocation.getSystemId());       // SID
                        mDevice.mCell.setMNC(cdmaCellLocation.getSystemId());       // MNC <== BUG!??
                        mDevice.setNetworkName(tm.getNetworkOperatorName());        // ??
                    }
            }

        }