diff options
author | Benjamin Franz <bfranz@google.com> | 2015-10-15 15:50:02 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-10-15 15:50:02 +0000 |
commit | cbbd48b780414f413e88cbd1a088d7244ca826d0 (patch) | |
tree | 8663f57ec54d72f4110cab01a3ed51266da197ea | |
parent | 7dd68bc0d537b0231dcf8c2bf507fe4f8ac51929 (diff) | |
parent | 2b9ba6997cd8353e17c673701f31c11d2ddee11e (diff) | |
download | android_packages_apps_ManagedProvisioning-cbbd48b780414f413e88cbd1a088d7244ca826d0.tar.gz android_packages_apps_ManagedProvisioning-cbbd48b780414f413e88cbd1a088d7244ca826d0.tar.bz2 android_packages_apps_ManagedProvisioning-cbbd48b780414f413e88cbd1a088d7244ca826d0.zip |
am 2b9ba699: am 9e7ee617: Add extra checks and timeouts to account migration. DO NOT MERGE
* commit '2b9ba6997cd8353e17c673701f31c11d2ddee11e':
Add extra checks and timeouts to account migration. DO NOT MERGE
-rw-r--r-- | src/com/android/managedprovisioning/ProfileOwnerProvisioningService.java | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/src/com/android/managedprovisioning/ProfileOwnerProvisioningService.java b/src/com/android/managedprovisioning/ProfileOwnerProvisioningService.java index e13e53e4..93478b1c 100644 --- a/src/com/android/managedprovisioning/ProfileOwnerProvisioningService.java +++ b/src/com/android/managedprovisioning/ProfileOwnerProvisioningService.java @@ -25,6 +25,7 @@ import static android.Manifest.permission.BIND_DEVICE_ADMIN; import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AccountManagerFuture; +import android.accounts.AuthenticatorDescription; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.app.Activity; @@ -62,6 +63,7 @@ import com.android.managedprovisioning.task.DisableBluetoothSharingTask; import com.android.managedprovisioning.task.DisableInstallShortcutListenersTask; import java.io.IOException; +import java.util.concurrent.TimeUnit; /** * Service that runs the profile owner provisioning. @@ -94,6 +96,10 @@ public class ProfileOwnerProvisioningService extends Service { /** Provisioning cancelled and cleanup complete. */ private static final int STATUS_CANCELLED = 5; + private static final int ACCOUNT_COPY_TIMEOUT_SECONDS = 60 * 2; // 2 minutes + private static final int ACCOUNT_TYPE_RETRIES = 30; + private static final int ACCOUNT_TYPE_POLLING_TIMEOUT_MILLIS = 1000; // 1 second + private IPackageManager mIpm; private UserInfo mManagedProfileUserInfo; private AccountManager mAccountManager; @@ -434,26 +440,61 @@ public class ProfileOwnerProvisioningService extends Service { } private void copyAccount() { - if (mParams.accountToMigrate == null) { + if (mParams.accountToMigrate == null || mParams.accountToMigrate.type == null) { ProvisionLogger.logd("No account to migrate to the managed profile."); return; } ProvisionLogger.logd("Attempting to copy account to user " + mManagedProfileUserInfo.id); + if (!waitForAuthenticatorReadyForAccountType(mParams.accountToMigrate.type, + mManagedProfileUserInfo.id)) { + ProvisionLogger.loge("Could not copy account to user " + mManagedProfileUserInfo.id + + ". Authenticator missing for account type " + mParams.accountToMigrate.type); + return; + } try { - if (mAccountManager.copyAccountToUser(mParams.accountToMigrate, + boolean copySucceeded = mAccountManager.copyAccountToUser( + mParams.accountToMigrate, mManagedProfileUserInfo.getUserHandle(), - /* callback= */ null, /* handler= */ null).getResult()) { + /* callback= */ null, /* handler= */ null) + .getResult(ACCOUNT_COPY_TIMEOUT_SECONDS, TimeUnit.SECONDS); + if (copySucceeded) { ProvisionLogger.logi("Copied account to user " + mManagedProfileUserInfo.id); } else { ProvisionLogger.loge("Could not copy account to user " + mManagedProfileUserInfo.id); } } catch (OperationCanceledException | AuthenticatorException | IOException e) { - ProvisionLogger.logw("Exception copying account to user " + mManagedProfileUserInfo.id, + ProvisionLogger.loge("Exception copying account to user " + mManagedProfileUserInfo.id, e); } } + private boolean waitForAuthenticatorReadyForAccountType(String accountType, int userId) { + for (int i = 0; i < ACCOUNT_TYPE_RETRIES; i++) { + if (!isAuthenticatorPresent(accountType, userId)) { + try { + Thread.sleep(ACCOUNT_TYPE_POLLING_TIMEOUT_MILLIS); + } catch (InterruptedException e) { + return false; + } + } else { + return true; + } + } + return false; + } + + private boolean isAuthenticatorPresent(String accountType, int userId) { + AuthenticatorDescription[] authenticators = AccountManager.get(this) + .getAuthenticatorTypesAsUser(userId); + for (AuthenticatorDescription authenticator : authenticators) { + if (authenticator.type.equals(accountType)) { + return true; + } + } + return false; + } + private void createProfile(String profileName) throws ProvisioningException { ProvisionLogger.logd("Creating managed profile with name " + profileName); |