Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Javier Baliosian
pringlesart
Commits
84a66981
Commit
84a66981
authored
Mar 22, 2015
by
Javier Baliosian
Browse files
primer commit
parent
6f50941b
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/elbitsalvaje/javier/wifidump/wifidumper.java
View file @
84a66981
...
...
@@ -20,6 +20,10 @@ import android.widget.ArrayAdapter;
import
android.widget.ListView
;
import
android.widget.Toast
;
import
android.os.Environment
;
import
android.hardware.Sensor
;
import
android.hardware.SensorEvent
;
import
android.hardware.SensorEventListener
;
import
android.hardware.SensorManager
;
public
class
wifidumper
extends
Activity
{
...
...
@@ -28,24 +32,47 @@ public class wifidumper extends Activity {
WifiScanReceiver
wifiReciever
;
ListView
list
;
String
wifis
[];
static
String
filename
=
"dump_wifis.txt"
;
OutputStreamWriter
myOutWriter
;
FileOutputStream
fOut
;
// String[] positions = new String[4];
static
String
filename_dump_wifis
=
"/sdcard/dump_wifis.txt"
;
OutputStreamWriter
myOutWifiDumpWriter
;
FileOutputStream
fileWifiDumpOut
;
static
String
filename_dump_position
=
"/sdcard/dump_position.txt"
;
OutputStreamWriter
myOutPositionWriter
;
FileOutputStream
filePositionOut
;
SensorManager
sensorManager
;
Sensor
sensorAccelerometer
;
SensorReceiver
positionReciver
;
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_wifidumper
);
list
=
(
ListView
)
findViewById
(
R
.
id
.
listView1
);
mainWifiObj
=
(
WifiManager
)
getSystemService
(
Context
.
WIFI_SERVICE
);
wifiReciever
=
new
WifiScanReceiver
();
mainWifiObj
.
startScan
();
sensorManager
=
(
SensorManager
)
getSystemService
(
SENSOR_SERVICE
);
sensorAccelerometer
=
sensorManager
.
getDefaultSensor
(
Sensor
.
TYPE_GRAVITY
);
positionReciver
=
new
SensorReceiver
();
try
{
File
myFile
=
new
File
(
"sdcard"
+
"/"
+
filename
);
myFile
.
createNewFile
();
fOut
=
new
FileOutputStream
(
myFile
);
myOutWriter
=
new
OutputStreamWriter
(
fOut
);
// file for dumping wifi information
File
myFile_wifis
=
new
File
(
filename_dump_wifis
);
myFile_wifis
.
createNewFile
();
fileWifiDumpOut
=
new
FileOutputStream
(
myFile_wifis
);
myOutWifiDumpWriter
=
new
OutputStreamWriter
(
fileWifiDumpOut
);
// file for dumping azimuth, pitch and roll
File
myFile_position
=
new
File
(
filename_dump_position
);
myFile_position
.
createNewFile
();
filePositionOut
=
new
FileOutputStream
(
myFile_position
);
myOutPositionWriter
=
new
OutputStreamWriter
(
filePositionOut
);
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
...
...
@@ -56,10 +83,13 @@ public class wifidumper extends Activity {
protected
void
onPause
()
{
unregisterReceiver
(
wifiReciever
);
sensorManager
.
unregisterListener
(
positionReciver
);
try
{
myOutWriter
.
close
();
fOut
.
close
();
myOutWifiDumpWriter
.
close
();
fileWifiDumpOut
.
close
();
myOutPositionWriter
.
close
();
filePositionOut
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -68,8 +98,8 @@ public class wifidumper extends Activity {
}
protected
void
onResume
()
{
registerReceiver
(
wifiReciever
,
new
IntentFilter
(
WifiManager
.
SCAN_RESULTS_AVAILABLE_ACTION
)
);
registerReceiver
(
wifiReciever
,
new
IntentFilter
(
WifiManager
.
SCAN_RESULTS_AVAILABLE_ACTION
));
sensorManager
.
registerListener
(
positionReciver
,
sensorAccelerometer
,
SensorManager
.
SENSOR_DELAY_NORMAL
);
super
.
onResume
();
}
...
...
@@ -93,6 +123,7 @@ public class wifidumper extends Activity {
}
class
WifiScanReceiver
extends
BroadcastReceiver
{
@SuppressLint
(
"UseValueOf"
)
public
void
onReceive
(
Context
c
,
Intent
intent
)
{
List
<
ScanResult
>
wifiScanList
=
mainWifiObj
.
getScanResults
();
...
...
@@ -100,21 +131,62 @@ public class wifidumper extends Activity {
long
currentTime
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
wifiScanList
.
size
();
i
++){
wifis
[
i
]
=
currentTime
+
","
+
wifiScanList
.
get
(
i
).
BSSID
+
","
+
wifiScanList
.
get
(
i
).
level
;
// not using wifiScanList.timestamp because is not available in version 7
wifis
[
i
]
=
currentTime
+
","
+
wifiScanList
.
get
(
i
).
BSSID
+
","
+
wifiScanList
.
get
(
i
).
level
;
// dumps wifi info on file
try
{
myOutWriter
.
append
(
wifis
[
i
]);
myOutWriter
.
append
(
"\n"
);
myOutW
ifiDumpW
riter
.
append
(
wifis
[
i
]);
myOutW
ifiDumpW
riter
.
append
(
"\n"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
// shows wifi info at the screen
list
.
setAdapter
(
new
ArrayAdapter
<
String
>(
getApplicationContext
(),
android
.
R
.
layout
.
simple_list_item_1
,
wifis
));
mainWifiObj
.
startScan
();
}
}
class
SensorReceiver
implements
SensorEventListener
{
public
void
onSensorChanged
(
SensorEvent
event
)
{
/*
* event.values[1]: pitch, rotation around the X axis.
* event.values[0]: azimuth, rotation around the Z axis.
* event.values[2]: roll, rotation around the Y axis.
*/
float
valueAzimuth
=
event
.
values
[
0
];
float
valuePitch
=
event
.
values
[
1
];
float
valueRoll
=
event
.
values
[
2
];
try
{
myOutPositionWriter
.
append
(
event
.
timestamp
+
", "
+
valueAzimuth
+
", "
+
valuePitch
+
", "
+
valueRoll
);
myOutPositionWriter
.
append
(
"\n"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
Log
.
d
(
"wifidump"
,
"Az: "
+
valueAzimuth
);
// positions[0] = "Position:";
// positions[1] = String.valueOf(valueAzimuth);
// positions[2] = String.valueOf(valuePitch);
// positions[3] = String.valueOf(valueRoll);
//
// list.setAdapter(new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1, positions));
}
@Override
public
void
onAccuracyChanged
(
Sensor
sensor
,
int
accuracy
)
{
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment