Added service breadcrumbs

This commit is contained in:
M66B 2019-07-26 13:55:00 +02:00
parent 4c433674e3
commit 490cb6cc80
3 changed files with 70 additions and 4 deletions

View File

@ -0,0 +1,68 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.content.Intent;
import android.os.Bundle;
import androidx.lifecycle.LifecycleService;
import com.bugsnag.android.BreadcrumbType;
import com.bugsnag.android.Bugsnag;
import java.util.HashMap;
import java.util.Map;
abstract class ServiceBase extends LifecycleService {
@Override
public void onCreate() {
Map<String, String> crumb = new HashMap<>();
crumb.put("state", "create");
Bugsnag.leaveBreadcrumb(this.getClass().getSimpleName(), BreadcrumbType.STATE, crumb);
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Map<String, String> crumb = new HashMap<>();
if (intent != null) {
crumb.put("action", intent.getAction());
Bundle data = intent.getExtras();
if (data != null)
for (String key : data.keySet()) {
Object value = data.get(key);
crumb.put(key, value == null ? null : value.toString());
}
}
Bugsnag.leaveBreadcrumb(this.getClass().getSimpleName(), BreadcrumbType.LOG, crumb);
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
Map<String, String> crumb = new HashMap<>();
crumb.put("state", "destroy");
Bugsnag.leaveBreadcrumb(this.getClass().getSimpleName(), BreadcrumbType.STATE, crumb);
super.onDestroy();
}
}

View File

@ -33,7 +33,6 @@ import android.text.TextUtils;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleService;
import androidx.lifecycle.Observer;
import androidx.preference.PreferenceManager;
@ -63,7 +62,7 @@ import javax.mail.internet.MimeMessage;
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
public class ServiceSend extends LifecycleService {
public class ServiceSend extends ServiceBase {
private int lastUnsent = 0;
private boolean lastSuitable = false;
private TwoStateOwner cowner;

View File

@ -39,7 +39,6 @@ import androidx.annotation.Nullable;
import androidx.core.app.AlarmManagerCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleService;
import androidx.lifecycle.Observer;
import androidx.preference.PreferenceManager;
@ -92,7 +91,7 @@ import javax.mail.event.StoreListener;
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
public class ServiceSynchronize extends LifecycleService {
public class ServiceSynchronize extends ServiceBase {
private ConnectionHelper.NetworkState networkState = new ConnectionHelper.NetworkState();
private Core.State state;
private int lastStartId = -1;