Skip to content

Commit

Permalink
Fix reported strange crashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruiaraujo committed May 15, 2015
1 parent ac35020 commit 28c9eb3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
50 changes: 30 additions & 20 deletions android/src/org/exobel/routerkeygen/AutoConnectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,36 @@ public int onStartCommand(Intent intent, int flags, int startId) {
}

private void tryingConnection() {
currentNetworkId = Wifi.connectToNewNetwork(this, wifi, network,
keys.get(attempts++), mNumOpenNetworksKept);
Log.d(AutoConnectManager.class.getSimpleName(),
"Trying " + keys.get(attempts - 1));

if (currentNetworkId != -1) {
lastTimeDisconnected = System.currentTimeMillis();
if (attempts == 1)// first try, we register the listener
registerReceiver(mReceiver, new IntentFilter(
WifiManager.SUPPLICANT_STATE_CHANGED_ACTION));
mNotificationManager.notify(UNIQUE_ID, NotificationUtils
.createProgressBar(
this,
getString(R.string.app_name),
getString(R.string.not_auto_connect_key_testing,
keys.get(attempts - 1)), keys.size(),
attempts, false,
getDefaultPendingIntent(getApplicationContext())));
cancelNotification = true;
} else {
currentNetworkId = -1;
try {
currentNetworkId = Wifi.connectToNewNetwork(this, wifi, network,
keys.get(attempts++), mNumOpenNetworksKept);
Log.d(AutoConnectManager.class.getSimpleName(),
"Trying " + keys.get(attempts - 1));
if (currentNetworkId != -1) {
lastTimeDisconnected = System.currentTimeMillis();
if (attempts == 1)// first try, we register the listener
registerReceiver(mReceiver, new IntentFilter(
WifiManager.SUPPLICANT_STATE_CHANGED_ACTION));
mNotificationManager
.notify(UNIQUE_ID,
NotificationUtils
.createProgressBar(
this,
getString(R.string.app_name),
getString(
R.string.not_auto_connect_key_testing,
keys.get(attempts - 1)),
keys.size(),
attempts,
false,
getDefaultPendingIntent(getApplicationContext())));
cancelNotification = true;
}
} catch (Exception e) {
e.printStackTrace();
}
if (currentNetworkId == -1) {
mNotificationManager.notify(
UNIQUE_ID,
NotificationUtils.getSimple(this,
Expand Down
37 changes: 20 additions & 17 deletions android/src/org/exobel/routerkeygen/WifiScanReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,28 @@ public void onReceive(Context context, Intent intent) {
return;
if (wifi == null)
return;
final List<ScanResult> results = wifi.getScanResults();
/*
* He have had reports of this returning null instead of empty
*/
if (results == null)
return;

try {
// Single scan
context.unregisterReceiver(this);
} catch (Exception e) {
}
if (task == null || task.getStatus() == Status.FINISHED) {
task = new KeygenMatcherTask(results, context);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
task.execute();
} else {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
final List<ScanResult> results = wifi.getScanResults();
/*
* We have had reports of this returning null instead of empty
*/
if (results == null)
return;
try {
// Single scan
context.unregisterReceiver(this);
} catch (Exception e) {
}
if (task == null || task.getStatus() == Status.FINISHED) {
task = new KeygenMatcherTask(results, context);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
task.execute();
} else {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
} catch (SecurityException e) {
//Sometimes getScanResults triggers a SecurityException
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class WifiListAdapter extends BaseAdapter implements
private final Drawable[] wifiSignalLocked;
private Typeface typeface = null;

@SuppressWarnings("deprecation")
public WifiListAdapter(Context context) {
this.listNetworks = new ArrayList<WifiListAdapter.Item>();
try {
Expand Down

0 comments on commit 28c9eb3

Please sign in to comment.