List of usage examples for android.telephony SignalStrength getGsmSignalStrength
@Deprecated public int getGsmSignalStrength()
From source file:com.vonglasow.michael.satstat.ui.RadioSectionFragment.java
/** * Updates all cell data.//from w w w . java 2 s. c om * * 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(); }