• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.callintent;
18 
19 import android.content.Intent;
20 import android.net.Uri;
21 import android.os.Bundle;
22 import android.os.SystemClock;
23 import android.support.annotation.NonNull;
24 import android.support.annotation.Nullable;
25 import android.support.annotation.VisibleForTesting;
26 import android.telecom.PhoneAccountHandle;
27 import android.telecom.TelecomManager;
28 import android.telecom.VideoProfile;
29 import android.text.TextUtils;
30 import com.android.dialer.common.Assert;
31 import com.android.dialer.performancereport.PerformanceReport;
32 import com.android.dialer.util.CallUtil;
33 
34 /** Creates an intent to start a new outgoing call. */
35 public class CallIntentBuilder {
36   private final Uri uri;
37   private final CallSpecificAppData callSpecificAppData;
38   @Nullable private PhoneAccountHandle phoneAccountHandle;
39   private boolean isVideoCall;
40   private String callSubject;
41 
42   private static int lightbringerButtonAppearInExpandedCallLogItemCount = 0;
43   private static int lightbringerButtonAppearInCollapsedCallLogItemCount = 0;
44   private static int lightbringerButtonAppearInSearchCount = 0;
45 
CallIntentBuilder(@onNull Uri uri, @NonNull CallSpecificAppData callSpecificAppData)46   public CallIntentBuilder(@NonNull Uri uri, @NonNull CallSpecificAppData callSpecificAppData) {
47     this.uri = Assert.isNotNull(uri);
48     Assert.isNotNull(callSpecificAppData);
49     Assert.checkArgument(
50         callSpecificAppData.getCallInitiationType() != CallInitiationType.Type.UNKNOWN_INITIATION);
51 
52     CallSpecificAppData.Builder builder =
53         CallSpecificAppData.newBuilder(callSpecificAppData)
54             .setLightbringerButtonAppearInExpandedCallLogItemCount(
55                 lightbringerButtonAppearInExpandedCallLogItemCount)
56             .setLightbringerButtonAppearInCollapsedCallLogItemCount(
57                 lightbringerButtonAppearInCollapsedCallLogItemCount)
58             .setLightbringerButtonAppearInSearchCount(lightbringerButtonAppearInSearchCount);
59     lightbringerButtonAppearInExpandedCallLogItemCount = 0;
60     lightbringerButtonAppearInCollapsedCallLogItemCount = 0;
61     lightbringerButtonAppearInSearchCount = 0;
62 
63     if (PerformanceReport.isRecording()) {
64       builder
65           .setTimeSinceAppLaunch(PerformanceReport.getTimeSinceAppLaunch())
66           .setTimeSinceFirstClick(PerformanceReport.getTimeSinceFirstClick())
67           .addAllUiActionsSinceAppLaunch(PerformanceReport.getActions())
68           .addAllUiActionTimestampsSinceAppLaunch(PerformanceReport.getActionTimestamps())
69           .build();
70       PerformanceReport.stopRecording();
71     }
72 
73     this.callSpecificAppData = builder.build();
74   }
75 
CallIntentBuilder(@onNull Uri uri, CallInitiationType.Type callInitiationType)76   public CallIntentBuilder(@NonNull Uri uri, CallInitiationType.Type callInitiationType) {
77     this(uri, createCallSpecificAppData(callInitiationType));
78   }
79 
CallIntentBuilder( @onNull String number, @NonNull CallSpecificAppData callSpecificAppData)80   public CallIntentBuilder(
81       @NonNull String number, @NonNull CallSpecificAppData callSpecificAppData) {
82     this(CallUtil.getCallUri(Assert.isNotNull(number)), callSpecificAppData);
83   }
84 
CallIntentBuilder(@onNull String number, CallInitiationType.Type callInitiationType)85   public CallIntentBuilder(@NonNull String number, CallInitiationType.Type callInitiationType) {
86     this(CallUtil.getCallUri(Assert.isNotNull(number)), callInitiationType);
87   }
88 
getCallSpecificAppData()89   public CallSpecificAppData getCallSpecificAppData() {
90     return callSpecificAppData;
91   }
92 
setPhoneAccountHandle(@ullable PhoneAccountHandle accountHandle)93   public CallIntentBuilder setPhoneAccountHandle(@Nullable PhoneAccountHandle accountHandle) {
94     this.phoneAccountHandle = accountHandle;
95     return this;
96   }
97 
setIsVideoCall(boolean isVideoCall)98   public CallIntentBuilder setIsVideoCall(boolean isVideoCall) {
99     this.isVideoCall = isVideoCall;
100     return this;
101   }
102 
setCallSubject(String callSubject)103   public CallIntentBuilder setCallSubject(String callSubject) {
104     this.callSubject = callSubject;
105     return this;
106   }
107 
build()108   public Intent build() {
109     Intent intent = new Intent(Intent.ACTION_CALL, uri);
110     intent.putExtra(
111         TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE,
112         isVideoCall ? VideoProfile.STATE_BIDIRECTIONAL : VideoProfile.STATE_AUDIO_ONLY);
113 
114     Bundle extras = new Bundle();
115     extras.putLong(Constants.EXTRA_CALL_CREATED_TIME_MILLIS, SystemClock.elapsedRealtime());
116     CallIntentParser.putCallSpecificAppData(extras, callSpecificAppData);
117     intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras);
118 
119     if (phoneAccountHandle != null) {
120       intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
121     }
122 
123     if (!TextUtils.isEmpty(callSubject)) {
124       intent.putExtra(TelecomManager.EXTRA_CALL_SUBJECT, callSubject);
125     }
126 
127     return intent;
128   }
129 
createCallSpecificAppData( CallInitiationType.Type callInitiationType)130   private static @NonNull CallSpecificAppData createCallSpecificAppData(
131       CallInitiationType.Type callInitiationType) {
132     CallSpecificAppData callSpecificAppData =
133         CallSpecificAppData.newBuilder().setCallInitiationType(callInitiationType).build();
134     return callSpecificAppData;
135   }
136 
increaseLightbringerCallButtonAppearInExpandedCallLogItemCount()137   public static void increaseLightbringerCallButtonAppearInExpandedCallLogItemCount() {
138     CallIntentBuilder.lightbringerButtonAppearInExpandedCallLogItemCount++;
139   }
140 
increaseLightbringerCallButtonAppearInCollapsedCallLogItemCount()141   public static void increaseLightbringerCallButtonAppearInCollapsedCallLogItemCount() {
142     CallIntentBuilder.lightbringerButtonAppearInCollapsedCallLogItemCount++;
143   }
144 
increaseLightbringerCallButtonAppearInSearchCount()145   public static void increaseLightbringerCallButtonAppearInSearchCount() {
146     CallIntentBuilder.lightbringerButtonAppearInSearchCount++;
147   }
148 
149   @VisibleForTesting
getLightbringerButtonAppearInExpandedCallLogItemCount()150   public static int getLightbringerButtonAppearInExpandedCallLogItemCount() {
151     return lightbringerButtonAppearInExpandedCallLogItemCount;
152   }
153 
154   @VisibleForTesting
getLightbringerButtonAppearInCollapsedCallLogItemCount()155   public static int getLightbringerButtonAppearInCollapsedCallLogItemCount() {
156     return lightbringerButtonAppearInCollapsedCallLogItemCount;
157   }
158 
159   @VisibleForTesting
getLightbringerButtonAppearInSearchCount()160   public static int getLightbringerButtonAppearInSearchCount() {
161     return lightbringerButtonAppearInSearchCount;
162   }
163 
164   @VisibleForTesting(otherwise = VisibleForTesting.NONE)
clearLightbringerCounts()165   public static void clearLightbringerCounts() {
166     lightbringerButtonAppearInCollapsedCallLogItemCount = 0;
167     lightbringerButtonAppearInExpandedCallLogItemCount = 0;
168     lightbringerButtonAppearInSearchCount = 0;
169   }
170 }
171