Skip to content

Commit

Permalink
More tests and updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
isuPatches committed Jul 17, 2017
1 parent 07ccac7 commit d981721
Show file tree
Hide file tree
Showing 94 changed files with 5,457 additions and 1,372 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ For the sake of transparency and because you're probably curious as to what perm

<strong> * NOTE * </strong>

If a search for an SSID is failing (returning false or NULL depending on the method) on >= 6.x devices but the network is visible, it's most likely because you haven't asked in your application for the `Manifest.permission.ACCESS_COARSE_LOCATION` permission which is what allows us to see the access points nearby. It has been up for debate on if it would be beneficial to move permission requests to the WiseFy library, but at this time, it remains as-is so users can determine their own UI/UX and to not add additional package bloat.
If access points or SSIDs are not being returned on >= 6.x devices but there are visible networks, it's most likely because you haven't asked in your application for the `Manifest.permission.ACCESS_COARSE_LOCATION` permission which is what allows us to see the access points nearby. This permission request will not be added to the WiseFy library to reduce package bloat and so users can determine their own UI/UX.

Please check [the documentation markdown directory](/documentation/permissions_example.md) for an example of requesting permissions for WiseFy.

## Usage

Expand Down
162 changes: 162 additions & 0 deletions documentation/permissions_example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
The `ACCESS_COARSE_LOCATION` location permission is necessary to query for nearby access points.

First we define the permissions in the manifest:

```xml
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
```

Then on the activity using WiseFy then we can start asking for permissions and handling the permission callbacks.

```java
package wisefy_sample.isupatches.com.wisefysample.ui;


import android.content.pm.PackageManager;
import android.net.wifi.ScanResult;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.isupatches.wisefy.WiseFy;
import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks;
import java.util.List;
import wisefy_sample.isupatches.com.wisefysample.R;
import wisefy_sample.isupatches.com.wisefysample.constants.Permissions;
import wisefy_sample.isupatches.com.wisefysample.util.PermissionUtil;
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;


public class MainActivity extends AppCompatActivity {

private static final String TAG = MainActivity.class.getSimpleName();

private WiseFy mWiseFy;

private PermissionUtil mPermissionUtil = PermissionUtil.getInstance();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (checkForPermissions()) {
getNearbyAccessPoints();
}
}

@Override
protected void onDestroy() {
super.onDestroy();
mWiseFy.dump();
}

private boolean checkForPermissions() {
return isPermissionGranted(ACCESS_COARSE_LOCATION, R.string.access_course_location_permission_rationale, Permissions.ACCESS_COARSE_LOCATION_RESULT_CODE);
}

public boolean isPermissionGranted(String permission, int rationaleResId, int requestCode) {
if (mPermissionUtil.permissionNotGranted(this, permission)) {
if (mPermissionUtil.shouldShowPermissionRationale(this, permission)) {
// Display dialog or rationale for requesting permission here
} else {
mPermissionUtil.requestPermissions(this, new String[]{permission}, requestCode);
}
return false;
} else {
return true;
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case Permissions.ACCESS_COARSE_LOCATION_RESULT_CODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Access course location permission granted");
// Continue WiseFy logic here
} else {
Log.e(TAG, "Access course location permission denied");
// Display permission error here
}
break;
default:
Log.wtf(TAG, "Weird permission requested, not handled");
// Display permission error here
break;
}
}

private void getNearbyAccessPoints() {
mWiseFy = new WiseFy.brains(this).logging(true).getSmarts();

mWiseFy.getNearbyAccessPoints(true, new GetNearbyAccessPointsCallbacks() {
@Override
public void getNearbyAccessPointsWiseFyFailure(Integer integer) {

}

@Override
public void retrievedNearbyAccessPoints(List<ScanResult> list) {
// You should see this populate with results after approving the
// the ACCESS_COARSE_LOCATION permission
Log.d(TAG, "List: " + list.toString());
}
});
}
}
```

In this example, PermissionUtil is just an abstracted, shared piece of logic:

```java
package wisefy_sample.isupatches.com.wisefysample.util;


import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;


public class PermissionUtil {

private static final PermissionUtil PERMISSION_UTIL = new PermissionUtil();

private PermissionUtil() {

}

public static PermissionUtil getInstance() {
return PERMISSION_UTIL;
}

public boolean permissionNotGranted(Activity activity, String permission) {
return ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED;
}

public boolean shouldShowPermissionRationale(Activity activity, String permission) {
return ActivityCompat.shouldShowRequestPermissionRationale(activity, permission);
}

public void requestPermissions(Activity activity, String[] permissions, int requestCode) {
ActivityCompat.requestPermissions(activity, permissions, requestCode);
}
}
```

And there is a class for storing constants for permission checks:

```java
package wisefy_sample.isupatches.com.wisefysample.constants;


public class Permissions {
public static final int ACCESS_COARSE_LOCATION_RESULT_CODE = 1;
}
```
11 changes: 8 additions & 3 deletions javadoc/allclasses-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_102) on Tue Jul 11 08:22:40 CDT 2017 -->
<!-- Generated by javadoc (1.8.0_102) on Sun Jul 16 20:08:41 CDT 2017 -->
<title>All Classes (wisefy 2.0.0-BETA API)</title>
<meta name="date" content="2017-07-11">
<meta name="date" content="2017-07-16">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand All @@ -25,19 +25,24 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="com/isupatches/wisefy/callbacks/GetCurrentNetworkCallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">GetCurrentNetworkCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/GetFrequencyCallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">GetFrequencyCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/GetNearbyAccessPointsCallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">GetNearbyAccessPointsCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/GetRSSICallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">GetRSSICallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/GetSavedNetworkCallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">GetSavedNetworkCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/GetSavedNetworksCallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">GetSavedNetworksCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/util/LogUtil.html" title="class in com.isupatches.wisefy.util" target="classFrame">LogUtil</a></li>
<li><a href="com/isupatches/wisefy/util/ManagerUtil.html" title="class in com.isupatches.wisefy.util" target="classFrame">ManagerUtil</a></li>
<li><a href="com/isupatches/wisefy/constants/NetworkTypes.html" title="class in com.isupatches.wisefy.constants" target="classFrame">NetworkTypes</a></li>
<li><a href="com/isupatches/wisefy/callbacks/RemoveNetworkCallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">RemoveNetworkCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/SearchForAccessPointCallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">SearchForAccessPointCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/SearchForAccessPointsCallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">SearchForAccessPointsCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/SearchForSSIDCallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">SearchForSSIDCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/SearchForSSIDsCallbacks.html" title="interface in com.isupatches.wisefy.callbacks" target="classFrame"><span class="interfaceName">SearchForSSIDsCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/util/SleepUtil.html" title="class in com.isupatches.wisefy.util" target="classFrame">SleepUtil</a></li>
<li><a href="com/isupatches/wisefy/util/SSIDUtil.html" title="class in com.isupatches.wisefy.util" target="classFrame">SSIDUtil</a></li>
<li><a href="com/isupatches/wisefy/annotations/Sync.html" title="annotation in com.isupatches.wisefy.annotations" target="classFrame">Sync</a></li>
<li><a href="com/isupatches/wisefy/annotations/WaitsForTimeout.html" title="annotation in com.isupatches.wisefy.annotations" target="classFrame">WaitsForTimeout</a></li>
<li><a href="com/isupatches/wisefy/util/WifiConfigurationUtil.html" title="class in com.isupatches.wisefy.util" target="classFrame">WifiConfigurationUtil</a></li>
<li><a href="com/isupatches/wisefy/WiseFy.html" title="class in com.isupatches.wisefy" target="classFrame">WiseFy</a></li>
<li><a href="com/isupatches/wisefy/WiseFy.withContext.html" title="class in com.isupatches.wisefy" target="classFrame">WiseFy.withContext</a></li>
<li><a href="com/isupatches/wisefy/WiseFy.brains.html" title="class in com.isupatches.wisefy" target="classFrame">WiseFy.brains</a></li>
<li><a href="com/isupatches/wisefy/constants/WiseFyCodes.html" title="class in com.isupatches.wisefy.constants" target="classFrame">WiseFyCodes</a></li>
<li><a href="com/isupatches/wisefy/threads/WiseFyHandlerThread.html" title="class in com.isupatches.wisefy.threads" target="classFrame">WiseFyHandlerThread</a></li>
<li><a href="com/isupatches/wisefy/annotations/WiseFyThread.html" title="annotation in com.isupatches.wisefy.annotations" target="classFrame">WiseFyThread</a></li>
Expand Down
11 changes: 8 additions & 3 deletions javadoc/allclasses-noframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_102) on Tue Jul 11 08:22:40 CDT 2017 -->
<!-- Generated by javadoc (1.8.0_102) on Sun Jul 16 20:08:41 CDT 2017 -->
<title>All Classes (wisefy 2.0.0-BETA API)</title>
<meta name="date" content="2017-07-11">
<meta name="date" content="2017-07-16">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand All @@ -25,19 +25,24 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="com/isupatches/wisefy/callbacks/GetCurrentNetworkCallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">GetCurrentNetworkCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/GetFrequencyCallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">GetFrequencyCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/GetNearbyAccessPointsCallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">GetNearbyAccessPointsCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/GetRSSICallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">GetRSSICallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/GetSavedNetworkCallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">GetSavedNetworkCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/GetSavedNetworksCallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">GetSavedNetworksCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/util/LogUtil.html" title="class in com.isupatches.wisefy.util">LogUtil</a></li>
<li><a href="com/isupatches/wisefy/util/ManagerUtil.html" title="class in com.isupatches.wisefy.util">ManagerUtil</a></li>
<li><a href="com/isupatches/wisefy/constants/NetworkTypes.html" title="class in com.isupatches.wisefy.constants">NetworkTypes</a></li>
<li><a href="com/isupatches/wisefy/callbacks/RemoveNetworkCallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">RemoveNetworkCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/SearchForAccessPointCallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">SearchForAccessPointCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/SearchForAccessPointsCallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">SearchForAccessPointsCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/SearchForSSIDCallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">SearchForSSIDCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/callbacks/SearchForSSIDsCallbacks.html" title="interface in com.isupatches.wisefy.callbacks"><span class="interfaceName">SearchForSSIDsCallbacks</span></a></li>
<li><a href="com/isupatches/wisefy/util/SleepUtil.html" title="class in com.isupatches.wisefy.util">SleepUtil</a></li>
<li><a href="com/isupatches/wisefy/util/SSIDUtil.html" title="class in com.isupatches.wisefy.util">SSIDUtil</a></li>
<li><a href="com/isupatches/wisefy/annotations/Sync.html" title="annotation in com.isupatches.wisefy.annotations">Sync</a></li>
<li><a href="com/isupatches/wisefy/annotations/WaitsForTimeout.html" title="annotation in com.isupatches.wisefy.annotations">WaitsForTimeout</a></li>
<li><a href="com/isupatches/wisefy/util/WifiConfigurationUtil.html" title="class in com.isupatches.wisefy.util">WifiConfigurationUtil</a></li>
<li><a href="com/isupatches/wisefy/WiseFy.html" title="class in com.isupatches.wisefy">WiseFy</a></li>
<li><a href="com/isupatches/wisefy/WiseFy.withContext.html" title="class in com.isupatches.wisefy">WiseFy.withContext</a></li>
<li><a href="com/isupatches/wisefy/WiseFy.brains.html" title="class in com.isupatches.wisefy">WiseFy.brains</a></li>
<li><a href="com/isupatches/wisefy/constants/WiseFyCodes.html" title="class in com.isupatches.wisefy.constants">WiseFyCodes</a></li>
<li><a href="com/isupatches/wisefy/threads/WiseFyHandlerThread.html" title="class in com.isupatches.wisefy.threads">WiseFyHandlerThread</a></li>
<li><a href="com/isupatches/wisefy/annotations/WiseFyThread.html" title="annotation in com.isupatches.wisefy.annotations">WiseFyThread</a></li>
Expand Down
Loading

0 comments on commit d981721

Please sign in to comment.