Merge "Pass result back from RecentsRedactionActivity." into pie-cts-dev
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 950e2a9..339aafc 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -2636,11 +2636,15 @@
</intent-filter>
<intent-filter>
<action android:name="com.android.cts.verifier.managedprovisioning.BYOD_STATUS" />
- <category android:name="android.intent.category.DEFAULT"></category>
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="com.android.cts.verifier.managedprovisioning.BYOD_TEST_RESULT" />
+ <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.android.cts.verifier.managedprovisioning.action.BYOD_DISK_ENCRYPTION_STATUS" />
- <category android:name="android.intent.category.DEFAULT"></category>
+ <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="test_category" android:value="@string/test_category_managed_provisioning" />
<meta-data android:name="test_required_features" android:value="android.software.managed_users:android.software.device_admin" />
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/TestResult.java b/apps/CtsVerifier/src/com/android/cts/verifier/TestResult.java
index c5d2d52..07208dd 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/TestResult.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/TestResult.java
@@ -68,7 +68,7 @@
testDetails, reportLog));
}
- private static Intent createResult(Activity activity, int testResult, String testName,
+ public static Intent createResult(Activity activity, int testResult, String testName,
String testDetails, ReportLog reportLog) {
Intent data = new Intent(activity, activity.getClass());
addResultData(data, testResult, testName, testDetails, reportLog);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java
index 9767530..5f90b66 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java
@@ -53,6 +53,12 @@
*/
public class ByodFlowTestActivity extends DialogTestListActivity {
+ // Action for delivering sub-test result from the profile.
+ public static final String ACTION_TEST_RESULT =
+ "com.android.cts.verifier.managedprovisioning.BYOD_TEST_RESULT";
+ // Extra for ACTION_TEST_RESULT containing test result.
+ public static final String EXTRA_RESULT = "extra-result";
+
private static final String TAG = "ByodFlowTestActivity";
private static ConnectivityManager mCm;
private static final int REQUEST_MANAGED_PROVISIONING = 0;
@@ -151,10 +157,13 @@
@Override
protected void onNewIntent(Intent intent) {
- // This is called when managed provisioning completes successfully without reboot.
super.onNewIntent(intent);
if (ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS.equals(intent.getAction())) {
+ // This is called when managed provisioning completes successfully without reboot.
handleStatusUpdate(RESULT_OK, intent);
+ } else if (ACTION_TEST_RESULT.equals(intent.getAction())) {
+ // Called when subtest cannot communicate test result from the profile via setResult().
+ handleLaunchTestResult(RESULT_OK, intent.getParcelableExtra(EXTRA_RESULT));
}
}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestHelper.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestHelper.java
index 485e4d8..24e0919 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestHelper.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestHelper.java
@@ -2,6 +2,7 @@
import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
public class ByodFlowTestHelper {
@@ -17,6 +18,23 @@
setComponentsEnabledState(PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
}
+ /** Reports result to ByodFlowTestActivity if it is impossible via normal setResult. */
+ public void sendResultToPrimary(Intent result) {
+ final Intent intent = new Intent(ByodFlowTestActivity.ACTION_TEST_RESULT);
+ intent.putExtra(ByodFlowTestActivity.EXTRA_RESULT, result);
+ startActivityInPrimary(intent);
+ }
+
+ public void startActivityInPrimary(Intent intent) {
+ // Disable app components in the current profile, so only the counterpart in the other
+ // profile can respond (via cross-profile intent filter)
+ mContext.getPackageManager().setComponentEnabledSetting(
+ new ComponentName(mContext, ByodFlowTestActivity.class),
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ PackageManager.DONT_KILL_APP);
+ mContext.startActivity(intent);
+ }
+
/**
* Clean up things. This has to be working even it is called multiple times.
*/
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodHelperActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodHelperActivity.java
index ab2f9d0..9bb9cf8 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodHelperActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodHelperActivity.java
@@ -219,7 +219,7 @@
// Jump back to CTS verifier with result.
Intent response = new Intent(ACTION_PROFILE_OWNER_STATUS);
response.putExtra(EXTRA_PROVISIONED, isProfileOwner());
- startActivityInPrimary(response);
+ new ByodFlowTestHelper(this).startActivityInPrimary(response);
// Queried by CtsVerifier in the primary side using startActivityForResult.
} else if (action.equals(ACTION_QUERY_PROFILE_OWNER)) {
Intent response = new Intent();
@@ -514,16 +514,6 @@
}
}
- private void startActivityInPrimary(Intent intent) {
- // Disable app components in the current profile, so only the counterpart in the other
- // profile can respond (via cross-profile intent filter)
- getPackageManager().setComponentEnabledSetting(new ComponentName(
- this, ByodFlowTestActivity.class),
- PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
- PackageManager.DONT_KILL_APP);
- startActivity(intent);
- }
-
private void grantCameraPermissionToSelf() {
mDevicePolicyManager.setPermissionGrantState(mAdminReceiverComponent, getPackageName(),
android.Manifest.permission.CAMERA,
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/DeviceAdminTestReceiver.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/DeviceAdminTestReceiver.java
index d81c155..abad5b5 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/DeviceAdminTestReceiver.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/DeviceAdminTestReceiver.java
@@ -184,6 +184,7 @@
filter = new IntentFilter();
filter.addAction(ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS);
filter.addAction(ByodHelperActivity.ACTION_DISK_ENCRYPTION_STATUS);
+ filter.addAction(ByodFlowTestActivity.ACTION_TEST_RESULT);
filter.addAction(CrossProfileTestActivity.ACTION_CROSS_PROFILE_TO_PERSONAL);
filter.addAction(LocationListenerActivity.ACTION_SET_LOCATION_AND_CHECK_UPDATES);
dpm.addCrossProfileIntentFilter(getWho(context), filter,
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/RecentsRedactionActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/RecentsRedactionActivity.java
index d9b6fda..a49985d 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/RecentsRedactionActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/RecentsRedactionActivity.java
@@ -28,6 +28,7 @@
import com.android.cts.verifier.ArrayTestListAdapter;
import com.android.cts.verifier.DialogTestListActivity;
import com.android.cts.verifier.R;
+import com.android.cts.verifier.TestResult;
/**
* This test verifies that if a work profile is locked with a separate password, Recents views for
@@ -52,10 +53,33 @@
/* instructions */ R.string.provisioning_byod_recents_instructions);
}
+ // Default listener will use setResult(), which won't work due to activity being in a new task.
+ private View.OnClickListener clickListener = target -> {
+ final int resultCode;
+ switch (target.getId()) {
+ case R.id.pass_button:
+ resultCode = TestResult.TEST_RESULT_PASSED;
+ break;
+ case R.id.fail_button:
+ resultCode = TestResult.TEST_RESULT_FAILED;
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown id: " + target.getId());
+ }
+ Intent resultIntent = TestResult.createResult(RecentsRedactionActivity.this, resultCode,
+ getTestId(), getTestDetails(), getReportLog());
+
+ new ByodFlowTestHelper(this).sendResultToPrimary(resultIntent);
+ finish();
+ };
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ findViewById(R.id.pass_button).setOnClickListener(clickListener);
+ findViewById(R.id.fail_button).setOnClickListener(clickListener);
+
mPrepareTestButton.setText(R.string.provisioning_byod_recents_lock_now);
mPrepareTestButton.setOnClickListener((View view) -> {
mDevicePolicyManager.lockNow();