GeoLocationService.java
20.3 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
package com.arellomobile.android.push;
import android.annotation.TargetApi;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.media.ToneGenerator;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.telephony.CellLocation;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
import com.arellomobile.android.push.data.PushZoneLocation;
import com.arellomobile.android.push.utils.WorkerTask;
import java.util.Iterator;
import java.util.List;
@TargetApi(9)
public class GeoLocationService
extends Service
implements LocationListener
{
public static final String ARG_DESIRED_ACCURACY = "desiredAccuracy";
public static final String ARG_DISTANCE_FILTER = "distanceFilter";
public static final String ARG_LOCATION_TIMEOUT = "locationTimeout";
public static final String ARG_STATIONARY_RADIUS = "stationaryRadius";
private static final Integer a = Integer.valueOf(5);
private static final Integer b = Integer.valueOf(3);
public static TelephonyManager telephonyManager = null;
private BroadcastReceiver A = new BroadcastReceiver()
{
public final void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
{
Log.i("LocationUpdateService", "- stationaryAlarm fired");
GeoLocationService.a(GeoLocationService.this, Boolean.valueOf(false));
}
};
private BroadcastReceiver B = new BroadcastReceiver()
{
public final void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
{
Log.i("LocationUpdateService", "- stationaryLocationMonitorReceiver fired");
if (GeoLocationService.a(GeoLocationService.this).booleanValue()) {
GeoLocationService.a(GeoLocationService.this, "dialtone");
}
GeoLocationService.b(GeoLocationService.this).setAccuracy(1);
GeoLocationService.b(GeoLocationService.this).setHorizontalAccuracy(3);
GeoLocationService.b(GeoLocationService.this).setPowerRequirement(3);
GeoLocationService.d(GeoLocationService.this).requestSingleUpdate(GeoLocationService.b(GeoLocationService.this), GeoLocationService.c(GeoLocationService.this));
}
};
private BroadcastReceiver C = new BroadcastReceiver()
{
public final void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
{
Log.i("LocationUpdateService", "stationaryRegionReceiver");
if (Boolean.valueOf(paramAnonymousIntent.getBooleanExtra("entering", false)).booleanValue()) {
if (GeoLocationService.e(GeoLocationService.this).booleanValue()) {
GeoLocationService.a(GeoLocationService.this, Boolean.valueOf(false));
}
}
do
{
return;
paramAnonymousContext = GeoLocationService.this.getLastBestLocation();
} while (paramAnonymousContext == null);
GeoLocationService.this.onExitStationaryRegion(paramAnonymousContext);
}
};
private PhoneStateListener D = new PhoneStateListener()
{
public final void onCellLocationChanged(CellLocation paramAnonymousCellLocation)
{
GeoLocationService.this.onCellLocationChange(paramAnonymousCellLocation);
}
};
private PowerManager.WakeLock c;
private Location d;
private float e;
private Location f;
private PendingIntent g;
private PendingIntent h;
private long i;
private PendingIntent j;
private PendingIntent k;
private Boolean l = Boolean.valueOf(false);
private Boolean m = Boolean.valueOf(false);
private Boolean n = Boolean.valueOf(false);
private Integer o = Integer.valueOf(0);
private Integer p = Integer.valueOf(100);
private Integer q = Integer.valueOf(30);
private Integer r;
private Integer s = Integer.valueOf(30);
private Boolean t;
private ToneGenerator u;
private Criteria v;
private LocationManager w;
private AlarmManager x;
private ConnectivityManager y;
private BroadcastReceiver z = new BroadcastReceiver()
{
public final void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
{
paramAnonymousContext = (Location)paramAnonymousIntent.getExtras().get("location");
if (paramAnonymousContext != null)
{
new StringBuilder("- singleUpdateReciever").append(paramAnonymousContext.toString());
GeoLocationService.this.onPollStationaryLocation(paramAnonymousContext);
}
}
};
private Integer a(Float paramFloat)
{
Double localDouble = Double.valueOf(this.q.intValue());
if (paramFloat.floatValue() < 100.0F) {
localDouble = Double.valueOf(Math.pow(Math.round(paramFloat.floatValue() / 5.0F) * 5, 2.0D) + this.q.intValue());
}
if (localDouble.intValue() < 1000) {}
for (int i1 = localDouble.intValue();; i1 = 1000) {
return Integer.valueOf(i1);
}
}
private void a()
{
this.w.removeUpdates(this);
this.x.cancel(this.g);
this.x.cancel(this.h);
this.u.release();
unregisterReceiver(this.A);
unregisterReceiver(this.z);
unregisterReceiver(this.C);
unregisterReceiver(this.B);
if ((this.f != null) && (!this.l.booleanValue())) {}
try
{
this.w.removeProximityAlert(this.j);
this.c.release();
return;
}
catch (Throwable localThrowable)
{
for (;;)
{
Log.w("LocationUpdateService", "- Something bad happened while removing proximity-alert");
}
}
}
private void a(Boolean paramBoolean)
{
Log.i("LocationUpdateService", "setPace: " + paramBoolean);
Object localObject = this.l;
this.l = paramBoolean;
this.m = Boolean.valueOf(false);
this.n = Boolean.valueOf(false);
this.f = null;
this.w.removeUpdates(this);
this.v.setAccuracy(1);
Criteria localCriteria = this.v;
switch (this.p.intValue())
{
default:
paramBoolean = Integer.valueOf(2);
localCriteria.setHorizontalAccuracy(paramBoolean.intValue());
this.v.setPowerRequirement(3);
if (this.l.booleanValue()) {
if (!((Boolean)localObject).booleanValue()) {
this.n = Boolean.valueOf(true);
}
}
break;
}
for (;;)
{
if ((!this.n.booleanValue()) && (!this.m.booleanValue())) {
break label294;
}
this.o = Integer.valueOf(0);
paramBoolean = this.w.getAllProviders().iterator();
while (paramBoolean.hasNext())
{
localObject = (String)paramBoolean.next();
if (localObject != "passive") {
this.w.requestLocationUpdates((String)localObject, 0L, 0.0F, this);
}
}
paramBoolean = Integer.valueOf(1);
break;
paramBoolean = Integer.valueOf(2);
break;
paramBoolean = Integer.valueOf(3);
break;
paramBoolean = Integer.valueOf(3);
break;
this.m = Boolean.valueOf(true);
}
label294:
this.w.requestLocationUpdates(this.w.getBestProvider(this.v, true), this.s.intValue() * 1000, this.r.intValue(), this);
}
private void a(String paramString)
{
int i1 = 0;
if (paramString.equals("beep")) {
i1 = 24;
}
for (;;)
{
this.u.startTone(i1, 1000);
return;
if (paramString.equals("beep_beep_beep")) {
i1 = 41;
} else if (paramString.equals("long_beep")) {
i1 = 97;
} else if (paramString.equals("doodly_doo")) {
i1 = 86;
} else if (paramString.equals("chirp_chirp_chirp")) {
i1 = 93;
} else if (paramString.equals("dialtone")) {
i1 = 23;
}
}
}
public Location getLastBestLocation()
{
int i1 = (int)this.e;
long l1 = System.currentTimeMillis() - this.s.intValue() * 1000;
Log.i("LocationUpdateService", "- fetching last best location " + i1 + "," + l1);
Object localObject1 = null;
float f1 = Float.MAX_VALUE;
Iterator localIterator = this.w.getAllProviders().iterator();
boolean bool;
if (localIterator.hasNext())
{
Object localObject2 = (String)localIterator.next();
localObject2 = this.w.getLastKnownLocation((String)localObject2);
if (localObject2 == null) {
break label290;
}
new StringBuilder(" location: ").append(((Location)localObject2).getLatitude()).append(",").append(((Location)localObject2).getLongitude()).append(",").append(((Location)localObject2).getAccuracy()).append(",").append(((Location)localObject2).getSpeed()).append("m/s");
float f2 = ((Location)localObject2).getAccuracy();
long l2 = ((Location)localObject2).getTime();
StringBuilder localStringBuilder = new StringBuilder("time>minTime: ");
if (l2 > l1)
{
bool = true;
label220:
localStringBuilder = localStringBuilder.append(bool).append(", accuracy<bestAccuracy: ");
if (f2 >= f1) {
break label281;
}
bool = true;
label244:
localStringBuilder.append(bool);
if ((l2 <= l1) || (f2 >= f1)) {
break label290;
}
localObject1 = localObject2;
f1 = f2;
}
}
label281:
label290:
for (;;)
{
break;
bool = false;
break label220;
bool = false;
break label244;
return (Location)localObject1;
}
}
public IBinder onBind(Intent paramIntent)
{
Log.i("LocationUpdateService", "OnBind" + paramIntent);
return null;
}
public void onCellLocationChange(CellLocation paramCellLocation)
{
Log.i("LocationUpdateService", "- onCellLocationChange" + paramCellLocation.toString());
if (this.t.booleanValue())
{
Toast.makeText(this, "Cellular location change", 1).show();
a("chirp_chirp_chirp");
}
if ((!this.l.booleanValue()) && (this.f != null))
{
this.v.setAccuracy(1);
this.v.setHorizontalAccuracy(3);
this.v.setPowerRequirement(3);
this.w.requestSingleUpdate(this.v, this.k);
}
}
public void onCreate()
{
super.onCreate();
Log.i("LocationUpdateService", "OnCreate");
this.w = ((LocationManager)getSystemService("location"));
this.x = ((AlarmManager)getSystemService("alarm"));
this.u = new ToneGenerator(5, 100);
this.y = ((ConnectivityManager)getSystemService("connectivity"));
telephonyManager = (TelephonyManager)getSystemService("phone");
this.g = PendingIntent.getBroadcast(this, 0, new Intent("com.tenforwardconsulting.cordova.bgloc.STATIONARY_ALARM_ACTION"), 0);
registerReceiver(this.A, new IntentFilter("com.tenforwardconsulting.cordova.bgloc.STATIONARY_ALARM_ACTION"));
this.j = PendingIntent.getBroadcast(this, 0, new Intent("com.tenforwardconsulting.cordova.bgloc.STATIONARY_REGION_ACTION"), 268435456);
registerReceiver(this.C, new IntentFilter("com.tenforwardconsulting.cordova.bgloc.STATIONARY_REGION_ACTION"));
this.h = PendingIntent.getBroadcast(this, 0, new Intent("com.tenforwardconsulting.cordova.bgloc.STATIONARY_LOCATION_MONITOR_ACTION"), 0);
registerReceiver(this.B, new IntentFilter("com.tenforwardconsulting.cordova.bgloc.STATIONARY_LOCATION_MONITOR_ACTION"));
this.k = PendingIntent.getBroadcast(this, 0, new Intent("com.tenforwardconsulting.cordova.bgloc.SINGLE_LOCATION_UPDATE_ACTION"), 268435456);
registerReceiver(this.z, new IntentFilter("com.tenforwardconsulting.cordova.bgloc.SINGLE_LOCATION_UPDATE_ACTION"));
this.c = ((PowerManager)getSystemService("power")).newWakeLock(1, "LocationUpdateService");
this.c.acquire();
this.v = new Criteria();
this.v.setAltitudeRequired(false);
this.v.setBearingRequired(false);
this.v.setSpeedRequired(true);
this.v.setCostAllowed(true);
}
public void onDestroy()
{
Log.w("LocationUpdateService", "------------------------------------------ Destroyed Location update Service");
a();
super.onDestroy();
}
public void onExitStationaryRegion(Location paramLocation)
{
if (this.t.booleanValue()) {
a("beep_beep_beep");
}
this.x.cancel(this.h);
this.w.removeProximityAlert(this.j);
a(Boolean.valueOf(true));
}
public void onLocationChanged(Location paramLocation)
{
new StringBuilder("- onLocationChanged: ").append(paramLocation.getLatitude()).append(",").append(paramLocation.getLongitude()).append(", accuracy: ").append(paramLocation.getAccuracy()).append(", isMoving: ").append(this.l).append(", speed: ").append(paramLocation.getSpeed());
if ((!this.l.booleanValue()) && (!this.m.booleanValue()) && (this.f == null)) {
a(Boolean.valueOf(false));
}
if (this.t.booleanValue()) {
Toast.makeText(this, "mv:" + this.l + ",acy:" + paramLocation.getAccuracy() + ",v:" + paramLocation.getSpeed() + ",df:" + this.r, 1).show();
}
Object localObject;
float f1;
label409:
boolean bool;
if (this.m.booleanValue())
{
if ((this.f == null) || (this.f.getAccuracy() > paramLocation.getAccuracy())) {
this.f = paramLocation;
}
localObject = Integer.valueOf(this.o.intValue() + 1);
this.o = ((Integer)localObject);
if (localObject == a)
{
this.m = Boolean.valueOf(false);
localObject = this.f;
this.w.removeUpdates(this);
this.f = ((Location)localObject);
Log.i("LocationUpdateService", "- startMonitoringStationaryRegion (" + ((Location)localObject).getLatitude() + "," + ((Location)localObject).getLongitude() + "), accuracy:" + ((Location)localObject).getAccuracy());
LocationManager localLocationManager = this.w;
double d1 = ((Location)localObject).getLatitude();
double d2 = ((Location)localObject).getLongitude();
if (((Location)localObject).getAccuracy() < this.e)
{
f1 = this.e;
localLocationManager.addProximityAlert(d1, d2, f1, -1L, this.j);
startPollingStationaryLocation(180000L);
if (this.t.booleanValue()) {
a("long_beep");
}
this.d = paramLocation;
localObject = this.y.getActiveNetworkInfo();
if (localObject == null) {
break label822;
}
new StringBuilder("Network found, type = ").append(((NetworkInfo)localObject).getTypeName());
bool = ((NetworkInfo)localObject).isConnected();
label454:
if (bool)
{
paramLocation = new a(this, paramLocation);
new StringBuilder("beforeexecute ").append(paramLocation.getStatus());
if (Build.VERSION.SDK_INT < 11) {
break label828;
}
paramLocation.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
}
}
}
}
for (;;)
{
new StringBuilder("afterexecute ").append(paramLocation.getStatus());
do
{
do
{
return;
f1 = ((Location)localObject).getAccuracy();
break;
} while (!this.t.booleanValue());
a("beep");
return;
if (!this.n.booleanValue()) {
break label662;
}
localObject = Integer.valueOf(this.o.intValue() + 1);
this.o = ((Integer)localObject);
if (localObject == b)
{
if (this.t.booleanValue()) {
a("doodly_doo");
}
this.n = Boolean.valueOf(false);
this.r = a(Float.valueOf(paramLocation.getSpeed()));
a(Boolean.valueOf(true));
break label409;
}
} while (!this.t.booleanValue());
a("beep");
return;
label662:
if (this.l.booleanValue())
{
if (this.t.booleanValue()) {
a("beep");
}
if ((paramLocation.getSpeed() >= 1.0F) && (paramLocation.getAccuracy() <= this.e)) {
resetStationaryAlarm();
}
localObject = a(Float.valueOf(paramLocation.getSpeed()));
if (((Integer)localObject).intValue() != this.r.intValue())
{
Log.i("LocationUpdateService", "- updated distanceFilter, new: " + localObject + ", old: " + this.r);
this.r = ((Integer)localObject);
a(Boolean.valueOf(true));
}
if (paramLocation.distanceTo(this.d) >= this.q.intValue()) {
break label409;
}
return;
}
if (this.f == null) {
break label409;
}
return;
label822:
bool = false;
break label454;
label828:
paramLocation.execute(new Void[0]);
}
}
public void onPollStationaryLocation(Location paramLocation)
{
if (this.l.booleanValue()) {}
do
{
return;
if (this.t.booleanValue()) {
a("beep");
}
float f1 = Math.abs(paramLocation.distanceTo(this.f) - this.f.getAccuracy() - paramLocation.getAccuracy());
if (this.t.booleanValue()) {
Toast.makeText(this, "Stationary exit in " + (this.e - f1) + "m", 1).show();
}
Log.i("LocationUpdateService", "- distance from stationary location: " + f1);
if (f1 > this.e)
{
onExitStationaryRegion(paramLocation);
return;
}
if (f1 > 0.0F)
{
startPollingStationaryLocation(60000L);
return;
}
} while (this.i == 180000L);
startPollingStationaryLocation(180000L);
}
public void onProviderDisabled(String paramString) {}
public void onProviderEnabled(String paramString) {}
public int onStartCommand(Intent paramIntent, int paramInt1, int paramInt2)
{
Log.i("LocationUpdateService", "Received start id " + paramInt2 + ": " + paramIntent);
if (paramIntent != null)
{
this.e = paramIntent.getFloatExtra("stationaryRadius", 20.0F);
this.p = Integer.valueOf(paramIntent.getIntExtra("desiredAccuracy", 10));
this.s = Integer.valueOf(paramIntent.getIntExtra("locationTimeout", 30));
this.q = Integer.valueOf(paramIntent.getIntExtra("distanceFilter", 30));
this.r = this.q;
this.t = Boolean.valueOf(paramIntent.getBooleanExtra("isDebugging", false));
}
Log.i("LocationUpdateService", "- stationaryRadius: " + this.e);
Log.i("LocationUpdateService", "- distanceFilter: " + this.q);
Log.i("LocationUpdateService", "- desiredAccuracy: " + this.p);
Log.i("LocationUpdateService", "- locationTimeout: " + this.s);
Log.i("LocationUpdateService", "- isDebugging: " + this.t);
a(Boolean.valueOf(false));
return 1;
}
public void onStatusChanged(String paramString, int paramInt, Bundle paramBundle)
{
new StringBuilder("- onStatusChanged: ").append(paramString).append(", status: ").append(paramInt);
}
@TargetApi(14)
public void onTaskRemoved(Intent paramIntent)
{
stopSelf();
super.onTaskRemoved(paramIntent);
}
public void resetStationaryAlarm()
{
this.x.cancel(this.g);
this.x.set(0, System.currentTimeMillis() + 300000L, this.g);
}
public void startPollingStationaryLocation(long paramLong)
{
this.i = paramLong;
this.x.cancel(this.h);
long l1 = System.currentTimeMillis();
this.x.setInexactRepeating(0, 60000L + l1, paramLong, this.h);
}
public boolean stopService(Intent paramIntent)
{
Log.i("LocationUpdateService", "- Received stop: " + paramIntent);
a();
if (this.t.booleanValue()) {
Toast.makeText(this, "Background location tracking stopped", 0).show();
}
return super.stopService(paramIntent);
}
final class a
extends WorkerTask
{
protected Location a;
protected PushZoneLocation b;
protected a(GeoLocationService paramGeoLocationService, Location paramLocation)
{
super();
this.a = paramLocation;
}
protected final void doWork(Context paramContext)
throws Exception
{
this.b = DeviceFeature2_5.getNearestZone(paramContext, this.a);
if (this.b != null)
{
long l = this.b.getDistanceTo();
GeoLocationService.a((GeoLocationService)paramContext, Integer.valueOf((int)(l / 2L)));
}
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/arellomobile/android/push/GeoLocationService.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/