1 /* 2 * Copyright (C) 2019 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 package com.android.cts.verifier.managedprovisioning; 17 18 import android.app.admin.DevicePolicyManager; 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.view.View; 24 25 import com.android.cts.verifier.ArrayTestListAdapter; 26 import com.android.cts.verifier.DialogTestListActivity; 27 import com.android.cts.verifier.R; 28 29 public class NonMarketAppsActivity extends DialogTestListActivity { 30 31 protected DevicePolicyManager mDpm; 32 33 public NonMarketAppsActivity() { 34 super(R.layout.provisioning_byod, 35 R.string.provisioning_byod_non_market_apps, 36 R.string.provisioning_byod_non_market_apps_info, 37 R.string.provisioning_byod_non_market_apps_info); 38 } 39 40 @Override 41 protected void onCreate(Bundle savedInstanceState) { 42 super.onCreate(savedInstanceState); 43 // Hiding button from default BYOD test layout, as it is not useful in this test. 44 mPrepareTestButton = findViewById(R.id.prepare_test_button); 45 mPrepareTestButton.setVisibility(View.INVISIBLE); 46 mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); 47 } 48 49 @Override 50 protected void setupTests(ArrayTestListAdapter adapter) { 51 DialogTestListItem disableNonMarketTest = new DialogTestListItem(this, 52 R.string.provisioning_byod_nonmarket_deny, 53 "BYOD_DisableNonMarketTest", 54 R.string.provisioning_byod_nonmarket_deny_info, 55 new Intent(ByodHelperActivity.ACTION_INSTALL_APK) 56 .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS, false)); 57 58 DialogTestListItem enableNonMarketTest = new DialogTestListItem(this, 59 R.string.provisioning_byod_nonmarket_allow, 60 "BYOD_EnableNonMarketTest", 61 R.string.provisioning_byod_nonmarket_allow_info, 62 new Intent(ByodHelperActivity.ACTION_INSTALL_APK) 63 .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS, true)); 64 65 DialogTestListItem disableNonMarketWorkProfileDeviceWideTest = new DialogTestListItem( 66 this, 67 R.string.provisioning_byod_nonmarket_deny_global, 68 "BYOD_DisableNonMarketDeviceWideTest", 69 R.string.provisioning_byod_nonmarket_deny_global_info, 70 new Intent(ByodHelperActivity.ACTION_INSTALL_APK_WORK_PROFILE_GLOBAL_RESTRICTION) 71 .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS_DEVICE_WIDE, 72 false)); 73 74 DialogTestListItem enableNonMarketWorkProfileDeviceWideTest = new DialogTestListItem( 75 this, 76 R.string.provisioning_byod_nonmarket_allow_global, 77 "BYOD_EnableNonMarketDeviceWideTest", 78 R.string.provisioning_byod_nonmarket_allow_global_info, 79 new Intent(ByodHelperActivity.ACTION_INSTALL_APK_WORK_PROFILE_GLOBAL_RESTRICTION) 80 .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS_DEVICE_WIDE, 81 true)); 82 83 DialogTestListItem disableNonMarketPrimaryUserDeviceWideTest = new DialogTestListItem( 84 this, 85 R.string.provisioning_byod_nonmarket_deny_global_primary, 86 "BYOD_DisableNonMarketPrimaryUserDeviceWideTest", 87 R.string.provisioning_byod_nonmarket_deny_global_primary_info, 88 new Intent(ByodHelperActivity.ACTION_INSTALL_APK_PRIMARY_PROFILE_GLOBAL_RESTRICTION) 89 .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS_DEVICE_WIDE, 90 false)); 91 92 DialogTestListItem enableNonMarketPrimaryUserDeviceWideTest = new DialogTestListItem( 93 this, 94 R.string.provisioning_byod_nonmarket_allow_global_primary, 95 "BYOD_EnableNonMarketPrimaryUserDeviceWideTest", 96 R.string.provisioning_byod_nonmarket_allow_global_primary_info, 97 new Intent(ByodHelperActivity.ACTION_INSTALL_APK_PRIMARY_PROFILE_GLOBAL_RESTRICTION) 98 .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS_DEVICE_WIDE, 99 true)); 100 101 adapter.add(disableNonMarketTest); 102 adapter.add(enableNonMarketTest); 103 adapter.add(disableNonMarketWorkProfileDeviceWideTest); 104 adapter.add(enableNonMarketWorkProfileDeviceWideTest); 105 adapter.add(disableNonMarketPrimaryUserDeviceWideTest); 106 adapter.add(enableNonMarketPrimaryUserDeviceWideTest); 107 } 108 109 protected ComponentName getAdminComponent() { 110 return DeviceAdminTestReceiver.getReceiverComponentName(); 111 } 112 } 113