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 package com.android.tradefed.suite.checker;
17 
18 import java.util.LinkedHashMap;
19 import java.util.Map;
20 
21 /** Contains the result of a {@link ISystemStatusChecker} execution. */
22 public class StatusCheckerResult {
23 
24     public enum CheckStatus {
25         /** status check was successful */
26         SUCCESS,
27         /** status check did not succeed. An error message might be available (optional). */
28         FAILED,
29     }
30 
31     public static final String SYSTEM_CHECKER = "system_checker";
32     private CheckStatus mCheckStatus = CheckStatus.FAILED;
33     private String mErrorMessage = null;
34     private boolean mBugreportNeeded = false;
35     private Map<String, String> mModuleProperties = new LinkedHashMap<>();
36 
37     /** Create a {@link StatusCheckerResult} with the default {@link CheckStatus#FAILED} status. */
StatusCheckerResult()38     public StatusCheckerResult() {}
39 
40     /**
41      * Create a {@link StatusCheckerResult} with the given status.
42      *
43      * @param status the {@link CheckStatus}
44      */
StatusCheckerResult(CheckStatus status)45     public StatusCheckerResult(CheckStatus status) {
46         mCheckStatus = status;
47     }
48 
49     /** Returns the {@link CheckStatus} of the checker. */
getStatus()50     public CheckStatus getStatus() {
51         return mCheckStatus;
52     }
53 
54     /** Sets the {@link CheckStatus} of the checker. */
setStatus(CheckStatus status)55     public void setStatus(CheckStatus status) {
56         mCheckStatus = status;
57     }
58 
59     /**
60      * Returns the error message associated with a failure. Can be null even in case of failures.
61      */
getErrorMessage()62     public String getErrorMessage() {
63         return mErrorMessage;
64     }
65 
66     /** Sets the error message associated with a failure. */
setErrorMessage(String message)67     public void setErrorMessage(String message) {
68         mErrorMessage = message;
69     }
70 
71     /** Returns whether or not a bugreport is needed in case of checker failure. */
isBugreportNeeded()72     public boolean isBugreportNeeded() {
73         return mBugreportNeeded;
74     }
75 
76     /** Sets whether or not a bugreport is needed in case of checker failure. */
setBugreportNeeded(boolean need)77     public void setBugreportNeeded(boolean need) {
78         mBugreportNeeded = need;
79     }
80 
81     /** Adds a module property reported by the checker. */
addModuleProperty(String propertyName, String property)82     public void addModuleProperty(String propertyName, String property) {
83         mModuleProperties.put(SYSTEM_CHECKER + '_' + propertyName, property);
84     }
85 
86     /** Returns the module properties reported by the checker. */
getModuleProperties()87     public Map<String, String> getModuleProperties() {
88         return mModuleProperties;
89     }
90 }
91