1 /*
2  * Copyright (C) 2017 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.content.ActivityNotFoundException;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.provider.Settings;
23 
24 import com.android.cts.verifier.ArrayTestListAdapter;
25 import com.android.cts.verifier.DialogTestListActivity;
26 import com.android.cts.verifier.R;
27 
28 /**
29  * Tests the Settings UI for always-on VPN in the work profile.
30  */
31 public class AlwaysOnVpnSettingsTestActivity extends DialogTestListActivity {
32 
33     public static final String ACTION_ALWAYS_ON_VPN_SETTINGS_TEST =
34             "com.android.cts.verifier.managedprovisioning.action.ALWAYS_ON_VPN_SETTINGS_TEST";
35 
36     private static final Intent VPN_SETTINGS_INTENT = new Intent(Settings.ACTION_VPN_SETTINGS);
37     private static final String CTS_VPN_APP_PACKAGE = "com.android.cts.vpnfirewall";
38     private static final String CTS_VPN_APP_ACTION =
39             "com.android.cts.vpnfirewall.action.CONNECT_AND_FINISH";
40 
AlwaysOnVpnSettingsTestActivity()41     public AlwaysOnVpnSettingsTestActivity() {
42         super(R.layout.provisioning_byod,
43                 R.string.provisioning_byod_always_on_vpn,
44                 R.string.provisioning_byod_always_on_vpn_info,
45                 R.string.provisioning_byod_always_on_vpn_instruction);
46     }
47 
48     @Override
setupTests(ArrayTestListAdapter adapter)49     protected void setupTests(ArrayTestListAdapter adapter) {
50         adapter.add(new DialogTestListItem(this,
51                 R.string.provisioning_byod_always_on_vpn_api23,
52                 "BYOD_AlwaysOnVpnSettingsApi23Test",
53                 R.string.provisioning_byod_always_on_vpn_api23_instruction,
54                 VPN_SETTINGS_INTENT
55         ));
56         adapter.add(new DialogTestListItem(this,
57                 R.string.provisioning_byod_always_on_vpn_api24,
58                 "BYOD_AlwaysOnVpnSettingsApi24Test",
59                 R.string.provisioning_byod_always_on_vpn_api24_instruction,
60                 VPN_SETTINGS_INTENT
61         ));
62         adapter.add(new DialogTestListItem(this,
63                 R.string.provisioning_byod_always_on_vpn_not_always_on,
64                 "BYOD_AlwaysOnVpnSettingsNotAlwaysOnTest",
65                 R.string.provisioning_byod_always_on_vpn_not_always_on_instruction,
66                 VPN_SETTINGS_INTENT
67         ));
68     }
69 
70     @Override
onCreate(Bundle savedInstanceState)71     protected void onCreate(Bundle savedInstanceState) {
72         super.onCreate(savedInstanceState);
73 
74         mPrepareTestButton.setText(
75                 R.string.provisioning_byod_always_on_vpn_prepare_button);
76         mPrepareTestButton.setOnClickListener(v -> {
77             try {
78                 final Intent intent =
79                         getPackageManager().getLaunchIntentForPackage(CTS_VPN_APP_PACKAGE);
80                 intent.setAction(CTS_VPN_APP_ACTION);
81                 startActivity(intent);
82             } catch (ActivityNotFoundException unused) {
83                 Utils.showToast(this, R.string.provisioning_byod_always_on_vpn_vpn_not_found_note);
84             }
85         });
86     }
87 }
88