blob: 500786dee7b9081a088af3d305bf0cc68a44b686 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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 android.test;
18
19
20import android.location.Criteria;
Mike Lockwood4e50b782009-04-03 08:24:43 -070021import android.location.ILocationManager;
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040022import android.location.ILocationProvider;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.location.Location;
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040024import android.location.LocationProvider;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.Bundle;
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040026import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.os.SystemClock;
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040028import android.util.Log;
Mike Lockwood79762a32009-04-28 11:31:44 -040029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030/**
31 * @hide - This is part of a framework that is under development and should not be used for
32 * active development.
33 */
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040034public class TestLocationProvider extends ILocationProvider.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
36 public static final String PROVIDER_NAME = "test";
37 public static final double LAT = 0;
38 public static final double LON = 1;
39 public static final double ALTITUDE = 10000;
40 public static final float SPEED = 10;
41 public static final float BEARING = 1;
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040042 public static final int STATUS = LocationProvider.AVAILABLE;
Mike Lockwood4e50b782009-04-03 08:24:43 -070043 private static final long LOCATION_INTERVAL = 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040045 private static final String TAG = "TestLocationProvider";
46
47 private final ILocationManager mLocationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 private Location mLocation;
49 private boolean mEnabled;
Mike Lockwood4e50b782009-04-03 08:24:43 -070050 private TestLocationProviderThread mThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
Mike Lockwood4e50b782009-04-03 08:24:43 -070052 private class TestLocationProviderThread extends Thread {
53
54 private boolean mDone = false;
55
56 public TestLocationProviderThread() {
57 super("TestLocationProviderThread");
58 }
59
60 public void run() {
61 // thread exits after disable() is called
62 synchronized (this) {
63 while (!mDone) {
64 try {
65 wait(LOCATION_INTERVAL);
66 } catch (InterruptedException e) {
67 }
68
69 if (!mDone) {
70 TestLocationProvider.this.updateLocation();
71 }
72 }
73 }
74 }
75
76 synchronized void setDone() {
77 mDone = true;
78 notify();
79 }
80 }
81
82 public TestLocationProvider(ILocationManager locationManager) {
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040083 mLocationManager = locationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 mLocation = new Location(PROVIDER_NAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 }
86
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 public int getAccuracy() {
88 return Criteria.ACCURACY_COARSE;
89 }
90
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 public int getPowerRequirement() {
92 return Criteria.NO_REQUIREMENT;
93 }
94
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 public boolean hasMonetaryCost() {
96 return false;
97 }
98
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 public boolean requiresCell() {
100 return false;
101 }
102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 public boolean requiresNetwork() {
104 return false;
105 }
106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 public boolean requiresSatellite() {
108 return false;
109 }
110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 public boolean supportsAltitude() {
112 return true;
113 }
114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 public boolean supportsBearing() {
116 return true;
117 }
118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 public boolean supportsSpeed() {
120 return true;
121 }
122
Mike Lockwood4e50b782009-04-03 08:24:43 -0700123 public synchronized void disable() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 mEnabled = false;
Mike Lockwood4e50b782009-04-03 08:24:43 -0700125 if (mThread != null) {
126 mThread.setDone();
127 try {
128 mThread.join();
129 } catch (InterruptedException e) {
130 }
131 mThread = null;
132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 }
134
Mike Lockwood4e50b782009-04-03 08:24:43 -0700135 public synchronized void enable() {
136 mEnabled = true;
137 mThread = new TestLocationProviderThread();
138 mThread.start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 }
140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 public boolean isEnabled() {
142 return mEnabled;
143 }
144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 public int getStatus(Bundle extras) {
146 return STATUS;
147 }
148
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400149 public long getStatusUpdateTime() {
150 return 0;
151 }
152
153 public void enableLocationTracking(boolean enable) {
154 }
155
156 public void setMinTime(long minTime) {
157 }
158
159 public void updateNetworkState(int state) {
160 }
161
162 public boolean sendExtraCommand(String command, Bundle extras) {
163 return false;
164 }
165
166 public void addListener(int uid) {
167 }
168
169 public void removeListener(int uid) {
170 }
171
172 public void wakeLockAcquired() {
173 }
174
175 public void wakeLockReleased() {
176 }
177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 private void updateLocation() {
179 long time = SystemClock.uptimeMillis();
180 long multiplier = (time/5000)%500000;
181 mLocation.setLatitude(LAT*multiplier);
182 mLocation.setLongitude(LON*multiplier);
183 mLocation.setAltitude(ALTITUDE);
184 mLocation.setSpeed(SPEED);
185 mLocation.setBearing(BEARING*multiplier);
186
187 Bundle extras = new Bundle();
188 extras.putInt("extraTest", 24);
189 mLocation.setExtras(extras);
190 mLocation.setTime(time);
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400191 try {
192 mLocationManager.setLocation(mLocation);
193 } catch (RemoteException e) {
194 Log.e(TAG, "RemoteException calling updateLocation");
195 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 }
197
198}