Skip to content

Commit

Permalink
add isSsidFamiliar method
Browse files Browse the repository at this point in the history
  • Loading branch information
ihrthk committed Dec 29, 2014
1 parent 294dffe commit cf17c84
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/com/android/utils/wificonnecter/WiFiConnecter.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class WiFiConnecter {

private boolean isRegistered;
private boolean isActiveScan;
private boolean bySsidIgnoreCase;
private boolean ssidIgnoreCase;

public WiFiConnecter(Context context) {
this.mContext = context;
Expand All @@ -61,7 +61,7 @@ public void onReceive(Context context, Intent intent) {

context.registerReceiver(mReceiver, mFilter);
isRegistered = true;
bySsidIgnoreCase = true;
ssidIgnoreCase = true;
mScanner = new Scanner();
}

Expand All @@ -83,10 +83,7 @@ public void connect(String ssid, String password, ActionListener listener) {
}

WifiInfo info = mWifiManager.getConnectionInfo();
String quotedString = StringUtils.convertToQuotedString(mSsid);
boolean ssidEquals = bySsidIgnoreCase ? quotedString.equalsIgnoreCase(info.getSSID())
: quotedString.equals(info.getSSID());
if (ssidEquals) {
if (isSsidFamiliar(mSsid, info.getSSID())) {
if (listener != null) {
listener.onSuccess(info);
listener.onFinished(true);
Expand All @@ -104,10 +101,7 @@ private void handleEvent(Context context, Intent intent) {
List<ScanResult> results = mWifiManager.getScanResults();
for (ScanResult result : results) {
//1.scan dest of ssid
String quotedString = StringUtils.convertToQuotedString(mSsid);
boolean ssidEquals = bySsidIgnoreCase ? quotedString.equalsIgnoreCase(result.SSID)
: quotedString.equals(result.SSID);
if (ssidEquals) {
if (isSsidFamiliar(mSsid, result.SSID)) {
//TODO ?
mScanner.pause();
//2.input error password
Expand All @@ -128,10 +122,7 @@ private void handleEvent(Context context, Intent intent) {
WifiInfo mWifiInfo = mWifiManager.getConnectionInfo();
//ssid equals&&connected
if (mWifiInfo != null && mInfo.isConnected() && mWifiInfo.getSSID() != null) {
String quotedString = StringUtils.convertToQuotedString(mSsid);
boolean ssidEquals = bySsidIgnoreCase ? quotedString.equalsIgnoreCase(mWifiInfo.getSSID())
: quotedString.equals(mWifiInfo.getSSID());
if (ssidEquals) {
if (isSsidFamiliar(mSsid, mWifiInfo.getSSID())) {
if (mListener != null) {
mListener.onSuccess(mWifiInfo);
mListener.onFinished(true);
Expand All @@ -143,6 +134,12 @@ private void handleEvent(Context context, Intent intent) {
}
}

private boolean isSsidFamiliar(String ssid, String other) {
String quotedString = StringUtils.convertToQuotedString(ssid);
return ssidIgnoreCase ? quotedString.equalsIgnoreCase(other)
: quotedString.equals(other);
}

public void onPause() {
if (isRegistered) {
mContext.unregisterReceiver(mReceiver);
Expand Down

0 comments on commit cf17c84

Please sign in to comment.