CellTowerListGsm.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:satstat 作者:
/**
 * 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, its signal strength and
 * whether it is the currently serving cell. If the API level is 18 or 
 * higher, it will also set the generation.
 * @return The new or updated entry.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public CellTowerGsm update(CellInfoGsm cell) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) 
        return null;
    CellIdentityGsm cid = cell.getCellIdentity();
    CellTowerGsm result = null;
    CellTowerGsm cand = this.get(cid.getMcc(), cid.getMnc(), cid.getLac(), cid.getCid());
    if ((cand != null) && CellTower.matches(cid.getPsc(), cand.getPsc()))
        result = cand;
    if (result == null) {
        cand = this.get(cid.getPsc());
        if ((cand != null)
                && ((cid.getMcc() == Integer.MAX_VALUE) || CellTower.matches(cid.getMcc(), cand.getMcc()))
                && ((cid.getMnc() == Integer.MAX_VALUE) || CellTower.matches(cid.getMnc(), cand.getMnc()))
                && ((cid.getLac() == Integer.MAX_VALUE) || CellTower.matches(cid.getLac(), cand.getLac()))
                && ((cid.getCid() == Integer.MAX_VALUE) ||CellTower.matches(cid.getCid(), cand.getCid())))
            result = cand;
    }
    if (result == null)
        result = new CellTowerGsm(cid.getMcc(), cid.getMnc(), cid.getLac(), cid.getCid(), cid.getPsc());
    if (result.getMcc() == CellTower.UNKNOWN)
        result.setMcc(cid.getMcc());
    if (result.getMnc() == CellTower.UNKNOWN)
        result.setMnc(cid.getMnc());
    if (result.getLac() == CellTower.UNKNOWN)
        result.setLac(cid.getLac());
    if (result.getCid() == CellTower.UNKNOWN)
        result.setCid(cid.getCid());
    if (result.getPsc() == CellTower.UNKNOWN)
        result.setPsc(cid.getPsc());
    this.put(result.getText(), result);
    this.put(result.getAltText(), result);
    result.setCellInfo(true);
    result.setDbm(cell.getCellSignalStrength().getDbm());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        result.setGeneration(2);
    result.setServing(cell.isRegistered());
    if ((result.getText() == null) && (result.getAltText() == null))
        Log.d(this.getClass().getSimpleName(), String.format("Added %d G cell with no data from CellInfoGsm", result.getGeneration()));
    return result;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号