Skip to content

Conversation

@daadu
Copy link
Member

@daadu daadu commented Oct 29, 2020

Picking up with changes in Flutter (Android side) and Android SDK

TODO

  • migrate to Android v2 Embedding [doc]
  • migrate to androidx dependencies (example app) [docs]
  • upgrade default compile SDK (29 0r 30) and gradle version (latest) (plugin and example app)
  • handle deprecated methods in Android SDK >= 29 [ref]
    • Wifi methods changed
      • loadWifiList(poResult);
        • WifiManager.startScan [deprecated in API 28] will not be supported in future, Lint is not giving warnings though.
        • Use cached result via WifiManger.getScanResult
      • setEnabled(poCall, poResult);
        • WifiManager.setWifiEnabled [deprecated in API 29] it will always fails
        • Add warning in the docs for the usage
      • connect(poCall, poResult);
        • connectTo method called in connect uses a lot of deprecated classes and methods
        • rename old connectTo to connectToDeprecated and add new implementation in connectTo
        • add warning in readme as WEP is not supported
      • findAndConnect(poCall, poResult);
        • same as connect
      • isConnected(poResult);
        • remove NetworkInfo from import
        • ConnectionManager.getNetworkInfo [deprecated in API 23], Lint is not giving warnings though.
        • rename old isConnected to isConnectedDeprecated and add new implementation
      • disconnect(poResult);
        • WifiManger.disconnect [deprecated in API 29]
        • use ConnectivityManager.unregisterCallback to disconnect for API >= 29
      • removeWifiNetwork(poCall, poResult);
        • WifiManager.getConfiguredNetworks [deprecated in API 29], WifiManager.removeNetwork [deprecated in API 29], WifiConfiguration [deprecated in API 29]
        • add error for API >= 29
        • add warning to readme
      • isRegisteredWifiNetwork(poCall, poResult);
        • WifiManager.getConfiguredNetworks [deprecated in API 29], WifiManager.removeNetwork [deprecated in API 29], WifiConfiguration [deprecated in API 29]
        • add error for API >= 29
        • add warning to readme
    • Access Point methods
      • getWiFiAPSSID(poResult);
        • WifiConfiguration [deprecated in API 29]
      • setWiFiAPSSID(poCall, poResult);
        • WifiConfiguration [deprecated in API 29]
      • isSSIDHidden(poResult);
        • WifiConfiguration [deprecated in API 29]
      • setSSIDHidden(poCall, poResult);
        • WifiConfiguration [deprecated in API 29]
      • getWiFiAPPreSharedKey(poResult);
        • WifiConfiguration [deprecated in API 29]
      • setWiFiAPPreSharedKey(poCall, poResult);
        • WifiConfiguration [deprecated in API 29]
  • other changes/refactor
    • remove unused sudoForResult and related methods.
    • replaces android.permission.ACCESS_COARSE_LOCATION with android.permission.ACCESS_FINE_LOCATION, since the documentation suggest it now.
  • resolve deprecation warning while flutter build apk

Note for tester/reviewers

All the changes should be backward compatible, ie. should work with all flutter app as it is by just upgrading the package version. There for I encourage the reviewer to test both scenarios (>=29 and < 29; embedding v1 and v2).

To test this branch use the following in dependencies in puspec.yaml of your app:

dependencies:
  wifi_iot:
    git: 
      url: https://github.com/daadu/WiFiFlutter.git
      ref: android-major-revamp

This PR should potentially resolve following issues:

…WithContext` and `initWithActivity` method; added `cleanup` method

- [WifiIotPlugin] added `FlutterPlugin` and `ActivityAware` interfaces and override associated methods
daadu added 3 commits October 29, 2020 10:48
- [example,android] upgraded `compileSDKVersion` to 29 and build tool to `4.1.0` and gradle to `6.5`
- [example,android] migrated to androidx
- [flutter] `pubspec.lock` upgraded
- [android] removed `WifiConfiguration` from import since deprecated, using full class name instead
- [android] `loadWifiList`: only calling `WifiManager.startScan` for API < 28
- [readme] added warning (5) for "Enabling / Disabling WiFi module" for android platform
…ted`, implemented latest APIs for connecting

- [readme] added warning for WEP deprecation for android platform
@Niek
Copy link
Contributor

Niek commented Oct 29, 2020

Great work @daadu! I tested your branch and it works fine, no errors or issues in the functions that we use: loadWifiList() and connect()/disconnect().

BTW there's a new official plugin that offers some "info" functions: https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter/wifi_info_flutter

@daadu
Copy link
Member Author

daadu commented Oct 29, 2020

Great work @daadu! I tested your branch and it works fine, no errors or issues in the functions that we use: loadWifiList() and connect()/disconnect().

did you test with both sets: Android SDK >=29 and < 29; Android Embedding v1 and v2?

BTW there's a new official plugin that offers some "info" functions: https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter/wifi_info_flutter

Will think of add this once the mammoth is dealt with!

daadu added 2 commits October 29, 2020 16:21
…xample app

- [android] `isConnected`: moved old logic to `isConnectedDeprecated` and implemented with new APIs
@daadu
Copy link
Member Author

daadu commented Oct 29, 2020

@Alternadom sudoForResult, readFully, Closer methods/classes where unused, I have removed. Are they of any use?

daadu added 3 commits October 30, 2020 16:49
…ilable`

- [android] `disconnect`: added new SDK implementations
…error for SDK >= 29

- [readme] added warning for Registering/Unregistering an Wifi Network
- [readme] added warning for Connecting/Disconnecting on a network
@daadu
Copy link
Member Author

daadu commented Nov 3, 2020

Seems like Access Point methods are complicated using "mirrors" (hidden API) and there has been no issue raised for AP, hence this PR will not cover it.

There for #83 is out of scope of this PR.

@daadu daadu marked this pull request as ready for review November 3, 2020 06:40
@daadu
Copy link
Member Author

daadu commented Nov 3, 2020

@Niek @krishnaaro Please test and review this.

@daadu
Copy link
Member Author

daadu commented Nov 3, 2020

unlinking #78 since AP is out of scope of this PR

@daadu daadu changed the title Major Android Revamp Major Android Revamp [Wifi Only] Nov 3, 2020
@daadu daadu marked this pull request as draft November 3, 2020 07:24
…cm.getActiveNetwork`, since it was returning network only when internet was present
@daadu daadu marked this pull request as ready for review November 10, 2020 13:05
@daadu
Copy link
Member Author

daadu commented Nov 10, 2020

@Alternadom This PR LGTM.

Just to be safe can we release this as "alpa" on pub.dev, and then maybe after few weeks push to main version. I was thinking something like 1.1.2-alpha.0 for now.

@daadu
Copy link
Member Author

daadu commented Nov 12, 2020

Although I found it later, this article/post is a good resource that explains and clarifies the new APIs.

@Niek
Copy link
Contributor

Niek commented Nov 19, 2020

Thanks for the amazing work @daadu! Is this ready for merging yet?

@daadu
Copy link
Member Author

daadu commented Nov 19, 2020

Thanks for the amazing work @daadu! Is this ready for merging yet?

Your welcome @Niek. It LGTM for merging, as mentioned before, would like if this changes are released as "alpha" (something like v1.1.2-alpha.0) before proper release with v1.1.2

@Niek
Copy link
Contributor

Niek commented Nov 19, 2020

Great, I do see one exception when changing target SDK to 30, but not sure if it's coming from this plugin:

W/ConnectionTracker(21779): Exception thrown while unbinding
W/ConnectionTracker(21779): java.lang.IllegalArgumentException: Service not registered: lp@3865763
W/ConnectionTracker(21779):     at android.app.LoadedApk.forgetServiceDispatcher(Unknown Source:195)
W/ConnectionTracker(21779):     at android.app.ContextImpl.unbindService(Unknown Source:11)
W/ConnectionTracker(21779):     at android.content.ContextWrapper.unbindService(Unknown Source:2)
W/ConnectionTracker(21779):     at ci.f(:com.google.android.gms.dynamite_measurementdynamite@204217081@20.42.17 (120400-0):1)
W/ConnectionTracker(21779):     at ci.d(:com.google.android.gms.dynamite_measurementdynamite@204217081@20.42.17 (120400-0):2)
W/ConnectionTracker(21779):     at lq.D(:com.google.android.gms.dynamite_measurementdynamite@204217081@20.42.17 (120400-0):10)
W/ConnectionTracker(21779):     at lc.a(:com.google.android.gms.dynamite_measurementdynamite@204217081@20.42.17 (120400-0):2)
W/ConnectionTracker(21779):     at ee.run(:com.google.android.gms.dynamite_measurementdynamite@204217081@20.42.17 (120400-0):3)
W/ConnectionTracker(21779):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
W/ConnectionTracker(21779):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/ConnectionTracker(21779):     at ix.run(:com.google.android.gms.dynamite_measurementdynamite@204217081@20.42.17 (120400-0):6)

@daadu
Copy link
Member Author

daadu commented Nov 19, 2020

@Niek Android SDK 30 (flutter/engine#20479) is not still supported by flutter engine in stable channel. Although it has been merged with master, so could be available master or dev.

Try with 29 and/or change the flutter channel and test with 30.

@daadu
Copy link
Member Author

daadu commented Nov 19, 2020

@Niek Also did the functionality worked (disrespect of the logs)?

@daadu
Copy link
Member Author

daadu commented Nov 19, 2020

@Niek Also the error looks like firebase plugin issue [ firebase/firebase-android-sdk#1662 ]

@daadu
Copy link
Member Author

daadu commented Nov 19, 2020

@Niek Looks like firebase is not ready for v30!!

@daadu
Copy link
Member Author

daadu commented Nov 21, 2020

#85 reported issue with internet connectivity after connecting to wifi.

@florian-guillemard florian-guillemard merged commit b177c40 into flutternetwork:master Nov 25, 2020
@daadu daadu deleted the android-major-revamp branch January 28, 2021 13:25
daadu pushed a commit that referenced this pull request May 12, 2021
Major Android Revamp [Wifi Only]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

findAndConnect returns FALSE in android 10 WiFiForIoTPlugin.connect always returns false Doesn't work with Android targetSdk 29

3 participants