1 /*
2  * Copyright (C) 2021 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.provisioninglisteners;
18 
19 import android.app.admin.DevicePolicyManager;
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  * This receiver is invoked after PO/DO provisioning is completed.
29  */
30 // TODO(b/178711424): move this into the framework.
31 public class ProvisioningCompletedListener extends BroadcastReceiver {
32 
33     @Override
onReceive(Context context, Intent intent)34     public void onReceive(Context context, Intent intent) {
35         if (!DevicePolicyManager.ACTION_PROVISIONING_COMPLETED.equals(intent.getAction())) {
36             ProvisionLogger.logw("Unexpected intent action: " + intent.getAction());
37             return;
38         }
39         final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
40         final boolean leaveAllSystemAppsEnabled = intent.getBooleanExtra(
41                 DevicePolicyManager.EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED, false);
42         final String provisioningAction = intent.getStringExtra(
43                 DevicePolicyManager.EXTRA_PROVISIONING_ACTION);
44         ProvisionLogger.logd("ACTION_PROVISIONING_COMPLETED received for user " + userId);
45         final PendingResult result = goAsync();
46         Thread thread = new Thread(() -> {
47             new ProvisioningCompletedController(
48                     userId, provisioningAction, leaveAllSystemAppsEnabled, context).run();
49             result.finish();
50         });
51         thread.setPriority(Thread.MAX_PRIORITY);
52         thread.start();
53     }
54 }
55