@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pass_fail_list);
    setInfoResources(
        R.string.device_owner_provisioning_tests, R.string.device_owner_provisioning_tests_info, 0);
    setPassFailButtonClickListeners();

    final ArrayTestListAdapter adapter = new ArrayTestListAdapter(this);
    adapter.add(TestListItem.newCategory(this, R.string.device_owner_provisioning_category));

    Intent startTestIntent =
        new Intent(this, IntentDrivenTestActivity.class)
            .putExtra(
                IntentDrivenTestActivity.EXTRA_ID, DEVICE_OWNER_NEGATIVE_TEST_INFO.getTestId())
            .putExtra(
                IntentDrivenTestActivity.EXTRA_TITLE, DEVICE_OWNER_NEGATIVE_TEST_INFO.getTitle())
            .putExtra(
                IntentDrivenTestActivity.EXTRA_INFO, DEVICE_OWNER_NEGATIVE_TEST_INFO.getInfoText())
            .putExtra(
                IntentDrivenTestActivity.EXTRA_BUTTONS,
                DEVICE_OWNER_NEGATIVE_TEST_INFO.getButtons());

    adapter.add(
        TestListItem.newTest(
            this,
            DEVICE_OWNER_NEGATIVE_TEST_INFO.getTitle(),
            DEVICE_OWNER_NEGATIVE_TEST_INFO.getTestId(),
            startTestIntent,
            null));

    adapter.registerDataSetObserver(
        new DataSetObserver() {
          @Override
          public void onChanged() {
            updatePassButton();
          }
        });

    setTestListAdapter(adapter);
  }
  @Override
  protected void setupTests(ArrayTestListAdapter adapter) {
    mProfileOwnerInstalled =
        new DialogTestListItem(
            this, R.string.provisioning_byod_profileowner, "BYOD_ProfileOwnerInstalled") {
          @Override
          public void performTest(DialogTestListActivity activity) {
            queryProfileOwner(true);
          }
        };

    /*
     * To keep the image in this test up to date, use the instructions in
     * {@link ByodIconSamplerActivity}.
     */
    mWorkAppVisibleTest =
        new DialogTestListItemWithIcon(
            this,
            R.string.provisioning_byod_workapps_visible,
            "BYOD_WorkAppVisibleTest",
            R.string.provisioning_byod_workapps_visible_instruction,
            new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME),
            R.drawable.badged_icon);

    mWorkNotificationBadgedTest =
        new DialogTestListItemWithIcon(
            this,
            R.string.provisioning_byod_work_notification,
            "BYOD_WorkNotificationBadgedTest",
            R.string.provisioning_byod_work_notification_instruction,
            new Intent(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION),
            R.drawable.ic_corp_icon);

    Intent workStatusIcon = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_ICON);
    workStatusIcon.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mWorkStatusBarIconTest =
        new DialogTestListItemWithIcon(
            this,
            R.string.provisioning_byod_work_status_icon,
            "BYOD_WorkStatusBarIconTest",
            R.string.provisioning_byod_work_status_icon_instruction,
            workStatusIcon,
            R.drawable.stat_sys_managed_profile_status);

    Intent workStatusToast = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_TOAST);
    workStatusToast.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mWorkStatusBarToastTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_work_status_toast,
            "BYOD_WorkStatusBarToastTest",
            R.string.provisioning_byod_work_status_toast_instruction,
            workStatusToast);

    mDisableNonMarketTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_nonmarket_deny,
            "BYOD_DisableNonMarketTest",
            R.string.provisioning_byod_nonmarket_deny_info,
            new Intent(ByodHelperActivity.ACTION_INSTALL_APK)
                .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS, false));

    mEnableNonMarketTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_nonmarket_allow,
            "BYOD_EnableNonMarketTest",
            R.string.provisioning_byod_nonmarket_allow_info,
            new Intent(ByodHelperActivity.ACTION_INSTALL_APK)
                .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS, true));

    mProfileAccountVisibleTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_profile_visible,
            "BYOD_ProfileAccountVisibleTest",
            R.string.provisioning_byod_profile_visible_instruction,
            new Intent(Settings.ACTION_SETTINGS));

    mAppSettingsVisibleTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_app_settings,
            "BYOD_AppSettingsVisibleTest",
            R.string.provisioning_byod_app_settings_instruction,
            new Intent(Settings.ACTION_APPLICATION_SETTINGS));

    mDeviceAdminVisibleTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_admin_visible,
            "BYOD_DeviceAdminVisibleTest",
            R.string.provisioning_byod_admin_visible_instruction,
            new Intent(Settings.ACTION_SECURITY_SETTINGS));

    mCredSettingsVisibleTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_cred_settings,
            "BYOD_CredSettingsVisibleTest",
            R.string.provisioning_byod_cred_settings_instruction,
            new Intent(Settings.ACTION_SECURITY_SETTINGS));

    mLocationSettingsVisibleTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_location_settings,
            "BYOD_LocationSettingsVisibleTest",
            R.string.provisioning_byod_location_settings_instruction,
            new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

    mBatterySettingsVisibleTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_battery_settings,
            "BYOD_BatterySettingsVisibleTest",
            R.string.provisioning_byod_battery_settings_instruction,
            new Intent(Intent.ACTION_POWER_USAGE_SUMMARY));

    mDataUsageSettingsVisibleTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_data_usage_settings,
            "BYOD_DataUsageSettingsVisibleTest",
            R.string.provisioning_byod_data_usage_settings_instruction,
            new Intent(Settings.ACTION_SETTINGS));

    mPrintSettingsVisibleTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_print_settings,
            "BYOD_PrintSettingsVisibleTest",
            R.string.provisioning_byod_print_settings_instruction,
            new Intent(Settings.ACTION_PRINT_SETTINGS));

    Intent intent = new Intent(CrossProfileTestActivity.ACTION_CROSS_PROFILE_TO_WORK);
    intent.putExtra(CrossProfileTestActivity.EXTRA_STARTED_FROM_WORK, false);
    Intent chooser =
        Intent.createChooser(
            intent, getResources().getString(R.string.provisioning_cross_profile_chooser));
    mCrossProfileIntentFiltersTestFromPersonal =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_cross_profile_from_personal,
            "BYOD_CrossProfileIntentFiltersTestFromPersonal",
            R.string.provisioning_byod_cross_profile_from_personal_instruction,
            chooser);

    mCrossProfileIntentFiltersTestFromWork =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_cross_profile_from_work,
            "BYOD_CrossProfileIntentFiltersTestFromWork",
            R.string.provisioning_byod_cross_profile_from_work_instruction,
            new Intent(ByodHelperActivity.ACTION_TEST_CROSS_PROFILE_INTENTS_DIALOG));

    mAppLinkingTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_app_linking,
            "BYOD_AppLinking",
            R.string.provisioning_byod_app_linking_instruction,
            new Intent(ByodHelperActivity.ACTION_TEST_APP_LINKING_DIALOG));

    mKeyguardDisabledFeaturesTest =
        TestListItem.newTest(
            this,
            R.string.provisioning_byod_keyguard_disabled_features,
            KeyguardDisabledFeaturesActivity.class.getName(),
            new Intent(this, KeyguardDisabledFeaturesActivity.class),
            null);

    mAuthenticationBoundKeyTest =
        TestListItem.newTest(
            this,
            R.string.provisioning_byod_auth_bound_key,
            AuthenticationBoundKeyTestActivity.class.getName(),
            new Intent(AuthenticationBoundKeyTestActivity.ACTION_AUTH_BOUND_KEY_TEST),
            null);

    // Test for checking if the required intent filters are set during managed provisioning.
    mIntentFiltersTest =
        new DialogTestListItem(
            this,
            R.string.provisioning_byod_cross_profile_intent_filters,
            "BYOD_IntentFiltersTest") {
          @Override
          public void performTest(DialogTestListActivity activity) {
            checkIntentFilters();
          }
        };

    Intent permissionCheckIntent =
        new Intent(PermissionLockdownTestActivity.ACTION_MANAGED_PROFILE_CHECK_PERMISSION_LOCKDOWN);
    mPermissionLockdownTest =
        new DialogTestListItem(
            this,
            R.string.device_profile_owner_permission_lockdown_test,
            "BYOD_PermissionLockdownTest",
            R.string.profile_owner_permission_lockdown_test_info,
            permissionCheckIntent);

    adapter.add(mProfileOwnerInstalled);

    // Badge related tests
    adapter.add(mWorkAppVisibleTest);
    adapter.add(mWorkNotificationBadgedTest);
    adapter.add(mWorkStatusBarIconTest);
    adapter.add(mWorkStatusBarToastTest);

    // Settings related tests.
    adapter.add(mProfileAccountVisibleTest);
    adapter.add(mDeviceAdminVisibleTest);
    adapter.add(mCredSettingsVisibleTest);
    adapter.add(mAppSettingsVisibleTest);
    adapter.add(mLocationSettingsVisibleTest);
    adapter.add(mBatterySettingsVisibleTest);
    adapter.add(mDataUsageSettingsVisibleTest);
    adapter.add(mPrintSettingsVisibleTest);

    adapter.add(mCrossProfileIntentFiltersTestFromPersonal);
    adapter.add(mCrossProfileIntentFiltersTestFromWork);
    adapter.add(mAppLinkingTest);
    adapter.add(mDisableNonMarketTest);
    adapter.add(mEnableNonMarketTest);
    adapter.add(mIntentFiltersTest);
    adapter.add(mPermissionLockdownTest);
    adapter.add(mKeyguardDisabledFeaturesTest);
    adapter.add(mAuthenticationBoundKeyTest);

    if (canResolveIntent(ByodHelperActivity.getCaptureImageIntent())) {
      // Capture image intent can be resolved in primary profile, so test.
      mCrossProfileImageCaptureSupportTest =
          new DialogTestListItem(
              this,
              R.string.provisioning_byod_capture_image_support,
              "BYOD_CrossProfileImageCaptureSupportTest",
              R.string.provisioning_byod_capture_image_support_info,
              new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_IMAGE));
      adapter.add(mCrossProfileImageCaptureSupportTest);
    } else {
      // Capture image intent cannot be resolved in primary profile, so skip test.
      Toast.makeText(
              ByodFlowTestActivity.this,
              R.string.provisioning_byod_no_image_capture_resolver,
              Toast.LENGTH_SHORT)
          .show();
    }

    if (canResolveIntent(ByodHelperActivity.getCaptureVideoIntent())) {
      // Capture video intent can be resolved in primary profile, so test.
      mCrossProfileVideoCaptureSupportTest =
          new DialogTestListItem(
              this,
              R.string.provisioning_byod_capture_video_support,
              "BYOD_CrossProfileVideoCaptureSupportTest",
              R.string.provisioning_byod_capture_video_support_info,
              new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_VIDEO));
      adapter.add(mCrossProfileVideoCaptureSupportTest);
    } else {
      // Capture video intent cannot be resolved in primary profile, so skip test.
      Toast.makeText(
              ByodFlowTestActivity.this,
              R.string.provisioning_byod_no_video_capture_resolver,
              Toast.LENGTH_SHORT)
          .show();
    }

    if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
      mDisableNfcBeamTest =
          new DialogTestListItem(
              this,
              R.string.provisioning_byod_nfc_beam,
              "BYOD_DisableNfcBeamTest",
              R.string.provisioning_byod_nfc_beam_allowed_instruction,
              new Intent(ByodHelperActivity.ACTION_TEST_NFC_BEAM)) {
            @Override
            public void performTest(final DialogTestListActivity activity) {
              activity.showManualTestDialog(
                  mDisableNfcBeamTest,
                  new DefaultTestCallback(mDisableNfcBeamTest) {
                    @Override
                    public void onPass() {
                      // Start a second test with beam disallowed by policy.
                      Intent testNfcBeamIntent =
                          new Intent(ByodHelperActivity.ACTION_TEST_NFC_BEAM);
                      testNfcBeamIntent.putExtra(NfcTestActivity.EXTRA_DISALLOW_BY_POLICY, true);
                      DialogTestListItem disableNfcBeamTest2 =
                          new DialogTestListItem(
                              activity,
                              R.string.provisioning_byod_nfc_beam,
                              "BYOD_DisableNfcBeamTest",
                              R.string.provisioning_byod_nfc_beam_disallowed_instruction,
                              testNfcBeamIntent);
                      // The result should be reflected on the original test.
                      activity.showManualTestDialog(
                          disableNfcBeamTest2, new DefaultTestCallback(mDisableNfcBeamTest));
                    }
                  });
            }
          };
      adapter.add(mDisableNfcBeamTest);
    }

    /* TODO: reinstate when bug b/20131958 is fixed
    if (canResolveIntent(ByodHelperActivity.getCaptureAudioIntent())) {
        // Capture audio intent can be resolved in primary profile, so test.
        mCrossProfileAudioCaptureSupportTest = new DialogTestListItem(this,
                R.string.provisioning_byod_capture_audio_support,
                "BYOD_CrossProfileAudioCaptureSupportTest",
                R.string.provisioning_byod_capture_audio_support_info,
                new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_AUDIO));
        adapter.add(mCrossProfileAudioCaptureSupportTest);
    } else {
        // Capture audio intent cannot be resolved in primary profile, so skip test.
        Toast.makeText(ByodFlowTestActivity.this,
                R.string.provisioning_byod_no_audio_capture_resolver, Toast.LENGTH_SHORT)
                .show();
    }
    */
  }