Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c781baf authored by Sarp Misoglu's avatar Sarp Misoglu
Browse files

Retrieve a monitor for backup Tasks when it's missing

Currently the monitor is already passed in via the
BackupManager#requestBackup API. This CL covers all the other entry
points to backups (that are still maintained).

Full backups:

1. FullBackupJob -- scheduled by the framework
2. The "bmgr fullbackup" adb command

Key-Value backups:

1. KeyValueBackupJob -- scheduled by the framework
2. BackupManager#backupNow API
3. "bmgr run" adb command

Requesting the monitor in PFTBT.java covers the full backup cases.
Unfortunately we can't request the monitor any earlier since PFTBT
only has access to a transport connection at this point. This means
sometimes (when KVBackupTask starts PFTBT when requestBackup() is
called) we won't need to request the monitor-- hence the null check.

Requesting it in BackupHandler when handling the MSG_RUN_BACKUP
covers the KV backups.

Bug: 252763821
Test: atest CtsBackupHostTestCases
Also manually by running the following commands and verifying the
correct methods are called with logcat logs.
  adb shell cmd jobscheduler run -f android {FullBackupJob id}
  adb shell bmgr fullbackup --all
  adb shell cmd jobscheduler run -f android {KeyValueBackupJob id}
  adb shell bmgr run --all

Change-Id: I1c49c30e5fa8d174f0974aef8384d1a113fa6c88
parent 64379f23
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -376,6 +376,16 @@ public class PerformFullTransportBackupTask extends FullBackupTask implements Ba
                return;
                return;
            }
            }


            // In some cases there may not be a monitor passed in when creating this task. So, if we
            // don't have one already we ask the transport for a monitor.
            if (mMonitor == null) {
                try {
                    mMonitor = transport.getBackupManagerMonitor();
                } catch (RemoteException e) {
                    Slog.i(TAG, "Failed to retrieve monitor from transport");
                }
            }

            // Set up to send data to the transport
            // Set up to send data to the transport
            final int N = mPackages.size();
            final int N = mPackages.size();
            final byte[] buffer = new byte[8192];
            final byte[] buffer = new byte[8192];
+10 −1
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
import static com.android.server.backup.BackupManagerService.TAG;
import static com.android.server.backup.BackupManagerService.TAG;


import android.app.backup.BackupManager.OperationType;
import android.app.backup.BackupManager.OperationType;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.RestoreSet;
import android.app.backup.RestoreSet;
import android.os.Handler;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.HandlerThread;
@@ -203,6 +204,14 @@ public class BackupHandler extends Handler {
                    }
                    }
                }
                }


                // Ask the transport for a monitor that will be used to relay log events back to it.
                IBackupManagerMonitor monitor = null;
                try {
                    monitor = transport.getBackupManagerMonitor();
                } catch (RemoteException e) {
                    Slog.i(TAG, "Failed to retrieve monitor from transport");
                }

                // At this point, we have started a new journal file, and the old
                // At this point, we have started a new journal file, and the old
                // file identity is being passed to the backup processing task.
                // file identity is being passed to the backup processing task.
                // When it completes successfully, that old journal file will be
                // When it completes successfully, that old journal file will be
@@ -225,7 +234,7 @@ public class BackupHandler extends Handler {
                                queue,
                                queue,
                                oldJournal,
                                oldJournal,
                                /* observer */ null,
                                /* observer */ null,
                                /* monitor */ null,
                                monitor,
                                listener,
                                listener,
                                Collections.emptyList(),
                                Collections.emptyList(),
                                /* userInitiated */ false,
                                /* userInitiated */ false,
+11 −0
Original line number Original line Diff line number Diff line
@@ -18,10 +18,12 @@ package com.android.server.backup.transport;


import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.backup.BackupTransport;
import android.app.backup.BackupTransport;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.RestoreDescription;
import android.app.backup.RestoreDescription;
import android.app.backup.RestoreSet;
import android.app.backup.RestoreSet;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInfo;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Slog;
import android.util.Slog;
@@ -362,6 +364,15 @@ public class BackupTransportClient {
        return result == null ? BackupTransport.TRANSPORT_ERROR : result;
        return result == null ? BackupTransport.TRANSPORT_ERROR : result;
    }
    }


    /**
     * See {@link IBackupTransport#getBackupManagerMonitor()}
     */
    public IBackupManagerMonitor getBackupManagerMonitor() throws RemoteException {
        AndroidFuture<IBackupManagerMonitor> resultFuture = mTransportFutures.newFuture();
        mTransportBinder.getBackupManagerMonitor(resultFuture);
        return IBackupManagerMonitor.Stub.asInterface((IBinder) getFutureResult(resultFuture));
    }

    /**
    /**
     * Allows the {@link TransportConnection} to notify this client
     * Allows the {@link TransportConnection} to notify this client
     * if the underlying transport has become unusable.  If that happens
     * if the underlying transport has become unusable.  If that happens