1 /* 2 * Copyright (C) 2020 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.ComponentName; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.provider.Settings; 24 import android.view.View; 25 import android.view.View.OnClickListener; 26 27 import com.android.cts.verifier.ArrayTestListAdapter; 28 import com.android.cts.verifier.DialogTestListActivity; 29 import com.android.cts.verifier.R; 30 31 import java.util.Set; 32 33 public class CrossProfilePermissionControlActivity extends DialogTestListActivity { 34 static final String ACTION_CROSS_PROFILE_PERMISSION_CONTROL = 35 "com.android.cts.verifier.managedprovisioning.action.CROSS_PROFILE_PERMISSION_CONTROL"; 36 private static final String TEST_APP_PACKAGE_NAME = 37 "com.android.cts.crossprofilepermissioncontrol"; 38 private static final String OPEN_TEST_APP_ACTION = 39 "com.android.cts.verifier.managedprovisioning.action.OPEN_CROSS_PROFILE_TEST_APP"; 40 41 protected DevicePolicyManager mDpm; 42 CrossProfilePermissionControlActivity()43 public CrossProfilePermissionControlActivity() { 44 super(R.layout.provisioning_byod, 45 R.string.provisioning_byod_cross_profile_permission_control, 46 R.string.provisioning_byod_cross_profile_permission_control_info, 47 R.string.provisioning_byod_cross_profile_permission_control_instruction); 48 } 49 50 @Override onCreate(Bundle savedInstanceState)51 protected void onCreate(Bundle savedInstanceState) { 52 super.onCreate(savedInstanceState); 53 54 mDpm = getSystemService(DevicePolicyManager.class); 55 mPrepareTestButton.setText( 56 R.string.provisioning_byod_cross_profile_permission_control_prepare_button); 57 mPrepareTestButton.setOnClickListener(new OnClickListener() { 58 @Override 59 public void onClick(View v) { 60 allowTestApp(); 61 } 62 }); 63 } 64 allowTestApp()65 protected void allowTestApp() { 66 mDpm.setCrossProfilePackages(getAdminComponent(), Set.of(TEST_APP_PACKAGE_NAME)); 67 } 68 getAdminComponent()69 protected ComponentName getAdminComponent() { 70 return DeviceAdminTestReceiver.getReceiverComponentName(); 71 } 72 setupInteractAcrossProfilesDisabledByDefault(ArrayTestListAdapter adapter)73 protected void setupInteractAcrossProfilesDisabledByDefault(ArrayTestListAdapter adapter) { 74 adapter.add(new DialogTestListItem( 75 this, R.string.provisioning_byod_cross_profile_permission_disabled_by_default, 76 getTestIdPrefix() + "interactAcrossProfilesDisabledByDefault", 77 R.string.provisioning_byod_cross_profile_permission_disabled_by_default_instruction, 78 new Intent(Settings.ACTION_MANAGE_CROSS_PROFILE_ACCESS))); 79 } 80 setupInteractAcrossProfilesEnabled(ArrayTestListAdapter adapter)81 protected void setupInteractAcrossProfilesEnabled(ArrayTestListAdapter adapter) { 82 adapter.add(new DialogTestListItem( 83 this, R.string.provisioning_byod_cross_profile_permission_enabled, 84 getTestIdPrefix() + "interactAcrossProfilesEnabled", 85 R.string.provisioning_byod_cross_profile_permission_enabled_instruction, 86 new Intent(OPEN_TEST_APP_ACTION))); 87 } 88 setupInteractAcrossProfilesDisabled(ArrayTestListAdapter adapter)89 protected void setupInteractAcrossProfilesDisabled(ArrayTestListAdapter adapter) { 90 adapter.add(new DialogTestListItem(this, 91 R.string.provisioning_byod_cross_profile_permission_disabled, 92 getTestIdPrefix() + "DisableUnredactedNotifications", 93 R.string.provisioning_byod_cross_profile_permission_disabled_instruction, 94 new Intent(OPEN_TEST_APP_ACTION))); 95 } 96 getTestIdPrefix()97 protected String getTestIdPrefix() { 98 return "BYOD_"; 99 } 100 101 @Override setupTests(ArrayTestListAdapter adapter)102 protected void setupTests(ArrayTestListAdapter adapter) { 103 setupInteractAcrossProfilesDisabledByDefault(adapter); 104 setupInteractAcrossProfilesEnabled(adapter); 105 setupInteractAcrossProfilesDisabled(adapter); 106 } 107 } 108