diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..2c39e9e4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,24 @@ +language: android +jdk: oraclejdk8 +sudo: false + +android: + components: + - platform-tools + - tools + - build-tools-24.0.3 + - android-22 + - android-24 + - sys-img-armeabi-v7a-android-22 + - extra-android-m2repository + - extra-android-support + - extra-google-m2repository + +before_script: + # Create and start emulator + - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a + - emulator -avd test -no-skin -no-audio -no-window & + - android-wait-for-emulator + - adb shell input keyevent 82 & + +script: ./gradlew clean connectedAndroidTest -PdisablePreDex --stacktrace \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..da63eed7 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2016 Patches Klinefelter + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index c830400e..46fff1dc 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Util library used as a wrapper around WiFi and Connectivity manager for Android >
*Developed by Patches 04/24/2016 - present*

+[![Build Status](https://travis-ci.org/isuPatches/WiseFy.svg?branch=master)](https://travis-ci.org/isuPatches/WiseFy) + ## Getting An Instance WiseFy now supports the builder pattern so cool functionality can be added later! @@ -10,34 +12,35 @@ WiseFy now supports the builder pattern so cool functionality can be added later To grab a default instance: ```java -WiseFy mWiseFy = new WiseFy.getSmarts().initiateHamsters(); +WiseFy mWiseFy = new WiseFy.withContext(getActivity()).getSmarts(); ``` To grab an instance with logging enabled: ```java -WiseFy mWiseFy = new WiseFy.getSmarts().withLogging(true).initiateHamsters(); +WiseFy mWiseFy = new WiseFy.withContext(getActivity()).logging(true).getSmarts(); ``` +**IMPORTANT!** Please make sure you call withContext for WiseFy to work properly ## Commands To add an open network: ```java -int addedSuccessfully = mWiseFy.addOpenNetwork(getActivity(), "Open Network"); +int addedSuccessfully = mWiseFy.addOpenNetwork("Open Network"); ``` To add a WEP network: ```java -int addedSuccessfully = mWiseFy.addWEPNetwork(getActivity(), "WEP Network", "123456"); +int addedSuccessfully = mWiseFy.addWEPNetwork("WEP Network", "123456"); ``` To add a WPA2 network: ```java -int addedSuccessfully = mWiseFy.addWPA2Network(getActivity(), "WPA2 Network", "12345678"); +int addedSuccessfully = mWiseFy.addWPA2Network("WPA2 Network", "12345678"); ``` To calculate number of bars given a networks signal strength and total number of bars: @@ -55,74 +58,74 @@ int result = mWiseFy.compareSignalLevel(-35, -70); To connect to a network given an SSID: ```java -boolean connectedSuccessfully = mWiseFy.connectToNetwork(getActivity(), "SSID To Reconnect To", 3000); +boolean connectedSuccessfully = mWiseFy.connectToNetwork("SSID To Reconnect To", 3000); ``` To disable wifi: ```java -boolean disabledWifiSuccessfully = mWiseFy.disableWifi(getActivity()); +boolean disabledWifiSuccessfully = mWiseFy.disableWifi(); ``` To disconnect from current network: ```java -boolean disconnectedSuccessfully = mWiseFy.disconnectFromCurrentNetwork(getActivity()); +boolean disconnectedSuccessfully = mWiseFy.disconnectFromCurrentNetwork(); ``` To enable wifi: ```java -boolean wifiEnabled = mWiseFy.enableWiFi(getActivity()); +boolean wifiEnabled = mWiseFy.enableWiFi(); ``` To get current network: ```java -WifiInfo currentNetwork = mWiseFy.getCurrentNetwork(getActivity()); +WifiInfo currentNetwork = mWiseFy.getCurrentNetwork(); ``` To get nearby access points:

Setting filterDuplicates to true will not return SSIDs with a weaker signal strength (will always take the highest) ```java -List nearbyAccessPoints = mWiseFy.getNearbyAccessPoints(getActivity(), true); +List nearbyAccessPoints = mWiseFy.getNearbyAccessPoints(true); ``` To get the networks whose configuration is already stored: ```java -List savedNetworks = mWiseFy.getSavedNetworks(getActivity()); +List savedNetworks = mWiseFy.getSavedNetworks(); ``` To check and see if the device is connected to a mobile network: ```java -boolean isConnected = mWiseFy.isDeviceConnectedToMobileNetwork(getActivity()); +boolean isConnected = mWiseFy.isDeviceConnectedToMobileNetwork(); ``` To check and see if the device is connected to a mobile or wifi network: ```java -boolean isConnected = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(getActivity()); +boolean isConnected = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(); ``` To check and see if the device is connected to a given SSID: ```java -boolean isConnected = mWiseFy.isDeviceConnectedToSSID(getActivity(), "SSID"); +boolean isConnected = mWiseFy.isDeviceConnectedToSSID("SSID"); ``` To check and see if the device is connected to a wifi network: ```java -boolean isConnected = mWiseFy.isDeviceConnectedToWifiNetwork(getActivity(), "SSID"); +boolean isConnected = mWiseFy.isDeviceConnectedToWifiNetwork("SSID"); ``` To check and see if a given SSID is in the devices set of configured networks: ```java -boolean isConfigured = mWiseFy.isNetworkInConfigurationList(getActivity(), "SSID"); +boolean isConfigured = mWiseFy.isNetworkInConfigurationList("SSID"); ``` To check and see if a network is secure (WEP/PSK/EAP capabilities): @@ -134,17 +137,17 @@ boolean isSecure = mWiseFy.isNetworkSecure(scanResult); To check and see if Wifi is enabled on a device: ```java -boolean wifiEnabled = mWiseFy.isWifiEnabled(getActivity()); +boolean wifiEnabled = mWiseFy.isWifiEnabled(); ``` To remove a configured network: ```java -boolean removedSuccessfully = mWiseFy.removeNetwork(getActivity(), "SSID To Remove"); +boolean removedSuccessfully = mWiseFy.removeNetwork("SSID To Remove"); ``` To search for an SSID given a search string: ```java -String ssid = mWiseFy.searchForSSID(getActivity(), "SSID To Search For", 3000); -``` +String ssid = mWiseFy.searchForSSID("SSID To Search For", 3000); +``` \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index a6ebbbf5..09e1e3aa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,10 @@ apply plugin: 'com.android.library' apply plugin: 'jacoco' apply plugin: 'com.getkeepsafe.dexcount' +apply plugin: "com.github.dcendents.android-maven" + +group = 'com.isupatches' +version = '1.0.4' def coverageSourceDirs = [ '../app/src/main/java' @@ -47,6 +51,11 @@ dexcount { android { + adbOptions { + timeOutInMs 15 * 60 * 1000 // 15 minutes + installOptions "-d","-t" + } + testOptions { // Allows Android code to be called from unit tests without causing a crash. // Helpful for allowing Log.d()-type calls @@ -59,8 +68,8 @@ android { defaultConfig { minSdkVersion 16 targetSdkVersion 24 - versionCode 4 - versionName "1.0.3" + versionCode 5 + versionName version testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' } @@ -89,4 +98,59 @@ dependencies { androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' testCompile 'junit:junit:4.12' -} \ No newline at end of file +} + +install { + repositories.mavenInstaller { + pom { + project { + artifactId 'wisefy' + packaging 'aar' + + name 'WiseFy' + url 'https://github.com/isuPatches/WiseFy' + + licenses { + license { + name 'The Apache Software License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id 'isuPatches' + name 'Sarah Klinefelter' + email 'isuPatches@yahoo.com' + } + } + scm { + connection 'https://github.com/isuPatches/WiseFy.git' + developerConnection 'https://github.com/isuPatches/WiseFy.git' + url 'https://github.com/isuPatches/WiseFy' + } + } + } + } +} + +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' +} + +task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + destinationDir = file("../javadoc/") + failOnError false +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} + +artifacts { + archives javadocJar + archives sourcesJar +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 54956cf9..163e5472 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -14,4 +14,4 @@ -verbose --keep class com.metova.** { *; } \ No newline at end of file +-keep class com.isupatches.** { *; } \ No newline at end of file diff --git a/app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java b/app/src/androidTest/java/com/isupatches/wisefy/WiseFyTest.java similarity index 71% rename from app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java rename to app/src/androidTest/java/com/isupatches/wisefy/WiseFyTest.java index 92c216fb..e5526ee0 100644 --- a/app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java +++ b/app/src/androidTest/java/com/isupatches/wisefy/WiseFyTest.java @@ -1,7 +1,6 @@ -package com.metova.wisefy; +package com.isupatches.wisefy; -import android.app.Activity; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -10,15 +9,14 @@ import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.support.test.rule.ActivityTestRule; -import com.metova.wisefy.base.BaseTestClass; -import com.metova.wisefy.util.GetManagerUtil; -import com.metova.wisefy.util.TestActivity; +import com.isupatches.wisefy.base.BaseTestClass; +import com.isupatches.wisefy.base.TestActivity; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import java.util.ArrayList; import java.util.List; -import static com.metova.wisefy.util.TestUtils.*; +import static com.isupatches.wisefy.base.TestUtils.*; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -30,11 +28,9 @@ public class WiseFyTest extends BaseTestClass { private ConnectivityManager mMockConnectivityManager; - private GetManagerUtil mMockGetManagerUtil; - private WifiManager mMockWiFiManager; - private WiseFy mWiseFy = new WiseFy.getSmarts().initiateHamsters(); + private WiseFy mWiseFy; public WiseFyTest() { super(TestActivity.class); @@ -44,133 +40,119 @@ public WiseFyTest() { public void setUp() { mMockWiFiManager = mock(WifiManager.class); mMockConnectivityManager = mock(ConnectivityManager.class); - mMockGetManagerUtil = mock(GetManagerUtil.class); - - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(mMockWiFiManager); - when(mMockGetManagerUtil.getConnectivityManager(any(Activity.class))).thenReturn(mMockConnectivityManager); - - mWiseFy.mGetManagerUtil = mMockGetManagerUtil; mActivityTestRule.launchActivity(new Intent()); + + mWiseFy = new WiseFy.withContext(mActivityTestRule.getActivity()).getSmarts(); } @Test - public void testAddOpenNetwork() { - int result = mWiseFy.addOpenNetwork(mActivityTestRule.getActivity(), OPEN_NETWORK_SSID); + public void testAddOpenNetworkSuccess() { + setManagers(); + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID); assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result); } @Test - public void testAddOpenNetworkFailureToAdd() { + public void testAddOpenNetworkFailure() { + setManagers(); when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); - int result = mWiseFy.addOpenNetwork(mActivityTestRule.getActivity(), OPEN_NETWORK_SSID); + int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID); assertEquals(WiseFy.WIFI_MANAGER_FAILURE, result); } @Test - public void testAddOpenNetworkNullActivity() { - int result = mWiseFy.addOpenNetwork(null, OPEN_NETWORK_SSID); - assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); - } - - @Test - public void testAddOpenNetworkNullPassword() { - int result = mWiseFy.addOpenNetwork(mActivityTestRule.getActivity(), null); + public void testAddOpenNetworkNullSSID() { + int result = mWiseFy.addOpenNetwork(null); assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); } @Test public void testAddOpenNetworkNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - int result = mWiseFy.addOpenNetwork(mActivityTestRule.getActivity(), OPEN_NETWORK_SSID); + setManagersToNull(); + int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID); assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); } @Test - public void testAddWEPNetwork() { - int result = mWiseFy.addWEPNetwork(mActivityTestRule.getActivity(), WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); + public void testAddWEPNetworkSuccess() { + setManagers(); + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + int result = mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result); } @Test - public void testAddWEPNetworkFailureToAdd() { + public void testAddWEPNetworkFailure() { + setManagers(); when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); - int result = mWiseFy.addWEPNetwork(mActivityTestRule.getActivity(), WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); + int result = mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); assertEquals(WiseFy.WIFI_MANAGER_FAILURE, result); } @Test - public void testAddWEPNetworkNullActivity() { - int result = mWiseFy.addWEPNetwork(null, WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); + public void testAddWEPNetworkNullPassword() { + int result = mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, null); assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); } @Test public void testAddWEPNetworkNullSSID() { - int result = mWiseFy.addWEPNetwork(mActivityTestRule.getActivity(), null, WEP_NETWORK_PASSWORD); - assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); - } - - @Test - public void testAddWEPNetworkNullPassword() { - int result = mWiseFy.addWEPNetwork(mActivityTestRule.getActivity(), WEP_NETWORK_SSID, null); + int result = mWiseFy.addWEPNetwork(null, WEP_NETWORK_PASSWORD); assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); } @Test public void testAddWEPNetworkNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - int result = mWiseFy.addWEPNetwork(mActivityTestRule.getActivity(), WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); + setManagersToNull(); + int result = mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD); assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); } @Test - public void testAddWPA2Network() { - int result = mWiseFy.addWPA2Network(mActivityTestRule.getActivity(), WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); + public void testAddWPA2NetworkSuccess() { + setManagers(); + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + int result = mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result); } @Test - public void testAddWPA2NetworkFailureToAdd() { + public void testAddWPA2NetworkFailure() { when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); - int result = mWiseFy.addWPA2Network(mActivityTestRule.getActivity(), WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); + int result = mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); assertEquals(WiseFy.WIFI_MANAGER_FAILURE, result); } @Test - public void testAddWPA2NetworkNullActivity() { - int result = mWiseFy.addWPA2Network(null, WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); + public void testAddWPA2NetworkNullPassword() { + int result = mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, null); assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); } @Test public void testAddWPA2NetworkNullSSID() { - int result = mWiseFy.addWPA2Network(mActivityTestRule.getActivity(), null, WPA2_NETWORK_PASSWORD); - assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); - } - - @Test - public void testAddWPA2NetworkNullPassword() { - int result = mWiseFy.addWPA2Network(mActivityTestRule.getActivity(), WPA2_NETWORK_SSID, null); + int result = mWiseFy.addWPA2Network(null, WPA2_NETWORK_PASSWORD); assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); } @Test public void testAddWPA2NetworkNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - int result = mWiseFy.addWPA2Network(mActivityTestRule.getActivity(), WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); + setManagersToNull(); + int result = mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD); assertEquals(WiseFy.WISE_MANAGER_FAILURE, result); } @Test public void testBuilderWithLoggingFalse() { - WiseFy wiseFy = new WiseFy.getSmarts().withLogging(false).initiateHamsters(); + WiseFy wiseFy = new WiseFy.withContext(mActivityTestRule.getActivity()).logging(false).getSmarts(); assertEquals(false, wiseFy.isLoggingEnabled()); } @Test public void testBuilderWithLoggingTrue() { - WiseFy wiseFy = new WiseFy.getSmarts().withLogging(true).initiateHamsters(); + WiseFy wiseFy = new WiseFy.withContext(mActivityTestRule.getActivity()).logging(true).getSmarts(); assertEquals(true, wiseFy.isLoggingEnabled()); } @@ -188,12 +170,14 @@ public void testCompareSignalLevel() { @Test public void testConnectToNetworkFailureNoList() { - boolean result = mWiseFy.connectToNetwork(mActivityTestRule.getActivity(), TEST_SSID, 1); + setManagers(); + boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1); assertEquals(false, result); } @Test public void testConnectToNetworkFailureNotAvailable() { + setManagers(); List wifiList = new ArrayList<>(); WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); mWiFiConfiguration.SSID = TEST_SSID; @@ -211,12 +195,13 @@ public void testConnectToNetworkFailureNotAvailable() { when(mockNetworkInfo.isAvailable()).thenReturn(false); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.connectToNetwork(mActivityTestRule.getActivity(), TEST_SSID, 1); + boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1); assertEquals(false, result); } @Test public void testConnectToNetworkFailureNotConnected() { + setManagers(); List wifiList = new ArrayList<>(); WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); mWiFiConfiguration.SSID = TEST_SSID; @@ -234,25 +219,20 @@ public void testConnectToNetworkFailureNotConnected() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(false); - boolean result = mWiseFy.connectToNetwork(mActivityTestRule.getActivity(), TEST_SSID, 1); - assertEquals(false, result); - } - - @Test - public void testConnectToNetworkFailureNullActivity() { - boolean result = mWiseFy.connectToNetwork(null, TEST_SSID, 1); + boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1); assertEquals(false, result); } @Test public void testConnectToNetworkFailureNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - boolean result = mWiseFy.connectToNetwork(null, TEST_SSID, 1); + setManagersToNull(); + boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1); assertEquals(false, result); } @Test public void testConnectToNetworkSuccess() { + setManagers(); List wifiList = new ArrayList<>(); WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); mWiFiConfiguration.SSID = TEST_SSID; @@ -270,98 +250,104 @@ public void testConnectToNetworkSuccess() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.connectToNetwork(mActivityTestRule.getActivity(), TEST_SSID, 1); + boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1); assertEquals(true, result); } @Test public void testDisableWifiFailure() { + setManagers(); when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); - boolean result = mWiseFy.disableWifi(mActivityTestRule.getActivity()); + boolean result = mWiseFy.disableWifi(); verify(mMockWiFiManager).setWifiEnabled(false); assertEquals(true, result); } @Test - public void testDisableWifiNullActivity() { - boolean result = mWiseFy.disableWifi(null); + public void testDisableWifiNullWifiManager() { + setManagersToNull(); + boolean result = mWiseFy.disableWifi(); assertEquals(false, result); } @Test public void testDisableWifiSuccess() { + setManagers(); when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); - boolean result = mWiseFy.disableWifi(mActivityTestRule.getActivity()); + boolean result = mWiseFy.disableWifi(); verify(mMockWiFiManager).setWifiEnabled(false); assertEquals(true, result); } @Test public void testDisconnectFromCurrentNetworkFailure() { + setManagers(); when(mMockWiFiManager.disconnect()).thenReturn(false); - boolean result = mWiseFy.disconnectFromCurrentNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.disconnectFromCurrentNetwork(); verify(mMockWiFiManager).disconnect(); assertEquals(false, result); } @Test - public void testDisconnectFromCurrentNetworkNullActivity() { - boolean result = mWiseFy.disconnectFromCurrentNetwork(null); + public void testDisconnectFromCurrentNetworkNullWifiManager() { + setManagersToNull(); + boolean result = mWiseFy.disconnectFromCurrentNetwork(); assertEquals(false, result); } @Test public void testDisconnectFromCurrentNetworkSuccess() { + setManagers(); when(mMockWiFiManager.disconnect()).thenReturn(true); - boolean result = mWiseFy.disconnectFromCurrentNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.disconnectFromCurrentNetwork(); verify(mMockWiFiManager).disconnect(); assertEquals(true, result); } @Test public void testEnableWiFiFailure() { + setManagers(); when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); - boolean result = mWiseFy.enableWifi(mActivityTestRule.getActivity()); + boolean result = mWiseFy.enableWifi(); verify(mMockWiFiManager).setWifiEnabled(true); assertEquals(false, result); } @Test - public void testEnableWiFiNullActivity() { - boolean result = mWiseFy.enableWifi(null); + public void testEnableWiFiNullWifiManager() { + setManagersToNull(); + boolean result = mWiseFy.enableWifi(); assertEquals(false, result); } @Test public void testEnableWiFiSuccess() { + setManagers(); when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); - boolean result = mWiseFy.enableWifi(mActivityTestRule.getActivity()); + boolean result = mWiseFy.enableWifi(); verify(mMockWiFiManager).setWifiEnabled(true); assertEquals(true, result); } @Test public void testGetCurrentNetwork() { + setManagers(); WifiInfo mockWifiInfo = mock(WifiInfo.class); when(mockWifiInfo.getSSID()).thenReturn(TEST_SSID); when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); - assertEquals(TEST_SSID, mWiseFy.getCurrentNetwork(mActivityTestRule.getActivity()).getSSID()); - } - - @Test - public void testGetCurrentNetworkNullActivity() { - assertEquals(null, mWiseFy.getCurrentNetwork(null)); + assertEquals(TEST_SSID, mWiseFy.getCurrentNetwork().getSSID()); } @Test public void testGetCurrentNetworkNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - assertEquals(null, mWiseFy.getCurrentNetwork(mActivityTestRule.getActivity())); + setManagersToNull(); + assertEquals(null, mWiseFy.getCurrentNetwork()); } @Test public void testGetNearbyAccessPoints() { + setManagers(); List scanResults = new ArrayList<>(); ScanResult scanResult1 = mock(ScanResult.class); scanResult1.SSID = TEST_SSID; @@ -372,7 +358,7 @@ public void testGetNearbyAccessPoints() { when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); - List results = mWiseFy.getNearbyAccessPoints(mActivityTestRule.getActivity(), false); + List results = mWiseFy.getNearbyAccessPoints(false); assertEquals(scanResults, results); assertEquals(2, results.size()); @@ -380,6 +366,7 @@ public void testGetNearbyAccessPoints() { @Test public void testGetNearbyAccessPointsFilterDuplicatesDifferent() { + setManagers(); List scanResults = new ArrayList<>(); ScanResult scanResult1 = mock(ScanResult.class); scanResult1.SSID = TEST_SSID; @@ -390,7 +377,7 @@ public void testGetNearbyAccessPointsFilterDuplicatesDifferent() { when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); - List results = mWiseFy.getNearbyAccessPoints(mActivityTestRule.getActivity(), true); + List results = mWiseFy.getNearbyAccessPoints(true); assertEquals(scanResults, results); assertEquals(2, results.size()); @@ -398,6 +385,7 @@ public void testGetNearbyAccessPointsFilterDuplicatesDifferent() { @Test public void testGetNearbyAccessPointsFilterDuplicatesHigher() { + setManagers(); List scanResults = new ArrayList<>(); ScanResult scanResult1 = mock(ScanResult.class); scanResult1.SSID = TEST_SSID; @@ -413,7 +401,7 @@ public void testGetNearbyAccessPointsFilterDuplicatesHigher() { when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); - List results = mWiseFy.getNearbyAccessPoints(mActivityTestRule.getActivity(), true); + List results = mWiseFy.getNearbyAccessPoints(true); assertEquals(expectedScanResults, results); assertEquals(1, results.size()); @@ -421,6 +409,7 @@ public void testGetNearbyAccessPointsFilterDuplicatesHigher() { @Test public void testGetNearbyAccessPointsFilterDuplicatesLower() { + setManagers(); List scanResults = new ArrayList<>(); ScanResult scanResult1 = mock(ScanResult.class); scanResult1.SSID = TEST_SSID; @@ -436,49 +425,40 @@ public void testGetNearbyAccessPointsFilterDuplicatesLower() { when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); - List results = mWiseFy.getNearbyAccessPoints(mActivityTestRule.getActivity(), true); + List results = mWiseFy.getNearbyAccessPoints(true); assertEquals(expectedScanResults, results); assertEquals(1, results.size()); } - @Test - public void testGetNearbyAccessPointsNullActivity() { - List results = mWiseFy.getNearbyAccessPoints(null, true); - assertEquals(null, results); - } - @Test public void testGetNearbyAccessPointsNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - List results = mWiseFy.getNearbyAccessPoints(mActivityTestRule.getActivity(), true); + setManagersToNull(); + List results = mWiseFy.getNearbyAccessPoints(true); assertEquals(null, results); } @Test public void testGetSavedNetworks() { + 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(mActivityTestRule.getActivity())); - } - - @Test - public void testGetSavedNetworksNullActivity() { - assertEquals(null, mWiseFy.getSavedNetworks(null)); + assertEquals(wifiList, mWiseFy.getSavedNetworks()); } @Test public void testGetSavedNetworksNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - assertEquals(null, mWiseFy.getSavedNetworks(mActivityTestRule.getActivity())); + setManagersToNull(); + assertEquals(null, mWiseFy.getSavedNetworks()); } @Test public void testIsDeviceConnectedToMobileNetworkFailureSuccess() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("MOBILE"); @@ -486,12 +466,13 @@ public void testIsDeviceConnectedToMobileNetworkFailureSuccess() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(); assertEquals(true, result); } @Test public void testIsDeviceConnectedToMobileNetworkFailureNotAvailable() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("MOBILE"); @@ -499,12 +480,13 @@ public void testIsDeviceConnectedToMobileNetworkFailureNotAvailable() { when(mockNetworkInfo.isAvailable()).thenReturn(false); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToMobileNetworkFailureNotConnected() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("MOBILE"); @@ -512,12 +494,13 @@ public void testIsDeviceConnectedToMobileNetworkFailureNotConnected() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(false); - boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToMobileNetworkFailureWrongType() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("WRONG TYPE"); @@ -525,25 +508,20 @@ public void testIsDeviceConnectedToMobileNetworkFailureWrongType() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(null); - assertEquals(false, result); - } - - @Test - public void testIsDeviceConnectedToMobileNetworkNullActivity() { - boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(null); + boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToMobileNetworkNullConfigurationManager() { - when(mMockGetManagerUtil.getConnectivityManager(any(Activity.class))).thenReturn(null); - boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(mActivityTestRule.getActivity()); + setManagersToNull(); + boolean result = mWiseFy.isDeviceConnectedToMobileNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToMobileOrWifiNetworkFailureSuccessMobile() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("MOBILE"); @@ -551,12 +529,13 @@ public void testIsDeviceConnectedToMobileOrWifiNetworkFailureSuccessMobile() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(); assertEquals(true, result); } @Test public void testIsDeviceConnectedToMobileOrWifiNetworkFailureSuccessWifi() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("WIFI"); @@ -564,12 +543,13 @@ public void testIsDeviceConnectedToMobileOrWifiNetworkFailureSuccessWifi() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(); assertEquals(true, result); } @Test public void testIsDeviceConnectedToMobileOrWifiNetworkFailureNotAvailableMobile() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("MOBILE"); @@ -577,12 +557,13 @@ public void testIsDeviceConnectedToMobileOrWifiNetworkFailureNotAvailableMobile( when(mockNetworkInfo.isAvailable()).thenReturn(false); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToMobileOrWifiNetworkFailureNotAvailableWifi() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("WIFI"); @@ -590,12 +571,13 @@ public void testIsDeviceConnectedToMobileOrWifiNetworkFailureNotAvailableWifi() when(mockNetworkInfo.isAvailable()).thenReturn(false); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToMobileOrWifiNetworkFailureNotConnectedMobile() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("MOBILE"); @@ -603,12 +585,13 @@ public void testIsDeviceConnectedToMobileOrWifiNetworkFailureNotConnectedMobile( when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(false); - boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToMobileOrWifiNetworkFailureNotConnectedWifi() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("WIFI"); @@ -616,38 +599,20 @@ public void testIsDeviceConnectedToMobileOrWifiNetworkFailureNotConnectedWifi() when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(false); - boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(mActivityTestRule.getActivity()); - assertEquals(false, result); - } - - @Test - public void testIsDeviceConnectedToMobileOrWifiNetworkFailureWrongType() { - NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); - when(mockNetworkInfo.getTypeName()).thenReturn("WRONG TYPE"); - - when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mockNetworkInfo); - when(mockNetworkInfo.isAvailable()).thenReturn(true); - when(mockNetworkInfo.isConnected()).thenReturn(true); - - boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(null); - assertEquals(false, result); - } - - @Test - public void testIsDeviceConnectedToMobileWifiNetworkNullActivity() { - boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(null); + boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToMobileOrWifiNetworkNullConfigurationManager() { - when(mMockGetManagerUtil.getConnectivityManager(any(Activity.class))).thenReturn(null); - boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(mActivityTestRule.getActivity()); + setManagersToNull(); + boolean result = mWiseFy.isDeviceConnectedToMobileOrWifiNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToSSID() { + setManagers(); List wifiList = new ArrayList<>(); WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); mWiFiConfiguration.SSID = TEST_SSID; @@ -665,12 +630,13 @@ public void testIsDeviceConnectedToSSID() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToSSID(mActivityTestRule.getActivity(), TEST_SSID); + boolean result = mWiseFy.isDeviceConnectedToSSID(TEST_SSID); assertEquals(true, result); } @Test public void testIsDeviceConnectedToSSIDFailureOtherSSID() { + setManagers(); List wifiList = new ArrayList<>(); WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); mWiFiConfiguration.SSID = TEST_SSID2; @@ -688,12 +654,13 @@ public void testIsDeviceConnectedToSSIDFailureOtherSSID() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToSSID(mActivityTestRule.getActivity(), TEST_SSID); + boolean result = mWiseFy.isDeviceConnectedToSSID(TEST_SSID); assertEquals(false, result); } @Test public void testIsDeviceConnectedToSSIDFailureNotAvailable() { + setManagers(); List wifiList = new ArrayList<>(); WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); mWiFiConfiguration.SSID = TEST_SSID; @@ -711,12 +678,13 @@ public void testIsDeviceConnectedToSSIDFailureNotAvailable() { when(mockNetworkInfo.isAvailable()).thenReturn(false); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToSSID(mActivityTestRule.getActivity(), TEST_SSID); + boolean result = mWiseFy.isDeviceConnectedToSSID(TEST_SSID); assertEquals(false, result); } @Test public void testIsDeviceConnectedToSSIDFailureNotConnected() { + setManagers(); List wifiList = new ArrayList<>(); WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); mWiFiConfiguration.SSID = TEST_SSID; @@ -734,25 +702,20 @@ public void testIsDeviceConnectedToSSIDFailureNotConnected() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(false); - boolean result = mWiseFy.isDeviceConnectedToSSID(mActivityTestRule.getActivity(), TEST_SSID); - assertEquals(false, result); - } - - @Test - public void testIsDeviceConnectedToSSIDFailureNullActivity() { - boolean result = mWiseFy.isDeviceConnectedToSSID(null, TEST_SSID); + boolean result = mWiseFy.isDeviceConnectedToSSID(TEST_SSID); assertEquals(false, result); } @Test public void testIsDeviceConnectedToSSIDFailureNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - boolean result = mWiseFy.isDeviceConnectedToSSID(mActivityTestRule.getActivity(), TEST_SSID); + setManagersToNull(); + boolean result = mWiseFy.isDeviceConnectedToSSID(TEST_SSID); assertEquals(false, result); } @Test public void testIsDeviceConnectedToWifiNetworkFailureSuccess() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("WIFI"); @@ -760,12 +723,13 @@ public void testIsDeviceConnectedToWifiNetworkFailureSuccess() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(); assertEquals(true, result); } @Test public void testIsDeviceConnectedToWifiNetworkFailureNotAvailable() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("WIFI"); @@ -773,12 +737,13 @@ public void testIsDeviceConnectedToWifiNetworkFailureNotAvailable() { when(mockNetworkInfo.isAvailable()).thenReturn(false); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToWifiNetworkFailureNotConnected() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("WIFI"); @@ -786,12 +751,13 @@ public void testIsDeviceConnectedToWifiNetworkFailureNotConnected() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(false); - boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(mActivityTestRule.getActivity()); + boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToWifiNetworkFailureWrongType() { + setManagers(); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); when(mockNetworkInfo.getTypeName()).thenReturn("WRONG TYPE"); @@ -799,54 +765,46 @@ public void testIsDeviceConnectedToWifiNetworkFailureWrongType() { when(mockNetworkInfo.isAvailable()).thenReturn(true); when(mockNetworkInfo.isConnected()).thenReturn(true); - boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(null); - assertEquals(false, result); - } - - @Test - public void testIsDeviceConnectedToWifiNetworkNullActivity() { - boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(null); + boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(); assertEquals(false, result); } @Test public void testIsDeviceConnectedToWifiNetworkNullConfigurationManager() { - when(mMockGetManagerUtil.getConnectivityManager(any(Activity.class))).thenReturn(null); - boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(mActivityTestRule.getActivity()); + setManagersToNull(); + boolean result = mWiseFy.isDeviceConnectedToWifiNetwork(); assertEquals(false, result); } @Test public void testIsNetworkInConfigurationListFailure() { - assertEquals(false, mWiseFy.isNetworkInConfigurationList(mActivityTestRule.getActivity(), TEST_SSID)); + setManagers(); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); } @Test public void testIsNetworkInConfigurationListFailureNoNetworks() { + setManagers(); List wifiList = new ArrayList<>(); when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); - assertEquals(false, mWiseFy.isNetworkInConfigurationList(mActivityTestRule.getActivity(), TEST_SSID)); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); } @Test public void testIsNetworkInConfigurationListSuccess() { + 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(mActivityTestRule.getActivity(), TEST_SSID)); - } - - @Test - public void testIsNetworkInConfigurationNullActivity() { - assertEquals(false, mWiseFy.isNetworkInConfigurationList(null, TEST_SSID)); + assertEquals(true, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); } @Test public void testIsNetworkInConfigurationNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - assertEquals(false, mWiseFy.isNetworkInConfigurationList(mActivityTestRule.getActivity(), TEST_SSID)); + setManagersToNull(); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); } @Test @@ -885,61 +843,56 @@ public void testIsNetworkSecureNullCapabilities() { @Test public void testIsWifiEnabledFailure() { + setManagers(); when(mMockWiFiManager.isWifiEnabled()).thenReturn(false); - assertEquals(false, mWiseFy.isWifiEnabled(mActivityTestRule.getActivity())); + assertEquals(false, mWiseFy.isWifiEnabled()); } @Test public void testIsWifiEnabledSuccess() { + setManagers(); when(mMockWiFiManager.isWifiEnabled()).thenReturn(true); - assertEquals(true, mWiseFy.isWifiEnabled(mActivityTestRule.getActivity())); - } - - @Test - public void testIsWifiEnabledNullActivity() { - assertEquals(false, mWiseFy.isWifiEnabled(null)); + assertEquals(true, mWiseFy.isWifiEnabled()); } @Test public void testIsWifiEnabledNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - assertEquals(false, mWiseFy.isWifiEnabled(mActivityTestRule.getActivity())); + setManagersToNull(); + assertEquals(false, mWiseFy.isWifiEnabled()); } @Test public void testRemoveNetworkFailure() { + setManagers(); when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(getTestWifiConfiguration()); when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(false); - boolean result = mWiseFy.removeNetwork(mActivityTestRule.getActivity(), TEST_SSID); + boolean result = mWiseFy.removeNetwork(TEST_SSID); assertEquals(false, result); } @Test public void testRemoveNetworkFailureNotInList() { + setManagers(); List wifiList = new ArrayList<>(); when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(false); - boolean result = mWiseFy.removeNetwork(mActivityTestRule.getActivity(), TEST_SSID); + boolean result = mWiseFy.removeNetwork(TEST_SSID); assertEquals(false, result); } - @Test - public void testRemoveNetworkNullActivity() { - boolean result = mWiseFy.removeNetwork(null, TEST_SSID); - assertEquals(false, result); - } @Test public void testRemoveNetworkNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - boolean result = mWiseFy.removeNetwork(null, TEST_SSID); + setManagersToNull(); + boolean result = mWiseFy.removeNetwork(TEST_SSID); assertEquals(false, result); } @Test public void testRemoveNetworkSuccess() { + setManagers(); List wifiList = new ArrayList<>(); WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); mWiFiConfiguration.SSID = TEST_SSID; @@ -947,32 +900,29 @@ public void testRemoveNetworkSuccess() { when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(true); - boolean result = mWiseFy.removeNetwork(mActivityTestRule.getActivity(), TEST_SSID); + boolean result = mWiseFy.removeNetwork(TEST_SSID); assertEquals(true, result); } @Test public void testSearchSSIDNFailure() { + setManagers(); WifiInfo mockWifiInfo = mock(WifiInfo.class); when(mockWifiInfo.getSSID()).thenReturn(TEST_SSID); when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); - assertEquals(null, mWiseFy.searchForSSID(mActivityTestRule.getActivity(), TEST_SSID, 1)); - } - - @Test - public void testSearchSSIDNullActivity() { - assertEquals(null, mWiseFy.searchForSSID(null, TEST_SSID, 1)); + assertEquals(null, mWiseFy.searchForSSID(TEST_SSID, 1)); } @Test public void testSearchSSIDNullWifiManager() { - when(mMockGetManagerUtil.getWiFiManager(any(Activity.class))).thenReturn(null); - assertEquals(null, mWiseFy.searchForSSID(null, TEST_SSID, 1)); + setManagersToNull(); + assertEquals(null, mWiseFy.searchForSSID(TEST_SSID, 1)); } @Test public void testSearchSSIDSuccess() { + setManagers(); List scanResults = new ArrayList<>(); ScanResult scanResult = mock(ScanResult.class); scanResult.SSID = TEST_SSID; @@ -983,6 +933,20 @@ public void testSearchSSIDSuccess() { when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); - assertEquals(TEST_SSID, mWiseFy.searchForSSID(mActivityTestRule.getActivity(), TEST_SSID, 1)); + assertEquals(TEST_SSID, mWiseFy.searchForSSID(TEST_SSID, 1)); + } + + /** + * HELPERS + */ + + private void setManagers() { + mWiseFy.mWifiManager = mMockWiFiManager; + mWiseFy.mConnectivityManager = mMockConnectivityManager; + } + + private void setManagersToNull() { + mWiseFy.mWifiManager = null; + mWiseFy.mConnectivityManager = null; } } \ No newline at end of file diff --git a/app/src/androidTest/java/com/isupatches/wisefy/base/BaseTestClass.java b/app/src/androidTest/java/com/isupatches/wisefy/base/BaseTestClass.java new file mode 100644 index 00000000..e5d4a654 --- /dev/null +++ b/app/src/androidTest/java/com/isupatches/wisefy/base/BaseTestClass.java @@ -0,0 +1,13 @@ +package com.isupatches.wisefy.base; + + +import android.app.Activity; +import android.support.test.rule.ActivityTestRule; + + +public abstract class BaseTestClass extends ActivityTestRule { + + public BaseTestClass(Class activityClass) { + super(activityClass); + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/com/metova/wisefy/util/TestActivity.java b/app/src/androidTest/java/com/isupatches/wisefy/base/TestActivity.java similarity index 68% rename from app/src/androidTest/java/com/metova/wisefy/util/TestActivity.java rename to app/src/androidTest/java/com/isupatches/wisefy/base/TestActivity.java index f93047ea..813c4c5e 100644 --- a/app/src/androidTest/java/com/metova/wisefy/util/TestActivity.java +++ b/app/src/androidTest/java/com/isupatches/wisefy/base/TestActivity.java @@ -1,4 +1,4 @@ -package com.metova.wisefy.util; +package com.isupatches.wisefy.base; import android.app.Activity; diff --git a/app/src/androidTest/java/com/metova/wisefy/util/TestUtils.java b/app/src/androidTest/java/com/isupatches/wisefy/base/TestUtils.java similarity index 96% rename from app/src/androidTest/java/com/metova/wisefy/util/TestUtils.java rename to app/src/androidTest/java/com/isupatches/wisefy/base/TestUtils.java index 4250840a..3ddb26a4 100644 --- a/app/src/androidTest/java/com/metova/wisefy/util/TestUtils.java +++ b/app/src/androidTest/java/com/isupatches/wisefy/base/TestUtils.java @@ -1,4 +1,4 @@ -package com.metova.wisefy.util; +package com.isupatches.wisefy.base; import android.net.wifi.WifiConfiguration; diff --git a/app/src/androidTest/java/com/metova/wisefy/util/GetManagerUtilTest.java b/app/src/androidTest/java/com/isupatches/wisefy/util/GetManagerUtilTest.java similarity index 90% rename from app/src/androidTest/java/com/metova/wisefy/util/GetManagerUtilTest.java rename to app/src/androidTest/java/com/isupatches/wisefy/util/GetManagerUtilTest.java index d38e140a..6e841ba8 100644 --- a/app/src/androidTest/java/com/metova/wisefy/util/GetManagerUtilTest.java +++ b/app/src/androidTest/java/com/isupatches/wisefy/util/GetManagerUtilTest.java @@ -1,10 +1,11 @@ -package com.metova.wisefy.util; +package com.isupatches.wisefy.util; import android.net.ConnectivityManager; import android.net.wifi.WifiManager; import android.support.test.rule.ActivityTestRule; -import com.metova.wisefy.base.BaseTestClass; +import com.isupatches.wisefy.base.BaseTestClass; +import com.isupatches.wisefy.base.TestActivity; import org.junit.Rule; import org.junit.Test; import static junit.framework.Assert.*; diff --git a/app/src/androidTest/java/com/metova/wisefy/base/BaseTestClass.java b/app/src/androidTest/java/com/metova/wisefy/base/BaseTestClass.java deleted file mode 100644 index 6ef3498a..00000000 --- a/app/src/androidTest/java/com/metova/wisefy/base/BaseTestClass.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.metova.wisefy.base; - - -import android.app.Activity; -import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.rule.ActivityTestRule; - - -public abstract class BaseTestClass extends ActivityTestRule { - - private Context targetContext = InstrumentationRegistry.getTargetContext(); - - - public BaseTestClass(Class activityClass) { - super(activityClass); - } - - - public Context getTargetContext() { - return targetContext; - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 673cb207..27cb118f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.isupatches.wisefy"> @@ -15,7 +15,7 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/java/com/isupatches/wisefy/WiseFy.java b/app/src/main/java/com/isupatches/wisefy/WiseFy.java new file mode 100644 index 00000000..9fa048a1 --- /dev/null +++ b/app/src/main/java/com/isupatches/wisefy/WiseFy.java @@ -0,0 +1,756 @@ +/** + * Copyright 2016 Patches Klinefelter + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.isupatches.wisefy; + + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.ScanResult; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.text.TextUtils; +import com.isupatches.wisefy.util.GetManagerUtil; +import com.isupatches.wisefy.util.LogUtil; +import com.isupatches.wisefy.util.SSIDUtil; +import java.util.ArrayList; +import java.util.List; + + +/** + * Main class to manipulate and query network settings on an Android device + * + * Uses the builder pattern for creation - {@link withContext} + */ +public class WiseFy { + + private static final String TAG = WiseFy.class.getSimpleName(); + + public static final int WISE_MANAGER_FAILURE = -1000; + + public static final int WIFI_MANAGER_FAILURE = -1; + + private LogUtil mLogUtil = LogUtil.getInstance(); + + private SSIDUtil mSSIDUtil = SSIDUtil.getInstance(); + + public ConnectivityManager mConnectivityManager; + + public WifiManager mWifiManager; + + private boolean mLoggingEnabled; + + /** + * Private constructor that accepts builder input + */ + private WiseFy(withContext withContext) { + this.mLoggingEnabled = withContext.loggingEnabled; + this.mConnectivityManager = GetManagerUtil.getInstance().getConnectivityManager(withContext.context); + this.mWifiManager = GetManagerUtil.getInstance().getWiFiManager(withContext.context); + } + + /** + * Static class for builder pattern + * + * Implements builder interfaces #{@link Logging} #{@link GetSmarts} + */ + public static class withContext implements Logging, GetSmarts { + + private Context context; + + private boolean loggingEnabled; + + /** + * Mandatory - The public constructor for the builder that requires a context + * + * @param context - The activity or application context to get a WifiConfiguration and + * ConnectivityManager instance + * + */ + public withContext(Context context) { + this.context = context; + } + + /** + * Mandatory - To build and return a WiseFy instance + * + * Must be called after withContext + * {@link #withContext(Context)} + * + * @return WiseFy - The instance created by the builder + * + */ + @Override + public WiseFy getSmarts() { + return new WiseFy(this); + } + + /** + * Optional - Builder method that enables/disables logging for a WiseWy instance + * + * @param loggingEnabled - If logging is enabled or disabled for an instance + * {@link Logging} + * + * @return withContext - The builder with updated logging setting + */ + @Override + public withContext logging(boolean loggingEnabled) { + this.loggingEnabled = loggingEnabled; + return this; + } + } + + /** + * An interface that enables/disables logging for a WiseFy instance + */ + interface Logging { + withContext logging(boolean loggingEnabled); + } + + /** + * An interface that builds a WiseFy instance + */ + interface GetSmarts { + WiseFy getSmarts(); + } + + /** + * To add an open network to the user's configured network list + * + * @param ssid - The ssid of the open network you want to add + * + * @return int - The return code from WifiManager for network creation (-1 for failure) + */ + public int addOpenNetwork(String ssid) { + if (TextUtils.isEmpty(ssid)) { + mLogUtil.e(TAG, "Breaking due to empty SSID", mLoggingEnabled); + return WISE_MANAGER_FAILURE; + } + if (mWifiManager != null) { + boolean ssidAlreadyConfigured = checkIfNetworkInConfigurationList(ssid); + + if (!ssidAlreadyConfigured) { + mLogUtil.d(TAG, "Adding open network with SSID " + ssid, mLoggingEnabled); + + WifiConfiguration wifiConfig = new WifiConfiguration(); + + wifiConfig.SSID = mSSIDUtil.convertSSIDForConfig(ssid); + wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); + wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); + wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); + wifiConfig.allowedAuthAlgorithms.clear(); + wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); + wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); + wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); + wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); + wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); + + return addNetwork(wifiConfig); + } + } else { + mLogUtil.e(TAG, "No mWifiManager to connect to add open network", mLoggingEnabled); + } + return WISE_MANAGER_FAILURE; + } + + /** + * To add a WEP network to the user's configured network list + * + * @param ssid - The ssid of the WEP network you want to add + * @param password - The password for the WEP network being added + * + * @return int - The return code from WifiManager for network creation (-1 for failure) + */ + public int addWEPNetwork(String ssid, String password) { + if (TextUtils.isEmpty(ssid) || TextUtils.isEmpty(password)) { + mLogUtil.w(TAG, "Breaking due to missing ssid or password. ssid: " + ssid + ", password: " + password, mLoggingEnabled); + return WISE_MANAGER_FAILURE; + } + if (mWifiManager != null) { + boolean ssidAlreadyConfigured = checkIfNetworkInConfigurationList(ssid); + + if (!ssidAlreadyConfigured) { + mLogUtil.d(TAG, "Adding WEP network with SSID " + ssid, mLoggingEnabled); + + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.SSID = mSSIDUtil.convertSSIDForConfig(ssid); + wifiConfig.wepKeys[0] = "\"" + password + "\""; + wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); + wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); + wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); + wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); + wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); + wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); + wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); + wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); + + return addNetwork(wifiConfig); + } + } else { + mLogUtil.e(TAG, "No mWifiManager to connect to add WEP network", mLoggingEnabled); + } + return WISE_MANAGER_FAILURE; + } + + /** + * To add a WPA2 network to the user's configured network list + * + * @param ssid - The ssid of the WPA2 network you want to add + * @param password - The password for the WPA2 network being added + * + * @return int - The return code from WifiManager for network creation (-1 for failure) + */ + public int addWPA2Network(String ssid, String password) { + if (TextUtils.isEmpty(ssid) || TextUtils.isEmpty(password)) { + mLogUtil.w(TAG, "Breaking due to missing ssid or password. ssid: " + ssid + ", password: " + password, mLoggingEnabled); + return WISE_MANAGER_FAILURE; + } + if (mWifiManager != null) { + boolean ssidAlreadyConfigured = checkIfNetworkInConfigurationList(ssid); + + if (!ssidAlreadyConfigured) { + mLogUtil.d(TAG, "Adding WPA2 network with SSID " + ssid, mLoggingEnabled); + + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.SSID = mSSIDUtil.convertSSIDForConfig(ssid); + wifiConfig.preSharedKey = "\"" + password + "\""; + wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); + wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); + wifiConfig.status = WifiConfiguration.Status.ENABLED; + wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); + wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); + wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); + wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); + wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); + + wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); + wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + + return addNetwork(wifiConfig); + } + } else { + mLogUtil.e(TAG, "No mWifiManager to connect to add WPA2 network", mLoggingEnabled); + } + return WISE_MANAGER_FAILURE; + } + + /** + * To convert an RSSI level for a network to a number of bars + * + * @param rssiLevel - The signal strength of the network + * @param targetNumberOfBars - How many bars or levels there will be total + * + * @return int - The number of bars for the given RSSI value + */ + public int calculateBars(int rssiLevel, int targetNumberOfBars) { + return WifiManager.calculateSignalLevel(rssiLevel, targetNumberOfBars); + } + + /** + * To compare the signal strength of two networks + * + * @param rssi1 - The signal strength of network 1 + * @param rssi2 - The signal strength of network 2 + * + * @return int - Returns negative value if the first signal is weaker than the second signal, 0 if the two + * signals have the same strength, and a positive value if the first signal is stronger than the second signal. + */ + public int compareSignalLevel(int rssi1, int rssi2) { + return WifiManager.compareSignalLevel(rssi1, rssi2); + } + + /** + * Used to connect to a network + * + * Gets a list of saved networks, connects/reconnects to the given ssid, and then calls waitToConnectToSSID to verify connectivity + * + * @param ssidToConnectTo - The ssid to connect/reconnect to + * @param timeoutInMillis - The number of milliseconds to continue waiting for the device to connect to the given SSID + * + * @return boolean - If the network was successfully reconnected + */ + public boolean connectToNetwork(String ssidToConnectTo, int timeoutInMillis) { + mLogUtil.d(TAG, "Connecting to network: " + ssidToConnectTo, mLoggingEnabled); + if (mWifiManager != null) { + List list = mWifiManager.getConfiguredNetworks(); + if (list != null) { + for (int i = 0; i < list.size(); i++) { + WifiConfiguration wifiConfiguration = list.get(i); + if (wifiConfiguration != null && wifiConfiguration.SSID != null) { + String ssidInList = wifiConfiguration.SSID.replaceAll("\"", ""); + + mLogUtil.d(TAG, "Configured WiFi Network {index:" + i + ", ssidInList:" + ssidInList + "}", mLoggingEnabled); + if (ssidInList.equals(ssidToConnectTo)) { + mLogUtil.d(TAG, "ssidToReconnectTo: " + ssidToConnectTo + " matches ssidInList:" + ssidInList, mLoggingEnabled); + mWifiManager.disconnect(); + mWifiManager.enableNetwork(wifiConfiguration.networkId, true); + mWifiManager.reconnect(); + return waitToConnectToSSID(ssidToConnectTo, timeoutInMillis); + } + } + } + } + mLogUtil.w(TAG, "ssidToReconnectTo: " + ssidToConnectTo + " was not found in list to connect to", mLoggingEnabled); + } else { + mLogUtil.e(TAG, "No mWifiManager to connect to network. SSID: " + ssidToConnectTo, mLoggingEnabled); + } + return false; + } + + /** + * To disable Wifi on a user's device + * + * @return boolean - If the command succeeded in disabling wifi + */ + public boolean disableWifi() { + mLogUtil.d(TAG, "Disabling WiFi", mLoggingEnabled); + if (mWifiManager != null) { + return mWifiManager.setWifiEnabled(false); + } else { + mLogUtil.e(TAG, "No mWifiManager to disable Wifi", mLoggingEnabled); + } + return false; + } + + /** + * To disconnect the user from their current network + * + * @return boolean - If the command succeeded in disconnecting the device from the current network + */ + public boolean disconnectFromCurrentNetwork() { + mLogUtil.d(TAG, "Disconnecting from current network", mLoggingEnabled); + if (mWifiManager != null) { + return mWifiManager.disconnect(); + } else { + mLogUtil.e(TAG, "No mWifiManager to disconnect from current network", mLoggingEnabled); + } + return false; + } + + /** + * To enable Wifi on a user's device + * + * @return boolean - If the command succeeded in enabling wifi + */ + public boolean enableWifi() { + mLogUtil.d(TAG, "Enabling WiFi", mLoggingEnabled); + if (mWifiManager != null) { + return mWifiManager.setWifiEnabled(true); + } else { + mLogUtil.e(TAG, "No mWifiManager to enable wifi", mLoggingEnabled); + } + return false; + } + + /** + * To retrieve the user's current network + * + * @return WifiInfo|null - The user's current network information + */ + public WifiInfo getCurrentNetwork() { + if (mWifiManager != null) { + return mWifiManager.getConnectionInfo(); + } else { + mLogUtil.e(TAG, "No mWifiManager to get current network", mLoggingEnabled); + } + return null; + } + + /** + * 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) + * + * @param filterDuplicates - If you want to exclude SSIDs with that same name that have a weaker signal strength + * + * @return List of ScanResults|null - List of nearby access points + */ + public List getNearbyAccessPoints(boolean filterDuplicates) { + if (mWifiManager != null) { + mWifiManager.startScan(); + if (!filterDuplicates) { + return mWifiManager.getScanResults(); + } else { + List scanResults = mWifiManager.getScanResults(); + List scanResultsToReturn = new ArrayList<>(); + + for (ScanResult newScanResult : scanResults) { + boolean found = false; + for (int i = 0; i < scanResultsToReturn.size(); i++) { + ScanResult scanResult = scanResultsToReturn.get(i); + mLogUtil.d(TAG, "SSID 1: " + newScanResult.SSID + ". SSID 2: " + scanResult.SSID, mLoggingEnabled); + if (newScanResult.SSID.equalsIgnoreCase(scanResult.SSID)) { + found = true; + mLogUtil.d(TAG, "SSID did match", mLoggingEnabled); + + mLogUtil.d(TAG, "Current level: " + scanResult.level, mLoggingEnabled); + mLogUtil.d(TAG, "New level: " + newScanResult.level, mLoggingEnabled); + mLogUtil.d(TAG, "comparison result: " + WifiManager.compareSignalLevel(newScanResult.level, scanResult.level), mLoggingEnabled); + + if (WifiManager.compareSignalLevel(newScanResult.level, scanResult.level) > 0) { + mLogUtil.d(TAG, "New result has a higher signal strength, swapping", mLoggingEnabled); + scanResultsToReturn.set(i, newScanResult); + } + } else { + mLogUtil.d(TAG, "SSID did not match", mLoggingEnabled); + } + } + + if (!found) { + mLogUtil.d(TAG, "Found new wifi network", mLoggingEnabled); + scanResultsToReturn.add(newScanResult); + } + } + return scanResultsToReturn; + } + } else { + mLogUtil.e(TAG, "No mWifiManager to get nearby access points", mLoggingEnabled); + } + return null; + } + + /** + * To retrieve a list of saved networks on a user's device + * + * @return List of WifiConfiguration|null - List of saved networks on a users device + */ + public List getSavedNetworks() { + if (mWifiManager != null) { + return mWifiManager.getConfiguredNetworks(); + } else { + mLogUtil.e(TAG, "No mWifiManager to get saved networks", mLoggingEnabled); + } + return null; + } + + /** + * To check if the device is connected to a mobile network + * + * @return bool - If the device is currently connected to a mobile network + */ + public boolean isDeviceConnectedToMobileNetwork() { + if (mConnectivityManager != null) { + NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); + if (networkInfo != null && networkInfo.getTypeName().equalsIgnoreCase("MOBILE")) { + if (networkInfo.isConnected() && networkInfo.isAvailable()) { + return true; + } + } + } else { + mLogUtil.e(TAG, "No mConnectivityManager check if device is connected to mobile network", mLoggingEnabled); + } + return false; + } + + /** + * To check if the device is connected to a mobile or wifi network + * + * @return bool - If the device is currently connected to a mobile or wifi network + */ + public boolean isDeviceConnectedToMobileOrWifiNetwork() { + if (mConnectivityManager != null) { + NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); + if (networkInfo.isConnected() && networkInfo.isAvailable()) { + return true; + } + } else { + mLogUtil.e(TAG, "No mConnectivityManager check if device is connected to mobile or wifi network", mLoggingEnabled); + } + return false; + } + + /** + * To check if the device is connected to a given SSID + * + * Used by connectToNetwork + * + * @param ssid - The SSID to check if the device is attached to + * + * @return bool - If the device is currently attached to the given SSID + */ + public boolean isDeviceConnectedToSSID(String ssid) { + if (mWifiManager != null) { + WifiInfo connectionInfo = mWifiManager.getConnectionInfo(); + if (connectionInfo != null && connectionInfo.getSSID() != null) { + String currentSSID = connectionInfo.getSSID().replaceAll("\"", ""); + mLogUtil.d(TAG, "Current SSID: " + currentSSID, mLoggingEnabled); + + if (currentSSID.equals(ssid)) { + mLogUtil.d(TAG, "Correct SSID", mLoggingEnabled); + if (mConnectivityManager != null + && mConnectivityManager.getActiveNetworkInfo() != null + && mConnectivityManager.getActiveNetworkInfo().isAvailable() + && mConnectivityManager.getActiveNetworkInfo().isConnected()) { + mLogUtil.d(TAG, "Network is connected", mLoggingEnabled); + return true; + } + } + } + } else { + mLogUtil.e(TAG, "No mWifiManager check if device is connected to SSID: " + ssid, mLoggingEnabled); + } + return false; + } + + /** + * To check if the device is connected to a wifi network + * + * @return bool - If the device is currently connected to a wifi network + */ + public boolean isDeviceConnectedToWifiNetwork() { + if (mConnectivityManager != null) { + NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); + if (networkInfo != null && networkInfo.getTypeName().equalsIgnoreCase("WIFI")) { + if (networkInfo.isConnected() && networkInfo.isAvailable()) { + return true; + } + } + } else { + mLogUtil.e(TAG, "No mConnectivityManager check if device is connected to wifi network", mLoggingEnabled); + } + return false; + } + + /** + * 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 + * + * @return boolean - If the SSID is in the list of configured networks + */ + public boolean isNetworkInConfigurationList(String ssid) { + if(mWifiManager != null) { + return checkIfNetworkInConfigurationList(ssid); + } else { + mLogUtil.e(TAG, "No mWifiManager to check if network is in the configuration list", mLoggingEnabled); + } + return false; + } + + /** + * To check and return if a network is secure (WEP/PSK/EAP capabilities) + * + * @param scanResult - The network to see if it is secure + * + * @return boolean - Whether the network is secure + */ + public boolean isNetworkSecure(ScanResult scanResult) { + boolean isSecure = false; + if (scanResult != null && scanResult.capabilities != null) { + if (scanResult.capabilities.contains("WEP") || scanResult.capabilities.contains("PSK") || scanResult.capabilities.contains("EAP")) { + isSecure = true; + } + } + return isSecure; + } + + /** + * To check if Wifi is enabled on the device or not + * + * @return boolean - if Wifi is enabled on device + */ + public boolean isWifiEnabled() { + if (mWifiManager != null) { + return mWifiManager.isWifiEnabled(); + } else { + mLogUtil.e(TAG, "No mWifiManager to check if wifi is enabled", mLoggingEnabled); + } + return false; + } + + /** + * To remove a configured network + * + * @param ssidToRemove - The ssid of the network you want to remove from the configured network list + * + * @return boolean - If the command succeeded in removing the network + */ + public boolean removeNetwork(String ssidToRemove) { + if (mWifiManager != null) { + List list = mWifiManager.getConfiguredNetworks(); + if (list != null) { + for (int i = 0; i < list.size(); i++) { + WifiConfiguration wifiConfiguration = list.get(i); + if (wifiConfiguration != null && wifiConfiguration.SSID != null) { + String ssidInList = wifiConfiguration.SSID.replaceAll("\"", ""); + + mLogUtil.d(TAG, "Configured WiFi Network {index:" + i + ", ssidInList:" + ssidInList + "}", mLoggingEnabled); + if (ssidInList.equals(ssidToRemove)) { + mLogUtil.d(TAG, "Removing network: " + ssidToRemove, mLoggingEnabled); + mWifiManager.disconnect(); + boolean result = mWifiManager.removeNetwork(wifiConfiguration.networkId); + if (result) { + mLogUtil.d(TAG, "Successfully removed network", mLoggingEnabled); + mWifiManager.saveConfiguration(); + } else { + mLogUtil.d(TAG, "Failed to remove network", mLoggingEnabled); + } + mWifiManager.reconnect(); + return result; + } + } + } + } + mLogUtil.w(TAG, "SSID to remove: " + ssidToRemove + " was not found in list to remove network", mLoggingEnabled); + } else { + mLogUtil.e(TAG, "No mWifiManager to remove network. SSID: " + ssidToRemove, mLoggingEnabled); + } + return false; + } + + /** + * To search local networks and return the first one that contains a given ssid (non-case sensitive) + * + * @param ssidToSearchFor - The ssid to search for + * @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) + */ + public String searchForSSID(String ssidToSearchFor, int timeoutInMillis) { + if (mWifiManager != null) { + int scanPass = 1; + long currentTime; + long endTime = System.currentTimeMillis() + timeoutInMillis; + LogUtil.getInstance().d(TAG, "End time (searchForSSID): " + endTime, mLoggingEnabled); + do { + mLogUtil.d(TAG, "Scanning SSIDs, pass " + scanPass, mLoggingEnabled); + mWifiManager.startScan(); + List networks = mWifiManager.getScanResults(); + for (ScanResult scanResult : networks) { + mLogUtil.d(TAG, "scanResult.SSID: " + scanResult.SSID, mLoggingEnabled); + if (scanResult.SSID != null && (scanResult.SSID.toUpperCase().contains(ssidToSearchFor.toUpperCase()))) { + mLogUtil.d(TAG, "Found match, SSID: " + scanResult.SSID, mLoggingEnabled); + return scanResult.SSID; + } + } + + try { + Thread.sleep(1000); + } catch (InterruptedException ie) { + // Do nothing + } + currentTime = System.currentTimeMillis(); + LogUtil.getInstance().d(TAG, "Current time (searchForSSID): " + endTime, mLoggingEnabled); + scanPass++; + } while(currentTime < endTime); + } else { + mLogUtil.e(TAG, "No mWifiManager to search for network. SSID: " + ssidToSearchFor, mLoggingEnabled); + } + return null; + } + + /** + * To query if logging is enabled or disabled for a WiseFy instance + * + * @return boolean - If logging is enabled for the WiseFy instance + */ + public boolean isLoggingEnabled() { + return mLoggingEnabled; + } + + /** + * HELPERS + */ + + /** + * Used internally by addOpenNetwork, addWEPNetwork, and addWPA2Network to add and save a new wifi configuration + * + * @param wifiConfig - The network to configuration to add + * + * {@link #addOpenNetwork(String)} + * {@link #addWEPNetwork(String, String)} + * {@link #addWPA2Network(String, String)} + * + * @return int - The return code from WifiManager for network creation (-1 for failure) + */ + private int addNetwork(WifiConfiguration wifiConfig) { + int result = mWifiManager.addNetwork(wifiConfig); + if (result != WIFI_MANAGER_FAILURE) { + mLogUtil.d(TAG, "Successfully added network", mLoggingEnabled); + mWifiManager.saveConfiguration(); + } else { + mLogUtil.e(TAG, "Failed to add network", mLoggingEnabled); + } + return result; + } + + /** + * Used internally by addOpenNetwork, addWEPNetwork, addWPA2Network, and + * isNetworkInConfigurationList to see if an ssid is already saved (CASE SENSITIVE!) + * + * @param ssid - The ssid to check for in the configured network list + * + * {@link #addOpenNetwork(String)} + * {@link #addWEPNetwork(String, String)} + * {@link #addWPA2Network(String, String)} + * {@link #isNetworkInConfigurationList(String)} + * + * @return boolean - If the ssid was found in the configuration list + */ + private boolean checkIfNetworkInConfigurationList(String ssid) { + List list = mWifiManager.getConfiguredNetworks(); + if (list != null && list.size() > 0) { + for (int i = 0; i < list.size(); i++) { + WifiConfiguration wifiConfiguration = list.get(i); + if (wifiConfiguration != null && wifiConfiguration.SSID != null) { + String ssidInList = wifiConfiguration.SSID.replaceAll("\"", ""); + mLogUtil.d(TAG, "SSID in list: " + ssidInList + ", SSID: " + ssid, mLoggingEnabled); + if (ssidInList.equals(ssid)) { + mLogUtil.d(TAG, "Found SSID in list", mLoggingEnabled); + return true; + } + } + } + } else { + mLogUtil.w(TAG, "Found 0 configured networks", mLoggingEnabled); + } + return false; + } + + /** + * Used internally by connectToNetwork to check if the device connects to + * a given SSID within a specified time (timeout is in millis) + * + * @param ssid - The ssid to wait for the device to connect to + * @param timeoutInMillis - The number of milliseconds to wait + * + * @return boolean - If the device is connected to the ssid in the given time + */ + private boolean waitToConnectToSSID(String ssid, int timeoutInMillis) { + long currentTime; + long endTime = System.currentTimeMillis() + timeoutInMillis; + LogUtil.getInstance().d(TAG, "End time (waitToConnectToSSID): " + endTime, mLoggingEnabled); + do { + boolean result = isDeviceConnectedToSSID(ssid); + if (result) { + return result; + } + try { + Thread.sleep(1000); + } catch (InterruptedException ie) { + // Do nothing + } + currentTime = System.currentTimeMillis(); + LogUtil.getInstance().d(TAG, "Current time (waitToConnectToSSID): " + endTime, mLoggingEnabled); + } while(currentTime < endTime); + return false; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/isupatches/wisefy/util/GetManagerUtil.java b/app/src/main/java/com/isupatches/wisefy/util/GetManagerUtil.java new file mode 100644 index 00000000..8d438648 --- /dev/null +++ b/app/src/main/java/com/isupatches/wisefy/util/GetManagerUtil.java @@ -0,0 +1,75 @@ +/** + * Copyright 2016 Patches Klinefelter + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.isupatches.wisefy.util; + + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.wifi.WifiManager; +import com.isupatches.wisefy.WiseFy; + + +public class GetManagerUtil { + + private static final GetManagerUtil GET_MANAGER_UTIL = new GetManagerUtil(); + + /** + * Private constructor with no setup + */ + private GetManagerUtil() { + } + + /** + * @return instance of GetManagerUtil + */ + public static GetManagerUtil getInstance() { + return GET_MANAGER_UTIL; + } + + /** + * To get a Connectivity manger instance from an activity's context. + * + * @see ConnectivityManager + * @see WiseFy + * + * @param context - The context to use to retrieve a connectivity manager via getSystemService + * @return ConnectivityManager|null + */ + public ConnectivityManager getConnectivityManager(Context context) { + if(context != null) { + return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + } else { + return null; + } + } + + /** + * To get a WiFi manger instance from an activity's context. + * + * @see WifiManager + * @see WiseFy + * + * @param context - The context to use to retrieve a wifi manager via getSystemService + * @return WifiManager|null + */ + public WifiManager getWiFiManager(Context context) { + if(context != null) { + return (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + } else { + return null; + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/metova/wisefy/util/LogUtil.java b/app/src/main/java/com/isupatches/wisefy/util/LogUtil.java similarity index 64% rename from app/src/main/java/com/metova/wisefy/util/LogUtil.java rename to app/src/main/java/com/isupatches/wisefy/util/LogUtil.java index 08f1cb20..bbb477d2 100644 --- a/app/src/main/java/com/metova/wisefy/util/LogUtil.java +++ b/app/src/main/java/com/isupatches/wisefy/util/LogUtil.java @@ -1,8 +1,22 @@ -package com.metova.wisefy.util; +/** + * Copyright 2016 Patches Klinefelter + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.isupatches.wisefy.util; import android.util.Log; -import com.metova.wisefy.BuildConfig; public class LogUtil { @@ -42,7 +56,7 @@ public void e (String tag, String message, boolean loggingEnabled) { private boolean isLoggable(String tag, int level, boolean loggingEnabled) { boolean isLoggable; - if(BuildConfig.DEBUG || loggingEnabled) { + if(loggingEnabled) { isLoggable = true; } else { if (tag.length() > 23) { diff --git a/app/src/main/java/com/metova/wisefy/util/SSIDUtil.java b/app/src/main/java/com/isupatches/wisefy/util/SSIDUtil.java similarity index 54% rename from app/src/main/java/com/metova/wisefy/util/SSIDUtil.java rename to app/src/main/java/com/isupatches/wisefy/util/SSIDUtil.java index a4b64832..184dc1e9 100644 --- a/app/src/main/java/com/metova/wisefy/util/SSIDUtil.java +++ b/app/src/main/java/com/isupatches/wisefy/util/SSIDUtil.java @@ -1,8 +1,24 @@ -package com.metova.wisefy.util; +/** + * Copyright 2016 Patches Klinefelter + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.isupatches.wisefy.util; import android.os.Build; + public class SSIDUtil { private static final SSIDUtil SSID_UTIL = new SSIDUtil(); diff --git a/app/src/main/java/com/metova/wisefy/WiseFy.java b/app/src/main/java/com/metova/wisefy/WiseFy.java deleted file mode 100644 index 49a259d4..00000000 --- a/app/src/main/java/com/metova/wisefy/WiseFy.java +++ /dev/null @@ -1,759 +0,0 @@ -package com.metova.wisefy; - - -import android.app.Activity; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.net.wifi.ScanResult; -import android.net.wifi.WifiConfiguration; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; -import android.support.annotation.VisibleForTesting; -import android.text.TextUtils; -import com.metova.wisefy.util.GetManagerUtil; -import com.metova.wisefy.util.LogUtil; -import com.metova.wisefy.util.SSIDUtil; -import java.util.ArrayList; -import java.util.List; - - -public class WiseFy { - - private static final String TAG = WiseFy.class.getSimpleName(); - - @VisibleForTesting - public GetManagerUtil mGetManagerUtil = GetManagerUtil.getInstance(); - - public static final int WISE_MANAGER_FAILURE = -1000; - - public static final int WIFI_MANAGER_FAILURE = -1; - - private LogUtil mLogUtil = LogUtil.getInstance(); - - private SSIDUtil mSSIDUtil = SSIDUtil.getInstance(); - - private boolean loggingEnabled; - - /** - * Private constructor that accepts builder input - */ - private WiseFy(getSmarts getSmarts) { - this.loggingEnabled = getSmarts.loggingEnabled; - } - - /** - * Internal static class for builder pattern - */ - public static class getSmarts { - private boolean loggingEnabled; - - public getSmarts() { - } - - /** - * To enable/disable logging for the WiseFy instance - * - * @param loggingEnabled - If logging is enabled or disabled - * - * @return getSmarts - The builder with updated logging setting - */ - public getSmarts withLogging(boolean loggingEnabled) { - this.loggingEnabled = loggingEnabled; - return this; - } - - /** - * To build and return a WiseFy instance - * - * @return WiseFy - The instance created by the builder - */ - public WiseFy initiateHamsters() { - return new WiseFy(this); - } - } - - /** - * To add an open network to the user's configured network list - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * @param ssid - The ssid of the open network you want to add - * - * @return int - The return code from WifiManager for network creation (-1 for failure) - */ - public int addOpenNetwork(Activity activity, String ssid) { - if (TextUtils.isEmpty(ssid) || activity == null || activity.isFinishing()) { - mLogUtil.w(TAG, "Breaking due to missing ssid or activity. ssid: " + ssid, loggingEnabled); - return WISE_MANAGER_FAILURE; - } - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - boolean ssidAlreadyConfigured = isNetworkInConfigurationList(wifiManager, ssid); - - if (!ssidAlreadyConfigured) { - mLogUtil.d(TAG, "Adding open network with SSID " + ssid, loggingEnabled); - - WifiConfiguration wifiConfig = new WifiConfiguration(); - - wifiConfig.SSID = mSSIDUtil.convertSSIDForConfig(ssid); - wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); - wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); - wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - wifiConfig.allowedAuthAlgorithms.clear(); - wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); - wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); - wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); - wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); - wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); - wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); - - return addNetwork(wifiManager, wifiConfig); - } - } - return WISE_MANAGER_FAILURE; - } - - /** - * To add a WEP network to the user's configured network list - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * @param ssid - The ssid of the WEP network you want to add - * @param password - The password for the WEP network being added - * - * @return int - The return code from WifiManager for network creation (-1 for failure) - */ - public int addWEPNetwork(Activity activity, String ssid, String password) { - if (TextUtils.isEmpty(ssid) || TextUtils.isEmpty(password) || activity == null || activity.isFinishing()) { - mLogUtil.w(TAG, "Breaking due to missing ssid, password, or activity. ssid: " + ssid + ", password: " + password, loggingEnabled); - return WISE_MANAGER_FAILURE; - } - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - boolean ssidAlreadyConfigured = isNetworkInConfigurationList(wifiManager, ssid); - - if (!ssidAlreadyConfigured) { - mLogUtil.d(TAG, "Adding WEP network with SSID " + ssid, loggingEnabled); - - WifiConfiguration wifiConfig = new WifiConfiguration(); - wifiConfig.SSID = mSSIDUtil.convertSSIDForConfig(ssid); - wifiConfig.wepKeys[0] = "\"" + password + "\""; - wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); - wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); - wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); - wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); - wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); - wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); - wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); - wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); - - return addNetwork(wifiManager, wifiConfig); - } - } - return WISE_MANAGER_FAILURE; - } - - /** - * To add a WPA2 network to the user's configured network list - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * @param ssid - The ssid of the WPA2 network you want to add - * @param password - The password for the WPA2 network being added - * - * @return int - The return code from WifiManager for network creation (-1 for failure) - */ - public int addWPA2Network(Activity activity, String ssid, String password) { - if (TextUtils.isEmpty(ssid) || TextUtils.isEmpty(password) || activity == null || activity.isFinishing()) { - mLogUtil.w(TAG, "Breaking due to missing ssid, password, or activity. ssid: " + ssid + ", password: " + password, loggingEnabled); - return WISE_MANAGER_FAILURE; - } - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - boolean ssidAlreadyConfigured = isNetworkInConfigurationList(wifiManager, ssid); - - if (!ssidAlreadyConfigured) { - mLogUtil.d(TAG, "Adding WPA2 network with SSID " + ssid, loggingEnabled); - - WifiConfiguration wifiConfig = new WifiConfiguration(); - wifiConfig.SSID = mSSIDUtil.convertSSIDForConfig(ssid); - wifiConfig.preSharedKey = "\"" + password + "\""; - wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); - wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); - wifiConfig.status = WifiConfiguration.Status.ENABLED; - wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); - wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); - wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); - wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); - wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); - wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - - wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); - wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); - - return addNetwork(wifiManager, wifiConfig); - } - } - return WISE_MANAGER_FAILURE; - } - - /** - * To convert an RSSI level for a network to a number of bars - * - * @param rssiLevel - The signal strength of the network - * @param targetNumberOfBars - How many bars or levels there will be total - * - * @return int - The number of bars for the given RSSI value - */ - public int calculateBars(int rssiLevel, int targetNumberOfBars) { - return WifiManager.calculateSignalLevel(rssiLevel, targetNumberOfBars); - } - - /** - * To compare the signal strength of two networks - * - * @param rssi1 - The signal strength of network 1 - * @param rssi2 - The signal strength of network 2 - * - * @return int - Returns <0 if the first signal is weaker than the second signal, 0 if the two - * signals have the same strength, and >0 if the first signal is stronger than the second signal. - */ - public int compareSignalLevel(int rssi1, int rssi2) { - return WifiManager.compareSignalLevel(rssi1, rssi2); - } - - /** - * Used to connect to a network - * - * Gets a list of saved networks, connects/reconnects to the given ssid, and then calls waitToConnectToSSID to verify connectivity - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * @param ssidToConnectTo - The ssid to connect/reconnect to - * @param timeoutInMillis - The number of milliseconds to continue waiting for the device to connect to the given SSID - * - * @return boolean - If the network was successfully reconnected - */ - public boolean connectToNetwork(Activity activity, String ssidToConnectTo, int timeoutInMillis) { - if (activity != null && !activity.isFinishing()) { - mLogUtil.d(TAG, "Connecting to network: " + ssidToConnectTo, loggingEnabled); - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - List list = wifiManager.getConfiguredNetworks(); - if (list != null) { - for (int i = 0; i < list.size(); i++) { - WifiConfiguration wifiConfiguration = list.get(i); - if (wifiConfiguration != null && wifiConfiguration.SSID != null) { - String ssidInList = wifiConfiguration.SSID.replaceAll("\"", ""); - - mLogUtil.d(TAG, "Configured WiFi Network {index:" + i + ", ssidInList:" + ssidInList + "}", loggingEnabled); - if (ssidInList.equals(ssidToConnectTo)) { - mLogUtil.d(TAG, "ssidToReconnectTo: " + ssidToConnectTo + " matches ssidInList:" + ssidInList, loggingEnabled); - wifiManager.disconnect(); - wifiManager.enableNetwork(wifiConfiguration.networkId, true); - wifiManager.reconnect(); - return waitToConnectToSSID(activity, ssidToConnectTo, timeoutInMillis); - } - } - } - } - - } - mLogUtil.w(TAG, "ssidToReconnectTo: " + ssidToConnectTo + " was not found in list to reconnect to", loggingEnabled); - } else { - mLogUtil.w(TAG, "No activity to reconnect to network", loggingEnabled); - } - return false; - } - - /** - * To disable Wifi on a user's device - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * - * @return boolean - If the command succeeded in disabling wifi - */ - public boolean disableWifi(Activity activity) { - if (activity != null && !activity.isFinishing()) { - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - return wifiManager.setWifiEnabled(false); - } - } else { - mLogUtil.w(TAG, "No activity to disable Wifi", loggingEnabled); - } - return false; - } - - /** - * To disconnect the user from their current network - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * - * @return boolean - If the command succeeded in disconnecting the device from the current network - */ - public boolean disconnectFromCurrentNetwork(Activity activity) { - if (activity != null && !activity.isFinishing()) { - mLogUtil.d(TAG, "Disconnecting from current network", loggingEnabled); - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - return wifiManager.disconnect(); - } - } else { - mLogUtil.w(TAG, "No activity to disconnect from current network", loggingEnabled); - } - return false; - } - - /** - * To enable Wifi on a user's device - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * - * @return boolean - If the command succeeded in enabling wifi - */ - public boolean enableWifi(Activity activity) { - if (activity != null && !activity.isFinishing()) { - mLogUtil.d(TAG, "Enabling WiFi", loggingEnabled); - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - return wifiManager.setWifiEnabled(true); - } - } else { - mLogUtil.w(TAG, "No activity to enable Wifi", loggingEnabled); - } - return false; - } - - /** - * To retrieve the user's current network - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * - * @return WifiInfo|null - The user's current network information - */ - public WifiInfo getCurrentNetwork(Activity activity) { - if (activity != null && !activity.isFinishing()) { - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - return wifiManager.getConnectionInfo(); - } - } else { - mLogUtil.w(TAG, "No activity to get current network", loggingEnabled); - } - return null; - } - - /** - * 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) - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * @param filterDuplicates - If you want to exclude SSIDs with that same name that have a weaker signal strength - * - * @return List|null - List of nearby access points - */ - public List getNearbyAccessPoints(Activity activity, boolean filterDuplicates) { - if (activity != null && !activity.isFinishing()) { - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - wifiManager.startScan(); - if (!filterDuplicates) { - return wifiManager.getScanResults(); - } else { - List scanResults = wifiManager.getScanResults(); - List scanResultsToReturn = new ArrayList<>(); - - for (ScanResult newScanResult : scanResults) { - boolean found = false; - for (int i = 0; i < scanResultsToReturn.size(); i++) { - ScanResult scanResult = scanResultsToReturn.get(i); - mLogUtil.d(TAG, "SSID 1: " + newScanResult.SSID + ". SSID 2: " + scanResult.SSID, loggingEnabled); - if (newScanResult.SSID.equalsIgnoreCase(scanResult.SSID)) { - found = true; - mLogUtil.d(TAG, "SSID did match", loggingEnabled); - - mLogUtil.d(TAG, "Current level: " + scanResult.level, loggingEnabled); - mLogUtil.d(TAG, "New level: " + newScanResult.level, loggingEnabled); - mLogUtil.d(TAG, "comparison result: " + WifiManager.compareSignalLevel(newScanResult.level, scanResult.level), loggingEnabled); - - if (WifiManager.compareSignalLevel(newScanResult.level, scanResult.level) > 0) { - mLogUtil.d(TAG, "New result has a higher signal strength, swapping", loggingEnabled); - scanResultsToReturn.set(i, newScanResult); - } - } else { - mLogUtil.d(TAG, "SSID did not match", loggingEnabled); - } - } - - if (!found) { - mLogUtil.d(TAG, "Found new wifi network", loggingEnabled); - scanResultsToReturn.add(newScanResult); - } - } - return scanResultsToReturn; - } - } - } else { - mLogUtil.w(TAG, "No activity to get nearby access points", loggingEnabled); - - } - return null; - } - - /** - * To retrieve a list of saved networks on a user's device - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * - * @return List|null - List of saved networks on a users device - */ - public List getSavedNetworks(Activity activity) { - if (activity != null && !activity.isFinishing()) { - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - return wifiManager.getConfiguredNetworks(); - } - } else { - mLogUtil.w(TAG, "No activity to get saved networks", loggingEnabled); - } - return null; - } - - /** - * To check if the device is connected to a mobile network - * - * @param activity - The activity to use as context to retrieve a wifi manager and a connectivity manager via getSystemService - * - * @return bool - If the device is currently connected to a mobile network - */ - public boolean isDeviceConnectedToMobileNetwork(Activity activity) { - if (activity != null && !activity.isFinishing()) { - ConnectivityManager connectivityManager = mGetManagerUtil.getConnectivityManager(activity); - if (connectivityManager != null) { - NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); - if (networkInfo != null && networkInfo.getTypeName().equalsIgnoreCase("MOBILE")) { - if (networkInfo.isConnected() && networkInfo.isAvailable()) { - return true; - } - } - } - } - return false; - } - - /** - * To check if the device is connected to a mobile or wifi network - * - * @param activity - The activity to use as context to retrieve a wifi manager and a connectivity manager via getSystemService - * - * @return bool - If the device is currently connected to a mobile or wifi network - */ - public boolean isDeviceConnectedToMobileOrWifiNetwork(Activity activity) { - if (activity != null && !activity.isFinishing()) { - ConnectivityManager connectivityManager = mGetManagerUtil.getConnectivityManager(activity); - if (connectivityManager != null) { - NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); - if (networkInfo.isConnected() && networkInfo.isAvailable()) { - return true; - } - } - } - return false; - } - - /** - * To check if the device is connected to a given SSID - * - * Used by connectToNetwork - * - * @param activity - The activity to use as context to retrieve a wifi manager and a connectivity manager via getSystemService - * @param ssid - The SSID to check if the device is attached to - * - * @return bool - If the device is currently attached to the given SSID - */ - public boolean isDeviceConnectedToSSID(Activity activity, String ssid) { - if (activity == null || activity.isFinishing()) { - mLogUtil.w(TAG, "Breaking due to no activity", loggingEnabled); - return false; - } - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - WifiInfo connectionInfo = wifiManager.getConnectionInfo(); - if (connectionInfo != null && connectionInfo.getSSID() != null) { - String currentSSID = connectionInfo.getSSID().replaceAll("\"", ""); - mLogUtil.d(TAG, "Current SSID: " + currentSSID, loggingEnabled); - - if (currentSSID.equals(ssid)) { - mLogUtil.d(TAG, "Correct SSID", loggingEnabled); - ConnectivityManager connectivityManager = mGetManagerUtil.getConnectivityManager(activity); - if (connectivityManager != null - && connectivityManager.getActiveNetworkInfo() != null - && connectivityManager.getActiveNetworkInfo().isAvailable() - && connectivityManager.getActiveNetworkInfo().isConnected()) { - mLogUtil.d(TAG, "Network is connected", loggingEnabled); - return true; - } - } - } - } - return false; - } - - /** - * To check if the device is connected to a wifi network - * - * @param activity - The activity to use as context to retrieve a wifi manager and a connectivity manager via getSystemService - * - * @return bool - If the device is currently connected to a wifi network - */ - public boolean isDeviceConnectedToWifiNetwork(Activity activity) { - if (activity != null && !activity.isFinishing()) { - ConnectivityManager connectivityManager = mGetManagerUtil.getConnectivityManager(activity); - if (connectivityManager != null) { - NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); - if (networkInfo != null && networkInfo.getTypeName().equalsIgnoreCase("WIFI")) { - if (networkInfo.isConnected() && networkInfo.isAvailable()) { - return true; - } - } - } - } - return false; - } - - /** - * To check if an SSID is in the list of configured networks - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * - * @return boolean - If the SSID is in the list of configured networks - */ - public boolean isNetworkInConfigurationList(Activity activity, String ssid) { - if (activity != null && !activity.isFinishing()) { - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if(wifiManager != null) { - return isNetworkInConfigurationList(wifiManager, ssid); - } - } else { - mLogUtil.w(TAG, "No activity to check if network is in configuration list", loggingEnabled); - } - return false; - } - - /** - * To check and return if a network is secure (WEP/PSK/EAP capabilities) - * - * @param scanResult - The network to see if it is secure - * - * @return boolean - Whether the network is secure - */ - public boolean isNetworkSecure(ScanResult scanResult) { - boolean isSecure = false; - if (scanResult != null && scanResult.capabilities != null) { - if (scanResult.capabilities.contains("WEP") || scanResult.capabilities.contains("PSK") || scanResult.capabilities.contains("EAP")) { - isSecure = true; - } - } - return isSecure; - } - - /** - * To check if Wifi is enabled on the device or not - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * - * @return boolean - if Wifi is enabled on device - */ - public boolean isWifiEnabled(Activity activity) { - if (activity != null && !activity.isFinishing()) { - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - return wifiManager.isWifiEnabled(); - } - } else { - mLogUtil.w(TAG, "No activity to check if wifi is enabled", loggingEnabled); - } - return false; - } - - /** - * To remove a configured network - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * @param ssidToRemove - The ssid of the network you want to remove from the configured network list - * - * @return boolean - If the command succeeded in removing the network - */ - public boolean removeNetwork(Activity activity, String ssidToRemove) { - if (activity != null && !activity.isFinishing()) { - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - List list = wifiManager.getConfiguredNetworks(); - if (list != null) { - for (int i = 0; i < list.size(); i++) { - WifiConfiguration wifiConfiguration = list.get(i); - if (wifiConfiguration != null && wifiConfiguration.SSID != null) { - String ssidInList = wifiConfiguration.SSID.replaceAll("\"", ""); - - mLogUtil.d(TAG, "Configured WiFi Network {index:" + i + ", ssidInList:" + ssidInList + "}", loggingEnabled); - if (ssidInList.equals(ssidToRemove)) { - mLogUtil.d(TAG, "Removing network: " + ssidToRemove, loggingEnabled); - wifiManager.disconnect(); - boolean result = wifiManager.removeNetwork(wifiConfiguration.networkId); - if (result) { - mLogUtil.d(TAG, "Successfully removed network", loggingEnabled); - wifiManager.saveConfiguration(); - } else { - mLogUtil.d(TAG, "Failed to remove network", loggingEnabled); - } - wifiManager.reconnect(); - return result; - } - } - } - } - - } - mLogUtil.w(TAG, "SSID to remove: " + ssidToRemove + " was not found in list to remove network", loggingEnabled); - } else { - mLogUtil.w(TAG, "No activity to remove network", loggingEnabled); - } - return false; - } - - /** - * To search local networks and return the first one that contains a given ssid (non-case sensitive) - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * @param ssidToSearchFor - The ssid to search for - * @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) - */ - public String searchForSSID(Activity activity, String ssidToSearchFor, int timeoutInMillis) { - if (activity != null && !activity.isFinishing()) { - WifiManager wifiManager = mGetManagerUtil.getWiFiManager(activity); - if (wifiManager != null) { - int scanPass = 1; - long currentTime; - long endTime = System.currentTimeMillis() + timeoutInMillis; - LogUtil.getInstance().d(TAG, "End time (searchForSSID): " + endTime, loggingEnabled); - do { - mLogUtil.d(TAG, "Scanning SSIDs, pass " + scanPass, loggingEnabled); - wifiManager.startScan(); - List networks = wifiManager.getScanResults(); - for (ScanResult scanResult : networks) { - mLogUtil.d(TAG, "scanResult.SSID: " + scanResult.SSID, loggingEnabled); - if (scanResult.SSID != null && (scanResult.SSID.toUpperCase().contains(ssidToSearchFor.toUpperCase()))) { - mLogUtil.d(TAG, "Found match, SSID: " + scanResult.SSID, loggingEnabled); - return scanResult.SSID; - } - } - - try { - Thread.sleep(1000); - } catch (InterruptedException ie) { - // Do nothing - } - currentTime = System.currentTimeMillis(); - LogUtil.getInstance().d(TAG, "Current time (searchForSSID): " + endTime, loggingEnabled); - scanPass++; - } while(currentTime < endTime); - } - } else { - mLogUtil.w(TAG, "No activity to search for SSID", loggingEnabled); - } - return null; - } - - /** - * To query if logging is enabled or disabled for a WiseFy instance - * - * @return boolean - If logging is enabled for the WiseFy instance - */ - @VisibleForTesting - public boolean isLoggingEnabled() { - return loggingEnabled; - } - - /** - * HELPERS - */ - - /** - * Used internally by addOpenNetwork, addWEPNetwork, and addWPA2Network to add and save a new wifi configuration - * - * @param wifiManager - A wifi manager instance to add the network - * @param wifiConfig - The network to configuration to add - * - * @return int - The return code from WifiManager for network creation (-1 for failure) - */ - private int addNetwork(WifiManager wifiManager, WifiConfiguration wifiConfig) { - int result = wifiManager.addNetwork(wifiConfig); - if (result != WIFI_MANAGER_FAILURE) { - mLogUtil.d(TAG, "Successfully added network", loggingEnabled); - wifiManager.saveConfiguration(); - } else { - mLogUtil.e(TAG, "Failed to add network", loggingEnabled); - } - return result; - } - - /** - * Used internally by addOpenNetwork, addWEPNetwork, addWPA2Network, and - * isNetworkInConfigurationList to see if an ssid is already saved (CASE SENSITIVE!) - * - * @param wifiManager - A wifi manager instance to search for the ssid - * @param ssid - The ssid to check for in the configured network list - * - * @return boolean - If the ssid was found in the configuration list - */ - private boolean isNetworkInConfigurationList(WifiManager wifiManager, String ssid) { - List list = wifiManager.getConfiguredNetworks(); - if (list != null && list.size() > 0) { - for (int i = 0; i < list.size(); i++) { - WifiConfiguration wifiConfiguration = list.get(i); - if (wifiConfiguration != null && wifiConfiguration.SSID != null) { - String ssidInList = wifiConfiguration.SSID.replaceAll("\"", ""); - mLogUtil.d(TAG, "SSID in list: " + ssidInList + ", SSID: " + ssid, loggingEnabled); - if (ssidInList.equals(ssid)) { - mLogUtil.d(TAG, "Found SSID in list", loggingEnabled); - return true; - } - } - } - } else { - mLogUtil.w(TAG, "Found 0 configured networks", loggingEnabled); - } - return false; - } - - /** - * Used internally by connectToNetwork to check if the device connects to - * a given SSID within a specified time (timeout is in millis) - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * @param ssid - The ssid to wait for the device to connect to - * @param timeoutInMillis - The number of milliseconds to wait - * - * @return boolean - If the device is connected to the ssid in the given time - */ - private boolean waitToConnectToSSID(Activity activity, String ssid, int timeoutInMillis) { - long currentTime; - long endTime = System.currentTimeMillis() + timeoutInMillis; - LogUtil.getInstance().d(TAG, "End time (waitToConnectToSSID): " + endTime, loggingEnabled); - do { - boolean result = isDeviceConnectedToSSID(activity, ssid); - if (result) { - return result; - } - try { - Thread.sleep(1000); - } catch (InterruptedException ie) { - // Do nothing - } - currentTime = System.currentTimeMillis(); - LogUtil.getInstance().d(TAG, "Current time (waitToConnectToSSID): " + endTime, loggingEnabled); - } while(currentTime < endTime); - return false; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/metova/wisefy/util/GetManagerUtil.java b/app/src/main/java/com/metova/wisefy/util/GetManagerUtil.java deleted file mode 100644 index 7187fb09..00000000 --- a/app/src/main/java/com/metova/wisefy/util/GetManagerUtil.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.metova.wisefy.util; - - -import android.app.Activity; -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.wifi.WifiManager; -import com.metova.wisefy.WiseFy; - - -public class GetManagerUtil { - - private static final GetManagerUtil GET_MANAGER_UTIL = new GetManagerUtil(); - - /** - * Private constructor with no setup - */ - private GetManagerUtil() { - } - - /** - * @return instance of GetManagerUtil - */ - public static GetManagerUtil getInstance() { - return GET_MANAGER_UTIL; - } - - /** - * To get a Connectivity manger instance from an activity's context. - * - * @see ConnectivityManager - * @see WiseFy - * - * @param activity - The activity to use as context to retrieve a connectivity manager via getSystemService - * @return ConnectivityManager|null - */ - public ConnectivityManager getConnectivityManager(Activity activity) { - if(activity != null) { - return (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); - } else { - return null; - } - } - - /** - * To get a WiFi manger instance from an activity's context. - * - * @see WifiManager - * @see WiseFy - * - * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService - * @return WifiManager|null - */ - public WifiManager getWiFiManager(Activity activity) { - if(activity != null) { - return (WifiManager) activity.getSystemService(Context.WIFI_SERVICE); - } else { - return null; - } - } -} \ No newline at end of file diff --git a/build.gradle b/build.gradle index c0fee68a..44c32b5a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,14 @@ buildscript { repositories { jcenter() + maven { + url "https://plugins.gradle.org/m2/" + } } dependencies { - classpath 'com.android.tools.build:gradle:2.2.1' + classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.5.6' + classpath "com.github.dcendents:android-maven-gradle-plugin:1.5" classpath "org.jacoco:org.jacoco.core:0.7.7.201606060606" classpath "org.jacoco:org.jacoco.agent:0.7.7.201606060606" classpath "org.jacoco:org.jacoco.report:0.7.7.201606060606" @@ -20,3 +24,21 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir } + +/** + * Improve build server performance by allowing disabling of pre-dexing + * (see http://tools.android.com/tech-docs/new-build-system/tips#TOC-Improving-Build-Server-performance.) + */ +project.ext.preDexLibs = !project.hasProperty('disablePreDex') + +subprojects { + project.plugins.whenPluginAdded { plugin -> + if (rootProject.ext.has('preDexLibs')) { + if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) { + project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs + } else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { + project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs + } + } + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 1d3591c8..6cbe7a62 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit diff --git a/javadoc/allclasses-frame.html b/javadoc/allclasses-frame.html new file mode 100644 index 00000000..388cb8b0 --- /dev/null +++ b/javadoc/allclasses-frame.html @@ -0,0 +1,23 @@ + + + + + +All Classes (app 1.0.4 API) + + + + + +

All Classes

+ + + diff --git a/javadoc/allclasses-noframe.html b/javadoc/allclasses-noframe.html new file mode 100644 index 00000000..daa1be58 --- /dev/null +++ b/javadoc/allclasses-noframe.html @@ -0,0 +1,23 @@ + + + + + +All Classes (app 1.0.4 API) + + + + + +

All Classes

+ + + diff --git a/javadoc/com/isupatches/wisefy/WiseFy.generator.html b/javadoc/com/isupatches/wisefy/WiseFy.generator.html new file mode 100644 index 00000000..09fe1b87 --- /dev/null +++ b/javadoc/com/isupatches/wisefy/WiseFy.generator.html @@ -0,0 +1,327 @@ + + + + + +WiseFy.generator (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy
+

Class WiseFy.generator

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.isupatches.wisefy.WiseFy.generator
    • +
    +
  • +
+
+
    +
  • +
    +
    Enclosing class:
    +
    WiseFy
    +
    +
    +
    +
    public static class WiseFy.generator
    +extends java.lang.Object
    +
    Internal static class for builder pattern
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      generator() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      WiseFygetSmarts() +
      Mandatory - To build and return a WiseFy instance
      +
      WiseFy.generatorlogging(boolean loggingEnabled) +
      Non-mandatory - To enable/disable logging for the WiseFy instance
      +
      com.isupatches.wisefy.WiseFy.GetSmartswithContext(android.content.Context context) +
      Mandatory - The context to get a WiFi and Connectivity manager
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

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

      Constructor Detail

      + + + +
        +
      • +

        generator

        +
        public generator()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        withContext

        +
        public com.isupatches.wisefy.WiseFy.GetSmarts withContext(android.content.Context context)
        +
        Mandatory - The context to get a WiFi and Connectivity manager
        +
        +
        Parameters:
        +
        context - - The activity or application context + WithContext
        +
        Returns:
        +
        generator - The builder with updated context
        +
        +
      • +
      + + + +
        +
      • +

        logging

        +
        public WiseFy.generator logging(boolean loggingEnabled)
        +
        Non-mandatory - To enable/disable logging for the WiseFy instance
        +
        +
        Parameters:
        +
        loggingEnabled - - If logging is enabled or disabled + GetSmarts
        +
        Returns:
        +
        generator - The builder with updated logging setting
        +
        +
      • +
      + + + +
        +
      • +

        getSmarts

        +
        public WiseFy getSmarts()
        +
        Mandatory - To build and return a WiseFy instance
        +
        +
        Returns:
        +
        WiseFy - The instance created by the builder
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/isupatches/wisefy/WiseFy.html b/javadoc/com/isupatches/wisefy/WiseFy.html new file mode 100644 index 00000000..481db33e --- /dev/null +++ b/javadoc/com/isupatches/wisefy/WiseFy.html @@ -0,0 +1,826 @@ + + + + + +WiseFy (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy
+

Class WiseFy

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.isupatches.wisefy.WiseFy
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class WiseFy
    +extends java.lang.Object
    +
    Main class to manipulate and query network settings on an Android device + + Uses the builder pattern for creation - WiseFy.withContext
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Nested Class Summary

      + + + + + + + + + + +
      Nested Classes 
      Modifier and TypeClass and Description
      static class WiseFy.withContext +
      Static class for builder pattern + + Implements builder interfaces #Logging #GetSmarts
      +
      +
    • +
    + + + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      intaddOpenNetwork(java.lang.String ssid) +
      To add an open network to the user's configured network list
      +
      intaddWEPNetwork(java.lang.String ssid, + java.lang.String password) +
      To add a WEP network to the user's configured network list
      +
      intaddWPA2Network(java.lang.String ssid, + java.lang.String password) +
      To add a WPA2 network to the user's configured network list
      +
      intcalculateBars(int rssiLevel, + int targetNumberOfBars) +
      To convert an RSSI level for a network to a number of bars
      +
      intcompareSignalLevel(int rssi1, + int rssi2) +
      To compare the signal strength of two networks
      +
      booleanconnectToNetwork(java.lang.String ssidToConnectTo, + int timeoutInMillis) +
      Used to connect to a network + + Gets a list of saved networks, connects/reconnects to the given ssid, and then calls waitToConnectToSSID to verify connectivity
      +
      booleandisableWifi() +
      To disable Wifi on a user's device
      +
      booleandisconnectFromCurrentNetwork() +
      To disconnect the user from their current network
      +
      booleanenableWifi() +
      To enable Wifi on a user's device
      +
      android.net.wifi.WifiInfogetCurrentNetwork() +
      To retrieve the user's current network
      +
      java.util.List<android.net.wifi.ScanResult>getNearbyAccessPoints(boolean filterDuplicates) +
      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.util.List<android.net.wifi.WifiConfiguration>getSavedNetworks() +
      To retrieve a list of saved networks on a user's device
      +
      booleanisDeviceConnectedToMobileNetwork() +
      To check if the device is connected to a mobile network
      +
      booleanisDeviceConnectedToMobileOrWifiNetwork() +
      To check if the device is connected to a mobile or wifi network
      +
      booleanisDeviceConnectedToSSID(java.lang.String ssid) +
      To check if the device is connected to a given SSID + + Used by connectToNetwork
      +
      booleanisDeviceConnectedToWifiNetwork() +
      To check if the device is connected to a wifi network
      +
      booleanisLoggingEnabled() +
      To query if logging is enabled or disabled for a WiseFy instance
      +
      booleanisNetworkInConfigurationList(java.lang.String ssid) +
      To check if an SSID is in the list of configured networks
      +
      booleanisNetworkSecure(android.net.wifi.ScanResult scanResult) +
      To check and return if a network is secure (WEP/PSK/EAP capabilities)
      +
      booleanisWifiEnabled() +
      To check if Wifi is enabled on the device or not
      +
      booleanremoveNetwork(java.lang.String ssidToRemove) +
      To remove a configured network
      +
      java.lang.StringsearchForSSID(java.lang.String ssidToSearchFor, + int timeoutInMillis) +
      To search local networks and return the first one that contains a given ssid (non-case sensitive)
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

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

      Field Detail

      + + + +
        +
      • +

        WISE_MANAGER_FAILURE

        +
        public static final int WISE_MANAGER_FAILURE
        +
        +
        See Also:
        +
        Constant Field Values
        +
        +
      • +
      + + + +
        +
      • +

        WIFI_MANAGER_FAILURE

        +
        public static final int WIFI_MANAGER_FAILURE
        +
        +
        See Also:
        +
        Constant Field Values
        +
        +
      • +
      + + + +
        +
      • +

        mConnectivityManager

        +
        public android.net.ConnectivityManager mConnectivityManager
        +
      • +
      + + + +
        +
      • +

        mWifiManager

        +
        public android.net.wifi.WifiManager mWifiManager
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        addOpenNetwork

        +
        public int addOpenNetwork(java.lang.String ssid)
        +
        To add an open network to the user's configured network list
        +
        +
        Parameters:
        +
        ssid - - The ssid of the open network you want to add
        +
        Returns:
        +
        int - The return code from WifiManager for network creation (-1 for failure)
        +
        +
      • +
      + + + +
        +
      • +

        addWEPNetwork

        +
        public int addWEPNetwork(java.lang.String ssid,
        +                         java.lang.String password)
        +
        To add a WEP network to the user's configured network list
        +
        +
        Parameters:
        +
        ssid - - The ssid of the WEP network you want to add
        +
        password - - The password for the WEP network being added
        +
        Returns:
        +
        int - The return code from WifiManager for network creation (-1 for failure)
        +
        +
      • +
      + + + +
        +
      • +

        addWPA2Network

        +
        public int addWPA2Network(java.lang.String ssid,
        +                          java.lang.String password)
        +
        To add a WPA2 network to the user's configured network list
        +
        +
        Parameters:
        +
        ssid - - The ssid of the WPA2 network you want to add
        +
        password - - The password for the WPA2 network being added
        +
        Returns:
        +
        int - The return code from WifiManager for network creation (-1 for failure)
        +
        +
      • +
      + + + +
        +
      • +

        calculateBars

        +
        public int calculateBars(int rssiLevel,
        +                         int targetNumberOfBars)
        +
        To convert an RSSI level for a network to a number of bars
        +
        +
        Parameters:
        +
        rssiLevel - - The signal strength of the network
        +
        targetNumberOfBars - - How many bars or levels there will be total
        +
        Returns:
        +
        int - The number of bars for the given RSSI value
        +
        +
      • +
      + + + +
        +
      • +

        compareSignalLevel

        +
        public int compareSignalLevel(int rssi1,
        +                              int rssi2)
        +
        To compare the signal strength of two networks
        +
        +
        Parameters:
        +
        rssi1 - - The signal strength of network 1
        +
        rssi2 - - The signal strength of network 2
        +
        Returns:
        +
        int - Returns negative value if the first signal is weaker than the second signal, 0 if the two + signals have the same strength, and a positive value if the first signal is stronger than the second signal.
        +
        +
      • +
      + + + +
        +
      • +

        connectToNetwork

        +
        public boolean connectToNetwork(java.lang.String ssidToConnectTo,
        +                                int timeoutInMillis)
        +
        Used to connect to a network + + Gets a list of saved networks, connects/reconnects to the given ssid, and then calls waitToConnectToSSID to verify connectivity
        +
        +
        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
        +
        Returns:
        +
        boolean - If the network was successfully reconnected
        +
        +
      • +
      + + + +
        +
      • +

        disableWifi

        +
        public boolean disableWifi()
        +
        To disable Wifi on a user's device
        +
        +
        Returns:
        +
        boolean - If the command succeeded in disabling wifi
        +
        +
      • +
      + + + +
        +
      • +

        disconnectFromCurrentNetwork

        +
        public boolean disconnectFromCurrentNetwork()
        +
        To disconnect the user from their current network
        +
        +
        Returns:
        +
        boolean - If the command succeeded in disconnecting the device from the current network
        +
        +
      • +
      + + + +
        +
      • +

        enableWifi

        +
        public boolean enableWifi()
        +
        To enable Wifi on a user's device
        +
        +
        Returns:
        +
        boolean - If the command succeeded in enabling wifi
        +
        +
      • +
      + + + +
        +
      • +

        getCurrentNetwork

        +
        public android.net.wifi.WifiInfo getCurrentNetwork()
        +
        To retrieve the user's current network
        +
        +
        Returns:
        +
        WifiInfo|null - The user's current network information
        +
        +
      • +
      + + + +
        +
      • +

        getNearbyAccessPoints

        +
        public java.util.List<android.net.wifi.ScanResult> getNearbyAccessPoints(boolean filterDuplicates)
        +
        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
        +
        Returns:
        +
        List of ScanResults|null - List of nearby access points
        +
        +
      • +
      + + + +
        +
      • +

        getSavedNetworks

        +
        public java.util.List<android.net.wifi.WifiConfiguration> getSavedNetworks()
        +
        To retrieve a list of saved networks on a user's device
        +
        +
        Returns:
        +
        List of WifiConfiguration|null - List of saved networks on a users device
        +
        +
      • +
      + + + +
        +
      • +

        isDeviceConnectedToMobileNetwork

        +
        public boolean isDeviceConnectedToMobileNetwork()
        +
        To check if the device is connected to a mobile network
        +
        +
        Returns:
        +
        bool - If the device is currently connected to a mobile network
        +
        +
      • +
      + + + +
        +
      • +

        isDeviceConnectedToMobileOrWifiNetwork

        +
        public boolean isDeviceConnectedToMobileOrWifiNetwork()
        +
        To check if the device is connected to a mobile or wifi network
        +
        +
        Returns:
        +
        bool - If the device is currently connected to a mobile or wifi network
        +
        +
      • +
      + + + +
        +
      • +

        isDeviceConnectedToSSID

        +
        public boolean isDeviceConnectedToSSID(java.lang.String ssid)
        +
        To check if the device is connected to a given SSID + + Used by connectToNetwork
        +
        +
        Parameters:
        +
        ssid - - The SSID to check if the device is attached to
        +
        Returns:
        +
        bool - If the device is currently attached to the given SSID
        +
        +
      • +
      + + + +
        +
      • +

        isDeviceConnectedToWifiNetwork

        +
        public boolean isDeviceConnectedToWifiNetwork()
        +
        To check if the device is connected to a wifi network
        +
        +
        Returns:
        +
        bool - If the device is currently connected to a wifi network
        +
        +
      • +
      + + + +
        +
      • +

        isNetworkInConfigurationList

        +
        public boolean isNetworkInConfigurationList(java.lang.String ssid)
        +
        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
        +
        Returns:
        +
        boolean - If the SSID is in the list of configured networks
        +
        +
      • +
      + + + +
        +
      • +

        isNetworkSecure

        +
        public boolean isNetworkSecure(android.net.wifi.ScanResult scanResult)
        +
        To check and return if a network is secure (WEP/PSK/EAP capabilities)
        +
        +
        Parameters:
        +
        scanResult - - The network to see if it is secure
        +
        Returns:
        +
        boolean - Whether the network is secure
        +
        +
      • +
      + + + +
        +
      • +

        isWifiEnabled

        +
        public boolean isWifiEnabled()
        +
        To check if Wifi is enabled on the device or not
        +
        +
        Returns:
        +
        boolean - if Wifi is enabled on device
        +
        +
      • +
      + + + +
        +
      • +

        removeNetwork

        +
        public boolean removeNetwork(java.lang.String ssidToRemove)
        +
        To remove a configured network
        +
        +
        Parameters:
        +
        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
        +
        +
      • +
      + + + +
        +
      • +

        searchForSSID

        +
        public java.lang.String searchForSSID(java.lang.String ssidToSearchFor,
        +                                      int timeoutInMillis)
        +
        To search local networks and return the first one that contains a given ssid (non-case sensitive)
        +
        +
        Parameters:
        +
        ssidToSearchFor - - The ssid to search for
        +
        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)
        +
        +
      • +
      + + + +
        +
      • +

        isLoggingEnabled

        +
        public boolean isLoggingEnabled()
        +
        To query if logging is enabled or disabled for a WiseFy instance
        +
        +
        Returns:
        +
        boolean - If logging is enabled for the WiseFy instance
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/isupatches/wisefy/WiseFy.withContext.html b/javadoc/com/isupatches/wisefy/WiseFy.withContext.html new file mode 100644 index 00000000..0d73e571 --- /dev/null +++ b/javadoc/com/isupatches/wisefy/WiseFy.withContext.html @@ -0,0 +1,320 @@ + + + + + +WiseFy.withContext (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy
+

Class WiseFy.withContext

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

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      withContext(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 withContext + #withContext(Context)
      +
      WiseFy.withContextlogging(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

      + + + +
        +
      • +

        withContext

        +
        public withContext(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 withContext + #withContext(Context)
        +
        +
        Returns:
        +
        WiseFy - The instance created by the builder
        +
        +
      • +
      + + + +
        +
      • +

        logging

        +
        public WiseFy.withContext 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:
        +
        withContext - The builder with updated logging setting
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/isupatches/wisefy/package-frame.html b/javadoc/com/isupatches/wisefy/package-frame.html new file mode 100644 index 00000000..be76153a --- /dev/null +++ b/javadoc/com/isupatches/wisefy/package-frame.html @@ -0,0 +1,21 @@ + + + + + +com.isupatches.wisefy (app 1.0.4 API) + + + + + +

com.isupatches.wisefy

+
+

Classes

+ +
+ + diff --git a/javadoc/com/isupatches/wisefy/package-summary.html b/javadoc/com/isupatches/wisefy/package-summary.html new file mode 100644 index 00000000..3296033f --- /dev/null +++ b/javadoc/com/isupatches/wisefy/package-summary.html @@ -0,0 +1,152 @@ + + + + + +com.isupatches.wisefy (app 1.0.4 API) + + + + + + + + + + + +
+

Package com.isupatches.wisefy

+
+
+
    +
  • + + + + + + + + + + + + + + + + +
    Class Summary 
    ClassDescription
    WiseFy +
    Main class to manipulate and query network settings on an Android device + + Uses the builder pattern for creation - WiseFy.withContext
    +
    WiseFy.withContext +
    Static class for builder pattern + + Implements builder interfaces #Logging #GetSmarts
    +
    +
  • +
+
+ + + + + + diff --git a/javadoc/com/isupatches/wisefy/package-tree.html b/javadoc/com/isupatches/wisefy/package-tree.html new file mode 100644 index 00000000..7739ef46 --- /dev/null +++ b/javadoc/com/isupatches/wisefy/package-tree.html @@ -0,0 +1,136 @@ + + + + + +com.isupatches.wisefy Class Hierarchy (app 1.0.4 API) + + + + + + + + + + + +
+

Hierarchy For Package com.isupatches.wisefy

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +
+ + + + + + diff --git a/javadoc/com/isupatches/wisefy/util/GetManagerUtil.html b/javadoc/com/isupatches/wisefy/util/GetManagerUtil.html new file mode 100644 index 00000000..3b7c95e1 --- /dev/null +++ b/javadoc/com/isupatches/wisefy/util/GetManagerUtil.html @@ -0,0 +1,289 @@ + + + + + +GetManagerUtil (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy.util
+

Class GetManagerUtil

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.isupatches.wisefy.util.GetManagerUtil
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class GetManagerUtil
    +extends java.lang.Object
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + +
      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      android.net.ConnectivityManagergetConnectivityManager(android.content.Context context) +
      To get a Connectivity manger instance from an activity's context.
      +
      static GetManagerUtilgetInstance() 
      android.net.wifi.WifiManagergetWiFiManager(android.content.Context context) +
      To get a WiFi manger instance from an activity's context.
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

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

      Method Detail

      + + + +
        +
      • +

        getInstance

        +
        public static GetManagerUtil getInstance()
        +
        +
        Returns:
        +
        instance of GetManagerUtil
        +
        +
      • +
      + + + +
        +
      • +

        getConnectivityManager

        +
        public android.net.ConnectivityManager getConnectivityManager(android.content.Context context)
        +
        To get a Connectivity manger instance from an activity's context.
        +
        +
        Parameters:
        +
        context - - The context to use to retrieve a connectivity manager via getSystemService
        +
        Returns:
        +
        ConnectivityManager|null
        +
        See Also:
        +
        ConnectivityManager, +WiseFy
        +
        +
      • +
      + + + +
        +
      • +

        getWiFiManager

        +
        public android.net.wifi.WifiManager getWiFiManager(android.content.Context context)
        +
        To get a WiFi manger instance from an activity's context.
        +
        +
        Parameters:
        +
        context - - The context to use to retrieve a wifi manager via getSystemService
        +
        Returns:
        +
        WifiManager|null
        +
        See Also:
        +
        WifiManager, +WiseFy
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/isupatches/wisefy/util/LogUtil.html b/javadoc/com/isupatches/wisefy/util/LogUtil.html new file mode 100644 index 00000000..97a79ad6 --- /dev/null +++ b/javadoc/com/isupatches/wisefy/util/LogUtil.html @@ -0,0 +1,290 @@ + + + + + +LogUtil (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy.util
+

Class LogUtil

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.isupatches.wisefy.util.LogUtil
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class LogUtil
    +extends java.lang.Object
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + +
      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      voidd(java.lang.String tag, + java.lang.String message, + boolean loggingEnabled) 
      voide(java.lang.String tag, + java.lang.String message, + boolean loggingEnabled) 
      static LogUtilgetInstance() 
      voidw(java.lang.String tag, + java.lang.String message, + boolean loggingEnabled) 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

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

      Method Detail

      + + + +
        +
      • +

        getInstance

        +
        public static LogUtil getInstance()
        +
        +
        Returns:
        +
        instance of LogUtil
        +
        +
      • +
      + + + +
        +
      • +

        d

        +
        public void d(java.lang.String tag,
        +              java.lang.String message,
        +              boolean loggingEnabled)
        +
      • +
      + + + +
        +
      • +

        w

        +
        public void w(java.lang.String tag,
        +              java.lang.String message,
        +              boolean loggingEnabled)
        +
      • +
      + + + +
        +
      • +

        e

        +
        public void e(java.lang.String tag,
        +              java.lang.String message,
        +              boolean loggingEnabled)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/isupatches/wisefy/util/SSIDUtil.html b/javadoc/com/isupatches/wisefy/util/SSIDUtil.html new file mode 100644 index 00000000..b67b07d2 --- /dev/null +++ b/javadoc/com/isupatches/wisefy/util/SSIDUtil.html @@ -0,0 +1,252 @@ + + + + + +SSIDUtil (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy.util
+

Class SSIDUtil

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.isupatches.wisefy.util.SSIDUtil
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class SSIDUtil
    +extends java.lang.Object
    +
  • +
+
+
+ +
+
+
    +
  • + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        getInstance

        +
        public static SSIDUtil getInstance()
        +
        +
        Returns:
        +
        instance of SSIDUtil
        +
        +
      • +
      + + + +
        +
      • +

        convertSSIDForConfig

        +
        public java.lang.String convertSSIDForConfig(java.lang.String ssid)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/isupatches/wisefy/util/package-frame.html b/javadoc/com/isupatches/wisefy/util/package-frame.html new file mode 100644 index 00000000..bf8afb3f --- /dev/null +++ b/javadoc/com/isupatches/wisefy/util/package-frame.html @@ -0,0 +1,22 @@ + + + + + +com.isupatches.wisefy.util (app 1.0.4 API) + + + + + +

com.isupatches.wisefy.util

+
+

Classes

+ +
+ + diff --git a/javadoc/com/isupatches/wisefy/util/package-summary.html b/javadoc/com/isupatches/wisefy/util/package-summary.html new file mode 100644 index 00000000..047c7c1b --- /dev/null +++ b/javadoc/com/isupatches/wisefy/util/package-summary.html @@ -0,0 +1,148 @@ + + + + + +com.isupatches.wisefy.util (app 1.0.4 API) + + + + + + + + + + + +
+

Package com.isupatches.wisefy.util

+
+
+ +
+ + + + + + diff --git a/javadoc/com/isupatches/wisefy/util/package-tree.html b/javadoc/com/isupatches/wisefy/util/package-tree.html new file mode 100644 index 00000000..4e51ac69 --- /dev/null +++ b/javadoc/com/isupatches/wisefy/util/package-tree.html @@ -0,0 +1,137 @@ + + + + + +com.isupatches.wisefy.util Class Hierarchy (app 1.0.4 API) + + + + + + + + + + + +
+

Hierarchy For Package com.isupatches.wisefy.util

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +
+ + + + + + diff --git a/javadoc/com/metova/wisefy/WiseFy.generator.html b/javadoc/com/metova/wisefy/WiseFy.generator.html new file mode 100644 index 00000000..a4206792 --- /dev/null +++ b/javadoc/com/metova/wisefy/WiseFy.generator.html @@ -0,0 +1,327 @@ + + + + + +WiseFy.generator (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy
+

Class WiseFy.generator

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.isupatches.wisefy.WiseFy.generator
    • +
    +
  • +
+
+
    +
  • +
    +
    Enclosing class:
    +
    WiseFy
    +
    +
    +
    +
    public static class WiseFy.generator
    +extends java.lang.Object
    +
    Internal static class for builder pattern
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      generator() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      WiseFygetSmarts() +
      Mandatory - To build and return a WiseFy instance
      +
      WiseFy.generatorlogging(boolean loggingEnabled) +
      Non-mandatory - To enable/disable logging for the WiseFy instance
      +
      com.isupatches.wisefy.WiseFy.GetSmartswithContext(android.content.Context context) +
      Mandatory - The context to get a WiFi and Connectivity manager
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

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

      Constructor Detail

      + + + +
        +
      • +

        generator

        +
        public generator()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        withContext

        +
        public com.isupatches.wisefy.WiseFy.GetSmarts withContext(android.content.Context context)
        +
        Mandatory - The context to get a WiFi and Connectivity manager
        +
        +
        Parameters:
        +
        context - - The activity or application context + WithContext
        +
        Returns:
        +
        generator - The builder with updated context
        +
        +
      • +
      + + + +
        +
      • +

        logging

        +
        public WiseFy.generator logging(boolean loggingEnabled)
        +
        Non-mandatory - To enable/disable logging for the WiseFy instance
        +
        +
        Parameters:
        +
        loggingEnabled - - If logging is enabled or disabled + GetSmarts
        +
        Returns:
        +
        generator - The builder with updated logging setting
        +
        +
      • +
      + + + +
        +
      • +

        getSmarts

        +
        public WiseFy getSmarts()
        +
        Mandatory - To build and return a WiseFy instance
        +
        +
        Returns:
        +
        WiseFy - The instance created by the builder
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/metova/wisefy/WiseFy.html b/javadoc/com/metova/wisefy/WiseFy.html new file mode 100644 index 00000000..de5c397d --- /dev/null +++ b/javadoc/com/metova/wisefy/WiseFy.html @@ -0,0 +1,821 @@ + + + + + +WiseFy (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy
+

Class WiseFy

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.isupatches.wisefy.WiseFy
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class WiseFy
    +extends java.lang.Object
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Nested Class Summary

      + + + + + + + + + + +
      Nested Classes 
      Modifier and TypeClass and Description
      static class WiseFy.generator +
      Internal static class for builder pattern
      +
      +
    • +
    + + + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      intaddOpenNetwork(java.lang.String ssid) +
      To add an open network to the user's configured network list
      +
      intaddWEPNetwork(java.lang.String ssid, + java.lang.String password) +
      To add a WEP network to the user's configured network list
      +
      intaddWPA2Network(java.lang.String ssid, + java.lang.String password) +
      To add a WPA2 network to the user's configured network list
      +
      intcalculateBars(int rssiLevel, + int targetNumberOfBars) +
      To convert an RSSI level for a network to a number of bars
      +
      intcompareSignalLevel(int rssi1, + int rssi2) +
      To compare the signal strength of two networks
      +
      booleanconnectToNetwork(java.lang.String ssidToConnectTo, + int timeoutInMillis) +
      Used to connect to a network + + Gets a list of saved networks, connects/reconnects to the given ssid, and then calls waitToConnectToSSID to verify connectivity
      +
      booleandisableWifi() +
      To disable Wifi on a user's device
      +
      booleandisconnectFromCurrentNetwork() +
      To disconnect the user from their current network
      +
      booleanenableWifi() +
      To enable Wifi on a user's device
      +
      android.net.wifi.WifiInfogetCurrentNetwork() +
      To retrieve the user's current network
      +
      java.util.List<android.net.wifi.ScanResult>getNearbyAccessPoints(boolean filterDuplicates) +
      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.util.List<android.net.wifi.WifiConfiguration>getSavedNetworks() +
      To retrieve a list of saved networks on a user's device
      +
      booleanisDeviceConnectedToMobileNetwork() +
      To check if the device is connected to a mobile network
      +
      booleanisDeviceConnectedToMobileOrWifiNetwork() +
      To check if the device is connected to a mobile or wifi network
      +
      booleanisDeviceConnectedToSSID(java.lang.String ssid) +
      To check if the device is connected to a given SSID + + Used by connectToNetwork
      +
      booleanisDeviceConnectedToWifiNetwork() +
      To check if the device is connected to a wifi network
      +
      booleanisLoggingEnabled() +
      To query if logging is enabled or disabled for a WiseFy instance
      +
      booleanisNetworkInConfigurationList(java.lang.String ssid) +
      To check if an SSID is in the list of configured networks
      +
      booleanisNetworkSecure(android.net.wifi.ScanResult scanResult) +
      To check and return if a network is secure (WEP/PSK/EAP capabilities)
      +
      booleanisWifiEnabled() +
      To check if Wifi is enabled on the device or not
      +
      booleanremoveNetwork(java.lang.String ssidToRemove) +
      To remove a configured network
      +
      java.lang.StringsearchForSSID(java.lang.String ssidToSearchFor, + int timeoutInMillis) +
      To search local networks and return the first one that contains a given ssid (non-case sensitive)
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

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

      Field Detail

      + + + +
        +
      • +

        WISE_MANAGER_FAILURE

        +
        public static final int WISE_MANAGER_FAILURE
        +
        +
        See Also:
        +
        Constant Field Values
        +
        +
      • +
      + + + +
        +
      • +

        WIFI_MANAGER_FAILURE

        +
        public static final int WIFI_MANAGER_FAILURE
        +
        +
        See Also:
        +
        Constant Field Values
        +
        +
      • +
      + + + +
        +
      • +

        mConnectivityManager

        +
        public android.net.ConnectivityManager mConnectivityManager
        +
      • +
      + + + +
        +
      • +

        mWifiManager

        +
        public android.net.wifi.WifiManager mWifiManager
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        addOpenNetwork

        +
        public int addOpenNetwork(java.lang.String ssid)
        +
        To add an open network to the user's configured network list
        +
        +
        Parameters:
        +
        ssid - - The ssid of the open network you want to add
        +
        Returns:
        +
        int - The return code from WifiManager for network creation (-1 for failure)
        +
        +
      • +
      + + + +
        +
      • +

        addWEPNetwork

        +
        public int addWEPNetwork(java.lang.String ssid,
        +                         java.lang.String password)
        +
        To add a WEP network to the user's configured network list
        +
        +
        Parameters:
        +
        ssid - - The ssid of the WEP network you want to add
        +
        password - - The password for the WEP network being added
        +
        Returns:
        +
        int - The return code from WifiManager for network creation (-1 for failure)
        +
        +
      • +
      + + + +
        +
      • +

        addWPA2Network

        +
        public int addWPA2Network(java.lang.String ssid,
        +                          java.lang.String password)
        +
        To add a WPA2 network to the user's configured network list
        +
        +
        Parameters:
        +
        ssid - - The ssid of the WPA2 network you want to add
        +
        password - - The password for the WPA2 network being added
        +
        Returns:
        +
        int - The return code from WifiManager for network creation (-1 for failure)
        +
        +
      • +
      + + + +
        +
      • +

        calculateBars

        +
        public int calculateBars(int rssiLevel,
        +                         int targetNumberOfBars)
        +
        To convert an RSSI level for a network to a number of bars
        +
        +
        Parameters:
        +
        rssiLevel - - The signal strength of the network
        +
        targetNumberOfBars - - How many bars or levels there will be total
        +
        Returns:
        +
        int - The number of bars for the given RSSI value
        +
        +
      • +
      + + + +
        +
      • +

        compareSignalLevel

        +
        public int compareSignalLevel(int rssi1,
        +                              int rssi2)
        +
        To compare the signal strength of two networks
        +
        +
        Parameters:
        +
        rssi1 - - The signal strength of network 1
        +
        rssi2 - - The signal strength of network 2
        +
        Returns:
        +
        int - Returns negative value if the first signal is weaker than the second signal, 0 if the two + signals have the same strength, and a positive value if the first signal is stronger than the second signal.
        +
        +
      • +
      + + + +
        +
      • +

        connectToNetwork

        +
        public boolean connectToNetwork(java.lang.String ssidToConnectTo,
        +                                int timeoutInMillis)
        +
        Used to connect to a network + + Gets a list of saved networks, connects/reconnects to the given ssid, and then calls waitToConnectToSSID to verify connectivity
        +
        +
        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
        +
        Returns:
        +
        boolean - If the network was successfully reconnected
        +
        +
      • +
      + + + +
        +
      • +

        disableWifi

        +
        public boolean disableWifi()
        +
        To disable Wifi on a user's device
        +
        +
        Returns:
        +
        boolean - If the command succeeded in disabling wifi
        +
        +
      • +
      + + + +
        +
      • +

        disconnectFromCurrentNetwork

        +
        public boolean disconnectFromCurrentNetwork()
        +
        To disconnect the user from their current network
        +
        +
        Returns:
        +
        boolean - If the command succeeded in disconnecting the device from the current network
        +
        +
      • +
      + + + +
        +
      • +

        enableWifi

        +
        public boolean enableWifi()
        +
        To enable Wifi on a user's device
        +
        +
        Returns:
        +
        boolean - If the command succeeded in enabling wifi
        +
        +
      • +
      + + + +
        +
      • +

        getCurrentNetwork

        +
        public android.net.wifi.WifiInfo getCurrentNetwork()
        +
        To retrieve the user's current network
        +
        +
        Returns:
        +
        WifiInfo|null - The user's current network information
        +
        +
      • +
      + + + +
        +
      • +

        getNearbyAccessPoints

        +
        public java.util.List<android.net.wifi.ScanResult> getNearbyAccessPoints(boolean filterDuplicates)
        +
        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
        +
        Returns:
        +
        List of ScanResults|null - List of nearby access points
        +
        +
      • +
      + + + +
        +
      • +

        getSavedNetworks

        +
        public java.util.List<android.net.wifi.WifiConfiguration> getSavedNetworks()
        +
        To retrieve a list of saved networks on a user's device
        +
        +
        Returns:
        +
        List of WifiConfiguration|null - List of saved networks on a users device
        +
        +
      • +
      + + + +
        +
      • +

        isDeviceConnectedToMobileNetwork

        +
        public boolean isDeviceConnectedToMobileNetwork()
        +
        To check if the device is connected to a mobile network
        +
        +
        Returns:
        +
        bool - If the device is currently connected to a mobile network
        +
        +
      • +
      + + + +
        +
      • +

        isDeviceConnectedToMobileOrWifiNetwork

        +
        public boolean isDeviceConnectedToMobileOrWifiNetwork()
        +
        To check if the device is connected to a mobile or wifi network
        +
        +
        Returns:
        +
        bool - If the device is currently connected to a mobile or wifi network
        +
        +
      • +
      + + + +
        +
      • +

        isDeviceConnectedToSSID

        +
        public boolean isDeviceConnectedToSSID(java.lang.String ssid)
        +
        To check if the device is connected to a given SSID + + Used by connectToNetwork
        +
        +
        Parameters:
        +
        ssid - - The SSID to check if the device is attached to
        +
        Returns:
        +
        bool - If the device is currently attached to the given SSID
        +
        +
      • +
      + + + +
        +
      • +

        isDeviceConnectedToWifiNetwork

        +
        public boolean isDeviceConnectedToWifiNetwork()
        +
        To check if the device is connected to a wifi network
        +
        +
        Returns:
        +
        bool - If the device is currently connected to a wifi network
        +
        +
      • +
      + + + +
        +
      • +

        isNetworkInConfigurationList

        +
        public boolean isNetworkInConfigurationList(java.lang.String ssid)
        +
        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
        +
        Returns:
        +
        boolean - If the SSID is in the list of configured networks
        +
        +
      • +
      + + + +
        +
      • +

        isNetworkSecure

        +
        public boolean isNetworkSecure(android.net.wifi.ScanResult scanResult)
        +
        To check and return if a network is secure (WEP/PSK/EAP capabilities)
        +
        +
        Parameters:
        +
        scanResult - - The network to see if it is secure
        +
        Returns:
        +
        boolean - Whether the network is secure
        +
        +
      • +
      + + + +
        +
      • +

        isWifiEnabled

        +
        public boolean isWifiEnabled()
        +
        To check if Wifi is enabled on the device or not
        +
        +
        Returns:
        +
        boolean - if Wifi is enabled on device
        +
        +
      • +
      + + + +
        +
      • +

        removeNetwork

        +
        public boolean removeNetwork(java.lang.String ssidToRemove)
        +
        To remove a configured network
        +
        +
        Parameters:
        +
        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
        +
        +
      • +
      + + + +
        +
      • +

        searchForSSID

        +
        public java.lang.String searchForSSID(java.lang.String ssidToSearchFor,
        +                                      int timeoutInMillis)
        +
        To search local networks and return the first one that contains a given ssid (non-case sensitive)
        +
        +
        Parameters:
        +
        ssidToSearchFor - - The ssid to search for
        +
        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)
        +
        +
      • +
      + + + +
        +
      • +

        isLoggingEnabled

        +
        public boolean isLoggingEnabled()
        +
        To query if logging is enabled or disabled for a WiseFy instance
        +
        +
        Returns:
        +
        boolean - If logging is enabled for the WiseFy instance
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/metova/wisefy/package-frame.html b/javadoc/com/metova/wisefy/package-frame.html new file mode 100644 index 00000000..193d7b98 --- /dev/null +++ b/javadoc/com/metova/wisefy/package-frame.html @@ -0,0 +1,21 @@ + + + + + +com.isupatches.wisefy (app 1.0.4 API) + + + + + +

com.isupatches.wisefy

+
+

Classes

+ +
+ + diff --git a/javadoc/com/metova/wisefy/package-summary.html b/javadoc/com/metova/wisefy/package-summary.html new file mode 100644 index 00000000..174eb4e8 --- /dev/null +++ b/javadoc/com/metova/wisefy/package-summary.html @@ -0,0 +1,145 @@ + + + + + +com.isupatches.wisefy (app 1.0.4 API) + + + + + + + + + + + +
+

Package com.isupatches.wisefy

+
+
+
    +
  • + + + + + + + + + + + + + + + + +
    Class Summary 
    ClassDescription
    WiseFy 
    WiseFy.generator +
    Internal static class for builder pattern
    +
    +
  • +
+
+ + + + + + diff --git a/javadoc/com/metova/wisefy/package-tree.html b/javadoc/com/metova/wisefy/package-tree.html new file mode 100644 index 00000000..e33d8528 --- /dev/null +++ b/javadoc/com/metova/wisefy/package-tree.html @@ -0,0 +1,135 @@ + + + + + +com.isupatches.wisefy Class Hierarchy (app 1.0.4 API) + + + + + + + + + + + +
+

Hierarchy For Package com.isupatches.wisefy

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +
+ + + + + + diff --git a/javadoc/com/metova/wisefy/util/GetManagerUtil.html b/javadoc/com/metova/wisefy/util/GetManagerUtil.html new file mode 100644 index 00000000..c12e5c29 --- /dev/null +++ b/javadoc/com/metova/wisefy/util/GetManagerUtil.html @@ -0,0 +1,289 @@ + + + + + +GetManagerUtil (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy.util
+

Class GetManagerUtil

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.isupatches.wisefy.util.GetManagerUtil
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class GetManagerUtil
    +extends java.lang.Object
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + +
      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      android.net.ConnectivityManagergetConnectivityManager(android.content.Context context) +
      To get a Connectivity manger instance from an activity's context.
      +
      static GetManagerUtilgetInstance() 
      android.net.wifi.WifiManagergetWiFiManager(android.content.Context context) +
      To get a WiFi manger instance from an activity's context.
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

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

      Method Detail

      + + + +
        +
      • +

        getInstance

        +
        public static GetManagerUtil getInstance()
        +
        +
        Returns:
        +
        instance of GetManagerUtil
        +
        +
      • +
      + + + +
        +
      • +

        getConnectivityManager

        +
        public android.net.ConnectivityManager getConnectivityManager(android.content.Context context)
        +
        To get a Connectivity manger instance from an activity's context.
        +
        +
        Parameters:
        +
        context - - The context to use to retrieve a connectivity manager via getSystemService
        +
        Returns:
        +
        ConnectivityManager|null
        +
        See Also:
        +
        ConnectivityManager, +WiseFy
        +
        +
      • +
      + + + +
        +
      • +

        getWiFiManager

        +
        public android.net.wifi.WifiManager getWiFiManager(android.content.Context context)
        +
        To get a WiFi manger instance from an activity's context.
        +
        +
        Parameters:
        +
        context - - The context to use to retrieve a wifi manager via getSystemService
        +
        Returns:
        +
        WifiManager|null
        +
        See Also:
        +
        WifiManager, +WiseFy
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/metova/wisefy/util/LogUtil.html b/javadoc/com/metova/wisefy/util/LogUtil.html new file mode 100644 index 00000000..0f91f021 --- /dev/null +++ b/javadoc/com/metova/wisefy/util/LogUtil.html @@ -0,0 +1,290 @@ + + + + + +LogUtil (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy.util
+

Class LogUtil

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.isupatches.wisefy.util.LogUtil
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class LogUtil
    +extends java.lang.Object
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + +
      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      voidd(java.lang.String tag, + java.lang.String message, + boolean loggingEnabled) 
      voide(java.lang.String tag, + java.lang.String message, + boolean loggingEnabled) 
      static LogUtilgetInstance() 
      voidw(java.lang.String tag, + java.lang.String message, + boolean loggingEnabled) 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

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

      Method Detail

      + + + +
        +
      • +

        getInstance

        +
        public static LogUtil getInstance()
        +
        +
        Returns:
        +
        instance of LogUtil
        +
        +
      • +
      + + + +
        +
      • +

        d

        +
        public void d(java.lang.String tag,
        +              java.lang.String message,
        +              boolean loggingEnabled)
        +
      • +
      + + + +
        +
      • +

        w

        +
        public void w(java.lang.String tag,
        +              java.lang.String message,
        +              boolean loggingEnabled)
        +
      • +
      + + + +
        +
      • +

        e

        +
        public void e(java.lang.String tag,
        +              java.lang.String message,
        +              boolean loggingEnabled)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/metova/wisefy/util/SSIDUtil.html b/javadoc/com/metova/wisefy/util/SSIDUtil.html new file mode 100644 index 00000000..d1e6c91a --- /dev/null +++ b/javadoc/com/metova/wisefy/util/SSIDUtil.html @@ -0,0 +1,252 @@ + + + + + +SSIDUtil (app 1.0.4 API) + + + + + + + + + + + + +
+
com.isupatches.wisefy.util
+

Class SSIDUtil

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.isupatches.wisefy.util.SSIDUtil
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class SSIDUtil
    +extends java.lang.Object
    +
  • +
+
+
+ +
+
+
    +
  • + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        getInstance

        +
        public static SSIDUtil getInstance()
        +
        +
        Returns:
        +
        instance of SSIDUtil
        +
        +
      • +
      + + + +
        +
      • +

        convertSSIDForConfig

        +
        public java.lang.String convertSSIDForConfig(java.lang.String ssid)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/javadoc/com/metova/wisefy/util/package-frame.html b/javadoc/com/metova/wisefy/util/package-frame.html new file mode 100644 index 00000000..e78be43c --- /dev/null +++ b/javadoc/com/metova/wisefy/util/package-frame.html @@ -0,0 +1,22 @@ + + + + + +com.isupatches.wisefy.util (app 1.0.4 API) + + + + + +

com.isupatches.wisefy.util

+
+

Classes

+ +
+ + diff --git a/javadoc/com/metova/wisefy/util/package-summary.html b/javadoc/com/metova/wisefy/util/package-summary.html new file mode 100644 index 00000000..eac7a11a --- /dev/null +++ b/javadoc/com/metova/wisefy/util/package-summary.html @@ -0,0 +1,147 @@ + + + + + +com.isupatches.wisefy.util (app 1.0.4 API) + + + + + + + + + + + +
+

Package com.isupatches.wisefy.util

+
+
+ +
+ + + + + + diff --git a/javadoc/com/metova/wisefy/util/package-tree.html b/javadoc/com/metova/wisefy/util/package-tree.html new file mode 100644 index 00000000..2d56cf74 --- /dev/null +++ b/javadoc/com/metova/wisefy/util/package-tree.html @@ -0,0 +1,136 @@ + + + + + +com.isupatches.wisefy.util Class Hierarchy (app 1.0.4 API) + + + + + + + + + + + +
+

Hierarchy For Package com.isupatches.wisefy.util

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +
+ + + + + + diff --git a/javadoc/constant-values.html b/javadoc/constant-values.html new file mode 100644 index 00000000..ecf9c4df --- /dev/null +++ b/javadoc/constant-values.html @@ -0,0 +1,158 @@ + + + + + +Constant Field Values (app 1.0.4 API) + + + + + + + + + + + +
+

Constant Field Values

+

Contents

+ +
+
+ + +

com.isupatches.*

+ +
+ + + + + + diff --git a/javadoc/deprecated-list.html b/javadoc/deprecated-list.html new file mode 100644 index 00000000..547cdffb --- /dev/null +++ b/javadoc/deprecated-list.html @@ -0,0 +1,122 @@ + + + + + +Deprecated List (app 1.0.4 API) + + + + + + + + +
+ + + + + + + +
+ + +
+

Deprecated API

+

Contents

+
+ +
+ + + + + + + +
+ + + + diff --git a/javadoc/help-doc.html b/javadoc/help-doc.html new file mode 100644 index 00000000..4b671312 --- /dev/null +++ b/javadoc/help-doc.html @@ -0,0 +1,223 @@ + + + + + +API Help (app 1.0.4 API) + + + + + + + + +
+ + + + + + + +
+ + +
+

How This API Document Is Organized

+
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
+
+
+
    +
  • +

    Overview

    +

    The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.

    +
  • +
  • +

    Package

    +

    Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:

    +
      +
    • Interfaces (italic)
    • +
    • Classes
    • +
    • Enums
    • +
    • Exceptions
    • +
    • Errors
    • +
    • Annotation Types
    • +
    +
  • +
  • +

    Class/Interface

    +

    Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    +
      +
    • Class inheritance diagram
    • +
    • Direct Subclasses
    • +
    • All Known Subinterfaces
    • +
    • All Known Implementing Classes
    • +
    • Class/interface declaration
    • +
    • Class/interface description
    • +
    +
      +
    • Nested Class Summary
    • +
    • Field Summary
    • +
    • Constructor Summary
    • +
    • Method Summary
    • +
    +
      +
    • Field Detail
    • +
    • Constructor Detail
    • +
    • Method Detail
    • +
    +

    Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.

    +
  • +
  • +

    Annotation Type

    +

    Each annotation type has its own separate page with the following sections:

    +
      +
    • Annotation Type declaration
    • +
    • Annotation Type description
    • +
    • Required Element Summary
    • +
    • Optional Element Summary
    • +
    • Element Detail
    • +
    +
  • +
  • +

    Enum

    +

    Each enum has its own separate page with the following sections:

    +
      +
    • Enum declaration
    • +
    • Enum description
    • +
    • Enum Constant Summary
    • +
    • Enum Constant Detail
    • +
    +
  • +
  • +

    Tree (Class Hierarchy)

    +

    There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.

    +
      +
    • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
    • +
    • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
    • +
    +
  • +
  • +

    Deprecated API

    +

    The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.

    +
  • +
  • +

    Index

    +

    The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.

    +
  • +
  • +

    Prev/Next

    +

    These links take you to the next or previous class, interface, package, or related page.

    +
  • +
  • +

    Frames/No Frames

    +

    These links show and hide the HTML frames. All pages are available with or without frames.

    +
  • +
  • +

    All Classes

    +

    The All Classes link shows all classes and interfaces except non-static nested types.

    +
  • +
  • +

    Serialized Form

    +

    Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.

    +
  • +
  • +

    Constant Field Values

    +

    The Constant Field Values page lists the static final fields and their values.

    +
  • +
+This help file applies to API documentation generated using the standard doclet.
+ +
+ + + + + + + +
+ + + + diff --git a/javadoc/index-all.html b/javadoc/index-all.html new file mode 100644 index 00000000..5eb6e966 --- /dev/null +++ b/javadoc/index-all.html @@ -0,0 +1,346 @@ + + + + + +Index (app 1.0.4 API) + + + + + + + + +
+ + + + + + + +
+ + +
A C D E G I L M R S W  + + +

A

+
+
addOpenNetwork(String) - Method in class com.isupatches.wisefy.WiseFy
+
+
To add an open network to the user's configured network list
+
+
addWEPNetwork(String, String) - Method in class com.isupatches.wisefy.WiseFy
+
+
To add a WEP network to the user's configured network list
+
+
addWPA2Network(String, String) - Method in class com.isupatches.wisefy.WiseFy
+
+
To add a WPA2 network to the user's configured network list
+
+
+ + + +

C

+
+
calculateBars(int, int) - Method in class com.isupatches.wisefy.WiseFy
+
+
To convert an RSSI level for a network to a number of bars
+
+
com.isupatches.wisefy - package com.isupatches.wisefy
+
 
+
com.isupatches.wisefy.util - package com.isupatches.wisefy.util
+
 
+
compareSignalLevel(int, int) - Method in class com.isupatches.wisefy.WiseFy
+
+
To compare the signal strength of two networks
+
+
connectToNetwork(String, int) - Method in class com.isupatches.wisefy.WiseFy
+
+
Used to connect to a network + + Gets a list of saved networks, connects/reconnects to the given ssid, and then calls waitToConnectToSSID to verify connectivity
+
+
convertSSIDForConfig(String) - Method in class com.isupatches.wisefy.util.SSIDUtil
+
 
+
+ + + +

D

+
+
d(String, String, boolean) - Method in class com.isupatches.wisefy.util.LogUtil
+
 
+
disableWifi() - Method in class com.isupatches.wisefy.WiseFy
+
+
To disable Wifi on a user's device
+
+
disconnectFromCurrentNetwork() - Method in class com.isupatches.wisefy.WiseFy
+
+
To disconnect the user from their current network
+
+
+ + + +

E

+
+
e(String, String, boolean) - Method in class com.isupatches.wisefy.util.LogUtil
+
 
+
enableWifi() - Method in class com.isupatches.wisefy.WiseFy
+
+
To enable Wifi on a user's device
+
+
+ + + +

G

+
+
getConnectivityManager(Context) - Method in class com.isupatches.wisefy.util.GetManagerUtil
+
+
To get a Connectivity manger instance from an activity's context.
+
+
getCurrentNetwork() - Method in class com.isupatches.wisefy.WiseFy
+
+
To retrieve the user's current network
+
+
getInstance() - Static method in class com.isupatches.wisefy.util.GetManagerUtil
+
 
+
getInstance() - Static method in class com.isupatches.wisefy.util.LogUtil
+
 
+
getInstance() - Static method in class com.isupatches.wisefy.util.SSIDUtil
+
 
+
GetManagerUtil - Class in com.isupatches.wisefy.util
+
 
+
getNearbyAccessPoints(boolean) - Method in class com.isupatches.wisefy.WiseFy
+
+
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)
+
+
getSavedNetworks() - Method in class com.isupatches.wisefy.WiseFy
+
+
To retrieve a list of saved networks on a user's device
+
+
getSmarts() - Method in class com.isupatches.wisefy.WiseFy.withContext
+
+
Mandatory - To build and return a WiseFy instance + + Must be called after withContext + #withContext(Context)
+
+
getWiFiManager(Context) - Method in class com.isupatches.wisefy.util.GetManagerUtil
+
+
To get a WiFi manger instance from an activity's context.
+
+
+ + + +

I

+
+
isDeviceConnectedToMobileNetwork() - Method in class com.isupatches.wisefy.WiseFy
+
+
To check if the device is connected to a mobile network
+
+
isDeviceConnectedToMobileOrWifiNetwork() - Method in class com.isupatches.wisefy.WiseFy
+
+
To check if the device is connected to a mobile or wifi network
+
+
isDeviceConnectedToSSID(String) - Method in class com.isupatches.wisefy.WiseFy
+
+
To check if the device is connected to a given SSID + + Used by connectToNetwork
+
+
isDeviceConnectedToWifiNetwork() - Method in class com.isupatches.wisefy.WiseFy
+
+
To check if the device is connected to a wifi network
+
+
isLoggingEnabled() - Method in class com.isupatches.wisefy.WiseFy
+
+
To query if logging is enabled or disabled for a WiseFy instance
+
+
isNetworkInConfigurationList(String) - Method in class com.isupatches.wisefy.WiseFy
+
+
To check if an SSID is in the list of configured networks
+
+
isNetworkSecure(ScanResult) - Method in class com.isupatches.wisefy.WiseFy
+
+
To check and return if a network is secure (WEP/PSK/EAP capabilities)
+
+
isWifiEnabled() - Method in class com.isupatches.wisefy.WiseFy
+
+
To check if Wifi is enabled on the device or not
+
+
+ + + +

L

+
+
logging(boolean) - Method in class com.isupatches.wisefy.WiseFy.withContext
+
+
Optional - Builder method that enables/disables logging for a WiseWy instance
+
+
LogUtil - Class in com.isupatches.wisefy.util
+
 
+
+ + + +

M

+
+
mConnectivityManager - Variable in class com.isupatches.wisefy.WiseFy
+
 
+
mWifiManager - Variable in class com.isupatches.wisefy.WiseFy
+
 
+
+ + + +

R

+
+
removeNetwork(String) - Method in class com.isupatches.wisefy.WiseFy
+
+
To remove a configured network
+
+
+ + + +

S

+
+
searchForSSID(String, int) - Method in class com.isupatches.wisefy.WiseFy
+
+
To search local networks and return the first one that contains a given ssid (non-case sensitive)
+
+
SSIDUtil - Class in com.isupatches.wisefy.util
+
 
+
+ + + +

W

+
+
w(String, String, boolean) - Method in class com.isupatches.wisefy.util.LogUtil
+
 
+
WIFI_MANAGER_FAILURE - Static variable in class com.isupatches.wisefy.WiseFy
+
 
+
WISE_MANAGER_FAILURE - Static variable in class com.isupatches.wisefy.WiseFy
+
 
+
WiseFy - Class in com.isupatches.wisefy
+
+
Main class to manipulate and query network settings on an Android device + + Uses the builder pattern for creation - WiseFy.withContext
+
+
WiseFy.withContext - Class in com.isupatches.wisefy
+
+
Static class for builder pattern + + Implements builder interfaces #Logging #GetSmarts
+
+
withContext(Context) - Constructor for class com.isupatches.wisefy.WiseFy.withContext
+
+
Mandatory - The public constructor for the builder that requires a context
+
+
+A C D E G I L M R S W 
+ +
+ + + + + + + +
+ + + + diff --git a/javadoc/index.html b/javadoc/index.html new file mode 100644 index 00000000..3c65afdc --- /dev/null +++ b/javadoc/index.html @@ -0,0 +1,74 @@ + + + + + +app 1.0.4 API + + + + + + + + + +<noscript> +<div>JavaScript is disabled on your browser.</div> +</noscript> +<h2>Frame Alert</h2> +<p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> + + + diff --git a/javadoc/overview-frame.html b/javadoc/overview-frame.html new file mode 100644 index 00000000..108bf676 --- /dev/null +++ b/javadoc/overview-frame.html @@ -0,0 +1,22 @@ + + + + + +Overview List (app 1.0.4 API) + + + + + + + +

 

+ + diff --git a/javadoc/overview-summary.html b/javadoc/overview-summary.html new file mode 100644 index 00000000..37697032 --- /dev/null +++ b/javadoc/overview-summary.html @@ -0,0 +1,140 @@ + + + + + +Overview (app 1.0.4 API) + + + + + + + + +
+ + + + + + + +
+ + +
+

app 1.0.4 API

+
+
+ + + + + + + + + + + + + + + + +
Packages 
PackageDescription
com.isupatches.wisefy 
com.isupatches.wisefy.util 
+
+ +
+ + + + + + + +
+ + + + diff --git a/javadoc/overview-tree.html b/javadoc/overview-tree.html new file mode 100644 index 00000000..3d6557eb --- /dev/null +++ b/javadoc/overview-tree.html @@ -0,0 +1,140 @@ + + + + + +Class Hierarchy (app 1.0.4 API) + + + + + + + + +
+ + + + + + + +
+ + +
+

Hierarchy For All Packages

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +
+ +
+ + + + + + + +
+ + + + diff --git a/javadoc/package-list b/javadoc/package-list new file mode 100644 index 00000000..b0c97570 --- /dev/null +++ b/javadoc/package-list @@ -0,0 +1,2 @@ +com.isupatches.wisefy +com.isupatches.wisefy.util diff --git a/javadoc/script.js b/javadoc/script.js new file mode 100644 index 00000000..b3463569 --- /dev/null +++ b/javadoc/script.js @@ -0,0 +1,30 @@ +function show(type) +{ + count = 0; + for (var key in methods) { + var row = document.getElementById(key); + if ((methods[key] & type) != 0) { + row.style.display = ''; + row.className = (count++ % 2) ? rowColor : altColor; + } + else + row.style.display = 'none'; + } + updateTabs(type); +} + +function updateTabs(type) +{ + for (var value in tabs) { + var sNode = document.getElementById(tabs[value][0]); + var spanNode = sNode.firstChild; + if (value == type) { + sNode.className = activeTableTab; + spanNode.innerHTML = tabs[value][1]; + } + else { + sNode.className = tableTab; + spanNode.innerHTML = "" + tabs[value][1] + ""; + } + } +} diff --git a/javadoc/stylesheet.css b/javadoc/stylesheet.css new file mode 100644 index 00000000..98055b22 --- /dev/null +++ b/javadoc/stylesheet.css @@ -0,0 +1,574 @@ +/* Javadoc style sheet */ +/* +Overall document style +*/ + +@import url('resources/fonts/dejavu.css'); + +body { + background-color:#ffffff; + color:#353833; + font-family:'DejaVu Sans', Arial, Helvetica, sans-serif; + font-size:14px; + margin:0; +} +a:link, a:visited { + text-decoration:none; + color:#4A6782; +} +a:hover, a:focus { + text-decoration:none; + color:#bb7a2a; +} +a:active { + text-decoration:none; + color:#4A6782; +} +a[name] { + color:#353833; +} +a[name]:hover { + text-decoration:none; + color:#353833; +} +pre { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; +} +h1 { + font-size:20px; +} +h2 { + font-size:18px; +} +h3 { + font-size:16px; + font-style:italic; +} +h4 { + font-size:13px; +} +h5 { + font-size:12px; +} +h6 { + font-size:11px; +} +ul { + list-style-type:disc; +} +code, tt { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; + margin-top:8px; + line-height:1.4em; +} +dt code { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; +} +table tr td dt code { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + vertical-align:top; + padding-top:4px; +} +sup { + font-size:8px; +} +/* +Document title and Copyright styles +*/ +.clear { + clear:both; + height:0px; + overflow:hidden; +} +.aboutLanguage { + float:right; + padding:0px 21px; + font-size:11px; + z-index:200; + margin-top:-9px; +} +.legalCopy { + margin-left:.5em; +} +.bar a, .bar a:link, .bar a:visited, .bar a:active { + color:#FFFFFF; + text-decoration:none; +} +.bar a:hover, .bar a:focus { + color:#bb7a2a; +} +.tab { + background-color:#0066FF; + color:#ffffff; + padding:8px; + width:5em; + font-weight:bold; +} +/* +Navigation bar styles +*/ +.bar { + background-color:#4D7A97; + color:#FFFFFF; + padding:.8em .5em .4em .8em; + height:auto;/*height:1.8em;*/ + font-size:11px; + margin:0; +} +.topNav { + background-color:#4D7A97; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; + font-size:12px; +} +.bottomNav { + margin-top:10px; + background-color:#4D7A97; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; + font-size:12px; +} +.subNav { + background-color:#dee3e9; + float:left; + width:100%; + overflow:hidden; + font-size:12px; +} +.subNav div { + clear:left; + float:left; + padding:0 0 5px 6px; + text-transform:uppercase; +} +ul.navList, ul.subNavList { + float:left; + margin:0 25px 0 0; + padding:0; +} +ul.navList li{ + list-style:none; + float:left; + padding: 5px 6px; + text-transform:uppercase; +} +ul.subNavList li{ + list-style:none; + float:left; +} +.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited { + color:#FFFFFF; + text-decoration:none; + text-transform:uppercase; +} +.topNav a:hover, .bottomNav a:hover { + text-decoration:none; + color:#bb7a2a; + text-transform:uppercase; +} +.navBarCell1Rev { + background-color:#F8981D; + color:#253441; + margin: auto 5px; +} +.skipNav { + position:absolute; + top:auto; + left:-9999px; + overflow:hidden; +} +/* +Page header and footer styles +*/ +.header, .footer { + clear:both; + margin:0 20px; + padding:5px 0 0 0; +} +.indexHeader { + margin:10px; + position:relative; +} +.indexHeader span{ + margin-right:15px; +} +.indexHeader h1 { + font-size:13px; +} +.title { + color:#2c4557; + margin:10px 0; +} +.subTitle { + margin:5px 0 0 0; +} +.header ul { + margin:0 0 15px 0; + padding:0; +} +.footer ul { + margin:20px 0 5px 0; +} +.header ul li, .footer ul li { + list-style:none; + font-size:13px; +} +/* +Heading styles +*/ +div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 { + background-color:#dee3e9; + border:1px solid #d0d9e0; + margin:0 0 6px -8px; + padding:7px 5px; +} +ul.blockList ul.blockList ul.blockList li.blockList h3 { + background-color:#dee3e9; + border:1px solid #d0d9e0; + margin:0 0 6px -8px; + padding:7px 5px; +} +ul.blockList ul.blockList li.blockList h3 { + padding:0; + margin:15px 0; +} +ul.blockList li.blockList h2 { + padding:0px 0 20px 0; +} +/* +Page layout container styles +*/ +.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer { + clear:both; + padding:10px 20px; + position:relative; +} +.indexContainer { + margin:10px; + position:relative; + font-size:12px; +} +.indexContainer h2 { + font-size:13px; + padding:0 0 3px 0; +} +.indexContainer ul { + margin:0; + padding:0; +} +.indexContainer ul li { + list-style:none; + padding-top:2px; +} +.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt { + font-size:12px; + font-weight:bold; + margin:10px 0 0 0; + color:#4E4E4E; +} +.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { + margin:5px 0 10px 0px; + font-size:14px; + font-family:'DejaVu Sans Mono',monospace; +} +.serializedFormContainer dl.nameValue dt { + margin-left:1px; + font-size:1.1em; + display:inline; + font-weight:bold; +} +.serializedFormContainer dl.nameValue dd { + margin:0 0 0 1px; + font-size:1.1em; + display:inline; +} +/* +List styles +*/ +ul.horizontal li { + display:inline; + font-size:0.9em; +} +ul.inheritance { + margin:0; + padding:0; +} +ul.inheritance li { + display:inline; + list-style:none; +} +ul.inheritance li ul.inheritance { + margin-left:15px; + padding-left:15px; + padding-top:1px; +} +ul.blockList, ul.blockListLast { + margin:10px 0 10px 0; + padding:0; +} +ul.blockList li.blockList, ul.blockListLast li.blockList { + list-style:none; + margin-bottom:15px; + line-height:1.4; +} +ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList { + padding:0px 20px 5px 10px; + border:1px solid #ededed; + background-color:#f8f8f8; +} +ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList { + padding:0 0 5px 8px; + background-color:#ffffff; + border:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockList { + margin-left:0; + padding-left:0; + padding-bottom:15px; + border:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast { + list-style:none; + border-bottom:none; + padding-bottom:0; +} +table tr td dl, table tr td dl dt, table tr td dl dd { + margin-top:0; + margin-bottom:1px; +} +/* +Table styles +*/ +.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary { + width:100%; + border-left:1px solid #EEE; + border-right:1px solid #EEE; + border-bottom:1px solid #EEE; +} +.overviewSummary, .memberSummary { + padding:0px; +} +.overviewSummary caption, .memberSummary caption, .typeSummary caption, +.useSummary caption, .constantsSummary caption, .deprecatedSummary caption { + position:relative; + text-align:left; + background-repeat:no-repeat; + color:#253441; + font-weight:bold; + clear:none; + overflow:hidden; + padding:0px; + padding-top:10px; + padding-left:1px; + margin:0px; + white-space:pre; +} +.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link, +.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link, +.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover, +.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover, +.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active, +.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active, +.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited, +.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited { + color:#FFFFFF; +} +.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span, +.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + padding-bottom:7px; + display:inline-block; + float:left; + background-color:#F8981D; + border: none; + height:16px; +} +.memberSummary caption span.activeTableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#F8981D; + height:16px; +} +.memberSummary caption span.tableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#4D7A97; + height:16px; +} +.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab { + padding-top:0px; + padding-left:0px; + padding-right:0px; + background-image:none; + float:none; + display:inline; +} +.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd, +.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd { + display:none; + width:5px; + position:relative; + float:left; + background-color:#F8981D; +} +.memberSummary .activeTableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + float:left; + background-color:#F8981D; +} +.memberSummary .tableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + background-color:#4D7A97; + float:left; + +} +.overviewSummary td, .memberSummary td, .typeSummary td, +.useSummary td, .constantsSummary td, .deprecatedSummary td { + text-align:left; + padding:0px 0px 12px 10px; +} +th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th, +td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{ + vertical-align:top; + padding-right:0px; + padding-top:8px; + padding-bottom:3px; +} +th.colFirst, th.colLast, th.colOne, .constantsSummary th { + background:#dee3e9; + text-align:left; + padding:8px 3px 3px 7px; +} +td.colFirst, th.colFirst { + white-space:nowrap; + font-size:13px; +} +td.colLast, th.colLast { + font-size:13px; +} +td.colOne, th.colOne { + font-size:13px; +} +.overviewSummary td.colFirst, .overviewSummary th.colFirst, +.useSummary td.colFirst, .useSummary th.colFirst, +.overviewSummary td.colOne, .overviewSummary th.colOne, +.memberSummary td.colFirst, .memberSummary th.colFirst, +.memberSummary td.colOne, .memberSummary th.colOne, +.typeSummary td.colFirst{ + width:25%; + vertical-align:top; +} +td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { + font-weight:bold; +} +.tableSubHeadingColor { + background-color:#EEEEFF; +} +.altColor { + background-color:#FFFFFF; +} +.rowColor { + background-color:#EEEEEF; +} +/* +Content styles +*/ +.description pre { + margin-top:0; +} +.deprecatedContent { + margin:0; + padding:10px 0; +} +.docSummary { + padding:0; +} + +ul.blockList ul.blockList ul.blockList li.blockList h3 { + font-style:normal; +} + +div.block { + font-size:14px; + font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; +} + +td.colLast div { + padding-top:0px; +} + + +td.colLast a { + padding-bottom:3px; +} +/* +Formatting effect styles +*/ +.sourceLineNo { + color:green; + padding:0 30px 0 0; +} +h1.hidden { + visibility:hidden; + overflow:hidden; + font-size:10px; +} +.block { + display:block; + margin:3px 10px 2px 0px; + color:#474747; +} +.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink, +.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel, +.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink { + font-weight:bold; +} +.deprecationComment, .emphasizedPhrase, .interfaceName { + font-style:italic; +} + +div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase, +div.block div.block span.interfaceName { + font-style:normal; +} + +div.contentContainer ul.blockList li.blockList h2{ + padding-bottom:0px; +}