apps-android-commons
apps-android-commons copied to clipboard
[Bug]: Set Wallpaper Not Working Correctly
Summary
The Set Wallpaper feature in the contributions page does not inform the user that it has failed to set wallpaper. Also, I am unable to abort this dialog.
The issue is not that set wallpaper is failing to set the Image as wallpaper but that it is NOT Informing the user that it has failed and dialog is still appearing on the screen which the user cannot close.
Also, we should make the "set as wallpaper" a background task that does not block the UI Thread as sometimes this can take long ( it is pretty similar to download )
Steps to reproduce
- Open the app
- Open any Contribution in Explore or your contribution
- Click "Set as Wallpaper"
Expected behaviour
Sets the wallpaper or if it fails then the dialog ends and the user is informed
Actual behaviour
set wallpaper keeps on going
Device name
Xiaomi 11 Lite NE
Android version
Android 13
Commons app version
4.2.1-debug-main
Device logs
HTTP FAILED: java.io.IOException: Canceled
2024-02-16 20:52:02.709 16877-17104 OkHttp fr.free.nrw.commons.beta V --> GET https://upload.wikimedia.beta.wmflabs.org/wikipedia/commons/thumb/6/6f/Sea_View.jpg/640px-Sea_View.jpg
2024-02-16 20:52:02.709 16877-17104 OkHttp fr.free.nrw.commons.beta V Cache-Control: no-store
2024-02-16 20:52:02.709 16877-17104 OkHttp fr.free.nrw.commons.beta V --> END GET
Screen-shots
https://github.com/commons-app/apps-android-commons/assets/126143257/b7ce8dfb-9482-48b7-ae7c-004cac5ca137
Would you like to work on the issue?
Yes
Hey @shashankiitbhu, it seems the issue is with the beta server, as I was able to set wallpaper successfully using prodDebug Screencast
@ShashwatKedia no that's not the issue I am trying to report here, if you read the summary again I have mentioned that failing is not the problem, but dialog still appearing after failing is.
Strange in my case the wallpaper is set successfully in milliseconds. However, this is about handling the case when the process is failed, right?
However, this is about handling the case when the process is failed, right?
Yes
Well, I just faced the same with betaDebug flavor😅
But yeah we need to handle the failure :)
Are you working on it?
If you don't mind can I work on this as I was digging it up recently and found the exact solution which is causing the bug and fix? Can I work on it if you wish or can we collaborate?
This is how I solved it. @shashankiitbhu @nicolas-raoul
Root cause of issue.
Currently code handles the issue when the url is not present it handles the failures. But what if we have a url but receive error from the API side this could include (Wrong URL, server high time in response, xyz issues from server side), this is not handled in our API side.
Currently
I checked the if the url threw the error dismiss the progressdialog and show toast, which solves the issue somewhat but not optimal.
Working Video
https://github.com/commons-app/apps-android-commons/assets/60827173/235e8c9e-b684-4498-9a8b-b241c088a48f
Additional Improvements
Add Failure mechanism directly at the API level (calling api).(if org approves I can work on it)
For example I have worked similarly on one of my project like this.
fun parseFailedResponse(t: Throwable): String {
return when (t) {
is SocketTimeoutException -> {
"Connection Lost, please try again - ${t::class.java.simpleName}"
}
is MalformedJsonException,
is JsonSyntaxException -> {
t.printStackTrace()
"SERVER sent invalid response - ${t::class.java.simpleName}"
}
else -> {
t.printStackTrace()
"Could not connect to SERVER - ${t::class.java.simpleName}"
}
}
}
Edit :
Logs
2024-03-05 20:13:35.885 17112-17112 ImageUtils fr.free.nrw.commons.beta D Trying to set wallpaper from url https://upload.wikimedia.beta.wmflabs.org/wikipedia/commons/c/ce/Test_Caption.jpg
2024-03-05 20:14:19.793 17112-17263 OkHttp fr.free.nrw.commons.beta V <-- 500 https://upload.wikimedia.beta.wmflabs.org/wikipedia/commons/thumb/3/30/Test_caption_4.jpg/640px-Test_caption_4.jpg (45307ms)
2024-03-05 20:14:19.794 17112-17263 OkHttp fr.free.nrw.commons.beta V report-to: { "group": "wm_nel", "max_age": 604800, "endpoints": [{ "url": "https://intake-logging.wikimedia.org/v1/events?stream=w3c.reportingapi.network_error&schema_uri=/w3c/reportingapi/network_error/1.0.0" }] }
2024-03-05 20:14:19.795 17112-17263 OkHttp fr.free.nrw.commons.beta V <!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Wikimedia Error</title>
<style>
* { margin: 0; padding: 0; }
body { background: #fff; font: 15px/1.6 sans-serif; color: #333; }
.content { margin: 7% auto 0; padding: 2em 1em 1em; max-width: 640px; }
.footer { clear: both; margin-top: 14%; border-top: 1px solid #e5e5e5; background: #f9f9f9; padding: 2em 0; font-size: 0.8em; text-align: center; }
img { float: left; margin: 0 2em 2em 0; }
a img { border: 0; }
h1 { margin-top: 1em; font-size: 1.2em; }
.content-text { overflow: hidden; overflow-wrap: break-word; word-wrap: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; -ms-hyphens: auto; hyphens: auto; }
p { margin: 0.7em 0 1em 0; }
a { color: #0645ad; text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: sans-serif; }
.text-muted { color: #777; }
</style>
<div class="content" role="main">
<a href="https://www.wikimedia.org"><img src="https://www.wikimedia.org/static/images/wmf-logo.png" srcset="https://www.wikimedia.org/static/images/wmf-logo-2x.png 2x" alt="Wikimedia" width="135" height="101">
</a>
<h1>Error</h1>
<div class="content-text">
<p>Our servers are currently under maintenance or experiencing a technical problem.
Please <a href="" title="Reload this page" onclick="window.location.reload(false); return false">try again</a> in a few minutes.</p>
<p>See the error message at the bottom of this page for more information.</p>
</div>
</div>
<div class="footer"><p>If you report this error to the Wikimedia System Administrators, please include the details below.</p><p class='text-muted'><code>Request from 49.36.111.247 via deployment-cache-upload08.deployment-prep.eqiad1.wikimedia.cloud, ATS/9.1.4<br>Error: 500, Cannot find server. at 2024-03-05 14:43:51 GMT</code></p></div>
</html>
2024-03-05 20:14:53.041 17112-17232 OkHttp fr.free.nrw.commons.beta V <-- 500 https://upload.wikimedia.beta.wmflabs.org/wikipedia/commons/3/30/Test_caption_4.jpg (78557ms)
2024-03-05 20:14:53.042 17112-17232 OkHttp fr.free.nrw.commons.beta V report-to: { "group": "wm_nel", "max_age": 604800, "endpoints": [{ "url": "https://intake-logging.wikimedia.org/v1/events?stream=w3c.reportingapi.network_error&schema_uri=/w3c/reportingapi/network_error/1.0.0" }] }
2024-03-05 20:14:53.043 17112-17232 OkHttp fr.free.nrw.commons.beta V <!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Wikimedia Error</title>
<style>
* { margin: 0; padding: 0; }
body { background: #fff; font: 15px/1.6 sans-serif; color: #333; }
.content { margin: 7% auto 0; padding: 2em 1em 1em; max-width: 640px; }
.footer { clear: both; margin-top: 14%; border-top: 1px solid #e5e5e5; background: #f9f9f9; padding: 2em 0; font-size: 0.8em; text-align: center; }
img { float: left; margin: 0 2em 2em 0; }
a img { border: 0; }
h1 { margin-top: 1em; font-size: 1.2em; }
.content-text { overflow: hidden; overflow-wrap: break-word; word-wrap: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; -ms-hyphens: auto; hyphens: auto; }
p { margin: 0.7em 0 1em 0; }
a { color: #0645ad; text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: sans-serif; }
.text-muted { color: #777; }
</style>
<div class="content" role="main">
<a href="https://www.wikimedia.org"><img src="https://www.wikimedia.org/static/images/wmf-logo.png" srcset="https://www.wikimedia.org/static/images/wmf-logo-2x.png 2x" alt="Wikimedia" width="135" height="101">
</a>
<h1>Error</h1>
<div class="content-text">
<p>Our servers are currently under maintenance or experiencing a technical problem.
Please <a href="" title="Reload this page" onclick="window.location.reload(false); return false">try again</a> in a few minutes.</p>
<p>See the error message at the bottom of this page for more information.</p>
</div>
</div>
<div class="footer"><p>If you report this error to the Wikimedia System Administrators, please include the details below.</p><p class='text-muted'><code>Request from 49.36.111.247 via deployment-cache-upload08.deployment-prep.eqiad1.wikimedia.cloud, ATS/9.1.4<br>Error: 500, Cannot find server. at 2024-03-05 14:44:24 GMT</code></p></div>
</html>
2024-03-05 20:15:19.829 17112-17327 OkHttp fr.free.nrw.commons.beta V <-- 500 https://upload.wikimedia.beta.wmflabs.org/wikipedia/commons/thumb/c/ce/Test_Caption.jpg/640px-Test_Caption.jpg (105317ms)
2024-03-05 20:15:19.829 17112-17327 OkHttp fr.free.nrw.commons.beta V report-to: { "group": "wm_nel", "max_age": 604800, "endpoints": [{ "url": "https://intake-logging.wikimedia.org/v1/events?stream=w3c.reportingapi.network_error&schema_uri=/w3c/reportingapi/network_error/1.0.0" }] }
2024-03-05 20:15:19.829 17112-17327 OkHttp fr.free.nrw.commons.beta V <!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Wikimedia Error</title>
<style>
* { margin: 0; padding: 0; }
body { background: #fff; font: 15px/1.6 sans-serif; color: #333; }
.content { margin: 7% auto 0; padding: 2em 1em 1em; max-width: 640px; }
.footer { clear: both; margin-top: 14%; border-top: 1px solid #e5e5e5; background: #f9f9f9; padding: 2em 0; font-size: 0.8em; text-align: center; }
img { float: left; margin: 0 2em 2em 0; }
a img { border: 0; }
h1 { margin-top: 1em; font-size: 1.2em; }
.content-text { overflow: hidden; overflow-wrap: break-word; word-wrap: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; -ms-hyphens: auto; hyphens: auto; }
p { margin: 0.7em 0 1em 0; }
a { color: #0645ad; text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: sans-serif; }
.text-muted { color: #777; }
</style>
<div class="content" role="main">
<a href="https://www.wikimedia.org"><img src="https://www.wikimedia.org/static/images/wmf-logo.png" srcset="https://www.wikimedia.org/static/images/wmf-logo-2x.png 2x" alt="Wikimedia" width="135" height="101">
</a>
<h1>Error</h1>
<div class="content-text">
<p>Our servers are currently under maintenance or experiencing a technical problem.
Please <a href="" title="Reload this page" onclick="window.location.reload(false); return false">try again</a> in a few minutes.</p>
<p>See the error message at the bottom of this page for more information.</p>
</div>
</div>
<div class="footer"><p>If you report this error to the Wikimedia System Administrators, please include the details below.</p><p class='text-muted'><code>Request from 49.36.111.247 via deployment-cache-upload08.deployment-prep.eqiad1.wikimedia.cloud, ATS/9.1.4<br>Error: 500, Cannot find server. at 2024-03-05 14:44:51 GMT</code></p></div>
</html>
2024-03-05 20:15:34.513 17112-17227 ImageUtils fr.free.nrw.commons.beta E Error getting bitmap from image url https://upload.wikimedia.beta.wmflabs.org/wikipedia/commons/c/ce/Test_Caption.jpg
If you don't mind can I work on this as I was digging it up recently and found the exact solution which is causing the bug and fix? Can I work on it if you wish or can we collaborate?
I have already worked on it and presented a solution, I was waiting for mentors approval to make the PR and take inputs for changes
If you don't mind can I work on this as I was digging it up recently and found the exact solution which is causing the bug and fix? Can I work on it if you wish or can we collaborate?
I have already worked on it and presented a solution, I was waiting for mentors approval to make the PR and take inputs for changes
Sure, no problem ;)
@shashankiitbhu Sorry do you still need anything from us? If yes would you mind summarizing or posting a link here? Thanks :-)
@shashankiitbhu Sorry do you still need anything from us? If yes would you mind summarizing or posting a link here? Thanks :-)
If this issue is stale then I would like to take it as I have already fixed the issue locally. Since @shashankiitbhu is currently assigned to it, I have refrained from submitting a pull request. However, I can offer a patch fix for the changes. You can easily apply the patch by copying from clipboard from Android Studio
@shashankiitbhu Sorry do you still need anything from us? If yes would you mind summarizing or posting a link here? Thanks :-)
Actually, as mentioned above I was waiting for your confirmation on whether I should Implement the enhancement or not , whether it's worth doing or not according to you.
The issue is not that set wallpaper is failing to set the Image as wallpaper but that it is NOT Informing the user that it has failed and dialog is still appearing on the screen which the user cannot close.\n\nAlso, we should make the "set as wallpaper" a background task that does not block the UI Thread as sometimes this can take long ( it is pretty similar to download )
@nicolas-raoul This is the enhancement I have suggested
In Summary :
I am suggesting two enhancements here :
-
Better Error Feedback For Operations like "Set Wallpaper"
-
Make set wallpaper a Background Task and Inform the user with a notification.
Based on this issue, it also made me remind that Progress Dialog is deprecated. I guess the better approach would be to remove the Progress dialog. Google Deprecated Progress Dialog
According to Google
This class was deprecated in API level 26. ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar, which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress.
The better approach according to me would be to handle it like this.
Additional Improvements Add Failure mechanism directly at the API level (calling api).(if org approves I can work on it)
For example I have worked similarly on one of my project like this.
Also CC : @psh as mentioned in https://github.com/commons-app/apps-android-commons/issues/5556#issuecomment-1978977703 can we add a failure mechanism to our api level
@shashankiitbhu Sounds good! 🙂
@nicolas-raoul Added the PR for this enhancement above, Please Review