1 /*
2  * Copyright (C) 2019 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 static com.android.managedprovisioning.finalization.FinalizationController.ProvisioningFinalizedResult;
20 
21 import android.os.Bundle;
22 
23 import com.android.managedprovisioning.model.ProvisioningParams;
24 
25 /**
26  * The methods in this interface are used to customize the behavior of
27  * {@link FinalizationController}.  An implementation of this interface must be provided when a
28  * {@link FinalizationController} is constructed.
29  */
30 public interface FinalizationControllerLogic {
31     /**
32      * Return true if all preconditions for {@link FinalizationController#provisioningFinalized()}
33      * to execute have been satisfied.  If false is returned,
34      * {@link FinalizationController#provisioningFinalized()} will need to be attempted again later.
35      */
isReadyForFinalization(ProvisioningParams params)36     boolean isReadyForFinalization(ProvisioningParams params);
37 
38     /**
39      * Notify the DPC for a managed profile that provisioning is completed.
40      *
41      * @return a {@link ProvisioningFinalizedResult} indicating whether the DPC started an activity
42      * as a result of that notification.
43      */
notifyDpcManagedProfile( ProvisioningParams params, int requestCode)44     @ProvisioningFinalizedResult int notifyDpcManagedProfile(
45             ProvisioningParams params, int requestCode);
46 
47     /**
48      * Notify the DPC for a managed device or managed user that provisioning is completed.
49      *
50      * @return a {@link ProvisioningFinalizedResult} indicating whether the DPC started an activity
51      * as a result of that notification.
52      */
notifyDpcManagedDeviceOrUser( ProvisioningParams params, int requestCode)53     @ProvisioningFinalizedResult int notifyDpcManagedDeviceOrUser(
54             ProvisioningParams params, int requestCode);
55 
56     /**
57      * Return true if, after managed profile provisioning, {@link PrimaryProfileFinalizationHelper}
58      * should be invoked at the time we update the system's provisioning state.
59      *
60      * If this is false, then {@link PrimaryProfileFinalizationHelper} must have already been
61      * invoked prior to reaching this point.
62      */
shouldFinalizePrimaryProfile(ProvisioningParams params)63     boolean shouldFinalizePrimaryProfile(ProvisioningParams params);
64 
65     /**
66      * This method is called when onSaveInstanceState() executes on the finalization activity.
67      */
saveInstanceState(Bundle outState)68     void saveInstanceState(Bundle outState);
69 
70     /**
71      * When saved instance state is passed to the finalization activity in its onCreate() method,
72      * that state is passed to the FinalizationControllerLogic object here so it can be restored.
73      */
restoreInstanceState(Bundle savedInstanceState, ProvisioningParams params)74     void restoreInstanceState(Bundle savedInstanceState, ProvisioningParams params);
75 
76     /**
77      * Execute cleanup actions that need to be performed when the finalization activity is
78      * destroyed, even if the system's provisioning state has not yet been finalized.
79      */
activityDestroyed(boolean isFinishing)80     void activityDestroyed(boolean isFinishing);
81 }
82