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.PreCallCoordinator; 29 import com.google.common.collect.ImmutableList; 30 import javax.inject.Inject; 31 32 /** Implementation of {@link PreCall} */ 33 public class PreCallImpl implements PreCall { 34 35 private final ImmutableList<PreCallAction> actions; 36 37 @Inject PreCallImpl(ImmutableList<PreCallAction> actions)38 PreCallImpl(ImmutableList<PreCallAction> actions) { 39 this.actions = actions; 40 } 41 42 @NonNull 43 @Override buildIntent(Context context, CallIntentBuilder builder)44 public Intent buildIntent(Context context, CallIntentBuilder builder) { 45 Logger.get(context).logImpression(DialerImpression.Type.PRECALL_INITIATED); 46 if (!requiresUi(context, builder)) { 47 LogUtil.i("PreCallImpl.buildIntent", "No UI requested, running pre-call directly"); 48 for (PreCallAction action : actions) { 49 action.runWithoutUi(context, builder); 50 } 51 return builder.build(); 52 } 53 LogUtil.i("PreCallImpl.buildIntent", "building intent to start activity"); 54 Intent intent = new Intent(context, PreCallActivity.class); 55 intent.putExtra(PreCallCoordinator.EXTRA_CALL_INTENT_BUILDER, builder); 56 return intent; 57 } 58 requiresUi(Context context, CallIntentBuilder builder)59 private boolean requiresUi(Context context, CallIntentBuilder builder) { 60 for (PreCallAction action : actions) { 61 if (action.requiresUi(context, builder)) { 62 LogUtil.i("PreCallImpl.requiresUi", action + " requested UI"); 63 return true; 64 } 65 } 66 return false; 67 } 68 } 69