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 */
16package com.android.dialer.calllogutils;
17
18import android.content.Context;
19import android.content.Intent;
20import android.provider.CallLog.Calls;
21import android.support.annotation.Nullable;
22import com.android.dialer.callintent.CallInitiationType;
23import com.android.dialer.callintent.CallIntentBuilder;
24import com.android.dialer.calllog.model.CoalescedRow;
25import com.android.dialer.phonenumberutil.PhoneNumberHelper;
26import com.android.dialer.precall.PreCall;
27import com.android.dialer.telecom.TelecomUtil;
28
29/** Provides intents related to call log entries. */
30public final class CallLogIntents {
31
32  /**
33   * Returns an intent which can be used to call back for the provided row.
34   *
35   * <p>If the call was a video call, a video call will be placed, and if the call was an audio
36   * call, an audio call will be placed.
37   *
38   * @return null if the provided {@code row} doesn't have a number
39   */
40  @Nullable
41  public static Intent getCallBackIntent(Context context, CoalescedRow row) {
42    String normalizedNumber = row.number().getNormalizedNumber();
43    if (!PhoneNumberHelper.canPlaceCallsTo(normalizedNumber, row.numberPresentation())) {
44      return null;
45    }
46
47    // TODO(zachh): More granular logging?
48    return PreCall.getIntent(
49        context,
50        new CallIntentBuilder(normalizedNumber, CallInitiationType.Type.CALL_LOG)
51            .setPhoneAccountHandle(
52                TelecomUtil.composePhoneAccountHandle(
53                    row.phoneAccountComponentName(), row.phoneAccountId()))
54            .setIsVideoCall((row.features() & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO));
55  }
56}
57