Don't start transport service in foreground
Start it on-deman instead. This way, we don't need a foreground service and thus can target API 28
This commit is contained in:
parent
540147470d
commit
2037291f81
4 changed files with 16 additions and 12 deletions
|
@ -1,9 +1,6 @@
|
|||
package com.stevesoltys.backup;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.stevesoltys.backup.transport.ConfigurableBackupTransportService;
|
||||
|
||||
/**
|
||||
* @author Steve Soltys
|
||||
|
@ -12,10 +9,4 @@ public class Backup extends Application {
|
|||
|
||||
public static final int JOB_ID_BACKGROUND_BACKUP = 1;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
startForegroundService(new Intent(this, ConfigurableBackupTransportService.class));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.widget.Toast;
|
|||
import com.stevesoltys.backup.activity.backup.CreateBackupActivity;
|
||||
import com.stevesoltys.backup.activity.restore.RestoreBackupActivity;
|
||||
import com.stevesoltys.backup.service.backup.BackupJobService;
|
||||
import com.stevesoltys.backup.transport.ConfigurableBackupTransportService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -57,6 +58,9 @@ public class MainActivityController {
|
|||
showChooseFolderActivity(parent, true);
|
||||
} else {
|
||||
try {
|
||||
// ensure that backup service is started
|
||||
parent.startService(new Intent(parent, ConfigurableBackupTransportService.class));
|
||||
|
||||
Uri fileUri = createBackupFile(parent.getContentResolver(), folderUri);
|
||||
showCreateBackupActivity(parent, fileUri);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.backup.BackupManager;
|
|||
import android.app.backup.IBackupManager;
|
||||
import android.app.job.JobParameters;
|
||||
import android.app.job.JobService;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
@ -11,6 +12,7 @@ import android.util.Log;
|
|||
import com.google.android.collect.Sets;
|
||||
import com.stevesoltys.backup.service.PackageService;
|
||||
import com.stevesoltys.backup.service.TransportService;
|
||||
import com.stevesoltys.backup.transport.ConfigurableBackupTransportService;
|
||||
import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfiguration;
|
||||
import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfigurationBuilder;
|
||||
|
||||
|
@ -44,6 +46,7 @@ public class BackupJobService extends JobService {
|
|||
@Override
|
||||
public boolean onStartJob(JobParameters params) {
|
||||
Log.i(TAG, "Triggering full backup");
|
||||
startService(new Intent(this, ConfigurableBackupTransportService.class));
|
||||
try {
|
||||
LinkedList<String> packages = new LinkedList<>(new PackageService().getEligiblePackages());
|
||||
packages.removeAll(IGNORED_PACKAGES);
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package com.stevesoltys.backup.transport;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* @author Steve Soltys
|
||||
*/
|
||||
public class ConfigurableBackupTransportService extends Service {
|
||||
|
||||
private static final int FOREGROUND_ID = 43594;
|
||||
private static final String TAG = ConfigurableBackupTransportService.class.getName();
|
||||
|
||||
private static ConfigurableBackupTransport backupTransport = null;
|
||||
|
||||
|
@ -26,11 +26,17 @@ public class ConfigurableBackupTransportService extends Service {
|
|||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
startForeground(FOREGROUND_ID, new Notification.Builder(this).build());
|
||||
Log.d(TAG, "Service created.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return getBackupTransport().getBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.d(TAG, "Service destroyed.");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue