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 com.android.car.storagemonitoring; 17 18 import static java.util.Objects.hash; 19 20 import android.car.storagemonitoring.WearEstimate; 21 22 public final class WearInformation { 23 public static final int UNKNOWN_LIFETIME_ESTIMATE = -1; 24 25 public static final int UNKNOWN_PRE_EOL_INFO = 0; 26 public static final int PRE_EOL_INFO_NORMAL = 1; 27 public static final int PRE_EOL_INFO_WARNING = 2; 28 public static final int PRE_EOL_INFO_URGENT = 3; 29 30 private static final String UNKNOWN = "unknown"; 31 private static final String[] PRE_EOL_STRINGS = new String[] { 32 UNKNOWN, "normal", "warning", "urgent" 33 }; 34 35 /** 36 * A lower bound on the lifetime estimate for "type A" memory cells, expressed as a percentage. 37 */ 38 public final int lifetimeEstimateA; 39 40 /** 41 * A lower bound on the lifetime estimate for "type B" memory cells, expressed as a percentage. 42 */ 43 public final int lifetimeEstimateB; 44 45 /** 46 * An estimate of the lifetime based on reserved block consumption. 47 */ 48 public final int preEolInfo; 49 WearInformation(int lifetimeA, int lifetimeB, int preEol)50 public WearInformation(int lifetimeA, int lifetimeB, int preEol) { 51 lifetimeEstimateA = lifetimeA; 52 lifetimeEstimateB = lifetimeB; 53 preEolInfo = preEol; 54 } 55 56 @Override hashCode()57 public int hashCode() { 58 return hash(lifetimeEstimateA, lifetimeEstimateB, preEolInfo); 59 } 60 61 @Override equals(Object other)62 public boolean equals(Object other) { 63 if (other instanceof WearInformation) { 64 WearInformation wi = (WearInformation)other; 65 return (wi.lifetimeEstimateA == lifetimeEstimateA) && 66 (wi.lifetimeEstimateB == lifetimeEstimateB) && 67 (wi.preEolInfo == preEolInfo); 68 } else { 69 return false; 70 } 71 } 72 lifetimeToString(int lifetime)73 private String lifetimeToString(int lifetime) { 74 if (lifetime == UNKNOWN_LIFETIME_ESTIMATE) return UNKNOWN; 75 76 return lifetime + "%"; 77 } 78 79 @Override toString()80 public String toString() { 81 return String.format("lifetime estimate: A = %s, B = %s; pre EOL info: %s", 82 lifetimeToString(lifetimeEstimateA), 83 lifetimeToString(lifetimeEstimateB), 84 PRE_EOL_STRINGS[preEolInfo]); 85 } 86 toWearEstimate()87 public WearEstimate toWearEstimate() { 88 return new WearEstimate(lifetimeEstimateA, lifetimeEstimateB); 89 } 90 } 91