• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.impl;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.support.annotation.NonNull;
22 import com.android.dialer.callintent.CallIntentBuilder;
23 import com.android.dialer.common.LogUtil;
24 import com.android.dialer.logging.DialerImpression;
25 import com.android.dialer.logging.Logger;
26 import com.android.dialer.precall.PreCall;
27 import com.android.dialer.precall.PreCallAction;
28 import com.android.dialer.precall.PreCallComponent;
29 import com.android.dialer.precall.PreCallCoordinator;
30 import com.google.common.collect.ImmutableList;
31 import javax.inject.Inject;
32 
33 /** Implementation of {@link PreCall} */
34 public class PreCallImpl implements PreCall {
35 
36   @Inject
PreCallImpl()37   PreCallImpl() {}
38 
39   @Override
getActions()40   public ImmutableList<PreCallAction> getActions() {
41     return ImmutableList.of(
42         new PermissionCheckAction(), new CallingAccountSelector(), new AssistedDialAction());
43   }
44 
45   @NonNull
46   @Override
buildIntent(Context context, CallIntentBuilder builder)47   public Intent buildIntent(Context context, CallIntentBuilder builder) {
48     Logger.get(context).logImpression(DialerImpression.Type.PRECALL_INITIATED);
49     if (!requiresUi(context, builder)) {
50       LogUtil.i("PreCallImpl.buildIntent", "No UI requested, running pre-call directly");
51       for (PreCallAction action : PreCallComponent.get(context).getPreCall().getActions()) {
52         action.runWithoutUi(context, builder);
53       }
54       return builder.build();
55     }
56     LogUtil.i("PreCallImpl.buildIntent", "building intent to start activity");
57     Intent intent = new Intent(context, PreCallActivity.class);
58     intent.putExtra(PreCallCoordinator.EXTRA_CALL_INTENT_BUILDER, builder);
59     return intent;
60   }
61 
requiresUi(Context context, CallIntentBuilder builder)62   private boolean requiresUi(Context context, CallIntentBuilder builder) {
63     for (PreCallAction action : PreCallComponent.get(context).getPreCall().getActions()) {
64       if (action.requiresUi(context, builder)) {
65         LogUtil.i("PreCallImpl.requiresUi", action + " requested UI");
66         return true;
67       }
68     }
69     return false;
70   }
71 }
72