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.example.android.deviceowner; 18 19 import android.app.admin.DeviceAdminReceiver; 20 import android.app.admin.DevicePolicyManager; 21 import android.content.ComponentName; 22 import android.content.Context; 23 import android.content.Intent; 24 25 /** 26 * Handles events related to device owner. 27 */ 28 public class DeviceOwnerReceiver extends DeviceAdminReceiver { 29 30 /** 31 * Called on the new profile when device owner provisioning has completed. Device owner 32 * provisioning is the process of setting up the device so that its main profile is managed by 33 * the mobile device management (MDM) application set up as the device owner. 34 */ 35 @Override onProfileProvisioningComplete(Context context, Intent intent)36 public void onProfileProvisioningComplete(Context context, Intent intent) { 37 // Enable the profile 38 DevicePolicyManager manager = 39 (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); 40 ComponentName componentName = getComponentName(context); 41 manager.setProfileName(componentName, context.getString(R.string.profile_name)); 42 // Open the main screen 43 Intent launch = new Intent(context, MainActivity.class); 44 launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 45 context.startActivity(launch); 46 } 47 48 /** 49 * @return A newly instantiated {@link android.content.ComponentName} for this 50 * DeviceAdminReceiver. 51 */ getComponentName(Context context)52 public static ComponentName getComponentName(Context context) { 53 return new ComponentName(context.getApplicationContext(), DeviceOwnerReceiver.class); 54 } 55 56 } 57