• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.adservices.shared.testing.shell;
18 
19 import com.google.common.annotations.VisibleForTesting;
20 
21 import java.util.Objects;
22 
23 // TODO(b/324491698): use ShellCommandOutput instead (or factor it to use it inside)
24 /** Contains the result of a shell command. */
25 public final class CommandResult {
26 
27     // TODO(b/324491698): make them package protected when moved to c.a.a.s.t.device packages
28     @VisibleForTesting public static final String STATUS_RUNNING = "RUNNING";
29     @VisibleForTesting public static final String STATUS_FINISHED = "FINISHED";
30 
31     private final String mOut;
32     private final String mErr;
33     private final String mCommandStatus;
34 
CommandResult(String out, String err, String commandStatus)35     public CommandResult(String out, String err, String commandStatus) {
36         mOut = Objects.requireNonNull(out, "out cannot be null");
37         mErr = Objects.requireNonNull(err, "err cannot be null");
38         mCommandStatus = Objects.requireNonNull(commandStatus, "status cannot be null");
39     }
40 
CommandResult(String out, String err)41     public CommandResult(String out, String err) {
42         this(out, err, STATUS_FINISHED);
43     }
44 
getOut()45     public String getOut() {
46         return mOut;
47     }
48 
getErr()49     public String getErr() {
50         return mErr;
51     }
52 
getCommandStatus()53     public String getCommandStatus() {
54         return mCommandStatus;
55     }
56 
57     @Override
toString()58     public String toString() {
59         return String.format(
60                 "CommandResult[out=%s, err=%s, status=%s]", mOut, mErr, mCommandStatus);
61     }
62 
isCommandRunning()63     public boolean isCommandRunning() {
64         return mCommandStatus.equals(STATUS_RUNNING);
65     }
66 }
67