1 /* 2 * Copyright (C) 2015 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.admin.DevicePolicyManager; 20 import android.content.ActivityNotFoundException; 21 import android.content.ComponentName; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.hardware.fingerprint.FingerprintManager; 25 import android.os.Bundle; 26 import android.provider.Settings; 27 import android.view.View; 28 import android.view.View.OnClickListener; 29 import android.widget.Toast; 30 31 import com.android.cts.verifier.ArrayTestListAdapter; 32 import com.android.cts.verifier.DialogTestListActivity; 33 import com.android.cts.verifier.R; 34 35 public class KeyguardDisabledFeaturesActivity extends DialogTestListActivity { 36 37 private DevicePolicyManager mDpm; 38 KeyguardDisabledFeaturesActivity()39 public KeyguardDisabledFeaturesActivity() { 40 super(R.layout.provisioning_byod, 41 R.string.provisioning_byod_keyguard_disabled_features, 42 R.string.provisioning_byod_keyguard_disabled_features_info, 43 R.string.provisioning_byod_keyguard_disabled_features_instruction); 44 } 45 46 @Override onCreate(Bundle savedInstanceState)47 protected void onCreate(Bundle savedInstanceState) { 48 super.onCreate(savedInstanceState); 49 50 mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); 51 52 mPrepareTestButton.setText( 53 R.string.provisioning_byod_keyguard_disabled_features_prepare_button); 54 mPrepareTestButton.setOnClickListener(new OnClickListener() { 55 @Override 56 public void onClick(View v) { 57 if (!mDpm.isAdminActive(DeviceAdminTestReceiver.getReceiverComponentName())) { 58 Toast.makeText(KeyguardDisabledFeaturesActivity.this, 59 R.string.provisioning_byod_keyguard_disabled_features_not_admin, 60 Toast.LENGTH_SHORT).show(); 61 return; 62 } 63 mDpm.resetPassword("testpassword", 0); 64 setKeyguardDisabledFeatures(DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS | 65 DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT | 66 DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS); 67 } 68 }); 69 } 70 71 @Override finish()72 public void finish() { 73 // Pass and fail buttons are known to call finish() when clicked, and this is when we want to 74 // clear the password. 75 final ComponentName adminComponent = DeviceAdminTestReceiver.getReceiverComponentName(); 76 if (mDpm.isAdminActive(adminComponent)) { 77 mDpm.resetPassword(null, 0); 78 mDpm.removeActiveAdmin(adminComponent); 79 } 80 super.finish(); 81 } 82 setKeyguardDisabledFeatures(final int flags)83 private void setKeyguardDisabledFeatures(final int flags) { 84 Intent setKeyguardDisabledFeaturesIntent = 85 new Intent(ByodHelperActivity.ACTION_KEYGUARD_DISABLED_FEATURES) 86 .putExtra(ByodHelperActivity.EXTRA_PARAMETER_1, flags); 87 startActivity(setKeyguardDisabledFeaturesIntent); 88 } 89 90 @Override setupTests(ArrayTestListAdapter adapter)91 protected void setupTests(ArrayTestListAdapter adapter) { 92 adapter.add(new DialogTestListItem(this, R.string.provisioning_byod_disable_trust_agents, 93 "BYOD_DisableTrustAgentsTest", 94 R.string.provisioning_byod_disable_trust_agents_instruction, 95 new Intent(Settings.ACTION_SECURITY_SETTINGS))); 96 adapter.add(new DialogTestListItemWithIcon(this, 97 R.string.provisioning_byod_disable_notifications, 98 "BYOD_DisableUnredactedNotifications", 99 R.string.provisioning_byod_disable_notifications_instruction, 100 new Intent(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION_ON_LOCKSCREEN), 101 R.drawable.ic_corp_icon)); 102 FingerprintManager fpm = (FingerprintManager) getSystemService(Context.FINGERPRINT_SERVICE); 103 if (fpm.isHardwareDetected()) { 104 adapter.add(new DialogTestListItem(this, 105 R.string.provisioning_byod_fingerprint_disabled_in_settings, 106 "BYOD_FingerprintDisabledInSettings", 107 R.string.provisioning_byod_fingerprint_disabled_in_settings_instruction, 108 new Intent(Settings.ACTION_SECURITY_SETTINGS))); 109 adapter.add(new DialogTestListItem(this, R.string.provisioning_byod_disable_fingerprint, 110 "BYOD_DisableFingerprint", 111 R.string.provisioning_byod_disable_fingerprint_instruction, 112 ByodHelperActivity.createLockIntent())); 113 } 114 } 115 116 @Override clearRemainingState(final DialogTestListItem test)117 protected void clearRemainingState(final DialogTestListItem test) { 118 super.clearRemainingState(test); 119 if (WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION_ON_LOCKSCREEN.equals( 120 test.getManualTestIntent().getAction())) { 121 try { 122 startActivity(new Intent( 123 WorkNotificationTestActivity.ACTION_CLEAR_WORK_NOTIFICATION)); 124 } catch (ActivityNotFoundException e) { 125 // User shouldn't run this test before work profile is set up. 126 } 127 } 128 } 129 } 130