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