-
Notifications
You must be signed in to change notification settings - Fork 197
feat(wifi_basic): plugin added #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
daadu
wants to merge
31
commits into
master
Choose a base branch
from
wifi_basic
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
44488d8
[wifi_basic] plugin created from flutter template
daadu 52d10a3
[ci] `wifi_basic`: workflow file added
daadu 5549592
- [pubspec] homepage link added
daadu b97974b
[ci,all_plugins] added `--no-select` option
daadu 77a4d8f
proper org name as reverse domain name
daadu bb3f0fd
Merge branch 'master' into wifi_basic
daadu f911faa
Merge branch 'master' into wifi_basic
daadu 15dadec
Merge branch 'master' into wifi_basic
daadu 05ccf12
- [wifi_basic] class renamed to `WiFiBasic`, basic methods added
daadu c0298d6
formatting
daadu 65b2bcd
- [android] handling methods - `hasCapability`, `isEnabled`, `setEnab…
daadu 6a34081
formatting
daadu d76c381
- [wifi_basic,android] `WiFiBasic`, `WifiBasicPlugin`: `setEnabled` -…
daadu 42581de
- [ios] `SwiftWifiBasicPlugin`: implemented `hasCapability`, `isEnabl…
daadu 793c651
- [ios] formatting with Xcode - ctrl+I
daadu 47349d7
[wifi_basic] renamed - `hasCapability` -> `isSupported`
daadu a38aef3
[android] making `context` non-nullable and lateinit
daadu 02f1496
`WiFiBasic` as singleton - can be access by `WiFiBasic.instance`, made
daadu 98b245b
`WiFiBasic`: minor re-arragne
daadu 6043606
- [wifi_basic] `WiFiGenerations` enum added
daadu 0edea8b
- [wifi_basic,pubspec] added `async` as dependency
daadu 77cb7c9
[wifi_basic,pubspec] downgrade `async` because of conflict
daadu 51ce1a8
- [wifi_basic] `WiFiInfo` class, `WiFiNetworkSecurity` enum and `WiFi…
daadu 4899fea
[wifi_ios] fix
daadu 2336752
[wifi_scan,android] removed unnecessary TODOs
daadu bb846dc
[wifi_scan,license] MIT license added
daadu a3736ca
[ios] dropped support for 8.0
daadu 0eafba3
Merge branch 'master' into wifi_basic
daadu e7792e0
[pubspec] pointing homepage to `flutternetwork`
daadu 92447f5
[license] minor - synced
daadu 9c3d992
- [lint] removed `analysis_options` from wifi_basic package, using gl…
daadu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Build wifi_basic example | ||
name: wifi_basic | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "packages/wifi_basic/**" | ||
- ".github/workflows/wifi_basic.yaml" | ||
|
||
env: | ||
PLUGIN_SCOPE: "*wifi_basic*" | ||
PLUGIN_EXAMPLE_SCOPE: "*wifi_basic_example*" | ||
|
||
jobs: | ||
android: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- name: "Checkout repository" | ||
uses: actions/checkout@v2 | ||
- name: "Install Flutter" | ||
run: ./.github/workflows/scripts/install-flutter.sh stable | ||
- name: "Install Tools" | ||
run: ./.github/workflows/scripts/install-tools.sh | ||
- name: "Build Example" | ||
run: ./.github/workflows/scripts/build-examples.sh android ./lib/main.dart | ||
|
||
ios: | ||
runs-on: macos-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- name: "Checkout repository" | ||
uses: actions/checkout@v2 | ||
- name: "Install Flutter" | ||
run: ./.github/workflows/scripts/install-flutter.sh stable | ||
- name: "Install Tools" | ||
run: ./.github/workflows/scripts/install-tools.sh | ||
- name: "Build Example" | ||
run: ./.github/workflows/scripts/build-examples.sh ios ./lib/main.dart | ||
|
||
# macos: | ||
# runs-on: macos-latest | ||
# timeout-minutes: 30 | ||
# steps: | ||
# - name: "Checkout repository" | ||
# uses: actions/checkout@v2 | ||
# - name: "Install Flutter" | ||
# run: ./.github/workflows/scripts/install-flutter.sh stable | ||
# - name: "Install Tools" | ||
# run: ./.github/workflows/scripts/install-tools.sh | ||
# - name: "Build Example" | ||
# run: ./.github/workflows/scripts/build-examples.sh macos ./lib/main.dart | ||
|
||
# linux: | ||
# runs-on: ubuntu-latest | ||
# timeout-minutes: 30 | ||
# steps: | ||
# - name: "Checkout repository" | ||
# uses: actions/checkout@v2 | ||
# - name: "Install Flutter" | ||
# run: ./.github/workflows/scripts/install-flutter.sh stable | ||
# - name: "Install Tools" | ||
# run: ./.github/workflows/scripts/install-tools.sh | ||
# - name: "Build Example" | ||
# run: ./.github/workflows/scripts/build-examples.sh linux ./lib/main.dart | ||
|
||
# windows: | ||
# runs-on: ubuntu-latest | ||
# timeout-minutes: 30 | ||
# steps: | ||
# - name: "Checkout repository" | ||
# uses: actions/checkout@v2 | ||
# - name: "Install Flutter" | ||
# run: ./.github/workflows/scripts/install-flutter.sh stable | ||
# - name: "Install Tools" | ||
# run: ./.github/workflows/scripts/install-tools.sh | ||
# - name: "Build Example" | ||
# run: ./.github/workflows/scripts/build-examples.sh windows ./lib/main.dart | ||
|
||
# web: | ||
# runs-on: ubuntu-latest | ||
# timeout-minutes: 30 | ||
# steps: | ||
# - name: "Checkout repository" | ||
# uses: actions/checkout@v2 | ||
# - name: "Install Flutter" | ||
# run: ./.github/workflows/scripts/install-flutter.sh stable | ||
# - name: "Install Tools" | ||
# run: ./.github/workflows/scripts/install-tools.sh | ||
# - name: "Build Example" | ||
# run: ./.github/workflows/scripts/build-examples.sh web ./lib/main.dart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
.dart_tool/ | ||
|
||
.packages | ||
.pub/ | ||
|
||
build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 18116933e77adc82f80866c928266a5b4f1ed645 | ||
channel: stable | ||
|
||
project_type: plugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 | ||
|
||
* TODO: Describe initial release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2022 WiFiFlutter | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# wifi_basic | ||
|
||
Flutter plugin for basic WiFi information and functionalities. | ||
|
||
## Getting Started | ||
|
||
This project is a starting point for a Flutter | ||
[plug-in package](https://flutter.dev/developing-packages/), | ||
a specialized package that includes platform-specific implementation code for | ||
Android and/or iOS. | ||
|
||
For help getting started with Flutter, view our | ||
[online documentation](https://flutter.dev/docs), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
group 'dev.flutternetwork.wifi.wifi_basic' | ||
version '1.0-SNAPSHOT' | ||
|
||
buildscript { | ||
ext.kotlin_version = '1.3.50' | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:4.1.0' | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
} | ||
} | ||
|
||
rootProject.allprojects { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
|
||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
android.useAndroidX=true | ||
android.enableJetifier=true |
5 changes: 5 additions & 0 deletions
5
packages/wifi_basic/android/gradle/wrapper/gradle-wrapper.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = 'wifi_basic' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dev.flutternetwork.wifi.wifi_basic"> | ||
</manifest> |
83 changes: 83 additions & 0 deletions
83
.../wifi_basic/android/src/main/kotlin/dev/flutternetwork/wifi/wifi_basic/WifiBasicPlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package dev.flutternetwork.wifi.wifi_basic | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.net.wifi.ScanResult | ||
import android.net.wifi.WifiManager | ||
import android.os.Build | ||
import android.provider.Settings | ||
import androidx.annotation.NonNull | ||
|
||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler | ||
import io.flutter.plugin.common.MethodChannel.Result | ||
|
||
/** WifiBasicPlugin */ | ||
class WifiBasicPlugin : FlutterPlugin, MethodCallHandler { | ||
/// The MethodChannel that will the communication between Flutter and native Android | ||
/// | ||
/// This local reference serves to register the plugin with the Flutter Engine and unregister it | ||
/// when the Flutter Engine is detached from the Activity | ||
private lateinit var channel: MethodChannel | ||
private lateinit var context: Context | ||
private var wifi: WifiManager? = null | ||
|
||
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { | ||
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "wifi_basic") | ||
channel.setMethodCallHandler(this) | ||
context = flutterPluginBinding.applicationContext | ||
wifi = | ||
context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager | ||
} | ||
|
||
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { | ||
when (call.method) { | ||
"isSupported" -> result.success(isSupported()) | ||
"getGeneration" -> result.success(getGeneration()) | ||
"isEnabled" -> result.success(isEnabled()) | ||
"setEnabled" -> { | ||
val enabled = call.argument<Boolean>("enabled") | ||
?: return result.error("InvalidArg", "enabled argument is null", null) | ||
result.success(setEnabled(enabled)) | ||
} | ||
"openSettings" -> { | ||
openSettings() | ||
result.success(null) | ||
} | ||
else -> result.notImplemented() | ||
} | ||
} | ||
|
||
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { | ||
channel.setMethodCallHandler(null) | ||
wifi = null | ||
} | ||
|
||
private fun isSupported(): Boolean = | ||
wifi != null && context.packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI) | ||
|
||
private fun getGeneration(): Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) when { | ||
wifi!!.isWifiStandardSupported(ScanResult.WIFI_STANDARD_11AX) -> 6 | ||
wifi!!.isWifiStandardSupported(ScanResult.WIFI_STANDARD_11AC) -> 5 | ||
wifi!!.isWifiStandardSupported(ScanResult.WIFI_STANDARD_11N) -> 4 | ||
wifi!!.isWifiStandardSupported(ScanResult.WIFI_STANDARD_LEGACY) -> 3 | ||
else -> -1 | ||
} else { | ||
// TODO: figure out based on link speed - https://stackoverflow.com/a/20970073/2554745 | ||
-1 | ||
} | ||
|
||
private fun isEnabled(): Boolean = wifi!!.isWifiEnabled | ||
|
||
private fun setEnabled(enabled: Boolean): Boolean = | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) wifi!!.setWifiEnabled(enabled) else false | ||
|
||
private fun openSettings() { | ||
val intent = Intent(Settings.ACTION_WIFI_SETTINGS) | ||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
context.startActivity(intent) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 18116933e77adc82f80866c928266a5b4f1ed645 | ||
channel: stable | ||
|
||
project_type: app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# wifi_basic_example | ||
|
||
Demonstrates how to use the wifi_basic plugin. | ||
|
||
## Getting Started | ||
|
||
This project is a starting point for a Flutter application. | ||
|
||
A few resources to get you started if this is your first Flutter project: | ||
|
||
- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) | ||
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) | ||
|
||
For help getting started with Flutter, view our | ||
[online documentation](https://flutter.dev/docs), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.