• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.server.usage;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.UserIdInt;
22 import android.util.LongArrayQueue;
23 
24 import java.util.Objects;
25 
26 /**
27  * Contains the data needed to identify a broadcast event.
28  */
29 class BroadcastEvent {
30     private int mSourceUid;
31     private String mTargetPackage;
32     private int mTargetUserId;
33     private long mIdForResponseEvent;
34     private final LongArrayQueue mTimestampsMs;
35 
BroadcastEvent(int sourceUid, @NonNull String targetPackage, @UserIdInt int targetUserId, long idForResponseEvent)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 
getSourceUid()45     public int getSourceUid() {
46         return mSourceUid;
47     }
48 
getTargetPackage()49     public @NonNull String getTargetPackage() {
50         return mTargetPackage;
51     }
52 
getTargetUserId()53     public @UserIdInt int getTargetUserId() {
54         return mTargetUserId;
55     }
56 
getIdForResponseEvent()57     public long getIdForResponseEvent() {
58         return mIdForResponseEvent;
59     }
60 
getTimestampsMs()61     public LongArrayQueue getTimestampsMs() {
62         return mTimestampsMs;
63     }
64 
addTimestampMs(long timestampMs)65     public void addTimestampMs(long timestampMs) {
66         mTimestampsMs.addLast(timestampMs);
67     }
68 
69     @Override
equals(@ullable Object obj)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
hashCode()85     public int hashCode() {
86         return Objects.hash(mSourceUid, mTargetPackage, mTargetUserId,
87                 mIdForResponseEvent);
88     }
89 
90     @Override
toString()91     public @NonNull String toString() {
92         return "BroadcastEvent {"
93                 + "srcUid=" + mSourceUid
94                 + ",tgtPkg=" + mTargetPackage
95                 + ",tgtUser=" + mTargetUserId
96                 + ",id=" + mIdForResponseEvent
97                 + "}";
98     }
99 }
100