• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.eventlib.events.deviceadminreceivers;
18 
19 import android.app.admin.DeviceAdminReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 
23 import androidx.annotation.CheckResult;
24 
25 import com.android.eventlib.Event;
26 import com.android.eventlib.EventLogger;
27 import com.android.eventlib.EventLogsQuery;
28 import com.android.queryable.info.DeviceAdminReceiverInfo;
29 import com.android.queryable.queries.DeviceAdminReceiverQuery;
30 import com.android.queryable.queries.DeviceAdminReceiverQueryHelper;
31 import com.android.queryable.queries.IntentQuery;
32 import com.android.queryable.queries.IntentQueryHelper;
33 import com.android.queryable.queries.LongQuery;
34 import com.android.queryable.queries.LongQueryHelper;
35 import com.android.queryable.util.SerializableParcelWrapper;
36 
37 /** Event logged when {@link DeviceAdminReceiver#onSystemUpdatePending} is called. */
38 public class DeviceAdminSystemUpdatePendingEvent extends Event {
39 
40     private static final long serialVersionUID = 1;
41 
42     /** Begins a query for {@link DeviceAdminSystemUpdatePendingEvent} events. */
queryPackage(String packageName)43     public static DeviceAdminSystemUpdatePendingEventQuery queryPackage(String packageName) {
44         return new DeviceAdminSystemUpdatePendingEventQuery(packageName);
45     }
46 
47     /** {@link EventLogsQuery} for {@link DeviceAdminSystemUpdatePendingEvent}. */
48     public static final class DeviceAdminSystemUpdatePendingEventQuery
49             extends EventLogsQuery<DeviceAdminSystemUpdatePendingEvent,
50                     DeviceAdminSystemUpdatePendingEventQuery> {
51 
52         private static final long serialVersionUID = 1;
53 
54         DeviceAdminReceiverQueryHelper<DeviceAdminSystemUpdatePendingEventQuery>
55                 mDeviceAdminReceiver = new DeviceAdminReceiverQueryHelper<>(this);
56         IntentQueryHelper<DeviceAdminSystemUpdatePendingEventQuery> mIntent =
57                 new IntentQueryHelper<>(this);
58         LongQueryHelper<DeviceAdminSystemUpdatePendingEventQuery> mReceivedTime =
59                 new LongQueryHelper<>(this);
60 
DeviceAdminSystemUpdatePendingEventQuery(String packageName)61         private DeviceAdminSystemUpdatePendingEventQuery(String packageName) {
62             super(DeviceAdminSystemUpdatePendingEvent.class, packageName);
63         }
64 
65         /**
66          * Queries {@link Intent} passed into {@link
67          * DeviceAdminReceiver#onPasswordSucceeded(Context, Intent)}.
68          */
69         @CheckResult
whereIntent()70         public IntentQuery<DeviceAdminSystemUpdatePendingEventQuery> whereIntent() {
71             return mIntent;
72         }
73 
74         /** Queries {@link DeviceAdminReceiver}. */
75         @CheckResult
76         public DeviceAdminReceiverQuery<DeviceAdminSystemUpdatePendingEventQuery>
whereDeviceAdminReceiver()77         whereDeviceAdminReceiver() {
78             return mDeviceAdminReceiver;
79         }
80 
81         /**
82          * Query the received time passed into {@link
83          * DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)}.
84          */
85         @CheckResult
whereReceivedTime()86         public LongQuery<DeviceAdminSystemUpdatePendingEventQuery> whereReceivedTime() {
87             return mReceivedTime;
88         }
89 
90         @Override
filter(DeviceAdminSystemUpdatePendingEvent event)91         protected boolean filter(DeviceAdminSystemUpdatePendingEvent event) {
92             if (!mIntent.matches(event.mIntent)) {
93                 return false;
94             }
95             if (!mDeviceAdminReceiver.matches(event.mDeviceAdminReceiver)) {
96                 return false;
97             }
98             if (!mReceivedTime.matches(event.mReceivedTime)) {
99                 return false;
100             }
101             return true;
102         }
103 
104         @Override
describeQuery(String fieldName)105         public String describeQuery(String fieldName) {
106             return toStringBuilder(DeviceAdminSystemUpdatePendingEvent.class, this)
107                     .field("intent", mIntent)
108                     .field("deviceAdminReceiver", mDeviceAdminReceiver)
109                     .field("receivedTime", mReceivedTime)
110                     .toString();
111         }
112     }
113 
114     /** Begins logging a {@link DeviceAdminSystemUpdatePendingEvent}. */
logger( DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent, long receivedTime)115     public static DeviceAdminSystemUpdatePendingEventLogger logger(
116             DeviceAdminReceiver deviceAdminReceiver,
117             Context context,
118             Intent intent,
119             long receivedTime) {
120         return new DeviceAdminSystemUpdatePendingEventLogger(
121                 deviceAdminReceiver, context, intent, receivedTime);
122     }
123 
124     /** {@link EventLogger} for {@link DeviceAdminSystemUpdatePendingEvent}. */
125     public static final class DeviceAdminSystemUpdatePendingEventLogger
126             extends EventLogger<DeviceAdminSystemUpdatePendingEvent> {
DeviceAdminSystemUpdatePendingEventLogger( DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent, long receivedTime)127         private DeviceAdminSystemUpdatePendingEventLogger(
128                 DeviceAdminReceiver deviceAdminReceiver,
129                 Context context,
130                 Intent intent,
131                 long receivedTime) {
132             super(context, new DeviceAdminSystemUpdatePendingEvent());
133             mEvent.mIntent = new SerializableParcelWrapper<>(intent);
134             setDeviceAdminReceiver(deviceAdminReceiver);
135             setReceivedTime(receivedTime);
136         }
137 
138         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( DeviceAdminReceiver deviceAdminReceiver)139         public DeviceAdminSystemUpdatePendingEventLogger setDeviceAdminReceiver(
140                 DeviceAdminReceiver deviceAdminReceiver) {
141             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiver);
142             return this;
143         }
144 
145         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( Class<? extends DeviceAdminReceiver> deviceAdminReceiverClass)146         public DeviceAdminSystemUpdatePendingEventLogger setDeviceAdminReceiver(
147                 Class<? extends DeviceAdminReceiver> deviceAdminReceiverClass) {
148             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiverClass);
149             return this;
150         }
151 
152         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( String deviceAdminReceiverClassName)153         public DeviceAdminSystemUpdatePendingEventLogger setDeviceAdminReceiver(
154                 String deviceAdminReceiverClassName) {
155             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiverClassName);
156             return this;
157         }
158 
159         /** Sets the {@link Intent} which was received. */
setIntent(Intent intent)160         public DeviceAdminSystemUpdatePendingEventLogger setIntent(Intent intent) {
161             mEvent.mIntent = new SerializableParcelWrapper<>(intent);
162             return this;
163         }
164 
165         /** Sets the received time. */
setReceivedTime(long receivedTime)166         public DeviceAdminSystemUpdatePendingEventLogger setReceivedTime(long receivedTime) {
167             mEvent.mReceivedTime = receivedTime;
168             return this;
169         }
170     }
171 
172     protected SerializableParcelWrapper<Intent> mIntent;
173     protected long mReceivedTime;
174     protected DeviceAdminReceiverInfo mDeviceAdminReceiver;
175 
176     /**
177      * The {@link Intent} passed into {@link
178      * DeviceAdminReceiver#onPasswordSucceeded(Context, Intent)}.
179      */
intent()180     public Intent intent() {
181         if (mIntent == null) {
182             return null;
183         }
184         return mIntent.get();
185     }
186 
187     /**
188      * The received time passed into {@link
189      * DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)}.
190      */
receivedTime()191     public long receivedTime() {
192         return mReceivedTime;
193     }
194 
195     /** Information about the {@link DeviceAdminReceiver} which received the intent. */
deviceAdminReceiver()196     public DeviceAdminReceiverInfo deviceAdminReceiver() {
197         return mDeviceAdminReceiver;
198     }
199 
200     @Override
toString()201     public String toString() {
202         return "DeviceAdminSystemUpdatePendingEvent{"
203                 + " intent=" + intent()
204                 + ", receivedTime=" + receivedTime()
205                 + ", deviceAdminReceiver=" + mDeviceAdminReceiver
206                 + ", packageName='" + mPackageName + "'"
207                 + ", timestamp=" + mTimestamp
208                 + "}";
209     }
210 }
211