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.app.Activity;
20 import android.app.admin.DevicePolicyManager;
21 import android.os.Bundle;
22 
23 /**
24  * This class is used to make sure that we start the MDM after we shut the setup wizard down.
25  * The shut down of the setup wizard is initiated in the
26  * {@link com.android.managedprovisioning.provisioning.ProvisioningActivity} by calling
27  * {@link DevicePolicyManager#setUserProvisioningState(int, int)}. This will cause the
28  * Setup wizard to shut down and send a ACTION_PROVISIONING_FINALIZATION intent. This intent is
29  * caught by this receiver instead which will send the
30  * ACTION_PROFILE_PROVISIONING_COMPLETE broadcast to the MDM, which can then present it's own
31  * activities.
32  */
33 public class FinalizationActivity extends Activity {
34 
35     @Override
onCreate(Bundle savedInstanceState)36     public void onCreate(Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38 
39         // To prevent b/131315856, we finish this activity now only if we do not expect to launch
40         // the admin app. Otherwise let android:noHistory automatically finish it.
41         final FinalizationController finalizationController = new FinalizationController(this);
42         finalizationController.provisioningFinalized();
43         final int result = finalizationController.getProvisioningFinalizedResult();
44         if (result != FinalizationController.PROVISIONING_FINALIZED_RESULT_ADMIN_WILL_LAUNCH) {
45             finish();
46         }
47     }
48 }
49