mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-02 21:24:34 +00:00
Prevent ROOM live data crash
This commit is contained in:
parent
f7d6dc55a2
commit
1cd74d08df
2 changed files with 21 additions and 28 deletions
|
@ -85,20 +85,19 @@ class RoomTrackingLiveData<T> extends LiveData<T> {
|
||||||
try {
|
try {
|
||||||
T value = null;
|
T value = null;
|
||||||
while (mInvalid.compareAndSet(true, false)) {
|
while (mInvalid.compareAndSet(true, false)) {
|
||||||
computed = true;
|
|
||||||
int retry = 0;
|
int retry = 0;
|
||||||
boolean done = false;
|
while (!computed) {
|
||||||
while (!done) {
|
|
||||||
try {
|
try {
|
||||||
value = mComputeFunction.call();
|
value = mComputeFunction.call();
|
||||||
done = true;
|
computed = true;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
if (++retry > 10)
|
if (++retry > 5) {
|
||||||
throw new RuntimeException(
|
eu.faircode.email.Log.e(e);
|
||||||
"Exception while computing database live data.", e);
|
break;
|
||||||
|
}
|
||||||
eu.faircode.email.Log.w(e);
|
eu.faircode.email.Log.w(e);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(3000L);
|
Thread.sleep(2000L);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +135,6 @@ class RoomTrackingLiveData<T> extends LiveData<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
RoomTrackingLiveData(
|
RoomTrackingLiveData(
|
||||||
RoomDatabase database,
|
RoomDatabase database,
|
||||||
|
|
|
@ -1,38 +1,33 @@
|
||||||
--- ./support/room/runtime/src/main/java/androidx/room/RoomTrackingLiveData.java 2020-03-23 17:03:46.216122318 +0100
|
diff --git a/app/src/main/java/androidx/room/RoomTrackingLiveData.java b/app/src/main/java/androidx/room/RoomTrackingLiveData.java
|
||||||
+++ ./email/app/src/main/java/androidx/room/RoomTrackingLiveData.java 2020-05-25 14:21:49.137386867 +0200
|
index 8df1014a4..d02ab8fea 100644
|
||||||
@@ -86,11 +86,22 @@ class RoomTrackingLiveData<T> extends Li
|
--- a/app/src/main/java/androidx/room/RoomTrackingLiveData.java
|
||||||
|
+++ b/app/src/main/java/androidx/room/RoomTrackingLiveData.java
|
||||||
|
@@ -85,12 +85,22 @@ class RoomTrackingLiveData<T> extends LiveData<T> {
|
||||||
|
try {
|
||||||
T value = null;
|
T value = null;
|
||||||
while (mInvalid.compareAndSet(true, false)) {
|
while (mInvalid.compareAndSet(true, false)) {
|
||||||
computed = true;
|
- computed = true;
|
||||||
- try {
|
- try {
|
||||||
- value = mComputeFunction.call();
|
- value = mComputeFunction.call();
|
||||||
- } catch (Exception e) {
|
- } catch (Exception e) {
|
||||||
- throw new RuntimeException("Exception while computing database"
|
- throw new RuntimeException("Exception while computing database"
|
||||||
- + " live data.", e);
|
- + " live data.", e);
|
||||||
+ int retry = 0;
|
+ int retry = 0;
|
||||||
+ boolean done = false;
|
+ while (!computed) {
|
||||||
+ while (!done) {
|
|
||||||
+ try {
|
+ try {
|
||||||
+ value = mComputeFunction.call();
|
+ value = mComputeFunction.call();
|
||||||
+ done = true;
|
+ computed = true;
|
||||||
+ } catch (Throwable e) {
|
+ } catch (Throwable e) {
|
||||||
+ if (++retry > 10)
|
+ if (++retry > 5) {
|
||||||
+ throw new RuntimeException(
|
+ eu.faircode.email.Log.e(e);
|
||||||
+ "Exception while computing database live data.", e);
|
+ break;
|
||||||
|
+ }
|
||||||
+ eu.faircode.email.Log.w(e);
|
+ eu.faircode.email.Log.w(e);
|
||||||
+ try {
|
+ try {
|
||||||
+ Thread.sleep(3000L);
|
+ Thread.sleep(2000L);
|
||||||
+ } catch (InterruptedException ignored) {
|
+ } catch (InterruptedException ignored) {
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (computed) {
|
if (computed) {
|
||||||
@@ -125,6 +136,7 @@ class RoomTrackingLiveData<T> extends Li
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
+
|
|
||||||
@SuppressLint("RestrictedApi")
|
|
||||||
RoomTrackingLiveData(
|
|
||||||
RoomDatabase database,
|
|
||||||
|
|
Loading…
Reference in a new issue