Stop activity if we cant start node

Currently when receiving a push notification while the app has not
started (on android), the whole app is woken up. If autologin is enabled, we will try
to start the node, but will fail has no activity has been attached.
In such cases we try for 10s and quit the app if not successful.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2019-03-14 11:18:24 +01:00
parent 8f40f796f5
commit 530a6dca2e
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
1 changed files with 17 additions and 3 deletions

View File

@ -90,12 +90,25 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
} }
private boolean checkAvailability() { private boolean checkAvailability() {
// We wait at least 10s for getCurrentActivity to return a value,
// otherwise we give up
for (int attempts = 0; attempts < 100; attempts++) {
if (getCurrentActivity() != null) { if (getCurrentActivity() != null) {
return true; return true;
} }
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
if (getCurrentActivity() != null) {
return true;
}
Log.d(TAG, "Activity doesn't exist");
return false;
}
}
Log.d(TAG, "Activity doesn't exist"); Log.d(TAG, "Activity doesn't exist");
return false; return false;
} }
@ -342,6 +355,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
Log.d(TAG, "startNode"); Log.d(TAG, "startNode");
if (!checkAvailability()) { if (!checkAvailability()) {
Log.e(TAG, "[startNode] Activity doesn't exist, cannot start node"); Log.e(TAG, "[startNode] Activity doesn't exist, cannot start node");
System.exit(0);
return; return;
} }