1 /*
2  * Copyright (C) 2016 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 service info logged in dmesg.
25  */
26 public class DmesgServiceInfoItem extends GenericItem {
27 
28     /** Constant for JSON output */
29     public static final String SERVICE_NAME = "SERVICE_NAME";
30     /** Constant for JSON output */
31     public static final String SERVICE_START_TIME = "SERVICE_START_TIME";
32     /** Constant for JSON output */
33     public static final String SERVICE_END_TIME = "SERVICE_END_TIME";
34     /** Constant for JSON output */
35     public static final String SERVICE_DURATION = "SERVICE_DURATION";
36 
37     private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList(
38             SERVICE_NAME, SERVICE_START_TIME, SERVICE_END_TIME));
39 
40     /**
41      * The constructor for {@link DmesgServiceInfoItem}.
42      */
DmesgServiceInfoItem()43     public DmesgServiceInfoItem() {
44         super(ATTRIBUTES);
45     }
46 
47     /**
48      * Get the name of the service
49      */
getServiceName()50     public String getServiceName() {
51         return (String) getAttribute(SERVICE_NAME);
52     }
53 
54     /**
55      * Set the name of the service
56      */
setServiceName(String serviceName)57     public void setServiceName(String serviceName) {
58         setAttribute(SERVICE_NAME, serviceName);
59     }
60 
61     /**
62      * Get the start time in msecs
63      */
getStartTime()64     public Long getStartTime() {
65         return (Long) getAttribute(SERVICE_START_TIME);
66     }
67 
68     /**
69      * Set the start time in msecs
70      */
setStartTime(Long startTime)71     public void setStartTime(Long startTime) {
72         setAttribute(SERVICE_START_TIME, startTime);
73     }
74 
75     /**
76      * Get the end time in msecs
77      */
getEndTime()78     public Long getEndTime() {
79         return (Long) getAttribute(SERVICE_END_TIME);
80     }
81 
82     /**
83      * Set the end time in msecs
84      */
setEndTime(Long endTime)85     public void setEndTime(Long endTime) {
86         setAttribute(SERVICE_END_TIME, endTime);
87     }
88 
89     /**
90      * Get the service duration in msecs If the start or end time is not present then return -1
91      */
getServiceDuration()92     public Long getServiceDuration() {
93         if (null != getAttribute(SERVICE_END_TIME) && null != getAttribute(SERVICE_START_TIME)) {
94             return getEndTime() - getStartTime();
95         }
96         return -1L;
97     }
98 
99 }
100