• 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 package android.car.storagemonitoring;
17 
18 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE;
19 
20 import android.annotation.SystemApi;
21 import android.car.annotation.AddedInOrBefore;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.util.JsonWriter;
25 
26 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
27 
28 import org.json.JSONException;
29 import org.json.JSONObject;
30 
31 import java.io.IOException;
32 import java.util.Objects;
33 
34 /**
35  * Information about how many bytes were written to a filesystem during its lifetime.
36  *
37  * @hide
38  */
39 @SystemApi
40 public final class LifetimeWriteInfo implements Parcelable {
41     @AddedInOrBefore(majorVersion = 33)
42     public static final Creator<LifetimeWriteInfo> CREATOR = new Creator<LifetimeWriteInfo>() {
43         @Override
44         public LifetimeWriteInfo createFromParcel(Parcel in) {
45             return new LifetimeWriteInfo(in);
46         }
47 
48         @Override
49         public LifetimeWriteInfo[] newArray(int size) {
50             return new LifetimeWriteInfo[size];
51         }
52     };
53 
54     @AddedInOrBefore(majorVersion = 33)
55     public final String partition;
56     @AddedInOrBefore(majorVersion = 33)
57     public final String fstype;
58     @AddedInOrBefore(majorVersion = 33)
59     public final long writtenBytes;
60 
LifetimeWriteInfo(String partition, String fstype, long writtenBytes)61     public LifetimeWriteInfo(String partition, String fstype, long writtenBytes) {
62         this.partition = Objects.requireNonNull(partition);
63         this.fstype = Objects.requireNonNull(fstype);
64         if (writtenBytes < 0) {
65             throw new IllegalArgumentException("writtenBytes must be non-negative");
66         }
67         this.writtenBytes = writtenBytes;
68     }
69 
LifetimeWriteInfo(Parcel in)70     public LifetimeWriteInfo(Parcel in) {
71         this.partition = in.readString();
72         this.fstype = in.readString();
73         this.writtenBytes = in.readLong();
74     }
75 
76     /**
77      * @hide
78      */
LifetimeWriteInfo(JSONObject in)79     public LifetimeWriteInfo(JSONObject in) throws JSONException {
80         partition = in.getString("partition");
81         fstype = in.getString("fstype");
82         writtenBytes = in.getLong("writtenBytes");
83     }
84 
85 
86     @Override
87     @AddedInOrBefore(majorVersion = 33)
writeToParcel(Parcel dest, int flags)88     public void writeToParcel(Parcel dest, int flags) {
89         dest.writeString(partition);
90         dest.writeString(fstype);
91         dest.writeLong(writtenBytes);
92     }
93 
94     /**
95      * @hide
96      */
97     @AddedInOrBefore(majorVersion = 33)
writeToJson(JsonWriter jsonWriter)98     public void writeToJson(JsonWriter jsonWriter) throws IOException {
99         jsonWriter.beginObject();
100         jsonWriter.name("partition").value(partition);
101         jsonWriter.name("fstype").value(fstype);
102         jsonWriter.name("writtenBytes").value(writtenBytes);
103         jsonWriter.endObject();
104     }
105 
106 
107     @Override
108     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
109     @AddedInOrBefore(majorVersion = 33)
describeContents()110     public int describeContents() {
111         return 0;
112     }
113 
114     @Override
equals(Object other)115     public boolean equals(Object other) {
116         if (other instanceof LifetimeWriteInfo) {
117             LifetimeWriteInfo lifetime = (LifetimeWriteInfo) other;
118             return partition.equals(lifetime.partition)
119                     && fstype.equals(lifetime.fstype)
120                     && writtenBytes == lifetime.writtenBytes;
121         }
122 
123         return false;
124     }
125 
126     @Override
hashCode()127     public int hashCode() {
128         return Objects.hash(partition, fstype, writtenBytes);
129     }
130 
131     @Override
toString()132     public String toString() {
133         return String.format("for partition %s of type %s, %d bytes were written",
134                 partition, fstype, writtenBytes);
135     }
136 }
137