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

Commit 97f29153 authored by Nupur Saxena's avatar Nupur Saxena Committed by Android (Google) Code Review
Browse files

Merge "Add retry logic to copy account during personal to work profile account migration" into main

parents 7cd86981 b196c002
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -173,6 +173,17 @@ flag {
  bug: "322777918"
}

flag {
  name: "copy_account_with_retry_enabled"
  namespace: "enterprise"
  description: "Retry copy and remove account from personal to work profile in case of failure"
  bug: "329424312"
  metadata {
      purpose: PURPOSE_BUGFIX
  }
}


flag {
  name: "esim_management_ux_enabled"
  namespace: "enterprise"
+20 −2
Original line number Diff line number Diff line
@@ -888,6 +888,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    private static final String APPLICATION_EXEMPTIONS_FLAG = "application_exemptions";
    private static final boolean DEFAULT_APPLICATION_EXEMPTIONS_FLAG = true;
    private static final int RETRY_COPY_ACCOUNT_ATTEMPTS = 3;
    /**
     * For apps targeting U+
     * Enable multiple admins to coexist on the same device.
@@ -21514,13 +21516,26 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            Slogf.w(LOG_TAG, "sourceUser and targetUser are the same, won't migrate account.");
            return;
        }
        if (Flags.copyAccountWithRetryEnabled()) {
            boolean copySucceeded = false;
            int retryAttemptsLeft = RETRY_COPY_ACCOUNT_ATTEMPTS;
            while (!copySucceeded && (retryAttemptsLeft > 0)) {
                Slogf.i(LOG_TAG, "Copying account. Attempts left : " + retryAttemptsLeft);
                copySucceeded =
                        copyAccount(targetUser, sourceUser, accountToMigrate, callerPackage);
                retryAttemptsLeft--;
            }
        } else {
            copyAccount(targetUser, sourceUser, accountToMigrate, callerPackage);
        }
        if (!keepAccountMigrated) {
            removeAccount(accountToMigrate, sourceUserId);
        }
    }
    private void copyAccount(
    private boolean copyAccount(
            UserHandle targetUser, UserHandle sourceUser, Account accountToMigrate,
            String callerPackage) {
        final long startTime = SystemClock.elapsedRealtime();
@@ -21538,6 +21553,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                        DevicePolicyEnums.PLATFORM_PROVISIONING_COPY_ACCOUNT_MS,
                        startTime,
                        callerPackage);
                Slogf.i(LOG_TAG, "Copy account successful to " + targetUser);
                return true;
            } else {
                logCopyAccountStatus(COPY_ACCOUNT_FAILED, callerPackage);
                Slogf.e(LOG_TAG, "Failed to copy account to " + targetUser);
@@ -21550,6 +21567,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            logCopyAccountStatus(COPY_ACCOUNT_EXCEPTION, callerPackage);
            Slogf.e(LOG_TAG, "Exception copying account to " + targetUser, e);
        }
        return false;
    }
    private static void logCopyAccountStatus(@CopyAccountStatus int status, String callerPackage) {