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.Manifest; 20 import android.app.admin.DevicePolicyManager; 21 import android.content.ComponentName; 22 import android.content.Intent; 23 import android.content.pm.PackageManager; 24 import android.database.DataSetObserver; 25 import android.os.Bundle; 26 import android.provider.Settings; 27 28 import com.android.cts.verifier.ArrayTestListAdapter; 29 import com.android.cts.verifier.IntentDrivenTestActivity.ButtonInfo; 30 import com.android.cts.verifier.PassFailButtons; 31 import com.android.cts.verifier.R; 32 import com.android.cts.verifier.TestListAdapter.TestListItem; 33 34 import static com.android.cts.verifier.managedprovisioning.Utils.createInteractiveTestItem; 35 36 /** 37 * Test class to verify privacy information is shown for devices managed by a Device Owner. 38 */ 39 public class EnterprisePrivacyTestListActivity extends PassFailButtons.TestListActivity { 40 41 private static final String ENTERPRISE_PRIVACY_PAGE = "ENTERPRISE_PRIVACY_PAGE"; 42 private static final String ENTERPRISE_PRIVACY_NETWORK_LOGGING 43 = "ENTERPRISE_PRIVACY_NETWORK_LOGGING"; 44 private static final String ENTERPRISE_PRIVACY_BUG_REPORT = "ENTERPRISE_PRIVACY_BUG_REPORT"; 45 private static final String ENTERPRISE_PRIVACY_SECURITY_LOGGING 46 = "ENTERPRISE_PRIVACY_SECURITY_LOGGING"; 47 private static final String ENTERPRISE_PRIVACY_ENTERPRISE_INSTALLED_APPS 48 = "ENTERPRISE_PRIVACY_ENTERPRISE_INSTALLED_APPS"; 49 private static final String ENTERPRISE_PRIVACY_LOCATION_ACCESS 50 = "ENTERPRISE_PRIVACY_LOCATION_ACCESS"; 51 private static final String ENTERPRISE_PRIVACY_MICROPHONE_ACCESS 52 = "ENTERPRISE_PRIVACY_MICROPHONE_ACCESS"; 53 private static final String ENTERPRISE_PRIVACY_CAMERA_ACCESS 54 = "ENTERPRISE_PRIVACY_CAMERA_ACCESS"; 55 private static final String ENTERPRISE_PRIVACY_DEFAULT_APPS 56 = "ENTERPRISE_PRIVACY_DEFAULT_APPS"; 57 private static final String ENTERPRISE_PRIVACY_DEFAULT_IME 58 = "ENTERPRISE_PRIVACY_DEFAULT_IME"; 59 private static final String ENTERPRISE_PRIVACY_ALWAYS_ON_VPN 60 = "ENTERPRISE_PRIVACY_ALWAYS_ON_VPN"; 61 private static final String ENTERPRISE_PRIVACY_COMP_ALWAYS_ON_VPN 62 = "ENTERPRISE_PRIVACY_COMP_ALWAYS_ON_VPN"; 63 private static final String ENTERPRISE_PRIVACY_GLOBAL_HTTP_PROXY 64 = "ENTERPRISE_PRIVACY_GLOBAL_HTTP_PROXY"; 65 private static final String ENTERPRISE_PRIVACY_CA_CERTS = "ENTERPRISE_PRIVACY_CA_CERTS"; 66 private static final String ENTERPRISE_PRIVACY_COMP_CA_CERTS 67 = "ENTERPRISE_PRIVACY_COMP_CA_CERTS"; 68 private static final String ENTERPRISE_PRIVACY_FAILED_PASSWORD_WIPE 69 = "ENTERPRISE_PRIVACY_FAILED_PASSWORD_WIPE"; 70 private static final String ENTERPRISE_PRIVACY_COMP_FAILED_PASSWORD_WIPE 71 = "ENTERPRISE_PRIVACY_COMP_FAILED_PASSWORD_WIPE"; 72 private static final String ENTERPRISE_PRIVACY_QUICK_SETTINGS 73 = "ENTERPRISE_PRIVACY_QUICK_SETTINGS"; 74 private static final String ENTERPRISE_PRIVACY_KEYGUARD = "ENTERPRISE_PRIVACY_KEYGUARD"; 75 private static final String ENTERPRISE_PRIVACY_ADD_ACCOUNT = "ENTERPRISE_PRIVACY_ADD_ACCOUNT"; 76 77 public static final String EXTRA_TEST_ID = 78 "com.android.cts.verifier.managedprovisioning.extra.TEST_ID"; 79 80 @Override 81 protected void onCreate(Bundle savedInstanceState) { 82 super.onCreate(savedInstanceState); 83 setContentView(R.layout.pass_fail_list); 84 setPassFailButtonClickListeners(); 85 final ArrayTestListAdapter adapter = new ArrayTestListAdapter(this); 86 addTestsToAdapter(adapter); 87 adapter.registerDataSetObserver(new DataSetObserver() { 88 @Override 89 public void onChanged() { 90 updatePassButton(); 91 } 92 }); 93 setTestListAdapter(adapter); 94 getPackageManager().setComponentEnabledSetting( 95 new ComponentName(this, CompHelperActivity.class), 96 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 97 PackageManager.DONT_KILL_APP); 98 } 99 100 private Intent buildCommandIntent(String command) { 101 return new Intent(CommandReceiverActivity.ACTION_EXECUTE_COMMAND) 102 .putExtra(CommandReceiverActivity.EXTRA_COMMAND, command); 103 } 104 105 private TestListItem buildCommandTest(String id, int titleRes, int infoRes, 106 int commandButtonRes, String command) { 107 return createInteractiveTestItem(this, id, titleRes, infoRes, 108 new ButtonInfo[] { 109 new ButtonInfo(commandButtonRes, buildCommandIntent(command)), 110 new ButtonInfo(R.string.enterprise_privacy_open_settings, 111 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS))}); 112 } 113 114 private TestListItem buildAdminGrantedPermissionTest(String id, int titleRes, int infoRes, 115 String permission) { 116 return createInteractiveTestItem(this, id, titleRes, infoRes, 117 new ButtonInfo[] { 118 new ButtonInfo(R.string.enterprise_privacy_reset, buildCommandIntent( 119 CommandReceiverActivity.COMMAND_SET_PERMISSION_GRANT_STATE) 120 .putExtra(CommandReceiverActivity.EXTRA_PERMISSION, permission) 121 .putExtra(CommandReceiverActivity.EXTRA_GRANT_STATE, 122 DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT)), 123 new ButtonInfo(R.string.enterprise_privacy_grant, buildCommandIntent( 124 CommandReceiverActivity.COMMAND_SET_PERMISSION_GRANT_STATE) 125 .putExtra(CommandReceiverActivity.EXTRA_PERMISSION, permission) 126 .putExtra(CommandReceiverActivity.EXTRA_GRANT_STATE, 127 DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED)), 128 new ButtonInfo(R.string.enterprise_privacy_open_settings, 129 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS))}); 130 } 131 132 private void addTestsToAdapter(final ArrayTestListAdapter adapter) { 133 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_PAGE, 134 R.string.enterprise_privacy_page, 135 R.string.enterprise_privacy_page_info, 136 new ButtonInfo(R.string.go_button_text, new Intent(Settings.ACTION_SETTINGS)))); 137 adapter.add(buildCommandTest(ENTERPRISE_PRIVACY_NETWORK_LOGGING, 138 R.string.enterprise_privacy_network_logging, 139 R.string.enterprise_privacy_network_logging_info, 140 R.string.enterprise_privacy_retrieve_network_logs, 141 CommandReceiverActivity.COMMAND_RETRIEVE_NETWORK_LOGS)); 142 adapter.add(buildCommandTest(ENTERPRISE_PRIVACY_BUG_REPORT, 143 R.string.enterprise_privacy_bug_report, 144 R.string.enterprise_privacy_bug_report_info, 145 R.string.enterprise_privacy_request_bug_report, 146 CommandReceiverActivity.COMMAND_REQUEST_BUGREPORT)); 147 adapter.add(buildCommandTest(ENTERPRISE_PRIVACY_SECURITY_LOGGING, 148 R.string.enterprise_privacy_security_logging, 149 R.string.enterprise_privacy_security_logging_info, 150 R.string.enterprise_privacy_retrieve_security_logs, 151 CommandReceiverActivity.COMMAND_RETRIEVE_SECURITY_LOGS)); 152 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_ENTERPRISE_INSTALLED_APPS, 153 R.string.enterprise_privacy_enterprise_installed_apps, 154 R.string.enterprise_privacy_enterprise_installed_apps_info, 155 new ButtonInfo[] { 156 new ButtonInfo(R.string.enterprise_privacy_install, 157 buildCommandIntent( 158 CommandReceiverActivity.COMMAND_INSTALL_HELPER_PACKAGE)), 159 new ButtonInfo(R.string.enterprise_privacy_uninstall, 160 buildCommandIntent(CommandReceiverActivity 161 .COMMAND_UNINSTALL_HELPER_PACKAGE)), 162 new ButtonInfo(R.string.enterprise_privacy_open_settings, 163 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS))})); 164 adapter.add(buildAdminGrantedPermissionTest(ENTERPRISE_PRIVACY_LOCATION_ACCESS, 165 R.string.enterprise_privacy_admin_granted_location_access, 166 R.string.enterprise_privacy_admin_granted_location_access_info, 167 Manifest.permission.ACCESS_FINE_LOCATION)); 168 adapter.add(buildAdminGrantedPermissionTest(ENTERPRISE_PRIVACY_MICROPHONE_ACCESS, 169 R.string.enterprise_privacy_admin_granted_microphone_access, 170 R.string.enterprise_privacy_admin_granted_microphone_access_info, 171 Manifest.permission.RECORD_AUDIO)); 172 adapter.add(buildAdminGrantedPermissionTest(ENTERPRISE_PRIVACY_CAMERA_ACCESS, 173 R.string.enterprise_privacy_admin_granted_camera_access, 174 R.string.enterprise_privacy_admin_granted_camera_access_info, 175 Manifest.permission.CAMERA)); 176 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_DEFAULT_APPS, 177 R.string.enterprise_privacy_default_apps, 178 R.string.enterprise_privacy_default_apps_info, 179 new ButtonInfo[] { 180 new ButtonInfo(R.string.enterprise_privacy_open_settings, 181 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)), 182 new ButtonInfo(R.string.enterprise_privacy_reset, buildCommandIntent( 183 CommandReceiverActivity 184 .COMMAND_CLEAR_PERSISTENT_PREFERRED_ACTIVITIES)), 185 new ButtonInfo(R.string.enterprise_privacy_set_default_apps, 186 buildCommandIntent(CommandReceiverActivity 187 .COMMAND_ADD_PERSISTENT_PREFERRED_ACTIVITIES))})); 188 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_DEFAULT_IME, 189 R.string.enterprise_privacy_default_ime, 190 R.string.enterprise_privacy_default_ime_info, 191 new ButtonInfo[] { 192 new ButtonInfo(R.string.enterprise_privacy_open_settings, 193 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)), 194 new ButtonInfo(R.string.enterprise_privacy_set_keyboard, 195 buildCommandIntent(CommandReceiverActivity 196 .COMMAND_SET_DEFAULT_IME)), 197 new ButtonInfo(R.string.enterprise_privacy_finish, 198 buildCommandIntent(CommandReceiverActivity 199 .COMMAND_CLEAR_DEFAULT_IME))})); 200 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_ALWAYS_ON_VPN, 201 R.string.enterprise_privacy_always_on_vpn, 202 R.string.enterprise_privacy_always_on_vpn_info, 203 new ButtonInfo[] { 204 new ButtonInfo(R.string.enterprise_privacy_open_settings, 205 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)), 206 new ButtonInfo(R.string.enterprise_privacy_set_always_on_vpn, 207 buildCommandIntent( 208 CommandReceiverActivity.COMMAND_SET_ALWAYS_ON_VPN)), 209 new ButtonInfo(R.string.enterprise_privacy_finish, 210 buildCommandIntent( 211 CommandReceiverActivity.COMMAND_CLEAR_ALWAYS_ON_VPN))})); 212 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS)) { 213 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_COMP_ALWAYS_ON_VPN, 214 R.string.enterprise_privacy_comp_always_on_vpn, 215 R.string.enterprise_privacy_comp_always_on_vpn_info, 216 new ButtonInfo[] { 217 new ButtonInfo(R.string.enterprise_privacy_start, 218 buildCommandIntent( 219 CommandReceiverActivity. 220 COMMAND_CREATE_MANAGED_PROFILE)), 221 new ButtonInfo(R.string.enterprise_privacy_open_settings, 222 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)), 223 new ButtonInfo(R.string.enterprise_privacy_set_always_on_vpn, 224 new Intent(CompHelperActivity.ACTION_SET_ALWAYS_ON_VPN)), 225 new ButtonInfo(R.string.enterprise_privacy_finish, 226 buildCommandIntent( 227 CommandReceiverActivity. 228 COMMAND_REMOVE_MANAGED_PROFILE))})); 229 } 230 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_GLOBAL_HTTP_PROXY, 231 R.string.enterprise_privacy_global_http_proxy, 232 R.string.enterprise_privacy_global_http_proxy_info, 233 new ButtonInfo[] { 234 new ButtonInfo(R.string.enterprise_privacy_open_settings, 235 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)), 236 new ButtonInfo(R.string.enterprise_privacy_set_proxy, 237 buildCommandIntent( 238 CommandReceiverActivity.COMMAND_SET_GLOBAL_HTTP_PROXY)), 239 new ButtonInfo(R.string.enterprise_privacy_clear_proxy, 240 buildCommandIntent(CommandReceiverActivity 241 .COMMAND_CLEAR_GLOBAL_HTTP_PROXY))})); 242 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_CA_CERTS, 243 R.string.enterprise_privacy_ca_certs, 244 R.string.enterprise_privacy_ca_certs_info, 245 new ButtonInfo[] { 246 new ButtonInfo(R.string.enterprise_privacy_open_settings, 247 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)), 248 new ButtonInfo(R.string.enterprise_privacy_install_cert, 249 buildCommandIntent( 250 CommandReceiverActivity.COMMAND_INSTALL_CA_CERT)), 251 new ButtonInfo(R.string.enterprise_privacy_finish, 252 buildCommandIntent( 253 CommandReceiverActivity.COMMAND_CLEAR_CA_CERT))})); 254 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS)) { 255 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_COMP_CA_CERTS, 256 R.string.enterprise_privacy_comp_ca_certs, 257 R.string.enterprise_privacy_comp_ca_certs_info, 258 new ButtonInfo[] { 259 new ButtonInfo(R.string.enterprise_privacy_start, 260 buildCommandIntent( 261 CommandReceiverActivity. 262 COMMAND_CREATE_MANAGED_PROFILE)), 263 new ButtonInfo(R.string.enterprise_privacy_settings, 264 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)), 265 new ButtonInfo(R.string.enterprise_privacy_install_cert, 266 new Intent(CompHelperActivity.ACTION_INSTALL_CA_CERT)), 267 new ButtonInfo(R.string.enterprise_privacy_finish, 268 buildCommandIntent( 269 CommandReceiverActivity. 270 COMMAND_REMOVE_MANAGED_PROFILE))})); 271 } 272 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_FAILED_PASSWORD_WIPE, 273 R.string.enterprise_privacy_failed_password_wipe, 274 R.string.enterprise_privacy_failed_password_wipe_info, 275 new ButtonInfo[] { 276 new ButtonInfo(R.string.enterprise_privacy_open_settings, 277 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)), 278 new ButtonInfo(R.string.enterprise_privacy_set_limit, 279 buildCommandIntent(CommandReceiverActivity 280 .COMMAND_SET_MAXIMUM_PASSWORD_ATTEMPTS)), 281 new ButtonInfo(R.string.enterprise_privacy_finish, 282 buildCommandIntent(CommandReceiverActivity 283 .COMMAND_CLEAR_MAXIMUM_PASSWORD_ATTEMPTS))})); 284 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS)) { 285 adapter.add(createInteractiveTestItem(this, 286 ENTERPRISE_PRIVACY_COMP_FAILED_PASSWORD_WIPE, 287 R.string.enterprise_privacy_comp_failed_password_wipe, 288 R.string.enterprise_privacy_comp_failed_password_wipe_info, 289 new ButtonInfo[]{ 290 new ButtonInfo(R.string.enterprise_privacy_start, 291 buildCommandIntent( 292 CommandReceiverActivity. 293 COMMAND_CREATE_MANAGED_PROFILE)), 294 new ButtonInfo(R.string.enterprise_privacy_open_settings, 295 new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)), 296 new ButtonInfo(R.string.enterprise_privacy_set_limit, new Intent( 297 CompHelperActivity.ACTION_SET_MAXIMUM_PASSWORD_ATTEMPTS)), 298 new ButtonInfo(R.string.enterprise_privacy_finish, 299 buildCommandIntent( 300 CommandReceiverActivity. 301 COMMAND_REMOVE_MANAGED_PROFILE))})); 302 } 303 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_QUICK_SETTINGS, 304 R.string.enterprise_privacy_quick_settings, 305 R.string.enterprise_privacy_quick_settings_info, 306 new ButtonInfo[] { 307 new ButtonInfo(R.string.enterprise_privacy_clear_organization, 308 buildCommandIntent( 309 CommandReceiverActivity.COMMAND_SET_ORGANIZATION_NAME)), 310 new ButtonInfo(R.string.enterprise_privacy_set_organization, 311 buildCommandIntent( 312 CommandReceiverActivity.COMMAND_SET_ORGANIZATION_NAME) 313 .putExtra(CommandReceiverActivity.EXTRA_ORGANIZATION_NAME, 314 "Foo, Inc."))})); 315 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_KEYGUARD, 316 R.string.enterprise_privacy_keyguard, 317 R.string.enterprise_privacy_keyguard_info, 318 new ButtonInfo[] { 319 new ButtonInfo(R.string.enterprise_privacy_open_settings, 320 new Intent(Settings.ACTION_SETTINGS)), 321 new ButtonInfo(R.string.enterprise_privacy_clear_organization, 322 buildCommandIntent( 323 CommandReceiverActivity.COMMAND_SET_ORGANIZATION_NAME)), 324 new ButtonInfo(R.string.enterprise_privacy_set_organization, 325 buildCommandIntent( 326 CommandReceiverActivity.COMMAND_SET_ORGANIZATION_NAME) 327 .putExtra(CommandReceiverActivity.EXTRA_ORGANIZATION_NAME, 328 "Foo, Inc."))})); 329 adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_ADD_ACCOUNT, 330 R.string.enterprise_privacy_add_account, 331 R.string.enterprise_privacy_add_account_info, 332 new ButtonInfo[] { 333 new ButtonInfo(R.string.enterprise_privacy_open_settings, 334 new Intent(Settings.ACTION_ADD_ACCOUNT)), 335 new ButtonInfo(R.string.enterprise_privacy_clear_organization, 336 buildCommandIntent( 337 CommandReceiverActivity.COMMAND_SET_ORGANIZATION_NAME)), 338 new ButtonInfo(R.string.enterprise_privacy_set_organization, 339 buildCommandIntent( 340 CommandReceiverActivity.COMMAND_SET_ORGANIZATION_NAME) 341 .putExtra(CommandReceiverActivity.EXTRA_ORGANIZATION_NAME, 342 "Foo, Inc."))})); 343 } 344 345 @Override 346 public String getTestId() { 347 return getIntent().getStringExtra(EXTRA_TEST_ID); 348 } 349 350 @Override 351 public void finish() { 352 super.finish(); 353 Intent intent = buildCommandIntent(CommandReceiverActivity.COMMAND_CLEAR_POLICIES) 354 .putExtra(PolicyTransparencyTestListActivity.EXTRA_MODE, 355 PolicyTransparencyTestListActivity.MODE_DEVICE_OWNER); 356 startActivity(intent); 357 startActivity(buildCommandIntent(CommandReceiverActivity.COMMAND_REMOVE_MANAGED_PROFILE)); 358 } 359 } 360