blob: 00c1ce8b7aa2cc5c9b1b0bfaa206560b5514faaf [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;
21import android.location.Location;
22import android.location.LocationProviderImpl;
23import android.os.Bundle;
24import android.os.SystemClock;
25
26/**
27 * @hide - This is part of a framework that is under development and should not be used for
28 * active development.
29 */
30public class TestLocationProvider extends LocationProviderImpl {
31
32 public static final String PROVIDER_NAME = "test";
33 public static final double LAT = 0;
34 public static final double LON = 1;
35 public static final double ALTITUDE = 10000;
36 public static final float SPEED = 10;
37 public static final float BEARING = 1;
38 public static final int STATUS = AVAILABLE;
39
40 private Location mLocation;
41 private boolean mEnabled;
42
43 public TestLocationProvider() {
44 super(PROVIDER_NAME);
45 mLocation = new Location(PROVIDER_NAME);
46 updateLocation();
47 }
48
49 //LocationProvider methods
50
51 @Override
52 public int getAccuracy() {
53 return Criteria.ACCURACY_COARSE;
54 }
55
56 @Override
57 public int getPowerRequirement() {
58 return Criteria.NO_REQUIREMENT;
59 }
60
61 @Override
62 public boolean hasMonetaryCost() {
63 return false;
64 }
65
66 @Override
67 public boolean requiresCell() {
68 return false;
69 }
70
71 @Override
72 public boolean requiresNetwork() {
73 return false;
74 }
75
76 @Override
77 public boolean requiresSatellite() {
78 return false;
79 }
80
81 @Override
82 public boolean supportsAltitude() {
83 return true;
84 }
85
86 @Override
87 public boolean supportsBearing() {
88 return true;
89 }
90
91 @Override
92 public boolean supportsSpeed() {
93 return true;
94 }
95
96 //LocationProviderImpl methods
97 @Override
98 public void disable() {
99 mEnabled = false;
100 }
101
102 @Override
103 public void enable() {
104 mEnabled = true;
105 }
106
107 @Override
108 public boolean isEnabled() {
109 return mEnabled;
110 }
111
112 @Override
113 public boolean getLocation(Location l) {
114 updateLocation();
115 l.set(mLocation);
116 return true;
117 }
118
119 @Override
120 public int getStatus(Bundle extras) {
121 return STATUS;
122 }
123
124 private void updateLocation() {
125 long time = SystemClock.uptimeMillis();
126 long multiplier = (time/5000)%500000;
127 mLocation.setLatitude(LAT*multiplier);
128 mLocation.setLongitude(LON*multiplier);
129 mLocation.setAltitude(ALTITUDE);
130 mLocation.setSpeed(SPEED);
131 mLocation.setBearing(BEARING*multiplier);
132
133 Bundle extras = new Bundle();
134 extras.putInt("extraTest", 24);
135 mLocation.setExtras(extras);
136 mLocation.setTime(time);
137 }
138
139}