1 /*
2  * Copyright (C) 2012 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 //package com.android.cts.verifier.managedprovisioning;
19 
20 import android.app.Activity;
21 import android.app.admin.DevicePolicyManager;
22 import android.content.ComponentName;
23 import android.content.Context;
24 import android.os.Bundle;
25 import android.os.Process;
26 import android.os.UserManager;
27 import android.view.View;
28 import android.view.View.OnClickListener;
29 import android.widget.TextView;
30 
31 import com.android.cts.verifier.R;
32 
33 /**
34  * Test activity for cross profile intents.
35  */
36 public class CrossProfileTestActivity extends Activity {
37     // Intent for app in both profiles
38     public static final String ACTION_CROSS_PROFILE_TO_PERSONAL =
39             "com.android.cts.verifier.managedprovisioning.CROSS_PROFILE_TO_PERSONAL";
40     public static final String ACTION_CROSS_PROFILE_TO_WORK =
41             "com.android.cts.verifier.managedprovisioning.CROSS_PROFILE_TO_WORK";
42     public static final String EXTRA_STARTED_FROM_WORK
43             = "com.android.cts.verifier.managedprovisioning.STARTED_FROM_WORK";
44 
45     @Override
onCreate(Bundle savedInstanceState)46     public void onCreate(Bundle savedInstanceState) {
47         super.onCreate(savedInstanceState);
48         setContentView(R.layout.provisioning_cross_profile);
49         TextView textView = (TextView) findViewById(R.id.text);
50 
51         // Check if we are running in the work or personal side, by testing if currently we are the
52         // profile owner or not.
53         boolean inWorkProfile = isProfileOwner();
54         boolean startedFromWork = getIntent().getBooleanExtra(EXTRA_STARTED_FROM_WORK, false);
55         if (inWorkProfile && !startedFromWork) {
56             textView.setText(R.string.provisioning_byod_cross_profile_app_work);
57         } else if (!inWorkProfile && startedFromWork) {
58             textView.setText(R.string.provisioning_byod_cross_profile_app_personal);
59         } else { // started from the same side we're currently running in
60             textView.setText(R.string.provisioning_byod_cross_profile_app_ctsverifier);
61         }
62         findViewById(R.id.button_finish).setOnClickListener(new OnClickListener() {
63             @Override
64             public void onClick(View v) {
65                 CrossProfileTestActivity.this.finish();
66             }
67         });
68     }
69 
isProfileOwner()70     private boolean isProfileOwner() {
71         ComponentName adminReceiver = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
72         DevicePolicyManager dpm = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
73         return dpm.isAdminActive(adminReceiver) && dpm.isProfileOwnerApp(adminReceiver.getPackageName());
74     }
75 }
76