1 /* 2 * Copyright (C) 2015 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.intent.receiver; 18 19 import android.app.admin.DevicePolicyManager; 20 import android.app.Activity; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.util.Log; 24 25 import android.os.Bundle; 26 27 /** 28 * An activity that receives an intent and returns immediately, indicating its own name and if it is 29 * running in a managed profile. 30 */ 31 public class SimpleIntentReceiverActivity extends Activity { 32 private static final String TAG = "SimpleIntentReceiverActivity"; 33 34 public void onCreate(Bundle savedInstanceState) { 35 super.onCreate(savedInstanceState); 36 String className = getIntent().getComponent().getClassName(); 37 38 // We try to check if we are in a managed profile or not. 39 // To do this, check if com.android.cts.managedprofile is the profile owner. 40 DevicePolicyManager dpm = 41 (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); 42 boolean inManagedProfile = dpm.isProfileOwnerApp("com.android.cts.managedprofile"); 43 44 Log.i(TAG, "activity " + className + " started, is in managed profile: " 45 + inManagedProfile); 46 Intent result = new Intent(); 47 result.putExtra("extra_receiver_class", className); 48 result.putExtra("extra_in_managed_profile", inManagedProfile); 49 setResult(Activity.RESULT_OK, result); 50 finish(); 51 } 52 } 53