1 /*
2  * Copyright (C) 2017 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.dialer.precall;
18 
19 import android.content.Context;
20 import android.support.annotation.MainThread;
21 import com.android.dialer.callintent.CallIntentBuilder;
22 
23 /**
24  * An action to perform before the call is made. The action should inspect and modify the {@link
25  * CallIntentBuilder} to generate full information for the call. For example, showing a dialog to
26  * select the phone account on a multi-SIM device, ask if RTT should be enabled, or rewrite the
27  * number for roaming calls.
28  *
29  * <p>UI actions are discarded when the hosting activity is paused. A new instance of the action
30  * will be created once the activity is resumed again.
31  */
32 public interface PreCallAction {
33 
34   /**
35    * Whether the action requires an activity to operate. This method is called on all actions before
36    * {@link #runWithUi(PreCallCoordinator)} is called. If {@link true} is returned, {@link
37    * #runWithUi(PreCallCoordinator)} will be guaranteed to be called on the execution phase.
38    * Otherwise {@link #runWithoutUi(Context, CallIntentBuilder)} may be called instead and the
39    * action will not be able to show UI, perform async task, or abort the call. This method should
40    * not make any state changes.
41    */
42   @MainThread
requiresUi(Context context, CallIntentBuilder builder)43   boolean requiresUi(Context context, CallIntentBuilder builder);
44 
45   /**
46    * Called when all actions returned {@code false} for {@link #requiresUi(Context,
47    * CallIntentBuilder)}.
48    */
runWithoutUi(Context context, CallIntentBuilder builder)49   void runWithoutUi(Context context, CallIntentBuilder builder);
50 
51   /**
52    * Runs the action. Should block on the main thread until the action is finished. If the action is
53    * not instantaneous, {@link PreCallCoordinator#startPendingAction()} should be called to release
54    * the thread and continue later.
55    */
56   @MainThread
runWithUi(PreCallCoordinator coordinator)57   void runWithUi(PreCallCoordinator coordinator);
58 
59   /**
60    * Called when the UI is being paused when a {@link PreCallCoordinator.PendingAction} is started,
61    * and the action is going to be discarded. If the action is showing a dialog the dialog should be
62    * dismissed. The action should not retain state, a new instance of the action will be re-run when
63    * the UI is resumed.
64    */
65   @MainThread
onDiscard()66   void onDiscard();
67 }
68