• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package android.car.storagemonitoring;
17 
18 import static java.util.Objects.requireNonNull;
19 
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.time.Instant;
26 import java.util.Objects;
27 
28 /**
29  * Change in wear-out information.
30  *
31  * Contains information about the first cycle during which the system detected a change
32  * in wear-out information of the flash storage.
33  *
34  * @hide
35  */
36 @SystemApi
37 public final class WearEstimateChange implements Parcelable {
38     public static final Parcelable.Creator<WearEstimateChange> CREATOR =
39             new Parcelable.Creator<WearEstimateChange>() {
40         public WearEstimateChange createFromParcel(Parcel in) {
41             return new WearEstimateChange(in);
42         }
43 
44         public WearEstimateChange[] newArray(int size) {
45                 return new WearEstimateChange[size];
46             }
47     };
48 
49     /**
50      * The previous wear estimate.
51      */
52     public final @NonNull WearEstimate oldEstimate;
53 
54     /**
55      * The new wear estimate.
56      */
57     public final @NonNull WearEstimate newEstimate;
58 
59     /**
60      * Total CarService uptime when this change was detected.
61      */
62     public final long uptimeAtChange;
63 
64     /**
65      * Wall-clock time when this change was detected.
66      */
67     public final @NonNull Instant dateAtChange;
68 
69     /**
70      * Whether this change was within the vendor range for acceptable flash degradation.
71      */
72     public final boolean isAcceptableDegradation;
73 
WearEstimateChange(WearEstimate oldEstimate, WearEstimate newEstimate, long uptimeAtChange, Instant dateAtChange, boolean isAcceptableDegradation)74     public WearEstimateChange(WearEstimate oldEstimate,
75                               WearEstimate newEstimate,
76                               long uptimeAtChange,
77                               Instant dateAtChange,
78                               boolean isAcceptableDegradation) {
79         if (uptimeAtChange < 0) {
80             throw new IllegalArgumentException("uptimeAtChange must be >= 0");
81         }
82         this.oldEstimate = requireNonNull(oldEstimate);
83         this.newEstimate = requireNonNull(newEstimate);
84         this.uptimeAtChange = uptimeAtChange;
85         this.dateAtChange = requireNonNull(dateAtChange);
86         this.isAcceptableDegradation = isAcceptableDegradation;
87     }
88 
WearEstimateChange(Parcel in)89     public WearEstimateChange(Parcel in) {
90         oldEstimate = in.readParcelable(WearEstimate.class.getClassLoader());
91         newEstimate = in.readParcelable(WearEstimate.class.getClassLoader());
92         uptimeAtChange = in.readLong();
93         dateAtChange = Instant.ofEpochMilli(in.readLong());
94         isAcceptableDegradation = in.readInt() == 1;
95     }
96 
97     @Override
describeContents()98     public int describeContents() {
99         return 0;
100     }
101 
102     @Override
writeToParcel(Parcel dest, int flags)103     public void writeToParcel(Parcel dest, int flags) {
104         dest.writeParcelable(oldEstimate, flags);
105         dest.writeParcelable(newEstimate, flags);
106         dest.writeLong(uptimeAtChange);
107         dest.writeLong(dateAtChange.toEpochMilli());
108         dest.writeInt(isAcceptableDegradation ? 1 : 0);
109     }
110 
111     @Override
equals(Object other)112     public boolean equals(Object other) {
113         if (other instanceof WearEstimateChange) {
114             WearEstimateChange wo = (WearEstimateChange) other;
115             return wo.isAcceptableDegradation == isAcceptableDegradation
116                     && wo.uptimeAtChange == uptimeAtChange
117                     && wo.dateAtChange.equals(dateAtChange)
118                     && wo.oldEstimate.equals(oldEstimate)
119                     && wo.newEstimate.equals(newEstimate);
120         }
121         return false;
122     }
123 
124     @Override
hashCode()125     public int hashCode() {
126         return Objects.hash(oldEstimate,
127                             newEstimate,
128                             uptimeAtChange,
129                             dateAtChange,
130                             isAcceptableDegradation);
131     }
132 
133     @Override
toString()134     public String toString() {
135         return String.format(
136                 "wear change{old level=%s, new level=%s, uptime=%d, date=%s, acceptable=%s}",
137                 oldEstimate,
138                 newEstimate,
139                 uptimeAtChange,
140                 dateAtChange,
141                 isAcceptableDegradation ? "yes" : "no");
142     }
143 
144 }
145