diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..22e7b11b --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,84 @@ +version: 2.1 + +orbs: + codecov: codecov/codecov@1.0.5 + +jobs: + ci_checks: + working_directory: ~/code + docker: + - image: circleci/android:api-28-alpha + environment: + JVM_OPTS: -Xmx3200m + steps: + - checkout + - restore_cache: + key: jars-{{ checksum "build.gradle" }}-{{ checksum "wisefy/build.gradle" }}-{{ checksum "wisefysample/build.gradle" }} + - run: + name: Chmod permissions + command: sudo chmod +x ./gradlew + - run: + name: Download dependencies + command: ./gradlew androidDependencies + - run: + name: Clean build + command: ./gradlew clean assembleDebug wisefy:assembleDebugAndroidTest wisefysample:assembleDebugAndroidTest --stacktrace + - run: + name: Static code analysis + command: ./gradlew staticAnalysisSanityCheck + - run: + name: Unit tests + command: ./gradlew :wisefy:jacocoDebugUnitTest :wisefysample:jacocoDebugUnitTest --stacktrace + - run: + name: Store Service Account + command: echo $GCLOUD_SERVICE_KEY > ${HOME}/gcloud-service-key.json + - run: + name: Firebase Testing + command: | + sudo pip install -U crcmod + sudo gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json + sudo gcloud --quiet config set project ${GOOGLE_PROJECT_ID} + sudo gcloud firebase test android run \ + --type instrumentation \ + --app wisefysample/build/outputs/apk/debug/wisefysample-debug.apk \ + --test wisefy/build/outputs/apk/androidTest/debug/wisefy-debug-androidTest.apk \ + --device model=Pixel2,version=28,locale=en,orientation=portrait \ + --device model=Nexus6,version=23,locale=en,orientation=portrait \ + --device model=Nexus5,version=19,locale=en,orientation=portrait \ + --environment-variables coverage=true,coverageFile="/sdcard/coverage.ec" \ + --directories-to-pull=/sdcard \ + --results-dir=${CIRCLE_BRANCH}_${CIRCLE_BUILD_NUM} + sudo gsutil -m cp -r -U gs://${GCLOUD_BUCKET_LOCATION}/${CIRCLE_BRANCH}_${CIRCLE_BUILD_NUM}/Nexus5-19-en-portrait/artifacts/coverage.ec wisefy/build/outputs/code-coverage/connected/wisefy-Nexus5-sdk19-coverage.ec + sudo gsutil -m cp -r -U gs://${GCLOUD_BUCKET_LOCATION}/${CIRCLE_BRANCH}_${CIRCLE_BUILD_NUM}/Nexus6-23-en-portrait/artifacts/coverage.ec wisefy/build/outputs/code-coverage/connected/wisefy-Nexus6-sdk23-coverage.ec + sudo gsutil -m cp -r -U gs://${GCLOUD_BUCKET_LOCATION}/${CIRCLE_BRANCH}_${CIRCLE_BUILD_NUM}/Pixel2-28-en-portrait/artifacts/coverage.ec wisefy/build/outputs/code-coverage/connected/wisefy-Pixel2-sdk28-coverage.ec + sudo gcloud firebase test android run \ + --type instrumentation \ + --app wisefysample/build/outputs/apk/debug/wisefysample-debug.apk \ + --test wisefysample/build/outputs/apk/androidTest/debug/wisefysample-debug-androidTest.apk \ + --device model=Pixel2,version=28,locale=en,orientation=portrait \ + --environment-variables coverage=true,coverageFile="/sdcard/coverage.ec" \ + --directories-to-pull=/sdcard \ + --results-dir=${CIRCLE_BRANCH}_${CIRCLE_BUILD_NUM} + sudo gsutil -m cp -r -U gs://${GCLOUD_BUCKET_LOCATION}/${CIRCLE_BRANCH}_${CIRCLE_BUILD_NUM}/Pixel2-28-en-portrait/artifacts/coverage.ec wisefysample/build/outputs/code-coverage/connected/wisefysample-coverage.ec + sudo gsutil rm -r gs://${GCLOUD_BUCKET_LOCATION}/${CIRCLE_BRANCH}_${CIRCLE_BUILD_NUM} + - run: + name: Generate coverage report + command: ./gradlew :wisefy:jacocoDebugCombinedTestReport :wisefysample:jacocoDebugCombinedTestReport --stacktrace + - codecov/upload: + file: /reports/jacoco/*.xml + - store_artifacts: + path: wisefy/build/reports + destination: reports/wisefy + - store_artifacts: + path: wisefysample/build/reports + destination: reports/wisefysample + - save_cache: + key: jars-{{ checksum "build.gradle" }}-{{ checksum "wisefy/build.gradle" }}-{{ checksum "wisefysample/build.gradle" }} + paths: + - ~/.gradle + +workflows: + version: 2 + workflow: + jobs: + - ci_checks \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index d7695c64..f7f69d36 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -6,7 +6,7 @@ about: Create a report to help us improve Thank you for creating an issue to improve this library! Please check Please check [the current issues](https://github.com/isuPatches/WiseFy/issues) to make sure that the improvement isn't already being worked on. -It will be _EXTREMELY_ helpful if you also take a look at the [sample app](/wisefysample) to see how it behalves and if you can reproduce there. +It will be _EXTREMELY_ helpful if you also take a look at the [sample app](/wisefysample) to see how it behaves and if you can reproduce there. **Description** A clear and concise description of the bug. diff --git a/.idea/dictionaries/patches.xml b/.idea/dictionaries/patches.xml index 533095c3..f7cb0dd3 100644 --- a/.idea/dictionaries/patches.xml +++ b/.idea/dictionaries/patches.xml @@ -3,9 +3,12 @@ inet isupatches + precheck prechecks + rssi runnables ssid + ssids wisefy diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a64819e2..00000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -sudo: required -language: android - -jdk: - - oraclejdk8 - -env: - global: - - TARGET_SDK=28 - - BUILD_TOOLS_VERSION=28.0.3 - -android: - components: - - tools - - platform-tools - - tools - - android-${TARGET_SDK} - - build-tools-${BUILD_TOOLS_VERSION} - - extra-google-m2repository - - extra-android-m2repository - -script: - - ./gradlew clean assembleDebug assembleDebugAndroidTest - - travis_wait 60 ./gradlew makeGoodChoices - -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index 867c7462..c55395bd 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,14 @@ Wifi configuration and util library built for Android. - Update to gradle 5.x - Static analysis tools updated - WEP is now deprecated due to security and other issues with this network type and will be phased out -- Introduction of [RoboElectric](https://github.com/robolectric/robolectric) for better unit testing - - This may be controversial, but please check this [issue](https://github.com/isuPatches/WiseFy/issues/133) for rationale +- Better naming for some saved network functions + - GetSavedNetworkCallbacks renamed SearchForSavedNetworkCallbacks + - Added SearchForSavedNetworksCallbacks + - getSavedNetwork(regex: String?): List? refactored to searchForSavedNetwork(regexForSSID: String?): WifiConfiguration? + - getSavedNetwork(regexForSSID: String?, callbacks: GetSavedNetworkCallbacks?) refactored to searchForSavedNetwork(regexForSSID: String?, callbacks: SearchForSavedNetworkCallbacks?) + - getSavedNetworks(regexForSSID: String?, callbacks: GetSavedNetworksCallbacks?) refactored to searchForSavedNetworks(regexForSSID: String?, callbacks: SearchForSavedNetworksCallbacks?) +- Moved from TravisCI to CircleCI +- Instrumentation tests are now run on Google's Firebase TestLab - Removal of Checkstyle and FindBugs since project is no longer Java - Removal of GCM support due to GCM being sunset - New [sample app](/wisefysample) included as part of the repo @@ -146,12 +152,12 @@ wisefy.dump(); For the sake of transparency and because you're probably curious as to what permissions this library adds to your app, here are the additional expected permissions: ```xml - - - + + - - + + + ``` * NOTE * diff --git a/build.gradle b/build.gradle index 333ddb82..c8650cf6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ buildscript { project.ext { - agp_version = '3.4.0' + agp_version = '3.4.1' bintray_version = '1.8.4' - cpd_version = '2.0-SNAPSHOT' + cpd_version = '2.0' dokka_version = '0.9.18' dexcount_version = '0.8.5' jacoco_version = '0.8.3' @@ -14,7 +14,6 @@ buildscript { jcenter() google() maven { url "https://plugins.gradle.org/m2/" } - maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } dependencies { @@ -25,7 +24,6 @@ buildscript { classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:$dexcount_version" classpath "de.aaschmid:gradle-cpd-plugin:$cpd_version" - // Code Coverage classpath "org.jacoco:org.jacoco.core:$jacoco_version" classpath "org.jacoco:org.jacoco.agent:$jacoco_version" @@ -141,7 +139,8 @@ task makeGoodChoices { outputs.upToDateWhen { false } - dependsOn 'staticAnalysisSanityCheck', ':wisefy:jacocoDebugUnitTest' + dependsOn 'staticAnalysisSanityCheck', + ':wisefy:jacocoDebugUnitTest', ':wisefysample:jacocoDebugUnitTest' doLast { println "\n#############################################" + "\n# All checks passed! You are doing so good! #" + diff --git a/changes/3.x.md b/changes/3.x.md index 6e75a8ba..95e65658 100644 --- a/changes/3.x.md +++ b/changes/3.x.md @@ -1,3 +1,35 @@ +## v3.0.1 - 09/15/2018 + +#### Update README.md to use implementation +commit de9f9c4690f7efa468a5211282f9a19cd6e109cc
+Author: Chintan Rathod <4371780+ChintanRathod@users.noreply.github.com>
+Date: Sun Apr 21 19:45:20 2019 +0530 + +#### Delete -verbose, -dontobfuscate +commit 95e3b8d1d2609822d0eb12aa3fa5f4c408977a4a
+Author: Jungwook Park (Victor)
+Date: Sun Nov 4 12:20:21 2018 +0900 + +#### issue-113 & issue-114 Update dependencies and adjust manifest +commit 07a93f06f9ad6efa05245cfa426d1551c024586b
+Author: Patches
+Date: Sat Sep 15 12:07:14 2018 -0500 + +#### Update README.md +commit 491a53d8014a1211e74d222c6d165d8fd450de3b
+Author: Patches
+Date: Sat Sep 8 14:37:47 2018 -0500 + +#### Add new logo/icon +commit 2dda2fe8409f63ad1400093ebde56ca842c8608d
+Author: mansyaprime <33461607+mansya@users.noreply.github.com>
+Date: Sun Sep 9 02:35:50 2018 +0700 + +#### Update 3.x changes for release +commit 1331e9f9e929405f5050b9419dc0986427adb201
+Author: isuPatches
+Date: Sun Aug 19 18:57:25 2018 -0500 + ## v3.0.0 - 08/19/2018 #### Enable XML for CodeCov diff --git a/changes/4.x.md b/changes/4.x.md index cf967710..2f75f83c 100644 --- a/changes/4.x.md +++ b/changes/4.x.md @@ -1 +1,2 @@ -## v4.0.0 - 05/x/2019 \ No newline at end of file +## v4.0.0 - 06/22/2019 + diff --git a/codecov.yml b/codecov.yml index 4364e18e..df0169d2 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,2 +1,2 @@ codecov: - branch: 3.x \ No newline at end of file + branch: 4.x diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml deleted file mode 100644 index e84397fa..00000000 --- a/config/checkstyle/import-control.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/config/detekt-config.yml b/config/detekt-config.yml index 4fcb6738..a48908d6 100644 --- a/config/detekt-config.yml +++ b/config/detekt-config.yml @@ -1,5 +1,4 @@ autoCorrect: true -failFast: false test-pattern: # Configure exclusions for test sources active: true @@ -338,7 +337,7 @@ style: UnusedImports: active: true ExpressionBodySyntax: - active: true + active: false NestedClassesVisibility: active: true RedundantVisibilityModifierRule: diff --git a/documentation/adding_and_removing_networks.md b/documentation/adding_and_removing_networks.md index cbe5cca4..0856055c 100644 --- a/documentation/adding_and_removing_networks.md +++ b/documentation/adding_and_removing_networks.md @@ -47,7 +47,7 @@ To remove a configured network: _With Kotlin_ ```kotlin -val removedSuccessfully = wisefy.removeNetwork("SSID to remove"); +val removedSuccessfully = wisefy.removeNetwork("SSID to remove") ``` _With Java_ diff --git a/documentation/checking_device_connectivity.md b/documentation/checking_device_connectivity.md index 3deaf7d8..5329febc 100644 --- a/documentation/checking_device_connectivity.md +++ b/documentation/checking_device_connectivity.md @@ -5,7 +5,7 @@ To check and see if the device is connected to a mobile network: _With Kotlin_ ```Kotlin -val isConnected = wisefy.isDeviceConnectedToMobileNetwork(); +val isConnected = wisefy.isDeviceConnectedToMobileNetwork() ``` _With Java_ @@ -19,7 +19,7 @@ To check and see if the device is connected to a mobile or wifi network: _With Kotlin_ ```kotlin -val isConnected = wisefy.isDeviceConnectedToMobileOrWifiNetwork(); +val isConnected = wisefy.isDeviceConnectedToMobileOrWifiNetwork() ``` _With Java_ @@ -33,7 +33,7 @@ To check and see if the device is connected to a given SSID: _With Kotlin_ ```kotlin -val isConnected = wisefy.isDeviceConnectedToSSID("SSID"); +val isConnected = wisefy.isDeviceConnectedToSSID("SSID") ``` _With Java_ @@ -47,7 +47,7 @@ To check and see if the device is connected to a wifi network: _With Kotlin_ ```kotlin -val isConnected = wisefy.isDeviceConnectedToWifiNetwork(); +val isConnected = wisefy.isDeviceConnectedToWifiNetwork() ``` _With Java_ @@ -61,7 +61,7 @@ To check and see if the device is roaming: _With Kotlin_ ```kotlin -val isDeviceRoaming = wisefy.isDeviceRoaming(); +val isDeviceRoaming = wisefy.isDeviceRoaming() ``` _With Java_ @@ -75,7 +75,7 @@ To check and see if Wifi is enabled on a device: _With Kotlin_ ```kotlin -boolean wifiEnabled = wisefy.isWifiEnabled(); +boolean wifiEnabled = wisefy.isWifiEnabled() ``` _With Java_ diff --git a/documentation/connecting_and_disconnecting_from_networks.md b/documentation/connecting_and_disconnecting_from_networks.md index 96afc747..d2e07ca0 100644 --- a/documentation/connecting_and_disconnecting_from_networks.md +++ b/documentation/connecting_and_disconnecting_from_networks.md @@ -5,7 +5,7 @@ To connect to a network given an SSID: _With Kotlin_ ```kotlin -val connectedSuccessfully = wisefy.connectToNetwork("SSID to connect to", 3000); +val connectedSuccessfully = wisefy.connectToNetwork("SSID to connect to", 3000) ``` _With Java_ @@ -19,7 +19,7 @@ To disconnect from current network: _With Kotlin_ ```kotlin -val disconnectedSuccessfully = wisefy.disconnectFromCurrentNetwork(); +val disconnectedSuccessfully = wisefy.disconnectFromCurrentNetwork() ``` _With Java_ diff --git a/documentation/nearby_access_points.md b/documentation/nearby_access_points.md index 80c3d1a0..afe458ec 100644 --- a/documentation/nearby_access_points.md +++ b/documentation/nearby_access_points.md @@ -21,7 +21,7 @@ To search for an access point given a regex (will return first match):

_With Kotlin_ ```kotlin -val wisefy.searchForAccessPoint("regex for SSID", 3000, true); +val wisefy.searchForAccessPoint("regex for SSID", 3000, true) ``` _With Java_ diff --git a/documentation/saved_networks.md b/documentation/saved_networks.md index 541380de..6cde2baa 100644 --- a/documentation/saved_networks.md +++ b/documentation/saved_networks.md @@ -1,17 +1,17 @@ #### Via The Synchronous API -To get the first saved network that matches a given regex: +To search for the first saved network that matches a given regex: _With Kotlin_ ```kotlin -val savedNetwork = wisefy.getSavedNetwork("regex for SSID") +val savedNetwork = wisefy.searchForSavedNetwork("regex for SSID") ``` _With Java_ ```java -WifiConfiguration savedNetwork = wisefy.getSavedNetwork("regex for SSID"); +WifiConfiguration savedNetwork = wisefy.searchForSavedNetwork("regex for SSID"); ``` To retrieve all of the saved networks: @@ -33,13 +33,13 @@ To return all saved networks that match a given regex: _With Kotlin_ ```kotlin -val savedNetworks = wisefy.getSavedNetworks("regex for SSID") +val savedNetworks = wisefy.searchForSavedNetworks("regex for SSID") ``` _With Java_ ```java -List savedNetworks = wisefy.getSavedNetworks("regex for SSID"); +List savedNetworks = wisefy.searchForSavedNetworks("regex for SSID"); ``` To check and see if a given SSID is in the devices set of configured networks: @@ -63,7 +63,7 @@ To get the first saved network that matches a given regex: _With Kotlin_ ```kotlin -wisefy.getSavedNetwork("regex for SSID", object: GetSavedNetworkCallbacks { +wisefy.searchForSavedNetwork("regex for SSID", object: SearchForSavedNetworkCallbacks { override fun retrievedSavedNetwork(savedNetwork: WifiConfiguration) { } @@ -81,7 +81,7 @@ wisefy.getSavedNetwork("regex for SSID", object: GetSavedNetworkCallbacks { _With Java_ ```java -wisefy.getSavedNetwork("regex for SSID", new GetSavedNetworkCallbacks() { +wisefy.searchForSavedNetwork("regex for SSID", new SearchForSavedNetworkCallbacks() { @Override public void retrievedSavedNetwork(WifiConfiguration savedNetwork) { @@ -145,7 +145,7 @@ To return all saved networks that match a given regex: _With Kotlin_ ```kotlin -wisefy.getSavedNetworks("regex for SSID", object: GetSavedNetworksCallbacks { +wisefy.searchForSavedNetworks("regex for SSID", object: SearchForSavedNetworksCallbacks { override fun retrievedSavedNetworks(savedNetworks: List) { } @@ -163,7 +163,7 @@ wisefy.getSavedNetworks("regex for SSID", object: GetSavedNetworksCallbacks { _With Java_ ```java -wisefy.getSavedNetworks("regex for SSID", new GetSavedNetworksCallbacks() { +wisefy.searchForSavedNetworks("regex for SSID", new SearchForSavedNetworksCallbacks() { @Override public void retrievedSavedNetworks(List savedNetworks) { diff --git a/gradle/detekt.gradle b/gradle/detekt.gradle index 52ecaa24..8ed4038b 100644 --- a/gradle/detekt.gradle +++ b/gradle/detekt.gradle @@ -2,5 +2,6 @@ apply plugin: "io.gitlab.arturbosch.detekt" detekt { version = "$detekt_version" + failFast = false config = files("$project.rootDir/config/detekt-config.yml") } \ No newline at end of file diff --git a/gradle/jacoco.gradle b/gradle/jacoco.gradle index 3c754027..ca9b4caf 100644 --- a/gradle/jacoco.gradle +++ b/gradle/jacoco.gradle @@ -1,7 +1,7 @@ apply plugin: 'jacoco' jacoco { -toolVersion = "$jacoco_version" + toolVersion = "$jacoco_version" } def srcDirs = ["src/main/java"] @@ -15,7 +15,8 @@ def excludes = [ '**/Manifest*.*', '**/*$Lambda$*.class', '**/*Factory*.class', - '**/*$Builder*' + '**/*$Builder*', + '**/di/*.class' ] project.afterEvaluate { @@ -39,7 +40,7 @@ project.afterEvaluate { ])) reports { - xml.enabled = true // Enabled for CodeCov + xml.enabled = false html.enabled = true } } @@ -131,7 +132,7 @@ project.afterEvaluate { ])) reports { - xml.enabled = false + xml.enabled = true // Enabled for CodeCov html.enabled = true } } diff --git a/gradle/static-analysis.gradle b/gradle/static-analysis.gradle index e13c87db..9bf6736d 100644 --- a/gradle/static-analysis.gradle +++ b/gradle/static-analysis.gradle @@ -14,7 +14,7 @@ task staticAnalysisSanityCheck { task ktlintAll { group = 'verification' - dependsOn ':wisefy:ktlintCheck' + dependsOn ':wisefy:ktlintCheck', 'wisefysample:ktlintCheck' doLast { println "\n##################################################" + "\n# KTLinted all the things! Go you! #" + @@ -25,7 +25,7 @@ task ktlintAll { task detektAll { group = 'verification' - dependsOn ':wisefy:detekt' + dependsOn ':wisefy:detekt', 'wisefysample:detekt' doLast { println "\n##################################################" + "\n# No issues Detekt'ed :badjoke: #" + @@ -36,7 +36,7 @@ task detektAll { task cpdAll { group = 'verification' - dependsOn ':wisefy:cpdCheck' + dependsOn ':wisefy:cpdCheck', 'wisefysample:cpdCheck' doLast { println "\n##################################################" + "\n# Code so DRY, it must have an umbrella! #" + @@ -47,7 +47,7 @@ task cpdAll { task pmdAll { group = 'verification' - dependsOn ':wisefy:pmd' + dependsOn ':wisefy:pmd', 'wisefysample:pmd' doLast { println "\n##################################################" + "\n# PMD'ed all the things! Oooohh yea!! #" + @@ -60,7 +60,7 @@ task lintAll { outputs.upToDateWhen { false } - dependsOn ':wisefy:lintDebug' + dependsOn ':wisefy:lintDebug', 'wisefysample:lintDebug' doLast { println "\n##################################################" + "\n# Lint error free is the way to be! #" + diff --git a/gradle/versions.gradle b/gradle/versions.gradle index b2e44042..afd91bcc 100644 --- a/gradle/versions.gradle +++ b/gradle/versions.gradle @@ -1,25 +1,25 @@ ext { - androidx_appcompat_version = "1.1.0-alpha04" - androidx_constraintlayout_version = "2.0.0-alpha5" + androidx_appcompat_version = "1.1.0-beta01" + androidx_constraintlayout_version = "2.0.0-beta2" androidx_support_annotations_version = '1.0.0' - androidx_core_ktx_version = '1.0.1' + androidx_core_ktx_version = '1.0.2' androidx_core_test_version = '1.1.0' - google_android_material_version = "1.1.0-alpha06" + google_android_material_version = "1.1.0-alpha07" - dagger_version = "2.22.1" + dagger_version = "2.23.2" - detekt_version = "1.0.0-RC14" - ktlint_version = "0.31.0" + detekt_version = "1.0.0-RC15" + ktlint_version = "0.33.0" rxandroid_version = '2.1.1' - rxjava_version = '2.2.7' + rxjava_version = '2.2.10' // Test deps junit_version = '4.12' - mockito_version = '2.27.0' - robo_electric_version = '4.2.1' + mockito_version = '2.28.2' + mockito_kotlin_version = '2.1.0' - androidx_espresso_core_version = '3.1.0' - androidx_test_runner_version = "1.1.0" + androidx_espresso_core_version = '3.1.1' + androidx_test_runner_version = "1.1.1" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 13536770..5c2d1cf0 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ed5aaee4..ee69dd68 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index cccdd3d5..b0d6d0ab 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# 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. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" diff --git a/gradlew.bat b/gradlew.bat index e95643d6..15e1ee37 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/javadoc/wisefy/alltypes/index.html b/javadoc/wisefy/alltypes/index.html index 3e838faa..3018c115 100644 --- a/javadoc/wisefy/alltypes/index.html +++ b/javadoc/wisefy/alltypes/index.html @@ -10,6 +10,20 @@

All Types

+com.isupatches.wisefy.AccessPointApi + +

An API for querying for nearby access points and related information.

+ + + + +com.isupatches.wisefy.AddNetworkApi + +

An API for adding networks as saved configurations on a device.

+ + + + com.isupatches.wisefy.callbacks.AddNetworkCallbacks

Callbacks for adding a network as a saved configuration on a device.

@@ -32,6 +46,13 @@

All Types

+com.isupatches.wisefy.ConnectionApi + +

An API for managing the network connection of a device.

+ + + + com.isupatches.wisefy.callbacks.ConnectToNetworkCallbacks

Callbacks for attempting to connect to a network.

@@ -39,6 +60,13 @@

All Types

+com.isupatches.wisefy.DeviceApi + +

An API for querying about the different network statuses of a device.

+ + + + com.isupatches.wisefy.callbacks.DisableWifiCallbacks

Callbacks for disabling a device's wifi.

@@ -60,6 +88,13 @@

All Types

+com.isupatches.wisefy.FrequencyApi + +

An API for querying about a network's frequency.

+ + + + com.isupatches.wisefy.callbacks.GetCurrentNetworkCallbacks

Callbacks for retrieving a device's current network.

@@ -102,16 +137,16 @@

All Types

-com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks +com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks -

Callbacks for retrieving a saved network on a device.

+

Callbacks for retrieving a list of saved networks on a device.

-com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks +com.isupatches.wisefy.NetworkInfoApi -

Callbacks for retrieving a list of saved networks on a device.

+

An API for querying about a device's current network information.

@@ -123,6 +158,13 @@

All Types

+com.isupatches.wisefy.RemoveNetworkApi + +

An API for removing a network as a saved configuration.

+ + + + com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks

Callbacks for removing a saved network on a device.

@@ -130,6 +172,13 @@

All Types

+com.isupatches.wisefy.SavedNetworkApi + +

An API for querying saved network information on a device.

+ + + + com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks

Callbacks for finding a nearby access point on a device.

@@ -144,6 +193,20 @@

All Types

+com.isupatches.wisefy.callbacks.SearchForSavedNetworkCallbacks + +

Callbacks for retrieving a saved network on a device.

+ + + + +com.isupatches.wisefy.callbacks.SearchForSavedNetworksCallbacks + +

Callbacks for retrieving a list of saved networks on a device.

+ + + + com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks

Callbacks for finding a nearby SSID on a device.

@@ -158,6 +221,27 @@

All Types

+com.isupatches.wisefy.SecurityApi + +

An API for querying about a network's security details.

+ + + + +com.isupatches.wisefy.SignalStrengthApi + +

An API for functionality relating to signal strength.

+ + + + +com.isupatches.wisefy.WifiApi + +

An API for functionality relating to Wifi.

+ + + + com.isupatches.wisefy.WiseFy

Main class for WiseFy that provides a synchronous and asynchronous API to manipulate and query @@ -185,6 +269,14 @@

All Types

A class used to synchronize logic.

+ + +com.isupatches.wisefy.WiseFyPublicApi + +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-base-callback/index.html b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-base-callback/index.html index 18776513..e041183d 100644 --- a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-base-callback/index.html +++ b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-base-callback/index.html @@ -134,15 +134,6 @@

Inheritors

-

GetSavedNetworkCallbacks

- - -interface GetSavedNetworkCallbacks : BaseCallback -

Callbacks for retrieving a saved network on a device.

- - - -

GetSavedNetworksCallbacks

@@ -179,6 +170,24 @@

Inheritors

+

SearchForSavedNetworkCallbacks

+ + +interface SearchForSavedNetworkCallbacks : BaseCallback +

Callbacks for retrieving a saved network on a device.

+ + + + +

SearchForSavedNetworksCallbacks

+ + +interface SearchForSavedNetworksCallbacks : BaseCallback +

Callbacks for retrieving a list of saved networks on a device.

+ + + +

SearchForSSIDCallbacks

diff --git a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-get-current-network-info-callbacks/index.html b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-get-current-network-info-callbacks/index.html index 681065c8..0aa60cb2 100644 --- a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-get-current-network-info-callbacks/index.html +++ b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-get-current-network-info-callbacks/index.html @@ -35,7 +35,7 @@

Functions

retrievedCurrentNetworkInfo

-abstract fun retrievedCurrentNetworkInfo(currentNetworkDetails: NetworkInfo): Unit +abstract fun retrievedCurrentNetworkInfo(currentNetworkInfo: NetworkInfo): Unit

Called when WiseFy has successfully retrieved the device's current network info.

diff --git a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-get-current-network-info-callbacks/retrieved-current-network-info.html b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-get-current-network-info-callbacks/retrieved-current-network-info.html index b069b94d..1ee56dae 100644 --- a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-get-current-network-info-callbacks/retrieved-current-network-info.html +++ b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-get-current-network-info-callbacks/retrieved-current-network-info.html @@ -9,7 +9,7 @@

retrievedCurrentNetworkInfo

-abstract fun retrievedCurrentNetworkInfo(currentNetworkDetails: NetworkInfo): Unit +abstract fun retrievedCurrentNetworkInfo(currentNetworkInfo: NetworkInfo): Unit

Called when WiseFy has successfully retrieved the device's current network info.

See Also

NetworkInfo

diff --git a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-network-callbacks/index.html b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-network-callbacks/index.html new file mode 100644 index 00000000..63d6c39c --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-network-callbacks/index.html @@ -0,0 +1,58 @@ + + + +SearchForSavedNetworkCallbacks - wisefy + + + +wisefy / com.isupatches.wisefy.callbacks / SearchForSavedNetworkCallbacks
+
+

SearchForSavedNetworkCallbacks

+interface SearchForSavedNetworkCallbacks : BaseCallback +

Callbacks for retrieving a saved network on a device.

+

See Also
+

BaseCallback

+

com.isupatches.wisefy.WiseFy.searchForSavedNetwork

+

+

Author
+Patches

+

Functions

+ + + + + + + + + + + +
+

retrievedSavedNetwork

+
+abstract fun retrievedSavedNetwork(savedNetwork: WifiConfiguration): Unit +

Called when WiseFy has successfully retrieved a matching saved network configuration.

+
+

savedNetworkNotFound

+
+abstract fun savedNetworkNotFound(): Unit +

Called when there are no saved network configurations matching search criteria.

+
+

Inherited Functions

+ + + + + + + +
+

wisefyFailure

+
+abstract fun wisefyFailure(wisefyFailureCode: Int): Unit +

Called when com.isupatches.wisefy.WiseFyPrechecks determines that there +is an issue and an operation cannot be completed.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-network-callbacks/retrieved-saved-network.html b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-network-callbacks/retrieved-saved-network.html new file mode 100644 index 00000000..ec20b33a --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-network-callbacks/retrieved-saved-network.html @@ -0,0 +1,22 @@ + + + +SearchForSavedNetworkCallbacks.retrievedSavedNetwork - wisefy + + + +wisefy / com.isupatches.wisefy.callbacks / SearchForSavedNetworkCallbacks / retrievedSavedNetwork
+
+

retrievedSavedNetwork

+ +abstract fun retrievedSavedNetwork(savedNetwork: WifiConfiguration): Unit +

Called when WiseFy has successfully retrieved a matching saved network configuration.

+

See Also
+

WifiConfiguration

+

+

Author
+Patches

+

Since
+4.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-network-callbacks/saved-network-not-found.html b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-network-callbacks/saved-network-not-found.html new file mode 100644 index 00000000..756d8897 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-network-callbacks/saved-network-not-found.html @@ -0,0 +1,19 @@ + + + +SearchForSavedNetworkCallbacks.savedNetworkNotFound - wisefy + + + +wisefy / com.isupatches.wisefy.callbacks / SearchForSavedNetworkCallbacks / savedNetworkNotFound
+
+

savedNetworkNotFound

+ +abstract fun savedNetworkNotFound(): Unit +

Called when there are no saved network configurations matching search criteria.

+

Author
+Patches

+

Since
+4.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-networks-callbacks/index.html b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-networks-callbacks/index.html new file mode 100644 index 00000000..07a9b1e0 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-networks-callbacks/index.html @@ -0,0 +1,62 @@ + + + +SearchForSavedNetworksCallbacks - wisefy + + + +wisefy / com.isupatches.wisefy.callbacks / SearchForSavedNetworksCallbacks
+
+

SearchForSavedNetworksCallbacks

+interface SearchForSavedNetworksCallbacks : BaseCallback +

Callbacks for retrieving a list of saved networks on a device.

+

See Also
+

BaseCallback

+

com.isupatches.wisefy.WiseFy.searchForSavedNetworks

+

+

Author
+Patches

+

Since
+4.0

+

Functions

+ + + + + + + + + + + +
+

noSavedNetworksFound

+
+abstract fun noSavedNetworksFound(): Unit +

Called when there are no saved network configuration on the device matching the +given search criteria.

+
+

retrievedSavedNetworks

+
+abstract fun retrievedSavedNetworks(savedNetworks: List<WifiConfiguration>): Unit +

Called when WiseFy has successfully retrieved a list of saved networks matching +the given search criteria.

+
+

Inherited Functions

+ + + + + + + +
+

wisefyFailure

+
+abstract fun wisefyFailure(wisefyFailureCode: Int): Unit +

Called when com.isupatches.wisefy.WiseFyPrechecks determines that there +is an issue and an operation cannot be completed.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-networks-callbacks/no-saved-networks-found.html b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-networks-callbacks/no-saved-networks-found.html new file mode 100644 index 00000000..db0a6b77 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-networks-callbacks/no-saved-networks-found.html @@ -0,0 +1,20 @@ + + + +SearchForSavedNetworksCallbacks.noSavedNetworksFound - wisefy + + + +wisefy / com.isupatches.wisefy.callbacks / SearchForSavedNetworksCallbacks / noSavedNetworksFound
+
+

noSavedNetworksFound

+ +abstract fun noSavedNetworksFound(): Unit +

Called when there are no saved network configuration on the device matching the +given search criteria.

+

Author
+Patches

+

Since
+4.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-networks-callbacks/retrieved-saved-networks.html b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-networks-callbacks/retrieved-saved-networks.html new file mode 100644 index 00000000..78de4f6d --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy.callbacks/-search-for-saved-networks-callbacks/retrieved-saved-networks.html @@ -0,0 +1,23 @@ + + + +SearchForSavedNetworksCallbacks.retrievedSavedNetworks - wisefy + + + +wisefy / com.isupatches.wisefy.callbacks / SearchForSavedNetworksCallbacks / retrievedSavedNetworks
+
+

retrievedSavedNetworks

+ +abstract fun retrievedSavedNetworks(savedNetworks: List<@JvmSuppressWildcards WifiConfiguration>): Unit +

Called when WiseFy has successfully retrieved a list of saved networks matching +the given search criteria.

+

See Also
+

WifiConfiguration

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy.callbacks/index.html b/javadoc/wisefy/com.isupatches.wisefy.callbacks/index.html index f267e14f..4d809543 100644 --- a/javadoc/wisefy/com.isupatches.wisefy.callbacks/index.html +++ b/javadoc/wisefy/com.isupatches.wisefy.callbacks/index.html @@ -122,15 +122,6 @@

Types

-

GetSavedNetworkCallbacks

- - -interface GetSavedNetworkCallbacks : BaseCallback -

Callbacks for retrieving a saved network on a device.

- - - -

GetSavedNetworksCallbacks

@@ -167,6 +158,24 @@

Types

+

SearchForSavedNetworkCallbacks

+ + +interface SearchForSavedNetworkCallbacks : BaseCallback +

Callbacks for retrieving a saved network on a device.

+ + + + +

SearchForSavedNetworksCallbacks

+ + +interface SearchForSavedNetworksCallbacks : BaseCallback +

Callbacks for retrieving a list of saved networks on a device.

+ + + +

SearchForSSIDCallbacks

diff --git a/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/get-nearby-access-points.html b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/get-nearby-access-points.html new file mode 100644 index 00000000..d364d5e8 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/get-nearby-access-points.html @@ -0,0 +1,48 @@ + + + +AccessPointApi.getNearbyAccessPoints - wisefy + + + +wisefy / com.isupatches.wisefy / AccessPointApi / getNearbyAccessPoints
+
+

getNearbyAccessPoints

+ +abstract fun getNearbyAccessPoints(filterDuplicates: Boolean): List<ScanResult>? +

To retrieve a list of nearby access points.

+

NOTE Setting filterDuplicates to true will exclude access points for an SSID that have a weaker RSSI +(will always take the highest signal strength).

+

Parameters

+

+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

+

See Also
+

WiseFy.getNearbyAccessPoints

+

ScanResult

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun getNearbyAccessPoints(filterDuplicates: Boolean, callbacks: GetNearbyAccessPointsCallbacks?): Unit +

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

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.getNearbyAccessPoints

+

GetNearbyAccessPointsCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/get-r-s-s-i.html b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/get-r-s-s-i.html new file mode 100644 index 00000000..0498b91f --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/get-r-s-s-i.html @@ -0,0 +1,53 @@ + + + +AccessPointApi.getRSSI - wisefy + + + +wisefy / com.isupatches.wisefy / AccessPointApi / getRSSI
+
+

getRSSI

+ +abstract fun getRSSI(regexForSSID: String?, takeHighest: Boolean, timeoutInMillis: Int): Int? +

To retrieve the RSSI of the first network matching a given regex.

+

NOTE Setting takeHighest to true will return the access point with the highest RSSI for the given SSID.

+

Parameters

+

+regexForSSID - The regex to be used to search for the ssid

+

+takeHighest - Whether to return the access point with the highest RSSI for the given SSID

+

+timeoutInMillis - The amount of time to search for a matching SSID

+

Return
+Integer - The RSSI value for the found SSID or null if no matching network found

+

See Also
+

WiseFy.getRSSI

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun getRSSI(regexForSSID: String?, takeHighest: Boolean, timeoutInMillis: Int, callbacks: GetRSSICallbacks?): Unit +

To retrieve the RSSI of the first network matching a given regex.

+

NOTE Setting takeHighest to true will return the access point with the highest RSSI for the given SSID.

+

Parameters

+

+regexForSSID - The regex to be used to search for the ssid

+

+takeHighest - Whether to return the access point with the highest RSSI for the given SSID

+

+timeoutInMillis - The amount of time to search for a matching SSID

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.getRSSI

+

GetRSSICallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/index.html new file mode 100644 index 00000000..91523374 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/index.html @@ -0,0 +1,98 @@ + + + +AccessPointApi - wisefy + + + +wisefy / com.isupatches.wisefy / AccessPointApi
+
+

AccessPointApi

+interface AccessPointApi +

An API for querying for nearby access points and related information.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

getNearbyAccessPoints

+
+abstract fun getNearbyAccessPoints(filterDuplicates: Boolean): List<ScanResult>?
+abstract fun getNearbyAccessPoints(filterDuplicates: Boolean, callbacks: GetNearbyAccessPointsCallbacks?): Unit +

To retrieve a list of nearby access points.

+
+

getRSSI

+
+abstract fun getRSSI(regexForSSID: String?, takeHighest: Boolean, timeoutInMillis: Int): Int?
+abstract fun getRSSI(regexForSSID: String?, takeHighest: Boolean, timeoutInMillis: Int, callbacks: GetRSSICallbacks?): Unit +

To retrieve the RSSI of the first network matching a given regex.

+
+

searchForAccessPoint

+
+abstract fun searchForAccessPoint(regexForSSID: String?, timeoutInMillis: Int, filterDuplicates: Boolean): ScanResult?
+abstract fun searchForAccessPoint(regexForSSID: String?, timeoutInMillis: Int, filterDuplicates: Boolean, callbacks: SearchForAccessPointCallbacks?): Unit +

To return the first access point that matches a given regex.

+
+

searchForAccessPoints

+
+abstract fun searchForAccessPoints(regexForSSID: String?, filterDuplicates: Boolean): List<ScanResult>?
+abstract fun searchForAccessPoints(regexForSSID: String?, filterDuplicates: Boolean, callbacks: SearchForAccessPointsCallbacks?): Unit +

To return nearby access points that match a given regex.

+
+

searchForSSID

+
+abstract fun searchForSSID(regexForSSID: String?, timeoutInMillis: Int): String?
+abstract fun searchForSSID(regexForSSID: String?, timeoutInMillis: Int, callbacks: SearchForSSIDCallbacks?): Unit +

To search local networks and return the first one that contains a given ssid.

+
+

searchForSSIDs

+
+abstract fun searchForSSIDs(regexForSSID: String?): List<String>?
+abstract fun searchForSSIDs(regexForSSID: String?, callbacks: SearchForSSIDsCallbacks?): Unit +

To search local networks and return the first one that contains a given ssid.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-access-point.html b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-access-point.html new file mode 100644 index 00000000..23d293ec --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-access-point.html @@ -0,0 +1,54 @@ + + + +AccessPointApi.searchForAccessPoint - wisefy + + + +wisefy / com.isupatches.wisefy / AccessPointApi / searchForAccessPoint
+
+

searchForAccessPoint

+ +abstract fun searchForAccessPoint(regexForSSID: String?, timeoutInMillis: Int, filterDuplicates: Boolean): ScanResult? +

To return the first access point that matches a given regex.

+

NOTE Setting filterDuplicates to true will not return an access point with a weaker signal strength (will always take the highest).

+

Parameters

+

+regexForSSID - The regex to use when iterating through nearby access points

+

+timeoutInMillis - The amount of time (in milliseconds) to wait for a matching access point

+

+filterDuplicates - If you want to exclude access points with the same name that have a weaker signal strength

+

Return
+ScanResult|null - The first access point or access point with the highest signal strength matching the regex

+

See Also
+

WiseFy.searchForAccessPoint

+

ScanResult

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun searchForAccessPoint(regexForSSID: String?, timeoutInMillis: Int, filterDuplicates: Boolean, callbacks: SearchForAccessPointCallbacks?): Unit +

To return the first access point that matches a given regex.

+

NOTE Setting filterDuplicates to true will not return an access point with a weaker signal strength (will always take the highest).

+

Parameters

+

+regexForSSID - The regex to use when iterating through nearby access points

+

+timeoutInMillis - The amount of time (in milliseconds) to wait for a matching access point

+

+filterDuplicates - If you want to exclude access points with the same name that have a weaker signal strength

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.searchForAccessPoint

+

SearchForAccessPointCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-access-points.html b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-access-points.html new file mode 100644 index 00000000..0d7d1a8c --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-access-points.html @@ -0,0 +1,50 @@ + + + +AccessPointApi.searchForAccessPoints - wisefy + + + +wisefy / com.isupatches.wisefy / AccessPointApi / searchForAccessPoints
+
+

searchForAccessPoints

+ +abstract fun searchForAccessPoints(regexForSSID: String?, filterDuplicates: Boolean): List<ScanResult>? +

To return nearby access points that match a given regex.

+

NOTE Setting filterDuplicates to true will not return access points with a weaker signal strength (will always take the highest).

+

Parameters

+

+regexForSSID - The regex to use when iterating through nearby access points

+

+filterDuplicates - If you want to exclude access points with the same name that have a weaker signal strength

+

Return
+List of ScanResult|null - The list of matching access points or null if none match the given regex

+

See Also
+

WiseFy.searchForAccessPoints

+

ScanResult

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun searchForAccessPoints(regexForSSID: String?, filterDuplicates: Boolean, callbacks: SearchForAccessPointsCallbacks?): Unit +

To return nearby access points that match a given regex.

+

NOTE Setting filterDuplicates to true will not return access points with a weaker signal strength (will always take the highest).

+

Parameters

+

+regexForSSID - The regex to use when iterating through nearby access points

+

+filterDuplicates - If you want to exclude access points with the same name that have a weaker signal strength

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.searchForAccessPoints

+

SearchForAccessPointsCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-s-s-i-d.html b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-s-s-i-d.html new file mode 100644 index 00000000..7336ca1c --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-s-s-i-d.html @@ -0,0 +1,47 @@ + + + +AccessPointApi.searchForSSID - wisefy + + + +wisefy / com.isupatches.wisefy / AccessPointApi / searchForSSID
+
+

searchForSSID

+ +abstract fun searchForSSID(regexForSSID: String?, timeoutInMillis: Int): String? +

To search local networks and return the first one that contains a given ssid.

+

Parameters

+

+regexForSSID - The regex to be used to search for the ssid

+

+timeoutInMillis - The number of milliseconds to keep searching for the SSID

+

Return
+String|null - The first SSID that contains the search ssid (if any, else null)

+

See Also
+

WiseFy.searchForSSID

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun searchForSSID(regexForSSID: String?, timeoutInMillis: Int, callbacks: SearchForSSIDCallbacks?): Unit +

To search local networks and return the first one that contains a given ssid.

+

Parameters

+

+regexForSSID - The regex to be used to search for the ssid

+

+timeoutInMillis - The number of milliseconds to keep searching for the SSID

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.searchForSSID

+

SearchForSSIDCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-s-s-i-ds.html b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-s-s-i-ds.html new file mode 100644 index 00000000..f09aec24 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-access-point-api/search-for-s-s-i-ds.html @@ -0,0 +1,43 @@ + + + +AccessPointApi.searchForSSIDs - wisefy + + + +wisefy / com.isupatches.wisefy / AccessPointApi / searchForSSIDs
+
+

searchForSSIDs

+ +abstract fun searchForSSIDs(regexForSSID: String?): List<String>? +

To search local networks and return the first one that contains a given ssid.

+

Parameters

+

+regexForSSID - The regex to be used to search for the ssid

+

Return
+String|null - The first SSID that contains the search ssid (if any, else null)

+

See Also
+

WiseFy.searchForSSIDs

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun searchForSSIDs(regexForSSID: String?, callbacks: SearchForSSIDsCallbacks?): Unit +

To search local networks and return the first one that contains a given ssid.

+

Parameters

+

+regexForSSID - The regex to be used to search for the ssid

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.searchForSSIDs

+

SearchForSSIDsCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/add-open-network.html b/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/add-open-network.html new file mode 100644 index 00000000..aec91a8d --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/add-open-network.html @@ -0,0 +1,43 @@ + + + +AddNetworkApi.addOpenNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / AddNetworkApi / addOpenNetwork
+
+

addOpenNetwork

+ +abstract fun addOpenNetwork(ssid: String?): Int +

To add an open network to the user's configured network list.

+

Parameters

+

+ssid - The ssid of the open network you want to add

+

Return
+int - The return code from WifiManager for network creation (-1 for failure)

+

See Also
+

WiseFy.addOpenNetwork

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun addOpenNetwork(ssid: String?, callbacks: AddNetworkCallbacks?): Unit +

To add an open network to the user's configured network list.

+

Parameters

+

+ssid - The ssid of the open network you want to add

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.addOpenNetwork

+

AddNetworkCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/add-w-e-p-network.html b/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/add-w-e-p-network.html new file mode 100644 index 00000000..be9ceed0 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/add-w-e-p-network.html @@ -0,0 +1,47 @@ + + + +AddNetworkApi.addWEPNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / AddNetworkApi / addWEPNetwork
+
+

addWEPNetwork

+ +abstract fun addWEPNetwork(ssid: String?, password: String?): Int +

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

+

Return
+int - The return code from WifiManager for network creation (-1 for failure)

+

See Also
+

WiseFy.addWEPNetwork

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun addWEPNetwork(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?): Unit +

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

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.addWEPNetwork

+

AddNetworkCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/add-w-p-a2-network.html b/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/add-w-p-a2-network.html new file mode 100644 index 00000000..4adac6c6 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/add-w-p-a2-network.html @@ -0,0 +1,47 @@ + + + +AddNetworkApi.addWPA2Network - wisefy + + + +wisefy / com.isupatches.wisefy / AddNetworkApi / addWPA2Network
+
+

addWPA2Network

+ +abstract fun addWPA2Network(ssid: String?, password: String?): Int +

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

+

Return
+int - The return code from WifiManager for network creation (-1 for failure)

+

See Also
+

WiseFy.addWPA2Network

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun addWPA2Network(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?): Unit +

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

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.addWPA2Network

+

AddNetworkCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/index.html new file mode 100644 index 00000000..9cba776b --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-add-network-api/index.html @@ -0,0 +1,68 @@ + + + +AddNetworkApi - wisefy + + + +wisefy / com.isupatches.wisefy / AddNetworkApi
+
+

AddNetworkApi

+interface AddNetworkApi +

An API for adding networks as saved configurations on a device.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + + + + + +
+

addOpenNetwork

+
+abstract fun addOpenNetwork(ssid: String?): Int
+abstract fun addOpenNetwork(ssid: String?, callbacks: AddNetworkCallbacks?): Unit +

To add an open network to the user's configured network list.

+
+

addWEPNetwork

+
+abstract fun addWEPNetwork(ssid: String?, password: String?): Int
+abstract fun addWEPNetwork(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?): Unit +

To add a WEP network to the user's configured network list.

+
+

addWPA2Network

+
+abstract fun addWPA2Network(ssid: String?, password: String?): Int
+abstract fun addWPA2Network(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?): Unit +

To add a WPA2 network to the user's configured network list.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-connection-api/connect-to-network.html b/javadoc/wisefy/com.isupatches.wisefy/-connection-api/connect-to-network.html new file mode 100644 index 00000000..2a63e9d7 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-connection-api/connect-to-network.html @@ -0,0 +1,47 @@ + + + +ConnectionApi.connectToNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / ConnectionApi / connectToNetwork
+
+

connectToNetwork

+ +abstract fun connectToNetwork(ssidToConnectTo: String?, timeoutInMillis: Int): Boolean +

Used to connect to a network.

+

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

+

Return
+boolean - If the network was successfully reconnected

+

See Also
+

WiseFy.connectToNetwork

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun connectToNetwork(ssidToConnectTo: String?, timeoutInMillis: Int, callbacks: ConnectToNetworkCallbacks?): Unit +

Used to connect to a network.

+

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

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.connectToNetwork

+

ConnectToNetworkCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-connection-api/disconnect-from-current-network.html b/javadoc/wisefy/com.isupatches.wisefy/-connection-api/disconnect-from-current-network.html new file mode 100644 index 00000000..823beafd --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-connection-api/disconnect-from-current-network.html @@ -0,0 +1,38 @@ + + + +ConnectionApi.disconnectFromCurrentNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / ConnectionApi / disconnectFromCurrentNetwork
+
+

disconnectFromCurrentNetwork

+ +abstract fun disconnectFromCurrentNetwork(): Boolean +

To disconnect the user from their current network.

+

Return
+boolean - If the command succeeded in disconnecting the device from the current network

+

See Also
+

WiseFy.disconnectFromCurrentNetwork

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun disconnectFromCurrentNetwork(callbacks: DisconnectFromCurrentNetworkCallbacks?): Unit +

To disconnect the user from their current network.

+

Parameters

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.disconnectFromCurrentNetwork

+

DisconnectFromCurrentNetworkCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-connection-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-connection-api/index.html new file mode 100644 index 00000000..2af1d1aa --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-connection-api/index.html @@ -0,0 +1,58 @@ + + + +ConnectionApi - wisefy + + + +wisefy / com.isupatches.wisefy / ConnectionApi
+
+

ConnectionApi

+interface ConnectionApi +

An API for managing the network connection of a device.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + +
+

connectToNetwork

+
+abstract fun connectToNetwork(ssidToConnectTo: String?, timeoutInMillis: Int): Boolean
+abstract fun connectToNetwork(ssidToConnectTo: String?, timeoutInMillis: Int, callbacks: ConnectToNetworkCallbacks?): Unit +

Used to connect to a network.

+
+

disconnectFromCurrentNetwork

+
+abstract fun disconnectFromCurrentNetwork(): Boolean
+abstract fun disconnectFromCurrentNetwork(callbacks: DisconnectFromCurrentNetworkCallbacks?): Unit +

To disconnect the user from their current network.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-device-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-device-api/index.html new file mode 100644 index 00000000..ae426d99 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-device-api/index.html @@ -0,0 +1,83 @@ + + + +DeviceApi - wisefy + + + +wisefy / com.isupatches.wisefy / DeviceApi
+
+

DeviceApi

+interface DeviceApi +

An API for querying about the different network statuses of a device.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + + + + + + + + + + + + + +
+

isDeviceConnectedToMobileNetwork

+
+abstract fun isDeviceConnectedToMobileNetwork(): Boolean +

To check if the device is connected to a mobile network.

+
+

isDeviceConnectedToMobileOrWifiNetwork

+
+abstract fun isDeviceConnectedToMobileOrWifiNetwork(): Boolean +

To check if the device is connected to a mobile or wifi network.

+
+

isDeviceConnectedToSSID

+
+abstract fun isDeviceConnectedToSSID(ssid: String?): Boolean +

To check if the device is connected to a given SSID.

+
+

isDeviceConnectedToWifiNetwork

+
+abstract fun isDeviceConnectedToWifiNetwork(): Boolean +

To check if the device is connected to a wifi network.

+
+

isDeviceRoaming

+
+abstract fun isDeviceRoaming(): Boolean +

To query if the device is roaming.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-mobile-network.html b/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-mobile-network.html new file mode 100644 index 00000000..3174ec95 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-mobile-network.html @@ -0,0 +1,24 @@ + + + +DeviceApi.isDeviceConnectedToMobileNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / DeviceApi / isDeviceConnectedToMobileNetwork
+
+

isDeviceConnectedToMobileNetwork

+ +abstract fun isDeviceConnectedToMobileNetwork(): Boolean +

To check if the device is connected to a mobile network.

+

Return
+bool - If the device is currently connected to a mobile network

+

See Also
+

WiseFy.isDeviceConnectedToMobileNetwork

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-mobile-or-wifi-network.html b/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-mobile-or-wifi-network.html new file mode 100644 index 00000000..5186abc3 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-mobile-or-wifi-network.html @@ -0,0 +1,24 @@ + + + +DeviceApi.isDeviceConnectedToMobileOrWifiNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / DeviceApi / isDeviceConnectedToMobileOrWifiNetwork
+
+

isDeviceConnectedToMobileOrWifiNetwork

+ +abstract fun isDeviceConnectedToMobileOrWifiNetwork(): Boolean +

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

+

See Also
+

WiseFy.isDeviceConnectedToMobileOrWifiNetwork

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-s-s-i-d.html b/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-s-s-i-d.html new file mode 100644 index 00000000..33081a96 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-s-s-i-d.html @@ -0,0 +1,27 @@ + + + +DeviceApi.isDeviceConnectedToSSID - wisefy + + + +wisefy / com.isupatches.wisefy / DeviceApi / isDeviceConnectedToSSID
+
+

isDeviceConnectedToSSID

+ +abstract fun isDeviceConnectedToSSID(ssid: String?): Boolean +

To check if the device is connected to a given SSID.

+

Parameters

+

+ssid - The SSID to check if the device is attached to

+

Return
+bool - If the device is currently attached to the given SSID

+

See Also
+

WiseFy.isDeviceConnectedToSSID

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-wifi-network.html b/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-wifi-network.html new file mode 100644 index 00000000..caa81456 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-connected-to-wifi-network.html @@ -0,0 +1,24 @@ + + + +DeviceApi.isDeviceConnectedToWifiNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / DeviceApi / isDeviceConnectedToWifiNetwork
+
+

isDeviceConnectedToWifiNetwork

+ +abstract fun isDeviceConnectedToWifiNetwork(): Boolean +

To check if the device is connected to a wifi network.

+

Return
+bool - If the device is currently connected to a wifi network

+

See Also
+

WiseFy.isDeviceConnectedToWifiNetwork

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-roaming.html b/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-roaming.html new file mode 100644 index 00000000..0d2ed99f --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-device-api/is-device-roaming.html @@ -0,0 +1,24 @@ + + + +DeviceApi.isDeviceRoaming - wisefy + + + +wisefy / com.isupatches.wisefy / DeviceApi / isDeviceRoaming
+
+

isDeviceRoaming

+ +abstract fun isDeviceRoaming(): Boolean +

To query if the device is roaming.

+

Return
+boolean - If the current network is roaming

+

See Also
+

WiseFy.isDeviceRoaming

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-frequency-api/get-frequency.html b/javadoc/wisefy/com.isupatches.wisefy/-frequency-api/get-frequency.html new file mode 100644 index 00000000..2d6b21e8 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-frequency-api/get-frequency.html @@ -0,0 +1,71 @@ + + + +FrequencyApi.getFrequency - wisefy + + + +wisefy / com.isupatches.wisefy / FrequencyApi / getFrequency
+
+

getFrequency

+ +abstract fun getFrequency(): Int? +

To retrieve the frequency of the device's current network.

+

Return
+Integer - The frequency of the devices current network or null if no network

+

See Also
+

WiseFy.getFrequency

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun getFrequency(callbacks: GetFrequencyCallbacks?): Unit +

To retrieve the frequency of the device's current network.

+

Parameters

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.getFrequency

+

GetFrequencyCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun getFrequency(network: WifiInfo?): Int? +

To retrieve the frequency of a network.

+

Parameters

+

+network - The network to return the frequency of

+

Return
+Integer - The frequency of the devices current network or null if no network

+

See Also
+

WiseFy.getFrequency

+

WifiInfo

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun getFrequency(network: WifiInfo?, callbacks: GetFrequencyCallbacks?): Unit +

To retrieve the frequency of a network.

+

Parameters

+

+network - The network to return the frequency of

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.getFrequency

+

GetFrequencyCallbacks

+

WifiInfo

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-frequency-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-frequency-api/index.html new file mode 100644 index 00000000..7c029ef1 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-frequency-api/index.html @@ -0,0 +1,62 @@ + + + +FrequencyApi - wisefy + + + +wisefy / com.isupatches.wisefy / FrequencyApi
+
+

FrequencyApi

+interface FrequencyApi +

An API for querying about a network's frequency.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + +
+

getFrequency

+
+abstract fun getFrequency(): Int?
+abstract fun getFrequency(callbacks: GetFrequencyCallbacks?): Unit +

To retrieve the frequency of the device's current network.

+abstract fun getFrequency(network: WifiInfo?): Int?
+abstract fun getFrequency(network: WifiInfo?, callbacks: GetFrequencyCallbacks?): Unit +

To retrieve the frequency of a network.

+
+

isNetwork5gHz

+
+abstract fun isNetwork5gHz(): Boolean +

To check if the device's current network is 5gHz.

+abstract fun isNetwork5gHz(network: WifiInfo?): Boolean +

To check if a given network is 5gHz.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-frequency-api/is-network5g-hz.html b/javadoc/wisefy/com.isupatches.wisefy/-frequency-api/is-network5g-hz.html new file mode 100644 index 00000000..7c9a4421 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-frequency-api/is-network5g-hz.html @@ -0,0 +1,41 @@ + + + +FrequencyApi.isNetwork5gHz - wisefy + + + +wisefy / com.isupatches.wisefy / FrequencyApi / isNetwork5gHz
+
+

isNetwork5gHz

+ +abstract fun isNetwork5gHz(): Boolean +

To check if the device's current network is 5gHz.

+

Return
+boolean - If the network is 5gHz

+

See Also
+

WiseFy.isNetwork5gHz

+

getFrequency

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun isNetwork5gHz(network: WifiInfo?): Boolean +

To check if a given network is 5gHz.

+

Parameters

+

+network - The network to check if it's 5gHz

+

Return
+boolean - If the network is 5gHz

+

See Also
+

WiseFy.isNetwork5gHz

+

WifiInfo

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/get-current-network-info.html b/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/get-current-network-info.html new file mode 100644 index 00000000..10f7ca13 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/get-current-network-info.html @@ -0,0 +1,39 @@ + + + +NetworkInfoApi.getCurrentNetworkInfo - wisefy + + + +wisefy / com.isupatches.wisefy / NetworkInfoApi / getCurrentNetworkInfo
+
+

getCurrentNetworkInfo

+ +abstract fun getCurrentNetworkInfo(): NetworkInfo? +

To retrieve the details of the phones active network.

+

Return
+NetworkInfo

+

See Also
+

WiseFy.getCurrentNetworkInfo

+

NetworkInfo

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun getCurrentNetworkInfo(callbacks: GetCurrentNetworkInfoCallbacks?): Unit +

To retrieve the details of the phones active network.

+

Parameters

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.getCurrentNetworkInfo

+

GetCurrentNetworkInfoCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/get-current-network.html b/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/get-current-network.html new file mode 100644 index 00000000..6182617f --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/get-current-network.html @@ -0,0 +1,39 @@ + + + +NetworkInfoApi.getCurrentNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / NetworkInfoApi / getCurrentNetwork
+
+

getCurrentNetwork

+ +abstract fun getCurrentNetwork(): WifiInfo? +

To retrieve the user's current network.

+

Return
+WifiInfo|null - The user's current network information

+

See Also
+

WiseFy.getCurrentNetwork

+

WifiInfo

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun getCurrentNetwork(callbacks: GetCurrentNetworkCallbacks?): Unit +

To retrieve the user's current network.

+

Parameters

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.getCurrentNetwork

+

GetCurrentNetworkCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/get-i-p.html b/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/get-i-p.html new file mode 100644 index 00000000..e34b0d2e --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/get-i-p.html @@ -0,0 +1,38 @@ + + + +NetworkInfoApi.getIP - wisefy + + + +wisefy / com.isupatches.wisefy / NetworkInfoApi / getIP
+
+

getIP

+ +abstract fun getIP(): String? +

To retrieve the IPv4 or IPv6 of a device.

+

Return
+String - The IPv4 or IPv6 address

+

See Also
+

WiseFy.getIP

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun getIP(callbacks: GetIPCallbacks?): Unit +

To retrieve the IPv4 or IPv6 of a device.

+

Parameters

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.getIP

+

GetIPCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/index.html new file mode 100644 index 00000000..50bd0a1e --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-network-info-api/index.html @@ -0,0 +1,68 @@ + + + +NetworkInfoApi - wisefy + + + +wisefy / com.isupatches.wisefy / NetworkInfoApi
+
+

NetworkInfoApi

+interface NetworkInfoApi +

An API for querying about a device's current network information.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + + + + + +
+

getCurrentNetwork

+
+abstract fun getCurrentNetwork(): WifiInfo?
+abstract fun getCurrentNetwork(callbacks: GetCurrentNetworkCallbacks?): Unit +

To retrieve the user's current network.

+
+

getCurrentNetworkInfo

+
+abstract fun getCurrentNetworkInfo(): NetworkInfo?
+abstract fun getCurrentNetworkInfo(callbacks: GetCurrentNetworkInfoCallbacks?): Unit +

To retrieve the details of the phones active network.

+
+

getIP

+
+abstract fun getIP(): String?
+abstract fun getIP(callbacks: GetIPCallbacks?): Unit +

To retrieve the IPv4 or IPv6 of a device.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-remove-network-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-remove-network-api/index.html new file mode 100644 index 00000000..8f4d5e39 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-remove-network-api/index.html @@ -0,0 +1,48 @@ + + + +RemoveNetworkApi - wisefy + + + +wisefy / com.isupatches.wisefy / RemoveNetworkApi
+
+

RemoveNetworkApi

+interface RemoveNetworkApi +

An API for removing a network as a saved configuration.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + +
+

removeNetwork

+
+abstract fun removeNetwork(ssidToRemove: String?): Boolean
+abstract fun removeNetwork(ssidToRemove: String?, callbacks: RemoveNetworkCallbacks?): Unit +

To remove a configured network.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-remove-network-api/remove-network.html b/javadoc/wisefy/com.isupatches.wisefy/-remove-network-api/remove-network.html new file mode 100644 index 00000000..4b5be774 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-remove-network-api/remove-network.html @@ -0,0 +1,43 @@ + + + +RemoveNetworkApi.removeNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / RemoveNetworkApi / removeNetwork
+
+

removeNetwork

+ +abstract fun removeNetwork(ssidToRemove: String?): Boolean +

To remove a configured network.

+

Parameters

+

+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

+

See Also
+

WiseFy.removeNetwork

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun removeNetwork(ssidToRemove: String?, callbacks: RemoveNetworkCallbacks?): Unit +

To remove a configured network.

+

Parameters

+

+ssidToRemove - The ssid of the network you want to remove from the configured network list

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.removeNetwork

+

RemoveNetworkCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/get-saved-networks.html b/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/get-saved-networks.html new file mode 100644 index 00000000..73b05ccc --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/get-saved-networks.html @@ -0,0 +1,39 @@ + + + +SavedNetworkApi.getSavedNetworks - wisefy + + + +wisefy / com.isupatches.wisefy / SavedNetworkApi / getSavedNetworks
+
+

getSavedNetworks

+ +abstract fun getSavedNetworks(): List<WifiConfiguration>? +

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

+

See Also
+

WiseFy.getSavedNetworks

+

WifiConfiguration

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun getSavedNetworks(callbacks: GetSavedNetworksCallbacks?): Unit +

To retrieve a list of saved networks on a user's device.

+

Parameters

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.getSavedNetworks

+

GetSavedNetworksCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/index.html new file mode 100644 index 00000000..6a544b07 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/index.html @@ -0,0 +1,77 @@ + + + +SavedNetworkApi - wisefy + + + +wisefy / com.isupatches.wisefy / SavedNetworkApi
+
+

SavedNetworkApi

+interface SavedNetworkApi +

An API for querying saved network information on a device.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + + + + + + + + + +
+

getSavedNetworks

+
+abstract fun getSavedNetworks(): List<WifiConfiguration>?
+abstract fun getSavedNetworks(callbacks: GetSavedNetworksCallbacks?): Unit +

To retrieve a list of saved networks on a user's device.

+
+

isNetworkSaved

+
+abstract fun isNetworkSaved(ssid: String?): Boolean +

To check if an SSID is in the list of configured networks.

+
+

searchForSavedNetwork

+
+abstract fun searchForSavedNetwork(regexForSSID: String?): WifiConfiguration?
+abstract fun searchForSavedNetwork(regexForSSID: String?, callbacks: SearchForSavedNetworkCallbacks?): Unit +

To search for and return a saved WiFiConfiguration given an SSID.

+
+

searchForSavedNetworks

+
+abstract fun searchForSavedNetworks(regexForSSID: String?): List<WifiConfiguration>?
+abstract fun searchForSavedNetworks(regexForSSID: String?, callbacks: SearchForSavedNetworksCallbacks?): Unit +

To retrieve a list of saved networks on a user's device that match a given regex.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/is-network-saved.html b/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/is-network-saved.html new file mode 100644 index 00000000..0a5a9b06 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/is-network-saved.html @@ -0,0 +1,27 @@ + + + +SavedNetworkApi.isNetworkSaved - wisefy + + + +wisefy / com.isupatches.wisefy / SavedNetworkApi / isNetworkSaved
+
+

isNetworkSaved

+ +abstract fun isNetworkSaved(ssid: String?): Boolean +

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

+

Return
+boolean - If the SSID is in the list of configured networks

+

See Also
+

WiseFy.isNetworkSaved

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/search-for-saved-network.html b/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/search-for-saved-network.html new file mode 100644 index 00000000..00eb4523 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/search-for-saved-network.html @@ -0,0 +1,44 @@ + + + +SavedNetworkApi.searchForSavedNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / SavedNetworkApi / searchForSavedNetwork
+
+

searchForSavedNetwork

+ +abstract fun searchForSavedNetwork(regexForSSID: String?): WifiConfiguration? +

To search for and return a saved WiFiConfiguration given an SSID.

+

Parameters

+

+regexForSSID - The ssid to use while searching for saved configuration

+

Return
+WifiConfiguration|null - Saved network that matches the ssid

+

See Also
+

WiseFy.searchForSavedNetwork

+

WifiConfiguration

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun searchForSavedNetwork(regexForSSID: String?, callbacks: SearchForSavedNetworkCallbacks?): Unit +

To search for and return a saved WiFiConfiguration given an SSID.

+

Parameters

+

+regexForSSID - The ssid to use while searching for saved configuration

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.searchForSavedNetwork

+

SearchForSavedNetworkCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/search-for-saved-networks.html b/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/search-for-saved-networks.html new file mode 100644 index 00000000..74d718b1 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-saved-network-api/search-for-saved-networks.html @@ -0,0 +1,44 @@ + + + +SavedNetworkApi.searchForSavedNetworks - wisefy + + + +wisefy / com.isupatches.wisefy / SavedNetworkApi / searchForSavedNetworks
+
+

searchForSavedNetworks

+ +abstract fun searchForSavedNetworks(regexForSSID: String?): List<WifiConfiguration>? +

To retrieve a list of saved networks on a user's device that match a given regex.

+

Parameters

+

+regexForSSID - The ssid to use while searching for saved configurations

+

Return
+List of WifiConfigurations|null - The list of saved network configurations that match the given regex

+

See Also
+

WiseFy.searchForSavedNetworks

+

WifiConfiguration

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun searchForSavedNetworks(regexForSSID: String?, callbacks: SearchForSavedNetworksCallbacks?): Unit +

To retrieve a list of saved networks on a user's device that match a given regex.

+

Parameters

+

+regexForSSID - The ssid to use while searching for saved configurations

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.searchForSavedNetworks

+

SearchForSavedNetworksCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-security-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-security-api/index.html new file mode 100644 index 00000000..7c0688e2 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-security-api/index.html @@ -0,0 +1,92 @@ + + + +SecurityApi - wisefy + + + +wisefy / com.isupatches.wisefy / SecurityApi
+
+

SecurityApi

+interface SecurityApi +

An API for querying about a network's security details.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

isNetworkEAP

+
+abstract fun isNetworkEAP(scanResult: ScanResult?): Boolean +

To check and return if a network is a EAP network.

+
+

isNetworkPSK

+
+abstract fun isNetworkPSK(scanResult: ScanResult?): Boolean +

To check and return if a network is a PSK network.

+
+

isNetworkSecure

+
+abstract fun isNetworkSecure(scanResult: ScanResult?): Boolean +

To check and return if a network is secure (contains EAP/PSK/WEP/WPA/WPA2 capabilities).

+
+

isNetworkWEP

+
+abstract fun isNetworkWEP(scanResult: ScanResult?): Boolean +

To check and return if a network is a WEP network.

+
+

isNetworkWPA

+
+abstract fun isNetworkWPA(scanResult: ScanResult?): Boolean +

To check and return if a network is a WPA network.

+
+

isNetworkWPA2

+
+abstract fun isNetworkWPA2(scanResult: ScanResult?): Boolean +

To check and return if a network is a WPA2 network.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-e-a-p.html b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-e-a-p.html new file mode 100644 index 00000000..5fed5e0a --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-e-a-p.html @@ -0,0 +1,28 @@ + + + +SecurityApi.isNetworkEAP - wisefy + + + +wisefy / com.isupatches.wisefy / SecurityApi / isNetworkEAP
+
+

isNetworkEAP

+ +abstract fun isNetworkEAP(scanResult: ScanResult?): Boolean +

To check and return if a network is a EAP network.

+

Parameters

+

+scanResult - The network to check

+

Return
+boolean - Whether the network has EAP capabilities listed

+

See Also
+

WiseFy.isNetworkEAP

+

ScanResult

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-p-s-k.html b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-p-s-k.html new file mode 100644 index 00000000..ef265901 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-p-s-k.html @@ -0,0 +1,28 @@ + + + +SecurityApi.isNetworkPSK - wisefy + + + +wisefy / com.isupatches.wisefy / SecurityApi / isNetworkPSK
+
+

isNetworkPSK

+ +abstract fun isNetworkPSK(scanResult: ScanResult?): Boolean +

To check and return if a network is a PSK network.

+

Parameters

+

+scanResult - The network to check

+

Return
+boolean - Whether the network has PSK capabilities listed

+

See Also
+

WiseFy.isNetworkPSK

+

ScanResult

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-secure.html b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-secure.html new file mode 100644 index 00000000..3ff94d93 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-secure.html @@ -0,0 +1,28 @@ + + + +SecurityApi.isNetworkSecure - wisefy + + + +wisefy / com.isupatches.wisefy / SecurityApi / isNetworkSecure
+
+

isNetworkSecure

+ +abstract fun isNetworkSecure(scanResult: ScanResult?): Boolean +

To check and return if a network is secure (contains EAP/PSK/WEP/WPA/WPA2 capabilities).

+

Parameters

+

+scanResult - The network to see if it is secure

+

Return
+boolean - Whether the network is secure

+

See Also
+

WiseFy.isNetworkSecure

+

ScanResult

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-w-e-p.html b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-w-e-p.html new file mode 100644 index 00000000..abb76c0e --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-w-e-p.html @@ -0,0 +1,28 @@ + + + +SecurityApi.isNetworkWEP - wisefy + + + +wisefy / com.isupatches.wisefy / SecurityApi / isNetworkWEP
+
+

isNetworkWEP

+ +abstract fun isNetworkWEP(scanResult: ScanResult?): Boolean +

To check and return if a network is a WEP network.

+

Parameters

+

+scanResult - The network to check

+

Return
+boolean - Whether the network has WEP capabilities listed

+

See Also
+

WiseFy.isNetworkWEP

+

ScanResult

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-w-p-a.html b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-w-p-a.html new file mode 100644 index 00000000..eaa1de28 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-w-p-a.html @@ -0,0 +1,28 @@ + + + +SecurityApi.isNetworkWPA - wisefy + + + +wisefy / com.isupatches.wisefy / SecurityApi / isNetworkWPA
+
+

isNetworkWPA

+ +abstract fun isNetworkWPA(scanResult: ScanResult?): Boolean +

To check and return if a network is a WPA network.

+

Parameters

+

+scanResult - The network to check

+

Return
+boolean - Whether the network has WPA capabilities listed

+

See Also
+

WiseFy.isNetworkWPA

+

ScanResult

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-w-p-a2.html b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-w-p-a2.html new file mode 100644 index 00000000..a6f4f592 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-security-api/is-network-w-p-a2.html @@ -0,0 +1,28 @@ + + + +SecurityApi.isNetworkWPA2 - wisefy + + + +wisefy / com.isupatches.wisefy / SecurityApi / isNetworkWPA2
+
+

isNetworkWPA2

+ +abstract fun isNetworkWPA2(scanResult: ScanResult?): Boolean +

To check and return if a network is a WPA2 network.

+

Parameters

+

+scanResult - The network to check

+

Return
+boolean - Whether the network has WPA2 capabilities listed

+

See Also
+

WiseFy.isNetworkWPA2

+

ScanResult

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-signal-strength-api/calculate-bars.html b/javadoc/wisefy/com.isupatches.wisefy/-signal-strength-api/calculate-bars.html new file mode 100644 index 00000000..2cbc75a1 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-signal-strength-api/calculate-bars.html @@ -0,0 +1,29 @@ + + + +SignalStrengthApi.calculateBars - wisefy + + + +wisefy / com.isupatches.wisefy / SignalStrengthApi / calculateBars
+
+

calculateBars

+ +abstract fun calculateBars(rssiLevel: Int, targetNumberOfBars: Int): Int +

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

+

Return
+int - The number of bars for the given RSSI value

+

See Also
+

WiseFy.calculateBars

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-signal-strength-api/compare-signal-level.html b/javadoc/wisefy/com.isupatches.wisefy/-signal-strength-api/compare-signal-level.html new file mode 100644 index 00000000..299a1dfb --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-signal-strength-api/compare-signal-level.html @@ -0,0 +1,34 @@ + + + +SignalStrengthApi.compareSignalLevel - wisefy + + + +wisefy / com.isupatches.wisefy / SignalStrengthApi / compareSignalLevel
+
+

compareSignalLevel

+ +abstract fun compareSignalLevel(rssi1: Int, rssi2: Int): Int +

To compare the signal strength of two networks.

+

This method will return:

+
  • Negative value if the first signal is weaker than the second signal
  • +
  • 0 if the two signals have the same strength
  • +
  • Positive value if the first signal is stronger than the second signal
  • +
+

Parameters

+

+rssi1 - The signal strength of network 1

+

+rssi2 - The signal strength of network 2

+

Return
+int - The result of the comparison

+

See Also
+

WiseFy.compareSignalLevel

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-signal-strength-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-signal-strength-api/index.html new file mode 100644 index 00000000..c464426d --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-signal-strength-api/index.html @@ -0,0 +1,56 @@ + + + +SignalStrengthApi - wisefy + + + +wisefy / com.isupatches.wisefy / SignalStrengthApi
+
+

SignalStrengthApi

+interface SignalStrengthApi +

An API for functionality relating to signal strength.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + +
+

calculateBars

+
+abstract fun calculateBars(rssiLevel: Int, targetNumberOfBars: Int): Int +

To convert an RSSI level for a network to a number of bars.

+
+

compareSignalLevel

+
+abstract fun compareSignalLevel(rssi1: Int, rssi2: Int): Int +

To compare the signal strength of two networks.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/disable-wifi.html b/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/disable-wifi.html new file mode 100644 index 00000000..cd4adca1 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/disable-wifi.html @@ -0,0 +1,35 @@ + + + +WifiApi.disableWifi - wisefy + + + +wisefy / com.isupatches.wisefy / WifiApi / disableWifi
+
+

disableWifi

+ +abstract fun disableWifi(): Boolean +

To disable Wifi on a user's device.

+

Return
+boolean - True if the command succeeded in disabling wifi

+

See Also
+

WiseFy.disableWifi

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun disableWifi(callbacks: DisableWifiCallbacks?): Unit +

To disable Wifi on a user's device.

+

See Also
+

WiseFy.disableWifi

+

DisableWifiCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/enable-wifi.html b/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/enable-wifi.html new file mode 100644 index 00000000..7ccca1af --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/enable-wifi.html @@ -0,0 +1,38 @@ + + + +WifiApi.enableWifi - wisefy + + + +wisefy / com.isupatches.wisefy / WifiApi / enableWifi
+
+

enableWifi

+ +abstract fun enableWifi(): Boolean +

To enable Wifi on a user's device.

+

Return
+boolean - If the command succeeded in enabling wifi

+

See Also
+

WiseFy.enableWifi

+

+

Author
+Patches

+

Since
+3.0

+ +abstract fun enableWifi(callbacks: EnableWifiCallbacks?): Unit +

To enable Wifi on a user's device.

+

Parameters

+

+callbacks - The listener to return results to

+

See Also
+

WiseFy.enableWifi

+

EnableWifiCallbacks

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/index.html new file mode 100644 index 00000000..aff58b16 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/index.html @@ -0,0 +1,67 @@ + + + +WifiApi - wisefy + + + +wisefy / com.isupatches.wisefy / WifiApi
+
+

WifiApi

+interface WifiApi +

An API for functionality relating to Wifi.

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + + + + + +
+

disableWifi

+
+abstract fun disableWifi(): Boolean
+abstract fun disableWifi(callbacks: DisableWifiCallbacks?): Unit +

To disable Wifi on a user's device.

+
+

enableWifi

+
+abstract fun enableWifi(): Boolean
+abstract fun enableWifi(callbacks: EnableWifiCallbacks?): Unit +

To enable Wifi on a user's device.

+
+

isWifiEnabled

+
+abstract fun isWifiEnabled(): Boolean +

To check if Wifi is enabled on the device or not.

+
+

Inheritors

+ + + + + + + +
+

WiseFyPublicApi

+
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/is-wifi-enabled.html b/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/is-wifi-enabled.html new file mode 100644 index 00000000..f6445335 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-wifi-api/is-wifi-enabled.html @@ -0,0 +1,24 @@ + + + +WifiApi.isWifiEnabled - wisefy + + + +wisefy / com.isupatches.wisefy / WifiApi / isWifiEnabled
+
+

isWifiEnabled

+ +abstract fun isWifiEnabled(): Boolean +

To check if Wifi is enabled on the device or not.

+

Return
+boolean - if Wifi is enabled on device

+

See Also
+

WiseFy.isWifiEnabled

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/dump.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/dump.html new file mode 100644 index 00000000..0de1ca6e --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/dump.html @@ -0,0 +1,22 @@ + + + +WiseFyPublicApi.dump - wisefy + + + +wisefy / com.isupatches.wisefy / WiseFyPublicApi / dump
+
+

dump

+ +abstract fun dump(): Unit +

Used to cleanup the thread started by WiseFy.

+

See Also
+

WiseFy.dump

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/get-wise-fy-lock.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/get-wise-fy-lock.html new file mode 100644 index 00000000..3ddcf9f1 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/get-wise-fy-lock.html @@ -0,0 +1,25 @@ + + + +WiseFyPublicApi.getWiseFyLock - wisefy + + + +wisefy / com.isupatches.wisefy / WiseFyPublicApi / getWiseFyLock
+
+

getWiseFyLock

+ +abstract fun getWiseFyLock(): WiseFyLock +

To retrieve the lock in use by WiseFy for synchronization.

+

Return
+WiseFyLock - The instance of the lock in-use by WiseFy

+

See Also
+

WiseFy.getWiseFyLock

+

WiseFyLock

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/index.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/index.html new file mode 100644 index 00000000..8d3859a7 --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/index.html @@ -0,0 +1,443 @@ + + + +WiseFyPublicApi - wisefy + + + +wisefy / com.isupatches.wisefy / WiseFyPublicApi
+
+

WiseFyPublicApi

+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

+

See Also
+

AccessPointApi

+

AddNetworkApi

+

ConnectionApi

+

DeviceApi

+

FrequencyApi

+

NetworkInfoApi

+

RemoveNetworkApi

+

SavedNetworkApi

+

SecurityApi

+

SignalStrengthApi

+

WiseFy

+

+

Author
+Patches

+

Since
+3.0

+

Functions

+ + + + + + + + + + + + + + + +
+

dump

+
+abstract fun dump(): Unit +

Used to cleanup the thread started by WiseFy.

+
+

getWiseFyLock

+
+abstract fun getWiseFyLock(): WiseFyLock +

To retrieve the lock in use by WiseFy for synchronization.

+
+

isLoggingEnabled

+
+abstract fun isLoggingEnabled(): Boolean +

To query if logging is enabled or disabled for a WiseFy instance.

+
+

Inherited Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

addOpenNetwork

+
+abstract fun addOpenNetwork(ssid: String?): Int
+abstract fun addOpenNetwork(ssid: String?, callbacks: AddNetworkCallbacks?): Unit +

To add an open network to the user's configured network list.

+
+

addWEPNetwork

+
+abstract fun addWEPNetwork(ssid: String?, password: String?): Int
+abstract fun addWEPNetwork(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?): Unit +

To add a WEP network to the user's configured network list.

+
+

addWPA2Network

+
+abstract fun addWPA2Network(ssid: String?, password: String?): Int
+abstract fun addWPA2Network(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?): Unit +

To add a WPA2 network to the user's configured network list.

+
+

calculateBars

+
+abstract fun calculateBars(rssiLevel: Int, targetNumberOfBars: Int): Int +

To convert an RSSI level for a network to a number of bars.

+
+

compareSignalLevel

+
+abstract fun compareSignalLevel(rssi1: Int, rssi2: Int): Int +

To compare the signal strength of two networks.

+
+

connectToNetwork

+
+abstract fun connectToNetwork(ssidToConnectTo: String?, timeoutInMillis: Int): Boolean
+abstract fun connectToNetwork(ssidToConnectTo: String?, timeoutInMillis: Int, callbacks: ConnectToNetworkCallbacks?): Unit +

Used to connect to a network.

+
+

disableWifi

+
+abstract fun disableWifi(): Boolean
+abstract fun disableWifi(callbacks: DisableWifiCallbacks?): Unit +

To disable Wifi on a user's device.

+
+

disconnectFromCurrentNetwork

+
+abstract fun disconnectFromCurrentNetwork(): Boolean
+abstract fun disconnectFromCurrentNetwork(callbacks: DisconnectFromCurrentNetworkCallbacks?): Unit +

To disconnect the user from their current network.

+
+

enableWifi

+
+abstract fun enableWifi(): Boolean
+abstract fun enableWifi(callbacks: EnableWifiCallbacks?): Unit +

To enable Wifi on a user's device.

+
+

getCurrentNetwork

+
+abstract fun getCurrentNetwork(): WifiInfo?
+abstract fun getCurrentNetwork(callbacks: GetCurrentNetworkCallbacks?): Unit +

To retrieve the user's current network.

+
+

getCurrentNetworkInfo

+
+abstract fun getCurrentNetworkInfo(): NetworkInfo?
+abstract fun getCurrentNetworkInfo(callbacks: GetCurrentNetworkInfoCallbacks?): Unit +

To retrieve the details of the phones active network.

+
+

getFrequency

+
+abstract fun getFrequency(): Int?
+abstract fun getFrequency(callbacks: GetFrequencyCallbacks?): Unit +

To retrieve the frequency of the device's current network.

+abstract fun getFrequency(network: WifiInfo?): Int?
+abstract fun getFrequency(network: WifiInfo?, callbacks: GetFrequencyCallbacks?): Unit +

To retrieve the frequency of a network.

+
+

getIP

+
+abstract fun getIP(): String?
+abstract fun getIP(callbacks: GetIPCallbacks?): Unit +

To retrieve the IPv4 or IPv6 of a device.

+
+

getNearbyAccessPoints

+
+abstract fun getNearbyAccessPoints(filterDuplicates: Boolean): List<ScanResult>?
+abstract fun getNearbyAccessPoints(filterDuplicates: Boolean, callbacks: GetNearbyAccessPointsCallbacks?): Unit +

To retrieve a list of nearby access points.

+
+

getRSSI

+
+abstract fun getRSSI(regexForSSID: String?, takeHighest: Boolean, timeoutInMillis: Int): Int?
+abstract fun getRSSI(regexForSSID: String?, takeHighest: Boolean, timeoutInMillis: Int, callbacks: GetRSSICallbacks?): Unit +

To retrieve the RSSI of the first network matching a given regex.

+
+

getSavedNetworks

+
+abstract fun getSavedNetworks(): List<WifiConfiguration>?
+abstract fun getSavedNetworks(callbacks: GetSavedNetworksCallbacks?): Unit +

To retrieve a list of saved networks on a user's device.

+
+

isDeviceConnectedToMobileNetwork

+
+abstract fun isDeviceConnectedToMobileNetwork(): Boolean +

To check if the device is connected to a mobile network.

+
+

isDeviceConnectedToMobileOrWifiNetwork

+
+abstract fun isDeviceConnectedToMobileOrWifiNetwork(): Boolean +

To check if the device is connected to a mobile or wifi network.

+
+

isDeviceConnectedToSSID

+
+abstract fun isDeviceConnectedToSSID(ssid: String?): Boolean +

To check if the device is connected to a given SSID.

+
+

isDeviceConnectedToWifiNetwork

+
+abstract fun isDeviceConnectedToWifiNetwork(): Boolean +

To check if the device is connected to a wifi network.

+
+

isDeviceRoaming

+
+abstract fun isDeviceRoaming(): Boolean +

To query if the device is roaming.

+
+

isNetwork5gHz

+
+abstract fun isNetwork5gHz(): Boolean +

To check if the device's current network is 5gHz.

+abstract fun isNetwork5gHz(network: WifiInfo?): Boolean +

To check if a given network is 5gHz.

+
+

isNetworkEAP

+
+abstract fun isNetworkEAP(scanResult: ScanResult?): Boolean +

To check and return if a network is a EAP network.

+
+

isNetworkPSK

+
+abstract fun isNetworkPSK(scanResult: ScanResult?): Boolean +

To check and return if a network is a PSK network.

+
+

isNetworkSaved

+
+abstract fun isNetworkSaved(ssid: String?): Boolean +

To check if an SSID is in the list of configured networks.

+
+

isNetworkSecure

+
+abstract fun isNetworkSecure(scanResult: ScanResult?): Boolean +

To check and return if a network is secure (contains EAP/PSK/WEP/WPA/WPA2 capabilities).

+
+

isNetworkWEP

+
+abstract fun isNetworkWEP(scanResult: ScanResult?): Boolean +

To check and return if a network is a WEP network.

+
+

isNetworkWPA

+
+abstract fun isNetworkWPA(scanResult: ScanResult?): Boolean +

To check and return if a network is a WPA network.

+
+

isNetworkWPA2

+
+abstract fun isNetworkWPA2(scanResult: ScanResult?): Boolean +

To check and return if a network is a WPA2 network.

+
+

isWifiEnabled

+
+abstract fun isWifiEnabled(): Boolean +

To check if Wifi is enabled on the device or not.

+
+

removeNetwork

+
+abstract fun removeNetwork(ssidToRemove: String?): Boolean
+abstract fun removeNetwork(ssidToRemove: String?, callbacks: RemoveNetworkCallbacks?): Unit +

To remove a configured network.

+
+

searchForAccessPoint

+
+abstract fun searchForAccessPoint(regexForSSID: String?, timeoutInMillis: Int, filterDuplicates: Boolean): ScanResult?
+abstract fun searchForAccessPoint(regexForSSID: String?, timeoutInMillis: Int, filterDuplicates: Boolean, callbacks: SearchForAccessPointCallbacks?): Unit +

To return the first access point that matches a given regex.

+
+

searchForAccessPoints

+
+abstract fun searchForAccessPoints(regexForSSID: String?, filterDuplicates: Boolean): List<ScanResult>?
+abstract fun searchForAccessPoints(regexForSSID: String?, filterDuplicates: Boolean, callbacks: SearchForAccessPointsCallbacks?): Unit +

To return nearby access points that match a given regex.

+
+

searchForSavedNetwork

+
+abstract fun searchForSavedNetwork(regexForSSID: String?): WifiConfiguration?
+abstract fun searchForSavedNetwork(regexForSSID: String?, callbacks: SearchForSavedNetworkCallbacks?): Unit +

To search for and return a saved WiFiConfiguration given an SSID.

+
+

searchForSavedNetworks

+
+abstract fun searchForSavedNetworks(regexForSSID: String?): List<WifiConfiguration>?
+abstract fun searchForSavedNetworks(regexForSSID: String?, callbacks: SearchForSavedNetworksCallbacks?): Unit +

To retrieve a list of saved networks on a user's device that match a given regex.

+
+

searchForSSID

+
+abstract fun searchForSSID(regexForSSID: String?, timeoutInMillis: Int): String?
+abstract fun searchForSSID(regexForSSID: String?, timeoutInMillis: Int, callbacks: SearchForSSIDCallbacks?): Unit +

To search local networks and return the first one that contains a given ssid.

+
+

searchForSSIDs

+
+abstract fun searchForSSIDs(regexForSSID: String?): List<String>?
+abstract fun searchForSSIDs(regexForSSID: String?, callbacks: SearchForSSIDsCallbacks?): Unit +

To search local networks and return the first one that contains a given ssid.

+
+

Inheritors

+ + + + + + + +
+

WiseFy

+
+class WiseFy : WiseFyPublicApi +

Main class for WiseFy that provides a synchronous and asynchronous API to manipulate and query +for different parts of a device's wifi configuration and status.

+
+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/is-logging-enabled.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/is-logging-enabled.html new file mode 100644 index 00000000..3d6926cf --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy-public-api/is-logging-enabled.html @@ -0,0 +1,24 @@ + + + +WiseFyPublicApi.isLoggingEnabled - wisefy + + + +wisefy / com.isupatches.wisefy / WiseFyPublicApi / isLoggingEnabled
+
+

isLoggingEnabled

+ +abstract fun isLoggingEnabled(): Boolean +

To query if logging is enabled or disabled for a WiseFy instance.

+

Return
+boolean - If logging is enabled for the WiseFy instance

+

See Also
+

WiseFy.isLoggingEnabled

+

+

Author
+Patches

+

Since
+3.0

+ + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-open-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-open-network.html index 272ccd06..eaaa7108 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-open-network.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-open-network.html @@ -10,6 +10,7 @@

addOpenNetwork

@Sync @CallingThread fun addOpenNetwork(ssid: String?): Int +

Overrides AddNetworkApi.addOpenNetwork

To add an open network to the user's configured network list.

Parameters

@@ -27,6 +28,7 @@

Parameters

3.0

@Async @WiseFyThread fun addOpenNetwork(ssid: String?, callbacks: AddNetworkCallbacks?): Unit +

Overrides AddNetworkApi.addOpenNetwork

To add an open network to the user's configured network list.

Parameters

diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-w-e-p-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-w-e-p-network.html index 6c187aa4..659cb8e5 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-w-e-p-network.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-w-e-p-network.html @@ -9,7 +9,9 @@

addWEPNetwork

-@Sync @CallingThread fun addWEPNetwork(ssid: String?, password: String?): Int
+@Sync @CallingThread fun addWEPNetwork(ssid: String?, password: String?): Int +

Overrides AddNetworkApi.addWEPNetwork

+
Deprecated: Due to security and performance limitations, WEP networks are discouraged

To add a WEP network to the user's configured network list.

@@ -30,7 +32,9 @@

Parameters

Since
3.0

-@Async @WiseFyThread fun addWEPNetwork(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?): Unit
+@Async @WiseFyThread fun addWEPNetwork(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?): Unit +

Overrides AddNetworkApi.addWEPNetwork

+
Deprecated: Due to security and performance limitations, WEP networks are discouraged

To add a WEP network to the user's configured network list.

diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-w-p-a2-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-w-p-a2-network.html index d83f5a02..f47342b9 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-w-p-a2-network.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/add-w-p-a2-network.html @@ -10,6 +10,7 @@

addWPA2Network

@Sync @CallingThread fun addWPA2Network(ssid: String?, password: String?): Int +

Overrides AddNetworkApi.addWPA2Network

To add a WPA2 network to the user's configured network list.

Parameters

@@ -29,6 +30,7 @@

Parameters

3.0

@Async @WiseFyThread fun addWPA2Network(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?): Unit +

Overrides AddNetworkApi.addWPA2Network

To add a WPA2 network to the user's configured network list.

Parameters

diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/calculate-bars.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/calculate-bars.html index 82327128..37051bc6 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/calculate-bars.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/calculate-bars.html @@ -10,6 +10,7 @@

calculateBars

@Sync @CallingThread fun calculateBars(rssiLevel: Int, targetNumberOfBars: Int): Int +

Overrides SignalStrengthApi.calculateBars

To convert an RSSI level for a network to a number of bars.

Parameters

diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/compare-signal-level.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/compare-signal-level.html index eb0e7a51..85a279ea 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/compare-signal-level.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/compare-signal-level.html @@ -10,6 +10,7 @@

compareSignalLevel

@Sync @CallingThread fun compareSignalLevel(rssi1: Int, rssi2: Int): Int +

Overrides SignalStrengthApi.compareSignalLevel

To compare the signal strength of two networks.

This method will return:

  • Negative value if the first signal is weaker than the second signal
  • diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/connect-to-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/connect-to-network.html index 1b39f700..c8590888 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/connect-to-network.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/connect-to-network.html @@ -10,6 +10,7 @@

    connectToNetwork

    @Sync @CallingThread @WaitsForTimeout fun connectToNetwork(ssidToConnectTo: String?, timeoutInMillis: Int): Boolean +

    Overrides ConnectionApi.connectToNetwork

    Used to connect to a network.

    NOTE Gets a list of saved networks, connects to the given ssid if found, and verifies connectivity.

    Parameters

    @@ -31,6 +32,7 @@

    Parameters

    3.0

    @Async @WiseFyThread @WaitsForTimeout fun connectToNetwork(ssidToConnectTo: String?, timeoutInMillis: Int, callbacks: ConnectToNetworkCallbacks?): Unit +

    Overrides ConnectionApi.connectToNetwork

    Used to connect to a network.

    Gets a list of saved networks, connects to the given ssid if found, and verifies connectivity.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/disable-wifi.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/disable-wifi.html index 448f930f..a7cb20c7 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/disable-wifi.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/disable-wifi.html @@ -10,6 +10,7 @@

    disableWifi

    @Sync @CallingThread fun disableWifi(): Boolean +

    Overrides WifiApi.disableWifi

    To disable Wifi on a user's device.

    Return
    boolean - True if the command succeeded in disabling wifi

    @@ -23,6 +24,7 @@

    disableWifi

    3.0

    @Async @WiseFyThread fun disableWifi(callbacks: DisableWifiCallbacks?): Unit +

    Overrides WifiApi.disableWifi

    To disable Wifi on a user's device.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/disconnect-from-current-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/disconnect-from-current-network.html index 69d6d5dd..5fb53a6d 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/disconnect-from-current-network.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/disconnect-from-current-network.html @@ -10,6 +10,7 @@

    disconnectFromCurrentNetwork

    @Sync @CallingThread fun disconnectFromCurrentNetwork(): Boolean +

    Overrides ConnectionApi.disconnectFromCurrentNetwork

    To disconnect the user from their current network.

    Return
    boolean - If the command succeeded in disconnecting the device from the current network

    @@ -23,6 +24,7 @@

    disconnectFromCurrentNetwork

    3.0

    @Async @WiseFyThread fun disconnectFromCurrentNetwork(callbacks: DisconnectFromCurrentNetworkCallbacks?): Unit +

    Overrides ConnectionApi.disconnectFromCurrentNetwork

    To disconnect the user from their current network.

    Parameters

    @@ -32,6 +34,7 @@

    Parameters

    runOnWiseFyThread

    WifiManager.disconnect

    WiseFyLock

    +

    WiseFyPrechecks.disconnectFromCurrentNetworkChecks

    Author
    Patches

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/dump.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/dump.html index fda023a8..0fa74f0a 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/dump.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/dump.html @@ -10,6 +10,7 @@

    dump

    fun dump(): Unit +

    Overrides WiseFyPublicApi.dump

    Used to cleanup the thread started by WiseFy.

    See Also

    WiseFyConnection.destroy

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/enable-wifi.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/enable-wifi.html index 7b5d8167..306d1106 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/enable-wifi.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/enable-wifi.html @@ -10,6 +10,7 @@

    enableWifi

    @Sync @CallingThread fun enableWifi(): Boolean +

    Overrides WifiApi.enableWifi

    To enable Wifi on a user's device.

    Return
    boolean - If the command succeeded in enabling wifi

    @@ -23,6 +24,7 @@

    enableWifi

    3.0

    @Async @WiseFyThread fun enableWifi(callbacks: EnableWifiCallbacks?): Unit +

    Overrides WifiApi.enableWifi

    To enable Wifi on a user's device.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-current-network-info.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-current-network-info.html index df5701d4..61325d58 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-current-network-info.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-current-network-info.html @@ -10,6 +10,7 @@

    getCurrentNetworkInfo

    @Sync @CallingThread fun getCurrentNetworkInfo(): NetworkInfo? +

    Overrides NetworkInfoApi.getCurrentNetworkInfo

    To retrieve the details of the phones active network.

    Return
    NetworkInfo

    @@ -24,6 +25,7 @@

    getCurrentNetworkInfo

    3.0

    @Async @WiseFyThread fun getCurrentNetworkInfo(callbacks: GetCurrentNetworkInfoCallbacks?): Unit +

    Overrides NetworkInfoApi.getCurrentNetworkInfo

    To retrieve the details of the phones active network.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-current-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-current-network.html index 6f7d967e..80168788 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-current-network.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-current-network.html @@ -10,10 +10,8 @@

    getCurrentNetwork

    @Sync @CallingThread fun getCurrentNetwork(): WifiInfo? +

    Overrides NetworkInfoApi.getCurrentNetwork

    To retrieve the user's current network.

    -

    Exceptions

    -

    -SecurityException - Without necessary permissions granted

    Return
    WifiInfo|null - The user's current network information

    See Also
    @@ -27,13 +25,11 @@

    Exceptions

    3.0

    @Async @WiseFyThread fun getCurrentNetwork(callbacks: GetCurrentNetworkCallbacks?): Unit +

    Overrides NetworkInfoApi.getCurrentNetwork

    To retrieve the user's current network.

    Parameters

    callbacks - The listener to return results to

    -

    Exceptions

    -

    -SecurityException - Without necessary permissions granted

    See Also

    GetCurrentNetworkCallbacks

    runOnWiseFyThread

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-frequency.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-frequency.html index df826b0a..6eba3df7 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-frequency.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-frequency.html @@ -10,10 +10,8 @@

    getFrequency

    @Sync @CallingThread fun getFrequency(): Int? +

    Overrides FrequencyApi.getFrequency

    To retrieve the frequency of the device's current network.

    -

    Exceptions

    -

    -SecurityException - Without necessary permissions granted

    Return
    Integer - The frequency of the devices current network or null if no network

    See Also
    @@ -26,13 +24,11 @@

    Exceptions

    3.0

    @Async @WiseFyThread fun getFrequency(callbacks: GetFrequencyCallbacks?): Unit +

    Overrides FrequencyApi.getFrequency

    To retrieve the frequency of the device's current network.

    Parameters

    callbacks - The listener to return results to

    -

    Exceptions

    -

    -SecurityException - Without necessary permissions granted

    See Also

    getCurrentNetwork

    GetFrequencyCallbacks

    @@ -46,6 +42,7 @@

    Exceptions

    3.0

    @Sync @CallingThread fun getFrequency(network: WifiInfo?): Int? +

    Overrides FrequencyApi.getFrequency

    To retrieve the frequency of a network.

    Parameters

    @@ -61,6 +58,7 @@

    Parameters

    3.0

    @Async @WiseFyThread fun getFrequency(network: WifiInfo?, callbacks: GetFrequencyCallbacks?): Unit +

    Overrides FrequencyApi.getFrequency

    To retrieve the frequency of a network.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-i-p.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-i-p.html index 0aa9ab75..0a4551c9 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-i-p.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-i-p.html @@ -10,6 +10,7 @@

    getIP

    @Sync @CallingThread fun getIP(): String? +

    Overrides NetworkInfoApi.getIP

    To retrieve the IPv4 or IPv6 of a device.

    Return
    String - The IPv4 or IPv6 address

    @@ -25,6 +26,7 @@

    getIP

    3.0

    @Async @WiseFyThread fun getIP(callbacks: GetIPCallbacks?): Unit +

    Overrides NetworkInfoApi.getIP

    To retrieve the IPv4 or IPv6 of a device.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-nearby-access-points.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-nearby-access-points.html index 51e0b195..647121b3 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-nearby-access-points.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-nearby-access-points.html @@ -10,15 +10,13 @@

    getNearbyAccessPoints

    @Sync @CallingThread fun getNearbyAccessPoints(filterDuplicates: Boolean): List<ScanResult>? +

    Overrides AccessPointApi.getNearbyAccessPoints

    To retrieve a list of nearby access points.

    NOTE Setting filterDuplicates to true will exclude access points for an SSID that have a weaker RSSI (will always take the highest signal strength).

    Parameters

    filterDuplicates - If you want to exclude SSIDs with that same name that have a weaker signal strength

    -

    Exceptions

    -

    -SecurityException - Without necessary permissions granted

    Return
    List of ScanResults|null - List of nearby access points

    See Also
    @@ -32,8 +30,10 @@

    Exceptions

    3.0

    @Async @WiseFyThread fun getNearbyAccessPoints(filterDuplicates: Boolean, callbacks: GetNearbyAccessPointsCallbacks?): Unit +

    Overrides AccessPointApi.getNearbyAccessPoints

    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).

    +

    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

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-r-s-s-i.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-r-s-s-i.html index 0b978bef..02fd5094 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-r-s-s-i.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-r-s-s-i.html @@ -10,6 +10,7 @@

    getRSSI

    @Sync @CallingThread @WaitsForTimeout fun getRSSI(regexForSSID: String?, takeHighest: Boolean, timeoutInMillis: Int): Int? +

    Overrides AccessPointApi.getRSSI

    To retrieve the RSSI of the first network matching a given regex.

    NOTE Setting takeHighest to true will return the access point with the highest RSSI for the given SSID.

    Parameters

    @@ -32,6 +33,7 @@

    Parameters

    3.0

    @Async @WiseFyThread @WaitsForTimeout fun getRSSI(regexForSSID: String?, takeHighest: Boolean, timeoutInMillis: Int, callbacks: GetRSSICallbacks?): Unit +

    Overrides AccessPointApi.getRSSI

    To retrieve the RSSI of the first network matching a given regex.

    NOTE Setting takeHighest to true will return the access point with the highest RSSI for the given SSID.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-saved-networks.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-saved-networks.html index 3a1b0313..3376b15f 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-saved-networks.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-saved-networks.html @@ -10,6 +10,7 @@

    getSavedNetworks

    @Sync @CallingThread fun getSavedNetworks(): List<WifiConfiguration>? +

    Overrides SavedNetworkApi.getSavedNetworks

    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

    @@ -24,6 +25,7 @@

    getSavedNetworks

    3.0

    @Async @WiseFyThread fun getSavedNetworks(callbacks: GetSavedNetworksCallbacks?): Unit +

    Overrides SavedNetworkApi.getSavedNetworks

    To retrieve a list of saved networks on a user's device.

    Parameters

    @@ -40,42 +42,5 @@

    Parameters

    Patches

    Since
    3.0

    - -@Sync @CallingThread fun getSavedNetworks(regexForSSID: String?): List<WifiConfiguration>? -

    To retrieve a list of saved networks on a user's device that match a given regex.

    -

    Parameters

    -

    -regexForSSID - The ssid to use while searching for saved configurations

    -

    Return
    -List of WifiConfigurations|null - The list of saved network configurations that match the given regex

    -

    See Also
    -

    WifiConfiguration

    -

    WiseFyPrechecks.getSavedNetworksChecks

    -

    WiseFySearch.findSavedNetworksMatchingRegex

    -

    -

    Author
    -Patches

    -

    Since
    -3.0

    - -@Async @WiseFyThread fun getSavedNetworks(regexForSSID: String?, callbacks: GetSavedNetworksCallbacks?): Unit -

    To retrieve a list of saved networks on a user's device that match a given regex.

    -

    Parameters

    -

    -regexForSSID - The ssid to use while searching for saved configurations

    -

    -callbacks - The listener to return results to

    -

    See Also
    -

    GetSavedNetworksCallbacks

    -

    runOnWiseFyThread

    -

    WifiConfiguration

    -

    WiseFyLock

    -

    WiseFyPrechecks.getSavedNetworksChecks

    -

    WiseFySearch.findSavedNetworksMatchingRegex

    -

    -

    Author
    -Patches

    -

    Since
    -3.0

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-wise-fy-lock.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-wise-fy-lock.html index b27cdbfc..fc7bb8c9 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-wise-fy-lock.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/get-wise-fy-lock.html @@ -10,9 +10,10 @@

    getWiseFyLock

    fun getWiseFyLock(): WiseFyLock +

    Overrides WiseFyPublicApi.getWiseFyLock

    To retrieve the lock in use by WiseFy for synchronization.

    Return
    -WiseFyLock - The instance of the lock in use by WiseFy

    +WiseFyLock - The instance of the lock in-use by WiseFy

    See Also

    WiseFyLock

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/index.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/index.html index 636d2d66..96bdd8cc 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/index.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/index.html @@ -8,7 +8,7 @@ wisefy / com.isupatches.wisefy / WiseFy

    WiseFy

    -@PublicAPI class WiseFy : WiseFyPublicApi +@PublicAPI class WiseFy : WiseFyPublicApi

    Main class for WiseFy that provides a synchronous and asynchronous API to manipulate and query for different parts of a device's wifi configuration and status.

    Author
    @@ -194,25 +194,12 @@

    Functions

    -

    getSavedNetwork

    - - -fun getSavedNetwork(regexForSSID: String?): WifiConfiguration?
    -fun getSavedNetwork(regexForSSID: String?, callbacks: GetSavedNetworkCallbacks?): Unit -

    To search for and return a saved WiFiConfiguration given an SSID.

    - - - -

    getSavedNetworks

    fun getSavedNetworks(): List<WifiConfiguration>?
    fun getSavedNetworks(callbacks: GetSavedNetworksCallbacks?): Unit

    To retrieve a list of saved networks on a user's device.

    -fun getSavedNetworks(regexForSSID: String?): List<WifiConfiguration>?
    -fun getSavedNetworks(regexForSSID: String?, callbacks: GetSavedNetworksCallbacks?): Unit -

    To retrieve a list of saved networks on a user's device that match a given regex.

    @@ -393,6 +380,26 @@

    Functions

    +

    searchForSavedNetwork

    + + +fun searchForSavedNetwork(regexForSSID: String?): WifiConfiguration?
    +fun searchForSavedNetwork(regexForSSID: String?, callbacks: SearchForSavedNetworkCallbacks?): Unit +

    To search for and return a saved WiFiConfiguration given an SSID.

    + + + + +

    searchForSavedNetworks

    + + +fun searchForSavedNetworks(regexForSSID: String?): List<WifiConfiguration>?
    +fun searchForSavedNetworks(regexForSSID: String?, callbacks: SearchForSavedNetworksCallbacks?): Unit +

    To retrieve a list of saved networks on a user's device that match a given regex.

    + + + +

    searchForSSID

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-mobile-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-mobile-network.html index 8ef1537a..8c4259d3 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-mobile-network.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-mobile-network.html @@ -10,6 +10,7 @@

    isDeviceConnectedToMobileNetwork

    @Sync @CallingThread fun isDeviceConnectedToMobileNetwork(): Boolean +

    Overrides DeviceApi.isDeviceConnectedToMobileNetwork

    To check if the device is connected to a mobile network.

    Return
    bool - If the device is currently connected to a mobile network

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-mobile-or-wifi-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-mobile-or-wifi-network.html index 2ad8fca0..0f819819 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-mobile-or-wifi-network.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-mobile-or-wifi-network.html @@ -10,6 +10,7 @@

    isDeviceConnectedToMobileOrWifiNetwork

    @Sync @CallingThread fun isDeviceConnectedToMobileOrWifiNetwork(): Boolean +

    Overrides DeviceApi.isDeviceConnectedToMobileOrWifiNetwork

    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

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-s-s-i-d.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-s-s-i-d.html index ea8a6e55..8d7bd329 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-s-s-i-d.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-s-s-i-d.html @@ -10,6 +10,7 @@

    isDeviceConnectedToSSID

    @Sync @CallingThread fun isDeviceConnectedToSSID(ssid: String?): Boolean +

    Overrides DeviceApi.isDeviceConnectedToSSID

    To check if the device is connected to a given SSID.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-wifi-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-wifi-network.html index ec3a609c..8940dd86 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-wifi-network.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-connected-to-wifi-network.html @@ -10,6 +10,7 @@

    isDeviceConnectedToWifiNetwork

    @Sync @CallingThread fun isDeviceConnectedToWifiNetwork(): Boolean +

    Overrides DeviceApi.isDeviceConnectedToWifiNetwork

    To check if the device is connected to a wifi network.

    Return
    bool - If the device is currently connected to a wifi network

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-roaming.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-roaming.html index 4ab9bc25..489ad889 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-roaming.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-device-roaming.html @@ -10,6 +10,7 @@

    isDeviceRoaming

    @Sync @CallingThread fun isDeviceRoaming(): Boolean +

    Overrides DeviceApi.isDeviceRoaming

    To query if the device is roaming.

    Return
    boolean - If the current network is roaming

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-logging-enabled.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-logging-enabled.html index 25f9bada..ced80aa9 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-logging-enabled.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-logging-enabled.html @@ -10,6 +10,7 @@

    isLoggingEnabled

    @Sync @CallingThread fun isLoggingEnabled(): Boolean +

    Overrides WiseFyPublicApi.isLoggingEnabled

    To query if logging is enabled or disabled for a WiseFy instance.

    Return
    boolean - If logging is enabled for the WiseFy instance

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-e-a-p.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-e-a-p.html index 2adeae28..a98eb7c5 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-e-a-p.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-e-a-p.html @@ -10,6 +10,7 @@

    isNetworkEAP

    @Sync @CallingThread fun isNetworkEAP(scanResult: ScanResult?): Boolean +

    Overrides SecurityApi.isNetworkEAP

    To check and return if a network is a EAP network.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-p-s-k.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-p-s-k.html index 1c3159e6..5fb91f0d 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-p-s-k.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-p-s-k.html @@ -10,6 +10,7 @@

    isNetworkPSK

    @Sync @CallingThread fun isNetworkPSK(scanResult: ScanResult?): Boolean +

    Overrides SecurityApi.isNetworkPSK

    To check and return if a network is a PSK network.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-saved.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-saved.html index a35bcf0d..06209f53 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-saved.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-saved.html @@ -10,6 +10,7 @@

    isNetworkSaved

    @Sync @CallingThread fun isNetworkSaved(ssid: String?): Boolean +

    Overrides SavedNetworkApi.isNetworkSaved

    To check if an SSID is in the list of configured networks.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-secure.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-secure.html index a2b11d1e..ac7506c5 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-secure.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-secure.html @@ -10,6 +10,7 @@

    isNetworkSecure

    @Sync @CallingThread fun isNetworkSecure(scanResult: ScanResult?): Boolean +

    Overrides SecurityApi.isNetworkSecure

    To check and return if a network is secure (contains EAP/PSK/WEP/WPA/WPA2 capabilities).

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-e-p.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-e-p.html index 02764f15..ee59efd2 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-e-p.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-e-p.html @@ -10,6 +10,7 @@

    isNetworkWEP

    @Sync @CallingThread fun isNetworkWEP(scanResult: ScanResult?): Boolean +

    Overrides SecurityApi.isNetworkWEP

    To check and return if a network is a WEP network.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-p-a.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-p-a.html index 96a0a6a0..b58412de 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-p-a.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-p-a.html @@ -10,6 +10,7 @@

    isNetworkWPA

    @Sync @CallingThread fun isNetworkWPA(scanResult: ScanResult?): Boolean +

    Overrides SecurityApi.isNetworkWPA

    To check and return if a network is a WPA network.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-p-a2.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-p-a2.html index 971b58c0..4fdd8ed8 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-p-a2.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network-w-p-a2.html @@ -10,6 +10,7 @@

    isNetworkWPA2

    @Sync @CallingThread fun isNetworkWPA2(scanResult: ScanResult?): Boolean +

    Overrides SecurityApi.isNetworkWPA2

    To check and return if a network is a WPA2 network.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network5g-hz.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network5g-hz.html index fb774a8d..07a82db3 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network5g-hz.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-network5g-hz.html @@ -10,10 +10,8 @@

    isNetwork5gHz

    @Sync @CallingThread fun isNetwork5gHz(): Boolean +

    Overrides FrequencyApi.isNetwork5gHz

    To check if the device's current network is 5gHz.

    -

    Exceptions

    -

    -SecurityException - Without necessary permissions granted

    Return
    boolean - If the network is 5gHz

    See Also
    @@ -27,6 +25,7 @@

    Exceptions

    3.0

    @Sync @CallingThread fun isNetwork5gHz(network: WifiInfo?): Boolean +

    Overrides FrequencyApi.isNetwork5gHz

    To check if a given network is 5gHz.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-wifi-enabled.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-wifi-enabled.html index 64ce0d1e..d857cb73 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-wifi-enabled.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/is-wifi-enabled.html @@ -10,6 +10,7 @@

    isWifiEnabled

    @Sync @CallingThread fun isWifiEnabled(): Boolean +

    Overrides WifiApi.isWifiEnabled

    To check if Wifi is enabled on the device or not.

    Return
    boolean - if Wifi is enabled on device

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/remove-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/remove-network.html index b11e1130..eb43260e 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/remove-network.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/remove-network.html @@ -10,6 +10,7 @@

    removeNetwork

    @Sync @CallingThread fun removeNetwork(ssidToRemove: String?): Boolean +

    Overrides RemoveNetworkApi.removeNetwork

    To remove a configured network.

    Parameters

    @@ -29,6 +30,7 @@

    Parameters

    3.0

    @Async @WiseFyThread fun removeNetwork(ssidToRemove: String?, callbacks: RemoveNetworkCallbacks?): Unit +

    Overrides RemoveNetworkApi.removeNetwork

    To remove a configured network.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-access-point.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-access-point.html index d89c7041..0cb38e6a 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-access-point.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-access-point.html @@ -10,6 +10,7 @@

    searchForAccessPoint

    @Sync @CallingThread fun searchForAccessPoint(regexForSSID: String?, timeoutInMillis: Int, filterDuplicates: Boolean): ScanResult? +

    Overrides AccessPointApi.searchForAccessPoint

    To return the first access point that matches a given regex.

    NOTE Setting filterDuplicates to true will not return an access point with a weaker signal strength (will always take the highest).

    Parameters

    @@ -32,6 +33,7 @@

    Parameters

    3.0

    @Async @WiseFyThread fun searchForAccessPoint(regexForSSID: String?, timeoutInMillis: Int, filterDuplicates: Boolean, callbacks: SearchForAccessPointCallbacks?): Unit +

    Overrides AccessPointApi.searchForAccessPoint

    To return the first access point that matches a given regex.

    NOTE Setting filterDuplicates to true will not return an access point with a weaker signal strength (will always take the highest).

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-access-points.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-access-points.html index 7d168310..54f9022f 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-access-points.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-access-points.html @@ -10,6 +10,7 @@

    searchForAccessPoints

    @Sync @CallingThread fun searchForAccessPoints(regexForSSID: String?, filterDuplicates: Boolean): List<ScanResult>? +

    Overrides AccessPointApi.searchForAccessPoints

    To return nearby access points that match a given regex.

    NOTE Setting filterDuplicates to true will not return access points with a weaker signal strength (will always take the highest).

    Parameters

    @@ -30,6 +31,7 @@

    Parameters

    3.0

    @Async @WiseFyThread fun searchForAccessPoints(regexForSSID: String?, filterDuplicates: Boolean, callbacks: SearchForAccessPointsCallbacks?): Unit +

    Overrides AccessPointApi.searchForAccessPoints

    To return nearby access points that match a given regex.

    NOTE Setting filterDuplicates to true will not return access points with a weaker signal strength (will always take the highest).

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-s-s-i-d.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-s-s-i-d.html index dcbf29d9..b5222a51 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-s-s-i-d.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-s-s-i-d.html @@ -10,6 +10,7 @@

    searchForSSID

    @Sync @CallingThread @WaitsForTimeout fun searchForSSID(regexForSSID: String?, timeoutInMillis: Int): String? +

    Overrides AccessPointApi.searchForSSID

    To search local networks and return the first one that contains a given ssid.

    Parameters

    @@ -29,6 +30,7 @@

    Parameters

    3.0

    @Async @WiseFyThread @WaitsForTimeout fun searchForSSID(regexForSSID: String?, timeoutInMillis: Int, callbacks: SearchForSSIDCallbacks?): Unit +

    Overrides AccessPointApi.searchForSSID

    To search local networks and return the first one that contains a given ssid.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-s-s-i-ds.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-s-s-i-ds.html index be2f882f..2e97ffa6 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-s-s-i-ds.html +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-s-s-i-ds.html @@ -10,6 +10,7 @@

    searchForSSIDs

    @Sync @CallingThread fun searchForSSIDs(regexForSSID: String?): List<String>? +

    Overrides AccessPointApi.searchForSSIDs

    To search local networks and return the first one that contains a given ssid.

    Parameters

    @@ -26,6 +27,7 @@

    Parameters

    3.0

    @Async @WiseFyThread fun searchForSSIDs(regexForSSID: String?, callbacks: SearchForSSIDsCallbacks?): Unit +

    Overrides AccessPointApi.searchForSSIDs

    To search local networks and return the first one that contains a given ssid.

    Parameters

    diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-saved-network.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-saved-network.html new file mode 100644 index 00000000..35dfefcf --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-saved-network.html @@ -0,0 +1,51 @@ + + + +WiseFy.searchForSavedNetwork - wisefy + + + +wisefy / com.isupatches.wisefy / WiseFy / searchForSavedNetwork
    +
    +

    searchForSavedNetwork

    + +@Sync @CallingThread fun searchForSavedNetwork(regexForSSID: String?): WifiConfiguration? +

    Overrides SavedNetworkApi.searchForSavedNetwork

    +

    To search for and return a saved WiFiConfiguration given an SSID.

    +

    Parameters

    +

    +regexForSSID - The ssid to use while searching for saved configuration

    +

    Return
    +WifiConfiguration|null - Saved network that matches the ssid

    +

    See Also
    +

    WifiConfiguration

    +

    WiseFyPrechecks.searchForSavedNetworkChecks

    +

    WiseFySearch.findSavedNetworkByRegex

    +

    +

    Author
    +Patches

    +

    Since
    +3.0

    + +@Async @WiseFyThread fun searchForSavedNetwork(regexForSSID: String?, callbacks: SearchForSavedNetworkCallbacks?): Unit +

    Overrides SavedNetworkApi.searchForSavedNetwork

    +

    To search for and return a saved WiFiConfiguration given an SSID.

    +

    Parameters

    +

    +regexForSSID - The ssid to use while searching for saved configuration

    +

    +callbacks - The listener to return results to

    +

    See Also
    +

    SearchForSavedNetworkCallbacks

    +

    runOnWiseFyThread

    +

    WifiConfiguration

    +

    WiseFyLock

    +

    WiseFyPrechecks.searchForSavedNetworkChecks

    +

    WiseFySearch.findSavedNetworkByRegex

    +

    +

    Author
    +Patches

    +

    Since
    +3.0

    + + diff --git a/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-saved-networks.html b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-saved-networks.html new file mode 100644 index 00000000..0bf187de --- /dev/null +++ b/javadoc/wisefy/com.isupatches.wisefy/-wise-fy/search-for-saved-networks.html @@ -0,0 +1,51 @@ + + + +WiseFy.searchForSavedNetworks - wisefy + + + +wisefy / com.isupatches.wisefy / WiseFy / searchForSavedNetworks
    +
    +

    searchForSavedNetworks

    + +@Sync @CallingThread fun searchForSavedNetworks(regexForSSID: String?): List<WifiConfiguration>? +

    Overrides SavedNetworkApi.searchForSavedNetworks

    +

    To retrieve a list of saved networks on a user's device that match a given regex.

    +

    Parameters

    +

    +regexForSSID - The ssid to use while searching for saved configurations

    +

    Return
    +List of WifiConfigurations|null - The list of saved network configurations that match the given regex

    +

    See Also
    +

    WifiConfiguration

    +

    WiseFyPrechecks.searchForSavedNetworksChecks

    +

    WiseFySearch.findSavedNetworksMatchingRegex

    +

    +

    Author
    +Patches

    +

    Since
    +3.0

    + +@Async @WiseFyThread fun searchForSavedNetworks(regexForSSID: String?, callbacks: SearchForSavedNetworksCallbacks?): Unit +

    Overrides SavedNetworkApi.searchForSavedNetworks

    +

    To retrieve a list of saved networks on a user's device that match a given regex.

    +

    Parameters

    +

    +regexForSSID - The ssid to use while searching for saved configurations

    +

    +callbacks - The listener to return results to

    +

    See Also
    +

    SearchForSavedNetworksCallbacks

    +

    runOnWiseFyThread

    +

    WifiConfiguration

    +

    WiseFyLock

    +

    WiseFyPrechecks.searchForSavedNetworksChecks

    +

    WiseFySearch.findSavedNetworksMatchingRegex

    +

    +

    Author
    +Patches

    +

    Since
    +3.0

    + + diff --git a/javadoc/wisefy/com.isupatches.wisefy/index.html b/javadoc/wisefy/com.isupatches.wisefy/index.html index 093b49fc..74c931b6 100644 --- a/javadoc/wisefy/com.isupatches.wisefy/index.html +++ b/javadoc/wisefy/com.isupatches.wisefy/index.html @@ -13,10 +13,109 @@

    Types

    +

    AccessPointApi

    + + +interface AccessPointApi +

    An API for querying for nearby access points and related information.

    + + + + +

    AddNetworkApi

    + + +interface AddNetworkApi +

    An API for adding networks as saved configurations on a device.

    + + + + +

    ConnectionApi

    + + +interface ConnectionApi +

    An API for managing the network connection of a device.

    + + + + +

    DeviceApi

    + + +interface DeviceApi +

    An API for querying about the different network statuses of a device.

    + + + + +

    FrequencyApi

    + + +interface FrequencyApi +

    An API for querying about a network's frequency.

    + + + + +

    NetworkInfoApi

    + + +interface NetworkInfoApi +

    An API for querying about a device's current network information.

    + + + + +

    RemoveNetworkApi

    + + +interface RemoveNetworkApi +

    An API for removing a network as a saved configuration.

    + + + + +

    SavedNetworkApi

    + + +interface SavedNetworkApi +

    An API for querying saved network information on a device.

    + + + + +

    SecurityApi

    + + +interface SecurityApi +

    An API for querying about a network's security details.

    + + + + +

    SignalStrengthApi

    + + +interface SignalStrengthApi +

    An API for functionality relating to signal strength.

    + + + + +

    WifiApi

    + + +interface WifiApi +

    An API for functionality relating to Wifi.

    + + + +

    WiseFy

    -class WiseFy : WiseFyPublicApi +class WiseFy : WiseFyPublicApi

    Main class for WiseFy that provides a synchronous and asynchronous API to manipulate and query for different parts of a device's wifi configuration and status.

    @@ -30,6 +129,16 @@

    Types

    A class used to synchronize logic.

    + + +

    WiseFyPublicApi

    + + +interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi +

    The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation +of functionality.

    + + diff --git a/javadoc/wisefy/index-outline.html b/javadoc/wisefy/index-outline.html index 72a44890..2ea714c5 100644 --- a/javadoc/wisefy/index-outline.html +++ b/javadoc/wisefy/index-outline.html @@ -23,6 +23,48 @@ +interface AccessPointApi
    + +interface AddNetworkApi
    + interface AddNetworkCallbacks : BaseCallback
      @@ -63,6 +105,22 @@
    +interface ConnectionApi
    + interface ConnectToNetworkCallbacks : BaseCallback
      @@ -78,6 +136,23 @@
    +interface DeviceApi
    + interface DisableWifiCallbacks : BaseCallback
      @@ -120,6 +195,24 @@
    +interface FrequencyApi
    + interface GetCurrentNetworkCallbacks : BaseCallback
    @@ -204,7 +297,7 @@
-interface GetSavedNetworkCallbacks : BaseCallback
+interface GetSavedNetworksCallbacks : BaseCallback
-interface GetSavedNetworksCallbacks : BaseCallback
+interface NetworkInfoApi
@@ -245,6 +342,20 @@ +interface RemoveNetworkApi
+ interface RemoveNetworkCallbacks : BaseCallback
    @@ -260,6 +371,25 @@
+interface SavedNetworkApi
+ interface SearchForAccessPointCallbacks : BaseCallback
    @@ -288,6 +418,34 @@
+interface SearchForSavedNetworkCallbacks : BaseCallback
+ +interface SearchForSavedNetworksCallbacks : BaseCallback
+ interface SearchForSSIDCallbacks : BaseCallback
    @@ -316,7 +474,56 @@
-@PublicAPI class WiseFy : WiseFyPublicApi
+interface SecurityApi
+ +interface SignalStrengthApi
+ +interface WifiApi
+ +@PublicAPI class WiseFy : WiseFyPublicApi
class WiseFyLock
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi
+ @@ -449,7 +671,200 @@ -@PublicAPI class WiseFy : WiseFyPublicApi
+interface AccessPointApi
+ +interface AddNetworkApi
+ +interface ConnectionApi
+ +interface DeviceApi
+ +interface FrequencyApi
+ +interface NetworkInfoApi
+ +interface RemoveNetworkApi
+ +interface SavedNetworkApi
+ +interface SecurityApi
+ +interface SignalStrengthApi
+ +interface WifiApi
+ +@PublicAPI class WiseFy : WiseFyPublicApi
class WiseFyLock
+interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi
+ @@ -664,7 +1094,7 @@ abstract fun noCurrentNetworkInfo(): Unit
-abstract fun retrievedCurrentNetworkInfo(currentNetworkDetails: NetworkInfo): Unit
+abstract fun retrievedCurrentNetworkInfo(currentNetworkInfo: NetworkInfo): Unit
@@ -724,20 +1154,6 @@ -interface GetSavedNetworkCallbacks : BaseCallback
- interface GetSavedNetworksCallbacks : BaseCallback
    @@ -795,6 +1211,34 @@
+interface SearchForSavedNetworkCallbacks : BaseCallback
+ +interface SearchForSavedNetworksCallbacks : BaseCallback
+ interface SearchForSSIDCallbacks : BaseCallback
    diff --git a/wisefy/build.gradle b/wisefy/build.gradle index e8787e3a..6780ed4c 100644 --- a/wisefy/build.gradle +++ b/wisefy/build.gradle @@ -91,10 +91,18 @@ dependencies { // Kotlin implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - testImplementation "org.robolectric:robolectric:$robo_electric_version" + // Unit Tests testImplementation "androidx.test:core:$androidx_core_test_version" testImplementation "org.mockito:mockito-core:$mockito_version" testImplementation "junit:junit:$junit_version" + + // Instrumentation Tests + androidTestImplementation "androidx.test.espresso:espresso-core:$androidx_espresso_core_version" + androidTestImplementation "androidx.test:runner:$androidx_test_runner_version" + androidTestImplementation "androidx.test:rules:$androidx_test_runner_version" + androidTestImplementation "org.mockito:mockito-core:$mockito_version" + androidTestImplementation "org.mockito:mockito-android:$mockito_version" + androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockito_kotlin_version" } apply from: rootProject.file("$rootProject.projectDir/gradle/gradle-bintray-install.gradle") diff --git a/wisefy/proguard-rules.pro b/wisefy/proguard-rules.pro index e0e5379e..49c4e946 100644 --- a/wisefy/proguard-rules.pro +++ b/wisefy/proguard-rules.pro @@ -1,9 +1,6 @@ -verbose -dontobfuscate -#-keepattributes SourceFile, LineNumberTable # For stacktraces -#-keepattributes LocalVariableTable, LocalVariableTypeTable # For debugging -#-keepattributes MethodParameters -keep class com.isupatches.wisefy.** { *; } --keep public interface com.isupatches.wisefy.** { *; } \ No newline at end of file +-keep public interface com.isupatches.wisefy.** { *; } diff --git a/wisefy/src/test/java/com/isupatches/wisefy/AddOpenNetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.kt similarity index 90% rename from wisefy/src/test/java/com/isupatches/wisefy/AddOpenNetworkTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.kt index 989d031c..46b986cd 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/AddOpenNetworkTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.kt @@ -1,32 +1,25 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.WiseFy.Companion.WIFI_MANAGER_FAILURE import com.isupatches.wisefy.callbacks.AddNetworkCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assert.assertNotEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to add open networks. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class AddOpenNetworkTests : BaseUnitTest() { +internal class AddOpenNetworkTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks() { mockWiseFyPrechecksUtil.addNetwork_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/AddWEPNetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.kt similarity index 90% rename from wisefy/src/test/java/com/isupatches/wisefy/AddWEPNetworkTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.kt index 69dcad27..c7ec7014 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/AddWEPNetworkTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.kt @@ -1,33 +1,26 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.WiseFy.Companion.WIFI_MANAGER_FAILURE import com.isupatches.wisefy.callbacks.AddNetworkCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assert.assertNotEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to add WEP networks. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) @Suppress("deprecation") -internal class AddWEPNetworkTests : BaseUnitTest() { +internal class AddWEPNetworkTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks() { mockWiseFyPrechecksUtil.addNetwork_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/AddWPA2NetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.kt similarity index 91% rename from wisefy/src/test/java/com/isupatches/wisefy/AddWPA2NetworkTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.kt index caea489b..61c4b0ab 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/AddWPA2NetworkTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.kt @@ -1,32 +1,25 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.WiseFy.Companion.WIFI_MANAGER_FAILURE import com.isupatches.wisefy.callbacks.AddNetworkCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assert.assertNotEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to add WPA2 networks. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class AddWPA2NetworkTests : BaseUnitTest() { +internal class AddWPA2NetworkTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks() { mockWiseFyPrechecksUtil.addNetwork_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/ConnectToNetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.kt similarity index 93% rename from wisefy/src/test/java/com/isupatches/wisefy/ConnectToNetworkTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.kt index c98b4219..7d5eae7c 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/ConnectToNetworkTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.ConnectToNetworkCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to connect to a network. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class ConnectToNetworkTests : BaseUnitTest() { +internal class ConnectToNetworkTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks() { mockWiseFyPrechecksUtil.connectToNetwork_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/DisableWifiTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.kt similarity index 89% rename from wisefy/src/test/java/com/isupatches/wisefy/DisableWifiTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.kt index 096d9aa7..81fb8633 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/DisableWifiTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.DisableWifiCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to disable a device's wifi. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class DisableWifiTests : BaseUnitTest() { +internal class DisableWifiTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks() { mockWiseFyPrechecksUtil.disableWifi_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.kt similarity index 91% rename from wisefy/src/test/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.kt index 7dc2b172..b63d7080 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.DisconnectFromCurrentNetworkCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to disconnect a device from it's current network. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class DisconnectFromCurrentNetworkTests : BaseUnitTest() { +internal class DisconnectFromCurrentNetworkTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks() { mockWiseFyPrechecksUtil.disconnectFromCurrentNetwork_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/EnableWifiTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.kt similarity index 89% rename from wisefy/src/test/java/com/isupatches/wisefy/EnableWifiTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.kt index b152d657..17464c60 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/EnableWifiTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.EnableWifiCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to enable a device's wifi. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class EnableWifiTests : BaseUnitTest() { +internal class EnableWifiTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks() { mockWiseFyPrechecksUtil.enableWifi_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/GetCurrentNetworkInfoTest.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkInfoTest.kt similarity index 90% rename from wisefy/src/test/java/com/isupatches/wisefy/GetCurrentNetworkInfoTest.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkInfoTest.kt index c7f07d9c..824f6e47 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/GetCurrentNetworkInfoTest.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkInfoTest.kt @@ -1,33 +1,27 @@ package com.isupatches.wisefy import android.net.NetworkInfo -import android.os.Build import com.isupatches.wisefy.callbacks.GetCurrentNetworkInfoCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Assert.fail import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to retrieve a device's current network information. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class GetCurrentNetworkInfoTest : BaseUnitTest() { +internal class GetCurrentNetworkInfoTest : BaseInstrumentationTest() { @Test fun sync_failure_prechecks() { mockWiseFyPrechecksUtil.getCurrentNetworkInfo_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/GetCurrentNetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.kt similarity index 90% rename from wisefy/src/test/java/com/isupatches/wisefy/GetCurrentNetworkTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.kt index f9e2670e..32569c7c 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/GetCurrentNetworkTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.kt @@ -1,31 +1,24 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.GetCurrentNetworkCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assert.fail import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to retrieve a device's current network. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class GetCurrentNetworkTests : BaseUnitTest() { +internal class GetCurrentNetworkTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks() { mockWiseFyPrechecksUtil.getCurrentNetwork_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/GetFrequencyTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.kt similarity index 92% rename from wisefy/src/test/java/com/isupatches/wisefy/GetFrequencyTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.kt index 8f17c7ea..2da052a8 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/GetFrequencyTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.kt @@ -5,29 +5,33 @@ import android.os.Build import com.isupatches.wisefy.callbacks.GetFrequencyCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assert.fail +import org.junit.Assume +import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.after import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to retrieve a network's frequency. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.LOLLIPOP]) -internal class GetFrequencyTests : BaseUnitTest() { +internal class GetFrequencyTests : BaseInstrumentationTest() { + + @Before fun setup() { + Assume.assumeTrue( + "Can only run on API Level 21 or newer", + Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP + ) + } @Test fun sync_getFrequency_currentNetwork_failure() { mockWiseFyPrechecksUtil.getCurrentNetwork_success() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/GetIPTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetIPTests.kt similarity index 88% rename from wisefy/src/test/java/com/isupatches/wisefy/GetIPTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/GetIPTests.kt index dbdd214d..a65815af 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/GetIPTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetIPTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.GetIPCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to get the IP of a device. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class GetIPTests : BaseUnitTest() { +internal class GetIPTests : BaseInstrumentationTest() { @Test fun sync_getIP_failure_missingPrerequisites() { mockWiseFyPrechecksUtil.getIP_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.kt similarity index 94% rename from wisefy/src/test/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.kt index dbeb9e28..965f4fcc 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to retrieve a list of nearby access points for a device. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class GetNearbyAccessPointsTests : BaseUnitTest() { +internal class GetNearbyAccessPointsTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks_filterDuplicates_false() { mockWiseFyPrechecksUtil.getNearbyAccessPoints_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/GetRSSITests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetRSSITests.kt similarity index 94% rename from wisefy/src/test/java/com/isupatches/wisefy/GetRSSITests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/GetRSSITests.kt index 06038a63..2df3dfe3 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/GetRSSITests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetRSSITests.kt @@ -1,31 +1,24 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.GetRSSICallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assert.fail import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to retrieve the RSSI for a nearby access point. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class GetRSSITests : BaseUnitTest() { +internal class GetRSSITests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks_takeHighest_false() { mockWiseFyPrechecksUtil.getRSSI_failure() diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.kt new file mode 100644 index 00000000..207843d7 --- /dev/null +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.kt @@ -0,0 +1,96 @@ +package com.isupatches.wisefy + +import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks +import com.isupatches.wisefy.constants.MISSING_PARAMETER +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest + +import org.junit.Assert.assertEquals +import org.junit.Test + +import org.mockito.Mockito.mock +import org.mockito.Mockito.timeout +import org.mockito.Mockito.verify + +/** + * Tests the ability to retrieve a list of saved networks on a device. + * + * @author Patches + * @since 3.0 + */ +internal class GetSavedNetworksTests : BaseInstrumentationTest() { + + @Test fun sync_failure_prechecks() { + mockWiseFyPrechecksUtil.getSavedNetworks_failure() + assertEquals(null, wisefy.getSavedNetworks()) + verificationUtil.didNotTryToGetSavedNetworks() + } + + @Test fun sync_success() { + mockWiseFyPrechecksUtil.getSavedNetworks_success() + val savedNetworks = mockNetworkUtil.savedNetworks() + assertEquals(savedNetworks, wisefy.getSavedNetworks()) + verificationUtil.triedToGetSavedNetworks() + } + + @Test fun async_failure_prechecks() { + mockWiseFyPrechecksUtil.getSavedNetworks_failure() + val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) + wisefy.getSavedNetworks(mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER) + verificationUtil.didNotTryToGetSavedNetworks() + } + + @Test fun async_failure_prechecks_nullCallback() { + mockWiseFyPrechecksUtil.getSavedNetworks_failure() + nullCallbackUtil.callGetSavedNetworks() + verificationUtil.didNotTryToGetSavedNetworks() + } + + @Test fun async_failure_nullSavedNetworks() { + mockWiseFyPrechecksUtil.getSavedNetworks_success() + mockNetworkUtil.savedNetworks_nullList() + val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) + wisefy.getSavedNetworks(mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).noSavedNetworksFound() + verificationUtil.triedToGetSavedNetworks() + } + + @Test fun async_failure_nullSavedNetworks_nullCallback() { + mockWiseFyPrechecksUtil.getSavedNetworks_success() + mockNetworkUtil.savedNetworks_nullList() + nullCallbackUtil.callGetSavedNetworks() + verificationUtil.triedToGetSavedNetworks() + } + + @Test fun async_failure_emptyConfiguredNetworks() { + mockWiseFyPrechecksUtil.getSavedNetworks_success() + mockNetworkUtil.savedNetworks_emptyList() + val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) + wisefy.getSavedNetworks(mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).noSavedNetworksFound() + verificationUtil.triedToGetSavedNetworks() + } + + @Test fun async_failure_emptyConfiguredNetworks_nullCallback() { + mockWiseFyPrechecksUtil.getSavedNetworks_success() + mockNetworkUtil.savedNetworks_emptyList() + nullCallbackUtil.callGetSavedNetworks() + verificationUtil.triedToGetSavedNetworks() + } + + @Test fun async_success() { + mockWiseFyPrechecksUtil.getSavedNetworks_success() + val savedNetworks = mockNetworkUtil.savedNetworks() + val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) + wisefy.getSavedNetworks(mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).retrievedSavedNetworks(savedNetworks) + verificationUtil.triedToGetSavedNetworks() + } + + @Test fun async_success_nullCallback() { + mockWiseFyPrechecksUtil.getSavedNetworks_success() + mockNetworkUtil.savedNetworks() + nullCallbackUtil.callGetSavedNetworks() + verificationUtil.triedToGetSavedNetworks() + } +} diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToMobileNetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileNetworkTests.kt similarity index 72% rename from wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToMobileNetworkTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileNetworkTests.kt index 6eae86bc..99af9a0f 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToMobileNetworkTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileNetworkTests.kt @@ -1,25 +1,18 @@ package com.isupatches.wisefy -import android.os.Build - -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a device is connected to a mobile network. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsDeviceConnectedToMobileNetworkTests : BaseUnitTest() { +internal class IsDeviceConnectedToMobileNetworkTests : BaseInstrumentationTest() { @Test fun failure_prechecks() { mockWiseFyPrechecksUtil.isDeviceConnectedToMobileNetwork_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToMobileOrWifiNetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileOrWifiNetworkTests.kt similarity index 77% rename from wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToMobileOrWifiNetworkTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileOrWifiNetworkTests.kt index 49658b9f..b6ddba84 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToMobileOrWifiNetworkTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileOrWifiNetworkTests.kt @@ -1,25 +1,18 @@ package com.isupatches.wisefy -import android.os.Build - -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a device is connected to a mobile or wifi network. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsDeviceConnectedToMobileOrWifiNetworkTests : BaseUnitTest() { +internal class IsDeviceConnectedToMobileOrWifiNetworkTests : BaseInstrumentationTest() { @Test fun failure_missingPrerequisite() { mockWiseFyPrechecksUtil.isDeviceConnectedToMobileOrWifiNetwork_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToSSIDTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToSSIDTests.kt similarity index 72% rename from wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToSSIDTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToSSIDTests.kt index 2a7c1bb4..81418dc4 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToSSIDTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToSSIDTests.kt @@ -1,25 +1,18 @@ package com.isupatches.wisefy -import android.os.Build - -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a device is connected to an SSID. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsDeviceConnectedToSSIDTests : BaseUnitTest() { +internal class IsDeviceConnectedToSSIDTests : BaseInstrumentationTest() { @Test fun failure_prechecks() { mockWiseFyPrechecksUtil.isDeviceConnectedToSSIDChecks_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToWifiNetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToWifiNetworkTests.kt similarity index 72% rename from wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToWifiNetworkTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToWifiNetworkTests.kt index 7c1d136c..129b2b1c 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsDeviceConnectedToWifiNetworkTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToWifiNetworkTests.kt @@ -1,25 +1,18 @@ package com.isupatches.wisefy -import android.os.Build - -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a device is connected to a wifi network. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsDeviceConnectedToWifiNetworkTests : BaseUnitTest() { +internal class IsDeviceConnectedToWifiNetworkTests : BaseInstrumentationTest() { @Test fun failure_missingPrerequisite() { mockWiseFyPrechecksUtil.isDeviceConnectedToWifiNetwork_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsDeviceRoamingTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceRoamingTests.kt similarity index 69% rename from wisefy/src/test/java/com/isupatches/wisefy/IsDeviceRoamingTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceRoamingTests.kt index 243a0530..afecd339 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsDeviceRoamingTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceRoamingTests.kt @@ -1,25 +1,18 @@ package com.isupatches.wisefy -import android.os.Build - -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a device is roaming. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsDeviceRoamingTests : BaseUnitTest() { +internal class IsDeviceRoamingTests : BaseInstrumentationTest() { @Test fun failure_missingPrerequisite() { mockWiseFyPrechecksUtil.isDeviceRoaming_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsNetwork5gHzTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.kt similarity index 81% rename from wisefy/src/test/java/com/isupatches/wisefy/IsNetwork5gHzTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.kt index d9202b8a..f96118fe 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsNetwork5gHzTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.kt @@ -2,30 +2,25 @@ package com.isupatches.wisefy import android.os.Build -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assume.assumeTrue import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a network is 5 gHz. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsNetwork5gHzTests : BaseUnitTest() { +internal class IsNetwork5gHzTests : BaseInstrumentationTest() { - @Before fun setup() { + @Before fun setUp() { assumeTrue( - "Can only run on API Level 21 or newer", - Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP + "Can only run on API Level 21 or newer", + Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) } diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkEAPTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkEAPTests.kt similarity index 77% rename from wisefy/src/test/java/com/isupatches/wisefy/IsNetworkEAPTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkEAPTests.kt index aaf06c1f..4e8267ed 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkEAPTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkEAPTests.kt @@ -1,26 +1,19 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.constants.EAP -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import com.isupatches.wisefy.internal.createMockAccessPointWithCapabilities import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a network has EAP security. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsNetworkEAPTests : BaseUnitTest() { +internal class IsNetworkEAPTests : BaseInstrumentationTest() { @Test fun failure_differentCapability() { val scanResult = createMockAccessPointWithCapabilities("Other") diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkPSKTest.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkPSKTest.kt similarity index 77% rename from wisefy/src/test/java/com/isupatches/wisefy/IsNetworkPSKTest.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkPSKTest.kt index a36d28b2..8a978719 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkPSKTest.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkPSKTest.kt @@ -1,26 +1,19 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.constants.PSK -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import com.isupatches.wisefy.internal.createMockAccessPointWithCapabilities import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a network has PSK security. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsNetworkPSKTest : BaseUnitTest() { +internal class IsNetworkPSKTest : BaseInstrumentationTest() { @Test fun failure_differentCapability() { val scanResult = createMockAccessPointWithCapabilities("Other") diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkSavedTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkSavedTests.kt similarity index 71% rename from wisefy/src/test/java/com/isupatches/wisefy/IsNetworkSavedTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkSavedTests.kt index e2aa5def..950bee3e 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkSavedTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkSavedTests.kt @@ -1,24 +1,17 @@ package com.isupatches.wisefy -import android.os.Build - -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a network is in a device's list of saved networks. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsNetworkSavedTests : BaseUnitTest() { +internal class IsNetworkSavedTests : BaseInstrumentationTest() { @Test fun failure_missingPrerequisite() { mockWiseFyPrechecksUtil.isNetworkSaved_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkSecureTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkSecureTests.kt similarity index 85% rename from wisefy/src/test/java/com/isupatches/wisefy/IsNetworkSecureTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkSecureTests.kt index 24393dc3..7cb2ba69 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkSecureTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkSecureTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.constants.EAP import com.isupatches.wisefy.constants.PSK import com.isupatches.wisefy.constants.WEP import com.isupatches.wisefy.constants.WPA import com.isupatches.wisefy.constants.WPA2 -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import com.isupatches.wisefy.internal.createMockAccessPointWithCapabilities import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a network is secure. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsNetworkSecureTests : BaseUnitTest() { +internal class IsNetworkSecureTests : BaseInstrumentationTest() { @Test fun failure_emptyCapabilities() { val scanResult = createMockAccessPointWithCapabilities("") diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkWPA2Test.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPA2Test.kt similarity index 77% rename from wisefy/src/test/java/com/isupatches/wisefy/IsNetworkWPA2Test.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPA2Test.kt index 4a1ad500..2daf3770 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkWPA2Test.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPA2Test.kt @@ -1,26 +1,19 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.constants.WPA2 -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import com.isupatches.wisefy.internal.createMockAccessPointWithCapabilities import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a network has WPA2 security. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsNetworkWPA2Test : BaseUnitTest() { +internal class IsNetworkWPA2Test : BaseInstrumentationTest() { @Test fun failure_differentCapability() { val scanResult = createMockAccessPointWithCapabilities("Other") diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkWPATests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPATests.kt similarity index 77% rename from wisefy/src/test/java/com/isupatches/wisefy/IsNetworkWPATests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPATests.kt index c1298435..12f13c1f 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkWPATests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPATests.kt @@ -1,26 +1,19 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.constants.WPA -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import com.isupatches.wisefy.internal.createMockAccessPointWithCapabilities import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a network has WPA security. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsNetworkWPATests : BaseUnitTest() { +internal class IsNetworkWPATests : BaseInstrumentationTest() { @Test fun failure_differentCapability() { val scanResult = createMockAccessPointWithCapabilities("Other") diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkWepTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWepTests.kt similarity index 77% rename from wisefy/src/test/java/com/isupatches/wisefy/IsNetworkWepTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWepTests.kt index 2c6118a4..bd0cc5ca 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsNetworkWepTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWepTests.kt @@ -1,26 +1,19 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.constants.WEP -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import com.isupatches.wisefy.internal.createMockAccessPointWithCapabilities import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if a network has WEP security. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsNetworkWepTests : BaseUnitTest() { +internal class IsNetworkWepTests : BaseInstrumentationTest() { @Test fun failure_differentCapability() { val scanResult = createMockAccessPointWithCapabilities("Other") diff --git a/wisefy/src/test/java/com/isupatches/wisefy/IsWifiEnabledTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsWifiEnabledTests.kt similarity index 68% rename from wisefy/src/test/java/com/isupatches/wisefy/IsWifiEnabledTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/IsWifiEnabledTests.kt index a7773872..30ac8be6 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/IsWifiEnabledTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsWifiEnabledTests.kt @@ -1,24 +1,17 @@ package com.isupatches.wisefy -import android.os.Build - -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests the ability to determine if wifi is enabled on a device. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class IsWifiEnabledTests : BaseUnitTest() { +internal class IsWifiEnabledTests : BaseInstrumentationTest() { @Test fun failure_prechecks() { mockWiseFyPrechecksUtil.isWifiEnabled_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/RemoveNetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.kt similarity index 93% rename from wisefy/src/test/java/com/isupatches/wisefy/RemoveNetworkTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.kt index ff5fa344..fd8d3b45 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/RemoveNetworkTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Tests the ability to remove a network from a device's list of saved networks. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class RemoveNetworkTests : BaseUnitTest() { +internal class RemoveNetworkTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks() { mockWiseFyPrechecksUtil.removeNetwork_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/SearchForAccessPointTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointTests.kt similarity index 94% rename from wisefy/src/test/java/com/isupatches/wisefy/SearchForAccessPointTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointTests.kt index 52014d61..4fdd2118 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/SearchForAccessPointTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Used to test the functionality to search for a set of nearby access points. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class SearchForAccessPointTests : BaseUnitTest() { +internal class SearchForAccessPointTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks_filterDuplicates_false() { mockWiseFyPrechecksUtil.searchForAccessPoint_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/SearchForAccessPointsTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointsTests.kt similarity index 94% rename from wisefy/src/test/java/com/isupatches/wisefy/SearchForAccessPointsTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointsTests.kt index 430170b7..53f541fa 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/SearchForAccessPointsTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointsTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Used to test the functionality to search for a nearby access point. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class SearchForAccessPointsTests : BaseUnitTest() { +internal class SearchForAccessPointsTests : BaseInstrumentationTest() { @Test fun sync_failure_prechecks_filterDuplicates_false() { mockWiseFyPrechecksUtil.searchForAccessPoints_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/SearchForSSIDTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDTests.kt similarity index 89% rename from wisefy/src/test/java/com/isupatches/wisefy/SearchForSSIDTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDTests.kt index dc17cb47..cad23bbf 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/SearchForSSIDTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Used to test the functionality to search for SSIDs nearby. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class SearchForSSIDTests : BaseUnitTest() { +internal class SearchForSSIDTests : BaseInstrumentationTest() { @Test fun sync_failure_missingPrerequisite() { mockWiseFyPrechecksUtil.searchForSSID_failure() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/SearchForSSIDsTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDsTests.kt similarity index 89% rename from wisefy/src/test/java/com/isupatches/wisefy/SearchForSSIDsTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDsTests.kt index a381b8d9..e6ea0516 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/SearchForSSIDsTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDsTests.kt @@ -1,30 +1,23 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - /** * Used to test the functionality to search for SSIDs nearby. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class SearchForSSIDsTests : BaseUnitTest() { +internal class SearchForSSIDsTests : BaseInstrumentationTest() { @Test fun sync_failure_precheck() { mockWiseFyPrechecksUtil.searchForSSIDs_failure() diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSavedNetworkTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSavedNetworkTests.kt new file mode 100644 index 00000000..d7cf2d9f --- /dev/null +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSavedNetworkTests.kt @@ -0,0 +1,79 @@ +package com.isupatches.wisefy + +import com.isupatches.wisefy.callbacks.SearchForSavedNetworkCallbacks +import com.isupatches.wisefy.constants.MISSING_PARAMETER + +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest + +import org.junit.Assert.assertEquals +import org.junit.Test + +import org.mockito.Mockito.mock +import org.mockito.Mockito.timeout +import org.mockito.Mockito.verify + +/** + * Tests the ability to search for a saved network on a device. + * + * @author Patches + * @since 4.0 + */ +internal class SearchForSavedNetworkTests : BaseInstrumentationTest() { + + @Test fun sync_failure_prechecks() { + mockWiseFyPrechecksUtil.searchForSavedNetwork_failure() + assertEquals(null, wisefy.searchForSavedNetwork(TEST_SSID)) + } + + @Test fun sync_failure() { + mockWiseFyPrechecksUtil.searchForSavedNetwork_success() + mockWiseFySearchUtil.findSavedNetworkByRegex_null() + assertEquals(null, wisefy.searchForSavedNetwork(TEST_SSID)) + } + + @Test fun sync_success() { + mockWiseFyPrechecksUtil.searchForSavedNetwork_success() + val savedNetwork = mockWiseFySearchUtil.findSavedNetworkByRegex_success() + assertEquals(savedNetwork, wisefy.searchForSavedNetwork(TEST_SSID)) + } + + @Test fun async_failure_prechecks() { + mockWiseFyPrechecksUtil.searchForSavedNetwork_failure() + val mockCallbacks = mock(SearchForSavedNetworkCallbacks::class.java) + wisefy.searchForSavedNetwork(TEST_SSID, mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER) + } + + @Test fun async_failure_prechecks_nullCallback() { + mockWiseFyPrechecksUtil.searchForSavedNetwork_failure() + nullCallbackUtil.callSearchForSavedNetwork(TEST_SSID) + } + + @Test fun async_failure() { + mockWiseFyPrechecksUtil.searchForSavedNetwork_success() + mockWiseFySearchUtil.findSavedNetworkByRegex_null() + val mockCallbacks = mock(SearchForSavedNetworkCallbacks::class.java) + wisefy.searchForSavedNetwork(TEST_SSID, mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).savedNetworkNotFound() + } + + @Test fun async_failure_nullCallback() { + mockWiseFyPrechecksUtil.searchForSavedNetwork_success() + mockWiseFySearchUtil.findSavedNetworkByRegex_null() + nullCallbackUtil.callSearchForSavedNetwork(TEST_SSID) + } + + @Test fun async_success() { + mockWiseFyPrechecksUtil.searchForSavedNetwork_success() + val savedNetwork = mockWiseFySearchUtil.findSavedNetworkByRegex_success() + val mockCallbacks = mock(SearchForSavedNetworkCallbacks::class.java) + wisefy.searchForSavedNetwork(TEST_SSID, mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).retrievedSavedNetwork(savedNetwork) + } + + @Test fun async_success_nullCallback() { + mockWiseFyPrechecksUtil.searchForSavedNetwork_success() + mockWiseFySearchUtil.findSavedNetworkByRegex_success() + nullCallbackUtil.callSearchForSavedNetwork(TEST_SSID) + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSavedNetworksTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSavedNetworksTests.kt new file mode 100644 index 00000000..896c1ac7 --- /dev/null +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSavedNetworksTests.kt @@ -0,0 +1,88 @@ +package com.isupatches.wisefy + +import com.isupatches.wisefy.callbacks.SearchForSavedNetworksCallbacks +import com.isupatches.wisefy.constants.MISSING_PARAMETER +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest + +import org.junit.Assert.assertEquals +import org.junit.Test + +import org.mockito.Mockito.mock +import org.mockito.Mockito.timeout +import org.mockito.Mockito.verify + +/** + * Tests the ability to search for saved networks on a device. + * + * @author Patches + * @since 4.0 + */ +internal class SearchForSavedNetworksTests : BaseInstrumentationTest() { + + @Test fun sync_failure_prechecks() { + mockWiseFyPrechecksUtil.searchForSavedNetworks_failure() + assertEquals(null, wisefy.searchForSavedNetworks(TEST_SSID)) + verificationUtil.didNotTryToGetSavedNetworks() + } + + @Test fun sync_success() { + mockWiseFyPrechecksUtil.searchForSavedNetworks_success() + val savedNetwork = mockWiseFySearchUtil.findSavedNetworksMatchingRegex_success() + assertEquals(savedNetwork, wisefy.searchForSavedNetworks(TEST_SSID)) + } + + @Test fun async_failure_prechecks() { + mockWiseFyPrechecksUtil.searchForSavedNetworks_failure() + val mockCallbacks = mock(SearchForSavedNetworksCallbacks::class.java) + wisefy.searchForSavedNetworks(TEST_SSID, mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER) + } + + @Test fun async_failure_prechecks_nullCallback() { + mockWiseFyPrechecksUtil.searchForSavedNetworks_failure() + nullCallbackUtil.callSearchForSavedNetworks(TEST_SSID) + wisefy.searchForSavedNetworks(TEST_SSID, null) + } + + @Test fun async_failure_nullSavedNetworks() { + mockWiseFyPrechecksUtil.searchForSavedNetworks_success() + mockWiseFySearchUtil.findSavedNetworksByRegex_null() + val mockCallbacks = mock(SearchForSavedNetworksCallbacks::class.java) + wisefy.searchForSavedNetworks(TEST_SSID, mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).noSavedNetworksFound() + } + + @Test fun async_failure_nullSavedNetworks_nullCallback() { + mockWiseFyPrechecksUtil.searchForSavedNetworks_success() + mockWiseFySearchUtil.findSavedNetworksByRegex_null() + nullCallbackUtil.callSearchForSavedNetworks(TEST_SSID) + } + + @Test fun async_failure_emptyConfiguredNetworks() { + mockWiseFyPrechecksUtil.searchForSavedNetworks_success() + mockWiseFySearchUtil.findSavedNetworksByRegex_emptyList() + val mockCallbacks = mock(SearchForSavedNetworksCallbacks::class.java) + wisefy.searchForSavedNetworks(TEST_SSID, mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).noSavedNetworksFound() + } + + @Test fun async_failure_emptyConfiguredNetworks_nullCallback() { + mockWiseFyPrechecksUtil.searchForSavedNetworks_success() + mockWiseFySearchUtil.findSavedNetworksByRegex_emptyList() + nullCallbackUtil.callSearchForSavedNetworks(TEST_SSID) + } + + @Test fun async_success() { + mockWiseFyPrechecksUtil.searchForSavedNetworks_success() + val savedNetworks = mockWiseFySearchUtil.findSavedNetworksMatchingRegex_success() + val mockCallbacks = mock(SearchForSavedNetworksCallbacks::class.java) + wisefy.searchForSavedNetworks(TEST_SSID, mockCallbacks) + verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).retrievedSavedNetworks(savedNetworks) + } + + @Test fun async_success_nullCallbacks() { + mockWiseFyPrechecksUtil.searchForSavedNetworks_success() + mockWiseFySearchUtil.findSavedNetworksMatchingRegex_success() + nullCallbackUtil.callSearchForSavedNetworks(TEST_SSID) + } +} diff --git a/wisefy/src/test/java/com/isupatches/wisefy/WiseFyPrechecksTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyPrechecksTests.kt similarity index 96% rename from wisefy/src/test/java/com/isupatches/wisefy/WiseFyPrechecksTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyPrechecksTests.kt index 7aecd023..f344a8ea 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/WiseFyPrechecksTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyPrechecksTests.kt @@ -1,28 +1,21 @@ package com.isupatches.wisefy -import android.os.Build - import com.isupatches.wisefy.constants.DEFAULT_PRECHECK_RETURN_CODE import com.isupatches.wisefy.constants.MISSING_PARAMETER import com.isupatches.wisefy.constants.NETWORK_ALREADY_CONFIGURED -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Used to test the WiseFyPrechecks class and functionality pertaining to being able to continue * with processing logic. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class WiseFyPrechecksTests : BaseUnitTest() { +internal class WiseFyPrechecksTests : BaseInstrumentationTest() { private val wisefyPrechecks: WiseFyPrechecks = WiseFyPrechecksImpl.create(mockWiseFySearch) diff --git a/wisefy/src/test/java/com/isupatches/wisefy/WiseFyTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.kt similarity index 80% rename from wisefy/src/test/java/com/isupatches/wisefy/WiseFyTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.kt index cbfed2b1..9c52dfb1 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/WiseFyTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.kt @@ -1,26 +1,20 @@ package com.isupatches.wisefy -import android.os.Build import androidx.test.platform.app.InstrumentationRegistry -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Tests that pertain to the builder for WiseFy or general use. * * @author Patches + * @since 3.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class WiseFyTests : BaseUnitTest() { +internal class WiseFyTests : BaseInstrumentationTest() { companion object { private const val EXPECTED_NUMBER_OF_BARS = 4 diff --git a/wisefy/src/test/java/com/isupatches/wisefy/connection/WiseFyConnectionLegacyTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/connection/WiseFyConnectionLegacyTests.kt similarity index 95% rename from wisefy/src/test/java/com/isupatches/wisefy/connection/WiseFyConnectionLegacyTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/connection/WiseFyConnectionLegacyTests.kt index ceda633d..3417a2e1 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/connection/WiseFyConnectionLegacyTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/connection/WiseFyConnectionLegacyTests.kt @@ -1,33 +1,27 @@ package com.isupatches.wisefy.connection -import android.os.Build - import com.isupatches.wisefy.TEST_SSID import com.isupatches.wisefy.TEST_SSID2 import com.isupatches.wisefy.TEST_TIMEOUT -import com.isupatches.wisefy.TEST_TYPE1 import com.isupatches.wisefy.constants.MOBILE import com.isupatches.wisefy.constants.WIFI -import com.isupatches.wisefy.internal.base.BaseUnitTest -import org.junit.After +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest +import org.junit.After import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Used to test the WiseFyConnectionLegacy class and functionality determining various connection states. * + * @see WiseFyConnectionLegacy + * * @author Patches + * @since 4.0 */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.JELLY_BEAN]) -internal class WiseFyConnectionLegacyTests : BaseUnitTest() { +internal class WiseFyConnectionLegacyTests : BaseInstrumentationTest() { private val wisefyConnection = WiseFyConnectionLegacy.create( mockConnectivityManager, @@ -35,7 +29,6 @@ internal class WiseFyConnectionLegacyTests : BaseUnitTest() { ) @Before fun setUp() { - super.tearDown() wisefyConnection.init() } @@ -282,31 +275,31 @@ internal class WiseFyConnectionLegacyTests : BaseUnitTest() { } @Test fun waitToConnectToSSID_failure_differentSSID() { - mockNetworkUtil.currentNetworkConnectionStatus(true, true, TEST_TYPE1) + mockNetworkUtil.currentNetworkConnectionStatus(true, true, WIFI) mockNetworkUtil.currentNetwork(TEST_SSID2) assertFalse(wisefyConnection.waitToConnectToSSID(TEST_SSID, TEST_TIMEOUT)) } @Test fun waitToConnectToSSID_failure_notAvailable() { - mockNetworkUtil.currentNetworkConnectionStatus(false, true, TEST_TYPE1) + mockNetworkUtil.currentNetworkConnectionStatus(false, true, WIFI) mockNetworkUtil.currentNetwork(TEST_SSID) assertFalse(wisefyConnection.waitToConnectToSSID(TEST_SSID, TEST_TIMEOUT)) } @Test fun waitToConnectToSSID_failure_notAvailableOrConnected() { - mockNetworkUtil.currentNetworkConnectionStatus(false, false, TEST_TYPE1) + mockNetworkUtil.currentNetworkConnectionStatus(false, false, WIFI) mockNetworkUtil.currentNetwork(TEST_SSID) assertFalse(wisefyConnection.waitToConnectToSSID(TEST_SSID, TEST_TIMEOUT)) } @Test fun waitToConnectToSSID_failure_notConnected() { - mockNetworkUtil.currentNetworkConnectionStatus(true, false, TEST_TYPE1) + mockNetworkUtil.currentNetworkConnectionStatus(true, false, WIFI) mockNetworkUtil.currentNetwork(TEST_SSID) assertFalse(wisefyConnection.waitToConnectToSSID(TEST_SSID, TEST_TIMEOUT)) } @Test fun waitToConnectToSSID_success() { - mockNetworkUtil.currentNetworkConnectionStatus(true, true, TEST_TYPE1) + mockNetworkUtil.currentNetworkConnectionStatus(true, true, WIFI) mockNetworkUtil.currentNetwork(TEST_SSID) assertTrue(wisefyConnection.waitToConnectToSSID(TEST_SSID, TEST_TIMEOUT)) } diff --git a/wisefy/src/test/java/com/isupatches/wisefy/connection/WisefyConnectionSDK23Tests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/connection/WisefyConnectionSDK23Tests.kt similarity index 76% rename from wisefy/src/test/java/com/isupatches/wisefy/connection/WisefyConnectionSDK23Tests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/connection/WisefyConnectionSDK23Tests.kt index 90c35aa8..e069e640 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/connection/WisefyConnectionSDK23Tests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/connection/WisefyConnectionSDK23Tests.kt @@ -6,8 +6,9 @@ import android.os.Build import com.isupatches.wisefy.TEST_SSID import com.isupatches.wisefy.TEST_SSID2 import com.isupatches.wisefy.TEST_TIMEOUT -import com.isupatches.wisefy.internal.base.BaseUnitTest +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import com.isupatches.wisefy.internal.getNetworkCapabilities +import com.isupatches.wisefy.internal.setUpNetworkCapabilities import org.junit.After import org.junit.Assert.assertFalse @@ -15,31 +16,38 @@ import org.junit.Assert.assertTrue import org.junit.Assume.assumeTrue import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mockito.`when` import org.mockito.Mockito.mock -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config +/** + * Used to test the WiseFyConnectionSDK23 class and functionality determining various connection states. + * + * @see WiseFyConnectionSDK23 + * + * @author Patches + * @since 4.0 + */ +internal class WisefyConnectionSDK23Tests : BaseInstrumentationTest() { -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class WisefyConnectionSDK23Tests : BaseUnitTest() { - - private val wisefyConnection = WiseFyConnectionSDK23.create( - mockConnectivityManager, - mockWifiManager - ) + private val wisefyConnection by lazy { + WiseFyConnectionSDK23.create(mockConnectivityManager, mockWifiManager) + } @Before fun setUp() { - super.tearDown() - wisefyConnection.init() + assumeTrue( + "Can only run on API Level 23 or newer", + Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + ) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + wisefyConnection.init() + } } @After override fun tearDown() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + wisefyConnection.destroy() + } super.tearDown() - wisefyConnection.destroy() } /* @@ -136,7 +144,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { android.net.NetworkCapabilities.TRANSPORT_WIFI, arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET) ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertFalse(wisefyConnection.isDeviceConnectedToMobileNetwork()) } @@ -145,7 +157,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { val networkCapabilities = getNetworkCapabilities( android.net.NetworkCapabilities.TRANSPORT_CELLULAR ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertFalse(wisefyConnection.isDeviceConnectedToMobileNetwork()) } @@ -155,7 +171,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { android.net.NetworkCapabilities.TRANSPORT_CELLULAR, arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET) ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertFalse(wisefyConnection.isDeviceConnectedToMobileNetwork()) } @@ -165,7 +185,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { android.net.NetworkCapabilities.TRANSPORT_CELLULAR, arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET) ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertFalse(wisefyConnection.isDeviceConnectedToMobileNetwork()) } @@ -175,7 +199,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { android.net.NetworkCapabilities.TRANSPORT_CELLULAR, arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET) ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertFalse(wisefyConnection.isDeviceConnectedToMobileNetwork()) } @@ -185,7 +213,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { android.net.NetworkCapabilities.TRANSPORT_CELLULAR, arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET) ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertTrue(wisefyConnection.isDeviceConnectedToMobileNetwork()) } @@ -208,7 +240,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { android.net.NetworkCapabilities.TRANSPORT_CELLULAR, arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET) ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertFalse(wisefyConnection.isDeviceConnectedToWifiNetwork()) } @@ -217,7 +253,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { val networkCapabilities = getNetworkCapabilities( android.net.NetworkCapabilities.TRANSPORT_WIFI ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertFalse(wisefyConnection.isDeviceConnectedToWifiNetwork()) } @@ -227,7 +267,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { android.net.NetworkCapabilities.TRANSPORT_WIFI, arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET) ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertFalse(wisefyConnection.isDeviceConnectedToWifiNetwork()) } @@ -237,7 +281,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { android.net.NetworkCapabilities.TRANSPORT_WIFI, arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET) ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertFalse(wisefyConnection.isDeviceConnectedToWifiNetwork()) } @@ -247,7 +295,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { android.net.NetworkCapabilities.TRANSPORT_WIFI, arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET) ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertFalse(wisefyConnection.isDeviceConnectedToWifiNetwork()) } @@ -257,7 +309,11 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { android.net.NetworkCapabilities.TRANSPORT_WIFI, arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET) ) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) assertTrue(wisefyConnection.isDeviceConnectedToWifiNetwork()) } @@ -267,16 +323,16 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { @Test fun isDeviceRoaming_failure_nullNetworkInfo() { assumeTrue( - "Can only run on API's before Level 28", - Build.VERSION.SDK_INT < Build.VERSION_CODES.P + "Can only run on API's before Level 28", + Build.VERSION.SDK_INT < Build.VERSION_CODES.P ) assertFalse(wisefyConnection.isDeviceRoaming()) } @Test fun isDeviceRoaming_failure() { assumeTrue( - "Can only run on API's before Level 28", - Build.VERSION.SDK_INT < Build.VERSION_CODES.P + "Can only run on API's before Level 28", + Build.VERSION.SDK_INT < Build.VERSION_CODES.P ) mockNetworkUtil.currentNetwork(TEST_SSID) mockNetworkUtil.isDeviceRoaming(false) @@ -285,15 +341,14 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { @Test fun isDeviceRoaming_success() { assumeTrue( - "Can only run on API's before Level 28", - Build.VERSION.SDK_INT < Build.VERSION_CODES.P + "Can only run on API's before Level 28", + Build.VERSION.SDK_INT < Build.VERSION_CODES.P ) mockNetworkUtil.currentNetwork(TEST_SSID) mockNetworkUtil.isDeviceRoaming(true) assertTrue(wisefyConnection.isDeviceRoaming()) } - @Config(sdk = [Build.VERSION_CODES.P]) @Test fun isDeviceRoaming_sdk28_failure_nullNetwork() { assumeTrue( "Can only run on API Level 28 or newer", @@ -303,26 +358,34 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { assertTrue(wisefyConnection.isDeviceRoaming()) } - @Config(sdk = [Build.VERSION_CODES.P]) @Test fun isDeviceRoaming_sdk28_failure_missingNotRoamingCapability() { assumeTrue( "Can only run on API Level 28 or newer", Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ) val networkCapabilities = android.net.NetworkCapabilities(null) - setUpNetworkCapabilities(networkCapabilities) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities + ) mockNetworkUtil.isDeviceRoaming(false) assertTrue(wisefyConnection.isDeviceRoaming()) } - @Config(sdk = [Build.VERSION_CODES.P]) @Test fun isDeviceRoaming_sdk28_success() { assumeTrue( - "Can only run on API Level 28 or newer", - Build.VERSION.SDK_INT >= Build.VERSION_CODES.P + "Can only run on API Level 28 or newer", + Build.VERSION.SDK_INT >= Build.VERSION_CODES.P + ) + val networkCapabilities = getNetworkCapabilities( + arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING) + ) + setUpNetworkCapabilities( + wisefyConnection as WiseFyConnectionSDK23, + mockConnectivityManager, + networkCapabilities ) - val networkCapabilities = getNetworkCapabilities(arrayOf(android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING)) - setUpNetworkCapabilities(networkCapabilities) mockNetworkUtil.isDeviceRoaming(true) assertFalse(wisefyConnection.isDeviceRoaming()) } @@ -378,20 +441,6 @@ internal class WisefyConnectionSDK23Tests : BaseUnitTest() { assertTrue(wisefyConnection.waitToConnectToSSID(TEST_SSID, TEST_TIMEOUT)) } - /* - * - */ - - private fun setUpNetworkCapabilities(networkCapabilities: android.net.NetworkCapabilities) { - val network = mock(Network::class.java) - `when`(mockConnectivityManager.activeNetwork).thenReturn(network) - `when`(mockConnectivityManager.getNetworkCapabilities(network)).thenReturn(networkCapabilities) - (wisefyConnection as WiseFyConnectionSDK23).networkChangeCallbacks.onCapabilitiesChanged( - network, - networkCapabilities - ) - } - /* * Connection status helpers */ diff --git a/wisefy/src/test/java/com/isupatches/wisefy/internal/GeneratorUtil.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/GeneratorUtil.kt similarity index 93% rename from wisefy/src/test/java/com/isupatches/wisefy/internal/GeneratorUtil.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/internal/GeneratorUtil.kt index 8e98e153..3a89b12e 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/internal/GeneratorUtil.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/GeneratorUtil.kt @@ -13,6 +13,9 @@ import org.mockito.Mockito.mock * @return ScanResult - A mock access point with the given capabilities * * @see ScanResult + * + * @author Patches + * @since 3.0 */ internal fun createMockAccessPointWithCapabilities(capabilities: String?): ScanResult { val scanResult = mock(ScanResult::class.java) @@ -31,6 +34,9 @@ internal fun createMockAccessPointWithCapabilities(capabilities: String?): ScanR * @return List of ScanResults - The mocked access points * * @see ScanResult + * + * @author Patches + * @since 3.0 */ internal fun createMockAccessPointList( ssid1: String, @@ -52,6 +58,9 @@ internal fun createMockAccessPointList( * @return ScanResult - A mock object representing a nearby access point * * @see ScanResult + * + * @author Patches + * @since 3.0 */ internal fun createMockAccessPointWithSSID(ssid: String?): ScanResult { val scanResult = mock(ScanResult::class.java) @@ -68,6 +77,9 @@ internal fun createMockAccessPointWithSSID(ssid: String?): ScanResult { * @return ScanResult - A mock object representing a nearby access point * * @see ScanResult + * + * @author Patches + * @since 3.0 */ internal fun createMockAccessPointWithSSIDAndRSSI(ssid: String, rssi: Int): ScanResult { val scanResult = mock(ScanResult::class.java) @@ -84,6 +96,9 @@ internal fun createMockAccessPointWithSSIDAndRSSI(ssid: String, rssi: Int): Scan * @return WifiConfiguration - Saved network * * @see WifiConfiguration + * + * @author Patches + * @since 3.0 */ internal fun createSavedNetwork(ssid: String?): WifiConfiguration { val wiFiConfiguration = WifiConfiguration() diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/NetworkCapabilitiesUtil.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/NetworkCapabilitiesUtil.kt new file mode 100644 index 00000000..0cadf0c1 --- /dev/null +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/NetworkCapabilitiesUtil.kt @@ -0,0 +1,113 @@ +package com.isupatches.wisefy.internal + +import android.net.ConnectivityManager +import android.net.Network +import android.net.NetworkCapabilities + +import com.isupatches.wisefy.connection.WiseFyConnectionSDK23 + +import org.mockito.Mockito.`when` +import org.mockito.Mockito.mock + +/** + * To create a NetworkCapabilities instance with a specified transport type. + * + * @param transportType The transport type for the NetworkCapabilities instance + * + * @return NetworkCapabilities - The network capabilities instance with a given transport type + * + * @see NetworkCapabilities + * + * @author Patches + * @since 3.0 + */ +internal fun getNetworkCapabilities(transportType: Int): NetworkCapabilities { + val networkCapabilities = NetworkCapabilities(null) + ReflectionHelpers.callInstanceMethod( + networkCapabilities, + "addTransportType", + ReflectionHelpers.ClassParameter.from(Int::class.java, transportType) + ) + return networkCapabilities +} + +/** + * To create a NetworkCapabilities instance with a specified set of capabilities. + * + * @return NetworkCapabilities - The network capabilities instance with a given transport type + * + * @see NetworkCapabilities + * + * @author Patches + * @since 3.0 + */ +internal fun getNetworkCapabilities(capabilities: Array): NetworkCapabilities { + val networkCapabilities = NetworkCapabilities(null) + for (capability in capabilities) { + ReflectionHelpers.callInstanceMethod( + networkCapabilities, + "addCapability", + ReflectionHelpers.ClassParameter.from(Int::class.java, capability) + ) + } + return networkCapabilities +} + +/** + * To create a NetworkCapabilities instance with a specified transport type and capabilities. + * + * @param transportType The transport type for the NetworkCapabilities instance + * @param capabilities The int array of capabilities for the NetworkCapabilities instance + * + * @return NetworkCapabilities - The network capabilities instance with a given transport type and + * set of capabilities + * + * @see NetworkCapabilities + * + * @author Patches + * @since 3.0 + */ +internal fun getNetworkCapabilities(transportType: Int, capabilities: Array): NetworkCapabilities { + val networkCapabilities = NetworkCapabilities(null) + ReflectionHelpers.callInstanceMethod( + networkCapabilities, + "addTransportType", + ReflectionHelpers.ClassParameter.from(Int::class.java, transportType) + ) + for (capability in capabilities) { + ReflectionHelpers.callInstanceMethod( + networkCapabilities, + "addCapability", + ReflectionHelpers.ClassParameter.from(Int::class.java, capability) + ) + } + return networkCapabilities +} + +/** + * To setup the network capabilities for WisefyConnectionSDK23Tests. + * + * @param wisefyConnection The wisefy connection SDK instance + * @param mockConnectivityManager The mock connectivity manager instance + * @param networkCapabilities The capabilities desired for test + * + * @see ConnectivityManager.getActiveNetwork + * @see WiseFyConnectionSDK23.networkChangeCallbacks + * @see NetworkCapabilities + * + * @author Patches + * @since 4.0 + */ +internal fun setUpNetworkCapabilities( + wisefyConnection: WiseFyConnectionSDK23, + mockConnectivityManager: ConnectivityManager, + networkCapabilities: NetworkCapabilities +) { + val network = mock(Network::class.java) + `when`(mockConnectivityManager.activeNetwork).thenReturn(network) + `when`(mockConnectivityManager.getNetworkCapabilities(network)).thenReturn(networkCapabilities) + wisefyConnection.networkChangeCallbacks.onCapabilitiesChanged( + network, + networkCapabilities + ) +} diff --git a/wisefy/src/test/java/com/isupatches/wisefy/internal/NullCallbackUtil.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/NullCallbackUtil.kt similarity index 83% rename from wisefy/src/test/java/com/isupatches/wisefy/internal/NullCallbackUtil.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/internal/NullCallbackUtil.kt index 5cee47dc..c6f8bd46 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/internal/NullCallbackUtil.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/NullCallbackUtil.kt @@ -14,6 +14,7 @@ import org.junit.Assert.fail * A helper class to call methods in WiseFy with no callbacks. * * @author Patches + * @since 3.0 */ @Suppress("TooGenericExceptionCaught") internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) { @@ -22,6 +23,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * To try to adding an open network with null callbacks. * * @param ssid The ssid to use when adding + * + * @author Patches + * @since 3.0 */ fun callAddOpenNetwork(ssid: String?) { try { @@ -36,6 +40,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * * @param ssid The ssid to use when adding * @param password The password to use when adding + * + * @author Patches + * @since 3.0 */ @Suppress("DEPRECATION") fun callAddWEPNetwork(ssid: String?, password: String?) { @@ -51,6 +58,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * * @param ssid The ssid to use when adding * @param password The password to use when adding + * + * @author Patches + * @since 3.0 */ fun callAddWPA2Network(ssid: String?, password: String?) { try { @@ -66,6 +76,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * @param ssid The ssid to use when connecting * * @see WiseFy.connectToNetwork + * + * @author Patches + * @since 3.0 */ fun callConnectToNetwork(ssid: String?) { try { @@ -79,6 +92,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * To try disable wifi with null callbacks. * * @see WiseFy.disableWifi + * + * @author Patches + * @since 3.0 */ fun callDisableWifi() { try { @@ -92,6 +108,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * To try to disconnect from the current network with null callbacks. * * @see WiseFy.disconnectFromCurrentNetwork + * + * @author Patches + * @since 3.0 */ fun callDisconnectFromCurrentNetwork() { try { @@ -105,6 +124,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * To try to enable wifi with null callbacks. * * @see WiseFy.enableWifi + * + * @author Patches + * @since 3.0 */ fun callEnableWifi() { try { @@ -118,6 +140,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * To try to get the current network with null callbacks. * * @see WiseFy.getCurrentNetwork + * + * @author Patches + * @since 3.0 */ fun callGetCurrentNetwork() { try { @@ -127,6 +152,14 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) } } + /** + * To try to get the current network info with null callbacks. + * + * @see WiseFy.getCurrentNetworkInfo + * + * @author Patches + * @since 3.0 + */ fun callGetCurrentNetworkInfo() { try { wisefy.getCurrentNetworkInfo(null) @@ -139,6 +172,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * To try and get the frequency of a network with null callbacks. * * @see WiseFy.getFrequency + * + * @author Patches + * @since 3.0 */ fun callGetFrequency() { try { @@ -154,6 +190,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * @param network The network to use when trying * * @see WiseFy.getFrequency + * + * @author Patches + * @since 3.0 */ fun callGetFrequency_networkProvided(network: WifiInfo?) { try { @@ -163,6 +202,14 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) } } + /** + * To try and get the IP of a device with null callbacks. + * + * @see WiseFy.getIP + * + * @author Patches + * @since 3.0 + */ fun callGetIP() { try { wisefy.getIP(null) @@ -177,6 +224,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * @param filterDuplicates The filterDuplicates param to use when trying. * * @see WiseFy.getCurrentNetwork + * + * @author Patches + * @since 3.0 */ fun callGetNearbyAccessPoints(filterDuplicates: Boolean) { try { @@ -192,6 +242,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * @param takeHighest The takeHighest param to use when trying * * @see WiseFy.getRSSI + * + * @author Patches + * @since 3.0 */ fun callGetRSSI(takeHighest: Boolean) { try { @@ -201,25 +254,13 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) } } - /** - * To try to retrieve a saved network with a given regex. - * - * @param regexForSSID The regex to use while trying - * - * @see WiseFy.getSavedNetwork - */ - fun callGetSavedNetwork(regexForSSID: String?) { - try { - wisefy.getSavedNetwork(regexForSSID, null) - } catch (npe: NullPointerException) { - fail() - } - } - /** * To try getting all nearby access points with a null callback. * * @see WiseFy.getSavedNetworks + * + * @author Patches + * @since 3.0 */ fun callGetSavedNetworks() { try { @@ -229,27 +270,15 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) } } - /** - * To try to get all nearby access points matching a given regex with null callbacks. - * - * @param regexForSSID The ssid to use while trying - * - * @see WiseFy.getSavedNetwork - */ - fun callGetSavedNetworks_withRegex(regexForSSID: String?) { - try { - wisefy.getSavedNetworks(regexForSSID, null) - } catch (npe: NullPointerException) { - fail() - } - } - /** * To try to remove a network with null callbacks. * * @param ssid The ssid to use while trying. * * @see WiseFy.removeNetwork + * + * @author Patches + * @since 3.0 */ fun callRemoveNetwork(ssid: String?) { try { @@ -266,6 +295,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * @param filterDuplicates The filter duplicate param to use when trying * * @see WiseFy.searchForAccessPoint + * + * @author Patches + * @since 3.0 */ fun callSearchForAccessPoint(ssid: String?, filterDuplicates: Boolean) { try { @@ -282,6 +314,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * @param filterDuplicates The filter duplicates param to use when trying * * @see WiseFy.searchForAccessPoints + * + * @author Patches + * @since 3.0 */ fun callSearchForAccessPoints(regexForSSID: String, filterDuplicates: Boolean) { try { @@ -291,12 +326,51 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) } } + /** + * To try to retrieve a saved network with a given regex. + * + * @param regexForSSID The regex to use while trying + * + * @see WiseFy.searchForSavedNetwork + * + * @author Patches + * @since 4.0 + */ + fun callSearchForSavedNetwork(regexForSSID: String?) { + try { + wisefy.searchForSavedNetwork(regexForSSID, null) + } catch (npe: NullPointerException) { + fail() + } + } + + /** + * To try to get all nearby access points matching a given regex with null callbacks. + * + * @param regexForSSID The ssid to use while trying + * + * @see WiseFy.searchForSavedNetworks + * + * @author Patches + * @since 4.0 + */ + fun callSearchForSavedNetworks(regexForSSID: String?) { + try { + wisefy.searchForSavedNetworks(regexForSSID, null) + } catch (npe: NullPointerException) { + fail() + } + } + /** * To try and search for a nearby SSID given a regex with null callbacks. * * @param regexForSSID The regex to use when trying * * @see WiseFy.searchForSSID + * + * @author Patches + * @since 3.0 */ fun callSearchForSSID(regexForSSID: String?) { try { @@ -312,6 +386,9 @@ internal class NullCallbackUtil internal constructor(private val wisefy: WiseFy) * @param regexForSSID The regex to use when trying * * @see WiseFy.searchForSSIDs + * + * @author Patches + * @since 3.0 */ fun callSearchForSSIDs(regexForSSID: String?) { try { diff --git a/wisefy/src/test/java/com/isupatches/wisefy/internal/ReflectionHelpers.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/ReflectionHelpers.java similarity index 95% rename from wisefy/src/test/java/com/isupatches/wisefy/internal/ReflectionHelpers.java rename to wisefy/src/androidTest/java/com/isupatches/wisefy/internal/ReflectionHelpers.java index 42014c7d..f15e07e6 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/internal/ReflectionHelpers.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/ReflectionHelpers.java @@ -1,3 +1,8 @@ +/* + * This logic/class was borrowed from Robolectric. + * + * https://github.com/robolectric/robolectric/blob/master/shadowapi/src/main/java/org/robolectric/util/ReflectionHelpers.java + */ package com.isupatches.wisefy.internal; import java.lang.reflect.InvocationTargetException; diff --git a/wisefy/src/test/java/com/isupatches/wisefy/internal/VerificationUtil.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/VerificationUtil.kt similarity index 80% rename from wisefy/src/test/java/com/isupatches/wisefy/internal/VerificationUtil.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/internal/VerificationUtil.kt index 24322fa7..48c39d71 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/internal/VerificationUtil.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/VerificationUtil.kt @@ -3,7 +3,6 @@ package com.isupatches.wisefy.internal import android.net.ConnectivityManager import android.net.wifi.WifiConfiguration import android.net.wifi.WifiManager - import com.isupatches.wisefy.VERIFICATION_FAILURE_TIMEOUT import com.isupatches.wisefy.VERIFICATION_SUCCESS_TIMEOUT @@ -21,6 +20,7 @@ import org.mockito.Mockito.verify * @see WifiManager * * @author Patches + * @since 3.0 */ internal class VerificationUtil internal constructor( private val mockConnectivityManager: ConnectivityManager, @@ -35,6 +35,9 @@ internal class VerificationUtil internal constructor( * To verify no attempt to add a network was made. * * @see WifiManager.addNetwork + * + * @author Patches + * @since 3.0 */ fun didNoTryToAddNetwork() { verify(mockWifiManager, after(VERIFICATION_FAILURE_TIMEOUT).times(0)).addNetwork(any(WifiConfiguration::class.java)) @@ -45,6 +48,9 @@ internal class VerificationUtil internal constructor( * * @see WifiManager.enableNetwork * @see WifiManager.reconnect + * + * @author Patches + * @since 3.0 */ fun didNotTryToConnectToNetwork() { verify(mockWifiManager, after(VERIFICATION_FAILURE_TIMEOUT).times(0)).enableNetwork(anyInt(), anyBoolean()) @@ -55,6 +61,9 @@ internal class VerificationUtil internal constructor( * To verify no attempt to disable wifi was made. * * @see WifiManager.setWifiEnabled + * + * @author Patches + * @since 3.0 */ fun didNotTryToDisableWifi() { verify(mockWifiManager, after(VERIFICATION_FAILURE_TIMEOUT).times(0)).isWifiEnabled = false @@ -64,6 +73,9 @@ internal class VerificationUtil internal constructor( * To verify no attempt to disconnect the device from it's current network was made. * * @see WifiManager.disconnect + * + * @author Patches + * @since 3.0 */ fun didNotTryToDisconnectFromCurrentNetwork() { verify(mockWifiManager, after(VERIFICATION_FAILURE_TIMEOUT).times(0)).disconnect() @@ -73,6 +85,9 @@ internal class VerificationUtil internal constructor( * To verify no attempt to enable wifi was made. * * @see WifiManager.setWifiEnabled + * + * @author Patches + * @since 3.0 */ fun didNotTryToEnableWifi() { verify(mockWifiManager, after(VERIFICATION_FAILURE_TIMEOUT).times(0)).isWifiEnabled = true @@ -82,11 +97,22 @@ internal class VerificationUtil internal constructor( * To verify no attempt to get the device's current network was made. * * @see WifiManager.getConnectionInfo + * + * @author Patches + * @since 3.0 */ fun didNotTryToGetCurrentNetwork() { verify(mockWifiManager, after(VERIFICATION_FAILURE_TIMEOUT).times(0)).connectionInfo } + /** + * To verify no attempt to get the device's current network info was made. + * + * @see ConnectivityManager.getActiveNetworkInfo + * + * @author Patches + * @since 3.0 + */ fun didNotTryToGetCurrentNetworkInfo() { verify(mockConnectivityManager, after(VERIFICATION_FAILURE_TIMEOUT).times(0)).activeNetworkInfo } @@ -95,11 +121,22 @@ internal class VerificationUtil internal constructor( * To verify no attempt to get saved networks was made. * * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 */ fun didNotTryToGetSavedNetworks() { verify(mockWifiManager, after(VERIFICATION_FAILURE_TIMEOUT).times(0)).configuredNetworks } + /** + * To verify no attempt to scan for nearby access points was made. + * + * @see WifiManager.startScan + * + * @author Patches + * @since 3.0 + */ @Suppress("DEPRECATION") fun didNotTryToScanForAccessPoints() { verify(mockWifiManager, after(VERIFICATION_FAILURE_TIMEOUT).times(0)).startScan() @@ -109,6 +146,9 @@ internal class VerificationUtil internal constructor( * To verify no attempt to remove a network was made. * * @see WifiManager.removeNetwork + * + * @author Patches + * @since 3.0 */ fun didNotTryToRemoveNetwork() { verify(mockWifiManager, after(VERIFICATION_FAILURE_TIMEOUT).times(0)).removeNetwork(anyInt()) @@ -122,6 +162,9 @@ internal class VerificationUtil internal constructor( * To verify no attempt to add a network was made. * * @see WifiManager.addNetwork + * + * @author Patches + * @since 3.0 */ fun triedToAddNetwork() { verify(mockWifiManager, timeout(VERIFICATION_SUCCESS_TIMEOUT)).addNetwork(any(WifiConfiguration::class.java)) @@ -132,6 +175,9 @@ internal class VerificationUtil internal constructor( * * @see WifiManager.enableNetwork * @see WifiManager.reconnect + * + * @author Patches + * @since 3.0 */ fun triedToConnectToNetwork() { verify(mockWifiManager, timeout(VERIFICATION_SUCCESS_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()) @@ -142,6 +188,9 @@ internal class VerificationUtil internal constructor( * To verify an attempt to disable wifi was made. * * @see WifiManager.setWifiEnabled + * + * @author Patches + * @since 3.0 */ fun triedToDisableWifi() { verify(mockWifiManager, timeout(VERIFICATION_SUCCESS_TIMEOUT)).isWifiEnabled = false @@ -151,6 +200,9 @@ internal class VerificationUtil internal constructor( * To verify an attempt to disconnect the device from it's current network was made. * * @see WifiManager.disconnect + * + * @author Patches + * @since 3.0 */ fun triedToDisconnectFromCurrentNetwork() { verify(mockWifiManager, timeout(VERIFICATION_SUCCESS_TIMEOUT)).disconnect() @@ -160,6 +212,9 @@ internal class VerificationUtil internal constructor( * To verify an attempt to enable wifi was made. * * @see WifiManager.setWifiEnabled + * + * @author Patches + * @since 3.0 */ fun triedToEnableWifi() { verify(mockWifiManager, timeout(VERIFICATION_SUCCESS_TIMEOUT)).isWifiEnabled = true @@ -169,11 +224,22 @@ internal class VerificationUtil internal constructor( * To verify an attempt to get the device's current network was made. * * @see WifiManager.getConnectionInfo + * + * @author Patches + * @since 3.0 */ fun triedToGetCurrentNetwork() { verify(mockWifiManager, timeout(VERIFICATION_SUCCESS_TIMEOUT)).connectionInfo } + /** + * To verify an attempt to get the device's current network info was made. + * + * @see ConnectivityManager.getActiveNetworkInfo + * + * @author Patches + * @since 3.0 + */ fun triedToGetCurrentNetworkInfo() { verify(mockConnectivityManager, timeout(VERIFICATION_SUCCESS_TIMEOUT)).activeNetworkInfo } @@ -182,6 +248,9 @@ internal class VerificationUtil internal constructor( * To verify an attempt to get nearby access points was made. * * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 */ fun triedToGetNearbyAccessPoints() { verify(mockWifiManager, timeout(VERIFICATION_SUCCESS_TIMEOUT)).scanResults @@ -191,6 +260,9 @@ internal class VerificationUtil internal constructor( * To verify an attempt to get saved networks was made. * * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 */ fun triedToGetSavedNetworks() { verify(mockWifiManager, timeout(VERIFICATION_SUCCESS_TIMEOUT)).configuredNetworks @@ -200,11 +272,22 @@ internal class VerificationUtil internal constructor( * To verify an attempt to remove a network was made. * * @see WifiManager.removeNetwork + * + * @author Patches + * @since 3.0 */ fun triedToRemoveNetwork() { verify(mockWifiManager, timeout(VERIFICATION_SUCCESS_TIMEOUT)).removeNetwork(anyInt()) } + /** + * To verify an attempt to scan for nearby access points was made. + * + * @see WifiManager.removeNetwork + * + * @author Patches + * @since 3.0 + */ @Suppress("DEPRECATION") fun triedToScanForAccessPoints() { verify(mockWifiManager, atLeastOnce()).startScan() diff --git a/wisefy/src/test/java/com/isupatches/wisefy/internal/base/BaseUnitTest.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/base/BaseInstrumentationTest.kt similarity index 94% rename from wisefy/src/test/java/com/isupatches/wisefy/internal/base/BaseUnitTest.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/internal/base/BaseInstrumentationTest.kt index 8f41801b..172f60d0 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/internal/base/BaseUnitTest.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/base/BaseInstrumentationTest.kt @@ -3,7 +3,7 @@ package com.isupatches.wisefy.internal.base import android.net.ConnectivityManager import android.net.wifi.WifiConfiguration import android.net.wifi.WifiManager -import androidx.test.core.app.ApplicationProvider +import androidx.test.platform.app.InstrumentationRegistry import com.isupatches.wisefy.VERIFICATION_SUCCESS_TIMEOUT import com.isupatches.wisefy.WiseFy @@ -26,7 +26,7 @@ import org.mockito.Mockito.mock import org.mockito.Mockito.timeout import org.mockito.Mockito.verify -internal abstract class BaseUnitTest { +internal abstract class BaseInstrumentationTest { protected val wisefy: WiseFy protected val mockWiseFySearch: WiseFySearch @@ -54,7 +54,7 @@ internal abstract class BaseUnitTest { mockWifiManager = mock(WifiManager::class.java) mockConnectivityManager = mock(ConnectivityManager::class.java) - wisefy = WiseFy.Brains(ApplicationProvider.getApplicationContext()) + wisefy = WiseFy.Brains(InstrumentationRegistry.getInstrumentation().targetContext) .customConnectivityManager(mockConnectivityManager) .customWifiManager(mockWifiManager) .customWiseFyConnection(mockWiseFyConnection) diff --git a/wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockNetworkUtil.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockNetworkUtil.kt similarity index 56% rename from wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockNetworkUtil.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockNetworkUtil.kt index 62acbf3c..742f3fd1 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockNetworkUtil.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockNetworkUtil.kt @@ -31,6 +31,7 @@ import org.mockito.Mockito.mock * @see WifiManager * * @author Patches + * @since 3.0 */ @Suppress("LargeClass") internal class MockNetworkUtil internal constructor( @@ -46,18 +47,55 @@ internal class MockNetworkUtil internal constructor( private var expectedSSIDs: MutableList? = null + /** + * To mock a device having active network info. + * + * @see ConnectivityManager.getActiveNetworkInfo + * + * @author Patches + * @since 3.0 + */ internal fun activeNetwork() { `when`(mockConnectivityManager.activeNetworkInfo).thenReturn(mock(NetworkInfo::class.java)) } + /** + * To mock a failure adding a network. + * + * @see WifiManager.addNetwork + * + * @author Patches + * @since 3.0 + */ internal fun addNetwork_failure() { `when`(mockWifiManager.addNetwork(any(WifiConfiguration::class.java))).thenReturn(WIFI_MANAGER_FAILURE) } + /** + * To mock a success adding a network. + * + * @see WifiManager.addNetwork + * + * @author Patches + * @since 3.0 + */ internal fun addNetwork_success() { `when`(mockWifiManager.addNetwork(any(WifiConfiguration::class.java))).thenReturn(0) } + /** + * To mock a device having an active network. + * + * @param ssid The SSID for the mocked network + * + * @return WifiInfo - The mock active network + * + * @see WifiInfo + * @see WifiManager.getConnectionInfo + * + * @author Patches + * @since 3.0 + */ internal fun currentNetwork(ssid: String?): WifiInfo { val mockCurrentNetwork = mock(WifiInfo::class.java) `when`(mockCurrentNetwork.ssid).thenReturn(ssid) @@ -65,6 +103,21 @@ internal class MockNetworkUtil internal constructor( return mockCurrentNetwork } + /** + * To mock a current connection status. + * + * @param isAvailable Whether the network is available or not + * @param isConnected Whether the network is connected or not + * @param type The network type + * + * @see NetworkInfo.isAvailable + * @see NetworkInfo.isConnected + * @see NetworkInfo.getTypeName + * @see ConnectivityManager.getActiveNetworkInfo + * + * @author Patches + * @since 3.0 + */ @Suppress("DEPRECATION") internal fun currentNetworkConnectionStatus(isAvailable: Boolean, isConnected: Boolean, type: String?) { val networkInfo = mock(NetworkInfo::class.java) @@ -76,42 +129,159 @@ internal class MockNetworkUtil internal constructor( `when`(mockConnectivityManager.activeNetworkInfo).thenReturn(networkInfo) } + /** + * To mock no current network. + * + * @see WifiManager.getConnectionInfo + * + * @author Patches + * @since 4.0 + */ internal fun currentNetwork_null() { `when`(mockWifiManager.connectionInfo).thenReturn(null) } + /** + * To mock a failure disabling Wifi. + * + * @see WifiManager.setWifiEnabled + * + * @author Patches + * @since 3.0 + */ internal fun disableWifi_failure() { `when`(mockWifiManager.setWifiEnabled(false)).thenReturn(false) } + /** + * To mock a success disabling Wifi. + * + * @see WifiManager.setWifiEnabled + * + * @author Patches + * @since 3.0 + */ internal fun disableWifi_success() { `when`(mockWifiManager.setWifiEnabled(false)).thenReturn(true) } + /** + * To mock a failure disconnecting from current network. + * + * @see WifiManager.disconnect + * + * @author Patches + * @since 3.0 + */ internal fun disconnectFromCurrentNetwork_failure() { `when`(mockWifiManager.disconnect()).thenReturn(false) } + /** + * To mock a success disconnecting from current network. + * + * @see WifiManager.disconnect + * + * @author Patches + * @since 3.0 + */ internal fun disconnectFromCurrentNetwork_success() { `when`(mockWifiManager.disconnect()).thenReturn(true) } + /** + * To mock a failure enabling Wifi. + * + * @see WifiManager.setWifiEnabled + * + * @author Patches + * @since 3.0 + */ internal fun enableWifi_failure() { `when`(mockWifiManager.setWifiEnabled(true)).thenReturn(false) } + /** + * To mock a success enabling Wifi. + * + * @see WifiManager.setWifiEnabled + * + * @author Patches + * @since 3.0 + */ internal fun enableWifi_success() { `when`(mockWifiManager.setWifiEnabled(true)).thenReturn(true) } + /** + * To return the expected access point for testing. + * + * @return List of ScanResult - The expected access point for test + * + * @see ScanResult + * + * @author Patches + * @since 3.0 + */ internal fun getExpectedNearbyAccessPoint(): ScanResult? = expectedNearbyAccessPoint + + /** + * To return the list of expected access points for testing. + * + * @return List of ScanResult - The expected access points for test + * + * @see ScanResult + * + * @author Patches + * @since 3.0 + */ internal fun getExpectedNearbyAccessPoints(): List? = expectedNearbyAccessPoints + /** + * To return the expected saved network for testing. + * + * @return List of Strings - The expected saved network for test + * + * @see WifiConfiguration + * + * @author Patches + * @since 3.0 + */ internal fun getExpectedSavedNetwork(): WifiConfiguration? = expectedSavedNetwork + + /** + * To return the expected list of saved networks for testing. + * + * @return List of WifiConfiguration - The expected saved networks for test + * + * @see WifiConfiguration + * + * @author Patches + * @since 3.0 + */ internal fun getExpectedSavedNetworks(): List? = expectedSavedNetworks + /** + * To return the expected list of SSIDs for testing. + * + * @return List of Strings - The expected SSIDS for test + * + * @author Patches + * @since 3.0 + */ internal fun getExpectedSSIDs(): List? = expectedSSIDs + /** + * To mock if a device is roaming. + * + * @param roaming Whether the device is roaming or not + * + * @see NetworkInfo.isRoaming + * @see ConnectivityManager.getActiveNetworkInfo + * + * @author Patches + * @since 3.0 + */ @Suppress("DEPRECATION") internal fun isDeviceRoaming(roaming: Boolean) { val networkInfo = mock(NetworkInfo::class.java) @@ -119,10 +289,31 @@ internal class MockNetworkUtil internal constructor( `when`(mockConnectivityManager.activeNetworkInfo).thenReturn(networkInfo) } + /** + * To mock if Wifi is enabled or not. + * + * @param wifiEnabled Whether the device has Wifi enabled or not + * + * @see WifiManager.isWifiEnabled + * + * @author Patches + * @since 3.0 + */ internal fun isWifiEnabled(wifiEnabled: Boolean) { `when`(mockWifiManager.isWifiEnabled).thenReturn(wifiEnabled) } + /** + * To mock a network with a given frequency. + * + * @param frequency The frequency for the network + * + * @see WifiInfo.getFrequency + * @see WifiManager.getConnectionInfo + * + * @author Patches + * @since 3.0 + */ internal fun networkWithFrequency(frequency: Int): WifiInfo { val mockWifiInfo = mock(WifiInfo::class.java) `when`(mockWifiInfo.frequency).thenReturn(frequency) @@ -130,43 +321,59 @@ internal class MockNetworkUtil internal constructor( return mockWifiInfo } - internal fun removeNetwork(removed: Boolean) { - `when`(mockWifiManager.removeNetwork(anyInt())).thenReturn(removed) - } - - internal fun savedNetworks(): List { - val savedNetworks = ArrayList() - val wiFiConfiguration = createSavedNetwork(TEST_SSID) - savedNetworks.add(wiFiConfiguration) - - `when`(mockWifiManager.configuredNetworks).thenReturn(savedNetworks) - return savedNetworks - } - - internal fun getConfiguredNetworks_null() { - `when`(mockWifiManager.configuredNetworks).thenReturn(null) - } - - internal fun getConfiguredNetworks_emptyList() { - `when`(mockWifiManager.configuredNetworks).thenReturn(ArrayList()) - } - + /** + * To mock a failure getting the IP of a device. + * + * @see WifiInfo.getIpAddress + * @see WifiManager.getConnectionInfo + * + * @author Patches + * @since 3.0 + */ internal fun ip_failure() { val wifiInfo = mock(WifiInfo::class.java) `when`(wifiInfo.ipAddress).thenReturn(0) `when`(mockWifiManager.connectionInfo).thenReturn(wifiInfo) } + /** + * To mock a success getting the IP of a device. + * + * @see WifiInfo.getIpAddress + * @see WifiManager.getConnectionInfo + * + * @author Patches + * @since 3.0 + */ internal fun ip_success() { val wifiInfo = mock(WifiInfo::class.java) `when`(wifiInfo.ipAddress).thenReturn(TEST_IP_ADDRESS_INT) `when`(mockWifiManager.connectionInfo).thenReturn(wifiInfo) } + /** + * To mock an empty list of access points. + * + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_emptyList() { `when`(mockWifiManager.scanResults).thenReturn(ArrayList()) } + /** + * To mock a list of access points with one that has a matching SSID. + * + * @see addToExpectedNearbyAccessPoints + * @see addToExpectedSSIDs + * @see ScanResult + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_matchingSSID() { val accessPoint = createMockAccessPointWithSSID(TEST_SSID) @@ -179,6 +386,21 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.scanResults).thenReturn(accessPoints) } + /** + * To mock a list of access points with multiple access points that have the same SSID. + * Access point 1 will have the higher RSSI level. + * + * @param takeHighest If the search is going to take the access point with the highest RSSI + * + * @see createMockAccessPointWithSSIDAndRSSI + * @see ScanResult + * @see addToExpectedNearbyAccessPoints + * @see addToExpectedSSIDs + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_multipleMatchingSSIDs_accessPoint1HasHigherRSSI(takeHighest: Boolean) { val accessPoint1 = createMockAccessPointWithSSIDAndRSSI(TEST_SSID, TEST_RSSI_LEVEL_HIGH) val accessPoint2 = createMockAccessPointWithSSIDAndRSSI(TEST_SSID, TEST_RSSI_LEVEL_LOW) @@ -197,6 +419,21 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.scanResults).thenReturn(accessPoints) } + /** + * To mock a list of access points with multiple access points that have the same SSID. + * Access point 2 will have the higher RSSI level. + * + * @param takeHighest If the search is going to take the access point with the highest RSSI + * + * @see createMockAccessPointWithSSIDAndRSSI + * @see ScanResult + * @see addToExpectedNearbyAccessPoints + * @see addToExpectedSSIDs + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_multipleMatchingSSIDs_accessPoint2HasHigherRSSI(takeHighest: Boolean) { val accessPoint1 = createMockAccessPointWithSSIDAndRSSI(TEST_SSID, TEST_RSSI_LEVEL_LOW) val accessPoint2 = createMockAccessPointWithSSIDAndRSSI(TEST_SSID, TEST_RSSI_LEVEL_HIGH) @@ -215,6 +452,22 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.scanResults).thenReturn(accessPoints) } + /** + * To mock a list of access points with one access point that has a matching SSID and + * another one that does not a matching SSID. Both will that have the same RSSI. + * + * @param addSecondNetwork If the second network should be added to the expected network + * list for testing + * + * @see createMockAccessPointWithSSIDAndRSSI + * @see ScanResult + * @see addToExpectedNearbyAccessPoints + * @see addToExpectedSSIDs + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_multipleSSIDs_sameRSSI(addSecondNetwork: Boolean) { val accessPoint1 = createMockAccessPointWithSSIDAndRSSI(TEST_SSID, TEST_RSSI_LEVEL) val accessPoint2 = createMockAccessPointWithSSIDAndRSSI(TEST_SSID2, TEST_RSSI_LEVEL) @@ -238,6 +491,22 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.scanResults).thenReturn(accessPoints) } + /** + * To mock a list of access points with multiple access points that have the same SSID and + * the same RSSI level. + * + * @param addSecondNetwork If the second network should be added to the expected network + * list for testing + * + * @see createMockAccessPointWithSSIDAndRSSI + * @see ScanResult + * @see addToExpectedNearbyAccessPoints + * @see addToExpectedSSIDs + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_multipleMatchingSSIDs_sameRSSI(addSecondNetwork: Boolean) { val accessPoint1 = createMockAccessPointWithSSIDAndRSSI(TEST_SSID, TEST_RSSI_LEVEL) val accessPoint2 = createMockAccessPointWithSSIDAndRSSI(TEST_SSID, TEST_RSSI_LEVEL) @@ -256,6 +525,16 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.scanResults).thenReturn(accessPoints) } + /** + * To mock a list of access points with multiple non-matching SSIDs. + * + * @see createMockAccessPointWithSSID + * @see ScanResult + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_multipleNonMatchingSSIDs() { val accessPoint1 = createMockAccessPointWithSSID(TEST_SSID2) val accessPoint2 = createMockAccessPointWithSSID(TEST_SSID3) @@ -267,6 +546,16 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.scanResults).thenReturn(accessPoints) } + /** + * To mock a list of access points with a non-matching SSID. + * + * @see createMockAccessPointWithSSID + * @see ScanResult + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_nonMatchingSSID() { val accessPoint = createMockAccessPointWithSSID(TEST_SSID2) @@ -276,15 +565,42 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.scanResults).thenReturn(accessPoints) } + /** + * To mock a list of access points with a null configuration. + * + * @see ScanResult + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_nullAccessPoint() { val accessPoints = arrayListOf(null) `when`(mockWifiManager.scanResults).thenReturn(accessPoints) } + /** + * To mock a null list of access points. + * + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_nullList() { `when`(mockWifiManager.scanResults).thenReturn(null) } + /** + * To mock a list of access points with a configuration that has a null SSID. + * + * @see createMockAccessPointWithSSID + * @see ScanResult + * @see WifiManager.getScanResults + * + * @author Patches + * @since 3.0 + */ internal fun nearbyAccessPoints_nullSSID() { val accessPoint = createMockAccessPointWithSSID(null) @@ -294,14 +610,77 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.scanResults).thenReturn(accessPoints) } + /** + * To mock if removing a network is successful or not. + * + * @param removed Whether or not the network was successfully removed + * + * @see WifiManager.removeNetwork + * + * @author Patches + * @since 3.0 + */ + internal fun removeNetwork(removed: Boolean) { + `when`(mockWifiManager.removeNetwork(anyInt())).thenReturn(removed) + } + + /** + * To mock a list of saved networks. + * + * @return The list of saved networks for testing + * + * @see createSavedNetwork + * @see WifiConfiguration + * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 + */ + internal fun savedNetworks(): List { + val savedNetworks = ArrayList() + val wiFiConfiguration = createSavedNetwork(TEST_SSID) + savedNetworks.add(wiFiConfiguration) + + `when`(mockWifiManager.configuredNetworks).thenReturn(savedNetworks) + return savedNetworks + } + + /** + * To mock an empty list of saved networks. + * + * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 + */ internal fun savedNetworks_emptyList() { `when`(mockWifiManager.configuredNetworks).thenReturn(ArrayList()) } + /** + * To mock a list of saved networks with a null configuration. + * + * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 + */ internal fun savedNetworks_listWithNull() { - `when`(mockWifiManager.configuredNetworks).thenReturn(arrayListOf(null)) + val savedNetworks = arrayListOf(null) + `when`(mockWifiManager.configuredNetworks).thenReturn(savedNetworks) } + /** + * To mock a list of saved networks with a configuration that has a matching SSID. + * + * @see addToExpectedSavedNetworks + * @see createSavedNetwork + * @see WifiConfiguration + * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 + */ internal fun savedNetworks_matchingSSID() { val savedNetwork = createSavedNetwork(TEST_SSID) @@ -313,6 +692,17 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.configuredNetworks).thenReturn(savedNetworks) } + /** + * To mock a list of saved networks with multiple configurations that have a matching SSID. + * + * @see addToExpectedSavedNetworks + * @see createSavedNetwork + * @see WifiConfiguration + * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 + */ internal fun savedNetworks_multipleMatchingSSIDs() { val savedNetwork1 = createSavedNetwork(TEST_SSID) val savedNetwork2 = createSavedNetwork(TEST_SSID) @@ -326,6 +716,16 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.configuredNetworks).thenReturn(savedNetworks) } + /** + * To mock a list of saved networks with multiple configurations that have non-matching SSIDs. + * + * @see createSavedNetwork + * @see WifiConfiguration + * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 + */ internal fun savedNetworks_multipleNonMatchingSSIDs() { val savedNetwork1 = createSavedNetwork(TEST_SSID2) val savedNetwork2 = createSavedNetwork(TEST_SSID3) @@ -337,6 +737,20 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.configuredNetworks).thenReturn(savedNetworks) } + /** + * To mock a list of saved networks with one matching and one non-matching SSID. + * + * @param addSecondNetwork If the second network should be added to the expected network + * list for testing + * + * @see addToExpectedSavedNetworks + * @see createSavedNetwork + * @see WifiConfiguration + * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 + */ internal fun savedNetworks_multipleSSIDs(addSecondNetwork: Boolean) { val savedNetwork1 = createSavedNetwork(TEST_SSID) val savedNetwork2 = createSavedNetwork(TEST_SSID2) @@ -354,6 +768,16 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.configuredNetworks).thenReturn(savedNetworks) } + /** + * To mock a list of saved networks with a configuration that has a non-matching SSID. + * + * @see createSavedNetwork + * @see WifiConfiguration + * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 + */ internal fun savedNetworks_nonMatchingSSID() { val savedNetwork = createSavedNetwork(TEST_SSID2) @@ -363,15 +787,28 @@ internal class MockNetworkUtil internal constructor( `when`(mockWifiManager.configuredNetworks).thenReturn(savedNetworks) } + /** + * To mock a null list of saved networks. + * + * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 + */ internal fun savedNetworks_nullList() { `when`(mockWifiManager.configuredNetworks).thenReturn(null) } - internal fun savedNetworks_nullSavedNetwork() { - val wifiList = emptyList() - `when`(mockWifiManager.configuredNetworks).thenReturn(wifiList) - } - + /** + * To mock a list of saved networks with a configuration that has a null SSID. + * + * @see createSavedNetwork + * @see WifiConfiguration + * @see WifiManager.getConfiguredNetworks + * + * @author Patches + * @since 3.0 + */ internal fun savedNetworks_nullSSID() { val savedNetwork = createSavedNetwork(null) diff --git a/wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockWiseFyConnectionUtil.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockWiseFyConnectionUtil.kt similarity index 83% rename from wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockWiseFyConnectionUtil.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockWiseFyConnectionUtil.kt index 66bb2c60..78accbb2 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockWiseFyConnectionUtil.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockWiseFyConnectionUtil.kt @@ -12,6 +12,7 @@ import org.mockito.Mockito.`when` * @see WiseFyConnection * * @author Patches + * @since 3.0 */ internal class MockWiseFyConnectionUtil internal constructor( private val mockWiseFyConnection: WiseFyConnection @@ -23,6 +24,9 @@ internal class MockWiseFyConnectionUtil internal constructor( * @param connected Whether the device is connected to the specific SSID or not * * @see WiseFyConnection.isCurrentNetworkConnectedToSSID + * + * @author Patches + * @since 3.0 */ fun isCurrentNetworkConnectedToSSID(connected: Boolean) { `when`(mockWiseFyConnection.isCurrentNetworkConnectedToSSID(anyString())).thenReturn(connected) @@ -34,6 +38,9 @@ internal class MockWiseFyConnectionUtil internal constructor( * @param connected If the device is connected to a mobile network * * @see WiseFyConnection.isDeviceConnectedToMobileNetwork + * + * @author Patches + * @since 3.0 */ fun isDeviceConnectedToMobileNetwork(connected: Boolean) { `when`(mockWiseFyConnection.isDeviceConnectedToMobileNetwork()).thenReturn(connected) @@ -45,11 +52,24 @@ internal class MockWiseFyConnectionUtil internal constructor( * @param connected If the device is connected to a Wifi network * * @see WiseFyConnection.isDeviceConnectedToWifiNetwork + * + * @author Patches + * @since 3.0 */ fun isDeviceConnectedToWifiNetwork(connected: Boolean) { `when`(mockWiseFyConnection.isDeviceConnectedToWifiNetwork()).thenReturn(connected) } + /** + * To mock whether the device is roaming. + * + * @param roaming If the device is roaming + * + * @see WiseFyConnection.isDeviceRoaming + * + * @author Patches + * @since 4.0 + */ fun isDeviceRoaming(roaming: Boolean) { `when`(mockWiseFyConnection.isDeviceRoaming()).thenReturn(roaming) } @@ -60,6 +80,9 @@ internal class MockWiseFyConnectionUtil internal constructor( * @param connected Whether the device is connected or not * * @see WiseFyConnection.isNetworkConnected + * + * @author Patches + * @since 3.0 */ fun isNetworkConnected(connected: Boolean) { `when`(mockWiseFyConnection.isNetworkConnected()).thenReturn(connected) @@ -71,6 +94,9 @@ internal class MockWiseFyConnectionUtil internal constructor( * @param success Whether waitToConnectToSSID succeeds or not * * @see WiseFyConnection.waitToConnectToSSID + * + * @author Patches + * @since 3.0 */ fun waitToConnectToSSID(success: Boolean) { `when`(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(success) diff --git a/wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockWiseFyPrechecksUtil.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockWiseFyPrechecksUtil.kt similarity index 58% rename from wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockWiseFyPrechecksUtil.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockWiseFyPrechecksUtil.kt index 7141e16c..45b2fc28 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockWiseFyPrechecksUtil.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockWiseFyPrechecksUtil.kt @@ -13,8 +13,8 @@ import org.mockito.Mockito.`when` * * @see WiseFyPrechecks * - * * @author Patches + * @since 3.0 */ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWiseFyPrechecks: WiseFyPrechecks) { @@ -23,12 +23,25 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * * @see WiseFyPrechecks.addNetworkPrechecks * @see WiseFyPrechecks.addNetworkPrechecks + * + * @author Patches + * @since 3.0 */ fun addNetwork_failure() { `when`(mockWiseFyPrechecks.addNetworkPrechecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) `when`(mockWiseFyPrechecks.addNetworkPrechecks(anyString(), anyString())).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success adding a network. + * + * @see WiseFyPrechecks.addNetworkPrechecks + * @see WiseFyPrechecks.addNetworkPrechecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun addNetwork_success() { `when`(mockWiseFyPrechecks.addNetworkPrechecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) `when`(mockWiseFyPrechecks.addNetworkPrechecks(anyString(), anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) @@ -38,11 +51,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure connecting to a network. * * @see WiseFyPrechecks.connectToNetworkPrechecks + * + * @author Patches + * @since 3.0 */ fun connectToNetwork_failure() { `when`(mockWiseFyPrechecks.connectToNetworkPrechecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success connecting to a network. + * + * @see WiseFyPrechecks.connectToNetworkPrechecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun connectToNetwork_success() { `when`(mockWiseFyPrechecks.connectToNetworkPrechecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -51,11 +76,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure disabling wifi. * * @see WiseFyPrechecks.disableWifiChecks + * + * @author Patches + * @since 3.0 */ fun disableWifi_failure() { `when`(mockWiseFyPrechecks.disableWifiChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success disabling wifi. + * + * @see WiseFyPrechecks.disableWifiChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun disableWifi_success() { `when`(mockWiseFyPrechecks.disableWifiChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -64,11 +101,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure disconnecting from the current network. * * @see WiseFyPrechecks.disconnectFromCurrentNetworkChecks + * + * @author Patches + * @since 3.0 */ fun disconnectFromCurrentNetwork_failure() { `when`(mockWiseFyPrechecks.disconnectFromCurrentNetworkChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success disconnecting from the current network. + * + * @see WiseFyPrechecks.disconnectFromCurrentNetworkChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun disconnectFromCurrentNetwork_success() { `when`(mockWiseFyPrechecks.disconnectFromCurrentNetworkChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -77,11 +126,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure enabling wifi. * * @see WiseFyPrechecks.enableWifiChecks + * + * @author Patches + * @since 3.0 */ fun enableWifi_failure() { `when`(mockWiseFyPrechecks.enableWifiChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success enabling wifi. + * + * @see WiseFyPrechecks.enableWifiChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun enableWifi_success() { `when`(mockWiseFyPrechecks.enableWifiChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -90,19 +151,48 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure getting the current network. * * @see WiseFyPrechecks.getCurrentNetworkChecks + * + * @author Patches + * @since 3.0 */ fun getCurrentNetwork_failure() { `when`(mockWiseFyPrechecks.getCurrentNetworkChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success getting the current network. + * + * @see WiseFyPrechecks.getCurrentNetworkChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun getCurrentNetwork_success() { `when`(mockWiseFyPrechecks.getCurrentNetworkChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } + /** + * Mocks a precheck failure getting a device's current network info. + * + * @see WiseFyPrechecks.getCurrentNetworkInfoChecks + * + * @author Patches + * @since 3.0 + */ fun getCurrentNetworkInfo_failure() { `when`(mockWiseFyPrechecks.getCurrentNetworkInfoChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success getting a device's current network info. + * + * @see WiseFyPrechecks.getCurrentNetworkInfoChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun getCurrentNetworkInfo_success() { `when`(mockWiseFyPrechecks.getCurrentNetworkInfoChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -111,11 +201,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure getting the ip of the device. * * @see WiseFyPrechecks.getIPChecks + * + * @author Patches + * @since 3.0 */ fun getIP_failure() { `when`(mockWiseFyPrechecks.getIPChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success getting the ip of the device. + * + * @see WiseFyPrechecks.getIPChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun getIP_success() { `when`(mockWiseFyPrechecks.getIPChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -124,11 +226,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure getting nearby access points. * * @see WiseFyPrechecks.getNearbyAccessPointsChecks + * + * @author Patches + * @since 3.0 */ fun getNearbyAccessPoints_failure() { `when`(mockWiseFyPrechecks.getNearbyAccessPointsChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success getting nearby access points. + * + * @see WiseFyPrechecks.getNearbyAccessPointsChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun getNearbyAccessPoints_success() { `when`(mockWiseFyPrechecks.getNearbyAccessPointsChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -137,53 +251,73 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure getting the RSSI level of a network. * * @see WiseFyPrechecks.getRSSIChecks + * + * @author Patches + * @since 3.0 */ fun getRSSI_failure() { `when`(mockWiseFyPrechecks.getRSSIChecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) } - fun getRSSI_success() { - `when`(mockWiseFyPrechecks.getRSSIChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) - } - /** - * Mocks a precheck failure getting a saved network. + * Mocks a precheck success getting the RSSI level of a network. * - * @see WiseFyPrechecks.getSavedNetworkChecks + * @see WiseFyPrechecks.getRSSIChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 */ - fun getSavedNetwork_failure() { - `when`(mockWiseFyPrechecks.getSavedNetworkChecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) - } - - fun getSavedNetwork_success() { - `when`(mockWiseFyPrechecks.getSavedNetworkChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) + fun getRSSI_success() { + `when`(mockWiseFyPrechecks.getRSSIChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) } /** * Mocks a precheck failure getting saved networks. * * @see WiseFyPrechecks.getSavedNetworksChecks - * @see WiseFyPrechecks.getSavedNetworksChecks + * + * @author Patches + * @since 3.0 */ fun getSavedNetworks_failure() { `when`(mockWiseFyPrechecks.getSavedNetworksChecks()).thenReturn(PRECHECK_RESULT_FAILURE) - `when`(mockWiseFyPrechecks.getSavedNetworksChecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success getting saved networks. + * + * @see WiseFyPrechecks.getSavedNetworksChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun getSavedNetworks_success() { `when`(mockWiseFyPrechecks.getSavedNetworksChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) - `when`(mockWiseFyPrechecks.getSavedNetworksChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) } /** * Mocks a precheck failure checking if a device is connected to a mobile network. * * @see WiseFyPrechecks.isDeviceConnectedToMobileNetworkChecks + * + * @author Patches + * @since 3.0 */ fun isDeviceConnectedToMobileNetwork_failure() { `when`(mockWiseFyPrechecks.isDeviceConnectedToMobileNetworkChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success checking if a device is connected to a mobile network. + * + * @see WiseFyPrechecks.isDeviceConnectedToMobileNetworkChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun isDeviceConnectedToMobileNetwork_success() { `when`(mockWiseFyPrechecks.isDeviceConnectedToMobileNetworkChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -192,11 +326,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure checking if a device is connected to a mobile or wifi network. * * @see WiseFyPrechecks.isDeviceConnectedToMobileOrWifiNetworkChecks + * + * @author Patches + * @since 3.0 */ fun isDeviceConnectedToMobileOrWifiNetwork_failure() { `when`(mockWiseFyPrechecks.isDeviceConnectedToMobileOrWifiNetworkChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success checking if a device is connected to a mobile or wifi network. + * + * @see WiseFyPrechecks.isDeviceConnectedToMobileOrWifiNetworkChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun isDeviceConnectedToMobileOrWifiNetwork_success() { `when`(mockWiseFyPrechecks.isDeviceConnectedToMobileOrWifiNetworkChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -205,11 +351,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure checking if a device is connected to a network with a specific SSID. * * @see WiseFyPrechecks.isDeviceConnectedToSSIDChecks + * + * @author Patches + * @since 3.0 */ fun isDeviceConnectedToSSIDChecks_failure() { `when`(mockWiseFyPrechecks.isDeviceConnectedToSSIDChecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success checking if a device is connected to a network with a specific SSID. + * + * @see WiseFyPrechecks.isDeviceConnectedToSSIDChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun isDeviceConnectedToSSIDChecks_success() { `when`(mockWiseFyPrechecks.isDeviceConnectedToSSIDChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -218,11 +376,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure checking if a device is connected to a wifi network. * * @see WiseFyPrechecks.isDeviceConnectedToWifiNetworkChecks + * + * @author Patches + * @since 3.0 */ fun isDeviceConnectedToWifiNetwork_failure() { `when`(mockWiseFyPrechecks.isDeviceConnectedToWifiNetworkChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success checking if a device is connected to a wifi network. + * + * @see WiseFyPrechecks.isDeviceConnectedToWifiNetworkChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun isDeviceConnectedToWifiNetwork_success() { `when`(mockWiseFyPrechecks.isDeviceConnectedToWifiNetworkChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -231,11 +401,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure checking if a device is roaming. * * @see WiseFyPrechecks.isDeviceRoamingChecks + * + * @author Patches + * @since 3.0 */ fun isDeviceRoaming_failure() { `when`(mockWiseFyPrechecks.isDeviceRoamingChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success checking if a device is roaming. + * + * @see WiseFyPrechecks.isDeviceRoamingChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun isDeviceRoaming_success() { `when`(mockWiseFyPrechecks.isDeviceRoamingChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -244,11 +426,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure checking if a network is saved on a device. * * @see WiseFyPrechecks.isNetworkSavedChecks + * + * @author Patches + * @since 3.0 */ fun isNetworkSaved_failure() { `when`(mockWiseFyPrechecks.isNetworkSavedChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success checking if a network is saved on a device. + * + * @see WiseFyPrechecks.isNetworkSavedChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun isNetworkSaved_success() { `when`(mockWiseFyPrechecks.isNetworkSavedChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -257,11 +451,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure checking if Wifi is enabled on a device. * * @see WiseFyPrechecks.isWifiEnabledChecks + * + * @author Patches + * @since 3.0 */ fun isWifiEnabled_failure() { `when`(mockWiseFyPrechecks.isWifiEnabledChecks()).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success checking if Wifi is enabled on a device. + * + * @see WiseFyPrechecks.isWifiEnabledChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun isWifiEnabled_success() { `when`(mockWiseFyPrechecks.isWifiEnabledChecks()).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -270,11 +476,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure removing a network. * * @see WiseFyPrechecks.removeNetworkCheck + * + * @author Patches + * @since 3.0 */ fun removeNetwork_failure() { `when`(mockWiseFyPrechecks.removeNetworkCheck(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success removing a network. + * + * @see WiseFyPrechecks.removeNetworkCheck + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun removeNetwork_success() { `when`(mockWiseFyPrechecks.removeNetworkCheck(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -283,11 +501,23 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure searching for a nearby access point. * * @see WiseFyPrechecks.searchForAccessPointsChecks + * + * @author Patches + * @since 3.0 */ fun searchForAccessPoints_failure() { `when`(mockWiseFyPrechecks.searchForAccessPointsChecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success searching for a nearby access point. + * + * @see WiseFyPrechecks.searchForAccessPointsChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun searchForAccessPoints_success() { `when`(mockWiseFyPrechecks.searchForAccessPointsChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -296,24 +526,98 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure searching for nearby access points. * * @see WiseFyPrechecks.searchForAccessPointChecks + * + * @author Patches + * @since 3.0 */ fun searchForAccessPoint_failure() { `when`(mockWiseFyPrechecks.searchForAccessPointChecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success searching for nearby access points. + * + * @see WiseFyPrechecks.searchForAccessPointChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun searchForAccessPoint_success() { `when`(mockWiseFyPrechecks.searchForAccessPointChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) } + /** + * Mocks a precheck failure searching for a saved network. + * + * @see WiseFyPrechecks.searchForSavedNetworksChecks + * + * @author Patches + * @since 3.0 + */ + fun searchForSavedNetwork_failure() { + `when`(mockWiseFyPrechecks.searchForSavedNetworkChecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) + } + + /** + * Mocks a precheck success searching for a saved network. + * + * @see WiseFyPrechecks.searchForSavedNetworksChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ + fun searchForSavedNetwork_success() { + `when`(mockWiseFyPrechecks.searchForSavedNetworkChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) + } + + /** + * Mocks a precheck failure searching for saved networks. + * + * @see WiseFyPrechecks.searchForSavedNetworksChecks + * + * @author Patches + * @since 3.0 + */ + fun searchForSavedNetworks_failure() { + `when`(mockWiseFyPrechecks.searchForSavedNetworksChecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) + } + + /** + * Mocks a precheck success searching for saved networks. + * + * @see WiseFyPrechecks.searchForSavedNetworksChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ + fun searchForSavedNetworks_success() { + `when`(mockWiseFyPrechecks.searchForSavedNetworksChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) + } + /** * Mocks a precheck failure searching for an SSID. * * @see WiseFyPrechecks.searchForSSIDChecks + * + * @author Patches + * @since 3.0 */ fun searchForSSID_failure() { `when`(mockWiseFyPrechecks.searchForSSIDChecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success searching for an SSID. + * + * @see WiseFyPrechecks.searchForSSIDChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun searchForSSID_success() { `when`(mockWiseFyPrechecks.searchForSSIDChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) } @@ -322,17 +626,28 @@ internal class MockWiseFyPrechecksUtil internal constructor(private val mockWise * Mocks a precheck failure searching for SSIDs. * * @see WiseFyPrechecks.searchForSSIDsChecks + * + * @author Patches + * @since 3.0 */ fun searchForSSIDs_failure() { `when`(mockWiseFyPrechecks.searchForSSIDsChecks(anyString())).thenReturn(PRECHECK_RESULT_FAILURE) } + /** + * Mocks a precheck success searching for SSIDs. + * + * @see WiseFyPrechecks.searchForSSIDsChecks + * @see DEFAULT_PRECHECK_RESULT + * + * @author Patches + * @since 3.0 + */ fun searchForSSIDs_success() { `when`(mockWiseFyPrechecks.searchForSSIDsChecks(anyString())).thenReturn(DEFAULT_PRECHECK_RESULT) } companion object { - private val PRECHECK_RESULT_FAILURE = PrecheckResult(MISSING_PARAMETER) } } diff --git a/wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockWiseFySearchUtil.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockWiseFySearchUtil.kt similarity index 78% rename from wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockWiseFySearchUtil.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockWiseFySearchUtil.kt index 7b9f4094..169c524d 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/internal/mock/MockWiseFySearchUtil.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/internal/mock/MockWiseFySearchUtil.kt @@ -24,13 +24,32 @@ import org.mockito.Mockito.`when` * @see WiseFySearch * * @author Patches + * @since 3.0 */ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFySearch: WiseFySearch) { + /** + * Mocks no nearby access points. + * + * @see WiseFySearch.getNearbyAccessPoints + * + * @author Patches + * @since 3.0 + */ fun nearbyAccessPoints_null(filterDuplicates: Boolean) { `when`(mockWiseFySearch.getNearbyAccessPoints(filterDuplicates)).thenReturn(null) } + /** + * Mocks a list of nearby access point. + * + * @return List of ScanResult - The mocked list of nearby access points + * + * @see WiseFySearch.getNearbyAccessPoints + * + * @author Patches + * @since 3.0 + */ fun nearbyAccessPoints_success(filterDuplicates: Boolean): List { val accessPoints = createMockAccessPointList(TEST_SSID, TEST_RSSI_LEVEL_HIGH, TEST_SSID2, TEST_RSSI_LEVEL_LOW) `when`(mockWiseFySearch.getNearbyAccessPoints(filterDuplicates)).thenReturn(accessPoints) @@ -41,6 +60,9 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS * Mocks no nearby access point. * * @see WiseFySearch.findAccessPointByRegex + * + * @author Patches + * @since 3.0 */ fun findAccessPointByRegex_null() { `when`(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null) @@ -50,6 +72,11 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS * Mocks a nearby access point. * * @return ScanResult - The mocked nearby access point. + * + * @see WiseFySearch.findAccessPointByRegex + * + * @author Patches + * @since 3.0 */ fun findAccessPointByRegex_success(): ScanResult { val accessPoint = createMockAccessPointWithSSIDAndRSSI(TEST_SSID, TEST_RSSI_LEVEL) @@ -58,9 +85,12 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS } /** - * Mocks no nearby access points. + * Mocks no nearby access points for search. * * @see WiseFySearch.findAccessPointsMatchingRegex + * + * @author Patches + * @since 3.0 */ fun findAccessPointsMatchingRegex_null() { `when`>(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null) @@ -70,6 +100,11 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS * Mocks nearby access point. * * @return List of ScanResults - The mocked access points. + * + * @see WiseFySearch.findAccessPointsMatchingRegex + * + * @author Patches + * @since 3.0 */ fun findAccessPointsMatchingRegex_success(): List { val accessPoints = ArrayList() @@ -81,6 +116,11 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS /** * Mocks no saved network. + * + * @see WiseFySearch.findSavedNetworkByRegex + * + * @author Patches + * @since 3.0 */ fun findSavedNetworkByRegex_null() { `when`(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null) @@ -90,6 +130,11 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS * Mocks a saved network. * * @return WifiConfiguration - The mocked saved network + * + * @see WiseFySearch.findSavedNetworkByRegex + * + * @author Patches + * @since 3.0 */ fun findSavedNetworkByRegex_success(): WifiConfiguration { val savedNetwork = createSavedNetwork(TEST_SSID) @@ -101,6 +146,9 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS * Mocks an empty saved network list. * * @see WiseFySearch.findSavedNetworksMatchingRegex + * + * @author Patches + * @since 3.0 */ fun findSavedNetworksByRegex_emptyList() { `when`>(mockWiseFySearch.findSavedNetworksMatchingRegex(anyString())).thenReturn(ArrayList()) @@ -108,6 +156,11 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS /** * Mocks no saved networks. + * + * @see WiseFySearch.findSavedNetworksMatchingRegex + * + * @author Patches + * @since 3.0 */ fun findSavedNetworksByRegex_null() { `when`>(mockWiseFySearch.findSavedNetworksMatchingRegex(anyString())).thenReturn(null) @@ -117,6 +170,11 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS * Mocks a list of saved networks. * * @return List of WifiConfigurations - The mocked saved network list + * + * @see WiseFySearch.findSavedNetworksMatchingRegex + * + * @author Patches + * @since 3.0 */ fun findSavedNetworksMatchingRegex_success(): List { val savedNetworks = ArrayList() @@ -131,6 +189,11 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS * Mocks a list of nearby SSIDs. * * @return List of Strings - The mocked list of SSIDs. + * + * @see WiseFySearch.findSSIDsMatchingRegex + * + * @author Patches + * @since 3.0 */ fun findSSIDsMatchingRegex_success(): List { val ssids = ArrayList() @@ -141,6 +204,11 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS /** * Mocks no matching SSIDs. + * + * @see WiseFySearch.findSSIDsMatchingRegex + * + * @author Patches + * @since 3.0 */ fun findSSIDsMatchingRegex_null() { `when`>(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(null) @@ -150,6 +218,11 @@ internal class MockWiseFySearchUtil internal constructor(private val mockWiseFyS * Mocks if a network is already saved. * * @param saved If the network is already saved + * + * @see WiseFySearch.isNetworkASavedConfiguration + * + * @author Patches + * @since 3.0 */ fun isNetworkASavedConfiguration(saved: Boolean) { `when`(mockWiseFySearch.isNetworkASavedConfiguration(anyString())).thenReturn(saved) diff --git a/wisefy/src/test/java/com/isupatches/wisefy/search/AbstractWiseFySearchTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/search/AbstractWiseFySearchTests.kt similarity index 87% rename from wisefy/src/test/java/com/isupatches/wisefy/search/AbstractWiseFySearchTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/search/AbstractWiseFySearchTests.kt index 4a167946..3797c4b2 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/search/AbstractWiseFySearchTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/search/AbstractWiseFySearchTests.kt @@ -1,22 +1,23 @@ package com.isupatches.wisefy.search -import android.os.Build - import com.isupatches.wisefy.TEST_REGEX import com.isupatches.wisefy.TEST_SSID -import com.isupatches.wisefy.internal.base.BaseUnitTest + +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config +/** + * Used to test the AbstractWiseFySearch class and common search functionality. + * + * @see AbstractWiseFySearch + * + * @author Patches + * @since 4.0 + */ @Suppress("LargeClass", "TooManyFunctions") -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.JELLY_BEAN, Build.VERSION_CODES.P]) -internal class AbstractWiseFySearchTests : BaseUnitTest() { +internal class AbstractWiseFySearchTests : BaseInstrumentationTest() { private val wisefySearch: WiseFySearch = WiseFySearchSDK23.create(mockWifiManager) @@ -39,11 +40,6 @@ internal class AbstractWiseFySearchTests : BaseUnitTest() { assertEquals(null, wisefySearch.findSavedNetworksMatchingRegex(TEST_SSID)) } - @Test fun findSavedNetworkByRegex_failure_nullWifiConfiguration() { - mockNetworkUtil.savedNetworks_nullSavedNetwork() - assertEquals(null, wisefySearch.findSavedNetworkByRegex(TEST_SSID)) - } - @Test fun findSavedNetworkByRegex_failure_nullSSID() { mockNetworkUtil.savedNetworks_nullSSID() assertEquals(null, wisefySearch.findSavedNetworkByRegex(TEST_SSID)) @@ -98,11 +94,6 @@ internal class AbstractWiseFySearchTests : BaseUnitTest() { assertEquals(null, wisefySearch.findSavedNetworksMatchingRegex(TEST_SSID)) } - @Test fun findSavedNetworksMatchingRegex_failure_nullWifiConfiguration() { - mockNetworkUtil.savedNetworks_nullSavedNetwork() - assertEquals(null, wisefySearch.findSavedNetworksMatchingRegex(TEST_SSID)) - } - @Test fun findSavedNetworksMatchingRegex_failure_nullSSID() { mockNetworkUtil.savedNetworks_nullSSID() assertEquals(null, wisefySearch.findSavedNetworksMatchingRegex(TEST_SSID)) @@ -162,11 +153,6 @@ internal class AbstractWiseFySearchTests : BaseUnitTest() { assertEquals(false, wisefySearch.isNetworkASavedConfiguration(TEST_SSID)) } - @Test fun isNetworkASavedConfiguration_failure_nullWifiConfiguration() { - mockNetworkUtil.savedNetworks_nullSavedNetwork() - assertEquals(false, wisefySearch.isNetworkASavedConfiguration(TEST_SSID)) - } - @Test fun isNetworkASavedConfiguration_failure_nullSSID() { mockNetworkUtil.savedNetworks_nullSSID() assertEquals(false, wisefySearch.isNetworkASavedConfiguration(TEST_SSID)) diff --git a/wisefy/src/test/java/com/isupatches/wisefy/search/WiseFySearchLegacyTests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/search/WiseFySearchLegacyTests.kt similarity index 98% rename from wisefy/src/test/java/com/isupatches/wisefy/search/WiseFySearchLegacyTests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/search/WiseFySearchLegacyTests.kt index c8cb32a0..77c5e989 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/search/WiseFySearchLegacyTests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/search/WiseFySearchLegacyTests.kt @@ -1,31 +1,25 @@ package com.isupatches.wisefy.search -import android.os.Build - import com.isupatches.wisefy.TEST_REGEX import com.isupatches.wisefy.TEST_SSID import com.isupatches.wisefy.TEST_TIMEOUT -import com.isupatches.wisefy.internal.base.BaseUnitTest + +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assert.assertNull import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** - * Used to test the WiseFySearch class and search capabilities. + * Used to test the WiseFySearchLegacy class and search capabilities. * - * @see WiseFySearch + * @see WiseFySearchLegacy * * @author Patches + * @since 4.0 */ @Suppress("LargeClass", "TooManyFunctions") -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.JELLY_BEAN]) -internal class WiseFySearchLegacyTests : BaseUnitTest() { +internal class WiseFySearchLegacyTests : BaseInstrumentationTest() { private val wisefySearch: WiseFySearch = WiseFySearchLegacy.create(mockWifiManager) diff --git a/wisefy/src/test/java/com/isupatches/wisefy/search/WiseFySearchSdk23Tests.kt b/wisefy/src/androidTest/java/com/isupatches/wisefy/search/WiseFySearchSdk23Tests.kt similarity index 97% rename from wisefy/src/test/java/com/isupatches/wisefy/search/WiseFySearchSdk23Tests.kt rename to wisefy/src/androidTest/java/com/isupatches/wisefy/search/WiseFySearchSdk23Tests.kt index 4b065040..9399b1fc 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/search/WiseFySearchSdk23Tests.kt +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/search/WiseFySearchSdk23Tests.kt @@ -1,26 +1,39 @@ package com.isupatches.wisefy.search import android.os.Build - import com.isupatches.wisefy.TEST_REGEX import com.isupatches.wisefy.TEST_SSID import com.isupatches.wisefy.TEST_TIMEOUT -import com.isupatches.wisefy.internal.base.BaseUnitTest + +import com.isupatches.wisefy.internal.base.BaseInstrumentationTest import org.junit.Assert.assertEquals import org.junit.Assert.assertNull +import org.junit.Assume.assumeTrue +import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config +/** + * Used to test the WiseFySearchSDK23 class and search capabilities. + * + * @see WiseFySearchSDK23 + * + * @author Patches + * @since 4.0 + */ @Suppress("LargeClass", "TooManyFunctions") -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class WiseFySearchSdk23Tests : BaseUnitTest() { +internal class WiseFySearchSdk23Tests : BaseInstrumentationTest() { - private val wisefySearch: WiseFySearch = WiseFySearchSDK23.create(mockWifiManager) + private val wisefySearch: WiseFySearch by lazy { + WiseFySearchSDK23.create(mockWifiManager) + } + + @Before fun setUp() { + assumeTrue( + "Can only run on API Level 23 or newer", + Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + ) + } /* * findAccessPointByRegex tests diff --git a/wisefy/src/commonTest/java/com/isupatches/wisefy/TestUtils.kt b/wisefy/src/commonTest/java/com/isupatches/wisefy/TestUtils.kt index 67bd658d..ba45c952 100644 --- a/wisefy/src/commonTest/java/com/isupatches/wisefy/TestUtils.kt +++ b/wisefy/src/commonTest/java/com/isupatches/wisefy/TestUtils.kt @@ -36,9 +36,6 @@ internal const val TEST_IP_ADDRESS_STRING = "127.0.0.1" internal const val TEST_REGEX = ".*Test.*" -internal const val TEST_TYPE1 = "TYPE 1" -internal const val TEST_TYPE2 = "TYPE 2" - internal const val TEST_SSID2 = "Test Network 2" internal const val TEST_SSID3 = "Test Network 3" diff --git a/wisefy/src/debug/AndroidManifest.xml b/wisefy/src/debug/AndroidManifest.xml new file mode 100644 index 00000000..ca5d6d7f --- /dev/null +++ b/wisefy/src/debug/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/wisefy/src/main/java/com/isupatches/wisefy/WiseFy.kt b/wisefy/src/main/java/com/isupatches/wisefy/WiseFy.kt index 6e58a7af..c4f9bfe1 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/WiseFy.kt +++ b/wisefy/src/main/java/com/isupatches/wisefy/WiseFy.kt @@ -51,13 +51,14 @@ import com.isupatches.wisefy.callbacks.GetFrequencyCallbacks import com.isupatches.wisefy.callbacks.GetIPCallbacks import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks import com.isupatches.wisefy.callbacks.GetRSSICallbacks -import com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworkCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworksCallbacks import com.isupatches.wisefy.connection.WiseFyConnection import com.isupatches.wisefy.connection.WiseFyConnectionLegacy import com.isupatches.wisefy.connection.WiseFyConnectionSDK23 @@ -685,7 +686,7 @@ class WiseFy private constructor( * @see [runOnWiseFyThread] * @see [WifiManager.disconnect] * @see [WiseFyLock] - * @see [WiseFyPrechecks.disconnectFromCurrentNetworkChecks + * @see [WiseFyPrechecks.disconnectFromCurrentNetworkChecks] * * @author Patches * @since 3.0 @@ -714,8 +715,8 @@ class WiseFy private constructor( * Used to cleanup the thread started by WiseFy. * * @see [WiseFyConnection.destroy] - * @see WiseFyHandlerThread - * @see WiseFyLock + * @see [WiseFyHandlerThread] + * @see [WiseFyLock] * * Updates * - 05/12/2019: Added new call to [WiseFyConnection.destroy] @@ -809,8 +810,6 @@ class WiseFy private constructor( * * @return WifiInfo|null - The user's current network information * - * @throws SecurityException Without necessary permissions granted - * * @see [WifiInfo] * @see [WifiManager.getConnectionInfo] * @see [WiseFyPrechecks.getCurrentNetworkChecks] @@ -821,7 +820,6 @@ class WiseFy private constructor( @Sync @CallingThread @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - @Throws(SecurityException::class) override fun getCurrentNetwork(): WifiInfo? { return if (wisefyPrechecks.getCurrentNetworkChecks().passed()) { wifiManager.connectionInfo @@ -833,8 +831,6 @@ class WiseFy private constructor( * * @param callbacks The listener to return results to * - * @throws SecurityException Without necessary permissions granted - * * @see [GetCurrentNetworkCallbacks] * @see [runOnWiseFyThread] * @see [WifiInfo] @@ -936,8 +932,6 @@ class WiseFy private constructor( * * @return Integer - The frequency of the devices current network or null if no network * - * @throws SecurityException Without necessary permissions granted - * * @see [getCurrentNetwork] * @see [WifiInfo.getFrequency] * @@ -948,7 +942,6 @@ class WiseFy private constructor( @CallingThread @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - @Throws(SecurityException::class) override fun getFrequency(): Int? { val currentNetwork = getCurrentNetwork() return currentNetwork?.frequency @@ -959,8 +952,6 @@ class WiseFy private constructor( * * @param callbacks The listener to return results to * - * @throws SecurityException Without necessary permissions granted - * * @see [getCurrentNetwork] * @see [GetFrequencyCallbacks] * @see [runOnWiseFyThread] @@ -974,7 +965,6 @@ class WiseFy private constructor( @WiseFyThread @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - @Throws(SecurityException::class) override fun getFrequency(callbacks: GetFrequencyCallbacks?) { runOnWiseFyThread(Runnable { synchronized(wisefyLock) { @@ -1113,8 +1103,6 @@ class WiseFy private constructor( * * @return List of ScanResults|null - List of nearby access points * - * @throws SecurityException Without necessary permissions granted - * * @see [ScanResult] * @see [WiseFySearch.getNearbyAccessPoints] * @see [WiseFyPrechecks.getNearbyAccessPointsChecks] @@ -1128,7 +1116,6 @@ class WiseFy private constructor( @Sync @CallingThread @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - @Throws(SecurityException::class) override fun getNearbyAccessPoints(filterDuplicates: Boolean): List? { if (wisefyPrechecks.getNearbyAccessPointsChecks().failed()) { return null @@ -1140,7 +1127,8 @@ class WiseFy private constructor( /** * 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). + * *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 * @param callbacks The listener to return results to @@ -1259,67 +1247,6 @@ class WiseFy private constructor( }) } - /** - * To search for and return a saved WiFiConfiguration given an SSID. - * - * @param regexForSSID The ssid to use while searching for saved configuration - * - * @return WifiConfiguration|null - Saved network that matches the ssid - * - * @see [WifiConfiguration] - * @see [WiseFyPrechecks.getSavedNetworkChecks] - * @see [WiseFySearch.findSavedNetworkByRegex] - * - * @author Patches - * @since 3.0 - */ - @Sync - @CallingThread - @RequiresPermission(ACCESS_WIFI_STATE) - override fun getSavedNetwork(regexForSSID: String?): WifiConfiguration? { - return if (wisefyPrechecks.getSavedNetworkChecks(regexForSSID).passed()) { - wisefySearch.findSavedNetworkByRegex(regexForSSID!!) - } else null - } - - /** - * To search for and return a saved WiFiConfiguration given an SSID. - * - * @param regexForSSID The ssid to use while searching for saved configuration - * @param callbacks The listener to return results to - * - * @see [GetSavedNetworkCallbacks] - * @see [runOnWiseFyThread] - * @see [WifiConfiguration] - * @see [WiseFyLock] - * @see [WiseFyPrechecks.getSavedNetworkChecks] - * @see [WiseFySearch.findSavedNetworkByRegex] - * - * @author Patches - * @since 3.0 - */ - @Async - @WiseFyThread - @RequiresPermission(ACCESS_WIFI_STATE) - override fun getSavedNetwork(regexForSSID: String?, callbacks: GetSavedNetworkCallbacks?) { - runOnWiseFyThread(Runnable { - synchronized(wisefyLock) { - val precheck = wisefyPrechecks.getSavedNetworkChecks(regexForSSID) - if (precheck.failed()) { - callbacks?.wisefyFailure(precheck.code) - return@Runnable - } - - val savedNetwork = wisefySearch.findSavedNetworkByRegex(regexForSSID!!) - if (savedNetwork != null) { - callbacks?.retrievedSavedNetwork(savedNetwork) - } else { - callbacks?.savedNetworkNotFound() - } - } - }) - } - /** * To retrieve a list of saved networks on a user's device. * @@ -1378,71 +1305,10 @@ class WiseFy private constructor( }) } - /** - * To retrieve a list of saved networks on a user's device that match a given regex. - * - * @param regexForSSID The ssid to use while searching for saved configurations - * - * @return List of WifiConfigurations|null - The list of saved network configurations that match the given regex - * - * @see [WifiConfiguration] - * @see [WiseFyPrechecks.getSavedNetworksChecks] - * @see [WiseFySearch.findSavedNetworksMatchingRegex] - * - * @author Patches - * @since 3.0 - */ - @Sync - @CallingThread - @RequiresPermission(ACCESS_WIFI_STATE) - override fun getSavedNetworks(regexForSSID: String?): List? { - return if (wisefyPrechecks.getSavedNetworksChecks(regexForSSID).passed()) { - wisefySearch.findSavedNetworksMatchingRegex(regexForSSID!!) - } else null - } - - /** - * To retrieve a list of saved networks on a user's device that match a given regex. - * - * @param regexForSSID The ssid to use while searching for saved configurations - * @param callbacks The listener to return results to - * - * @see [GetSavedNetworksCallbacks] - * @see [runOnWiseFyThread] - * @see [WifiConfiguration] - * @see [WiseFyLock] - * @see [WiseFyPrechecks.getSavedNetworksChecks] - * @see [WiseFySearch.findSavedNetworksMatchingRegex] - * - * @author Patches - * @since 3.0 - */ - @Async - @WiseFyThread - @RequiresPermission(ACCESS_WIFI_STATE) - override fun getSavedNetworks(regexForSSID: String?, callbacks: GetSavedNetworksCallbacks?) { - runOnWiseFyThread(Runnable { - synchronized(wisefyLock) { - val precheck = wisefyPrechecks.getSavedNetworksChecks(regexForSSID) - if (precheck.failed()) { - callbacks?.wisefyFailure(precheck.code) - return@Runnable - } - - val savedNetworks = wisefySearch.findSavedNetworksMatchingRegex(regexForSSID!!) - if (savedNetworks != null && savedNetworks.isNotEmpty()) { - callbacks?.retrievedSavedNetworks(savedNetworks) - } else { - callbacks?.noSavedNetworksFound() - } - } - }) - } - /** * To retrieve the lock in use by WiseFy for synchronization. * - * @return WiseFyLock - The instance of the lock in use by WiseFy + * @return WiseFyLock - The instance of the lock in-use by WiseFy * * @see WiseFyLock * @@ -1575,8 +1441,6 @@ class WiseFy private constructor( * * @return boolean - If the network is 5gHz * - * @throws SecurityException Without necessary permissions granted - * * @see [getFrequency] * @see [MAX_FREQUENCY_5GHZ] * @see [MIN_FREQUENCY_5GHZ] @@ -1588,7 +1452,6 @@ class WiseFy private constructor( @CallingThread @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - @Throws(SecurityException::class) override fun isNetwork5gHz(): Boolean { val frequency = getFrequency() return frequency != null && frequency > MIN_FREQUENCY_5GHZ && frequency < MAX_FREQUENCY_5GHZ @@ -1853,7 +1716,6 @@ class WiseFy private constructor( /** * To return the first access point that matches a given regex. * - * * *NOTE* Setting filterDuplicates to true will not return an access point with a weaker signal strength (will always take the highest). * * @param regexForSSID The regex to use when iterating through nearby access points @@ -1885,7 +1747,6 @@ class WiseFy private constructor( /** * To return the first access point that matches a given regex. * - * * *NOTE* Setting filterDuplicates to true will not return an access point with a weaker signal strength (will always take the highest). * * @param regexForSSID The regex to use when iterating through nearby access points @@ -1933,7 +1794,6 @@ class WiseFy private constructor( /** * To return nearby access points that match a given regex. * - * * *NOTE* Setting filterDuplicates to true will not return access points with a weaker signal strength (will always take the highest). * * @param regexForSSID The regex to use when iterating through nearby access points @@ -1960,7 +1820,6 @@ class WiseFy private constructor( /** * To return nearby access points that match a given regex. * - * * *NOTE* Setting filterDuplicates to true will not return access points with a weaker signal strength (will always take the highest). * * @param regexForSSID The regex to use when iterating through nearby access points @@ -2003,6 +1862,128 @@ class WiseFy private constructor( }) } + /** + * To search for and return a saved WiFiConfiguration given an SSID. + * + * @param regexForSSID The ssid to use while searching for saved configuration + * + * @return WifiConfiguration|null - Saved network that matches the ssid + * + * @see [WifiConfiguration] + * @see [WiseFyPrechecks.searchForSavedNetworkChecks] + * @see [WiseFySearch.findSavedNetworkByRegex] + * + * @author Patches + * @since 3.0 + */ + @Sync + @CallingThread + @RequiresPermission(ACCESS_WIFI_STATE) + override fun searchForSavedNetwork(regexForSSID: String?): WifiConfiguration? { + return if (wisefyPrechecks.searchForSavedNetworkChecks(regexForSSID).passed()) { + wisefySearch.findSavedNetworkByRegex(regexForSSID!!) + } else null + } + + /** + * To search for and return a saved WiFiConfiguration given an SSID. + * + * @param regexForSSID The ssid to use while searching for saved configuration + * @param callbacks The listener to return results to + * + * @see [SearchForSavedNetworkCallbacks] + * @see [runOnWiseFyThread] + * @see [WifiConfiguration] + * @see [WiseFyLock] + * @see [WiseFyPrechecks.searchForSavedNetworkChecks] + * @see [WiseFySearch.findSavedNetworkByRegex] + * + * @author Patches + * @since 3.0 + */ + @Async + @WiseFyThread + @RequiresPermission(ACCESS_WIFI_STATE) + override fun searchForSavedNetwork(regexForSSID: String?, callbacks: SearchForSavedNetworkCallbacks?) { + runOnWiseFyThread(Runnable { + synchronized(wisefyLock) { + val precheck = wisefyPrechecks.searchForSavedNetworkChecks(regexForSSID) + if (precheck.failed()) { + callbacks?.wisefyFailure(precheck.code) + return@Runnable + } + + val savedNetwork = wisefySearch.findSavedNetworkByRegex(regexForSSID!!) + if (savedNetwork != null) { + callbacks?.retrievedSavedNetwork(savedNetwork) + } else { + callbacks?.savedNetworkNotFound() + } + } + }) + } + + /** + * To retrieve a list of saved networks on a user's device that match a given regex. + * + * @param regexForSSID The ssid to use while searching for saved configurations + * + * @return List of WifiConfigurations|null - The list of saved network configurations that match the given regex + * + * @see [WifiConfiguration] + * @see [WiseFyPrechecks.searchForSavedNetworksChecks] + * @see [WiseFySearch.findSavedNetworksMatchingRegex] + * + * @author Patches + * @since 3.0 + */ + @Sync + @CallingThread + @RequiresPermission(ACCESS_WIFI_STATE) + override fun searchForSavedNetworks(regexForSSID: String?): List? { + return if (wisefyPrechecks.searchForSavedNetworksChecks(regexForSSID).passed()) { + wisefySearch.findSavedNetworksMatchingRegex(regexForSSID!!) + } else null + } + + /** + * To retrieve a list of saved networks on a user's device that match a given regex. + * + * @param regexForSSID The ssid to use while searching for saved configurations + * @param callbacks The listener to return results to + * + * @see [SearchForSavedNetworksCallbacks] + * @see [runOnWiseFyThread] + * @see [WifiConfiguration] + * @see [WiseFyLock] + * @see [WiseFyPrechecks.searchForSavedNetworksChecks] + * @see [WiseFySearch.findSavedNetworksMatchingRegex] + * + * @author Patches + * @since 3.0 + */ + @Async + @WiseFyThread + @RequiresPermission(ACCESS_WIFI_STATE) + override fun searchForSavedNetworks(regexForSSID: String?, callbacks: SearchForSavedNetworksCallbacks?) { + runOnWiseFyThread(Runnable { + synchronized(wisefyLock) { + val precheck = wisefyPrechecks.searchForSavedNetworksChecks(regexForSSID) + if (precheck.failed()) { + callbacks?.wisefyFailure(precheck.code) + return@Runnable + } + + val savedNetworks = wisefySearch.findSavedNetworksMatchingRegex(regexForSSID!!) + if (savedNetworks != null && savedNetworks.isNotEmpty()) { + callbacks?.retrievedSavedNetworks(savedNetworks) + } else { + callbacks?.noSavedNetworksFound() + } + } + }) + } + /** * To search local networks and return the first one that contains a given ssid. * diff --git a/wisefy/src/main/java/com/isupatches/wisefy/WiseFyPrechecks.kt b/wisefy/src/main/java/com/isupatches/wisefy/WiseFyPrechecks.kt index 75b23f20..4f5f75f8 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/WiseFyPrechecks.kt +++ b/wisefy/src/main/java/com/isupatches/wisefy/WiseFyPrechecks.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018 Patches Klinefelter + * Copyright 2019 Patches Klinefelter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -197,14 +197,14 @@ internal class WiseFyPrechecksImpl private constructor( checkForParam(regexForSSID) /** - * Used internally to make sure perquisites for getting the saved networks on a device are met. + * Used internally to make sure perquisites for searching for a saved network on a device are met. * - * @param regexForSSID The regexForSSID param from [com.isupatches.wisefy.WiseFy.getSavedNetwork] + * @param regexForSSID The regexForSSID param from [com.isupatches.wisefy.WiseFy.searchForSavedNetwork] * * @return PrecheckResult - [DEFAULT_PRECHECK_RESULT] or a [PrecheckResult] with an error code. * * @see [checkForParam] - * @see [com.isupatches.wisefy.WiseFy.getSavedNetwork] + * @see [com.isupatches.wisefy.WiseFy.searchForSavedNetwork] * * @author Patches * @since 3.0 @@ -389,6 +389,39 @@ internal class WiseFyPrechecksImpl private constructor( override fun searchForAccessPointsChecks(regexForSSID: String?): PrecheckResult = checkForParam(regexForSSID) + /** + * Used internally to make sure prerequisites for searching for an individual saved network + * are met. + * + * @param regexForSSID The regexForSsid param from [com.isupatches.wisefy.WiseFy.searchForSavedNetwork] + * + * @return PrecheckResult - [DEFAULT_PRECHECK_RESULT] or a [PrecheckResult] with an error code. + * + * @see [checkForParam] + * @see [com.isupatches.wisefy.WiseFy.searchForSavedNetwork] + * + * @author Patches + * @since 4.0 + */ + override fun searchForSavedNetworkChecks(regexForSSID: String?): PrecheckResult = + checkForParam(regexForSSID) + + /** + * Used internally to make sure prerequisites for searching for saved networks are met. + * + * @param regexForSSID The regexForSsid param from [com.isupatches.wisefy.WiseFy.searchForSavedNetworks] + * + * @return PrecheckResult - [DEFAULT_PRECHECK_RESULT] or a [PrecheckResult] with an error code. + * + * @see [checkForParam] + * @see [com.isupatches.wisefy.WiseFy.searchForSavedNetworks] + * + * @author Patches + * @since 4.0 + */ + override fun searchForSavedNetworksChecks(regexForSSID: String?): PrecheckResult = + checkForParam(regexForSSID) + /** * Used internally to make sure prerequisites for searching for an individual SSID are met. * @@ -563,6 +596,10 @@ internal interface WiseFyPrechecks { fun searchForAccessPointsChecks(regexForSSID: String?): PrecheckResult + fun searchForSavedNetworkChecks(regexForSSID: String?): PrecheckResult + + fun searchForSavedNetworksChecks(regexForSSID: String?): PrecheckResult + fun searchForSSIDChecks(regexForSSID: String?): PrecheckResult fun searchForSSIDsChecks(regexForSSID: String?): PrecheckResult diff --git a/wisefy/src/main/java/com/isupatches/wisefy/WisePublicApi.kt b/wisefy/src/main/java/com/isupatches/wisefy/WisePublicApi.kt index 8246c876..9efff79d 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/WisePublicApi.kt +++ b/wisefy/src/main/java/com/isupatches/wisefy/WisePublicApi.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018 Patches Klinefelter + * Copyright 2019 Patches Klinefelter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,19 +31,19 @@ import com.isupatches.wisefy.callbacks.GetFrequencyCallbacks import com.isupatches.wisefy.callbacks.GetIPCallbacks import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks import com.isupatches.wisefy.callbacks.GetRSSICallbacks -import com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworkCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworksCallbacks /** * The interface that is the public facing API for WiseFy. It is composed of various other sub-apis for separation * of functionality. * - * @see [WiseFy] * @see [AccessPointApi] * @see [AddNetworkApi] * @see [ConnectionApi] @@ -59,13 +59,42 @@ import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks * @author Patches * @since 3.0 */ -internal interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, +interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionApi, DeviceApi, FrequencyApi, NetworkInfoApi, RemoveNetworkApi, SavedNetworkApi, SecurityApi, SignalStrengthApi, WifiApi { + /** + * Used to cleanup the thread started by WiseFy. + * + * @see [WiseFy.dump] + * + * @author Patches + * @since 3.0 + */ fun dump() + /** + * To retrieve the lock in use by WiseFy for synchronization. + * + * @return WiseFyLock - The instance of the lock in-use by WiseFy + * + * @see [WiseFy.getWiseFyLock] + * @see [WiseFyLock] + * + * @author Patches + * @since 3.0 + */ fun getWiseFyLock(): WiseFyLock + /** + * To query if logging is enabled or disabled for a WiseFy instance. + * + * @return boolean - If logging is enabled for the WiseFy instance + * + * @see [WiseFy.isLoggingEnabled] + * + * @author Patches + * @since 3.0 + */ fun isLoggingEnabled(): Boolean } @@ -75,14 +104,77 @@ internal interface WiseFyPublicApi : AccessPointApi, AddNetworkApi, ConnectionAp * @author Patches * @since 3.0 */ -internal interface AccessPointApi { - +interface AccessPointApi { + + /** + * To retrieve a list of nearby access points. + * + * *NOTE* Setting filterDuplicates to true will exclude access points for an SSID that have a weaker RSSI + * (will always take the highest signal strength). + * + * @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 + * + * @see [WiseFy.getNearbyAccessPoints] + * @see [ScanResult] + * + * @author Patches + * @since 3.0 + */ fun getNearbyAccessPoints(filterDuplicates: Boolean): List? + /** + * 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 + * @param callbacks The listener to return results to + * + * @see [WiseFy.getNearbyAccessPoints] + * @see [GetNearbyAccessPointsCallbacks] + + * @author Patches + * @since 3.0 + */ fun getNearbyAccessPoints(filterDuplicates: Boolean, callbacks: GetNearbyAccessPointsCallbacks?) + /** + * To retrieve the RSSI of the first network matching a given regex. + * + * *NOTE* Setting takeHighest to true will return the access point with the highest RSSI for the given SSID. + * + * @param regexForSSID The regex to be used to search for the ssid + * @param takeHighest Whether to return the access point with the highest RSSI for the given SSID + * @param timeoutInMillis The amount of time to search for a matching SSID + * + * @return Integer - The RSSI value for the found SSID or null if no matching network found + * + * @see [WiseFy.getRSSI] + * + * @author Patches + * @since 3.0 + */ fun getRSSI(regexForSSID: String?, takeHighest: Boolean, timeoutInMillis: Int): Int? + /** + * To retrieve the RSSI of the first network matching a given regex. + * + * *NOTE* Setting takeHighest to true will return the access point with the highest RSSI for the given SSID. + * + * @param regexForSSID The regex to be used to search for the ssid + * @param takeHighest Whether to return the access point with the highest RSSI for the given SSID + * @param timeoutInMillis The amount of time to search for a matching SSID + * @param callbacks The listener to return results to + * + * @see [WiseFy.getRSSI] + * @see [GetRSSICallbacks] + * + * @author Patches + * @since 3.0 + */ fun getRSSI( regexForSSID: String?, takeHighest: Boolean, @@ -90,12 +182,45 @@ internal interface AccessPointApi { callbacks: GetRSSICallbacks? ) + /** + * To return the first access point that matches a given regex. + * + * *NOTE* Setting filterDuplicates to true will not return an access point with a weaker signal strength (will always take the highest). + * + * @param regexForSSID The regex to use when iterating through nearby access points + * @param timeoutInMillis The amount of time (in milliseconds) to wait for a matching access point + * @param filterDuplicates If you want to exclude access points with the same name that have a weaker signal strength + * + * @return ScanResult|null - The first access point or access point with the highest signal strength matching the regex + * + * @see [WiseFy.searchForAccessPoint] + * @see [ScanResult] + * + * @author Patches + * @since 3.0 + */ fun searchForAccessPoint( regexForSSID: String?, timeoutInMillis: Int, filterDuplicates: Boolean ): ScanResult? + /** + * To return the first access point that matches a given regex. + * + * *NOTE* Setting filterDuplicates to true will not return an access point with a weaker signal strength (will always take the highest). + * + * @param regexForSSID The regex to use when iterating through nearby access points + * @param timeoutInMillis The amount of time (in milliseconds) to wait for a matching access point + * @param filterDuplicates If you want to exclude access points with the same name that have a weaker signal strength + * @param callbacks The listener to return results to + * + * @see [WiseFy.searchForAccessPoint] + * @see [SearchForAccessPointCallbacks] + * + * @author Patches + * @since 3.0 + */ fun searchForAccessPoint( regexForSSID: String?, timeoutInMillis: Int, @@ -103,20 +228,101 @@ internal interface AccessPointApi { callbacks: SearchForAccessPointCallbacks? ) + /** + * To return nearby access points that match a given regex. + * + * *NOTE* Setting filterDuplicates to true will not return access points with a weaker signal strength (will always take the highest). + * + * @param regexForSSID The regex to use when iterating through nearby access points + * @param filterDuplicates If you want to exclude access points with the same name that have a weaker signal strength + * + * @return List of ScanResult|null - The list of matching access points or null if none match the given regex + * + * @see [WiseFy.searchForAccessPoints] + * @see [ScanResult] + * + * @author Patches + * @since 3.0 + */ fun searchForAccessPoints(regexForSSID: String?, filterDuplicates: Boolean): List? + /** + * To return nearby access points that match a given regex. + * + * *NOTE* Setting filterDuplicates to true will not return access points with a weaker signal strength (will always take the highest). + * + * @param regexForSSID The regex to use when iterating through nearby access points + * @param filterDuplicates If you want to exclude access points with the same name that have a weaker signal strength + * @param callbacks The listener to return results to + * + * @see [WiseFy.searchForAccessPoints] + * @see [SearchForAccessPointsCallbacks] + * + * @author Patches + * @since 3.0 + */ fun searchForAccessPoints( regexForSSID: String?, filterDuplicates: Boolean, callbacks: SearchForAccessPointsCallbacks? ) + /** + * To search local networks and return the first one that contains a given ssid. + * + * @param regexForSSID The regex to be used to search for the ssid + * @param timeoutInMillis The number of milliseconds to keep searching for the SSID + * + * @return String|null - The first SSID that contains the search ssid (if any, else null) + * + * @see [WiseFy.searchForSSID] + * + * @author Patches + * @since 3.0 + */ fun searchForSSID(regexForSSID: String?, timeoutInMillis: Int): String? + /** + * To search local networks and return the first one that contains a given ssid. + * + * @param regexForSSID The regex to be used to search for the ssid + * @param timeoutInMillis The number of milliseconds to keep searching for the SSID + * @param callbacks The listener to return results to + * + * @see [WiseFy.searchForSSID] + * @see [SearchForSSIDCallbacks] + * + * @author Patches + * @since 3.0 + */ fun searchForSSID(regexForSSID: String?, timeoutInMillis: Int, callbacks: SearchForSSIDCallbacks?) + /** + * To search local networks and return the first one that contains a given ssid. + * + * @param regexForSSID The regex to be used to search for the ssid + * + * @return String|null - The first SSID that contains the search ssid (if any, else null) + * + * @see [WiseFy.searchForSSIDs] + * + * @author Patches + * @since 3.0 + */ fun searchForSSIDs(regexForSSID: String?): List? + /** + * To search local networks and return the first one that contains a given ssid. + * + * @param regexForSSID The regex to be used to search for the ssid + * @param callbacks The listener to return results to + * + * @see [WiseFy.searchForSSIDs] + * @see [SearchForSSIDsCallbacks] + * + * @author Patches + * @since 3.0 + */ fun searchForSSIDs(regexForSSID: String?, callbacks: SearchForSSIDsCallbacks?) } @@ -126,18 +332,94 @@ internal interface AccessPointApi { * @author Patches * @since 3.0 */ -internal interface AddNetworkApi { - +interface AddNetworkApi { + + /** + * 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) + * + * @see [WiseFy.addOpenNetwork] + * + * @author Patches + * @since 3.0 + */ fun addOpenNetwork(ssid: String?): Int + /** + * To add an open network to the user's configured network list. + * + * @param ssid The ssid of the open network you want to add + * @param callbacks The listener to return results to + * + * @see [WiseFy.addOpenNetwork] + * @see [AddNetworkCallbacks] + * + * @author Patches + * @since 3.0 + */ fun addOpenNetwork(ssid: String?, callbacks: AddNetworkCallbacks?) + /** + * 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) + * + * @see [WiseFy.addWEPNetwork] + * + * @author Patches + * @since 3.0 + */ fun addWEPNetwork(ssid: String?, password: String?): Int + /** + * 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 + * @param callbacks The listener to return results to + * + * @see [WiseFy.addWEPNetwork] + * @see [AddNetworkCallbacks] + + * @author Patches + * @since 3.0 + */ fun addWEPNetwork(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?) + /** + * 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) + * + * @see [WiseFy.addWPA2Network] + * + * @author Patches + * @since 3.0 + */ fun addWPA2Network(ssid: String?, password: String?): Int + /** + * 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 + * @param callbacks The listener to return results to + * + * @see [WiseFy.addWPA2Network] + * @see [AddNetworkCallbacks] + * + * @author Patches + * @since 3.0 + */ fun addWPA2Network(ssid: String?, password: String?, callbacks: AddNetworkCallbacks?) } @@ -147,18 +429,65 @@ internal interface AddNetworkApi { * @author Patches * @since 3.0 */ -internal interface ConnectionApi { - +interface ConnectionApi { + + /** + * Used to connect to a network. + * + * @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 + * + * @see [WiseFy.connectToNetwork] + * + * @author Patches + * @since 3.0 + */ fun connectToNetwork(ssidToConnectTo: String?, timeoutInMillis: Int): Boolean + /** + * Used to connect to a network. + * + * @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 + * @param callbacks The listener to return results to + * + * @see [WiseFy.connectToNetwork] + * @see [ConnectToNetworkCallbacks] + * + * @author Patches + * @since 3.0 + */ fun connectToNetwork( ssidToConnectTo: String?, timeoutInMillis: Int, callbacks: ConnectToNetworkCallbacks? ) + /** + * To disconnect the user from their current network. + * + * @return boolean - If the command succeeded in disconnecting the device from the current network + * + * @see [WiseFy.disconnectFromCurrentNetwork] + * + * @author Patches + * @since 3.0 + */ fun disconnectFromCurrentNetwork(): Boolean + /** + * To disconnect the user from their current network. + * + * @param callbacks The listener to return results to + * + * @see [WiseFy.disconnectFromCurrentNetwork] + * @see [DisconnectFromCurrentNetworkCallbacks] + * + * @author Patches + * @since 3.0 + */ fun disconnectFromCurrentNetwork(callbacks: DisconnectFromCurrentNetworkCallbacks?) } @@ -168,16 +497,68 @@ internal interface ConnectionApi { * @author Patches * @since 3.0 */ -internal interface DeviceApi { - +interface DeviceApi { + + /** + * To check if the device is connected to a mobile network. + * + * @return bool - If the device is currently connected to a mobile network + * + * @see [WiseFy.isDeviceConnectedToMobileNetwork] + * + * @author Patches + * @since 3.0 + */ fun isDeviceConnectedToMobileNetwork(): Boolean + /** + * 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 + * + * @see [WiseFy.isDeviceConnectedToMobileOrWifiNetwork] + * + * @author Patches + * @since 3.0 + */ fun isDeviceConnectedToMobileOrWifiNetwork(): Boolean + /** + * To check if the device is connected to a given SSID. + * + * @param ssid The SSID to check if the device is attached to + * + * @return bool - If the device is currently attached to the given SSID + * + * @see [WiseFy.isDeviceConnectedToSSID] + * + * @author Patches + * @since 3.0 + */ fun isDeviceConnectedToSSID(ssid: String?): Boolean + /** + * To check if the device is connected to a wifi network. + * + * @return bool - If the device is currently connected to a wifi network + * + * @see [WiseFy.isDeviceConnectedToWifiNetwork] + * + * @author Patches + * @since 3.0 + */ fun isDeviceConnectedToWifiNetwork(): Boolean + /** + * To query if the device is roaming. + * + * @return boolean - If the current network is roaming + * + * @see [WiseFy.isDeviceRoaming] + * + * @author Patches + * @since 3.0 + */ fun isDeviceRoaming(): Boolean } @@ -187,18 +568,89 @@ internal interface DeviceApi { * @author Patches * @since 3.0 */ -internal interface FrequencyApi { - +interface FrequencyApi { + + /** + * To retrieve the frequency of the device's current network. + * + * @return Integer - The frequency of the devices current network or null if no network + * + * @see [WiseFy.getFrequency] + * + * @author Patches + * @since 3.0 + */ fun getFrequency(): Int? + /** + * To retrieve the frequency of the device's current network. + * + * @param callbacks The listener to return results to + * + * @see [WiseFy.getFrequency] + * @see [GetFrequencyCallbacks] + * + * @author Patches + * @since 3.0 + */ fun getFrequency(callbacks: GetFrequencyCallbacks?) + /** + * To retrieve the frequency of a network. + * + * @param network The network to return the frequency of + * + * @return Integer - The frequency of the devices current network or null if no network + * + * @see [WiseFy.getFrequency] + * @see [WifiInfo] + * + * @author Patches + * @since 3.0 + */ fun getFrequency(network: WifiInfo?): Int? + /** + * To retrieve the frequency of a network. + * + * @param network The network to return the frequency of + * @param callbacks The listener to return results to + * + * @see [WiseFy.getFrequency] + * @see [GetFrequencyCallbacks] + * @see [WifiInfo] + * + * @author Patches + * @since 3.0 + */ fun getFrequency(network: WifiInfo?, callbacks: GetFrequencyCallbacks?) + /** + * To check if the device's current network is 5gHz. + * + * @return boolean - If the network is 5gHz + * + * @see [WiseFy.isNetwork5gHz] + * @see [getFrequency] + * + * @author Patches + * @since 3.0 + */ fun isNetwork5gHz(): Boolean + /** + * To check if a given network is 5gHz. + * + * @param network The network to check if it's 5gHz + * + * @return boolean - If the network is 5gHz + * + * @see [WiseFy.isNetwork5gHz] + * @see [WifiInfo] + * + * @author Patches + * @since 3.0 + */ fun isNetwork5gHz(network: WifiInfo?): Boolean } @@ -208,18 +660,83 @@ internal interface FrequencyApi { * @author Patches * @since 3.0 */ -internal interface NetworkInfoApi { - +interface NetworkInfoApi { + + /** + * To retrieve the user's current network. + * + * @return WifiInfo|null - The user's current network information + * + * @see [WiseFy.getCurrentNetwork] + * @see [WifiInfo] + * + * @author Patches + * @since 3.0 + */ fun getCurrentNetwork(): WifiInfo? + /** + * To retrieve the user's current network. + * + * @param callbacks The listener to return results to + * + * @see [WiseFy.getCurrentNetwork] + * @see [GetCurrentNetworkCallbacks] + * + * @author Patches + * @since 3.0 + */ fun getCurrentNetwork(callbacks: GetCurrentNetworkCallbacks?) + /** + * To retrieve the details of the phones active network. + * + * @return NetworkInfo + * + * @see [WiseFy.getCurrentNetworkInfo] + * @see [NetworkInfo] + * + * @author Patches + * @since 3.0 + */ fun getCurrentNetworkInfo(): NetworkInfo? + /** + * To retrieve the details of the phones active network. + * + * @param callbacks The listener to return results to + * + * @see [WiseFy.getCurrentNetworkInfo] + * @see [GetCurrentNetworkInfoCallbacks] + * + * @author Patches + * @since 3.0 + */ fun getCurrentNetworkInfo(callbacks: GetCurrentNetworkInfoCallbacks?) + /** + * To retrieve the IPv4 or IPv6 of a device. + * + * @return String - The IPv4 or IPv6 address + * + * @see [WiseFy.getIP] + * + * @author Patches + * @since 3.0 + */ fun getIP(): String? + /** + * To retrieve the IPv4 or IPv6 of a device. + * + * @param callbacks The listener to return results to + * + * @see [WiseFy.getIP] + * @see [GetIPCallbacks] + * + * @author Patches + * @since 3.0 + */ fun getIP(callbacks: GetIPCallbacks?) } @@ -229,10 +746,34 @@ internal interface NetworkInfoApi { * @author Patches * @since 3.0 */ -internal interface RemoveNetworkApi { - +interface RemoveNetworkApi { + + /** + * 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 + * + * @see [WiseFy.removeNetwork] + * + * @author Patches + * @since 3.0 + */ fun removeNetwork(ssidToRemove: String?): Boolean + /** + * To remove a configured network. + * + * @param ssidToRemove The ssid of the network you want to remove from the configured network list + * @param callbacks The listener to return results to + * + * @see [WiseFy.removeNetwork] + * @see [RemoveNetworkCallbacks] + * + * @author Patches + * @since 3.0 + */ fun removeNetwork(ssidToRemove: String?, callbacks: RemoveNetworkCallbacks?) } @@ -242,21 +783,105 @@ internal interface RemoveNetworkApi { * @author Patches * @since 3.0 */ -internal interface SavedNetworkApi { - - fun getSavedNetwork(regexForSSID: String?): WifiConfiguration? - - fun getSavedNetwork(regexForSSID: String?, callbacks: GetSavedNetworkCallbacks?) - +interface SavedNetworkApi { + + /** + * 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 + * + * @see [WiseFy.getSavedNetworks] + * @see [WifiConfiguration] + * + * @author Patches + * @since 3.0 + */ fun getSavedNetworks(): List? + /** + * To retrieve a list of saved networks on a user's device. + * + * @param callbacks The listener to return results to + * + * @see [WiseFy.getSavedNetworks] + * @see [GetSavedNetworksCallbacks] + * + * @author Patches + * @since 3.0 + */ fun getSavedNetworks(callbacks: GetSavedNetworksCallbacks?) - fun getSavedNetworks(regexForSSID: String?): List? - - fun getSavedNetworks(regexForSSID: String?, callbacks: GetSavedNetworksCallbacks?) - + /** + * 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 + * + * @see [WiseFy.isNetworkSaved] + * + * @author Patches + * @since 3.0 + */ fun isNetworkSaved(ssid: String?): Boolean + + /** + * To search for and return a saved WiFiConfiguration given an SSID. + * + * @param regexForSSID The ssid to use while searching for saved configuration + * + * @return WifiConfiguration|null - Saved network that matches the ssid + * + * @see [WiseFy.searchForSavedNetwork] + * @see [WifiConfiguration] + * + * @author Patches + * @since 3.0 + */ + fun searchForSavedNetwork(regexForSSID: String?): WifiConfiguration? + + /** + * To search for and return a saved WiFiConfiguration given an SSID. + * + * @param regexForSSID The ssid to use while searching for saved configuration + * @param callbacks The listener to return results to + * + * @see [WiseFy.searchForSavedNetwork] + * @see [SearchForSavedNetworkCallbacks] + * + * @author Patches + * @since 3.0 + */ + fun searchForSavedNetwork(regexForSSID: String?, callbacks: SearchForSavedNetworkCallbacks?) + + /** + * To retrieve a list of saved networks on a user's device that match a given regex. + * + * @param regexForSSID The ssid to use while searching for saved configurations + * + * @return List of WifiConfigurations|null - The list of saved network configurations that match the given regex + * + * @see [WiseFy.searchForSavedNetworks] + * @see [WifiConfiguration] + * + * @author Patches + * @since 3.0 + */ + fun searchForSavedNetworks(regexForSSID: String?): List? + + /** + * To retrieve a list of saved networks on a user's device that match a given regex. + * + * @param regexForSSID The ssid to use while searching for saved configurations + * @param callbacks The listener to return results to + * + * @see [WiseFy.searchForSavedNetworks] + * @see [SearchForSavedNetworksCallbacks] + * + * @author Patches + * @since 3.0 + */ + fun searchForSavedNetworks(regexForSSID: String?, callbacks: SearchForSavedNetworksCallbacks?) } /** @@ -265,18 +890,96 @@ internal interface SavedNetworkApi { * @author Patches * @since 3.0 */ -internal interface SecurityApi { - +interface SecurityApi { + + /** + * To check and return if a network is a EAP network. + * + * @param scanResult The network to check + * + * @return boolean - Whether the network has EAP capabilities listed + * + * @see [WiseFy.isNetworkEAP] + * @see [ScanResult] + * + * @author Patches + * @since 3.0 + */ fun isNetworkEAP(scanResult: ScanResult?): Boolean + /** + * To check and return if a network is a PSK network. + * + * @param scanResult The network to check + * + * @return boolean - Whether the network has PSK capabilities listed + * + * @see [WiseFy.isNetworkPSK] + * @see [ScanResult] + * + * @author Patches + * @since 3.0 + */ fun isNetworkPSK(scanResult: ScanResult?): Boolean + /** + * To check and return if a network is secure (contains EAP/PSK/WEP/WPA/WPA2 capabilities). + * + * @param scanResult The network to see if it is secure + * + * @return boolean - Whether the network is secure + * + * @see [WiseFy.isNetworkSecure] + * @see [ScanResult] + * + * @author Patches + * @since 3.0 + */ fun isNetworkSecure(scanResult: ScanResult?): Boolean + /** + * To check and return if a network is a WEP network. + * + * @param scanResult The network to check + * + * @return boolean - Whether the network has WEP capabilities listed + * + * @see [WiseFy.isNetworkWEP] + * @see [ScanResult] + * + * @author Patches + * @since 3.0 + */ fun isNetworkWEP(scanResult: ScanResult?): Boolean + /** + * To check and return if a network is a WPA network. + * + * @param scanResult The network to check + * + * @return boolean - Whether the network has WPA capabilities listed + * + * @see [WiseFy.isNetworkWPA] + * @see [ScanResult] + * + * @author Patches + * @since 3.0 + */ fun isNetworkWPA(scanResult: ScanResult?): Boolean + /** + * To check and return if a network is a WPA2 network. + * + * @param scanResult The network to check + * + * @return boolean - Whether the network has WPA2 capabilities listed + * + * @see [WiseFy.isNetworkWPA2] + * @see [ScanResult]] + * + * @author Patches + * @since 3.0 + */ fun isNetworkWPA2(scanResult: ScanResult?): Boolean } @@ -286,10 +989,41 @@ internal interface SecurityApi { * @author Patches * @since 3.0 */ -internal interface SignalStrengthApi { - +interface SignalStrengthApi { + + /** + * 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 + * + * @see [WiseFy.calculateBars] + * + * @author Patches + * @since 3.0 + */ fun calculateBars(rssiLevel: Int, targetNumberOfBars: Int): Int + /** + * To compare the signal strength of two networks. + * + * This method will return: + * - Negative value if the first signal is weaker than the second signal + * - 0 if the two signals have the same strength + * - Positive value if the first signal is stronger than the second signal + * + * @param rssi1 The signal strength of network 1 + * @param rssi2 The signal strength of network 2 + * + * @return int - The result of the comparison + * + * @see [WiseFy.compareSignalLevel] + * + * @author Patches + * @since 3.0 + */ fun compareSignalLevel(rssi1: Int, rssi2: Int): Int } @@ -299,15 +1033,65 @@ internal interface SignalStrengthApi { * @author Patches * @since 3.0 */ -internal interface WifiApi { - +interface WifiApi { + + /** + * To disable Wifi on a user's device. + * + * @return boolean - True if the command succeeded in disabling wifi + * + * @see [WiseFy.disableWifi] + * + * @author Patches + * @since 3.0 + */ fun disableWifi(): Boolean + /** + * To disable Wifi on a user's device. + * + * @see [WiseFy.disableWifi] + * @see [DisableWifiCallbacks] + * + * @author Patches + * @since 3.0 + */ fun disableWifi(callbacks: DisableWifiCallbacks?) + /** + * To enable Wifi on a user's device. + * + * @return boolean - If the command succeeded in enabling wifi + * + * @see [WiseFy.enableWifi] + * + * @author Patches + * @since 3.0 + */ fun enableWifi(): Boolean + /** + * To enable Wifi on a user's device. + * + * @param callbacks The listener to return results to + * + * @see [WiseFy.enableWifi] + * @see [EnableWifiCallbacks] + * + * @author Patches + * @since 3.0 + */ fun enableWifi(callbacks: EnableWifiCallbacks?) + /** + * To check if Wifi is enabled on the device or not. + * + * @return boolean - if Wifi is enabled on device + * + * @see [WiseFy.isWifiEnabled] + * + * @author Patches + * @since 3.0 + */ fun isWifiEnabled(): Boolean } diff --git a/wisefy/src/main/java/com/isupatches/wisefy/callbacks/GetCurrentNetworkInfoCallbacks.kt b/wisefy/src/main/java/com/isupatches/wisefy/callbacks/GetCurrentNetworkInfoCallbacks.kt index f672bd7f..e95adc83 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/callbacks/GetCurrentNetworkInfoCallbacks.kt +++ b/wisefy/src/main/java/com/isupatches/wisefy/callbacks/GetCurrentNetworkInfoCallbacks.kt @@ -47,5 +47,5 @@ interface GetCurrentNetworkInfoCallbacks : BaseCallback { * @author Patches * @since 3.0 */ - fun retrievedCurrentNetworkInfo(currentNetworkDetails: NetworkInfo) + fun retrievedCurrentNetworkInfo(currentNetworkInfo: NetworkInfo) } diff --git a/wisefy/src/main/java/com/isupatches/wisefy/callbacks/GetSavedNetworkCallbacks.kt b/wisefy/src/main/java/com/isupatches/wisefy/callbacks/SearchForSavedNetworkCallbacks.kt similarity index 78% rename from wisefy/src/main/java/com/isupatches/wisefy/callbacks/GetSavedNetworkCallbacks.kt rename to wisefy/src/main/java/com/isupatches/wisefy/callbacks/SearchForSavedNetworkCallbacks.kt index afd41bbe..1336d6e9 100644 --- a/wisefy/src/main/java/com/isupatches/wisefy/callbacks/GetSavedNetworkCallbacks.kt +++ b/wisefy/src/main/java/com/isupatches/wisefy/callbacks/SearchForSavedNetworkCallbacks.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018 Patches Klinefelter + * Copyright 2019 Patches Klinefelter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,18 +21,18 @@ import android.net.wifi.WifiConfiguration * Callbacks for retrieving a saved network on a device. * * @see [BaseCallback] - * @see [com.isupatches.wisefy.WiseFy.getSavedNetwork] + * @see [com.isupatches.wisefy.WiseFy.searchForSavedNetwork] * * @author Patches - * @see 3.0 + * @see 4.0 */ -interface GetSavedNetworkCallbacks : BaseCallback { +interface SearchForSavedNetworkCallbacks : BaseCallback { /** - * Called when the given network is not a saved configuration. + * Called when there are no saved network configurations matching search criteria. * * @author Patches - * @since 3.0 + * @since 4.0 */ fun savedNetworkNotFound() @@ -42,7 +42,7 @@ interface GetSavedNetworkCallbacks : BaseCallback { * @see [WifiConfiguration] * * @author Patches - * @since 3.0 + * @since 4.0 */ fun retrievedSavedNetwork(savedNetwork: WifiConfiguration) } diff --git a/wisefy/src/main/java/com/isupatches/wisefy/callbacks/SearchForSavedNetworksCallbacks.kt b/wisefy/src/main/java/com/isupatches/wisefy/callbacks/SearchForSavedNetworksCallbacks.kt new file mode 100644 index 00000000..266e707d --- /dev/null +++ b/wisefy/src/main/java/com/isupatches/wisefy/callbacks/SearchForSavedNetworksCallbacks.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2019 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.callbacks + +import android.net.wifi.WifiConfiguration + +/** + * Callbacks for retrieving a list of saved networks on a device. + * + * @see [BaseCallback] + * @see [com.isupatches.wisefy.WiseFy.searchForSavedNetworks] + * + * @author Patches + * @since 4.0 + */ +interface SearchForSavedNetworksCallbacks : BaseCallback { + + /** + * Called when there are no saved network configuration on the device matching the + * given search criteria. + * + * @author Patches + * @since 4.0 + */ + fun noSavedNetworksFound() + + /** + * Called when WiseFy has successfully retrieved a list of saved networks matching + * the given search criteria. + * + * @see [WifiConfiguration] + * + * @author Patches + * @since 3.0 + */ + fun retrievedSavedNetworks(savedNetworks: List<@JvmSuppressWildcards WifiConfiguration>) +} diff --git a/wisefy/src/test/java/com/isupatches/wisefy/GetSavedNetworkTests.kt b/wisefy/src/test/java/com/isupatches/wisefy/GetSavedNetworkTests.kt deleted file mode 100644 index 73331d43..00000000 --- a/wisefy/src/test/java/com/isupatches/wisefy/GetSavedNetworkTests.kt +++ /dev/null @@ -1,85 +0,0 @@ -package com.isupatches.wisefy - -import android.os.Build - -import com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks -import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest - -import org.junit.Assert.assertEquals -import org.junit.Test -import org.junit.runner.RunWith - -import org.mockito.Mockito.mock -import org.mockito.Mockito.timeout -import org.mockito.Mockito.verify - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - -/** - * Tests the ability to retrieve a saved on a device. - * - * @author Patches - */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class GetSavedNetworkTests : BaseUnitTest() { - - @Test fun sync_failure_prechecks() { - mockWiseFyPrechecksUtil.getSavedNetwork_failure() - assertEquals(null, wisefy.getSavedNetwork(TEST_SSID)) - } - - @Test fun sync_failure() { - mockWiseFyPrechecksUtil.getSavedNetwork_success() - mockWiseFySearchUtil.findSavedNetworkByRegex_null() - assertEquals(null, wisefy.getSavedNetwork(TEST_SSID)) - } - - @Test fun sync_success() { - mockWiseFyPrechecksUtil.getSavedNetwork_success() - val savedNetwork = mockWiseFySearchUtil.findSavedNetworkByRegex_success() - assertEquals(savedNetwork, wisefy.getSavedNetwork(TEST_SSID)) - } - - @Test fun async_failure_prechecks() { - mockWiseFyPrechecksUtil.getSavedNetwork_failure() - val mockCallbacks = mock(GetSavedNetworkCallbacks::class.java) - wisefy.getSavedNetwork(TEST_SSID, mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER) - } - - @Test fun async_failure_prechecks_nullCallback() { - mockWiseFyPrechecksUtil.getSavedNetwork_failure() - nullCallbackUtil.callGetSavedNetwork(TEST_SSID) - } - - @Test fun async_failure() { - mockWiseFyPrechecksUtil.getSavedNetwork_success() - mockWiseFySearchUtil.findSavedNetworkByRegex_null() - val mockCallbacks = mock(GetSavedNetworkCallbacks::class.java) - wisefy.getSavedNetwork(TEST_SSID, mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).savedNetworkNotFound() - } - - @Test fun async_failure_nullCallback() { - mockWiseFyPrechecksUtil.getSavedNetwork_success() - mockWiseFySearchUtil.findSavedNetworkByRegex_null() - nullCallbackUtil.callGetSavedNetwork(TEST_SSID) - } - - @Test fun async_success() { - mockWiseFyPrechecksUtil.getSavedNetwork_success() - val savedNetwork = mockWiseFySearchUtil.findSavedNetworkByRegex_success() - val mockCallbacks = mock(GetSavedNetworkCallbacks::class.java) - wisefy.getSavedNetwork(TEST_SSID, mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).retrievedSavedNetwork(savedNetwork) - } - - @Test fun async_success_nullCallback() { - mockWiseFyPrechecksUtil.getSavedNetwork_success() - mockWiseFySearchUtil.findSavedNetworkByRegex_success() - nullCallbackUtil.callGetSavedNetwork(TEST_SSID) - } -} diff --git a/wisefy/src/test/java/com/isupatches/wisefy/GetSavedNetworksTests.kt b/wisefy/src/test/java/com/isupatches/wisefy/GetSavedNetworksTests.kt deleted file mode 100644 index 3ac6a31c..00000000 --- a/wisefy/src/test/java/com/isupatches/wisefy/GetSavedNetworksTests.kt +++ /dev/null @@ -1,170 +0,0 @@ -package com.isupatches.wisefy - -import android.os.Build - -import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks -import com.isupatches.wisefy.constants.MISSING_PARAMETER -import com.isupatches.wisefy.internal.base.BaseUnitTest - -import org.junit.Assert.assertEquals -import org.junit.Test -import org.junit.runner.RunWith - -import org.mockito.Mockito.mock -import org.mockito.Mockito.timeout -import org.mockito.Mockito.verify - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - -/** - * Tests the ability to retrieve a list of saved networks on a device. - * - * @author Patches - */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [Build.VERSION_CODES.M]) -internal class GetSavedNetworksTests : BaseUnitTest() { - - @Test fun sync_failure_prechecks() { - mockWiseFyPrechecksUtil.getSavedNetworks_failure() - assertEquals(null, wisefy.getSavedNetworks()) - verificationUtil.didNotTryToGetSavedNetworks() - } - - @Test fun sync_success() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - val savedNetworks = mockNetworkUtil.savedNetworks() - assertEquals(savedNetworks, wisefy.getSavedNetworks()) - verificationUtil.triedToGetSavedNetworks() - } - - @Test fun async_failure_prechecks() { - mockWiseFyPrechecksUtil.getSavedNetworks_failure() - val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) - wisefy.getSavedNetworks(mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER) - verificationUtil.didNotTryToGetSavedNetworks() - } - - @Test fun async_failure_prechecks_nullCallback() { - mockWiseFyPrechecksUtil.getSavedNetworks_failure() - nullCallbackUtil.callGetSavedNetworks() - verificationUtil.didNotTryToGetSavedNetworks() - } - - @Test fun async_failure_nullSavedNetworks() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - mockNetworkUtil.getConfiguredNetworks_null() - val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) - wisefy.getSavedNetworks(mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).noSavedNetworksFound() - verificationUtil.triedToGetSavedNetworks() - } - - @Test fun async_failure_nullSavedNetworks_nullCallback() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - mockNetworkUtil.getConfiguredNetworks_null() - nullCallbackUtil.callGetSavedNetworks() - verificationUtil.triedToGetSavedNetworks() - } - - @Test fun async_failure_emptyConfiguredNetworks() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - mockNetworkUtil.getConfiguredNetworks_emptyList() - val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) - wisefy.getSavedNetworks(mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).noSavedNetworksFound() - verificationUtil.triedToGetSavedNetworks() - } - - @Test fun async_failure_emptyConfiguredNetworks_nullCallback() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - mockNetworkUtil.getConfiguredNetworks_emptyList() - nullCallbackUtil.callGetSavedNetworks() - verificationUtil.triedToGetSavedNetworks() - } - - @Test fun async_success() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - val savedNetworks = mockNetworkUtil.savedNetworks() - val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) - wisefy.getSavedNetworks(mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).retrievedSavedNetworks(savedNetworks) - verificationUtil.triedToGetSavedNetworks() - } - - @Test fun async_success_nullCallback() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - mockNetworkUtil.savedNetworks() - nullCallbackUtil.callGetSavedNetworks() - verificationUtil.triedToGetSavedNetworks() - } - - @Test fun sync_failure_prechecks_withRegex() { - mockWiseFyPrechecksUtil.getSavedNetworks_failure() - assertEquals(null, wisefy.getSavedNetworks(TEST_SSID)) - verificationUtil.didNotTryToGetSavedNetworks() - } - - @Test fun sync_success_withRegex() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - val savedNetwork = mockWiseFySearchUtil.findSavedNetworksMatchingRegex_success() - assertEquals(savedNetwork, wisefy.getSavedNetworks(TEST_SSID)) - } - - @Test fun async_failure_prechecks_withRegex() { - mockWiseFyPrechecksUtil.getSavedNetworks_failure() - val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) - wisefy.getSavedNetworks(TEST_SSID, mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER) - } - - @Test fun async_failure_prechecks_withRegex_nullCallback() { - mockWiseFyPrechecksUtil.getSavedNetworks_failure() - nullCallbackUtil.callGetSavedNetworks_withRegex(TEST_SSID) - wisefy.getSavedNetworks(TEST_SSID, null) - } - - @Test fun async_failure_withRegex_nullSavedNetworks() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - mockWiseFySearchUtil.findSavedNetworksByRegex_null() - val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) - wisefy.getSavedNetworks(TEST_SSID, mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).noSavedNetworksFound() - } - - @Test fun async_failure_withRegex_nullSavedNetworks_nullCallback() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - mockWiseFySearchUtil.findSavedNetworksByRegex_null() - nullCallbackUtil.callGetSavedNetworks_withRegex(TEST_SSID) - } - - @Test fun async_failure_withRegex_emptyConfiguredNetworks() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - mockWiseFySearchUtil.findSavedNetworksByRegex_emptyList() - val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) - wisefy.getSavedNetworks(TEST_SSID, mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).noSavedNetworksFound() - } - - @Test fun async_failure_withRegex_emptyConfiguredNetworks_nullCallback() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - mockWiseFySearchUtil.findSavedNetworksByRegex_emptyList() - nullCallbackUtil.callGetSavedNetworks_withRegex(TEST_SSID) - } - - @Test fun async_success_withRegex() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - val savedNetworks = mockWiseFySearchUtil.findSavedNetworksMatchingRegex_success() - val mockCallbacks = mock(GetSavedNetworksCallbacks::class.java) - wisefy.getSavedNetworks(TEST_SSID, mockCallbacks) - verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).retrievedSavedNetworks(savedNetworks) - } - - @Test fun async_success_withRegex_nullCallbacks() { - mockWiseFyPrechecksUtil.getSavedNetworks_success() - mockWiseFySearchUtil.findSavedNetworksMatchingRegex_success() - nullCallbackUtil.callGetSavedNetworks_withRegex(TEST_SSID) - } -} diff --git a/wisefy/src/test/java/com/isupatches/wisefy/internal/NetworkCapabilitiesUtil.kt b/wisefy/src/test/java/com/isupatches/wisefy/internal/NetworkCapabilitiesUtil.kt deleted file mode 100644 index ac3b7c40..00000000 --- a/wisefy/src/test/java/com/isupatches/wisefy/internal/NetworkCapabilitiesUtil.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.isupatches.wisefy.internal - -import android.net.NetworkCapabilities - -internal fun getNetworkCapabilities(transportType: Int): NetworkCapabilities { - val networkCapabilities = NetworkCapabilities(null) - ReflectionHelpers.callInstanceMethod( - networkCapabilities, - "addTransportType", - ReflectionHelpers.ClassParameter.from(Int::class.java, transportType) - ) - return networkCapabilities -} - -internal fun getNetworkCapabilities(capabilities: Array): NetworkCapabilities { - val networkCapabilities = NetworkCapabilities(null) - for (capability in capabilities) { - ReflectionHelpers.callInstanceMethod( - networkCapabilities, - "addCapability", - ReflectionHelpers.ClassParameter.from(Int::class.java, capability) - ) - } - return networkCapabilities -} - -internal fun getNetworkCapabilities(transportType: Int, capabilities: Array): NetworkCapabilities { - val networkCapabilities = NetworkCapabilities(null) - ReflectionHelpers.callInstanceMethod( - networkCapabilities, - "addTransportType", - ReflectionHelpers.ClassParameter.from(Int::class.java, transportType) - ) - for (capability in capabilities) { - ReflectionHelpers.callInstanceMethod( - networkCapabilities, - "addCapability", - ReflectionHelpers.ClassParameter.from(Int::class.java, capability) - ) - } - return networkCapabilities -} diff --git a/wisefy/src/test/java/com/isupatches/wisefy/main/PublicApiVisibilityTests.kt b/wisefy/src/test/java/com/isupatches/wisefy/main/PublicApiVisibilityTests.kt index 43407de6..6becea91 100644 --- a/wisefy/src/test/java/com/isupatches/wisefy/main/PublicApiVisibilityTests.kt +++ b/wisefy/src/test/java/com/isupatches/wisefy/main/PublicApiVisibilityTests.kt @@ -29,13 +29,14 @@ import com.isupatches.wisefy.callbacks.GetFrequencyCallbacks import com.isupatches.wisefy.callbacks.GetIPCallbacks import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks import com.isupatches.wisefy.callbacks.GetRSSICallbacks -import com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworkCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworksCallbacks import org.junit.Assert.assertEquals import org.junit.Test @@ -52,13 +53,11 @@ import org.mockito.Mockito.verify * * @author Patches */ -@Suppress("LargeClass", "UndocumentedPublicFunction") -class PublicApiVisibilityTests { +@Suppress("LargeClass") +internal class PublicApiVisibilityTests { private val wisefy = mock(WiseFyPublicApi::class.java) - private val savedNetworksCallbacks = MyGetSavedNetworksCallbacks() - @Test fun addOpenNetwork_apis() { wisefy.addOpenNetwork(OPEN_NETWORK_SSID) verify(wisefy).addOpenNetwork(anyString()) @@ -294,32 +293,20 @@ class PublicApiVisibilityTests { verify(wisefy).getRSSI(anyString(), anyBoolean(), anyInt(), any(GetRSSICallbacks::class.java)) } - @Test fun getSavedNetwork_apis() { - wisefy.getSavedNetwork(TEST_SSID) - verify(wisefy).getSavedNetwork(anyString()) - wisefy.getSavedNetwork(TEST_SSID, object : GetSavedNetworkCallbacks { - override fun wisefyFailure(wisefyFailureCode: Int) { + @Test fun getSavedNetworks_apis() { + wisefy.getSavedNetworks() + verify(wisefy).getSavedNetworks() + wisefy.getSavedNetworks(object : GetSavedNetworksCallbacks { + override fun noSavedNetworksFound() { } - override fun savedNetworkNotFound() { + override fun retrievedSavedNetworks(savedNetworks: List) { } - override fun retrievedSavedNetwork(savedNetwork: WifiConfiguration) { + override fun wisefyFailure(wisefyFailureCode: Int) { } }) - verify(wisefy).getSavedNetwork(anyString(), any(GetSavedNetworkCallbacks::class.java)) - } - - @Test fun getSavedNetworks_apis() { - wisefy.getSavedNetworks() - verify(wisefy).getSavedNetworks() - wisefy.getSavedNetworks(savedNetworksCallbacks) verify(wisefy).getSavedNetworks(any(GetSavedNetworksCallbacks::class.java)) - - wisefy.getSavedNetworks(TEST_SSID) - verify(wisefy).getSavedNetworks(anyString()) - wisefy.getSavedNetworks(TEST_SSID, savedNetworksCallbacks) - verify(wisefy).getSavedNetworks(anyString(), any(GetSavedNetworksCallbacks::class.java)) } @Test fun getWiseFyLock_api() { @@ -460,6 +447,38 @@ class PublicApiVisibilityTests { verify(wisefy).searchForAccessPoints(anyString(), anyBoolean(), any(SearchForAccessPointsCallbacks::class.java)) } + @Test fun searchForSavedNetwork_apis() { + wisefy.searchForSavedNetwork(TEST_SSID) + verify(wisefy).searchForSavedNetwork(anyString()) + wisefy.searchForSavedNetwork(TEST_SSID, object : SearchForSavedNetworkCallbacks { + override fun wisefyFailure(wisefyFailureCode: Int) { + } + + override fun savedNetworkNotFound() { + } + + override fun retrievedSavedNetwork(savedNetwork: WifiConfiguration) { + } + }) + verify(wisefy).searchForSavedNetwork(anyString(), any(SearchForSavedNetworkCallbacks::class.java)) + } + + @Test fun searchForSavedNetworks_apis() { + wisefy.searchForSavedNetworks(TEST_SSID) + verify(wisefy).searchForSavedNetworks(anyString()) + wisefy.searchForSavedNetworks(TEST_SSID, object : SearchForSavedNetworksCallbacks { + override fun noSavedNetworksFound() { + } + + override fun retrievedSavedNetworks(savedNetworks: List) { + } + + override fun wisefyFailure(wisefyFailureCode: Int) { + } + }) + verify(wisefy).searchForSavedNetworks(anyString(), any(SearchForSavedNetworksCallbacks::class.java)) + } + @Test fun searchForSSID_api() { wisefy.searchForSSID(TEST_SSID, TEST_DELAY) verify(wisefy).searchForSSID(anyString(), anyInt()) @@ -497,15 +516,4 @@ class PublicApiVisibilityTests { @Test fun wifiManagerFailure_value() { assertEquals(WIFI_MANAGER_FAILURE.toLong(), -1) } - - private class MyGetSavedNetworksCallbacks : GetSavedNetworksCallbacks { - override fun noSavedNetworksFound() { - } - - override fun retrievedSavedNetworks(savedNetworks: List) { - } - - override fun wisefyFailure(wisefyFailureCode: Int) { - } - } } diff --git a/wisefysample/build.gradle b/wisefysample/build.gradle index f63b8e60..699bb023 100644 --- a/wisefysample/build.gradle +++ b/wisefysample/build.gradle @@ -14,15 +14,36 @@ android { targetSdkVersion rootProject.ext.MAX_SDK_VERSION versionCode rootProject.ext.VERSION_CODE versionName rootProject.ext.VERSION_NAME - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { + debug { + testCoverageEnabled true + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + testProguardFile file("proguard-test-rules.pro.pro") + } + release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + + testOptions { + unitTests.returnDefaultValues = true + } + + sourceSets { + def commonTestDir = 'src/commonTest/java' + + test { java.srcDir commonTestDir } + + androidTest { java.srcDir commonTestDir } + + main { jni.srcDirs = [] } + } } dependencies { @@ -51,6 +72,9 @@ dependencies { implementation "io.reactivex.rxjava2:rxjava:$rxjava_version" // Unit test dependencies + testImplementation "androidx.test:core:$androidx_core_test_version" + testImplementation "org.mockito:mockito-core:$mockito_version" + testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockito_kotlin_version" testImplementation "junit:junit:$junit_version" // Instrumentation test dependencies @@ -58,4 +82,9 @@ dependencies { androidTestImplementation "androidx.test.espresso:espresso-intents:$androidx_espresso_core_version" androidTestImplementation "androidx.test:runner:$androidx_test_runner_version" androidTestImplementation "androidx.test:rules:$androidx_test_runner_version" + androidTestImplementation "org.mockito:mockito-core:$mockito_version" + androidTestImplementation "org.mockito:mockito-android:$mockito_version" + androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockito_kotlin_version" + kaptAndroidTest "com.google.dagger:dagger-compiler:$dagger_version" + kaptAndroidTest "com.google.dagger:dagger-android-processor:$dagger_version" } diff --git a/wisefysample/proguard-rules.pro b/wisefysample/proguard-rules.pro index e69de29b..d3aaaa43 100644 --- a/wisefysample/proguard-rules.pro +++ b/wisefysample/proguard-rules.pro @@ -0,0 +1,21 @@ +-verbose + +-dontobfuscate + +-keep class com.isupatches.wisefysample.** { *; } +-keep public interface com.isupatches.wisefysample.** { *; } + +-keep class kotlin.** { *; } +-keep class kotlin.Metadata { *; } +-dontwarn kotlin.** +-keepclassmembers class **$WhenMappings { + ; +} +-keepclassmembers class kotlin.Metadata { + public ; +} +-assumenosideeffects class kotlin.jvm.internal.Intrinsics { + static void checkParameterIsNotNull(java.lang.Object, java.lang.String); +} + +-keep class io.reactivex.schedulers.Schedulers { *; } diff --git a/wisefysample/proguard-test-rules.pro b/wisefysample/proguard-test-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/base/AbstractEspressoTestClass.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/base/AbstractEspressoTestClass.kt new file mode 100644 index 00000000..cc0bce4b --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/base/AbstractEspressoTestClass.kt @@ -0,0 +1,77 @@ +package com.isupatches.wisefysample.internal.base + +import androidx.test.platform.app.InstrumentationRegistry +import com.isupatches.wisefy.WiseFyPublicApi +import com.isupatches.wisefysample.DebugMainApplication +import com.isupatches.wisefysample.TestRxSchedulersProvider +import com.isupatches.wisefysample.internal.di.DaggerTestMainApplicationComponent +import com.isupatches.wisefysample.internal.di.addCommonComponents +import com.isupatches.wisefysample.internal.preferences.InMemoryAddNetworkStore +import com.isupatches.wisefysample.internal.preferences.InMemoryRemoveNetworkStore +import com.isupatches.wisefysample.internal.preferences.InMemorySearchStore +import com.isupatches.wisefysample.internal.util.PermissionUtil +import com.isupatches.wisefysample.internal.util.SdkUtil +import com.isupatches.wisefysample.ui.add.AddNetworkModel +import com.isupatches.wisefysample.ui.add.AddNetworkMvp +import com.isupatches.wisefysample.ui.add.AddNetworkPresenter +import com.isupatches.wisefysample.ui.misc.MiscModel +import com.isupatches.wisefysample.ui.misc.MiscMvp +import com.isupatches.wisefysample.ui.misc.MiscPresenter +import com.isupatches.wisefysample.ui.remove.RemoveNetworkModel +import com.isupatches.wisefysample.ui.remove.RemoveNetworkMvp +import com.isupatches.wisefysample.ui.remove.RemoveNetworkPresenter +import com.isupatches.wisefysample.ui.search.SearchModel +import com.isupatches.wisefysample.ui.search.SearchMvp +import com.isupatches.wisefysample.ui.search.SearchPresenter + +import com.nhaarman.mockitokotlin2.mock + +internal abstract class AbstractEspressoTestClass { + + protected val wiseFy: WiseFyPublicApi = mock() + protected val permissionUtil: PermissionUtil = mock() + protected val sdkUtil: SdkUtil = mock() + + private val addNetworkPresenter: AddNetworkMvp.Presenter = AddNetworkPresenter( + model = AddNetworkModel(wiseFy = wiseFy), + rxSchedulersProvider = TestRxSchedulersProvider() + ) + protected val addNetworkStore = InMemoryAddNetworkStore() + + private val removeNetworkPresenter: RemoveNetworkMvp.Presenter = RemoveNetworkPresenter( + model = RemoveNetworkModel(wiseFy = wiseFy), + rxSchedulersProvider = TestRxSchedulersProvider() + ) + protected val removeNetworkStore = InMemoryRemoveNetworkStore() + + private val miscPresenter: MiscMvp.Presenter = MiscPresenter( + model = MiscModel(wiseFy = wiseFy), + rxSchedulersProvider = TestRxSchedulersProvider() + ) + private val searchPresenter: SearchMvp.Presenter = SearchPresenter( + model = SearchModel(wiseFy = wiseFy), + rxSchedulersProvider = TestRxSchedulersProvider() + ) + protected val searchStore = InMemorySearchStore() + + open fun setUp() { + @SuppressWarnings("UnsafeCast") + val app = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as DebugMainApplication + val mainComponent = DaggerTestMainApplicationComponent.builder() + .addCommonComponents( + app = app, + wiseFy = wiseFy, + permissionUtil = permissionUtil, + addNetworkPresenter = addNetworkPresenter, + addNetworkStore = addNetworkStore, + removeNetworkPresenter = removeNetworkPresenter, + removeNetworkStore = removeNetworkStore, + miscPresenter = miscPresenter, + searchPresenter = searchPresenter, + searchStore = searchStore, + sdkUtil = sdkUtil + ) + .build() + app.setTestComponent(mainComponent) + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/base/BaseRobot.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/base/BaseRobot.kt new file mode 100644 index 00000000..68622a77 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/base/BaseRobot.kt @@ -0,0 +1,94 @@ +package com.isupatches.wisefysample.internal.base + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.rule.ActivityTestRule + +import com.isupatches.wisefy.constants.MISSING_PARAMETER +import com.isupatches.wisefysample.R +import com.isupatches.wisefysample.RANDO_PERMISSION_REQUEST_CODE +import com.isupatches.wisefysample.TEST_SSID_1 +import com.isupatches.wisefysample.internal.espresso.checkIsDisplayed +import com.isupatches.wisefysample.internal.espresso.getString +import com.isupatches.wisefysample.internal.espresso.performClick +import com.isupatches.wisefysample.internal.espresso.performScrollToAndCheckIsDisplayed +import com.isupatches.wisefysample.internal.util.PermissionUtil + +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.eq + +import org.hamcrest.CoreMatchers.allOf +import org.hamcrest.CoreMatchers.containsString + +import org.mockito.Mockito.`when` + +internal abstract class BaseRobot( + private val activityTestRule: ActivityTestRule<*>, + private val permissionUtil: PermissionUtil +) { + + fun dismissResultsDialog() { + onView(withText(R.string.ok)).performClick() + } + + fun dismissErrorDialog() { + onView(withText(R.string.ok)).performClick() + } + + fun withPermission(permission: String) { + `when`(permissionUtil.isPermissionGranted(any(), eq(permission))) + .thenReturn(true) + } + + fun withPermissions(vararg permissions: String) { + for (permission in permissions) { + `when`(permissionUtil.isPermissionGranted(any(), eq(permission))) + .thenReturn(true) + } + } + + fun withPermissionDeniedOnce(permission: String) { + `when`(permissionUtil.isPermissionGranted(any(), eq(permission))) + .thenReturn(false) + .thenReturn(true) + } + + fun verifyNetworkNameIsPopulated() { + onView(allOf(withId(R.id.networkNameEdt), withText(TEST_SSID_1))).performScrollToAndCheckIsDisplayed() + } + + fun verifyPermissionErrorShown() { + onView(withText( + activityTestRule.getString( + R.string.permission_error_unhandled_request_code_args, + RANDO_PERMISSION_REQUEST_CODE + ) + )) + .checkIsDisplayed() + } + + fun verifyWiseFyFailureIsDisplayed() { + onView(withText(R.string.wisefy_error)).checkIsDisplayed() + onView(withText( + activityTestRule.getString( + R.string.wisefy_error_descriptions_args, MISSING_PARAMETER) + )).checkIsDisplayed() + } + + fun verifyAccessPointsAreDisplayed() { + onView(withText(containsString("Access points"))).checkIsDisplayed() + } + + fun verifyNoAccessPointsFoundIsDisplayed() { + onView(withText(R.string.no_access_points_found)).checkIsDisplayed() + } + + fun verifySavedNetworksAreDisplayed() { + onView(withText(containsString("Saved networks"))).checkIsDisplayed() + } + + fun verifyNoSavedNetworksFoundIsDisplayed() { + onView(withText(R.string.no_saved_networks_found)).checkIsDisplayed() + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestCommonModule.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestCommonModule.kt new file mode 100644 index 00000000..6f4358ed --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestCommonModule.kt @@ -0,0 +1,9 @@ +package com.isupatches.wisefysample.internal.di + +import dagger.Module +import dagger.android.support.AndroidSupportInjectionModule + +@Module(includes = [ + AndroidSupportInjectionModule::class, + TestRxModule::class +]) interface TestCommonModule diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestMainApplicationComponent.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestMainApplicationComponent.kt new file mode 100644 index 00000000..8638d7cb --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestMainApplicationComponent.kt @@ -0,0 +1,20 @@ +package com.isupatches.wisefysample.internal.di + +import com.isupatches.wisefysample.MainApplication + +import dagger.Component + +import javax.inject.Singleton + +@Suppress("unused") +@Singleton +@Component(modules = [ + TestCommonModule::class, + TestScreenBindingsModule::class +]) +internal interface TestMainApplicationComponent : MainApplication.MainApplicationComponent { + + @Component.Builder interface Builder : TestMainApplicationComponentBuilder { + fun build(): TestMainApplicationComponent + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestMainApplicationComponentBuilder.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestMainApplicationComponentBuilder.kt new file mode 100644 index 00000000..827907d5 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestMainApplicationComponentBuilder.kt @@ -0,0 +1,65 @@ +package com.isupatches.wisefysample.internal.di + +import android.content.Context + +import com.isupatches.wisefy.WiseFyPublicApi +import com.isupatches.wisefysample.DebugMainApplication +import com.isupatches.wisefysample.MainApplication +import com.isupatches.wisefysample.TestRxSchedulersProvider +import com.isupatches.wisefysample.internal.preferences.AddNetworkStore +import com.isupatches.wisefysample.internal.preferences.RemoveNetworkStore +import com.isupatches.wisefysample.internal.preferences.SearchStore +import com.isupatches.wisefysample.internal.util.PermissionUtil +import com.isupatches.wisefysample.internal.util.RxSchedulersProvider +import com.isupatches.wisefysample.internal.util.SdkUtil +import com.isupatches.wisefysample.ui.add.AddNetworkMvp +import com.isupatches.wisefysample.ui.misc.MiscMvp +import com.isupatches.wisefysample.ui.remove.RemoveNetworkMvp +import com.isupatches.wisefysample.ui.search.SearchMvp + +import dagger.BindsInstance + +internal interface TestMainApplicationComponentBuilder> { + @BindsInstance fun application(app: MainApplication): THIS + @BindsInstance fun context(context: Context): THIS + @BindsInstance fun wiseFy(wiseFy: WiseFyPublicApi): THIS + @BindsInstance fun permissionUtil(permissionUtil: PermissionUtil): THIS + @BindsInstance fun addNetworkPresenter(impl: AddNetworkMvp.Presenter): THIS + @BindsInstance fun addNetworkStore(impl: AddNetworkStore): THIS + @BindsInstance fun removeNetworkPresenter(impl: RemoveNetworkMvp.Presenter): THIS + @BindsInstance fun removeNetworkStore(impl: RemoveNetworkStore): THIS + @BindsInstance fun miscPresenter(impl: MiscMvp.Presenter): THIS + @BindsInstance fun searchPresenter(impl: SearchMvp.Presenter): THIS + @BindsInstance fun searchStore(impl: SearchStore): THIS + @BindsInstance fun sdkUtil(impl: SdkUtil): THIS + @BindsInstance fun rxSchedulersProv(prov: RxSchedulersProvider): THIS +} + +internal fun > T.addCommonComponents( + app: DebugMainApplication, + wiseFy: WiseFyPublicApi, + permissionUtil: PermissionUtil, + addNetworkPresenter: AddNetworkMvp.Presenter, + addNetworkStore: AddNetworkStore, + removeNetworkPresenter: RemoveNetworkMvp.Presenter, + removeNetworkStore: RemoveNetworkStore, + miscPresenter: MiscMvp.Presenter, + searchPresenter: SearchMvp.Presenter, + searchStore: SearchStore, + sdkUtil: SdkUtil, + rxSchedulersProvider: RxSchedulersProvider = TestRxSchedulersProvider() +): T = apply { + application(app) + context(app) + wiseFy(wiseFy) + permissionUtil(permissionUtil) + addNetworkPresenter(addNetworkPresenter) + addNetworkStore(addNetworkStore) + removeNetworkPresenter(removeNetworkPresenter) + removeNetworkStore(removeNetworkStore) + miscPresenter(miscPresenter) + searchPresenter(searchPresenter) + searchStore(searchStore) + sdkUtil(sdkUtil) + rxSchedulersProv(rxSchedulersProvider) +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestRxModule.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestRxModule.kt new file mode 100644 index 00000000..d037aaef --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestRxModule.kt @@ -0,0 +1,10 @@ +package com.isupatches.wisefysample.internal.di + +import com.isupatches.wisefysample.TestRxSchedulersProvider +import dagger.Module +import dagger.Provides + +@Suppress("unused") +@Module object TestRxModule { + @Provides @JvmStatic fun rxSchedulersProvider() = TestRxSchedulersProvider() +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestScreenBindingsModule.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestScreenBindingsModule.kt new file mode 100644 index 00000000..3dd17c64 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/di/TestScreenBindingsModule.kt @@ -0,0 +1,21 @@ +package com.isupatches.wisefysample.internal.di + +import com.isupatches.wisefysample.ui.add.AddNetworkFragment +import com.isupatches.wisefysample.ui.main.MainActivity +import com.isupatches.wisefysample.ui.main.MainFragment +import com.isupatches.wisefysample.ui.misc.MiscFragment +import com.isupatches.wisefysample.ui.remove.RemoveNetworkFragment +import com.isupatches.wisefysample.ui.search.SearchFragment + +import dagger.Module +import dagger.android.ContributesAndroidInjector + +@Suppress("unused") +@Module internal interface TestScreenBindingsModule { + @ContributesAndroidInjector fun mainActivity(): MainActivity + @ContributesAndroidInjector fun addNetworkFragment(): AddNetworkFragment + @ContributesAndroidInjector fun removeNetworkFragment(): RemoveNetworkFragment + @ContributesAndroidInjector fun mainFragment(): MainFragment + @ContributesAndroidInjector fun miscFragment(): MiscFragment + @ContributesAndroidInjector fun searchFragment(): SearchFragment +} \ No newline at end of file diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/espresso/ActivityTestRule.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/espresso/ActivityTestRule.kt new file mode 100644 index 00000000..b5e3b3c4 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/espresso/ActivityTestRule.kt @@ -0,0 +1,10 @@ +package com.isupatches.wisefysample.internal.espresso + +import androidx.annotation.StringRes +import androidx.test.rule.ActivityTestRule + +fun ActivityTestRule<*>.getString(@StringRes stringRes: Int): String = + activity.getString(stringRes) + +fun ActivityTestRule<*>.getString(@StringRes stringRes: Int, varargs: Any): String = + activity.getString(stringRes, varargs) \ No newline at end of file diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/espresso/SetProgress.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/espresso/SetProgress.kt new file mode 100644 index 00000000..61802c55 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/espresso/SetProgress.kt @@ -0,0 +1,27 @@ +package com.isupatches.wisefysample.internal.espresso + +import android.view.View +import android.widget.SeekBar +import androidx.test.espresso.UiController +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.ViewAction + +import org.hamcrest.Matcher + +fun setProgress(progress: Int): ViewAction { + return object : ViewAction { + + override fun perform(uiController: UiController, view: View) { + val seekBar = view as SeekBar + seekBar.progress = progress + } + + override fun getDescription(): String { + return "Set progress value on a SeekBar" + } + + override fun getConstraints(): Matcher { + return ViewMatchers.isAssignableFrom(SeekBar::class.java) + } + } +} \ No newline at end of file diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/espresso/ViewInteractions.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/espresso/ViewInteractions.kt new file mode 100644 index 00000000..742fe15a --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/espresso/ViewInteractions.kt @@ -0,0 +1,45 @@ +package com.isupatches.wisefysample.internal.espresso + +import androidx.test.espresso.ViewInteraction +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.replaceText +import androidx.test.espresso.action.ViewActions.scrollTo +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.isChecked +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.isNotChecked +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility + +fun ViewInteraction.checkIsDisplayed(): ViewInteraction = + check(matches(isDisplayed())) + +fun ViewInteraction.performScrollToAndCheckIsDisplayed(): ViewInteraction = + perform(scrollTo()) + .check(matches(isDisplayed())) + +fun ViewInteraction.checkIsVisible(): ViewInteraction = + check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + +fun ViewInteraction.checkIsInvisible(): ViewInteraction = + check(matches(withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE))) + +fun ViewInteraction.checkIsChecked(): ViewInteraction = + check(matches(isChecked())) + +fun ViewInteraction.checkIsNotChecked(): ViewInteraction = + check(matches(isNotChecked())) + +fun ViewInteraction.performClick(): ViewInteraction = + checkIsDisplayed() + .perform(click()) + +fun ViewInteraction.performScrollToAndClick(): ViewInteraction = + perform(scrollTo()) + .checkIsDisplayed() + .perform(click()) + +fun ViewInteraction.performScrollToAndReplaceText(text: String): ViewInteraction = + perform(scrollTo()) + .checkIsDisplayed() + .perform(replaceText(text)) diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/preferences/InMemoryAddNetworkStore.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/preferences/InMemoryAddNetworkStore.kt new file mode 100644 index 00000000..4a9c0d7c --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/preferences/InMemoryAddNetworkStore.kt @@ -0,0 +1,43 @@ +package com.isupatches.wisefysample.internal.preferences + +import com.isupatches.wisefysample.internal.models.NetworkType + +internal class InMemoryAddNetworkStore : AddNetworkStore { + + private var networkType: NetworkType? = null + private var lastUsedNetworkName: String = "" + private var lastUsedNetworkPassword: String = "" + + override fun clear() { + networkType = null + lastUsedNetworkName = "" + lastUsedNetworkPassword = "" + } + + /* + * Network Type + */ + + override fun getNetworkType(): NetworkType = networkType ?: NetworkType.WPA2 + override fun setNetworkType(networkType: NetworkType) { + this.networkType = networkType + } + + /* + * Last Used Network Name + */ + + override fun getLastUsedNetworkName() = lastUsedNetworkName + override fun setLastUsedNetworkName(lastUsedNetworkName: String) { + this.lastUsedNetworkName = lastUsedNetworkName + } + + /* + * Last Used Network Password + */ + + override fun getLastUsedNetworkPassword() = lastUsedNetworkPassword + override fun setLastUsedNetworkPassword(lastUsedNetworkPassword: String) { + this.lastUsedNetworkPassword = lastUsedNetworkPassword + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/preferences/InMemoryRemoveNetworkStore.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/preferences/InMemoryRemoveNetworkStore.kt new file mode 100644 index 00000000..6398e62e --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/preferences/InMemoryRemoveNetworkStore.kt @@ -0,0 +1,15 @@ +package com.isupatches.wisefysample.internal.preferences + +internal class InMemoryRemoveNetworkStore : RemoveNetworkStore { + + private var lastUsedRegex: String = "" + + override fun clear() { + lastUsedRegex = "" + } + + override fun getLastUsedRegex() = lastUsedRegex + override fun setLastUsedRegex(lastUsedRegex: String) { + this.lastUsedRegex = lastUsedRegex + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/preferences/InMemorySearchStore.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/preferences/InMemorySearchStore.kt new file mode 100644 index 00000000..283624de --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/internal/preferences/InMemorySearchStore.kt @@ -0,0 +1,65 @@ +package com.isupatches.wisefysample.internal.preferences + +import com.isupatches.wisefysample.internal.models.SearchType + +internal class InMemorySearchStore : SearchStore { + + private var lastUsedRegex: String = "" + private var searchType: SearchType = SearchType.ACCESS_POINT + private var returnFullList: Boolean = true + private var filterDuplicates: Boolean = true + private var timeout: Int = 1 + + override fun clear() { + lastUsedRegex = "" + searchType = SearchType.ACCESS_POINT + returnFullList = true + filterDuplicates = true + timeout = 1 + } + + /* + * Last Used Regex + */ + + override fun getLastUsedRegex() = lastUsedRegex + override fun setLastUsedRegex(lastUsedRegex: String) { + this.lastUsedRegex = lastUsedRegex + } + + /* + * Search Type + */ + + override fun getSearchType() = searchType + override fun setSearchType(searchType: SearchType) { + this.searchType = searchType + } + + /* + * Return Full List + */ + + override fun shouldReturnFullList() = returnFullList + override fun setReturnFullList(returnFullList: Boolean) { + this.returnFullList = returnFullList + } + + /* + * Filter Duplicates + */ + + override fun shouldFilterDuplicates() = filterDuplicates + override fun setFilterDuplicates(filterDuplicates: Boolean) { + this.filterDuplicates = filterDuplicates + } + + /* + * Timeout + */ + + override fun getTimeout() = timeout + override fun setTimeout(timeout: Int) { + this.timeout = timeout + } +} \ No newline at end of file diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/add/AddNetworkFragmentTest.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/add/AddNetworkFragmentTest.kt new file mode 100644 index 00000000..cf24c2d7 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/add/AddNetworkFragmentTest.kt @@ -0,0 +1,556 @@ +package com.isupatches.wisefysample.ui.add + +import android.Manifest.permission.ACCESS_WIFI_STATE +import android.content.pm.PackageManager +import androidx.test.espresso.intent.rule.IntentsTestRule + +import com.isupatches.wisefysample.RANDO_PERMISSION_REQUEST_CODE +import com.isupatches.wisefysample.internal.base.AbstractEspressoTestClass +import com.isupatches.wisefysample.ui.main.MainActivity + +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +internal class AddNetworkFragmentTest : AbstractEspressoTestClass() { + + @get:Rule + val activityTestRule = IntentsTestRule(MainActivity::class.java, false, false) + + private lateinit var addNetworkRobot: AddNetworkRobot + + @Before override fun setUp() { + super.setUp() + addNetworkRobot = AddNetworkRobot( + activityTestRule, + wiseFy, + addNetworkStore, + permissionUtil + ) + } + + @Test fun networkTypeSelector() { + with(addNetworkRobot) { + // Given + launchAddNetworkScreen() + + // Then + checkOpenNetwork() + verifyOpenNetworkIsChecked() + verifyOnlyNetworkNameIsVisible() + + // And + checkWEPNetwork() + verifyWEPNetworkIsChecked() + verifyNetworkNameAndPasswordAreBothVisible() + + // And + checkWPA2Network() + verifyWPA2NetworkIsChecked() + verifyNetworkNameAndPasswordAreBothVisible() + + // And + checkOpenNetwork() + verifyOpenNetworkIsChecked() + verifyOnlyNetworkNameIsVisible() + } + } + + @Test fun loadsOpenNetworkFromStore() { + with(addNetworkRobot) { + // Given + withOpenNetworkInStore() + + // When + launchAddNetworkScreen() + + // Then + verifyOpenNetworkIsChecked() + verifyNetworkNameIsPopulated() + } + } + + @Test fun loadsWEPNetworkFromStore() { + with(addNetworkRobot) { + // Given + withWEPNetworkInStore() + + // When + launchAddNetworkScreen() + + // Then + verifyWEPNetworkIsChecked() + verifyNetworkNameAndPasswordIsPopulated() + } + } + + @Test fun loadsWPA2NetworkFromStore() { + with(addNetworkRobot) { + // Given + withWPA2NetworkInStore() + + // When + launchAddNetworkScreen() + + // Then + verifyWPA2NetworkIsChecked() + verifyNetworkNameAndPasswordIsPopulated() + } + } + + @Test fun addOpenNetwork_permissionErrorDialog() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + launchAddNetworkScreen() + addOpenNetwork() + + // When + permissionCallbackTriggered( + AddNetworkFragment.WISEFY_ADD_OPEN_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun addOpenNetwork_permissionError_once() { + with(addNetworkRobot) { + // Given + withSuccessAddingOpenNetwork() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + launchAddNetworkScreen() + + // When + addOpenNetwork() + + // Then + verifyTriedToAddOpenNetwork() + verifyNewNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addOpenNetwork_permissionError_emptyList() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingOpenNetwork() + launchAddNetworkScreen() + addOpenNetwork() + + // When + permissionCallbackTriggeredWithEmptyArray( + AddNetworkFragment.WISEFY_ADD_OPEN_NETWORK_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToAddOpenNetwork() + } + } + + @Test fun addOpenNetwork_permissionError_permissionDenied() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingOpenNetwork() + launchAddNetworkScreen() + addOpenNetwork() + + // When + permissionCallbackTriggered( + AddNetworkFragment.WISEFY_ADD_OPEN_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToAddOpenNetwork() + } + } + + @Test fun addOpenNetwork_success_afterPermissionGranted() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingOpenNetwork() + launchAddNetworkScreen() + addOpenNetwork() + + // When + permissionCallbackTriggered( + AddNetworkFragment.WISEFY_ADD_OPEN_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToAddOpenNetwork(times = 2) + verifyNewNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addOpenNetwork_success() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingOpenNetwork() + launchAddNetworkScreen() + + // When + addOpenNetwork() + + // Then + verifyTriedToAddOpenNetwork() + verifyNewNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addOpenNetwork_wifiManagerFailure() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withWifiManagerFailureAddingOpenNetwork() + launchAddNetworkScreen() + + // When + addOpenNetwork() + + // Then + verifyTriedToAddOpenNetwork() + verifyFailureAddingNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addOpenNetwork_wiseFyFailure() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withWiseFyFailureAddingOpenNetwork() + launchAddNetworkScreen() + + // When + addOpenNetwork() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToAddOpenNetwork() + + // And + dismissErrorDialog() + } + } + + @Test fun addWEPNetwork_permissionErrorDialog() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + launchAddNetworkScreen() + addWEPNetwork() + + // When + permissionCallbackTriggered( + AddNetworkFragment.WISEFY_ADD_WEP_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun addWEPNetwork_permissionError_once() { + with(addNetworkRobot) { + // Given + withSuccessAddingWEPNetwork() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + launchAddNetworkScreen() + + // When + addWEPNetwork() + + // Then + verifyTriedToAddWEPNetwork() + verifyNewNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addWEPNetwork_permissionError_emptyList() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingWEPNetwork() + launchAddNetworkScreen() + addWEPNetwork() + + // When + permissionCallbackTriggeredWithEmptyArray( + AddNetworkFragment.WISEFY_ADD_WEP_NETWORK_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToAddWEPNetwork() + } + } + + @Test fun addWEPNetwork_permissionError_permissionDenied() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingWEPNetwork() + launchAddNetworkScreen() + addWEPNetwork() + + // When + permissionCallbackTriggered( + AddNetworkFragment.WISEFY_ADD_WEP_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToAddWEPNetwork() + } + } + + @Test fun addWEPNetwork_success_afterPermissionGranted() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingWEPNetwork() + launchAddNetworkScreen() + addWEPNetwork() + + // When + permissionCallbackTriggered( + AddNetworkFragment.WISEFY_ADD_WEP_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToAddWEPNetwork(times = 2) + verifyNewNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addWEPNetwork_success() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingWEPNetwork() + launchAddNetworkScreen() + + // When + addWEPNetwork() + + // Then + verifyTriedToAddWEPNetwork() + verifyNewNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addWEPNetwork_wifiManagerFailure() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withWifiManagerFailureAddingWEPNetwork() + launchAddNetworkScreen() + + // When + addWEPNetwork() + + // Then + verifyTriedToAddWEPNetwork() + verifyFailureAddingNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addWEPNetwork_wiseFyFailure() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withWiseFyFailureAddingWEPNetwork() + launchAddNetworkScreen() + + // When + addWEPNetwork() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToAddWEPNetwork() + + // And + dismissErrorDialog() + } + } + + @Test fun addWPA2Network_permissionErrorDialog() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + launchAddNetworkScreen() + addWPA2Network() + + // When + permissionCallbackTriggered( + AddNetworkFragment.WISEFY_ADD_WPA2_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + @Test fun addWPA2Network_permissionError_once() { + with(addNetworkRobot) { + // Given + withSuccessAddingWPA2Network() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + launchAddNetworkScreen() + + // When + addWPA2Network() + + // Then + verifyTriedToAddWPA2Network() + verifyNewNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addWPA2Network_permissionError_emptyList() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingWPA2Network() + launchAddNetworkScreen() + addWPA2Network() + + // When + permissionCallbackTriggeredWithEmptyArray( + AddNetworkFragment.WISEFY_ADD_WPA2_NETWORK_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToAddWPA2Network() + } + } + + @Test fun addWPA2Network_permissionError_permissionDenied() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingWEPNetwork() + launchAddNetworkScreen() + addWPA2Network() + + // When + permissionCallbackTriggered( + AddNetworkFragment.WISEFY_ADD_WPA2_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToAddWPA2Network() + } + } + + @Test fun addWPA2Network_success_afterPermissionGranted() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingWPA2Network() + launchAddNetworkScreen() + addWPA2Network() + + // When + permissionCallbackTriggered( + AddNetworkFragment.WISEFY_ADD_WPA2_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToAddWPA2Network(times = 2) + verifyNewNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addWPA2Network_success() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessAddingWPA2Network() + launchAddNetworkScreen() + + // When + addWPA2Network() + + // Then + verifyTriedToAddWPA2Network() + dismissResultsDialog() + } + } + + @Test fun addWPA2Network_wifiManagerFailure() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withWifiManagerFailureAddingWPA2Network() + launchAddNetworkScreen() + + // When + addWPA2Network() + + // Then + verifyTriedToAddWPA2Network() + verifyFailureAddingNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun addWPA2Network_wiseFyFailure() { + with(addNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withWiseFyFailureAddingWPA2Network() + launchAddNetworkScreen() + + // When + addWPA2Network() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToAddWPA2Network() + + // And + dismissErrorDialog() + } + } + + @Test fun ridiculousPermissionRequested() { + with(addNetworkRobot) { + // Given + launchAddNetworkScreen() + + // When + permissionCallbackTriggeredWithEmptyArray(RANDO_PERMISSION_REQUEST_CODE) + + // Then + verifyPermissionErrorShown() + dismissErrorDialog() + } + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/add/AddNetworkRobot.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/add/AddNetworkRobot.kt new file mode 100644 index 00000000..7ab88458 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/add/AddNetworkRobot.kt @@ -0,0 +1,316 @@ +package com.isupatches.wisefysample.ui.add + +import android.content.Intent +import android.net.wifi.WifiConfiguration +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.rule.ActivityTestRule + +import com.isupatches.wisefy.WiseFyPublicApi +import com.isupatches.wisefy.callbacks.AddNetworkCallbacks +import com.isupatches.wisefy.constants.MISSING_PARAMETER +import com.isupatches.wisefysample.BAD_WIFI_MANAGER_RETURN +import com.isupatches.wisefysample.R +import com.isupatches.wisefysample.TEST_PASSWORD_1 +import com.isupatches.wisefysample.TEST_SSID_1 +import com.isupatches.wisefysample.internal.base.BaseRobot +import com.isupatches.wisefysample.internal.espresso.checkIsChecked +import com.isupatches.wisefysample.internal.espresso.checkIsDisplayed +import com.isupatches.wisefysample.internal.espresso.checkIsInvisible +import com.isupatches.wisefysample.internal.espresso.checkIsVisible +import com.isupatches.wisefysample.internal.espresso.getString +import com.isupatches.wisefysample.internal.espresso.performClick +import com.isupatches.wisefysample.internal.espresso.performScrollToAndCheckIsDisplayed +import com.isupatches.wisefysample.internal.espresso.performScrollToAndClick +import com.isupatches.wisefysample.internal.espresso.performScrollToAndReplaceText +import com.isupatches.wisefysample.internal.models.NetworkType +import com.isupatches.wisefysample.internal.preferences.AddNetworkStore +import com.isupatches.wisefysample.internal.util.PermissionUtil +import com.isupatches.wisefysample.ui.main.MainActivity + +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.doAnswer +import com.nhaarman.mockitokotlin2.eq +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.timeout +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.whenever +import org.hamcrest.CoreMatchers.allOf +import org.hamcrest.CoreMatchers.containsString + +internal class AddNetworkRobot( + private val activityTestRule: ActivityTestRule, + private val wiseFyPublicApi: WiseFyPublicApi, + private val addNetworkStore: AddNetworkStore, + permissionUtil: PermissionUtil +) : BaseRobot(activityTestRule, permissionUtil) { + + companion object { + private const val NETWORK_ID = 1 + private val SAVED_NETWORK = mock() + } + + /* + * Preconditions + */ + + fun withSuccessAddingOpenNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as AddNetworkCallbacks + callback.networkAdded(NETWORK_ID, SAVED_NETWORK) + }.whenever(wiseFyPublicApi).addOpenNetwork(eq(TEST_SSID_1), any()) + } + + fun withWifiManagerFailureAddingOpenNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as AddNetworkCallbacks + callback.failureAddingNetwork(BAD_WIFI_MANAGER_RETURN) + }.whenever(wiseFyPublicApi).addOpenNetwork(eq(TEST_SSID_1), any()) + } + + fun withWiseFyFailureAddingOpenNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as AddNetworkCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).addOpenNetwork(eq(TEST_SSID_1), any()) + } + + fun withSuccessAddingWEPNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as AddNetworkCallbacks + callback.networkAdded(NETWORK_ID, SAVED_NETWORK) + }.whenever(wiseFyPublicApi).addWEPNetwork( + eq(TEST_SSID_1), + eq(TEST_PASSWORD_1), + any() + ) + } + + fun withWifiManagerFailureAddingWEPNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as AddNetworkCallbacks + callback.failureAddingNetwork(BAD_WIFI_MANAGER_RETURN) + }.whenever(wiseFyPublicApi).addWEPNetwork( + eq(TEST_SSID_1), + eq(TEST_PASSWORD_1), + any() + ) + } + + fun withWiseFyFailureAddingWEPNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as AddNetworkCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).addWEPNetwork( + eq(TEST_SSID_1), + eq(TEST_PASSWORD_1), + any() + ) + } + + fun withSuccessAddingWPA2Network() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as AddNetworkCallbacks + callback.networkAdded(NETWORK_ID, SAVED_NETWORK) + }.whenever(wiseFyPublicApi).addWPA2Network( + eq(TEST_SSID_1), + eq(TEST_PASSWORD_1), + any() + ) + } + + fun withWifiManagerFailureAddingWPA2Network() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as AddNetworkCallbacks + callback.failureAddingNetwork(BAD_WIFI_MANAGER_RETURN) + }.whenever(wiseFyPublicApi).addWPA2Network( + eq(TEST_SSID_1), + eq(TEST_PASSWORD_1), + any() + ) + } + + fun withWiseFyFailureAddingWPA2Network() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as AddNetworkCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).addWPA2Network( + eq(TEST_SSID_1), + eq(TEST_PASSWORD_1), + any() + ) + } + + fun withOpenNetworkInStore() { + with(addNetworkStore) { + setNetworkType(NetworkType.OPEN) + setLastUsedNetworkName(TEST_SSID_1) + } + } + + fun withWEPNetworkInStore() { + with(addNetworkStore) { + setNetworkType(NetworkType.WEP) + setLastUsedNetworkName(TEST_SSID_1) + setLastUsedNetworkPassword(TEST_PASSWORD_1) + } + } + + fun withWPA2NetworkInStore() { + with(addNetworkStore) { + setNetworkType(NetworkType.WPA2) + setLastUsedNetworkName(TEST_SSID_1) + setLastUsedNetworkPassword(TEST_PASSWORD_1) + } + } + + /* + * Actions + */ + + fun launchAddNetworkScreen() { + activityTestRule.launchActivity(Intent()) + onView(withId(R.id.menu_add)).performClick() + } + + fun addOpenNetwork() { + onView(withId(R.id.openNetworkRdb)).performScrollToAndClick() + onView(withId(R.id.networkNameEdt)).performScrollToAndReplaceText(TEST_SSID_1) + onView((withId(R.id.addNetworkBtn))).performScrollToAndClick() + } + + fun addWEPNetwork() { + onView(withId(R.id.wepNetworkRdb)).performScrollToAndClick() + enterNetworkNameAndPassword() + onView((withId(R.id.addNetworkBtn))).performScrollToAndClick() + } + + fun addWPA2Network() { + onView(withId(R.id.wpa2NetworkRdb)).performScrollToAndClick() + enterNetworkNameAndPassword() + onView((withId(R.id.addNetworkBtn))).performScrollToAndClick() + } + + fun checkOpenNetwork() { + onView(withId(R.id.openNetworkRdb)).performScrollToAndClick() + } + + fun checkWEPNetwork() { + onView(withId(R.id.wepNetworkRdb)).performScrollToAndClick() + } + + fun checkWPA2Network() { + onView(withId(R.id.wpa2NetworkRdb)).performScrollToAndClick() + } + + /* + * Permission Helpers + */ + + fun permissionCallbackTriggered(requestCode: Int, permissionResult: Int) { + val activity = activityTestRule.activity + val fragment: AddNetworkFragment? = activity + .supportFragmentManager + .findFragmentByTag( + AddNetworkFragment.TAG + ) as? AddNetworkFragment + + activity.runOnUiThread { + fragment?.onRequestPermissionsResult( + requestCode, + emptyArray(), + intArrayOf(permissionResult) + ) + } + } + + fun permissionCallbackTriggeredWithEmptyArray(requestCode: Int) { + val activity = activityTestRule.activity + val fragment: AddNetworkFragment? = activity + .supportFragmentManager + .findFragmentByTag( + AddNetworkFragment.TAG + ) as? AddNetworkFragment + + activity.runOnUiThread { + fragment?.onRequestPermissionsResult( + requestCode, + emptyArray(), + intArrayOf() + ) + } + } + + /* + * Verification + */ + + fun verifyNewNetworkIsDisplayed() { + onView(withText(containsString("Network added"))).checkIsDisplayed() + } + + fun verifyFailureAddingNetworkIsDisplayed() { + onView(withText( + activityTestRule.getString(R.string.failure_adding_network, -1) + )).checkIsDisplayed() + } + + fun verifyOpenNetworkIsChecked() { + onView(withId(R.id.openNetworkRdb)).checkIsChecked() + } + + fun verifyWEPNetworkIsChecked() { + onView(withId(R.id.wepNetworkRdb)).checkIsChecked() + } + + fun verifyWPA2NetworkIsChecked() { + onView(withId(R.id.wpa2NetworkRdb)).checkIsChecked() + } + + fun verifyOnlyNetworkNameIsVisible() { + onView(withId(R.id.networkNameEdt)).checkIsVisible() + onView(withId(R.id.networkPasswordEdt)).checkIsInvisible() + } + + fun verifyNetworkNameAndPasswordAreBothVisible() { + onView(withId(R.id.networkNameEdt)).checkIsVisible() + onView(withId(R.id.networkPasswordEdt)).checkIsVisible() + } + + fun verifyNetworkNameAndPasswordIsPopulated() { + onView(allOf(withId(R.id.networkNameEdt), withText(TEST_SSID_1))).performScrollToAndCheckIsDisplayed() + onView( + allOf(withId(R.id.networkPasswordEdt), withText(TEST_PASSWORD_1)) + ).performScrollToAndCheckIsDisplayed() + } + + fun verifyTriedToAddOpenNetwork(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).addOpenNetwork(eq(TEST_SSID_1), any()) + } + + fun verifyTriedToAddWEPNetwork(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).addWEPNetwork( + eq(TEST_SSID_1), + eq(TEST_PASSWORD_1), + any() + ) + } + + fun verifyTriedToAddWPA2Network(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).addWPA2Network( + eq(TEST_SSID_1), + eq(TEST_PASSWORD_1), + any() + ) + } + + /* + * Form Helpers + */ + + private fun enterNetworkNameAndPassword() { + onView(withId(R.id.networkNameEdt)).performScrollToAndReplaceText(TEST_SSID_1) + onView(withId(R.id.networkPasswordEdt)).performScrollToAndReplaceText(TEST_PASSWORD_1) + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/main/MainFragmentTest.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/main/MainFragmentTest.kt new file mode 100644 index 00000000..2908604e --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/main/MainFragmentTest.kt @@ -0,0 +1,103 @@ +package com.isupatches.wisefysample.ui.main + +import android.Manifest.permission.ACCESS_COARSE_LOCATION +import androidx.test.espresso.intent.rule.IntentsTestRule +import androidx.test.rule.GrantPermissionRule + +import com.isupatches.wisefysample.internal.base.AbstractEspressoTestClass + +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +internal class MainFragmentTest : AbstractEspressoTestClass() { + + @get:Rule + val activityTestRule = IntentsTestRule(MainActivity::class.java, false, false) + + @get:Rule + val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(ACCESS_COARSE_LOCATION) + + private lateinit var mainRobot: MainRobot + + @Before override fun setUp() { + super.setUp() + mainRobot = MainRobot(activityTestRule, permissionUtil) + } + + @Test fun verifyOpensAddNetwork() { + with(mainRobot) { + // Given + launchActivity() + + // When + clickAddNetwork() + + // Then + verifyAddNetworkWasOpened() + + // And When + clickHome() + + // Then + verifyHomeWasOpened() + } + } + + @Test fun verifyOpensRemoveNetwork() { + with(mainRobot) { + // Given + launchActivity() + + // When + clickRemoveNetwork() + + // Then + verifyRemoveNetworkWasOpened() + + // And When + clickHome() + + // Then + verifyHomeWasOpened() + } + } + + @Test fun verifyOpensMisc() { + with(mainRobot) { + // Given + launchActivity() + + // When + clickMisc() + + // Then + verifyMiscWasOpened() + + // And When + clickHome() + + // Then + verifyHomeWasOpened() + } + } + + @Test fun verifyOpensSearch() { + with(mainRobot) { + // Given + launchActivity() + + // When + clickSearch() + + // Then + verifySearchWasOpened() + + // And When + clickHome() + + // Then + verifyHomeWasOpened() + } + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/main/MainRobot.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/main/MainRobot.kt new file mode 100644 index 00000000..eb52c044 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/main/MainRobot.kt @@ -0,0 +1,70 @@ +package com.isupatches.wisefysample.ui.main + +import android.content.Intent +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.rule.ActivityTestRule + +import com.isupatches.wisefysample.R +import com.isupatches.wisefysample.internal.base.BaseRobot +import com.isupatches.wisefysample.internal.espresso.performClick +import com.isupatches.wisefysample.internal.espresso.performScrollToAndCheckIsDisplayed +import com.isupatches.wisefysample.internal.util.PermissionUtil + +internal class MainRobot( + private val activityTestRule: ActivityTestRule, + permissionUtil: PermissionUtil +) : BaseRobot(activityTestRule, permissionUtil) { + + /* + * Actions + */ + + fun clickAddNetwork() { + onView(withId(R.id.menu_add)).performClick() + } + + fun clickRemoveNetwork() { + onView(withId(R.id.menu_remove)).performClick() + } + + fun clickHome() { + onView(withId(R.id.menu_home)).performClick() + } + + fun clickMisc() { + onView(withId(R.id.menu_misc)).performClick() + } + + fun clickSearch() { + onView(withId(R.id.menu_search)).performClick() + } + + fun launchActivity() { + activityTestRule.launchActivity(Intent()) + } + + /* + * Verification + */ + + fun verifyAddNetworkWasOpened() { + onView(withId(R.id.addNetworkBtn)).performScrollToAndCheckIsDisplayed() + } + + fun verifyRemoveNetworkWasOpened() { + onView(withId(R.id.removeNetworkBtn)).performScrollToAndCheckIsDisplayed() + } + + fun verifyHomeWasOpened() { + onView(withId(R.id.wisefyImg)).performScrollToAndCheckIsDisplayed() + } + + fun verifyMiscWasOpened() { + onView(withId(R.id.disableWifiBtn)).performScrollToAndCheckIsDisplayed() + } + + fun verifySearchWasOpened() { + onView(withId(R.id.searchBtn)).performScrollToAndCheckIsDisplayed() + } +} \ No newline at end of file diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/misc/MiscFragmentTest.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/misc/MiscFragmentTest.kt new file mode 100644 index 00000000..bac4f446 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/misc/MiscFragmentTest.kt @@ -0,0 +1,1403 @@ +package com.isupatches.wisefysample.ui.misc + +import android.Manifest.permission.ACCESS_COARSE_LOCATION +import android.Manifest.permission.ACCESS_NETWORK_STATE +import android.Manifest.permission.ACCESS_WIFI_STATE +import android.Manifest.permission.CHANGE_WIFI_STATE +import android.content.pm.PackageManager +import androidx.test.espresso.intent.rule.IntentsTestRule +import androidx.test.rule.GrantPermissionRule + +import com.isupatches.wisefysample.RANDO_PERMISSION_REQUEST_CODE +import com.isupatches.wisefysample.internal.base.AbstractEspressoTestClass +import com.isupatches.wisefysample.ui.main.MainActivity + +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +internal class MiscFragmentTest : AbstractEspressoTestClass() { + + @get:Rule + val activityTestRule = IntentsTestRule(MainActivity::class.java, false, false) + + @get:Rule + val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(ACCESS_COARSE_LOCATION) + + private lateinit var miscRobot: MiscRobot + + @Before override fun setUp() { + super.setUp() + miscRobot = MiscRobot(activityTestRule, wiseFy, sdkUtil, permissionUtil) + } + + @Test fun disableWifi_permissionErrorDialog() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + launchMiscScreen() + disableWifi() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_DISABLE_WIFI_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun disableWifi_permissionError_once() { + with(miscRobot) { + // Given + withSuccessDisablingWifi() + withPermissionDeniedOnce(CHANGE_WIFI_STATE) + launchMiscScreen() + + // When + disableWifi() + + // Then + verifyTriedToDisableWifi() + verifyWifiDisabledIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun disableWifi_permissionError_emptyList() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withSuccessDisablingWifi() + launchMiscScreen() + disableWifi() + + // When + permissionCallbackTriggeredWithEmptyArray( + MiscFragment.WISEFY_DISABLE_WIFI_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToDisableWifi() + } + } + + @Test fun disableWifi_permissionError_permissionDenied() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withSuccessDisablingWifi() + launchMiscScreen() + disableWifi() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_DISABLE_WIFI_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToDisableWifi() + } + } + + @Test fun disableWifi_success_afterPermissionGranted() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withSuccessDisablingWifi() + launchMiscScreen() + disableWifi() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_DISABLE_WIFI_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToDisableWifi(times = 2) + verifyWifiDisabledIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun disableWifi_success() { + with(miscRobot) { + // Given + withPermissionDeniedOnce(CHANGE_WIFI_STATE) + withSuccessDisablingWifi() + launchMiscScreen() + + // When + disableWifi() + + // Then + verifyTriedToDisableWifi() + verifyWifiDisabledIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun disableWifi_failureDisablingWifi() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withFailureDisablingWifi() + launchMiscScreen() + + // When + disableWifi() + + // Then + verifyTriedToDisableWifi() + verifyFailureDisablingWifiIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun disableWifi_wiseFyFailure() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withWiseFyFailureDisablingWifi() + launchMiscScreen() + + // When + disableWifi() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToDisableWifi() + + // And + dismissErrorDialog() + } + } + + @Test fun enableWifi_permissionErrorDialog() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + launchMiscScreen() + enableWifi() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_ENABLE_WIFI_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun enableWifi_permissionError_once() { + with(miscRobot) { + // Given + withSuccessEnablingWifi() + withPermissionDeniedOnce(CHANGE_WIFI_STATE) + launchMiscScreen() + + // When + enableWifi() + + // Then + verifyTriedToEnableWifi() + verifyWifiEnabledIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun enableWifi_permissionError_emptyList() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withSuccessEnablingWifi() + launchMiscScreen() + enableWifi() + + // When + permissionCallbackTriggeredWithEmptyArray( + MiscFragment.WISEFY_ENABLE_WIFI_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToEnableWifi() + } + } + + @Test fun enableWifi_permissionError_permissionDenied() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withSuccessEnablingWifi() + launchMiscScreen() + enableWifi() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_ENABLE_WIFI_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToEnableWifi() + } + } + + @Test fun enableWifi_success_afterPermissionGranted() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withSuccessEnablingWifi() + launchMiscScreen() + enableWifi() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_ENABLE_WIFI_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToEnableWifi(times = 2) + verifyWifiEnabledIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun enableWifi_success() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withSuccessEnablingWifi() + launchMiscScreen() + + // When + enableWifi() + + // Then + verifyTriedToEnableWifi() + verifyWifiEnabledIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun enableWifi_failureEnablingWifi() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withFailureEnablingWifi() + launchMiscScreen() + + // When + enableWifi() + + // Then + verifyTriedToEnableWifi() + verifyFailureEnablingWifiIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun enableWifi_wiseFyFailure() { + with(miscRobot) { + // Given + withPermission(CHANGE_WIFI_STATE) + withWiseFyFailureEnablingWifi() + launchMiscScreen() + + // When + enableWifi() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToEnableWifi() + + // And + dismissErrorDialog() + } + } + + @Test fun getCurrentNetwork_permissionErrorDialog() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchMiscScreen() + getCurrentNetwork() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun getCurrentNetwork_permissionError_once() { + with(miscRobot) { + // Given + withSuccessGettingCurrentNetwork() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getCurrentNetwork() + + // Then + verifyTriedToGetCurrentNetwork() + verifyCurrentNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getCurrentNetwork_permissionError_once_accessWifiState() { + with(miscRobot) { + // Given + withSuccessGettingCurrentNetwork() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermission(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getCurrentNetwork() + + // Then + verifyTriedToGetCurrentNetwork() + verifyCurrentNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getCurrentNetwork_permissionError_once_accessCoarseLocation() { + with(miscRobot) { + // Given + withSuccessGettingCurrentNetwork() + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getCurrentNetwork() + + // Then + verifyTriedToGetCurrentNetwork() + verifyCurrentNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getCurrentNetwork_permissionError_emptyList() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingCurrentNetwork() + launchMiscScreen() + getCurrentNetwork() + + // When + permissionCallbackTriggeredWithEmptyArray( + MiscFragment.WISEFY_GET_CURRENT_NETWORK_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToGetCurrentNetwork() + } + } + + @Test fun getCurrentNetwork_permissionError_permissionDenied() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingCurrentNetwork() + launchMiscScreen() + getCurrentNetwork() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_CURRENT_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToGetCurrentNetwork() + } + } + + @Test fun getCurrentNetwork_success_afterPermissionGranted() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingCurrentNetwork() + launchMiscScreen() + getCurrentNetwork() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_CURRENT_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToGetCurrentNetwork(times = 2) + verifyCurrentNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getCurrentNetwork_success() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingCurrentNetwork() + launchMiscScreen() + + // When + getCurrentNetwork() + + // Then + verifyTriedToGetCurrentNetwork() + verifyCurrentNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getCurrentNetwork_noCurrentNetwork() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withNoCurrentNetwork() + launchMiscScreen() + + // When + getCurrentNetwork() + + // Then + verifyTriedToGetCurrentNetwork() + verifyNoCurrentNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getCurrentNetwork_wiseFyFailure() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withWiseFyFailureGettingCurrentNetwork() + launchMiscScreen() + + // When + getCurrentNetwork() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToGetCurrentNetwork() + + // And + dismissErrorDialog() + } + } + + @Test fun getCurrentNetworkInfo_permissionErrorDialog() { + with(miscRobot) { + // Given + withPermission(ACCESS_NETWORK_STATE) + launchMiscScreen() + getCurrentNetworkInfo() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_CURRENT_NETWORK_INFO_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun getCurrentNetworkInfo_permissionError_once() { + with(miscRobot) { + // Given + withSuccessGettingCurrentNetworkInfo() + withPermissionDeniedOnce(ACCESS_NETWORK_STATE) + launchMiscScreen() + + // When + getCurrentNetworkInfo() + + // Then + verifyTriedToGetCurrentNetworkInfo() + verifyCurrentNetworkInfoIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getCurrentNetworkInfo_permissionError_emptyList() { + with(miscRobot) { + // Given + withPermission(ACCESS_NETWORK_STATE) + withSuccessGettingCurrentNetworkInfo() + launchMiscScreen() + getCurrentNetworkInfo() + + // When + permissionCallbackTriggeredWithEmptyArray( + MiscFragment.WISEFY_GET_CURRENT_NETWORK_INFO_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToGetCurrentNetworkInfo() + } + } + + @Test fun getCurrentNetworkInfo_permissionError_permissionDenied() { + with(miscRobot) { + // Given + withPermission(ACCESS_NETWORK_STATE) + withSuccessGettingCurrentNetworkInfo() + launchMiscScreen() + getCurrentNetworkInfo() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_CURRENT_NETWORK_INFO_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToGetCurrentNetworkInfo() + } + } + + @Test fun getCurrentNetworkInfo_success_afterPermissionGranted() { + with(miscRobot) { + // Given + withPermission(ACCESS_NETWORK_STATE) + withSuccessGettingCurrentNetworkInfo() + launchMiscScreen() + getCurrentNetworkInfo() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_CURRENT_NETWORK_INFO_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToGetCurrentNetworkInfo(times = 2) + verifyCurrentNetworkInfoIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getCurrentNetworkInfo_success() { + with(miscRobot) { + // Given + withPermission(ACCESS_NETWORK_STATE) + withSuccessGettingCurrentNetworkInfo() + launchMiscScreen() + + // When + getCurrentNetworkInfo() + + // Then + verifyTriedToGetCurrentNetworkInfo() + verifyCurrentNetworkInfoIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getCurrentNetworkInfo_noCurrentNetworkInfo() { + with(miscRobot) { + // Given + withPermission(ACCESS_NETWORK_STATE) + withNoCurrentNetworkInfo() + launchMiscScreen() + + // When + getCurrentNetworkInfo() + + // Then + verifyTriedToGetCurrentNetworkInfo() + verifyNoCurrentNetworkInfoIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getCurrentNetworkInfo_wiseFyFailure() { + with(miscRobot) { + // Given + withPermission(ACCESS_NETWORK_STATE) + withWiseFyFailureGettingCurrentNetworkInfo() + launchMiscScreen() + + // When + getCurrentNetworkInfo() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToGetCurrentNetworkInfo() + + // And + dismissErrorDialog() + } + } + + @Test fun getFrequency_belowLollipop() { + with(miscRobot) { + // Given + withDeviceBelowLollipop() + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getFrequency() + + // Then + verifyFrequencyLollipopNoticeIsDisplayed() + dismissErrorDialog() + } + } + + @Test fun getFrequency_permissionErrorDialog() { + with(miscRobot) { + // Given + withDeviceLollipopOrHigher() + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchMiscScreen() + getFrequency() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_FREQUENCY_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun getFrequency_permissionError_once() { + with(miscRobot) { + // Given + withDeviceLollipopOrHigher() + withSuccessGettingFrequency() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getFrequency() + + // Then + verifyTriedToGetFrequency() + dismissResultsDialog() + } + } + + @Test fun getFrequency_permissionError_once_accessWifiState() { + with(miscRobot) { + // Given + withDeviceLollipopOrHigher() + withSuccessGettingFrequency() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermission(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getFrequency() + + // Then + verifyTriedToGetFrequency() + verifyFrequencyIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getFrequency_permissionError_once_accessCoarseLocation() { + with(miscRobot) { + // Given + withDeviceLollipopOrHigher() + withSuccessGettingFrequency() + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getFrequency() + + // Then + verifyTriedToGetFrequency() + verifyFrequencyIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getFrequency_permissionError_emptyList() { + with(miscRobot) { + // Given + withDeviceLollipopOrHigher() + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingFrequency() + launchMiscScreen() + getFrequency() + + // When + permissionCallbackTriggeredWithEmptyArray( + MiscFragment.WISEFY_GET_FREQUENCY_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToGetFrequency() + } + } + + @Test fun getFrequency_permissionError_permissionDenied() { + with(miscRobot) { + // Given + withDeviceLollipopOrHigher() + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingFrequency() + launchMiscScreen() + getFrequency() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_FREQUENCY_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToGetFrequency() + } + } + + @Test fun getFrequency_success_afterPermissionGranted() { + with(miscRobot) { + // Given + withDeviceLollipopOrHigher() + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingFrequency() + launchMiscScreen() + getFrequency() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_FREQUENCY_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToGetFrequency(times = 2) + dismissResultsDialog() + } + } + + @Test fun getFrequency_success() { + with(miscRobot) { + // Given + withDeviceLollipopOrHigher() + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingFrequency() + launchMiscScreen() + + // When + getFrequency() + + // Then + verifyTriedToGetFrequency() + verifyFrequencyIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getFrequency_failureGettingFrequency() { + with(miscRobot) { + // Given + withDeviceLollipopOrHigher() + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withFailureGettingFrequency() + launchMiscScreen() + + // When + getFrequency() + + // Then + verifyTriedToGetFrequency() + verifyFailureRetrievingFrequencyIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getFrequency_wiseFyFailure() { + with(miscRobot) { + // Given + withDeviceLollipopOrHigher() + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withWiseFyFailureGettingFrequency() + launchMiscScreen() + + // When + getFrequency() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToGetFrequency() + + // And + dismissErrorDialog() + } + } + + @Test fun getIP_permissionErrorDialog() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchMiscScreen() + getIP() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_IP_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun getIP_permissionError_once() { + with(miscRobot) { + // Given + withSuccessGettingIP() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getIP() + + // Then + verifyTriedToGetIP() + verifyIPIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getIP_permissionError_once_accessWifiState() { + with(miscRobot) { + // Given + withSuccessGettingIP() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermission(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getIP() + + // Then + verifyTriedToGetIP() + verifyIPIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getIP_permissionError_once_accessCoarseLocation() { + with(miscRobot) { + // Given + withSuccessGettingIP() + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getIP() + + // Then + verifyTriedToGetIP() + verifyIPIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getIP_permissionError_emptyList() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingIP() + launchMiscScreen() + getIP() + + // When + permissionCallbackTriggeredWithEmptyArray( + MiscFragment.WISEFY_GET_IP_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToGetIP() + } + } + + @Test fun getIP_permissionError_permissionDenied() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingIP() + launchMiscScreen() + getIP() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_IP_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToGetIP() + } + } + + @Test fun getIP_success_afterPermissionGranted() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingIP() + launchMiscScreen() + getIP() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_IP_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToGetIP(times = 2) + verifyIPIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getIP_success() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingIP() + launchMiscScreen() + + // When + getIP() + + // Then + verifyTriedToGetIP() + verifyIPIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getIP_failureGettingIp() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withFailureGettingIP() + launchMiscScreen() + + // When + getIP() + + // Then + verifyTriedToGetIP() + verifyFailureRetrievingIPIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getIP_wiseFyFailure() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withWiseFyFailureGettingIP() + launchMiscScreen() + + // When + getIP() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToGetIP() + + // And + dismissErrorDialog() + } + } + + @Test fun getNearbyAccessPoints_permissionErrorDialog() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchMiscScreen() + getNearbyAccessPoints() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun getNearbyAccessPoints_permissionError_once() { + with(miscRobot) { + // Given + withSuccessGettingNearbyAccessPoints() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getNearbyAccessPoints() + + // Then + verifyTriedToGetNearbyAccessPoints() + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun getNearbyAccessPoints_permissionError_once_accessWifiState() { + with(miscRobot) { + // Given + withSuccessGettingNearbyAccessPoints() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermission(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getNearbyAccessPoints() + + // Then + verifyTriedToGetNearbyAccessPoints() + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun getNearbyAccessPoints_permissionError_once_accessCoarseLocation() { + with(miscRobot) { + // Given + withSuccessGettingNearbyAccessPoints() + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchMiscScreen() + + // When + getNearbyAccessPoints() + + // Then + verifyTriedToGetNearbyAccessPoints() + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun getNearbyAccessPoints_permissionError_emptyList() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingNearbyAccessPoints() + launchMiscScreen() + getNearbyAccessPoints() + + // When + permissionCallbackTriggeredWithEmptyArray( + MiscFragment.WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToGetNearbyAccessPoints() + } + } + + @Test fun getNearbyAccessPoints_permissionError_permissionDenied() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingNearbyAccessPoints() + launchMiscScreen() + getNearbyAccessPoints() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToGetNearbyAccessPoints() + } + } + + @Test fun getNearbyAccessPoints_success_afterPermissionGranted() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingNearbyAccessPoints() + launchMiscScreen() + getNearbyAccessPoints() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToGetNearbyAccessPoints(times = 2) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun getNearbyAccessPoints_success() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessGettingNearbyAccessPoints() + launchMiscScreen() + + // When + getNearbyAccessPoints() + + // Then + verifyTriedToGetNearbyAccessPoints() + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun getNearbyAccessPoints_noNearbyAccessPoints() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withNoNearbyAccessPoints() + launchMiscScreen() + + // When + getNearbyAccessPoints() + + // Then + verifyTriedToGetNearbyAccessPoints() + verifyNoAccessPointsFoundIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getNearbyAccessPoints_wiseFyFailure() { + with(miscRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withWiseFyFailureGettingNearbyAccessPoints() + launchMiscScreen() + + // When + getNearbyAccessPoints() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToGetNearbyAccessPoints() + + // And + dismissErrorDialog() + } + } + + @Test fun getSavedNetworks_permissionErrorDialog() { + with(miscRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + launchMiscScreen() + getSavedNetworks() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_SAVED_NETWORKS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun getSavedNetworks_permissionError_once() { + with(miscRobot) { + // Given + withSuccessGettingSavedNetworks() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + launchMiscScreen() + + // When + getSavedNetworks() + + // Then + verifyTriedToGetSavedNetworks() + verifySavedNetworksAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun getSavedNetworks_permissionError_emptyList() { + with(miscRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessGettingCurrentNetworkInfo() + launchMiscScreen() + getSavedNetworks() + + // When + permissionCallbackTriggeredWithEmptyArray( + MiscFragment.WISEFY_GET_SAVED_NETWORKS_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToGetSavedNetworks() + } + } + + @Test fun getSavedNetworks_permissionError_permissionDenied() { + with(miscRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessGettingCurrentNetworkInfo() + launchMiscScreen() + getSavedNetworks() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_SAVED_NETWORKS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToGetSavedNetworks() + } + } + + @Test fun getSavedNetworks_success_afterPermissionGranted() { + with(miscRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessGettingSavedNetworks() + launchMiscScreen() + getSavedNetworks() + + // When + permissionCallbackTriggered( + MiscFragment.WISEFY_GET_SAVED_NETWORKS_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToGetSavedNetworks(times = 2) + verifySavedNetworksAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun getSavedNetworks_success() { + with(miscRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessGettingSavedNetworks() + launchMiscScreen() + + // When + getSavedNetworks() + + // Then + verifyTriedToGetSavedNetworks() + verifySavedNetworksAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun getSavedNetworks_noSavedNetworks() { + with(miscRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withNoSavedNetworks() + launchMiscScreen() + + // When + getSavedNetworks() + + // Then + verifyTriedToGetSavedNetworks() + verifyNoSavedNetworksFoundIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun getSavedNetworks_wiseFyFailure() { + with(miscRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withWiseFyFailureGettingSavedNetworks() + launchMiscScreen() + + // When + getSavedNetworks() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToGetSavedNetworks() + + // And + dismissErrorDialog() + } + } + + @Test fun ridiculousPermissionRequested() { + with(miscRobot) { + // Given + launchMiscScreen() + + // When + permissionCallbackTriggeredWithEmptyArray(RANDO_PERMISSION_REQUEST_CODE) + + // Then + verifyPermissionErrorShown() + dismissErrorDialog() + } + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/misc/MiscRobot.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/misc/MiscRobot.kt new file mode 100644 index 00000000..211698e1 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/misc/MiscRobot.kt @@ -0,0 +1,410 @@ +package com.isupatches.wisefysample.ui.misc + +import android.content.Intent +import android.net.NetworkInfo +import android.net.wifi.ScanResult +import android.net.wifi.WifiConfiguration +import android.net.wifi.WifiInfo +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.rule.ActivityTestRule + +import com.isupatches.wisefy.WiseFy.Companion.MIN_FREQUENCY_5GHZ +import com.isupatches.wisefy.WiseFyPublicApi +import com.isupatches.wisefy.callbacks.DisableWifiCallbacks +import com.isupatches.wisefy.callbacks.EnableWifiCallbacks +import com.isupatches.wisefy.callbacks.GetCurrentNetworkCallbacks +import com.isupatches.wisefy.callbacks.GetCurrentNetworkInfoCallbacks +import com.isupatches.wisefy.callbacks.GetFrequencyCallbacks +import com.isupatches.wisefy.callbacks.GetIPCallbacks +import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks +import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks +import com.isupatches.wisefy.constants.MISSING_PARAMETER +import com.isupatches.wisefysample.R +import com.isupatches.wisefysample.TEST_IP +import com.isupatches.wisefysample.internal.base.BaseRobot +import com.isupatches.wisefysample.internal.espresso.checkIsDisplayed +import com.isupatches.wisefysample.internal.espresso.getString +import com.isupatches.wisefysample.internal.espresso.performClick +import com.isupatches.wisefysample.internal.espresso.performScrollToAndClick +import com.isupatches.wisefysample.internal.util.PermissionUtil +import com.isupatches.wisefysample.internal.util.SdkUtil +import com.isupatches.wisefysample.ui.main.MainActivity + +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.doAnswer +import com.nhaarman.mockitokotlin2.eq +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.timeout +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.whenever +import org.hamcrest.CoreMatchers.containsString + +import org.mockito.Mockito.`when` + +internal class MiscRobot( + private val activityTestRule: ActivityTestRule, + private val wiseFyPublicApi: WiseFyPublicApi, + private val sdkUtil: SdkUtil, + permissionUtil: PermissionUtil +) : BaseRobot(activityTestRule, permissionUtil) { + + companion object { + private val CURRENT_NETWORK = mock() + private val CURRENT_NETWORK_INFO = mock() + + private val ACCESS_POINT = mock() + private val SAVED_NETWORK = mock() + } + + /* + * Preconditions + */ + + fun withSuccessDisablingWifi() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as DisableWifiCallbacks + callback.wifiDisabled() + }.whenever(wiseFyPublicApi).disableWifi(any()) + } + + fun withFailureDisablingWifi() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as DisableWifiCallbacks + callback.failureDisablingWifi() + }.whenever(wiseFyPublicApi).disableWifi(any()) + } + + fun withWiseFyFailureDisablingWifi() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as DisableWifiCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).disableWifi(any()) + } + + fun withSuccessEnablingWifi() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as EnableWifiCallbacks + callback.wifiEnabled() + }.whenever(wiseFyPublicApi).enableWifi(any()) + } + + fun withFailureEnablingWifi() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as EnableWifiCallbacks + callback.failureEnablingWifi() + }.whenever(wiseFyPublicApi).enableWifi(any()) + } + + fun withWiseFyFailureEnablingWifi() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as EnableWifiCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).enableWifi(any()) + } + + fun withSuccessGettingCurrentNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetCurrentNetworkCallbacks + callback.retrievedCurrentNetwork(CURRENT_NETWORK) + }.whenever(wiseFyPublicApi).getCurrentNetwork(any()) + } + + fun withNoCurrentNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetCurrentNetworkCallbacks + callback.noCurrentNetwork() + }.whenever(wiseFyPublicApi).getCurrentNetwork(any()) + } + + fun withWiseFyFailureGettingCurrentNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetCurrentNetworkCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).getCurrentNetwork(any()) + } + + fun withSuccessGettingCurrentNetworkInfo() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetCurrentNetworkInfoCallbacks + callback.retrievedCurrentNetworkInfo(CURRENT_NETWORK_INFO) + }.whenever(wiseFyPublicApi).getCurrentNetworkInfo(any()) + } + + fun withNoCurrentNetworkInfo() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetCurrentNetworkInfoCallbacks + callback.noCurrentNetworkInfo() + }.whenever(wiseFyPublicApi).getCurrentNetworkInfo(any()) + } + + fun withWiseFyFailureGettingCurrentNetworkInfo() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetCurrentNetworkInfoCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).getCurrentNetworkInfo(any()) + } + + fun withSuccessGettingFrequency() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetFrequencyCallbacks + callback.retrievedFrequency(MIN_FREQUENCY_5GHZ) + }.whenever(wiseFyPublicApi).getFrequency(any()) + } + + fun withFailureGettingFrequency() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetFrequencyCallbacks + callback.failureGettingFrequency() + }.whenever(wiseFyPublicApi).getFrequency(any()) + } + + fun withWiseFyFailureGettingFrequency() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetFrequencyCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).getFrequency(any()) + } + + fun withSuccessGettingIP() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetIPCallbacks + callback.retrievedIP(TEST_IP) + }.whenever(wiseFyPublicApi).getIP(any()) + } + + fun withFailureGettingIP() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetIPCallbacks + callback.failureRetrievingIP() + }.whenever(wiseFyPublicApi).getIP(any()) + } + + fun withWiseFyFailureGettingIP() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetIPCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).getIP(any()) + } + + fun withSuccessGettingNearbyAccessPoints() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as GetNearbyAccessPointsCallbacks + callback.retrievedNearbyAccessPoints(listOf(ACCESS_POINT)) + }.whenever(wiseFyPublicApi).getNearbyAccessPoints(eq(true), any()) + } + + fun withNoNearbyAccessPoints() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as GetNearbyAccessPointsCallbacks + callback.noAccessPointsFound() + }.whenever(wiseFyPublicApi).getNearbyAccessPoints(eq(true), any()) + } + + fun withWiseFyFailureGettingNearbyAccessPoints() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as GetNearbyAccessPointsCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).getNearbyAccessPoints(eq(true), any()) + } + + fun withSuccessGettingSavedNetworks() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetSavedNetworksCallbacks + callback.retrievedSavedNetworks(listOf(SAVED_NETWORK)) + }.whenever(wiseFyPublicApi).getSavedNetworks(any()) + } + + fun withNoSavedNetworks() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetSavedNetworksCallbacks + callback.noSavedNetworksFound() + }.whenever(wiseFyPublicApi).getSavedNetworks(any()) + } + + fun withWiseFyFailureGettingSavedNetworks() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[0] as GetSavedNetworksCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).getSavedNetworks(any()) + } + + fun withDeviceBelowLollipop() { + `when`(sdkUtil.isAtLeastLollipop()).thenReturn(false) + } + + fun withDeviceLollipopOrHigher() { + `when`(sdkUtil.isAtLeastLollipop()).thenReturn(true) + } + + /* + * Actions + */ + + fun disableWifi() { + onView(withId(R.id.disableWifiBtn)).performScrollToAndClick() + } + + fun enableWifi() { + onView(withId(R.id.enableWifiBtn)).performScrollToAndClick() + } + + fun getCurrentNetwork() { + onView(withId(R.id.getCurrentNetworkBtn)).performScrollToAndClick() + } + + fun getCurrentNetworkInfo() { + onView(withId(R.id.getCurrentNetworkInfoBtn)).performScrollToAndClick() + } + + fun getFrequency() { + onView(withId(R.id.getFrequencyBtn)).performScrollToAndClick() + } + + fun getIP() { + onView(withId(R.id.getIPBtn)).performScrollToAndClick() + } + + fun getNearbyAccessPoints() { + onView(withId(R.id.getNearbyAccessPointsBtn)).performScrollToAndClick() + } + + fun getSavedNetworks() { + onView(withId(R.id.getSavedNetworksBtn)).performScrollToAndClick() + } + + fun launchMiscScreen() { + activityTestRule.launchActivity(Intent()) + onView(withId(R.id.menu_misc)).performClick() + } + + /* + * Permission Helpers + */ + + fun permissionCallbackTriggered(requestCode: Int, permissionResult: Int) { + val activity = activityTestRule.activity + val fragment: MiscFragment? = activity + .supportFragmentManager + .findFragmentByTag( + MiscFragment.TAG + ) as? MiscFragment + + activity.runOnUiThread { + fragment?.onRequestPermissionsResult( + requestCode, + emptyArray(), + intArrayOf(permissionResult) + ) + } + } + + fun permissionCallbackTriggeredWithEmptyArray(requestCode: Int) { + val activity = activityTestRule.activity + val fragment: MiscFragment? = activity + .supportFragmentManager + .findFragmentByTag( + MiscFragment.TAG + ) as? MiscFragment + + activity.runOnUiThread { + fragment?.onRequestPermissionsResult( + requestCode, + emptyArray(), + intArrayOf() + ) + } + } + + /* + * Verification + */ + + fun verifyWifiDisabledIsDisplayed() { + onView(withText(R.string.wifi_disabled)).checkIsDisplayed() + } + + fun verifyFailureDisablingWifiIsDisplayed() { + onView(withText(R.string.failure_disabling_wifi)).checkIsDisplayed() + } + + fun verifyWifiEnabledIsDisplayed() { + onView(withText(R.string.wifi_enabled)).checkIsDisplayed() + } + + fun verifyFailureEnablingWifiIsDisplayed() { + onView(withText(R.string.failure_enabling_wifi)).checkIsDisplayed() + } + + fun verifyCurrentNetworkIsDisplayed() { + onView(withText(containsString("Current network"))).checkIsDisplayed() + } + + fun verifyNoCurrentNetworkIsDisplayed() { + onView(withText(R.string.no_current_network)).checkIsDisplayed() + } + + fun verifyCurrentNetworkInfoIsDisplayed() { + onView(withText(containsString("Current network info"))).checkIsDisplayed() + } + + fun verifyNoCurrentNetworkInfoIsDisplayed() { + onView(withText(R.string.no_current_network_info)).checkIsDisplayed() + } + + fun verifyFrequencyIsDisplayed() { + onView(withText(containsString("$MIN_FREQUENCY_5GHZ"))).checkIsDisplayed() + } + + fun verifyFailureRetrievingFrequencyIsDisplayed() { + onView(withText(R.string.failure_retrieving_frequency)).checkIsDisplayed() + } + + fun verifyIPIsDisplayed() { + onView(withText(containsString(TEST_IP))).checkIsDisplayed() + } + + fun verifyFailureRetrievingIPIsDisplayed() { + onView(withText(R.string.failure_retrieving_ip)).checkIsDisplayed() + } + + fun verifyTriedToDisableWifi(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).disableWifi(any()) + } + + fun verifyTriedToEnableWifi(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).enableWifi(any()) + } + + fun verifyTriedToGetCurrentNetwork(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).getCurrentNetwork(any()) + } + + fun verifyTriedToGetCurrentNetworkInfo(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).getCurrentNetworkInfo(any()) + } + + fun verifyTriedToGetIP(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).getIP(any()) + } + + fun verifyTriedToGetFrequency(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).getFrequency(any()) + } + + fun verifyTriedToGetNearbyAccessPoints(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).getNearbyAccessPoints(eq(true), any()) + } + + fun verifyTriedToGetSavedNetworks(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).getSavedNetworks(any()) + } + + fun verifyFrequencyLollipopNoticeIsDisplayed() { + onView(withText( + activityTestRule.getString(R.string.frequency_lollipop_notice) + )) + .checkIsDisplayed() + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkFragmentTest.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkFragmentTest.kt new file mode 100644 index 00000000..13009197 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkFragmentTest.kt @@ -0,0 +1,223 @@ +package com.isupatches.wisefysample.ui.remove + +import android.Manifest.permission.ACCESS_WIFI_STATE +import android.content.pm.PackageManager +import androidx.test.espresso.intent.rule.IntentsTestRule + +import com.isupatches.wisefysample.RANDO_PERMISSION_REQUEST_CODE +import com.isupatches.wisefysample.internal.base.AbstractEspressoTestClass +import com.isupatches.wisefysample.ui.main.MainActivity + +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +internal class RemoveNetworkFragmentTest : AbstractEspressoTestClass() { + + @get:Rule + val activityTestRule = IntentsTestRule(MainActivity::class.java, false, false) + + private lateinit var removeNetworkRobot: RemoveNetworkRobot + + @Before override fun setUp() { + super.setUp() + removeNetworkRobot = RemoveNetworkRobot( + activityTestRule, + wiseFy, + removeNetworkStore, + permissionUtil + ) + } + + @Test fun loadsFromStore() { + with(removeNetworkRobot) { + // Given + withDetailsInStore() + + // When + launchRemoveNetworkScreen() + + // Then + verifyNetworkNameIsPopulated() + } + } + + @Test fun removeNetwork_permissionErrorDialog() { + with(removeNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + launchRemoveNetworkScreen() + removeNetwork() + + // When + permissionCallbackTriggered( + RemoveNetworkFragment.WISEFY_REMOVE_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun removeNetwork_permissionError_once() { + with(removeNetworkRobot) { + // Given + withSuccessRemovingNetwork() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + launchRemoveNetworkScreen() + + // When + removeNetwork() + + // Then + verifyTriedToRemoveNetwork() + verifyNetworkRemovedIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun removeNetwork_permissionError_emptyList() { + with(removeNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessRemovingNetwork() + launchRemoveNetworkScreen() + removeNetwork() + + // When + permissionCallbackTriggeredWithEmptyArray( + RemoveNetworkFragment.WISEFY_REMOVE_NETWORK_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifyTriedToRemoveNetwork() + } + } + + @Test fun removeNetwork_permissionError_permissionDenied() { + with(removeNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessRemovingNetwork() + launchRemoveNetworkScreen() + removeNetwork() + + // When + permissionCallbackTriggered( + RemoveNetworkFragment.WISEFY_REMOVE_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifyTriedToRemoveNetwork() + } + } + + @Test fun removeNetwork_success_afterPermissionGranted() { + with(removeNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessRemovingNetwork() + launchRemoveNetworkScreen() + removeNetwork() + + // When + permissionCallbackTriggered( + RemoveNetworkFragment.WISEFY_REMOVE_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifyTriedToRemoveNetwork(times = 2) + verifyNetworkRemovedIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun removeNetwork_success() { + with(removeNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessRemovingNetwork() + launchRemoveNetworkScreen() + + // When + removeNetwork() + + // Then + verifyTriedToRemoveNetwork() + verifyNetworkRemovedIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun removeNetwork_failureToRemoveNetwork() { + with(removeNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withFailureRemovingNetwork() + launchRemoveNetworkScreen() + + // When + removeNetwork() + + // Then + verifyTriedToRemoveNetwork() + verifyFailureToRemovingNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun removeNetwork_networkNotFoundToRemove() { + with(removeNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withNetworkNotFoundToRemove() + launchRemoveNetworkScreen() + + // When + removeNetwork() + + // Then + verifyTriedToRemoveNetwork() + verifyNetworkNotFoundToRemoveIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun removeNetwork_wiseFyFailure() { + with(removeNetworkRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withWiseFyFailureRemovingNetwork() + launchRemoveNetworkScreen() + + // When + removeNetwork() + + // Then + verifyWiseFyFailureIsDisplayed() + verifyTriedToRemoveNetwork() + + // And + dismissErrorDialog() + } + } + + @Test fun ridiculousPermissionRequested() { + with(removeNetworkRobot) { + // Given + launchRemoveNetworkScreen() + + // When + permissionCallbackTriggeredWithEmptyArray(RANDO_PERMISSION_REQUEST_CODE) + + // Then + verifyPermissionErrorShown() + dismissErrorDialog() + } + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkRobot.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkRobot.kt new file mode 100644 index 00000000..94014d94 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkRobot.kt @@ -0,0 +1,158 @@ +package com.isupatches.wisefysample.ui.remove + +import android.content.Intent +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.rule.ActivityTestRule + +import com.isupatches.wisefy.WiseFyPublicApi +import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks +import com.isupatches.wisefy.constants.MISSING_PARAMETER +import com.isupatches.wisefysample.R +import com.isupatches.wisefysample.TEST_SSID_1 +import com.isupatches.wisefysample.internal.base.BaseRobot +import com.isupatches.wisefysample.internal.espresso.checkIsDisplayed +import com.isupatches.wisefysample.internal.espresso.performClick +import com.isupatches.wisefysample.internal.espresso.performScrollToAndClick +import com.isupatches.wisefysample.internal.espresso.performScrollToAndReplaceText +import com.isupatches.wisefysample.internal.preferences.RemoveNetworkStore +import com.isupatches.wisefysample.internal.util.PermissionUtil +import com.isupatches.wisefysample.ui.main.MainActivity + +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.doAnswer +import com.nhaarman.mockitokotlin2.eq +import com.nhaarman.mockitokotlin2.timeout +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.whenever + +internal class RemoveNetworkRobot( + private val activityTestRule: ActivityTestRule, + private val wiseFyPublicApi: WiseFyPublicApi, + private val removeNetworkStore: RemoveNetworkStore, + permissionUtil: PermissionUtil +) : BaseRobot(activityTestRule, permissionUtil) { + + /* + * Preconditions + */ + + fun withDetailsInStore() { + with(removeNetworkStore) { + setLastUsedRegex(TEST_SSID_1) + } + } + + fun withSuccessRemovingNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as RemoveNetworkCallbacks + callback.networkRemoved() + }.whenever(wiseFyPublicApi).removeNetwork( + eq(TEST_SSID_1), + any() + ) + } + + fun withNetworkNotFoundToRemove() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as RemoveNetworkCallbacks + callback.networkNotFoundToRemove() + }.whenever(wiseFyPublicApi).removeNetwork( + eq(TEST_SSID_1), + any() + ) + } + + fun withFailureRemovingNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as RemoveNetworkCallbacks + callback.failureRemovingNetwork() + }.whenever(wiseFyPublicApi).removeNetwork( + eq(TEST_SSID_1), + any() + ) + } + + fun withWiseFyFailureRemovingNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as RemoveNetworkCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).removeNetwork( + eq(TEST_SSID_1), + any() + ) + } + + /* + * Actions + */ + + fun launchRemoveNetworkScreen() { + activityTestRule.launchActivity(Intent()) + onView(withId(R.id.menu_remove)).performClick() + } + + fun removeNetwork() { + onView(withId(R.id.networkNameEdt)).performScrollToAndReplaceText(TEST_SSID_1) + onView(withId(R.id.removeNetworkBtn)).performScrollToAndClick() + } + + /* + * Permission Helpers + */ + + fun permissionCallbackTriggered(requestCode: Int, permissionResult: Int) { + val activity = activityTestRule.activity + val fragment: RemoveNetworkFragment? = activity + .supportFragmentManager + .findFragmentByTag( + RemoveNetworkFragment.TAG + ) as? RemoveNetworkFragment + + activity.runOnUiThread { + fragment?.onRequestPermissionsResult( + requestCode, + emptyArray(), + intArrayOf(permissionResult) + ) + } + } + + fun permissionCallbackTriggeredWithEmptyArray(requestCode: Int) { + val activity = activityTestRule.activity + val fragment: RemoveNetworkFragment? = activity + .supportFragmentManager + .findFragmentByTag( + RemoveNetworkFragment.TAG + ) as? RemoveNetworkFragment + + activity.runOnUiThread { + fragment?.onRequestPermissionsResult( + requestCode, + emptyArray(), + intArrayOf() + ) + } + } + + /* + * Verification + */ + + fun verifyFailureToRemovingNetworkIsDisplayed() { + onView(withText(R.string.failure_removing_network)).checkIsDisplayed() + } + + fun verifyNetworkNotFoundToRemoveIsDisplayed() { + onView(withText(R.string.network_not_found_to_remove)).checkIsDisplayed() + } + + fun verifyNetworkRemovedIsDisplayed() { + onView(withText("Network removed")).checkIsDisplayed() + } + + fun verifyTriedToRemoveNetwork(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).removeNetwork(eq(TEST_SSID_1), any()) + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/search/SearchFragmentTest.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/search/SearchFragmentTest.kt new file mode 100644 index 00000000..e0e8e4f6 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/search/SearchFragmentTest.kt @@ -0,0 +1,1679 @@ +package com.isupatches.wisefysample.ui.search + +import android.Manifest.permission.ACCESS_COARSE_LOCATION +import android.Manifest.permission.ACCESS_WIFI_STATE +import android.content.pm.PackageManager +import androidx.test.espresso.intent.rule.IntentsTestRule +import androidx.test.rule.GrantPermissionRule + +import com.isupatches.wisefysample.RANDO_PERMISSION_REQUEST_CODE +import com.isupatches.wisefysample.internal.base.AbstractEspressoTestClass +import com.isupatches.wisefysample.ui.main.MainActivity + +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +internal class SearchFragmentTest : AbstractEspressoTestClass() { + + @get:Rule + var activityTestRule = IntentsTestRule(MainActivity::class.java, false, false) + + @get:Rule + val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(ACCESS_COARSE_LOCATION) + + private lateinit var searchRobot: SearchRobot + + @Before override fun setUp() { + super.setUp() + searchRobot = SearchRobot(activityTestRule, wiseFy, searchStore, permissionUtil) + } + + @Test fun adaptiveUI() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withAccessPointInStore(false) + launchSearchScreen() + + // When + selectAccessPoint() + + // Then - Access Point + verifyAccessPointIsChecked() + verifyReturnFullListIsSetToNo() + + verifyFilterDuplicatesIsDisplayed() + setFilterDupesToNo() + verifyFilterDupesSetToNo() + setFilterDupesToYes() + verifyFilterDupesSetToYes() + + verifyTimeoutIsDisplayed() + + // And When + selectAccessPoints() + + // Then - Access Points + verifyAccessPointIsChecked() + verifyReturnFullListIsSetToYes() + + verifyFilterDuplicatesIsDisplayed() + setFilterDupesToNo() + verifyFilterDupesSetToNo() + setFilterDupesToYes() + verifyFilterDupesSetToYes() + + verifyTimeoutIsNotDisplayed() + + // And When + selectSSID() + + // Then - SSID + verifySSIDsChecked() + verifyReturnFullListIsSetToNo() + verifyFilterDuplicatesIsNotDisplayed() + verifyTimeoutIsDisplayed() + + // And When + selectSSIDs() + + // Then - SSIDS + verifySSIDsChecked() + verifyReturnFullListIsSetToYes() + verifyFilterDuplicatesIsNotDisplayed() + verifyTimeoutIsNotDisplayed() + + // And When + selectSavedNetwork() + + // Then - Saved Network + verifySavedNetworkIsChecked() + verifyReturnFullListIsSetToNo() + verifyFilterDuplicatesIsNotDisplayed() + verifyTimeoutIsNotDisplayed() + + // And When + selectSavedNetworks() + + // Then - Saved Networks + verifySavedNetworkIsChecked() + verifyReturnFullListIsSetToYes() + verifyFilterDuplicatesIsNotDisplayed() + verifyTimeoutIsNotDisplayed() + + // And When + selectAccessPoint() + + // Then Finally - Access Point + verifyAccessPointIsChecked() + verifyReturnFullListIsSetToNo() + verifyFilterDuplicatesIsDisplayed() + verifyTimeoutIsDisplayed() + } + } + + @Test fun loadsAccessPointFromStore_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withAccessPointInStore(false) + + // When + launchSearchScreen() + + // Then + verifySearchRegexIsPopulated() + verifyAccessPointIsChecked() + verifyReturnFullListIsSetToNo() + verifyFilterDupesSetToNo() + verifyTimeoutIsDisplayed() + } + } + + @Test fun loadsAccessPointFromStore_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withAccessPointInStore(true) + + // When + launchSearchScreen() + + // Then + verifySearchRegexIsPopulated() + verifyAccessPointIsChecked() + verifyReturnFullListIsSetToNo() + verifyFilterDupesSetToYes() + verifyTimeoutIsDisplayed() + } + } + + @Test fun loadsAccessPointsFromStore_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withAccessPointsInStore(false) + + // When + launchSearchScreen() + + // Then + verifySearchRegexIsPopulated() + verifyAccessPointIsChecked() + verifyReturnFullListIsSetToYes() + verifyFilterDupesSetToNo() + verifyTimeoutIsNotDisplayed() + } + } + + @Test fun loadsAccessPointsFromStore_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withAccessPointsInStore(true) + + // When + launchSearchScreen() + + // Then + verifySearchRegexIsPopulated() + verifyAccessPointIsChecked() + verifyReturnFullListIsSetToYes() + verifyFilterDupesSetToYes() + verifyTimeoutIsNotDisplayed() + } + } + + @Test fun loadsSSIDFromStore() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSSIDInStore() + + // When + launchSearchScreen() + + // Then + verifySearchRegexIsPopulated() + verifySSIDsChecked() + verifyReturnFullListIsSetToNo() + verifyFilterDuplicatesIsNotDisplayed() + verifyTimeoutIsDisplayed() + } + } + + @Test fun loadsSSIDSFromStore() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSSIDsInStore() + + // When + launchSearchScreen() + + // Then + verifySearchRegexIsPopulated() + verifySSIDsChecked() + verifyReturnFullListIsSetToYes() + verifyFilterDuplicatesIsNotDisplayed() + verifyTimeoutIsNotDisplayed() + } + } + + @Test fun loadsSavedNetworkFromStore() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSavedNetworkInStore() + + // When + launchSearchScreen() + + // Then + verifySearchRegexIsPopulated() + verifySavedNetworkIsChecked() + verifyReturnFullListIsSetToNo() + verifyFilterDuplicatesIsNotDisplayed() + verifyTimeoutIsNotDisplayed() + } + } + + @Test fun loadsSavedNetworksFromStore() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSavedNetworksInStore() + + // When + launchSearchScreen() + + // Then + verifySearchRegexIsPopulated() + verifySavedNetworkIsChecked() + verifyReturnFullListIsSetToYes() + verifyFilterDuplicatesIsNotDisplayed() + verifyTimeoutIsNotDisplayed() + } + } + + @Test fun searchForAccessPoint_permissionErrorDialog_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchSearchScreen() + searchForAccessPoint(true) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun searchForAccessPoint_permissionError_once_filterDuplicates_true() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoint(true) + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoint(true) + + // Then + verifySearchedForAccessPoint(true) + verifyAccessPointIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_permissionError_once_accessWifiState_filterDuplicates_true() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoint(true) + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermission(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoint(true) + + // Then + verifySearchedForAccessPoint(true) + verifyAccessPointIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_permissionError_once_accessCourseLocation_filterDuplicates_true() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoint(true) + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoint(true) + + // Then + verifySearchedForAccessPoint(true) + verifyAccessPointIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_permissionError_emptyList_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoint(true) + launchSearchScreen() + searchForAccessPoint(true) + + // When + permissionCallbackTriggeredWithEmptyArray( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifySearchedForAccessPoint(true) + } + } + + @Test fun searchForAccessPoint_permissionError_permissionDenied_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoint(true) + launchSearchScreen() + searchForAccessPoint(true) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifySearchedForAccessPoint(true) + } + } + + @Test fun searchForAccessPoint_success_afterPermissionGranted_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoint(true) + launchSearchScreen() + searchForAccessPoint(true) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifySearchedForAccessPoint(true, times = 2) + verifyAccessPointIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_success_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoint(true) + launchSearchScreen() + + // When + searchForAccessPoint(true) + + // Then + verifySearchedForAccessPoint(true) + verifyAccessPointIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_accessPointNotFound_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withAccessPointNotFound(true) + launchSearchScreen() + + // When + searchForAccessPoint(true) + + // Then + verifySearchedForAccessPoint(true) + verifyAccessPointNotFoundIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_wiseFyFailure_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withWiseFyFailureSearchingForAccessPoint(true) + launchSearchScreen() + + // When + searchForAccessPoint(true) + + // Then + verifyWiseFyFailureIsDisplayed() + verifySearchedForAccessPoint(true) + + // And + dismissErrorDialog() + } + } + + @Test fun searchForAccessPoint_permissionErrorDialog_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchSearchScreen() + searchForAccessPoint(false) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun searchForAccessPoint_permissionError_once_filterDuplicates_false() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoint(false) + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoint(false) + + // Then + verifySearchedForAccessPoint(false) + verifyAccessPointIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_permissionError_once_accessWifiState_filterDuplicates_false() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoint(false) + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermission(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoint(false) + + // Then + verifySearchedForAccessPoint(false) + verifyAccessPointIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_permissionError_once_accessCourseLocation_filterDuplicates_false() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoint(false) + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoint(false) + + // Then + verifySearchedForAccessPoint(false) + verifyAccessPointIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_permissionError_emptyList_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoint(false) + launchSearchScreen() + searchForAccessPoint(false) + + // When + permissionCallbackTriggeredWithEmptyArray( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifySearchedForAccessPoint(false) + } + } + + @Test fun searchForAccessPoint_permissionError_permissionDenied_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoint(false) + launchSearchScreen() + searchForAccessPoint(false) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifySearchedForAccessPoint(false) + } + } + + @Test fun searchForAccessPoint_success_afterPermissionGranted_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoint(false) + launchSearchScreen() + searchForAccessPoint(false) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifySearchedForAccessPoint(false, times = 2) + verifyAccessPointIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_success_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoint(false) + launchSearchScreen() + + // When + searchForAccessPoint(false) + + // Then + verifySearchedForAccessPoint(false) + verifyAccessPointIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_accessPointNotFound_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withAccessPointNotFound(false) + launchSearchScreen() + + // When + searchForAccessPoint(false) + + // Then + verifySearchedForAccessPoint(false) + verifyAccessPointNotFoundIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoint_wiseFyFailure_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withWiseFyFailureSearchingForAccessPoint(false) + launchSearchScreen() + + // When + searchForAccessPoint(false) + + // Then + verifyWiseFyFailureIsDisplayed() + verifySearchedForAccessPoint(false) + + // And + dismissErrorDialog() + } + } + + @Test fun searchForAccessPoints_permissionErrorDialog_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchSearchScreen() + searchForAccessPoints(true) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun searchForAccessPoints_permissionError_once_filterDuplicates_true() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoints(true) + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoints(true) + + // Then + verifySearchedForAccessPoints(true) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_permissionError_once_accessWifiState_filterDuplicates_true() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoints(true) + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermission(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoints(true) + + // Then + verifySearchedForAccessPoints(true) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_permissionError_once_accessCourseLocation_filterDuplicates_true() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoints(true) + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoints(true) + + // Then + verifySearchedForAccessPoints(true) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_permissionError_emptyList_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoints(true) + launchSearchScreen() + searchForAccessPoints(true) + + // When + permissionCallbackTriggeredWithEmptyArray( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifySearchedForAccessPoints(true) + } + } + + @Test fun searchForAccessPoints_permissionError_permissionDenied_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoints(true) + launchSearchScreen() + searchForAccessPoints(true) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifySearchedForAccessPoints(true) + } + } + + @Test fun searchForAccessPoints_success_afterPermissionGranted_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoints(true) + launchSearchScreen() + searchForAccessPoints(true) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifySearchedForAccessPoints(true, times = 2) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_success_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoints(true) + launchSearchScreen() + + // When + searchForAccessPoints(true) + + // Then + verifySearchedForAccessPoints(true) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_noAccessPointsFound_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withNoAccessPointsFound(true) + launchSearchScreen() + + // When + searchForAccessPoints(true) + + // Then + verifySearchedForAccessPoints(true) + verifyNoAccessPointsFoundIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_wiseFyFailure_filterDuplicates_true() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withWiseFyFailureSearchingForAccessPoints(true) + launchSearchScreen() + + // When + searchForAccessPoints(true) + + // Then + verifyWiseFyFailureIsDisplayed() + verifySearchedForAccessPoints(true) + + // And + dismissErrorDialog() + } + } + + @Test fun searchForAccessPoints_permissionErrorDialog_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchSearchScreen() + searchForAccessPoints(false) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun searchForAccessPoints_permissionError_once_filterDuplicates_false() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoints(false) + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoints(false) + + // Then + verifySearchedForAccessPoints(false) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_permissionError_once_accessWifiState_filterDuplicates_false() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoints(false) + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermission(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoints(false) + + // Then + verifySearchedForAccessPoints(false) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_permissionError_once_accessCourseLocation_filterDuplicates_false() { + with(searchRobot) { + // Given + withSuccessSearchingForAccessPoints(false) + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForAccessPoints(false) + + // Then + verifySearchedForAccessPoints(false) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_permissionError_emptyList_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoints(false) + launchSearchScreen() + searchForAccessPoints(false) + + // When + permissionCallbackTriggeredWithEmptyArray( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifySearchedForAccessPoints(false) + } + } + + @Test fun searchForAccessPoints_permissionError_permissionDenied_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoints(false) + launchSearchScreen() + searchForAccessPoints(false) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifySearchedForAccessPoints(false) + } + } + + @Test fun searchForAccessPoints_success_afterPermissionGranted_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoints(false) + launchSearchScreen() + searchForAccessPoints(false) + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifySearchedForAccessPoints(false, times = 2) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_success_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForAccessPoints(false) + launchSearchScreen() + + // When + searchForAccessPoints(false) + + // Then + verifySearchedForAccessPoints(false) + verifyAccessPointsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_noAccessPointsFound_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withNoAccessPointsFound(false) + launchSearchScreen() + + // When + searchForAccessPoints(false) + + // Then + verifySearchedForAccessPoints(false) + verifyNoAccessPointsFoundIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForAccessPoints_wiseFyFailure_filterDuplicates_false() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withWiseFyFailureSearchingForAccessPoints(false) + launchSearchScreen() + + // When + searchForAccessPoints(false) + + // Then + verifyWiseFyFailureIsDisplayed() + verifySearchedForAccessPoints(false) + + // And + dismissErrorDialog() + } + } + + @Test fun searchForSSID_permissionErrorDialog() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchSearchScreen() + searchForSSID() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SSID_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun searchForSSID_permissionError_once() { + with(searchRobot) { + // Given + withSuccessSearchingForSSID() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForSSID() + + // Then + verifySearchedForSSID() + verifySSIDIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSID_permissionError_once_accessWifiState() { + with(searchRobot) { + // Given + withSuccessSearchingForSSID() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermission(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForSSID() + + // Then + verifySearchedForSSID() + verifySSIDIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSID_permissionError_once_accessCoarseLocation() { + with(searchRobot) { + // Given + withSuccessSearchingForSSID() + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForSSID() + + // Then + verifySearchedForSSID() + verifySSIDIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSID_permissionError_emptyList() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForSSID() + launchSearchScreen() + searchForSSID() + + // When + permissionCallbackTriggeredWithEmptyArray( + SearchFragment.WISEFY_SEARCH_FOR_SSID_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifySearchedForSSID() + } + } + + @Test fun searchForSSID_permissionError_permissionDenied() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForSSID() + launchSearchScreen() + searchForSSID() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SSID_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifySearchedForSSID() + } + } + + @Test fun searchForSSID_success_afterPermissionGranted() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForSSID() + launchSearchScreen() + searchForSSID() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SSID_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifySearchedForSSID(times = 2) + verifySSIDIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSID_success() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForSSID() + launchSearchScreen() + + // When + searchForSSID() + + // Then + verifySearchedForSSID() + verifySSIDIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSID_SSIDNotFound() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSSIDNotFound() + launchSearchScreen() + + // When + searchForSSID() + + // Then + verifySearchedForSSID() + verifySSIDNotFoundIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSID_wiseFyFailure() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withWiseFyFailureSearchingForSSID() + launchSearchScreen() + + // When + searchForSSID() + + // Then + verifyWiseFyFailureIsDisplayed() + verifySearchedForSSID() + + // And + dismissErrorDialog() + } + } + + @Test fun searchForSSIDs_permissionErrorDialog() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + launchSearchScreen() + searchForSSIDs() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun searchForSSIDs_permissionError_once() { + with(searchRobot) { + // Given + withSuccessSearchingForSSIDs() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForSSIDs() + + // Then + verifySearchedForSSIDs() + verifySSIDsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSIDs_permissionError_once_accessWifiState() { + with(searchRobot) { + // Given + withSuccessSearchingForSSIDs() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + withPermission(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForSSIDs() + + // Then + verifySearchedForSSIDs() + verifySSIDsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSIDs_permissionError_once_accessCoarseLocation() { + with(searchRobot) { + // Given + withSuccessSearchingForSSIDs() + withPermission(ACCESS_WIFI_STATE) + withPermissionDeniedOnce(ACCESS_COARSE_LOCATION) + launchSearchScreen() + + // When + searchForSSIDs() + + // Then + verifySearchedForSSIDs() + verifySSIDsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSIDs_permissionError_emptyList() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForSSIDs() + launchSearchScreen() + searchForSSIDs() + + // When + permissionCallbackTriggeredWithEmptyArray( + SearchFragment.WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifySearchedForSSIDs() + } + } + + @Test fun searchForSSIDs_permissionError_permissionDenied() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForSSIDs() + launchSearchScreen() + searchForSSIDs() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifySearchedForSSIDs() + } + } + + @Test fun searchForSSIDs_success_afterPermissionGranted() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForSSIDs() + launchSearchScreen() + searchForSSIDs() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifySearchedForSSIDs(times = 2) + verifySSIDsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSIDs_success() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withSuccessSearchingForSSIDs() + launchSearchScreen() + + // When + searchForSSIDs() + + // Then + verifySearchedForSSIDs() + verifySSIDsAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSIDs_noSSIDsFound() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withNoSSIDsFound() + launchSearchScreen() + + // When + searchForSSIDs() + + // Then + verifySearchedForSSIDs() + verifyNoSSIDsFoundIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSSIDs_wiseFyFailure() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION) + withWiseFyFailureSearchingForSSIDs() + launchSearchScreen() + + // When + searchForSSIDs() + + // Then + verifyWiseFyFailureIsDisplayed() + verifySearchedForSSIDs() + + // And + dismissErrorDialog() + } + } + + @Test fun searchForSavedNetwork_permissionErrorDialog() { + with(searchRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + launchSearchScreen() + searchForSavedNetwork() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SAVED_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun searchForSavedNetwork_permissionError_once() { + with(searchRobot) { + // Given + withSuccessSearchingForSavedNetwork() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + launchSearchScreen() + + // When + searchForSavedNetwork() + + // Then + verifySearchedForSavedNetwork() + verifySavedNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSavedNetwork_permissionError_emptyList() { + with(searchRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessSearchingForSavedNetwork() + launchSearchScreen() + searchForSavedNetwork() + + // When + permissionCallbackTriggeredWithEmptyArray( + SearchFragment.WISEFY_SEARCH_FOR_SAVED_NETWORK_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifySearchedForSavedNetwork() + } + } + + @Test fun searchForSavedNetwork_permissionError_permissionDenied() { + with(searchRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessSearchingForSavedNetwork() + launchSearchScreen() + searchForSavedNetwork() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SAVED_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifySearchedForSavedNetwork() + } + } + + @Test fun searchForSavedNetwork_success_afterPermissionGranted() { + with(searchRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessSearchingForSavedNetwork() + launchSearchScreen() + searchForSavedNetwork() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SAVED_NETWORK_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifySearchedForSavedNetwork(times = 2) + verifySavedNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSavedNetwork_success() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE) + withSuccessSearchingForSavedNetwork() + launchSearchScreen() + + // When + searchForSavedNetwork() + + // Then + verifySearchedForSavedNetwork() + verifySavedNetworkIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSavedNetwork_savedNetworkNotFound() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE) + withSavedNetworkNotFound() + launchSearchScreen() + + // When + searchForSavedNetwork() + + // Then + verifySearchedForSavedNetwork() + verifySavedNetworkNotFoundIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSavedNetwork_wiseFyFailure() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE) + withWiseFyFailureSearchingForSavedNetwork() + launchSearchScreen() + + // When + searchForSavedNetwork() + + // Then + verifyWiseFyFailureIsDisplayed() + verifySearchedForSavedNetwork() + + // And + dismissErrorDialog() + } + } + + @Test fun searchForSavedNetworks_permissionErrorDialog() { + with(searchRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + launchSearchScreen() + searchForSavedNetworks() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SAVED_NETWORKS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + } + } + + @Test fun searchForSavedNetworks_permissionError_once() { + with(searchRobot) { + // Given + withSuccessSearchingForSavedNetworks() + withPermissionDeniedOnce(ACCESS_WIFI_STATE) + launchSearchScreen() + + // When + searchForSavedNetworks() + + // Then + verifySearchedForSavedNetworks() + verifySavedNetworksAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSavedNetworks_permissionError_emptyList() { + with(searchRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessSearchingForSavedNetworks() + launchSearchScreen() + searchForSavedNetworks() + + // When + permissionCallbackTriggeredWithEmptyArray( + SearchFragment.WISEFY_SEARCH_FOR_SAVED_NETWORKS_REQUEST_CODE + ) + + // Then + dismissErrorDialog() + verifySearchedForSavedNetworks() + } + } + + @Test fun searchForSavedNetworks_permissionError_permissionDenied() { + with(searchRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessSearchingForSavedNetworks() + launchSearchScreen() + searchForSavedNetworks() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SAVED_NETWORKS_REQUEST_CODE, + PackageManager.PERMISSION_DENIED + ) + + // Then + dismissErrorDialog() + verifySearchedForSavedNetworks() + } + } + + @Test fun searchForSavedNetworks_success_afterPermissionGranted() { + with(searchRobot) { + // Given + withPermission(ACCESS_WIFI_STATE) + withSuccessSearchingForSavedNetworks() + launchSearchScreen() + searchForSavedNetworks() + + // When + permissionCallbackTriggered( + SearchFragment.WISEFY_SEARCH_FOR_SAVED_NETWORKS_REQUEST_CODE, + PackageManager.PERMISSION_GRANTED + ) + + // Then + verifySearchedForSavedNetworks(times = 2) + verifySavedNetworksAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSavedNetworks_success() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE) + withSuccessSearchingForSavedNetworks() + launchSearchScreen() + + // When + searchForSavedNetworks() + + // Then + verifySearchedForSavedNetworks() + verifySavedNetworksAreDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSavedNetworks_noSavedNetworksFound() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE) + withNotSavedNetworksFound() + launchSearchScreen() + + // When + searchForSavedNetworks() + + // Then + verifySearchedForSavedNetworks() + verifyNoSavedNetworksFoundIsDisplayed() + dismissResultsDialog() + } + } + + @Test fun searchForSavedNetworks_wiseFyFailure() { + with(searchRobot) { + // Given + withPermissions(ACCESS_WIFI_STATE) + withWiseFyFailureSearchingForSavedNetworks() + launchSearchScreen() + + // When + searchForSavedNetworks() + + // Then + verifyWiseFyFailureIsDisplayed() + verifySearchedForSavedNetworks() + + // And + dismissErrorDialog() + } + } + + @Test fun ridiculousPermissionRequested() { + with(searchRobot) { + // Given + launchSearchScreen() + + // When + permissionCallbackTriggeredWithEmptyArray(RANDO_PERMISSION_REQUEST_CODE) + + // Then + verifyPermissionErrorShown() + dismissErrorDialog() + } + } +} diff --git a/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/search/SearchRobot.kt b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/search/SearchRobot.kt new file mode 100644 index 00000000..dd6600c6 --- /dev/null +++ b/wisefysample/src/androidTest/java/com/isupatches/wisefysample/ui/search/SearchRobot.kt @@ -0,0 +1,562 @@ +package com.isupatches.wisefysample.ui.search + +import android.content.Intent +import android.net.wifi.ScanResult +import android.net.wifi.WifiConfiguration +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.scrollTo +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.rule.ActivityTestRule + +import com.isupatches.wisefy.WiseFyPublicApi +import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks +import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks +import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks +import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworkCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworksCallbacks +import com.isupatches.wisefy.constants.MISSING_PARAMETER +import com.isupatches.wisefysample.R +import com.isupatches.wisefysample.TEST_SSID_1 +import com.isupatches.wisefysample.TEST_TIMEOUT +import com.isupatches.wisefysample.internal.base.BaseRobot +import com.isupatches.wisefysample.internal.espresso.checkIsChecked +import com.isupatches.wisefysample.internal.espresso.checkIsDisplayed +import com.isupatches.wisefysample.internal.espresso.checkIsInvisible +import com.isupatches.wisefysample.internal.espresso.checkIsNotChecked +import com.isupatches.wisefysample.internal.espresso.performClick +import com.isupatches.wisefysample.internal.espresso.performScrollToAndCheckIsDisplayed +import com.isupatches.wisefysample.internal.espresso.performScrollToAndClick +import com.isupatches.wisefysample.internal.espresso.performScrollToAndReplaceText +import com.isupatches.wisefysample.internal.espresso.setProgress +import com.isupatches.wisefysample.internal.models.SearchType +import com.isupatches.wisefysample.internal.preferences.SearchStore +import com.isupatches.wisefysample.internal.util.PermissionUtil +import com.isupatches.wisefysample.ui.main.MainActivity + +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.doAnswer +import com.nhaarman.mockitokotlin2.eq +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.timeout +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.whenever +import org.hamcrest.CoreMatchers.allOf +import org.hamcrest.CoreMatchers.containsString + +internal class SearchRobot( + private val activityTestRule: ActivityTestRule, + private val wiseFyPublicApi: WiseFyPublicApi, + private val searchStore: SearchStore, + permissionUtil: PermissionUtil +) : BaseRobot(activityTestRule, permissionUtil) { + + companion object { + private val SAVED_NETWORK = mock() + private val ACCESS_POINT = mock() + } + + /* + * Preconditions + */ + + fun withSuccessSearchingForAccessPoint(filterDuplicates: Boolean) { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[3] as SearchForAccessPointCallbacks + callback.accessPointFound(ACCESS_POINT) + }.whenever(wiseFyPublicApi).searchForAccessPoint( + eq(TEST_SSID_1), + eq(TEST_TIMEOUT * 1000), + eq(filterDuplicates), + any() + ) + } + + fun withAccessPointNotFound(filterDuplicates: Boolean) { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[3] as SearchForAccessPointCallbacks + callback.accessPointNotFound() + }.whenever(wiseFyPublicApi).searchForAccessPoint( + eq(TEST_SSID_1), + eq(TEST_TIMEOUT * 1000), + eq(filterDuplicates), + any() + ) + } + + fun withWiseFyFailureSearchingForAccessPoint(filterDuplicates: Boolean) { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[3] as SearchForAccessPointCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).searchForAccessPoint( + eq(TEST_SSID_1), + eq(TEST_TIMEOUT * 1000), + eq(filterDuplicates), + any() + ) + } + + fun withSuccessSearchingForAccessPoints(filterDuplicates: Boolean) { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as SearchForAccessPointsCallbacks + callback.foundAccessPoints(listOf(ACCESS_POINT)) + }.whenever(wiseFyPublicApi).searchForAccessPoints( + eq(TEST_SSID_1), + eq(filterDuplicates), + any() + ) + } + + fun withNoAccessPointsFound(filterDuplicates: Boolean) { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as SearchForAccessPointsCallbacks + callback.noAccessPointsFound() + }.whenever(wiseFyPublicApi).searchForAccessPoints(eq(TEST_SSID_1), eq(filterDuplicates), any()) + } + + fun withWiseFyFailureSearchingForAccessPoints(filterDuplicates: Boolean) { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as SearchForAccessPointsCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).searchForAccessPoints(eq(TEST_SSID_1), eq(filterDuplicates), any()) + } + + fun withSuccessSearchingForSavedNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as SearchForSavedNetworkCallbacks + callback.retrievedSavedNetwork(SAVED_NETWORK) + }.whenever(wiseFyPublicApi).searchForSavedNetwork(eq(TEST_SSID_1), any()) + } + + fun withSavedNetworkNotFound() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as SearchForSavedNetworkCallbacks + callback.savedNetworkNotFound() + }.whenever(wiseFyPublicApi).searchForSavedNetwork(eq(TEST_SSID_1), any()) + } + + fun withWiseFyFailureSearchingForSavedNetwork() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as SearchForSavedNetworkCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).searchForSavedNetwork(eq(TEST_SSID_1), any()) + } + + fun withSuccessSearchingForSavedNetworks() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as SearchForSavedNetworksCallbacks + callback.retrievedSavedNetworks(listOf(SAVED_NETWORK)) + }.whenever(wiseFyPublicApi).searchForSavedNetworks(eq(TEST_SSID_1), any()) + } + + fun withNotSavedNetworksFound() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as SearchForSavedNetworksCallbacks + callback.noSavedNetworksFound() + }.whenever(wiseFyPublicApi).searchForSavedNetworks(eq(TEST_SSID_1), any()) + } + + fun withWiseFyFailureSearchingForSavedNetworks() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as SearchForSavedNetworksCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).searchForSavedNetworks(eq(TEST_SSID_1), any()) + } + + fun withSuccessSearchingForSSID() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as SearchForSSIDCallbacks + callback.ssidFound(TEST_SSID_1) + }.whenever(wiseFyPublicApi).searchForSSID( + eq(TEST_SSID_1), + eq(TEST_TIMEOUT * 1000), + any() + ) + } + + fun withSSIDNotFound() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as SearchForSSIDCallbacks + callback.ssidNotFound() + }.whenever(wiseFyPublicApi).searchForSSID( + eq(TEST_SSID_1), + eq(TEST_TIMEOUT * 1000), + any() + ) + } + + fun withWiseFyFailureSearchingForSSID() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[2] as SearchForSSIDCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).searchForSSID( + eq(TEST_SSID_1), + eq(TEST_TIMEOUT * 1000), + any() + ) + } + + fun withSuccessSearchingForSSIDs() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as SearchForSSIDsCallbacks + callback.retrievedSSIDs(listOf(TEST_SSID_1)) + }.whenever(wiseFyPublicApi).searchForSSIDs(eq(TEST_SSID_1), any()) + } + + fun withNoSSIDsFound() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as SearchForSSIDsCallbacks + callback.noSSIDsFound() + }.whenever(wiseFyPublicApi).searchForSSIDs(eq(TEST_SSID_1), any()) + } + + fun withWiseFyFailureSearchingForSSIDs() { + doAnswer { invocationOnMock -> + val callback = invocationOnMock.arguments[1] as SearchForSSIDsCallbacks + callback.wisefyFailure(MISSING_PARAMETER) + }.whenever(wiseFyPublicApi).searchForSSIDs(eq(TEST_SSID_1), any()) + } + + fun withAccessPointInStore(filterDuplicates: Boolean) { + searchStore.setLastUsedRegex(TEST_SSID_1) + searchStore.setSearchType(SearchType.ACCESS_POINT) + searchStore.setFilterDuplicates(filterDuplicates) + searchStore.setReturnFullList(false) + searchStore.setTimeout(TEST_TIMEOUT) + } + + fun withAccessPointsInStore(filterDuplicates: Boolean) { + searchStore.setLastUsedRegex(TEST_SSID_1) + searchStore.setSearchType(SearchType.ACCESS_POINT) + searchStore.setFilterDuplicates(filterDuplicates) + searchStore.setReturnFullList(true) + searchStore.setTimeout(TEST_TIMEOUT) + } + + fun withSSIDInStore() { + searchStore.setLastUsedRegex(TEST_SSID_1) + searchStore.setSearchType(SearchType.SSID) + searchStore.setReturnFullList(false) + searchStore.setTimeout(TEST_TIMEOUT) + } + + fun withSSIDsInStore() { + searchStore.setLastUsedRegex(TEST_SSID_1) + searchStore.setSearchType(SearchType.SSID) + searchStore.setReturnFullList(true) + searchStore.setTimeout(TEST_TIMEOUT) + } + + fun withSavedNetworkInStore() { + searchStore.setLastUsedRegex(TEST_SSID_1) + searchStore.setSearchType(SearchType.SAVED_NETWORK) + searchStore.setReturnFullList(false) + searchStore.setTimeout(TEST_TIMEOUT) + } + + fun withSavedNetworksInStore() { + searchStore.setLastUsedRegex(TEST_SSID_1) + searchStore.setSearchType(SearchType.SAVED_NETWORK) + searchStore.setReturnFullList(true) + searchStore.setTimeout(TEST_TIMEOUT) + } + + /* + * Actions + */ + + fun launchSearchScreen() { + activityTestRule.launchActivity(Intent()) + onView(withId(R.id.menu_search)).performClick() + } + + fun setFilterDupesToNo() { + onView(withId(R.id.noFilterDupesRdb)).performScrollToAndClick() + } + + fun setFilterDupesToYes() { + onView(withId(R.id.yesFilterDupesRdb)).performScrollToAndClick() + } + + fun searchForAccessPoint(filterDuplicates: Boolean) { + fillOutFormForAccessPoint() + onView(withId(R.id.noFullListRdb)).performScrollToAndClick() + if (filterDuplicates) { + onView(withId(R.id.yesFilterDupesRdb)).performScrollToAndClick() + } else { + onView(withId(R.id.noFilterDupesRdb)).performScrollToAndClick() + } + setTimeoutSeek() + clickSearchButton() + } + + fun searchForAccessPoints(filterDuplicates: Boolean) { + fillOutFormForAccessPoint() + onView(withId(R.id.yesFullListRdb)).performScrollToAndClick() + if (filterDuplicates) { + onView(withId(R.id.yesFilterDupesRdb)).performScrollToAndClick() + } else { + onView(withId(R.id.noFilterDupesRdb)).performScrollToAndClick() + } + clickSearchButton() + } + + fun searchForSavedNetwork() { + fillOutFormForForSavedNetwork() + onView(withId(R.id.noFullListRdb)).performScrollToAndClick() + clickSearchButton() + } + + fun searchForSavedNetworks() { + fillOutFormForForSavedNetwork() + onView(withId(R.id.yesFullListRdb)).performScrollToAndClick() + clickSearchButton() + } + + fun searchForSSID() { + fillOutFormFormForSSID() + onView(withId(R.id.noFullListRdb)).performScrollToAndClick() + setTimeoutSeek() + clickSearchButton() + } + + fun searchForSSIDs() { + fillOutFormFormForSSID() + onView(withId(R.id.yesFullListRdb)).performScrollToAndClick() + clickSearchButton() + } + + fun selectAccessPoint() { + fillOutFormForAccessPoint() + onView(withId(R.id.noFullListRdb)).performScrollToAndClick() + } + + fun selectAccessPoints() { + fillOutFormForAccessPoint() + onView(withId(R.id.yesFullListRdb)).performScrollToAndClick() + } + + fun selectSSID() { + fillOutFormFormForSSID() + onView(withId(R.id.noFullListRdb)).performScrollToAndClick() + } + + fun selectSSIDs() { + fillOutFormFormForSSID() + onView(withId(R.id.yesFullListRdb)).performScrollToAndClick() + } + + fun selectSavedNetwork() { + fillOutFormForForSavedNetwork() + onView(withId(R.id.noFullListRdb)).performScrollToAndClick() + } + + fun selectSavedNetworks() { + fillOutFormForForSavedNetwork() + onView(withId(R.id.yesFullListRdb)).performScrollToAndClick() + } + + /* + * View Helpers + */ + + private fun clickSearchButton() { + onView(withId(R.id.searchBtn)).performScrollToAndClick() + } + + private fun fillOutFormForAccessPoint() { + onView(withId(R.id.accessPointRdb)).performScrollToAndClick() + setSearchRegex() + } + + private fun fillOutFormForForSavedNetwork() { + onView(withId(R.id.savedNetworkRdb)).performScrollToAndClick() + setSearchRegex() + } + + private fun fillOutFormFormForSSID() { + onView(withId(R.id.ssidRdb)).performScrollToAndClick() + setSearchRegex() + } + + private fun setSearchRegex() { + onView(withId(R.id.searchRegexEdt)).performScrollToAndReplaceText(TEST_SSID_1) + } + + private fun setTimeoutSeek() { + onView(withId(R.id.timeoutSeek)).perform(scrollTo()).perform(setProgress(TEST_TIMEOUT)) + } + + /* + * Permission Helpers + */ + + fun permissionCallbackTriggered(requestCode: Int, permissionResult: Int) { + val activity = activityTestRule.activity + val fragment: SearchFragment? = activity + .supportFragmentManager + .findFragmentByTag( + SearchFragment.TAG + ) as? SearchFragment + + activity.runOnUiThread { + fragment?.onRequestPermissionsResult( + requestCode, + emptyArray(), + intArrayOf(permissionResult) + ) + } + } + + fun permissionCallbackTriggeredWithEmptyArray(requestCode: Int) { + val activity = activityTestRule.activity + val fragment: SearchFragment? = activity + .supportFragmentManager + .findFragmentByTag( + SearchFragment.TAG + ) as? SearchFragment + + activity.runOnUiThread { + fragment?.onRequestPermissionsResult( + requestCode, + emptyArray(), + intArrayOf() + ) + } + } + + /* + * Verification + */ + + fun verifyAccessPointIsDisplayed() { + onView(withText(containsString("Access point"))).checkIsDisplayed() + } + + fun verifyAccessPointNotFoundIsDisplayed() { + onView(withText(R.string.access_point_not_found)).checkIsDisplayed() + } + + fun verifySavedNetworkIsDisplayed() { + onView(withText(containsString("Saved network"))).checkIsDisplayed() + } + + fun verifySavedNetworkNotFoundIsDisplayed() { + onView(withText(R.string.saved_network_not_found)).checkIsDisplayed() + } + + fun verifySSIDIsDisplayed() { + onView(withText(containsString("SSID"))).checkIsDisplayed() + } + + fun verifySSIDNotFoundIsDisplayed() { + onView(withText(R.string.ssid_not_found)).checkIsDisplayed() + } + + fun verifySSIDsAreDisplayed() { + onView(withText(containsString("SSIDs"))).checkIsDisplayed() + } + + fun verifyNoSSIDsFoundIsDisplayed() { + onView(withText(R.string.no_ssids_found)).checkIsDisplayed() + } + + fun verifySearchedForAccessPoint(filterDuplicates: Boolean, times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).searchForAccessPoint( + eq(TEST_SSID_1), + eq(TEST_TIMEOUT * 1000), + eq(filterDuplicates), + any() + ) + } + + fun verifySearchedForAccessPoints(filterDuplicates: Boolean, times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).searchForAccessPoints( + eq(TEST_SSID_1), + eq(filterDuplicates), + any() + ) + } + + fun verifySearchedForSavedNetwork(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).searchForSavedNetwork( + eq(TEST_SSID_1), + any() + ) + } + + fun verifySearchedForSavedNetworks(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).searchForSavedNetworks( + eq(TEST_SSID_1), + any() + ) + } + + fun verifySearchedForSSID(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).searchForSSID( + eq(TEST_SSID_1), + eq(TEST_TIMEOUT * 1000), + any() + ) + } + + fun verifySearchedForSSIDs(times: Int = 1) { + verify(wiseFyPublicApi, timeout(3000).times(times)).searchForSSIDs( + eq(TEST_SSID_1), + any() + ) + } + + fun verifySearchRegexIsPopulated() { + onView(allOf(withId(R.id.searchRegexEdt), withText(TEST_SSID_1))).performScrollToAndCheckIsDisplayed() + } + + fun verifyAccessPointIsChecked() { + onView(withId(R.id.accessPointRdb)).checkIsChecked() + } + + fun verifySSIDsChecked() { + onView(withId(R.id.ssidRdb)).checkIsChecked() + } + + fun verifySavedNetworkIsChecked() { + onView(withId(R.id.savedNetworkRdb)).checkIsChecked() + } + + fun verifyFilterDupesSetToYes() { + onView(withId(R.id.yesFilterDupesRdb)).checkIsChecked() + onView((withId(R.id.noFilterDupesRdb))).checkIsNotChecked() + } + + fun verifyFilterDupesSetToNo() { + onView(withId(R.id.noFilterDupesRdb)).checkIsChecked() + onView((withId(R.id.yesFilterDupesRdb))).checkIsNotChecked() + } + + fun verifyReturnFullListIsSetToYes() { + onView(withId(R.id.yesFullListRdb)).checkIsChecked() + onView((withId(R.id.noFullListRdb))).checkIsNotChecked() + } + + fun verifyReturnFullListIsSetToNo() { + onView(withId(R.id.noFullListRdb)).checkIsChecked() + onView((withId(R.id.yesFullListRdb))).checkIsNotChecked() + } + + fun verifyTimeoutIsDisplayed() { + onView(withId(R.id.timeoutSeek)).performScrollToAndCheckIsDisplayed() + } + + fun verifyTimeoutIsNotDisplayed() { + onView(withId(R.id.timeoutSeek)).checkIsInvisible() + } + + fun verifyFilterDuplicatesIsDisplayed() { + onView(withId(R.id.filterDupesRdg)).performScrollToAndCheckIsDisplayed() + } + + fun verifyFilterDuplicatesIsNotDisplayed() { + onView(withId(R.id.filterDupesRdg)).checkIsInvisible() + } +} diff --git a/wisefysample/src/commonTest/java/com/isupatches/wisefysample/TestConstants.kt b/wisefysample/src/commonTest/java/com/isupatches/wisefysample/TestConstants.kt new file mode 100644 index 00000000..e1973a69 --- /dev/null +++ b/wisefysample/src/commonTest/java/com/isupatches/wisefysample/TestConstants.kt @@ -0,0 +1,12 @@ +package com.isupatches.wisefysample + +internal const val TEST_SSID_1 = "Test SSID" +internal const val TEST_PASSWORD_1 = "passWORD1!" + +internal const val TEST_TIMEOUT = 1 + +internal const val BAD_WIFI_MANAGER_RETURN = -1 + +internal const val TEST_IP = "192.168.0.1" + +internal const val RANDO_PERMISSION_REQUEST_CODE = -9999 diff --git a/wisefysample/src/commonTest/java/com/isupatches/wisefysample/TestRxSchedulersProvider.kt b/wisefysample/src/commonTest/java/com/isupatches/wisefysample/TestRxSchedulersProvider.kt new file mode 100644 index 00000000..0675b5c4 --- /dev/null +++ b/wisefysample/src/commonTest/java/com/isupatches/wisefysample/TestRxSchedulersProvider.kt @@ -0,0 +1,10 @@ +package com.isupatches.wisefysample + +import com.isupatches.wisefysample.internal.util.RxSchedulersProvider +import io.reactivex.Scheduler +import io.reactivex.schedulers.Schedulers + +class TestRxSchedulersProvider(mainThread: Scheduler = Schedulers.trampoline()) : RxSchedulersProvider() { + override val main: Scheduler = mainThread + override val io: Scheduler = Schedulers.trampoline() +} diff --git a/wisefysample/src/debug/AndroidManifest.xml b/wisefysample/src/debug/AndroidManifest.xml new file mode 100644 index 00000000..f3245d4e --- /dev/null +++ b/wisefysample/src/debug/AndroidManifest.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file diff --git a/wisefysample/src/debug/java/com/isupatches/wisefysample/DebugMainApplication.kt b/wisefysample/src/debug/java/com/isupatches/wisefysample/DebugMainApplication.kt new file mode 100644 index 00000000..fbf18130 --- /dev/null +++ b/wisefysample/src/debug/java/com/isupatches/wisefysample/DebugMainApplication.kt @@ -0,0 +1,9 @@ +package com.isupatches.wisefysample + +internal open class DebugMainApplication : MainApplication() { + + fun setTestComponent(component: MainApplicationComponent) { + mainApplicationComponent = component + mainApplicationComponent.inject(this) + } +} diff --git a/wisefysample/src/main/AndroidManifest.xml b/wisefysample/src/main/AndroidManifest.xml index 824c1ab2..d8372b7b 100644 --- a/wisefysample/src/main/AndroidManifest.xml +++ b/wisefysample/src/main/AndroidManifest.xml @@ -4,16 +4,16 @@ xmlns:tools="http://schemas.android.com/tools" package="com.isupatches.wisefysample"> + + - - - + diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/MainApplication.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/MainApplication.kt index bae2a977..49e8d942 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/MainApplication.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/MainApplication.kt @@ -1,6 +1,20 @@ +/* + * Copyright 2019 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.wisefysample -import android.annotation.SuppressLint import android.app.Activity import android.app.Application import android.content.Context @@ -9,6 +23,7 @@ import androidx.fragment.app.Fragment import com.isupatches.wisefysample.internal.di.PermissionsModule import com.isupatches.wisefysample.internal.di.PreferencesModule import com.isupatches.wisefysample.internal.di.ScreenBindingsModule +import com.isupatches.wisefysample.internal.util.RxSchedulersProvider import dagger.BindsInstance import dagger.Component @@ -20,7 +35,7 @@ import dagger.android.support.HasSupportFragmentInjector import javax.inject.Inject import javax.inject.Singleton -@SuppressLint("Registered") +@Suppress("Registered", "UndocumentedPublicClass", "UndocumentedPublicFunction") internal open class MainApplication : Application(), HasActivityInjector, HasSupportFragmentInjector { override fun onCreate() { @@ -31,6 +46,7 @@ internal open class MainApplication : Application(), HasActivityInjector, HasSup private fun initializeDependencyInjection() { mainApplicationComponent = DaggerMainApplication_MainApplicationComponent.builder() .application(this) + .rxSchedulersProvider(RxSchedulersProvider()) .build() mainApplicationComponent.inject(this) } @@ -41,7 +57,7 @@ internal open class MainApplication : Application(), HasActivityInjector, HasSup @Inject lateinit var supportFragmentInject: DispatchingAndroidInjector override fun supportFragmentInjector() = supportFragmentInject - private lateinit var mainApplicationComponent: MainApplicationComponent + protected lateinit var mainApplicationComponent: MainApplicationComponent @Singleton @Component(modules = [ @@ -50,7 +66,7 @@ internal open class MainApplication : Application(), HasActivityInjector, HasSup PermissionsModule::class, PreferencesModule::class ]) - interface MainApplicationComponent { + internal interface MainApplicationComponent { fun inject(mainApplication: MainApplication) @@ -58,6 +74,7 @@ internal open class MainApplication : Application(), HasActivityInjector, HasSup fun build(): MainApplicationComponent @BindsInstance fun application(application: Context): Builder + @BindsInstance fun rxSchedulersProvider(prov: RxSchedulersProvider): Builder } } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseActivity.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseActivity.kt index 3d54cca2..4c62731b 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseActivity.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseActivity.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.base import android.os.Bundle diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseDialogFragment.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseDialogFragment.kt new file mode 100644 index 00000000..8ae32f5b --- /dev/null +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseDialogFragment.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2019 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.wisefysample.internal.base + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.annotation.LayoutRes +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager + +internal abstract class BaseDialogFragment : DialogFragment() { + + @get:LayoutRes abstract val layoutRes: Int + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(layoutRes, container, false) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setStyle(STYLE_NO_TITLE, 0) + } + + fun showNoDuplicates(manager: FragmentManager, tag: String) { + if (manager.findFragmentByTag(tag) != null) return + show(manager, tag) + } +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseFragment.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseFragment.kt index 47fddc47..7cbad8c9 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseFragment.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseFragment.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.base import android.content.Context @@ -6,12 +21,14 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.annotation.LayoutRes +import androidx.annotation.StringRes import androidx.fragment.app.Fragment -import com.isupatches.wisefy.WiseFy import com.isupatches.wisefy.constants.WiseFyCode +import com.isupatches.wisefysample.R import com.isupatches.wisefysample.internal.util.PermissionUtil -import com.isupatches.wisefysample.internal.util.displayShortToast +import com.isupatches.wisefysample.ui.dialogs.FullScreenNoticeDialogFragment +import com.isupatches.wisefysample.ui.dialogs.NoticeDialogFragment import dagger.android.support.AndroidSupportInjection @@ -21,40 +38,88 @@ internal abstract class BaseFragment : Fragment() { @get:LayoutRes abstract val layoutRes: Int - protected lateinit var wiseFy: WiseFy @Inject lateinit var permissionUtil: PermissionUtil + private fun isActivityInvalid(): Boolean = activity == null || activity!!.isFinishing + override fun onAttach(context: Context) { AndroidSupportInjection.inject(this) super.onAttach(context) } - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - wiseFy = WiseFy.Brains(activity!!).logging(true).getSmarts() - } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(layoutRes, container, false) } - override fun onDestroy() { - super.onDestroy() - wiseFy.dump() + protected fun displayInfo(@StringRes infoMessageResId: Int, @StringRes infoTitleResId: Int = R.string.info) { + showDialogNoDuplicates( + tag = NoticeDialogFragment.TAG, + dialog = NoticeDialogFragment.newInstance( + title = getString(infoTitleResId), + message = getString(infoMessageResId) + ) + ) + } + + protected fun displayInfo(infoMessage: String, @StringRes infoTitleResId: Int) { + showDialogNoDuplicates( + tag = NoticeDialogFragment.TAG, + dialog = NoticeDialogFragment.newInstance( + title = getString(infoTitleResId), + message = infoMessage + ) + ) + } + + protected fun displayInfoFullScreen(infoMessage: String, @StringRes infoTitleResId: Int) { + showDialogNoDuplicates( + tag = FullScreenNoticeDialogFragment.TAG, + dialog = FullScreenNoticeDialogFragment.newInstance( + title = getString(infoTitleResId), + message = infoMessage + ) + ) + } + + protected fun displayPermissionErrorDialog(@StringRes permissionErrorMessageResId: Int) { + showDialogNoDuplicates( + tag = NoticeDialogFragment.TAG, + dialog = NoticeDialogFragment.newInstance( + title = getString(R.string.permission_error), + message = getString(permissionErrorMessageResId) + ) + ) + } + + protected fun displayPermissionErrorDialog(permissionErrorMessage: String) { + showDialogNoDuplicates( + tag = NoticeDialogFragment.TAG, + dialog = NoticeDialogFragment.newInstance( + title = getString(R.string.permission_error), + message = permissionErrorMessage + ) + ) + } + + private fun showDialogNoDuplicates(tag: String, dialog: T) { + if (isActivityInvalid()) return + dialog.showNoDuplicates(childFragmentManager, tag) } protected fun displayWiseFyFailureWithCode(@WiseFyCode wiseFyFailureCode: Int) { - displayShortToast("WiseFy Failure. Code: $wiseFyFailureCode") + showDialogNoDuplicates( + tag = NoticeDialogFragment.TAG, + dialog = NoticeDialogFragment.newInstance( + title = getString(R.string.wisefy_error), + message = getString(R.string.wisefy_error_descriptions_args, wiseFyFailureCode) + ) + ) } protected fun isPermissionGranted(permission: String, requestCode: Int): Boolean { - return if (permissionUtil.permissionNotGranted(activity!!, permission)) { - if (shouldShowRequestPermissionRationale(permission)) { - // Display dialog or rationale for requesting permission here - requestPermissions(arrayOf(permission), requestCode) - } else { - requestPermissions(arrayOf(permission), requestCode) - } + return if (!permissionUtil.isPermissionGranted(activity!!, permission)) { + // Logic may be added here to display rationale if needed + requestPermissions(arrayOf(permission), requestCode) false } else { true diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseMvp.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseMvp.kt index c3da0fd1..c1d1e09b 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseMvp.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BaseMvp.kt @@ -1,7 +1,23 @@ +/* + * Copyright 2019 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.wisefysample.internal.base import com.isupatches.wisefy.constants.WiseFyCode +@Suppress("UndocumentedPublicClass", "UndocumentedPublicFunction") internal interface BaseMvp { interface View { diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BasePresenter.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BasePresenter.kt index b6bf1109..cb07c263 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BasePresenter.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/BasePresenter.kt @@ -1,12 +1,28 @@ +/* + * Copyright 2019 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.wisefysample.internal.base import android.util.Log import com.isupatches.wisefy.constants.WiseFyCode +import com.isupatches.wisefysample.internal.util.RxSchedulersProvider -import io.reactivex.android.schedulers.AndroidSchedulers - -internal abstract class BasePresenter : BaseMvp.Presenter { +internal abstract class BasePresenter constructor( + private val rxSchedulersProvider: RxSchedulersProvider +) : BaseMvp.Presenter { companion object { private val TAG = BasePresenter::class.java.simpleName @@ -14,8 +30,6 @@ internal abstract class BasePresenter : BaseMvp.Presenter { private var view: V? = null - private val mainThread = AndroidSchedulers.mainThread() - private val isViewAttached: Boolean get() = view != null @@ -31,7 +45,7 @@ internal abstract class BasePresenter : BaseMvp.Presenter { protected fun doSafelyWithView(viewCommand: (view: V) -> Unit) { if (isViewAttached) { - mainThread.scheduleDirect { + rxSchedulersProvider.main.scheduleDirect { if (isViewAttached) { viewCommand(view!!) } else { @@ -44,9 +58,4 @@ internal abstract class BasePresenter : BaseMvp.Presenter { override fun displayWiseFyFailure(@WiseFyCode wiseFyFailureCode: Int) { doSafelyWithView { view -> view.displayWiseFyFailure(wiseFyFailureCode) } } - - @Suppress("unused") - protected interface ViewCommand { - fun command(view: V?) - } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/ViewNotAttachedException.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/ViewNotAttachedException.kt index bc75cea4..a0e1f610 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/ViewNotAttachedException.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/base/ViewNotAttachedException.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.base import java.lang.RuntimeException diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/PermissionsModule.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/PermissionsModule.kt index eb40647b..a7ab50ad 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/PermissionsModule.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/PermissionsModule.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.di import com.isupatches.wisefysample.internal.util.PermissionUtil diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/PreferencesModule.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/PreferencesModule.kt index 894d4da3..544881fe 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/PreferencesModule.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/PreferencesModule.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.di import android.content.Context @@ -16,7 +31,7 @@ import dagger.Provides import javax.inject.Singleton -@Suppress("unused") +@Suppress("unused", "UndocumentedPublicClass", "UndocumentedPublicFunction") @Module internal object PreferencesModule { @JvmStatic @Singleton @Provides diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/ScreenBindingsModule.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/ScreenBindingsModule.kt index 7957505a..181ef58e 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/ScreenBindingsModule.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/di/ScreenBindingsModule.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.di import com.isupatches.wisefysample.ui.main.MainActivity @@ -6,10 +21,10 @@ import dagger.Module import dagger.android.ContributesAndroidInjector @Suppress("unused") -@Module -internal interface ScreenBindingsModule { +@Module internal interface ScreenBindingsModule { @ContributesAndroidInjector(modules = [ + MainActivity.MainActivityModule::class, MainActivity.FragmentBindings::class ]) fun mainActivity(): MainActivity diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/models/NetworkType.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/models/NetworkType.kt index a21f87a6..068509f4 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/models/NetworkType.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/models/NetworkType.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.models internal enum class NetworkType(val intVal: Int) { diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/models/SearchType.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/models/SearchType.kt index d580f97b..1281e84a 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/models/SearchType.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/models/SearchType.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.models internal enum class SearchType(val intVal: Int) { diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/nav/MainRouter.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/nav/MainRouter.kt index 63d87fb3..cabf7abe 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/nav/MainRouter.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/nav/MainRouter.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.nav import androidx.fragment.app.Fragment diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/AddNetworkStore.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/AddNetworkStore.kt index cc66b2c6..d184f21f 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/AddNetworkStore.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/AddNetworkStore.kt @@ -1,13 +1,29 @@ +/* + * Copyright 2019 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.wisefysample.internal.preferences import android.content.SharedPreferences +import androidx.annotation.VisibleForTesting import androidx.core.content.edit import com.isupatches.wisefysample.internal.models.NetworkType -private const val PREF_NETWORK_TYPE = "network type" -private const val PREF_LAST_USED_NETWORK_NAME = "last used network name" -private const val PREF_LAST_USED_NETWORK_PASSWORD = "last used network password" +@VisibleForTesting internal const val PREF_NETWORK_TYPE = "network type" +@VisibleForTesting internal const val PREF_LAST_USED_NETWORK_NAME = "last used network name" +@VisibleForTesting internal const val PREF_LAST_USED_NETWORK_PASSWORD = "last used network password" internal interface AddNetworkStore { fun clear() @@ -47,10 +63,10 @@ internal class SharedPreferencesAddNetworkStore( * Last used network name */ - override fun getLastUsedNetworkName() = sharedPreferences.getString( - PREF_LAST_USED_NETWORK_NAME, - "" - ) ?: "" + override fun getLastUsedNetworkName() = sharedPreferences.getNonNullString( + PREF_LAST_USED_NETWORK_NAME + ) + override fun setLastUsedNetworkName(lastUsedNetworkName: String) { sharedPreferences.edit { putString(PREF_LAST_USED_NETWORK_NAME, lastUsedNetworkName) @@ -61,10 +77,9 @@ internal class SharedPreferencesAddNetworkStore( * Last used network password */ - override fun getLastUsedNetworkPassword() = sharedPreferences.getString( - PREF_LAST_USED_NETWORK_PASSWORD, - "" - ) ?: "" + override fun getLastUsedNetworkPassword() = sharedPreferences.getNonNullString( + PREF_LAST_USED_NETWORK_PASSWORD + ) override fun setLastUsedNetworkPassword(lastUsedNetworkPassword: String) { sharedPreferences.edit { diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/RemoveNetworkStore.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/RemoveNetworkStore.kt index 95ef2df6..0e295f50 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/RemoveNetworkStore.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/RemoveNetworkStore.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.preferences import android.content.SharedPreferences @@ -24,14 +39,9 @@ internal class SharedPreferencesRemoveNetworkStore( * Last used Regex */ - override fun getLastUsedRegex() = sharedPreferences.getString( - PREF_LAST_USED_REGEX, - "" - ) ?: "" + override fun getLastUsedRegex() = sharedPreferences.getLastUsedRegex() override fun setLastUsedRegex(lastUsedRegex: String) { - sharedPreferences.edit { - putString(PREF_LAST_USED_REGEX, lastUsedRegex) - } + sharedPreferences.setLastUsedRegex(lastUsedRegex) } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SearchStore.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SearchStore.kt index 8970842e..25baa6ed 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SearchStore.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SearchStore.kt @@ -1,15 +1,30 @@ +/* + * Copyright 2019 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.wisefysample.internal.preferences import android.content.SharedPreferences - +import androidx.annotation.VisibleForTesting import androidx.core.content.edit import com.isupatches.wisefysample.internal.models.SearchType -private const val PREF_SEARCH_TYPE = "search type" -private const val PREF_RETURN_FULL_LIST = "return full list" -private const val PREF_FILTER_DUPLICATES = "filter duplicates" -private const val PREF_TIMEOUT = "timeout" +@VisibleForTesting internal const val PREF_SEARCH_TYPE = "search type" +@VisibleForTesting internal const val PREF_RETURN_FULL_LIST = "return full list" +@VisibleForTesting internal const val PREF_FILTER_DUPLICATES = "filter duplicates" +@VisibleForTesting internal const val PREF_TIMEOUT = "timeout" internal interface SearchStore { fun clear() @@ -39,15 +54,10 @@ internal class SharedPreferencesSearchStore( * Last used Regex */ - override fun getLastUsedRegex() = sharedPreferences.getString( - PREF_LAST_USED_REGEX, - "" - ) ?: "" + override fun getLastUsedRegex() = sharedPreferences.getLastUsedRegex() override fun setLastUsedRegex(lastUsedRegex: String) { - sharedPreferences.edit { - putString(PREF_LAST_USED_REGEX, lastUsedRegex) - } + sharedPreferences.setLastUsedRegex(lastUsedRegex) } /* diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SharedPreferenceKeys.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SharedPreferenceKeys.kt index 65cc979c..cef8763d 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SharedPreferenceKeys.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SharedPreferenceKeys.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.preferences internal const val PREF_LAST_USED_REGEX = "last used regex" diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SharedPreferences.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SharedPreferences.kt new file mode 100644 index 00000000..3f7e2483 --- /dev/null +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/preferences/SharedPreferences.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2019 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.wisefysample.internal.preferences + +import android.content.SharedPreferences +import androidx.core.content.edit + +internal fun SharedPreferences.getLastUsedRegex() = getNonNullString( + PREF_LAST_USED_REGEX + ) + +internal fun SharedPreferences.setLastUsedRegex(lastUsedRegex: String) { + edit { + putString(PREF_LAST_USED_REGEX, lastUsedRegex) + } +} + +internal fun SharedPreferences.getNonNullString(key: String) = + getString(key, "") ?: "" diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/BundleUtil.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/BundleUtil.kt new file mode 100644 index 00000000..7333ef46 --- /dev/null +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/BundleUtil.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2019 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.wisefysample.internal.util + +import android.os.Bundle +import androidx.fragment.app.Fragment + +/** + * + */ +fun T.applyArguments(block: Bundle.() -> Unit): T { + arguments = Bundle().apply(block) + return this +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/EditTextExtensions.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/EditTextExtensions.kt deleted file mode 100644 index 60b1aa5b..00000000 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/EditTextExtensions.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.isupatches.wisefysample.internal.util - -import android.widget.EditText - -internal fun EditText.getTrimmedInput(): String = text.toString().trim() diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/EditTextUtil.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/EditTextUtil.kt new file mode 100644 index 00000000..bd8542c6 --- /dev/null +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/EditTextUtil.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2019 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.wisefysample.internal.util + +import android.widget.EditText + +internal fun EditText.getTrimmedInput(): String = text.toString().trim() diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/HtmlUtil.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/HtmlUtil.kt index 375dd6aa..db3b5f5f 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/HtmlUtil.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/HtmlUtil.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.util import android.os.Build diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/KeyboardUtil.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/KeyboardUtil.kt index aa96c77b..ff2e9eba 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/KeyboardUtil.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/KeyboardUtil.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.util import android.app.Activity @@ -12,4 +27,4 @@ internal fun BaseFragment.hideKeyboardFrom(view: View) { inputManger.hideSoftInputFromWindow(view.windowToken, 0) } } -} \ No newline at end of file +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/PermissionsUtil.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/PermissionsUtil.kt index 6ab58d30..76d8ef2d 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/PermissionsUtil.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/PermissionsUtil.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.internal.util import android.content.Context @@ -7,12 +22,12 @@ import androidx.core.content.ContextCompat import javax.inject.Inject internal interface PermissionUtil { - fun permissionNotGranted(context: Context, permission: String): Boolean + fun isPermissionGranted(context: Context, permission: String): Boolean } -internal class PermissionsUtilImpl @Inject constructor(): PermissionUtil { +internal class PermissionsUtilImpl @Inject constructor() : PermissionUtil { - override fun permissionNotGranted(context: Context, permission: String): Boolean { - return ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED + override fun isPermissionGranted(context: Context, permission: String): Boolean { + return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED } -} \ No newline at end of file +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/RxSchedulersProvider.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/RxSchedulersProvider.kt new file mode 100644 index 00000000..491bc955 --- /dev/null +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/RxSchedulersProvider.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2019 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.wisefysample.internal.util + +import io.reactivex.Scheduler +import io.reactivex.schedulers.Schedulers +import io.reactivex.android.schedulers.AndroidSchedulers + +import javax.inject.Inject + +@Suppress("UndocumentedPublicClass") +open class RxSchedulersProvider @Inject constructor() { + open val main: Scheduler by lazy { AndroidSchedulers.mainThread() } + open val io: Scheduler by lazy { Schedulers.io() } +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/SdkUtil.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/SdkUtil.kt new file mode 100644 index 00000000..0685da6b --- /dev/null +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/SdkUtil.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2019 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.wisefysample.internal.util + +import android.os.Build + +import javax.inject.Inject + +internal interface SdkUtil { + + fun isAtLeastLollipop(): Boolean +} + +internal class SdkUtilImpl @Inject constructor() : SdkUtil { + + override fun isAtLeastLollipop() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/ToastUtil.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/ToastUtil.kt deleted file mode 100644 index 257bdfe9..00000000 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/ToastUtil.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.isupatches.wisefysample.internal.util - -import android.widget.Toast -import com.isupatches.wisefysample.internal.base.BaseFragment - -internal fun BaseFragment.displayShortToast(message: String) { - Toast.makeText(activity, message, Toast.LENGTH_SHORT).show() -} \ No newline at end of file diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/WiseFyFactory.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/WiseFyFactory.kt new file mode 100644 index 00000000..d612e5d1 --- /dev/null +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/internal/util/WiseFyFactory.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2019 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.wisefysample.internal.util + +import androidx.fragment.app.FragmentActivity + +import com.isupatches.wisefy.WiseFy +import com.isupatches.wisefy.WiseFyPublicApi + +@Suppress("UndocumentedPublicFunction") +fun createWiseFy(activity: FragmentActivity): WiseFyPublicApi = WiseFy.Brains(activity) + .logging(true) + .getSmarts() diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkFragment.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkFragment.kt index ad0ac1d4..64b5074d 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkFragment.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkFragment.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.ui.add import android.Manifest.permission.ACCESS_WIFI_STATE @@ -6,16 +21,19 @@ import android.net.wifi.WifiConfiguration import android.os.Bundle import android.util.Log import android.view.View +import androidx.annotation.VisibleForTesting import com.isupatches.wisefy.constants.WiseFyCode import com.isupatches.wisefysample.R import com.isupatches.wisefysample.internal.base.BaseFragment import com.isupatches.wisefysample.internal.models.NetworkType import com.isupatches.wisefysample.internal.preferences.AddNetworkStore -import com.isupatches.wisefysample.internal.util.displayShortToast import com.isupatches.wisefysample.internal.util.getTrimmedInput import com.isupatches.wisefysample.internal.util.hideKeyboardFrom +import dagger.Binds +import dagger.Module + import kotlinx.android.synthetic.main.fragment_add.addNetworkBtn import kotlinx.android.synthetic.main.fragment_add.addNetworkTypeRdg import kotlinx.android.synthetic.main.fragment_add.networkNameEdt @@ -28,8 +46,7 @@ internal class AddNetworkFragment : BaseFragment(), AddNetworkMvp.View { override val layoutRes = R.layout.fragment_add - private val presenter by lazy { AddNetworkPresenter(wiseFy) } - + @Inject lateinit var presenter: AddNetworkMvp.Presenter @Inject lateinit var addNetworkStore: AddNetworkStore companion object { @@ -37,9 +54,9 @@ internal class AddNetworkFragment : BaseFragment(), AddNetworkMvp.View { fun newInstance() = AddNetworkFragment() - private const val WISEFY_ADD_OPEN_NETWORK_REQUEST_CODE = 1 - private const val WISEFY_ADD_WEP_NETWORK_REQUEST_CODE = 2 - private const val WISEFY_ADD_WPA2_NETWORK_REQUEST_CODE = 3 + @VisibleForTesting internal const val WISEFY_ADD_OPEN_NETWORK_REQUEST_CODE = 1 + @VisibleForTesting internal const val WISEFY_ADD_WEP_NETWORK_REQUEST_CODE = 2 + @VisibleForTesting internal const val WISEFY_ADD_WPA2_NETWORK_REQUEST_CODE = 3 } override fun onStart() { @@ -94,7 +111,7 @@ internal class AddNetworkFragment : BaseFragment(), AddNetworkMvp.View { networkPasswordEdt.setText(addNetworkStore.getLastUsedNetworkPassword()) // Restore checked state - val checkedId = when(addNetworkStore.getNetworkType()) { + val checkedId = when (addNetworkStore.getNetworkType()) { NetworkType.OPEN -> R.id.openNetworkRdb NetworkType.WEP -> R.id.wepNetworkRdb NetworkType.WPA2 -> R.id.wpa2NetworkRdb @@ -102,14 +119,14 @@ internal class AddNetworkFragment : BaseFragment(), AddNetworkMvp.View { addNetworkTypeRdg.check(checkedId) // Show/hide password edit - when(addNetworkStore.getNetworkType()) { + when (addNetworkStore.getNetworkType()) { NetworkType.OPEN -> adjustNetworkPasswordVisibility(View.INVISIBLE) else -> adjustNetworkPasswordVisibility(View.VISIBLE) } } private fun updateUI() { - when(addNetworkTypeRdg.checkedRadioButtonId) { + when (addNetworkTypeRdg.checkedRadioButtonId) { R.id.openNetworkRdb -> adjustNetworkPasswordVisibility(View.INVISIBLE) else -> adjustNetworkPasswordVisibility(View.VISIBLE) } @@ -120,11 +137,14 @@ internal class AddNetworkFragment : BaseFragment(), AddNetworkMvp.View { */ override fun displayFailureAddingNetwork(wifiManagerReturn: Int) { - displayShortToast("Failure adding network. WifiManager return: $wifiManagerReturn") + displayInfo(getString(R.string.failure_adding_network, wifiManagerReturn), R.string.add_network_result) } override fun displayNetworkAdded(newNetworkId: Int, networkConfig: WifiConfiguration) { - displayShortToast("Network added. Id: $newNetworkId, Config: $networkConfig") + displayInfoFullScreen( + getString(R.string.network_added, newNetworkId, networkConfig), + R.string.add_network_result + ) } override fun displayWiseFyFailure(@WiseFyCode wiseFyFailureCode: Int) { @@ -182,7 +202,7 @@ internal class AddNetworkFragment : BaseFragment(), AddNetworkMvp.View { addOpenNetwork() } else { Log.w(TAG, "Permissions for adding an open network are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_add_open_network) } } WISEFY_ADD_WEP_NETWORK_REQUEST_CODE -> { @@ -190,7 +210,7 @@ internal class AddNetworkFragment : BaseFragment(), AddNetworkMvp.View { addWEPNetwork() } else { Log.w(TAG, "Permissions for adding a WEP network are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_add_wep_network) } } WISEFY_ADD_WPA2_NETWORK_REQUEST_CODE -> { @@ -198,13 +218,25 @@ internal class AddNetworkFragment : BaseFragment(), AddNetworkMvp.View { addWPA2Network() } else { Log.w(TAG, "Permissions for adding a WPA2 network are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_add_wpa2_network) } } else -> { - // Display permission error here Log.wtf(TAG, "Weird permission requested, not handled") + displayPermissionErrorDialog( + getString(R.string.permission_error_unhandled_request_code_args, requestCode) + ) } } } + + /* + * Dagger + */ + + @Suppress("unused") + @Module internal interface AddNetworkFragmentModule { + @Binds fun bindAddNetworkModel(impl: AddNetworkModel): AddNetworkMvp.Model + @Binds fun bindAddNetworkPresenter(impl: AddNetworkPresenter): AddNetworkMvp.Presenter + } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkModel.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkModel.kt index 1d402f39..7c353d71 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkModel.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkModel.kt @@ -1,66 +1,53 @@ +/* + * Copyright 2019 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.wisefysample.ui.add import android.Manifest.permission.ACCESS_WIFI_STATE -import android.net.wifi.WifiConfiguration import androidx.annotation.RequiresPermission -import com.isupatches.wisefy.WiseFy +import com.isupatches.wisefy.WiseFyPublicApi import com.isupatches.wisefy.callbacks.AddNetworkCallbacks -internal class AddNetworkModel( - private val presenter: AddNetworkMvp.Presenter, - private val wiseFy: WiseFy -): AddNetworkMvp.Model { +import javax.inject.Inject - @RequiresPermission(ACCESS_WIFI_STATE) - override fun addOpenNetwork(ssid: String) { - wiseFy.addOpenNetwork(ssid, object : AddNetworkCallbacks { - override fun networkAdded(newNetworkId: Int, networkConfig: WifiConfiguration) { - presenter.displayNetworkAdded(newNetworkId, networkConfig) - } - - override fun failureAddingNetwork(wifiManagerReturn: Int) { - presenter.displayFailureAddingNetwork(wifiManagerReturn) - } +internal class AddNetworkModel @Inject constructor( + private val wiseFy: WiseFyPublicApi +) : AddNetworkMvp.Model { - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + @RequiresPermission(ACCESS_WIFI_STATE) + override fun addOpenNetwork(ssid: String, callbacks: AddNetworkCallbacks) { + wiseFy.addOpenNetwork(ssid, callbacks) } @RequiresPermission(ACCESS_WIFI_STATE) @Suppress("DEPRECATION") - override fun addWEPNetwork(ssid: String, password: String) { - wiseFy.addWEPNetwork(ssid, password, object : AddNetworkCallbacks { - override fun networkAdded(newNetworkId: Int, networkConfig: WifiConfiguration) { - presenter.displayNetworkAdded(newNetworkId, networkConfig) - } - - override fun failureAddingNetwork(wifiManagerReturn: Int) { - presenter.displayFailureAddingNetwork(wifiManagerReturn) - } - - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun addWEPNetwork( + ssid: String, + password: String, + callbacks: AddNetworkCallbacks + ) { + wiseFy.addWEPNetwork(ssid, password, callbacks) } @RequiresPermission(ACCESS_WIFI_STATE) - override fun addWPA2Network(ssid: String, password: String) { - wiseFy.addWPA2Network(ssid, password, object : AddNetworkCallbacks { - override fun networkAdded(newNetworkId: Int, networkConfig: WifiConfiguration) { - presenter.displayNetworkAdded(newNetworkId, networkConfig) - } - - override fun failureAddingNetwork(wifiManagerReturn: Int) { - presenter.displayFailureAddingNetwork(wifiManagerReturn) - } - - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun addWPA2Network( + ssid: String, + password: String, + callbacks: AddNetworkCallbacks + ) { + wiseFy.addWPA2Network(ssid, password, callbacks) } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkMvp.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkMvp.kt index 1a334a55..1f9f6b0e 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkMvp.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkMvp.kt @@ -1,9 +1,26 @@ +/* + * Copyright 2019 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.wisefysample.ui.add import android.net.wifi.WifiConfiguration +import com.isupatches.wisefy.callbacks.AddNetworkCallbacks import com.isupatches.wisefysample.internal.base.BaseMvp +@Suppress("UndocumentedPublicClass", "UndocumentedPublicFunction") internal interface AddNetworkMvp { interface View : BaseMvp.View { @@ -12,24 +29,14 @@ internal interface AddNetworkMvp { } interface Presenter : BaseMvp.Presenter { - - /* - * Model call-throughs - */ fun addOpenNetwork(ssid: String) fun addWEPNetwork(ssid: String, password: String) fun addWPA2Network(ssid: String, password: String) - - /* - * View callbacks - */ - fun displayFailureAddingNetwork(wifiManagerReturn: Int) - fun displayNetworkAdded(newNetworkId: Int, networkConfig: WifiConfiguration) } interface Model { - fun addOpenNetwork(ssid: String) - fun addWEPNetwork(ssid: String, password: String) - fun addWPA2Network(ssid: String, password: String) + fun addOpenNetwork(ssid: String, callbacks: AddNetworkCallbacks) + fun addWEPNetwork(ssid: String, password: String, callbacks: AddNetworkCallbacks) + fun addWPA2Network(ssid: String, password: String, callbacks: AddNetworkCallbacks) } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkPresenter.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkPresenter.kt index 311573af..45d71f1b 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkPresenter.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/add/AddNetworkPresenter.kt @@ -1,17 +1,50 @@ +/* + * Copyright 2019 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.wisefysample.ui.add import android.Manifest.permission.ACCESS_WIFI_STATE import android.net.wifi.WifiConfiguration import androidx.annotation.RequiresPermission -import com.isupatches.wisefy.WiseFy +import com.isupatches.wisefy.callbacks.AddNetworkCallbacks import com.isupatches.wisefysample.internal.base.BasePresenter +import com.isupatches.wisefysample.internal.util.RxSchedulersProvider -internal class AddNetworkPresenter( - wiseFy: WiseFy -) : BasePresenter(), AddNetworkMvp.Presenter { +import javax.inject.Inject - private val model = AddNetworkModel(this, wiseFy) +internal class AddNetworkPresenter @Inject constructor( + private val model: AddNetworkMvp.Model, + rxSchedulersProvider: RxSchedulersProvider +) : BasePresenter(rxSchedulersProvider), AddNetworkMvp.Presenter { + + private val addNetworkCallbacks by lazy { + object : AddNetworkCallbacks { + override fun networkAdded(newNetworkId: Int, networkConfig: WifiConfiguration) { + displayNetworkAdded(newNetworkId, networkConfig) + } + + override fun failureAddingNetwork(wifiManagerReturn: Int) { + displayFailureAddingNetwork(wifiManagerReturn) + } + + override fun wisefyFailure(wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + } + } /* * Model call-throughs @@ -19,28 +52,28 @@ internal class AddNetworkPresenter( @RequiresPermission(ACCESS_WIFI_STATE) override fun addOpenNetwork(ssid: String) { - model.addOpenNetwork(ssid) + model.addOpenNetwork(ssid, addNetworkCallbacks) } @RequiresPermission(ACCESS_WIFI_STATE) override fun addWEPNetwork(ssid: String, password: String) { - model.addWEPNetwork(ssid, password) + model.addWEPNetwork(ssid, password, addNetworkCallbacks) } @RequiresPermission(ACCESS_WIFI_STATE) override fun addWPA2Network(ssid: String, password: String) { - model.addWPA2Network(ssid, password) + model.addWPA2Network(ssid, password, addNetworkCallbacks) } /* * View callbacks */ - override fun displayFailureAddingNetwork(wifiManagerReturn: Int) { + private fun displayFailureAddingNetwork(wifiManagerReturn: Int) { doSafelyWithView { view -> view.displayFailureAddingNetwork(wifiManagerReturn) } } - override fun displayNetworkAdded(newNetworkId: Int, networkConfig: WifiConfiguration) { + private fun displayNetworkAdded(newNetworkId: Int, networkConfig: WifiConfiguration) { doSafelyWithView { view -> view.displayNetworkAdded(newNetworkId, networkConfig) } } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/dialogs/BaseNoticeDialogFragment.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/dialogs/BaseNoticeDialogFragment.kt new file mode 100644 index 00000000..d192b2ca --- /dev/null +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/dialogs/BaseNoticeDialogFragment.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2019 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.wisefysample.ui.dialogs + +import android.os.Bundle +import android.view.View + +import com.isupatches.wisefysample.internal.base.BaseDialogFragment + +import kotlinx.android.synthetic.main.dialog_base.dialogMessageTxt +import kotlinx.android.synthetic.main.dialog_base.dialogTitleTxt +import kotlinx.android.synthetic.main.dialog_base.okBtn + +internal const val EXTRA_DIALOG_TITLE = "dialog title" +internal const val EXTRA_DIALOG_MESSAGE = "dialog message" + +internal abstract class BaseNoticeDialogFragment : BaseDialogFragment() { + + private val dialogTitle: String by lazy { + arguments!!.getString(EXTRA_DIALOG_TITLE) + } + + private val dialogMessage: String by lazy { + arguments!!.getString(EXTRA_DIALOG_MESSAGE) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + isCancelable = false + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + dialogTitleTxt.text = dialogTitle + dialogMessageTxt.text = dialogMessage + okBtn.setOnClickListener { + dismiss() + } + } +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/dialogs/FullScreenNoticeDialogFragment.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/dialogs/FullScreenNoticeDialogFragment.kt new file mode 100644 index 00000000..6766ebc8 --- /dev/null +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/dialogs/FullScreenNoticeDialogFragment.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2019 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.wisefysample.ui.dialogs + +import android.app.Dialog +import android.os.Bundle +import android.view.ViewGroup + +import com.isupatches.wisefysample.R +import com.isupatches.wisefysample.internal.util.applyArguments + +internal class FullScreenNoticeDialogFragment : BaseNoticeDialogFragment() { + + override val layoutRes = R.layout.dialog_base_fullscreen + + companion object { + val TAG: String = FullScreenNoticeDialogFragment::class.java.simpleName + + fun newInstance(title: String, message: String) = + FullScreenNoticeDialogFragment().applyArguments { + putString(EXTRA_DIALOG_TITLE, title) + putString(EXTRA_DIALOG_MESSAGE, message) + } + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + dialog?.window?.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + return super.onCreateDialog(savedInstanceState) + } +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/dialogs/NoticeDialogFragment.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/dialogs/NoticeDialogFragment.kt new file mode 100644 index 00000000..806d4d70 --- /dev/null +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/dialogs/NoticeDialogFragment.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2019 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.wisefysample.ui.dialogs + +import com.isupatches.wisefysample.R +import com.isupatches.wisefysample.internal.util.applyArguments + +internal class NoticeDialogFragment : BaseNoticeDialogFragment() { + + override val layoutRes = R.layout.dialog_base + + companion object { + val TAG: String = NoticeDialogFragment::class.java.simpleName + + fun newInstance(title: String, message: String) = + NoticeDialogFragment().applyArguments { + putString(EXTRA_DIALOG_TITLE, title) + putString(EXTRA_DIALOG_MESSAGE, message) + } + } +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/main/MainActivity.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/main/MainActivity.kt index 58d0e701..bc3bab27 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/main/MainActivity.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/main/MainActivity.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.ui.main import android.os.Bundle @@ -6,16 +21,22 @@ import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import com.google.android.material.bottomnavigation.BottomNavigationView +import com.isupatches.wisefy.WiseFyPublicApi import com.isupatches.wisefysample.R import com.isupatches.wisefysample.internal.nav.openFragment import com.isupatches.wisefysample.internal.nav.selectItem +import com.isupatches.wisefysample.internal.util.SdkUtil +import com.isupatches.wisefysample.internal.util.SdkUtilImpl +import com.isupatches.wisefysample.internal.util.createWiseFy import com.isupatches.wisefysample.ui.add.AddNetworkFragment import com.isupatches.wisefysample.ui.misc.MiscFragment import com.isupatches.wisefysample.ui.remove.RemoveNetworkFragment import com.isupatches.wisefysample.ui.search.SearchFragment +import dagger.Binds import dagger.Module +import dagger.Provides import dagger.android.AndroidInjection import dagger.android.AndroidInjector import dagger.android.ContributesAndroidInjector @@ -33,6 +54,8 @@ internal class MainActivity : AppCompatActivity(), @Inject lateinit var fragmentInjector: DispatchingAndroidInjector override fun supportFragmentInjector(): AndroidInjector = fragmentInjector + @Inject lateinit var wiseFy: WiseFyPublicApi + override fun onCreate(savedInstanceState: Bundle?) { AndroidInjection.inject(this) super.onCreate(savedInstanceState) @@ -45,6 +68,12 @@ internal class MainActivity : AppCompatActivity(), } } + override fun onDestroy() { + super.onDestroy() + wiseFy.dump() + } + + @Suppress("ReturnCount") override fun onNavigationItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_add -> { @@ -74,10 +103,29 @@ internal class MainActivity : AppCompatActivity(), @Suppress("unused") @Module internal interface FragmentBindings { - @ContributesAndroidInjector fun addNetworkFragment(): AddNetworkFragment - @ContributesAndroidInjector fun removeNetworkFragment(): RemoveNetworkFragment + @ContributesAndroidInjector(modules = [ + AddNetworkFragment.AddNetworkFragmentModule::class + ]) fun addNetworkFragment(): AddNetworkFragment + @ContributesAndroidInjector(modules = [ + RemoveNetworkFragment.RemoveNetworkFragmentModule::class + ]) fun removeNetworkFragment(): RemoveNetworkFragment @ContributesAndroidInjector fun mainFragment(): MainFragment - @ContributesAndroidInjector fun miscFragment(): MiscFragment - @ContributesAndroidInjector fun searchFragment(): SearchFragment + @ContributesAndroidInjector(modules = [ + MiscFragment.MiscFragmentModule::class + ]) fun miscFragment(): MiscFragment + @ContributesAndroidInjector(modules = [ + SearchFragment.SearchFragmentModule::class + ]) fun searchFragment(): SearchFragment + } + + @Suppress("unused") + @Module internal abstract class MainActivityModule { + + @Binds abstract fun bindSdkUtil(impl: SdkUtilImpl): SdkUtil + + @Module companion object { + @Provides @JvmStatic + fun provideWiseFy(activity: MainActivity) = createWiseFy(activity) + } } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/main/MainFragment.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/main/MainFragment.kt index 6a0bbc45..598c74dc 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/main/MainFragment.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/main/MainFragment.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.ui.main import com.isupatches.wisefysample.R diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscFragment.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscFragment.kt index a31c9d4a..bc4c7404 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscFragment.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscFragment.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.ui.misc import android.Manifest.permission.ACCESS_COARSE_LOCATION @@ -9,44 +24,51 @@ import android.net.NetworkInfo import android.net.wifi.ScanResult import android.net.wifi.WifiConfiguration import android.net.wifi.WifiInfo -import android.os.Build import android.os.Bundle import android.util.Log import android.view.View +import androidx.annotation.VisibleForTesting import com.isupatches.wisefy.constants.WiseFyCode import com.isupatches.wisefysample.R import com.isupatches.wisefysample.internal.base.BaseFragment -import com.isupatches.wisefysample.internal.util.displayShortToast +import com.isupatches.wisefysample.internal.util.SdkUtil + +import dagger.Binds +import dagger.Module import kotlinx.android.synthetic.main.fragment_misc.enableWifiBtn import kotlinx.android.synthetic.main.fragment_misc.disableWifiBtn import kotlinx.android.synthetic.main.fragment_misc.getCurrentNetworkBtn -import kotlinx.android.synthetic.main.fragment_misc.getCurrentNetworkDetailsBtn +import kotlinx.android.synthetic.main.fragment_misc.getCurrentNetworkInfoBtn import kotlinx.android.synthetic.main.fragment_misc.getFrequencyBtn import kotlinx.android.synthetic.main.fragment_misc.getIPBtn import kotlinx.android.synthetic.main.fragment_misc.getNearbyAccessPointsBtn import kotlinx.android.synthetic.main.fragment_misc.getSavedNetworksBtn +import javax.inject.Inject + +@Suppress("LargeClass") internal class MiscFragment : BaseFragment(), MiscMvp.View { override val layoutRes = R.layout.fragment_misc - private val presenter by lazy { MiscPresenter(wiseFy) } + @Inject lateinit var presenter: MiscMvp.Presenter + @Inject lateinit var sdkUtil: SdkUtil companion object { val TAG: String = MiscFragment::class.java.simpleName fun newInstance() = MiscFragment() - private const val WISEFY_DISABLE_WIFI_REQUEST_CODE = 1 - private const val WISEFY_ENABLE_WIFI_REQUEST_CODE = 2 - private const val WISEFY_GET_CURRENT_NETWORK_REQUEST_CODE = 3 - private const val WISEFY_GET_CURRENT_NETWORK_INFO_REQUEST_CODE = 4 - private const val WISEFY_GET_FREQUENCY_REQUEST_CODE = 5 - private const val WISEFY_GET_IP_REQUEST_CODE = 6 - private const val WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE = 7 - private const val WISEFY_GET_SAVED_NETWORKS_REQUEST_CODE = 8 + @VisibleForTesting internal const val WISEFY_DISABLE_WIFI_REQUEST_CODE = 1 + @VisibleForTesting internal const val WISEFY_ENABLE_WIFI_REQUEST_CODE = 2 + @VisibleForTesting internal const val WISEFY_GET_CURRENT_NETWORK_REQUEST_CODE = 3 + @VisibleForTesting internal const val WISEFY_GET_CURRENT_NETWORK_INFO_REQUEST_CODE = 4 + @VisibleForTesting internal const val WISEFY_GET_FREQUENCY_REQUEST_CODE = 5 + @VisibleForTesting internal const val WISEFY_GET_IP_REQUEST_CODE = 6 + @VisibleForTesting internal const val WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE = 7 + @VisibleForTesting internal const val WISEFY_GET_SAVED_NETWORKS_REQUEST_CODE = 8 } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -61,7 +83,7 @@ internal class MiscFragment : BaseFragment(), MiscMvp.View { getCurrentNetworkBtn.setOnClickListener { getCurrentNetwork() } - getCurrentNetworkDetailsBtn.setOnClickListener { + getCurrentNetworkInfoBtn.setOnClickListener { getCurrentNetworkInfo() } getFrequencyBtn.setOnClickListener { @@ -93,67 +115,79 @@ internal class MiscFragment : BaseFragment(), MiscMvp.View { */ override fun displayWifiDisabled() { - displayShortToast("Wifi disabled!") + displayInfo(R.string.wifi_disabled, R.string.wisefy_action_result) } override fun displayFailureDisablingWifi() { - displayShortToast("Failure disabling wifi") + displayInfo(R.string.failure_disabling_wifi, R.string.wisefy_action_result) } override fun displayWifiEnabled() { - displayShortToast("Wifi enabled!") + displayInfo(R.string.wifi_enabled, R.string.wisefy_action_result) } override fun displayFailureEnablingWifi() { - displayShortToast("Failure enabling wifi") + displayInfo(R.string.failure_enabling_wifi, R.string.wisefy_action_result) } override fun displayCurrentNetwork(currentNetwork: WifiInfo) { - displayShortToast("Current network: $currentNetwork") + displayInfoFullScreen( + getString(R.string.current_network_args, currentNetwork), + R.string.wisefy_action_result + ) } override fun displayNoCurrentNetwork() { - displayShortToast("No current network") + displayInfo(R.string.no_current_network, R.string.wisefy_action_result) } - override fun displayCurrentNetworkInfo(currentNetworkDetails: NetworkInfo) { - displayShortToast("Current network info: $currentNetworkDetails") + override fun displayCurrentNetworkInfo(currentNetworkInfo: NetworkInfo) { + displayInfoFullScreen( + getString(R.string.current_network_info_args, currentNetworkInfo), + R.string.wisefy_action_result + ) } override fun displayNoCurrentNetworkInfo() { - displayShortToast("No current network info") + displayInfo(R.string.no_current_network_info, R.string.wisefy_action_result) } override fun displayFrequency(frequency: Int) { - displayShortToast("Frequency: $frequency") + displayInfo(getString(R.string.frequency_args, frequency), R.string.wisefy_action_result) } override fun displayFailureRetrievingFrequency() { - displayShortToast("Failure retrieving frequency") + displayInfo(R.string.failure_retrieving_frequency, R.string.wisefy_action_result) } override fun displayIP(ip: String) { - displayShortToast("IP: $ip") + displayInfo(getString(R.string.ip_args, ip), R.string.wisefy_action_result) } override fun displayFailureRetrievingIP() { - displayShortToast("Failure retrieving IP") + displayInfo(R.string.failure_retrieving_ip, R.string.wisefy_action_result) } override fun displayNearbyAccessPoints(accessPoints: List) { - displayShortToast("Nearby access points: $accessPoints") + displayInfoFullScreen( + getString(R.string.access_points_args, accessPoints), + R.string.wisefy_action_result + ) } override fun displayNoAccessPointsFound() { - displayShortToast("No access points found!") + displayInfo(R.string.no_access_points_found, R.string.wisefy_action_result) } override fun displaySavedNetworks(savedNetworks: List) { - displayShortToast("Saved networks: $savedNetworks") + displayInfoFullScreen( + getString(R.string.saved_networks_args, savedNetworks), + R.string.wisefy_action_result + ) } override fun displayNoSavedNetworksFound() { - displayShortToast("No saved networks found!") + displayInfo(R.string.no_saved_networks_found, R.string.wisefy_action_result) } override fun displayWiseFyFailure(@WiseFyCode wiseFyFailureCode: Int) { @@ -191,12 +225,12 @@ internal class MiscFragment : BaseFragment(), MiscMvp.View { @Throws(SecurityException::class) private fun getFrequency() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (sdkUtil.isAtLeastLollipop()) { if (checkGetFrequencyPermissions()) { presenter.getFrequency() } } else { - displayShortToast("getFrequency is a Lollipop and above feature") + displayInfo(R.string.frequency_lollipop_notice) } } @@ -233,8 +267,8 @@ internal class MiscFragment : BaseFragment(), MiscMvp.View { } private fun checkGetCurrentNetworkPermissions(): Boolean { - return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_GET_CURRENT_NETWORK_REQUEST_CODE) - && isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_GET_CURRENT_NETWORK_REQUEST_CODE) + return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_GET_CURRENT_NETWORK_REQUEST_CODE) && + isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_GET_CURRENT_NETWORK_REQUEST_CODE) } private fun checkGetCurrentNetworkInfoPermissions(): Boolean { @@ -242,40 +276,41 @@ internal class MiscFragment : BaseFragment(), MiscMvp.View { } private fun checkGetFrequencyPermissions(): Boolean { - return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_GET_FREQUENCY_REQUEST_CODE) - && isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_GET_FREQUENCY_REQUEST_CODE) + return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_GET_FREQUENCY_REQUEST_CODE) && + isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_GET_FREQUENCY_REQUEST_CODE) } - private fun checkGetIPPermissions(): Boolean { - return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_GET_IP_REQUEST_CODE) - && isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_GET_IP_REQUEST_CODE) + private fun checkGetIPPermissions(): Boolean { + return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_GET_IP_REQUEST_CODE) && + isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_GET_IP_REQUEST_CODE) } private fun checkGetNearbyAccessPointsPermissions(): Boolean { - return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE) - && isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE) + return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE) && + isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE) } private fun checkGetSavedNetworksPermissions(): Boolean { return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_GET_SAVED_NETWORKS_REQUEST_CODE) } + @Suppress("LongMethod", "ComplexMethod") override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { when (requestCode) { WISEFY_DISABLE_WIFI_REQUEST_CODE -> { if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - getIP() + disableWifi() } else { Log.w(TAG, "Permissions for disabling wifi are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_disable_wifi) } } WISEFY_ENABLE_WIFI_REQUEST_CODE -> { if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - getIP() + enableWifi() } else { Log.w(TAG, "Permissions for enabling wifi are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_enable_wifi) } } WISEFY_GET_CURRENT_NETWORK_REQUEST_CODE -> { @@ -283,7 +318,7 @@ internal class MiscFragment : BaseFragment(), MiscMvp.View { getCurrentNetwork() } else { Log.w(TAG, "Permissions for getting current network are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_get_current_network) } } WISEFY_GET_CURRENT_NETWORK_INFO_REQUEST_CODE -> { @@ -291,7 +326,7 @@ internal class MiscFragment : BaseFragment(), MiscMvp.View { getCurrentNetworkInfo() } else { Log.w(TAG, "Permissions for getting current network info are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_get_current_network_info) } } WISEFY_GET_FREQUENCY_REQUEST_CODE -> { @@ -299,7 +334,7 @@ internal class MiscFragment : BaseFragment(), MiscMvp.View { getFrequency() } else { Log.w(TAG, "Permissions for getting frequency are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_get_frequency) } } WISEFY_GET_IP_REQUEST_CODE -> { @@ -307,7 +342,7 @@ internal class MiscFragment : BaseFragment(), MiscMvp.View { getIP() } else { Log.w(TAG, "Permissions for getting ip are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_get_ip) } } WISEFY_GET_NEARBY_ACCESS_POINTS_REQUEST_CODE -> { @@ -315,21 +350,33 @@ internal class MiscFragment : BaseFragment(), MiscMvp.View { getNearbyAccessPoints() } else { Log.w(TAG, "Permissions for getting nearby access points are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_get_nearby_access_points) } } WISEFY_GET_SAVED_NETWORKS_REQUEST_CODE -> { if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - getIP() + getSavedNetworks() } else { Log.w(TAG, "Permissions for getting saved networks are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_get_saved_networks) } } else -> { - // Display permission error here Log.wtf(TAG, "Weird permission requested, not handled") + displayPermissionErrorDialog( + getString(R.string.permission_error_unhandled_request_code_args, requestCode) + ) } } } + + /* + * Dagger + */ + + @Suppress("unused") + @Module internal interface MiscFragmentModule { + @Binds fun bindMiscModel(impl: MiscModel): MiscMvp.Model + @Binds fun bindMiscPresenter(impl: MiscPresenter): MiscMvp.Presenter + } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscModel.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscModel.kt index 4f894ebf..c6b47b87 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscModel.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscModel.kt @@ -1,18 +1,29 @@ +/* + * Copyright 2019 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.wisefysample.ui.misc import android.Manifest.permission.ACCESS_COARSE_LOCATION import android.Manifest.permission.ACCESS_NETWORK_STATE import android.Manifest.permission.ACCESS_WIFI_STATE import android.Manifest.permission.CHANGE_WIFI_STATE -import android.net.NetworkInfo -import android.net.wifi.ScanResult -import android.net.wifi.WifiConfiguration -import android.net.wifi.WifiInfo import android.os.Build import androidx.annotation.RequiresApi import androidx.annotation.RequiresPermission -import com.isupatches.wisefy.WiseFy +import com.isupatches.wisefy.WiseFyPublicApi import com.isupatches.wisefy.callbacks.DisableWifiCallbacks import com.isupatches.wisefy.callbacks.EnableWifiCallbacks import com.isupatches.wisefy.callbacks.GetCurrentNetworkCallbacks @@ -22,145 +33,50 @@ import com.isupatches.wisefy.callbacks.GetIPCallbacks import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks -internal class MiscModel( - private val presenter: MiscMvp.Presenter, - private val wiseFy: WiseFy -): MiscMvp.Model { +import javax.inject.Inject - @RequiresPermission(allOf = [CHANGE_WIFI_STATE]) - override fun disableWifi() { - wiseFy.disableWifi(object : DisableWifiCallbacks { - override fun wifiDisabled() { - presenter.displayWifiDisabled() - } - - override fun failureDisablingWifi() { - presenter.displayFailureDisablingWifi() - } +internal class MiscModel @Inject constructor( + private val wiseFy: WiseFyPublicApi +) : MiscMvp.Model { - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + @RequiresPermission(allOf = [CHANGE_WIFI_STATE]) + override fun disableWifi(callbacks: DisableWifiCallbacks) { + wiseFy.disableWifi(callbacks) } @RequiresPermission(allOf = [CHANGE_WIFI_STATE]) - override fun enableWifi() { - wiseFy.enableWifi(object : EnableWifiCallbacks { - override fun wifiEnabled() { - presenter.displayWifiEnabled() - } - - override fun failureEnablingWifi() { - presenter.displayFailureEnablingWifi() - } - - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun enableWifi(callbacks: EnableWifiCallbacks) { + wiseFy.enableWifi(callbacks) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - override fun getCurrentNetwork() { - wiseFy.getCurrentNetwork(object : GetCurrentNetworkCallbacks { - override fun retrievedCurrentNetwork(currentNetwork: WifiInfo) { - presenter.displayCurrentNetwork(currentNetwork) - } - - override fun noCurrentNetwork() { - presenter.displayNoCurrentNetwork() - } - - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun getCurrentNetwork(callbacks: GetCurrentNetworkCallbacks) { + wiseFy.getCurrentNetwork(callbacks) } @RequiresPermission(allOf = [ACCESS_NETWORK_STATE]) - override fun getCurrentNetworkInfo() { - wiseFy.getCurrentNetworkInfo(object : GetCurrentNetworkInfoCallbacks { - override fun retrievedCurrentNetworkInfo(currentNetworkDetails: NetworkInfo) { - presenter.displayCurrentNetworkInfo(currentNetworkDetails) - } - - override fun noCurrentNetworkInfo() { - presenter.displayNoCurrentNetworkInfo() - } - - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun getCurrentNetworkInfo(callbacks: GetCurrentNetworkInfoCallbacks) { + wiseFy.getCurrentNetworkInfo(callbacks) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - override fun getFrequency() { - wiseFy.getFrequency(object : GetFrequencyCallbacks { - override fun retrievedFrequency(frequency: Int) { - presenter.displayFrequency(frequency) - } - - override fun failureGettingFrequency() { - presenter.displayFailureRetrievingFrequency() - } - - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun getFrequency(callbacks: GetFrequencyCallbacks) { + wiseFy.getFrequency(callbacks) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - override fun getIP() { - wiseFy.getIP(object : GetIPCallbacks { - override fun retrievedIP(ip: String) { - presenter.displayIP(ip) - } - - override fun failureRetrievingIP() { - presenter.displayFailureRetrievingIP() - } - - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun getIP(callbacks: GetIPCallbacks) { + wiseFy.getIP(callbacks) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - override fun getNearbyAccessPoints() { - wiseFy.getNearbyAccessPoints(true, object : GetNearbyAccessPointsCallbacks { - override fun retrievedNearbyAccessPoints(nearbyAccessPoints: List) { - presenter.displayNearbyAccessPoints(nearbyAccessPoints) - } - - override fun noAccessPointsFound() { - presenter.displayNoAccessPointsFound() - } - - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun getNearbyAccessPoints(callbacks: GetNearbyAccessPointsCallbacks) { + wiseFy.getNearbyAccessPoints(true, callbacks) } @RequiresPermission(allOf = [ACCESS_WIFI_STATE]) - override fun getSavedNetworks() { - wiseFy.getSavedNetworks(object : GetSavedNetworksCallbacks { - override fun noSavedNetworksFound() { - presenter.displayNoSavedNetworksFound() - } - - override fun retrievedSavedNetworks(savedNetworks: List) { - presenter.displaySavedNetworks(savedNetworks) - } - - override fun wisefyFailure(wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun getSavedNetworks(callbacks: GetSavedNetworksCallbacks) { + wiseFy.getSavedNetworks(callbacks) } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscMvp.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscMvp.kt index 42229059..5a88adba 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscMvp.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscMvp.kt @@ -1,11 +1,36 @@ +/* + * Copyright 2019 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.wisefysample.ui.misc import android.net.NetworkInfo import android.net.wifi.ScanResult import android.net.wifi.WifiConfiguration import android.net.wifi.WifiInfo + +import com.isupatches.wisefy.callbacks.DisableWifiCallbacks +import com.isupatches.wisefy.callbacks.EnableWifiCallbacks +import com.isupatches.wisefy.callbacks.GetCurrentNetworkCallbacks +import com.isupatches.wisefy.callbacks.GetCurrentNetworkInfoCallbacks +import com.isupatches.wisefy.callbacks.GetFrequencyCallbacks +import com.isupatches.wisefy.callbacks.GetIPCallbacks +import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks +import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks import com.isupatches.wisefysample.internal.base.BaseMvp +@Suppress("UndocumentedPublicClass", "UndocumentedPublicFunction") internal interface MiscMvp { interface View : BaseMvp.View { @@ -15,7 +40,7 @@ internal interface MiscMvp { fun displayFailureEnablingWifi() fun displayCurrentNetwork(currentNetwork: WifiInfo) fun displayNoCurrentNetwork() - fun displayCurrentNetworkInfo(currentNetworkDetails: NetworkInfo) + fun displayCurrentNetworkInfo(currentNetworkInfo: NetworkInfo) fun displayNoCurrentNetworkInfo() fun displayFrequency(frequency: Int) fun displayFailureRetrievingFrequency() @@ -28,10 +53,6 @@ internal interface MiscMvp { } interface Presenter : BaseMvp.Presenter { - - /* - * Model call-throughs - */ fun disableWifi() fun enableWifi() fun getCurrentNetwork() @@ -40,36 +61,16 @@ internal interface MiscMvp { fun getIP() fun getNearbyAccessPoints() fun getSavedNetworks() - - /* - * View callbacks - */ - fun displayWifiDisabled() - fun displayFailureDisablingWifi() - fun displayWifiEnabled() - fun displayFailureEnablingWifi() - fun displayCurrentNetwork(currentNetwork: WifiInfo) - fun displayNoCurrentNetwork() - fun displayCurrentNetworkInfo(currentNetworkDetails: NetworkInfo) - fun displayNoCurrentNetworkInfo() - fun displayFrequency(frequency: Int) - fun displayFailureRetrievingFrequency() - fun displayIP(ip: String) - fun displayFailureRetrievingIP() - fun displayNearbyAccessPoints(accessPoints: List) - fun displayNoAccessPointsFound() - fun displayNoSavedNetworksFound() - fun displaySavedNetworks(savedNetworks: List) } interface Model { - fun disableWifi() - fun enableWifi() - fun getCurrentNetwork() - fun getCurrentNetworkInfo() - fun getFrequency() - fun getIP() - fun getNearbyAccessPoints() - fun getSavedNetworks() + fun disableWifi(callbacks: DisableWifiCallbacks) + fun enableWifi(callbacks: EnableWifiCallbacks) + fun getCurrentNetwork(callbacks: GetCurrentNetworkCallbacks) + fun getCurrentNetworkInfo(callbacks: GetCurrentNetworkInfoCallbacks) + fun getFrequency(callbacks: GetFrequencyCallbacks) + fun getIP(callbacks: GetIPCallbacks) + fun getNearbyAccessPoints(callbacks: GetNearbyAccessPointsCallbacks) + fun getSavedNetworks(callbacks: GetSavedNetworksCallbacks) } -} \ No newline at end of file +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscPresenter.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscPresenter.kt index 30859d6c..f9121fb7 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscPresenter.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/misc/MiscPresenter.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.ui.misc import android.Manifest.permission.ACCESS_COARSE_LOCATION @@ -12,12 +27,23 @@ import android.os.Build import androidx.annotation.RequiresApi import androidx.annotation.RequiresPermission -import com.isupatches.wisefy.WiseFy +import com.isupatches.wisefy.callbacks.DisableWifiCallbacks +import com.isupatches.wisefy.callbacks.EnableWifiCallbacks +import com.isupatches.wisefy.callbacks.GetCurrentNetworkCallbacks +import com.isupatches.wisefy.callbacks.GetCurrentNetworkInfoCallbacks +import com.isupatches.wisefy.callbacks.GetFrequencyCallbacks +import com.isupatches.wisefy.callbacks.GetIPCallbacks +import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks +import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks import com.isupatches.wisefysample.internal.base.BasePresenter +import com.isupatches.wisefysample.internal.util.RxSchedulersProvider -internal class MiscPresenter(wiseFy: WiseFy) : BasePresenter(), MiscMvp.Presenter { +import javax.inject.Inject - private val model = MiscModel(this, wiseFy) +internal class MiscPresenter @Inject constructor( + private val model: MiscMvp.Model, + rxSchedulersProvider: RxSchedulersProvider +) : BasePresenter(rxSchedulersProvider), MiscMvp.Presenter { /* * Model call-throughs @@ -25,110 +51,206 @@ internal class MiscPresenter(wiseFy: WiseFy) : BasePresenter(), Mi @RequiresPermission(allOf = [CHANGE_WIFI_STATE]) override fun disableWifi() { - model.disableWifi() + model.disableWifi(object : DisableWifiCallbacks { + override fun wifiDisabled() { + displayWifiDisabled() + } + + override fun failureDisablingWifi() { + displayFailureDisablingWifi() + } + + override fun wisefyFailure(wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } @RequiresPermission(allOf = [CHANGE_WIFI_STATE]) override fun enableWifi() { - model.enableWifi() + model.enableWifi(object : EnableWifiCallbacks { + override fun wifiEnabled() { + displayWifiEnabled() + } + + override fun failureEnablingWifi() { + displayFailureEnablingWifi() + } + + override fun wisefyFailure(wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) override fun getCurrentNetwork() { - model.getCurrentNetwork() + model.getCurrentNetwork(object : GetCurrentNetworkCallbacks { + override fun retrievedCurrentNetwork(currentNetwork: WifiInfo) { + displayCurrentNetwork(currentNetwork) + } + + override fun noCurrentNetwork() { + displayNoCurrentNetwork() + } + + override fun wisefyFailure(wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } @RequiresPermission(allOf = [ACCESS_NETWORK_STATE]) override fun getCurrentNetworkInfo() { - model.getCurrentNetworkInfo() + model.getCurrentNetworkInfo(object : GetCurrentNetworkInfoCallbacks { + override fun retrievedCurrentNetworkInfo(currentNetworkInfo: NetworkInfo) { + displayCurrentNetworkInfo(currentNetworkInfo) + } + + override fun noCurrentNetworkInfo() { + displayNoCurrentNetworkInfo() + } + + override fun wisefyFailure(wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) @RequiresApi(Build.VERSION_CODES.LOLLIPOP) override fun getFrequency() { - model.getFrequency() + model.getFrequency(object : GetFrequencyCallbacks { + override fun retrievedFrequency(frequency: Int) { + displayFrequency(frequency) + } + + override fun failureGettingFrequency() { + displayFailureRetrievingFrequency() + } + + override fun wisefyFailure(wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) override fun getIP() { - model.getIP() + model.getIP(object : GetIPCallbacks { + override fun retrievedIP(ip: String) { + displayIP(ip) + } + + override fun failureRetrievingIP() { + displayFailureRetrievingIP() + } + + override fun wisefyFailure(wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) override fun getNearbyAccessPoints() { - model.getNearbyAccessPoints() + model.getNearbyAccessPoints(object : GetNearbyAccessPointsCallbacks { + override fun retrievedNearbyAccessPoints(nearbyAccessPoints: List) { + displayNearbyAccessPoints(nearbyAccessPoints) + } + + override fun noAccessPointsFound() { + displayNoAccessPointsFound() + } + + override fun wisefyFailure(wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } @RequiresPermission(allOf = [ACCESS_WIFI_STATE]) override fun getSavedNetworks() { - model.getSavedNetworks() + model.getSavedNetworks(object : GetSavedNetworksCallbacks { + override fun noSavedNetworksFound() { + displayNoSavedNetworksFound() + } + + override fun retrievedSavedNetworks(savedNetworks: List) { + displaySavedNetworks(savedNetworks) + } + + override fun wisefyFailure(wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } /* * View callbacks */ - override fun displayWifiDisabled() { + private fun displayWifiDisabled() { doSafelyWithView { view -> view.displayWifiDisabled() } } - override fun displayFailureDisablingWifi() { + private fun displayFailureDisablingWifi() { doSafelyWithView { view -> view.displayFailureDisablingWifi() } } - override fun displayWifiEnabled() { + private fun displayWifiEnabled() { doSafelyWithView { view -> view.displayWifiEnabled() } } - override fun displayFailureEnablingWifi() { + private fun displayFailureEnablingWifi() { doSafelyWithView { view -> view.displayFailureEnablingWifi() } } - override fun displayCurrentNetwork(currentNetwork: WifiInfo) { + private fun displayCurrentNetwork(currentNetwork: WifiInfo) { doSafelyWithView { view -> view.displayCurrentNetwork(currentNetwork) } } - override fun displayNoCurrentNetwork() { + private fun displayNoCurrentNetwork() { doSafelyWithView { view -> view.displayNoCurrentNetwork() } } - override fun displayCurrentNetworkInfo(currentNetworkDetails: NetworkInfo) { + private fun displayCurrentNetworkInfo(currentNetworkDetails: NetworkInfo) { doSafelyWithView { view -> view.displayCurrentNetworkInfo(currentNetworkDetails) } } - override fun displayNoCurrentNetworkInfo() { + private fun displayNoCurrentNetworkInfo() { doSafelyWithView { view -> view.displayNoCurrentNetworkInfo() } } - override fun displayFrequency(frequency: Int) { + private fun displayFrequency(frequency: Int) { doSafelyWithView { view -> view.displayFrequency(frequency) } } - override fun displayFailureRetrievingFrequency() { + private fun displayFailureRetrievingFrequency() { doSafelyWithView { view -> view.displayFailureRetrievingFrequency() } } - override fun displayIP(ip: String) { + private fun displayIP(ip: String) { doSafelyWithView { view -> view.displayIP(ip) } } - override fun displayFailureRetrievingIP() { + private fun displayFailureRetrievingIP() { doSafelyWithView { view -> view.displayFailureRetrievingIP() } } - override fun displayNearbyAccessPoints(accessPoints: List) { + private fun displayNearbyAccessPoints(accessPoints: List) { doSafelyWithView { view -> view.displayNearbyAccessPoints(accessPoints) } } - override fun displayNoAccessPointsFound() { + private fun displayNoAccessPointsFound() { doSafelyWithView { view -> view.displayNoAccessPointsFound() } } - override fun displayNoSavedNetworksFound() { + private fun displayNoSavedNetworksFound() { doSafelyWithView { view -> view.displayNoSavedNetworksFound() } } - override fun displaySavedNetworks(savedNetworks: List) { + private fun displaySavedNetworks(savedNetworks: List) { doSafelyWithView { view -> view.displaySavedNetworks(savedNetworks) } } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkFragment.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkFragment.kt index 3d7f6577..023a9840 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkFragment.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkFragment.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.ui.remove import android.Manifest.permission.ACCESS_WIFI_STATE @@ -5,17 +20,20 @@ import android.content.pm.PackageManager import android.os.Bundle import android.util.Log import android.view.View +import androidx.annotation.VisibleForTesting import com.isupatches.wisefy.constants.WiseFyCode import com.isupatches.wisefysample.R import com.isupatches.wisefysample.internal.base.BaseFragment import com.isupatches.wisefysample.internal.preferences.RemoveNetworkStore -import com.isupatches.wisefysample.internal.util.displayShortToast import com.isupatches.wisefysample.internal.util.getTrimmedInput import com.isupatches.wisefysample.internal.util.hideKeyboardFrom +import dagger.Binds +import dagger.Module + import kotlinx.android.synthetic.main.fragment_remove.removeNetworkBtn -import kotlinx.android.synthetic.main.fragment_remove.removeNetworkEdt +import kotlinx.android.synthetic.main.fragment_remove.networkNameEdt import javax.inject.Inject @@ -23,8 +41,7 @@ internal class RemoveNetworkFragment : BaseFragment(), RemoveNetworkMvp.View { override val layoutRes = R.layout.fragment_remove - private val presenter by lazy { RemoveNetworkPresenter(wiseFy) } - + @Inject lateinit var presenter: RemoveNetworkMvp.Presenter @Inject lateinit var removeNetworkStore: RemoveNetworkStore companion object { @@ -32,7 +49,7 @@ internal class RemoveNetworkFragment : BaseFragment(), RemoveNetworkMvp.View { fun newInstance() = RemoveNetworkFragment() - private const val WISEFY_REMOVE_NETWORK_REQUEST_CODE = 1 + @VisibleForTesting internal const val WISEFY_REMOVE_NETWORK_REQUEST_CODE = 1 } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -56,7 +73,7 @@ internal class RemoveNetworkFragment : BaseFragment(), RemoveNetworkMvp.View { override fun onStop() { presenter.detachView() super.onStop() - removeNetworkStore.setLastUsedRegex(removeNetworkEdt.getTrimmedInput()) + removeNetworkStore.setLastUsedRegex(networkNameEdt.getTrimmedInput()) hideKeyboardFrom(removeNetworkBtn) } @@ -66,7 +83,7 @@ internal class RemoveNetworkFragment : BaseFragment(), RemoveNetworkMvp.View { private fun restoreUI() { // Restore edit text value - removeNetworkEdt.setText(removeNetworkStore.getLastUsedRegex()) + networkNameEdt.setText(removeNetworkStore.getLastUsedRegex()) } /* @@ -74,15 +91,15 @@ internal class RemoveNetworkFragment : BaseFragment(), RemoveNetworkMvp.View { */ override fun displayNetworkRemoved() { - displayShortToast("Network removed") + displayInfo(R.string.network_removed, R.string.remover_network_result) } override fun displayNetworkNotFoundToRemove() { - displayShortToast("Network not found to remove") + displayInfo(R.string.network_not_found_to_remove, R.string.remover_network_result) } override fun displayFailureRemovingNetwork() { - displayShortToast("Failure removing network!") + displayInfo(R.string.failure_removing_network, R.string.remover_network_result) } override fun displayWiseFyFailure(@WiseFyCode wiseFyFailureCode: Int) { @@ -95,7 +112,7 @@ internal class RemoveNetworkFragment : BaseFragment(), RemoveNetworkMvp.View { private fun removeNetwork() { if (checkRemoveNetworkPermissions()) { - presenter.removeNetwork(removeNetworkEdt.getTrimmedInput()) + presenter.removeNetwork(networkNameEdt.getTrimmedInput()) } } @@ -114,13 +131,25 @@ internal class RemoveNetworkFragment : BaseFragment(), RemoveNetworkMvp.View { removeNetwork() } else { Log.w(TAG, "Permissions for remove saved network are denied") - // Display permission error here + displayPermissionErrorDialog(R.string.permission_error_remove_network) } } else -> { - // Display permission error here Log.wtf(TAG, "Weird permission requested, not handled") + displayPermissionErrorDialog( + getString(R.string.permission_error_unhandled_request_code_args, requestCode) + ) } } } + + /* + * Dagger + */ + + @Suppress("unused") + @Module internal interface RemoveNetworkFragmentModule { + @Binds fun bindRemoveNetworkModel(impl: RemoveNetworkModel): RemoveNetworkMvp.Model + @Binds fun bindRemoveNetworkPresenter(impl: RemoveNetworkPresenter): RemoveNetworkMvp.Presenter + } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkModel.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkModel.kt index e929da34..34289061 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkModel.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkModel.kt @@ -1,35 +1,34 @@ +/* + * Copyright 2019 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.wisefysample.ui.remove import android.Manifest.permission.ACCESS_WIFI_STATE import androidx.annotation.RequiresPermission -import com.isupatches.wisefy.WiseFy +import com.isupatches.wisefy.WiseFyPublicApi import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks -import com.isupatches.wisefy.constants.WiseFyCode -internal class RemoveNetworkModel( - private val presenter: RemoveNetworkMvp.Presenter, - private val wiseFy: WiseFy -): RemoveNetworkMvp.Model { +import javax.inject.Inject - @RequiresPermission(ACCESS_WIFI_STATE) - override fun removeNetwork(networkName: String) { - wiseFy.removeNetwork(networkName, object : RemoveNetworkCallbacks { - override fun networkRemoved() { - presenter.displayNetworkRemoved() - } - - override fun networkNotFoundToRemove() { - presenter.displayNetworkNotFoundToRemove() - } +internal class RemoveNetworkModel @Inject constructor( + private val wiseFy: WiseFyPublicApi +) : RemoveNetworkMvp.Model { - override fun failureRemovingNetwork() { - presenter.displayFailureRemovingNetwork() - } - - override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + @RequiresPermission(ACCESS_WIFI_STATE) + override fun removeNetwork(networkName: String, callbacks: RemoveNetworkCallbacks) { + wiseFy.removeNetwork(networkName, callbacks) } -} \ No newline at end of file +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkMvp.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkMvp.kt index de71a923..6178c6df 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkMvp.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkMvp.kt @@ -1,7 +1,24 @@ +/* + * Copyright 2019 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.wisefysample.ui.remove +import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks import com.isupatches.wisefysample.internal.base.BaseMvp +@Suppress("UndocumentedPublicClass", "UndocumentedPublicFunction") internal interface RemoveNetworkMvp { interface View : BaseMvp.View { @@ -11,21 +28,10 @@ internal interface RemoveNetworkMvp { } interface Presenter : BaseMvp.Presenter { - - /* - * Model call-throughs - */ fun removeNetwork(networkName: String) - - /* - * View callbacks - */ - fun displayNetworkRemoved() - fun displayNetworkNotFoundToRemove() - fun displayFailureRemovingNetwork() } interface Model { - fun removeNetwork(networkName: String) + fun removeNetwork(networkName: String, callbacks: RemoveNetworkCallbacks) } -} \ No newline at end of file +} diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkPresenter.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkPresenter.kt index cc4dfe55..35c2bafa 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkPresenter.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/remove/RemoveNetworkPresenter.kt @@ -1,16 +1,34 @@ +/* + * Copyright 2019 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.wisefysample.ui.remove import android.Manifest.permission.ACCESS_WIFI_STATE import androidx.annotation.RequiresPermission -import com.isupatches.wisefy.WiseFy +import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks +import com.isupatches.wisefy.constants.WiseFyCode import com.isupatches.wisefysample.internal.base.BasePresenter +import com.isupatches.wisefysample.internal.util.RxSchedulersProvider -internal class RemoveNetworkPresenter( - wiseFy: WiseFy -) : BasePresenter(), RemoveNetworkMvp.Presenter { +import javax.inject.Inject - private val model = RemoveNetworkModel(this, wiseFy) +internal class RemoveNetworkPresenter @Inject constructor( + private val model: RemoveNetworkMvp.Model, + rxSchedulersProvider: RxSchedulersProvider +) : BasePresenter(rxSchedulersProvider), RemoveNetworkMvp.Presenter { /* * Model call-throughs @@ -18,22 +36,38 @@ internal class RemoveNetworkPresenter( @RequiresPermission(ACCESS_WIFI_STATE) override fun removeNetwork(networkName: String) { - model.removeNetwork(networkName) + model.removeNetwork(networkName, object : RemoveNetworkCallbacks { + override fun networkRemoved() { + displayNetworkRemoved() + } + + override fun networkNotFoundToRemove() { + displayNetworkNotFoundToRemove() + } + + override fun failureRemovingNetwork() { + displayFailureRemovingNetwork() + } + + override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } /* * View callbacks */ - override fun displayNetworkRemoved() { + private fun displayNetworkRemoved() { doSafelyWithView { view -> view.displayNetworkRemoved() } } - override fun displayNetworkNotFoundToRemove() { + private fun displayNetworkNotFoundToRemove() { doSafelyWithView { view -> view.displayNetworkNotFoundToRemove() } } - override fun displayFailureRemovingNetwork() { + private fun displayFailureRemovingNetwork() { doSafelyWithView { view -> view.displayFailureRemovingNetwork() } } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchFragment.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchFragment.kt index f3b348a0..ce63aa7b 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchFragment.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchFragment.kt @@ -1,22 +1,42 @@ +/* + * Copyright 2019 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.wisefysample.ui.search -import android.Manifest +import android.Manifest.permission.ACCESS_COARSE_LOCATION import android.Manifest.permission.ACCESS_WIFI_STATE +import android.content.pm.PackageManager import android.net.wifi.ScanResult import android.net.wifi.WifiConfiguration import android.os.Bundle +import android.util.Log import android.view.View import android.widget.SeekBar +import androidx.annotation.VisibleForTesting import com.isupatches.wisefysample.R import com.isupatches.wisefysample.internal.models.SearchType import com.isupatches.wisefysample.internal.preferences.SearchStore import com.isupatches.wisefysample.internal.base.BaseFragment import com.isupatches.wisefysample.internal.util.asHtmlSpanned -import com.isupatches.wisefysample.internal.util.displayShortToast import com.isupatches.wisefysample.internal.util.getTrimmedInput import com.isupatches.wisefysample.internal.util.hideKeyboardFrom +import dagger.Binds +import dagger.Module + import kotlinx.android.synthetic.main.fragment_search.filterDupesRdg import kotlinx.android.synthetic.main.fragment_search.filterDupesTxt import kotlinx.android.synthetic.main.fragment_search.returnFullListRdg @@ -28,12 +48,12 @@ import kotlinx.android.synthetic.main.fragment_search.timeoutTxt import javax.inject.Inject +@Suppress("LargeClass") internal class SearchFragment : BaseFragment(), SearchMvp.View { override val layoutRes = R.layout.fragment_search - private val presenter by lazy { SearchPresenter(wiseFy) } - + @Inject lateinit var presenter: SearchMvp.Presenter @Inject lateinit var searchStore: SearchStore companion object { @@ -44,12 +64,14 @@ internal class SearchFragment : BaseFragment(), SearchMvp.View { private const val TIMEOUT_MIN = 1 private const val TIMEOUT_MAX = 60 - private const val WISEFY_SEARCH_FOR_SAVED_NETWORK_REQUEST_CODE = 1 - private const val WISEFY_SEARCH_FOR_SAVED_NETWORKS_REQUEST_CODE = 2 - private const val WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE = 3 - private const val WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE = 4 - private const val WISEFY_SEARCH_FOR_SSID_REQUEST_CODE = 5 - private const val WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE = 6 + private const val SEEK_MILLI_OFFSET = 1000 + + @VisibleForTesting internal const val WISEFY_SEARCH_FOR_SAVED_NETWORK_REQUEST_CODE = 1 + @VisibleForTesting internal const val WISEFY_SEARCH_FOR_SAVED_NETWORKS_REQUEST_CODE = 2 + @VisibleForTesting internal const val WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE = 3 + @VisibleForTesting internal const val WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE = 4 + @VisibleForTesting internal const val WISEFY_SEARCH_FOR_SSID_REQUEST_CODE = 5 + @VisibleForTesting internal const val WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE = 6 } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -131,7 +153,7 @@ internal class SearchFragment : BaseFragment(), SearchMvp.View { private fun getFilterDuplicates(): Boolean = filterDupesRdg.checkedRadioButtonId == R.id.yesFilterDupesRdb - private fun getSelectedTimeout(): Int = timeoutSeek.progress * 1000 + private fun getSelectedTimeout(): Int = timeoutSeek.progress * SEEK_MILLI_OFFSET private fun restoreUI() { // Restore edit text value @@ -158,7 +180,7 @@ internal class SearchFragment : BaseFragment(), SearchMvp.View { val fullListCheckedId = if (searchStore.shouldReturnFullList()) { R.id.yesFullListRdb } else { - R.id.noReturnFullListRdb + R.id.noFullListRdb } returnFullListRdg.check(fullListCheckedId) @@ -174,7 +196,7 @@ internal class SearchFragment : BaseFragment(), SearchMvp.View { val timeout = searchStore.getTimeout() timeoutSeek.progress = timeout timeoutTxt.text = getString(R.string.timeout_after_x_seconds_args_html, timeout).asHtmlSpanned() - when(searchStore.getSearchType()) { + when (searchStore.getSearchType()) { SearchType.SAVED_NETWORK -> adjustTimeoutVisibility(View.INVISIBLE) else -> toggleSeekVisibility() } @@ -185,19 +207,19 @@ internal class SearchFragment : BaseFragment(), SearchMvp.View { R.id.accessPointRdb -> { when (returnFullListRdg.checkedRadioButtonId) { R.id.yesFullListRdb -> searchForAccessPoints() - R.id.noReturnFullListRdb -> searchForAccessPoint() + R.id.noFullListRdb -> searchForAccessPoint() } } - R.id.ssidRdb -> { + R.id.savedNetworkRdb -> { when (returnFullListRdg.checkedRadioButtonId) { - R.id.yesFullListRdb -> searchForSSIDs() - R.id.noReturnFullListRdb -> searchForSSID() + R.id.yesFullListRdb -> searchForSavedNetworks() + R.id.noFullListRdb -> searchForSavedNetwork() } } - R.id.savedNetworkRdb -> { + R.id.ssidRdb -> { when (returnFullListRdg.checkedRadioButtonId) { - R.id.yesFullListRdb -> getSavedNetworks() - R.id.noReturnFullListRdb -> getSavedNetwork() + R.id.yesFullListRdb -> searchForSSIDs() + R.id.noFullListRdb -> searchForSSID() } } } @@ -221,7 +243,7 @@ internal class SearchFragment : BaseFragment(), SearchMvp.View { private fun toggleSeekVisibility() { when (returnFullListRdg.checkedRadioButtonId) { R.id.yesFullListRdb -> adjustTimeoutVisibility(View.INVISIBLE) - R.id.noReturnFullListRdb -> adjustTimeoutVisibility(View.VISIBLE) + R.id.noFullListRdb -> adjustTimeoutVisibility(View.VISIBLE) } } @@ -237,18 +259,6 @@ internal class SearchFragment : BaseFragment(), SearchMvp.View { * WiseFy helpers */ - private fun getSavedNetwork() { - if (checkSearchForSavedNetworkPermissions()) { - presenter.getSavedNetwork(searchRegexEdt.getTrimmedInput()) - } - } - - private fun getSavedNetworks() { - if (checkSearchForSavedNetworksPermissions()) { - presenter.getSavedNetworks(searchRegexEdt.getTrimmedInput()) - } - } - @Throws(SecurityException::class) private fun searchForAccessPoint() { if (checkSearchForAccessPointPermissions()) { @@ -263,6 +273,18 @@ internal class SearchFragment : BaseFragment(), SearchMvp.View { } } + private fun searchForSavedNetwork() { + if (checkSearchForSavedNetworkPermissions()) { + presenter.searchForSavedNetwork(searchRegexEdt.getTrimmedInput()) + } + } + + private fun searchForSavedNetworks() { + if (checkSearchForSavedNetworksPermissions()) { + presenter.searchForSavedNetworks(searchRegexEdt.getTrimmedInput()) + } + } + @Throws(SecurityException::class) private fun searchForSSID() { if (checkSearchForSSIDPermissions()) { @@ -282,51 +304,51 @@ internal class SearchFragment : BaseFragment(), SearchMvp.View { */ override fun displaySavedNetwork(savedNetwork: WifiConfiguration) { - displayShortToast("Saved network: $savedNetwork") + displayInfoFullScreen(getString(R.string.saved_network_args, savedNetwork), R.string.search_result) } override fun displaySavedNetworkNotFound() { - displayShortToast("Saved network not found") + displayInfo(R.string.saved_network_not_found, R.string.search_result) } override fun displaySavedNetworks(savedNetworks: List) { - displayShortToast("Saved networks: $savedNetworks") + displayInfo(getString(R.string.saved_networks_args, savedNetworks), R.string.search_result) } override fun displayNoSavedNetworksFound() { - displayShortToast("No saved networks found") + displayInfo(R.string.no_saved_networks_found, R.string.search_result) } override fun displayAccessPoint(accessPoint: ScanResult) { - displayShortToast("Access point: $accessPoint") + displayInfoFullScreen(getString(R.string.access_point_args, accessPoint), R.string.search_result) } override fun displayAccessPointNotFound() { - displayShortToast("Access point not found") + displayInfo(R.string.access_point_not_found, R.string.search_result) } override fun displayAccessPoints(accessPoints: List) { - displayShortToast("Access points: $accessPoints") + displayInfoFullScreen(getString(R.string.access_points_args, accessPoints), R.string.search_result) } override fun displayNoAccessPointsFound() { - displayShortToast("No access points found") + displayInfo(R.string.no_access_points_found, R.string.search_result) } override fun displaySSID(ssid: String) { - displayShortToast("SSID: $ssid") + displayInfoFullScreen(getString(R.string.ssid_args, ssid), R.string.search_result) } override fun displaySSIDNotFound() { - displayShortToast("SSID not found") + displayInfo(R.string.ssid_not_found, R.string.search_result) } override fun displaySSIDs(ssids: List) { - displayShortToast("SSIDs: $ssids") + displayInfoFullScreen(getString(R.string.ssids_args, ssids), R.string.search_result) } override fun displayNoSSIDsFound() { - displayShortToast("No SSIDs found") + displayInfo(R.string.no_ssids_found, R.string.search_result) } override fun displayWiseFyFailure(wiseFyFailureCode: Int) { @@ -346,22 +368,92 @@ internal class SearchFragment : BaseFragment(), SearchMvp.View { } private fun checkSearchForAccessPointPermissions(): Boolean { - return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE) - && isPermissionGranted(Manifest.permission.ACCESS_COARSE_LOCATION, WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE) + return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE) && + isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE) } private fun checkSearchForAccessPointsPermissions(): Boolean { - return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE) - && isPermissionGranted(Manifest.permission.ACCESS_COARSE_LOCATION, WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE) + return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE) && + isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE) } private fun checkSearchForSSIDPermissions(): Boolean { - return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_SEARCH_FOR_SSID_REQUEST_CODE) - && isPermissionGranted(Manifest.permission.ACCESS_COARSE_LOCATION, WISEFY_SEARCH_FOR_SSID_REQUEST_CODE) + return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_SEARCH_FOR_SSID_REQUEST_CODE) && + isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_SEARCH_FOR_SSID_REQUEST_CODE) } private fun checkSearchForSSIDsPermissions(): Boolean { - return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE) - && isPermissionGranted(Manifest.permission.ACCESS_COARSE_LOCATION, WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE) + return isPermissionGranted(ACCESS_WIFI_STATE, WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE) && + isPermissionGranted(ACCESS_COARSE_LOCATION, WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE) + } + + @Suppress("LongMethod", "ComplexMethod") + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + when (requestCode) { + WISEFY_SEARCH_FOR_SAVED_NETWORK_REQUEST_CODE -> { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + searchForSavedNetwork() + } else { + Log.w(TAG, "Permissions for getting a saved network are denied") + displayPermissionErrorDialog(R.string.permission_error_search_for_saved_network) + } + } + WISEFY_SEARCH_FOR_SAVED_NETWORKS_REQUEST_CODE -> { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + searchForSavedNetworks() + } else { + Log.w(TAG, "Permissions for getting saved networks are denied") + displayPermissionErrorDialog(R.string.permission_error_search_for_saved_networks) + } + } + WISEFY_SEARCH_FOR_ACCESS_POINT_REQUEST_CODE -> { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + searchForAccessPoint() + } else { + Log.w(TAG, "Permissions for searching for an access point are denied") + displayPermissionErrorDialog(R.string.permission_error_search_for_access_point) + } + } + WISEFY_SEARCH_FOR_ACCESS_POINTS_REQUEST_CODE -> { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + searchForAccessPoints() + } else { + Log.w(TAG, "Permissions for searching for access points are denied") + displayPermissionErrorDialog(R.string.permission_error_search_for_access_points) + } + } + WISEFY_SEARCH_FOR_SSID_REQUEST_CODE -> { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + searchForSSID() + } else { + Log.w(TAG, "Permissions for searching for an SSID are denied") + displayPermissionErrorDialog(R.string.permission_error_search_for_ssid) + } + } + WISEFY_SEARCH_FOR_SSIDS_REQUEST_CODE -> { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + searchForSSIDs() + } else { + Log.w(TAG, "Permissions for searching for SSIDs are denied") + displayPermissionErrorDialog(R.string.permission_error_search_for_ssids) + } + } + else -> { + Log.wtf(TAG, "Weird permission requested, not handled") + displayPermissionErrorDialog( + getString(R.string.permission_error_unhandled_request_code_args, requestCode) + ) + } + } + } + + /* + * Dagger + */ + + @Suppress("unused") + @Module internal interface SearchFragmentModule { + @Binds fun bindSearchModel(impl: SearchModel): SearchMvp.Model + @Binds fun bindSearchPresenter(impl: SearchPresenter): SearchMvp.Presenter } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchModel.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchModel.kt index 877d6dc3..5bec96d1 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchModel.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchModel.kt @@ -1,124 +1,84 @@ +/* + * Copyright 2019 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.wisefysample.ui.search import android.Manifest.permission.ACCESS_COARSE_LOCATION import android.Manifest.permission.ACCESS_WIFI_STATE -import android.net.wifi.ScanResult -import android.net.wifi.WifiConfiguration import androidx.annotation.RequiresPermission -import com.isupatches.wisefy.WiseFy -import com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks -import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks +import com.isupatches.wisefy.WiseFyPublicApi import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks -import com.isupatches.wisefy.constants.WiseFyCode +import com.isupatches.wisefy.callbacks.SearchForSavedNetworkCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworksCallbacks -internal class SearchModel( - private val presenter: SearchMvp.Presenter, - private val wiseFy: WiseFy -): SearchMvp.Model { +import javax.inject.Inject - @RequiresPermission(ACCESS_WIFI_STATE) - override fun getSavedNetwork(regexForSSID: String) { - wiseFy.getSavedNetwork(regexForSSID, object : GetSavedNetworkCallbacks { - override fun retrievedSavedNetwork(savedNetwork: WifiConfiguration) { - presenter.displaySavedNetwork(savedNetwork) - } - - override fun savedNetworkNotFound() { - presenter.displaySavedNetworkNotFound() - } - - override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) - } - - @RequiresPermission(ACCESS_WIFI_STATE) - override fun getSavedNetworks(regexForSSID: String) { - wiseFy.getSavedNetworks(regexForSSID, object : GetSavedNetworksCallbacks { - override fun retrievedSavedNetworks(savedNetworks: List) { - presenter.displaySavedNetworks(savedNetworks) - } - - override fun noSavedNetworksFound() { - presenter.displayNoSavedNetworksFound() - } - - override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) - } +internal class SearchModel @Inject constructor( + private val wiseFy: WiseFyPublicApi +) : SearchMvp.Model { @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - override fun searchForAccessPoint(regexForSSID: String, timeout: Int, filterDuplicates: Boolean) { - wiseFy.searchForAccessPoint(regexForSSID, timeout, filterDuplicates, object : SearchForAccessPointCallbacks { - override fun accessPointFound(accessPoint: ScanResult) { - presenter.displayAccessPoint(accessPoint) - } - - override fun accessPointNotFound() { - presenter.displayAccessPointNotFound() - } - - override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun searchForAccessPoint( + regexForSSID: String, + timeout: Int, + filterDuplicates: Boolean, + callbacks: SearchForAccessPointCallbacks + ) { + wiseFy.searchForAccessPoint(regexForSSID, timeout, filterDuplicates, callbacks) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - override fun searchForAccessPoints(regexForSSID: String, filterDuplicates: Boolean) { - wiseFy.searchForAccessPoints(regexForSSID, filterDuplicates, object : SearchForAccessPointsCallbacks { - override fun foundAccessPoints(accessPoints: List) { - presenter.displayAccessPoints(accessPoints) - } + override fun searchForAccessPoints( + regexForSSID: String, + filterDuplicates: Boolean, + callbacks: SearchForAccessPointsCallbacks + ) { + wiseFy.searchForAccessPoints(regexForSSID, filterDuplicates, callbacks) + } - override fun noAccessPointsFound() { - presenter.displayNoAccessPointsFound() - } + @RequiresPermission(ACCESS_WIFI_STATE) + override fun searchForSavedNetwork( + regexForSSID: String, + callbacks: SearchForSavedNetworkCallbacks + ) { + wiseFy.searchForSavedNetwork(regexForSSID, callbacks) + } - override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + @RequiresPermission(ACCESS_WIFI_STATE) + override fun searchForSavedNetworks( + regexForSSID: String, + callbacks: SearchForSavedNetworksCallbacks + ) { + wiseFy.searchForSavedNetworks(regexForSSID, callbacks) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - override fun searchForSSID(regexForSSID: String, timeout: Int) { - wiseFy.searchForSSID(regexForSSID, timeout, object : SearchForSSIDCallbacks { - override fun ssidFound(ssid: String) { - presenter.displaySSID(ssid) - } - - override fun ssidNotFound() { - presenter.displaySSIDNotFound() - } - - override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun searchForSSID( + regexForSSID: String, + timeout: Int, + callbacks: SearchForSSIDCallbacks + ) { + wiseFy.searchForSSID(regexForSSID, timeout, callbacks) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - override fun searchForSSIDs(regexForSSID: String) { - wiseFy.searchForSSIDs(regexForSSID, object : SearchForSSIDsCallbacks { - override fun retrievedSSIDs(ssids: List) { - presenter.displaySSIDs(ssids) - } - - override fun noSSIDsFound() { - presenter.displayNoSSIDsFound() - } - - override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { - presenter.displayWiseFyFailure(wisefyFailureCode) - } - }) + override fun searchForSSIDs(regexForSSID: String, callbacks: SearchForSSIDsCallbacks) { + wiseFy.searchForSSIDs(regexForSSID, callbacks) } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchMvp.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchMvp.kt index dc164229..bfee598f 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchMvp.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchMvp.kt @@ -1,13 +1,35 @@ +/* + * Copyright 2019 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.wisefysample.ui.search import android.net.wifi.ScanResult import android.net.wifi.WifiConfiguration + +import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks +import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks +import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks +import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworkCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworksCallbacks import com.isupatches.wisefysample.internal.base.BaseMvp +@Suppress("UndocumentedPublicClass", "UndocumentedPublicFunction") internal interface SearchMvp { interface View : BaseMvp.View { - fun displaySavedNetwork(savedNetwork: WifiConfiguration) fun displaySavedNetworkNotFound() fun displaySavedNetworks(savedNetworks: List) @@ -23,41 +45,29 @@ internal interface SearchMvp { } interface Presenter : BaseMvp.Presenter { - - /* - * Model call-throughs - */ - fun getSavedNetwork(regexForSSID: String) - fun getSavedNetworks(regexForSSID: String) fun searchForAccessPoint(regexForSSID: String, timeout: Int, filterDuplicates: Boolean) fun searchForAccessPoints(regexForSSID: String, filterDuplicates: Boolean) + fun searchForSavedNetwork(regexForSSID: String) + fun searchForSavedNetworks(regexForSSID: String) fun searchForSSID(regexForSSID: String, timeout: Int) fun searchForSSIDs(regexForSSID: String) - - /* - * View Callbacks - */ - fun displaySavedNetwork(savedNetwork: WifiConfiguration) - fun displaySavedNetworkNotFound() - fun displaySavedNetworks(savedNetworks: List) - fun displayNoSavedNetworksFound() - fun displayAccessPoint(accessPoint: ScanResult) - fun displayAccessPointNotFound() - fun displayAccessPoints(accessPoints: List) - fun displayNoAccessPointsFound() - fun displaySSID(ssid: String) - fun displaySSIDNotFound() - fun displaySSIDs(ssids: List) - fun displayNoSSIDsFound() } interface Model { - - fun getSavedNetwork(regexForSSID: String) - fun getSavedNetworks(regexForSSID: String) - fun searchForAccessPoint(regexForSSID: String, timeout: Int, filterDuplicates: Boolean) - fun searchForAccessPoints(regexForSSID: String, filterDuplicates: Boolean) - fun searchForSSID(regexForSSID: String, timeout: Int) - fun searchForSSIDs(regexForSSID: String) + fun searchForAccessPoint( + regexForSSID: String, + timeout: Int, + filterDuplicates: Boolean, + callbacks: SearchForAccessPointCallbacks + ) + fun searchForAccessPoints( + regexForSSID: String, + filterDuplicates: Boolean, + callbacks: SearchForAccessPointsCallbacks + ) + fun searchForSavedNetwork(regexForSSID: String, callbacks: SearchForSavedNetworkCallbacks) + fun searchForSavedNetworks(regexForSSID: String, callbacks: SearchForSavedNetworksCallbacks) + fun searchForSSID(regexForSSID: String, timeout: Int, callbacks: SearchForSSIDCallbacks) + fun searchForSSIDs(regexForSSID: String, callbacks: SearchForSSIDsCallbacks) } } diff --git a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchPresenter.kt b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchPresenter.kt index 878eb0cc..023f9720 100644 --- a/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchPresenter.kt +++ b/wisefysample/src/main/java/com/isupatches/wisefysample/ui/search/SearchPresenter.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.wisefysample.ui.search import android.Manifest.permission.ACCESS_COARSE_LOCATION @@ -6,96 +21,184 @@ import android.net.wifi.ScanResult import android.net.wifi.WifiConfiguration import androidx.annotation.RequiresPermission -import com.isupatches.wisefy.WiseFy +import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks +import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks +import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks +import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworkCallbacks +import com.isupatches.wisefy.callbacks.SearchForSavedNetworksCallbacks +import com.isupatches.wisefy.constants.WiseFyCode import com.isupatches.wisefysample.internal.base.BasePresenter +import com.isupatches.wisefysample.internal.util.RxSchedulersProvider -internal class SearchPresenter( - wiseFy: WiseFy -) : BasePresenter(), SearchMvp.Presenter { +import javax.inject.Inject - private val model = SearchModel(this, wiseFy) +internal class SearchPresenter @Inject constructor( + private val model: SearchMvp.Model, + rxSchedulersProvider: RxSchedulersProvider +) : BasePresenter(rxSchedulersProvider), SearchMvp.Presenter { /* * Model call-throughs */ - override fun getSavedNetwork(regexForSSID: String) { - model.getSavedNetwork(regexForSSID) + @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) + override fun searchForAccessPoint( + regexForSSID: String, + timeout: Int, + filterDuplicates: Boolean + ) { + model.searchForAccessPoint( + regexForSSID, + timeout, + filterDuplicates, + object : SearchForAccessPointCallbacks { + override fun accessPointFound(accessPoint: ScanResult) { + displayAccessPoint(accessPoint) + } + + override fun accessPointNotFound() { + displayAccessPointNotFound() + } + + override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } - override fun getSavedNetworks(regexForSSID: String) { - model.getSavedNetworks(regexForSSID) + @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) + override fun searchForAccessPoints(regexForSSID: String, filterDuplicates: Boolean) { + model.searchForAccessPoints(regexForSSID, filterDuplicates, object : SearchForAccessPointsCallbacks { + override fun foundAccessPoints(accessPoints: List) { + displayAccessPoints(accessPoints) + } + + override fun noAccessPointsFound() { + displayNoAccessPointsFound() + } + + override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } - @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - override fun searchForAccessPoint(regexForSSID: String, timeout: Int, filterDuplicates: Boolean) { - model.searchForAccessPoint(regexForSSID, timeout, filterDuplicates) + override fun searchForSavedNetwork(regexForSSID: String) { + model.searchForSavedNetwork(regexForSSID, object : SearchForSavedNetworkCallbacks { + override fun retrievedSavedNetwork(savedNetwork: WifiConfiguration) { + displaySavedNetwork(savedNetwork) + } + + override fun savedNetworkNotFound() { + displaySavedNetworkNotFound() + } + + override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } - @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) - override fun searchForAccessPoints(regexForSSID: String, filterDuplicates: Boolean) { - model.searchForAccessPoints(regexForSSID, filterDuplicates) + override fun searchForSavedNetworks(regexForSSID: String) { + model.searchForSavedNetworks(regexForSSID, object : SearchForSavedNetworksCallbacks { + override fun retrievedSavedNetworks(savedNetworks: List) { + displaySavedNetworks(savedNetworks) + } + + override fun noSavedNetworksFound() { + displayNoSavedNetworksFound() + } + + override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) override fun searchForSSID(regexForSSID: String, timeout: Int) { - model.searchForSSID(regexForSSID, timeout) + model.searchForSSID(regexForSSID, timeout, object : SearchForSSIDCallbacks { + override fun ssidFound(ssid: String) { + displaySSID(ssid) + } + + override fun ssidNotFound() { + displaySSIDNotFound() + } + + override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } @RequiresPermission(allOf = [ACCESS_COARSE_LOCATION, ACCESS_WIFI_STATE]) override fun searchForSSIDs(regexForSSID: String) { - model.searchForSSIDs(regexForSSID) + model.searchForSSIDs(regexForSSID, object : SearchForSSIDsCallbacks { + override fun retrievedSSIDs(ssids: List) { + displaySSIDs(ssids) + } + + override fun noSSIDsFound() { + displayNoSSIDsFound() + } + + override fun wisefyFailure(@WiseFyCode wisefyFailureCode: Int) { + displayWiseFyFailure(wisefyFailureCode) + } + }) } /* * View callbacks */ - override fun displaySavedNetwork(savedNetwork: WifiConfiguration) { + private fun displaySavedNetwork(savedNetwork: WifiConfiguration) { doSafelyWithView { view -> view.displaySavedNetwork(savedNetwork) } } - override fun displaySavedNetworkNotFound() { + private fun displaySavedNetworkNotFound() { doSafelyWithView { view -> view.displaySavedNetworkNotFound() } } - override fun displaySavedNetworks(savedNetworks: List) { + private fun displaySavedNetworks(savedNetworks: List) { doSafelyWithView { view -> view.displaySavedNetworks(savedNetworks) } } - override fun displayNoSavedNetworksFound() { + private fun displayNoSavedNetworksFound() { doSafelyWithView { view -> view.displayNoSavedNetworksFound() } } - override fun displayAccessPoint(accessPoint: ScanResult) { + private fun displayAccessPoint(accessPoint: ScanResult) { doSafelyWithView { view -> view.displayAccessPoint(accessPoint) } } - override fun displayAccessPointNotFound() { + private fun displayAccessPointNotFound() { doSafelyWithView { view -> view.displayAccessPointNotFound() } } - override fun displayAccessPoints(accessPoints: List) { + private fun displayAccessPoints(accessPoints: List) { doSafelyWithView { view -> view.displayAccessPoints(accessPoints) } } - override fun displayNoAccessPointsFound() { + private fun displayNoAccessPointsFound() { doSafelyWithView { view -> view.displayNoAccessPointsFound() } } - override fun displaySSID(ssid: String) { + private fun displaySSID(ssid: String) { doSafelyWithView { view -> view.displaySSID(ssid) } } - override fun displaySSIDNotFound() { + private fun displaySSIDNotFound() { doSafelyWithView { view -> view.displaySSIDNotFound() } } - override fun displaySSIDs(ssids: List) { + private fun displaySSIDs(ssids: List) { doSafelyWithView { view -> view.displaySSIDs(ssids) } } - override fun displayNoSSIDsFound() { + private fun displayNoSSIDsFound() { doSafelyWithView { view -> view.displayNoSSIDsFound() } } } diff --git a/wisefysample/src/main/res/drawable/ic_launcher_background.xml b/wisefysample/src/main/res/drawable/ic_launcher_background.xml index 91fd4e4a..7c1db8e7 100644 --- a/wisefysample/src/main/res/drawable/ic_launcher_background.xml +++ b/wisefysample/src/main/res/drawable/ic_launcher_background.xml @@ -1,9 +1,14 @@ - - - + android:height="108dp" + android:viewportWidth="108" + android:viewportHeight="108"> + + diff --git a/wisefysample/src/main/res/drawable/ic_launcher_foreground.xml b/wisefysample/src/main/res/drawable/ic_launcher_foreground.xml index 6ec36c05..9419423f 100644 --- a/wisefysample/src/main/res/drawable/ic_launcher_foreground.xml +++ b/wisefysample/src/main/res/drawable/ic_launcher_foreground.xml @@ -1,13 +1,10 @@ - - - + + + + diff --git a/wisefysample/src/main/res/drawable/ic_logo.xml b/wisefysample/src/main/res/drawable/ic_logo.xml new file mode 100644 index 00000000..16ce541a --- /dev/null +++ b/wisefysample/src/main/res/drawable/ic_logo.xml @@ -0,0 +1,9 @@ + + + + diff --git a/wisefysample/src/main/res/layout/dialog_base.xml b/wisefysample/src/main/res/layout/dialog_base.xml new file mode 100644 index 00000000..e923f0c0 --- /dev/null +++ b/wisefysample/src/main/res/layout/dialog_base.xml @@ -0,0 +1,64 @@ + + + + + + + +