1 /*
2  * Copyright 2016, 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.managedprovisioning.finalization;
18 
19 import android.accounts.Account;
20 import android.content.BroadcastReceiver;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.os.UserHandle;
24 
25 import com.android.managedprovisioning.common.ProvisionLogger;
26 
27 /**
28  * Class that acts as the final receiver of the intent ACTION_PROFILE_PROVISIONING_COMPLETE
29  * which is broadcast using
30  * {@link Context#sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, android.os.Bundle)}
31  * after profile owner or device owner provisioning is completed.
32  */
33 public class DpcReceivedSuccessReceiver extends BroadcastReceiver {
34 
35     interface Callback {
cleanup()36         void cleanup();
37     }
38 
39     private final PrimaryProfileFinalizationHelper mHelper;
40     private final Callback mCallback;
41 
DpcReceivedSuccessReceiver(Account migratedAccount, UserHandle managedUserHandle, String mdmPackageName, Callback callback)42     public DpcReceivedSuccessReceiver(Account migratedAccount, UserHandle managedUserHandle,
43             String mdmPackageName, Callback callback) {
44         mCallback = callback;
45         mHelper = new PrimaryProfileFinalizationHelper(
46                 migratedAccount, managedUserHandle, mdmPackageName);
47     }
48 
49     @Override
onReceive(Context context, Intent intent)50     public void onReceive(Context context, Intent intent) {
51         ProvisionLogger.logd("ACTION_PROFILE_PROVISIONING_COMPLETE broadcast received by mdm");
52         mHelper.finalizeProvisioningInPrimaryProfile(context, mCallback);
53     }
54 }
55