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.support.annotation.NonNull; 21 import com.android.dialer.activecalls.ActiveCallsComponent; 22 import com.android.dialer.commandline.Arguments; 23 import com.android.dialer.commandline.Command; 24 import com.android.dialer.inject.ApplicationContext; 25 import com.google.common.util.concurrent.Futures; 26 import com.google.common.util.concurrent.ListenableFuture; 27 import javax.inject.Inject; 28 29 /** Manipulates {@link com.android.dialer.activecalls.ActiveCalls} */ 30 public class ActiveCallsCommand implements Command { 31 32 private final Context appContext; 33 34 @Inject ActiveCallsCommand(@pplicationContext Context appContext)35 ActiveCallsCommand(@ApplicationContext Context appContext) { 36 this.appContext = appContext; 37 } 38 39 @NonNull 40 @Override getShortDescription()41 public String getShortDescription() { 42 return "manipulate active calls"; 43 } 44 45 @NonNull 46 @Override getUsage()47 public String getUsage() { 48 return "activecalls list"; 49 } 50 51 @Override run(Arguments args)52 public ListenableFuture<String> run(Arguments args) throws IllegalCommandLineArgumentException { 53 if (args.getPositionals().isEmpty()) { 54 return Futures.immediateFuture(getUsage()); 55 } 56 57 String command = args.getPositionals().get(0); 58 59 switch (command) { 60 case "list": 61 return Futures.immediateFuture( 62 ActiveCallsComponent.get(appContext).activeCalls().getActiveCalls().toString()); 63 default: 64 throw new IllegalCommandLineArgumentException("unknown command " + command); 65 } 66 } 67 } 68