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.provider.Settings; 27 import android.view.View; 28 29 import com.android.cts.verifier.ArrayTestListAdapter; 30 import com.android.cts.verifier.DialogTestListActivity; 31 import com.android.cts.verifier.R; 32 import com.android.cts.verifier.TestResult; 33 34 /** 35 * This test verifies that if a work profile is locked with a separate password, Recents views for 36 * for applications in the work profile are redacted appropriately. 37 */ 38 public class RecentsRedactionActivity extends DialogTestListActivity { 39 private static final String TAG = RecentsRedactionActivity.class.getSimpleName(); 40 41 public static final String ACTION_RECENTS = 42 "com.android.cts.verifier.managedprovisioning.RECENTS"; 43 44 private ComponentName mAdmin; 45 private DevicePolicyManager mDevicePolicyManager; 46 47 private DialogTestListItem mVerifyRedacted; 48 private DialogTestListItem mVerifyNotRedacted; 49 RecentsRedactionActivity()50 public RecentsRedactionActivity() { 51 super(R.layout.provisioning_byod, 52 /* title */ R.string.provisioning_byod_recents, 53 /* description */ R.string.provisioning_byod_recents_info, 54 /* instructions */ R.string.provisioning_byod_recents_instructions); 55 } 56 57 // Default listener will use setResult(), which won't work due to activity being in a new task. 58 private View.OnClickListener clickListener = target -> { 59 final int resultCode; 60 switch (target.getId()) { 61 case R.id.pass_button: 62 resultCode = TestResult.TEST_RESULT_PASSED; 63 break; 64 case R.id.fail_button: 65 resultCode = TestResult.TEST_RESULT_FAILED; 66 break; 67 default: 68 throw new IllegalArgumentException("Unknown id: " + target.getId()); 69 } 70 Intent resultIntent = TestResult.createResult(RecentsRedactionActivity.this, resultCode, 71 getTestId(), getTestDetails(), getReportLog()); 72 73 new ByodFlowTestHelper(this).sendResultToPrimary(resultIntent); 74 finish(); 75 }; 76 77 @Override onCreate(Bundle savedInstanceState)78 protected void onCreate(Bundle savedInstanceState) { 79 super.onCreate(savedInstanceState); 80 81 findViewById(R.id.pass_button).setOnClickListener(clickListener); 82 findViewById(R.id.fail_button).setOnClickListener(clickListener); 83 84 mPrepareTestButton.setText(R.string.provisioning_byod_recents_lock_now); 85 mPrepareTestButton.setOnClickListener((View view) -> { 86 mDevicePolicyManager.lockNow(); 87 }); 88 89 mAdmin = new ComponentName(this, DeviceAdminTestReceiver.class.getName()); 90 mDevicePolicyManager = (DevicePolicyManager) 91 getSystemService(Context.DEVICE_POLICY_SERVICE); 92 } 93 94 @Override setupTests(ArrayTestListAdapter adapter)95 protected void setupTests(ArrayTestListAdapter adapter) { 96 mVerifyRedacted = new DialogTestListItem(this, 97 /* name */ R.string.provisioning_byod_recents_verify_redacted, 98 /* testId */ "BYOD_recents_verify_redacted", 99 /* instruction */ R.string.provisioning_byod_recents_verify_redacted_instruction, 100 /* action */ new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD)); 101 102 mVerifyNotRedacted = new DialogTestListItem(this, 103 /* name */ R.string.provisioning_byod_recents_verify_not_redacted, 104 /* testId */ "BYOD_recents_verify_not_redacted", 105 /* intruction */ R.string.provisioning_byod_recents_verify_not_redacted_instruction, 106 /* action */ new Intent(Settings.ACTION_SECURITY_SETTINGS)); 107 108 adapter.add(mVerifyRedacted); 109 adapter.add(mVerifyNotRedacted); 110 } 111 112 @Override onBackPressed()113 public void onBackPressed() { 114 if (hasPassword()) { 115 requestRemovePassword(); 116 return; 117 } 118 super.onBackPressed(); 119 } 120 hasPassword()121 private boolean hasPassword() { 122 try { 123 mDevicePolicyManager.setPasswordQuality(mAdmin, 124 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); 125 return mDevicePolicyManager.isActivePasswordSufficient(); 126 } finally { 127 mDevicePolicyManager.setPasswordQuality(mAdmin, 128 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); 129 } 130 } 131 requestRemovePassword()132 private void requestRemovePassword() { 133 new AlertDialog.Builder(this) 134 .setIcon(android.R.drawable.ic_dialog_info) 135 .setTitle(R.string.provisioning_byod_recents) 136 .setMessage(R.string.provisioning_byod_recents_remove_password) 137 .setPositiveButton(android.R.string.ok, (DialogInterface dialog, int which) -> { 138 startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS)); 139 }) 140 .show(); 141 } 142 } 143