• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.devicelockcontroller.policy;
18 
19 import androidx.annotation.IntDef;
20 import androidx.lifecycle.LifecycleOwner;
21 
22 import com.android.devicelockcontroller.common.DeviceLockConstants.SetupFailureReason;
23 
24 import com.google.common.util.concurrent.ListenableFuture;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 
29 /**
30  * Controller managing communication between setup tasks and UI layer.
31  *
32  * Note that some APIs return a listenable future because the underlying calls to
33  * {@link com.android.devicelockcontroller.storage.SetupParametersClient} return a listenable future
34  * for inter process calls.
35  */
36 public interface SetupController {
37 
38     /** Definitions for status of the setup. */
39     @Retention(RetentionPolicy.SOURCE)
40     @IntDef({
41             SetupStatus.SETUP_NOT_STARTED,
42             SetupStatus.SETUP_IN_PROGRESS,
43             SetupStatus.SETUP_FAILED,
44             SetupStatus.SETUP_FINISHED})
45     @interface SetupStatus {
46         /** Setup has not started and will be triggered from the activity. */
47         int SETUP_NOT_STARTED = 0;
48         /** Setup is in progress */
49         int SETUP_IN_PROGRESS = 1;
50         /** Setup has failed. */
51         int SETUP_FAILED = 2;
52         /** Setup has finished successfully. */
53         int SETUP_FINISHED = 3;
54     }
55 
56     /** Registers a callback listener. */
addListener(SetupUpdatesCallbacks cb)57     void addListener(SetupUpdatesCallbacks cb);
58 
59     /** Removes a callback listener. */
removeListener(SetupUpdatesCallbacks cb)60     void removeListener(SetupUpdatesCallbacks cb);
61 
62     /** Returns the status of Setup progress. */
63     @SetupStatus
getSetupState()64     int getSetupState();
65 
66     /** Triggers the setup flow process. */
startSetupFlow(LifecycleOwner owner)67     ListenableFuture<Void> startSetupFlow(LifecycleOwner owner);
68 
69     /** Callback interface for updates on setup tasks */
70     interface SetupUpdatesCallbacks {
71 
72         /** Method called when setup has failed. */
setupFailed(@etupFailureReason int reason)73         void setupFailed(@SetupFailureReason int reason);
74 
75         /** Method called when setup tasks have completed successfully. */
setupCompleted()76         void setupCompleted();
77     }
78 }
79