| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.usage; |
| 18 |
|
| 19 |
import android.annotation.IntRange; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.app.BroadcastOptions; |
| 23 |
import android.os.Parcel; |
| 24 |
import android.os.Parcelable; |
| 25 |
|
| 26 |
import java.util.Objects; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
@SystemApi |
| 37 |
public final class BroadcastResponseStats implements Parcelable { |
| 38 |
private final String mPackageName; |
| 39 |
private final long mId; |
| 40 |
private int mBroadcastsDispatchedCount; |
| 41 |
private int mNotificationsPostedCount; |
| 42 |
private int mNotificationsUpdatedCount; |
| 43 |
private int mNotificationsCancelledCount; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public BroadcastResponseStats(@NonNull String packageName, @IntRange(from = 1) long id) { |
| 56 |
mPackageName = packageName; |
| 57 |
mId = id; |
| 58 |
} |
| 59 |
|
| 60 |
private BroadcastResponseStats(@NonNull Parcel in) { |
| 61 |
mPackageName = in.readString8(); |
| 62 |
mId = in.readLong(); |
| 63 |
mBroadcastsDispatchedCount = in.readInt(); |
| 64 |
mNotificationsPostedCount = in.readInt(); |
| 65 |
mNotificationsUpdatedCount = in.readInt(); |
| 66 |
mNotificationsCancelledCount = in.readInt(); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
@NonNull |
| 73 |
public String getPackageName() { |
| 74 |
return mPackageName; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
@IntRange(from = 1) |
| 81 |
public long getId() { |
| 82 |
return mId; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
@IntRange(from = 0) |
| 95 |
public int getBroadcastsDispatchedCount() { |
| 96 |
return mBroadcastsDispatchedCount; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
@IntRange(from = 0) |
| 111 |
public int getNotificationsPostedCount() { |
| 112 |
return mNotificationsPostedCount; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
@IntRange(from = 0) |
| 127 |
public int getNotificationsUpdatedCount() { |
| 128 |
return mNotificationsUpdatedCount; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
@IntRange(from = 0) |
| 143 |
public int getNotificationsCancelledCount() { |
| 144 |
return mNotificationsCancelledCount; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
public void incrementBroadcastsDispatchedCount(@IntRange(from = 0) int count) { |
| 149 |
mBroadcastsDispatchedCount += count; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
public void incrementNotificationsPostedCount(@IntRange(from = 0) int count) { |
| 154 |
mNotificationsPostedCount += count; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
public void incrementNotificationsUpdatedCount(@IntRange(from = 0) int count) { |
| 159 |
mNotificationsUpdatedCount += count; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
public void incrementNotificationsCancelledCount(@IntRange(from = 0) int count) { |
| 164 |
mNotificationsCancelledCount += count; |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
public void addCounts(@NonNull BroadcastResponseStats stats) { |
| 169 |
incrementBroadcastsDispatchedCount(stats.getBroadcastsDispatchedCount()); |
| 170 |
incrementNotificationsPostedCount(stats.getNotificationsPostedCount()); |
| 171 |
incrementNotificationsUpdatedCount(stats.getNotificationsUpdatedCount()); |
| 172 |
incrementNotificationsCancelledCount(stats.getNotificationsCancelledCount()); |
| 173 |
} |
| 174 |
|
| 175 |
@Override |
| 176 |
public boolean equals(Object obj) { |
| 177 |
if (this == obj) { |
| 178 |
return true; |
| 179 |
} |
| 180 |
if (obj == null || !(obj instanceof BroadcastResponseStats)) { |
| 181 |
return false; |
| 182 |
} |
| 183 |
final BroadcastResponseStats other = (BroadcastResponseStats) obj; |
| 184 |
return this.mBroadcastsDispatchedCount == other.mBroadcastsDispatchedCount |
| 185 |
&& this.mNotificationsPostedCount == other.mNotificationsPostedCount |
| 186 |
&& this.mNotificationsUpdatedCount == other.mNotificationsUpdatedCount |
| 187 |
&& this.mNotificationsCancelledCount == other.mNotificationsCancelledCount |
| 188 |
&& this.mId == other.mId |
| 189 |
&& this.mPackageName.equals(other.mPackageName); |
| 190 |
} |
| 191 |
|
| 192 |
@Override |
| 193 |
public int hashCode() { |
| 194 |
return Objects.hash(mPackageName, mId, mBroadcastsDispatchedCount, |
| 195 |
mNotificationsPostedCount, mNotificationsUpdatedCount, |
| 196 |
mNotificationsCancelledCount); |
| 197 |
} |
| 198 |
|
| 199 |
@Override |
| 200 |
public @NonNull String toString() { |
| 201 |
return "stats {" |
| 202 |
+ "package=" + mPackageName |
| 203 |
+ ",id=" + mId |
| 204 |
+ ",broadcastsSent=" + mBroadcastsDispatchedCount |
| 205 |
+ ",notificationsPosted=" + mNotificationsPostedCount |
| 206 |
+ ",notificationsUpdated=" + mNotificationsUpdatedCount |
| 207 |
+ ",notificationsCancelled=" + mNotificationsCancelledCount |
| 208 |
+ "}"; |
| 209 |
} |
| 210 |
|
| 211 |
@Override |
| 212 |
public @ContentsFlags int describeContents() { |
| 213 |
return 0; |
| 214 |
} |
| 215 |
|
| 216 |
@Override |
| 217 |
public void writeToParcel(@NonNull Parcel dest, @WriteFlags int flags) { |
| 218 |
dest.writeString8(mPackageName); |
| 219 |
dest.writeLong(mId); |
| 220 |
dest.writeInt(mBroadcastsDispatchedCount); |
| 221 |
dest.writeInt(mNotificationsPostedCount); |
| 222 |
dest.writeInt(mNotificationsUpdatedCount); |
| 223 |
dest.writeInt(mNotificationsCancelledCount); |
| 224 |
} |
| 225 |
|
| 226 |
public static final @NonNull Creator<BroadcastResponseStats> CREATOR = |
| 227 |
new Creator<BroadcastResponseStats>() { |
| 228 |
@Override |
| 229 |
public @NonNull BroadcastResponseStats createFromParcel(@NonNull Parcel source) { |
| 230 |
return new BroadcastResponseStats(source); |
| 231 |
} |
| 232 |
|
| 233 |
@Override |
| 234 |
public @NonNull BroadcastResponseStats[] newArray(int size) { |
| 235 |
return new BroadcastResponseStats[size]; |
| 236 |
} |
| 237 |
}; |
| 238 |
} |