Android Open Source - pyneo-wirelesslocation Meta






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;
/*  www .ja  va  2 s . c  o  m*/
import android.annotation.TargetApi;
import android.content.Context;
import android.location.LocationManager;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.Log;

import org.pyneo.android.TheDictionary;

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

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

  private TelephonyManager telephonyManager;

  public Meta(TelephonyManager telephonyManager) {
    this.telephonyManager = telephonyManager;
  }

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

  @Override
  public boolean hasNext() {
    return telephonyManager != null;
  }

  @Override
  public TheDictionary next() {
    TheDictionary map = new TheDictionary();
    try {
      fill(map, this.telephonyManager);
    }
    catch (Exception e) {
      throw new RuntimeException(e);
    }
    telephonyManager = null;
    return map;
  }

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

  static String phone_type_text(int i) {
    switch (i) {
    case TelephonyManager.PHONE_TYPE_CDMA: return "PHONE_TYPE_CDMA";
    case TelephonyManager.PHONE_TYPE_GSM: return "PHONE_TYPE_GSM";
    case TelephonyManager.PHONE_TYPE_NONE: return "PHONE_TYPE_NONE";
    case TelephonyManager.PHONE_TYPE_SIP: return "PHONE_TYPE_SIP";
    default: return "PHONE_TYPE_" + i;
    }
  }

  static String sim_state_text(int i) {
    switch (i) {
    case TelephonyManager.SIM_STATE_ABSENT: return "SIM_STATE_ABSENT";
    case TelephonyManager.SIM_STATE_NETWORK_LOCKED: return "SIM_STATE_NETWORK_LOCKED";
    case TelephonyManager.SIM_STATE_PIN_REQUIRED: return "SIM_STATE_PIN_REQUIRED";
    case TelephonyManager.SIM_STATE_PUK_REQUIRED: return "SIM_STATE_PUK_REQUIRED";
    case TelephonyManager.SIM_STATE_READY: return "SIM_STATE_READY";
    case TelephonyManager.SIM_STATE_UNKNOWN: return "SIM_STATE_UNKNOWN";
    default: return "SIM_STATE_" + i;
    }
  }

  static String call_state_text(int i) {
    switch (i) {
    case TelephonyManager.CALL_STATE_IDLE: return "CALL_STATE_IDLE";
    case TelephonyManager.CALL_STATE_OFFHOOK: return "CALL_STATE_OFFHOOK";
    case TelephonyManager.CALL_STATE_RINGING: return "CALL_STATE_RINGING";
    default: return "CALL_STATE_" + i;
    }
  }

  static String data_activity_text(int i) {
    switch (i) {
    case TelephonyManager.DATA_ACTIVITY_DORMANT: return "DATA_ACTIVITY_DORMANT";
    case TelephonyManager.DATA_ACTIVITY_IN: return "DATA_ACTIVITY_IN";
    case TelephonyManager.DATA_ACTIVITY_INOUT: return "DATA_ACTIVITY_INOUT";
    case TelephonyManager.DATA_ACTIVITY_NONE: return "DATA_ACTIVITY_NONE";
    case TelephonyManager.DATA_ACTIVITY_OUT: return "DATA_ACTIVITY_OUT";
    default: return "DATA_ACTIVITY_" + i;
    }
  }

  static String data_state_text(int i) {
    switch (i) {
    case TelephonyManager.DATA_CONNECTED: return "DATA_CONNECTED";
    case TelephonyManager.DATA_CONNECTING: return "DATA_CONNECTING";
    case TelephonyManager.DATA_DISCONNECTED: return "DATA_DISCONNECTED";
    case TelephonyManager.DATA_SUSPENDED: return "DATA_SUSPENDED";
    default: return "DATA_STATE_" + i;
    }
  }

  static String network_type_text(int i) {
    switch (i) {
    case TelephonyManager.NETWORK_TYPE_1xRTT: return "NETWORK_TYPE_1xRTT";
    case TelephonyManager.NETWORK_TYPE_CDMA: return "NETWORK_TYPE_CDMA";
    case TelephonyManager.NETWORK_TYPE_EDGE: return "NETWORK_TYPE_EDGE";
    case TelephonyManager.NETWORK_TYPE_EHRPD: return "NETWORK_TYPE_EHRPD";
    case TelephonyManager.NETWORK_TYPE_EVDO_0: return "NETWORK_TYPE_EVDO_0";
    case TelephonyManager.NETWORK_TYPE_EVDO_A: return "NETWORK_TYPE_EVDO_A";
    case TelephonyManager.NETWORK_TYPE_EVDO_B: return "NETWORK_TYPE_EVDO_B";
    case TelephonyManager.NETWORK_TYPE_GPRS: return "NETWORK_TYPE_GPRS";
    case TelephonyManager.NETWORK_TYPE_HSDPA: return "NETWORK_TYPE_HSDPA";
    case TelephonyManager.NETWORK_TYPE_HSPA: return "NETWORK_TYPE_HSPA";
    case TelephonyManager.NETWORK_TYPE_HSPAP: return "NETWORK_TYPE_HSPAP";
    case TelephonyManager.NETWORK_TYPE_HSUPA: return "NETWORK_TYPE_HSUPA";
    case TelephonyManager.NETWORK_TYPE_IDEN: return "NETWORK_TYPE_IDEN";
    case TelephonyManager.NETWORK_TYPE_LTE: return "NETWORK_TYPE_LTE";
    case TelephonyManager.NETWORK_TYPE_UMTS: return "NETWORK_TYPE_UMTS";
    case TelephonyManager.NETWORK_TYPE_UNKNOWN: return "NETWORK_TYPE_UNKNOWN";
    default: return "NETWORK_TYPE_" + i;
    }
  }

  /////////////////////
  public static void fill(TheDictionary map, TelephonyManager value) throws Exception {
    if (value != null) {
      map.put("type", "m");
      if (true) {
        map.put("android_version", Build.VERSION.SDK_INT);
        try { map.put("imei", value.getDeviceId().substring(0, 8)); } catch (Exception e) {}
        try { map.put("network_operator", value.getNetworkOperator()); } catch (Exception e) {}
        try { map.put("sim_operator", value.getSimOperator()); } catch (Exception e) {}
        if (CellIdPre17API.fallback_pre17api) {
          map.put("android_pre17api", CellIdPre17API.fallback_pre17api);
        }
        if (false) {
          try { map.put("imei", value.getDeviceId()); } catch (Exception e) {}
          try { map.put("msisdn", value.getLine1Number()); } catch (Exception e) {}
          try { map.put("imsi", value.getSubscriberId()); } catch (Exception e) {}
          try { map.put("android_call_state", call_state_text(value.getCallState())); } catch (Exception e) {}
          try { map.put("android_data_activity", data_activity_text(value.getDataActivity())); } catch (Exception e) {}
          try { map.put("android_data_state", data_state_text(value.getDataState())); } catch (Exception e) {}
          try { map.put("android_device_software_version", value.getDeviceSoftwareVersion()); } catch (Exception e) {}
          try { map.put("android_group_id_level1", value.getGroupIdLevel1()); } catch (Exception e) {}
          try { map.put("android_network_country_iso", value.getNetworkCountryIso()); } catch (Exception e) {}
          try { map.put("android_network_operator_name", value.getNetworkOperatorName()); } catch (Exception e) {}
          try { map.put("android_network_type", network_type_text(value.getNetworkType())); } catch (Exception e) {}
          try { map.put("android_phone_type", phone_type_text(value.getPhoneType())); } catch (Exception e) {}
          try { map.put("android_sim_country_iso", value.getSimCountryIso()); } catch (Exception e) {}
          try { map.put("android_sim_operator_name", value.getSimOperatorName()); } catch (Exception e) {}
          try { map.put("android_sim_serial_number", value.getSimSerialNumber()); } catch (Exception e) {}
          try { map.put("android_sim_state", sim_state_text(value.getSimState())); } catch (Exception e) {}
          try { map.put("android_voice_mail_alpha_tag", value.getVoiceMailAlphaTag()); } catch (Exception e) {}
          try { map.put("android_voice_mail_number", value.getVoiceMailNumber()); } catch (Exception e) {}
          try { map.put("android_icc_card", value.hasIccCard()); } catch (Exception e) {}
          try { map.put("android_network_roaming", value.isNetworkRoaming()); } catch (Exception e) {}
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            try { map.put("android_mms_ua_prof_url", value.getMmsUAProfUrl()); } catch (Exception e) {}
            try { map.put("android_mms_user_agent", value.getMmsUserAgent()); } catch (Exception e) {}
          }
        }
      }
    }
  }

  ///////////////////// test
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  static public String test(Context context) {
    List<TheDictionary> arr = new ArrayList<TheDictionary>();
    int post17cells = 0;
    int pre17cells = 0;
    int gps = 0;
    int wlans = 0;
    int mobiles = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      for (TheDictionary o: new CellId(((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getAllCellInfo())) {
        post17cells++;
        if (DEBUG) Log.d(TAG, "got: " + o);
        arr.add(o);
      }
      if (post17cells <= 0) {
        Log.e(TAG, "test: post-17 android, pre-17 api!");
      }
    }
    TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    for (TheDictionary o: new CellIdPre17API(telephonyManager, telephonyManager.getCellLocation(), telephonyManager.getNeighboringCellInfo())) {
      pre17cells++;
      if (DEBUG) Log.d(TAG, "got: " + o);
      arr.add(o);
    }
    for (TheDictionary o: new Satellite(((LocationManager)context.getSystemService(Context.LOCATION_SERVICE)).getLastKnownLocation(LocationManager.GPS_PROVIDER))) {
      gps++;
      if (DEBUG) Log.d(TAG, "got: " + o);
      arr.add(o);
    }
    for (TheDictionary o: new WifiId(((WifiManager)context.getSystemService(Context.WIFI_SERVICE)).getScanResults())) {
      wlans++;
      if (DEBUG) Log.d(TAG, "got: " + o);
      arr.add(o);
    }
    for (TheDictionary o: new Meta((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE))) {
      mobiles++;
      if (DEBUG) Log.d(TAG, "got: " + o);
      arr.add(o);
    }
    if (DEBUG) Log.d(TAG, "json=" + arr.toString());
    return "post17cells=" + post17cells + '\n' +
      "pre17cells=" + pre17cells + '\n' +
      "gps=" + gps + '\n' +
      "wlans=" + wlans + '\n' +
      "mobiles=" + mobiles + '\n';
  }
}




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