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
17package com.android.server.location;
18
19import android.location.Criteria;
20import android.location.ILocationManager;
21import android.location.Location;
22import android.location.LocationManager;
23import android.location.LocationProvider;
24import android.net.NetworkInfo;
25import android.os.Bundle;
26import android.os.RemoteException;
27import android.os.WorkSource;
28import android.util.Log;
29
30/**
31 * A passive location provider reports locations received from other providers
32 * for clients that want to listen passively without actually triggering
33 * location updates.
34 *
35 * {@hide}
36 */
37public class PassiveProvider implements LocationProviderInterface {
38
39    private static final String TAG = "PassiveProvider";
40
41    private final ILocationManager mLocationManager;
42    private boolean mTracking;
43
44    public PassiveProvider(ILocationManager locationManager) {
45        mLocationManager = locationManager;
46    }
47
48    public String getName() {
49        return LocationManager.PASSIVE_PROVIDER;
50    }
51
52    public boolean requiresNetwork() {
53        return false;
54    }
55
56    public boolean requiresSatellite() {
57        return false;
58    }
59
60    public boolean requiresCell() {
61        return false;
62    }
63
64    public boolean hasMonetaryCost() {
65        return false;
66    }
67
68    public boolean supportsAltitude() {
69        return false;
70    }
71
72    public boolean supportsSpeed() {
73        return false;
74    }
75
76    public boolean supportsBearing() {
77        return false;
78    }
79
80    public int getPowerRequirement() {
81        return -1;
82    }
83
84    public boolean meetsCriteria(Criteria criteria) {
85        // We do not want to match the special passive provider based on criteria.
86        return false;
87    }
88
89    public int getAccuracy() {
90        return -1;
91    }
92
93    public boolean isEnabled() {
94        return true;
95    }
96
97    public void enable() {
98    }
99
100    public void disable() {
101    }
102
103    public int getStatus(Bundle extras) {
104        if (mTracking) {
105            return LocationProvider.AVAILABLE;
106        } else {
107            return LocationProvider.TEMPORARILY_UNAVAILABLE;
108        }
109    }
110
111    public long getStatusUpdateTime() {
112        return -1;
113    }
114
115    public String getInternalState() {
116        return null;
117    }
118
119    public void enableLocationTracking(boolean enable) {
120        mTracking = enable;
121    }
122
123    public boolean requestSingleShotFix() {
124        return false;
125    }
126
127    public void setMinTime(long minTime, WorkSource ws) {
128    }
129
130    public void updateNetworkState(int state, NetworkInfo info) {
131    }
132
133    public void updateLocation(Location location) {
134        if (mTracking) {
135            try {
136                // pass the location back to the location manager
137                mLocationManager.reportLocation(location, true);
138            } catch (RemoteException e) {
139                Log.e(TAG, "RemoteException calling reportLocation");
140            }
141        }
142    }
143
144    public boolean sendExtraCommand(String command, Bundle extras) {
145        return false;
146    }
147
148    public void addListener(int uid) {
149    }
150
151    public void removeListener(int uid) {
152    }
153}
154