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

It is not possiable to changing user avatar #4767

Closed
375573088 opened this issue Dec 20, 2021 · 13 comments · Fixed by #4783
Closed

It is not possiable to changing user avatar #4767

375573088 opened this issue Dec 20, 2021 · 13 comments · Fixed by #4783
Assignees
Labels
A-Settings A-User Avatar T-Defect Something isn't working: bugs, crashes, hangs and other reported problems

Comments

@375573088
Copy link

Steps to reproduce

It is not possiable to changing user avatar
image
image
cut and uploading photo
image
image

Outcome

final Exception:android.os.NetworkOnMainThreadException
image
image

Your phone model

18208727060

Operating system version

Android 31

Application version and app store

No response

Homeserver

https://im.ynzzpt.cn/

Will you send logs?

Yes

@375573088 375573088 added the T-Defect Something isn't working: bugs, crashes, hangs and other reported problems label Dec 20, 2021
@RiotRobot RiotRobot added this to Incoming in Issue triage Dec 20, 2021
@YamatoRyou
Copy link

Same as me.
#4730

@ouchadam
Copy link
Contributor

I'm unable to reproduce this issue (matrix.org and a private server) using the latest from develop,

which version of Element Android is this / have you made any modifications?

change-avatar

@375573088
Copy link
Author

Changes in Element v1.3.9 (2021-12-01)

@375573088
Copy link
Author

And i did't have made any modifications.
That is my virtual machine device:
image

@ouchadam
Copy link
Contributor

ouchadam commented Dec 20, 2021

@375573088
Copy link
Author

This is try catch code,and execute the code Exception:android.os.NetworkOnMainThreadException

  override suspend fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String) {
        val logger = FormattedJsonHttpLogger()
        withContext(coroutineDispatchers.main) {
           try{
               val response = fileUploader.uploadFromUri(newAvatarUri, fileName, MimeTypes.Jpeg)
               setAvatarUrlTask.execute(SetAvatarUrlTask.Params(userId = userId, newAvatarUrl = response.contentUri))
               userStore.updateAvatar(userId, response.contentUri)
           }
           catch (e :Exception){
               logger.log("updateAvatar------>"+ e.message)  // android.os.NetworkOnMainThreadException
           }
        }
    }

@ouchadam
Copy link
Contributor

what happens if we only execute the file uploading?

  override suspend fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String) {
        val logger = FormattedJsonHttpLogger()
        withContext(coroutineDispatchers.main) {
           try{
               fileUploader.uploadFromUri(newAvatarUri, fileName, MimeTypes.Jpeg)
               //setAvatarUrlTask.execute(SetAvatarUrlTask.Params(userId = userId, newAvatarUrl = response.contentUri))
               //userStore.updateAvatar(userId, response.contentUri)
           }
           catch (e :Exception){
               logger.log("updateAvatar------>"+ e.message)  // android.os.NetworkOnMainThreadException
           }
        }
    }

if we still get the NetworkOnMainThreadException then it proves the error is within fileUploader.uploadFromUri, if there is no error then we can infer that setAvatarUrlTask.execute is the problem

@375573088
Copy link
Author

The way just only execute this code and exception:

fileUploader.uploadFromUri(newAvatarUri, fileName, MimeTypes.Jpeg)

however it is not step into below code:

setAvatarUrlTask.execute

@ouchadam
Copy link
Contributor

ouchadam commented Dec 20, 2021

I'm really confused by this issue, the only way I've been able to reproduce the NetworkOnMainThreadException in the uploadFromUri flow is by replacing okHttpClient.newCall(request).awaitResponse() with okHttpClient.newCall(request).execute()

https://github.com/vector-im/element-android/blob/develop/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/FileUploader.kt#L144

@375573088 does changing the dispatcher to .io fix the exception?

- withContext(coroutineDispatchers.main) {
+ withContext(coroutineDispatchers.io) {

https://github.com/vector-im/element-android/blob/develop/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DefaultProfileService.kt#L71

@375573088
Copy link
Author

Very nice ,Thanks for you. Use coroutineDispatchers.io it is dit fixed the exception and setAvatar successed。
i guess coroutineDispatchers.main it's can not dispatch my process into asynchronous process。

 withContext(coroutineDispatchers.io)

Now , Wish you a merry Christmas in advance. 3Q

image
image
image

@ouchadam
Copy link
Contributor

💯 great to hear! I'll raise a PR with the change

thanks for your help with debugging

@ouchadam ouchadam moved this from Need info to Triaged in Issue triage Dec 21, 2021
@ouchadam ouchadam added this to In progress in Android App Team Dec 21, 2021
@ouchadam ouchadam self-assigned this Dec 21, 2021
@375573088
Copy link
Author

💯 great to hear! I'll raise a PR with the change

thanks for your help with debugging

No problem,hahaha~

@ouchadam ouchadam moved this from In progress to In Code Review in Android App Team Dec 21, 2021
Issue triage automation moved this from Triaged to Closed Dec 30, 2021
Android App Team automation moved this from In Code Review to Merged Dec 30, 2021
@bmarty
Copy link
Member

bmarty commented Dec 30, 2021

Fix included in EA 1.3.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Settings A-User Avatar T-Defect Something isn't working: bugs, crashes, hangs and other reported problems
Projects
Development

Successfully merging a pull request may close this issue.

4 participants