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

Commit 5b07d5bc authored by Annie Meng's avatar Annie Meng Committed by Android (Google) Code Review
Browse files

Merge "Unrevert update references to backup agent timeouts"

parents 1edca2c3 a1e8fd61
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.Handler;
import android.provider.Settings;
import android.util.KeyValueListParser;
import android.util.KeyValueSettingObserver;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

@@ -31,6 +32,8 @@ import com.android.internal.annotations.VisibleForTesting;
 * are represented as a comma-delimited key value list.
 */
public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
    private static final String TAG = "BackupAgentTimeout";

    @VisibleForTesting
    public static final String SETTING = Settings.Global.BACKUP_AGENT_TIMEOUT_PARAMETERS;

@@ -120,30 +123,50 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {

    public long getKvBackupAgentTimeoutMillis() {
        synchronized (mLock) {
            if (BackupManagerService.DEBUG_SCHEDULING) {
                Slog.v(TAG, "getKvBackupAgentTimeoutMillis(): " + mKvBackupAgentTimeoutMillis);
            }
            return mKvBackupAgentTimeoutMillis;
        }
    }

    public long getFullBackupAgentTimeoutMillis() {
        synchronized (mLock) {
            if (BackupManagerService.DEBUG_SCHEDULING) {
                Slog.v(TAG, "getFullBackupAgentTimeoutMillis(): " + mFullBackupAgentTimeoutMillis);
            }
            return mFullBackupAgentTimeoutMillis;
        }
    }

    public long getSharedBackupAgentTimeoutMillis() {
        synchronized (mLock) {
            if (BackupManagerService.DEBUG_SCHEDULING) {
                Slog.v(
                        TAG,
                        "getSharedBackupAgentTimeoutMillis(): " + mSharedBackupAgentTimeoutMillis);
            }
            return mSharedBackupAgentTimeoutMillis;
        }
    }

    public long getRestoreAgentTimeoutMillis() {
        synchronized (mLock) {
            if (BackupManagerService.DEBUG_SCHEDULING) {
                Slog.v(TAG, "getRestoreAgentTimeoutMillis(): " + mRestoreAgentTimeoutMillis);
            }
            return mRestoreAgentTimeoutMillis;
        }
    }

    public long getRestoreAgentFinishedTimeoutMillis() {
        synchronized (mLock) {
            if (BackupManagerService.DEBUG_SCHEDULING) {
                Slog.v(
                        TAG,
                        "getRestoreAgentFinishedTimeoutMillis(): "
                                + mRestoreAgentFinishedTimeoutMillis);
            }
            return mRestoreAgentFinishedTimeoutMillis;
        }
    }
+10 −8
Original line number Diff line number Diff line
@@ -215,13 +215,6 @@ public class BackupManagerService implements BackupManagerServiceInterface {
    // Timeout interval for deciding that a bind or clear-data has taken too long
    private static final long TIMEOUT_INTERVAL = 10 * 1000;

    // Timeout intervals for agent backup & restore operations
    public static final long TIMEOUT_BACKUP_INTERVAL = 30 * 1000;
    public static final long TIMEOUT_FULL_BACKUP_INTERVAL = 5 * 60 * 1000;
    public static final long TIMEOUT_SHARED_BACKUP_INTERVAL = 30 * 60 * 1000;
    public static final long TIMEOUT_RESTORE_INTERVAL = 60 * 1000;
    public static final long TIMEOUT_RESTORE_FINISHED_INTERVAL = 30 * 1000;

    // User confirmation timeout for a full backup/restore operation.  It's this long in
    // order to give them time to enter the backup password.
    private static final long TIMEOUT_FULL_CONFIRMATION = 60 * 1000;
@@ -232,6 +225,7 @@ public class BackupManagerService implements BackupManagerServiceInterface {
    private static final int BUSY_BACKOFF_FUZZ = 1000 * 60 * 60 * 2;  // two hours

    private BackupManagerConstants mConstants;
    private final BackupAgentTimeoutParameters mAgentTimeoutParameters;
    private Context mContext;
    private PackageManager mPackageManager;
    private IPackageManager mPackageManagerBinder;
@@ -315,6 +309,10 @@ public class BackupManagerService implements BackupManagerServiceInterface {
        return mConstants;
    }

    public BackupAgentTimeoutParameters getAgentTimeoutParameters() {
        return mAgentTimeoutParameters;
    }

    public Context getContext() {
        return mContext;
    }
@@ -799,6 +797,10 @@ public class BackupManagerService implements BackupManagerServiceInterface {

        mBackupManagerBinder = Trampoline.asInterface(parent.asBinder());

        mAgentTimeoutParameters = new
                BackupAgentTimeoutParameters(Handler.getMain(), mContext.getContentResolver());
        mAgentTimeoutParameters.start();

        // spin up the backup/restore handler thread
        mBackupHandler = new BackupHandler(this, backupThread.getLooper());

@@ -3407,7 +3409,7 @@ public class BackupManagerService implements BackupManagerServiceInterface {
            }
            mActiveRestoreSession = new ActiveRestoreSession(this, packageName, transport);
            mBackupHandler.sendEmptyMessageDelayed(MSG_RESTORE_SESSION_TIMEOUT,
                    TIMEOUT_RESTORE_INTERVAL);
                    mAgentTimeoutParameters.getRestoreAgentTimeoutMillis());
        }
        return mActiveRestoreSession;
    }
+3 −0
Original line number Diff line number Diff line
@@ -191,4 +191,7 @@ public interface BackupManagerServiceInterface {
  void dump(FileDescriptor fd, PrintWriter pw, String[] args);

  IBackupManager getBackupManagerBinder();

  // Gets access to the backup/restore agent timeout parameters.
  BackupAgentTimeoutParameters getAgentTimeoutParameters();
}
+10 −4
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@ import static android.os.ParcelFileDescriptor.MODE_CREATE;
import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;
import static android.os.ParcelFileDescriptor.MODE_READ_WRITE;
import static android.os.ParcelFileDescriptor.MODE_TRUNCATE;

import static com.android.server.backup.BackupManagerService.OP_TYPE_BACKUP_WAIT;
import static com.android.server.backup.BackupManagerService.TIMEOUT_BACKUP_INTERVAL;

import android.app.ApplicationThreadConstants;
import android.app.IBackupAgent;
@@ -19,6 +19,7 @@ import android.os.RemoteException;
import android.os.SELinux;
import android.util.Slog;

import com.android.internal.util.Preconditions;
import com.android.server.backup.utils.FullBackupUtils;

import libcore.io.IoUtils;
@@ -59,6 +60,7 @@ public class KeyValueAdbBackupEngine {
    private ParcelFileDescriptor mSavedState;
    private ParcelFileDescriptor mBackupData;
    private ParcelFileDescriptor mNewState;
    private final BackupAgentTimeoutParameters mAgentTimeoutParameters;

    public KeyValueAdbBackupEngine(OutputStream output, PackageInfo packageInfo,
            BackupManagerServiceInterface backupManagerService, PackageManager packageManager,
@@ -81,6 +83,9 @@ public class KeyValueAdbBackupEngine {
                pkg + BACKUP_KEY_VALUE_NEW_STATE_FILENAME_SUFFIX);

        mManifestFile = new File(mDataDir, BackupManagerService.BACKUP_MANIFEST_FILENAME);
        mAgentTimeoutParameters = Preconditions.checkNotNull(
                backupManagerService.getAgentTimeoutParameters(),
                "Timeout parameters cannot be null");
    }

    public void backupOnePackage() throws IOException {
@@ -148,8 +153,9 @@ public class KeyValueAdbBackupEngine {
    // Return true on backup success, false otherwise
    private boolean invokeAgentForAdbBackup(String packageName, IBackupAgent agent) {
        int token = mBackupManagerService.generateRandomIntegerToken();
        long kvBackupAgentTimeoutMillis = mAgentTimeoutParameters.getKvBackupAgentTimeoutMillis();
        try {
            mBackupManagerService.prepareOperationTimeout(token, TIMEOUT_BACKUP_INTERVAL, null,
            mBackupManagerService.prepareOperationTimeout(token, kvBackupAgentTimeoutMillis, null,
                    OP_TYPE_BACKUP_WAIT);

            // Start backup and wait for BackupManagerService to get callback for success or timeout
@@ -231,14 +237,14 @@ public class KeyValueAdbBackupEngine {
    }

    private void writeBackupData() throws IOException {

        int token = mBackupManagerService.generateRandomIntegerToken();
        long kvBackupAgentTimeoutMillis = mAgentTimeoutParameters.getKvBackupAgentTimeoutMillis();

        ParcelFileDescriptor[] pipes = null;
        try {
            pipes = ParcelFileDescriptor.createPipe();

            mBackupManagerService.prepareOperationTimeout(token, TIMEOUT_BACKUP_INTERVAL, null,
            mBackupManagerService.prepareOperationTimeout(token, kvBackupAgentTimeoutMillis, null,
                    OP_TYPE_BACKUP_WAIT);

            // We will have to create a runnable that will read the manifest and backup data we
+9 −6
Original line number Diff line number Diff line
@@ -25,9 +25,6 @@ import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
import static com.android.server.backup.BackupManagerService.OP_TYPE_BACKUP_WAIT;
import static com.android.server.backup.BackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
import static com.android.server.backup.BackupManagerService.TAG;
import static com.android.server.backup.BackupManagerService.TIMEOUT_FULL_BACKUP_INTERVAL;
import static com.android.server.backup.BackupManagerService
        .TIMEOUT_SHARED_BACKUP_INTERVAL;

import android.app.ApplicationThreadConstants;
import android.app.IBackupAgent;
@@ -44,9 +41,11 @@ import android.util.Log;
import android.util.Slog;
import android.util.StringBuilderPrinter;

import com.android.internal.util.Preconditions;
import com.android.server.AppWidgetBackupBridge;
import com.android.server.backup.BackupRestoreTask;
import com.android.server.backup.BackupAgentTimeoutParameters;
import com.android.server.backup.BackupManagerService;
import com.android.server.backup.BackupRestoreTask;
import com.android.server.backup.utils.FullBackupUtils;

import java.io.BufferedOutputStream;
@@ -75,6 +74,7 @@ public class FullBackupEngine {
    private final long mQuota;
    private final int mOpToken;
    private final int mTransportFlags;
    private final BackupAgentTimeoutParameters mAgentTimeoutParameters;

    class FullBackupRunner implements Runnable {

@@ -137,8 +137,8 @@ public class FullBackupEngine {
                final boolean isSharedStorage =
                        mPackage.packageName.equals(SHARED_BACKUP_AGENT_PACKAGE);
                final long timeout = isSharedStorage ?
                        TIMEOUT_SHARED_BACKUP_INTERVAL :
                        TIMEOUT_FULL_BACKUP_INTERVAL;
                        mAgentTimeoutParameters.getSharedBackupAgentTimeoutMillis() :
                        mAgentTimeoutParameters.getFullBackupAgentTimeoutMillis();

                if (DEBUG) {
                    Slog.d(TAG, "Calling doFullBackup() on " + mPackage.packageName);
@@ -180,6 +180,9 @@ public class FullBackupEngine {
        mQuota = quota;
        mOpToken = opToken;
        mTransportFlags = transportFlags;
        mAgentTimeoutParameters = Preconditions.checkNotNull(
                backupManagerService.getAgentTimeoutParameters(),
                "Timeout parameters cannot be null");
    }

    public int preflightCheck() throws RemoteException {
Loading