Home | History | Annotate | Download | only in managedprovisioning
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.cts.verifier.managedprovisioning;
     18 
     19 import android.app.AlertDialog;
     20 import android.app.admin.DevicePolicyManager;
     21 import android.content.ComponentName;
     22 import android.content.Context;
     23 import android.content.DialogInterface;
     24 import android.content.Intent;
     25 import android.os.Bundle;
     26 import android.view.View;
     27 
     28 import com.android.cts.verifier.ArrayTestListAdapter;
     29 import com.android.cts.verifier.DialogTestListActivity;
     30 import com.android.cts.verifier.R;
     31 
     32 /**
     33  * This test verifies that if a work profile is locked with a separate password, Recents views for
     34  * for applications in the work profile are redacted appropriately.
     35  */
     36 public class RecentsRedactionActivity extends DialogTestListActivity {
     37     private static final String TAG = RecentsRedactionActivity.class.getSimpleName();
     38 
     39     public static final String ACTION_RECENTS =
     40             "com.android.cts.verifier.managedprovisioning.RECENTS";
     41 
     42     private ComponentName mAdmin;
     43     private DevicePolicyManager mDevicePolicyManager;
     44 
     45     private DialogTestListItem mVerifyRedacted;
     46     private DialogTestListItem mVerifyNotRedacted;
     47 
     48     public RecentsRedactionActivity() {
     49         super(R.layout.provisioning_byod,
     50                 /* title */ R.string.provisioning_byod_recents,
     51                 /* description */ R.string.provisioning_byod_recents_info,
     52                 /* instructions */ R.string.provisioning_byod_recents_instructions);
     53     }
     54 
     55     @Override
     56     protected void onCreate(Bundle savedInstanceState) {
     57         super.onCreate(savedInstanceState);
     58 
     59         mPrepareTestButton.setText(R.string.provisioning_byod_recents_lock_now);
     60         mPrepareTestButton.setOnClickListener((View view) -> {
     61             mDevicePolicyManager.lockNow();
     62         });
     63 
     64         mAdmin = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
     65         mDevicePolicyManager = (DevicePolicyManager)
     66                 getSystemService(Context.DEVICE_POLICY_SERVICE);
     67     }
     68 
     69     @Override
     70     protected void setupTests(ArrayTestListAdapter adapter) {
     71         mVerifyRedacted = new DialogTestListItem(this,
     72                 /* name */ R.string.provisioning_byod_recents_verify_redacted,
     73                 /* testId */ "BYOD_recents_verify_redacted",
     74                 /* instruction */ R.string.provisioning_byod_recents_verify_redacted_instruction,
     75                 /* action */ new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD));
     76 
     77         mVerifyNotRedacted = new DialogTestListItem(this,
     78                 /* name */ R.string.provisioning_byod_recents_verify_not_redacted,
     79                 /* testId */ "BYOD_recents_verify_not_redacted",
     80                 /* intruction */ R.string.provisioning_byod_recents_verify_not_redacted_instruction,
     81                 /* action */ new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD));
     82 
     83         adapter.add(mVerifyRedacted);
     84         adapter.add(mVerifyNotRedacted);
     85     }
     86 
     87     @Override
     88     public void onBackPressed() {
     89         if (hasPassword()) {
     90             requestRemovePassword();
     91             return;
     92         }
     93         super.onBackPressed();
     94     }
     95 
     96     private boolean hasPassword() {
     97         try {
     98             mDevicePolicyManager.setPasswordQuality(mAdmin,
     99                     DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
    100             return mDevicePolicyManager.isActivePasswordSufficient();
    101         } finally {
    102             mDevicePolicyManager.setPasswordQuality(mAdmin,
    103                     DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
    104         }
    105     }
    106 
    107     private void requestRemovePassword() {
    108         new AlertDialog.Builder(this)
    109                 .setIcon(android.R.drawable.ic_dialog_info)
    110                 .setTitle(R.string.provisioning_byod_recents)
    111                 .setMessage(R.string.provisioning_byod_recents_remove_password)
    112                 .setPositiveButton(android.R.string.ok, (DialogInterface dialog, int which) -> {
    113                     startActivity(new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD));
    114                 })
    115                 .show();
    116     }
    117 }
    118