Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 17 | package com.android.server.location; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 18 | |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 19 | import android.location.Criteria; |
Mike Lockwood | 4e50b78 | 2009-04-03 08:24:43 -0700 | [diff] [blame] | 20 | import android.location.ILocationManager; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 21 | import android.location.Location; |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 22 | import android.location.LocationProvider; |
Mike Lockwood | 03d2467 | 2009-10-08 15:45:03 -0400 | [diff] [blame] | 23 | import android.net.NetworkInfo; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 25 | import android.os.RemoteException; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame^] | 26 | import android.os.WorkSource; |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 27 | import android.util.Log; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 28 | import android.util.PrintWriterPrinter; |
| 29 | |
| 30 | import java.io.PrintWriter; |
| 31 | |
| 32 | /** |
| 33 | * A mock location provider used by LocationManagerService to implement test providers. |
| 34 | * |
| 35 | * {@hide} |
| 36 | */ |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 37 | public class MockProvider implements LocationProviderInterface { |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 38 | private final String mName; |
| 39 | private final ILocationManager mLocationManager; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 40 | private final boolean mRequiresNetwork; |
| 41 | private final boolean mRequiresSatellite; |
| 42 | private final boolean mRequiresCell; |
| 43 | private final boolean mHasMonetaryCost; |
| 44 | private final boolean mSupportsAltitude; |
| 45 | private final boolean mSupportsSpeed; |
| 46 | private final boolean mSupportsBearing; |
| 47 | private final int mPowerRequirement; |
| 48 | private final int mAccuracy; |
| 49 | private final Location mLocation; |
| 50 | private int mStatus; |
| 51 | private long mStatusUpdateTime; |
| 52 | private final Bundle mExtras = new Bundle(); |
| 53 | private boolean mHasLocation; |
| 54 | private boolean mHasStatus; |
| 55 | private boolean mEnabled; |
| 56 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 57 | private static final String TAG = "MockProvider"; |
| 58 | |
Mike Lockwood | 4e50b78 | 2009-04-03 08:24:43 -0700 | [diff] [blame] | 59 | public MockProvider(String name, ILocationManager locationManager, |
| 60 | boolean requiresNetwork, boolean requiresSatellite, |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 61 | boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude, |
| 62 | boolean supportsSpeed, boolean supportsBearing, int powerRequirement, int accuracy) { |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 63 | mName = name; |
| 64 | mLocationManager = locationManager; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 65 | mRequiresNetwork = requiresNetwork; |
| 66 | mRequiresSatellite = requiresSatellite; |
| 67 | mRequiresCell = requiresCell; |
| 68 | mHasMonetaryCost = hasMonetaryCost; |
| 69 | mSupportsAltitude = supportsAltitude; |
| 70 | mSupportsBearing = supportsBearing; |
| 71 | mSupportsSpeed = supportsSpeed; |
| 72 | mPowerRequirement = powerRequirement; |
| 73 | mAccuracy = accuracy; |
| 74 | mLocation = new Location(name); |
| 75 | } |
| 76 | |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 77 | public String getName() { |
| 78 | return mName; |
| 79 | } |
| 80 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 81 | public void disable() { |
| 82 | mEnabled = false; |
| 83 | } |
| 84 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 85 | public void enable() { |
| 86 | mEnabled = true; |
| 87 | } |
| 88 | |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 89 | public boolean isEnabled() { |
| 90 | return mEnabled; |
| 91 | } |
| 92 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 93 | public int getStatus(Bundle extras) { |
| 94 | if (mHasStatus) { |
| 95 | extras.clear(); |
| 96 | extras.putAll(mExtras); |
| 97 | return mStatus; |
| 98 | } else { |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 99 | return LocationProvider.AVAILABLE; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Mike Lockwood | 4e50b78 | 2009-04-03 08:24:43 -0700 | [diff] [blame] | 103 | public long getStatusUpdateTime() { |
| 104 | return mStatusUpdateTime; |
| 105 | } |
| 106 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 107 | public int getAccuracy() { |
| 108 | return mAccuracy; |
| 109 | } |
| 110 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 111 | public int getPowerRequirement() { |
| 112 | return mPowerRequirement; |
| 113 | } |
| 114 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 115 | public boolean hasMonetaryCost() { |
| 116 | return mHasMonetaryCost; |
| 117 | } |
| 118 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 119 | public boolean requiresCell() { |
| 120 | return mRequiresCell; |
| 121 | } |
| 122 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 123 | public boolean requiresNetwork() { |
| 124 | return mRequiresNetwork; |
| 125 | } |
| 126 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 127 | public boolean requiresSatellite() { |
| 128 | return mRequiresSatellite; |
| 129 | } |
| 130 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 131 | public boolean supportsAltitude() { |
| 132 | return mSupportsAltitude; |
| 133 | } |
| 134 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 135 | public boolean supportsBearing() { |
| 136 | return mSupportsBearing; |
| 137 | } |
| 138 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 139 | public boolean supportsSpeed() { |
| 140 | return mSupportsSpeed; |
| 141 | } |
| 142 | |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 143 | public boolean meetsCriteria(Criteria criteria) { |
| 144 | if ((criteria.getAccuracy() != Criteria.NO_REQUIREMENT) && |
| 145 | (criteria.getAccuracy() < mAccuracy)) { |
| 146 | return false; |
| 147 | } |
| 148 | int criteriaPower = criteria.getPowerRequirement(); |
| 149 | if ((criteriaPower != Criteria.NO_REQUIREMENT) && |
| 150 | (criteriaPower < mPowerRequirement)) { |
| 151 | return false; |
| 152 | } |
| 153 | if (criteria.isAltitudeRequired() && !mSupportsAltitude) { |
| 154 | return false; |
| 155 | } |
| 156 | if (criteria.isSpeedRequired() && !mSupportsSpeed) { |
| 157 | return false; |
| 158 | } |
| 159 | if (criteria.isBearingRequired() && !mSupportsBearing) { |
| 160 | return false; |
| 161 | } |
| 162 | return true; |
| 163 | } |
| 164 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 165 | public void setLocation(Location l) { |
| 166 | mLocation.set(l); |
| 167 | mHasLocation = true; |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 168 | try { |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 169 | mLocationManager.reportLocation(mLocation, false); |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 170 | } catch (RemoteException e) { |
| 171 | Log.e(TAG, "RemoteException calling reportLocation"); |
| 172 | } |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | public void clearLocation() { |
| 176 | mHasLocation = false; |
| 177 | } |
| 178 | |
| 179 | public void setStatus(int status, Bundle extras, long updateTime) { |
| 180 | mStatus = status; |
| 181 | mStatusUpdateTime = updateTime; |
| 182 | mExtras.clear(); |
| 183 | if (extras != null) { |
| 184 | mExtras.putAll(extras); |
| 185 | } |
| 186 | mHasStatus = true; |
| 187 | } |
| 188 | |
| 189 | public void clearStatus() { |
| 190 | mHasStatus = false; |
Mike Lockwood | 4e50b78 | 2009-04-03 08:24:43 -0700 | [diff] [blame] | 191 | mStatusUpdateTime = 0; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 194 | public String getInternalState() { |
| 195 | return null; |
| 196 | } |
| 197 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 198 | public void enableLocationTracking(boolean enable) { |
| 199 | } |
| 200 | |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 201 | public boolean requestSingleShotFix() { |
| 202 | return false; |
| 203 | } |
| 204 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame^] | 205 | public void setMinTime(long minTime, WorkSource ws) { |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 206 | } |
| 207 | |
Mike Lockwood | 03d2467 | 2009-10-08 15:45:03 -0400 | [diff] [blame] | 208 | public void updateNetworkState(int state, NetworkInfo info) { |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 209 | } |
| 210 | |
Mike Lockwood | fd6e5f0 | 2009-05-21 11:28:20 -0400 | [diff] [blame] | 211 | public void updateLocation(Location location) { |
| 212 | } |
| 213 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 214 | public boolean sendExtraCommand(String command, Bundle extras) { |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | public void addListener(int uid) { |
| 219 | } |
| 220 | |
| 221 | public void removeListener(int uid) { |
| 222 | } |
| 223 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 224 | public void dump(PrintWriter pw, String prefix) { |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 225 | pw.println(prefix + mName); |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 226 | pw.println(prefix + "mHasLocation=" + mHasLocation); |
| 227 | pw.println(prefix + "mLocation:"); |
| 228 | mLocation.dump(new PrintWriterPrinter(pw), prefix + " "); |
| 229 | pw.println(prefix + "mHasStatus=" + mHasStatus); |
| 230 | pw.println(prefix + "mStatus=" + mStatus); |
| 231 | pw.println(prefix + "mStatusUpdateTime=" + mStatusUpdateTime); |
| 232 | pw.println(prefix + "mExtras=" + mExtras); |
| 233 | } |
| 234 | } |