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