1 /*
2  * Copyright (C) 2017 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.loganalysis.item;
18 
19 import java.util.Arrays;
20 import java.util.HashSet;
21 import java.util.Set;
22 
23 /**
24  * An {@link IItem} used to store action info logged in dmesg
25  * For example: [   14.942872] init: processing action (early-init)
26  */
27 public class DmesgActionInfoItem extends GenericItem {
28 
29     /** Constant for JSON output */
30     public static final String SOURCE_NAME = "SOURCE_NAME";
31     /** Constant for JSON output */
32     public static final String ACTION_NAME = "ACTION_NAME";
33     /** Constant for JSON output */
34     public static final String ACTION_START_TIME = "ACTION_START_TIME";
35 
36     private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList(
37             SOURCE_NAME, ACTION_NAME, ACTION_START_TIME));
38 
39     /**
40      * The constructor for {@link DmesgActionInfoItem}.
41      */
DmesgActionInfoItem()42     public DmesgActionInfoItem() {
43         super(ATTRIBUTES);
44     }
45 
46     /**
47      * The constructor for {@link DmesgActionInfoItem}.
48      */
DmesgActionInfoItem(String source, String name, Long startTime)49     public DmesgActionInfoItem(String source, String name, Long startTime) {
50         super(ATTRIBUTES);
51         setAttribute(SOURCE_NAME, source);
52         setAttribute(ACTION_NAME, name);
53         setAttribute(ACTION_START_TIME, startTime);
54     }
55 
56     /**
57      * Get the name of the source
58      */
getSourceName()59     public String getSourceName() {
60         return (String) getAttribute(SOURCE_NAME);
61     }
62 
63     /**
64      * Set the name of the source
65      */
setSourceName(String sourceName)66     public void setSourceName(String sourceName) {
67         setAttribute(SOURCE_NAME, sourceName);
68     }
69 
70     /**
71      * Get the name of the action
72      */
getActionName()73     public String getActionName() {
74         return (String) getAttribute(ACTION_NAME);
75     }
76 
77     /**
78      * Set the name of the action
79      */
setActionName(String stageName)80     public void setActionName(String stageName) {
81         setAttribute(ACTION_NAME, stageName);
82     }
83 
84     /**
85      * Get the start time in msecs
86      */
getStartTime()87     public Long getStartTime() {
88         return (Long) getAttribute(ACTION_START_TIME);
89     }
90 
91     /**
92      * Set the start time in msecs
93      */
setStartTime(Long startTime)94     public void setStartTime(Long startTime) {
95         setAttribute(ACTION_START_TIME, startTime);
96     }
97 
98     @Override
toString()99     public String toString() {
100         return "ActionInfoItem ["
101                 + "getSourceName()=" + getSourceName()
102                 + ", getActionName()=" + getActionName()
103                 + ", getStartTime()=" + getStartTime()
104                 + "]";
105     }
106 
107 }
108