Android Open Source - pyneo-wirelesslocation Cell Id






From Project

Back to project page pyneo-wirelesslocation.

License

The source code is released under:

GNU General Public License

If you think the Android project pyneo-wirelesslocation listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.pyneo.android.wirelessid;
/*  w ww . j  a  v a 2 s .c o m*/
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.telephony.CellIdentityCdma;
import android.telephony.CellIdentityGsm;
import android.telephony.CellIdentityLte;
import android.telephony.CellIdentityWcdma;
import android.telephony.CellInfo;
import android.telephony.CellInfoCdma;
import android.telephony.CellInfoGsm;
import android.telephony.CellInfoLte;
import android.telephony.CellInfoWcdma;
import android.telephony.CellSignalStrengthCdma;
import android.telephony.CellSignalStrengthGsm;
import android.telephony.CellSignalStrengthLte;
import android.telephony.CellSignalStrengthWcdma;
import android.telephony.TelephonyManager;
import android.util.Log;

import org.pyneo.android.TheDictionary;

import java.util.Iterator;
import java.util.List;

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class CellId implements Iterator<TheDictionary>, Iterable<TheDictionary> {
  private static final String TAG = CellId.class.getName();
  private static boolean DEBUG = false;
  static { DEBUG = Log.isLoggable("org.pyneo.proprorep", Log.DEBUG); }

  private List<CellInfo> cellInfoList;
  private int i = 0;

  public CellId(List<CellInfo> value) {
    this.cellInfoList = value;
  }

  ///////////////////////// enumerator stuff
  @Override
  public Iterator<TheDictionary> iterator() {
    return this;
  }

  @Override
  public boolean hasNext() {
    return cellInfoList != null && i < cellInfoList.size();
  }

  @Override
  public TheDictionary next() {
    TheDictionary map = new TheDictionary();
    if (cellInfoList != null) {
      try {
        fill(map, cellInfoList.get(i));
      }
      catch (Exception e) {
        throw new RuntimeException(e);
      }
      i++;
    }
    return map;
  }

  @Override
  public void remove() {
    throw new UnsupportedOperationException();
  }

  //////////////////////////////// api 17 and younger:
  @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());
      }
    }
  }

  public static void fill(TheDictionary map, CellIdentityCdma value) throws Exception {
    if (value != null) {
      map.put("type", "1");
      int i;
      i = value.getBasestationId(); if (i != Integer.MAX_VALUE) map.put("basestation_id", i);
      i = value.getLatitude(); if (i != Integer.MAX_VALUE) map.put("latitude", i);
      i = value.getLongitude(); if (i != Integer.MAX_VALUE) map.put("longitude", i);
      i = value.getNetworkId(); if (i != Integer.MAX_VALUE) map.put("network_id", i);
      i = value.getSystemId(); if (i != Integer.MAX_VALUE) map.put("system_id", i);
    }
  }

  public static void fill(TheDictionary map, CellIdentityGsm value) throws Exception {
    if (value != null) {
      map.put("type", "2");
      int i;
      i = value.getMcc(); if (i != Integer.MAX_VALUE && i > 0 && i < 1000) map.put("mcc", i);
      i = value.getMnc(); if (i != Integer.MAX_VALUE && i > 0 && i < 1000) map.put("mnc", i);
      i = value.getLac(); if (i != Integer.MAX_VALUE && i > 0) map.put("lac", i);
      i = value.getCid(); if (i != Integer.MAX_VALUE && i > 0) map.put("cid", i);
      //map.put("psc", value.getPsc()); // depricated
    }
  }

  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
  public static void fill(TheDictionary map, CellIdentityWcdma value) throws Exception {
    if (value != null) {
      map.put("type", "3");
      int i;
      i = value.getMcc(); if (i != Integer.MAX_VALUE && i > 0 && i < 1000) map.put("mcc", i);
      i = value.getMnc(); if (i != Integer.MAX_VALUE && i > 0 && i < 1000) map.put("mnc", i);
      i = value.getLac(); if (i != Integer.MAX_VALUE && i > 0) map.put("lac", i);
      i = value.getPsc(); if (i != Integer.MAX_VALUE && i > 0) map.put("psc", i);
      i = value.getCid(); if (i != Integer.MAX_VALUE && i > 0) {
        if (i >= 0x10000) {
          map.put("rncid", i / 0x10000);
          i %= 0x10000;
        }
        map.put("cid", i);
      }
    }
  }

  public static void fill(TheDictionary map, CellIdentityLte value) throws Exception {
    if (value != null) {
      map.put("type", "4");
      int i;
      i = value.getMcc(); if (i != Integer.MAX_VALUE && i > 0 && i < 1000) map.put("mcc", i);
      i = value.getMnc(); if (i != Integer.MAX_VALUE && i > 0 && i < 1000) map.put("mnc", i);
      i = value.getTac(); if (i != Integer.MAX_VALUE && i > 0) map.put("tac", i);
      i = value.getPci(); if (i != Integer.MAX_VALUE && i > 0) map.put("pci", i);
      i = value.getCi(); if (i != Integer.MAX_VALUE && i > 0) map.put("ci", i);
    }
  }

  public static void fill(TheDictionary map, CellSignalStrengthCdma value) throws Exception {
    if (value != null) {
      int i;
      i = value.getAsuLevel(); if (i != 99) map.put("asu_level", i);
      map.put("dbm", value.getDbm());
      map.put("level", value.getLevel());
    }
  }

  public static void fill(TheDictionary map, CellSignalStrengthGsm value) throws Exception {
    if (value != null) {
      int i;
      i = value.getAsuLevel(); if (i != 99) map.put("asu_level", i);
      map.put("dbm", value.getDbm());
      map.put("level", value.getLevel());
    }
  }

  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
  public static void fill(TheDictionary map, CellSignalStrengthWcdma value) throws Exception {
    if (value != null) {
      int i;
      i = value.getAsuLevel(); if (i != 99) map.put("asu_level", i);
      map.put("dbm", value.getDbm());
      map.put("level", value.getLevel());
    }
  }

  public static void fill(TheDictionary map, CellSignalStrengthLte value) throws Exception {
    if (value != null) {
      int i;
      i = value.getTimingAdvance(); if (i != Integer.MAX_VALUE) map.put("timing_advance", i);
      i = value.getAsuLevel(); if (i != 99) map.put("asu_level", i);
      map.put("dbm", value.getDbm());
      map.put("level", value.getLevel());
    }
  }

  ///////////////////// test
  static public String test(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    int a = 0;
    int b = 0;
    int c = 0;
    for (TheDictionary o: new CellId(telephonyManager.getAllCellInfo())) {
      a++;
      if (DEBUG) Log.d(TAG, "got: " + o);
    }
    return "counts: " + a + '/' + b + '/' + c;
  }
}




Java Source Code List

android.location.GeocoderParams.java
android.location.LocationRequest.java
android.net.NetworkInfo.java
android.os.WorkSource.java
com.android.internal.location.ProviderProperties.java
com.android.internal.location.ProviderRequest.java
com.google.android.location.NetworkLocationService.java
com.google.android.location.geocode.GeocodeService.java
com.google.android.location.internal.server.GoogleLocationService.java
com.google.android.location.internal.server.NetworkLocationService.java
com.google.android.location.network.NetworkLocationService.java
internal.com.android.location.provider.GeocodeProvider.java
internal.com.android.location.provider.LocationProviderBase.java
internal.com.android.location.provider.LocationProvider.java
internal.com.android.location.provider.LocationRequestUnbundled.java
internal.com.android.location.provider.ProviderPropertiesUnbundled.java
internal.com.android.location.provider.ProviderRequestUnbundled.java
org.pyneo.android.TheDictionary.java
org.pyneo.android.TheList.java
org.pyneo.android.cellapi.CellAPI2.java
org.pyneo.android.wirelessid.CellIdPre17API.java
org.pyneo.android.wirelessid.CellId.java
org.pyneo.android.wirelessid.Meta.java
org.pyneo.android.wirelessid.Satellite.java
org.pyneo.android.wirelessid.WifiId.java
org.pyneo.wirelesslocation.GeocodeProvider.java
org.pyneo.wirelesslocation.MainService.java
org.pyneo.wirelesslocation.NetworkLocationProviderV1.java
org.pyneo.wirelesslocation.NetworkLocationProviderV2.java
org.pyneo.wirelesslocation.NetworkLocationProvider.java
org.pyneo.wirelesslocation.WirelessEnvListener.java