Android Open Source - pyneo-wirelesslocation Main Service






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.wirelesslocation;
//w  ww. j ava  2  s . c o  m
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.IBinder;
import android.provider.Settings;
import android.util.Log;

public class MainService extends Service {
  private static final String TAG = MainService.class.getName();
  public static boolean DEBUG = false;
  static { DEBUG = Log.isLoggable("org.pyneo.android", Log.DEBUG); }

  private static Context context;
  private NetworkLocationProvider nlprovider;
  private GeocodeProvider geoprovider;

  public MainService() {
    if (DEBUG) Log.d(TAG, "MainService:");
  }

  public static Context getContext() {
    if (DEBUG) Log.d(TAG, "getContext:");
    return context;
  }

  public Location getCurrentLocation() {
    if (DEBUG) Log.d(TAG, "getCurrentLocation:");
    return null;
  }

  public boolean isActive() {
    if (DEBUG) Log.d(TAG, "isActive:");
    return nlprovider != null && nlprovider.isActive();
  }

  private static int androidProviderSettingsGlobalGetInt(ContentResolver contentResolver, String name, int defaultValue) {
    if (DEBUG) Log.d(TAG, "androidProviderSettingsGlobalGetInt:");
    try {
      Class<?> clazz = Class.forName("android.provider.Settings$Global");
      Method getInt = clazz.getDeclaredMethod("getInt", ContentResolver.class, String.class, int.class);
      return (Integer) getInt.invoke(null, contentResolver, name, defaultValue);
    } catch (Exception e) {
      Log.w("android.provider.Settings.Global.getInt", e);
      return defaultValue;
    }
  }

  @Override
  public IBinder onBind(final Intent intent) {
    if (DEBUG) Log.d(TAG, "onBind: intent=" + intent);
    IBinder ret = null;
    if (nlprovider != null && intent != null) {
      String action = intent.getAction();
      if (action != null) {
        if (
          action.equalsIgnoreCase("com.google.android.location.NetworkLocationProvider") ||
          action.equalsIgnoreCase("com.android.location.service.NetworkLocationProvider") ||
          action.equalsIgnoreCase("com.android.location.service.v2.NetworkLocationProvider") ||
          action.equalsIgnoreCase("com.android.location.service.v3.NetworkLocationProvider")) {
          ret = nlprovider.getBinder();
        } else if (
          action.equalsIgnoreCase("com.google.android.location.GeocodeProvider") ||
          action.equalsIgnoreCase("com.android.location.service.GeocodeProvider")) {
          ret = geoprovider.getBinder();
        } else if (
          action.equalsIgnoreCase("com.google.android.location.internal.ANDROID_NLP")) {
          ret = nlprovider.getBinder();
        } else {
          Log.w(TAG, "onBind: unknown intent");
        }
      }
    }
    if (DEBUG) Log.d(TAG, "onBind: ret=" + ret);
    return ret;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    if (DEBUG) Log.d(TAG, "onCreate:");
    context = this;
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
      nlprovider = new NetworkLocationProviderV1();
    } else {
      nlprovider = new NetworkLocationProviderV2(context);
    }
    geoprovider = new GeocodeProvider();
  }

  @Override
  public void onDestroy() {
    if (DEBUG) Log.d(TAG, "onDestroy:");
    geoprovider.disable();
    geoprovider = null;
    nlprovider.disable();
    nlprovider = null;
  }
}




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