blob: dc07585cede83814cb3d5ec862ca0e781d959778 [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;
Mike Lockwood03d24672009-10-08 15:45:03 -040025import android.net.NetworkInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.os.Bundle;
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040027import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.SystemClock;
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040029import android.util.Log;
Mike Lockwood79762a32009-04-28 11:31:44 -040030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031/**
32 * @hide - This is part of a framework that is under development and should not be used for
33 * active development.
34 */
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040035public class TestLocationProvider extends ILocationProvider.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37 public static final String PROVIDER_NAME = "test";
38 public static final double LAT = 0;
39 public static final double LON = 1;
40 public static final double ALTITUDE = 10000;
41 public static final float SPEED = 10;
42 public static final float BEARING = 1;
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040043 public static final int STATUS = LocationProvider.AVAILABLE;
Mike Lockwood4e50b782009-04-03 08:24:43 -070044 private static final long LOCATION_INTERVAL = 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040046 private static final String TAG = "TestLocationProvider";
47
48 private final ILocationManager mLocationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 private Location mLocation;
50 private boolean mEnabled;
Mike Lockwood4e50b782009-04-03 08:24:43 -070051 private TestLocationProviderThread mThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
Mike Lockwood4e50b782009-04-03 08:24:43 -070053 private class TestLocationProviderThread extends Thread {
54
55 private boolean mDone = false;
56
57 public TestLocationProviderThread() {
58 super("TestLocationProviderThread");
59 }
60
61 public void run() {
62 // thread exits after disable() is called
63 synchronized (this) {
64 while (!mDone) {
65 try {
66 wait(LOCATION_INTERVAL);
67 } catch (InterruptedException e) {
68 }
69
70 if (!mDone) {
71 TestLocationProvider.this.updateLocation();
72 }
73 }
74 }
75 }
76
77 synchronized void setDone() {
78 mDone = true;
79 notify();
80 }
81 }
82
83 public TestLocationProvider(ILocationManager locationManager) {
Mike Lockwood15e3d0f2009-05-01 07:53:28 -040084 mLocationManager = locationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 mLocation = new Location(PROVIDER_NAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 }
87
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 public int getAccuracy() {
89 return Criteria.ACCURACY_COARSE;
90 }
91
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 public int getPowerRequirement() {
93 return Criteria.NO_REQUIREMENT;
94 }
95
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 public boolean hasMonetaryCost() {
97 return false;
98 }
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 public boolean requiresCell() {
101 return false;
102 }
103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 public boolean requiresNetwork() {
105 return false;
106 }
107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 public boolean requiresSatellite() {
109 return false;
110 }
111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 public boolean supportsAltitude() {
113 return true;
114 }
115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 public boolean supportsBearing() {
117 return true;
118 }
119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 public boolean supportsSpeed() {
121 return true;
122 }
123
Mike Lockwood4e50b782009-04-03 08:24:43 -0700124 public synchronized void disable() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 mEnabled = false;
Mike Lockwood4e50b782009-04-03 08:24:43 -0700126 if (mThread != null) {
127 mThread.setDone();
128 try {
129 mThread.join();
130 } catch (InterruptedException e) {
131 }
132 mThread = null;
133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 }
135
Mike Lockwood4e50b782009-04-03 08:24:43 -0700136 public synchronized void enable() {
137 mEnabled = true;
138 mThread = new TestLocationProviderThread();
139 mThread.start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 }
141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 public boolean isEnabled() {
143 return mEnabled;
144 }
145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 public int getStatus(Bundle extras) {
147 return STATUS;
148 }
149
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400150 public long getStatusUpdateTime() {
151 return 0;
152 }
153
154 public void enableLocationTracking(boolean enable) {
155 }
156
157 public void setMinTime(long minTime) {
158 }
159
Mike Lockwood03d24672009-10-08 15:45:03 -0400160 public void updateNetworkState(int state, NetworkInfo info) {
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400161 }
162
Mike Lockwoodfd6e5f02009-05-21 11:28:20 -0400163 public void updateLocation(Location location) {
164 }
165
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400166 public boolean sendExtraCommand(String command, Bundle extras) {
167 return false;
168 }
169
170 public void addListener(int uid) {
171 }
172
173 public void removeListener(int uid) {
174 }
175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 private void updateLocation() {
177 long time = SystemClock.uptimeMillis();
178 long multiplier = (time/5000)%500000;
179 mLocation.setLatitude(LAT*multiplier);
180 mLocation.setLongitude(LON*multiplier);
181 mLocation.setAltitude(ALTITUDE);
182 mLocation.setSpeed(SPEED);
183 mLocation.setBearing(BEARING*multiplier);
184
185 Bundle extras = new Bundle();
186 extras.putInt("extraTest", 24);
187 mLocation.setExtras(extras);
188 mLocation.setTime(time);
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400189 try {
Mike Lockwood275555c2009-05-01 11:30:34 -0400190 mLocationManager.reportLocation(mLocation);
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400191 } catch (RemoteException e) {
192 Log.e(TAG, "RemoteException calling updateLocation");
193 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 }
195
196}