Skip to content

Commit 7bcb5fe

Browse files
committed
Repaired the auto-signin feature for all 2.2 devices. The broadcast receiver now uses a Service to perform the actual authentication to prevent ANR errors.
1 parent 60f9dfc commit 7bcb5fe

File tree

2 files changed

+57
-40
lines changed

2 files changed

+57
-40
lines changed

AndroidManifest.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.craigsc.gthive"
4-
android:versionCode="2"
5-
android:versionName="1.1">
4+
android:versionCode="3"
5+
android:versionName="1.2">
66
<application
77
android:icon="@drawable/icon"
88
android:label="@string/app_name"
@@ -30,6 +30,7 @@
3030
<action android:name="android.net.wifi.STATE_CHANGE"></action>
3131
</intent-filter>
3232
</receiver>
33+
<service android:name=".GTHiveReceiver$LoginService" />
3334

3435
</application>
3536

src/com/craigsc/gthive/GTHiveReceiver.java

+54-38
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
import org.apache.http.impl.client.DefaultHttpClient;
1313
import org.apache.http.message.BasicNameValuePair;
1414

15+
import android.app.Service;
1516
import android.content.BroadcastReceiver;
1617
import android.content.Context;
1718
import android.content.Intent;
1819
import android.content.SharedPreferences;
1920
import android.net.NetworkInfo;
2021
import android.net.wifi.WifiInfo;
2122
import android.net.wifi.WifiManager;
23+
import android.os.IBinder;
2224
import android.util.Log;
2325
import android.widget.Toast;
2426

@@ -30,50 +32,64 @@ public void onReceive(Context context, Intent intent) {
3032
NetworkInfo ni = (NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
3133
WifiInfo wi = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo();
3234
if (ni.isConnected() && wi != null && wi.getSSID().equalsIgnoreCase(GTHive.SSID)) {
33-
SharedPreferences settings = context.getSharedPreferences(GTHive.PREFS_NAME, 0);
34-
String user = settings.getString("user", null);
35-
String pass = settings.getString("pass", null);
36-
if (user != null && pass != null) {
35+
context.startService(new Intent(context, LoginService.class));
36+
}
37+
}
38+
}
39+
40+
public static class LoginService extends Service {
41+
42+
@Override
43+
public void onStart(Intent intent, int startId) {
44+
Context context = this;
45+
46+
SharedPreferences settings = context.getSharedPreferences(GTHive.PREFS_NAME, 0);
47+
String user = settings.getString("user", null);
48+
String pass = settings.getString("pass", null);
49+
if (user != null && pass != null) {
3750

38-
HttpClient client = new DefaultHttpClient();
39-
HttpPost post = new HttpPost("https://auth.lawn.gatech.edu/index.php");
40-
try {
41-
//set up post parameters
42-
List<NameValuePair> data = new ArrayList<NameValuePair>(3);
43-
data.add(new BasicNameValuePair("username", user));
44-
data.add(new BasicNameValuePair("password", pass));
45-
data.add(new BasicNameValuePair("output", "text"));
46-
//check preferences for ISS status
47-
if (Prefs.getISS(context)) {
48-
Log.d("GTHive", "ISS ENABLED");
49-
data.add(new BasicNameValuePair("iss", "on"));
50-
}
51-
post.setEntity(new UrlEncodedFormEntity(data));
52-
53-
ResponseHandler<String> rh = new BasicResponseHandler();
54-
String result = client.execute(post,rh);
51+
HttpClient client = new DefaultHttpClient();
52+
HttpPost post = new HttpPost("https://auth.lawn.gatech.edu/index.php");
53+
try {
54+
//set up post parameters
55+
List<NameValuePair> data = new ArrayList<NameValuePair>(3);
56+
data.add(new BasicNameValuePair("username", user));
57+
data.add(new BasicNameValuePair("password", pass));
58+
data.add(new BasicNameValuePair("output", "text"));
59+
//check preferences for ISS status
60+
if (Prefs.getISS(context)) {
61+
Log.d("GTHive", "ISS ENABLED");
62+
data.add(new BasicNameValuePair("iss", "on"));
63+
}
64+
post.setEntity(new UrlEncodedFormEntity(data));
5565

56-
//check text response and alert user of success/failure
57-
if (result.equals("Logging you into LAWN...")) {
58-
result = "Successfully logged into LAWN";
59-
}
60-
else if (result.equals("")) {
61-
result = "Already logged into LAWN.";
62-
}
63-
display(context, result);
64-
} catch (Exception e) {
65-
display(context, "Error authenticating to LAWN. Try using GTHive.");
66-
Log.d("GTHive_BROADCAST_RECEIVER", e.toString());
66+
ResponseHandler<String> rh = new BasicResponseHandler();
67+
String result = client.execute(post,rh);
68+
//check text response and alert user of success/failure
69+
if (result.equals("Logging you into LAWN...")) {
70+
result = "Successfully logged into LAWN";
6771
}
68-
72+
else if (result.equals("")) {
73+
result = "Already logged into LAWN.";
74+
}
75+
display(context, result);
76+
} catch (Exception e) {
77+
display(context, "Error authenticating to LAWN. Try using GTHive.");
78+
Log.d("GTHive_BROADCAST_RECEIVER", e.toString());
6979
}
7080
}
7181
}
72-
}
73-
74-
private void display(Context c, String text) {
75-
if (Prefs.showAutoSigninMessages(c)) {
76-
Toast.makeText(c, text, Toast.LENGTH_LONG).show();
82+
83+
private void display(Context c, String text) {
84+
if (Prefs.showAutoSigninMessages(c)) {
85+
Toast.makeText(c, text, Toast.LENGTH_LONG).show();
86+
}
87+
}
88+
89+
@Override
90+
public IBinder onBind(Intent intent) {
91+
return null;
7792
}
93+
7894
}
7995
}

0 commit comments

Comments
 (0)