@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());

    disableComponent();
    mPrepareTestButton.setText(R.string.provisioning_byod_start);
    mPrepareTestButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            startByodProvisioning();
          }
        });

    // If we are started by managed provisioning (fresh managed provisioning after encryption
    // reboot), redirect the user back to the main test list. This is because the test result
    // is only saved by the parent TestListActivity, and if we did allow the user to proceed
    // here, the test result would be lost when this activity finishes.
    if (ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS.equals(getIntent().getAction())) {
      startActivity(new Intent(this, TestListActivity.class));
      // Calling super.finish() because we delete managed profile in our overridden of finish(),
      // which is not what we want to do here.
      super.finish();
    } else {
      queryProfileOwner(false);
    }
  }
 @Override
 public void finish() {
   // Pass and fail buttons are known to call finish() when clicked, and this is when we want to
   // clean up the provisioned profile.
   requestDeleteProfileOwner();
   super.finish();
 }
 @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())) {
     handleStatusUpdate(RESULT_OK, intent);
   }
 }
 @Override
 protected void clearRemainingState(final DialogTestListItem test) {
   super.clearRemainingState(test);
   if (WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION.equals(
       test.getManualTestIntent().getAction())) {
     try {
       startActivity(new Intent(WorkNotificationTestActivity.ACTION_CLEAR_WORK_NOTIFICATION));
     } catch (ActivityNotFoundException e) {
       // User shouldn't run this test before work profile is set up.
     }
   }
 }
 @Override
 protected void handleActivityResult(int requestCode, int resultCode, Intent data) {
   switch (requestCode) {
     case REQUEST_MANAGED_PROVISIONING:
       return;
     case REQUEST_PROFILE_OWNER_STATUS:
       {
         // Called after queryProfileOwner()
         handleStatusUpdate(resultCode, data);
       }
       break;
     case REQUEST_INTENT_FILTERS_STATUS:
       {
         // Called after checkIntentFilters()
         handleIntentFiltersStatus(resultCode);
       }
       break;
     default:
       {
         super.handleActivityResult(requestCode, resultCode, data);
       }
   }
 }