From d981721a100eae6ce37da1d0e05884f1157959cc Mon Sep 17 00:00:00 2001 From: isuPatches Date: Sun, 16 Jul 2017 20:09:36 -0500 Subject: [PATCH] More tests and updated documentation --- README.md | 4 +- documentation/permissions_example.md | 162 ++++ javadoc/allclasses-frame.html | 11 +- javadoc/allclasses-noframe.html | 11 +- .../com/isupatches/wisefy/WiseFy.brains.html | 320 ++++++++ javadoc/com/isupatches/wisefy/WiseFy.html | 698 ++++++++++------ .../isupatches/wisefy/WiseFyApplication.html | 350 ++++++++ .../isupatches/wisefy/annotations/Async.html | 4 +- .../wisefy/annotations/CallingThread.html | 4 +- .../isupatches/wisefy/annotations/Sync.html | 4 +- .../wisefy/annotations/WaitsForTimeout.html | 4 +- .../wisefy/annotations/WiseFyThread.html | 4 +- .../wisefy/annotations/package-frame.html | 4 +- .../wisefy/annotations/package-summary.html | 4 +- .../wisefy/annotations/package-tree.html | 8 +- .../callbacks/AddOpenNetworkCallbacks.html | 4 +- .../callbacks/AddWEPNetworkCallbacks.html | 4 +- .../callbacks/AddWPA2NetworkCallbacks.html | 4 +- .../callbacks/ConnectToNetworkCallbacks.html | 4 +- .../callbacks/DisableWifiCallbacks.html | 4 +- ...DisconnectFromCurrentNetworkCallbacks.html | 4 +- .../wisefy/callbacks/EnableWifiCallbacks.html | 4 +- .../callbacks/GetCurrentNetworkCallbacks.html | 4 +- .../callbacks/GetFrequencyCallbacks.html | 4 +- .../GetNearbyAccessPointsCallbacks.html | 8 +- .../wisefy/callbacks/GetRSSICallbacks.html | 245 ++++++ .../callbacks/GetSavedNetworkCallbacks.html | 18 +- .../callbacks/GetSavedNetworksCallbacks.html | 4 +- .../callbacks/RemoveNetworkCallbacks.html | 8 +- .../SearchForAccessPointCallbacks.html | 245 ++++++ .../SearchForAccessPointsCallbacks.html | 245 ++++++ .../callbacks/SearchForSSIDCallbacks.html | 12 +- .../callbacks/SearchForSSIDsCallbacks.html | 245 ++++++ .../wisefy/callbacks/package-frame.html | 8 +- .../wisefy/callbacks/package-summary.html | 24 +- .../wisefy/callbacks/package-tree.html | 8 +- .../wisefy/constants/Capabilities.html | 38 +- .../wisefy/constants/NetworkTypes.html | 4 +- .../wisefy/constants/WiseFyCodes.html | 4 +- .../wisefy/constants/package-frame.html | 4 +- .../wisefy/constants/package-summary.html | 4 +- .../wisefy/constants/package-tree.html | 4 +- .../com/isupatches/wisefy/package-frame.html | 6 +- .../isupatches/wisefy/package-summary.html | 9 +- .../com/isupatches/wisefy/package-tree.html | 6 +- .../wisefy/threads/WiseFyHandlerThread.html | 19 +- .../wisefy/threads/package-frame.html | 4 +- .../wisefy/threads/package-summary.html | 10 +- .../wisefy/threads/package-tree.html | 4 +- .../com/isupatches/wisefy/util/LogUtil.html | 16 +- .../isupatches/wisefy/util/ManagerUtil.html | 19 +- .../com/isupatches/wisefy/util/SSIDUtil.html | 9 +- .../com/isupatches/wisefy/util/SleepUtil.html | 277 +++++++ .../wisefy/util/WifiConfigurationUtil.html | 40 +- .../isupatches/wisefy/util/package-frame.html | 5 +- .../wisefy/util/package-summary.html | 24 +- .../isupatches/wisefy/util/package-tree.html | 5 +- javadoc/constant-values.html | 18 +- javadoc/deprecated-list.html | 4 +- javadoc/help-doc.html | 4 +- javadoc/index-all.html | 168 +++- javadoc/index.html | 2 +- javadoc/overview-frame.html | 4 +- javadoc/overview-summary.html | 4 +- javadoc/overview-tree.html | 11 +- .../wisefy/AddOpenNetworkTests.java | 42 +- .../isupatches/wisefy/AddWEPNetworkTests.java | 50 +- .../wisefy/AddWPA2NetworkTests.java | 49 +- .../com/isupatches/wisefy/BaseTestClass.java | 24 +- .../wisefy/ConnectToNetworkTests.java | 38 +- .../isupatches/wisefy/DisableWifiTests.java | 27 +- .../DisconnectFromCurrentNetworkTests.java | 27 +- .../isupatches/wisefy/EnableWifiTests.java | 27 +- .../wisefy/GetCurrentNetworkTests.java | 9 +- .../isupatches/wisefy/GetFrequencyTests.java | 4 +- .../wisefy/GetNearbyAccessPointsTests.java | 23 +- .../wisefy/GetSavedNetworkTests.java | 127 ++- .../wisefy/GetSavedNetworksTests.java | 249 +++--- .../isupatches/wisefy/IsNetwork5gHzTests.java | 213 +++-- .../IsNetworkInConfigurationListTests.java | 208 +++-- .../isupatches/wisefy/RemoveNetworkTests.java | 40 +- .../isupatches/wisefy/WiseFySearchTests.java | 675 ++++++++++++++-- .../com/isupatches/wisefy/WiseFyTests.java | 2 + .../com/isupatches/wisefy/base/TestUtils.java | 11 - .../isupatches/wisefy/test/BuilderTests.java | 32 + .../wisefy/test/PublicApiVisibilityTests.java | 608 ++++++++++++++ wisefy/src/main/AndroidManifest.xml | 3 +- .../java/com/isupatches/wisefy/WiseFy.java | 745 +++++++++--------- .../wisefy/WiseFyConfiguration.java | 17 + .../isupatches/wisefy/WiseFyConnection.java | 31 +- .../wisefy/WiseFyPrerequisites.java | 28 + .../com/isupatches/wisefy/WiseFySearch.java | 83 +- .../wisefy/threads/WiseFyHandlerThread.java | 6 +- .../com/isupatches/wisefy/util/SleepUtil.java | 7 + 94 files changed, 5457 insertions(+), 1372 deletions(-) create mode 100644 documentation/permissions_example.md create mode 100644 javadoc/com/isupatches/wisefy/WiseFy.brains.html create mode 100644 javadoc/com/isupatches/wisefy/WiseFyApplication.html create mode 100644 javadoc/com/isupatches/wisefy/callbacks/GetRSSICallbacks.html create mode 100644 javadoc/com/isupatches/wisefy/callbacks/SearchForAccessPointCallbacks.html create mode 100644 javadoc/com/isupatches/wisefy/callbacks/SearchForAccessPointsCallbacks.html create mode 100644 javadoc/com/isupatches/wisefy/callbacks/SearchForSSIDsCallbacks.html create mode 100644 javadoc/com/isupatches/wisefy/util/SleepUtil.html create mode 100644 wisefy/src/androidTest/java/com/isupatches/wisefy/test/BuilderTests.java create mode 100644 wisefy/src/androidTest/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java diff --git a/README.md b/README.md index 4d20f652..b96930e4 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,9 @@ For the sake of transparency and because you're probably curious as to what perm * NOTE * -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 diff --git a/documentation/permissions_example.md b/documentation/permissions_example.md new file mode 100644 index 00000000..0aeda3a8 --- /dev/null +++ b/documentation/permissions_example.md @@ -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 + + + + + + +``` + +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 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; +} +``` \ No newline at end of file diff --git a/javadoc/allclasses-frame.html b/javadoc/allclasses-frame.html index bb9a416c..d8c55f18 100644 --- a/javadoc/allclasses-frame.html +++ b/javadoc/allclasses-frame.html @@ -2,9 +2,9 @@ - + All Classes (wisefy 2.0.0-BETA API) - + @@ -25,19 +25,24 @@

All Classes

  • GetCurrentNetworkCallbacks
  • GetFrequencyCallbacks
  • GetNearbyAccessPointsCallbacks
  • +
  • GetRSSICallbacks
  • GetSavedNetworkCallbacks
  • GetSavedNetworksCallbacks
  • LogUtil
  • ManagerUtil
  • NetworkTypes
  • RemoveNetworkCallbacks
  • +
  • SearchForAccessPointCallbacks
  • +
  • SearchForAccessPointsCallbacks
  • SearchForSSIDCallbacks
  • +
  • SearchForSSIDsCallbacks
  • +
  • SleepUtil
  • SSIDUtil
  • Sync
  • WaitsForTimeout
  • WifiConfigurationUtil
  • WiseFy
  • -
  • WiseFy.withContext
  • +
  • WiseFy.brains
  • WiseFyCodes
  • WiseFyHandlerThread
  • WiseFyThread
  • diff --git a/javadoc/allclasses-noframe.html b/javadoc/allclasses-noframe.html index 5f755ec2..915cfe67 100644 --- a/javadoc/allclasses-noframe.html +++ b/javadoc/allclasses-noframe.html @@ -2,9 +2,9 @@ - + All Classes (wisefy 2.0.0-BETA API) - + @@ -25,19 +25,24 @@

    All Classes

  • GetCurrentNetworkCallbacks
  • GetFrequencyCallbacks
  • GetNearbyAccessPointsCallbacks
  • +
  • GetRSSICallbacks
  • GetSavedNetworkCallbacks
  • GetSavedNetworksCallbacks
  • LogUtil
  • ManagerUtil
  • NetworkTypes
  • RemoveNetworkCallbacks
  • +
  • SearchForAccessPointCallbacks
  • +
  • SearchForAccessPointsCallbacks
  • SearchForSSIDCallbacks
  • +
  • SearchForSSIDsCallbacks
  • +
  • SleepUtil
  • SSIDUtil
  • Sync
  • WaitsForTimeout
  • WifiConfigurationUtil
  • WiseFy
  • -
  • WiseFy.withContext
  • +
  • WiseFy.brains
  • WiseFyCodes
  • WiseFyHandlerThread
  • WiseFyThread
  • diff --git a/javadoc/com/isupatches/wisefy/WiseFy.brains.html b/javadoc/com/isupatches/wisefy/WiseFy.brains.html new file mode 100644 index 00000000..7dc17b9b --- /dev/null +++ b/javadoc/com/isupatches/wisefy/WiseFy.brains.html @@ -0,0 +1,320 @@ + + + + + +WiseFy.brains (wisefy 2.0.0-BETA API) + + + + + + + + + + + + +
    +
    com.isupatches.wisefy
    +

    Class WiseFy.brains

    +
    +
    +
      +
    • java.lang.Object
    • +
    • +
        +
      • com.isupatches.wisefy.WiseFy.brains
      • +
      +
    • +
    +
    +
      +
    • +
      +
      Enclosing class:
      +
      WiseFy
      +
      +
      +
      +
      public static class WiseFy.brains
      +extends java.lang.Object
      +
      Static class for builder pattern + + Implements builder interfaces #Logging #GetSmarts
      +
    • +
    +
    +
    +
      +
    • + +
        +
      • + + +

        Constructor Summary

        + + + + + + + + +
        Constructors 
        Constructor and Description
        brains(android.content.Context context) +
        Mandatory - The public constructor for the builder that requires a context
        +
        +
      • +
      + +
        +
      • + + +

        Method Summary

        + + + + + + + + + + + + + + +
        All Methods Instance Methods Concrete Methods 
        Modifier and TypeMethod and Description
        WiseFygetSmarts() +
        Mandatory - To build and return a WiseFy instance + + Must be called after brains + WiseFy.brains
        +
        WiseFy.brainslogging(boolean loggingEnabled) +
        Optional - Builder method that enables/disables logging for a WiseWy instance
        +
        +
          +
        • + + +

          Methods inherited from class java.lang.Object

          +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
        • +
        +
      • +
      +
    • +
    +
    +
    +
      +
    • + +
        +
      • + + +

        Constructor Detail

        + + + +
          +
        • +

          brains

          +
          public brains(android.content.Context context)
          +
          Mandatory - The public constructor for the builder that requires a context
          +
          +
          Parameters:
          +
          context - The activity or application context to get a WifiConfiguration and + ConnectivityManager instance
          +
          +
        • +
        +
      • +
      + +
        +
      • + + +

        Method Detail

        + + + +
          +
        • +

          getSmarts

          +
          public WiseFy getSmarts()
          +
          Mandatory - To build and return a WiseFy instance + + Must be called after brains + WiseFy.brains
          +
          +
          Returns:
          +
          WiseFy - The instance created by the builder
          +
          +
        • +
        + + + +
          +
        • +

          logging

          +
          public WiseFy.brains logging(boolean loggingEnabled)
          +
          Optional - Builder method that enables/disables logging for a WiseWy instance
          +
          +
          Parameters:
          +
          loggingEnabled - If logging is enabled or disabled for an instance + Logging
          +
          Returns:
          +
          brains - The builder with updated logging setting
          +
          +
        • +
        +
      • +
      +
    • +
    +
    +
    + + + + + + + diff --git a/javadoc/com/isupatches/wisefy/WiseFy.html b/javadoc/com/isupatches/wisefy/WiseFy.html index e8801e66..52fd8017 100644 --- a/javadoc/com/isupatches/wisefy/WiseFy.html +++ b/javadoc/com/isupatches/wisefy/WiseFy.html @@ -2,9 +2,9 @@ - + WiseFy (wisefy 2.0.0-BETA API) - + @@ -18,7 +18,7 @@ catch(err) { } //--> -var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10,"i20":10,"i21":10,"i22":10,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10,"i35":10,"i36":10,"i37":10,"i38":10,"i39":10,"i40":10,"i41":10,"i42":10,"i43":10,"i44":10}; +var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10,"i20":10,"i21":10,"i22":10,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10,"i35":10,"i36":10,"i37":10,"i38":10,"i39":10,"i40":10,"i41":10,"i42":10,"i43":10,"i44":10,"i45":10,"i46":10,"i47":10,"i48":10,"i49":10,"i50":10,"i51":10,"i52":10,"i53":10,"i54":10,"i55":10,"i56":10,"i57":10}; var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -49,7 +49,7 @@ @@ -131,7 +132,7 @@

    Nested Class Summary

    static class  -WiseFy.withContext +WiseFy.brains
    Static class for builder pattern Implements builder interfaces #Logging #GetSmarts
    @@ -157,17 +158,9 @@

    Field Summary

    MAX_FREQUENCY_5GHZ  -android.net.ConnectivityManager -mConnectivityManager  - - static int MIN_FREQUENCY_5GHZ  - -android.net.wifi.WifiManager -mWifiManager  - static int WIFI_MANAGER_FAILURE  @@ -196,7 +189,7 @@

    Method Summary

    void addOpenNetwork(java.lang.String ssid, - AddOpenNetworkCallbacks addOpenNetworkCallbacks) + AddOpenNetworkCallbacks callbacks)
    To add an open network to the user's configured network list (asynchronously)
    @@ -211,7 +204,7 @@

    Method Summary

    void addWEPNetwork(java.lang.String ssid, java.lang.String password, - AddWEPNetworkCallbacks addWEPNetworkCallbacks) + AddWEPNetworkCallbacks callbacks)
    To add a WEP network to the user's configured network list (asynchronously)
    @@ -226,7 +219,7 @@

    Method Summary

    void addWPA2Network(java.lang.String ssid, java.lang.String password, - AddWPA2NetworkCallbacks addWPA2NetworkCallbacks) + AddWPA2NetworkCallbacks callbacks)
    To add a WPA2 network to the user's configured network list (asynchronously)
    @@ -257,7 +250,7 @@

    Method Summary

    void connectToNetwork(java.lang.String ssidToConnectTo, int timeoutInMillis, - ConnectToNetworkCallbacks connectToNetworkCallbacks) + ConnectToNetworkCallbacks callbacks)
    Used to connect to a network (asynchronously) Gets a list of saved networks, connects to the given ssid if found, and verifies connectivity
    @@ -271,7 +264,7 @@

    Method Summary

    void -disableWifi(DisableWifiCallbacks disableWifiCallbacks) +disableWifi(DisableWifiCallbacks callbacks)
    To disable Wifi on a user's device (asynchronously)
    @@ -283,60 +276,66 @@

    Method Summary

    void -disconnectFromCurrentNetwork(DisconnectFromCurrentNetworkCallbacks disconnectFromCurrentNetworkCallbacks) +disconnectFromCurrentNetwork(DisconnectFromCurrentNetworkCallbacks callbacks)
    To disconnect the user from their current network (asynchronously)
    +void +dump() +
    Used to cleanup the thread started by WiseFy
    + + + boolean enableWifi()
    To enable Wifi on a user's device
    - + void -enableWifi(EnableWifiCallbacks enableWifiCallbacks) +enableWifi(EnableWifiCallbacks callbacks)
    To enable Wifi on a user's device
    - + android.net.wifi.WifiInfo getCurrentNetwork()
    To retrieve the user's current network
    - + void -getCurrentNetwork(GetCurrentNetworkCallbacks getCurrentNetworkCallbacks) +getCurrentNetwork(GetCurrentNetworkCallbacks callbacks)
    To retrieve the user's current network
    - + java.lang.Integer getFrequency()
    To retrieve the frequency of the device's current network
    - + void -getFrequency(GetFrequencyCallbacks getFrequencyCallbacks) +getFrequency(GetFrequencyCallbacks callbacks)
    To retrieve the frequency of the device's current network
    - + java.lang.Integer getFrequency(android.net.wifi.WifiInfo network)
    To retrieve the frequency of a network
    - + void getFrequency(android.net.wifi.WifiInfo network, - GetFrequencyCallbacks getFrequencyCallbacks) + GetFrequencyCallbacks callbacks)
    To retrieve the frequency of a network
    - + java.util.List<android.net.wifi.ScanResult> getNearbyAccessPoints(boolean filterDuplicates)
    To retrieve a list of nearby access points @@ -344,53 +343,75 @@

    Method Summary

    *NOTE* Setting filterDuplicates to true will not return SSIDs with a weaker signal strength (will always take the highest)
    - + void getNearbyAccessPoints(boolean filterDuplicates, - GetNearbyAccessPointsCallbacks getNearbyAccessPointsCallbacks) + GetNearbyAccessPointsCallbacks callbacks)
    To retrieve a list of nearby access points *NOTE* Setting filterDuplicates to true will not return SSIDs with a weaker signal strength (will always take the highest)
    - + +java.lang.Integer +getRSSI(java.lang.String regexForSSID, + boolean takeHighest, + int timeoutInMillis)  + + +void +getRSSI(java.lang.String regexForSSID, + boolean takeHighest, + int timeoutInMillis, + GetRSSICallbacks callbacks)  + + android.net.wifi.WifiConfiguration -getSavedNetwork(java.lang.String ssid) +getSavedNetwork(java.lang.String regexForSSID)
    To search for and return a saved WiFiConfiguration given an SSID
    - + void -getSavedNetwork(java.lang.String ssid, - GetSavedNetworkCallbacks getSavedNetworkCallback) +getSavedNetwork(java.lang.String regexForSSID, + GetSavedNetworkCallbacks callbacks)
    To search for and return a saved WiFiConfiguration given an SSID
    - + java.util.List<android.net.wifi.WifiConfiguration> getSavedNetworks()
    To retrieve a list of saved networks on a user's device
    - + void -getSavedNetworks(GetSavedNetworksCallbacks getSavedNetworksCallback) +getSavedNetworks(GetSavedNetworksCallbacks callbacks)
    To retrieve a list of saved networks on a user's device
    - + +java.util.List<android.net.wifi.WifiConfiguration> +getSavedNetworks(java.lang.String regexForSSID)  + + +void +getSavedNetworks(java.lang.String regexForSSID, + GetSavedNetworksCallbacks callbacks)  + + boolean isDeviceConnectedToMobileNetwork()
    To check if the device is connected to a mobile network
    - + boolean isDeviceConnectedToMobileOrWifiNetwork()
    To check if the device is connected to a mobile or wifi network
    - + boolean isDeviceConnectedToSSID(java.lang.String ssid)
    To check if the device is connected to a given SSID @@ -398,94 +419,140 @@

    Method Summary

    Used by connectToNetwork
    - + boolean isDeviceConnectedToWifiNetwork() -
    To check if the device is connected to a wifi network - - Uses - NetworkTypes
    +
    To check if the device is connected to a wifi network
    - + boolean isLoggingEnabled()
    To query if logging is enabled or disabled for a WiseFy instance
    - + boolean isNetwork5gHz()
    To check if the device's current network is 5gHz
    - + boolean isNetwork5gHz(android.net.wifi.WifiInfo network)
    To check if a given network is 5gHz
    - + +boolean +isNetworkEAP(android.net.wifi.ScanResult scanResult) +
    To check and return if a network is a EAP network
    + + + boolean isNetworkInConfigurationList(java.lang.String ssid)
    To check if an SSID is in the list of configured networks
    - + +boolean +isNetworkPSK(android.net.wifi.ScanResult scanResult) +
    To check and return if a network is a PSK network
    + + + boolean isNetworkSecure(android.net.wifi.ScanResult scanResult)
    To check and return if a network is secure (WEP/WPA/WPA2 capabilities)
    - + boolean isNetworkWEP(android.net.wifi.ScanResult scanResult)
    To check and return if a network is a WEP network
    - + boolean isNetworkWPA(android.net.wifi.ScanResult scanResult)
    To check and return if a network is a WPA network
    - + boolean isNetworkWPA2(android.net.wifi.ScanResult scanResult)
    To check and return if a network is a WPA2 network
    - + boolean isWifiEnabled()
    To check if Wifi is enabled on the device or not
    - + boolean removeNetwork(java.lang.String ssidToRemove)
    To remove a configured network
    - + void removeNetwork(java.lang.String ssidToRemove, - RemoveNetworkCallbacks removeNetworkCallback) + RemoveNetworkCallbacks callbacks)
    To remove a configured network
    - + +android.net.wifi.ScanResult +searchForAccessPoint(java.lang.String regexForSSID, + int timeoutInMillis, + boolean filterDuplicates)  + + +void +searchForAccessPoint(java.lang.String regexForSSID, + int timeoutInMillis, + boolean filterDuplicates, + SearchForAccessPointCallbacks callbacks)  + + +java.util.List<android.net.wifi.ScanResult> +searchForAccessPoints(java.lang.String regexForSSID, + boolean filterDuplicates)  + + +void +searchForAccessPoints(java.lang.String regexForSSID, + boolean filterDuplicates, + SearchForAccessPointsCallbacks callbacks)  + + java.lang.String searchForSSID(java.lang.String regexForSSID, int timeoutInMillis)
    To search local networks and return the first one that contains a given ssid
    - + void searchForSSID(java.lang.String regexForSSID, int timeoutInMillis, - SearchForSSIDCallbacks searchForSSIDCallback) + SearchForSSIDCallbacks callbacks) +
    To search local networks and return the first one that contains a given ssid
    + + + +java.util.List<java.lang.String> +searchForSSIDs(java.lang.String regexForSSID) +
    To search local networks and return the first one that contains a given ssid
    + + + +void +searchForSSIDs(java.lang.String regexForSSID, + SearchForSSIDsCallbacks callbacks)
    To search local networks and return the first one that contains a given ssid
    @@ -540,7 +607,7 @@

    MIN_FREQUENCY_5GHZ

    -
      +
      • MAX_FREQUENCY_5GHZ

        public static final int MAX_FREQUENCY_5GHZ
        @@ -550,24 +617,6 @@

        MAX_FREQUENCY_5GHZ

      - - - -
        -
      • -

        mConnectivityManager

        -
        public android.net.ConnectivityManager mConnectivityManager
        -
      • -
      - - - -
        -
      • -

        mWifiManager

        -
        public android.net.wifi.WifiManager mWifiManager
        -
      • -
    @@ -592,11 +641,12 @@

    addOpenNetwork

    Returns:
    int - The return code from WifiManager for network creation (-1 for failure)
    See Also:
    -
    addNetwork(WifiConfiguration), -checkIfNetworkInConfigurationList(String), -hasPrerequisites(), +
    addNetworkConfiguration(WifiConfiguration), WifiConfigurationUtil.generateOpenNetworkConfiguration(String), -WiseFyCodes
    +WiseFyCodes, +WiseFyConfiguration.isLoggingEnabled(), +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.isNetworkASavedConfiguration(String) @@ -609,21 +659,21 @@

    addOpenNetwork

    @Async
      @WiseFyThread
     public void addOpenNetwork(java.lang.String ssid,
    -                                                 AddOpenNetworkCallbacks addOpenNetworkCallbacks)
    + AddOpenNetworkCallbacks callbacks)
    To add an open network to the user's configured network list (asynchronously)
    Parameters:
    ssid - The ssid of the open network you want to add
    -
    addOpenNetworkCallbacks - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    -
    addNetwork(WifiConfiguration), -checkIfNetworkInConfigurationList(String), +
    addNetworkConfiguration(WifiConfiguration), execute(Runnable), -hasPrerequisites(), -stopThreadSafely(), AddOpenNetworkCallbacks, WifiConfigurationUtil.generateOpenNetworkConfiguration(String), -WiseFyCodes
    +WiseFyCodes, +WiseFyConfiguration.isLoggingEnabled(), +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.isNetworkASavedConfiguration(String)
    @@ -645,11 +695,12 @@

    addWEPNetwork

    Returns:
    int - The return code from WifiManager for network creation (-1 for failure)
    See Also:
    -
    addNetwork(WifiConfiguration), -checkIfNetworkInConfigurationList(String), -hasPrerequisites(), +
    addNetworkConfiguration(WifiConfiguration), WifiConfigurationUtil.generateWEPNetworkConfiguration(String, String), -WiseFyCodes
    +WiseFyCodes, +WiseFyConfiguration.isLoggingEnabled(), +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.isNetworkASavedConfiguration(String) @@ -663,22 +714,22 @@

    addWEPNetwork

    @WiseFyThread public void addWEPNetwork(java.lang.String ssid, java.lang.String password, - AddWEPNetworkCallbacks addWEPNetworkCallbacks) + AddWEPNetworkCallbacks callbacks)
    To add a WEP network to the user's configured network list (asynchronously)
    Parameters:
    ssid - The ssid of the WEP network you want to add
    password - The password for the WEP network being added
    -
    addWEPNetworkCallbacks - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    -
    addNetwork(WifiConfiguration), -checkIfNetworkInConfigurationList(String), +
    addNetworkConfiguration(WifiConfiguration), execute(Runnable), -hasPrerequisites(), -stopThreadSafely(), AddWEPNetworkCallbacks, WifiConfigurationUtil.generateWEPNetworkConfiguration(String, String), -WiseFyCodes
    +WiseFyCodes, +WiseFyConfiguration.isLoggingEnabled(), +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.isNetworkASavedConfiguration(String)
    @@ -700,11 +751,12 @@

    addWPA2Network

    Returns:
    int - The return code from WifiManager for network creation (-1 for failure)
    See Also:
    -
    addNetwork(WifiConfiguration), -checkIfNetworkInConfigurationList(String), -hasPrerequisites(), +
    addNetworkConfiguration(WifiConfiguration), WifiConfigurationUtil.generateWPA2NetworkConfiguration(String, String), -WiseFyCodes
    +WiseFyCodes, +WiseFyConfiguration.isLoggingEnabled(), +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.isNetworkASavedConfiguration(String) @@ -718,22 +770,22 @@

    addWPA2Network

    @WiseFyThread public void addWPA2Network(java.lang.String ssid, java.lang.String password, - AddWPA2NetworkCallbacks addWPA2NetworkCallbacks) + AddWPA2NetworkCallbacks callbacks)
    To add a WPA2 network to the user's configured network list (asynchronously)
    Parameters:
    ssid - The ssid of the WPA2 network you want to add
    password - The password for the WPA2 network being added
    -
    addWPA2NetworkCallbacks - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    -
    addNetwork(WifiConfiguration), -checkIfNetworkInConfigurationList(String), +
    addNetworkConfiguration(WifiConfiguration), execute(Runnable), -hasPrerequisites(), -stopThreadSafely(), AddWPA2NetworkCallbacks, WifiConfigurationUtil.generateWPA2NetworkConfiguration(String, String), -WiseFyCodes
    +WiseFyCodes, +WiseFyConfiguration.isLoggingEnabled(), +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.isNetworkASavedConfiguration(String)
    @@ -799,9 +851,9 @@

    connectToNetwork

    Returns:
    boolean - If the network was successfully reconnected
    See Also:
    -
    findNetworkInConfigurationList(String), -hasPrerequisites(), -waitToConnectToSSID(String, int)
    +
    WiseFyConnection.waitToConnectToSSID(String, int), +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.findSavedNetworkByRegex(String)
    @@ -816,7 +868,7 @@

    connectToNetwork

    @WaitsForTimeout public void connectToNetwork(java.lang.String ssidToConnectTo, int timeoutInMillis, - ConnectToNetworkCallbacks connectToNetworkCallbacks) + ConnectToNetworkCallbacks callbacks)
    Used to connect to a network (asynchronously) Gets a list of saved networks, connects to the given ssid if found, and verifies connectivity
    @@ -824,15 +876,14 @@

    connectToNetwork

    Parameters:
    ssidToConnectTo - The ssid to connect/reconnect to
    timeoutInMillis - The number of milliseconds to continue waiting for the device to connect to the given SSID
    -
    connectToNetworkCallbacks - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), -findNetworkInConfigurationList(String), -hasPrerequisites(), -stopThreadSafely(), -waitToConnectToSSID(String, int), ConnectToNetworkCallbacks, -WiseFyCodes
    +WiseFyCodes, +WiseFyConnection.waitToConnectToSSID(String, int), +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.findSavedNetworkByRegex(String) @@ -848,9 +899,9 @@

    disableWifi

    To disable Wifi on a user's device (synchronously)
    Returns:
    -
    boolean - If the command succeeded in disabling wifi
    +
    boolean - True if the command succeeded in disabling wifi
    See Also:
    -
    hasPrerequisites()
    +
    WiseFyPrerequisites.hasPrerequisites()
    @@ -862,17 +913,16 @@

    disableWifi

    disableWifi

    @Async
      @WiseFyThread
    -public void disableWifi(DisableWifiCallbacks disableWifiCallbacks)
    +public void disableWifi(DisableWifiCallbacks callbacks)
    To disable Wifi on a user's device (asynchronously)
    Parameters:
    -
    disableWifiCallbacks - - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), -hasPrerequisites(), -stopThreadSafely(), DisableWifiCallbacks, -WiseFyCodes
    +WiseFyCodes, +WiseFyPrerequisites.hasPrerequisites()
    @@ -890,7 +940,7 @@

    disconnectFromCurrentNetwork

    Returns:
    boolean - If the command succeeded in disconnecting the device from the current network
    See Also:
    -
    hasPrerequisites()
    +
    WiseFyPrerequisites.hasPrerequisites()
    @@ -902,20 +952,29 @@

    disconnectFromCurrentNetwork

    disconnectFromCurrentNetwork

    @Async
      @WiseFyThread
    -public void disconnectFromCurrentNetwork(DisconnectFromCurrentNetworkCallbacks disconnectFromCurrentNetworkCallbacks)
    +public void disconnectFromCurrentNetwork(DisconnectFromCurrentNetworkCallbacks callbacks)
    To disconnect the user from their current network (asynchronously)
    Parameters:
    -
    disconnectFromCurrentNetworkCallbacks - - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), -hasPrerequisites(), -stopThreadSafely(), DisconnectFromCurrentNetworkCallbacks, -WiseFyCodes
    +WiseFyCodes, +WiseFyPrerequisites.hasPrerequisites()
    + + + +
      +
    • +

      dump

      +
      public void dump()
      +
      Used to cleanup the thread started by WiseFy
      +
    • +
    @@ -930,7 +989,7 @@

    enableWifi

    Returns:
    boolean - If the command succeeded in enabling wifi
    See Also:
    -
    hasPrerequisites()
    +
    WiseFyPrerequisites.hasPrerequisites()
    @@ -942,17 +1001,16 @@

    enableWifi

    enableWifi

    @Async
      @WiseFyThread
    -public void enableWifi(EnableWifiCallbacks enableWifiCallbacks)
    +public void enableWifi(EnableWifiCallbacks callbacks)
    To enable Wifi on a user's device
    Parameters:
    -
    enableWifiCallbacks - - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), -hasPrerequisites(), -stopThreadSafely(), EnableWifiCallbacks, -WiseFyCodes
    +WiseFyCodes, +WiseFyPrerequisites.hasPrerequisites()
    @@ -970,7 +1028,7 @@

    getCurrentNetwork

    Returns:
    WifiInfo|null - The user's current network information
    See Also:
    -
    hasPrerequisites()
    +
    WiseFyPrerequisites.hasPrerequisites()
    @@ -982,17 +1040,16 @@

    getCurrentNetwork

    getCurrentNetwork

    @Async
      @WiseFyThread
    -public void getCurrentNetwork(GetCurrentNetworkCallbacks getCurrentNetworkCallbacks)
    +public void getCurrentNetwork(GetCurrentNetworkCallbacks callbacks)
    To retrieve the user's current network
    Parameters:
    -
    getCurrentNetworkCallbacks - - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), -hasPrerequisites(), -stopThreadSafely(), GetCurrentNetworkCallbacks, -WiseFyCodes
    +WiseFyCodes, +WiseFyPrerequisites.hasPrerequisites()
    @@ -1008,7 +1065,7 @@

    getFrequency

    To retrieve the frequency of the device's current network
    Returns:
    -
    int|NULL - The frequency of the devices current network or null if no network
    +
    Integer - The frequency of the devices current network or null if no network
    See Also:
    getCurrentNetwork()
    @@ -1022,15 +1079,14 @@

    getFrequency

    getFrequency

    @Async
      @WiseFyThread
    -public void getFrequency(GetFrequencyCallbacks getFrequencyCallbacks)
    +public void getFrequency(GetFrequencyCallbacks callbacks)
    To retrieve the frequency of the device's current network
    Parameters:
    -
    getFrequencyCallbacks - - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), getCurrentNetwork(GetCurrentNetworkCallbacks), -stopThreadSafely(), GetFrequencyCallbacks
    @@ -1047,9 +1103,9 @@

    getFrequency

    To retrieve the frequency of a network
    Parameters:
    -
    network - - The network to return the frequency of
    +
    network - The network to return the frequency of
    Returns:
    -
    int|NULL - The frequency of the devices current network or null if no network
    +
    Integer - The frequency of the devices current network or null if no network
    @@ -1062,15 +1118,14 @@

    getFrequency

    @Async
      @WiseFyThread
     public void getFrequency(android.net.wifi.WifiInfo network,
    -                                               GetFrequencyCallbacks getFrequencyCallbacks)
    + GetFrequencyCallbacks callbacks)
    To retrieve the frequency of a network
    Parameters:
    -
    network - - The network to return the frequency of
    -
    getFrequencyCallbacks - - The listener to return results to
    +
    network - The network to return the frequency of
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), -stopThreadSafely(), GetFrequencyCallbacks, WiseFyCodes
    @@ -1090,12 +1145,12 @@

    getNearbyAccessPoints

    *NOTE* Setting filterDuplicates to true will not return SSIDs with a weaker signal strength (will always take the highest)
    Parameters:
    -
    filterDuplicates - - If you want to exclude SSIDs with that same name that have a weaker signal strength
    +
    filterDuplicates - If you want to exclude SSIDs with that same name that have a weaker signal strength
    Returns:
    List of ScanResults|null - List of nearby access points
    See Also:
    -
    hasPrerequisites(), -filterScanResults()
    +
    WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.removeEntriesWithLowerSignalStrength(List)
    @@ -1108,24 +1163,52 @@

    getNearbyAccessPoints

    @Async
      @WiseFyThread
     public void getNearbyAccessPoints(boolean filterDuplicates,
    -                                                        GetNearbyAccessPointsCallbacks getNearbyAccessPointsCallbacks)
    + GetNearbyAccessPointsCallbacks callbacks)
    To retrieve a list of nearby access points *NOTE* Setting filterDuplicates to true will not return SSIDs with a weaker signal strength (will always take the highest)
    Parameters:
    filterDuplicates - If you want to exclude SSIDs with that same name that have a weaker signal strength
    -
    getNearbyAccessPointsCallbacks - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), -hasPrerequisites(), -filterScanResults(), -stopThreadSafely(), GetNearbyAccessPointsCallbacks, -WiseFyCodes
    +WiseFyCodes, +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.removeEntriesWithLowerSignalStrength(List)
    + + + + + + + + @@ -1134,16 +1217,16 @@

    getNearbyAccessPoints

    getSavedNetwork

    @Sync
      @CallingThread
    -public android.net.wifi.WifiConfiguration getSavedNetwork(java.lang.String ssid)
    +public android.net.wifi.WifiConfiguration getSavedNetwork(java.lang.String regexForSSID)
    To search for and return a saved WiFiConfiguration given an SSID
    Parameters:
    -
    ssid - - The ssid to use while searching for saved configuration
    +
    regexForSSID - The ssid to use while searching for saved configuration
    Returns:
    WifiConfiguration|null - Saved network that matches the ssid
    See Also:
    -
    hasPrerequisites(), -findNetworkInConfigurationList(String)
    +
    WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.findSavedNetworkByRegex(String)
    @@ -1155,20 +1238,19 @@

    getSavedNetwork

    getSavedNetwork

    @Async
      @WiseFyThread
    -public void getSavedNetwork(java.lang.String ssid,
    -                                                  GetSavedNetworkCallbacks getSavedNetworkCallback)
    +public void getSavedNetwork(java.lang.String regexForSSID, + GetSavedNetworkCallbacks callbacks)
    To search for and return a saved WiFiConfiguration given an SSID
    Parameters:
    -
    ssid - - The ssid to use while searching for saved configuration
    -
    getSavedNetworkCallback - - The listener to return results to
    +
    regexForSSID - The ssid to use while searching for saved configuration
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), -hasPrerequisites(), -findNetworkInConfigurationList(String), -stopThreadSafely(), GetSavedNetworkCallbacks, -WiseFyCodes
    +WiseFyCodes, +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.findSavedNetworkByRegex(String)
    @@ -1186,7 +1268,7 @@

    getSavedNetworks

    Returns:
    List of WifiConfiguration|null - List of saved networks on a users device
    See Also:
    -
    hasPrerequisites()
    +
    WiseFyPrerequisites.hasPrerequisites()
    @@ -1198,20 +1280,42 @@

    getSavedNetworks

    getSavedNetworks

    @Async
      @WiseFyThread
    -public void getSavedNetworks(GetSavedNetworksCallbacks getSavedNetworksCallback)
    +public void getSavedNetworks(GetSavedNetworksCallbacks callbacks)
    To retrieve a list of saved networks on a user's device
    Parameters:
    -
    getSavedNetworksCallback - - The listener to return results to
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), -hasPrerequisites(), -stopThreadSafely(), GetSavedNetworksCallbacks, -WiseFyCodes
    +WiseFyCodes, +WiseFyPrerequisites.hasPrerequisites()
    + + + +
      +
    • +

      getSavedNetworks

      +
      @Sync
      + @CallingThread
      +public java.util.List<android.net.wifi.WifiConfiguration> getSavedNetworks(java.lang.String regexForSSID)
      +
    • +
    + + + + @@ -1226,9 +1330,9 @@

    isDeviceConnectedToMobileNetwork

    Returns:
    bool - If the device is currently connected to a mobile network
    See Also:
    -
    hasPrerequisites(), -isNetworkConnectedAndMatchType(NetworkInfo, String), -NetworkTypes
    +
    NetworkTypes, +WiseFyConnection.isNetworkConnectedAndMatchesType(NetworkInfo, String), +WiseFyPrerequisites.hasPrerequisites()
    @@ -1246,8 +1350,8 @@

    isDeviceConnectedToMobileOrWifiNetwork

    Returns:
    bool - If the device is currently connected to a mobile or wifi network
    See Also:
    -
    hasPrerequisites(), -isNetworkConnected(NetworkInfo)
    +
    WiseFyConnection.isNetworkConnected(NetworkInfo), +WiseFyPrerequisites.hasPrerequisites()
    @@ -1265,11 +1369,11 @@

    isDeviceConnectedToSSID

    Used by connectToNetwork
    Parameters:
    -
    ssid - - The SSID to check if the device is attached to
    +
    ssid - The SSID to check if the device is attached to
    Returns:
    bool - If the device is currently attached to the given SSID
    See Also:
    -
    isNetworkConnected(NetworkInfo)
    +
    WiseFyConnection.isCurrentNetworkConnectedToSSID(String)
    @@ -1282,13 +1386,14 @@

    isDeviceConnectedToWifiNetwork

    @Sync
      @CallingThread
     public boolean isDeviceConnectedToWifiNetwork()
    -
    To check if the device is connected to a wifi network - - Uses - NetworkTypes
    +
    To check if the device is connected to a wifi network
    Returns:
    bool - If the device is currently connected to a wifi network
    +
    See Also:
    +
    NetworkTypes, +WiseFyPrerequisites.hasPrerequisites(), +WiseFyConnection.isNetworkConnectedAndMatchesType(NetworkInfo, String)
    @@ -1322,7 +1427,9 @@

    isNetwork5gHz

    Returns:
    boolean - If the network is 5gHz
    See Also:
    -
    getFrequency()
    +
    getFrequency(), +MIN_FREQUENCY_5GHZ, +MAX_FREQUENCY_5GHZ
    @@ -1338,11 +1445,13 @@

    isNetwork5gHz

    To check if a given network is 5gHz
    Parameters:
    -
    network - - The network to check if it's 5gHz
    +
    network - The network to check if it's 5gHz
    Returns:
    boolean - If the network is 5gHz
    See Also:
    -
    getFrequency(WifiInfo)
    +
    getFrequency(WifiInfo), +MIN_FREQUENCY_5GHZ, +MAX_FREQUENCY_5GHZ
    @@ -1358,12 +1467,52 @@

    isNetworkInConfigurationList

    To check if an SSID is in the list of configured networks
    Parameters:
    -
    ssid - - The SSID to check and see if it's in the list of configured networks
    +
    ssid - The SSID to check and see if it's in the list of configured networks
    Returns:
    boolean - If the SSID is in the list of configured networks
    See Also:
    -
    checkIfNetworkInConfigurationList(String), -hasPrerequisites()
    +
    WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.isNetworkASavedConfiguration(String)
    +
    + + + + + +
      +
    • +

      isNetworkEAP

      +
      @Sync
      + @CallingThread
      +public boolean isNetworkEAP(android.net.wifi.ScanResult scanResult)
      +
      To check and return if a network is a EAP network
      +
      +
      Parameters:
      +
      scanResult - The network to check
      +
      Returns:
      +
      boolean - Whether the network has EAP capabilities listed
      +
      See Also:
      +
      Capabilities
      +
      +
    • +
    + + + +
      +
    • +

      isNetworkPSK

      +
      @Sync
      + @CallingThread
      +public boolean isNetworkPSK(android.net.wifi.ScanResult scanResult)
      +
      To check and return if a network is a PSK network
      +
      +
      Parameters:
      +
      scanResult - The network to check
      +
      Returns:
      +
      boolean - Whether the network has PSK capabilities listed
      +
      See Also:
      +
      Capabilities
    @@ -1379,7 +1528,7 @@

    isNetworkSecure

    To check and return if a network is secure (WEP/WPA/WPA2 capabilities)
    Parameters:
    -
    scanResult - - The network to see if it is secure
    +
    scanResult - The network to see if it is secure
    Returns:
    boolean - Whether the network is secure
    See Also:
    @@ -1399,7 +1548,7 @@

    isNetworkWEP

    To check and return if a network is a WEP network
    Parameters:
    -
    scanResult - - The network to check
    +
    scanResult - The network to check
    Returns:
    boolean - Whether the network has WEP capabilities listed
    See Also:
    @@ -1419,7 +1568,7 @@

    isNetworkWPA

    To check and return if a network is a WPA network
    Parameters:
    -
    scanResult - - The network to check
    +
    scanResult - The network to check
    Returns:
    boolean - Whether the network has WPA capabilities listed
    See Also:
    @@ -1439,7 +1588,7 @@

    isNetworkWPA2

    To check and return if a network is a WPA2 network
    Parameters:
    -
    scanResult - - The network to check
    +
    scanResult - The network to check
    Returns:
    boolean - Whether the network has WPA2 capabilities listed
    See Also:
    @@ -1461,7 +1610,7 @@

    isWifiEnabled

    Returns:
    boolean - if Wifi is enabled on device
    See Also:
    -
    hasPrerequisites()
    +
    WiseFyPrerequisites.hasPrerequisites()
    @@ -1477,12 +1626,12 @@

    removeNetwork

    To remove a configured network
    Parameters:
    -
    ssidToRemove - - The ssid of the network you want to remove from the configured network list
    +
    ssidToRemove - The ssid of the network you want to remove from the configured network list
    Returns:
    boolean - If the command succeeded in removing the network
    See Also:
    -
    hasPrerequisites(), -findNetworkInConfigurationList(String)
    +
    WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.findSavedNetworkByRegex(String)
    @@ -1495,22 +1644,65 @@

    removeNetwork

    @Async
      @WiseFyThread
     public void removeNetwork(java.lang.String ssidToRemove,
    -                                                RemoveNetworkCallbacks removeNetworkCallback)
    + RemoveNetworkCallbacks callbacks)
    To remove a configured network
    Parameters:
    -
    ssidToRemove - - The ssid of the network you want to remove from the configured network list
    -
    removeNetworkCallback - - The listener to return results to
    +
    ssidToRemove - The ssid of the network you want to remove from the configured network list
    +
    callbacks - The listener to return results to
    See Also:
    execute(Runnable), -hasPrerequisites(), -findNetworkInConfigurationList(String), -stopThreadSafely(), RemoveNetworkCallbacks, -WiseFyCodes
    +WiseFyCodes, +WiseFyPrerequisites.hasPrerequisites(), +WiseFySearch.findSavedNetworkByRegex(String)
    + + + +
      +
    • +

      searchForAccessPoint

      +
      public android.net.wifi.ScanResult searchForAccessPoint(java.lang.String regexForSSID,
      +                                                        int timeoutInMillis,
      +                                                        boolean filterDuplicates)
      +
    • +
    + + + +
      +
    • +

      searchForAccessPoint

      +
      public void searchForAccessPoint(java.lang.String regexForSSID,
      +                                 int timeoutInMillis,
      +                                 boolean filterDuplicates,
      +                                 SearchForAccessPointCallbacks callbacks)
      +
    • +
    + + + +
      +
    • +

      searchForAccessPoints

      +
      public java.util.List<android.net.wifi.ScanResult> searchForAccessPoints(java.lang.String regexForSSID,
      +                                                                         boolean filterDuplicates)
      +
    • +
    + + + +
      +
    • +

      searchForAccessPoints

      +
      public void searchForAccessPoints(java.lang.String regexForSSID,
      +                                  boolean filterDuplicates,
      +                                  SearchForAccessPointsCallbacks callbacks)
      +
    • +
    @@ -1525,8 +1717,8 @@

    searchForSSID

    To search local networks and return the first one that contains a given ssid
    Parameters:
    -
    regexForSSID - - The regex to be used to search for the ssid
    -
    timeoutInMillis - - The number of milliseconds to keep searching for the SSID
    +
    regexForSSID - The regex to be used to search for the ssid
    +
    timeoutInMillis - The number of milliseconds to keep searching for the SSID
    Returns:
    String|null - The first SSID that contains the search ssid (if any, else null)
    @@ -1535,7 +1727,7 @@

    searchForSSID

    -
      +
      • searchForSSID

        @Async
        @@ -1543,19 +1735,61 @@ 

        searchForSSID

        @WaitsForTimeout public void searchForSSID(java.lang.String regexForSSID, int timeoutInMillis, - SearchForSSIDCallbacks searchForSSIDCallback)
        + SearchForSSIDCallbacks callbacks)
        To search local networks and return the first one that contains a given ssid
        Parameters:
        -
        regexForSSID - - The regex to be used to search for the ssid
        -
        timeoutInMillis - - The number of milliseconds to keep searching for the SSID
        -
        searchForSSIDCallback - - The listener to return results to
        +
        regexForSSID - The regex to be used to search for the ssid
        +
        timeoutInMillis - The number of milliseconds to keep searching for the SSID
        +
        callbacks - The listener to return results to
        See Also:
        execute(Runnable), -findSSIDByRegex(String, Integer), -stopThreadSafely(), SearchForSSIDCallbacks, -WiseFyCodes
        +WiseFyCodes, +WiseFySearch.findAccessPointByRegex(String, Integer, boolean) +
        +
      • +
      + + + +
        +
      • +

        searchForSSIDs

        +
        @Sync
        + @CallingThread
        + @WaitsForTimeout
        +public java.util.List<java.lang.String> searchForSSIDs(java.lang.String regexForSSID)
        +
        To search local networks and return the first one that contains a given ssid
        +
        +
        Parameters:
        +
        regexForSSID - The regex to be used to search for the ssid
        +
        Returns:
        +
        String|null - The first SSID that contains the search ssid (if any, else null)
        +
        +
      • +
      + + + + @@ -1587,7 +1821,7 @@

      searchForSSID

      @@ -203,7 +206,7 @@

      Method Summary

      boolean -quitSafely()  +quit()  void @@ -215,7 +218,7 @@

      Method Summary

      Methods inherited from class android.os.HandlerThread

      -getLooper, getThreadId, onLooperPrepared, quit, run +getLooper, getThreadId, onLooperPrepared, quitSafely, run
    - +
    • -

      quitSafely

      -
      public boolean quitSafely()
      +

      quit

      +
      public boolean quit()
      Overrides:
      -
      quitSafely in class android.os.HandlerThread
      +
      quit in class android.os.HandlerThread
    diff --git a/javadoc/com/isupatches/wisefy/threads/package-frame.html b/javadoc/com/isupatches/wisefy/threads/package-frame.html index 3f36b62e..8c6fac4c 100644 --- a/javadoc/com/isupatches/wisefy/threads/package-frame.html +++ b/javadoc/com/isupatches/wisefy/threads/package-frame.html @@ -2,9 +2,9 @@ - + com.isupatches.wisefy.threads (wisefy 2.0.0-BETA API) - + diff --git a/javadoc/com/isupatches/wisefy/threads/package-summary.html b/javadoc/com/isupatches/wisefy/threads/package-summary.html index df5d8a45..492633eb 100644 --- a/javadoc/com/isupatches/wisefy/threads/package-summary.html +++ b/javadoc/com/isupatches/wisefy/threads/package-summary.html @@ -2,9 +2,9 @@ - + com.isupatches.wisefy.threads (wisefy 2.0.0-BETA API) - + @@ -83,7 +83,11 @@

    Package com.isupatches.wisefy.threads

    WiseFyHandlerThread -  + +
    A Thread to use for all WiseFy background processing + + *NOTE* Must be cleaned!! WiseFy.dump()
    + diff --git a/javadoc/com/isupatches/wisefy/threads/package-tree.html b/javadoc/com/isupatches/wisefy/threads/package-tree.html index a68cc1d7..fb56a515 100644 --- a/javadoc/com/isupatches/wisefy/threads/package-tree.html +++ b/javadoc/com/isupatches/wisefy/threads/package-tree.html @@ -2,9 +2,9 @@ - + com.isupatches.wisefy.threads Class Hierarchy (wisefy 2.0.0-BETA API) - + diff --git a/javadoc/com/isupatches/wisefy/util/LogUtil.html b/javadoc/com/isupatches/wisefy/util/LogUtil.html index b3d70cc6..7b069369 100644 --- a/javadoc/com/isupatches/wisefy/util/LogUtil.html +++ b/javadoc/com/isupatches/wisefy/util/LogUtil.html @@ -2,9 +2,9 @@ - + LogUtil (wisefy 2.0.0-BETA API) - + @@ -205,13 +205,13 @@

    isLoggable

    Checks to see given a TAG, log level, and if logging is enabled if logging should occur
    Parameters:
    -
    tag - - The tag to be used for the log
    -
    level - - The level of logging (i.e Log.DEBUG, Log.WARN, Log.ERROR, etc)
    -
    loggingEnabled - - If the instances of WiseFy has logging set to always be enabled - - Log
    +
    tag - The tag to be used for the log
    +
    level - The level of logging (i.e Log.DEBUG, Log.WARN, Log.ERROR, etc)
    +
    loggingEnabled - If the instances of WiseFy has logging set to always be enabled
    Returns:
    -
    boolean - if logging is enabled
    +
    boolean - True if logging should occur based off level and other factors
    +
    See Also:
    +
    Log
    diff --git a/javadoc/com/isupatches/wisefy/util/ManagerUtil.html b/javadoc/com/isupatches/wisefy/util/ManagerUtil.html index 1cad0987..f1e32d49 100644 --- a/javadoc/com/isupatches/wisefy/util/ManagerUtil.html +++ b/javadoc/com/isupatches/wisefy/util/ManagerUtil.html @@ -2,9 +2,9 @@ - + ManagerUtil (wisefy 2.0.0-BETA API) - + @@ -49,7 +49,7 @@ @@ -189,12 +190,11 @@

    getConnectivityManager

    To get a Connectivity manger instance from an activity's context.
    Parameters:
    -
    context - - The context to use to retrieve a connectivity manager via getSystemService
    +
    context - The context to use to retrieve a connectivity manager via getSystemService
    Returns:
    ConnectivityManager|null
    See Also:
    -
    ConnectivityManager, -WiseFy
    +
    ConnectivityManager
    @@ -208,12 +208,11 @@

    getWiFiManager

    To get a WiFi manger instance from an activity's context.
    Parameters:
    -
    context - - The context to use to retrieve a wifi manager via getSystemService
    +
    context - The context to use to retrieve a wifi manager via getSystemService
    Returns:
    WifiManager|null
    See Also:
    -
    WifiManager, -WiseFy
    +
    WifiManager
    @@ -245,7 +244,7 @@

    getWiFiManager

    @@ -150,7 +151,7 @@

    Methods inherited from class java.lang.Object

    @@ -130,17 +131,23 @@

    Method Summary

    android.net.wifi.WifiConfiguration -generateOpenNetworkConfiguration(java.lang.String ssid)  +generateOpenNetworkConfiguration(java.lang.String ssid) +
    To generate a configuration for an open network
    + android.net.wifi.WifiConfiguration generateWEPNetworkConfiguration(java.lang.String ssid, - java.lang.String password)  + java.lang.String password) +
    To generate a configuration for a WEP network
    + android.net.wifi.WifiConfiguration generateWPA2NetworkConfiguration(java.lang.String ssid, - java.lang.String password)  + java.lang.String password) +
    To generate a configuration for a WPA2 network
    + static WifiConfigurationUtil @@ -188,6 +195,13 @@

    getInstance

  • generateOpenNetworkConfiguration

    public android.net.wifi.WifiConfiguration generateOpenNetworkConfiguration(java.lang.String ssid)
    +
    To generate a configuration for an open network
    +
    +
    Parameters:
    +
    ssid - The ssid for the open network's configuration
    +
    Returns:
    +
    WifiConfiguration - The open network configuration
    +
  • @@ -198,6 +212,14 @@

    generateOpenNetworkConfiguration

    generateWEPNetworkConfiguration

    public android.net.wifi.WifiConfiguration generateWEPNetworkConfiguration(java.lang.String ssid,
                                                                               java.lang.String password)
    +
    To generate a configuration for a WEP network
    +
    +
    Parameters:
    +
    ssid - The ssid for the WEP network's configuration
    +
    password - The password for the WEP networks configuration
    +
    Returns:
    +
    WifiConfiguration - The WEP network configuration
    +
    @@ -208,6 +230,14 @@

    generateWEPNetworkConfiguration

    generateWPA2NetworkConfiguration

    public android.net.wifi.WifiConfiguration generateWPA2NetworkConfiguration(java.lang.String ssid,
                                                                                java.lang.String password)
    +
    To generate a configuration for a WPA2 network
    +
    +
    Parameters:
    +
    ssid - The ssid for the WPA2 network's configuration
    +
    password - The password for the WPA2 networks configuration
    +
    Returns:
    +
    WifiConfiguration - The WPA2 network configuration
    +
    diff --git a/javadoc/com/isupatches/wisefy/util/package-frame.html b/javadoc/com/isupatches/wisefy/util/package-frame.html index cd4817db..cdcfa40c 100644 --- a/javadoc/com/isupatches/wisefy/util/package-frame.html +++ b/javadoc/com/isupatches/wisefy/util/package-frame.html @@ -2,9 +2,9 @@ - + com.isupatches.wisefy.util (wisefy 2.0.0-BETA API) - + @@ -15,6 +15,7 @@

    Classes

    diff --git a/javadoc/com/isupatches/wisefy/util/package-summary.html b/javadoc/com/isupatches/wisefy/util/package-summary.html index 6079a601..281f753d 100644 --- a/javadoc/com/isupatches/wisefy/util/package-summary.html +++ b/javadoc/com/isupatches/wisefy/util/package-summary.html @@ -2,9 +2,9 @@ - + com.isupatches.wisefy.util (wisefy 2.0.0-BETA API) - + @@ -89,15 +89,27 @@

    Package com.isupatches.wisefy.util

    ManagerUtil -  + +
    Manager helper class
    + -SSIDUtil -  +SleepUtil + +
    A helper class for shared wait logic
    + +SSIDUtil + +
    A helper class to manipulate the string value for SSIDs
    + + + WifiConfigurationUtil -  + +
    A helper class to generate WifiConfigurations
    + diff --git a/javadoc/com/isupatches/wisefy/util/package-tree.html b/javadoc/com/isupatches/wisefy/util/package-tree.html index 382a3ec9..6ecf251c 100644 --- a/javadoc/com/isupatches/wisefy/util/package-tree.html +++ b/javadoc/com/isupatches/wisefy/util/package-tree.html @@ -2,9 +2,9 @@ - + com.isupatches.wisefy.util Class Hierarchy (wisefy 2.0.0-BETA API) - + @@ -82,6 +82,7 @@

    Class Hierarchy

    diff --git a/javadoc/constant-values.html b/javadoc/constant-values.html index 34a9dbc5..612e31ff 100644 --- a/javadoc/constant-values.html +++ b/javadoc/constant-values.html @@ -2,9 +2,9 @@ - + Constant Field Values (wisefy 2.0.0-BETA API) - + @@ -125,6 +125,20 @@

    com.isupatches.*

    + + +public static final java.lang.String +EAP +"EAP" + + + + +public static final java.lang.String +PSK +"PSK" + + public static final java.lang.String diff --git a/javadoc/deprecated-list.html b/javadoc/deprecated-list.html index b5fce2de..e0c203b0 100644 --- a/javadoc/deprecated-list.html +++ b/javadoc/deprecated-list.html @@ -2,9 +2,9 @@ - + Deprecated List (wisefy 2.0.0-BETA API) - + diff --git a/javadoc/help-doc.html b/javadoc/help-doc.html index 810758b4..f08c0b7a 100644 --- a/javadoc/help-doc.html +++ b/javadoc/help-doc.html @@ -2,9 +2,9 @@ - + API Help (wisefy 2.0.0-BETA API) - + diff --git a/javadoc/index-all.html b/javadoc/index-all.html index 9fcb38e4..e3918089 100644 --- a/javadoc/index-all.html +++ b/javadoc/index-all.html @@ -2,9 +2,9 @@ - + Index (wisefy 2.0.0-BETA API) - + @@ -68,11 +68,15 @@ -
    A C D E F G I L M N O Q R S T W  +
    A B C D E F G I L M N O P Q R S T W 

    A

    +
    accessPointFound(ScanResult) - Method in interface com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks
    +
     
    +
    accessPointNotFound() - Method in interface com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks
    +
     
    addOpenNetwork(String) - Method in class com.isupatches.wisefy.WiseFy
    To add an open network to the user's configured network list (synchronously)
    @@ -112,6 +116,16 @@

    A

    Async - Annotation Type in com.isupatches.wisefy.annotations
     
    + + + +

    B

    +
    +
    brains(Context) - Constructor for class com.isupatches.wisefy.WiseFy.brains
    +
    +
    Mandatory - The public constructor for the builder that requires a context
    +
    +
    @@ -193,12 +207,18 @@

    D

     
    disconnectFromCurrentNetworkWiseFyFailure(Integer) - Method in interface com.isupatches.wisefy.callbacks.DisconnectFromCurrentNetworkCallbacks
     
    +
    dump() - Method in class com.isupatches.wisefy.WiseFy
    +
    +
    Used to cleanup the thread started by WiseFy
    +

    E

    +
    EAP - Static variable in class com.isupatches.wisefy.constants.Capabilities
    +
     
    enableWifi() - Method in class com.isupatches.wisefy.WiseFy
    To enable Wifi on a user's device
    @@ -235,6 +255,8 @@

    F

     
    failureRemovingNetwork() - Method in interface com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks
     
    +
    foundNetworks(List<ScanResult>) - Method in interface com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks
    +
     
    @@ -242,11 +264,17 @@

    F

    G

    generateOpenNetworkConfiguration(String) - Method in class com.isupatches.wisefy.util.WifiConfigurationUtil
    -
     
    +
    +
    To generate a configuration for an open network
    +
    generateWEPNetworkConfiguration(String, String) - Method in class com.isupatches.wisefy.util.WifiConfigurationUtil
    -
     
    +
    +
    To generate a configuration for a WEP network
    +
    generateWPA2NetworkConfiguration(String, String) - Method in class com.isupatches.wisefy.util.WifiConfigurationUtil
    -
     
    +
    +
    To generate a configuration for a WPA2 network
    +
    getConnectivityManager(Context) - Method in class com.isupatches.wisefy.util.ManagerUtil
    To get a Connectivity manger instance from an activity's context.
    @@ -303,6 +331,14 @@

    G

     
    getNearbyAccessPointsWiseFyFailure(Integer) - Method in interface com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks
     
    +
    getRSSI(String, boolean, int) - Method in class com.isupatches.wisefy.WiseFy
    +
     
    +
    getRSSI(String, boolean, int, GetRSSICallbacks) - Method in class com.isupatches.wisefy.WiseFy
    +
     
    +
    GetRSSICallbacks - Interface in com.isupatches.wisefy.callbacks
    +
     
    +
    getRSSIWiseFyFailure(Integer) - Method in interface com.isupatches.wisefy.callbacks.GetRSSICallbacks
    +
     
    getSavedNetwork(String) - Method in class com.isupatches.wisefy.WiseFy
    To search for and return a saved WiFiConfiguration given an SSID
    @@ -321,18 +357,22 @@

    G

    To retrieve a list of saved networks on a user's device
    +
    getSavedNetworks(String) - Method in class com.isupatches.wisefy.WiseFy
    +
     
    +
    getSavedNetworks(String, GetSavedNetworksCallbacks) - Method in class com.isupatches.wisefy.WiseFy
    +
     
    GetSavedNetworksCallbacks - Interface in com.isupatches.wisefy.callbacks
     
    getSavedNetworksWiseFyFailure(Integer) - Method in interface com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks
     
    getSavedNetworkWiseFyFailure(Integer) - Method in interface com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks
     
    -
    getSmarts() - Method in class com.isupatches.wisefy.WiseFy.withContext
    +
    getSmarts() - Method in class com.isupatches.wisefy.WiseFy.brains
    Mandatory - To build and return a WiseFy instance - Must be called after withContext - WiseFy.withContext
    + Must be called after brains + WiseFy.brains
    getWiFiManager(Context) - Method in class com.isupatches.wisefy.util.ManagerUtil
    @@ -360,10 +400,7 @@

    I

    isDeviceConnectedToWifiNetwork() - Method in class com.isupatches.wisefy.WiseFy
    -
    To check if the device is connected to a wifi network - - Uses - NetworkTypes
    +
    To check if the device is connected to a wifi network
    isLoggable(String, int, boolean) - Static method in class com.isupatches.wisefy.util.LogUtil
    @@ -381,10 +418,18 @@

    I

    To check if a given network is 5gHz
    +
    isNetworkEAP(ScanResult) - Method in class com.isupatches.wisefy.WiseFy
    +
    +
    To check and return if a network is a EAP network
    +
    isNetworkInConfigurationList(String) - Method in class com.isupatches.wisefy.WiseFy
    To check if an SSID is in the list of configured networks
    +
    isNetworkPSK(ScanResult) - Method in class com.isupatches.wisefy.WiseFy
    +
    +
    To check and return if a network is a PSK network
    +
    isNetworkSecure(ScanResult) - Method in class com.isupatches.wisefy.WiseFy
    To check and return if a network is secure (WEP/WPA/WPA2 capabilities)
    @@ -411,7 +456,7 @@

    I

    L

    -
    logging(boolean) - Method in class com.isupatches.wisefy.WiseFy.withContext
    +
    logging(boolean) - Method in class com.isupatches.wisefy.WiseFy.brains
    Optional - Builder method that enables/disables logging for a WiseWy instance
    @@ -428,11 +473,11 @@

    L

    M

    ManagerUtil - Class in com.isupatches.wisefy.util
    -
     
    +
    +
    Manager helper class
    +
    MAX_FREQUENCY_5GHZ - Static variable in class com.isupatches.wisefy.WiseFy
     
    -
    mConnectivityManager - Variable in class com.isupatches.wisefy.WiseFy
    -
     
    MIN_FREQUENCY_5GHZ - Static variable in class com.isupatches.wisefy.WiseFy
     
    MISSING_PARAMETER - Static variable in class com.isupatches.wisefy.constants.WiseFyCodes
    @@ -441,8 +486,6 @@

    M

     
    MOBILE - Static variable in class com.isupatches.wisefy.constants.NetworkTypes
     
    -
    mWifiManager - Variable in class com.isupatches.wisefy.WiseFy
    -
     
    @@ -451,18 +494,22 @@

    N

    NETWORK_ALREADY_CONFIGURED - Static variable in class com.isupatches.wisefy.constants.WiseFyCodes
     
    -
    networkNotFound() - Method in interface com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks
    -
     
    networkNotFoundToConnectTo() - Method in interface com.isupatches.wisefy.callbacks.ConnectToNetworkCallbacks
     
    networkNotFoundToRemove() - Method in interface com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks
     
    +
    networkNotFoundToRetrieveRSSI() - Method in interface com.isupatches.wisefy.callbacks.GetRSSICallbacks
    +
     
    networkRemoved() - Method in interface com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks
     
    NetworkTypes - Class in com.isupatches.wisefy.constants
     
    NetworkTypes() - Constructor for class com.isupatches.wisefy.constants.NetworkTypes
     
    +
    noNetworksFound() - Method in interface com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks
    +
     
    +
    noSSIDsFound() - Method in interface com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks
    +
     
    @@ -472,12 +519,20 @@

    O

    openNetworkAdded(WifiConfiguration) - Method in interface com.isupatches.wisefy.callbacks.AddOpenNetworkCallbacks
     
    + + + +

    P

    +
    +
    PSK - Static variable in class com.isupatches.wisefy.constants.Capabilities
    +
     
    +

    Q

    -
    quitSafely() - Method in class com.isupatches.wisefy.threads.WiseFyHandlerThread
    +
    quit() - Method in class com.isupatches.wisefy.threads.WiseFyHandlerThread
     
    @@ -503,16 +558,38 @@

    R

     
    retrievedNearbyAccessPoints(List<ScanResult>) - Method in interface com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks
     
    +
    retrievedRSSI(Integer) - Method in interface com.isupatches.wisefy.callbacks.GetRSSICallbacks
    +
     
    retrievedSavedNetwork(WifiConfiguration) - Method in interface com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks
     
    retrievedSavedNetworks(List<WifiConfiguration>) - Method in interface com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks
     
    +
    retrievedSSIDs(List<String>) - Method in interface com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks
    +
     

    S

    +
    savedNetworkNotFound() - Method in interface com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks
    +
     
    +
    searchForAccessPoint(String, int, boolean) - Method in class com.isupatches.wisefy.WiseFy
    +
     
    +
    searchForAccessPoint(String, int, boolean, SearchForAccessPointCallbacks) - Method in class com.isupatches.wisefy.WiseFy
    +
     
    +
    SearchForAccessPointCallbacks - Interface in com.isupatches.wisefy.callbacks
    +
     
    +
    searchForAccessPoints(String, boolean) - Method in class com.isupatches.wisefy.WiseFy
    +
     
    +
    searchForAccessPoints(String, boolean, SearchForAccessPointsCallbacks) - Method in class com.isupatches.wisefy.WiseFy
    +
     
    +
    SearchForAccessPointsCallbacks - Interface in com.isupatches.wisefy.callbacks
    +
     
    +
    searchForAccessPointsWiseFyFailure(Integer) - Method in interface com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks
    +
     
    +
    searchForAccessPointWiseFyFailure(Integer) - Method in interface com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks
    +
     
    searchForSSID(String, int) - Method in class com.isupatches.wisefy.WiseFy
    To search local networks and return the first one that contains a given ssid
    @@ -523,14 +600,38 @@

    S

    SearchForSSIDCallbacks - Interface in com.isupatches.wisefy.callbacks
     
    +
    searchForSSIDs(String) - Method in class com.isupatches.wisefy.WiseFy
    +
    +
    To search local networks and return the first one that contains a given ssid
    +
    +
    searchForSSIDs(String, SearchForSSIDsCallbacks) - Method in class com.isupatches.wisefy.WiseFy
    +
    +
    To search local networks and return the first one that contains a given ssid
    +
    +
    SearchForSSIDsCallbacks - Interface in com.isupatches.wisefy.callbacks
    +
     
    +
    searchForSSIDsWiseFyFailure(Integer) - Method in interface com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks
    +
     
    searchForSSIDWiseFyFailure(Integer) - Method in interface com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks
     
    +
    sleep(long) - Static method in class com.isupatches.wisefy.util.SleepUtil
    +
    +
    Used to wait for a given amount of time (in milliseconds)
    +
    +
    SleepUtil - Class in com.isupatches.wisefy.util
    +
    +
    A helper class for shared wait logic
    +
    +
    SleepUtil() - Constructor for class com.isupatches.wisefy.util.SleepUtil
    +
     
    ssidFound(String) - Method in interface com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks
     
    ssidNotFound() - Method in interface com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks
     
    SSIDUtil - Class in com.isupatches.wisefy.util
    -
     
    +
    +
    A helper class to manipulate the string value for SSIDs
    +
    start() - Method in class com.isupatches.wisefy.threads.WiseFyHandlerThread
     
    Sync - Annotation Type in com.isupatches.wisefy.annotations
    @@ -560,16 +661,19 @@

    W

    WIFI_MANAGER_FAILURE - Static variable in class com.isupatches.wisefy.WiseFy
     
    WifiConfigurationUtil - Class in com.isupatches.wisefy.util
    -
     
    +
    +
    A helper class to generate WifiConfigurations
    +
    wifiDisabled() - Method in interface com.isupatches.wisefy.callbacks.DisableWifiCallbacks
     
    wifiEnabled() - Method in interface com.isupatches.wisefy.callbacks.EnableWifiCallbacks
     
    WiseFy - Class in com.isupatches.wisefy
    -
    Main class to manipulate and query network settings on an Android device
    +
    Main class for WiseFy that provides a synchronous and asynchronous API to manipulate and query + for different parts of a device's wifi configuration and status.
    -
    WiseFy.withContext - Class in com.isupatches.wisefy
    +
    WiseFy.brains - Class in com.isupatches.wisefy
    Static class for builder pattern @@ -580,15 +684,15 @@

    W

    WiseFyCodes() - Constructor for class com.isupatches.wisefy.constants.WiseFyCodes
     
    WiseFyHandlerThread - Class in com.isupatches.wisefy.threads
    -
     
    +
    +
    A Thread to use for all WiseFy background processing + + *NOTE* Must be cleaned!! WiseFy.dump()
    +
    WiseFyHandlerThread(String, boolean) - Constructor for class com.isupatches.wisefy.threads.WiseFyHandlerThread
     
    WiseFyThread - Annotation Type in com.isupatches.wisefy.annotations
     
    -
    withContext(Context) - Constructor for class com.isupatches.wisefy.WiseFy.withContext
    -
    -
    Mandatory - The public constructor for the builder that requires a context
    -
    WPA - Static variable in class com.isupatches.wisefy.constants.Capabilities
     
    WPA2 - Static variable in class com.isupatches.wisefy.constants.Capabilities
    @@ -596,7 +700,7 @@

    W

    wpa2NetworkAdded(WifiConfiguration) - Method in interface com.isupatches.wisefy.callbacks.AddWPA2NetworkCallbacks
     
    -A C D E F G I L M N O Q R S T W  +A B C D E F G I L M N O P Q R S T W 
    diff --git a/javadoc/index.html b/javadoc/index.html index db896ea5..5478c4a2 100644 --- a/javadoc/index.html +++ b/javadoc/index.html @@ -2,7 +2,7 @@ - + wisefy 2.0.0-BETA API diff --git a/javadoc/overview-summary.html b/javadoc/overview-summary.html index 166819be..1fb11068 100644 --- a/javadoc/overview-summary.html +++ b/javadoc/overview-summary.html @@ -2,9 +2,9 @@ - + Overview (wisefy 2.0.0-BETA API) - + diff --git a/javadoc/overview-tree.html b/javadoc/overview-tree.html index ca93a302..78c49fdd 100644 --- a/javadoc/overview-tree.html +++ b/javadoc/overview-tree.html @@ -2,9 +2,9 @@ - + Class Hierarchy (wisefy 2.0.0-BETA API) - + @@ -89,6 +89,7 @@

    Class Hierarchy

  • com.isupatches.wisefy.util.LogUtil
  • com.isupatches.wisefy.util.ManagerUtil
  • com.isupatches.wisefy.constants.NetworkTypes
  • +
  • com.isupatches.wisefy.util.SleepUtil
  • com.isupatches.wisefy.util.SSIDUtil
  • java.lang.Thread (implements java.lang.Runnable)
  • @@ -118,10 +119,14 @@

    Interface Hierarchy

  • com.isupatches.wisefy.callbacks.GetCurrentNetworkCallbacks
  • com.isupatches.wisefy.callbacks.GetFrequencyCallbacks
  • com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks
  • +
  • com.isupatches.wisefy.callbacks.GetRSSICallbacks
  • com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks
  • com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks
  • com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks
  • +
  • com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks
  • +
  • com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks
  • com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks
  • +
  • com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks
  • Annotation Type Hierarchy

      diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.java index 094e7788..76073241 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.java @@ -12,6 +12,7 @@ import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -26,36 +27,35 @@ public AddOpenNetworkTests() { @Test public void noCallbacks_failure() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); - int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID); - assertEquals(WiseFy.WIFI_MANAGER_FAILURE, result); + assertEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_failure_nullSSIDParam() { - int result = mWiseFy.addOpenNetwork(null); - assertEquals(WiseFyCodes.MISSING_PARAMETER, result); + assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addOpenNetwork(null)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_failure_missingPrerequisite() { missingPrerequisite(); - int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID); - assertEquals(WiseFyCodes.MISSING_PREREQUISITE, result); + assertEquals(WiseFyCodes.MISSING_PREREQUISITE, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_success() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); - int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID); - assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result); + assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_success_alreadyConfigured() { networkAlreadyInConfigurationList(); - - int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID); - assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, result); + assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test @@ -63,7 +63,8 @@ public void callbacks_failure() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); - verify(mockCallbacks, timeout(3000)).failureAddingOpenNetwork(WiseFy.WIFI_MANAGER_FAILURE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureAddingOpenNetwork(WiseFy.WIFI_MANAGER_FAILURE); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test @@ -71,6 +72,7 @@ public void callbacks_failure_nullCallback() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); try { mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -80,13 +82,15 @@ public void callbacks_failure_nullCallback() { public void callbacks_failure_nullSSIDParam() { AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); mWiseFy.addOpenNetwork(null, mockCallbacks); - verify(mockCallbacks, timeout(3000)).addOpenNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addOpenNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void callbacks_failure_nullSSIDParam_nullCallback() { try { mWiseFy.addOpenNetwork(null, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -97,7 +101,8 @@ public void callbacks_failure_missingPrerequisite() { missingPrerequisite(); AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); - verify(mockCallbacks, timeout(3000)).addOpenNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addOpenNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test @@ -105,6 +110,7 @@ public void callbacks_failure_missingPrerequisite_nullCallback() { missingPrerequisite(); try { mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -115,7 +121,8 @@ public void callbacks_success() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); - verify(mockCallbacks, timeout(3000)).openNetworkAdded(any(WifiConfiguration.class)); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).openNetworkAdded(any(WifiConfiguration.class)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test @@ -123,6 +130,7 @@ public void callbacks_success_nullCallback() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); try { mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -134,7 +142,8 @@ public void callbacks_success_alreadyConfigured() { AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); - verify(mockCallbacks, timeout(3000)).addOpenNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addOpenNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test @@ -143,6 +152,7 @@ public void callbacks_success_alreadyConfigured_nullCallback() { try { mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.java index 78225517..d637cf7d 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.java @@ -13,6 +13,7 @@ import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -27,42 +28,41 @@ public AddWEPNetworkTests() { @Test public void noCallbacks_failure() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); - int result = mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); - assertEquals(WiseFy.WIFI_MANAGER_FAILURE, result); + assertEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_failure_nullPasswordParam() { - int result = mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, null); - assertEquals(WiseFyCodes.MISSING_PARAMETER, result); + assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, null)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_failure_nullSSIDParam() { - int result = mWiseFy.addWEPNetwork(null, WEP_NETWORK_PASSWORD); - assertEquals(WiseFyCodes.MISSING_PARAMETER, result); + assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWEPNetwork(null, WEP_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_failure_missingPrerequisite() { missingPrerequisite(); - int result = mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); - assertEquals(WiseFyCodes.MISSING_PREREQUISITE, result); + assertEquals(WiseFyCodes.MISSING_PREREQUISITE, mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_success() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); - int result = mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); - assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result); + assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_success_alreadyConfigured() { networkAlreadyInConfigurationList(); - - int result = mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); - assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, result); + assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test @@ -70,7 +70,8 @@ public void callbacks_failure() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks); - verify(mockCallbacks, timeout(3000)).failureAddingWEPNetwork(WiseFy.WIFI_MANAGER_FAILURE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureAddingWEPNetwork(WiseFy.WIFI_MANAGER_FAILURE); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test @@ -79,6 +80,7 @@ public void callbacks_failure_nullCallback() { try { mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -88,13 +90,15 @@ public void callbacks_failure_nullCallback() { public void callbacks_failure_nullPasswordParam() { AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, null, mockCallbacks); - verify(mockCallbacks, timeout(2000)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void callbacks_failure_nullPasswordParam_nullCallback() { try { mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, null, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -104,13 +108,15 @@ public void callbacks_failure_nullPasswordParam_nullCallback() { public void callbacks_failure_nullSSIDParam() { AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); mWiseFy.addWEPNetwork(null, WEP_NETWORK_PASSWORD, mockCallbacks); - verify(mockCallbacks, timeout(2000)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void callbacks_failure_nullSSIDParam_nullCallback() { try { mWiseFy.addWEPNetwork(null, WEP_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -121,7 +127,8 @@ public void callbacks_failure_missingPrerequisite() { missingPrerequisite(); AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks); - verify(mockCallbacks, timeout(2000)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test @@ -130,6 +137,7 @@ public void callbacks_failure_missingPrerequisite_nullCallback() { try { mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -140,7 +148,8 @@ public void callbacks_success() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks); - verify(mockCallbacks, timeout(2000)).wepNetworkAdded(any(WifiConfiguration.class)); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wepNetworkAdded(any(WifiConfiguration.class)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test @@ -149,6 +158,7 @@ public void callbacks_success_nullCallback() { try { mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -160,7 +170,8 @@ public void callbacks_success_alreadyConfigured() { AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks); - verify(mockCallbacks, timeout(2000)).addWEPNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test @@ -169,6 +180,7 @@ public void callbacks_success_alreadyConfigured_nullCallback() { try { mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.java index 663d343f..4e3d2480 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.java @@ -13,6 +13,7 @@ import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -27,42 +28,41 @@ public AddWPA2NetworkTests() { @Test public void noCallbacks_failure() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); - int result = mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); - assertEquals(WiseFy.WIFI_MANAGER_FAILURE, result); + assertEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_failure_nullPasswordParam() { - int result = mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, null); - assertEquals(WiseFyCodes.MISSING_PARAMETER, result); + assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, null)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void anoCallbacks_failure_nullSSIDParam() { - int result = mWiseFy.addWPA2Network(null, WPA2_NETWORK_PASSWORD); - assertEquals(WiseFyCodes.MISSING_PARAMETER, result); + assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWPA2Network(null, WPA2_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_failure_missingPrerequisite() { missingPrerequisite(); - int result = mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); - assertEquals(WiseFyCodes.MISSING_PREREQUISITE, result); + assertEquals(WiseFyCodes.MISSING_PREREQUISITE, mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_success() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); - int result = mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); - assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result); + assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test public void noCallbacks_success_alreadyConfigured() { networkAlreadyInConfigurationList(); - - int result = mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); - assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, result); + assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test @@ -70,7 +70,8 @@ public void callbacks_failure() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks); - verify(mockCallbacks, timeout(2000)).failureAddingWPA2Network(WiseFy.WIFI_MANAGER_FAILURE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureAddingWPA2Network(WiseFy.WIFI_MANAGER_FAILURE); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test @@ -78,6 +79,7 @@ public void callbacks_failure_nullCallback() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); try { mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -87,13 +89,15 @@ public void callbacks_failure_nullCallback() { public void callbacks_failure_nullPasswordParam() { AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, null, mockCallbacks); - verify(mockCallbacks, timeout(2000)).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test public void callbacks_failure_nullPasswordParam_nullCallback() { try { mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, null, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -103,13 +107,14 @@ public void callbacks_failure_nullPasswordParam_nullCallback() { public void callbacks_failure_nullSSIDParam() { AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); mWiseFy.addWPA2Network(null, WPA2_NETWORK_PASSWORD, mockCallbacks); - verify(mockCallbacks, timeout(2000)).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mockCallbacks, never()).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); } @Test public void callbacks_failure_nullSSIDParam_nullCallback() { try { mWiseFy.addWPA2Network(null, WPA2_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -121,7 +126,8 @@ public void callbacks_failure_missingPrerequisite() { AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks); - verify(mockCallbacks, timeout(2000)).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test @@ -130,6 +136,7 @@ public void callbacks_failure_missingPrerequisite_nullCallback() { try { mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -140,7 +147,8 @@ public void callbacks_success() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks); - verify(mockCallbacks, timeout(2000)).wpa2NetworkAdded(any(WifiConfiguration.class)); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wpa2NetworkAdded(any(WifiConfiguration.class)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); } @Test @@ -149,6 +157,7 @@ public void callbacks_success_nullCallback() { try { mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } @@ -160,7 +169,8 @@ public void callbacks_success_alreadyConfigured() { AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks); - verify(mockCallbacks, timeout(2000)).addWPA2NetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWPA2NetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } @Test @@ -169,6 +179,7 @@ public void callbacks_success_alreadyConfigured_nullCallback() { try { mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); } catch (NullPointerException npe) { fail(); } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/BaseTestClass.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/BaseTestClass.java index 688bb483..070ec0d0 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/BaseTestClass.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/BaseTestClass.java @@ -4,8 +4,6 @@ import android.app.Activity; import android.content.Intent; import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.support.test.rule.ActivityTestRule; import com.isupatches.wisefy.base.TestActivity; @@ -22,12 +20,14 @@ public abstract class BaseTestClass extends ActivityTestRule @Rule public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(TestActivity.class); - protected ConnectivityManager mMockConnectivityManager; + ConnectivityManager mMockConnectivityManager; protected WifiManager mMockWiFiManager; protected WiseFy mWiseFy; + protected static final Integer VERIFICATION_TIMEOUT = 2000; + public BaseTestClass(Class activityClass) { super(activityClass); } @@ -55,7 +55,7 @@ public void tearDown() { * HELPERS */ - void missingPrerequisite() { + public void missingPrerequisite() { WiseFyPrerequisites mockPrereqs = mock(WiseFyPrerequisites.class); mWiseFy.mWiseFyPrerequisites = mockPrereqs; when(mockPrereqs.hasPrerequisites()).thenReturn(false); @@ -64,22 +64,10 @@ void missingPrerequisite() { void networkAlreadyInConfigurationList() { WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); mWiseFy.mWiseFySearch = mockWiseFySearch; - when(mockWiseFySearch.checkIfNetworkInConfigurationList(anyString())).thenReturn(true); - } - - void setupConnection(String ssid, boolean isAvailable, boolean isConnected) { - WifiInfo mockWiFiInfo = mock(WifiInfo.class); - when(mockWiFiInfo.getSSID()).thenReturn(ssid); - - when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWiFiInfo); - NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); - - when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mockNetworkInfo); - when(mockNetworkInfo.isAvailable()).thenReturn(isAvailable); - when(mockNetworkInfo.isConnected()).thenReturn(isConnected); + when(mockWiseFySearch.isNetworkASavedConfiguration(anyString())).thenReturn(true); } - void setManagers() { + private void setManagers() { WiseFyPrerequisites mockPrereqs = mock(WiseFyPrerequisites.class); mWiseFy.mWiseFyPrerequisites = mockPrereqs; mWiseFy.mWiseFySearch.mWiseFyPrerequisites = mockPrereqs; diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.java index 13c9e9ff..e5893856 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.java @@ -9,9 +9,11 @@ import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -25,15 +27,15 @@ public ConnectToNetworkTests() { @Test public void noCallbacks_failure_nullSSIDParam() { - boolean result = mWiseFy.connectToNetwork(null, 1); - assertEquals(false, result); + assertEquals(false, mWiseFy.connectToNetwork(null, 1)); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } @Test public void noCallbacks_failure_missingPrerequisites() { missingPrerequisite(); - boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1); - assertEquals(false, result); + assertEquals(false, mWiseFy.connectToNetwork(TEST_SSID, 1)); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } @Test @@ -42,8 +44,8 @@ public void noCallbacks_failure_noSavedNetwork() { mWiseFy.mWiseFySearch = mockWiseFySearch; when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); - boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1); - assertEquals(false, result); + assertEquals(false, mWiseFy.connectToNetwork(TEST_SSID, 1)); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } @Test @@ -58,8 +60,8 @@ public void noCallbacks_failure() { mWiseFy.mWiseFyConnection = mockWiseFyConnection; when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(false); - boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1); - assertEquals(false, result); + assertEquals(false, mWiseFy.connectToNetwork(TEST_SSID, 1)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); } @Test @@ -74,8 +76,8 @@ public void noCallbacks_success() { mWiseFy.mWiseFyConnection = mockWiseFyConnection; when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(true); - boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1); - assertEquals(true, result); + assertEquals(true, mWiseFy.connectToNetwork(TEST_SSID, 1)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); } @Test @@ -83,12 +85,14 @@ public void callbacks_failure_nullSSIDParam() { ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); mWiseFy.connectToNetwork(null, 1, mockCallbacks); verify(mockCallbacks, timeout(3000)).connectToNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } @Test public void callbacks_failure_nullSSIDParam_nullCallback() { try { mWiseFy.connectToNetwork(null, 1, null); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } catch (NullPointerException npe) { fail(); } @@ -100,6 +104,7 @@ public void callbacks_failure_missingPrerequisites() { ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); verify(mockCallbacks, timeout(3000)).connectToNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } @Test @@ -107,6 +112,7 @@ public void callbacks_failure_missingPrerequisites_nullCallback() { missingPrerequisite(); try { mWiseFy.connectToNetwork(TEST_SSID, 1, null); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } catch (NullPointerException npe) { fail(); } @@ -120,7 +126,8 @@ public void callbacks_failure_noSavedNetwork() { ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); - verify(mockCallbacks, timeout(3000)).networkNotFoundToConnectTo(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).networkNotFoundToConnectTo(); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } @Test @@ -131,6 +138,7 @@ public void callbacks_failure_noSavedNetwork_nullCallback() { try { mWiseFy.connectToNetwork(TEST_SSID, 1, null); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } catch (NullPointerException npe) { fail(); } @@ -150,7 +158,8 @@ public void callbacks_failure() { ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); - verify(mockCallbacks, timeout(3000)).failureConnectingToNetwork(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureConnectingToNetwork(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); } @Test @@ -167,6 +176,7 @@ public void callbacks_failure_nullCallback() { try { mWiseFy.connectToNetwork(TEST_SSID, 1, null); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } catch (NullPointerException npe) { fail(); } @@ -186,7 +196,8 @@ public void callbacks_success() { ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); - verify(mockCallbacks, timeout(3000)).connectedToNetwork(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).connectedToNetwork(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); } @Test @@ -203,6 +214,7 @@ public void callbacks_success_nullCallback() { try { mWiseFy.connectToNetwork(TEST_SSID, 1, null); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); } catch (NullPointerException npe) { fail(); } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.java index 89e060e2..9afbe40d 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.java @@ -24,24 +24,22 @@ public DisableWifiTests() { @Test public void noCallbacks_failure() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); - boolean result = mWiseFy.disableWifi(); - verify(mMockWiFiManager, timeout(2000)).setWifiEnabled(false); - assertEquals(false, result); + assertEquals(false, mWiseFy.disableWifi()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); } @Test public void noCallbacks_failure_missingPrerequisite() { missingPrerequisite(); - boolean result = mWiseFy.disableWifi(); - assertEquals(false, result); + assertEquals(false, mWiseFy.disableWifi()); + verify(mMockWiFiManager, never()).setWifiEnabled(false); } @Test public void noCallbacks_success() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); - boolean result = mWiseFy.disableWifi(); - verify(mMockWiFiManager, timeout(2000)).setWifiEnabled(false); - assertEquals(true, result); + assertEquals(true, mWiseFy.disableWifi()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); } @Test @@ -49,8 +47,8 @@ public void callbacks_failure() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); DisableWifiCallbacks mockCallbacks = mock(DisableWifiCallbacks.class); mWiseFy.disableWifi(mockCallbacks); - verify(mMockWiFiManager, timeout(2000)).setWifiEnabled(false); - verify(mockCallbacks, timeout(2000)).failureDisablingWifi(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureDisablingWifi(); } @Test @@ -58,6 +56,7 @@ public void callbacks_failure_nullCallback() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); try { mWiseFy.disableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(false); } catch (NullPointerException npe) { fail(); } @@ -69,7 +68,7 @@ public void callbacks_failure_missingPrerequisite() { DisableWifiCallbacks mockCallbacks = mock(DisableWifiCallbacks.class); mWiseFy.disableWifi(mockCallbacks); verify(mMockWiFiManager, never()).setWifiEnabled(false); - verify(mockCallbacks, timeout(2000)).disableWifiWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).disableWifiWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); } @Test @@ -77,6 +76,7 @@ public void callbacks_failure_missingPrerequisite_nullCallback() { missingPrerequisite(); try { mWiseFy.disableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(false); } catch (NullPointerException npe) { fail(); } @@ -87,8 +87,8 @@ public void callbacks_success() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); DisableWifiCallbacks mockCallbacks = mock(DisableWifiCallbacks.class); mWiseFy.disableWifi(mockCallbacks); - verify(mMockWiFiManager, timeout(2000)).setWifiEnabled(false); - verify(mockCallbacks, timeout(2000)).wifiDisabled(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wifiDisabled(); } @Test @@ -96,6 +96,7 @@ public void callbacks_success_nullCallback() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); try { mWiseFy.disableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(false); } catch (NullPointerException npe) { fail(); } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.java index 4856b84f..d26f12a4 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.java @@ -23,24 +23,22 @@ public DisconnectFromCurrentNetworkTests() { @Test public void noCallbacks_failure() { when(mMockWiFiManager.disconnect()).thenReturn(false); - boolean result = mWiseFy.disconnectFromCurrentNetwork(); - verify(mMockWiFiManager, timeout(2000)).disconnect(); - assertEquals(false, result); + assertEquals(false, mWiseFy.disconnectFromCurrentNetwork()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); } @Test public void noCallbacks_failure_missingPrerequisite() { missingPrerequisite(); - boolean result = mWiseFy.disconnectFromCurrentNetwork(); - assertEquals(false, result); + assertEquals(false, mWiseFy.disconnectFromCurrentNetwork()); + verify(mMockWiFiManager, never()).disconnect(); } @Test public void noCallbacks_success() { when(mMockWiFiManager.disconnect()).thenReturn(true); - boolean result = mWiseFy.disconnectFromCurrentNetwork(); - verify(mMockWiFiManager, timeout(2000)).disconnect(); - assertEquals(true, result); + assertEquals(true, mWiseFy.disconnectFromCurrentNetwork()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); } @Test @@ -48,8 +46,8 @@ public void callbacks_failure() { when(mMockWiFiManager.disconnect()).thenReturn(false); DisconnectFromCurrentNetworkCallbacks mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks.class); mWiseFy.disconnectFromCurrentNetwork(mockCallbacks); - verify(mMockWiFiManager, timeout(2000)).disconnect(); - verify(mockCallbacks, timeout(2000)).failureDisconnectingFromCurrentNetwork(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureDisconnectingFromCurrentNetwork(); } @Test @@ -57,6 +55,7 @@ public void callbacks_failure_nullCallback() { when(mMockWiFiManager.disconnect()).thenReturn(false); try { mWiseFy.disconnectFromCurrentNetwork(null); + verify(mMockWiFiManager, never()).disconnect(); } catch (NullPointerException npe) { fail(); } @@ -68,7 +67,7 @@ public void callbacks_failure_missingPrerequisite() { DisconnectFromCurrentNetworkCallbacks mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks.class); mWiseFy.disconnectFromCurrentNetwork(mockCallbacks); verify(mMockWiFiManager, never()).disconnect(); - verify(mockCallbacks, timeout(2000)).disconnectFromCurrentNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).disconnectFromCurrentNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); } @Test @@ -76,6 +75,7 @@ public void callbacks_failure_missingPrerequisite_nullCallback() { missingPrerequisite(); try { mWiseFy.disconnectFromCurrentNetwork(null); + verify(mMockWiFiManager, never()).disconnect(); } catch (NullPointerException npe) { fail(); } @@ -86,8 +86,8 @@ public void callbacks_success() { when(mMockWiFiManager.disconnect()).thenReturn(true); DisconnectFromCurrentNetworkCallbacks mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks.class); mWiseFy.disconnectFromCurrentNetwork(mockCallbacks); - verify(mMockWiFiManager, timeout(2000)).disconnect(); - verify(mockCallbacks, timeout(2000)).disconnectedFromCurrentNetwork(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).disconnectedFromCurrentNetwork(); } @Test @@ -95,6 +95,7 @@ public void callbacks_success_nullCallback() { when(mMockWiFiManager.disconnect()).thenReturn(true); try { mWiseFy.disconnectFromCurrentNetwork(null); + verify(mMockWiFiManager, never()).disconnect(); } catch (NullPointerException npe) { fail(); } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.java index dbba6a54..f962b3e7 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.java @@ -24,24 +24,22 @@ public EnableWifiTests() { @Test public void noCallbacks_failure() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); - boolean result = mWiseFy.enableWifi(); - verify(mMockWiFiManager, timeout(2000)).setWifiEnabled(true); - assertEquals(false, result); + assertEquals(false, mWiseFy.enableWifi()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); } @Test public void noCallbacks_failure_missingPrerequisite() { missingPrerequisite(); - boolean result = mWiseFy.enableWifi(); - assertEquals(false, result); + assertEquals(false, mWiseFy.enableWifi()); + verify(mMockWiFiManager, never()).setWifiEnabled(true); } @Test public void noCallbacks_success() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); - boolean result = mWiseFy.enableWifi(); - verify(mMockWiFiManager, timeout(2000)).setWifiEnabled(true); - assertEquals(true, result); + assertEquals(true, mWiseFy.enableWifi()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); } @Test @@ -49,8 +47,8 @@ public void callbacks_failure() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); EnableWifiCallbacks mockCallbacks = mock(EnableWifiCallbacks.class); mWiseFy.enableWifi(mockCallbacks); - verify(mMockWiFiManager, timeout(2000)).setWifiEnabled(true); - verify(mockCallbacks, timeout(2000)).failureEnablingWifi(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureEnablingWifi(); } @Test @@ -58,6 +56,7 @@ public void callbacks_failure_nullCallback() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); try { mWiseFy.enableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(true); } catch (NullPointerException npe) { fail(); } @@ -69,7 +68,7 @@ public void callbacks_failure_missingPrerequisite() { EnableWifiCallbacks mockCallbacks = mock(EnableWifiCallbacks.class); mWiseFy.enableWifi(mockCallbacks); verify(mMockWiFiManager, never()).setWifiEnabled(true); - verify(mockCallbacks, timeout(2000)).enableWifiWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).enableWifiWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); } @Test @@ -77,6 +76,7 @@ public void callbacks_failure_missingPrerequisite_nullCallback() { missingPrerequisite(); try { mWiseFy.enableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(true); } catch (NullPointerException npe) { fail(); } @@ -87,8 +87,8 @@ public void callbacks_success() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); EnableWifiCallbacks mockCallbacks = mock(EnableWifiCallbacks.class); mWiseFy.enableWifi(mockCallbacks); - verify(mMockWiFiManager, timeout(2000)).setWifiEnabled(true); - verify(mockCallbacks, timeout(2000)).wifiEnabled(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wifiEnabled(); } @Test @@ -96,6 +96,7 @@ public void callbacks_success_nullCallback() { when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); try { mWiseFy.enableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(true); } catch (NullPointerException npe) { fail(); } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.java index 37fffb81..6acdfd66 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.java @@ -10,6 +10,7 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.fail; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -25,6 +26,7 @@ public GetCurrentNetworkTests() { public void noCallbacks_failure_missingPrerequisite() { missingPrerequisite(); assertEquals(null, mWiseFy.getCurrentNetwork()); + verify(mMockWiFiManager, never()).getConnectionInfo(); } @Test @@ -34,6 +36,7 @@ public void noCallbacks_success() { when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); assertEquals(TEST_SSID, mWiseFy.getCurrentNetwork().getSSID()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConnectionInfo(); } @Test @@ -41,7 +44,8 @@ public void callbacks_failure_missingPrerequisite() { missingPrerequisite(); GetCurrentNetworkCallbacks mockCallbacks = mock(GetCurrentNetworkCallbacks.class); mWiseFy.getCurrentNetwork(mockCallbacks); - verify(mockCallbacks, timeout(2000)).getCurrentNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getCurrentNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getConnectionInfo(); } @Test @@ -49,6 +53,7 @@ public void callbacks_failure_missingPrerequisite_nullCallbacks() { missingPrerequisite(); try { mWiseFy.getCurrentNetwork(null); + verify(mMockWiFiManager, never()).getConnectionInfo(); } catch (NullPointerException npe) { fail(); } @@ -63,6 +68,7 @@ public void callbacks_success() { GetCurrentNetworkCallbacks mockCallbacks = mock(GetCurrentNetworkCallbacks.class); mWiseFy.getCurrentNetwork(mockCallbacks); verify(mockCallbacks, timeout(2000)).retrievedCurrentNetwork(mockWifiInfo); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConnectionInfo(); } @Test @@ -73,6 +79,7 @@ public void callbacks_success_nullCallback() { try { mWiseFy.getCurrentNetwork(null); + verify(mMockWiFiManager, never()).getConnectionInfo(); } catch (NullPointerException npe) { fail(); } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.java index 0ef87313..3963809e 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.java @@ -37,6 +37,7 @@ public void noCallbacks_getFrequency_currentNetwork_success() { when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); assertEquals(TEST_NETWORK_FREQUENCY_24GHZ, (int) mWiseFy.getFrequency()); + verify(mockWifiInfo, timeout(VERIFICATION_TIMEOUT)).getFrequency(); } } @@ -70,7 +71,8 @@ public void callbacks_getFrequency_currentNetwork_success() { when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); GetFrequencyCallbacks mockCallbacks = mock(GetFrequencyCallbacks.class); mWiseFy.getFrequency(mockCallbacks); - verify(mockCallbacks, timeout(2000)).retrievedFrequency(TEST_NETWORK_FREQUENCY_24GHZ); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedFrequency(TEST_NETWORK_FREQUENCY_24GHZ); + verify(mockWifiInfo, timeout(VERIFICATION_TIMEOUT)).getFrequency(); } } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.java index c0cb22cb..df07acfc 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.java @@ -14,6 +14,7 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.fail; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -28,13 +29,15 @@ public GetNearbyAccessPointsTests() { @Test public void noCallbacks_failure_missingPrerequisite_filterDuplicates_false() { missingPrerequisite(); - mWiseFy.getNearbyAccessPoints(false); + assertEquals(null, mWiseFy.getNearbyAccessPoints(false)); + verify(mMockWiFiManager, never()).getScanResults(); } @Test public void noCallbacks_failure_missingPrerequisite_filterDuplicates_true() { missingPrerequisite(); - mWiseFy.getNearbyAccessPoints(true); + assertEquals(null, mWiseFy.getNearbyAccessPoints(true)); + verify(mMockWiFiManager, never()).getScanResults(); } @Test @@ -53,6 +56,7 @@ public void noCallbacks_success_filterDuplicates_false() { List accessPoints = mWiseFy.getNearbyAccessPoints(false); assertEquals(accessPoints, scanResults); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); } @Test @@ -73,6 +77,7 @@ public void noCallbacks_success_filterDuplicates_true() { List accessPoints = mWiseFy.getNearbyAccessPoints(true); assertEquals(accessPoints, scanResults); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); } @Test @@ -80,7 +85,8 @@ public void callbacks_failure_missingPrerequisite_filterDuplicates_false() { missingPrerequisite(); GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); mWiseFy.getNearbyAccessPoints(false, mockCallbacks); - verify(mockCallbacks, timeout(3000)).getNearbyAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getNearbyAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getScanResults(); } @Test @@ -88,6 +94,7 @@ public void callbacks_failure_missingPrerequisite_filterDuplicates_false_nullCal missingPrerequisite(); try { mWiseFy.getNearbyAccessPoints(false, null); + verify(mMockWiFiManager, never()).getScanResults(); } catch (NullPointerException npe) { fail(); } @@ -99,6 +106,7 @@ public void callbacks_failure_missingPrerequisite_filterDuplicates_true() { GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); mWiseFy.getNearbyAccessPoints(true, mockCallbacks); verify(mockCallbacks, timeout(3000)).getNearbyAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getScanResults(); } @Test @@ -106,6 +114,7 @@ public void callbacks_failure_missingPrerequisite_filterDuplicates_true_nullCall missingPrerequisite(); try { mWiseFy.getNearbyAccessPoints(true, null); + verify(mMockWiFiManager, never()).getScanResults(); } catch (NullPointerException npe) { fail(); } @@ -127,7 +136,8 @@ public void callbacks_success_filterDuplicates_false() { GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); mWiseFy.getNearbyAccessPoints(false, mockCallbacks); - verify(mockCallbacks, timeout(3000)).retrievedNearbyAccessPoints(scanResults); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedNearbyAccessPoints(scanResults); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); } @Test @@ -146,6 +156,7 @@ public void callbacks_success_filterDuplicates_false_nullCallback() { try { mWiseFy.getNearbyAccessPoints(false, null); + verify(mMockWiFiManager, never()).getScanResults(); } catch (NullPointerException npe) { fail(); } @@ -169,7 +180,8 @@ public void callbacks_success_filterDuplicates_true() { GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); mWiseFy.getNearbyAccessPoints(true, mockCallbacks); - verify(mockCallbacks, timeout(3000)).retrievedNearbyAccessPoints(scanResults); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedNearbyAccessPoints(scanResults); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); } @Test @@ -190,6 +202,7 @@ public void callbacks_success_filterDuplicates_true_nullCallback() { try { mWiseFy.getNearbyAccessPoints(true, null); + verify(mMockWiFiManager, never()).getScanResults(); } catch (NullPointerException npe) { fail(); } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworkTests.java index b4d5738e..1bbe3a07 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworkTests.java @@ -2,15 +2,15 @@ import android.net.wifi.WifiConfiguration; -import com.isupatches.wisefy.BaseTestClass; import com.isupatches.wisefy.base.TestActivity; import com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks; import com.isupatches.wisefy.constants.WiseFyCodes; import org.junit.Test; -import java.util.ArrayList; -import java.util.List; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -23,5 +23,122 @@ public GetSavedNetworkTests() { } @Test - public void no + public void noCallbacks_failure_nullSSIDParam() { + assertEquals(null, mWiseFy.getSavedNetwork(null)); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getSavedNetwork(TEST_SSID)); + } + + @Test + public void noCallbacks_failure() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + assertEquals(null, mWiseFy.getSavedNetwork(TEST_SSID)); + } + + @Test + public void noCallbacks_success() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + assertEquals(wiFiConfiguration, mWiseFy.getSavedNetwork(TEST_SSID)); + } + + @Test + public void callbacks_failure_nullSSIDParam() { + GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); + mWiseFy.getSavedNetwork(null, mockCallbacks); + verify(mockCallbacks, timeout(2000)).getSavedNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_nullSSIDParam_nullCallback() { + try { + mWiseFy.getSavedNetwork(null, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); + mWiseFy.getSavedNetwork(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(2000)).getSavedNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.getSavedNetwork(TEST_SSID, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); + mWiseFy.getSavedNetwork(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(2000)).savedNetworkNotFound(); + } + + @Test + public void callbacks_failure_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + try { + mWiseFy.getSavedNetwork(TEST_SSID, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); + mWiseFy.getSavedNetwork(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(2000)).retrievedSavedNetwork(wiFiConfiguration); + } + + @Test + public void callbacks_success_nullCallback() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + try { + mWiseFy.getSavedNetwork(TEST_SSID, null); + } catch (NullPointerException npe) { + fail(); + } + } } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.java index 34c2e2e9..82716210 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.java @@ -1,88 +1,161 @@ -//package com.isupatches.wisefy.test; -// -// -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import com.isupatches.wisefy.test.base.BaseTestClass; -//import com.isupatches.wisefy.test.base.TestActivity; -//import org.junit.Test; -//import java.util.ArrayList; -//import java.util.List; -//import static com.isupatches.wisefy.test.base.TestUtils.TEST_SSID; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class GetSavedNetworksTests extends BaseTestClass { -// -// public GetSavedNetworksTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_nullWifiManager() { -// setManagersToNull(); -// assertEquals(null, mWiseFy.getSavedNetworks()); -// } -// -// @Test -// public void noCallbacks_success() { -// setManagers(); -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// -// assertEquals(wifiList, mWiseFy.getSavedNetworks()); -// } -// -// @Test -// public void callbacks_failure_nullWifiManager() { -// setManagersToNull(); -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(mockCallbacks); -// verify(mockCallbacks, timeout(2000)).getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_nullWifiManager_nullCallback() { -// setManagersToNull(); -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(null); -// verify(mockCallbacks, never()).getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_success() { -// setManagers(); -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(mockCallbacks); -// verify(mockCallbacks, timeout(2000)).retrievedSavedNetworks(wifiList); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// setManagers(); -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(null); -// verify(mockCallbacks, never()).retrievedSavedNetworks(wifiList); -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiConfiguration; +import com.isupatches.wisefy.base.TestActivity; +import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import java.util.ArrayList; +import java.util.List; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class GetSavedNetworksTests extends BaseTestClass { + + public GetSavedNetworksTests() { + super(TestActivity.class); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getSavedNetworks()); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } + + @Test + public void noCallbacks_success() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + assertEquals(wifiList, mWiseFy.getSavedNetworks()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks((GetSavedNetworksCallbacks) null); + verify(mockCallbacks, never()).getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } + + @Test + public void callbacks_success() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedSavedNetworks(wifiList); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); + } + + @Test + public void callbacks_success_nullCallback() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks((GetSavedNetworksCallbacks)null); + verify(mockCallbacks, never()).retrievedSavedNetworks(wifiList); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } + + @Test + public void callbacks_failure_withRegex_missingPrerequisite() { + missingPrerequisite(); + + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } + + @Test + public void noCallbacks_failure_withRegex_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getSavedNetworks(TEST_SSID)); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } + + @Test + public void noCallbacks_success_withRegex() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + assertEquals(wifiList, mWiseFy.getSavedNetworks(TEST_SSID)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); + } + + @Test + public void callbacks_failure_withRegex_missingPrerequisite_nullCallback() { + missingPrerequisite(); + + try{ + mWiseFy.getSavedNetworks(TEST_SSID, null); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_withRegex() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedSavedNetworks(wifiList); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); + } + + @Test + public void callbacks_success_withRegex_nullCallbacks() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + try { + mWiseFy.getSavedNetworks(TEST_SSID, null); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.java index 0751063b..0e5622c8 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.java @@ -1,111 +1,102 @@ -//package com.isupatches.wisefy.test; -// -// -//import android.net.wifi.WifiInfo; -//import android.os.Build; -//import com.isupatches.wisefy.test.base.BaseTestClass; -//import com.isupatches.wisefy.test.base.TestActivity; -//import org.junit.Test; -//import static com.isupatches.wisefy.test.base.TestUtils.TEST_NETWORK_FREQUENCY_5GHZ; -//import static com.isupatches.wisefy.test.base.TestUtils.TEST_NETWORK_FREQUENCY_ABOVE_5GHZ; -//import static com.isupatches.wisefy.test.base.TestUtils.TEST_NETWORK_FREQUENCY_BELOW_5GHZ; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.when; -// -// -//public class IsNetwork5gHzTests extends BaseTestClass { -// -// public IsNetwork5gHzTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void currentNetwork_failure_above5ghz() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// setManagers(); -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_ABOVE_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(false, mWiseFy.isNetwork5gHz()); -// } -// } -// -// @Test -// public void currentNetwork_failure_below5ghz() { -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// setManagers(); -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_BELOW_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(false, mWiseFy.isNetwork5gHz()); -// } -// } -// -// @Test -// public void currentNetwork_failure_null() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// setManagers(); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); -// assertEquals(false, mWiseFy.isNetwork5gHz()); -// } -// } -// -// @Test -// public void currentNetwork_success() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// setManagers(); -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(true, mWiseFy.isNetwork5gHz()); -// } -// } -// -// @Test -// public void provideWifiInfo_failure_above5ghz() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// setManagers(); -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_ABOVE_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(false, mWiseFy.isNetwork5gHz(mockWifiInfo)); -// } -// } -// -// @Test -// public void provideWifiInfo_failure_below5ghz() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// setManagers(); -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_BELOW_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(false, mWiseFy.isNetwork5gHz(mockWifiInfo)); -// } -// } -// -// @Test -// public void provideWifiInfo_failure_null() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// setManagers(); -// assertEquals(false, mWiseFy.isNetwork5gHz(null)); -// } -// } -// -// @Test -// public void provideWifiInfo_success() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// setManagers(); -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(true, mWiseFy.isNetwork5gHz(mockWifiInfo)); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiInfo; +import android.os.Build; +import com.isupatches.wisefy.base.TestActivity; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_5GHZ; +import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_ABOVE_5GHZ; +import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_BELOW_5GHZ; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class IsNetwork5gHzTests extends BaseTestClass { + + public IsNetwork5gHzTests() { + super(TestActivity.class); + } + + @Test + public void currentNetwork_failure_above5ghz() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_ABOVE_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(false, mWiseFy.isNetwork5gHz()); + } + } + + @Test + public void currentNetwork_failure_below5ghz() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_BELOW_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(false, mWiseFy.isNetwork5gHz()); + } + } + + @Test + public void currentNetwork_failure_null() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); + assertEquals(false, mWiseFy.isNetwork5gHz()); + } + } + + @Test + public void currentNetwork_success() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(true, mWiseFy.isNetwork5gHz()); + } + } + + @Test + public void provideWifiInfo_failure_above5ghz() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_ABOVE_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(false, mWiseFy.isNetwork5gHz(mockWifiInfo)); + } + } + + @Test + public void provideWifiInfo_failure_below5ghz() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_BELOW_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(false, mWiseFy.isNetwork5gHz(mockWifiInfo)); + } + } + + @Test + public void provideWifiInfo_failure_null() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + assertEquals(false, mWiseFy.isNetwork5gHz(null)); + } + } + + @Test + public void provideWifiInfo_success() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(true, mWiseFy.isNetwork5gHz(mockWifiInfo)); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkInConfigurationListTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkInConfigurationListTests.java index be8d21a4..ee5bd639 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkInConfigurationListTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkInConfigurationListTests.java @@ -1,109 +1,99 @@ -//package com.isupatches.wisefy.test; -// -// -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.test.base.BaseTestClass; -//import com.isupatches.wisefy.test.base.TestActivity; -//import org.junit.Test; -//import java.util.ArrayList; -//import java.util.List; -//import static com.isupatches.wisefy.test.base.TestUtils.TEST_SSID; -//import static com.isupatches.wisefy.test.base.TestUtils.TEST_SSID2; -//import static com.isupatches.wisefy.test.base.TestUtils.TEST_SSID3; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.when; -// -// -//public class IsNetworkInConfigurationListTests extends BaseTestClass { -// -// public IsNetworkInConfigurationListTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure() { -// setManagers(); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void failure_multipleNetworks() { -// setManagers(); -// -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration wifiConfiguration1 = new WifiConfiguration(); -// wifiConfiguration1.SSID = TEST_SSID2; -// wifiList.add(wifiConfiguration1); -// -// WifiConfiguration wiFiConfiguration2 = new WifiConfiguration(); -// wiFiConfiguration2.SSID = TEST_SSID3; -// wifiList.add(wiFiConfiguration2); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void failure_noNetworks() { -// setManagers(); -// List wifiList = new ArrayList<>(); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void failure_nullSSID() { -// setManagers(); -// List wifiList = new ArrayList<>(); -// WifiConfiguration wifiConfiguration = new WifiConfiguration(); -// wifiConfiguration.SSID = null; -// wifiList.add(wifiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void failure_nullWifiConfiguration() { -// setManagers(); -// List wifiList = new ArrayList<>(); -// wifiList.add(0, null); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void failure_nullWifiManager() { -// setManagersToNull(); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void success() { -// setManagers(); -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(true, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void success_multipleNetworks() { -// setManagers(); -// -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration wifiConfiguration1 = new WifiConfiguration(); -// wifiConfiguration1.SSID = TEST_SSID; -// wifiList.add(wifiConfiguration1); -// -// WifiConfiguration wiFiConfiguration2 = new WifiConfiguration(); -// wiFiConfiguration2.SSID = TEST_SSID2; -// wifiList.add(wiFiConfiguration2); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(true, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiConfiguration; +import com.isupatches.wisefy.base.TestActivity; +import org.junit.Test; +import java.util.ArrayList; +import java.util.List; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID2; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID3; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + + +public class IsNetworkInConfigurationListTests extends BaseTestClass { + + public IsNetworkInConfigurationListTests() { + super(TestActivity.class); + } + + @Test + public void failure() { + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void failure_multipleNetworks() { + List wifiList = new ArrayList<>(); + + WifiConfiguration wifiConfiguration1 = new WifiConfiguration(); + wifiConfiguration1.SSID = TEST_SSID2; + wifiList.add(wifiConfiguration1); + + WifiConfiguration wiFiConfiguration2 = new WifiConfiguration(); + wiFiConfiguration2.SSID = TEST_SSID3; + wifiList.add(wiFiConfiguration2); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void failure_noNetworks() { + List wifiList = new ArrayList<>(); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void failure_nullSSID() { + List wifiList = new ArrayList<>(); + WifiConfiguration wifiConfiguration = new WifiConfiguration(); + wifiConfiguration.SSID = null; + wifiList.add(wifiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void failure_nullWifiConfiguration() { + List wifiList = new ArrayList<>(); + wifiList.add(0, null); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void failure_nmissingPrerequisite() { + missingPrerequisite(); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void success() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(true, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void success_multipleNetworks() { + List wifiList = new ArrayList<>(); + + WifiConfiguration wifiConfiguration1 = new WifiConfiguration(); + wifiConfiguration1.SSID = TEST_SSID; + wifiList.add(wifiConfiguration1); + + WifiConfiguration wiFiConfiguration2 = new WifiConfiguration(); + wiFiConfiguration2.SSID = TEST_SSID2; + wifiList.add(wiFiConfiguration2); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(true, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.java index 091871a0..942aa1ca 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.java @@ -12,6 +12,7 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -25,15 +26,15 @@ public RemoveNetworkTests() { @Test public void noCallbacks_failure_nullSSIDParam() { - boolean result = mWiseFy.removeNetwork(null); - assertEquals(false, result); + assertEquals(false, mWiseFy.removeNetwork(null)); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } @Test public void noCallbacks_failure_missingPrerequisites() { missingPrerequisite(); - boolean result = mWiseFy.removeNetwork(TEST_SSID); - assertEquals(false, result); + assertEquals(false, mWiseFy.removeNetwork(TEST_SSID)); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } @Test @@ -42,8 +43,8 @@ public void noCallbacks_failure_noSavedNetwork() { mWiseFy.mWiseFySearch = mockWiseFySearch; when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); - boolean result = mWiseFy.removeNetwork(TEST_SSID); - assertEquals(false, result); + assertEquals(false, mWiseFy.removeNetwork(TEST_SSID)); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } @Test @@ -56,8 +57,9 @@ public void noCallbacks_failure() { when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(false); - boolean result = mWiseFy.removeNetwork(TEST_SSID); - assertEquals(false, result); + assertEquals(false, mWiseFy.removeNetwork(TEST_SSID)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); + } @Test @@ -70,8 +72,8 @@ public void noCallbacks_success() { when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(true); - boolean result = mWiseFy.removeNetwork(TEST_SSID); - assertEquals(true, result); + assertEquals(true, mWiseFy.removeNetwork(TEST_SSID)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); } @Test @@ -79,12 +81,14 @@ public void callbacks_failure_nullSSIDParam() { RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); mWiseFy.removeNetwork(null, mockCallbacks); verify(mockCallbacks, timeout(3000)).removeNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } @Test public void callbacks_failure_nullSSIDParam_nullCallback() { try { mWiseFy.removeNetwork(null, null); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } catch (NullPointerException npe) { fail(); } @@ -95,7 +99,8 @@ public void callbacks_failure_missingPrerequisites() { missingPrerequisite(); RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); - verify(mockCallbacks, timeout(3000)).removeNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).removeNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } @Test @@ -103,6 +108,7 @@ public void callbacks_failure_missingPrerequisites_nullCallback() { missingPrerequisite(); try { mWiseFy.removeNetwork(TEST_SSID, null); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } catch (NullPointerException npe) { fail(); } @@ -116,7 +122,8 @@ public void callbacks_failure_noSavedNetwork() { RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); - verify(mockCallbacks, timeout(3000)).networkNotFoundToRemove(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).networkNotFoundToRemove(); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } @Test @@ -127,6 +134,7 @@ public void callbacks_failure_noSavedNetwork_nullCallback() { try { mWiseFy.removeNetwork(TEST_SSID, null); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } catch (NullPointerException npe) { fail(); } @@ -144,7 +152,8 @@ public void callbacks_failure() { RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); - verify(mockCallbacks, timeout(3000)).failureRemovingNetwork(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureRemovingNetwork(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); } @Test @@ -159,6 +168,7 @@ public void callbacks_failure_nullCallback() { try { mWiseFy.removeNetwork(TEST_SSID, null); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } catch (NullPointerException npe) { fail(); } @@ -176,7 +186,8 @@ public void callbacks_success() { RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); - verify(mockCallbacks, timeout(3000)).networkRemoved(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).networkRemoved(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); } @Test @@ -191,6 +202,7 @@ public void callbacks_success_nullCallback() { try { mWiseFy.removeNetwork(TEST_SSID, null); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); } catch (NullPointerException npe) { fail(); } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFySearchTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFySearchTests.java index 15462294..eb786da6 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFySearchTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFySearchTests.java @@ -21,6 +21,459 @@ public WiseFySearchTests() { super(TestActivity.class); } + /* + * findAccessPointByRegex tests + */ + + @Test + public void findAccessPointByRegex_failure_nullAccessPoints_takeHighest_false() { + when(mMockWiFiManager.getScanResults()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_nullAccessPoints_takeHighest_true() { + when(mMockWiFiManager.getScanResults()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_failure_emptyAccessPointList_takeHighest_false() { + when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_emptyAccessPointList_takeHighest_true() { + when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_failure_nullAccessPoint_takeHighest_false() { + List accessPoints = new ArrayList<>(); + accessPoints.add(null); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_nullAccessPoint_takeHighest_true() { + List accessPoints = new ArrayList<>(); + accessPoints.add(null); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_failure_nullSSID_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = null; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_nullSSID_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = null; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_failure_nonMatchingSSID_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = TEST_SSID2; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_nonMatchingSSID_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = TEST_SSID2; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_failure_multipleNonMatchingSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID2; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID3; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_multipleNnonMatchingSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1= mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID2; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID3; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_success_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_success_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_success_multipleSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID2; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint1, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_success_multipleSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID2; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint1, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_success_multipleSameSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint1, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_success_multipleSameSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint2, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + /* + * findAccessPointsMatchingRegex tests + */ + + @Test + public void findAccessPointsMatchingRegex_failure_nullAccessPoints_takeHighest_false() { + when(mMockWiFiManager.getScanResults()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nullAccessPoints_takeHighest_true() { + when(mMockWiFiManager.getScanResults()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_emptyAccessPointList_takeHighest_false() { + when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_emptyAccessPointList_takeHighest_true() { + when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nullAccessPoint_takeHighest_false() { + List accessPoints = new ArrayList<>(); + accessPoints.add(null); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nullAccessPoint_takeHighest_true() { + List accessPoints = new ArrayList<>(); + accessPoints.add(null); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nullSSID_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = null; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nullSSID_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = null; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nonMatchingSSID_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = TEST_SSID2; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nonMatchingSSID_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = TEST_SSID2; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_multipleNonMatchingSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID2; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID3; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_multipleNnonMatchingSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1= mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID2; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID3; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_success_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoints, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_success_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoints, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_success_multipleSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID2; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_success_multipleSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID2; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_success_multipleSameSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + expectedResults.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_success_multipleSameSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + expectedResults.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + /* * findSavedNetworkByRegex tests */ @@ -205,10 +658,9 @@ public void findSavedNetworksMatchingRegex_success_multipleSSIDs() { } /* - * findSSIDsMatchingRegex + * findSSIDsMatchingRegex tests */ - @Test public void findSSIDsMatchingRegex_failure_nullAccessPoints() { when(mMockWiFiManager.getScanResults()).thenReturn(null); @@ -241,59 +693,168 @@ public void findSSIDsMatchingRegex_failure_nullSSID() { when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); } -// -// @Test -// public void findSavedNetworksMatchingRegex_failure_nonMatchingSSID() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID2; -// wifiList.add(mWiFiConfiguration); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworksMatchingRegex_failure_multipleNonMatchingSSIDs() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration1 = new WifiConfiguration(); -// mWiFiConfiguration1.SSID = TEST_SSID2; -// wifiList.add(mWiFiConfiguration1); -// -// WifiConfiguration mWiFiConfiguration2 = new WifiConfiguration(); -// mWiFiConfiguration2.SSID = TEST_SSID3; -// wifiList.add(mWiFiConfiguration2); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworksMatchingRegex_success() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(wifiList, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworksMatchingRegex_success_multipleSSIDs() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration1 = new WifiConfiguration(); -// mWiFiConfiguration1.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration1); -// -// WifiConfiguration mWiFiConfiguration2 = new WifiConfiguration(); -// mWiFiConfiguration2.SSID = TEST_SSID2; -// wifiList.add(mWiFiConfiguration2); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(wifiList, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(".*Test.*")); -// } + + @Test + public void findSSIDsMatchingRegex_failure_nonMatchingSSID() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID2; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); + } + + @Test + public void findSSIDsMatchingRegex_failure_multipleNonMatchingSSIDs() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID2; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID3; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); + } + + @Test + public void findSSIDsMatchingRegex_success() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoints.add(accessPoint); + expectedResults.add(TEST_SSID); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); + } + + @Test + public void findSSIDsMatchingRegex_success_multipleSSIDs() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoints.add(accessPoint1); + expectedResults.add(TEST_SSID); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoints.add(accessPoint2); + expectedResults.add(TEST_SSID); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(".*Test.*")); + } + + /* + * isNetworkASavedConfiguration tests + */ + + @Test + public void isNetworkASavedConfiguration_failure() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); + assertEquals(false, mWiseFy.mWiseFySearch.isNetworkASavedConfiguration(TEST_SSID)); + } + + @Test + public void isNetworkASavedConfiguration_success() { + List wifiList = new ArrayList<>(); + + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(true, mWiseFy.mWiseFySearch.isNetworkASavedConfiguration(TEST_SSID)); + } + + /* + * removeEntriesWithLowerSignalStrength tests + */ + + @Test + public void removeEntriesWithLowerSignalStrength_differentSSIDs() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID2; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + expectedResults.add(accessPoint2); + + assertEquals(expectedResults, mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); + } + + @Test + public void removeEntriesWithLowerSignalStrength_sameSignalLevels() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -70; + accessPoints.add(accessPoint2); + + assertEquals(expectedResults, mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); + } + + @Test + public void removeEntriesWithLowerSignalStrength_accessPoint1Higher() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -50; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -70; + accessPoints.add(accessPoint2); + + assertEquals(expectedResults , mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); + } + + @Test + public void removeEntriesWithLowerSignalStrength_accessPoint2Higher() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoints.add(accessPoint1); + accessPoint1.level = -70; + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + expectedResults.add(accessPoint2); + + assertEquals(expectedResults , mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); + } } diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.java index d4737eeb..c435d876 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.java @@ -17,12 +17,14 @@ public WiseFyTests() { public void builder_loggingFalse() { WiseFy wiseFy = new WiseFy.brains(mActivityTestRule.getActivity()).logging(false).getSmarts(); assertEquals(false, wiseFy.mWiseFyConfiguration.isLoggingEnabled()); + assertEquals(false, wiseFy.isLoggingEnabled()); } @Test public void builder_loggingTrue() { WiseFy wiseFy = new WiseFy.brains(mActivityTestRule.getActivity()).logging(true).getSmarts(); assertEquals(true, wiseFy.mWiseFyConfiguration.isLoggingEnabled()); + assertEquals(true, wiseFy.isLoggingEnabled()); } @Test diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/base/TestUtils.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/base/TestUtils.java index 05109156..9295e18f 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/base/TestUtils.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/base/TestUtils.java @@ -1,10 +1,7 @@ package com.isupatches.wisefy.base; -import android.net.wifi.WifiConfiguration; import com.isupatches.wisefy.WiseFy; -import java.util.ArrayList; -import java.util.List; public class TestUtils { @@ -34,12 +31,4 @@ public class TestUtils { public static final int TEST_NETWORK_FREQUENCY_5GHZ = 5000; public static final int TEST_RSSI_LEVEL = -60; - - public static List getTestWifiConfiguration() { - List wifiList = new ArrayList<>(); - WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); - mWiFiConfiguration.SSID = TEST_SSID; - wifiList.add(mWiFiConfiguration); - return wifiList; - } } \ No newline at end of file diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/test/BuilderTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/test/BuilderTests.java new file mode 100644 index 00000000..d90be9cb --- /dev/null +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/test/BuilderTests.java @@ -0,0 +1,32 @@ +package com.isupatches.wisefy.test; + + +import android.support.test.rule.ActivityTestRule; +import com.isupatches.wisefy.WiseFy; +import com.isupatches.wisefy.base.TestActivity; +import org.junit.Rule; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + + +public class BuilderTests extends ActivityTestRule { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(TestActivity.class); + + public BuilderTests() { + super(TestActivity.class); + } + + @Test + public void builder_loggingFalse() { + WiseFy wiseFy = new WiseFy.brains(mActivityTestRule.getActivity()).logging(false).getSmarts(); + assertEquals(false, wiseFy.isLoggingEnabled()); + } + + @Test + public void builder_loggingTrue() { + WiseFy wiseFy = new WiseFy.brains(mActivityTestRule.getActivity()).logging(true).getSmarts(); + assertEquals(true, wiseFy.isLoggingEnabled()); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java new file mode 100644 index 00000000..9961dcc2 --- /dev/null +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java @@ -0,0 +1,608 @@ +package com.isupatches.wisefy.test; + + +import android.content.Intent; +import android.net.wifi.ScanResult; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; +import android.support.test.rule.ActivityTestRule; +import com.isupatches.wisefy.WiseFy; +import com.isupatches.wisefy.base.TestActivity; +import com.isupatches.wisefy.callbacks.AddOpenNetworkCallbacks; +import com.isupatches.wisefy.callbacks.AddWEPNetworkCallbacks; +import com.isupatches.wisefy.callbacks.AddWPA2NetworkCallbacks; +import com.isupatches.wisefy.callbacks.ConnectToNetworkCallbacks; +import com.isupatches.wisefy.callbacks.DisableWifiCallbacks; +import com.isupatches.wisefy.callbacks.DisconnectFromCurrentNetworkCallbacks; +import com.isupatches.wisefy.callbacks.EnableWifiCallbacks; +import com.isupatches.wisefy.callbacks.GetCurrentNetworkCallbacks; +import com.isupatches.wisefy.callbacks.GetFrequencyCallbacks; +import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks; +import com.isupatches.wisefy.callbacks.GetRSSICallbacks; +import com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks; +import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks; +import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks; +import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks; +import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks; +import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks; +import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import java.util.List; + +import static junit.framework.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + + +public class PublicApiVisibilityTests extends ActivityTestRule { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(TestActivity.class); + + private WiseFy mWiseFy; + + public PublicApiVisibilityTests() { + super(TestActivity.class); + } + + @Before + public void setUp() { + mActivityTestRule.launchActivity(new Intent()); + + mWiseFy = mock(WiseFy.class); + } + + @Test + public void addOpenNetwork_apis() { + mWiseFy.addOpenNetwork("TEST"); + verify(mWiseFy).addOpenNetwork(anyString()); + mWiseFy.addOpenNetwork("TEST", new AddOpenNetworkCallbacks() { + @Override + public void addOpenNetworkWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void failureAddingOpenNetwork(Integer wifiManagerReturnCode) { + + } + + @Override + public void openNetworkAdded(WifiConfiguration wifiConfiguration) { + + } + }); + verify(mWiseFy).addOpenNetwork(anyString(), any(AddOpenNetworkCallbacks.class)); + } + + @Test + public void addWEPNetwork_apis() { + mWiseFy.addWEPNetwork("WEP Network", "123456"); + verify(mWiseFy).addWEPNetwork(anyString(), anyString()); + mWiseFy.addWEPNetwork("WEP Network", "123456", new AddWEPNetworkCallbacks() { + @Override + public void addWEPNetworkWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void failureAddingWEPNetwork(Integer wifiManagerReturnCode) { + + } + + @Override + public void wepNetworkAdded(WifiConfiguration wifiConfiguration) { + + } + }); + verify(mWiseFy).addWEPNetwork(anyString(), anyString(), any(AddWEPNetworkCallbacks.class)); + } + + @Test + public void addWPA2Network_apis() { + mWiseFy.addWPA2Network("WPA2 Network", "12345678"); + verify(mWiseFy).addWPA2Network(anyString(), anyString()); + mWiseFy.addWPA2Network("WPA2 Network", "12345678", new AddWPA2NetworkCallbacks() { + @Override + public void addWPA2NetworkWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void failureAddingWPA2Network(Integer wifiManagerReturnCode) { + + } + + @Override + public void wpa2NetworkAdded(WifiConfiguration wifiConfiguration) { + + } + }); + verify(mWiseFy).addWPA2Network(anyString(), anyString(), any(AddWPA2NetworkCallbacks.class)); + } + + @Test + public void compareSignalLevel_api() { + mWiseFy.compareSignalLevel(-50, -65); + verify(mWiseFy).compareSignalLevel(anyInt(), anyInt()); + } + + @Test + public void calculateBars_api() { + mWiseFy.calculateBars(-50, 5); + verify(mWiseFy).calculateBars(anyInt(), anyInt()); + } + + @Test + public void connectToNetwork_apis() { + mWiseFy.connectToNetwork("SSID to connect to", 3000); + verify(mWiseFy).connectToNetwork(anyString(), anyInt()); + mWiseFy.connectToNetwork("SSID to connect", 3000, new ConnectToNetworkCallbacks() { + @Override + public void connectedToNetwork() { + + } + + @Override + public void connectToNetworkWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void failureConnectingToNetwork() { + + } + + @Override + public void networkNotFoundToConnectTo() { + + } + }); + verify(mWiseFy).connectToNetwork(anyString(), anyInt(), any(ConnectToNetworkCallbacks.class)); + } + + @Test + public void disableWifi_apis() { + mWiseFy.disableWifi(); + verify(mWiseFy).disableWifi(); + mWiseFy.disableWifi(new DisableWifiCallbacks() { + @Override + public void disableWifiWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void failureDisablingWifi() { + + } + + @Override + public void wifiDisabled() { + + } + }); + verify(mWiseFy).disableWifi(any(DisableWifiCallbacks.class)); + } + + @Test + public void disconnectFromCurrentNetwork_apis() { + mWiseFy.disconnectFromCurrentNetwork(); + verify(mWiseFy).disconnectFromCurrentNetwork(); + mWiseFy.disconnectFromCurrentNetwork(new DisconnectFromCurrentNetworkCallbacks() { + @Override + public void disconnectedFromCurrentNetwork() { + + } + + @Override + public void disconnectFromCurrentNetworkWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void failureDisconnectingFromCurrentNetwork() { + + } + }); + verify(mWiseFy).disconnectFromCurrentNetwork(any(DisconnectFromCurrentNetworkCallbacks.class)); + } + + @Test + public void enableWifi_apis() { + mWiseFy.enableWifi(); + verify(mWiseFy).enableWifi(); + mWiseFy.enableWifi(new EnableWifiCallbacks() { + @Override + public void enableWifiWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void failureEnablingWifi() { + + } + + @Override + public void wifiEnabled() { + + } + }); + verify(mWiseFy).enableWifi(any(EnableWifiCallbacks.class)); + } + + @Test + public void getCurrentNetwork_apis() { + mWiseFy.getCurrentNetwork(); + verify(mWiseFy).getCurrentNetwork(); + mWiseFy.getCurrentNetwork(new GetCurrentNetworkCallbacks() { + @Override + public void getCurrentNetworkWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void retrievedCurrentNetwork(WifiInfo currentNetwork) { + + } + }); + verify(mWiseFy).getCurrentNetwork(any(GetCurrentNetworkCallbacks.class)); + } + + @Test + public void getFrequency_apis() { + mWiseFy.getFrequency(); + verify(mWiseFy).getFrequency(); + mWiseFy.getFrequency(new GetFrequencyCallbacks() { + @Override + public void failureGettingFrequency() { + + } + + @Override + public void getFrequencyWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void retrievedFrequency(int frequency) { + + } + }); + verify(mWiseFy).getFrequency(any(GetFrequencyCallbacks.class)); + + mWiseFy.getFrequency(mock(WifiInfo.class)); + verify(mWiseFy).getFrequency(any(WifiInfo.class)); + mWiseFy.getFrequency(mock(WifiInfo.class), new GetFrequencyCallbacks() { + @Override + public void failureGettingFrequency() { + + } + + @Override + public void getFrequencyWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void retrievedFrequency(int frequency) { + + } + }); + verify(mWiseFy).getFrequency(any(WifiInfo.class), any(GetFrequencyCallbacks.class)); + } + + @Test + public void getNearbyAccessPoints_apis() { + mWiseFy.getNearbyAccessPoints(true); + verify(mWiseFy).getNearbyAccessPoints(anyBoolean()); + mWiseFy.getNearbyAccessPoints(true, new GetNearbyAccessPointsCallbacks() { + @Override + public void getNearbyAccessPointsWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void retrievedNearbyAccessPoints(List nearbyAccessPoints) { + + } + }); + verify(mWiseFy).getNearbyAccessPoints(anyBoolean(), any(GetNearbyAccessPointsCallbacks.class)); + } + + @Test + public void getRSSI_apis() { + mWiseFy.getRSSI("SSID", true, 1000); + verify(mWiseFy).getRSSI(anyString(), anyBoolean(), anyInt()); + mWiseFy.getRSSI("SSID", true, 1000, new GetRSSICallbacks() { + @Override + public void retrievedRSSI(Integer rssi) { + + } + + @Override + public void networkNotFoundToRetrieveRSSI() { + + } + + @Override + public void getRSSIWiseFyFailure(Integer wisefyReturnCode) { + + } + }); + verify(mWiseFy).getRSSI(anyString(), anyBoolean(), anyInt(), any(GetRSSICallbacks.class)); + } + + @Test + public void getSavedNetwork_apis() { + mWiseFy.getSavedNetwork("SSID"); + verify(mWiseFy).getSavedNetwork(anyString()); + mWiseFy.getSavedNetwork("SSID", new GetSavedNetworkCallbacks() { + @Override + public void getSavedNetworkWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void savedNetworkNotFound() { + + } + + @Override + public void retrievedSavedNetwork(WifiConfiguration savedNetwork) { + + } + }); + verify(mWiseFy).getSavedNetwork(anyString(), any(GetSavedNetworkCallbacks.class)); + } + + @Test + public void getSavedNetworks_apis() { + mWiseFy.getSavedNetworks(); + verify(mWiseFy).getSavedNetworks(); + mWiseFy.getSavedNetworks(new GetSavedNetworksCallbacks() { + @Override + public void getSavedNetworksWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void retrievedSavedNetworks(List savedNetworks) { + + } + }); + verify(mWiseFy).getSavedNetworks(any(GetSavedNetworksCallbacks.class)); + + mWiseFy.getSavedNetworks("SSID"); + verify(mWiseFy).getSavedNetworks(anyString()); + mWiseFy.getSavedNetworks("SSID", new GetSavedNetworksCallbacks() { + @Override + public void getSavedNetworksWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void retrievedSavedNetworks(List savedNetworks) { + + } + }); + verify(mWiseFy).getSavedNetworks(anyString(), any(GetSavedNetworksCallbacks.class)); + } + + @Test + public void isDeviceConnectedToMobileNetwork_apis() { + mWiseFy.isDeviceConnectedToMobileNetwork(); + verify(mWiseFy).isDeviceConnectedToMobileNetwork(); + } + + @Test + public void isDeviceConnectedToMobileOrWifiNetwork_apis() { + mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(); + verify(mWiseFy).isDeviceConnectedToMobileOrWifiNetwork(); + } + + @Test + public void isDeviceConnectedToSSID_apis() { + mWiseFy.isDeviceConnectedToSSID("SSID"); + verify(mWiseFy).isDeviceConnectedToSSID(anyString()); + } + + @Test + public void isDeviceConnectedToWifiNetwork_apis() { + mWiseFy.isDeviceConnectedToWifiNetwork(); + verify(mWiseFy).isDeviceConnectedToWifiNetwork(); + } + + @Test + public void isNetwork5gHz_apis() { + mWiseFy.isNetwork5gHz(); + verify(mWiseFy).isNetwork5gHz(); + + mWiseFy.isNetwork5gHz(mock(WifiInfo.class)); + verify(mWiseFy).isNetwork5gHz(any(WifiInfo.class)); + } + + @Test + public void isNetworkInConfigurationList_api() { + mWiseFy.isNetworkInConfigurationList("SSID"); + verify(mWiseFy).isNetworkInConfigurationList(anyString()); + } + + @Test + public void isNetworkEAP_api() { + mWiseFy.isNetworkEAP(mock(ScanResult.class)); + verify(mWiseFy).isNetworkEAP(any(ScanResult.class)); + } + + @Test + public void isNetworkPSK_api() { + mWiseFy.isNetworkPSK(mock(ScanResult.class)); + verify(mWiseFy).isNetworkPSK(any(ScanResult.class)); + } + + @Test + public void iisNetworkSecure_api() { + mWiseFy.isNetworkSecure(mock(ScanResult.class)); + verify(mWiseFy).isNetworkSecure(any(ScanResult.class)); + } + + @Test + public void isNetworkWEP_api() { + mWiseFy.isNetworkWEP(mock(ScanResult.class)); + verify(mWiseFy).isNetworkWEP(any(ScanResult.class)); + } + + @Test + public void isNetworkWPA_api() { + mWiseFy.isNetworkWPA(mock(ScanResult.class)); + verify(mWiseFy).isNetworkWPA(any(ScanResult.class)); + } + + @Test + public void isNetworkWPA2_api() { + mWiseFy.isNetworkWPA2(mock(ScanResult.class)); + verify(mWiseFy).isNetworkWPA2(any(ScanResult.class)); + } + + @Test + public void isWifiEnabled_api() { + mWiseFy.isWifiEnabled(); + verify(mWiseFy).isWifiEnabled(); + } + + @Test + public void removeNetwork_api() { + mWiseFy.removeNetwork("SSID"); + verify(mWiseFy).removeNetwork(anyString()); + + mWiseFy.removeNetwork("SSID", new RemoveNetworkCallbacks() { + @Override + public void failureRemovingNetwork() { + + } + + @Override + public void networkNotFoundToRemove() { + + } + + @Override + public void networkRemoved() { + + } + + @Override + public void removeNetworkWiseFyFailure(Integer wisefyReturnCode) { + + } + }); + verify(mWiseFy).removeNetwork(anyString(), any(RemoveNetworkCallbacks.class)); + } + + + @Test + public void searchForAccessPoint_api() { + mWiseFy.searchForAccessPoint("SSID", 1000, true); + verify(mWiseFy).searchForAccessPoint(anyString(), anyInt(), anyBoolean()); + + mWiseFy.searchForAccessPoint("SSID", 1000, true, new SearchForAccessPointCallbacks() { + @Override + public void searchForAccessPointWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void accessPointFound(ScanResult network) { + + } + + @Override + public void accessPointNotFound() { + + } + }); + verify(mWiseFy).searchForAccessPoint(anyString(), anyInt(), anyBoolean(), any(SearchForAccessPointCallbacks.class)); + } + + @Test + public void searchForAccessPoints_api() { + mWiseFy.searchForAccessPoints("SSID", true); + verify(mWiseFy).searchForAccessPoints(anyString(), anyBoolean()); + + mWiseFy.searchForAccessPoints("SSID", true, new SearchForAccessPointsCallbacks() { + @Override + public void searchForAccessPointsWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void foundNetworks(List networks) { + + } + + @Override + public void noNetworksFound() { + + } + }); + verify(mWiseFy).searchForAccessPoints(anyString(), anyBoolean(), any(SearchForAccessPointsCallbacks.class)); + } + + @Test + public void searchForSSID_api() { + mWiseFy.searchForSSID("SSID", 1000); + verify(mWiseFy).searchForSSID(anyString(), anyInt()); + + mWiseFy.searchForSSID("SSID", 1000, new SearchForSSIDCallbacks() { + @Override + public void searchForSSIDWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void ssidFound(String ssid) { + + } + + @Override + public void ssidNotFound() { + + } + }); + verify(mWiseFy).searchForSSID(anyString(), anyInt(), any(SearchForSSIDCallbacks.class)); + } + + @Test + public void searchForSSIDs_api() { + mWiseFy.searchForSSIDs("SSID"); + verify(mWiseFy).searchForSSIDs(anyString()); + + mWiseFy.searchForSSIDs("SSID", new SearchForSSIDsCallbacks() { + @Override + public void searchForSSIDsWiseFyFailure(Integer wisefyReturnCode) { + + } + + @Override + public void retrievedSSIDs(List ssids) { + + } + + @Override + public void noSSIDsFound() { + + } + }); + verify(mWiseFy).searchForSSIDs(anyString(), any(SearchForSSIDsCallbacks.class)); + } + + @Test + public void wifiManagerFailure_value() { + assertEquals(WiseFy.WIFI_MANAGER_FAILURE, -1); + } +} diff --git a/wisefy/src/main/AndroidManifest.xml b/wisefy/src/main/AndroidManifest.xml index 28d0be6b..a338e68b 100644 --- a/wisefy/src/main/AndroidManifest.xml +++ b/wisefy/src/main/AndroidManifest.xml @@ -8,7 +8,8 @@ - + diff --git a/wisefy/src/main/java/com/isupatches/wisefy/WiseFy.java b/wisefy/src/main/java/com/isupatches/wisefy/WiseFy.java index 7d5eb35e..4ebfc5c4 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/WiseFy.java +++ b/wisefy/src/main/java/com/isupatches/wisefy/WiseFy.java @@ -56,13 +56,13 @@ import com.isupatches.wisefy.threads.WiseFyHandlerThread; import com.isupatches.wisefy.util.LogUtil; import com.isupatches.wisefy.util.ManagerUtil; -import com.isupatches.wisefy.util.SleepUtil; import com.isupatches.wisefy.util.WifiConfigurationUtil; import java.util.List; /** - * Main class to manipulate and query network settings on an Android device + * Main class for WiseFy that provides a synchronous and asynchronous API to manipulate and query + * for different parts of a device's wifi configuration and status. * * @author Patches * @version 2.0 @@ -177,7 +177,7 @@ interface GetSmarts { * @see WiseFyCodes * @see WiseFyConfiguration#isLoggingEnabled() * @see WiseFyPrerequisites#hasPrerequisites() - * @see WiseFySearch#checkIfNetworkInConfigurationList(String) + * @see WiseFySearch#isNetworkASavedConfiguration(String) * * @return int - The return code from WifiManager for network creation (-1 for failure) */ @@ -192,7 +192,7 @@ public int addOpenNetwork(String ssid) { return WiseFyCodes.MISSING_PREREQUISITE; } - if (mWiseFySearch.checkIfNetworkInConfigurationList(ssid)) { + if (mWiseFySearch.isNetworkASavedConfiguration(ssid)) { return WiseFyCodes.NETWORK_ALREADY_CONFIGURED; } @@ -216,7 +216,7 @@ public int addOpenNetwork(String ssid) { * @see WiseFyCodes * @see WiseFyConfiguration#isLoggingEnabled() * @see WiseFyPrerequisites#hasPrerequisites() - * @see WiseFySearch#checkIfNetworkInConfigurationList(String) + * @see WiseFySearch#isNetworkASavedConfiguration(String) */ @Async @WiseFyThread @@ -238,7 +238,7 @@ public void run() { return; } - if (mWiseFySearch.checkIfNetworkInConfigurationList(ssid)) { + if (mWiseFySearch.isNetworkASavedConfiguration(ssid)) { if (callbacks != null) { callbacks.addOpenNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); } @@ -273,7 +273,7 @@ public void run() { * @see WiseFyCodes * @see WiseFyConfiguration#isLoggingEnabled() * @see WiseFyPrerequisites#hasPrerequisites() - * @see WiseFySearch#checkIfNetworkInConfigurationList(String) + * @see WiseFySearch#isNetworkASavedConfiguration(String) * * @return int - The return code from WifiManager for network creation (-1 for failure) */ @@ -288,7 +288,7 @@ public int addWEPNetwork(String ssid, String password) { return WiseFyCodes.MISSING_PREREQUISITE; } - if (mWiseFySearch.checkIfNetworkInConfigurationList(ssid)) { + if (mWiseFySearch.isNetworkASavedConfiguration(ssid)) { return WiseFyCodes.NETWORK_ALREADY_CONFIGURED; } @@ -313,7 +313,7 @@ public int addWEPNetwork(String ssid, String password) { * @see WiseFyCodes * @see WiseFyConfiguration#isLoggingEnabled() * @see WiseFyPrerequisites#hasPrerequisites() - * @see WiseFySearch#checkIfNetworkInConfigurationList(String) + * @see WiseFySearch#isNetworkASavedConfiguration(String) */ @Async @WiseFyThread @@ -335,7 +335,7 @@ public void run() { return; } - if (mWiseFySearch.checkIfNetworkInConfigurationList(ssid)) { + if (mWiseFySearch.isNetworkASavedConfiguration(ssid)) { if (callbacks != null) { callbacks.addWEPNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); } @@ -370,7 +370,7 @@ public void run() { * @see WiseFyCodes * @see WiseFyConfiguration#isLoggingEnabled() * @see WiseFyPrerequisites#hasPrerequisites() - * @see WiseFySearch#checkIfNetworkInConfigurationList(String) + * @see WiseFySearch#isNetworkASavedConfiguration(String) * * @return int - The return code from WifiManager for network creation (-1 for failure) */ @@ -385,7 +385,7 @@ public int addWPA2Network(String ssid, String password) { return WiseFyCodes.MISSING_PREREQUISITE; } - if (mWiseFySearch.checkIfNetworkInConfigurationList(ssid)) { + if (mWiseFySearch.isNetworkASavedConfiguration(ssid)) { return WiseFyCodes.NETWORK_ALREADY_CONFIGURED; } @@ -410,7 +410,7 @@ public int addWPA2Network(String ssid, String password) { * @see WiseFyCodes * @see WiseFyConfiguration#isLoggingEnabled() * @see WiseFyPrerequisites#hasPrerequisites() - * @see WiseFySearch#checkIfNetworkInConfigurationList(String) + * @see WiseFySearch#isNetworkASavedConfiguration(String) */ @Async @WiseFyThread @@ -432,7 +432,7 @@ public void run() { return; } - if (mWiseFySearch.checkIfNetworkInConfigurationList(ssid)) { + if (mWiseFySearch.isNetworkASavedConfiguration(ssid)) { if (callbacks != null) { callbacks.addWPA2NetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); } @@ -686,18 +686,18 @@ public void run() { } /** - * To cleanup the thread started by WiseFy - * - * @return boolean - If the command succeeded in cleaning up the WiseFyHandlerThread + * Used to cleanup the thread started by WiseFy */ public void dump() { - boolean result = false; if (mWiseFyHandlerThread != null) { mWiseFyHandlerThread.interrupt(); + mWiseFyHandlerThread.quit(); + mWiseFyHandlerThread = null; if (LogUtil.isLoggable(TAG, Log.DEBUG, mWiseFyConfiguration.isLoggingEnabled())) { - Log.d(TAG, String.format("Cleaning up WiseFy Thread. Result: %b, Thread value: %s, Handler value: %s", result, mWiseFyHandlerThread, mWiseFyHandler)); + Log.d(TAG, String.format("Cleaning up WiseFy Thread. Thread value: %s, Handler value: %s", mWiseFyHandlerThread, mWiseFyHandler)); } } + mWiseFyHandler = null; } /** @@ -1069,83 +1069,83 @@ public void run() { }; execute(runnable); } -// -// /** -// * To retrieve a list of saved networks on a user's device -// * -// * @see #hasPrerequisites() -// * -// * @return List of WifiConfiguration|null - List of saved networks on a users device -// */ -// @Sync -// @CallingThread -// public List getSavedNetworks() { -// if (!mWiseFyPrerequisites.hasPrerequisites()) { -// return null; -// } -// return mWiseFyPrerequisites.getWifiManager().getConfiguredNetworks(); -// } -// -// /** -// * To retrieve a list of saved networks on a user's device -// * -// * @param callbacks The listener to return results to -// * -// * @see #execute(Runnable) -// * @see #hasPrerequisites() -// * @see GetSavedNetworksCallbacks -// * @see WiseFyCodes -// */ -// @Async -// @WiseFyThread -// public void getSavedNetworks(final GetSavedNetworksCallbacks callbacks) { -// Runnable runnable = new Runnable() { -// @Override -// public void run() { -// if (!mWiseFyPrerequisites.hasPrerequisites()) { -// if (callbacks != null) { -// callbacks.getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// return; -// } -// -// if (callbacks != null) { -// callbacks.retrievedSavedNetworks(mWiseFyPrerequisites.getWifiManager().getConfiguredNetworks()); -// } -// } -// }; -// execute(runnable); -// } -// -// @Sync -// @CallingThread -// public List getSavedNetworks(String regexForSSID) { -// if (!mWiseFyPrerequisites.hasPrerequisites()) { -// return null; -// } -// return mWiseFySearch.findSavedNetworksMatchingRegex(regexForSSID); -// } -// -// @Async -// @WiseFyThread -// public void getSavedNetworks(final String regexForSSID, final GetSavedNetworksCallbacks callbacks) { -// Runnable runnable = new Runnable() { -// @Override -// public void run() { -// if (!mWiseFyPrerequisites.hasPrerequisites()) { -// if (callbacks != null) { -// callbacks.getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// return; -// } -// -// if (callbacks != null) { -// callbacks.retrievedSavedNetworks(mWiseFySearch.findSavedNetworksMatchingRegex(regexForSSID)); -// } -// } -// }; -// execute(runnable); -// } + + /** + * To retrieve a list of saved networks on a user's device + * + * @see WiseFyPrerequisites#hasPrerequisites() + * + * @return List of WifiConfiguration|null - List of saved networks on a users device + */ + @Sync + @CallingThread + public List getSavedNetworks() { + if (!mWiseFyPrerequisites.hasPrerequisites()) { + return null; + } + return mWiseFyPrerequisites.getWifiManager().getConfiguredNetworks(); + } + + /** + * To retrieve a list of saved networks on a user's device + * + * @param callbacks The listener to return results to + * + * @see #execute(Runnable) + * @see GetSavedNetworksCallbacks + * @see WiseFyCodes + * @see WiseFyPrerequisites#hasPrerequisites() + */ + @Async + @WiseFyThread + public void getSavedNetworks(final GetSavedNetworksCallbacks callbacks) { + Runnable runnable = new Runnable() { + @Override + public void run() { + if (!mWiseFyPrerequisites.hasPrerequisites()) { + if (callbacks != null) { + callbacks.getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + return; + } + + if (callbacks != null) { + callbacks.retrievedSavedNetworks(mWiseFyPrerequisites.getWifiManager().getConfiguredNetworks()); + } + } + }; + execute(runnable); + } + + @Sync + @CallingThread + public List getSavedNetworks(String regexForSSID) { + if (!mWiseFyPrerequisites.hasPrerequisites()) { + return null; + } + return mWiseFySearch.findSavedNetworksMatchingRegex(regexForSSID); + } + + @Async + @WiseFyThread + public void getSavedNetworks(final String regexForSSID, final GetSavedNetworksCallbacks callbacks) { + Runnable runnable = new Runnable() { + @Override + public void run() { + if (!mWiseFyPrerequisites.hasPrerequisites()) { + if (callbacks != null) { + callbacks.getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + return; + } + + if (callbacks != null) { + callbacks.retrievedSavedNetworks(mWiseFySearch.findSavedNetworksMatchingRegex(regexForSSID)); + } + } + }; + execute(runnable); + } /** * To check if the device is connected to a mobile network @@ -1222,68 +1222,67 @@ public boolean isDeviceConnectedToWifiNetwork() { NetworkInfo networkInfo = mWiseFyPrerequisites.getConnectivityManager().getActiveNetworkInfo(); return mWiseFyConnection.isNetworkConnectedAndMatchesType(networkInfo, NetworkTypes.WIFI); } -// -// /** -// * To query if logging is enabled or disabled for a WiseFy instance -// * -// * @return boolean - If logging is enabled for the WiseFy instance -// */ -// @Sync -// @CallingThread -// public boolean isLoggingEnabled() { -// return mWiseFyConfiguration.isLoggingEnabled(); -// } -// -// /** -// * To check if the device's current network is 5gHz -// * -// * @see #getFrequency() -// * @see #MIN_FREQUENCY_5GHZ -// * @see #MAX_FREQUENCY_5GHZ -// * -// * @return boolean - If the network is 5gHz -// */ -// @Sync -// @CallingThread -// public boolean isNetwork5gHz() { -// Integer frequency = getFrequency(); -// return frequency != null && frequency > MIN_FREQUENCY_5GHZ && frequency < MAX_FREQUENCY_5GHZ; -// } -// -// /** -// * To check if a given network is 5gHz -// * -// * @param network The network to check if it's 5gHz -// * -// * @see #getFrequency(WifiInfo) -// * @see #MIN_FREQUENCY_5GHZ -// * @see #MAX_FREQUENCY_5GHZ -// * -// * @return boolean - If the network is 5gHz -// */ -// @Sync -// @CallingThread -// public boolean isNetwork5gHz(WifiInfo network) { -// Integer frequency = getFrequency(network); -// return frequency != null && frequency > MIN_FREQUENCY_5GHZ && frequency < MAX_FREQUENCY_5GHZ; -// } -// -// /** -// * To check if an SSID is in the list of configured networks -// * -// * @param ssid The SSID to check and see if it's in the list of configured networks -// * -// * @see #checkIfNetworkInConfigurationList(String) -// * @see WiseFyPrerequisites#hasPrerequisites() -// * -// * @return boolean - If the SSID is in the list of configured networks -// */ -// @Sync -// @CallingThread -// public boolean isNetworkInConfigurationList(String ssid) { -// return mWiseFyPrerequisites.hasPrerequisites() && checkIfNetworkInConfigurationList(ssid); -// } -// + + /** + * To query if logging is enabled or disabled for a WiseFy instance + * + * @return boolean - If logging is enabled for the WiseFy instance + */ + @Sync + @CallingThread + public boolean isLoggingEnabled() { + return mWiseFyConfiguration.isLoggingEnabled(); + } + + /** + * To check if the device's current network is 5gHz + * + * @see #getFrequency() + * @see #MIN_FREQUENCY_5GHZ + * @see #MAX_FREQUENCY_5GHZ + * + * @return boolean - If the network is 5gHz + */ + @Sync + @CallingThread + public boolean isNetwork5gHz() { + Integer frequency = getFrequency(); + return frequency != null && frequency > MIN_FREQUENCY_5GHZ && frequency < MAX_FREQUENCY_5GHZ; + } + + /** + * To check if a given network is 5gHz + * + * @param network The network to check if it's 5gHz + * + * @see #getFrequency(WifiInfo) + * @see #MIN_FREQUENCY_5GHZ + * @see #MAX_FREQUENCY_5GHZ + * + * @return boolean - If the network is 5gHz + */ + @Sync + @CallingThread + public boolean isNetwork5gHz(WifiInfo network) { + Integer frequency = getFrequency(network); + return frequency != null && frequency > MIN_FREQUENCY_5GHZ && frequency < MAX_FREQUENCY_5GHZ; + } + + /** + * To check if an SSID is in the list of configured networks + * + * @param ssid The SSID to check and see if it's in the list of configured networks + * + * @see WiseFyPrerequisites#hasPrerequisites() + * @see WiseFySearch#isNetworkASavedConfiguration(String) + * + * @return boolean - If the SSID is in the list of configured networks + */ + @Sync + @CallingThread + public boolean isNetworkInConfigurationList(String ssid) { + return mWiseFyPrerequisites.hasPrerequisites() && mWiseFySearch.isNetworkASavedConfiguration(ssid); + } /** * To check and return if a network is a EAP network @@ -1490,221 +1489,221 @@ public void run() { }; execute(runnable); } -// -// public ScanResult searchForAccessPoint(String regexForSSID, int timeoutInMillis, boolean filterDuplicates) { -// if (TextUtils.isEmpty(regexForSSID) || !mWiseFyPrerequisites.hasPrerequisites()) { -// return null; -// } -// -// ScanResult scanResult = mWiseFySearch.findAccessPointByRegex(regexForSSID, timeoutInMillis, filterDuplicates); -// if (scanResult != null) { -// return scanResult; -// } -// return null; -// } -// -// public void searchForAccessPoint(final String regexForSSID, final int timeoutInMillis, final boolean filterDuplicates, final SearchForAccessPointCallbacks callbacks) { -// Runnable runnable = new Runnable() { -// @Override -// public void run() { -// if (TextUtils.isEmpty(regexForSSID)) { -// if (callbacks != null) { -// callbacks.searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// return; -// } -// -// if (!mWiseFyPrerequisites.hasPrerequisites()) { -// if (callbacks != null) { -// callbacks.searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// return; -// } -// -// ScanResult scanResult = mWiseFySearch.findAccessPointByRegex(regexForSSID, timeoutInMillis, filterDuplicates); -// if (callbacks != null) { -// if (scanResult != null) { -// callbacks.accessPointFound(scanResult); -// } else { -// callbacks.accessPointNotFound(); -// } -// } -// } -// }; -// execute(runnable); -// } -// -// public List searchForAccessPoints(String regexForSSID, boolean filterDuplicates) { -// if (TextUtils.isEmpty(regexForSSID) || !mWiseFyPrerequisites.hasPrerequisites()) { -// return null; -// } -// -// return mWiseFySearch.findAccessPointsMatchingRegex(regexForSSID, filterDuplicates); -// } -// -// public void searchForAccessPoints(final String regexForSSID, final boolean filterDuplicates, final SearchForAccessPointsCallbacks callbacks) { -// Runnable runnable = new Runnable() { -// @Override -// public void run() { -// if (TextUtils.isEmpty(regexForSSID)) { -// if (callbacks != null) { -// callbacks.searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// return; -// } -// -// if (!mWiseFyPrerequisites.hasPrerequisites()) { -// if (callbacks != null) { -// callbacks.searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// return; -// } -// -// List networks = mWiseFySearch.findAccessPointsMatchingRegex(regexForSSID, filterDuplicates); -// if (callbacks != null) { -// if (networks != null && networks.size() > 0) { -// callbacks.foundNetworks(networks); -// } else { -// callbacks.noNetworksFound(); -// } -// } -// } -// }; -// execute(runnable); -// } -// -// /** -// * To search local networks and return the first one that contains a given ssid -// * -// * @param regexForSSID The regex to be used to search for the ssid -// * @param timeoutInMillis The number of milliseconds to keep searching for the SSID -// * -// * @return String|null - The first SSID that contains the search ssid (if any, else null) -// */ -// @Sync -// @CallingThread -// @WaitsForTimeout -// public String searchForSSID(String regexForSSID, int timeoutInMillis) { -// if (TextUtils.isEmpty(regexForSSID) || !mWiseFyPrerequisites.hasPrerequisites()) { -// return null; -// } -// -// ScanResult scanResult = mWiseFySearch.findAccessPointByRegex(regexForSSID, timeoutInMillis, false); -// if (scanResult != null) { -// return scanResult.SSID; -// } -// return null; -// } -// -// /** -// * To search local networks and return the first one that contains a given ssid -// * -// * @param regexForSSID The regex to be used to search for the ssid -// * @param timeoutInMillis The number of milliseconds to keep searching for the SSID -// * @param callbacks The listener to return results to -// * -// * @see #execute(Runnable) -// * @see SearchForSSIDCallbacks -// * @see WiseFyCodes -// * @see WiseFySearch#findAccessPointByRegex(String, Integer, boolean) -// */ -// @Async -// @WiseFyThread -// @WaitsForTimeout -// public void searchForSSID(final String regexForSSID, final int timeoutInMillis, final SearchForSSIDCallbacks callbacks) { -// Runnable runnable = new Runnable() { -// @Override -// public void run() { -// if (TextUtils.isEmpty(regexForSSID)) { -// if (callbacks != null) { -// callbacks.searchForSSIDWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// return; -// } -// -// if (!mWiseFyPrerequisites.hasPrerequisites()) { -// if (callbacks != null) { -// callbacks.searchForSSIDWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// return; -// } -// -// ScanResult scanResult = mWiseFySearch.findAccessPointByRegex(regexForSSID, timeoutInMillis, false); -// if (callbacks != null) { -// if (scanResult != null) { -// callbacks.ssidFound(scanResult.SSID); -// } else { -// callbacks.ssidNotFound(); -// } -// } -// } -// }; -// execute(runnable); -// } -// -// /** -// * To search local networks and return the first one that contains a given ssid -// * -// * @param regexForSSID The regex to be used to search for the ssid -// * -// * @return List|null - The first SSID that contains the search ssid (if any, else null) -// */ -// @Sync -// @CallingThread -// @WaitsForTimeout -// public List searchForSSIDs(String regexForSSID) { -// if (TextUtils.isEmpty(regexForSSID) || !mWiseFyPrerequisites.hasPrerequisites()) { -// return null; -// } -// -// return mWiseFySearch.findSSIDsMatchingRegex(regexForSSID); -// } -// -// /** -// * To search local networks and return the first one that contains a given ssid -// * -// * @param regexForSSID The regex to be used to search for the ssid -// * @param callbacks -// * -// * @see #execute(Runnable) -// * @see SearchForSSIDCallbacks -// * @see WiseFyCodes -// * @see WiseFySearch#findSSIDsMatchingRegex(String) -// */ -// @Async -// @WiseFyThread -// @WaitsForTimeout -// public void searchForSSIDs(final String regexForSSID, final SearchForSSIDsCallbacks callbacks) { -// Runnable runnable = new Runnable() { -// @Override -// public void run() { -// if (TextUtils.isEmpty(regexForSSID)) { -// if (callbacks != null) { -// callbacks.searchForSSIDsWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// return; -// } -// -// if (!mWiseFyPrerequisites.hasPrerequisites()) { -// if (callbacks != null) { -// callbacks.searchForSSIDsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// return; -// } -// -// List ssids = mWiseFySearch.findSSIDsMatchingRegex(regexForSSID); -// if (callbacks != null) { -// if (ssids != null) { -// callbacks.retrievedSSIDs(ssids); -// } else { -// callbacks.noSSIDsFound(); -// } -// } -// } -// }; -// execute(runnable); -// } -// + + public ScanResult searchForAccessPoint(String regexForSSID, int timeoutInMillis, boolean filterDuplicates) { + if (TextUtils.isEmpty(regexForSSID) || !mWiseFyPrerequisites.hasPrerequisites()) { + return null; + } + + ScanResult scanResult = mWiseFySearch.findAccessPointByRegex(regexForSSID, timeoutInMillis, filterDuplicates); + if (scanResult != null) { + return scanResult; + } + return null; + } + + public void searchForAccessPoint(final String regexForSSID, final int timeoutInMillis, final boolean filterDuplicates, final SearchForAccessPointCallbacks callbacks) { + Runnable runnable = new Runnable() { + @Override + public void run() { + if (TextUtils.isEmpty(regexForSSID)) { + if (callbacks != null) { + callbacks.searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + return; + } + + if (!mWiseFyPrerequisites.hasPrerequisites()) { + if (callbacks != null) { + callbacks.searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + return; + } + + ScanResult scanResult = mWiseFySearch.findAccessPointByRegex(regexForSSID, timeoutInMillis, filterDuplicates); + if (callbacks != null) { + if (scanResult != null) { + callbacks.accessPointFound(scanResult); + } else { + callbacks.accessPointNotFound(); + } + } + } + }; + execute(runnable); + } + + public List searchForAccessPoints(String regexForSSID, boolean filterDuplicates) { + if (TextUtils.isEmpty(regexForSSID) || !mWiseFyPrerequisites.hasPrerequisites()) { + return null; + } + + return mWiseFySearch.findAccessPointsMatchingRegex(regexForSSID, filterDuplicates); + } + + public void searchForAccessPoints(final String regexForSSID, final boolean filterDuplicates, final SearchForAccessPointsCallbacks callbacks) { + Runnable runnable = new Runnable() { + @Override + public void run() { + if (TextUtils.isEmpty(regexForSSID)) { + if (callbacks != null) { + callbacks.searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + return; + } + + if (!mWiseFyPrerequisites.hasPrerequisites()) { + if (callbacks != null) { + callbacks.searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + return; + } + + List networks = mWiseFySearch.findAccessPointsMatchingRegex(regexForSSID, filterDuplicates); + if (callbacks != null) { + if (networks != null && networks.size() > 0) { + callbacks.foundNetworks(networks); + } else { + callbacks.noNetworksFound(); + } + } + } + }; + execute(runnable); + } + + /** + * To search local networks and return the first one that contains a given ssid + * + * @param regexForSSID The regex to be used to search for the ssid + * @param timeoutInMillis The number of milliseconds to keep searching for the SSID + * + * @return String|null - The first SSID that contains the search ssid (if any, else null) + */ + @Sync + @CallingThread + @WaitsForTimeout + public String searchForSSID(String regexForSSID, int timeoutInMillis) { + if (TextUtils.isEmpty(regexForSSID) || !mWiseFyPrerequisites.hasPrerequisites()) { + return null; + } + + ScanResult scanResult = mWiseFySearch.findAccessPointByRegex(regexForSSID, timeoutInMillis, false); + if (scanResult != null) { + return scanResult.SSID; + } + return null; + } + + /** + * To search local networks and return the first one that contains a given ssid + * + * @param regexForSSID The regex to be used to search for the ssid + * @param timeoutInMillis The number of milliseconds to keep searching for the SSID + * @param callbacks The listener to return results to + * + * @see #execute(Runnable) + * @see SearchForSSIDCallbacks + * @see WiseFyCodes + * @see WiseFySearch#findAccessPointByRegex(String, Integer, boolean) + */ + @Async + @WiseFyThread + @WaitsForTimeout + public void searchForSSID(final String regexForSSID, final int timeoutInMillis, final SearchForSSIDCallbacks callbacks) { + Runnable runnable = new Runnable() { + @Override + public void run() { + if (TextUtils.isEmpty(regexForSSID)) { + if (callbacks != null) { + callbacks.searchForSSIDWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + return; + } + + if (!mWiseFyPrerequisites.hasPrerequisites()) { + if (callbacks != null) { + callbacks.searchForSSIDWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + return; + } + + ScanResult scanResult = mWiseFySearch.findAccessPointByRegex(regexForSSID, timeoutInMillis, false); + if (callbacks != null) { + if (scanResult != null) { + callbacks.ssidFound(scanResult.SSID); + } else { + callbacks.ssidNotFound(); + } + } + } + }; + execute(runnable); + } + + /** + * To search local networks and return the first one that contains a given ssid + * + * @param regexForSSID The regex to be used to search for the ssid + * + * @return String|null - The first SSID that contains the search ssid (if any, else null) + */ + @Sync + @CallingThread + @WaitsForTimeout + public List searchForSSIDs(String regexForSSID) { + if (TextUtils.isEmpty(regexForSSID) || !mWiseFyPrerequisites.hasPrerequisites()) { + return null; + } + + return mWiseFySearch.findSSIDsMatchingRegex(regexForSSID); + } + + /** + * To search local networks and return the first one that contains a given ssid + * + * @param regexForSSID The regex to be used to search for the ssid + * @param callbacks The listener to return results to + * + * @see #execute(Runnable) + * @see SearchForSSIDCallbacks + * @see WiseFyCodes + * @see WiseFySearch#findSSIDsMatchingRegex(String) + */ + @Async + @WiseFyThread + @WaitsForTimeout + public void searchForSSIDs(final String regexForSSID, final SearchForSSIDsCallbacks callbacks) { + Runnable runnable = new Runnable() { + @Override + public void run() { + if (TextUtils.isEmpty(regexForSSID)) { + if (callbacks != null) { + callbacks.searchForSSIDsWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + return; + } + + if (!mWiseFyPrerequisites.hasPrerequisites()) { + if (callbacks != null) { + callbacks.searchForSSIDsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + return; + } + + List ssids = mWiseFySearch.findSSIDsMatchingRegex(regexForSSID); + if (callbacks != null) { + if (ssids != null) { + callbacks.retrievedSSIDs(ssids); + } else { + callbacks.noSSIDsFound(); + } + } + } + }; + execute(runnable); + } + /* * HELPERS */ diff --git a/wisefy/src/main/java/com/isupatches/wisefy/WiseFyConfiguration.java b/wisefy/src/main/java/com/isupatches/wisefy/WiseFyConfiguration.java index c69c06aa..d9f768ee 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/WiseFyConfiguration.java +++ b/wisefy/src/main/java/com/isupatches/wisefy/WiseFyConfiguration.java @@ -16,6 +16,13 @@ package com.isupatches.wisefy; +/** + * A class used internally to hold a shared reference to the configuration provided with the + * builder pattern. Right now logging is the only configurable option, but this could potentially + * be expanded. + * + * @author Patches + */ class WiseFyConfiguration { private static final WiseFyConfiguration WISEFY_CONFIGURATION = new WiseFyConfiguration(); @@ -35,10 +42,20 @@ static WiseFyConfiguration getInstance() { return WISEFY_CONFIGURATION; } + /** + * Used internally to query for if logging has been enabled on this instance of WiseFy + * + * @return boolean - True if logging has been enabled + */ boolean isLoggingEnabled() { return mLoggingEnabled; } + /** + * Used internally to set the logging configuration + * + * *NOTE* Called upon initialization + */ void setLoggingEnabled(boolean mLoggingEnabled) { this.mLoggingEnabled = mLoggingEnabled; } diff --git a/wisefy/src/main/java/com/isupatches/wisefy/WiseFyConnection.java b/wisefy/src/main/java/com/isupatches/wisefy/WiseFyConnection.java index 5f66977f..7fa12d61 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/WiseFyConnection.java +++ b/wisefy/src/main/java/com/isupatches/wisefy/WiseFyConnection.java @@ -24,6 +24,12 @@ import com.isupatches.wisefy.util.SleepUtil; +/** + * A class used internally to query and determine different parts of the connection state for a + * device. + * + * @author Patches + */ class WiseFyConnection { private static final String TAG = WiseFyConnection.class.getSimpleName(); @@ -50,19 +56,14 @@ static WiseFyConnection getInstance() { } /** - * Used internally to check to see if a given network matches a specified type (i.e. Mobile or Wifi) + * Used internally to see if the current network is connected to and matches a given ssid * * *NOTE* Case insensitive * - * @param networkInfo The network to check - * @param type The type of network + * @param ssid The ssid to check if the device is connected to * - * @return boolean - True if the network matches the given type + * @return boolean - True if the device is connected to a network */ - boolean doesNetworkMatchType(NetworkInfo networkInfo, String type) { - return networkInfo != null && networkInfo.getTypeName() != null && networkInfo.getTypeName().equalsIgnoreCase(type); - } - boolean isCurrentNetworkConnectedToSSID(String ssid) { WifiInfo connectionInfo = mWiseFyPrerequisites.getWifiManager().getConnectionInfo(); if (connectionInfo != null && connectionInfo.getSSID() != null) { @@ -135,4 +136,18 @@ boolean waitToConnectToSSID(String ssid, int timeoutInMillis) { } while (currentTime < endTime); return false; } + + /** + * Used internally to check to see if a given network matches a specified type (i.e. Mobile or Wifi) + * + * *NOTE* Case insensitive + * + * @param networkInfo The network to check + * @param type The type of network + * + * @return boolean - True if the network matches the given type + */ + private boolean doesNetworkMatchType(NetworkInfo networkInfo, String type) { + return networkInfo != null && networkInfo.getTypeName() != null && networkInfo.getTypeName().equalsIgnoreCase(type); + } } diff --git a/wisefy/src/main/java/com/isupatches/wisefy/WiseFyPrerequisites.java b/wisefy/src/main/java/com/isupatches/wisefy/WiseFyPrerequisites.java index 9616989d..ac977085 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/WiseFyPrerequisites.java +++ b/wisefy/src/main/java/com/isupatches/wisefy/WiseFyPrerequisites.java @@ -22,6 +22,13 @@ import com.isupatches.wisefy.util.LogUtil; +/** + * A class used internally as a bridge for other parts of the library to use a shared set of + * prerequisite instances. This contains the WifiManager and ConnectivityManger used throughout + * the library. + * + * @author Patches + */ class WiseFyPrerequisites { private static final String TAG = WiseFyPrerequisites.class.getSimpleName(); @@ -69,18 +76,39 @@ boolean hasPrerequisites() { return true; } + /** + * Used internally to return a shared ConnectivityManager instance to the rest of the library + * + * @return ConnectivityManager|null - The shared ConnectivityManager instance if any or null + */ ConnectivityManager getConnectivityManager() { return mConnectivityManager; } + /** + * Used internally to return a shared WifiManager instance to the rest of the library + * + * @return WifiManager|null - The shared WifiManager instance if any or null + */ WifiManager getWifiManager() { return mWifiManager; } + + /** + * Used internally to set the shared ConnectivityManager instance for the rest of the library + * + * *NOTE* Called upon initialization or in test + */ void setConnectivityManager(ConnectivityManager mConnectivityManager) { this.mConnectivityManager = mConnectivityManager; } + /** + * Used internally to set the shared WifiManager instance for the rest of the library + * + * *NOTE* Called upon initialization or in test + */ void setWifiManager(WifiManager mWifiManager) { this.mWifiManager = mWifiManager; } diff --git a/wisefy/src/main/java/com/isupatches/wisefy/WiseFySearch.java b/wisefy/src/main/java/com/isupatches/wisefy/WiseFySearch.java index 0f1740df..50e161c9 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/WiseFySearch.java +++ b/wisefy/src/main/java/com/isupatches/wisefy/WiseFySearch.java @@ -26,6 +26,13 @@ import java.util.List; +/** + * A class used internally for the purposes of shared query logic. This handles saved networks and + * nearby access points. There is also filtering by regex functionality and some RSSI logic that + * are tied into these queries. + * + * @author Patches + */ class WiseFySearch { private static final String TAG = WiseFySearch.class.getSimpleName(); @@ -51,29 +58,18 @@ static WiseFySearch getInstance() { return WISEFY_SEARCH; } - /** - * Used internally to see if an ssid is already saved - * - * *NOTE* CASE SENSITIVE! - * - * @param ssid The ssid to check for in the configured network list - * @return boolean - True if the ssid was found in the configuration list - * @see WiseFySearch#findSavedNetworkByRegex(String) - */ - boolean checkIfNetworkInConfigurationList(String ssid) { - WifiConfiguration wifiConfiguration = findSavedNetworkByRegex(ssid); - return wifiConfiguration != null; - } - /** * Used internally to wait for a given time and return the first ScanResult whose SSID matches a given regex * - * @param regexForSSID The regex to check the SSID of the network against + * @param regexForSSID The regex to check the SSID of the network against * @param timeoutInMillis The amount of time to wait for a match + * @param takeHighest If the method should iterate through and return only the access point with the highest RSSI + * + * @see #hasHighestSignalStrength(List, ScanResult) * * @return ScanResult|null - The first network whose SSID matches a given regex */ - ScanResult findAccessPointByRegex(String regexForSSID, Integer timeoutInMillis, boolean filterDuplicates) { + ScanResult findAccessPointByRegex(String regexForSSID, Integer timeoutInMillis, boolean takeHighest) { int scanPass = 1; long currentTime; long endTime = System.currentTimeMillis() + timeoutInMillis; @@ -85,11 +81,11 @@ ScanResult findAccessPointByRegex(String regexForSSID, Integer timeoutInMillis, List accessPoints = mWiseFyPrerequisites.getWifiManager().getScanResults(); if (accessPoints != null && accessPoints.size() > 0) { for (ScanResult accessPoint : accessPoints) { - if (LogUtil.isLoggable(TAG, Log.DEBUG, mWiseFyConfiguration.isLoggingEnabled())) { - Log.d(TAG, String.format("scanResult.SSID: %s, regex for SSID: %s", accessPoint.SSID, regexForSSID)); - } - if (accessPoint.SSID != null && (accessPoint.SSID).matches(regexForSSID)) { - if (filterDuplicates) { + if (accessPoint != null && accessPoint.SSID != null && (accessPoint.SSID).matches(regexForSSID)) { + if (LogUtil.isLoggable(TAG, Log.DEBUG, mWiseFyConfiguration.isLoggingEnabled())) { + Log.d(TAG, String.format("scanResult.SSID: %s, regex for SSID: %s", accessPoint.SSID, regexForSSID)); + } + if (takeHighest) { if (hasHighestSignalStrength(accessPoints, accessPoint)) { return accessPoint; } @@ -115,20 +111,23 @@ ScanResult findAccessPointByRegex(String regexForSSID, Integer timeoutInMillis, * Used internally to return a list of networks whose SSID match the given regex * * @param regexForSSID The regex to check the SSID of the network against + * @param takeHighest If the method should iterate through and return only the access point with the highest RSSI + * + * @see #hasHighestSignalStrength(List, ScanResult) * * @return List|null - The list of networks that have an SSID that matches the given regex */ - List findAccessPointsMatchingRegex(String regexForSSID, boolean filterDuplicates) { + List findAccessPointsMatchingRegex(String regexForSSID, boolean takeHighest) { mWiseFyPrerequisites.getWifiManager().startScan(); List matchingAccessPoints = new ArrayList<>(); List accessPoints = mWiseFyPrerequisites.getWifiManager().getScanResults(); if (accessPoints != null && accessPoints.size() > 0) { for (ScanResult accessPoint : accessPoints) { - if (LogUtil.isLoggable(TAG, Log.DEBUG, mWiseFyConfiguration.isLoggingEnabled())) { - Log.d(TAG, String.format("accessPoint.SSID: %s, regex for SSID: %s", accessPoint.SSID, regexForSSID)); - } - if (accessPoint.SSID != null && accessPoint.SSID.matches(regexForSSID)) { - if (filterDuplicates) { + if (accessPoint != null && accessPoint.SSID != null && accessPoint.SSID.matches(regexForSSID)) { + if (LogUtil.isLoggable(TAG, Log.DEBUG, mWiseFyConfiguration.isLoggingEnabled())) { + Log.d(TAG, String.format("accessPoint.SSID: %s, regex for SSID: %s", accessPoint.SSID, regexForSSID)); + } + if (takeHighest) { if (hasHighestSignalStrength(accessPoints, accessPoint)) { matchingAccessPoints.add(accessPoint); } @@ -234,7 +233,21 @@ List findSSIDsMatchingRegex(String regexForSSID) { } /** - * Used internally to build a list of ScanResults (Removes duplicates by taking access point with higher RSSI) + * Used internally to determine if a network exists as a saved network configuration + * + * @param ssid The ssid to check for in the configured network list + * + * @see WiseFySearch#findSavedNetworkByRegex(String) + * + * @return boolean - True if the ssid was found in the configuration list + */ + boolean isNetworkASavedConfiguration(String ssid) { + WifiConfiguration wifiConfiguration = findSavedNetworkByRegex(ssid); + return wifiConfiguration != null; + } + + /** + * Used internally to build a list of ScanResults (removes duplicates by taking access point with higher RSSI) * * *NOTE* Case insensitive * @@ -259,7 +272,7 @@ List removeEntriesWithLowerSignalStrength(List accessPoi } if (WifiManager.compareSignalLevel(accessPoint.level, scanResult.level) > 0) { if (LogUtil.isLoggable(TAG, Log.DEBUG, mWiseFyConfiguration.isLoggingEnabled())) { - Log.d(TAG, "New result has a higher signal strength, swapping"); + Log.d(TAG, "New result has a higher or same signal strength, swapping"); } accessPointsToReturn.set(i, accessPoint); } @@ -281,9 +294,13 @@ List removeEntriesWithLowerSignalStrength(List accessPoi */ /** - * @param accessPoints - * @param currentAccessPoint - * @return + * Used internally to determine if the current access point has the highest signal strength + * compared to others that have the same SSID + * + * @param accessPoints A list of access points to compare the current access point to + * @param currentAccessPoint The access point to see if it has the highest signal strength + * + * @return boolean - True if the current access point has the highest signal strength */ private boolean hasHighestSignalStrength(List accessPoints, ScanResult currentAccessPoint) { for (ScanResult accessPoint : accessPoints) { @@ -293,7 +310,7 @@ private boolean hasHighestSignalStrength(List accessPoints, ScanResu Log.d(TAG, String.format("RSSI level of access point in list: %d", accessPoint.level)); Log.d(TAG, String.format("comparison result: %d", WifiManager.compareSignalLevel(accessPoint.level, currentAccessPoint.level))); } - if (WifiManager.compareSignalLevel(accessPoint.level, currentAccessPoint.level) < 0) { + if (WifiManager.compareSignalLevel(accessPoint.level, currentAccessPoint.level) > 0) { if (LogUtil.isLoggable(TAG, Log.DEBUG, mWiseFyConfiguration.isLoggingEnabled())) { Log.d(TAG, "Stronger signal strength found"); } diff --git a/wisefy/src/main/java/com/isupatches/wisefy/threads/WiseFyHandlerThread.java b/wisefy/src/main/java/com/isupatches/wisefy/threads/WiseFyHandlerThread.java index 742a735d..8580fc9c 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/threads/WiseFyHandlerThread.java +++ b/wisefy/src/main/java/com/isupatches/wisefy/threads/WiseFyHandlerThread.java @@ -49,10 +49,10 @@ public synchronized void start() { } @Override - public boolean quitSafely() { + public boolean quit() { if (LogUtil.isLoggable(TAG, Log.DEBUG, mLoggingEnabled)) { - Log.d(TAG, "quitSafely called on WiseFyHandlerThread"); + Log.d(TAG, "quit called on WiseFyHandlerThread"); } - return super.quitSafely(); + return super.quit(); } } diff --git a/wisefy/src/main/java/com/isupatches/wisefy/util/SleepUtil.java b/wisefy/src/main/java/com/isupatches/wisefy/util/SleepUtil.java index f0df8748..beb96671 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/util/SleepUtil.java +++ b/wisefy/src/main/java/com/isupatches/wisefy/util/SleepUtil.java @@ -16,10 +16,17 @@ package com.isupatches.wisefy.util; +/** + * A helper class for shared wait logic + * + * @author Patches + */ public class SleepUtil { /** * Used to wait for a given amount of time (in milliseconds) + * + * @param timeToSleepInMillis The number of milliseconds to sleep */ public static void sleep(long timeToSleepInMillis) { try {