Home | History | Annotate | Download | only in location
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.server.location;
     18 
     19 import java.io.FileDescriptor;
     20 import java.io.PrintWriter;
     21 
     22 import com.android.internal.location.ProviderProperties;
     23 import com.android.internal.location.ProviderRequest;
     24 
     25 import android.location.Criteria;
     26 import android.location.ILocationManager;
     27 import android.location.Location;
     28 import android.location.LocationManager;
     29 import android.location.LocationProvider;
     30 import android.os.Bundle;
     31 import android.os.RemoteException;
     32 import android.os.WorkSource;
     33 import android.util.Log;
     34 
     35 
     36 /**
     37  * A passive location provider reports locations received from other providers
     38  * for clients that want to listen passively without actually triggering
     39  * location updates.
     40  *
     41  * {@hide}
     42  */
     43 public class PassiveProvider implements LocationProviderInterface {
     44     private static final String TAG = "PassiveProvider";
     45 
     46     private static final ProviderProperties PROPERTIES = new ProviderProperties(
     47             false, false, false, false, false, false, false,
     48             Criteria.POWER_LOW, Criteria.ACCURACY_COARSE);
     49 
     50     private final ILocationManager mLocationManager;
     51     private boolean mReportLocation;
     52 
     53     public PassiveProvider(ILocationManager locationManager) {
     54         mLocationManager = locationManager;
     55     }
     56 
     57     @Override
     58     public String getName() {
     59         return LocationManager.PASSIVE_PROVIDER;
     60     }
     61 
     62     @Override
     63     public ProviderProperties getProperties() {
     64         return PROPERTIES;
     65     }
     66 
     67     @Override
     68     public boolean isEnabled() {
     69         return true;
     70     }
     71 
     72     @Override
     73     public void enable() {
     74     }
     75 
     76     @Override
     77     public void disable() {
     78     }
     79 
     80     @Override
     81     public int getStatus(Bundle extras) {
     82         if (mReportLocation) {
     83             return LocationProvider.AVAILABLE;
     84         } else {
     85             return LocationProvider.TEMPORARILY_UNAVAILABLE;
     86         }
     87     }
     88 
     89     @Override
     90     public long getStatusUpdateTime() {
     91         return -1;
     92     }
     93 
     94     @Override
     95     public void setRequest(ProviderRequest request, WorkSource source) {
     96         mReportLocation = request.reportLocation;
     97     }
     98 
     99     public void updateLocation(Location location) {
    100         if (mReportLocation) {
    101             try {
    102                 // pass the location back to the location manager
    103                 mLocationManager.reportLocation(location, true);
    104             } catch (RemoteException e) {
    105                 Log.e(TAG, "RemoteException calling reportLocation");
    106             }
    107         }
    108     }
    109 
    110     @Override
    111     public boolean sendExtraCommand(String command, Bundle extras) {
    112         return false;
    113     }
    114 
    115     @Override
    116     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    117         pw.println("mReportLocation=" + mReportLocation);
    118     }
    119 }
    120