1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-29 15:51:17 +00:00

Show notification if SDcard is full (fixes #381) (#382)

* Add string: notification_out_of_disk_space

* Show notification if SDcard is full (fixes #381)

* Imported de translation

* Handle event: FolderErrors "insufficient space in basic" (fixes #381)
This commit is contained in:
Catfriend1 2019-03-23 16:57:25 +01:00 committed by GitHub
parent fc5a99cd5c
commit 304cf72c42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 7 deletions

View file

@ -15,6 +15,10 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.SyncthingApp; import com.nutomic.syncthingandroid.SyncthingApp;
import com.nutomic.syncthingandroid.activities.DeviceActivity; import com.nutomic.syncthingandroid.activities.DeviceActivity;
@ -78,7 +82,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
// If that's the case we've to start at zero because syncthing was restarted. // If that's the case we've to start at zero because syncthing was restarted.
mRestApi.getEvents(0, 1, new RestApi.OnReceiveEventListener() { mRestApi.getEvents(0, 1, new RestApi.OnReceiveEventListener() {
@Override @Override
public void onEvent(Event event) { public void onEvent(Event event, JsonElement json) {
} }
@Override @Override
@ -96,7 +100,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
* Performs the actual event handling. * Performs the actual event handling.
*/ */
@Override @Override
public void onEvent(Event event) { public void onEvent(Event event, JsonElement json) {
switch (event.type) { switch (event.type) {
case "ConfigSaved": case "ConfigSaved":
if (mRestApi != null) { if (mRestApi != null) {
@ -119,6 +123,10 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
completionInfo completionInfo
); );
break; break;
case "FolderErrors":
LogV("Event " + event.type + ", data " + event.data);
onFolderErrors(json);
break;
case "FolderRejected": case "FolderRejected":
onFolderRejected( onFolderRejected(
(String) event.data.get("device"), // deviceId (String) event.data.get("device"), // deviceId
@ -171,9 +179,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
case "Starting": case "Starting":
case "StartupComplete": case "StartupComplete":
case "StateChanged": case "StateChanged":
if (ENABLE_VERBOSE_LOG) {
LogV("Ignored event " + event.type + ", data " + event.data); LogV("Ignored event " + event.type + ", data " + event.data);
}
break; break;
default: default:
Log.d(TAG, "Unhandled event " + event.type); Log.d(TAG, "Unhandled event " + event.type);
@ -293,6 +299,36 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
mNotificationHandler.showConsentNotification(notificationId, title, piAccept, piIgnore); mNotificationHandler.showConsentNotification(notificationId, title, piAccept, piIgnore);
} }
private void onFolderErrors(JsonElement json) {
JsonElement data = ((JsonObject) json).get("data");
if (data == null) {
Log.e(TAG, "onFolderErrors: data == null");
return;
}
JsonArray errors = (JsonArray) ((JsonObject) data).get("errors");
if (errors == null) {
Log.e(TAG, "onFolderErrors: errors == null");
return;
}
for (int i = 0; i < errors.size(); i++) {
JsonElement error = errors.get(i);
if (error != null) {
String strError = ((JsonObject) error).get("error").toString();
String strPath = ((JsonObject) error).get("path").toString();
if (!TextUtils.isEmpty(strError) &&
!TextUtils.isEmpty(strPath) &&
strError.contains("insufficient space in basic")) {
String[] segments = strPath.split(File.separator);
String shortenedFileAndFolder =
segments.length < 2 ?
strPath :
segments[segments.length-2] + File.separator + segments[segments.length-1];
mNotificationHandler.showCrashedNotification(R.string.notification_out_of_disk_space, shortenedFileAndFolder);
}
}
}
}
/** /**
* Precondition: action != null * Precondition: action != null
*/ */
@ -300,6 +336,14 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
String relativeFilePath = updatedFile.toString(); String relativeFilePath = updatedFile.toString();
if (!TextUtils.isEmpty(error)) { if (!TextUtils.isEmpty(error)) {
Log.e(TAG, "onItemFinished: Error \"" + error + "\" reported on file: " + relativeFilePath); Log.e(TAG, "onItemFinished: Error \"" + error + "\" reported on file: " + relativeFilePath);
if (error.contains("no space left on device")) {
String[] segments = relativeFilePath.split(File.separator);
String shortenedFileAndFolder =
segments.length < 2 ?
relativeFilePath :
segments[segments.length-2] + File.separator + segments[segments.length-1];
mNotificationHandler.showCrashedNotification(R.string.notification_out_of_disk_space, shortenedFileAndFolder);
}
return; return;
} }

View file

@ -749,7 +749,7 @@ public class RestApi {
/** /**
* Called for each event. * Called for each event.
*/ */
void onEvent(Event event); void onEvent(Event event, JsonElement json);
/** /**
* Called after all available events have been processed. * Called after all available events have been processed.
@ -778,7 +778,7 @@ public class RestApi {
if (lastId < event.id) if (lastId < event.id)
lastId = event.id; lastId = event.id;
listener.onEvent(event); listener.onEvent(event, json);
} }
listener.onDone(lastId); listener.onDone(lastId);

View file

@ -821,6 +821,10 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<string name="notification_persistent_waiting_channel">Laufkonditionen werden überwacht</string> <string name="notification_persistent_waiting_channel">Laufkonditionen werden überwacht</string>
<string name="notifications_other_channel">Andere Benachrichtigungen</string> <string name="notifications_other_channel">Andere Benachrichtigungen</string>
<!-- EventProcessor -->
<string name="notification_out_of_disk_space">SD-Karte ist voll. Datei %1$s</string>
<!-- RestApi --> <!-- RestApi -->

View file

@ -842,6 +842,10 @@ Please report any problems you encounter via Github.</string>
<string name="notification_persistent_waiting_channel">Monitoring run conditions</string> <string name="notification_persistent_waiting_channel">Monitoring run conditions</string>
<string name="notifications_other_channel">Other notifications</string> <string name="notifications_other_channel">Other notifications</string>
<!-- EventProcessor -->
<string name="notification_out_of_disk_space">The SDcard is full. File %1$s</string>
<!-- RestApi --> <!-- RestApi -->