Skip to content
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

NetworkType #9

Open
2math opened this issue May 26, 2021 · 2 comments
Open

NetworkType #9

2math opened this issue May 26, 2021 · 2 comments

Comments

@2math
Copy link

2math commented May 26, 2021

Hi, thanks for this great plugin!

I'm currently testing the abilities with the example app and I'm noticing something strange with the NetworkTypes.

When I set NetworkType.notRequired , the task is not executing until I enable the WiFi and connect to the router, like is set NetworkType.unmetered.

If I set NetworkType.unmetered , the task is executing even if the WiFi is off and I'm connected on the mobile network only, like should be for NetworkType.connected.

If I set NetworkType.connected, the task is executing even if the WiFi and Mobile data are off, like should be for NetworkType.notRequired.

I'm testing with the example app on Pixel XL 3a - Android 11

/// Enqueues a work request to update the counter.
void _increaseCounter(int counter) {
enqueueWorkIntent(WorkIntent(
identifier: kTagCounterWork,
constraints: WorkConstraints(networkType: NetworkType.connected),
input: <String, dynamic>{
'counter': counter,
},
isProcessingTask: true,
));
}

[√] Flutter (Channel dev, 1.26.0-1.0.pre, on Microsoft Windows [Version 10.0.19041.985], locale bg-BG)
• Flutter version 1.26.0-1.0.pre at C:\code\soft\flutter_sdk\flutter
• Framework revision 63062a6443 (5 months ago), 2020-12-13 23:19:13 +0800
• Engine revision 4797b06652
• Dart version 2.12.0 (build 2.12.0-141.0.dev)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:/Users/x/AppData/Local/Android/Sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = C:/Users/x/AppData/Local/Android/Sdk
• Java binary at: C:\code\soft\android-studio-ide-4.1.3\android-studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.1.0)
• Android Studio at C:\code\soft\android-studio-ide-4.1.3\android-studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (3 available)
• Pixel 3a XL (mobile) • 94DAX0DRW1 • android-arm64 • Android 11 (API 30)
• Chrome (web) • chrome • web-javascript • Google Chrome 90.0.4430.212
• Edge (web) • edge • web-javascript • Microsoft Edge 90.0.818.62

• No issues found!

@2math
Copy link
Author

2math commented Jun 2, 2021

I think the problem is how the NetworkConstrains are parsed on android side

 builder.setRequiredNetworkType(
          NetworkType.values()[(Integer) constraintsJson.get("networkType")]);

The order is different btw Dart and Java enums and currently the order position is sent

Here is the Dart enum

enum NetworkType {
  /// Any working network connection is required for this work.
  connected,

  /// A metered network connection is required for this work.
  metered,

  /// A network is not required for this work.
  notRequired,

  /// A non-roaming network connection is required for this work.
  notRoaming,

  /// An unmetered network connection is required for this work.
  unmetered,
}

And here is the Java one

package androidx.work;

public enum NetworkType {
    NOT_REQUIRED,
    CONNECTED,
    UNMETERED,
    NOT_ROAMING,
    METERED;

    private NetworkType() {
    }
}

connected -> NOT_REQUIRED
metered -> CONNECTED
notRequired -> UNMETERED
notRoaming -> NOT_ROAMING
unmetered -> METERED

@2math
Copy link
Author

2math commented Jun 18, 2021

There is a pull request with a fix for that from 1 Oct 2020

Since something important as that is not fixed for almost an year, makes me think that this plugin is not supported anymore

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

No branches or pull requests

1 participant