Android Open Source - pyneo-wirelesslocation Location Provider Base






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

/*
 * Copyright (C) 2010 The Android Open Source Project
 *// w  ww .  ja va2 s.c  o  m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package internal.com.android.location.provider;

import java.io.FileDescriptor;
import java.lang.reflect.Method;

import android.content.Context;
import android.location.ILocationManager;
import android.location.Location;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import com.android.internal.location.ILocationProvider;
import com.android.internal.location.ProviderProperties;
import com.android.internal.location.ProviderRequest;

/**
 * Base class for location providers implemented as unbundled services.
 * <p/>
 * <p>The network location provider must export a service with action
 * "com.android.location.service.v2.NetworkLocationProvider"
 * and a valid minor version in a meta-data field on the service, and
 * then return the result of {@link #getBinder()} on service binding.
 * <p/>
 * <p>The fused location provider must export a service with action
 * "com.android.location.service.FusedLocationProvider"
 * and a valid minor version in a meta-data field on the service, and
 * then return the result of {@link #getBinder()} on service binding.
 * <p/>
 * <p>IMPORTANT: This class is effectively a public API for unbundled
 * applications, and must remain API stable. See README.txt in the root
 * of this package for more information.
 */
public abstract class LocationProviderBase {
  /**
   * Bundle key for a version of the location containing no GPS data.
   * Allows location providers to flag locations as being safe to
   * feed to LocationFudger.
   */
  public static final String EXTRA_NO_GPS_LOCATION = "noGPSLocation";
  /**
   * Name of the Fused location provider.
   * <p/>
   * <p>This provider combines inputs for all possible location sources
   * to provide the best possible Location fix.
   */
  public static final String FUSED_PROVIDER = "fused";
  protected final ILocationManager mLocationManager;
  private final String TAG;
  private final ProviderProperties mProperties;
  private final IBinder mBinder;

  private static IBinder androidOsServiceManagerGetService(String service) {
    try {
      Class clazz = Class.forName("android.os.ServiceManager");
      Method makeComplete = clazz.getDeclaredMethod("getService", String.class);
      return (IBinder) makeComplete.invoke(null, service);
    } catch (Exception e) {
      Log.w("android.os.ServiceManager.getService", e);
      return null;
    }
  }
  
  public LocationProviderBase(String tag, ProviderPropertiesUnbundled properties) {
    TAG = tag;
    IBinder b = androidOsServiceManagerGetService(Context.LOCATION_SERVICE);
    mLocationManager = ILocationManager.Stub.asInterface(b);
    mProperties = properties.getProviderProperties();
    mBinder = new Service();
  }

  public IBinder getBinder() {
    return mBinder;
  }

  /**
   * Disable the location provider.
   * <p>The provider must release resources, and stop
   * performing work. It may no longer report locations.
   */
  public abstract void onDisable();

  /**
   * Enable the location provider.
   * <p>The provider may initialize resources, but does
   * not yet need to report locations.
   */
  public abstract void onEnable();

  /**
   * Returns a information on the status of this provider.
   * <p>{@link android.location.LocationProvider#OUT_OF_SERVICE} is returned if the provider is
   * out of service, and this is not expected to change in the near
   * future; {@link android.location.LocationProvider#TEMPORARILY_UNAVAILABLE} is returned if
   * the provider is temporarily unavailable but is expected to be
   * available shortly; and {@link android.location.LocationProvider#AVAILABLE} is returned
   * if the provider is currently available.
   * <p/>
   * <p>If extras is non-null, additional status information may be
   * added to it in the form of provider-specific key/value pairs.
   */
  public abstract int onGetStatus(Bundle extras);

  /**
   * Returns the time at which the status was last updated. It is the
   * responsibility of the provider to appropriately set this value using
   * {@link android.os.SystemClock#elapsedRealtime SystemClock.elapsedRealtime()}.
   * there is a status update that it wishes to broadcast to all its
   * listeners. The provider should be careful not to broadcast
   * the same status again.
   *
   * @return time of last status update in millis since last reboot
   */
  public abstract long onGetStatusUpdateTime();

  /**
   * Implements addditional location provider specific additional commands.
   *
   * @param command name of the command to send to the provider.
   * @param extras  optional arguments for the command (or null).
   *                The provider may optionally fill the extras Bundle with results from the command.
   * @return true if the command succeeds.
   */
  public boolean onSendExtraCommand(String command, Bundle extras) {
    // default implementation
    return false;
  }

  /**
   * Set the {@link com.android.internal.location.ProviderRequest} requirements for this provider.
   * <p>Each call to this method overrides all previous requests.
   * <p>This method might trigger the provider to start returning
   * locations, or to stop returning locations, depending on the
   * parameters in the request.
   */
  public abstract void onSetRequest(ProviderRequestUnbundled request, android.os.WorkSource source);

  /**
   * Used by the location provider to report new locations.
   *
   * @param location new Location to report
   *                 <p/>
   *                 Requires the android.permission.INSTALL_LOCATION_PROVIDER permission.
   */
  public final void reportLocation(Location location) {
    try {
      mLocationManager.reportLocation(location, false);
    } catch (RemoteException e) {
      Log.e(TAG, "RemoteException", e);
    } catch (Exception e) {
      // never crash provider, might be running in a system process
      Log.e(TAG, "Exception", e);
    }
  }

  private final class Service extends ILocationProvider.Stub {
    @Override
    public void disable() {
      onDisable();
    }

    @Override
    public void dump(FileDescriptor fd, String[] args) {
    }

    @Override
    public void enable() {
      onEnable();
    }

    @Override
    public ProviderProperties getProperties() {
      return mProperties;
    }

    @Override
    public int getStatus(Bundle extras) {
      return onGetStatus(extras);
    }

    @Override
    public long getStatusUpdateTime() {
      return onGetStatusUpdateTime();
    }

    @Override
    public boolean sendExtraCommand(String command, Bundle extras) {
      return onSendExtraCommand(command, extras);
    }

    @Override
    public void setRequest(ProviderRequest request, android.os.WorkSource ws) {
      onSetRequest(new ProviderRequestUnbundled(request), ws);
    }
  }
}




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