My favorites
▼
|
Sign in
gpslogger
A simple GPS location logger service for Android handsets
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
7
attachment: energy.patch
(9.6 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
--- ./java_workspace/GPSLogger-to-publish/src/com/prom2m/android/gpslogger/service/GPSLoggerService.java
+++ ./java_workspace/GPSLogger-r15/src/com/prom2m/android/gpslogger/service/GPSLoggerService.java
@@ -7,6 +7,7 @@
import java.util.GregorianCalendar;
import java.util.TimeZone;
+import com.prom2m.android.gpslogger.R;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -24,8 +25,6 @@
import android.util.Log;
import android.widget.Toast;
-import com.prom2m.android.gpslogger.R;
-
public class GPSLoggerService extends Service {
public static final String DATABASE_NAME = "GPSLOGGERDB";
@@ -39,29 +38,13 @@
private LocationListener locationListener;
private SQLiteDatabase db;
- private static long minTimeMillis_normal = 2000;
- private static long minTimeMillis_slow = 30000;
- private static long minTimeMills_veryslow = 120000;
+ private static long minTimeMillis = 2000;
private static long minDistanceMeters = 10;
private static float minAccuracyMeters = 35;
private int lastStatus = 0;
private static boolean showingDebugToast = false;
- private static long currentUpdateTimeInterval;
- private static final int TO_SLOW = 1;
- private static final int TO_NORMAL = 2;
- private static final int TO_VERY_SLOW = 3;
-
-
- //if we receive inaccurate results for "inaccuracyTolerance" times, location sensing will be slowed down
- private static int consecutiveInaccurateLocUpdate = 0;
- private static int inaccuracyTolerance = 5;
-
- //if we receive accurate results for many times, we increase sensing rate if it is slow
- private static int consecutiveAccurateLocUpdate = 0;
- private static int accurateTimesBound = 2;
-
private static final String tag = "GPSLoggerService";
/** Called when the activity is first created. */
@@ -72,15 +55,10 @@
locationListener = new MyLocationListener();
- synchronized (this) {
- lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,
- minTimeMillis_normal,
- minDistanceMeters,
- locationListener);
- currentUpdateTimeInterval = minTimeMillis_normal;
- }
-
-
+ lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,
+ minTimeMillis,
+ minDistanceMeters,
+ locationListener);
initDatabase();
}
@@ -96,65 +74,11 @@
private void shutdownLoggerService() {
lm.removeUpdates(locationListener);
}
-
- /**
- * we maintain a state machine for tuning location sensing rate
- * state: normal, slow, very slow
- * transitions: normal --> slow (on consecutive inaccurate readings), slow --> normal (on consecutive accurate readings)
- * slow --> very slow (if gps service temporarily unavailable or out of service), very slow --> slow (if GPS service becomes available)
- * normal --> very slow (if gps service temporarily unavailable or out of service)
- * @param target the target sensing rate
- * @param slower indicate if the sensing rate is going to be reduced or increased
- * example: changeLocUpdateRate(2_SLOW, true) means if the current state is normal, go down to slow, otherwise, no effect
- */
- private synchronized void changeLocUpdateRate(int target, boolean slower){
- if(target == TO_SLOW){
- if(slower){
- //normal to slow
- if(currentUpdateTimeInterval == minTimeMillis_normal){
- lm.removeUpdates(locationListener);
- lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeMillis_slow, minDistanceMeters, locationListener);
- currentUpdateTimeInterval = minTimeMillis_slow;
- }
- } else{
- //very slow to slow
- if(currentUpdateTimeInterval == minTimeMills_veryslow){
- lm.removeUpdates(locationListener);
- lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeMillis_slow, minDistanceMeters, locationListener);
- currentUpdateTimeInterval = minTimeMillis_slow;
- }
- }
- }
- if(target == TO_NORMAL){
- if(!slower){
- //only one possibility: slow to normal
- if(currentUpdateTimeInterval == minTimeMillis_slow){
- lm.removeUpdates(locationListener);
- lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeMillis_normal, minDistanceMeters, locationListener);
- currentUpdateTimeInterval = minTimeMillis_normal;
- }
- }
- }
- if(target == TO_VERY_SLOW){
- if(slower){
- //normal to very slow, slow to very slow
- if(currentUpdateTimeInterval != minTimeMills_veryslow){
- lm.removeUpdates(locationListener);
- lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeMills_veryslow, minDistanceMeters, locationListener);
- currentUpdateTimeInterval = minTimeMills_veryslow;
- }
- }
- }
-
- }
public class MyLocationListener implements LocationListener {
public void onLocationChanged(Location loc) {
- //if the current sensing rate is very slow, change it to slow
- changeLocUpdateRate(TO_SLOW, false);
if (loc != null) {
- //log the last location update time
boolean pointIsRecorded = false;
try {
if (loc.hasAccuracy() && loc.getAccuracy() <= minAccuracyMeters) {
@@ -191,16 +115,6 @@
+ " \nAlt: " + (loc.hasAltitude() ? loc.getAltitude()+"m":"?")
+ " \nAcc: " + (loc.hasAccuracy() ? loc.getAccuracy()+"m":"?"),
Toast.LENGTH_SHORT).show();
- synchronized (this) {
- consecutiveAccurateLocUpdate++;
- if(consecutiveAccurateLocUpdate >= accurateTimesBound){
- //change to normal sensing rate if it is slow sensing now
- changeLocUpdateRate(TO_NORMAL, false);
- }
- consecutiveInaccurateLocUpdate = 0;
- consecutiveInaccurateLocUpdate = 0;
- }
-
} else {
if (showingDebugToast) Toast.makeText(
getBaseContext(),
@@ -209,15 +123,6 @@
+ " \nAlt: " + (loc.hasAltitude() ? loc.getAltitude()+"m":"?")
+ " \nAcc: " + (loc.hasAccuracy() ? loc.getAccuracy()+"m":"?"),
Toast.LENGTH_SHORT).show();
- synchronized (this) {
- consecutiveInaccurateLocUpdate++;
- if(consecutiveInaccurateLocUpdate >= inaccuracyTolerance){
- //if the current sensing rate is normal, change it to slow
- changeLocUpdateRate(TO_SLOW, true);
- }
- consecutiveAccurateLocUpdate = 0;
- consecutiveInaccurateLocUpdate = 0;
- }
}
}
}
@@ -225,31 +130,23 @@
public void onProviderDisabled(String provider) {
if (showingDebugToast) Toast.makeText(getBaseContext(), "onProviderDisabled: " + provider,
Toast.LENGTH_SHORT).show();
- changeLocUpdateRate(TO_VERY_SLOW, true);
}
public void onProviderEnabled(String provider) {
if (showingDebugToast) Toast.makeText(getBaseContext(), "onProviderEnabled: " + provider,
Toast.LENGTH_SHORT).show();
- changeLocUpdateRate(TO_SLOW, false);
}
public void onStatusChanged(String provider, int status, Bundle extras) {
String showStatus = null;
- if (status == LocationProvider.AVAILABLE){
+ if (status == LocationProvider.AVAILABLE)
showStatus = "Available";
- changeLocUpdateRate(TO_SLOW, false);
- }
- if (status == LocationProvider.TEMPORARILY_UNAVAILABLE){
+ if (status == LocationProvider.TEMPORARILY_UNAVAILABLE)
showStatus = "Temporarily Unavailable";
- changeLocUpdateRate(TO_VERY_SLOW, true);
- }
- if (status == LocationProvider.OUT_OF_SERVICE){
+ if (status == LocationProvider.OUT_OF_SERVICE)
showStatus = "Out of Service";
- changeLocUpdateRate(TO_VERY_SLOW, true);
- }
if (status != lastStatus && showingDebugToast) {
Toast.makeText(getBaseContext(),
"new status: " + showStatus,
@@ -267,9 +164,8 @@
@Override
public void onCreate() {
super.onCreate();
-
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-
+
startLoggerService();
// Display a notification about us starting. We put an icon in the
@@ -285,12 +181,12 @@
// Cancel the persistent notification.
mNM.cancel(R.string.local_service_started);
-
+
// Tell the user we stopped.
Toast.makeText(this, R.string.local_service_stopped,
Toast.LENGTH_SHORT).show();
}
-
+
/**
* Show a notification while this service is running.
*/
@@ -327,29 +223,29 @@
return mBinder;
}
-// public static void setMinTimeMillis(long _minTimeMillis) {
-// minTimeMillis = _minTimeMillis;
-// }
+ public static void setMinTimeMillis(long _minTimeMillis) {
+ minTimeMillis = _minTimeMillis;
+ }
-// public static long getMinTimeMillis() {
-// return minTimeMillis;
-// }
+ public static long getMinTimeMillis() {
+ return minTimeMillis;
+ }
-// public static void setMinDistanceMeters(long _minDistanceMeters) {
-// minDistanceMeters = _minDistanceMeters;
-// }
+ public static void setMinDistanceMeters(long _minDistanceMeters) {
+ minDistanceMeters = _minDistanceMeters;
+ }
-// public static long getMinDistanceMeters() {
-// return minDistanceMeters;
-// }
+ public static long getMinDistanceMeters() {
+ return minDistanceMeters;
+ }
-// public static float getMinAccuracyMeters() {
-// return minAccuracyMeters;
-// }
-//
-// public static void setMinAccuracyMeters(float minAccuracyMeters) {
-// GPSLoggerService.minAccuracyMeters = minAccuracyMeters;
-// }
+ public static float getMinAccuracyMeters() {
+ return minAccuracyMeters;
+ }
+
+ public static void setMinAccuracyMeters(float minAccuracyMeters) {
+ GPSLoggerService.minAccuracyMeters = minAccuracyMeters;
+ }
public static void setShowingDebugToast(boolean showingDebugToast) {
GPSLoggerService.showingDebugToast = showingDebugToast;
Powered by
Google Project Hosting