Show notification for low memory shutdown.

This commit is contained in:
akwizgran
2018-03-29 11:45:03 +01:00
parent 196cf15ef2
commit 8ebced9481
2 changed files with 23 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import org.briarproject.bramble.api.system.AndroidExecutor;
import org.briarproject.briar.R;
import org.briarproject.briar.android.logout.HideUiActivity;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import org.briarproject.briar.android.splash.SplashScreenActivity;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -221,6 +222,7 @@ public class BriarService extends Service {
super.onLowMemory();
LOG.warning("Memory is low");
shutdownFromBackground();
showLowMemoryShutdownNotification();
}
private void shutdownFromBackground() {
@@ -245,6 +247,24 @@ public class BriarService extends Service {
}).start();
}
private void showLowMemoryShutdownNotification() {
androidExecutor.runOnUiThread(() -> {
NotificationCompat.Builder b = new NotificationCompat.Builder(
BriarService.this, FAILURE_CHANNEL_ID);
b.setSmallIcon(android.R.drawable.stat_notify_error);
b.setContentTitle(getText(
R.string.low_memory_shutdown_notification_title));
b.setContentText(getText(
R.string.low_memory_shutdown_notification_text));
Intent i = new Intent(this, SplashScreenActivity.class);
b.setContentIntent(PendingIntent.getActivity(this, 0, i, 0));
b.setAutoCancel(true);
Object o = getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o;
nm.notify(FAILURE_NOTIFICATION_ID, b.build());
});
}
/**
* Waits for all services to start before returning.
*/

View File

@@ -411,4 +411,7 @@
<string name="permission_camera_denied_body">You have denied access to the camera, but adding contacts requires using the camera.\n\nPlease consider granting access.</string>
<string name="permission_camera_denied_toast">Camera permission was not granted</string>
<!-- Low Memory Notification -->
<string name="low_memory_shutdown_notification_title">Signed out of Briar</string>
<string name="low_memory_shutdown_notification_text">Signed out due to lack of memory.</string>
</resources>