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

判定网络连接状态有误 #614

Open
narakai opened this issue Feb 15, 2020 · 18 comments
Open

判定网络连接状态有误 #614

narakai opened this issue Feb 15, 2020 · 18 comments
Labels
bug

Comments

@narakai
Copy link

@narakai narakai commented Feb 15, 2020

版本

框架版本
3.8.5
系统版本
Android 10
错误日志

E/StartCmd: 启动任务失败,网络未连接

重现步骤

打开APP下载时联网,手动断网,打开APP,新建任务,提示E/StartCmd: 启动任务失败,网络未连接,无法下载,所有任务无法进行。
刚开始我还以为网络问题,但是Glide把网络图片加载出来了才发现log提示Aria找不到网络...

onDestroy里面进行了 Aria.download(this).load(id).stop()
Aria.download(this).unRegister()

@narakai

This comment has been minimized.

Copy link
Author

@narakai narakai commented Feb 15, 2020

刚试了下,应该和ondertoy里的操作没关系

@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Feb 17, 2020

手动断网后,重新联网没?

@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Feb 17, 2020

感谢反馈,已验证这个问题,出现这个问题的原因:先断网,再下载

@AriaLyy AriaLyy added the bug label Feb 17, 2020
AriaLyy added a commit that referenced this issue Feb 17, 2020
@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Feb 18, 2020

3.8.6 已修复了这个问题

@narakai

This comment has been minimized.

Copy link
Author

@narakai narakai commented Feb 19, 2020

谢谢作者修复,我待会验证下,现在暂时设置的不进行网络连接判断

@MinghaoCao

This comment has been minimized.

Copy link

@MinghaoCao MinghaoCao commented Feb 20, 2020

我刚试了,先用wifi下载,然后手动断开wifi,接着用4g的话可以正常下载,但是重新连接wifi下载还是 启动任务失败,网络未连接,而且后续再添加下载全部都是网络未连接,需要重新启动app才能恢复,用的3.8.6版本

@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Feb 20, 2020

@MinghaoCao 建议你在Application 初始化Aria看看 Aria.init(this);

@MinghaoCao

This comment has been minimized.

Copy link

@MinghaoCao MinghaoCao commented Feb 21, 2020

@MinghaoCao 建议你在Application 初始化Aria看看 Aria.init(this);

init 后,wifi可以,但是4g会显示网络未连接,4g是有网的,

@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Feb 25, 2020

@MinghaoCaoonAvailableonLost这两个日志的打印吗?

@MinghaoCao

This comment has been minimized.

Copy link

@MinghaoCao MinghaoCao commented Feb 26, 2020

@MinghaoCaoonAvailableonLost这两个日志的打印吗?

有打印的,还有个情况就是我重连wifi前先把4g断掉,是可以下载的,

@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Mar 3, 2020

这就奇怪了,有打印的话就表示监听是正常的,一般不会出问题,debug看看AriaConfig.isConnectedNet的状态

@MinghaoCao

This comment has been minimized.

Copy link

@MinghaoCao MinghaoCao commented Mar 5, 2020

这就奇怪了,有打印的话就表示监听是正常的,一般不会出问题,debug看看AriaConfig.isConnectedNet的状态
问题应该就在 ConnectivityManager.NetworkCallback()这,从4g切到wifi,会先调onAvailable isConnectedNet = true,然后再调onLost isConnectedNet就变成false了,

@wuMaoTou

This comment has been minimized.

Copy link

@wuMaoTou wuMaoTou commented Mar 6, 2020

我也遇到了类似的问题,在android 9上面突然出现"提示E/StartCmd: 启动任务失败,网络未连接"
开始以为是网络连接状态监听出问题了,debug的时候发现流程是正常的,后面在下载页面加了@Upload.onTaskFail注解监听又正常了
几次调试下来发现确实是@Upload.onTaskFail有影响到,但是找不到他们之间的关联

@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Mar 6, 2020

@wuMaoTou Upload.onTaskFai,只是vr tl来接收器,是不会影响到网络监听的啊😂

@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Mar 6, 2020

@MinghaoCao 也是android 9.0 出现的问题?

@wuMaoTou

This comment has been minimized.

Copy link

@wuMaoTou wuMaoTou commented Mar 6, 2020

@wuMaoTou Upload.onTaskFai,只是vr tl来接收器,是不会影响到网络监听的啊

我也是这么想的,但是几次测试来看确实有影响,注释@Upload.onTaskFail注解的方法会报失败,放开注释又可以,测试了3次,很郁闷,哈哈哈

@MinghaoCao

This comment has been minimized.

Copy link

@MinghaoCao MinghaoCao commented Mar 6, 2020

@MinghaoCao 也是android 9.0 出现的问题?

我用Samsung s9+ Android 10.0 测试的,我debug看起来是网络监听的bug,

@wuMaoTou

This comment has been minimized.

Copy link

@wuMaoTou wuMaoTou commented Apr 3, 2020

今天在测试的时候复现了这个bug的原因

  cm.registerNetworkCallback(request, new ConnectivityManager.NetworkCallback() {

        @Override public void onLost(Network network) {
          super.onLost(network);
            ALog.d(TAG, "onLost");
            isConnectedNet = false;
            ALog.e("registerNetworkCallback-onLost", "     Network:" +  network.toString() + "------isConnectedNet:" + isConnectedNet + "--------------");
        }

        @Override public void onAvailable(Network network) {
          super.onAvailable(network);
          ALog.d(TAG, "onAvailable");
          isConnectedNet = true;
          ALog.e("registerNetworkCallback-onAvailable", "Network:" +  network.toString() + "------isConnectedNet:-----------" + isConnectedNet + "--------------");
        }

      });

网络监听的回调在wifi网络或移动网络发现改变的时候各会调用一次,也就是说,当手机存在wifi连接和移动网络连接的时候会出现以下回调情况

1.wifi和移动网络数据网络数据打开情况下,点击关闭wifi,回调情况

registerNetworkCallback-onLost:         Network:170------isConnectedNet:false--------------
registerNetworkCallback-onAvailable: Network:171------isConnectedNet:-----------true--------------

wifi先断开回调onLost,然后切换到移动网络回调了onAvailable

2.在上面的状态下(wifi关闭,移动网络启用),点击开启wifi,回调情况

registerNetworkCallback-onAvailable: Network:172------isConnectedNet:-----------true--------------
registerNetworkCallback-onLost:      Network:171------isConnectedNet:false--------------

wifi先连接回调onAvailable,然后移动网络断开回调了onLost

这个时候就出现了网络是连接状态,但是isConnectedNet的布尔值为false

解决方法
我的解决方案是在onLost回调的时候去调用 isNetworkAvailable()方法获取当前网络连接状态

@Override public void onLost(Network network) {
          super.onLost(network);
            ALog.d(TAG, "onLost");
            isConnectedNet = isNetworkAvailable();
            ALog.e("registerNetworkCallback-onLost", "     Network:" +  network.toString() + "------isConnectedNet:" + isConnectedNet + "--------------");
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.