Do not validate FRP if started by setup wizard

If started by LEGACY_ACTION_PROVISION_MANAGED_DEVICE  or
ACTION_PROVISION_MANAGED_DEVICE, do not validate FRP as setup wizard
must have already validated it. In fact SUW might have just added an
account which will confuse MP about whether FRP is activated by a
previous account or the newly-added account.

Bug: 21748042
Change-Id: I34211ce16965f723080983a5f93c4a2a8a9f5c47
diff --git a/src/com/android/managedprovisioning/DeviceOwnerPreProvisioningActivity.java b/src/com/android/managedprovisioning/DeviceOwnerPreProvisioningActivity.java
index ddcb0f4..f39d220 100644
--- a/src/com/android/managedprovisioning/DeviceOwnerPreProvisioningActivity.java
+++ b/src/com/android/managedprovisioning/DeviceOwnerPreProvisioningActivity.java
@@ -181,6 +181,20 @@
             ProvisionLogger.logd("Reset protection check skipped on secondary users.");
             return false;
         }
+
+        // If we are started by setup wizard, do not check for factory reset protection since setup
+        // wizard must have already validated it. This avoids provisioning being blocked by FRP
+        // if an account was added in the setup wizard on devices that enforce FRP as soon as the
+        // account is added.
+        if (getIntent() != null) {
+            String action = getIntent().getAction();
+            if (ACTION_PROVISION_MANAGED_DEVICE.equals(action) ||
+                    LEGACY_ACTION_PROVISION_MANAGED_DEVICE.equals(action)) {
+                ProvisionLogger.logd("FRP not required if started by SUW");
+                return false;
+            }
+        }
+
         PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
                 getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
         if (pdbManager == null) {