-
-
Notifications
You must be signed in to change notification settings - Fork 45
Enhance install error message on app backgrounding #3432
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
base: master
Are you sure you want to change the base?
Changes from all commits
310bc41
50f28bc
cdb47f8
0cd1764
a580a83
2dc4076
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import org.commcare.util.CommCarePlatform; | ||
| import org.commcare.util.LogTypes; | ||
| import org.commcare.utils.AndroidCommCarePlatform; | ||
| import org.commcare.utils.ConnectivityStatus; | ||
| import org.commcare.utils.FileUtil; | ||
| import org.commcare.utils.StringUtils; | ||
| import org.javarosa.core.io.StreamsUtil; | ||
|
|
@@ -41,6 +42,7 @@ | |
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import java.net.UnknownHostException; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Vector; | ||
|
|
@@ -125,10 +127,16 @@ public boolean install(Resource r, ResourceLocation location, | |
|
|
||
| throw mURE; | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| UnreliableSourceException exception = new UnreliableSourceException(r, e.getMessage()); | ||
| exception.initCause(e); | ||
| throw exception; | ||
| if (e instanceof UnknownHostException && !CommCareApplication.instance().isAppInForeground()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @avazirna Can it also throw
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
| UnresolvedResourceException mURE = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constructor I'm using already accepts a |
||
| new UnresolvedResourceException(r, e, | ||
| "The connection was interrupted because CommCare is in the background", true); | ||
| throw mURE; | ||
| } else { | ||
| UnreliableSourceException exception = new UnreliableSourceException(r, e.getMessage()); | ||
| exception.initCause(e); | ||
| throw exception; | ||
| } | ||
| } catch (RateLimitedException e) { | ||
| UnresolvedResourceException mURE = new UnresolvedResourceException(r, "Our servers are unavailable at this time. Please try again later", true); | ||
| mURE.initCause(e); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
|
|
||
| import java.net.MalformedURLException; | ||
| import java.net.URL; | ||
| import java.net.UnknownHostException; | ||
| import java.util.Date; | ||
|
|
||
| import javax.net.ssl.SSLException; | ||
|
|
@@ -144,6 +145,9 @@ public static void handleAppInstallResult(ResourceEngineTask resourceEngineTask, | |
| case CaptivePortal: | ||
| receiver.failWithNotification(AppInstallStatus.CaptivePortal); | ||
| break; | ||
| case ConnectionInterrupted: | ||
| receiver.failWithNotification(AppInstallStatus.ConnectionInterrupted); | ||
| break; | ||
| default: | ||
| receiver.failUnknown(AppInstallStatus.UnknownFailure); | ||
| break; | ||
|
|
@@ -267,6 +271,10 @@ public static AppInstallStatus processUnresolvedResource(UnresolvedResourceExcep | |
| Logger.exception("Encountered SSLException while trying to install a resource", exception); | ||
| return AppInstallStatus.BadSslCertificate; | ||
| } | ||
| if (exception.getCause() instanceof UnknownHostException) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @avazirna Should it check for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The determining factor is when CommCare is in the background, and in that case we wrap the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So just trying to understand here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, so this check is inside a method that only handles |
||
| Logger.exception("Encountered UnknownHostException while trying to install a resource", exception); | ||
| return AppInstallStatus.ConnectionInterrupted; | ||
| } | ||
|
|
||
| if(exception.getCause() instanceof RateLimitedException){ | ||
| return AppInstallStatus.RateLimited; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider thread safety for the foreground state flag.
The
isForegroundboolean is accessed from multiple threads (lifecycle callbacks and the install process) without synchronization. While boolean reads/writes are atomic in Java, there's no guarantee of visibility across threads without proper synchronization.Consider one of these approaches:
volatileto ensure visibility across threadsAtomicBooleanfor thread-safe operationsApply this diff to make the field volatile:
📝 Committable suggestion
🤖 Prompt for AI Agents