summaryrefslogtreecommitdiff
path: root/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/DeviceOwnerNegativeTestActivity.java
blob: 078e9ce5be0947c07bbd5f83148b8797b1d0bf6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.cts.verifier.managedprovisioning;

import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.provider.Settings;

import com.android.cts.verifier.ArrayTestListAdapter;
import com.android.cts.verifier.IntentDrivenTestActivity;
import com.android.cts.verifier.IntentDrivenTestActivity.ButtonInfo;
import com.android.cts.verifier.IntentDrivenTestActivity.TestInfo;
import com.android.cts.verifier.PassFailButtons;
import com.android.cts.verifier.R;
import com.android.cts.verifier.TestListAdapter.TestListItem;

import static com.android.cts.verifier.managedprovisioning.Utils.createInteractiveTestItem;

/**
 * Activity that lists all device owner negative tests.
 */
public class DeviceOwnerNegativeTestActivity extends PassFailButtons.TestListActivity {

    private static final String DEVICE_OWNER_PROVISIONING_NEGATIVE
            = "DEVICE_OWNER_PROVISIONING_NEGATIVE";
    private static final String ENTERPRISE_PRIVACY_QUICK_SETTINGS_NEGATIVE
            = "ENTERPRISE_PRIVACY_QUICK_SETTINGS_NEGATIVE";
    private static final String ENTERPRISE_PRIVACY_KEYGUARD_NEGATIVE
            = "ENTERPRISE_PRIVACY_KEYGUARD_NEGATIVE";
    private static final String ENTERPRISE_PRIVACY_ADD_ACCOUNT_NEGATIVE
            = "ENTERPRISE_PRIVACY_ADD_ACCOUNT_NEGATIVE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pass_fail_list);
        setPassFailButtonClickListeners();

        final ArrayTestListAdapter adapter = new ArrayTestListAdapter(this);
        adapter.add(TestListItem.newCategory(this, R.string.device_owner_negative_category));

        addTestsToAdapter(adapter);

        adapter.registerDataSetObserver(new DataSetObserver() {
            @Override
            public void onChanged() {
                updatePassButton();
            }
        });

        setTestListAdapter(adapter);
    }

    private void addTestsToAdapter(final ArrayTestListAdapter adapter) {
        final TestInfo provisioningNegativeTestInfo = new TestInfo(
                DEVICE_OWNER_PROVISIONING_NEGATIVE,
                R.string.device_owner_provisioning_negative,
                R.string.device_owner_provisioning_negative_info,
                new ButtonInfo(
                        R.string.start_device_owner_provisioning_button,
                        new Intent(this, TrampolineActivity.class)));
        final Intent startTestIntent = new Intent(this, IntentDrivenTestActivity.class)
                    .putExtra(IntentDrivenTestActivity.EXTRA_ID,
                            provisioningNegativeTestInfo.getTestId())
                    .putExtra(IntentDrivenTestActivity.EXTRA_TITLE,
                            provisioningNegativeTestInfo.getTitle())
                    .putExtra(IntentDrivenTestActivity.EXTRA_INFO,
                            provisioningNegativeTestInfo.getInfoText())
                    .putExtra(IntentDrivenTestActivity.EXTRA_BUTTONS,
                            provisioningNegativeTestInfo.getButtons());
        adapter.add(TestListItem.newTest(this, provisioningNegativeTestInfo.getTitle(),
                provisioningNegativeTestInfo.getTestId(), startTestIntent, null));
        adapter.add(TestListItem.newTest(this, R.string.enterprise_privacy_quick_settings_negative,
                ENTERPRISE_PRIVACY_QUICK_SETTINGS_NEGATIVE,
                new Intent(this, EnterprisePrivacyInfoOnlyTestActivity.class)
                        .putExtra(EnterprisePrivacyInfoOnlyTestActivity.EXTRA_ID,
                                ENTERPRISE_PRIVACY_QUICK_SETTINGS_NEGATIVE)
                        .putExtra(EnterprisePrivacyInfoOnlyTestActivity.EXTRA_TITLE,
                                R.string.enterprise_privacy_quick_settings_negative)
                        .putExtra(EnterprisePrivacyInfoOnlyTestActivity.EXTRA_INFO,
                                R.string.enterprise_privacy_quick_settings_negative_info),
                        null));
        adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_KEYGUARD_NEGATIVE,
                R.string.enterprise_privacy_keyguard_negative,
                R.string.enterprise_privacy_keyguard_negative_info,
                new ButtonInfo(R.string.go_button_text, new Intent(Settings.ACTION_SETTINGS))));
        adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_ADD_ACCOUNT_NEGATIVE,
                R.string.enterprise_privacy_add_account_negative,
                R.string.enterprise_privacy_add_account_negative_info,
                new ButtonInfo(R.string.go_button_text, new Intent(Settings.ACTION_ADD_ACCOUNT))));
    }

    /**
     * This is needed because IntentDrivenTestActivity fires the intent by startActivity when
     * a button is clicked, but ACTION_PROVISION_MANAGED_DEVICE requires to be fired by
     * startActivityForResult.
     */
    public static class TrampolineActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Intent provisionDeviceIntent = new Intent(
                    DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE);
            provisionDeviceIntent.putExtra(
                    DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
                    new ComponentName(this, DeviceAdminTestReceiver.class.getName()));
            startActivityForResult(provisionDeviceIntent, 0);
        }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            finish();
        }
    }
}