1 /* 2 * Copyright (C) 2021 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 android.car.watchdog; 18 19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 20 21 import android.annotation.NonNull; 22 import android.annotation.SuppressLint; 23 import android.annotation.SystemApi; 24 import android.annotation.TestApi; 25 import android.os.Parcelable; 26 27 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 28 29 /** 30 * System-wide disk I/O overuse alert threshold. 31 * 32 * @hide 33 */ 34 @SystemApi 35 public final class IoOveruseAlertThreshold implements Parcelable { 36 /** 37 * Duration over which the given written bytes per second should be checked against. 38 * 39 * <p>Non-zero duration must provided in seconds. 40 */ 41 @SuppressLint({"MethodNameUnits"}) 42 private long mDurationInSeconds; 43 44 /** 45 * Alert I/O overuse on reaching the written bytes/second over {@link #mDurationInSeconds}. 46 * 47 * <p>Must provide non-zero bytes. 48 */ 49 private long mWrittenBytesPerSecond; 50 51 /** 52 * Creates a new IoOveruseAlertThreshold. 53 * 54 * @param durationInSeconds 55 * Duration over which the given written bytes per second should be checked against. 56 * 57 * <p>Non-zero duration must provided in seconds. 58 * @param writtenBytesPerSecond 59 * Alert I/O overuse on reaching the written bytes/second over {@link #mDurationInSeconds}. 60 * 61 * <p>Must provide non-zero bytes. 62 * @hide 63 */ 64 @TestApi IoOveruseAlertThreshold( @uppressLint{ "MethodNameUnits" }) long durationInSeconds, long writtenBytesPerSecond)65 public IoOveruseAlertThreshold( 66 @SuppressLint({ "MethodNameUnits" }) long durationInSeconds, 67 long writtenBytesPerSecond) { 68 this.mDurationInSeconds = durationInSeconds; 69 this.mWrittenBytesPerSecond = writtenBytesPerSecond; 70 } 71 72 /** 73 * Duration over which the given written bytes per second should be checked against. 74 * 75 * <p>Non-zero duration must provided in seconds. 76 */ getDurationInSeconds()77 public @SuppressLint({ "MethodNameUnits" }) long getDurationInSeconds() { 78 return mDurationInSeconds; 79 } 80 81 /** 82 * Alert I/O overuse on reaching the written bytes/second over {@link #mDurationInSeconds}. 83 * 84 * <p>Must provide non-zero bytes. 85 */ getWrittenBytesPerSecond()86 public long getWrittenBytesPerSecond() { 87 return mWrittenBytesPerSecond; 88 } 89 90 @Override toString()91 public String toString() { 92 return "IoOveruseAlertThreshold { " + 93 "durationInSeconds = " + mDurationInSeconds + ", " + 94 "writtenBytesPerSecond = " + mWrittenBytesPerSecond + 95 " }"; 96 } 97 98 @Override writeToParcel(@onNull android.os.Parcel dest, int flags)99 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 100 dest.writeLong(mDurationInSeconds); 101 dest.writeLong(mWrittenBytesPerSecond); 102 } 103 104 @Override 105 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) describeContents()106 public int describeContents() { return 0; } 107 108 /** @hide */ 109 @SuppressWarnings({"unchecked", "RedundantCast"}) IoOveruseAlertThreshold(@onNull android.os.Parcel in)110 /* package-private */ IoOveruseAlertThreshold(@NonNull android.os.Parcel in) { 111 long durationInSeconds = in.readLong(); 112 long writtenBytesPerSecond = in.readLong(); 113 114 this.mDurationInSeconds = durationInSeconds; 115 this.mWrittenBytesPerSecond = writtenBytesPerSecond; 116 } 117 118 public static final @NonNull Parcelable.Creator<IoOveruseAlertThreshold> CREATOR 119 = new Parcelable.Creator<IoOveruseAlertThreshold>() { 120 @Override 121 public IoOveruseAlertThreshold[] newArray(int size) { 122 return new IoOveruseAlertThreshold[size]; 123 } 124 125 @Override 126 public IoOveruseAlertThreshold createFromParcel(@NonNull android.os.Parcel in) { 127 return new IoOveruseAlertThreshold(in); 128 } 129 }; 130 } 131