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

Commit 623ad185 authored by Ruslan Tkhakokhov's avatar Ruslan Tkhakokhov
Browse files

Increase restore timeout for system agents

This change is motivated by b/161248425 where the restore times out before all
call logs can be restored by CallLogBackupAgent. The CL increases
restore time limit for agents running in the system process. See the
linked bug below for rationale as to why the change is limited to system
agents only.

Changes in the CL:
  * Split timeouts for restore session and agent restore into 2 separate
    values in BackupAgentTimeoutParameters, so that the latter can be
    changed independently.
  * Pass application UID to #getRestoreSessionTimeoutMillis() so that we
    adjust the return value  based on whether the agent is part of the system.

Bug: 170076589
Test: 1. atest BackupAgentTimeoutParametersTest
      2. Populate 7000 call log entries; run backup; clear call history;
         run restore and verify it fails without the change and succeeds
         with the change.
Change-Id: Id32e34973be380f7206cb9000ca95e6b76bbf8c0
parent 7532b221
Loading
Loading
Loading
Loading
+41 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.backup;

import android.content.ContentResolver;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.KeyValueListParser;
import android.util.KeyValueSettingObserver;
@@ -52,10 +53,18 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
    public static final String SETTING_RESTORE_AGENT_TIMEOUT_MILLIS =
            "restore_agent_timeout_millis";

    @VisibleForTesting
    public static final String SETTING_RESTORE_SYSTEM_AGENT_TIMEOUT_MILLIS =
            "restore_system_agent_timeout_millis";

    @VisibleForTesting
    public static final String SETTING_RESTORE_AGENT_FINISHED_TIMEOUT_MILLIS =
            "restore_agent_finished_timeout_millis";

    @VisibleForTesting
    public static final String SETTING_RESTORE_SESSION_TIMEOUT_MILLIS =
            "restore_session_timeout_millis";

    @VisibleForTesting
    public static final String SETTING_QUOTA_EXCEEDED_TIMEOUT_MILLIS =
            "quota_exceeded_timeout_millis";
@@ -71,9 +80,14 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {

    @VisibleForTesting public static final long DEFAULT_RESTORE_AGENT_TIMEOUT_MILLIS = 60 * 1000;

    @VisibleForTesting public static final long DEFAULT_RESTORE_SYSTEM_AGENT_TIMEOUT_MILLIS =
            180 * 1000;

    @VisibleForTesting
    public static final long DEFAULT_RESTORE_AGENT_FINISHED_TIMEOUT_MILLIS = 30 * 1000;

    @VisibleForTesting public static final long DEFAULT_RESTORE_SESSION_TIMEOUT_MILLIS = 60 * 1000;

    @VisibleForTesting
    public static final long DEFAULT_QUOTA_EXCEEDED_TIMEOUT_MILLIS = 3 * 1000;

@@ -89,6 +103,12 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
    @GuardedBy("mLock")
    private long mRestoreAgentTimeoutMillis;

    @GuardedBy("mLock")
    private long mRestoreSystemAgentTimeoutMillis;

    @GuardedBy("mLock")
    private long mRestoreSessionTimeoutMillis;

    @GuardedBy("mLock")
    private long mRestoreAgentFinishedTimeoutMillis;

@@ -123,10 +143,18 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
                    parser.getLong(
                            SETTING_RESTORE_AGENT_TIMEOUT_MILLIS,
                            DEFAULT_RESTORE_AGENT_TIMEOUT_MILLIS);
            mRestoreSystemAgentTimeoutMillis =
                    parser.getLong(
                            SETTING_RESTORE_SYSTEM_AGENT_TIMEOUT_MILLIS,
                            DEFAULT_RESTORE_SYSTEM_AGENT_TIMEOUT_MILLIS);
            mRestoreAgentFinishedTimeoutMillis =
                    parser.getLong(
                            SETTING_RESTORE_AGENT_FINISHED_TIMEOUT_MILLIS,
                            DEFAULT_RESTORE_AGENT_FINISHED_TIMEOUT_MILLIS);
            mRestoreSessionTimeoutMillis =
                    parser.getLong(
                            SETTING_RESTORE_SESSION_TIMEOUT_MILLIS,
                            DEFAULT_RESTORE_SESSION_TIMEOUT_MILLIS);
            mQuotaExceededTimeoutMillis =
                    parser.getLong(
                            SETTING_QUOTA_EXCEEDED_TIMEOUT_MILLIS,
@@ -152,9 +180,20 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
        }
    }

    public long getRestoreAgentTimeoutMillis() {
    /**
     * @param applicationUid UID of the application for which to get restore timeout
     * @return restore timeout in milliseconds
     */
    public long getRestoreAgentTimeoutMillis(int applicationUid) {
        synchronized (mLock) {
            return UserHandle.isCore(applicationUid) ? mRestoreSystemAgentTimeoutMillis :
                    mRestoreAgentTimeoutMillis;
        }
    }

    public long getRestoreSessionTimeoutMillis() {
        synchronized (mLock) {
            return mRestoreAgentTimeoutMillis;
            return mRestoreSessionTimeoutMillis;
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -4088,7 +4088,7 @@ public class UserBackupManagerService {
            mActiveRestoreSession = new ActiveRestoreSession(this, packageName, transport,
                    getEligibilityRulesForOperation(operationType));
            mBackupHandler.sendEmptyMessageDelayed(MSG_RESTORE_SESSION_TIMEOUT,
                    mAgentTimeoutParameters.getRestoreAgentTimeoutMillis());
                    mAgentTimeoutParameters.getRestoreSessionTimeoutMillis());
        }
        return mActiveRestoreSession;
    }
+1 −1
Original line number Diff line number Diff line
@@ -390,7 +390,7 @@ public class BackupHandler extends Handler {
                    // Done: reset the session timeout clock
                    removeMessages(MSG_RESTORE_SESSION_TIMEOUT);
                    sendEmptyMessageDelayed(MSG_RESTORE_SESSION_TIMEOUT,
                            mAgentTimeoutParameters.getRestoreAgentTimeoutMillis());
                            mAgentTimeoutParameters.getRestoreSessionTimeoutMillis());

                    params.listener.onFinished(callerLogString);
                }
+2 −1
Original line number Diff line number Diff line
@@ -403,7 +403,8 @@ public class FullRestoreEngine extends RestoreEngine {
                        final boolean isSharedStorage = pkg.equals(SHARED_BACKUP_AGENT_PACKAGE);
                        final long timeout = isSharedStorage ?
                                mAgentTimeoutParameters.getSharedBackupAgentTimeoutMillis() :
                                mAgentTimeoutParameters.getRestoreAgentTimeoutMillis();
                                mAgentTimeoutParameters.getRestoreAgentTimeoutMillis(
                                        mTargetApp.uid);
                        try {
                            mBackupManagerService.prepareOperationTimeout(token,
                                    timeout,
+7 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.content.pm.PackageManagerInternal;
import android.os.Bundle;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
@@ -433,6 +434,8 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask {
            // Pull the Package Manager metadata from the restore set first
            mCurrentPackage = new PackageInfo();
            mCurrentPackage.packageName = PACKAGE_MANAGER_SENTINEL;
            mCurrentPackage.applicationInfo = new ApplicationInfo();
            mCurrentPackage.applicationInfo.uid = Process.SYSTEM_UID;
            mPmAgent = backupManagerService.makeMetadataAgent(null);
            mAgent = IBackupAgent.Stub.asInterface(mPmAgent.onBind());
            if (MORE_DEBUG) {
@@ -760,7 +763,8 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask {
            // Kick off the restore, checking for hung agents.  The timeout or
            // the operationComplete() callback will schedule the next step,
            // so we do not do that here.
            long restoreAgentTimeoutMillis = mAgentTimeoutParameters.getRestoreAgentTimeoutMillis();
            long restoreAgentTimeoutMillis = mAgentTimeoutParameters.getRestoreAgentTimeoutMillis(
                    app.applicationInfo.uid);
            backupManagerService.prepareOperationTimeout(
                    mEphemeralOpToken, restoreAgentTimeoutMillis, this, OP_TYPE_RESTORE_WAIT);
            startedAgentRestore = true;
@@ -1122,7 +1126,8 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask {
        } else {
            // We were invoked via an active restore session, not by the Package
            // Manager, so start up the session timeout again.
            long restoreAgentTimeoutMillis = mAgentTimeoutParameters.getRestoreAgentTimeoutMillis();
            long restoreAgentTimeoutMillis =
                    mAgentTimeoutParameters.getRestoreSessionTimeoutMillis();
            backupManagerService.getBackupHandler().sendEmptyMessageDelayed(
                    MSG_RESTORE_SESSION_TIMEOUT,
                    restoreAgentTimeoutMillis);
Loading