• 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;
18 
19 import com.android.dialer.commandline.impl.ActiveCallsCommand;
20 import com.android.dialer.commandline.impl.BlockingCommand;
21 import com.android.dialer.commandline.impl.CallCommand;
22 import com.android.dialer.commandline.impl.Echo;
23 import com.android.dialer.commandline.impl.Help;
24 import com.android.dialer.commandline.impl.Version;
25 import com.android.dialer.function.Supplier;
26 import com.android.dialer.inject.DialerVariant;
27 import com.android.dialer.inject.InstallIn;
28 import com.google.common.collect.ImmutableMap;
29 import dagger.Module;
30 import dagger.Provides;
31 import javax.inject.Inject;
32 
33 /** Provides {@link Command} */
34 @InstallIn(variants = {DialerVariant.DIALER_TEST})
35 @Module
36 public abstract class CommandLineModule {
37 
38   @Provides
provideCommandSupplier( AospCommandInjector aospCommandInjector)39   static Supplier<ImmutableMap<String, Command>> provideCommandSupplier(
40       AospCommandInjector aospCommandInjector) {
41 
42     return aospCommandInjector.inject(CommandSupplier.builder()).build();
43   }
44 
45   /** Injects standard commands to the builder */
46   public static class AospCommandInjector {
47     private final Help help;
48     private final Version version;
49     private final Echo echo;
50     private final BlockingCommand blockingCommand;
51     private final CallCommand callCommand;
52     private final ActiveCallsCommand activeCallsCommand;
53 
54     @Inject
AospCommandInjector( Help help, Version version, Echo echo, BlockingCommand blockingCommand, CallCommand callCommand, ActiveCallsCommand activeCallsCommand)55     AospCommandInjector(
56         Help help,
57         Version version,
58         Echo echo,
59         BlockingCommand blockingCommand,
60         CallCommand callCommand,
61         ActiveCallsCommand activeCallsCommand) {
62       this.help = help;
63       this.version = version;
64       this.echo = echo;
65       this.blockingCommand = blockingCommand;
66       this.callCommand = callCommand;
67       this.activeCallsCommand = activeCallsCommand;
68     }
69 
inject(CommandSupplier.Builder builder)70     public CommandSupplier.Builder inject(CommandSupplier.Builder builder) {
71       builder.addCommand("help", help);
72       builder.addCommand("version", version);
73       builder.addCommand("echo", echo);
74       builder.addCommand("blocking", blockingCommand);
75       builder.addCommand("call", callCommand);
76       builder.addCommand("activecalls", activeCallsCommand);
77       return builder;
78     }
79   }
80 }
81