• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.Context;
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 WorkProfileWidgetActivity extends DialogTestListActivity {
30 
31     public static final String ACTION_TEST_WORK_PROFILE_WIDGET =
32             "com.android.cts.verifier.byod.test_work_profile_widget";
33 
34     private DevicePolicyManager mDpm;
35 
WorkProfileWidgetActivity()36     public WorkProfileWidgetActivity() {
37         super(R.layout.provisioning_byod,
38                 R.string.provisioning_byod_work_profile_widget,
39                 R.string.provisioning_byod_work_profile_widget_info,
40                 R.string.provisioning_byod_work_profile_widget_description);
41     }
42 
43     @Override
onCreate(Bundle savedInstanceState)44     protected void onCreate(Bundle savedInstanceState) {
45         super.onCreate(savedInstanceState);
46         mPrepareTestButton.setVisibility(View.GONE);
47 
48         mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
49         allowToAddCtsVerifierWidget();
50     }
51 
52     @Override
finish()53     public void finish() {
54         // Revert the policy.
55         disallowToAddCtsVerifierWidget();
56         super.finish();
57     }
58 
59     @Override
setupTests(ArrayTestListAdapter adapter)60     protected void setupTests(ArrayTestListAdapter adapter) {
61         // no-op
62     }
63 
allowToAddCtsVerifierWidget()64     private void allowToAddCtsVerifierWidget() {
65         mDpm.addCrossProfileWidgetProvider(getAdminComponent(), getPackageName());
66     }
67 
disallowToAddCtsVerifierWidget()68     private void disallowToAddCtsVerifierWidget() {
69         mDpm.removeCrossProfileWidgetProvider(getAdminComponent(), getPackageName());
70     }
71 
getAdminComponent()72     private ComponentName getAdminComponent() {
73         return DeviceAdminTestReceiver.getReceiverComponentName();
74     }
75 }
76