Home | History | Annotate | Download | only in managedprovisioning
      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 = "com.android.cts.verifier.managedprovisioning.CROSS_PROFILE";
     39 
     40     @Override
     41     public void onCreate(Bundle savedInstanceState) {
     42         super.onCreate(savedInstanceState);
     43         setContentView(R.layout.provisioning_cross_profile);
     44         TextView textView = (TextView) findViewById(R.id.text);
     45 
     46         // Check if we are running in the work or personal side, by testing if currently we are the
     47         // profile owner or not.
     48         textView.setText(isProfileOwner() ? R.string.provisioning_byod_cross_profile_app_work
     49                 : R.string.provisioning_byod_cross_profile_app_personal);
     50 
     51         findViewById(R.id.button_finish).setOnClickListener(new OnClickListener() {
     52             @Override
     53             public void onClick(View v) {
     54                 CrossProfileTestActivity.this.finish();
     55             }
     56         });
     57     }
     58 
     59     private boolean isProfileOwner() {
     60         ComponentName adminReceiver = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
     61         DevicePolicyManager dpm = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
     62         return dpm.isAdminActive(adminReceiver) && dpm.isProfileOwnerApp(adminReceiver.getPackageName());
     63     }
     64 }
     65