• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.commandline.impl;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.support.annotation.NonNull;
22 import android.telecom.TelecomManager;
23 import com.android.dialer.buildtype.BuildType;
24 import com.android.dialer.buildtype.BuildType.Type;
25 import com.android.dialer.callintent.CallInitiationType;
26 import com.android.dialer.callintent.CallIntentBuilder;
27 import com.android.dialer.commandline.Arguments;
28 import com.android.dialer.commandline.Command;
29 import com.android.dialer.inject.ApplicationContext;
30 import com.android.dialer.precall.PreCall;
31 import com.google.common.util.concurrent.Futures;
32 import com.google.common.util.concurrent.ListenableFuture;
33 import javax.inject.Inject;
34 
35 /** Make calls. Requires bugfood build. */
36 public class CallCommand implements Command {
37 
38   private final Context appContext;
39 
40   @Inject
CallCommand(@pplicationContext Context appContext)41   CallCommand(@ApplicationContext Context appContext) {
42     this.appContext = appContext;
43   }
44 
45   @NonNull
46   @Override
getShortDescription()47   public String getShortDescription() {
48     return "make a call";
49   }
50 
51   @NonNull
52   @Override
getUsage()53   public String getUsage() {
54     return "call [flags --] number\n"
55         + "\nuse 'voicemail' to call voicemail"
56         + "\n\nflags:"
57         + "\n--direct send intent to telecom instead of pre call";
58   }
59 
60   @Override
61   @SuppressWarnings("missingPermission")
run(Arguments args)62   public ListenableFuture<String> run(Arguments args) throws IllegalCommandLineArgumentException {
63     if (BuildType.get() != Type.BUGFOOD) {
64       throw new SecurityException("Bugfood only command");
65     }
66     String number = args.expectPositional(0, "number");
67     TelecomManager telecomManager = appContext.getSystemService(TelecomManager.class);
68     CallIntentBuilder callIntentBuilder;
69     if ("voicemail".equals(number)) {
70       callIntentBuilder =
71           CallIntentBuilder.forVoicemail(CallInitiationType.Type.DIALPAD);
72     } else {
73       callIntentBuilder = new CallIntentBuilder(number, CallInitiationType.Type.DIALPAD);
74     }
75     if (args.getBoolean("direct", false)) {
76       Intent intent = callIntentBuilder.build();
77       appContext
78           .getSystemService(TelecomManager.class)
79           .placeCall(intent.getData(), intent.getExtras());
80     } else {
81       Intent intent = PreCall.getIntent(appContext, callIntentBuilder);
82       intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
83       appContext.startActivity(intent);
84     }
85     return Futures.immediateFuture("Calling " + number);
86   }
87 }
88