blob: e56a541078e69e6f52d248b0d0965641b387a0c8 [file] [log] [blame]
Aurimas Liutikas88c7ff12023-08-10 12:42:26 -07001/*
2 * Copyright (C) 2022 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
17package com.android.server.usage;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.UserIdInt;
22import android.util.LongArrayQueue;
23
24import java.util.Objects;
25
26/**
27 * Contains the data needed to identify a broadcast event.
28 */
29class BroadcastEvent {
30 private int mSourceUid;
31 private String mTargetPackage;
32 private int mTargetUserId;
33 private long mIdForResponseEvent;
34 private final LongArrayQueue mTimestampsMs;
35
36 BroadcastEvent(int sourceUid, @NonNull String targetPackage, @UserIdInt int targetUserId,
37 long idForResponseEvent) {
38 mSourceUid = sourceUid;
39 mTargetPackage = targetPackage;
40 mTargetUserId = targetUserId;
41 mIdForResponseEvent = idForResponseEvent;
42 mTimestampsMs = new LongArrayQueue();
43 }
44
45 public int getSourceUid() {
46 return mSourceUid;
47 }
48
49 public @NonNull String getTargetPackage() {
50 return mTargetPackage;
51 }
52
53 public @UserIdInt int getTargetUserId() {
54 return mTargetUserId;
55 }
56
57 public long getIdForResponseEvent() {
58 return mIdForResponseEvent;
59 }
60
61 public LongArrayQueue getTimestampsMs() {
62 return mTimestampsMs;
63 }
64
65 public void addTimestampMs(long timestampMs) {
66 mTimestampsMs.addLast(timestampMs);
67 }
68
69 @Override
70 public boolean equals(@Nullable Object obj) {
71 if (this == obj) {
72 return true;
73 }
74 if (obj == null || !(obj instanceof BroadcastEvent)) {
75 return false;
76 }
77 final BroadcastEvent other = (BroadcastEvent) obj;
78 return this.mSourceUid == other.mSourceUid
79 && this.mIdForResponseEvent == other.mIdForResponseEvent
80 && this.mTargetUserId == other.mTargetUserId
81 && this.mTargetPackage.equals(other.mTargetPackage);
82 }
83
84 @Override
85 public int hashCode() {
86 return Objects.hash(mSourceUid, mTargetPackage, mTargetUserId,
87 mIdForResponseEvent);
88 }
89
90 @Override
91 public @NonNull String toString() {
92 return "BroadcastEvent {"
93 + "srcUid=" + mSourceUid
94 + ",tgtPkg=" + mTargetPackage
95 + ",tgtUser=" + mTargetUserId
96 + ",id=" + mIdForResponseEvent
97 + "}";
98 }
99}